Some textures is inside out

I hav seen in some models which I import from 3DS Max via .obj that the textures is pasted inside a model rather than outside like i shoud.



First i thaught it had something to do with the normals directions, but thats not the case…

you can try



TangentBinormalGenerator.generate(model);

nehon said:
you can try
`
TangentBinormalGenerator.generate(model);
`

Where?

Just after loading your model in the simpleInitApp for example.

Tangent and binormals are needed for the lighting shader to render the material correctly.

Maybe this could fix your problem

Unfortunately no effect…

I Tried to import a simple teapot from Max and this has textures on both sides… Wierd

I had this kind of porblem, I had to edit my model. If only some of your model’s faces are textured outside, try to scale it in 3dsMax, such that it would be the same size, but totally revesed, then export from 3dsMax and import it in jME3. If only some of your model’s faces are textured outside, try the same, but I’m not sure about the result. Say if there any changes.

I tried to flip the entire tri-mesh in 3DS Max, and that did the trick!



this may be connected with the fact that the coordinate systems in Max and jME are different

I dodn’t know how to fix it in code itself.

it should be possible to change this in the com.jmex.model.converters.ObjToJme.java



I am not sure how this actuallu works, but i think that the direction of a triangle has to do which way the vertexes are added. I will do some tests…

If I flip the editable poly in Max the normals is inside out, but the textures is outside on the model.



I have experimented with just changing the order of adding vertecies in com.jmex.model.converters.ObjToJme.java and in my case this did the trick. I have added a property in my code : “flipFaces”



[java]### Eclipse Workspace Patch 1.0

#P jMonkeyEngine

Index: src/com/jmex/model/converters/ObjToJme.java

===================================================================

— src/com/jmex/model/converters/ObjToJme.java (revision 4862)

+++ src/com/jmex/model/converters/ObjToJme.java (working copy)

@@ -114,7 +114,7 @@

/** Reference to the renderer for creating RenderState objects **/

private Renderer renderer;

private boolean generateMissingNormals = true;

-

  • private boolean flipFaces = false;

    /**
  • Converts an Obj file to jME format. The syntax is: "ObjToJme file.obj
  • outfile.jme".

    @@ -154,6 +154,7 @@

    String in;

    curGroup = defaultMaterialGroup;

    materialSets.put(defaultMaterialGroup, new ArraySet());
  •    flipFaces = (Boolean)properties.get("flipFaces");<br />
    

while ((in = inFile.readLine()) != null) {

processLine(in);

}

@@ -190,6 +191,7 @@

String in;

curGroup = defaultMaterialGroup;

materialSets.put(defaultMaterialGroup, new ArraySet());

  •    flipFaces = (Boolean)properties.get("flipFaces");<br />
    

while ((in = inFile.readLine()) != null) {

processLine(in);

}

@@ -453,9 +455,18 @@

thisMat.objName = curGroupName;

}

}

  •    IndexSet first = new IndexSet(parts[1]);<br />
    
  •    IndexSet first = null;<br />
    
  •    IndexSet second = null;<br />
    

+

  •    if(flipFaces) {<br />
    
  •      first = new IndexSet(parts[2]);<br />
    
  •      second = new IndexSet(parts[1]);<br />
    
  •    }<br />
    
  •    else {<br />
    
  •      first = new IndexSet(parts[1]);<br />
    
  •      second = new IndexSet(parts[2]);<br />
    
  •    }<br />
    

int firstIndex = thisMat.findSet(first);

  •    IndexSet second = new IndexSet(parts[2]);<br />
    

int secondIndex = thisMat.findSet(second);

for (int i = 3; i < parts.length; i++) {

IndexSet third = new IndexSet();

[/java]



Please check if its OK to commit



edit: typo…

I will commit this since no one complained

Hi



After I did an svn-update on the jme2-code today, the ObjToJme class now throws a NullPointerException:

java.lang.NullPointerException

at com.jmex.model.converters.ObjToJme.convert(ObjToJme.java:157)



Line 157 reads:

flipFaces = (Boolean)properties.get(“flipFaces”);



What’s going wrong? Before the svn-update it worked, but now I get this. I figured that this patch might be the cause for this, so I directly post here, if you don’t mind :slight_smile:

Wasserleiche said:
Hi

After I did an svn-update on the jme2-code today, the ObjToJme class now throws a NullPointerException:
java.lang.NullPointerException
at com.jmex.model.converters.ObjToJme.convert(ObjToJme.java:157)

Line 157 reads:
flipFaces = (Boolean)properties.get("flipFaces");

What's going wrong? Before the svn-update it worked, but now I get this. I figured that this patch might be the cause for this, so I directly post here, if you don't mind :)


Fixed! Sorry about that!

[java]if(properties.containsKey("flipFaces"))
flipFaces = (Boolean)properties.get("flipFaces");[/java]