angular-three icon indicating copy to clipboard operation
angular-three copied to clipboard

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

Open IRobot1 opened this issue 3 years ago • 2 comments

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 avatar Aug 19 '22 23:08 IRobot1

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<TObjectA>, 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 avatar Aug 20 '22 01:08 IRobot1

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

IRobot1 avatar Aug 20 '22 16:08 IRobot1