Some coding style changes, made one method const.

git-svn-id: http://svn.code.sf.net/p/irrlicht/code/trunk@1242 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
hybrid 2008-02-12 15:31:35 +00:00
parent a5137993dc
commit 83cda72c66
6 changed files with 162 additions and 219 deletions

View File

@ -54,7 +54,7 @@ namespace scene
public: public:
IBoneSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id=-1) : IBoneSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id=-1) :
ISceneNode(parent, mgr, id),positionHint(-1),scaleHint(-1),rotationHint(-1) { } ISceneNode(parent, mgr, id),positionHint(-1),scaleHint(-1),rotationHint(-1) { }
//! Returns the name of the bone //! Returns the name of the bone
virtual const c8* getBoneName() const = 0; virtual const c8* getBoneName() const = 0;
@ -83,13 +83,11 @@ namespace scene
virtual void setSkinningSpace( E_BONE_SKINNING_SPACE space ) =0; virtual void setSkinningSpace( E_BONE_SKINNING_SPACE space ) =0;
//! How the relative transformation of the bone is used //! How the relative transformation of the bone is used
virtual E_BONE_SKINNING_SPACE getSkinningSpace() =0; virtual E_BONE_SKINNING_SPACE getSkinningSpace() const =0;
//! updates the absolute position based on the relative and the parents position //! updates the absolute position based on the relative and the parents position
virtual void updateAbsolutePositionOfAllChildren()=0; virtual void updateAbsolutePositionOfAllChildren()=0;
s32 positionHint; s32 positionHint;
s32 scaleHint; s32 scaleHint;
s32 rotationHint; s32 rotationHint;

View File

@ -1,8 +1,5 @@
#include "CBoneSceneNode.h" #include "CBoneSceneNode.h"
namespace irr namespace irr
{ {
namespace scene namespace scene
@ -17,11 +14,6 @@ CBoneSceneNode::CBoneSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
} }
//! destructor
CBoneSceneNode::~CBoneSceneNode()
{
}
//! Returns the name of the bone //! Returns the name of the bone
const c8* CBoneSceneNode::getBoneName() const const c8* CBoneSceneNode::getBoneName() const
@ -82,8 +74,6 @@ void CBoneSceneNode::OnAnimate(u32 timeMs)
} }
void CBoneSceneNode::helper_updateAbsolutePositionOfAllChildren(ISceneNode *Node) void CBoneSceneNode::helper_updateAbsolutePositionOfAllChildren(ISceneNode *Node)
{ {
Node->updateAbsolutePosition(); Node->updateAbsolutePosition();
@ -102,9 +92,6 @@ void CBoneSceneNode::updateAbsolutePositionOfAllChildren()
} }
void CBoneSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const void CBoneSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{ {
out->addInt("BoneIndex", BoneIndex); out->addInt("BoneIndex", BoneIndex);
@ -112,13 +99,16 @@ void CBoneSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeRea
out->addEnum("AnimationMode", AnimationMode, BoneAnimationModeNames); out->addEnum("AnimationMode", AnimationMode, BoneAnimationModeNames);
} }
void CBoneSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) void CBoneSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{ {
BoneIndex = in->getAttributeAsInt("BoneIndex"); BoneIndex = in->getAttributeAsInt("BoneIndex");
BoneName = in->getAttributeAsString("BoneName"); BoneName = in->getAttributeAsString("BoneName");
AnimationMode = (E_BONE_ANIMATION_MODE)in->getAttributeAsEnumeration("AnimationMode", BoneAnimationModeNames); AnimationMode = (E_BONE_ANIMATION_MODE)in->getAttributeAsEnumeration("AnimationMode", BoneAnimationModeNames);
// todo: add/replace bone in parent with bone from mesh // TODO: add/replace bone in parent with bone from mesh
} }
} // namespace scene } // namespace scene
} // namespace irr } // namespace irr

View File

@ -20,9 +20,6 @@ namespace scene
CBoneSceneNode(ISceneNode* parent, ISceneManager* mgr, CBoneSceneNode(ISceneNode* parent, ISceneManager* mgr,
s32 id=-1, u32 boneIndex=0, const c8* boneName=0); s32 id=-1, u32 boneIndex=0, const c8* boneName=0);
//! destructor
~CBoneSceneNode();
//! Returns the name of the bone //! Returns the name of the bone
virtual const c8* getBoneName() const; virtual const c8* getBoneName() const;
@ -38,14 +35,13 @@ namespace scene
//! returns the axis aligned bounding box of this node //! returns the axis aligned bounding box of this node
virtual const core::aabbox3d<f32>& getBoundingBox() const; virtual const core::aabbox3d<f32>& getBoundingBox() const;
/*
//! Returns the relative transformation of the scene node. //! Returns the relative transformation of the scene node.
//virtual core::matrix4 getRelativeTransformation() const; //virtual core::matrix4 getRelativeTransformation() const;
*/
virtual void OnAnimate(u32 timeMs); virtual void OnAnimate(u32 timeMs);
void helper_updateAbsolutePositionOfAllChildren(ISceneNode *Node);
virtual void updateAbsolutePositionOfAllChildren(); virtual void updateAbsolutePositionOfAllChildren();
//! Writes attributes of the scene node. //! Writes attributes of the scene node.
@ -60,22 +56,20 @@ namespace scene
SkinningSpace=space; SkinningSpace=space;
} }
virtual E_BONE_SKINNING_SPACE getSkinningSpace() virtual E_BONE_SKINNING_SPACE getSkinningSpace() const
{ {
return SkinningSpace; return SkinningSpace;
} }
private: private:
void helper_updateAbsolutePositionOfAllChildren(ISceneNode *Node);
E_BONE_ANIMATION_MODE AnimationMode; E_BONE_ANIMATION_MODE AnimationMode;
E_BONE_SKINNING_SPACE SkinningSpace; E_BONE_SKINNING_SPACE SkinningSpace;
u32 BoneIndex; u32 BoneIndex;
core::stringc BoneName; core::stringc BoneName;
core::aabbox3d<f32> Box; core::aabbox3d<f32> Box;
}; };

