KinectPV2: get and import obj files

Can you show us your code?

Hi tony!
This is the sketch I used to import OBJ file in Processing

PShape rocket;

float ry;
  
public void setup() {
  size(640, 360, P3D);
    
  rocket = loadShape("frame00.obj");
}

public void draw() {
  background(0);
  lights();
  
  translate(width/2, height/2 + 100, -200);
  rotateZ(PI);
  rotateY(ry);
  shape(rocket);
  
  ry += 0.02;
}

frame00.obj is the name of file. Obviously, the file is in data folder of sketch folder

1 Like

I haven’t worked too often with .obj files. What does the pointcloud look like rendered in Blender?

Hi elyon,
Is your object only dots?
I think you need to have surface to be able to see something.
(It is like the render mode in blender: you can’t see the points, you can see them only in edit mode)

this is how the pointcloud frame caugth by kinect appears in Blender.

Hi jb4x!
Yeah, my object is only points, as you can see from the picture above.
You’ve probably right, but it’s so strange that a file create by Processing its not readable by Processing itself, isn’t it?

It is readable, it just not behave the way you expect it.

What you can try is to loop through all the point a draw a sphere at the position of each point.
You should get the result you expect this way.

1 Like

According to the loadShape() reference, your pointcloud is loaded as a PShape. Try iterating through all those points, like @jb4x says

Ah that’s an idea, guys!
Can you guide me? I’m a beginner and I don’t know how to do that :sweat::sweat_smile:

Let’s take a look at the PShape reference

We can use getVertex() to access the vertices. Give it an index and it will return to you a PVector.

2 Likes

To complement @tony 's answer, you can use getVertexCount() to get the number of vertex in your object. It makes it super easy to loop through all of the vertices of your object :wink:

1 Like

Some examples here: https://github.com/n1ckfg/MeshSequencer

Mh, so I have to use loadShape() to load the OBJ file, then use getVertexCount() to get vertex number, put them in a Vector and create a sphere on each vertex?

Hi elyon,

try this:

PShape rocket;

void setup() {
  size(640, 360, P3D);
  rocket = loadShape("frame00.obj");
  lights();

  for (int i = 0; i < s.getVertexCount(); i++) {
    PVector v = s.getVertex(i);
    pushMatrix();
    translate(v.x, v.y, v.z);
    sphere(3);
    popMatrix();
  }
}
1 Like

it doesn’t work. I think that the problem is the way that RecordPointCloud in KinectPV2 example make the OBJ file, because this is the result when i execute loadShape("frame00.obj")

I found also jeremydouglass solution here but in debugger I see that the OBJ hasn’t children and childCount is 0

This is really interesting - at this point I don’t know what to say.

Can I ask though: Can I ask though, have you checked out @shiffman’s Kinect Tutorial?

Have you posted the file anywhere? Can you copy and paste some lines from the top of it?

I’m happy to try to help if I can. Could you:

  1. confirm that this is the sketch generating your data? https://github.com/ThomasLengeling/KinectPV2/blob/master/KinectPV2/examples/RecordPointCloud/RecordPointCloud.pde

    There are some things going on here with PShader and OpenGL / PGL that I don’t fully understand. We might ask some of our form shader / OpenGL experts.

  2. Could you provide a sample of an actual OBJ you are producing? Ideally just a simple test example with dozens or hundreds of points – not thousands.

If you are using this code,

it looks like you should be saving an obj file that is just a list of verts, 1 per line, and nothing else.

v 0.123 0.234 0.345 1.0

If that is the case then even if you can’t get your current loader to work (which is odd) you could write your own loader in a few lines with loadStrings and split.

tony I checked Kinect Tutorial page but I don’t think it talks about record point cloud. Do I skipped any step?

@neilcsmith the code is the one that jeremydouglass posted

@jeremydouglass HI! Yeah, I confirm that is the code I used. Here is the link where you can find the file but, as you said, is just a list of verts, 1 per line, and nothing else.

Mhh, do you think that I can create an OBJ loader my self?

I was referring to the OBJ file! :smile:

So, I’ve run the file through a debugger against the PraxisLIVE source code (it’s what I have handy :wink: and the obj loader is the same code as Processing). And there’s a very obvious flaw - the OBJ file has no faces. All the vertices are parsed correctly, but the OBJ loader creates the actual PShape children from the faces data. I believe that Blender has vertex and faces views - I assume you’ll see nothing in the faces view?!

Your best bet at this stage is probably parsing the file manually into a single PShape.

This is kind of what @jb4x was getting at earlier, except explains why you can’t access the vertices in the resulting shape.

1 Like