So I’m building a makeshift house from various items in my game. My game allows rotations of some items in 45 degree angles, so you can have walls, floors and roofs in variations of 45 degree angles.
Long story short, you can press the E key to adjust a quad to an isosceles or equilateral triangle instead - I guess a picture will explain it better:
This will allow people to have pitched roofs amongst other things. The problem is that when I have both a quad and a triangle in the same GeometryBatchFactory node, it returns an error:
UnsupportedOperationException: The geometry buffer TexCoord has different number of components than the rest of the meshes (this: 2, expected: 3)
I’m far from being a game guru, so i’m a little lost. Below is the code I use to create the various geometries needed. The same material is used for each shape.
[java]
public class ShapeFactory
{
public static enum ShapeType { Quad, Isosceles, Equalateral };
public static Geometry createQuad(String name)
{
Quad quad = new Quad(1f, 1f);
Geometry geom = new Geometry(name, quad);
return geom;
}
public static Geometry createIsoscelesTriangle(String name)
{
Vector3f[] vertices =
{
new Vector3f(0, 0, 0),
new Vector3f(0, 1, 0),
new Vector3f(1, 0, 0),
};
Vector3f[] textCoords =
{
new Vector3f(0, 0, 0),
new Vector3f(0, 1, 0),
new Vector3f(1, 0, 0),
};
int[] indexes = { 0, 1, 2 };
Mesh mesh = new Mesh();
mesh.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
mesh.setBuffer(VertexBuffer.Type.TexCoord, 3, BufferUtils.createFloatBuffer(textCoords));
mesh.setBuffer(VertexBuffer.Type.Index, 3, BufferUtils.createIntBuffer(indexes));
mesh.updateBound();
Geometry geom = new Geometry(name, mesh);
return geom;
}
public static Geometry createEqualateralTriangle(String name)
{
Vector3f[] vertices =
{
new Vector3f(0, 0, 0),
new Vector3f(.5f, 1, 0),
new Vector3f(1, 0, 0),
};
Vector3f[] textCoords =
{
new Vector3f(0, 0, 0),
new Vector3f(.5f, 1, 0),
new Vector3f(1, 0, 0),
};
int[] indexes = { 0, 1, 2 };
Mesh mesh = new Mesh();
mesh.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
mesh.setBuffer(VertexBuffer.Type.TexCoord, 3, BufferUtils.createFloatBuffer(textCoords));
mesh.setBuffer(VertexBuffer.Type.Index, 3, BufferUtils.createIntBuffer(indexes));
mesh.updateBound();
Geometry geom = new Geometry(name, mesh);
return geom;
}
}
[/java]