PShape, .obj-file, Vertex transformation

edited October 2013 in How To...

Hey, when I load an .obj - file as a PShape; is there any way to manipulate the vertices manually? PShape.getVertexCount() returns 0.

Answers

  • This is probably because an obj model typically consists of child shapes contained inside a root shape. Calling getVertexCount() on the root shape will give you 0 because it doesn't hold any vertices, you should access the child shapes by doing:

    PShape obj = loadShape("model.obj");
    for (int i = 0; i < obj.getChildCount(); i++) {
      PShape child = obj.getChild(i);
      println(child.getVertexCount());
    }
    

    PShape also has a getChildren() method that returns all the child shapes in an array. Also, a child shape could also be a group containing further children.

  • thank you for the quick replay, I'll test it.

Sign In or Register to comment.