David Catuhe 7 years ago
parent
commit
053b6baf0b

File diff suppressed because it is too large
+ 7657 - 7493
Playground/babylon.d.txt


File diff suppressed because it is too large
+ 7675 - 7511
dist/preview release/babylon.d.ts


File diff suppressed because it is too large
+ 1 - 1
dist/preview release/babylon.js


File diff suppressed because it is too large
+ 583 - 359
dist/preview release/babylon.max.js


File diff suppressed because it is too large
+ 583 - 359
dist/preview release/babylon.no-module.max.js


File diff suppressed because it is too large
+ 1 - 1
dist/preview release/babylon.worker.js


File diff suppressed because it is too large
+ 585 - 361
dist/preview release/es6.js


File diff suppressed because it is too large
+ 1 - 1
dist/preview release/inspector/babylon.inspector.bundle.js


File diff suppressed because it is too large
+ 1 - 1
dist/preview release/inspector/babylon.inspector.bundle.js.map


+ 2 - 16
dist/preview release/typedocValidationBaseline.json

@@ -1,7 +1,7 @@
 {
-  "errors": 3752,
+  "errors": 3750,
   "babylon.typedoc.json": {
-    "errors": 3752,
+    "errors": 3750,
     "AnimationGroup": {
       "Constructor": {
         "new AnimationGroup": {
@@ -10925,13 +10925,6 @@
         }
       }
     },
-    "PlaySoundAction": {
-      "Class": {
-        "Comments": {
-          "MissingText": true
-        }
-      }
-    },
     "PointerDragBehavior": {
       "Method": {
         "releaseDrag": {
@@ -15744,13 +15737,6 @@
         }
       }
     },
-    "StopSoundAction": {
-      "Class": {
-        "Comments": {
-          "MissingText": true
-        }
-      }
-    },
     "StringDictionary": {
       "Property": {
         "count": {

File diff suppressed because it is too large
+ 2 - 2
dist/preview release/viewer/babylon.viewer.js


File diff suppressed because it is too large
+ 2 - 2
dist/preview release/viewer/babylon.viewer.max.js


+ 1 - 57
src/Mesh/babylon.abstractMesh.ts

@@ -463,12 +463,6 @@
          */
         public actionManager: Nullable<ActionManager> = null;
 
-        /**
-         * Gets or sets impostor used for physic simulation
-         * @see http://doc.babylonjs.com/features/physics_engine
-         */
-        public physicsImpostor: Nullable<PhysicsImpostor> = null;
-
         // Collisions
         private _checkCollisions = false;
         private _collisionMask = -1;
@@ -1173,15 +1167,6 @@
         }
 
         /**
-         * Gets the current physics impostor
-         * @see http://doc.babylonjs.com/features/physics_engine
-         * @returns a physics impostor or null
-         */
-        public getPhysicsImpostor(): Nullable<PhysicsImpostor> {
-            return this.physicsImpostor;
-        }
-
-        /**
          * Gets the position of the current mesh in camera space
          * @param camera defines the camera to use
          * @returns a position
@@ -1204,43 +1189,7 @@
                 camera = (<Camera>this.getScene().activeCamera);
             }
             return this.absolutePosition.subtract(camera.position).length();
-        }
-
-        /**
-         * Apply a physic impulse to the mesh 
-         * @param force defines the force to apply
-         * @param contactPoint defines where to apply the force
-         * @returns the current mesh
-         * @see http://doc.babylonjs.com/how_to/using_the_physics_engine
-         */
-        public applyImpulse(force: Vector3, contactPoint: Vector3): AbstractMesh {
-            if (!this.physicsImpostor) {
-                return this;
-            }
-            this.physicsImpostor.applyImpulse(force, contactPoint);
-            return this;
-        }
-
-        /**
-         * Creates a physic joint between two meshes
-         * @param otherMesh defines the other mesh to use
-         * @param pivot1 defines the pivot to use on this mesh
-         * @param pivot2 defines the pivot to use on the other mesh
-         * @param options defines additional options (can be plugin dependent)
-         * @returns the current mesh
-         * @see https://www.babylonjs-playground.com/#0BS5U0#0
-         */
-        public setPhysicsLinkWith(otherMesh: Mesh, pivot1: Vector3, pivot2: Vector3, options?: any): AbstractMesh {
-            if (!this.physicsImpostor || !otherMesh.physicsImpostor) {
-                return this;
-            }
-            this.physicsImpostor.createJoint(otherMesh.physicsImpostor, PhysicsJoint.HingeJoint, {
-                mainPivot: pivot1,
-                connectedPivot: pivot2,
-                nativeParams: options
-            });
-            return this;
-        }
+        }    
 
         // Collisions
 
@@ -1485,11 +1434,6 @@
             // Skeleton
             this._skeleton = null;
 
-            // Physics
-            if (this.physicsImpostor) {
-                this.physicsImpostor.dispose(/*!doNotRecurse*/);
-            }
-
             // Intersections in progress
             for (index = 0; index < this._intersectionsInProgress.length; index++) {
                 var other = this._intersectionsInProgress[index];

+ 113 - 0
src/Physics/babylon.physicsEngineComponent.ts

@@ -121,6 +121,119 @@ module BABYLON {
             this.onAfterPhysicsObservable.notifyObservers(this);
         }
     }
+
+    export interface AbstractMesh {       
+        /** @hidden */
+        _physicsImpostor: Nullable<PhysicsImpostor>;
+
+        /**
+         * Gets or sets impostor used for physic simulation
+         * @see http://doc.babylonjs.com/features/physics_engine
+         */
+        physicsImpostor: Nullable<PhysicsImpostor>;
+
+        /**
+         * Gets the current physics impostor
+         * @see http://doc.babylonjs.com/features/physics_engine
+         * @returns a physics impostor or null
+         */
+        getPhysicsImpostor(): Nullable<PhysicsImpostor>;
+
+        /** Apply a physic impulse to the mesh 
+         * @param force defines the force to apply
+         * @param contactPoint defines where to apply the force
+         * @returns the current mesh
+         * @see http://doc.babylonjs.com/how_to/using_the_physics_engine
+         */
+        applyImpulse(force: Vector3, contactPoint: Vector3): AbstractMesh;
+
+        /**
+         * Creates a physic joint between two meshes
+         * @param otherMesh defines the other mesh to use
+         * @param pivot1 defines the pivot to use on this mesh
+         * @param pivot2 defines the pivot to use on the other mesh
+         * @param options defines additional options (can be plugin dependent)
+         * @returns the current mesh
+         * @see https://www.babylonjs-playground.com/#0BS5U0#0
+         */
+        setPhysicsLinkWith(otherMesh: Mesh, pivot1: Vector3, pivot2: Vector3, options?: any): AbstractMesh;
+
+        /** @hidden */
+        _disposePhysicsObserver: Nullable<Observer<Node>>;
+    }
+
+    Object.defineProperty(AbstractMesh.prototype, "physicsImpostor", {
+        get: function (this:AbstractMesh) {
+            return this._physicsImpostor;
+        },
+        set: function(this:AbstractMesh, value: Nullable<PhysicsImpostor>) {
+            if (this._physicsImpostor === value) {
+                return;
+            }
+            if (this._disposePhysicsObserver) {
+                this.onDisposeObservable.remove(this._disposePhysicsObserver);
+            }
+
+            this._physicsImpostor = value;
+
+            if (value) {
+                this._disposePhysicsObserver = this.onDisposeObservable.add(() => {
+                    // Physics
+                    if (this.physicsImpostor) {
+                        this.physicsImpostor.dispose(/*!doNotRecurse*/);
+                        this.physicsImpostor = null;
+                    }
+                });
+            }
+        },
+        enumerable: true,
+        configurable: true
+    });
+
+    /**
+     * Gets the current physics impostor
+     * @see http://doc.babylonjs.com/features/physics_engine
+     * @returns a physics impostor or null
+     */
+    AbstractMesh.prototype.getPhysicsImpostor = function(): Nullable<PhysicsImpostor> {
+        return this.physicsImpostor;
+    }
+
+    /**
+     * Apply a physic impulse to the mesh 
+     * @param force defines the force to apply
+     * @param contactPoint defines where to apply the force
+     * @returns the current mesh
+     * @see http://doc.babylonjs.com/how_to/using_the_physics_engine
+     */
+    AbstractMesh.prototype.applyImpulse = function(force: Vector3, contactPoint: Vector3): AbstractMesh {
+        if (!this.physicsImpostor) {
+            return this;
+        }
+        this.physicsImpostor.applyImpulse(force, contactPoint);
+        return this;
+    }
+
+    /**
+     * Creates a physic joint between two meshes
+     * @param otherMesh defines the other mesh to use
+     * @param pivot1 defines the pivot to use on this mesh
+     * @param pivot2 defines the pivot to use on the other mesh
+     * @param options defines additional options (can be plugin dependent)
+     * @returns the current mesh
+     * @see https://www.babylonjs-playground.com/#0BS5U0#0
+     */
+    AbstractMesh.prototype.setPhysicsLinkWith = function(otherMesh: Mesh, pivot1: Vector3, pivot2: Vector3, options?: any): AbstractMesh {
+        if (!this.physicsImpostor || !otherMesh.physicsImpostor) {
+            return this;
+        }
+        this.physicsImpostor.createJoint(otherMesh.physicsImpostor, PhysicsJoint.HingeJoint, {
+            mainPivot: pivot1,
+            connectedPivot: pivot2,
+            nativeParams: options
+        });
+        return this;
+    }    
    
     /**
      * Defines the physics engine scene component responsible to manage a physics engine