Re-added non-indexed mesh support

This commit is contained in:
Anuken
2025-07-11 11:51:55 -04:00
parent f5f1933923
commit 0539d00cda
@@ -91,9 +91,9 @@ public class MeshBuilder{
boolean emit = mesher.isEmissive(); boolean emit = mesher.isEmissive();
if(grid.tiles.length * 6 >= 65535) throw new RuntimeException("Due to index size limits, only meshes with a maximum of 65535 vertices are supported. If you want more than that, make your own non-indexed mesh builder."); boolean indexed = grid.tiles.length * 6 < 65535;
Mesh mesh = begin(grid.tiles.length * 6, grid.tiles.length * 4 * 3, true, emit); Mesh mesh = begin(indexed ? grid.tiles.length * 6 : grid.tiles.length * 12, indexed ? grid.tiles.length * 4 * 3 : 0, true, emit);
float[] heights; float[] heights;
@@ -109,7 +109,7 @@ public class MeshBuilder{
} }
int position = 0; int position = 0;
short[] shorts = new short[12]; short[] shorts = indexed ? new short[12] : null;
float[] floats = new float[3 + (gl30 ? 1 : 3) + 1 + (emit ? 1 : 0)]; float[] floats = new float[3 + (gl30 ? 1 : 3) + 1 + (emit ? 1 : 0)];
Vec3 nor = new Vec3(); Vec3 nor = new Vec3();
@@ -150,6 +150,7 @@ public class MeshBuilder{
emissive = tmpCol.toFloatBits(); emissive = tmpCol.toFloatBits();
} }
if(indexed){
for(var corner : c){ for(var corner : c){
float height = heights[corner.id]; float height = heights[corner.id];
@@ -175,7 +176,17 @@ public class MeshBuilder{
} }
mesh.getIndicesBuffer().put(shorts, 0, c.length > 5 ? 12 : 9); mesh.getIndicesBuffer().put(shorts, 0, c.length > 5 ? 12 : 9);
position += c.length; position += c.length;
}else{
verts(mesh, floats, c[0].v, heights[c[0].id], c[1].v, heights[c[1].id], c[2].v, heights[c[2].id], nor, color, emissive);
verts(mesh, floats, c[0].v, heights[c[0].id], c[2].v, heights[c[2].id], c[3].v, heights[c[3].id], nor, color, emissive);
verts(mesh, floats, c[0].v, heights[c[0].id], c[3].v, heights[c[3].id], c[4].v, heights[c[4].id], nor, color, emissive);
if(c.length > 5){
verts(mesh, floats, c[0].v, heights[c[0].id], c[4].v, heights[c[4].id], c[5].v, heights[c[5].id], nor, color, emissive);
}
}
} }
return end(mesh); return end(mesh);
@@ -240,6 +251,12 @@ public class MeshBuilder{
out.set(cx, cy, cz).nor(); out.set(cx, cy, cz).nor();
} }
private static void verts(Mesh mesh, float[] floats, Vec3 a, float h1, Vec3 b, float h2, Vec3 c, float h3, Vec3 normal, float color, float emissive){
vert(mesh, floats, a.x * h1, a.y * h1, a.z * h1, normal, color, emissive);
vert(mesh, floats, b.x * h2, b.y * h2, b.z * h2, normal, color, emissive);
vert(mesh, floats, c.x * h3, c.y * h3, c.z * h3, normal, color, emissive);
}
private static void vert(Mesh mesh, float[] floats, float x, float y, float z, Vec3 normal, float color, float emissive){ private static void vert(Mesh mesh, float[] floats, float x, float y, float z, Vec3 normal, float color, float emissive){
floats[0] = x; floats[0] = x;
floats[1] = y; floats[1] = y;