nonnex
1
[Java]
Mesh mesh = new Mesh();
mesh.setMode(Mesh.Mode.Triangles);
mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
mesh.setBuffer(Type.Index, 3, BufferUtils.createIntBuffer(generatePolygonIndices(vertices.length)));
mesh.updateBound();
[/Java]
[Java]
/**
-
Create Buffer indices for Polygons (front and backside)
-
@param size (int) Num of Vertices
*/
public int[] generatePolygonIndices(int size) {
// Frontside Indices
int[] indicesF = new int[size * 3];
int fc = 0, t1 = 0, t2 = 1, t3 = 2;
for (int n = 0; n < size; n++) {
int mod = (n % 2 == 0) ? 0 : 1;
indicesF[fc++] = t1;
indicesF[fc++] = t2;
indicesF[fc++] = t3;
t1 = (mod == 0) ? n + 2 : 0;
t2 = (n == size - 2) ? 1 : (mod == 0) ? n + 3 : n + 2;
t3 = (n == size - 2) ? (t1 == 0) ? size : 0 : (mod != 0) ? n + 3 : 0;
}
// Backside Indices
int[] indicesB = new int[indicesF.length];
// Take the Frontside indices and reverse the array
for (int i = 0; i < indicesF.length; i++) {
indicesB[i] = indicesF[indicesF.length - 1 - i];
}
// Combine both Arrays
int[] indices = ArrayUtils.addAll(indicesF, indicesB); // Combine both Arrays
return indices;
}
[/Java]
nonnex
2
Sry, for the html tags. Iām new to the hub.
Are the Topics somehow editable by the autor?
here again:
[java]
Mesh mesh = new Mesh();
mesh.setMode(Mesh.Mode.Triangles);
mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
mesh.setBuffer(Type.Index, 3, BufferUtils.createIntBuffer(generatePolygonIndices(vertices.length)));
mesh.updateBound();
[/java]
[java]
/**
-
Create Buffer indices for Polygons (front and backside)
-
@param size (int) Num of Vertices
*/
public int[] generatePolygonIndices(int size) {
// Frontside Indices
int[] indicesF = new int[size * 3];
int fc = 0, t1 = 0, t2 = 1, t3 = 2;
for (int n = 0; n < size; n++) {
int mod = (n % 2 == 0) ? 0 : 1;
indicesF[fc++] = t1;
indicesF[fc++] = t2;
indicesF[fc++] = t3;
t1 = (mod == 0) ? n + 2 : 0;
t2 = (n == size - 2) ? 1 : (mod == 0) ? n + 3 : n + 2;
t3 = (n == size - 2) ? (t1 == 0) ? size : 0 : (mod != 0) ? n + 3 : 0;
}
// Backside Indices
int[] indicesB = new int[indicesF.length];
// Take the Frontside indices and reverse the array
for (int i = 0; i < indicesF.length; i++) {
indicesB[i] = indicesF[indicesF.length - 1 - i];
}
// Combine both Arrays
int[] indices = ArrayUtils.addAll(indicesF, indicesB); // Combine both Arrays
return indices;
}
[/java]
1 Like