From 99edb31ec25c618ab67aca47fec508fa934c63b7 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Fri, 7 Jun 2024 21:35:06 -0400 Subject: [PATCH] fix vertex writer endVertex --- .../flywheel/lib/model/part/VertexWriter.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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; }