Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PShape.getVertexCount() always outputs 0 #896

Open
dtplsongithub opened this issue Dec 24, 2024 · 5 comments
Open

PShape.getVertexCount() always outputs 0 #896

dtplsongithub opened this issue Dec 24, 2024 · 5 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@dtplsongithub
Copy link

Most appropriate sub-area of Processing 4?

Core/Environment/Rendering

Processing version

4.3.1

Operating system

Windows 11 (24H2)

Steps to reproduce this

PShape.getVertexCount() always seems to output 0. (tried 1 .svg file and 4 .obj files, even included the .mtl files)

snippet

PShape shape;
  
void setup() {
  size(640, 360, P3D);
    
  shape = loadShape("cuboctahedron.obj");
  println(shape.getVertexCount()); // zero???
}

void draw() {
  background(0);
  lights();
  translate(width/2, height/2, -200);
  scale(50);
  rotateY((float)millis()/2000);
  shape(shape);
}

Additional context

No response

@dtplsongithub dtplsongithub added the bug Something isn't working label Dec 24, 2024
@hx2A
Copy link
Collaborator

hx2A commented Dec 27, 2024

@dtplsongithub , can you check if your shape is a group shape?

I just tested this on the Processing example "LoadDisplayOBJ", which shows a rotating rocket. The vertex count was zero but I could use the below code to get the vertices for the object's children:

  rocket = loadShape("rocket.obj");
  println(rocket.getVertexCount());
  int count = 0;
  for (PShape shape : rocket.getChildren()) {
    count += shape.getVertexCount();
  }
  println(count);

The output is:

0
1101

I would argue that a call to getVertexCount() on a group shape should return the total vertex count of its children, and that all renderers (JAVA2D, P2D, P3D) should behave in a similar fashion for loaded shapes.

@dtplsongithub
Copy link
Author

the code you provided me works, i guess i was using the method wrong...

@hx2A
Copy link
Collaborator

hx2A commented Dec 27, 2024

the code you provided me works, i guess i was using the method wrong...

No, I think the code you originally wrote should work. getVertexCount() is confusing if it returns zero for group shapes. Also, consider that the 1101 vertex count of my example could also be wrong. What if the group shape contains a mixture of mesh shapes and other group shapes? Group shapes can be nested. Some of the calls to getVertexCount() for the shape's children could also be zero. The 1101 value could be an under-count of the correct number.

Let's keep this open so we can use this as an opportunity to improve Processing. It would likely be an easy PR, so I'll add some tags so a first-time contributor can fix it.

@hx2A hx2A reopened this Dec 27, 2024
@hx2A hx2A added the good first issue Good for newcomers label Dec 27, 2024
@hx2A
Copy link
Collaborator

hx2A commented Dec 27, 2024

And @dtplsongithub , if you, or anyone else reading this would like some help working through the PR, I'm available to assist!

@Stefterv
Copy link
Collaborator

Stefterv commented Dec 28, 2024

Adding a warning message, that groups are ignored in the count would also be helpful. Maybe even a countGroups = false parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants