diff --git a/core/src/processing/core/PShape.java b/core/src/processing/core/PShape.java
index 0538cb761d..09c5e07362 100644
--- a/core/src/processing/core/PShape.java
+++ b/core/src/processing/core/PShape.java
@@ -2335,18 +2335,28 @@ protected void setPath(int vcount, float[][] verts, int ccount, int[] codes) {
}
/**
- * The getVertexCount() method returns the number of vertices that
- * make up a PShape. In the above example, the value 4 is returned by the
+ * The getVertexCount() method returns the number of vertices (with an option to count children by passing true as boolean parameter to method call) that
+ * make up a PShape. By default, it does not count child vertices for GROUP shapes. To include child vertices, pass true as a boolean parameter. In the above example, the value 4 is returned by the
* getVertexCount() method because 4 vertices are defined in
* setup().
*
* @webref pshape:method
- * @webBrief Returns the total number of vertices as an int
+ * @webBrief Returns the total number of vertices as an int with an option to count children Vertex for GROUP Shapes
* @see PShape#getVertex(int)
* @see PShape#setVertex(int, float, float)
*/
+ public int getVertexCount(boolean includeChildren) {
+ if(!includeChildren && family == GROUP){
+ PGraphics.showWarning(NO_VERTICES_ERROR);
+ }
+ else if (family == PRIMITIVE) {
+ PGraphics.showWarning(NO_VERTICES_ERROR);
+ }
+ return vertexCount;
+ }
+
public int getVertexCount() {
- if (family == GROUP || family == PRIMITIVE) {
+ if(family == GROUP || 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 810cbab708..f34031f1ac 100644
--- a/core/src/processing/opengl/PShapeOpenGL.java
+++ b/core/src/processing/opengl/PShapeOpenGL.java
@@ -1632,20 +1632,34 @@ protected void curveVertexImpl(float x, float y, float z) {
// Setters/getters of individual vertices
-
+ //for taking the default value as false , so user don't have to explicitly enter false
+ // if user don't want to include children vertex count
@Override
public int getVertexCount() {
- if (family == GROUP) return 0; // Group shapes don't have vertices
- else {
+ return getVertexCount(false); // Calls the main method with default false
+ }
+ @Override
+ public int getVertexCount(boolean includeChildren) {
+ int count = 0;
+ // If the shape is a group, recursively count the vertices of its children
+ if (family == GROUP) {
+ if(!includeChildren){
+ return 0;
+ }
+ // Iterate through all the child shapes and count their vertices
+ for (int i = 0; i < getChildCount(); i++) {
+ count += getChild(i).getVertexCount(true); // 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,9 +1667,10 @@ public int getVertexCount() {
// tessellation
updateTessellation();
}
- return inGeo.vertexCount;
+ count += inGeo.vertexCount;
}
}
+ return count;
}