diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/VertexWriter.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/VertexWriter.java index fddde36ad..2eb0b27c1 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/VertexWriter.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/VertexWriter.java @@ -42,7 +42,8 @@ public VertexConsumer addVertex(float x, float y, float z) { MemoryUtil.memPutFloat(ptr + 8, z); filledPosition = true; } - return this; + + return this.endVertex(); } @Override @@ -93,6 +94,25 @@ public VertexConsumer setNormal(float x, float y, float z) { return this; } + public VertexConsumer endVertex() { + if ((!filledPosition || !filledTexture || !filledNormal) && vertexCount != 0) { + throw new IllegalStateException("Not filled all elements of the vertex"); + } + + filledPosition = false; + filledTexture = false; + filledNormal = false; + vertexCount++; + + long byteSize = (vertexCount + 1) * STRIDE; + long capacity = data.size(); + if (byteSize > capacity) { + data = data.realloc(capacity * 2); + } + + return this; + } + private long vertexPtr() { return data.ptr() + vertexCount * STRIDE; }