|
|
@@ -54,6 +54,19 @@ function getShape( geometry ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @classdesc Can be used to include Rapier as a Physics engine into
|
|
|
+ * `three.js` apps. The API can be initialized via:
|
|
|
+ * ```js
|
|
|
+ * const physics = await RapierPhysics();
|
|
|
+ * ```
|
|
|
+ * The component automatically imports Rapier from a CDN so make sure
|
|
|
+ * to use the component with an active Internet connection.
|
|
|
+ *
|
|
|
+ * @name RapierPhysics
|
|
|
+ * @class
|
|
|
+ * @hideconstructor
|
|
|
+ */
|
|
|
async function RapierPhysics() {
|
|
|
|
|
|
if ( RAPIER === null ) {
|
|
|
@@ -229,9 +242,52 @@ async function RapierPhysics() {
|
|
|
setInterval( step, 1000 / frameRate );
|
|
|
|
|
|
return {
|
|
|
+ /**
|
|
|
+ * Adds the given scene to this physics simulation. Only meshes with a
|
|
|
+ * `physics` object in their {@link Object3D#userData} field will be honored.
|
|
|
+ * The object can be used to store the mass and restitution of the mesh. E.g.:
|
|
|
+ * ```js
|
|
|
+ * box.userData.physics = { mass: 1, restitution: 0 };
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * @method
|
|
|
+ * @name RapierPhysics#addScene
|
|
|
+ * @param {Object3D} scene The scene or any type of 3D object to add.
|
|
|
+ */
|
|
|
addScene: addScene,
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Adds the given mesh to this physics simulation.
|
|
|
+ *
|
|
|
+ * @method
|
|
|
+ * @name RapierPhysics#addMesh
|
|
|
+ * @param {Mesh} mesh The mesh to add.
|
|
|
+ * @param {number} [mass=0] The mass in kg of the mesh.
|
|
|
+ * @param {number} [restitution=0] The restitution/friction of the mesh.
|
|
|
+ */
|
|
|
addMesh: addMesh,
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Set the position of the given mesh which is part of the pyhsics simulation. Calling this
|
|
|
+ * method will reset the current simulated velocity of the mesh.
|
|
|
+ *
|
|
|
+ * @method
|
|
|
+ * @name RapierPhysics#setMeshPosition
|
|
|
+ * @param {Mesh} mesh The mesh to update the position for.
|
|
|
+ * @param {Vector3} position - The new position.
|
|
|
+ * @param {number} [index=0] - If the mesh is instanced, the index represents the instanced ID.
|
|
|
+ */
|
|
|
setMeshPosition: setMeshPosition,
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Set the velocity of the given mesh which is part of the pyhsics simulation.
|
|
|
+ *
|
|
|
+ * @method
|
|
|
+ * @name RapierPhysics#setMeshVelocity
|
|
|
+ * @param {Mesh} mesh The mesh to update the velocity for.
|
|
|
+ * @param {Vector3} velocity - The new velocity.
|
|
|
+ * @param {number} [index=0] - If the mesh is instanced, the index represents the instanced ID.
|
|
|
+ */
|
|
|
setMeshVelocity: setMeshVelocity
|
|
|
};
|
|
|
|