Various questions about ofmesh and texture coordinates

hello guys i’m really new so bare with me :stuck_out_tongue:
So i have a mesh I created like this:

define ofpoint
addvertex(point)
addcolor(c)

and then i add the triangles

for()
int a = base+i;
int b = base+(i+1) %circleN;
int c = circleN + a;
int d = circleN+b;
mesh.addTriangle(a,b,d);
mesh.addTriangle(a,d,c);

how can I remove vertices from this? for exemple the first ones created so i can get the tube runing endlessly?
(this is taken from the book Mastering openFrameworks: Creative Coding Demystified , drawing 3d twisting knot)

now for texture coordinates, imagine i want to texture some hand made geometry and i want to apply a texture in the model, and then modify the texture coordinates to manipulate the position of the texture in the model, how do i do that? I cant understand how to give coordinates to vertices of parts that are not the picture, hope you guys understand.

Thanks, Roger.

Can anyone give me a hint please?

Roger

You can remove vertices using:

myMesh.removeVertex(indexToRemove);

In terms of you texCoords, you just need to add one for every vertex in the mesh. You can then adjust them like so:

myMesh.setTextCoord(index, ofVec3f(newX, newY, newZ));

or

ofVec3f vec = &myMesh.getTexCoord(index);
vec->x = newX;
vec->y = newY;
vec->z = newZ;

I’d recommend having a good look through this if you haven’t already? - http://openframeworks.cc/tutorials/graphics/opengl.html

thanks mate.

still have some questions. maybe i wasn’t clear enough :stuck_out_tongue:

how do I figure whitch indexes i should remove.

for example:

i want to remove vertice v1, i have to remove the 3 indexes right? how do I find them out?

now for the vertice coordinates, maping a texture from 0 to 1.

how should i define a texture coordinate when the vertice is out of the texture?

v1-----------------v2

---------------------
-------------…
-------------…

v3-----------…v4
the texture is in the dots, the dashes are empty. How do I map v1 v2 and v3?
even better how to map just one face of ofbox?

Thanks, Roger.

If you remove the vertex it would probably be best to clear the indices and re-enter them though. ofMesh::removeVertex() uses the erase method which will close the gap in the vertex array (you will have [0,2,3] instead of [0,1,2,3]). This will mean all your indices that connect vertices above the index you removed will be incorrect. Unless of course you loop through the indices and correct them.

Maybe it would be better to keep the vertices consistent and just redraw the indices whenever you want a vertex to seem to have disappeared.

quickly (and not sure if it’s helpful) theres a function in this addon:

to take a non indexed mesh and make it use indicies.

yeah, its silly that i didn’t thought of that, thanks. My problem was really on restructuring the indices so that should work well.

@zach thanks will look into it!

I’ll do some experimentation with tex coords this afternoon, if I have time.
I will probably come with more questions after that :stuck_out_tongue:

thanks alot! Roger

hi again guys.

so tryed the texture thing.
http://imgur.com/LNlSDN6

so what i get from this is that i have to create each face independent of the others for this to work?
I tryed some clamping, but it did not help.

Ok so I think using 2 separate meshes is ok for what I want.

I tryed doing the mesh with the faces as islands but i would have to give texcoords to the other faces aswell, so doing 2 completly independent meshes works the best.
http://imgur.com/JcAb2av

ofVboMesh mesh;
ofVboMesh front;

//bot face vertices

mesh.addVertex(ofVec3f(0,0,0)*scale);//0
mesh.addVertex(ofVec3f(1,0,0)*scale);//1
mesh.addVertex(ofVec3f(1,0,-1)*scale);//2
mesh.addVertex(ofVec3f(0,0,-1)*scale);//3
//top face vertices
mesh.addVertex(ofVec3f(0,1,0)*scale);//4
mesh.addVertex(ofVec3f(1,1,0)*scale);//5
mesh.addVertex(ofVec3f(1,1,-1)*scale);//6	
mesh.addVertex(ofVec3f(0,1,-1)*scale);//7

//front face vertices
front.addVertex(ofVec3f(0,0,0)*scale);//0
front.addTexCoord(ofVec2f(0,0));
front.addVertex(ofVec3f(1,0,0)*scale);//1
front.addTexCoord(ofVec2f(0,1));
front.addVertex(ofVec3f(1,1,0)*scale);//2
front.addTexCoord(ofVec2f(1,1));
front.addVertex(ofVec3f(0,1,0)*scale);//3
front.addTexCoord(ofVec2f(1,0));

//front
front.addTriangle(0,1,2);
front.addTriangle(2,3,0); 

//bot
mesh.addTriangle(0,1,2);
mesh.addTriangle(2,3,0);
//top	
mesh.addTriangle(4,5,6);
mesh.addTriangle(6,7,4);	
//back
mesh.addTriangle(3,2,6);
mesh.addTriangle(6,7,3);
//right
mesh.addTriangle(1,2,6);
mesh.addTriangle(6,5,1);
//left
mesh.addTriangle(0,3,7);
mesh.addTriangle(7,4,0);

Btw I’m using ofVboMesh here, but I dont really know if its better or not, I supose it is, since i’m not moving the vertices that much (going to use oftranslate/rotate so these cubes are going to stay on model space), but i’m going to have a few of them, but my hardware is not able to do instancing(i think, atleast the example does not work, and says its 'cos of that).
What do you guys think about this?