Skip to content

Commit

Permalink
Fixed issue #1121.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsschmidt1337 committed Oct 10, 2024
1 parent a03e796 commit 4ecda93
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/org/nschmidt/ldparteditor/data/GL33ModelRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
46 changes: 30 additions & 16 deletions src/org/nschmidt/ldparteditor/data/HiQualityEdgeCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,33 +145,37 @@ public static EdgeData[] hiQualityEdgeData(List<GDataAndWinding> 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);
}
}

Expand All @@ -183,6 +187,16 @@ public static EdgeData[] hiQualityEdgeData(List<GDataAndWinding> dataInOrder, Li
return result;
}

private static void addTriangleIndicies(List<Integer> 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<Float> data, Matrix4f matrix,
float vx, float vy, float vz,
float r, float g, float b) {
Expand Down
14 changes: 7 additions & 7 deletions test/org/nschmidt/ldparteditor/HiQualityEdgeCalculatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
}

Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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);
}

Expand Down

0 comments on commit 4ecda93

Please sign in to comment.