View File

@ -1500,13 +1500,14 @@ E_DRIVER_TYPE CNullDriver::getDriverType() const
void CNullDriver::deleteMaterialRenders() void CNullDriver::deleteMaterialRenders()
{ {
// delete material renderers // delete material renderers
for (int i=0; i<(int)MaterialRenderers.size(); ++i) for (u32 i=0; i<MaterialRenderers.size(); ++i)
if (MaterialRenderers[i].Renderer) if (MaterialRenderers[i].Renderer)
MaterialRenderers[i].Renderer->drop(); MaterialRenderers[i].Renderer->drop();
MaterialRenderers.clear(); MaterialRenderers.clear();
} }
//! Returns pointer to material renderer or null //! Returns pointer to material renderer or null
IMaterialRenderer* CNullDriver::getMaterialRenderer(u32 idx) IMaterialRenderer* CNullDriver::getMaterialRenderer(u32 idx)
{ {
@ -1517,7 +1518,6 @@ IMaterialRenderer* CNullDriver::getMaterialRenderer(u32 idx)
} }
//! Returns amount of currently available material renderers. //! Returns amount of currently available material renderers.
u32 CNullDriver::getMaterialRendererCount() const u32 CNullDriver::getMaterialRendererCount() const
{ {

View File

@ -19,7 +19,7 @@ namespace scene
//! constructor //! constructor
CSkinnedMesh::CSkinnedMesh() CSkinnedMesh::CSkinnedMesh()
: SkinningBuffers(0), HasAnimation(0), PreparedForSkinning(0), : SkinningBuffers(0), HasAnimation(0), PreparedForSkinning(0),
AnimationFrames(0.f), lastAnimatedFrame(0.f), lastSkinnedFrame(0.f), AnimationFrames(0.f), LastAnimatedFrame(0.f), LastSkinnedFrame(0.f),
BoneControlUsed(false), AnimateNormals(true), HardwareSkinning(0), InterpolationMode(EIM_LINEAR) BoneControlUsed(false), AnimateNormals(true), HardwareSkinning(0), InterpolationMode(EIM_LINEAR)
{ {
#ifdef _DEBUG #ifdef _DEBUG
@ -76,10 +76,10 @@ IMesh* CSkinnedMesh::getMesh(s32 frame, s32 detailLevel, s32 startFrameLoop, s32
//! blend: {0-old position, 1-New position} //! blend: {0-old position, 1-New position}
void CSkinnedMesh::animateMesh(f32 frame, f32 blend) void CSkinnedMesh::animateMesh(f32 frame, f32 blend)
{ {
if ( !HasAnimation || lastAnimatedFrame==frame) if ( !HasAnimation || LastAnimatedFrame==frame)
return; return;
lastAnimatedFrame=frame; LastAnimatedFrame=frame;
if (blend<=0.f) if (blend<=0.f)
return; //No need to animate return; //No need to animate
@ -87,34 +87,34 @@ void CSkinnedMesh::animateMesh(f32 frame, f32 blend)
for (u32 i=0; i<AllJoints.size(); ++i) for (u32 i=0; i<AllJoints.size(); ++i)
{ {
//To Bitplane: The joints can be animated here with no input from their parents, but for setAnimationMode extra checks are needed to their parents //To Bitplane: The joints can be animated here with no input from their parents, but for setAnimationMode extra checks are needed to their parents
SJoint *Joint = AllJoints[i]; SJoint *joint = AllJoints[i];
const core::vector3df oldPosition = Joint->Animatedposition; const core::vector3df oldPosition = joint->Animatedposition;
const core::vector3df oldScale = Joint->Animatedscale; const core::vector3df oldScale = joint->Animatedscale;
const core::quaternion oldRotation = Joint->Animatedrotation; const core::quaternion oldRotation = joint->Animatedrotation;
core::vector3df position = oldPosition; core::vector3df position = oldPosition;
core::vector3df scale = oldScale; core::vector3df scale = oldScale;
core::quaternion rotation = oldRotation; core::quaternion rotation = oldRotation;
getFrameData(frame, Joint, getFrameData(frame, joint,
position, Joint->positionHint, position, joint->positionHint,
scale, Joint->scaleHint, scale, joint->scaleHint,
rotation, Joint->rotationHint); rotation, joint->rotationHint);
if (blend==1.0f) if (blend==1.0f)
{ {
//No blending needed //No blending needed
Joint->Animatedposition = position; joint->Animatedposition = position;
Joint->Animatedscale = scale; joint->Animatedscale = scale;
Joint->Animatedrotation = rotation; joint->Animatedrotation = rotation;
} }
else else
{ {
//Blend animation //Blend animation
Joint->Animatedposition = core::lerp(oldPosition, position, blend); joint->Animatedposition = core::lerp(oldPosition, position, blend);
Joint->Animatedscale = core::lerp(oldScale, scale, blend); joint->Animatedscale = core::lerp(oldScale, scale, blend);
Joint->Animatedrotation.slerp(oldRotation, rotation, blend); joint->Animatedrotation.slerp(oldRotation, rotation, blend);
} }
//Note: //Note:
@ -134,20 +134,20 @@ void CSkinnedMesh::buildAll_LocalAnimatedMatrices()
{ {
for (u32 i=0; i<AllJoints.size(); ++i) for (u32 i=0; i<AllJoints.size(); ++i)
{ {
SJoint *Joint = AllJoints[i]; SJoint *joint = AllJoints[i];
//Could be faster: //Could be faster:
if (Joint->UseAnimationFrom && if (joint->UseAnimationFrom &&
(Joint->UseAnimationFrom->PositionKeys.size() || (joint->UseAnimationFrom->PositionKeys.size() ||
Joint->UseAnimationFrom->ScaleKeys.size() || joint->UseAnimationFrom->ScaleKeys.size() ||
Joint->UseAnimationFrom->RotationKeys.size() )) joint->UseAnimationFrom->RotationKeys.size() ))
{ {
Joint->LocalAnimatedMatrix=Joint->Animatedrotation.getMatrix(); joint->LocalAnimatedMatrix=joint->Animatedrotation.getMatrix();
// --- Joint->LocalAnimatedMatrix *= Joint->Animatedrotation.getMatrix() --- // --- joint->LocalAnimatedMatrix *= joint->Animatedrotation.getMatrix() ---
f32 *m1 = Joint->LocalAnimatedMatrix.pointer(); f32 *m1 = joint->LocalAnimatedMatrix.pointer();
core::vector3df &Pos = Joint->Animatedposition; core::vector3df &Pos = joint->Animatedposition;
m1[0] += Pos.X*m1[3]; m1[0] += Pos.X*m1[3];
m1[1] += Pos.Y*m1[3]; m1[1] += Pos.Y*m1[3];
m1[2] += Pos.Z*m1[3]; m1[2] += Pos.Z*m1[3];
@ -162,46 +162,46 @@ void CSkinnedMesh::buildAll_LocalAnimatedMatrices()
m1[14] += Pos.Z*m1[15]; m1[14] += Pos.Z*m1[15];
// ----------------------------------- // -----------------------------------
Joint->GlobalSkinningSpace=false; joint->GlobalSkinningSpace=false;
if (Joint->ScaleKeys.size()) if (joint->ScaleKeys.size())
{ {
/* /*
core::matrix4 scaleMatrix; core::matrix4 scaleMatrix;
scaleMatrix.setScale(Joint->Animatedscale); scaleMatrix.setScale(joint->Animatedscale);
Joint->LocalAnimatedMatrix *= scaleMatrix; joint->LocalAnimatedMatrix *= scaleMatrix;
*/ */
// -------- Joint->LocalAnimatedMatrix *= scaleMatrix ----------------- // -------- joint->LocalAnimatedMatrix *= scaleMatrix -----------------
f32 *m1 = Joint->LocalAnimatedMatrix.pointer(); f32 *m1 = joint->LocalAnimatedMatrix.pointer();
m1[0] *= Joint->Animatedscale.X; m1[0] *= joint->Animatedscale.X;
m1[1] *= Joint->Animatedscale.X; m1[1] *= joint->Animatedscale.X;
m1[2] *= Joint->Animatedscale.X; m1[2] *= joint->Animatedscale.X;
m1[3] *= Joint->Animatedscale.X; m1[3] *= joint->Animatedscale.X;
m1[4] *= Joint->Animatedscale.Y; m1[4] *= joint->Animatedscale.Y;
m1[5] *= Joint->Animatedscale.Y; m1[5] *= joint->Animatedscale.Y;
m1[6] *= Joint->Animatedscale.Y; m1[6] *= joint->Animatedscale.Y;
m1[7] *= Joint->Animatedscale.Y; m1[7] *= joint->Animatedscale.Y;
m1[8] *= Joint->Animatedscale.Z; m1[8] *= joint->Animatedscale.Z;
m1[9] *= Joint->Animatedscale.Z; m1[9] *= joint->Animatedscale.Z;
m1[10] *= Joint->Animatedscale.Z; m1[10] *= joint->Animatedscale.Z;
m1[11] *= Joint->Animatedscale.Z; m1[11] *= joint->Animatedscale.Z;
m1[12] *= Joint->Animatedscale.X; m1[12] *= joint->Animatedscale.X;
// ----------------------------------- // -----------------------------------
} }
} }
else else
{ {
Joint->LocalAnimatedMatrix=Joint->LocalMatrix; joint->LocalAnimatedMatrix=joint->LocalMatrix;
} }
} }
} }
void CSkinnedMesh::buildAll_GlobalAnimatedMatrices(SJoint *Joint, SJoint *ParentJoint) void CSkinnedMesh::buildAll_GlobalAnimatedMatrices(SJoint *joint, SJoint *parentJoint)
{ {
if (!Joint) if (!joint)
{ {
for (u32 i=0; i<RootJoints.size(); ++i) for (u32 i=0; i<RootJoints.size(); ++i)
buildAll_GlobalAnimatedMatrices(RootJoints[i], 0); buildAll_GlobalAnimatedMatrices(RootJoints[i], 0);
@ -210,19 +210,19 @@ void CSkinnedMesh::buildAll_GlobalAnimatedMatrices(SJoint *Joint, SJoint *Parent
else else
{ {
// Find global matrix... // Find global matrix...
if (!ParentJoint || Joint->GlobalSkinningSpace) if (!parentJoint || joint->GlobalSkinningSpace)
Joint->GlobalAnimatedMatrix = Joint->LocalAnimatedMatrix; joint->GlobalAnimatedMatrix = joint->LocalAnimatedMatrix;
else else
Joint->GlobalAnimatedMatrix = ParentJoint->GlobalAnimatedMatrix * Joint->LocalAnimatedMatrix; joint->GlobalAnimatedMatrix = parentJoint->GlobalAnimatedMatrix * joint->LocalAnimatedMatrix;
} }
for (u32 j=0; j<Joint->Children.size(); ++j) for (u32 j=0; j<joint->Children.size(); ++j)
buildAll_GlobalAnimatedMatrices(Joint->Children[j], Joint); buildAll_GlobalAnimatedMatrices(joint->Children[j], joint);
} }
void CSkinnedMesh::getFrameData(f32 frame, SJoint *Joint, void CSkinnedMesh::getFrameData(f32 frame, SJoint *joint,
core::vector3df &position, s32 &positionHint, core::vector3df &position, s32 &positionHint,
core::vector3df &scale, s32 &scaleHint, core::vector3df &scale, s32 &scaleHint,
core::quaternion &rotation, s32 &rotationHint) core::quaternion &rotation, s32 &rotationHint)
@ -231,11 +231,11 @@ void CSkinnedMesh::getFrameData(f32 frame, SJoint *Joint,
s32 foundScaleIndex = -1; s32 foundScaleIndex = -1;
s32 foundRotationIndex = -1; s32 foundRotationIndex = -1;
if (Joint->UseAnimationFrom) if (joint->UseAnimationFrom)
{ {
const core::array<SPositionKey> &PositionKeys=Joint->UseAnimationFrom->PositionKeys; const core::array<SPositionKey> &PositionKeys=joint->UseAnimationFrom->PositionKeys;
const core::array<SScaleKey> &ScaleKeys=Joint->UseAnimationFrom->ScaleKeys; const core::array<SScaleKey> &ScaleKeys=joint->UseAnimationFrom->ScaleKeys;
const core::array<SRotationKey> &RotationKeys=Joint->UseAnimationFrom->RotationKeys; const core::array<SRotationKey> &RotationKeys=joint->UseAnimationFrom->RotationKeys;
if (PositionKeys.size()) if (PositionKeys.size())
{ {
@ -464,55 +464,55 @@ void CSkinnedMesh::skinMesh()
} }
void CSkinnedMesh::SkinJoint(SJoint *Joint, SJoint *ParentJoint) void CSkinnedMesh::SkinJoint(SJoint *joint, SJoint *parentJoint)
{ {
if (Joint->Weights.size()) if (joint->Weights.size())
{ {
//Find this joints pull on vertices... //Find this joints pull on vertices...
core::matrix4 JointVertexPull(core::matrix4::EM4CONST_NOTHING); core::matrix4 jointVertexPull(core::matrix4::EM4CONST_NOTHING);
JointVertexPull.setbyproduct(Joint->GlobalAnimatedMatrix, Joint->GlobalInversedMatrix); jointVertexPull.setbyproduct(joint->GlobalAnimatedMatrix, joint->GlobalInversedMatrix);
core::vector3df ThisVertexMove, ThisNormalMove; core::vector3df thisVertexMove, thisNormalMove;
core::array<scene::SSkinMeshBuffer*> &BuffersUsed=*SkinningBuffers; core::array<scene::SSkinMeshBuffer*> &buffersUsed=*SkinningBuffers;
//Skin Vertices Positions and Normals... //Skin Vertices Positions and Normals...
for (u32 i=0; i<Joint->Weights.size(); ++i) for (u32 i=0; i<joint->Weights.size(); ++i)
{ {
SWeight& weight = Joint->Weights[i]; SWeight& weight = joint->Weights[i];
// Pull this vertex... // Pull this vertex...
JointVertexPull.transformVect(ThisVertexMove, weight.StaticPos); jointVertexPull.transformVect(thisVertexMove, weight.StaticPos);
if (AnimateNormals) if (AnimateNormals)
JointVertexPull.rotateVect(ThisNormalMove, weight.StaticNormal); jointVertexPull.rotateVect(thisNormalMove, weight.StaticNormal);
if (! (*(weight.Moved)) ) if (! (*(weight.Moved)) )
{ {
*(weight.Moved) = true; *(weight.Moved) = true;
BuffersUsed[weight.buffer_id]->getVertex(weight.vertex_id)->Pos = ThisVertexMove * weight.strength; buffersUsed[weight.buffer_id]->getVertex(weight.vertex_id)->Pos = thisVertexMove * weight.strength;
if (AnimateNormals) if (AnimateNormals)
BuffersUsed[weight.buffer_id]->getVertex(weight.vertex_id)->Normal = ThisNormalMove * weight.strength; buffersUsed[weight.buffer_id]->getVertex(weight.vertex_id)->Normal = thisNormalMove * weight.strength;
//*(weight._Pos) = ThisVertexMove * weight.strength; //*(weight._Pos) = thisVertexMove * weight.strength;
} }
else else
{ {
BuffersUsed[weight.buffer_id]->getVertex(weight.vertex_id)->Pos += ThisVertexMove * weight.strength; buffersUsed[weight.buffer_id]->getVertex(weight.vertex_id)->Pos += thisVertexMove * weight.strength;
if (AnimateNormals) if (AnimateNormals)
BuffersUsed[weight.buffer_id]->getVertex(weight.vertex_id)->Normal += ThisNormalMove * weight.strength; buffersUsed[weight.buffer_id]->getVertex(weight.vertex_id)->Normal += thisNormalMove * weight.strength;
//*(weight._Pos) += ThisVertexMove * weight.strength; //*(weight._Pos) += thisVertexMove * weight.strength;
} }
} }
} }
//Skin all children //Skin all children
for (u32 j=0; j<Joint->Children.size(); ++j) for (u32 j=0; j<joint->Children.size(); ++j)
SkinJoint(Joint->Children[j], Joint); SkinJoint(joint->Children[j], joint);
} }
@ -624,7 +624,8 @@ bool CSkinnedMesh::useAnimationFrom(const ISkinnedMesh *mesh)
joint->UseAnimationFrom=otherJoint; joint->UseAnimationFrom=otherJoint;
} }
} }
if (!joint->UseAnimationFrom) unmatched=true; if (!joint->UseAnimationFrom)
unmatched=true;
} }
} }
@ -668,8 +669,6 @@ const core::array<CSkinnedMesh::SJoint*> &CSkinnedMesh::getAllJoints() const
} }
//! (This feature is not implementated in irrlicht yet) //! (This feature is not implementated in irrlicht yet)
bool CSkinnedMesh::setHardwareSkinning(bool on) bool CSkinnedMesh::setHardwareSkinning(bool on)
{ {
@ -682,13 +681,13 @@ bool CSkinnedMesh::setHardwareSkinning(bool on)
//set mesh to static pose... //set mesh to static pose...
for (u32 i=0; i<AllJoints.size(); ++i) for (u32 i=0; i<AllJoints.size(); ++i)
{ {
SJoint *Joint=AllJoints[i]; SJoint *joint=AllJoints[i];
for (u32 j=0; j<Joint->Weights.size(); ++j) for (u32 j=0; j<joint->Weights.size(); ++j)
{ {
const u16 buffer_id=Joint->Weights[j].buffer_id; const u16 buffer_id=joint->Weights[j].buffer_id;
const u32 vertex_id=Joint->Weights[j].vertex_id; const u32 vertex_id=joint->Weights[j].vertex_id;
LocalBuffers[buffer_id]->getVertex(vertex_id)->Pos = Joint->Weights[j].StaticPos; LocalBuffers[buffer_id]->getVertex(vertex_id)->Pos = joint->Weights[j].StaticPos;
LocalBuffers[buffer_id]->getVertex(vertex_id)->Normal = Joint->Weights[j].StaticNormal; LocalBuffers[buffer_id]->getVertex(vertex_id)->Normal = joint->Weights[j].StaticNormal;
} }
} }
@ -700,35 +699,36 @@ bool CSkinnedMesh::setHardwareSkinning(bool on)
return HardwareSkinning; return HardwareSkinning;
} }
void CSkinnedMesh::CalculateGlobalMatrixes(SJoint *Joint,SJoint *ParentJoint)
void CSkinnedMesh::CalculateGlobalMatrices(SJoint *joint,SJoint *parentJoint)
{ {
if (!Joint && ParentJoint) // bit of protection from endless loops if (!joint && parentJoint) // bit of protection from endless loops
return; return;
//Go through the root bones //Go through the root bones
if (!Joint) if (!joint)
{ {
for (u32 i=0; i<RootJoints.size(); ++i) for (u32 i=0; i<RootJoints.size(); ++i)
CalculateGlobalMatrixes(RootJoints[i],0); CalculateGlobalMatrices(RootJoints[i],0);
return; return;
} }
if (!ParentJoint) if (!parentJoint)
Joint->GlobalMatrix = Joint->LocalMatrix; joint->GlobalMatrix = joint->LocalMatrix;
else else
Joint->GlobalMatrix = ParentJoint->GlobalMatrix * Joint->LocalMatrix; joint->GlobalMatrix = parentJoint->GlobalMatrix * joint->LocalMatrix;
Joint->LocalAnimatedMatrix=Joint->LocalMatrix; joint->LocalAnimatedMatrix=joint->LocalMatrix;
Joint->GlobalAnimatedMatrix=Joint->GlobalMatrix; joint->GlobalAnimatedMatrix=joint->GlobalMatrix;
if (Joint->GlobalInversedMatrix.isIdentity())//might be pre calculated if (joint->GlobalInversedMatrix.isIdentity())//might be pre calculated
{ {
Joint->GlobalInversedMatrix = Joint->GlobalMatrix; joint->GlobalInversedMatrix = joint->GlobalMatrix;
Joint->GlobalInversedMatrix.makeInverse(); // slow joint->GlobalInversedMatrix.makeInverse(); // slow
} }
for (u32 j=0; j<Joint->Children.size(); ++j) for (u32 j=0; j<joint->Children.size(); ++j)
CalculateGlobalMatrixes(Joint->Children[j],Joint); CalculateGlobalMatrices(joint->Children[j],joint);
} }
@ -790,22 +790,22 @@ void CSkinnedMesh::checkForAnimation()
//check for bugs: //check for bugs:
for(i=0; i < AllJoints.size(); ++i) for(i=0; i < AllJoints.size(); ++i)
{ {
SJoint *Joint = AllJoints[i]; SJoint *joint = AllJoints[i];
for (j=0; j<Joint->Weights.size(); ++j) for (j=0; j<joint->Weights.size(); ++j)
{ {
const u16 buffer_id=Joint->Weights[j].buffer_id; const u16 buffer_id=joint->Weights[j].buffer_id;
const u32 vertex_id=Joint->Weights[j].vertex_id; const u32 vertex_id=joint->Weights[j].vertex_id;
//check for invalid ids //check for invalid ids
if (buffer_id>=LocalBuffers.size()) if (buffer_id>=LocalBuffers.size())
{ {
os::Printer::log("Skinned Mesh: Weight buffer id too large", ELL_WARNING); os::Printer::log("Skinned Mesh: Weight buffer id too large", ELL_WARNING);
Joint->Weights[j].buffer_id = Joint->Weights[j].vertex_id =0; joint->Weights[j].buffer_id = joint->Weights[j].vertex_id =0;
} }
else if (vertex_id>=LocalBuffers[buffer_id]->getVertexCount()) else if (vertex_id>=LocalBuffers[buffer_id]->getVertexCount())
{ {
os::Printer::log("Skinned Mesh: Weight vertex id too large", ELL_WARNING); os::Printer::log("Skinned Mesh: Weight vertex id too large", ELL_WARNING);
Joint->Weights[j].buffer_id = Joint->Weights[j].vertex_id =0; joint->Weights[j].buffer_id = joint->Weights[j].vertex_id =0;
} }
} }
} }
@ -820,17 +820,17 @@ void CSkinnedMesh::checkForAnimation()
for (i=0; i<AllJoints.size(); ++i) for (i=0; i<AllJoints.size(); ++i)
{ {
SJoint *Joint = AllJoints[i]; SJoint *joint = AllJoints[i];
for (j=0; j<Joint->Weights.size(); ++j) for (j=0; j<joint->Weights.size(); ++j)
{ {
const u16 buffer_id=Joint->Weights[j].buffer_id; const u16 buffer_id=joint->Weights[j].buffer_id;
const u32 vertex_id=Joint->Weights[j].vertex_id; const u32 vertex_id=joint->Weights[j].vertex_id;
Joint->Weights[j].Moved = &Vertices_Moved[buffer_id] [vertex_id]; joint->Weights[j].Moved = &Vertices_Moved[buffer_id] [vertex_id];
Joint->Weights[j].StaticPos = LocalBuffers[buffer_id]->getVertex(vertex_id)->Pos; joint->Weights[j].StaticPos = LocalBuffers[buffer_id]->getVertex(vertex_id)->Pos;
Joint->Weights[j].StaticNormal = LocalBuffers[buffer_id]->getVertex(vertex_id)->Normal; joint->Weights[j].StaticNormal = LocalBuffers[buffer_id]->getVertex(vertex_id)->Normal;
//Joint->Weights[j]._Pos=&Buffers[buffer_id]->getVertex(vertex_id)->Pos; //joint->Weights[j]._Pos=&Buffers[buffer_id]->getVertex(vertex_id)->Pos;
} }
} }
@ -845,8 +845,8 @@ void CSkinnedMesh::finalize()
{ {
u32 i; u32 i;
lastAnimatedFrame=-1; LastAnimatedFrame=-1;
lastSkinnedFrame=-1; LastSkinnedFrame=-1;
//calculate bounding box //calculate bounding box
@ -915,13 +915,10 @@ void CSkinnedMesh::finalize()
Vertices_Moved[i].set_used(LocalBuffers[i]->getVertexCount()); Vertices_Moved[i].set_used(LocalBuffers[i]->getVertexCount());
} }
//Todo: optimise keys here... //Todo: optimise keys here...
checkForAnimation(); checkForAnimation();
if (HasAnimation) if (HasAnimation)
{ {
//--- optimize and check keyframes --- //--- optimize and check keyframes ---
@ -1069,14 +1066,12 @@ void CSkinnedMesh::finalize()
//Needed for animation and skinning... //Needed for animation and skinning...
CalculateGlobalMatrixes(0,0); CalculateGlobalMatrices(0,0);
//animateMesh(0, 1); //animateMesh(0, 1);
//buildAll_LocalAnimatedMatrices(); //buildAll_LocalAnimatedMatrices();
//buildAll_GlobalAnimatedMatrices(); //buildAll_GlobalAnimatedMatrices();
//rigid animation for non animated meshes //rigid animation for non animated meshes
for (i=0; i<AllJoints.size(); ++i) for (i=0; i<AllJoints.size(); ++i)
{ {
@ -1120,13 +1115,9 @@ CSkinnedMesh::SPositionKey *CSkinnedMesh::createPositionKey(SJoint *joint)
{ {
if (!joint) if (!joint)
return 0; return 0;
SPositionKey *key;
joint->PositionKeys.push_back(SPositionKey()); joint->PositionKeys.push_back(SPositionKey());
key=&joint->PositionKeys.getLast(); return &joint->PositionKeys.getLast();
key->frame=0;
return key;
} }
@ -1134,12 +1125,9 @@ CSkinnedMesh::SScaleKey *CSkinnedMesh::createScaleKey(SJoint *joint)
{ {
if (!joint) if (!joint)
return 0; return 0;
SScaleKey *key;
joint->ScaleKeys.push_back(SScaleKey()); joint->ScaleKeys.push_back(SScaleKey());
key=&joint->ScaleKeys.getLast(); return &joint->ScaleKeys.getLast();
return key;
} }
@ -1147,12 +1135,9 @@ CSkinnedMesh::SRotationKey *CSkinnedMesh::createRotationKey(SJoint *joint)
{ {
if (!joint) if (!joint)
return 0; return 0;
SRotationKey *key;
joint->RotationKeys.push_back(SRotationKey()); joint->RotationKeys.push_back(SRotationKey());
key=&joint->RotationKeys.getLast(); return &joint->RotationKeys.getLast();
return key;
} }
@ -1162,25 +1147,16 @@ CSkinnedMesh::SWeight *CSkinnedMesh::createWeight(SJoint *joint)
return 0; return 0;
joint->Weights.push_back(SWeight()); joint->Weights.push_back(SWeight());
return &joint->Weights.getLast();
SWeight *weight=&joint->Weights.getLast();
//Could do stuff here...
return weight;
} }
bool CSkinnedMesh::isStatic() bool CSkinnedMesh::isStatic()
{ {
return !HasAnimation; return !HasAnimation;
} }
void CSkinnedMesh::normalizeWeights() void CSkinnedMesh::normalizeWeights()
{ {
// note: unsure if weights ids are going to be used. // note: unsure if weights ids are going to be used.
@ -1196,36 +1172,35 @@ void CSkinnedMesh::normalizeWeights()
Vertices_TotalWeight[i].set_used(LocalBuffers[i]->getVertexCount()); Vertices_TotalWeight[i].set_used(LocalBuffers[i]->getVertexCount());
} }
for (i=0; i<Vertices_TotalWeight.size(); ++i) for (i=0; i<Vertices_TotalWeight.size(); ++i)
for (j=0; j<Vertices_TotalWeight[i].size(); ++j) for (j=0; j<Vertices_TotalWeight[i].size(); ++j)
Vertices_TotalWeight[i][j] = 0; Vertices_TotalWeight[i][j] = 0;
for (i=0; i<AllJoints.size(); ++i) for (i=0; i<AllJoints.size(); ++i)
{ {
SJoint *Joint=AllJoints[i]; SJoint *joint=AllJoints[i];
for (j=0; j<Joint->Weights.size(); ++j) for (j=0; j<joint->Weights.size(); ++j)
{ {
if (Joint->Weights[j].strength<=0)//Check for invalid weights if (joint->Weights[j].strength<=0)//Check for invalid weights
{ {
Joint->Weights.erase(j); joint->Weights.erase(j);
j--; --j;
} }
else else
{ {
Vertices_TotalWeight[ Joint->Weights[j].buffer_id ] [ Joint->Weights[j].vertex_id ] += Joint->Weights[j].strength; Vertices_TotalWeight[ joint->Weights[j].buffer_id ] [ joint->Weights[j].vertex_id ] += joint->Weights[j].strength;
} }
} }
} }
for (i=0; i<AllJoints.size(); ++i) for (i=0; i<AllJoints.size(); ++i)
{ {
SJoint *Joint=AllJoints[i]; SJoint *joint=AllJoints[i];
for (j=0; j< Joint->Weights.size(); ++j) for (j=0; j< joint->Weights.size(); ++j)
{ {
f32 total = Vertices_TotalWeight[ Joint->Weights[j].buffer_id ] [ Joint->Weights[j].vertex_id ]; const f32 total = Vertices_TotalWeight[ joint->Weights[j].buffer_id ] [ joint->Weights[j].vertex_id ];
if (total != 0 && total != 1) if (total != 0 && total != 1)
Joint->Weights[j].strength /= total; joint->Weights[j].strength /= total;
} }
} }
} }
@ -1253,18 +1228,16 @@ void CSkinnedMesh::recoverJointsFromMesh(core::array<IBoneSceneNode*> &JointChil
} }
} }
void CSkinnedMesh::transferJointsToMesh(const core::array<IBoneSceneNode*> &JointChildSceneNodes) void CSkinnedMesh::transferJointsToMesh(const core::array<IBoneSceneNode*> &JointChildSceneNodes)
{ {
for (u32 i=0;i<AllJoints.size();++i) for (u32 i=0; i<AllJoints.size(); ++i)
{ {
IBoneSceneNode* node=JointChildSceneNodes[i]; const IBoneSceneNode* const node=JointChildSceneNodes[i];
SJoint *joint=AllJoints[i]; SJoint *joint=AllJoints[i];
joint->LocalAnimatedMatrix.setTranslation(node->getPosition());
joint->LocalAnimatedMatrix.setRotationDegrees(node->getRotation());
joint->LocalAnimatedMatrix.setTranslation( node->getPosition() );
joint->LocalAnimatedMatrix.setRotationDegrees( node->getRotation() );
//joint->LocalAnimatedMatrix.setScale( node->getScale() ); //joint->LocalAnimatedMatrix.setScale( node->getScale() );
@ -1278,17 +1251,16 @@ void CSkinnedMesh::transferJointsToMesh(const core::array<IBoneSceneNode*> &Join
joint->GlobalSkinningSpace=false; joint->GlobalSkinningSpace=false;
} }
//Remove cache, temp... //Remove cache, temp...
lastAnimatedFrame=-1; LastAnimatedFrame=-1;
lastSkinnedFrame=-1; LastSkinnedFrame=-1;
} }
void CSkinnedMesh::transferOnlyJointsHintsToMesh(const core::array<IBoneSceneNode*> &JointChildSceneNodes) void CSkinnedMesh::transferOnlyJointsHintsToMesh(const core::array<IBoneSceneNode*> &JointChildSceneNodes)
{ {
for (u32 i=0;i<AllJoints.size();++i) for (u32 i=0;i<AllJoints.size();++i)
{ {
IBoneSceneNode* node=JointChildSceneNodes[i]; const IBoneSceneNode* const node=JointChildSceneNodes[i];
SJoint *joint=AllJoints[i]; SJoint *joint=AllJoints[i];
joint->positionHint=node->positionHint; joint->positionHint=node->positionHint;
@ -1298,26 +1270,23 @@ void CSkinnedMesh::transferOnlyJointsHintsToMesh(const core::array<IBoneSceneNod
} }
void CSkinnedMesh::createJoints(core::array<IBoneSceneNode*> &JointChildSceneNodes, void CSkinnedMesh::createJoints(core::array<IBoneSceneNode*> &JointChildSceneNodes,
IAnimatedMeshSceneNode* AnimatedMeshSceneNode, ISceneManager* SceneManager) IAnimatedMeshSceneNode* AnimatedMeshSceneNode,
ISceneManager* SceneManager)
{ {
u32 i; u32 i;
//Create new joints //Create new joints
for (i=0;i<AllJoints.size();++i) for (i=0;i<AllJoints.size();++i)
{ {
IBoneSceneNode* node = new CBoneSceneNode(0, SceneManager, 0, i, AllJoints[i]->Name.c_str()); JointChildSceneNodes.push_back(new CBoneSceneNode(0, SceneManager, 0, i, AllJoints[i]->Name.c_str()));
JointChildSceneNodes.push_back(node);
} }
//Match up parents //Match up parents
for (i=0;i<JointChildSceneNodes.size();++i) for (i=0;i<JointChildSceneNodes.size();++i)
{ {
IBoneSceneNode* node=JointChildSceneNodes[i]; IBoneSceneNode* node=JointChildSceneNodes[i];
SJoint *joint=AllJoints[i]; //should be fine const SJoint* const joint=AllJoints[i]; //should be fine
s32 parentID=-1; s32 parentID=-1;
@ -1325,7 +1294,7 @@ void CSkinnedMesh::createJoints(core::array<IBoneSceneNode*> &JointChildSceneNod
{ {
if (i!=j && parentID==-1) if (i!=j && parentID==-1)
{ {
SJoint *parentTest=AllJoints[j]; const SJoint* const parentTest=AllJoints[j];
for (u32 n=0;n<parentTest->Children.size();++n) for (u32 n=0;n<parentTest->Children.size();++n)
{ {
if (parentTest->Children[n]==joint) if (parentTest->Children[n]==joint)
@ -1356,7 +1325,7 @@ void CSkinnedMesh::convertMeshToTangents()
{ {
LocalBuffers[b]->MoveTo_Tangents(); LocalBuffers[b]->MoveTo_Tangents();
s32 idxCnt = LocalBuffers[b]->getIndexCount(); const s32 idxCnt = LocalBuffers[b]->getIndexCount();
u16* idx = LocalBuffers[b]->getIndices(); u16* idx = LocalBuffers[b]->getIndices();
video::S3DVertexTangents* v = video::S3DVertexTangents* v =

View File

@ -112,9 +112,6 @@ namespace scene
//! (This feature is not implementated in irrlicht yet) //! (This feature is not implementated in irrlicht yet)
virtual bool setHardwareSkinning(bool on); virtual bool setHardwareSkinning(bool on);
//Interface for the mesh loaders (finalize should lock these functions, and they should have some prefix like loader_ //Interface for the mesh loaders (finalize should lock these functions, and they should have some prefix like loader_
//these functions will use the needed arrays, set vaules, etc to help the loaders //these functions will use the needed arrays, set vaules, etc to help the loaders
@ -131,21 +128,16 @@ namespace scene
//! loaders should call this after populating the mesh //! loaders should call this after populating the mesh
virtual void finalize(); virtual void finalize();
virtual SSkinMeshBuffer *createBuffer(); virtual SSkinMeshBuffer *createBuffer();
virtual SJoint *createJoint(SJoint *parent=0); virtual SJoint *createJoint(SJoint *parent=0);
virtual SPositionKey *createPositionKey(SJoint *joint); virtual SPositionKey *createPositionKey(SJoint *joint);
virtual SScaleKey *createScaleKey(SJoint *joint);
virtual SRotationKey *createRotationKey(SJoint *joint); virtual SRotationKey *createRotationKey(SJoint *joint);
virtual SScaleKey *createScaleKey(SJoint *joint);
virtual SWeight *createWeight(SJoint *joint); virtual SWeight *createWeight(SJoint *joint);
private: private:
void checkForAnimation(); void checkForAnimation();
@ -158,7 +150,7 @@ private:
void getFrameData(f32 frame,SJoint *Node,core::vector3df &position, s32 &positionHint, core::vector3df &scale, s32 &scaleHint, core::quaternion &rotation, s32 &rotationHint); void getFrameData(f32 frame,SJoint *Node,core::vector3df &position, s32 &positionHint, core::vector3df &scale, s32 &scaleHint, core::quaternion &rotation, s32 &rotationHint);
void CalculateGlobalMatrixes(SJoint *Joint,SJoint *ParentJoint); void CalculateGlobalMatrices(SJoint *Joint,SJoint *ParentJoint);
void SkinJoint(SJoint *Joint, SJoint *ParentJoint); void SkinJoint(SJoint *Joint, SJoint *ParentJoint);
@ -183,8 +175,8 @@ private:
f32 AnimationFrames; f32 AnimationFrames;
f32 lastAnimatedFrame; f32 LastAnimatedFrame;
f32 lastSkinnedFrame; f32 LastSkinnedFrame;
bool BoneControlUsed; bool BoneControlUsed;
bool AnimateNormals; bool AnimateNormals;