|
|
@@ -1,6 +1,6 @@
|
|
|
import { Clock, Vector3, Quaternion, Matrix4 } from 'three';
|
|
|
|
|
|
-const RAPIER_PATH = 'https://cdn.skypack.dev/@dimforge/rapier3d-compat@0.12.0';
|
|
|
+const RAPIER_PATH = 'https://cdn.skypack.dev/@dimforge/rapier3d-compat@0.17.3';
|
|
|
|
|
|
const frameRate = 60;
|
|
|
|
|
|
@@ -149,6 +149,39 @@ async function RapierPhysics() {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ function removeMesh( mesh ) {
|
|
|
+
|
|
|
+ const index = meshes.indexOf( mesh );
|
|
|
+
|
|
|
+ if ( index !== - 1 ) {
|
|
|
+
|
|
|
+ meshes.splice( index, 1 );
|
|
|
+ meshMap.delete( mesh );
|
|
|
+
|
|
|
+ if ( ! mesh.userData.physics ) return;
|
|
|
+
|
|
|
+ const body = mesh.userData.physics.body;
|
|
|
+
|
|
|
+ if ( ! body ) return;
|
|
|
+
|
|
|
+ if ( Array.isArray( body ) ) {
|
|
|
+
|
|
|
+ for ( let i = 0; i < body.length; i ++ ) {
|
|
|
+
|
|
|
+ world.removeRigidBody( body[ i ] );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ world.removeRigidBody( body );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
function createInstancedBody( mesh, mass, shape ) {
|
|
|
|
|
|
const array = mesh.instanceMatrix.array;
|
|
|
@@ -306,6 +339,15 @@ async function RapierPhysics() {
|
|
|
*/
|
|
|
addMesh: addMesh,
|
|
|
|
|
|
+ /**
|
|
|
+ * Removes the given mesh from this physics simulation.
|
|
|
+ *
|
|
|
+ * @method
|
|
|
+ * @name RapierPhysics#removeMesh
|
|
|
+ * @param {Mesh} mesh The mesh to remove.
|
|
|
+ */
|
|
|
+ removeMesh: removeMesh,
|
|
|
+
|
|
|
/**
|
|
|
* Set the position of the given mesh which is part of the physics simulation. Calling this
|
|
|
* method will reset the current simulated velocity of the mesh.
|