Displaying custom mesh from both sides

Hi, I am pretty new to JME, managed to install it and run some tutorial, however I ran into the problem:



I have copied the simple custom mesh example, and it displays only from one side.

E.g. when I move my camera to the other side of the custom mesh it appears to be empty and I can’t see anything.



code:

[java]Mesh m = new Mesh();



// Vertex positions in space

Vector3f [] vertices = new Vector3f[4];

vertices[0] = new Vector3f(0,0,0);

vertices[1] = new Vector3f(3,0,0);

vertices[2] = new Vector3f(0,3,0);

vertices[3] = new Vector3f(3,3,0);



// Texture coordinates

Vector2f [] texCoord = new Vector2f[4];

texCoord[0] = new Vector2f(0,0);

texCoord[1] = new Vector2f(1,0);

texCoord[2] = new Vector2f(0,1);

texCoord[3] = new Vector2f(1,1);



// Indexes. We define the order in which mesh should be constructed

int [] indexes = {2,0,1,1,3,2};



// Setting buffers

m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));

m.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));

m.setBuffer(Type.Index, 1, BufferUtils.createIntBuffer(indexes));

m.updateBound();



// *************************************************************************

// First mesh uses one solid color

// *************************************************************************



// Creating a geometry, and apply a single color material to it

Geometry geom = new Geometry(“OurMesh”, m);

Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

mat.setColor(“Color”, ColorRGBA.Blue);

geom.setMaterial(mat);



// Attaching our geometry to the root node.

rootNode.attachChild(geom);[/java]



Please give me a hint,

Peter

[java]mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);[/java] dont think this works well for lighting tho, just a fyi

1 Like

Thank you Wezrule !



Worked like a miracle, what would be a great solution for lighting ?

it should work for lighting. culling is just showing/hiding faces



and add a envoirement light + directional light to node, and set material based on lighting.j3md



here some tuts:

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:materials

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_material

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:light_and_shadow



at all if you want use normal maps or other maps needed tangents, then you need to generate this tangents.

We have a FAQ and manual you know ^^ you should read them.

I see, it’s very nicely written and structured, really enjoy reading it!



Thank you for your help)