瀏覽代碼

OimoPlugin and refactoring

Raanan Weber 9 年之前
父節點
當前提交
a49f848998

+ 21 - 13
src/Mesh/babylon.abstractMesh.js

@@ -163,8 +163,8 @@ var BABYLON;
             },
             set: function (newScaling) {
                 this._scaling = newScaling;
-                if (this.physicImpostor) {
-                    this.physicImpostor.forceUpdate();
+                if (this.physicsImpostor) {
+                    this.physicsImpostor.forceUpdate();
                 }
             },
             enumerable: true,
@@ -485,6 +485,14 @@ var BABYLON;
             // Scaling
             BABYLON.Matrix.ScalingToRef(this.scaling.x * this.scalingDeterminant, this.scaling.y * this.scalingDeterminant, this.scaling.z * this.scalingDeterminant, BABYLON.Tmp.Matrix[1]);
             // Rotation
+            //rotate, if quaternion is set and rotation was used
+            if (this.rotationQuaternion) {
+                var len = this.rotation.length();
+                if (len) {
+                    this.rotationQuaternion.multiplyInPlace(BABYLON.Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z));
+                    this.rotation.copyFromFloats(0, 0, 0);
+                }
+            }
             if (this.rotationQuaternion) {
                 this.rotationQuaternion.toRotationMatrix(BABYLON.Tmp.Matrix[0]);
                 this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion);
