Pārlūkot izejas kodu

update with regard to soft bodies

Guide 6 gadi atpakaļ
vecāks
revīzija
3227d256c0
2 mainītis faili ar 32 papildinājumiem un 9 dzēšanām
  1. 0 1
      src/Physics/physicsEngine.ts
  2. 32 8
      src/Physics/physicsImpostor.ts

+ 0 - 1
src/Physics/physicsEngine.ts

@@ -33,7 +33,6 @@ export class PhysicsEngine implements IPhysicsEngine {
 
     /**
      * Creates a new Physics Engine
-     * Only AmmoJSPlugin allows soft bodies
      * @param gravity defines the gravity vector used by the simulation
      * @param _physicsPlugin defines the plugin to use (CannonJS by default)
      */

+ 32 - 8
src/Physics/physicsImpostor.ts

@@ -263,82 +263,106 @@ export class PhysicsImpostor {
     }
 
     /**
-     * Gets the pressure
+     * Gets the pressure of a soft body; only supported by the AmmoJSPlugin
      */
     get pressure(): number {
         if (!this._physicsEngine) {
             return 0;
         }
+        if (!this._physicsEngine.getPhysicsPlugin().getBodyPressure) {
+            return 0;
+        }
         return this._physicsEngine.getPhysicsPlugin().getBodyPressure!(this);
     }
 
     /**
-     * Sets pressure
+     * Sets the pressure of a soft body; only supported by the AmmoJSPlugin
      */
     set pressure(value: number) {
         if (!this._physicsEngine) {
             return;
         }
+        if (!this._physicsEngine.getPhysicsPlugin().setBodyPressure) {
+            return;
+        }
         this._physicsEngine.getPhysicsPlugin().setBodyPressure!(this, value);
     }
 
     /**
-     * Gets the stiffness
+     * Gets the stiffness of a soft body; only supported by the AmmoJSPlugin
      */
     get stiffness(): number {
         if (!this._physicsEngine) {
             return 0;
         }
+        if (!this._physicsEngine.getPhysicsPlugin().getBodyStiffness) {
+            return 0;
+        }
         return this._physicsEngine.getPhysicsPlugin().getBodyStiffness!(this);
     }
 
     /**
-     * Sets the stiffness
+     * Sets the stiffness of a soft body; only supported by the AmmoJSPlugin
      */
     set stiffness(value: number) {
         if (!this._physicsEngine) {
             return;
         }
+        if (!this._physicsEngine.getPhysicsPlugin().setBodyStiffness) {
+            return;
+        }
         this._physicsEngine.getPhysicsPlugin().setBodyStiffness!(this, value);
     }
 
     /**
-     * Gets the velocityIterations
+     * Gets the velocityIterations of a soft body; only supported by the AmmoJSPlugin
      */
     get velocityIterations(): number {
         if (!this._physicsEngine) {
             return 0;
         }
+        if (!this._physicsEngine.getPhysicsPlugin().getBodyVelocityIterations) {
+            return 0;
+        }
         return this._physicsEngine.getPhysicsPlugin().getBodyVelocityIterations!(this);
     }
 
     /**
-     * Sets the velocityIterations
+     * Sets the velocityIterations of a soft body; only supported by the AmmoJSPlugin
      */
     set velocityIterations(value: number) {
         if (!this._physicsEngine) {
             return;
         }
+        if (!this._physicsEngine.getPhysicsPlugin().setBodyVelocityIterations) {
+            return;
+        }
         this._physicsEngine.getPhysicsPlugin().setBodyVelocityIterations!(this, value);
     }
 
     /**
-     * Gets the positionIterations
+     * Gets the positionIterations of a soft body; only supported by the AmmoJSPlugin
      */
     get positionIterations(): number {
         if (!this._physicsEngine) {
             return 0;
         }
+        if (!this._physicsEngine.getPhysicsPlugin().getBodyPositionIterations) {
+            return 0;
+        }
         return this._physicsEngine.getPhysicsPlugin().getBodyPositionIterations!(this);
     }
 
     /**
-     * Sets the positionIterations
+     * Sets the positionIterations of a soft body; only supported by the AmmoJSPlugin
      */
     set positionIterations(value: number) {
         if (!this._physicsEngine) {
             return;
         }
+        if (!this._physicsEngine.getPhysicsPlugin().setBodyPositionIterations) {
+            return;
+        }
         this._physicsEngine.getPhysicsPlugin().setBodyPositionIterations!(this, value);
     }