Parcourir la source

Merge pull request #1065 from RaananW/fix-physics-cloning

Code moved from clone but object reference is the same.
David Catuhe il y a 9 ans
Parent
commit
1ed27f4274
2 fichiers modifiés avec 12 ajouts et 3 suppressions
  1. 4 3
      src/Mesh/babylon.mesh.ts
  2. 8 0
      src/Physics/babylon.physicsImpostor.ts

+ 4 - 3
src/Mesh/babylon.mesh.ts

@@ -161,10 +161,11 @@
                 }
 
                 // Physics clone  
-                if (clonePhysicsImpostor && this.getScene().getPhysicsEngine()) {
-                    var impostor = this.getScene().getPhysicsEngine().getImpostorForPhysicsObject(this);
+                var physicsEngine = this.getScene().getPhysicsEngine();
+                if (clonePhysicsImpostor && physicsEngine) {
+                    var impostor = physicsEngine.getImpostorForPhysicsObject(mesh);
                     if (impostor) {
-                        mesh.physicsImpostor = impostor.clone(mesh);
+                        this.physicsImpostor = impostor.clone(this);
                     }
                 }  
 

+ 8 - 0
src/Physics/babylon.physicsImpostor.ts

@@ -50,6 +50,13 @@ module BABYLON {
         }>;
 
         constructor(public object: IPhysicsEnabledObject, public type: number, private _options: PhysicsImpostorParameters = { mass: 0 }, private _scene?: Scene) {
+
+            //sanity check!
+            if (!this.object) {
+                Tools.Error("No object was provided. A physics object is obligatory");
+                return;
+            }
+
             //legacy support for old syntax.
             if (!this._scene && object.getScene) {
                 this._scene = object.getScene()
@@ -379,6 +386,7 @@ module BABYLON {
         }
 
         public clone(newObject: IPhysicsEnabledObject) {
+            if (!newObject) return null;
             return new PhysicsImpostor(newObject, this.type, this._options, this._scene);
         }