diff --git a/examples/jsm/physics/RapierPhysics.js b/examples/jsm/physics/RapierPhysics.js index f2c7fa3af3d32e..09761d94f8f9d1 100644 --- a/examples/jsm/physics/RapierPhysics.js +++ b/examples/jsm/physics/RapierPhysics.js @@ -281,6 +281,20 @@ async function RapierPhysics() { } + function applyImpulse( mesh, impulse, index = 0 ) { + + let { body } = meshMap.get( mesh ); + + if ( mesh.isInstancedMesh ) { + + body = body[ index ]; + + } + + body.applyImpulse( impulse, true ); + + } + function addHeightfield( mesh, width, depth, heights, scale ) { const shape = RAPIER.ColliderDesc.heightfield( width, depth, heights, scale ); @@ -414,7 +428,7 @@ async function RapierPhysics() { /** * Adds a heightfield terrain to the physics simulation. - * + * * @method * @name RapierPhysics#addHeightfield * @param {Mesh} mesh - The Three.js mesh representing the terrain. @@ -427,7 +441,18 @@ async function RapierPhysics() { * @param {number} scale.z - Scale factor for depth. * @returns {RigidBody} The created Rapier rigid body for the heightfield. */ - addHeightfield: addHeightfield + addHeightfield: addHeightfield, + + /** + * Applies an impulse to the given mesh which is part of the physics simulation. + * + * @method + * @name RapierPhysics#applyImpulse + * @param {Mesh} mesh - The mesh to apply the impulse to. + * @param {Vector3} impulse - The impulse to apply. + * @param {number} [index=0] - If the mesh is instanced, the index represents the instanced ID. + */ + applyImpulse: applyImpulse }; diff --git a/examples/physics_rapier_instancing.html b/examples/physics_rapier_instancing.html index 4a8cf2e5f09e42..b98267cdb02f5f 100644 --- a/examples/physics_rapier_instancing.html +++ b/examples/physics_rapier_instancing.html @@ -9,7 +9,8 @@
- three.js physics - rapier instancing + three.js physics - rapier instancing
+