Browse Source

Merge pull request #6560 from TrevorDev/clothFixes

remove softbody when the impostor is soft, provide warning when impos…
David Catuhe 6 years ago
parent
commit
856450dd6b

+ 1 - 0
dist/preview release/what's new.md

@@ -89,6 +89,7 @@
 - Cannon and Ammo forceUpdate will no longer cause an unexpected exception ([TrevorDev](https://github.com/TrevorDev))
 - Loading the same multi-material twice and disposing one should not impact the other ([TrevorDev](https://github.com/TrevorDev))
 - GLTF loader should now preserve the texture naming ([Drigax](https://github.com/Drigax))
+- Avoid exception when disposing of Ammo cloth physics ([TrevorDev](https://github.com/TrevorDev))
 
 ## Breaking changes
 - Setting mesh.scaling to a new vector will no longer automatically call forceUpdate (this should be done manually when needed) ([TrevorDev](https://github.com/TrevorDev))

+ 5 - 1
src/Physics/Plugins/ammoJSPlugin.ts

@@ -462,7 +462,11 @@ export class AmmoJSPlugin implements IPhysicsEnginePlugin {
      */
     public removePhysicsBody(impostor: PhysicsImpostor) {
         if (this.world) {
-            this.world.removeRigidBody(impostor.physicsBody);
+            if (impostor.soft) {
+                this.world.removeSoftBody(impostor.physicsBody);
+            }else {
+                this.world.removeRigidBody(impostor.physicsBody);
+            }
 
             if (impostor._pluginData) {
                 impostor._pluginData.toDispose.forEach((d: any) => {

+ 3 - 0
src/Physics/physicsImpostor.ts

@@ -441,6 +441,9 @@ export class PhysicsImpostor {
             Logger.Error("No object was provided. A physics object is obligatory");
             return;
         }
+        if (this.object.parent && _options.mass !== 0) {
+            Logger.Warn("A physics impostor has been created for an object which has a parent. Babylon physics currently works in local space so unexpected issues may occur.");
+        }
 
         // Legacy support for old syntax.
         if (!this._scene && object.getScene) {