diff -r 8ecc8dc21f86 lib/irrlicht/include/IMeshManipulator.h --- a/lib/irrlicht/include/IMeshManipulator.h Fri Mar 06 17:24:47 2009 +0100 +++ b/lib/irrlicht/include/IMeshManipulator.h Wed Mar 11 03:04:11 2009 +0100 @@ -20,6 +20,7 @@ class IMesh; class IMeshBuffer; struct SMesh; + class ISkinnedMesh; //! An interface for easy manipulation of meshes. /** Scale, set alpha value, flip surfaces, and so on. This exists for @@ -180,6 +181,13 @@ IReferenceCounted::drop() for more information. */ virtual IAnimatedMesh * createAnimatedMesh(IMesh* mesh, scene::E_ANIMATED_MESH_TYPE type = scene::EAMT_UNKNOWN) const = 0; + + //! Create a skinned mesh which has copied all meshbuffers and joints of the original mesh + /** Note, that this will not copy any other information like joints data. + \param mesh Original mesh + \return Newly created skinned mesh. You should call drop() wehn you don't need it anymore. + See IReferenceCounted::drop() for more information. */ + virtual ISkinnedMesh* createSkinnedMesh(ISkinnedMesh* mesh) const = 0; }; } // end namespace scene diff -r 8ecc8dc21f86 lib/irrlicht/source/Irrlicht/CMeshManipulator.cpp --- a/lib/irrlicht/source/Irrlicht/CMeshManipulator.cpp Fri Mar 06 17:24:47 2009 +0100 +++ b/lib/irrlicht/source/Irrlicht/CMeshManipulator.cpp Wed Mar 11 03:04:11 2009 +0100 @@ -6,6 +6,7 @@ #include "SMesh.h" #include "CMeshBuffer.h" #include "SAnimatedMesh.h" +#include "CSkinnedMesh.h" #include "os.h" namespace irr @@ -1140,6 +1141,50 @@ return new SAnimatedMesh(mesh, type); } +//! Create a skinned mesh which has copied all meshbuffers and joints of the original mesh +ISkinnedMesh* CMeshManipulator::createSkinnedMesh(ISkinnedMesh* mesh) const +{ + CSkinnedMesh * skinnedMesh = new CSkinnedMesh(); + + if ( !mesh ) + return skinnedMesh; + + for ( u32 i=0; i < mesh->getMeshBuffers().size(); ++i ) + { + SSkinMeshBuffer * buffer = skinnedMesh->createBuffer(); + *buffer = *(mesh->getMeshBuffers()[i]); + } + + for ( u32 j=0; j < mesh->getAllJoints().size(); ++j ) + { + CSkinnedMesh::SJoint *joint = skinnedMesh->createJoint(); + *joint = *(mesh->getAllJoints()[j]); + } + + // fix children pointers (they still have old pointers) + core::array & newJoints = skinnedMesh->getAllJoints(); + core::array & oldJoints = mesh->getAllJoints(); + for ( u32 i=0; i < newJoints.size(); ++i ) + { + CSkinnedMesh::SJoint * joint = newJoints[i]; + for ( u32 c=0; c < joint->Children.size(); ++c ) + { + // the child is one of the oldJoints and must be replaced by the newjoint on the same index + for ( u32 k=0; k < oldJoints.size(); ++k ) + { + if ( joint->Children[c] == oldJoints[k] ) + { + joint->Children[c] = newJoints[k]; + break; + } + } + } + } + + skinnedMesh->finalize(); + + return skinnedMesh; +} } // end namespace scene } // end namespace irr diff -r 8ecc8dc21f86 lib/irrlicht/source/Irrlicht/CMeshManipulator.h --- a/lib/irrlicht/source/Irrlicht/CMeshManipulator.h Fri Mar 06 17:24:47 2009 +0100 +++ b/lib/irrlicht/source/Irrlicht/CMeshManipulator.h Wed Mar 11 03:04:11 2009 +0100 @@ -106,6 +106,9 @@ //! create a new AnimatedMesh and adds the mesh to it virtual IAnimatedMesh * createAnimatedMesh(scene::IMesh* mesh,scene::E_ANIMATED_MESH_TYPE type) const; + //! Create a skinned mesh which has copied all meshbuffersand joints of the original mesh + virtual ISkinnedMesh* createSkinnedMesh(ISkinnedMesh* mesh) const; + private: static void calculateTangents(core::vector3df& normal,