diff -r 59e6bca88355 lib/irrlicht/include/IMeshManipulator.h --- a/lib/irrlicht/include/IMeshManipulator.h Thu Jun 04 02:31:04 2009 +0200 +++ b/lib/irrlicht/include/IMeshManipulator.h Thu Jun 04 02:35:23 2009 +0200 @@ -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 @@ -205,6 +206,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 59e6bca88355 lib/irrlicht/source/Irrlicht/CMeshManipulator.cpp --- a/lib/irrlicht/source/Irrlicht/CMeshManipulator.cpp Thu Jun 04 02:31:04 2009 +0200 +++ b/lib/irrlicht/source/Irrlicht/CMeshManipulator.cpp Thu Jun 04 02:35:23 2009 +0200 @@ -6,6 +6,7 @@ #include "SMesh.h" #include "CMeshBuffer.h" #include "SAnimatedMesh.h" +#include "CSkinnedMesh.h" #include "os.h" namespace irr @@ -671,7 +672,7 @@ buffer->Vertices.push_back(v[i]); } } - + break; } case video::EVT_2TCOORDS: @@ -879,21 +880,21 @@ for ( i=0; igetMeshBuffers().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 59e6bca88355 lib/irrlicht/source/Irrlicht/CMeshManipulator.h --- a/lib/irrlicht/source/Irrlicht/CMeshManipulator.h Thu Jun 04 02:31:04 2009 +0200 +++ b/lib/irrlicht/source/Irrlicht/CMeshManipulator.h Thu Jun 04 02:35:23 2009 +0200 @@ -81,7 +81,7 @@ //! Creates a planar texture mapping on the mesh /** \param mesh: Mesh on which the operation is performed. \param resolution: resolution of the planar mapping. This is the value - specifying which is the relation between world space and + specifying which is the relation between world space and texture coordinate space. */ virtual void makePlanarTextureMapping(scene::IMesh* mesh, f32 resolution) const; @@ -115,11 +115,14 @@ //! 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, - core::vector3df& tangent, - core::vector3df& binormal, + static void calculateTangents(core::vector3df& normal, + core::vector3df& tangent, + core::vector3df& binormal, const core::vector3df& vt1, const core::vector3df& vt2, const core::vector3df& vt3, const core::vector2df& tc1, const core::vector2df& tc2, const core::vector2df& tc3); };