Getting (or Adding?) the node of an ofMesh or ofVboMesh

Im trying to use the “look at” feature of the camera and light. As per the documentation, ofNode is supposed to be at the base of everything 3d. So far, i wasnt able to “look at” neither an ofAssimpModelLoader, an ofMesh or an ofVboMesh.

How do i get the nodes from objects of those 3 types? Is it already part of the mesh or do i need to add(or assign) one?

Hey @Thormind , usually I use an of3dPrimitive when I want an ofNode and an ofMesh (or ofVboMesh) together in 1 class. You can always create a custom class too though. The of3dPrimitive is a parent class of other 3d primitives classes like ofSpherePrimitive, ofPlanePrimitive, etc. These will all have ofNode in them too. ofMesh and ofVboMesh do not have an ofNode in them. At the top of the documentation page for a class, you should see a quick mention if the class is extending another, like this one: of3dPrimitive | openFrameworks

not sure about ofAssimpModelLoader, but certainly ofMesh and ofVboMesh are not sublcasses of ofNode, nor this have an ofNode attached. Although as @TimChi points out of3dPrimitive class does and joins a mesh with a node.

I wouldn’t undestand ofMesh or ofVboMesh as a 3d thing, as you can use it, and it gets used, for 2d stuff as well.

1 Like

Tks! so if i understand correctly, instead of creating an “ofMesh” object, i create an “of3dPrimitive” object and i do my mesh with the “ofMesh” thats already in “of3dPrivitive”?

The nice thing about of3dPrimitive is that it will automatically apply the transformations you make to it onto the mesh when you draw.

// of3dPrimitive prim;
prim.getMesh().addVertex(...); //etc

Check also the classes that inherit from of3dPrimitive, which mostly will generate automatically meshes of certain types (sphere, plane, cube, etc). Here all the ones that end with Primitive, ie. ofBoxPrimitive

1 Like

Hey yes, you can get the ofMesh in the of3dPrimitive with its .getMesh() function. The of3dPrimitive class inherits from ofNode, so you can just call those functions like you would for ofNode:

of3dPrimitive primitive;
int numVertices = 100;
for(int i = 0; i < numVertices; ++i)
        float value = ofRandom(1.f) * 1000;
        primitive.getMesh().addVertex(glm::vec3(value, value, 0.f));
// call an ofNode function
glm::vec3 position = primitive.getGlobalPosition();

I’m not sure about of ofxAssimpModelLoader and if it has an ofNode in it or not. You could have a look in its header file to see if it inherits from ofNode, or if it has an ofNode as a class member. I’m thinking it probably doesn’t, but I haven’t looked to be sure.

1 Like