Fixed getVertexCount() method issue of giving output 0 for GROUP shape by Updating it in PShape & PShapeOpenGL class

This commit is contained in:
Aditya Chaudhary
2025-02-01 11:41:22 +05:30
parent 3edd72c152
commit 46b8de48e5
2 changed files with 16 additions and 8 deletions
+1 -1
View File
@@ -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;
+15 -7
View File
@@ -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();