3dprimitive.setPosition() not applying when doing 3dprimitive.getMesh()


Just started exporting a group of ofBoxPrimitive with different positions to an ofMesh

Couldnt get it working by setting the position of the primitive by using the class function setPosition(), but found a workaround in the forum that works for me.

link to the forum thread: Workaround on last post

Why does this workaround work on setting the positions while the class function does nothing?


//this works
for(int i = 0; i < primitiveCube.getMesh().getVertices().size(); i++){
        primitiveCube.getMesh().getVertices()[i] += ofVec3f( x*separation ,
                                                            y*separation ,
                                                            fin_s / 2.0

//this doesnt work
primitiveCube.setPosition( x*separation ,
                               y*separation ,
                               fin_s / 2.0

return primitiveCube.getMesh();

Sorry in advance if this is not a bug, just thought this was some extrange behavior that could be fixed.



Because those are two very different operations. When you do setPosition you are not changing the vertices. What your are doing, is setting a matrix so that the model changes it’s position in the world space. An vec3(10, 20, 30) will keep it’s values and gets multiply by a matrix.

This matrix operation, is not exported. Only the model space is exported.

That’s why, when you loop through each vertex and change it’s value, you are actually changing it’s model space coordinates.

This forum is not, in any way, only about bugs. Any questions, feel free to ask. :slightly_smiling:

Ok got it. Thanks a lot for the explanation