notrabs / use-ammojs

ammo.js physics for use with react-three-fiber
MIT License
46 stars 9 forks source link

Cloth simulation #5

Open DrRonne opened 2 years ago

DrRonne commented 2 years ago

Hi, first of all, this looks like an amazing project and would very much like to use it. As the title suggests, I'd like to use it for some cloth simulation. I saw an example of Ammo.js with some cloth and it looks very nice: https://threejs.org/examples/?q=cloth#physics_ammo_cloth I would like to create something similar in react, but I'm unsure if this project is already fit for such purpose. A nudge in the right direction here would be immensily appreciated!

Thanks in advance!

notrabs commented 2 years ago

Hi @DrRonne ,

this should already be possible. The cloth in the example is implemented as a "SoftBody" in ammojs. The three example uses a specific helper ("CreatePatch") to create the mesh, which use-ammmojs doesn't expose directly yet. Instead arbitrary Meshes can be passed (example) and the result should be identical if you pass in a subdivided plane yourself.

Only caveat is that Textures don't work yet. There's some work to be done to match and map the UV coordinates correctly into the physics buffers in the worker thread.

Attachment points are also demonstrated here.

Hope that helps

DrRonne commented 2 years ago

Hi, I'm sorry for being late to respond. I did manage to get it working. I would like to have some textures on it as well though. Is there already a plan on implementing this? If needed/wanted, I could perhaps try this as well. Not yet very familiar with the source code here though.