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
master
hybrid 2007-09-09 22:40:28 +00:00
parent 9b7603025a
commit d6a18858b2
4 changed files with 60 additions and 84 deletions

View File

@ -186,21 +186,19 @@ namespace scene
rotation.set ( angle * core::DEGTORAD ); rotation.set ( angle * core::DEGTORAD );
} }
core::stringc Name;
core::vector3df position;
core::quaternion rotation;
bool operator == ( const SMD3QuaterionTag &other ) const bool operator == ( const SMD3QuaterionTag &other ) const
{ {
return Name == other.Name; return Name == other.Name;
} }
core::stringc Name;
core::vector3df position;
core::quaternion rotation;
}; };
// holds a assoziative list of named quaternions // holds a assoziative list of named quaternions
struct SMD3QuaterionTagList : public virtual IReferenceCounted struct SMD3QuaterionTagList : public virtual IReferenceCounted
{ {
~SMD3QuaterionTagList() {}
SMD3QuaterionTag* get ( const core::stringc& name ) SMD3QuaterionTag* get ( const core::stringc& name )
{ {
SMD3QuaterionTag search ( name ); SMD3QuaterionTag search ( name );
@ -220,7 +218,6 @@ namespace scene
return Container[index]; return Container[index];
} }
core::array < SMD3QuaterionTag > Container; core::array < SMD3QuaterionTag > Container;
}; };

View File