@@ -674,28 +682,28 @@ var BABYLON;
          *  @Deprecated. Use new PhysicsImpostor instead.
          * */
         AbstractMesh.prototype.setPhysicsState = function (impostor, options) {
-            this.physicImpostor = new BABYLON.PhysicsImpostor(this, impostor, options);
+            this.physicsImpostor = new BABYLON.PhysicsImpostor(this, impostor, options);
         };
         AbstractMesh.prototype.getPhysicsImpostor = function () {
-            return this.physicImpostor;
+            return this.physicsImpostor;
         };
         /**
          * @Deprecated. Use getPhysicsImpostor().getParam("mass");
          */
         AbstractMesh.prototype.getPhysicsMass = function () {
-            return this.physicImpostor.getParam("mass");
+            return this.physicsImpostor.getParam("mass");
         };
         /**
          * @Deprecated. Use getPhysicsImpostor().getParam("friction");
          */
         AbstractMesh.prototype.getPhysicsFriction = function () {
-            return this.physicImpostor.getParam("friction");
+            return this.physicsImpostor.getParam("friction");
         };
         /**
          * @Deprecated. Use getPhysicsImpostor().getParam("restitution");
          */
         AbstractMesh.prototype.getPhysicsRestitution = function () {
-            return this.physicImpostor.getParam("resitution");
+            return this.physicsImpostor.getParam("resitution");
         };
         AbstractMesh.prototype.getPositionInCameraSpace = function (camera) {
             if (!camera) {
@@ -710,16 +718,16 @@ var BABYLON;
             return this.absolutePosition.subtract(camera.position).length();
         };
         AbstractMesh.prototype.applyImpulse = function (force, contactPoint) {
-            if (!this.physicImpostor) {
+            if (!this.physicsImpostor) {
                 return;
             }
-            this.physicImpostor.applyImpulse(force, contactPoint);
+            this.physicsImpostor.applyImpulse(force, contactPoint);
         };
         AbstractMesh.prototype.setPhysicsLinkWith = function (otherMesh, pivot1, pivot2, options) {
-            if (!this.physicImpostor || !otherMesh.physicImpostor) {
+            if (!this.physicsImpostor || !otherMesh.physicsImpostor) {
                 return;
             }
-            this.physicImpostor.createJoint(otherMesh.physicImpostor, BABYLON.PhysicsJoint.HingeJoint, {
+            this.physicsImpostor.createJoint(otherMesh.physicsImpostor, BABYLON.PhysicsJoint.HingeJoint, {
                 mainPivot: pivot1,
                 connectedPivot: pivot2
             });
@@ -911,8 +919,8 @@ var BABYLON;
             // Animations
             this.getScene().stopAnimation(this);
             // Physics
-            if (this.physicImpostor) {
-                this.physicImpostor.dispose(!doNotRecurse);
+            if (this.physicsImpostor) {
+                this.physicsImpostor.dispose(!doNotRecurse);
             }
             // Intersections in progress
             for (index = 0; index < this._intersectionsInProgress.length; index++) {

+ 14 - 14
src/Mesh/babylon.abstractMesh.ts

@@ -69,7 +69,7 @@
         public alwaysSelectAsActiveMesh = false;
 
         // Physics
-        public physicImpostor: BABYLON.PhysicsImpostor;
+        public physicsImpostor: BABYLON.PhysicsImpostor;
         //Deprecated, Legacy support
         public onPhysicsCollide: (collidedMesh: AbstractMesh, contact: any) => void; 
 
@@ -174,8 +174,8 @@
 
         public set scaling(newScaling: Vector3) {
             this._scaling = newScaling;
-            if (this.physicImpostor) {
-                this.physicImpostor.forceUpdate();
+            if (this.physicsImpostor) {
+                this.physicsImpostor.forceUpdate();
             }
         }
 
@@ -772,32 +772,32 @@
          *  @Deprecated. Use new PhysicsImpostor instead.
          * */
         public setPhysicsState(impostor?: any, options?: PhysicsImpostorParameters): any {
-            this.physicImpostor = new PhysicsImpostor(this, impostor, options);
+            this.physicsImpostor = new PhysicsImpostor(this, impostor, options);
         }
 
         public getPhysicsImpostor(): PhysicsImpostor {
-            return this.physicImpostor;
+            return this.physicsImpostor;
         }
 
         /**
          * @Deprecated. Use getPhysicsImpostor().getParam("mass");
          */
         public getPhysicsMass(): number {
-            return this.physicImpostor.getParam("mass")
+            return this.physicsImpostor.getParam("mass")
         }
 
         /**
          * @Deprecated. Use getPhysicsImpostor().getParam("friction");
          */
         public getPhysicsFriction(): number {
-            return this.physicImpostor.getParam("friction")
+            return this.physicsImpostor.getParam("friction")
         }
 
         /**
          * @Deprecated. Use getPhysicsImpostor().getParam("restitution");
          */
         public getPhysicsRestitution(): number {
-            return this.physicImpostor.getParam("resitution")
+            return this.physicsImpostor.getParam("resitution")
         }
 
         public getPositionInCameraSpace(camera?: Camera): Vector3 {
@@ -817,19 +817,19 @@
         }
 
         public applyImpulse(force: Vector3, contactPoint: Vector3): void {
-            if (!this.physicImpostor) {
+            if (!this.physicsImpostor) {
                 return;
             }
 
-            this.physicImpostor.applyImpulse(force, contactPoint);
+            this.physicsImpostor.applyImpulse(force, contactPoint);
         }
 
         public setPhysicsLinkWith(otherMesh: Mesh, pivot1: Vector3, pivot2: Vector3, options?: any): void {
-            if (!this.physicImpostor || !otherMesh.physicImpostor) {
+            if (!this.physicsImpostor || !otherMesh.physicsImpostor) {
                 return;
             }
 
-            this.physicImpostor.createJoint(otherMesh.physicImpostor, PhysicsJoint.HingeJoint, {
+            this.physicsImpostor.createJoint(otherMesh.physicsImpostor, PhysicsJoint.HingeJoint, {
                 mainPivot: pivot1,
                 connectedPivot: pivot2
             })
@@ -1079,8 +1079,8 @@
             this.getScene().stopAnimation(this);
 
             // Physics
-            if (this.physicImpostor) {
-                this.physicImpostor.dispose(!doNotRecurse);
+            if (this.physicsImpostor) {
+                this.physicsImpostor.dispose(!doNotRecurse);
             }
 
             // Intersections in progress

+ 0 - 8
src/Mesh/babylon.mesh.js

@@ -636,14 +636,6 @@ var BABYLON;
             if (!this._geometry || !this._geometry.getVertexBuffers() || !this._geometry.getIndexBuffer()) {
                 return;
             }
-            //rotate, if quaternion is set and rotation was used
-            if (this.rotationQuaternion) {
-                var len = this.rotation.length();
-                if (len) {
-                    this.rotationQuaternion.multiplyInPlace(BABYLON.Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z));
-                    this.rotation.copyFromFloats(0, 0, 0);
-                }
-            }
             var callbackIndex;
             for (callbackIndex = 0; callbackIndex < this._onBeforeRenderCallbacks.length; callbackIndex++) {
                 this._onBeforeRenderCallbacks[callbackIndex](this);

+ 32 - 27
src/Physics/Plugins/babylon.oimoJSPlugin.js

@@ -5,13 +5,15 @@ var BABYLON;
             this.name = "OimoJSPlugin";
             this._tmpImpostorsArray = [];
             this._tmpPositionVector = BABYLON.Vector3.Zero();
-            this.world = new OIMO.World(null, null, iterations);
+            this.world = new OIMO.World(1 / 60, 2, iterations);
             this.world.clear();
+            this.world.isNoStat = true;
         }
         OimoJSPlugin.prototype.setGravity = function (gravity) {
             this.world.gravity.copy(gravity);
         };
         OimoJSPlugin.prototype.executeStep = function (delta, impostors) {
+            var _this = this;
             impostors.forEach(function (impostor) {
                 impostor.beforeStep();
             });
@@ -19,26 +21,29 @@ var BABYLON;
             impostors.forEach(function (impostor) {
                 impostor.afterStep();
                 //update the ordered impostors array
-                this._tmpImpostorsArray[impostor.mesh.uniqueId] = impostor;
+                _this._tmpImpostorsArray[impostor.mesh.uniqueId] = impostor;
             });
             //check for collisions
             var contact = this.world.contacts;
             while (contact !== null) {
                 if (contact.touching && !contact.body1.sleeping && !contact.body2.sleeping) {
+                    contact = contact.next;
                     continue;
                 }
                 //is this body colliding with any other? get the impostor
                 var mainImpostor = this._tmpImpostorsArray[+contact.body1.name];
                 var collidingImpostor = this._tmpImpostorsArray[+contact.body2.name];
-                if (!mainImpostor || !collidingImpostor)
+                if (!mainImpostor || !collidingImpostor) {
+                    contact = contact.next;
                     continue;
+                }
                 mainImpostor.onCollide({ body: collidingImpostor.physicsBody });
                 collidingImpostor.onCollide({ body: mainImpostor.physicsBody });
                 contact = contact.next;
             }
         };
         OimoJSPlugin.prototype.applyImpulse = function (impostor, force, contactPoint) {
-            impostor.physicsBody.body.applyImpulse(contactPoint.scale(OIMO.INV_SCALE), force.scale(OIMO.INV_SCALE));
+            impostor.physicsBody.applyImpulse(contactPoint.scale(OIMO.INV_SCALE), force.scale(OIMO.INV_SCALE));
         };
         OimoJSPlugin.prototype.applyForce = function (impostor, force, contactPoint) {
             BABYLON.Tools.Warn("Oimo doesn't support applying force. Using impule instead.");
@@ -59,27 +64,30 @@ var BABYLON;
                 if (!impostor.mesh.rotationQuaternion) {
                     impostor.mesh.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(impostor.mesh.rotation.y, impostor.mesh.rotation.x, impostor.mesh.rotation.z);
                 }
-                var deltaPosition = impostor.mesh.position.subtract(impostor.mesh.getBoundingInfo().boundingBox.center);
-                //calculate rotation to fit Oimo's needs (Euler...)
+                impostor.mesh.position.subtractToRef(impostor.mesh.getBoundingInfo().boundingBox.center, this._tmpPositionVector);
                 var bodyConfig = {
                     name: impostor.mesh.uniqueId,
-                    //pos: [bbox.center.x, bbox.center.y, bbox.center.z],
-                    //rot: [rot.x / OIMO.TO_RAD, rot.y / OIMO.TO_RAD, rot.z / OIMO.TO_RAD],
-                    config: [impostor.getParam("mass"), impostor.getParam("friction"), impostor.getParam("restitution")],
+                    //Oimo must have mass, also for static objects.
+                    config: [impostor.getParam("mass") || 1, impostor.getParam("friction"), impostor.getParam("restitution")],
                     size: [],
                     type: [],
                     pos: [],
-                    rot: []
+                    rot: [],
+                    move: impostor.getParam("mass") !== 0
                 };
                 var impostors = [impostor];
                 function addToArray(parent) {
                     parent.getChildMeshes().forEach(function (m) {
-                        if (m.physicImpostor) {
-                            impostors.push(m.physicImpostor);
+                        if (m.physicsImpostor) {
+                            impostors.push(m.physicsImpostor);
                         }
+                        addToArray(m);
                     });
                 }
                 addToArray(impostor.mesh);
+                function checkWithEpsilon(value) {
+                    return Math.max(value, BABYLON.PhysicsEngine.Epsilon);
+                }
                 impostors.forEach(function (i) {
                     //get the correct bounding box
                     var oldQuaternion = i.mesh.rotationQuaternion;
@@ -98,16 +106,16 @@ var BABYLON;
                         bodyConfig.pos.push(i.mesh.position.y);
                         bodyConfig.pos.push(i.mesh.position.z);
                     }
-                    bodyConfig.rot.push(rot.x / OIMO.TO_RAD);
-                    bodyConfig.rot.push(rot.y / OIMO.TO_RAD);
-                    bodyConfig.rot.push(rot.z / OIMO.TO_RAD);
+                    bodyConfig.rot.push(rot.x / OIMO.degtorad);
+                    bodyConfig.rot.push(rot.y / OIMO.degtorad);
+                    bodyConfig.rot.push(rot.z / OIMO.degtorad);
                     // register mesh
                     switch (i.type) {
                         case BABYLON.PhysicsEngine.SphereImpostor:
                             var radiusX = bbox.maximumWorld.x - bbox.minimumWorld.x;
                             var radiusY = bbox.maximumWorld.y - bbox.minimumWorld.y;
                             var radiusZ = bbox.maximumWorld.z - bbox.minimumWorld.z;
-                            var size = Math.max(this._checkWithEpsilon(radiusX), this._checkWithEpsilon(radiusY), this._checkWithEpsilon(radiusZ)) / 2;
+                            var size = Math.max(checkWithEpsilon(radiusX), checkWithEpsilon(radiusY), checkWithEpsilon(radiusZ)) / 2;
                             bodyConfig.type.push('sphere');
                             //due to the way oimo works with compounds, add 3 times
                             bodyConfig.size.push(size);
@@ -118,12 +126,13 @@ var BABYLON;
                         //TODO Oimo now supports cylinder!
                         case BABYLON.PhysicsEngine.CylinderImpostor:
                         case BABYLON.PhysicsEngine.BoxImpostor:
+                        default:
                             var min = bbox.minimumWorld;
                             var max = bbox.maximumWorld;
                             var box = max.subtract(min);
-                            var sizeX = this._checkWithEpsilon(box.x);
-                            var sizeY = this._checkWithEpsilon(box.y);
-                            var sizeZ = this._checkWithEpsilon(box.z);
+                            var sizeX = checkWithEpsilon(box.x);
+                            var sizeY = checkWithEpsilon(box.y);
+                            var sizeZ = checkWithEpsilon(box.z);
                             bodyConfig.type.push('box');
                             bodyConfig.size.push(sizeX);
                             bodyConfig.size.push(sizeY);
@@ -134,7 +143,7 @@ var BABYLON;
                     i.mesh.rotationQuaternion = oldQuaternion;
                 });
                 impostor.physicsBody = this.world.add(bodyConfig);
-                impostor.setDeltaPosition(deltaPosition);
+                impostor.setDeltaPosition(this._tmpPositionVector);
             }
             else {
                 this._tmpPositionVector.copyFromFloats(0, 0, 0);
@@ -142,9 +151,6 @@ var BABYLON;
             this._tmpPositionVector.addInPlace(impostor.mesh.getBoundingInfo().boundingBox.center);
             this.setPhysicsBodyTransformation(impostor, this._tmpPositionVector, impostor.mesh.rotationQuaternion);
         };
-        OimoJSPlugin.prototype._checkWithEpsilon = function (value) {
-            return value < BABYLON.PhysicsEngine.Epsilon ? BABYLON.PhysicsEngine.Epsilon : value;
-        };
         OimoJSPlugin.prototype.removePhysicsBody = function (impostor) {
             this.world.removeRigidBody(impostor.physicsBody);
         };
@@ -215,11 +221,10 @@ var BABYLON;
         };
         OimoJSPlugin.prototype.setPhysicsBodyTransformation = function (impostor, newPosition, newRotation) {
             var body = impostor.physicsBody;
-            body.setPosition(newPosition);
+            if (!newPosition.equalsWithEpsilon(impostor.mesh.position)) {
+                body.setPosition(newPosition);
+            }
             body.setQuaternion(newRotation);
-            body.sleeping = false;
-            //force Oimo to update the body's position
-            body.updatePosition(1);
         };
         OimoJSPlugin.prototype._getLastShape = function (body) {
             var lastShape = body.shapes;

+ 40 - 35
src/Physics/Plugins/babylon.oimoJSPlugin.ts

@@ -7,8 +7,9 @@ module BABYLON {
         public name: string = "OimoJSPlugin";
 
         constructor(iterations?: number) {
-            this.world = new OIMO.World(null, null, iterations);
+            this.world = new OIMO.World(1/60, 2, iterations);
             this.world.clear();
+            this.world.isNoStat = true;
         }
 
         public setGravity(gravity: Vector3) {
@@ -25,7 +26,7 @@ module BABYLON {
 
             this.world.step();
 
-            impostors.forEach(function(impostor) {
+            impostors.forEach((impostor) => {
                 impostor.afterStep();
                 //update the ordered impostors array
                 this._tmpImpostorsArray[impostor.mesh.uniqueId] = impostor;
@@ -36,13 +37,18 @@ module BABYLON {
 
             while (contact !== null) {
                 if (contact.touching && !contact.body1.sleeping && !contact.body2.sleeping) {
+                    contact = contact.next;
                     continue;
                 }
                 //is this body colliding with any other? get the impostor
                 var mainImpostor = this._tmpImpostorsArray[+contact.body1.name];
                 var collidingImpostor = this._tmpImpostorsArray[+contact.body2.name];
 
-                if (!mainImpostor || !collidingImpostor) continue;
+                if (!mainImpostor || !collidingImpostor) {
+                    contact = contact.next;
+                    continue;
+                }
+                
                 mainImpostor.onCollide({ body: collidingImpostor.physicsBody });
                 collidingImpostor.onCollide({ body: mainImpostor.physicsBody });
                 contact = contact.next;
@@ -51,7 +57,7 @@ module BABYLON {
         }
 
         public applyImpulse(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3) {
-            impostor.physicsBody.body.applyImpulse(contactPoint.scale(OIMO.INV_SCALE), force.scale(OIMO.INV_SCALE));
+            impostor.physicsBody.applyImpulse(contactPoint.scale(OIMO.INV_SCALE), force.scale(OIMO.INV_SCALE));
 
         }
         public applyForce(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3) {
@@ -76,32 +82,34 @@ module BABYLON {
                     impostor.mesh.rotationQuaternion = Quaternion.RotationYawPitchRoll(impostor.mesh.rotation.y, impostor.mesh.rotation.x, impostor.mesh.rotation.z);
                 }
 
-                var deltaPosition = impostor.mesh.position.subtract(impostor.mesh.getBoundingInfo().boundingBox.center);
+                impostor.mesh.position.subtractToRef(impostor.mesh.getBoundingInfo().boundingBox.center, this._tmpPositionVector);
             
-                //calculate rotation to fit Oimo's needs (Euler...)
-                
-                
                 var bodyConfig: any = {
                     name: impostor.mesh.uniqueId,
-                    //pos: [bbox.center.x, bbox.center.y, bbox.center.z],
-                    //rot: [rot.x / OIMO.TO_RAD, rot.y / OIMO.TO_RAD, rot.z / OIMO.TO_RAD],
-                    config: [impostor.getParam("mass"), impostor.getParam("friction"), impostor.getParam("restitution")],
+                    //Oimo must have mass, also for static objects.
+                    config: [impostor.getParam("mass") || 1, impostor.getParam("friction"), impostor.getParam("restitution")],
                     size: [],
                     type: [],
                     pos: [],
-                    rot: []
+                    rot: [],
+                    move: impostor.getParam("mass") !== 0
                 };
 
                 var impostors = [impostor];
                 function addToArray(parent: AbstractMesh) {
                     parent.getChildMeshes().forEach(function(m) {
-                        if (m.physicImpostor) {
-                            impostors.push(m.physicImpostor);
+                        if (m.physicsImpostor) {
+                            impostors.push(m.physicsImpostor);
                         }
+                        addToArray(m);
                     });
                 }
                 addToArray(impostor.mesh)
 
+                function checkWithEpsilon(value: number): number {
+                    return Math.max(value, PhysicsEngine.Epsilon);
+                }
+
                 impostors.forEach(function(i) {
                     
                     //get the correct bounding box
@@ -109,10 +117,9 @@ module BABYLON {
                     i.mesh.rotationQuaternion = new Quaternion(0, 0, 0, 1);
                     i.mesh.computeWorldMatrix(true);
 
-
                     var bbox = i.mesh.getBoundingInfo().boundingBox;
                     var rot = new OIMO.Euler().setFromQuaternion({ x: impostor.mesh.rotationQuaternion.x, y: impostor.mesh.rotationQuaternion.y, z: impostor.mesh.rotationQuaternion.z, s: impostor.mesh.rotationQuaternion.w });
-                    
+
                     if (i === impostor) {
                         //Can also use Array.prototype.push.apply
                         bodyConfig.pos.push(bbox.center.x);
@@ -124,9 +131,9 @@ module BABYLON {
                         bodyConfig.pos.push(i.mesh.position.z);
                     }
 
-                    bodyConfig.rot.push(rot.x / OIMO.TO_RAD);
-                    bodyConfig.rot.push(rot.y / OIMO.TO_RAD);
-                    bodyConfig.rot.push(rot.z / OIMO.TO_RAD);
+                    bodyConfig.rot.push(rot.x / OIMO.degtorad);
+                    bodyConfig.rot.push(rot.y / OIMO.degtorad);
+                    bodyConfig.rot.push(rot.z / OIMO.degtorad);
                     
                     // register mesh
                     switch (i.type) {
@@ -136,9 +143,9 @@ module BABYLON {
                             var radiusZ = bbox.maximumWorld.z - bbox.minimumWorld.z;
 
                             var size = Math.max(
-                                this._checkWithEpsilon(radiusX),
-                                this._checkWithEpsilon(radiusY),
-                                this._checkWithEpsilon(radiusZ)) / 2;
+                                checkWithEpsilon(radiusX),
+                                checkWithEpsilon(radiusY),
+                                checkWithEpsilon(radiusZ)) / 2;
 
                             bodyConfig.type.push('sphere');
                             //due to the way oimo works with compounds, add 3 times
@@ -151,13 +158,14 @@ module BABYLON {
                         //TODO Oimo now supports cylinder!
                         case PhysicsEngine.CylinderImpostor:
                         case PhysicsEngine.BoxImpostor:
+                        default:
 
                             var min = bbox.minimumWorld;
                             var max = bbox.maximumWorld;
                             var box = max.subtract(min);
-                            var sizeX = this._checkWithEpsilon(box.x);
-                            var sizeY = this._checkWithEpsilon(box.y);
-                            var sizeZ = this._checkWithEpsilon(box.z);
+                            var sizeX = checkWithEpsilon(box.x);
+                            var sizeY = checkWithEpsilon(box.y);
+                            var sizeZ = checkWithEpsilon(box.z);
 
                             bodyConfig.type.push('box');
                             bodyConfig.size.push(sizeX);
@@ -171,8 +179,8 @@ module BABYLON {
                 });
 
                 impostor.physicsBody = this.world.add(bodyConfig);
-                
-                impostor.setDeltaPosition(deltaPosition);
+
+                impostor.setDeltaPosition(this._tmpPositionVector);
 
             } else {
                 this._tmpPositionVector.copyFromFloats(0, 0, 0);
@@ -181,10 +189,6 @@ module BABYLON {
             this.setPhysicsBodyTransformation(impostor, this._tmpPositionVector, impostor.mesh.rotationQuaternion);
         }
 
-        private _checkWithEpsilon(value: number): number {
-            return value < PhysicsEngine.Epsilon ? PhysicsEngine.Epsilon : value;
-        }
-
         private _tmpPositionVector: Vector3 = Vector3.Zero();
 
         public removePhysicsBody(impostor: PhysicsImpostor) {
@@ -263,11 +267,12 @@ module BABYLON {
 
         public setPhysicsBodyTransformation(impostor: PhysicsImpostor, newPosition: Vector3, newRotation: Quaternion) {
             var body = impostor.physicsBody;
-            body.setPosition(newPosition);
+            
+            if(!newPosition.equalsWithEpsilon(impostor.mesh.position)) {
+                body.setPosition(newPosition);
+            }
+            
             body.setQuaternion(newRotation);
-            body.sleeping = false;
-            //force Oimo to update the body's position
-            body.updatePosition(1);
         }
 
         private _getLastShape(body: any): any {

+ 3 - 3
src/Physics/babylon.physicsImpostor.js

@@ -179,10 +179,10 @@ var BABYLON;
             }
             else {
                 this.mesh.getChildMeshes().forEach(function (mesh) {
-                    if (mesh.physicImpostor) {
+                    if (mesh.physicsImpostor) {
                         if (disposeChildren) {
-                            mesh.physicImpostor.dispose();
-                            mesh.physicImpostor = null;
+                            mesh.physicsImpostor.dispose();
+                            mesh.physicsImpostor = null;
                         }
                     }
                 });

+ 3 - 3
src/Physics/babylon.physicsImpostor.ts

@@ -215,10 +215,10 @@ module BABYLON {
                 this.parent.forceUpdate();
             } else {
                 this.mesh.getChildMeshes().forEach(function(mesh) {
-                    if (mesh.physicImpostor) {
+                    if (mesh.physicsImpostor) {
                         if (disposeChildren) {
-                            mesh.physicImpostor.dispose();
-                            mesh.physicImpostor = null;
+                            mesh.physicsImpostor.dispose();
+                            mesh.physicsImpostor = null;
                         }
                     }
                 })

+ 4 - 4
src/babylon.scene.js

@@ -2034,20 +2034,20 @@ var BABYLON;
                 parts = parts.parts;
             }
             var mainMesh = parts[0].mesh;
-            mainMesh.physicImpostor = new BABYLON.PhysicsImpostor(mainMesh, parts[0].impostor, options);
+            mainMesh.physicsImpostor = new BABYLON.PhysicsImpostor(mainMesh, parts[0].impostor, options);
             for (var index = 1; index < parts.length; index++) {
                 var mesh = parts[index].mesh;
                 if (mesh.parent !== mainMesh) {
                     mesh.position = mesh.position.subtract(mainMesh.position);
                     mesh.parent = mainMesh;
                 }
-                mesh.physicImpostor = new BABYLON.PhysicsImpostor(mesh, parts[index].impostor, options);
+                mesh.physicsImpostor = new BABYLON.PhysicsImpostor(mesh, parts[index].impostor, options);
             }
         };
         Scene.prototype.deleteCompoundImpostor = function (compound) {
             var mesh = compound.parts[0].mesh;
-            mesh.physicImpostor.dispose(true);
-            mesh.physicImpostor = null;
+            mesh.physicsImpostor.dispose(true);
+            mesh.physicsImpostor = null;
         };
         // Misc.
         Scene.prototype.createDefaultCameraOrLight = function () {

+ 4 - 4
src/babylon.scene.ts

@@ -2541,21 +2541,21 @@
             }
 
             var mainMesh: AbstractMesh = parts[0].mesh;
-            mainMesh.physicImpostor = new PhysicsImpostor(mainMesh, parts[0].impostor, options)
+            mainMesh.physicsImpostor = new PhysicsImpostor(mainMesh, parts[0].impostor, options)
             for (var index = 1; index < parts.length; index++) {
                 var mesh: AbstractMesh = parts[index].mesh;
                 if (mesh.parent !== mainMesh) {
                     mesh.position = mesh.position.subtract(mainMesh.position);
                     mesh.parent = mainMesh;
                 }
-                mesh.physicImpostor = new PhysicsImpostor(mesh, parts[index].impostor, options)
+                mesh.physicsImpostor = new PhysicsImpostor(mesh, parts[index].impostor, options)
             }
         }
 
         public deleteCompoundImpostor(compound: any): void {
             var mesh: AbstractMesh = compound.parts[0].mesh;
-            mesh.physicImpostor.dispose(true);
-            mesh.physicImpostor = null;
+            mesh.physicsImpostor.dispose(true);
+            mesh.physicsImpostor = null;
         }
 
         // Misc.