Переглянути джерело

Adding get body function

For those who wish to execute low-level physics changes to the mesh's
physics body - the physics engine now exposes a function that will
return it.
Raanan Weber 9 роки тому
батько
коміт
c4fe99352b

+ 9 - 0
src/Physics/Plugins/babylon.cannonJSPlugin.js

@@ -223,6 +223,15 @@ var BABYLON;
         CannonJSPlugin.prototype.getWorldObject = function () {
         CannonJSPlugin.prototype.getWorldObject = function () {
             return this._world;
             return this._world;
         };
         };
+        CannonJSPlugin.prototype.getPhysicsBodyOfMesh = function (mesh) {
+            for (var index = 0; index < this._registeredMeshes.length; index++) {
+                var registeredMesh = this._registeredMeshes[index];
+                if (registeredMesh.mesh === mesh) {
+                    return registeredMesh.body;
+                }
+            }
+            return null;
+        };
         return CannonJSPlugin;
         return CannonJSPlugin;
     })();
     })();
     BABYLON.CannonJSPlugin = CannonJSPlugin;
     BABYLON.CannonJSPlugin = CannonJSPlugin;

+ 10 - 0
src/Physics/Plugins/babylon.cannonJSPlugin.ts

@@ -291,6 +291,16 @@
         public getWorldObject() : any {
         public getWorldObject() : any {
             return this._world;
             return this._world;
         }
         }
+        
+        public getPhysicsBodyOfMesh(mesh: AbstractMesh) {
+            for (var index = 0; index < this._registeredMeshes.length; index++) {
+                var registeredMesh = this._registeredMeshes[index];
+                if (registeredMesh.mesh === mesh) {
+                    return registeredMesh.body;
+                }
+            }
+            return null;
+        }
     }
     }
 }
 }
 
 

+ 10 - 1
src/Physics/Plugins/babylon.oimoJSPlugin.js

@@ -37,7 +37,7 @@ var BABYLON;
             return value < BABYLON.PhysicsEngine.Epsilon ? BABYLON.PhysicsEngine.Epsilon : value;
             return value < BABYLON.PhysicsEngine.Epsilon ? BABYLON.PhysicsEngine.Epsilon : value;
         };
         };
         OimoJSPlugin.prototype.initialize = function (iterations) {
         OimoJSPlugin.prototype.initialize = function (iterations) {
-            this._world = new OIMO.World();
+            this._world = new OIMO.World(null, null, iterations);
             this._world.clear();
             this._world.clear();
         };
         };
         OimoJSPlugin.prototype.setGravity = function (gravity) {
         OimoJSPlugin.prototype.setGravity = function (gravity) {
@@ -247,6 +247,15 @@ var BABYLON;
         OimoJSPlugin.prototype.getWorldObject = function () {
         OimoJSPlugin.prototype.getWorldObject = function () {
             return this._world;
             return this._world;
         };
         };
+        OimoJSPlugin.prototype.getPhysicsBodyOfMesh = function (mesh) {
+            for (var index = 0; index < this._registeredMeshes.length; index++) {
+                var registeredMesh = this._registeredMeshes[index];
+                if (registeredMesh.mesh === mesh) {
+                    return registeredMesh.body;
+                }
+            }
+            return null;
+        };
         OimoJSPlugin.prototype._getLastShape = function (body) {
         OimoJSPlugin.prototype._getLastShape = function (body) {
             var lastShape = body.shapes;
             var lastShape = body.shapes;
             while (lastShape.next) {
             while (lastShape.next) {

+ 10 - 0
src/Physics/Plugins/babylon.oimoJSPlugin.ts

@@ -311,6 +311,16 @@ module BABYLON {
         public getWorldObject() : any {
         public getWorldObject() : any {
             return this._world;
             return this._world;
         }
         }
+        
+        public getPhysicsBodyOfMesh(mesh: AbstractMesh) {
+            for (var index = 0; index < this._registeredMeshes.length; index++) {
+                var registeredMesh = this._registeredMeshes[index];
+                if (registeredMesh.mesh === mesh) {
+                    return registeredMesh.body;
+                }
+            }
+            return null;
+        }
 
 
         private _getLastShape(body: any): any {
         private _getLastShape(body: any): any {
             var lastShape = body.shapes;
             var lastShape = body.shapes;

+ 3 - 0
src/Physics/babylon.physicsEngine.js

@@ -45,6 +45,9 @@ var BABYLON;
         PhysicsEngine.prototype.isSupported = function () {
         PhysicsEngine.prototype.isSupported = function () {
             return this._currentPlugin.isSupported();
             return this._currentPlugin.isSupported();
         };
         };
+        PhysicsEngine.prototype.getPhysicsBodyOfMesh = function (mesh) {
+            return this._currentPlugin.getPhysicsBodyOfMesh(mesh);
+        };
         // Statics
         // Statics
         PhysicsEngine.NoImpostor = 0;
         PhysicsEngine.NoImpostor = 0;
         PhysicsEngine.SphereImpostor = 1;
         PhysicsEngine.SphereImpostor = 1;

+ 5 - 0
src/Physics/babylon.physicsEngine.ts

@@ -12,6 +12,7 @@
         isSupported(): boolean;
         isSupported(): boolean;
         updateBodyPosition(mesh: AbstractMesh): void;
         updateBodyPosition(mesh: AbstractMesh): void;
         getWorldObject() : any; //Will return the physics world object of the engine used.
         getWorldObject() : any; //Will return the physics world object of the engine used.
+        getPhysicsBodyOfMesh(mesh: AbstractMesh) : any;
     }
     }
 
 
     export interface PhysicsBodyCreationOptions {
     export interface PhysicsBodyCreationOptions {
@@ -85,6 +86,10 @@
         public isSupported(): boolean {
         public isSupported(): boolean {
             return this._currentPlugin.isSupported();
             return this._currentPlugin.isSupported();
         }
         }
+        
+        public getPhysicsBodyOfMesh(mesh: AbstractMesh) {
+            return this._currentPlugin.getPhysicsBodyOfMesh(mesh);
+        }
 
 
         // Statics
         // Statics
         public static NoImpostor = 0;
         public static NoImpostor = 0;