From 4ecda93c7c962baa0372781ca025d998cc6fa821 Mon Sep 17 00:00:00 2001 From: Nils Schmidt Date: Thu, 10 Oct 2024 12:57:16 +0200 Subject: [PATCH] Fixed issue #1121. --- .../ldparteditor/data/GL33ModelRenderer.java | 8 ++-- .../data/HiQualityEdgeCalculator.java | 46 ++++++++++++------- .../HiQualityEdgeCalculatorTest.java | 14 +++--- 3 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/org/nschmidt/ldparteditor/data/GL33ModelRenderer.java b/src/org/nschmidt/ldparteditor/data/GL33ModelRenderer.java index 1726a5309..a66f21eb4 100644 --- a/src/org/nschmidt/ldparteditor/data/GL33ModelRenderer.java +++ b/src/org/nschmidt/ldparteditor/data/GL33ModelRenderer.java @@ -2451,7 +2451,7 @@ public void draw(GLMatrixStack stack, GLShader mainShader, GLShader lineShader, GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboCondlinesIndices); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW); - // A vertex consists of 6 floats, a quad of 4 vertices + // A vertex consists of 6 floats, a triangle of 3 vertices final int indexCount = indices.length; GL20.glEnableVertexAttribArray(0); @@ -2464,7 +2464,7 @@ public void draw(GLMatrixStack stack, GLShader mainShader, GLShader lineShader, stack.glPushMatrix(); stack.glTranslatef(tr.x, tr.y, tr.z); - GL11.glDrawElements(GL11.GL_QUADS, indexCount, GL11.GL_UNSIGNED_INT, 0); + GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); @@ -2488,7 +2488,7 @@ public void draw(GLMatrixStack stack, GLShader mainShader, GLShader lineShader, GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboCondlinesIndices); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW); - // A vertex consists of 18 floats, a quad of 4 vertices + // A vertex consists of 18 floats, a triangle of 3 vertices final int indexCount = indices.length; GL20.glEnableVertexAttribArray(0); @@ -2510,7 +2510,7 @@ public void draw(GLMatrixStack stack, GLShader mainShader, GLShader lineShader, stack.glPushMatrix(); stack.glTranslatef(tr.x, tr.y, tr.z); - GL11.glDrawElements(GL11.GL_QUADS, indexCount, GL11.GL_UNSIGNED_INT, 0); + GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); diff --git a/src/org/nschmidt/ldparteditor/data/HiQualityEdgeCalculator.java b/src/org/nschmidt/ldparteditor/data/HiQualityEdgeCalculator.java index 3d8a96a39..da1760528 100644 --- a/src/org/nschmidt/ldparteditor/data/HiQualityEdgeCalculator.java +++ b/src/org/nschmidt/ldparteditor/data/HiQualityEdgeCalculator.java @@ -145,33 +145,37 @@ public static EdgeData[] hiQualityEdgeData(List dataInOrder, Li int startIndex2 = index + 1; for (int i = 0; i < 7; i++) { - tagetIndices.add(index + 3); - tagetIndices.add(index + 1); - tagetIndices.add(index); - tagetIndices.add(index + 2); + addTriangleIndicies(tagetIndices, + index + 3, + index + 1, + index, + index + 2); index += 2; } - tagetIndices.add(index); - tagetIndices.add(startIndex1); - tagetIndices.add(startIndex2); - tagetIndices.add(index + 1); + addTriangleIndicies(tagetIndices, + index, + startIndex1, + startIndex2, + index + 1); } else { int startIndex1 = index; int startIndex2 = index + 1; for (int i = 0; i < 7; i++) { - tagetIndices.add(index + 3); - tagetIndices.add(index + 2); - tagetIndices.add(index); - tagetIndices.add(index + 1); + addTriangleIndicies(tagetIndices, + index + 3, + index + 2, + index, + index + 1); index += 2; } - tagetIndices.add(index); - tagetIndices.add(index + 1); - tagetIndices.add(startIndex2); - tagetIndices.add(startIndex1); + addTriangleIndicies(tagetIndices, + index, + index + 1, + startIndex2, + startIndex1); } } @@ -183,6 +187,16 @@ public static EdgeData[] hiQualityEdgeData(List dataInOrder, Li return result; } + private static void addTriangleIndicies(List indices, int index1, int index2, int index3, int index4) { + indices.add(index1); + indices.add(index2); + indices.add(index3); + + indices.add(index3); + indices.add(index4); + indices.add(index1); + } + private static void addPoint(List data, Matrix4f matrix, float vx, float vy, float vz, float r, float g, float b) { diff --git a/test/org/nschmidt/ldparteditor/HiQualityEdgeCalculatorTest.java b/test/org/nschmidt/ldparteditor/HiQualityEdgeCalculatorTest.java index 13f15d61d..2d104eb22 100644 --- a/test/org/nschmidt/ldparteditor/HiQualityEdgeCalculatorTest.java +++ b/test/org/nschmidt/ldparteditor/HiQualityEdgeCalculatorTest.java @@ -62,7 +62,7 @@ public void testOneEdge() { assertEquals(0, result[1].vertices().length); assertEquals(0, result[2].vertices().length); assertEquals(0, result[3].vertices().length); - assertEquals(32, result[0].indices().length); + assertEquals(48, result[0].indices().length); assertEquals(0, result[1].indices().length); assertEquals(0, result[2].indices().length); assertEquals(0, result[3].indices().length); @@ -87,7 +87,7 @@ public void testOneTransparentEdge() { assertEquals(0, result[2].vertices().length); assertEquals(0, result[3].vertices().length); assertEquals(0, result[0].indices().length); - assertEquals(32, result[1].indices().length); + assertEquals(48, result[1].indices().length); assertEquals(0, result[2].indices().length); assertEquals(0, result[3].indices().length); } @@ -113,7 +113,7 @@ public void testOneRandomColourEdge() { assertEquals(0, result[1].vertices().length); assertEquals(0, result[2].vertices().length); assertEquals(0, result[3].vertices().length); - assertEquals(32, result[0].indices().length); + assertEquals(48, result[0].indices().length); assertEquals(0, result[1].indices().length); assertEquals(0, result[2].indices().length); assertEquals(0, result[3].indices().length); @@ -139,7 +139,7 @@ public void testOneCondline() { assertEquals(0, result[3].vertices().length); assertEquals(0, result[0].indices().length); assertEquals(0, result[1].indices().length); - assertEquals(32, result[2].indices().length); + assertEquals(48, result[2].indices().length); assertEquals(0, result[3].indices().length); } @@ -161,7 +161,7 @@ public void testOneCondlineInCondlineMode() { assertEquals(0, result[1].vertices().length); assertEquals(0, result[2].vertices().length); assertEquals(0, result[3].vertices().length); - assertEquals(32, result[0].indices().length); + assertEquals(48, result[0].indices().length); assertEquals(0, result[1].indices().length); assertEquals(0, result[2].indices().length); assertEquals(0, result[3].indices().length); @@ -188,7 +188,7 @@ public void testOneTransparentCondline() { assertEquals(0, result[0].indices().length); assertEquals(0, result[1].indices().length); assertEquals(0, result[2].indices().length); - assertEquals(32, result[3].indices().length); + assertEquals(48, result[3].indices().length); } @Test @@ -214,7 +214,7 @@ public void testOneRandomColourCondline() { assertEquals(0, result[3].vertices().length); assertEquals(0, result[0].indices().length); assertEquals(0, result[1].indices().length); - assertEquals(32, result[2].indices().length); + assertEquals(48, result[2].indices().length); assertEquals(0, result[3].indices().length); }