From d6a18858b299671b3d3dce140164ea84daf1159a Mon Sep 17 00:00:00 2001 From: hybrid Date: Sun, 9 Sep 2007 22:40:28 +0000 Subject: [PATCH] Fixed .x parser for missing whitespaces and delimiters. Some minor changes in other files. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@935 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/IAnimatedMeshMD3.h | 11 ++- source/Irrlicht/CAnimatedMeshSceneNode.cpp | 17 +---- source/Irrlicht/CSkinnedMesh.cpp | 83 +++++++++++----------- source/Irrlicht/CXMeshFileLoader.cpp | 33 ++++----- 4 files changed, 60 insertions(+), 84 deletions(-) diff --git a/include/IAnimatedMeshMD3.h b/include/IAnimatedMeshMD3.h index 1eb9afd7..8250f93f 100644 --- a/include/IAnimatedMeshMD3.h +++ b/include/IAnimatedMeshMD3.h @@ -186,21 +186,19 @@ namespace scene rotation.set ( angle * core::DEGTORAD ); } - core::stringc Name; - core::vector3df position; - core::quaternion rotation; - bool operator == ( const SMD3QuaterionTag &other ) const { return Name == other.Name; } + + core::stringc Name; + core::vector3df position; + core::quaternion rotation; }; // holds a assoziative list of named quaternions struct SMD3QuaterionTagList : public virtual IReferenceCounted { - ~SMD3QuaterionTagList() {} - SMD3QuaterionTag* get ( const core::stringc& name ) { SMD3QuaterionTag search ( name ); @@ -220,7 +218,6 @@ namespace scene return Container[index]; } - core::array < SMD3QuaterionTag > Container; }; diff --git a/source/Irrlicht/CAnimatedMeshSceneNode.cpp b/source/Irrlicht/CAnimatedMeshSceneNode.cpp index 7f6e1f1e..daa69ac9 100644 --- a/source/Irrlicht/CAnimatedMeshSceneNode.cpp +++ b/source/Irrlicht/CAnimatedMeshSceneNode.cpp @@ -571,11 +571,8 @@ IShadowVolumeSceneNode* CAnimatedMeshSceneNode::addShadowVolumeSceneNode(s32 id, } - - IBoneSceneNode* CAnimatedMeshSceneNode::getJointNode(const c8* jointName) { - if (!Mesh || Mesh->getMeshType() != EAMT_SKINNED) return 0; @@ -599,13 +596,11 @@ IBoneSceneNode* CAnimatedMeshSceneNode::getJointNode(const c8* jointName) } return getJointNode((u32)number); - } IBoneSceneNode* CAnimatedMeshSceneNode::getJointNode(u32 jointID) { - if (JointChildSceneNodes.size() <= jointID) { os::Printer::log("Joint not loaded into node", ELL_WARNING); @@ -613,20 +608,14 @@ IBoneSceneNode* CAnimatedMeshSceneNode::getJointNode(u32 jointID) } return JointChildSceneNodes[jointID]; - } - - //! Returns a pointer to a child node, which has the same transformation as //! the corrsesponding joint, if the mesh in this scene node is a ms3d mesh. ISceneNode* CAnimatedMeshSceneNode::getMS3DJointNode(const c8* jointName) { - return getJointNode(jointName); - - return 0; } @@ -635,12 +624,9 @@ ISceneNode* CAnimatedMeshSceneNode::getMS3DJointNode(const c8* jointName) ISceneNode* CAnimatedMeshSceneNode::getXJointNode(const c8* jointName) { return getJointNode(jointName); - - return 0; } - //! 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. @@ -657,7 +643,7 @@ bool CAnimatedMeshSceneNode::removeChild(ISceneNode* child) { if (ISceneNode::removeChild(child)) { - for (s32 i=0; i<(s32)JointChildSceneNodes.size(); ++i) + for (u32 i=0; idrop(); @@ -708,7 +694,6 @@ bool CAnimatedMeshSceneNode::setMD2Animation(const c8* animationName) } - //! Sets looping mode which is on by default. If set to false, //! animations will not be looped. void CAnimatedMeshSceneNode::setLoopMode(bool playAnimationLooped) diff --git a/source/Irrlicht/CSkinnedMesh.cpp b/source/Irrlicht/CSkinnedMesh.cpp index a6f6bfc1..5e8b9cf9 100644 --- a/source/Irrlicht/CSkinnedMesh.cpp +++ b/source/Irrlicht/CSkinnedMesh.cpp @@ -140,6 +140,7 @@ void CSkinnedMesh::animateMesh(f32 frame, f32 blend) BoneControlUsed=false; } + void CSkinnedMesh::buildAll_LocalAnimatedMatrices() { for (u32 i=0; iChildren[j], Joint); } + void CSkinnedMesh::getFrameData(f32 frame, SJoint *Joint, core::vector3df &position, s32 &positionHint, core::vector3df &scale, s32 &scaleHint, @@ -205,16 +207,16 @@ void CSkinnedMesh::getFrameData(f32 frame, SJoint *Joint, if (Joint->UseAnimationFrom) { - core::array &PositionKeys=Joint->UseAnimationFrom->PositionKeys; - core::array &ScaleKeys=Joint->UseAnimationFrom->ScaleKeys; - 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()) { foundPositionIndex = -1; //Test the Hints... - if (positionHint>0 && positionHint < (s32)PositionKeys.size() ) + if ((u32)positionHint < PositionKeys.size()) { //check this hint if (PositionKeys[positionHint].frame>=frame && PositionKeys[positionHint-1].frameframe; - f32 fd2 = KeyB->frame-frame; - position = ((KeyB->position-KeyA->position)/(fd1+fd2))*fd1 + KeyA->position; + const f32 fd1 = frame - KeyA.frame; + const f32 fd2 = KeyB.frame - frame; + position = ((KeyB.position-KeyA.position)/(fd1+fd2))*fd1 + KeyA.position; } } } @@ -271,7 +273,7 @@ void CSkinnedMesh::getFrameData(f32 frame, SJoint *Joint, foundScaleIndex = -1; //Test the Hints... - if (scaleHint>0 && scaleHint < (s32)ScaleKeys.size() ) + if ((u32)scaleHint < ScaleKeys.size()) { //check this hint if (ScaleKeys[scaleHint].frame>=frame && ScaleKeys[scaleHint-1].frameframe; - f32 fd2 = KeyB->frame-frame; - scale = ((KeyB->scale-KeyA->scale)/(fd1+fd2))*fd1 + KeyA->scale; + const f32 fd1 = frame - KeyA.frame; + const f32 fd2 = KeyB.frame - frame; + scale = ((KeyB.scale-KeyA.scale)/(fd1+fd2))*fd1 + KeyA.scale; } } } @@ -329,7 +331,7 @@ void CSkinnedMesh::getFrameData(f32 frame, SJoint *Joint, foundRotationIndex = -1; //Test the Hints... - if (rotationHint>0 && rotationHint < (s32)RotationKeys.size() ) + if ((u32)rotationHint < RotationKeys.size()) { //check this hint if (RotationKeys[rotationHint].frame>=frame && RotationKeys[rotationHint-1].frame= frame) //Keys should to be sorted by frame + if (RotationKeys[i].frame >= frame) //Keys should be sorted by frame { foundRotationIndex=i; rotationHint=i; @@ -370,26 +372,24 @@ void CSkinnedMesh::getFrameData(f32 frame, SJoint *Joint, } else if (InterpolationMode==EIM_LINEAR) { - SRotationKey *KeyA = &RotationKeys[foundRotationIndex]; - SRotationKey *KeyB = &RotationKeys[foundRotationIndex-1]; + const SRotationKey& KeyA = RotationKeys[foundRotationIndex]; + const SRotationKey& KeyB = RotationKeys[foundRotationIndex-1]; - f32 fd1 = frame-KeyA->frame; - f32 fd2 = KeyB->frame - frame; - f32 t = (1.0f/(fd1+fd2))*fd1; + const f32 fd1 = frame - KeyA.frame; + const f32 fd2 = KeyB.frame - frame; + const f32 t = fd1/(fd1+fd2); /* f32 t = 0; - if (KeyA->frame!=KeyB->frame) - t = (frame-KeyA->frame) / (KeyB->frame - KeyA->frame); + if (KeyA.frame!=KeyB.frame) + t = (frame-KeyA.frame) / (KeyB.frame - KeyA.frame); */ - rotation.slerp(KeyA->rotation, KeyB->rotation, t); - + rotation.slerp(KeyA.rotation, KeyB.rotation, t); } } } } - } //-------------------------------------------------------------------------- @@ -503,7 +503,7 @@ s32 CSkinnedMesh::getJointCount() const //! Gets the name of a joint. const c8* CSkinnedMesh::getJointName(s32 number) const { - if (number < 0 || number >= (s32)AllJoints.size()) + if ((u32)number >= AllJoints.size()) return 0; return AllJoints[number]->Name.c_str(); } @@ -512,7 +512,7 @@ const c8* CSkinnedMesh::getJointName(s32 number) const //! Gets a joint number from its name s32 CSkinnedMesh::getJointNumber(const c8* name) const { - for (s32 i=0; i<(s32)AllJoints.size(); ++i) + for (u32 i=0; iName == name) return i; @@ -638,7 +638,7 @@ void CSkinnedMesh::CalculateGlobalMatrixes(SJoint *Joint,SJoint *ParentJoint) if (!Joint && ParentJoint) // bit of protection from endless loops return; - //Go thought the root bones + //Go through the root bones if (!Joint) { for (u32 i=0; iWeights.size()) HasAnimation = true; + if (AllJoints[i]->Weights.size()) + HasAnimation = true; } } if (HasAnimation) { - //--- Find the length of the animation --- AnimationFrames=0; for(i=0;iWeights[j].buffer_id = Joint->Weights[j].vertex_id =0; } - } } @@ -764,7 +763,6 @@ void CSkinnedMesh::checkForAnimation() 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; } } @@ -778,7 +776,7 @@ void CSkinnedMesh::checkForAnimation() //! called by loader after populating with mesh and bone data void CSkinnedMesh::finalize() { - u32 i=0,j=0; + u32 i; lastAnimatedFrame=-1; lastSkinnedFrame=-1; @@ -870,7 +868,7 @@ void CSkinnedMesh::finalize() if (PositionKeys.size()>2) { - for(j=0;j1) { - for(j=0;j= PositionKeys[j+1].frame) //bad frame, unneed and may cause problems { @@ -894,7 +892,7 @@ void CSkinnedMesh::finalize() if (ScaleKeys.size()>2) { - for(j=0;j1) { - for(j=0;j= ScaleKeys[j+1].frame) //bad frame, unneed and may cause problems { @@ -918,7 +916,7 @@ void CSkinnedMesh::finalize() if (RotationKeys.size()>2) { - for(j=0;j1) { - for(j=0;j= RotationKeys[j+1].frame) //bad frame, unneed and may cause problems { @@ -1033,7 +1031,7 @@ CSkinnedMesh::SJoint *CSkinnedMesh::createJoint(SJoint *parent) } else { - //Set parent (Be careful of the mesh loader also setting the parent) + //Set parent (Be careful of the mesh loader also setting the parent) parent->Children.push_back(joint); } @@ -1236,6 +1234,7 @@ void CSkinnedMesh::createJoints(core::array &JointChildSceneNod } } + void CSkinnedMesh::convertMeshToTangents() { // now calculate tangents diff --git a/source/Irrlicht/CXMeshFileLoader.cpp b/source/Irrlicht/CXMeshFileLoader.cpp index 7782818a..f770059d 100644 --- a/source/Irrlicht/CXMeshFileLoader.cpp +++ b/source/Irrlicht/CXMeshFileLoader.cpp @@ -370,7 +370,6 @@ bool CXMeshFileLoader::parseDataObject() else if (objectName == "Frame") { - return parseDataObjectFrame( 0 ); } else @@ -531,19 +530,12 @@ bool CXMeshFileLoader::parseDataObjectFrame( CSkinnedMesh::SJoint *Parent ) else if (objectName == "FrameTransformMatrix") { - //if (!parseDataObjectTransformationMatrix(joint->LocalMatrix)) - if (!parseDataObjectTransformationMatrix(joint->LocalMatrix)) return false; //joint->LocalAnimatedMatrix - - //joint->LocalAnimatedMatrix.makeInverse(); - //joint->LocalMatrix=tmp*joint->LocalAnimatedMatrix; - - } else if (objectName == "Mesh") @@ -566,7 +558,6 @@ bool CXMeshFileLoader::parseDataObjectFrame( CSkinnedMesh::SJoint *Parent ) if (!parseUnknownDataObject()) return false; } - } return true; @@ -1996,19 +1987,23 @@ core::stringc CXMeshFileLoader::getNextToken() if (P >= End) return s; - - char last=0; - - //&& last!=';' && last!='}' && last!='{' && last!=',' - - while(P < End && !core::isspace(P[0]) ) //Luke:Not only space? + while((P < End) && !core::isspace(P[0])) { - last=P[0]; - + // either keep token delimiters when already holding a token, or return if first valid char + if (P[0]==';' || P[0]=='}' || P[0]=='{' || P[0]==',') + { + if (!s.size()) + { + s.append(P[0]); + ++P; + } + break; // stop for delimiter + } s.append(P[0]); ++P; } } +os::Printer::log(s.c_str()); return s; } @@ -2046,7 +2041,7 @@ void CXMeshFileLoader::findNextNoneWhiteSpace() while(true) { - while(P < End && (P[0]==' ' || P[0]=='\n' || P[0]=='\r' || P[0]=='\t')) + while((P < End) && core::isspace(P[0])) ++P; if (P >= End) @@ -2100,7 +2095,7 @@ void CXMeshFileLoader::readUntilEndOfLine() while(P < End) { - if (P[0] == '\n') + if (P[0] == '\n' || P[0] == '\r') { ++P; return;