Hey guys,
I’m working on a project which involves spawning cubes. When I have cubes that have same texture on each face, it’s simple. However I need certain cubes to have different textures on each face. I’m a long time Blender user, so I exported custom mesh with UV mapping and it works fine.
BUT, I also kinda need to make this via code, so I can edit the material inside the code immediately.
I have followed the the tutorial in the docu - https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes and I managed to create a simple box. Now I don’t know how to set a different texture on each face of the cube :/. My code:
mesh1 = new Mesh();
Vector3f[] vertices = new Vector3f[8];
vertices[0] = new Vector3f(0, 0, 0);
vertices[1] = new Vector3f(1, 0, 0);
vertices[2] = new Vector3f(0, 1, 0);
vertices[3] = new Vector3f(1, 1, 0);
vertices[4] = new Vector3f(0, 0, 1);
vertices[5] = new Vector3f(1, 0, 1);
vertices[6] = new Vector3f(0, 1, 1);
vertices[7] = new Vector3f(1, 1, 1);
Vector3f[] texCoord = new Vector3f[8];
texCoord[0] = new Vector3f(0, 0, 0);
texCoord[1] = new Vector3f(1, 0, 0);
texCoord[2] = new Vector3f(0, 1, 0);
texCoord[3] = new Vector3f(1, 1, 0);
texCoord[4] = new Vector3f(0, 0, 1);
texCoord[5] = new Vector3f(1, 0, 1);
texCoord[6] = new Vector3f(0, 1, 1);
texCoord[7] = new Vector3f(1, 1, 1);
int[] indexes =
{
3,1,0,
0,2,3,
7,5,1,
1,3,7,
6,4,5,
5,7,6,
2,0,4,
4,6,2,
7,3,2,
2,6,7,
1,5,4,
4,0,1
};
mesh1.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
mesh1.setBuffer(VertexBuffer.Type.TexCoord, 3, BufferUtils.createFloatBuffer(texCoord));
mesh1.setBuffer(VertexBuffer.Type.Index, 3, BufferUtils.createIntBuffer(indexes));
mesh1.updateBound();
cube = new Geometry("MyGeometry", mesh1);
mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
cube.setMaterial(mat);
I’m not sure if the texCoords are correct, and if they are/are not, how to reproduce them for a cube and then how to set the textures?
Thank you very much