[fixed]B3D

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Auria
Competition winner
Posts: 120
Joined: Wed Feb 18, 2009 1:11 am
Contact:

[fixed]B3D

Post by Auria »

Hi,

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();
note that the "start" variable above needs to be a class member, it can't just be a local variable, because of the recursion
d3jake
Posts: 198
Joined: Sat Mar 22, 2008 7:49 pm
Location: United States of America

Post by d3jake »

Out of curiosity: Which B3D exporter are you using from which modeling program?
The Open Descent Foundation is always looking for programmers! http://www.odf-online.org
"I'll find out if what I deleted was vital here shortly..." -d3jake
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yeah, could be that we never had such objects so far. I'll check with our current test models. It might also help if someone could test the object in question with b3d engine.
Auria
Competition winner
Posts: 120
Joined: Wed Feb 18, 2009 1:11 am
Contact:

Post by Auria »

We are using Blender, and a modified version of gandaldf's B3D exporter (modified version found at http://supertuxkart.svn.sourceforge.net ... iew=markup )

Now I don't know the B3D format, so it may actually be that the exporter and not the loader is at fault :)
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Is there also a link for the model to test it here?
Auria
Competition winner
Posts: 120
Joined: Wed Feb 18, 2009 1:11 am
Contact:

Post by Auria »

Take this little blend I made for testing : http://www.mediafire.com/?w63maew0qgc47o8

it displays clearly wrong in the mesh viewer sample of irrlicht
Auria
Competition winner
Posts: 120
Joined: Wed Feb 18, 2009 1:11 am
Contact:

Post by Auria »

Friendly bump :)

This is a blocker bug, is there anything I can do to speed up correction of this?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

So how should the mesh display? And what makes you think that this is correct, not the one that is currently displayed?
Auria
Competition winner
Posts: 120
Joined: Wed Feb 18, 2009 1:11 am
Contact:

Post by Auria »

hybrid wrote:So how should the mesh display? And what makes you think that this is correct, not the one that is currently displayed?
Well, to see how it's supposed to display, just open blender??

But really, check again my first screenshot : http://yfrog.com/h6lh1p
Honestly, you can't think when looking at this that the current display is OK, right? ;) [ this critter normally looks like http://supertuxkart.sourceforge.net/per ... k061-3.jpg , holes in him quite unexpected ;) ]

I uploaded a comparison here : http://img510.imageshack.us/i/comparisonb.png/

Now, even after my patch, the 2 dancing guys are sadly still not 100% like in blender, seems like the armature translation is not applied - but I think this is a different issue
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yeah, the wholes were pretty convincing. I didn't get the relation to the new meshes. Nor did I know how the animation were supposed to look like (but probably the skeleton gives a good hint for this). I'll check further, as I now also have the test meshes at my computer here.
Please don't take these questions wrong, I just need to get a correct interpretation and correct in all situations fix for this. The b3d documentation is unfortunately just as bad as those of most other file formats.
Auria
Competition winner
Posts: 120
Joined: Wed Feb 18, 2009 1:11 am
Contact:

Post by Auria »

hybrid wrote:Yeah, the wholes were pretty convincing. I didn't get the relation to the new meshes. Nor did I know how the animation were supposed to look like (but probably the skeleton gives a good hint for this). I'll check further, as I now also have the test meshes at my computer here.
Please don't take these questions wrong, I just need to get a correct interpretation and correct in all situations fix for this. The b3d documentation is unfortunately just as bad as those of most other file formats.
ok sure ;)
The difference between the kart model and the dancing guys is most likely because the 2 dancing guys are identical, so they both have the same vertices in the same order - while the kart's two models, the vehicle and the fish, have no relation in their vertices whatsoever. So the bug, which is picking vertices from the wrong model, has different visual results in both cases
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ah, ok. Then the movements also make sense, because they will probably overlay or replace each other partially. I will prepare the loader for this case and check the other meshes and the format specs.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ok, your fix was completely right. The indices read are local, while the variable suggested that it was global already (a little thinking would have made this obvious before, but such a strong hint can easily confuse :wink: ). Thanks for the fix.
Auria
Competition winner
Posts: 120
Joined: Wed Feb 18, 2009 1:11 am
Contact:

Post by Auria »

Nice, thanks :D
Post Reply