From 83cda72c662a13d9a103b718efe83d42f320716e Mon Sep 17 00:00:00 2001 From: hybrid Date: Tue, 12 Feb 2008 15:31:35 +0000 Subject: [PATCH] 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 --- include/IBoneSceneNode.h | 6 +- source/Irrlicht/CBoneSceneNode.cpp | 18 +- source/Irrlicht/CBoneSceneNode.h | 16 +- source/Irrlicht/CNullDriver.cpp | 4 +- source/Irrlicht/CSkinnedMesh.cpp | 321 +++++++++++++---------------- source/Irrlicht/CSkinnedMesh.h | 16 +- 6 files changed, 162 insertions(+), 219 deletions(-) diff --git a/include/IBoneSceneNode.h b/include/IBoneSceneNode.h index f840e1c3..1116432b 100644 --- a/include/IBoneSceneNode.h +++ b/include/IBoneSceneNode.h @@ -54,7 +54,7 @@ namespace scene public: 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 virtual const c8* getBoneName() const = 0; @@ -83,13 +83,11 @@ namespace scene virtual void setSkinningSpace( E_BONE_SKINNING_SPACE space ) =0; //! 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 virtual void updateAbsolutePositionOfAllChildren()=0; - - s32 positionHint; s32 scaleHint; s32 rotationHint; diff --git a/source/Irrlicht/CBoneSceneNode.cpp b/source/Irrlicht/CBoneSceneNode.cpp index 44fa61c1..37391271 100644 --- a/source/Irrlicht/CBoneSceneNode.cpp +++ b/source/Irrlicht/CBoneSceneNode.cpp @@ -1,8 +1,5 @@ - #include "CBoneSceneNode.h" - - namespace irr { namespace scene @@ -17,11 +14,6 @@ CBoneSceneNode::CBoneSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id, } -//! destructor -CBoneSceneNode::~CBoneSceneNode() -{ - -} //! Returns the name of the bone const c8* CBoneSceneNode::getBoneName() const @@ -82,8 +74,6 @@ void CBoneSceneNode::OnAnimate(u32 timeMs) } - - void CBoneSceneNode::helper_updateAbsolutePositionOfAllChildren(ISceneNode *Node) { Node->updateAbsolutePosition(); @@ -102,9 +92,6 @@ void CBoneSceneNode::updateAbsolutePositionOfAllChildren() } - - - void CBoneSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const { out->addInt("BoneIndex", BoneIndex); @@ -112,13 +99,16 @@ void CBoneSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeRea out->addEnum("AnimationMode", AnimationMode, BoneAnimationModeNames); } + void CBoneSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) { BoneIndex = in->getAttributeAsInt("BoneIndex"); BoneName = in->getAttributeAsString("BoneName"); 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 irr + diff --git a/source/Irrlicht/CBoneSceneNode.h b/source/Irrlicht/CBoneSceneNode.h index 6d6bbb5a..5a6ed18a 100644 --- a/source/Irrlicht/CBoneSceneNode.h +++ b/source/Irrlicht/CBoneSceneNode.h @@ -20,9 +20,6 @@ namespace scene CBoneSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id=-1, u32 boneIndex=0, const c8* boneName=0); - //! destructor - ~CBoneSceneNode(); - //! Returns the name of the bone virtual const c8* getBoneName() const; @@ -38,14 +35,13 @@ namespace scene //! returns the axis aligned bounding box of this node virtual const core::aabbox3d& getBoundingBox() const; + /* //! Returns the relative transformation of the scene node. //virtual core::matrix4 getRelativeTransformation() const; + */ virtual void OnAnimate(u32 timeMs); - - void helper_updateAbsolutePositionOfAllChildren(ISceneNode *Node); - virtual void updateAbsolutePositionOfAllChildren(); //! Writes attributes of the scene node. @@ -60,22 +56,20 @@ namespace scene SkinningSpace=space; } - virtual E_BONE_SKINNING_SPACE getSkinningSpace() + virtual E_BONE_SKINNING_SPACE getSkinningSpace() const { return SkinningSpace; } private: + void helper_updateAbsolutePositionOfAllChildren(ISceneNode *Node); + E_BONE_ANIMATION_MODE AnimationMode; E_BONE_SKINNING_SPACE SkinningSpace; u32 BoneIndex; core::stringc BoneName; - - - - core::aabbox3d Box; }; diff --git a/source/Irrlicht/CNullDriver.cpp b/source/Irrlicht/CNullDriver.cpp index 5313b1a9..ad1c8101 100644 --- a/source/Irrlicht/CNullDriver.cpp +++ b/source/Irrlicht/CNullDriver.cpp @@ -1500,13 +1500,14 @@ E_DRIVER_TYPE CNullDriver::getDriverType() const void CNullDriver::deleteMaterialRenders() { // delete material renderers - for (int i=0; i<(int)MaterialRenderers.size(); ++i) + for (u32 i=0; idrop(); MaterialRenderers.clear(); } + //! Returns pointer to material renderer or null IMaterialRenderer* CNullDriver::getMaterialRenderer(u32 idx) { @@ -1517,7 +1518,6 @@ IMaterialRenderer* CNullDriver::getMaterialRenderer(u32 idx) } - //! Returns amount of currently available material renderers. u32 CNullDriver::getMaterialRendererCount() const { diff --git a/source/Irrlicht/CSkinnedMesh.cpp b/source/Irrlicht/CSkinnedMesh.cpp index cd2fd3dd..5b668321 100644 --- a/source/Irrlicht/CSkinnedMesh.cpp +++ b/source/Irrlicht/CSkinnedMesh.cpp @@ -19,7 +19,7 @@ namespace scene //! constructor CSkinnedMesh::CSkinnedMesh() : 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) { #ifdef _DEBUG @@ -76,10 +76,10 @@ IMesh* CSkinnedMesh::getMesh(s32 frame, s32 detailLevel, s32 startFrameLoop, s32 //! blend: {0-old position, 1-New position} void CSkinnedMesh::animateMesh(f32 frame, f32 blend) { - if ( !HasAnimation || lastAnimatedFrame==frame) + if ( !HasAnimation || LastAnimatedFrame==frame) return; - lastAnimatedFrame=frame; + LastAnimatedFrame=frame; if (blend<=0.f) return; //No need to animate @@ -87,34 +87,34 @@ void CSkinnedMesh::animateMesh(f32 frame, f32 blend) for (u32 i=0; iAnimatedposition; - const core::vector3df oldScale = Joint->Animatedscale; - const core::quaternion oldRotation = Joint->Animatedrotation; + const core::vector3df oldPosition = joint->Animatedposition; + const core::vector3df oldScale = joint->Animatedscale; + const core::quaternion oldRotation = joint->Animatedrotation; core::vector3df position = oldPosition; core::vector3df scale = oldScale; core::quaternion rotation = oldRotation; - getFrameData(frame, Joint, - position, Joint->positionHint, - scale, Joint->scaleHint, - rotation, Joint->rotationHint); + getFrameData(frame, joint, + position, joint->positionHint, + scale, joint->scaleHint, + rotation, joint->rotationHint); if (blend==1.0f) { //No blending needed - Joint->Animatedposition = position; - Joint->Animatedscale = scale; - Joint->Animatedrotation = rotation; + joint->Animatedposition = position; + joint->Animatedscale = scale; + joint->Animatedrotation = rotation; } else { //Blend animation - Joint->Animatedposition = core::lerp(oldPosition, position, blend); - Joint->Animatedscale = core::lerp(oldScale, scale, blend); - Joint->Animatedrotation.slerp(oldRotation, rotation, blend); + joint->Animatedposition = core::lerp(oldPosition, position, blend); + joint->Animatedscale = core::lerp(oldScale, scale, blend); + joint->Animatedrotation.slerp(oldRotation, rotation, blend); } //Note: @@ -134,20 +134,20 @@ void CSkinnedMesh::buildAll_LocalAnimatedMatrices() { for (u32 i=0; iUseAnimationFrom && - (Joint->UseAnimationFrom->PositionKeys.size() || - Joint->UseAnimationFrom->ScaleKeys.size() || - Joint->UseAnimationFrom->RotationKeys.size() )) + if (joint->UseAnimationFrom && + (joint->UseAnimationFrom->PositionKeys.size() || + joint->UseAnimationFrom->ScaleKeys.size() || + joint->UseAnimationFrom->RotationKeys.size() )) { - Joint->LocalAnimatedMatrix=Joint->Animatedrotation.getMatrix(); + joint->LocalAnimatedMatrix=joint->Animatedrotation.getMatrix(); - // --- Joint->LocalAnimatedMatrix *= Joint->Animatedrotation.getMatrix() --- - f32 *m1 = Joint->LocalAnimatedMatrix.pointer(); - core::vector3df &Pos = Joint->Animatedposition; + // --- joint->LocalAnimatedMatrix *= joint->Animatedrotation.getMatrix() --- + f32 *m1 = joint->LocalAnimatedMatrix.pointer(); + core::vector3df &Pos = joint->Animatedposition; m1[0] += Pos.X*m1[3]; m1[1] += Pos.Y*m1[3]; m1[2] += Pos.Z*m1[3]; @@ -162,46 +162,46 @@ void CSkinnedMesh::buildAll_LocalAnimatedMatrices() m1[14] += Pos.Z*m1[15]; // ----------------------------------- - Joint->GlobalSkinningSpace=false; + joint->GlobalSkinningSpace=false; - if (Joint->ScaleKeys.size()) + if (joint->ScaleKeys.size()) { /* core::matrix4 scaleMatrix; - scaleMatrix.setScale(Joint->Animatedscale); - Joint->LocalAnimatedMatrix *= scaleMatrix; + scaleMatrix.setScale(joint->Animatedscale); + joint->LocalAnimatedMatrix *= scaleMatrix; */ - // -------- Joint->LocalAnimatedMatrix *= scaleMatrix ----------------- - f32 *m1 = Joint->LocalAnimatedMatrix.pointer(); - m1[0] *= Joint->Animatedscale.X; - m1[1] *= Joint->Animatedscale.X; - m1[2] *= Joint->Animatedscale.X; - m1[3] *= Joint->Animatedscale.X; - m1[4] *= Joint->Animatedscale.Y; - m1[5] *= Joint->Animatedscale.Y; - m1[6] *= Joint->Animatedscale.Y; - m1[7] *= Joint->Animatedscale.Y; - m1[8] *= Joint->Animatedscale.Z; - m1[9] *= Joint->Animatedscale.Z; - m1[10] *= Joint->Animatedscale.Z; - m1[11] *= Joint->Animatedscale.Z; - m1[12] *= Joint->Animatedscale.X; + // -------- joint->LocalAnimatedMatrix *= scaleMatrix ----------------- + f32 *m1 = joint->LocalAnimatedMatrix.pointer(); + m1[0] *= joint->Animatedscale.X; + m1[1] *= joint->Animatedscale.X; + m1[2] *= joint->Animatedscale.X; + m1[3] *= joint->Animatedscale.X; + m1[4] *= joint->Animatedscale.Y; + m1[5] *= joint->Animatedscale.Y; + m1[6] *= joint->Animatedscale.Y; + m1[7] *= joint->Animatedscale.Y; + m1[8] *= joint->Animatedscale.Z; + m1[9] *= joint->Animatedscale.Z; + m1[10] *= joint->Animatedscale.Z; + m1[11] *= joint->Animatedscale.Z; + m1[12] *= joint->Animatedscale.X; // ----------------------------------- } } 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; iGlobalSkinningSpace) - Joint->GlobalAnimatedMatrix = Joint->LocalAnimatedMatrix; + if (!parentJoint || joint->GlobalSkinningSpace) + joint->GlobalAnimatedMatrix = joint->LocalAnimatedMatrix; else - Joint->GlobalAnimatedMatrix = ParentJoint->GlobalAnimatedMatrix * Joint->LocalAnimatedMatrix; + joint->GlobalAnimatedMatrix = parentJoint->GlobalAnimatedMatrix * joint->LocalAnimatedMatrix; } - for (u32 j=0; jChildren.size(); ++j) - buildAll_GlobalAnimatedMatrices(Joint->Children[j], Joint); + for (u32 j=0; jChildren.size(); ++j) + 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 &scale, s32 &scaleHint, core::quaternion &rotation, s32 &rotationHint) @@ -231,11 +231,11 @@ void CSkinnedMesh::getFrameData(f32 frame, SJoint *Joint, s32 foundScaleIndex = -1; s32 foundRotationIndex = -1; - if (Joint->UseAnimationFrom) + if (joint->UseAnimationFrom) { - const core::array &PositionKeys=Joint->UseAnimationFrom->PositionKeys; - const core::array &ScaleKeys=Joint->UseAnimationFrom->ScaleKeys; - const core::array &RotationKeys=Joint->UseAnimationFrom->RotationKeys; + const core::array &PositionKeys=joint->UseAnimationFrom->PositionKeys; + const core::array &ScaleKeys=joint->UseAnimationFrom->ScaleKeys; + const core::array &RotationKeys=joint->UseAnimationFrom->RotationKeys; 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... - core::matrix4 JointVertexPull(core::matrix4::EM4CONST_NOTHING); - JointVertexPull.setbyproduct(Joint->GlobalAnimatedMatrix, Joint->GlobalInversedMatrix); + core::matrix4 jointVertexPull(core::matrix4::EM4CONST_NOTHING); + jointVertexPull.setbyproduct(joint->GlobalAnimatedMatrix, joint->GlobalInversedMatrix); - core::vector3df ThisVertexMove, ThisNormalMove; + core::vector3df thisVertexMove, thisNormalMove; - core::array &BuffersUsed=*SkinningBuffers; + core::array &buffersUsed=*SkinningBuffers; //Skin Vertices Positions and Normals... - for (u32 i=0; iWeights.size(); ++i) + for (u32 i=0; iWeights.size(); ++i) { - SWeight& weight = Joint->Weights[i]; + SWeight& weight = joint->Weights[i]; // Pull this vertex... - JointVertexPull.transformVect(ThisVertexMove, weight.StaticPos); + jointVertexPull.transformVect(thisVertexMove, weight.StaticPos); if (AnimateNormals) - JointVertexPull.rotateVect(ThisNormalMove, weight.StaticNormal); + jointVertexPull.rotateVect(thisNormalMove, weight.StaticNormal); if (! (*(weight.Moved)) ) { *(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) - 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 { - 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) - 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 - for (u32 j=0; jChildren.size(); ++j) - SkinJoint(Joint->Children[j], Joint); + for (u32 j=0; jChildren.size(); ++j) + SkinJoint(joint->Children[j], joint); } @@ -624,7 +624,8 @@ bool CSkinnedMesh::useAnimationFrom(const ISkinnedMesh *mesh) joint->UseAnimationFrom=otherJoint; } } - if (!joint->UseAnimationFrom) unmatched=true; + if (!joint->UseAnimationFrom) + unmatched=true; } } @@ -668,8 +669,6 @@ const core::array &CSkinnedMesh::getAllJoints() const } - - //! (This feature is not implementated in irrlicht yet) bool CSkinnedMesh::setHardwareSkinning(bool on) { @@ -682,13 +681,13 @@ bool CSkinnedMesh::setHardwareSkinning(bool on) //set mesh to static pose... for (u32 i=0; iWeights.size(); ++j) + SJoint *joint=AllJoints[i]; + for (u32 j=0; jWeights.size(); ++j) { - const u16 buffer_id=Joint->Weights[j].buffer_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)->Normal = Joint->Weights[j].StaticNormal; + const u16 buffer_id=joint->Weights[j].buffer_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)->Normal = joint->Weights[j].StaticNormal; } } @@ -700,35 +699,36 @@ bool CSkinnedMesh::setHardwareSkinning(bool on) 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; //Go through the root bones - if (!Joint) + if (!joint) { for (u32 i=0; iGlobalMatrix = Joint->LocalMatrix; + if (!parentJoint) + joint->GlobalMatrix = joint->LocalMatrix; else - Joint->GlobalMatrix = ParentJoint->GlobalMatrix * Joint->LocalMatrix; + joint->GlobalMatrix = parentJoint->GlobalMatrix * joint->LocalMatrix; - Joint->LocalAnimatedMatrix=Joint->LocalMatrix; - Joint->GlobalAnimatedMatrix=Joint->GlobalMatrix; + joint->LocalAnimatedMatrix=joint->LocalMatrix; + 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.makeInverse(); // slow + joint->GlobalInversedMatrix = joint->GlobalMatrix; + joint->GlobalInversedMatrix.makeInverse(); // slow } - for (u32 j=0; jChildren.size(); ++j) - CalculateGlobalMatrixes(Joint->Children[j],Joint); + for (u32 j=0; jChildren.size(); ++j) + CalculateGlobalMatrices(joint->Children[j],joint); } @@ -790,22 +790,22 @@ void CSkinnedMesh::checkForAnimation() //check for bugs: for(i=0; i < AllJoints.size(); ++i) { - SJoint *Joint = AllJoints[i]; - for (j=0; jWeights.size(); ++j) + SJoint *joint = AllJoints[i]; + for (j=0; jWeights.size(); ++j) { - const u16 buffer_id=Joint->Weights[j].buffer_id; - const u32 vertex_id=Joint->Weights[j].vertex_id; + const u16 buffer_id=joint->Weights[j].buffer_id; + const u32 vertex_id=joint->Weights[j].vertex_id; //check for invalid ids if (buffer_id>=LocalBuffers.size()) { 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()) { 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; iWeights.size(); ++j) + SJoint *joint = AllJoints[i]; + for (j=0; jWeights.size(); ++j) { - const u16 buffer_id=Joint->Weights[j].buffer_id; - const u32 vertex_id=Joint->Weights[j].vertex_id; + const u16 buffer_id=joint->Weights[j].buffer_id; + const u32 vertex_id=joint->Weights[j].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].StaticNormal = LocalBuffers[buffer_id]->getVertex(vertex_id)->Normal; + joint->Weights[j].Moved = &Vertices_Moved[buffer_id] [vertex_id]; + 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]._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; - lastAnimatedFrame=-1; - lastSkinnedFrame=-1; + LastAnimatedFrame=-1; + LastSkinnedFrame=-1; //calculate bounding box @@ -915,13 +915,10 @@ void CSkinnedMesh::finalize() Vertices_Moved[i].set_used(LocalBuffers[i]->getVertexCount()); } - //Todo: optimise keys here... - checkForAnimation(); - if (HasAnimation) { //--- optimize and check keyframes --- @@ -1069,14 +1066,12 @@ void CSkinnedMesh::finalize() //Needed for animation and skinning... - CalculateGlobalMatrixes(0,0); + CalculateGlobalMatrices(0,0); //animateMesh(0, 1); //buildAll_LocalAnimatedMatrices(); //buildAll_GlobalAnimatedMatrices(); - - //rigid animation for non animated meshes for (i=0; iPositionKeys.push_back(SPositionKey()); - key=&joint->PositionKeys.getLast(); - - key->frame=0; - return key; + return &joint->PositionKeys.getLast(); } @@ -1134,12 +1125,9 @@ CSkinnedMesh::SScaleKey *CSkinnedMesh::createScaleKey(SJoint *joint) { if (!joint) return 0; - SScaleKey *key; joint->ScaleKeys.push_back(SScaleKey()); - key=&joint->ScaleKeys.getLast(); - - return key; + return &joint->ScaleKeys.getLast(); } @@ -1147,12 +1135,9 @@ CSkinnedMesh::SRotationKey *CSkinnedMesh::createRotationKey(SJoint *joint) { if (!joint) return 0; - SRotationKey *key; joint->RotationKeys.push_back(SRotationKey()); - key=&joint->RotationKeys.getLast(); - - return key; + return &joint->RotationKeys.getLast(); } @@ -1162,25 +1147,16 @@ CSkinnedMesh::SWeight *CSkinnedMesh::createWeight(SJoint *joint) return 0; joint->Weights.push_back(SWeight()); - - SWeight *weight=&joint->Weights.getLast(); - - //Could do stuff here... - - return weight; + return &joint->Weights.getLast(); } - - bool CSkinnedMesh::isStatic() { return !HasAnimation; } - - void CSkinnedMesh::normalizeWeights() { // 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()); } - for (i=0; iWeights.size(); ++j) + SJoint *joint=AllJoints[i]; + for (j=0; jWeights.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); - j--; + joint->Weights.erase(j); + --j; } 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; iWeights.size(); ++j) + SJoint *joint=AllJoints[i]; + 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) - Joint->Weights[j].strength /= total; + joint->Weights[j].strength /= total; } } } @@ -1253,18 +1228,16 @@ void CSkinnedMesh::recoverJointsFromMesh(core::array &JointChil } } + void CSkinnedMesh::transferJointsToMesh(const core::array &JointChildSceneNodes) { - for (u32 i=0;iLocalAnimatedMatrix.setTranslation( node->getPosition() ); - joint->LocalAnimatedMatrix.setRotationDegrees( node->getRotation() ); - + joint->LocalAnimatedMatrix.setTranslation(node->getPosition()); + joint->LocalAnimatedMatrix.setRotationDegrees(node->getRotation()); //joint->LocalAnimatedMatrix.setScale( node->getScale() ); @@ -1278,17 +1251,16 @@ void CSkinnedMesh::transferJointsToMesh(const core::array &Join joint->GlobalSkinningSpace=false; } //Remove cache, temp... - lastAnimatedFrame=-1; - lastSkinnedFrame=-1; - - + LastAnimatedFrame=-1; + LastSkinnedFrame=-1; } + void CSkinnedMesh::transferOnlyJointsHintsToMesh(const core::array &JointChildSceneNodes) { for (u32 i=0;ipositionHint=node->positionHint; @@ -1298,26 +1270,23 @@ void CSkinnedMesh::transferOnlyJointsHintsToMesh(const core::array &JointChildSceneNodes, - IAnimatedMeshSceneNode* AnimatedMeshSceneNode, ISceneManager* SceneManager) + IAnimatedMeshSceneNode* AnimatedMeshSceneNode, + ISceneManager* SceneManager) { u32 i; //Create new joints for (i=0;iName.c_str()); - - JointChildSceneNodes.push_back(node); + JointChildSceneNodes.push_back(new CBoneSceneNode(0, SceneManager, 0, i, AllJoints[i]->Name.c_str())); } //Match up parents for (i=0;i &JointChildSceneNod { if (i!=j && parentID==-1) { - SJoint *parentTest=AllJoints[j]; + const SJoint* const parentTest=AllJoints[j]; for (u32 n=0;nChildren.size();++n) { if (parentTest->Children[n]==joint) @@ -1356,7 +1325,7 @@ void CSkinnedMesh::convertMeshToTangents() { LocalBuffers[b]->MoveTo_Tangents(); - s32 idxCnt = LocalBuffers[b]->getIndexCount(); + const s32 idxCnt = LocalBuffers[b]->getIndexCount(); u16* idx = LocalBuffers[b]->getIndices(); video::S3DVertexTangents* v = diff --git a/source/Irrlicht/CSkinnedMesh.h b/source/Irrlicht/CSkinnedMesh.h index 74819061..68119110 100644 --- a/source/Irrlicht/CSkinnedMesh.h +++ b/source/Irrlicht/CSkinnedMesh.h @@ -112,9 +112,6 @@ namespace scene //! (This feature is not implementated in irrlicht yet) virtual bool setHardwareSkinning(bool on); - - - //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 @@ -131,21 +128,16 @@ namespace scene //! loaders should call this after populating the mesh virtual void finalize(); - virtual SSkinMeshBuffer *createBuffer(); virtual SJoint *createJoint(SJoint *parent=0); virtual SPositionKey *createPositionKey(SJoint *joint); - virtual SScaleKey *createScaleKey(SJoint *joint); virtual SRotationKey *createRotationKey(SJoint *joint); + virtual SScaleKey *createScaleKey(SJoint *joint); virtual SWeight *createWeight(SJoint *joint); - - - - private: 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 CalculateGlobalMatrixes(SJoint *Joint,SJoint *ParentJoint); + void CalculateGlobalMatrices(SJoint *Joint,SJoint *ParentJoint); void SkinJoint(SJoint *Joint, SJoint *ParentJoint); @@ -183,8 +175,8 @@ private: f32 AnimationFrames; - f32 lastAnimatedFrame; - f32 lastSkinnedFrame; + f32 LastAnimatedFrame; + f32 LastSkinnedFrame; bool BoneControlUsed; bool AnimateNormals;