nartc / angular-three

🧊 THREE.js integration for Angular 🧊
https://angular-three.netlify.app/
MIT License
306 stars 26 forks source link

Can't access useBody internal UUID when adding constraints against instance mesh bodies #146

Open IRobot1 opened 2 years ago

IRobot1 commented 2 years ago

Physics bodies can be created against instance meshes. The index can be passed to the body function

  sphereProps = this.physicBody.useParticle((index: number) => ({

Internally, this creates a virtual UUID that's passed to cannon.

However, constraints are missing a way to refer to instance bodies using the virtual UUID. Currently, only non instance bodies are supported.

My guess is a check if objects are InstanceMesh would need to be added here to lookup the internal UUID.

Am I on the right track?

IRobot1 commented 2 years ago

I found NgtCannonUtils.getUUID(ref, index). This could be called like

this.physicConstraint.useDistanceConstraint( NgtCannonUtils.getUUID(instancebody.ref, instanceA), NgtCannonUtils.getUUID(instancebody.ref, instanceB), {});

but unfortunately, there's no useXXXConstraint method that takes two uuid strings. Perhaps there could be a duplicate methods that supports instance body and two indices

useDistanceConstraint(instBody: Ref, indexA: number, indexB: number, optns:...)

The existing private useConstraint could be split up to handle objects or uuids and the new methods could use the uuid version.

Does this seem reasonable?

IRobot1 commented 2 years ago

Created pull request for supporting constraints against instance mesh.

Added variation of physics clump to sandbox examples that limits distance from center using fixed distance constraint using instance bodies.

image