Fixed animation loader bug, added CBoneTransformData to separate animation transforms away from CSkeleton, added skeleton raycasting, added a bunch of animation playback controls to the character editor

This commit is contained in:
parax0
2016-04-10 06:49:42 -06:00
parent dfdbed24c4
commit feace9e38c
23 changed files with 508 additions and 98 deletions

View File

@@ -4,8 +4,9 @@
CCharacterNode::CCharacterNode(CScene *pScene, u32 NodeID, CAnimSet *pChar /*= 0*/, CSceneNode *pParent /*= 0*/)
: CSceneNode(pScene, NodeID, pParent)
, mAnimTime(0.f)
{
SetCharacter(pChar);
SetCharSet(pChar);
}
ENodeType CCharacterNode::NodeType()
@@ -36,31 +37,53 @@ void CCharacterNode::Draw(FRenderOptions Options, int /*ComponentIndex*/, const
{
CSkeleton *pSkel = mpCharacter->NodeSkeleton(mActiveCharSet);
CAnimation *pAnim = mpCharacter->Animation(mActiveAnim);
pSkel->UpdateTransform(pAnim, (float) CTimer::GlobalTime(), false);
pSkel->Draw(Options);
pSkel->UpdateTransform(mTransformData, pAnim, mAnimTime, false);
pSkel->Draw(Options, mTransformData);
}
SRayIntersection CCharacterNode::RayNodeIntersectTest(const CRay& /*rkRay*/, u32 /*AssetID*/, const SViewInfo& /*rkViewInfo*/)
SRayIntersection CCharacterNode::RayNodeIntersectTest(const CRay& rkRay, u32 /*AssetID*/, const SViewInfo& /*rkViewInfo*/)
{
// Not currently doing any ray checks on character nodes so don't care about this right now.
// Check for bone under ray. Doesn't check for model intersections atm
if (mpCharacter)
{
CSkeleton *pSkel = mpCharacter->NodeSkeleton(mActiveCharSet);
if (pSkel)
{
std::pair<s32,float> Hit = pSkel->RayIntersect(rkRay, mTransformData);
if (Hit.first != -1)
{
SRayIntersection Intersect;
Intersect.Hit = true;
Intersect.ComponentIndex = Hit.first;
Intersect.Distance = Hit.second;
Intersect.HitPoint = rkRay.PointOnRay(Hit.second);
Intersect.pNode = this;
return Intersect;
}
}
}
return SRayIntersection();
}
void CCharacterNode::SetCharacter(CAnimSet *pChar)
void CCharacterNode::SetCharSet(CAnimSet *pChar)
{
mpCharacter = pChar;
SetActiveCharSet(0);
SetActiveChar(0);
if (!mpCharacter)
mLocalAABox = CAABox::skOne;
}
void CCharacterNode::SetActiveCharSet(u32 CharIndex)
void CCharacterNode::SetActiveChar(u32 CharIndex)
{
mActiveCharSet = CharIndex;
if (mpCharacter)
{
mTransformData.ResizeToSkeleton(mpCharacter->NodeSkeleton(CharIndex));
mLocalAABox = mpCharacter->NodeModel(CharIndex)->AABox();
MarkTransformChanged();
}
@@ -70,3 +93,8 @@ void CCharacterNode::SetActiveAnim(u32 AnimIndex)
{
mActiveAnim = AnimIndex;
}
void CCharacterNode::SetAnimTime(float Time)
{
mAnimTime = Time;
}

View File

@@ -2,13 +2,16 @@
#define CCHARACTERNODE_H
#include "CSceneNode.h"
#include "Core/Render/CBoneTransformData.h"
#include "Core/Resource/CAnimSet.h"
class CCharacterNode : public CSceneNode
{
TResPtr<CAnimSet> mpCharacter;
CBoneTransformData mTransformData;
u32 mActiveCharSet;
u32 mActiveAnim;
float mAnimTime;
public:
explicit CCharacterNode(CScene *pScene, u32 NodeID, CAnimSet *pChar = 0, CSceneNode *pParent = 0);
@@ -22,9 +25,10 @@ public:
inline u32 ActiveCharSet() const { return mActiveCharSet; }
inline u32 ActiveAnim() const { return mActiveAnim; }
void SetCharacter(CAnimSet *pChar);
void SetActiveCharSet(u32 CharIndex);
void SetCharSet(CAnimSet *pChar);
void SetActiveChar(u32 CharIndex);
void SetActiveAnim(u32 AnimIndex);
void SetAnimTime(float Time);
};
#endif // CCHARACTERNODE_H

View File

@@ -80,7 +80,7 @@ SRayIntersection CLightNode::RayNodeIntersectTest(const CRay& rkRay, u32 AssetID
// Step 1: check whether the ray intersects with the plane the billboard is on
CPlane BillboardPlane(-rkViewInfo.pCamera->Direction(), mPosition);
std::pair<bool,float> PlaneTest = Math::RayPlaneIntersecton(rkRay, BillboardPlane);
std::pair<bool,float> PlaneTest = Math::RayPlaneIntersection(rkRay, BillboardPlane);
if (PlaneTest.first)
{

View File

@@ -361,7 +361,7 @@ SRayIntersection CScriptNode::RayNodeIntersectTest(const CRay& rkRay, u32 AssetI
{
// Step 1: check whether the ray intersects with the plane the billboard is on
CPlane BillboardPlane(-rkViewInfo.pCamera->Direction(), mPosition);
std::pair<bool,float> PlaneTest = Math::RayPlaneIntersecton(rkRay, BillboardPlane);
std::pair<bool,float> PlaneTest = Math::RayPlaneIntersection(rkRay, BillboardPlane);
if (PlaneTest.first)
{