Texture mapping an ofMesh from a model

I’ve been searching tutorials, this forum, books the entire day on how to texture map an ofMesh but I haven’t found anything much beyond simple 4 vertex planes or unanswered questions…
I’m loading a model using ofxAssimpModelLoader which I then get into an ofMesh (I want to deform the model at a later stage).
I want to texture this mesh using the image from a webcam but I can’t figure out where to start…

So far I’ve got the model into an ofMesh instance, the camera/texture up and running , but I don’t understand how I get that texture onto the mesh…?

Hi -
I’m struggling with the same thing right now. Actually - maybe even more straightforward: I have a model (obj) with a working texture, which I’m simply trying to alter (change colors, etc.). I’m wondering if you were able to solve the issue? There’s really little info out there on how to do this.

I just figured this out.
If the model comes with texture coords already, you need to call ofDisableArbTex(); since those coords are normalized (0-1 percentages of the texture dimensions) rather than pixel dimensions.
Otherwise oF will read the coordinates as all being within the first pixel of the texture, since they’re all between 0 and 1.

A good way to do what you want might be to take a sample image from your webcam, and wrap the model in that texture using your modeling software. Then export the model with the texture so you have the texture coordinates imported into oF. Then in oF you can do:

ofDisableArbTex();
ofMesh mesh = model.getMesh(0); // or whichever mesh index you want if you have more than one mesh
// now get your custom texture and bind it
vidGrabber.getTexture().bind();
mesh.drawFaces();
vidGrabber.getTexture().unbind();

Your live webcam image should replace the texture you used in the modeling software, but use the same texture coordinates.

1 Like