mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-13 15:16:28 +00:00
Applied various fixes to the attachment system, made skeleton rendering more flexible, added the ability for attachments to specify an attach type
This commit is contained in:
@@ -57,7 +57,7 @@ void CCharacterNode::Draw(FRenderOptions Options, int ComponentIndex, const SVie
|
||||
// Draw skeleton
|
||||
if (ComponentIndex == -2)
|
||||
{
|
||||
pSkel->Draw(Options, mTransformData);
|
||||
pSkel->Draw(Options, &mTransformData);
|
||||
}
|
||||
|
||||
// Draw mesh
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
#include "Core/Resource/Script/IProperty.h"
|
||||
#include <Common/Assert.h>
|
||||
|
||||
CScriptAttachNode::CScriptAttachNode(CScene *pScene, const TIDString& rkAttachProperty, const TString& rkLocator, CScriptNode *pParent)
|
||||
CScriptAttachNode::CScriptAttachNode(CScene *pScene, const SAttachment& rkAttachment, CScriptNode *pParent)
|
||||
: CSceneNode(pScene, -1, pParent)
|
||||
, mpScriptNode(pParent)
|
||||
, mLocatorName(rkLocator)
|
||||
, mAttachType(rkAttachment.AttachType)
|
||||
, mLocatorName(rkAttachment.LocatorName)
|
||||
{
|
||||
CPropertyStruct *pBaseStruct = pParent->Instance()->Properties();
|
||||
mpAttachAssetProp = pBaseStruct->PropertyByIDString(rkAttachProperty);
|
||||
mpAttachAssetProp = pBaseStruct->PropertyByIDString(rkAttachment.AttachProperty);
|
||||
if (mpAttachAssetProp) AttachPropertyModified();
|
||||
|
||||
ParentDisplayAssetChanged(mpScriptNode->DisplayAsset());
|
||||
@@ -150,8 +151,16 @@ SRayIntersection CScriptAttachNode::RayNodeIntersectTest(const CRay& rkRay, u32
|
||||
// ************ PROTECTED ************
|
||||
void CScriptAttachNode::CalculateTransform(CTransform4f& rOut) const
|
||||
{
|
||||
if (mpLocator)
|
||||
rOut = mpScriptNode->BoneTransform(mpLocator->ID(), false);
|
||||
// Apply our local transform
|
||||
rOut.Scale(LocalScale());
|
||||
rOut.Rotate(LocalRotation());
|
||||
rOut.Translate(LocalPosition());
|
||||
|
||||
CSceneNode::CalculateTransform(rOut);
|
||||
// Apply bone transform
|
||||
if (mpLocator)
|
||||
rOut = mpScriptNode->BoneTransform(mpLocator->ID(), mAttachType, false) * rOut;
|
||||
|
||||
// Apply parent transform
|
||||
if (mpParent)
|
||||
rOut = mpParent->Transform() * rOut;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "CSceneNode.h"
|
||||
#include "Core/Resource/Script/IProperty.h"
|
||||
#include "Core/Resource/Script/CScriptTemplate.h"
|
||||
|
||||
class CScriptNode;
|
||||
|
||||
@@ -12,11 +13,12 @@ class CScriptAttachNode : public CSceneNode
|
||||
TResPtr<CResource> mpAttachAsset;
|
||||
IProperty *mpAttachAssetProp;
|
||||
|
||||
EAttachType mAttachType;
|
||||
TString mLocatorName;
|
||||
CBone *mpLocator;
|
||||
|
||||
public:
|
||||
explicit CScriptAttachNode(CScene *pScene, const TIDString& rkAttachProperty, const TString& rkLocator, CScriptNode *pParent);
|
||||
explicit CScriptAttachNode(CScene *pScene, const SAttachment& rkAttachment, CScriptNode *pParent);
|
||||
void AttachPropertyModified();
|
||||
void ParentDisplayAssetChanged(CResource *pNewDisplayAsset);
|
||||
CModel* Model() const;
|
||||
@@ -29,6 +31,7 @@ public:
|
||||
SRayIntersection RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo);
|
||||
|
||||
inline IProperty* AttachProperty() const { return mpAttachAssetProp; }
|
||||
inline TString LocatorName() const { return mLocatorName; }
|
||||
|
||||
protected:
|
||||
void CalculateTransform(CTransform4f& rOut) const;
|
||||
|
||||
@@ -40,8 +40,6 @@ CScriptNode::CScriptNode(CScene *pScene, u32 NodeID, CSceneNode *pParent, CScrip
|
||||
|
||||
// Determine display assets
|
||||
SetDisplayAsset(mpInstance->DisplayAsset());
|
||||
mCharIndex = mpInstance->ActiveCharIndex();
|
||||
mAnimIndex = mpInstance->ActiveAnimIndex();
|
||||
mpCollisionNode->SetCollision(mpInstance->Collision());
|
||||
|
||||
// Create preview volume node
|
||||
@@ -62,7 +60,7 @@ CScriptNode::CScriptNode(CScene *pScene, u32 NodeID, CSceneNode *pParent, CScrip
|
||||
for (u32 iAttach = 0; iAttach < pTemp->NumAttachments(); iAttach++)
|
||||
{
|
||||
const SAttachment& rkAttach = pTemp->Attachment(iAttach);
|
||||
CScriptAttachNode *pAttach = new CScriptAttachNode(pScene, rkAttach.AttachProperty, rkAttach.LocatorName, this);
|
||||
CScriptAttachNode *pAttach = new CScriptAttachNode(pScene, rkAttach, this);
|
||||
mAttachments.push_back(pAttach);
|
||||
}
|
||||
|
||||
@@ -481,8 +479,6 @@ void CScriptNode::PropertyModified(IProperty *pProp)
|
||||
if (pProp->Type() == eCharacterProperty)
|
||||
{
|
||||
mpInstance->EvaluateDisplayAsset();
|
||||
mCharIndex = mpInstance->ActiveCharIndex();
|
||||
mAnimIndex = mpInstance->ActiveAnimIndex();
|
||||
SetDisplayAsset(mpInstance->DisplayAsset());
|
||||
}
|
||||
|
||||
@@ -493,8 +489,6 @@ void CScriptNode::PropertyModified(IProperty *pProp)
|
||||
if (pFileTemp->AcceptsExtension("CMDL") || pFileTemp->AcceptsExtension("TXTR") || pFileTemp->AcceptsExtension("ANCS") || pFileTemp->AcceptsExtension("CHAR"))
|
||||
{
|
||||
mpInstance->EvaluateDisplayAsset();
|
||||
mCharIndex = mpInstance->ActiveCharIndex();
|
||||
mAnimIndex = mpInstance->ActiveAnimIndex();
|
||||
SetDisplayAsset(mpInstance->DisplayAsset());
|
||||
}
|
||||
else if (pFileTemp->AcceptsExtension("DCLN"))
|
||||
@@ -692,6 +686,13 @@ CSkeleton* CScriptNode::ActiveSkeleton() const
|
||||
else return nullptr;
|
||||
}
|
||||
|
||||
CAnimation* CScriptNode::ActiveAnimation() const
|
||||
{
|
||||
CAnimSet *pSet = ActiveAnimSet();
|
||||
if (pSet) return pSet->Animation(mAnimIndex);
|
||||
else return nullptr;
|
||||
}
|
||||
|
||||
CTexture* CScriptNode::ActiveBillboard() const
|
||||
{
|
||||
if (mpDisplayAsset && mpDisplayAsset->Type() == eTexture)
|
||||
@@ -724,7 +725,7 @@ CVector2f CScriptNode::BillboardScale() const
|
||||
return Out * 0.5f * Template()->PreviewScale();
|
||||
}
|
||||
|
||||
CTransform4f CScriptNode::BoneTransform(u32 BoneID, bool Absolute) const
|
||||
CTransform4f CScriptNode::BoneTransform(u32 BoneID, EAttachType AttachType, bool Absolute) const
|
||||
{
|
||||
CTransform4f Out;
|
||||
CSkeleton *pSkel = ActiveSkeleton();
|
||||
@@ -732,6 +733,9 @@ CTransform4f CScriptNode::BoneTransform(u32 BoneID, bool Absolute) const
|
||||
if (pSkel)
|
||||
{
|
||||
CBone *pBone = pSkel->BoneByID(BoneID);
|
||||
ASSERT(pBone);
|
||||
|
||||
if (AttachType == eAttach) Out.Rotate(pBone->Rotation());
|
||||
Out.Translate(pBone->Position());
|
||||
}
|
||||
|
||||
@@ -743,19 +747,21 @@ CTransform4f CScriptNode::BoneTransform(u32 BoneID, bool Absolute) const
|
||||
// ************ PROTECTED ************
|
||||
void CScriptNode::SetDisplayAsset(CResource *pRes)
|
||||
{
|
||||
if (mpDisplayAsset != pRes)
|
||||
{
|
||||
mpDisplayAsset = pRes;
|
||||
CModel *pModel = ActiveModel();
|
||||
mLocalAABox = (pModel ? pModel->AABox() : CAABox::skOne);
|
||||
MarkTransformChanged();
|
||||
mpDisplayAsset = pRes;
|
||||
|
||||
for (u32 iAttach = 0; iAttach < mAttachments.size(); iAttach++)
|
||||
mAttachments[iAttach]->ParentDisplayAssetChanged(pRes);
|
||||
bool IsAnimSet = (pRes && pRes->Type() == eAnimSet);
|
||||
mCharIndex = (IsAnimSet ? mpInstance->ActiveCharIndex() : -1);
|
||||
mAnimIndex = (IsAnimSet ? mpInstance->ActiveAnimIndex() : -1);
|
||||
|
||||
if (mpExtra)
|
||||
mpExtra->DisplayAssetChanged(pRes);
|
||||
}
|
||||
CModel *pModel = ActiveModel();
|
||||
mLocalAABox = (pModel ? pModel->AABox() : CAABox::skOne);
|
||||
MarkTransformChanged();
|
||||
|
||||
for (u32 iAttach = 0; iAttach < mAttachments.size(); iAttach++)
|
||||
mAttachments[iAttach]->ParentDisplayAssetChanged(pRes);
|
||||
|
||||
if (mpExtra)
|
||||
mpExtra->DisplayAssetChanged(pRes);
|
||||
}
|
||||
|
||||
void CScriptNode::CalculateTransform(CTransform4f& rOut) const
|
||||
|
||||
@@ -59,15 +59,18 @@ public:
|
||||
bool HasPreviewVolume() const;
|
||||
CAABox PreviewVolumeAABox() const;
|
||||
CVector2f BillboardScale() const;
|
||||
CTransform4f BoneTransform(u32 BoneID, bool Absolute) const;
|
||||
CTransform4f BoneTransform(u32 BoneID, EAttachType AttachType, bool Absolute) const;
|
||||
|
||||
CModel* ActiveModel() const;
|
||||
CAnimSet* ActiveAnimSet() const;
|
||||
CSkeleton* ActiveSkeleton() const;
|
||||
CAnimation* ActiveAnimation() const;
|
||||
CTexture* ActiveBillboard() const;
|
||||
bool UsesModel() const;
|
||||
|
||||
inline CResource* DisplayAsset() const { return mpDisplayAsset; }
|
||||
inline u32 NumAttachments() const { return mAttachments.size(); }
|
||||
inline CScriptAttachNode* Attachment(u32 Index) const { return mAttachments[Index]; }
|
||||
inline CResource* DisplayAsset() const { return mpDisplayAsset; }
|
||||
|
||||
protected:
|
||||
void SetDisplayAsset(CResource *pRes);
|
||||
|
||||
Reference in New Issue
Block a user