From 8c0d3a9a31db62855f3e296895ace422f1ea2906 Mon Sep 17 00:00:00 2001 From: jonathanklein Date: Tue, 21 Feb 2012 16:46:02 +0000 Subject: [PATCH] Ogre - Animations without Scaling Key supported - when the model has more than 1 texcoord, the first one is loaded (instead of nothing) git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1178 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/OgreImporter.cpp | 75 +++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 28 deletions(-) diff --git a/code/OgreImporter.cpp b/code/OgreImporter.cpp index 2bb5e552a..944e28eb9 100644 --- a/code/OgreImporter.cpp +++ b/code/OgreImporter.cpp @@ -424,7 +424,10 @@ void OgreImporter::ReadVertexBuffer(SubMesh &theSubMesh, XmlReader *Reader, unsi DefaultLogger::get()->debug("reading texture coords"); } if(theSubMesh.NumUvs>1) - DefaultLogger::get()->warn("too many texcoords (just 1 supported!), no texcoords will be loaded!"); + { + DefaultLogger::get()->warn("too many texcoords (just 1 supported!), just the first texcoords will be loaded!"); + theSubMesh.NumUvs=1; + } //___________________________________________________________________ @@ -484,6 +487,11 @@ void OgreImporter::ReadVertexBuffer(SubMesh &theSubMesh, XmlReader *Reader, unsi NewUv.x=GetAttribute(Reader, "u"); NewUv.y=GetAttribute(Reader, "v")*(-1)+1;//flip the uv vertikal, blender exports them so! theSubMesh.Uvs.push_back(NewUv); + + //skip all the following texcoords: + while(Reader->getNodeName()==string("texcoord")) + XmlRead(Reader); + continue;//don't read another line at the end of the loop } //Attribute could not be read @@ -762,35 +770,46 @@ void OgreImporter::LoadSkeleton(std::string FileName, vector &Bones, vecto Keyframe NewKeyframe; NewKeyframe.Time=GetAttribute(SkeletonFile, "time"); - //Position: - XmlRead(SkeletonFile); - if(string("translate")!=SkeletonFile->getNodeName()) - throw DeadlyImportError("translate node not first in keyframe"); - NewKeyframe.Position.x=GetAttribute(SkeletonFile, "x"); - NewKeyframe.Position.y=GetAttribute(SkeletonFile, "y"); - NewKeyframe.Position.z=GetAttribute(SkeletonFile, "z"); + //loop over the attributes: + + while(true) + { + XmlRead(SkeletonFile); - //Rotation: - XmlRead(SkeletonFile); - if(string("rotate")!=SkeletonFile->getNodeName()) - throw DeadlyImportError("rotate is not second node in keyframe"); - float RotationAngle=GetAttribute(SkeletonFile, "angle"); - aiVector3D RotationAxis; - XmlRead(SkeletonFile); - if(string("axis")!=SkeletonFile->getNodeName()) - throw DeadlyImportError("No axis for keyframe rotation!"); - RotationAxis.x=GetAttribute(SkeletonFile, "x"); - RotationAxis.y=GetAttribute(SkeletonFile, "y"); - RotationAxis.z=GetAttribute(SkeletonFile, "z"); - NewKeyframe.Rotation=aiQuaternion(RotationAxis, RotationAngle); + //Position: + if(string("translate")==SkeletonFile->getNodeName()) + { + NewKeyframe.Position.x=GetAttribute(SkeletonFile, "x"); + NewKeyframe.Position.y=GetAttribute(SkeletonFile, "y"); + NewKeyframe.Position.z=GetAttribute(SkeletonFile, "z"); + } - //Scaling: - XmlRead(SkeletonFile); - if(string("scale")!=SkeletonFile->getNodeName()) - throw DeadlyImportError("no scalling key in keyframe!"); - NewKeyframe.Scaling.x=GetAttribute(SkeletonFile, "x"); - NewKeyframe.Scaling.y=GetAttribute(SkeletonFile, "y"); - NewKeyframe.Scaling.z=GetAttribute(SkeletonFile, "z"); + //Rotation: + else if(string("rotate")!=SkeletonFile->getNodeName()) + { + float RotationAngle=GetAttribute(SkeletonFile, "angle"); + aiVector3D RotationAxis; + XmlRead(SkeletonFile); + if(string("axis")!=SkeletonFile->getNodeName()) + throw DeadlyImportError("No axis for keyframe rotation!"); + RotationAxis.x=GetAttribute(SkeletonFile, "x"); + RotationAxis.y=GetAttribute(SkeletonFile, "y"); + RotationAxis.z=GetAttribute(SkeletonFile, "z"); + NewKeyframe.Rotation=aiQuaternion(RotationAxis, RotationAngle); + } + + //Scaling: + else if(string("scale")==SkeletonFile->getNodeName()) + { + NewKeyframe.Scaling.x=GetAttribute(SkeletonFile, "x"); + NewKeyframe.Scaling.y=GetAttribute(SkeletonFile, "y"); + NewKeyframe.Scaling.z=GetAttribute(SkeletonFile, "z"); + } + + //we suppose, that we read all attributes and this is a new keyframe or the end of the animation + else + break; + } NewTrack.Keyframes.push_back(NewKeyframe);