Hi Guys!

I found that when exporting models to obj files in blender without checking the triangulate option the imported file in jme might look different cos’ the importer handles quads different than blender does internaly.

I copy the relevant code part here:

[java]

protected Face[] quadToTriangle(Face f){

assert f.verticies.length == 4;

Face[] t = new Face[]{ new Face(), new Face() };

t[0].verticies = new Vertex[3];

t[1].verticies = new Vertex[3];

Vertex v0 = f.verticies[0];

Vertex v1 = f.verticies[1];

Vertex v2 = f.verticies[2];

Vertex v3 = f.verticies[3];

// find the pair of verticies that is closest to each over

// v0 and v2

// OR

// v1 and v3

float d1 = v0.v.distanceSquared(v2.v);

float d2 = v1.v.distanceSquared(v3.v);

if (d1 < d2){

// put an edge in v0, v2

t[0].verticies[0] = v0;

t[0].verticies[1] = v1;

t[0].verticies[2] = v3;

t[1].verticies[0] = v1;

t[1].verticies[1] = v2;

t[1].verticies[2] = v3;

}else{

// put an edge in v1, v3

t[0].verticies[0] = v0;

t[0].verticies[1] = v1;

t[0].verticies[2] = v2;

t[1].verticies[0] = v0;

t[1].verticies[1] = v2;

t[1].verticies[2] = v3;

}

return t;

}

[/java]

The code triangulates a quad along the longer diagonal (though from the comments I think the author wanted to cut along the shorter) but it seems blender does it in a different way. This leads to shading issues sometimes. I used a model uploaded by @mifth in one of his thread to demonstrate this.

I used the same obj file in the three cases.

Fig 1. is how the model looks in blender viewport using glsl shading

Fig 2. is how it looks in jme with the current version of the importer, the mid part is off

Fig 3. shows what happens when I change the split condition from (d1 < d2) to (d1 > d2)

so the quads are split along the shorter diagonal. The mid part is ok but the upper portion is off

Fig 4. I ignored the diagonal check and all quads were triangulated in a fixed vertex order 0,1,2 and 0,2,3

this gives the correct result. I also improved the tangents to remove the nasty seams.

If we remove the diagonal check then we can import quads from blender correctly but it is possible that files produced by other tools will show up wrong. If we don’t change the code then quad format exports from blender should be avoided (the triangulate option must be used) and this must be documented somewhere. Alternatively quadToTriangle can be made customizable.

Regards,

Remorhaz

A game-ready model consists of triangles, so you should do that in the editor anyway. Thanks for the hint though, we’ll see if it makes sense / is possible to adapt to the way blender does the triangulation.