Texturing cloth mesh with OfxBullet addon

Hello!

I have been aiming to create a cloth simulation with my own images. I decided to use the OfxBullet addon (https://github.com/NickHardeman/ofxBullet) because it has a cloth example.

This is what happens when I apply a texture to the cloth mesh using a shader: https://streamable.com/t35vy3

I think the texcoords of the mesh is not being passed into the shader properly, so the texture doesn’t actually look as if its applied onto the mesh.

Here is my code: https://github.com/deliriouspointblanc/Batik-Cloth-Simulation/tree/master/test_ofxBullet_cloth

I have tried doing getMesh.getTexCoords(); but it doesn’t work. Many examples using ofMesh add the texcoords manually, but because this is wrapped up in an addon, that stuff is done for me already. I have passed textures into shaders before, but not like this.

Any pointers and hints will be really helpful, thank you!

So I got in touch with Nick, who created the ofxBullet addon and he helped me out with this issue!

This is what he said:

I found this function that should help

https://github.com/NickHardeman/ofxBullet/blob/master/src/shapes/ofxBulletPatch.h#L25

// try something like:
for( int i = 0; i < patches.size(); i++ ) {
	ofMesh& pmesh = patches[i]->getMesh();
	// maps the tex coords from 0 - 1 
	patches[i]->updateMeshTexCoords( pmesh );
        pmesh.draw(); //drawWireframe
   }

Problem solved!