add the following:
to IAnimatedMeshSceneNode.h
Code: Select all
public:
//! Returns a pointer to a child node, wich has the same transformation as
//! the corrsesponding joint, if the mesh in this scene node is a .X mesh.
virtual ISceneNode* getXJointNode(const c8* jointName)=0;
Code: Select all
public:
//! Returns a pointer to a child node, wich has the same transformation as
//! the corrsesponding joint, if the mesh in this scene node is a .X mesh.
virtual ISceneNode* getXJointNode(const c8* jointName);
private:
core::array<IDummyTransformationSceneNode* > JointChildSceneNodesX;
Code: Select all
//! Returns a pointer to a child node, wich has the same transformation as
//! the corrsesponding joint, if the mesh in this scene node is a .X mesh.
ISceneNode* CAnimatedMeshSceneNode::getXJointNode(const c8* jointName)
{
if (!Mesh || Mesh->getMeshType() != EAMT_X)
return 0;
IAnimatedMeshX* amm = (IAnimatedMeshX*)Mesh;
s32 jointCount = amm->getJointCount();
s32 number = amm->getJointNumber(jointName);
if (number == -1)
{
os::Printer::log("Joint with specified name not found in .X mesh.", jointName, ELL_WARNING);
return 0;
}
if (JointChildSceneNodesX.empty())
{
// allocate joints for the first time.
JointChildSceneNodesX.set_used(jointCount);
for (s32 i=0; i<jointCount; ++i)
JointChildSceneNodesX[i] = 0;
}
if (JointChildSceneNodesX[number] == 0)
{
JointChildSceneNodesX[number] =
SceneManager->addDummyTransformationSceneNode(this);
JointChildSceneNodesX[number]->grab();
}
return JointChildSceneNodesX[number];
}
//added by JAMES is new code (James is my name)
all of these are in CAnimatedMeshSceneNode.cpp
the destructor should now look like this
Code: Select all
//! destructor
CAnimatedMeshSceneNode::~CAnimatedMeshSceneNode()
{
if (Mesh)
Mesh->drop();
if (Shadow)
Shadow->drop();
for (s32 i=0; i<(s32)JointChildSceneNodes.size(); ++i)
if (JointChildSceneNodes[i])
JointChildSceneNodes[i]->drop();
//added by JAMES
for (s32 i=0; i<(s32)JointChildSceneNodesX.size(); ++i)
if (JointChildSceneNodesX[i])
JointChildSceneNodesX[i]->drop();
//end added by JAMES
}
Code: Select all
//! frame
void CAnimatedMeshSceneNode::OnPreRender()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnPreRender();
if (IsVisible)
{
for (s32 i=0; i<(s32)JointChildSceneNodes.size(); ++i){
if (JointChildSceneNodes[i])
JointChildSceneNodes[i]->OnPreRender();}
//added by JAMES
for (s32 i=0; i<(s32)JointChildSceneNodesX.size(); ++i){
if (JointChildSceneNodesX[i])
JointChildSceneNodesX[i]->OnPreRender();}
//end added by JAMES
}
}
Code: Select all
//! OnPostRender() is called just after rendering the whole scene.
void CAnimatedMeshSceneNode::OnPostRender(u32 timeMs)
{
s32 frameNr = getFrameNr();
if (IsVisible)
{
// animate this node with all animators
core::list<ISceneNodeAnimator*>::Iterator ait = Animators.begin();
for (; ait != Animators.end(); ++ait)
(*ait)->animateNode(this, timeMs);
// update absolute position
updateAbsolutePosition();
// update all dummy transformation nodes
if (!JointChildSceneNodes.empty() && Mesh && Mesh->getMeshType() == EAMT_MS3D)
{
IAnimatedMeshMS3D* amm = (IAnimatedMeshMS3D*)Mesh;
core::matrix4* mat;
for (s32 i=0; i<(s32)JointChildSceneNodes.size(); ++i)
if (JointChildSceneNodes[i])
{
mat = amm->getMatrixOfJoint(i, frameNr);
if (mat)
JointChildSceneNodes[i]->getRelativeTransformationMatrix() = *mat;
}
}
//added by JAMES
if (!JointChildSceneNodesX.empty() && Mesh && Mesh->getMeshType() == EAMT_X)
{
IAnimatedMeshX* amm = (IAnimatedMeshX*)Mesh;
core::matrix4* mat;
for (s32 i=0; i<(s32)JointChildSceneNodesX.size(); ++i)
if (JointChildSceneNodesX[i])
{
mat = amm->getMatrixOfJoint(i, frameNr);
if (mat)
JointChildSceneNodesX[i]->getRelativeTransformationMatrix() = *mat;
}
}
//end added by JAMES
core::list<ISceneNode*>::Iterator it = Children.begin();
for (; it != Children.end(); ++it)
(*it)->OnPostRender(timeMs);
}
}
Code: Select all
//! Removes a child from this scene node.
//! Implemented here, to be able to remove the shadow properly, if there is one,
//! or to remove attached childs.
bool CAnimatedMeshSceneNode::removeChild(ISceneNode* child)
{
if (child && Shadow == child)
{
Shadow->drop();
Shadow = 0;
return true;
}
if (ISceneNode::removeChild(child))
{
for (s32 i=0; i<(s32)JointChildSceneNodes.size(); ++i)
if (JointChildSceneNodes[i] == child)
{
JointChildSceneNodes[i]->drop();
JointChildSceneNodes[i] = 0;
return true;
}
//added by JAMES
for (s32 i=0; i<(s32)JointChildSceneNodesX.size(); ++i)
if (JointChildSceneNodesX[i] == child)
{
JointChildSceneNodesX[i]->drop();
JointChildSceneNodesX[i] = 0;
return true;
}
//end added by JAMES
return true;
}
return false;
}