|
|
@@ -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
|
|
|
|
|
|
};
|
|
|
|