Blender importer vertex count + material troubles

Hi guys!



If I use the blender importer the number of vertices shown in the property inspector is not matching with the vertex count of the model. The example I provided is a simple plane (4 vertices 2 triangles) but the imported model has 6 vertices. Is this the expected behaviour?

Just asking cos. when I make an obj export in blender and import the obj file the vertex count is the correct number of 4. The same mismatch can be reproduced just with any blender model.



The other porblem is that the material of this plane is not imported correctly, apparently just an empty material definition is created. I get a warning during import:

Attention! Many textures found for material: Material.001. Only the first of each supported mapping types will be used!



However I have only one material defined and it has only one texture.



The only “tricky” material setup I made is that in the object data panel I set the game engine-only properties:

two-sided and transparency: alpha. I can create a material in JMP that gives the same result as the blender setup though:



Material MyMaterial : Common/MatDefs/Light/Lighting.j3md {

MaterialParameters {

DiffuseMap : Models/mat-test/leafbranch-color4.png

VTangent : true

HighQuality : true

WardIso : true

LATC : false

}

AdditionalRenderState {

FaceCull Off

Blend PremultAlpha

}

}



So the question is how to set up a two-sided material with transparency in blender that can be imported by the

blender importer?



Here is the link for the example blend file I was refering:



http://www.2shared.com/file/ppxDpKVd/test.html



The verison of the blender support plugin is:

Version: 3.0.0.8298 jMonkeyEngine SDK 3.0beta

I use blender 2.59



Thanks!

maybe try convert the quad to triangles and try smooth shading in blender, see if that makes a difference. Seems the triangles aren’t been shared.

Transparency wont work i dont think, as blender materials != jme materials, think you have to do the transparency in jme.

Thanks for the tip but does not help. As for the material, the object has a uv mapped image based texture, and that is supported I think, but it seems not all the settings are translated to jme material properties (though jme supports the setting). I am more interested in the solution of the vertex problem.

The importers aren’t guaranteed to import the mesh 1:1, you would have to create the mesh by yourself or an importer that works this way.

Thanks normen! What you are saying is probably true.

But now blender’s default cube is imported with 36 vertices instead of 8 and I imported a custom character model of ~3K vertices that resulted in a ~11K vertex count in jme. I know this importer is still work in progress and I simply don’t think that the author Kaelthas wanted to work in this way. However only he can tell us if this is a feature we must live with or a bug.

Again, none of the importers is guaranteed to give you the same vertex count as you see in the editor. For example all meshes must consist of triangles for live rendering, subsurfs get applied etc.

@remorhaz said:
But now blender's default cube is imported with 36 vertices instead of 8


This is a good example... though 36 seems high to me. So the blender importer is probably treating each triangle individually and never sharing vertexes...

Anyway, a cube conceptually can be represented with only 8 vertexes... but in OpenGL you will usually need 24. Each face has to have its own 4 vertexes because they will need their own normals and texture coordinates. These can't be shared among the faces. You can only share vertexes when they have the same normal, texture coordinate, etc... basically all of the vertex attributes have to be the same to share them. That's common in a smooth shape like a sphere. Not possible in something like a cube.

As above, my guess is that the blender importer decides that figuring this out is too hard and just treats every triangle individually. There are 12 triangles in a cube, therefore 36 vertexes.
1 Like

Thanks pspeed for the clear explanation. That makes sense and the obj format export/import results in 24 vertices indeed in the case of the cube and I double checked the blender import and it is 36, but I am not sure if it is the fault of the importer any more, maybe it is how blender internally represents the model, who knows.

@pspeed said:
my guess is that the blender importer decides that figuring this out is too hard and just treats every triangle individually.

I didn't have too much time recently but now I looked into the source code of blender importer an it seems it does not even attempt
to figure it out and regardless of the mesh structure/uv/normal setup it will always create a vertex buffer of size number of tris * 3 (and of course the uv and normal buffer with the same size).
The problem is in com.jme3.scene.plugins.blender.meshes.MeshHelper.toMesh(...). It can be fixed relatively easily though using
the same method that can be found in the obj loader.

While testing I found that the calculation of vertex normals of smooth vertices are wrong as well. When
I printed out the normals of an axis aligned cube with smooth vertices I got this set of vectors:
(-0.70710695, 0.49999976, 0.49999985)
(0.49999973, 0.49999973, 0.70710707)
(-0.49999982, 0.50000006, -0.70710677)
(0.50000024, 0.5000001, -0.70710653)
(-0.49999985, -0.4999999, -0.70710695)
(-0.7071068, -0.5, 0.49999982)
(0.5000002, -0.49999997, -0.70710665)
(0.49999976, -0.5000002, 0.7071068)

while I expected this:

0.577349 -0.577349 -0.577349
0.577349 -0.577349 0.577349
-0.577349 -0.577349 0.577349
-0.577349 -0.577349 -0.577349
0.577349 0.577349 -0.577349
-0.577349 0.577349 -0.577349
-0.577349 0.577349 0.577349
0.577349 0.577349 0.577349

So the vectors are unit long but have wrong directions.
The problem is in the addNormal() function in the same class, it normalizes the intermediate results, so
if the normal vector is the result of the sum of 3 vectors the calculation goes like this: norm(norm(a+b) +c) instead of norm(a+b+c) where
"norm" is making a vector unit long (normalizeLocal in the code) .

Is there anybody who can verify this ?
Thanks

@Kaelthas?

Hi,



sorry for late response.



As for the vertex amount - the count of Vertex3f instances is equal to the one in blender, they are only referenced more times (3 for each triangle face).

There is no need to triangulate the mesh - the importer loads everything to triangles.

At first I was planning to create the mesh made of triangle fans but it took me long time to implement it so I decided to do it the easier way to see some results (it was the early stage of the importer life then :slight_smile: ). Maybe I’ll return to this in some time to be when I solve other bugs.

I’ll check the obj loader as you suggested - maybe it will give me some hints.



As for the material loading I’ll check this out as soon as I download the file you provided.





Cheers,

Kaelthas

@Kaelthas said:
At first I was planning to create the mesh made of triangle fans but it took me long time to implement it so I decided to do it the easier way to see some results (it was the early stage of the importer life then :) ). Maybe I'll return to this in some time to be when I solve other bugs.
I'll check the obj loader as you suggested - maybe it will give me some hints.


Thanks, Kaelthas!

I think I can do the mesh loading fix myself and post the result for reviewing and committing. Don't forget about the normal calculation issue as well. I think the normalization of the vectors should happen after the normalList is completely populated in the toMesh method, am I correct?

You made a great work on deciphering the basically undocumented blender file format!

Cheers,
Remorhaz