From 46b8de48e560b1452eba9249babd622f5af856a5 Mon Sep 17 00:00:00 2001 From: Aditya Chaudhary Date: Sat, 1 Feb 2025 11:41:22 +0530 Subject: [PATCH] Fixed getVertexCount() method issue of giving output 0 for GROUP shape by Updating it in PShape & PShapeOpenGL class --- core/src/processing/core/PShape.java | 2 +- core/src/processing/opengl/PShapeOpenGL.java | 22 +++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/core/src/processing/core/PShape.java b/core/src/processing/core/PShape.java index 0538cb761..da2af3a90 100644 --- a/core/src/processing/core/PShape.java +++ b/core/src/processing/core/PShape.java @@ -2346,7 +2346,7 @@ public class PShape implements PConstants { * @see PShape#setVertex(int, float, float) */ public int getVertexCount() { - if (family == GROUP || family == PRIMITIVE) { + if (family == PRIMITIVE) { PGraphics.showWarning(NO_VERTICES_ERROR); } return vertexCount; diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index 810cbab70..c611b6afa 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -1635,17 +1635,23 @@ public class PShapeOpenGL extends PShape { @Override public int getVertexCount() { - if (family == GROUP) return 0; // Group shapes don't have vertices - else { + int count = 0; + // If the shape is a group, recursively count the vertices of its children + if (family == GROUP) { + // Iterate through all the child shapes and count their vertices + for (int i = 0; i < getChildCount(); i++) { + count += getChild(i).getVertexCount(); // Recursive call to get the vertex count of child shapes + } + } else { if (root.tessUpdate) { if (root.tessKind == TRIANGLES) { - return lastPolyVertex - firstPolyVertex + 1; + count += lastPolyVertex - firstPolyVertex + 1; } else if (root.tessKind == LINES) { - return lastLineVertex - firstLineVertex + 1; + count += lastLineVertex - firstLineVertex + 1; } else if (root.tessKind == POINTS) { - return lastPointVertex - firstPointVertex + 1; + count += lastPointVertex - firstPointVertex + 1; } else { - return 0; + count += 0; // Handle other cases } } else { if (family == PRIMITIVE || family == PATH) { @@ -1653,12 +1659,14 @@ public class PShapeOpenGL extends PShape { // tessellation updateTessellation(); } - return inGeo.vertexCount; + count += inGeo.vertexCount; } } + return count; } + @Override public PVector getVertex(int index, PVector vec) { if (vec == null) vec = new PVector();