We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hello guys...i've a question.
you can access the vertex of an obj file ?
i try with this...but it doesn't work.
import peasy.*;
PShape shp;
PeasyCam cam;
void setup() {
size(1000, 1000, P3D);
shp=loadShape("face.obj");
println(shp.getVertexCount());
cam = new PeasyCam(this, 100);
cam.setMinimumDistance(50);
cam.setMaximumDistance(500);
}
void draw() {
lights();
directionalLight(255, 150, 200, -1, 0, 0);
background(0);
shape(shp);
}
the result of println(shp.getVertexCount()) is 0.
thank you!! :)
Answers
As far as I know, the
getVertexCount()
andgetVertex()
functions only work with vertexes you've added in code using thevertex()
function, not with vertexes loaded from a shape file.From the reference:
thanks for the answer...there isn't a way to get that vertexes?
I was working on some related aspects on PShape on another thread.
As far as I know KevinWorkman's answer from the documentation is correct, however I'm not able to check your code because I don't have a face.obj file or anything similar to make it work. If you want to make an obj file available or link to one that is similar to the data you are working with then I could take a quick look.
there's a rocket.obj file included in the examples > Basic > Shapes
Thank you koogs -- for some reason I had never looked at the LoadDisplayOBJ example sketch before, mainly being focused on 2D. Interesting simple data format.
pietroLama -- your problem is that the main OBJ-imported PShape does not contain any vertices. Instead it contains a collection of child PShapes, each of which contain vertices.
The reference that KevinWorkman cites is correct -- but misleading. You can use these methods, but you must first loop through child shapes in order to use them.
Rather than vertices [0], [1], [2], [3], [4], [5]... you have vertices like [0][0], [0][1], [0][2], [1][0], [1][1], [1][2] ... where [s][v] is each child shape (each 3D polygon) containing some number of vertices (e.g. three in a triangular polygon).
Below I wrote a couple quick demo functions to work with them --
printChildVertices
andgetChildrenVertexCount
. I tested them by adding them to the standard LoadDisplayOBJ example.Here is some of the output:
You can see that rocket.obj is made of 367 polygons, which average 3 vertices per triangular tile, for a total of 1101 vertices defining the whole rocket (although many of these vertices are shared between multiple polygons where they meet).
sorry...for the late reply...really thanks about your support :D
Glad that it was helpful, @pietroLama.