@ -571,11 +571,8 @@ IShadowVolumeSceneNode* CAnimatedMeshSceneNode::addShadowVolumeSceneNode(s32 id,
} }
IBoneSceneNode* CAnimatedMeshSceneNode::getJointNode(const c8* jointName) IBoneSceneNode* CAnimatedMeshSceneNode::getJointNode(const c8* jointName)
{ {
if (!Mesh || Mesh->getMeshType() != EAMT_SKINNED) if (!Mesh || Mesh->getMeshType() != EAMT_SKINNED)
return 0; return 0;
@ -599,13 +596,11 @@ IBoneSceneNode* CAnimatedMeshSceneNode::getJointNode(const c8* jointName)
} }
return getJointNode((u32)number); return getJointNode((u32)number);
} }
IBoneSceneNode* CAnimatedMeshSceneNode::getJointNode(u32 jointID) IBoneSceneNode* CAnimatedMeshSceneNode::getJointNode(u32 jointID)
{ {
if (JointChildSceneNodes.size() <= jointID) if (JointChildSceneNodes.size() <= jointID)
{ {
os::Printer::log("Joint not loaded into node", ELL_WARNING); os::Printer::log("Joint not loaded into node", ELL_WARNING);
@ -613,20 +608,14 @@ IBoneSceneNode* CAnimatedMeshSceneNode::getJointNode(u32 jointID)
} }
return JointChildSceneNodes[jointID]; return JointChildSceneNodes[jointID];
} }
//! Returns a pointer to a child node, which has the same transformation as //! 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. //! the corrsesponding joint, if the mesh in this scene node is a ms3d mesh.
ISceneNode* CAnimatedMeshSceneNode::getMS3DJointNode(const c8* jointName) ISceneNode* CAnimatedMeshSceneNode::getMS3DJointNode(const c8* jointName)
{ {
return getJointNode(jointName); return getJointNode(jointName);
return 0;
} }
@ -635,12 +624,9 @@ ISceneNode* CAnimatedMeshSceneNode::getMS3DJointNode(const c8* jointName)
ISceneNode* CAnimatedMeshSceneNode::getXJointNode(const c8* jointName) ISceneNode* CAnimatedMeshSceneNode::getXJointNode(const c8* jointName)
{ {
return getJointNode(jointName); return getJointNode(jointName);
return 0;
} }
//! Removes a child from this scene node. //! Removes a child from this scene node.
//! Implemented here, to be able to remove the shadow properly, if there is one, //! Implemented here, to be able to remove the shadow properly, if there is one,
//! or to remove attached childs. //! or to remove attached childs.
@ -657,7 +643,7 @@ bool CAnimatedMeshSceneNode::removeChild(ISceneNode* child)
{ {
if (ISceneNode::removeChild(child)) if (ISceneNode::removeChild(child))
{ {
for (s32 i=0; i<(s32)JointChildSceneNodes.size(); ++i) for (u32 i=0; i<JointChildSceneNodes.size(); ++i)
if (JointChildSceneNodes[i] == child) if (JointChildSceneNodes[i] == child)
{ {
//JointChildSceneNodes[i]->drop(); //JointChildSceneNodes[i]->drop();
@ -708,7 +694,6 @@ bool CAnimatedMeshSceneNode::setMD2Animation(const c8* animationName)
} }
//! Sets looping mode which is on by default. If set to false, //! Sets looping mode which is on by default. If set to false,
//! animations will not be looped. //! animations will not be looped.
void CAnimatedMeshSceneNode::setLoopMode(bool playAnimationLooped) void CAnimatedMeshSceneNode::setLoopMode(bool playAnimationLooped)

View File

@ -140,6 +140,7 @@ void CSkinnedMesh::animateMesh(f32 frame, f32 blend)
BoneControlUsed=false; BoneControlUsed=false;
} }
void CSkinnedMesh::buildAll_LocalAnimatedMatrices() void CSkinnedMesh::buildAll_LocalAnimatedMatrices()
{ {
for (u32 i=0; i<AllJoints.size(); ++i) for (u32 i=0; i<AllJoints.size(); ++i)
@ -194,6 +195,7 @@ void CSkinnedMesh::buildAll_GlobalAnimatedMatrices(SJoint *Joint, SJoint *Parent
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,
@ -205,16 +207,16 @@ void CSkinnedMesh::getFrameData(f32 frame, SJoint *Joint,
if (Joint->UseAnimationFrom) if (Joint->UseAnimationFrom)
{ {
core::array<SPositionKey> &PositionKeys=Joint->UseAnimationFrom->PositionKeys; const core::array<SPositionKey> &PositionKeys=Joint->UseAnimationFrom->PositionKeys;
core::array<SScaleKey> &ScaleKeys=Joint->UseAnimationFrom->ScaleKeys; const core::array<SScaleKey> &ScaleKeys=Joint->UseAnimationFrom->ScaleKeys;
core::array<SRotationKey> &RotationKeys=Joint->UseAnimationFrom->RotationKeys; const core::array<SRotationKey> &RotationKeys=Joint->UseAnimationFrom->RotationKeys;
if (PositionKeys.size()) if (PositionKeys.size())
{ {
foundPositionIndex = -1; foundPositionIndex = -1;
//Test the Hints... //Test the Hints...
if (positionHint>0 && positionHint < (s32)PositionKeys.size() ) if ((u32)positionHint < PositionKeys.size())
{ {
//check this hint //check this hint
if (PositionKeys[positionHint].frame>=frame && PositionKeys[positionHint-1].frame<frame ) if (PositionKeys[positionHint].frame>=frame && PositionKeys[positionHint-1].frame<frame )
@ -254,12 +256,12 @@ void CSkinnedMesh::getFrameData(f32 frame, SJoint *Joint,
} }
else if (InterpolationMode==EIM_LINEAR) else if (InterpolationMode==EIM_LINEAR)
{ {
SPositionKey *KeyA = &PositionKeys[foundPositionIndex]; const SPositionKey& KeyA = PositionKeys[foundPositionIndex];
SPositionKey *KeyB = &PositionKeys[foundPositionIndex-1]; const SPositionKey& KeyB = PositionKeys[foundPositionIndex-1];
f32 fd1 = frame-KeyA->frame; const f32 fd1 = frame - KeyA.frame;
f32 fd2 = KeyB->frame-frame; const f32 fd2 = KeyB.frame - frame;
position = ((KeyB->position-KeyA->position)/(fd1+fd2))*fd1 + KeyA->position; position = ((KeyB.position-KeyA.position)/(fd1+fd2))*fd1 + KeyA.position;
} }
} }
} }
@ -271,7 +273,7 @@ void CSkinnedMesh::getFrameData(f32 frame, SJoint *Joint,
foundScaleIndex = -1; foundScaleIndex = -1;
//Test the Hints... //Test the Hints...
if (scaleHint>0 && scaleHint < (s32)ScaleKeys.size() ) if ((u32)scaleHint < ScaleKeys.size())
{ {
//check this hint //check this hint
if (ScaleKeys[scaleHint].frame>=frame && ScaleKeys[scaleHint-1].frame<frame ) if (ScaleKeys[scaleHint].frame>=frame && ScaleKeys[scaleHint-1].frame<frame )
@ -312,12 +314,12 @@ void CSkinnedMesh::getFrameData(f32 frame, SJoint *Joint,
} }
else if (InterpolationMode==EIM_LINEAR) else if (InterpolationMode==EIM_LINEAR)
{ {
SScaleKey *KeyA = &ScaleKeys[foundScaleIndex]; const SScaleKey& KeyA = ScaleKeys[foundScaleIndex];
SScaleKey *KeyB = &ScaleKeys[foundScaleIndex-1]; const SScaleKey& KeyB = ScaleKeys[foundScaleIndex-1];
f32 fd1 = frame-KeyA->frame; const f32 fd1 = frame - KeyA.frame;
f32 fd2 = KeyB->frame-frame; const f32 fd2 = KeyB.frame - frame;
scale = ((KeyB->scale-KeyA->scale)/(fd1+fd2))*fd1 + KeyA->scale; scale = ((KeyB.scale-KeyA.scale)/(fd1+fd2))*fd1 + KeyA.scale;
} }
} }
} }
@ -329,7 +331,7 @@ void CSkinnedMesh::getFrameData(f32 frame, SJoint *Joint,
foundRotationIndex = -1; foundRotationIndex = -1;
//Test the Hints... //Test the Hints...
if (rotationHint>0 && rotationHint < (s32)RotationKeys.size() ) if ((u32)rotationHint < RotationKeys.size())
{ {
//check this hint //check this hint
if (RotationKeys[rotationHint].frame>=frame && RotationKeys[rotationHint-1].frame<frame ) if (RotationKeys[rotationHint].frame>=frame && RotationKeys[rotationHint-1].frame<frame )
@ -352,7 +354,7 @@ void CSkinnedMesh::getFrameData(f32 frame, SJoint *Joint,
{ {
for (u32 i=0; i<RotationKeys.size(); ++i) for (u32 i=0; i<RotationKeys.size(); ++i)
{ {
if (RotationKeys[i].frame >= frame) //Keys should to be sorted by frame if (RotationKeys[i].frame >= frame) //Keys should be sorted by frame
{ {
foundRotationIndex=i; foundRotationIndex=i;
rotationHint=i; rotationHint=i;
@ -370,26 +372,24 @@ void CSkinnedMesh::getFrameData(f32 frame, SJoint *Joint,
} }
else if (InterpolationMode==EIM_LINEAR) else if (InterpolationMode==EIM_LINEAR)
{ {
SRotationKey *KeyA = &RotationKeys[foundRotationIndex]; const SRotationKey& KeyA = RotationKeys[foundRotationIndex];
SRotationKey *KeyB = &RotationKeys[foundRotationIndex-1]; const SRotationKey& KeyB = RotationKeys[foundRotationIndex-1];
f32 fd1 = frame-KeyA->frame; const f32 fd1 = frame - KeyA.frame;
f32 fd2 = KeyB->frame - frame; const f32 fd2 = KeyB.frame - frame;
f32 t = (1.0f/(fd1+fd2))*fd1; const f32 t = fd1/(fd1+fd2);
/* /*
f32 t = 0; f32 t = 0;
if (KeyA->frame!=KeyB->frame) if (KeyA.frame!=KeyB.frame)
t = (frame-KeyA->frame) / (KeyB->frame - KeyA->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. //! Gets the name of a joint.
const c8* CSkinnedMesh::getJointName(s32 number) const const c8* CSkinnedMesh::getJointName(s32 number) const
{ {
if (number < 0 || number >= (s32)AllJoints.size()) if ((u32)number >= AllJoints.size())
return 0; return 0;
return AllJoints[number]->Name.c_str(); return AllJoints[number]->Name.c_str();
} }
@ -512,7 +512,7 @@ const c8* CSkinnedMesh::getJointName(s32 number) const
//! Gets a joint number from its name //! Gets a joint number from its name
s32 CSkinnedMesh::getJointNumber(const c8* name) const s32 CSkinnedMesh::getJointNumber(const c8* name) const
{ {
for (s32 i=0; i<(s32)AllJoints.size(); ++i) for (u32 i=0; i<AllJoints.size(); ++i)
{ {
if (AllJoints[i]->Name == name) if (AllJoints[i]->Name == name)
return i; return i;
@ -638,7 +638,7 @@ void CSkinnedMesh::CalculateGlobalMatrixes(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 thought 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)
@ -688,13 +688,13 @@ void CSkinnedMesh::checkForAnimation()
{ {
for(i=0;i<AllJoints.size();++i) for(i=0;i<AllJoints.size();++i)
{ {
if (AllJoints[i]->Weights.size()) HasAnimation = true; if (AllJoints[i]->Weights.size())
HasAnimation = true;
} }
} }
if (HasAnimation) if (HasAnimation)
{ {
//--- Find the length of the animation --- //--- Find the length of the animation ---
AnimationFrames=0; AnimationFrames=0;
for(i=0;i<AllJoints.size();++i) for(i=0;i<AllJoints.size();++i)
@ -740,7 +740,6 @@ void CSkinnedMesh::checkForAnimation()
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;
} }
} }
} }
@ -764,7 +763,6 @@ void CSkinnedMesh::checkForAnimation()
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;
} }
} }
@ -778,7 +776,7 @@ void CSkinnedMesh::checkForAnimation()
//! called by loader after populating with mesh and bone data //! called by loader after populating with mesh and bone data
void CSkinnedMesh::finalize() void CSkinnedMesh::finalize()
{ {
u32 i=0,j=0; u32 i;
lastAnimatedFrame=-1; lastAnimatedFrame=-1;
lastSkinnedFrame=-1; lastSkinnedFrame=-1;
@ -870,7 +868,7 @@ void CSkinnedMesh::finalize()
if (PositionKeys.size()>2) if (PositionKeys.size()>2)
{ {
for(j=0;j<PositionKeys.size()-2;++j) for(u32 j=0;j<PositionKeys.size()-2;++j)
{ {
if (PositionKeys[j].position == PositionKeys[j+1].position && PositionKeys[j+1].position == PositionKeys[j+2].position) if (PositionKeys[j].position == PositionKeys[j+1].position && PositionKeys[j+1].position == PositionKeys[j+2].position)
{ {
@ -882,7 +880,7 @@ void CSkinnedMesh::finalize()
if (PositionKeys.size()>1) if (PositionKeys.size()>1)
{ {
for(j=0;j<PositionKeys.size()-1;++j) for(u32 j=0;j<PositionKeys.size()-1;++j)
{ {
if (PositionKeys[j].frame >= PositionKeys[j+1].frame) //bad frame, unneed and may cause problems if (PositionKeys[j].frame >= PositionKeys[j+1].frame) //bad frame, unneed and may cause problems
{ {
@ -894,7 +892,7 @@ void CSkinnedMesh::finalize()
if (ScaleKeys.size()>2) if (ScaleKeys.size()>2)
{ {
for(j=0;j<ScaleKeys.size()-2;++j) for(u32 j=0;j<ScaleKeys.size()-2;++j)
{ {
if (ScaleKeys[j].scale == ScaleKeys[j+1].scale && ScaleKeys[j+1].scale == ScaleKeys[j+2].scale) if (ScaleKeys[j].scale == ScaleKeys[j+1].scale && ScaleKeys[j+1].scale == ScaleKeys[j+2].scale)
{ {
@ -906,7 +904,7 @@ void CSkinnedMesh::finalize()
if (ScaleKeys.size()>1) if (ScaleKeys.size()>1)
{ {
for(j=0;j<ScaleKeys.size()-1;++j) for(u32 j=0;j<ScaleKeys.size()-1;++j)
{ {
if (ScaleKeys[j].frame >= ScaleKeys[j+1].frame) //bad frame, unneed and may cause problems if (ScaleKeys[j].frame >= ScaleKeys[j+1].frame) //bad frame, unneed and may cause problems
{ {
@ -918,7 +916,7 @@ void CSkinnedMesh::finalize()
if (RotationKeys.size()>2) if (RotationKeys.size()>2)
{ {
for(j=0;j<RotationKeys.size()-2;++j) for(u32 j=0;j<RotationKeys.size()-2;++j)
{ {
if (RotationKeys[j].rotation == RotationKeys[j+1].rotation && RotationKeys[j+1].rotation == RotationKeys[j+2].rotation) if (RotationKeys[j].rotation == RotationKeys[j+1].rotation && RotationKeys[j+1].rotation == RotationKeys[j+2].rotation)
{ {
@ -930,7 +928,7 @@ void CSkinnedMesh::finalize()
if (RotationKeys.size()>1) if (RotationKeys.size()>1)
{ {
for(j=0;j<RotationKeys.size()-1;++j) for(u32 j=0;j<RotationKeys.size()-1;++j)
{ {
if (RotationKeys[j].frame >= RotationKeys[j+1].frame) //bad frame, unneed and may cause problems if (RotationKeys[j].frame >= RotationKeys[j+1].frame) //bad frame, unneed and may cause problems
{ {
@ -1236,6 +1234,7 @@ void CSkinnedMesh::createJoints(core::array<IBoneSceneNode*> &JointChildSceneNod
} }
} }
void CSkinnedMesh::convertMeshToTangents() void CSkinnedMesh::convertMeshToTangents()
{ {
// now calculate tangents // now calculate tangents

View File

@ -370,7 +370,6 @@ bool CXMeshFileLoader::parseDataObject()
else else
if (objectName == "Frame") if (objectName == "Frame")
{ {
return parseDataObjectFrame( 0 ); return parseDataObjectFrame( 0 );
} }
else else
@ -531,19 +530,12 @@ bool CXMeshFileLoader::parseDataObjectFrame( CSkinnedMesh::SJoint *Parent )
else else
if (objectName == "FrameTransformMatrix") if (objectName == "FrameTransformMatrix")
{ {
//if (!parseDataObjectTransformationMatrix(joint->LocalMatrix))
if (!parseDataObjectTransformationMatrix(joint->LocalMatrix)) if (!parseDataObjectTransformationMatrix(joint->LocalMatrix))
return false; return false;
//joint->LocalAnimatedMatrix //joint->LocalAnimatedMatrix
//joint->LocalAnimatedMatrix.makeInverse(); //joint->LocalAnimatedMatrix.makeInverse();
//joint->LocalMatrix=tmp*joint->LocalAnimatedMatrix; //joint->LocalMatrix=tmp*joint->LocalAnimatedMatrix;
} }
else else
if (objectName == "Mesh") if (objectName == "Mesh")
@ -566,7 +558,6 @@ bool CXMeshFileLoader::parseDataObjectFrame( CSkinnedMesh::SJoint *Parent )
if (!parseUnknownDataObject()) if (!parseUnknownDataObject())
return false; return false;
} }
} }
return true; return true;
@ -1996,19 +1987,23 @@ core::stringc CXMeshFileLoader::getNextToken()
if (P >= End) if (P >= End)
return s; return s;
while((P < End) && !core::isspace(P[0]))
char last=0;
//&& last!=';' && last!='}' && last!='{' && last!=','
while(P < End && !core::isspace(P[0]) ) //Luke:Not only space?
{ {
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]); s.append(P[0]);
++P; ++P;
} }
} }
os::Printer::log(s.c_str());
return s; return s;
} }
@ -2046,7 +2041,7 @@ void CXMeshFileLoader::findNextNoneWhiteSpace()
while(true) while(true)
{ {
while(P < End && (P[0]==' ' || P[0]=='\n' || P[0]=='\r' || P[0]=='\t')) while((P < End) && core::isspace(P[0]))
++P; ++P;
if (P >= End) if (P >= End)
@ -2100,7 +2095,7 @@ void CXMeshFileLoader::readUntilEndOfLine()
while(P < End) while(P < End)
{ {
if (P[0] == '\n') if (P[0] == '\n' || P[0] == '\r')
{ {
++P; ++P;
return; return;