Skip to content

Commit 46b8de4

Browse files
committed
Fixed getVertexCount() method issue of giving output 0 for GROUP shape by Updating it in PShape & PShapeOpenGL class
1 parent 3edd72c commit 46b8de4

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

core/src/processing/core/PShape.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2346,7 +2346,7 @@ protected void setPath(int vcount, float[][] verts, int ccount, int[] codes) {
23462346
* @see PShape#setVertex(int, float, float)
23472347
*/
23482348
public int getVertexCount() {
2349-
if (family == GROUP || family == PRIMITIVE) {
2349+
if (family == PRIMITIVE) {
23502350
PGraphics.showWarning(NO_VERTICES_ERROR);
23512351
}
23522352
return vertexCount;

core/src/processing/opengl/PShapeOpenGL.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,30 +1635,38 @@ protected void curveVertexImpl(float x, float y, float z) {
16351635

16361636
@Override
16371637
public int getVertexCount() {
1638-
if (family == GROUP) return 0; // Group shapes don't have vertices
1639-
else {
1638+
int count = 0;
1639+
// If the shape is a group, recursively count the vertices of its children
1640+
if (family == GROUP) {
1641+
// Iterate through all the child shapes and count their vertices
1642+
for (int i = 0; i < getChildCount(); i++) {
1643+
count += getChild(i).getVertexCount(); // Recursive call to get the vertex count of child shapes
1644+
}
1645+
} else {
16401646
if (root.tessUpdate) {
16411647
if (root.tessKind == TRIANGLES) {
1642-
return lastPolyVertex - firstPolyVertex + 1;
1648+
count += lastPolyVertex - firstPolyVertex + 1;
16431649
} else if (root.tessKind == LINES) {
1644-
return lastLineVertex - firstLineVertex + 1;
1650+
count += lastLineVertex - firstLineVertex + 1;
16451651
} else if (root.tessKind == POINTS) {
1646-
return lastPointVertex - firstPointVertex + 1;
1652+
count += lastPointVertex - firstPointVertex + 1;
16471653
} else {
1648-
return 0;
1654+
count += 0; // Handle other cases
16491655
}
16501656
} else {
16511657
if (family == PRIMITIVE || family == PATH) {
16521658
// the input geometry of primitive and path shapes is built during
16531659
// tessellation
16541660
updateTessellation();
16551661
}
1656-
return inGeo.vertexCount;
1662+
count += inGeo.vertexCount;
16571663
}
16581664
}
1665+
return count;
16591666
}
16601667

16611668

1669+
16621670
@Override
16631671
public PVector getVertex(int index, PVector vec) {
16641672
if (vec == null) vec = new PVector();

0 commit comments

Comments
 (0)