there is an issue when a single B3D file contains two (or more) animated objects.
Looking at the B3D exporter and the irrlicht loading code, I have come to the conclusion that the cause is probably because B3D and irrlicht disagree on whether vertex IDs within bones are relative or absolute. The B3D exporter seems to write vertex IDs relative to the parent mesh buffer; but irrlicht reads back this ID into a variable called "globalVertexID", without doing "+= vertices_Start" like done when reading triangles.
See screenshot at http://yfrog.com/h6lh1p to see what this causes
And below is the patch that fixes it all as far as I can tell:
Code: Select all
Index: Irrlicht/CB3DMeshFileLoader.cpp
===================================================================
--- Irrlicht/CB3DMeshFileLoader.cpp (revision 3516)
+++ Irrlicht/CB3DMeshFileLoader.cpp (working copy)
@@ -68,10 +68,10 @@
return AnimatedMesh;
}
-
-
+
bool CB3DMeshFileLoader::load()
{
+ start = 0;
B3dStack.clear();
NormalsInFile=false;
@@ -198,12 +198,15 @@
}
else if ( strncmp( B3dStack.getLast().name, "MESH", 4 ) == 0 )
{
+ // this is the offset we need to use next time we read bone coordinates
+ start = BaseVertices.size();
+
if (!readChunkMESH(joint))
return false;
}
else if ( strncmp( B3dStack.getLast().name, "BONE", 4 ) == 0 )
{
- if (!readChunkBONE(joint))
+ if (!readChunkBONE(start, joint))
return false;
}
else if ( strncmp( B3dStack.getLast().name, "KEYS", 4 ) == 0 )
@@ -544,12 +547,14 @@
}
-bool CB3DMeshFileLoader::readChunkBONE(CSkinnedMesh::SJoint *inJoint)
+bool CB3DMeshFileLoader::readChunkBONE(int vertices_Start, CSkinnedMesh::SJoint *inJoint)
{
#ifdef _B3D_READER_DEBUG
os::Printer::log("read ChunkBONE");
@@ -562,6 +567,7 @@
globalVertexID = os::Byteswap::byteswap(globalVertexID);
strength = os::Byteswap::byteswap(strength);
#endif
+ globalVertexID += vertices_Start; // make vertex ID global
if (AnimatedVertices_VertexID[globalVertexID]==-1)
{
Index: Irrlicht/CB3DMeshFileLoader.h
===================================================================
--- Irrlicht/CB3DMeshFileLoader.h (revision 3516)
+++ Irrlicht/CB3DMeshFileLoader.h (working copy)
@@ -40,6 +40,8 @@
//! See IReferenceCounted::drop() for more information.
virtual IAnimatedMesh* createMesh(io::IReadFile* file);
+ int start;
+
private:
struct SB3dChunkHeader
@@ -97,7 +99,7 @@
bool readChunkMESH(CSkinnedMesh::SJoint* InJoint);
bool readChunkVRTS(CSkinnedMesh::SJoint* InJoint);
bool readChunkTRIS(scene::SSkinMeshBuffer *MeshBuffer, u32 MeshBufferID, s32 Vertices_Start);
- bool readChunkBONE(CSkinnedMesh::SJoint* InJoint);
+ bool readChunkBONE(int start, CSkinnedMesh::SJoint* InJoint);
bool readChunkKEYS(CSkinnedMesh::SJoint* InJoint);
bool readChunkANIM();
bool readChunkTEXS();