Преглед на файлове

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

jbousquie преди 9 години
родител
ревизия
69c282b67b

Файловите разлики са ограничени, защото са твърде много
+ 22 - 17
dist/preview release/babylon.core.js


Файловите разлики са ограничени, защото са твърде много
+ 743 - 726
dist/preview release/babylon.d.ts


Файловите разлики са ограничени, защото са твърде много
+ 30 - 24
dist/preview release/babylon.js


Файловите разлики са ограничени, защото са твърде много
+ 164 - 134
dist/preview release/babylon.max.js


Файловите разлики са ограничени, защото са твърде много
+ 29 - 23
dist/preview release/babylon.noworker.js


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

@@ -16,11 +16,11 @@
     - Improved reflection shader performance ([deltakosh](https://github.com/deltakosh))
     - New `Material.sideOrientation` property to define clockwise or counter-clockwise faces selection. [Demo here](http://www.babylonjs-playground.com/#1TZJQY) ([deltakosh](https://github.com/deltakosh))
     - It is now possible to create a custom loading screen. [PR](https://github.com/BabylonJS/Babylon.js/pull/700) ([RaananW](https://github.com/RaananW))
-    - Per face color and texture feature in `Mesh.CreateCylinder()` ([jerome](https://github.com/jbousquie))
+    - Per face color and texture feature in `MeshBuilder.CreateCylinder()` ([jerome](https://github.com/jbousquie))
     - _Arc_ feature in `CreateCylinder`, `CreateSphere`, `CreateTube` and `CreateLathe` ([jerome](https://github.com/jbousquie))
-    - _Slice_ feature in `Mesh.CreateSphere()` ([jerome](https://github.com/jbousquie))
-    - `closed` parameter in `Mesh.CreateLathe()` ([jerome](https://github.com/jbousquie))
-    - `diameter` parameter in `Mesh.CreateCreateCylinder()` ([jerome](https://github.com/jbousquie))
+    - _Slice_ feature in `MeshBuilder.CreateSphere()` ([jerome](https://github.com/jbousquie))
+    - `closed` parameter in `MeshBuilder.CreateLathe()` ([jerome](https://github.com/jbousquie))
+    - `diameter` parameter in `MeshBuilder.CreateCreateCylinder()` ([jerome](https://github.com/jbousquie))
     - `Material.dispose()` now removes disposed material from meshes ([deltakosh](https://github.com/deltakosh))
     - New `Material.getBindedMeshes()` function ([deltakosh](https://github.com/deltakosh))
   - **Bug fixes**

+ 9 - 9
src/Materials/Textures/babylon.renderTargetTexture.js

@@ -35,23 +35,23 @@ var BABYLON;
             // Rendering groups
             this._renderingManager = new BABYLON.RenderingManager(scene);
         }
-        Object.defineProperty(RenderTargetTexture, "REFRESHRATE_RENDERONCE", {
+        Object.defineProperty(RenderTargetTexture, "REFRESHRATE_RENDER_ONCE", {
             get: function () {
-                return RenderTargetTexture._REFRESHRATE_RENDERONCE;
+                return RenderTargetTexture._REFRESHRATE_RENDER_ONCE;
             },
             enumerable: true,
             configurable: true
         });
-        Object.defineProperty(RenderTargetTexture, "REFRESHRATE_RENDERONEVERYFRAME", {
+        Object.defineProperty(RenderTargetTexture, "REFRESHRATE_RENDER_ONEVERYFRAME", {
             get: function () {
-                return RenderTargetTexture._REFRESHRATE_RENDERONEVERYFRAME;
+                return RenderTargetTexture._REFRESHRATE_RENDER_ONEVERYFRAME;
             },
             enumerable: true,
             configurable: true
         });
-        Object.defineProperty(RenderTargetTexture, "REFRESHRATE_RENDERONEVERYTWOFRAME", {
+        Object.defineProperty(RenderTargetTexture, "REFRESHRATE_RENDER_ONEVERYTWOFRAMES", {
             get: function () {
-                return RenderTargetTexture._REFRESHRATE_RENDERONEVERYTWOFRAME;
+                return RenderTargetTexture._REFRESHRATE_RENDER_ONEVERYTWOFRAMES;
             },
             enumerable: true,
             configurable: true
@@ -226,9 +226,9 @@ var BABYLON;
             newTexture.renderList = this.renderList.slice(0);
             return newTexture;
         };
-        RenderTargetTexture._REFRESHRATE_RENDERONCE = 0;
-        RenderTargetTexture._REFRESHRATE_RENDERONEVERYFRAME = 1;
-        RenderTargetTexture._REFRESHRATE_RENDERONEVERYTWOFRAME = 2;
+        RenderTargetTexture._REFRESHRATE_RENDER_ONCE = 0;
+        RenderTargetTexture._REFRESHRATE_RENDER_ONEVERYFRAME = 1;
+        RenderTargetTexture._REFRESHRATE_RENDER_ONEVERYTWOFRAMES = 2;
         return RenderTargetTexture;
     })(BABYLON.Texture);
     BABYLON.RenderTargetTexture = RenderTargetTexture;

+ 9 - 9
src/Materials/Textures/babylon.renderTargetTexture.ts

@@ -1,19 +1,19 @@
 module BABYLON {
     export class RenderTargetTexture extends Texture {
-        public static _REFRESHRATE_RENDERONCE: number = 0;
-        public static _REFRESHRATE_RENDERONEVERYFRAME: number = 1;
-        public static _REFRESHRATE_RENDERONEVERYTWOFRAME: number = 2;
+        public static _REFRESHRATE_RENDER_ONCE: number = 0;
+        public static _REFRESHRATE_RENDER_ONEVERYFRAME: number = 1;
+        public static _REFRESHRATE_RENDER_ONEVERYTWOFRAMES: number = 2;
 
-        public static get REFRESHRATE_RENDERONCE(): number {
-            return RenderTargetTexture._REFRESHRATE_RENDERONCE;
+        public static get REFRESHRATE_RENDER_ONCE(): number {
+            return RenderTargetTexture._REFRESHRATE_RENDER_ONCE;
         }
 
-        public static get REFRESHRATE_RENDERONEVERYFRAME(): number {
-            return RenderTargetTexture._REFRESHRATE_RENDERONEVERYFRAME;
+        public static get REFRESHRATE_RENDER_ONEVERYFRAME(): number {
+            return RenderTargetTexture._REFRESHRATE_RENDER_ONEVERYFRAME;
         }
 
-        public static get REFRESHRATE_RENDERONEVERYTWOFRAME(): number {
-            return RenderTargetTexture._REFRESHRATE_RENDERONEVERYTWOFRAME;
+        public static get REFRESHRATE_RENDER_ONEVERYTWOFRAMES(): number {
+            return RenderTargetTexture._REFRESHRATE_RENDER_ONEVERYTWOFRAMES;
         }
 
         public renderList = new Array<AbstractMesh>();

+ 1 - 2
src/Mesh/babylon.meshBuilder.ts

@@ -390,7 +390,6 @@
             var updatable = options.updatable;
             var sideOrientation = options.sideOrientation || Mesh.DEFAULTSIDE;
             var instance = options.instance;
-            options.arc = (options.arc <= 0) ? 1.0 : options.arc || 1.0;
 
             // tube geometry
             var tubePathArray = (path, path3D, circlePaths, radius, tessellation, radiusFunction, cap, arc) => {
@@ -782,4 +781,4 @@
             return extrudedGeneric;
         }
     }
-}
+}

+ 68 - 68
src/Particles/babylon.solidParticleSystem.ts

@@ -2,53 +2,53 @@ module BABYLON {
 
     export class SolidParticleSystem implements IDisposable {
         // public members  
-        public particles = new Array<SolidParticle>();
-        public nbParticles = 0;
-        public billboard = false;
-        public counter = 0;
+        public particles: SolidParticle[] = new Array<SolidParticle>();
+        public nbParticles: number = 0;
+        public billboard: boolean = false;
+        public counter: number = 0;
         public name: string;
         public mesh: Mesh;
         
         // private members
         private _scene: Scene;
-        private _positions = new Array<number>();
-        private _indices = new Array<number>();
-        private _normals = new Array<number>();
-        private _colors = new Array<number>();
-        private _uvs = new Array<number>();
-        private _index = 0;  // indices index
-        private _shapeCounter = 0;
-        private _setParticleColor = true;
-        private _setParticleTexture = true;
-        private _setParticleRotation = true;
-        private _setParticleVertex = false;
-        private _cam_axisZ = Vector3.Zero();
-        private _cam_axisY = Vector3.Zero();
-        private _cam_axisX = Vector3.Zero();
-        private _axisX = Axis.X;
-        private _axisY = Axis.Y;
-        private _axisZ = Axis.Z;
+        private _positions: number[] = new Array<number>();
+        private _indices: number[] = new Array<number>();
+        private _normals: number[] = new Array<number>();
+        private _colors: number[] = new Array<number>();
+        private _uvs: number[] = new Array<number>();
+        private _index: number = 0;  // indices index
+        private _shapeCounter: number = 0;
+        private _computeParticleColor: boolean = true;
+        private _computeParticleTexture: boolean = true;
+        private _computeParticleRotation: boolean = true;
+        private _computeParticleVertex: boolean = false;
+        private _cam_axisZ: Vector3 = Vector3.Zero();
+        private _cam_axisY: Vector3 = Vector3.Zero();
+        private _cam_axisX: Vector3 = Vector3.Zero();
+        private _axisX: Vector3 = Axis.X;
+        private _axisY: Vector3 = Axis.Y;
+        private _axisZ: Vector3 = Axis.Z;
         private _camera: Camera;
         private _particle: SolidParticle;
         private _previousParticle: SolidParticle;
-        private _fakeCamPos = Vector3.Zero();
-        private _rotMatrix = new Matrix();
-        private _invertedMatrix = new Matrix();
-        private _rotated = Vector3.Zero();
-        private _quaternion = new Quaternion();
-        private _vertex = Vector3.Zero();
-        private _yaw = 0.0;
-        private _pitch = 0.0;
-        private _roll = 0.0;
-        private _halfroll = 0.0;
-        private _halfpitch = 0.0;
-        private _halfyaw = 0.0;
-        private _sinRoll = 0.0;
-        private _cosRoll = 0.0;
-        private _sinPitch = 0.0;
-        private _cosPitch = 0.0;
-        private _sinYaw = 0.0;
-        private _cosYaw = 0.0;
+        private _fakeCamPos: Vector3 = Vector3.Zero();
+        private _rotMatrix: Matrix = new Matrix();
+        private _invertedMatrix: Matrix = new Matrix();
+        private _rotated: Vector3 = Vector3.Zero();
+        private _quaternion: Quaternion = new Quaternion();
+        private _vertex: Vector3 = Vector3.Zero();
+        private _yaw: number = 0.0;
+        private _pitch: number = 0.0;
+        private _roll: number = 0.0;
+        private _halfroll: number = 0.0;
+        private _halfpitch: number = 0.0;
+        private _halfyaw: number = 0.0;
+        private _sinRoll: number = 0.0;
+        private _cosRoll: number = 0.0;
+        private _sinPitch: number = 0.0;
+        private _cosPitch: number = 0.0;
+        private _sinYaw: number = 0.0;
+        private _cosYaw: number = 0.0;
 
 
         constructor(name: string, scene: Scene) {
@@ -221,7 +221,7 @@ module BABYLON {
                     this._particle.rotation.x = 0.0;
                     this._particle.rotation.y = 0.0;
                 }
-                if (this._setParticleRotation) {
+                if (this._computeParticleRotation) {
                     if (this._particle.quaternion) {
                         this._quaternion.x = this._particle.quaternion.x;
                         this._quaternion.y = this._particle.quaternion.y;
@@ -241,28 +241,28 @@ module BABYLON {
                     colidx = colorIndex + pt * 4;
                     uvidx = uvIndex + pt * 2;
 
-                    this._vertex.x = this._particle._shape[pt].x;
-                    this._vertex.y = this._particle._shape[pt].y;
-                    this._vertex.z = this._particle._shape[pt].z;
+                    this._vertex.x = this._particle._shape[pt].x * this._particle.scale.x;
+                    this._vertex.y = this._particle._shape[pt].y * this._particle.scale.y;
+                    this._vertex.z = this._particle._shape[pt].z * this._particle.scale.z;
 
-                    if (this._setParticleVertex) {
+                    if (this._computeParticleVertex) {
                         this.updateParticleVertex(this._particle, this._vertex, pt);
                     }
 
                     Vector3.TransformCoordinatesToRef(this._vertex, this._rotMatrix, this._rotated);
 
-                    this._positions[idx] = this._particle.position.x + this._cam_axisX.x * this._rotated.x * this._particle.scale.x + this._cam_axisY.x * this._rotated.y * this._particle.scale.y + this._cam_axisZ.x * this._rotated.z * this._particle.scale.z;
-                    this._positions[idx + 1] = this._particle.position.y + this._cam_axisX.y * this._rotated.x * this._particle.scale.x + this._cam_axisY.y * this._rotated.y * this._particle.scale.y + this._cam_axisZ.y * this._rotated.z * this._particle.scale.z;
-                    this._positions[idx + 2] = this._particle.position.z + this._cam_axisX.z * this._rotated.x * this._particle.scale.x + this._cam_axisY.z * this._rotated.y * this._particle.scale.y + this._cam_axisZ.z * this._rotated.z * this._particle.scale.z;
+                    this._positions[idx] = this._particle.position.x + this._cam_axisX.x * this._rotated.x + this._cam_axisY.x * this._rotated.y + this._cam_axisZ.x * this._rotated.z;
+                    this._positions[idx + 1] = this._particle.position.y + this._cam_axisX.y * this._rotated.x + this._cam_axisY.y * this._rotated.y + this._cam_axisZ.y * this._rotated.z;
+                    this._positions[idx + 2] = this._particle.position.z + this._cam_axisX.z * this._rotated.x + this._cam_axisY.z * this._rotated.y + this._cam_axisZ.z * this._rotated.z;
 
-                    if (this._setParticleColor) {
+                    if (this._computeParticleColor) {
                         this._colors[colidx] = this._particle.color.r;
                         this._colors[colidx + 1] = this._particle.color.g;
                         this._colors[colidx + 2] = this._particle.color.b;
                         this._colors[colidx + 3] = this._particle.color.a;
                     }
 
-                    if (this._setParticleTexture) {
+                    if (this._computeParticleTexture) {
                         this._uvs[uvidx] = this._particle._shapeUV[pt * 2] * (this._particle.uvs.z - this._particle.uvs.x) + this._particle.uvs.x;
                         this._uvs[uvidx + 1] = this._particle._shapeUV[pt * 2 + 1] * (this._particle.uvs.w - this._particle.uvs.y) + this._particle.uvs.y;
                     }
@@ -273,10 +273,10 @@ module BABYLON {
             }
 
             if (update) {
-                if (this._setParticleColor) {
+                if (this._computeParticleColor) {
                     this.mesh.updateVerticesData(VertexBuffer.ColorKind, this._colors, false, false);
                 }
-                if (this._setParticleTexture) {
+                if (this._computeParticleTexture) {
                     this.mesh.updateVerticesData(VertexBuffer.UVKind, this._uvs, false, false);
                 }
                 this.mesh.updateVerticesData(VertexBuffer.PositionKind, this._positions, false, false);
@@ -329,37 +329,37 @@ module BABYLON {
         }
 
         // Optimizer setters
-        public set setParticleRotation(val: boolean) {
-            this._setParticleRotation = val;
+        public set computeParticleRotation(val: boolean) {
+            this._computeParticleRotation = val;
         }
 
-        public set setParticleColor(val: boolean) {
-            this._setParticleColor = val;
+        public set computeParticleColor(val: boolean) {
+            this._computeParticleColor = val;
         }
 
-        public set setParticleTexture(val: boolean) {
-            this._setParticleTexture = val;
+        public set computeParticleTexture(val: boolean) {
+            this._computeParticleTexture = val;
         }
 
-        public set setParticleVertex(val: boolean) {
-            this._setParticleVertex = val;
+        public set computeParticleVertex(val: boolean) {
+            this._computeParticleVertex = val;
         } 
 
         // getters
-        public get setParticleRotation(): boolean {
-            return this._setParticleRotation;
+        public get computeParticleRotation(): boolean {
+            return this._computeParticleRotation;
         }
 
-        public get setParticleColor(): boolean {
-            return this._setParticleColor;
+        public get computeParticleColor(): boolean {
+            return this._computeParticleColor;
         }
 
-        public get setParticleTexture(): boolean {
-            return this._setParticleTexture;
+        public get computeParticleTexture(): boolean {
+            return this._computeParticleTexture;
         }
 
-        public get setParticleVertex(): boolean {
-            return this._setParticleVertex;
+        public get computeParticleVertex(): boolean {
+            return this._computeParticleVertex;
         } 
        
 
@@ -400,4 +400,4 @@ module BABYLON {
         public afterUpdateParticles(start?: number, stop?: number, update?: boolean): void {
         }
     }
-}
+}

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

@@ -38,10 +38,12 @@ var BABYLON;
                 }
                 // Body position
                 var bodyX = registeredMesh.body.position.x, bodyY = registeredMesh.body.position.y, bodyZ = registeredMesh.body.position.z;
-                var deltaPos = registeredMesh.delta || BABYLON.Vector3.Zero();
-                registeredMesh.mesh.position.x = bodyX + deltaPos.x;
-                registeredMesh.mesh.position.y = bodyY + deltaPos.y;
-                registeredMesh.mesh.position.z = bodyZ + deltaPos.z;
+                if (!registeredMesh.delta) {
+                    registeredMesh.delta = BABYLON.Vector3.Zero();
+                }
+                registeredMesh.mesh.position.x = bodyX + registeredMesh.delta.x;
+                registeredMesh.mesh.position.y = bodyY + registeredMesh.delta.y;
+                registeredMesh.mesh.position.z = bodyZ + registeredMesh.delta.z;
                 registeredMesh.mesh.rotationQuaternion.x = registeredMesh.body.quaternion.x;
                 registeredMesh.mesh.rotationQuaternion.y = registeredMesh.body.quaternion.y;
                 registeredMesh.mesh.rotationQuaternion.z = registeredMesh.body.quaternion.z;
@@ -53,18 +55,27 @@ var BABYLON;
         };
         CannonJSPlugin.prototype.registerMesh = function (mesh, impostor, options) {
             this.unregisterMesh(mesh);
+            if (!mesh.rotationQuaternion) {
+                mesh.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(mesh.rotation.y, mesh.rotation.x, mesh.rotation.z);
+            }
             mesh.computeWorldMatrix(true);
             var shape = this._createShape(mesh, impostor, options);
             return this._createRigidBodyFromShape(shape, mesh, options.mass, options.friction, options.restitution);
         };
         CannonJSPlugin.prototype._createShape = function (mesh, impostor, options) {
+            //get the correct bounding box
+            var oldQuaternion = mesh.rotationQuaternion;
+            mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
+            mesh.computeWorldMatrix(true);
+            var returnValue;
             switch (impostor) {
                 case BABYLON.PhysicsEngine.SphereImpostor:
                     var bbox = mesh.getBoundingInfo().boundingBox;
                     var radiusX = bbox.maximumWorld.x - bbox.minimumWorld.x;
                     var radiusY = bbox.maximumWorld.y - bbox.minimumWorld.y;
                     var radiusZ = bbox.maximumWorld.z - bbox.minimumWorld.z;
-                    return new CANNON.Sphere(Math.max(this._checkWithEpsilon(radiusX), this._checkWithEpsilon(radiusY), this._checkWithEpsilon(radiusZ)) / 2);
+                    returnValue = new CANNON.Sphere(Math.max(this._checkWithEpsilon(radiusX), this._checkWithEpsilon(radiusY), this._checkWithEpsilon(radiusZ)) / 2);
+                    break;
                 //TMP also for cylinder - TODO Cannon supports cylinder natively.
                 case BABYLON.PhysicsEngine.CylinderImpostor:
                     BABYLON.Tools.Warn("CylinderImposter not yet implemented, using BoxImposter instead");
@@ -73,15 +84,20 @@ var BABYLON;
                     var min = bbox.minimumWorld;
                     var max = bbox.maximumWorld;
                     var box = max.subtract(min).scale(0.5);
-                    return new CANNON.Box(new CANNON.Vec3(this._checkWithEpsilon(box.x), this._checkWithEpsilon(box.y), this._checkWithEpsilon(box.z)));
+                    returnValue = new CANNON.Box(new CANNON.Vec3(this._checkWithEpsilon(box.x), this._checkWithEpsilon(box.y), this._checkWithEpsilon(box.z)));
+                    break;
                 case BABYLON.PhysicsEngine.PlaneImpostor:
                     BABYLON.Tools.Warn("Attention, Cannon.js PlaneImposter might not behave as you wish. Consider using BoxImposter instead");
-                    return new CANNON.Plane();
+                    returnValue = new CANNON.Plane();
+                    break;
                 case BABYLON.PhysicsEngine.MeshImpostor:
                     var rawVerts = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
                     var rawFaces = mesh.getIndices();
-                    return this._createConvexPolyhedron(rawVerts, rawFaces, mesh, options);
+                    returnValue = this._createConvexPolyhedron(rawVerts, rawFaces, mesh, options);
+                    break;
             }
+            mesh.rotationQuaternion = oldQuaternion;
+            return returnValue;
         };
         CannonJSPlugin.prototype._createConvexPolyhedron = function (rawVerts, rawFaces, mesh, options) {
             var verts = [], faces = [];
@@ -118,7 +134,6 @@ var BABYLON;
             return currentMat;
         };
         CannonJSPlugin.prototype._createRigidBodyFromShape = function (shape, mesh, mass, friction, restitution) {
-            var initialRotation = null;
             if (!mesh.rotationQuaternion) {
                 mesh.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(mesh.rotation.y, mesh.rotation.x, mesh.rotation.z);
             }
@@ -219,6 +234,18 @@ var BABYLON;
         CannonJSPlugin.prototype.isSupported = function () {
             return window.CANNON !== undefined;
         };
+        CannonJSPlugin.prototype.getWorldObject = function () {
+            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;
     })();
     BABYLON.CannonJSPlugin = CannonJSPlugin;

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

@@ -32,11 +32,13 @@
                     bodyY = registeredMesh.body.position.y,
                     bodyZ = registeredMesh.body.position.z;
 
-                var deltaPos = registeredMesh.delta || Vector3.Zero();
+                if (!registeredMesh.delta) {
+                    registeredMesh.delta = Vector3.Zero();
+                }
 
-                registeredMesh.mesh.position.x = bodyX + deltaPos.x;
-                registeredMesh.mesh.position.y = bodyY + deltaPos.y;
-                registeredMesh.mesh.position.z = bodyZ + deltaPos.z;
+                registeredMesh.mesh.position.x = bodyX + registeredMesh.delta.x;
+                registeredMesh.mesh.position.y = bodyY + registeredMesh.delta.y;
+                registeredMesh.mesh.position.z = bodyZ + registeredMesh.delta.z;
 
                 registeredMesh.mesh.rotationQuaternion.x = registeredMesh.body.quaternion.x;
                 registeredMesh.mesh.rotationQuaternion.y = registeredMesh.body.quaternion.y;
@@ -52,6 +54,10 @@
         public registerMesh(mesh: AbstractMesh, impostor: number, options?: PhysicsBodyCreationOptions): any {
             this.unregisterMesh(mesh);
 
+            if (!mesh.rotationQuaternion) {
+                mesh.rotationQuaternion = Quaternion.RotationYawPitchRoll(mesh.rotation.y, mesh.rotation.x, mesh.rotation.z);
+            }
+
             mesh.computeWorldMatrix(true);
 
             var shape = this._createShape(mesh, impostor, options);
@@ -60,6 +66,14 @@
         }
 
         private _createShape(mesh: AbstractMesh, impostor: number, options?: PhysicsBodyCreationOptions) {
+		
+            //get the correct bounding box
+            var oldQuaternion = mesh.rotationQuaternion;
+            mesh.rotationQuaternion = new Quaternion(0, 0, 0, 1);
+            mesh.computeWorldMatrix(true);
+
+            var returnValue;
+
             switch (impostor) {
                 case PhysicsEngine.SphereImpostor:
                     var bbox = mesh.getBoundingInfo().boundingBox;
@@ -67,7 +81,9 @@
                     var radiusY = bbox.maximumWorld.y - bbox.minimumWorld.y;
                     var radiusZ = bbox.maximumWorld.z - bbox.minimumWorld.z;
 
-                    return new CANNON.Sphere(Math.max(this._checkWithEpsilon(radiusX), this._checkWithEpsilon(radiusY), this._checkWithEpsilon(radiusZ)) / 2);
+                    returnValue = new CANNON.Sphere(Math.max(this._checkWithEpsilon(radiusX), this._checkWithEpsilon(radiusY), this._checkWithEpsilon(radiusZ)) / 2);
+
+                    break;
                 //TMP also for cylinder - TODO Cannon supports cylinder natively.
                 case PhysicsEngine.CylinderImpostor:
                     Tools.Warn("CylinderImposter not yet implemented, using BoxImposter instead");
@@ -76,16 +92,23 @@
                     var min = bbox.minimumWorld;
                     var max = bbox.maximumWorld;
                     var box = max.subtract(min).scale(0.5);
-                    return new CANNON.Box(new CANNON.Vec3(this._checkWithEpsilon(box.x), this._checkWithEpsilon(box.y), this._checkWithEpsilon(box.z)));
+                    returnValue = new CANNON.Box(new CANNON.Vec3(this._checkWithEpsilon(box.x), this._checkWithEpsilon(box.y), this._checkWithEpsilon(box.z)));
+                    break;
                 case PhysicsEngine.PlaneImpostor:
                     Tools.Warn("Attention, Cannon.js PlaneImposter might not behave as you wish. Consider using BoxImposter instead");
-                    return new CANNON.Plane();
+                    returnValue = new CANNON.Plane();
+                    break;
                 case PhysicsEngine.MeshImpostor:
                     var rawVerts = mesh.getVerticesData(VertexBuffer.PositionKind);
                     var rawFaces = mesh.getIndices();
 
-                    return this._createConvexPolyhedron(rawVerts, rawFaces, mesh, options);
+                    returnValue = this._createConvexPolyhedron(rawVerts, rawFaces, mesh, options);
+                    break;
             }
+
+            mesh.rotationQuaternion = oldQuaternion;
+
+            return returnValue;
         }
 
         private _createConvexPolyhedron(rawVerts: number[] | Float32Array, rawFaces: number[], mesh: AbstractMesh, options?: PhysicsBodyCreationOptions): any {
@@ -138,8 +161,6 @@
         }
 
         private _createRigidBodyFromShape(shape: any, mesh: AbstractMesh, mass: number, friction: number, restitution: number): any {
-            var initialRotation: Quaternion = null;
-
             if (!mesh.rotationQuaternion) {
                 mesh.rotationQuaternion = Quaternion.RotationYawPitchRoll(mesh.rotation.y, mesh.rotation.x, mesh.rotation.z);
             }
@@ -287,6 +308,21 @@
         public isSupported(): boolean {
             return window.CANNON !== undefined;
         }
+
+        public getWorldObject(): any {
+            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;
+        }
     }
 }
 
+

+ 76 - 85
src/Physics/Plugins/babylon.oimoJSPlugin.js

@@ -15,7 +15,7 @@ var BABYLON;
                         mesh.computeWorldMatrix(true);
                         var center = mesh.getBoundingInfo().boundingBox.center;
                         body.setPosition(new OIMO.Vec3(center.x, center.y, center.z));
-                        body.setRotation(new OIMO.Vec3(mesh.rotation.x, mesh.rotation.y, mesh.rotation.z));
+                        body.setQuaternion(mesh.rotationQuaternion);
                         body.sleeping = false;
                         return;
                     }
@@ -24,10 +24,9 @@ var BABYLON;
                         mesh.computeWorldMatrix(true);
                         registeredMesh.mesh.computeWorldMatrix(true);
                         var absolutePosition = registeredMesh.mesh.getAbsolutePosition();
-                        var absoluteRotation = mesh.rotation;
                         body = registeredMesh.body.body;
                         body.setPosition(new OIMO.Vec3(absolutePosition.x, absolutePosition.y, absolutePosition.z));
-                        body.setRotation(new OIMO.Vec3(absoluteRotation.x, absoluteRotation.y, absoluteRotation.z));
+                        body.setQuaternion(mesh.rotationQuaternion);
                         body.sleeping = false;
                         return;
                     }
@@ -38,31 +37,34 @@ var BABYLON;
             return value < BABYLON.PhysicsEngine.Epsilon ? BABYLON.PhysicsEngine.Epsilon : value;
         };
         OimoJSPlugin.prototype.initialize = function (iterations) {
-            this._world = new OIMO.World();
+            this._world = new OIMO.World(null, null, iterations);
             this._world.clear();
         };
         OimoJSPlugin.prototype.setGravity = function (gravity) {
             this._world.gravity = gravity;
         };
         OimoJSPlugin.prototype.registerMesh = function (mesh, impostor, options) {
-            var body = null;
             this.unregisterMesh(mesh);
-            mesh.computeWorldMatrix(true);
-            var initialRotation = null;
-            if (mesh.rotationQuaternion) {
-                initialRotation = mesh.rotationQuaternion.clone();
-                mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
-                mesh.computeWorldMatrix(true);
+            if (!mesh.rotationQuaternion) {
+                mesh.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(mesh.rotation.y, mesh.rotation.x, mesh.rotation.z);
             }
+            mesh.computeWorldMatrix(true);
             var bbox = mesh.getBoundingInfo().boundingBox;
             // The delta between the mesh position and the mesh bounding box center
             var deltaPosition = mesh.position.subtract(bbox.center);
-            // Transform delta position with the rotation
-            if (initialRotation) {
-                var m = new BABYLON.Matrix();
-                initialRotation.toRotationMatrix(m);
-                deltaPosition = BABYLON.Vector3.TransformCoordinates(deltaPosition, m);
-            }
+            //calculate rotation to fit Oimo's needs (Euler...)
+            var rot = new OIMO.Euler().setFromQuaternion({ x: mesh.rotationQuaternion.x, y: mesh.rotationQuaternion.y, z: mesh.rotationQuaternion.z, s: mesh.rotationQuaternion.w });
+            //get the correct bounding box
+            var oldQuaternion = mesh.rotationQuaternion;
+            mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
+            mesh.computeWorldMatrix(true);
+            var bodyConfig = {
+                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],
+                move: options.mass != 0,
+                config: [options.mass, options.friction, options.restitution],
+                world: this._world
+            };
             // register mesh
             switch (impostor) {
                 case BABYLON.PhysicsEngine.SphereImpostor:
@@ -70,15 +72,8 @@ var BABYLON;
                     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;
-                    body = new OIMO.Body({
-                        type: 'sphere',
-                        size: [size],
-                        pos: [bbox.center.x, bbox.center.y, bbox.center.z],
-                        rot: [mesh.rotation.x / OIMO.TO_RAD, mesh.rotation.y / OIMO.TO_RAD, mesh.rotation.z / OIMO.TO_RAD],
-                        move: options.mass != 0,
-                        config: [options.mass, options.friction, options.restitution],
-                        world: this._world
-                    });
+                    bodyConfig.type = 'sphere';
+                    bodyConfig.size = [size];
                     break;
                 case BABYLON.PhysicsEngine.PlaneImpostor:
                 //Oimo "fakes" a cylinder as a box, so why don't we!
@@ -90,30 +85,25 @@ var BABYLON;
                     var sizeX = this._checkWithEpsilon(box.x);
                     var sizeY = this._checkWithEpsilon(box.y);
                     var sizeZ = this._checkWithEpsilon(box.z);
-                    body = new OIMO.Body({
-                        type: 'box',
-                        size: [sizeX, sizeY, sizeZ],
-                        pos: [bbox.center.x, bbox.center.y, bbox.center.z],
-                        rot: [mesh.rotation.x / OIMO.TO_RAD, mesh.rotation.y / OIMO.TO_RAD, mesh.rotation.z / OIMO.TO_RAD],
-                        move: options.mass != 0,
-                        config: [options.mass, options.friction, options.restitution],
-                        world: this._world
-                    });
+                    bodyConfig.type = 'box';
+                    bodyConfig.size = [sizeX, sizeY, sizeZ];
                     break;
             }
-            //If quaternion was set as the rotation of the object
-            if (initialRotation) {
-                //We have to access the rigid body's properties to set the quaternion. 
-                //The setQuaternion function of Oimo only sets the newOrientation that is only set after an impulse is given or a collision.
-                body.body.orientation = new OIMO.Quat(initialRotation.w, initialRotation.x, initialRotation.y, initialRotation.z);
-                //update the internal rotation matrix
-                body.body.syncShapes();
-            }
+            var body = new OIMO.Body(bodyConfig);
+            //We have to access the rigid body's properties to set the quaternion. 
+            //The setQuaternion function of Oimo only sets the newOrientation that is only set after an impulse is given or a collision.
+            //body.body.orientation = new OIMO.Quat(mesh.rotationQuaternion.w, mesh.rotationQuaternion.x, mesh.rotationQuaternion.y, mesh.rotationQuaternion.z);
+            //TEST
+            //body.body.resetQuaternion(new OIMO.Quat(mesh.rotationQuaternion.w, mesh.rotationQuaternion.x, mesh.rotationQuaternion.y, mesh.rotationQuaternion.z));
+            //update the internal rotation matrix
+            //body.body.syncShapes();
             this._registeredMeshes.push({
                 mesh: mesh,
                 body: body,
                 delta: deltaPosition
             });
+            //for the sake of consistency.
+            mesh.rotationQuaternion = oldQuaternion;
             return body;
         };
         OimoJSPlugin.prototype.registerMeshesAsCompound = function (parts, options) {
@@ -136,6 +126,9 @@ var BABYLON;
                 config: [options.mass, options.friction, options.restitution],
                 world: this._world
             });
+            //Reset the body's rotation to be of the initial mesh's.
+            var rot = new OIMO.Euler().setFromQuaternion({ x: initialMesh.rotationQuaternion.x, y: initialMesh.rotationQuaternion.y, z: initialMesh.rotationQuaternion.z, s: initialMesh.rotationQuaternion.w });
+            body.resetRotation(rot.x / OIMO.TO_RAD, rot.y / OIMO.TO_RAD, rot.z / OIMO.TO_RAD);
             this._registeredMeshes.push({
                 mesh: initialMesh,
                 body: body
@@ -143,10 +136,23 @@ var BABYLON;
             return body;
         };
         OimoJSPlugin.prototype._createBodyAsCompound = function (part, options, initialMesh) {
-            var bodyParameters = null;
             var mesh = part.mesh;
+            if (!mesh.rotationQuaternion) {
+                mesh.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(mesh.rotation.y, mesh.rotation.x, mesh.rotation.z);
+            }
             // We need the bounding box/sphere info to compute the physics body
-            mesh.computeWorldMatrix();
+            mesh.computeWorldMatrix(true);
+            var rot = new OIMO.Euler().setFromQuaternion({ x: mesh.rotationQuaternion.x, y: mesh.rotationQuaternion.y, z: mesh.rotationQuaternion.z, s: mesh.rotationQuaternion.w });
+            var bodyParameters = {
+                pos: [mesh.position.x, mesh.position.y, mesh.position.z],
+                //A bug in Oimo (Body class) prevents us from using rot directly.
+                rot: [0, 0, 0],
+                //For future reference, if the bug will ever be fixed.
+                realRot: [rot.x / OIMO.TO_RAD, rot.y / OIMO.TO_RAD, rot.z / OIMO.TO_RAD]
+            };
+            var oldQuaternion = mesh.rotationQuaternion;
+            mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
+            mesh.computeWorldMatrix(true);
             switch (part.impostor) {
                 case BABYLON.PhysicsEngine.SphereImpostor:
                     var bbox = mesh.getBoundingInfo().boundingBox;
@@ -154,15 +160,11 @@ var BABYLON;
                     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;
-                    bodyParameters = {
-                        type: 'sphere',
-                        /* bug with oimo : sphere needs 3 sizes in this case */
-                        size: [size, -1, -1],
-                        pos: [mesh.position.x, mesh.position.y, mesh.position.z],
-                        rot: [mesh.rotation.x / OIMO.TO_RAD, mesh.rotation.y / OIMO.TO_RAD, mesh.rotation.z / OIMO.TO_RAD]
-                    };
+                    bodyParameters.type = 'sphere';
+                    bodyParameters.size = [size, size, size];
                     break;
                 case BABYLON.PhysicsEngine.PlaneImpostor:
+                case BABYLON.PhysicsEngine.CylinderImpostor:
                 case BABYLON.PhysicsEngine.BoxImpostor:
                     bbox = mesh.getBoundingInfo().boundingBox;
                     var min = bbox.minimumWorld;
@@ -171,15 +173,11 @@ var BABYLON;
                     var sizeX = this._checkWithEpsilon(box.x);
                     var sizeY = this._checkWithEpsilon(box.y);
                     var sizeZ = this._checkWithEpsilon(box.z);
-                    var relativePosition = mesh.position;
-                    bodyParameters = {
-                        type: 'box',
-                        size: [sizeX, sizeY, sizeZ],
-                        pos: [relativePosition.x, relativePosition.y, relativePosition.z],
-                        rot: [mesh.rotation.x / OIMO.TO_RAD, mesh.rotation.y / OIMO.TO_RAD, mesh.rotation.z / OIMO.TO_RAD]
-                    };
+                    bodyParameters.type = 'box';
+                    bodyParameters.size = [sizeX, sizeY, sizeZ];
                     break;
             }
+            mesh.rotationQuaternion = oldQuaternion;
             return bodyParameters;
         };
         OimoJSPlugin.prototype.unregisterMesh = function (mesh) {
@@ -257,6 +255,18 @@ var BABYLON;
         OimoJSPlugin.prototype.isSupported = function () {
             return OIMO !== undefined;
         };
+        OimoJSPlugin.prototype.getWorldObject = function () {
+            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) {
             var lastShape = body.shapes;
             while (lastShape.next) {
@@ -272,41 +282,22 @@ var BABYLON;
             while (i--) {
                 var body = this._registeredMeshes[i].body.body;
                 var mesh = this._registeredMeshes[i].mesh;
-                var delta = this._registeredMeshes[i].delta;
+                if (!this._registeredMeshes[i].delta) {
+                    this._registeredMeshes[i].delta = BABYLON.Vector3.Zero();
+                }
                 if (!body.sleeping) {
+                    //TODO check that
                     if (body.shapes.next) {
                         var parentShape = this._getLastShape(body);
                         mesh.position.x = parentShape.position.x * OIMO.WORLD_SCALE;
                         mesh.position.y = parentShape.position.y * OIMO.WORLD_SCALE;
                         mesh.position.z = parentShape.position.z * OIMO.WORLD_SCALE;
-                        var mtx = BABYLON.Matrix.FromArray(body.getMatrix());
-                        if (!mesh.rotationQuaternion) {
-                            mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
-                        }
-                        mesh.rotationQuaternion.fromRotationMatrix(mtx);
-                        mesh.computeWorldMatrix();
                     }
                     else {
-                        m = body.getMatrix();
-                        mtx = BABYLON.Matrix.FromArray(m);
-                        // Body position
-                        var bodyX = mtx.m[12], bodyY = mtx.m[13], bodyZ = mtx.m[14];
-                        if (!delta) {
-                            mesh.position.x = bodyX;
-                            mesh.position.y = bodyY;
-                            mesh.position.z = bodyZ;
-                        }
-                        else {
-                            mesh.position.x = bodyX + delta.x;
-                            mesh.position.y = bodyY + delta.y;
-                            mesh.position.z = bodyZ + delta.z;
-                        }
-                        if (!mesh.rotationQuaternion) {
-                            mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
-                        }
-                        BABYLON.Quaternion.FromRotationMatrixToRef(mtx, mesh.rotationQuaternion);
-                        mesh.computeWorldMatrix();
+                        mesh.position.copyFrom(body.getPosition()).addInPlace(this._registeredMeshes[i].delta);
                     }
+                    mesh.rotationQuaternion.copyFrom(body.getQuaternion());
+                    mesh.computeWorldMatrix();
                 }
             }
         };

+ 98 - 97
src/Physics/Plugins/babylon.oimoJSPlugin.ts

@@ -10,7 +10,7 @@ module BABYLON {
         }
 
         public initialize(iterations?: number): void {
-            this._world = new OIMO.World();
+            this._world = new OIMO.World(null, null, iterations);
             this._world.clear();
         }
 
@@ -19,35 +19,38 @@ module BABYLON {
         }
 
         public registerMesh(mesh: AbstractMesh, impostor: number, options: PhysicsBodyCreationOptions): any {
-            var body = null;
             this.unregisterMesh(mesh);
-            mesh.computeWorldMatrix(true);
-
 
-            var initialRotation = null;
-            if (mesh.rotationQuaternion) {
-                initialRotation = mesh.rotationQuaternion.clone();
-                mesh.rotationQuaternion = new Quaternion(0, 0, 0, 1);
-                mesh.computeWorldMatrix(true);
+            if (!mesh.rotationQuaternion) {
+                mesh.rotationQuaternion = Quaternion.RotationYawPitchRoll(mesh.rotation.y, mesh.rotation.x, mesh.rotation.z);
             }
 
+            mesh.computeWorldMatrix(true);
+
             var bbox = mesh.getBoundingInfo().boundingBox;
 
             // The delta between the mesh position and the mesh bounding box center
             var deltaPosition = mesh.position.subtract(bbox.center);
+            
+            //calculate rotation to fit Oimo's needs (Euler...)
+            var rot = new OIMO.Euler().setFromQuaternion({ x: mesh.rotationQuaternion.x, y: mesh.rotationQuaternion.y, z: mesh.rotationQuaternion.z, s: mesh.rotationQuaternion.w });
 
-            // Transform delta position with the rotation
-            if (initialRotation) {
-                var m = new Matrix();
-                initialRotation.toRotationMatrix(m);
-                deltaPosition = Vector3.TransformCoordinates(deltaPosition, m);
-            }
+            //get the correct bounding box
+            var oldQuaternion = mesh.rotationQuaternion;
+            mesh.rotationQuaternion = new Quaternion(0, 0, 0, 1);
+            mesh.computeWorldMatrix(true);
+
+            var bodyConfig: any = {
+                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],
+                move: options.mass != 0,
+                config: [options.mass, options.friction, options.restitution],
+                world: this._world
+            };
 
             // register mesh
             switch (impostor) {
                 case 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;
@@ -57,16 +60,8 @@ module BABYLON {
                         this._checkWithEpsilon(radiusY),
                         this._checkWithEpsilon(radiusZ)) / 2;
 
-                    body = new OIMO.Body({
-                        type: 'sphere',
-                        size: [size],
-                        pos: [bbox.center.x, bbox.center.y, bbox.center.z],
-                        rot: [mesh.rotation.x / OIMO.TO_RAD, mesh.rotation.y / OIMO.TO_RAD, mesh.rotation.z / OIMO.TO_RAD],
-                        move: options.mass != 0,
-                        config: [options.mass, options.friction, options.restitution],
-                        world: this._world
-                    });
-
+                    bodyConfig.type = 'sphere';
+                    bodyConfig.size = [size];
                     break;
 
                 case PhysicsEngine.PlaneImpostor:
@@ -81,33 +76,29 @@ module BABYLON {
                     var sizeY = this._checkWithEpsilon(box.y);
                     var sizeZ = this._checkWithEpsilon(box.z);
 
-                    body = new OIMO.Body({
-                        type: 'box',
-                        size: [sizeX, sizeY, sizeZ],
-                        pos: [bbox.center.x, bbox.center.y, bbox.center.z],
-                        rot: [mesh.rotation.x / OIMO.TO_RAD, mesh.rotation.y / OIMO.TO_RAD, mesh.rotation.z / OIMO.TO_RAD],
-                        move: options.mass != 0,
-                        config: [options.mass, options.friction, options.restitution],
-                        world: this._world
-                    });
-
+                    bodyConfig.type = 'box';
+                    bodyConfig.size = [sizeX, sizeY, sizeZ];
                     break;
             }
 
-            //If quaternion was set as the rotation of the object
-            if (initialRotation) {
-                //We have to access the rigid body's properties to set the quaternion. 
-                //The setQuaternion function of Oimo only sets the newOrientation that is only set after an impulse is given or a collision.
-                body.body.orientation = new OIMO.Quat(initialRotation.w, initialRotation.x, initialRotation.y, initialRotation.z);
-                //update the internal rotation matrix
-                body.body.syncShapes();
-            }
+            var body = new OIMO.Body(bodyConfig);
 
+            //We have to access the rigid body's properties to set the quaternion. 
+            //The setQuaternion function of Oimo only sets the newOrientation that is only set after an impulse is given or a collision.
+            //body.body.orientation = new OIMO.Quat(mesh.rotationQuaternion.w, mesh.rotationQuaternion.x, mesh.rotationQuaternion.y, mesh.rotationQuaternion.z);
+            //TEST
+            //body.body.resetQuaternion(new OIMO.Quat(mesh.rotationQuaternion.w, mesh.rotationQuaternion.x, mesh.rotationQuaternion.y, mesh.rotationQuaternion.z));
+            //update the internal rotation matrix
+            //body.body.syncShapes();
+            
             this._registeredMeshes.push({
                 mesh: mesh,
                 body: body,
                 delta: deltaPosition
             });
+			
+            //for the sake of consistency.
+            mesh.rotationQuaternion = oldQuaternion;
 
             return body;
         }
@@ -138,6 +129,11 @@ module BABYLON {
                 config: [options.mass, options.friction, options.restitution],
                 world: this._world
             });
+            
+            //Reset the body's rotation to be of the initial mesh's.
+            var rot = new OIMO.Euler().setFromQuaternion({ x: initialMesh.rotationQuaternion.x, y: initialMesh.rotationQuaternion.y, z: initialMesh.rotationQuaternion.z, s: initialMesh.rotationQuaternion.w });
+
+            body.resetRotation(rot.x / OIMO.TO_RAD, rot.y / OIMO.TO_RAD, rot.z / OIMO.TO_RAD);
 
             this._registeredMeshes.push({
                 mesh: initialMesh,
@@ -148,10 +144,28 @@ module BABYLON {
         }
 
         private _createBodyAsCompound(part: PhysicsCompoundBodyPart, options: PhysicsBodyCreationOptions, initialMesh: AbstractMesh): any {
-            var bodyParameters = null;
             var mesh = part.mesh;
+
+            if (!mesh.rotationQuaternion) {
+                mesh.rotationQuaternion = Quaternion.RotationYawPitchRoll(mesh.rotation.y, mesh.rotation.x, mesh.rotation.z);
+            }
+			
             // We need the bounding box/sphere info to compute the physics body
-            mesh.computeWorldMatrix();
+            mesh.computeWorldMatrix(true);
+
+            var rot = new OIMO.Euler().setFromQuaternion({ x: mesh.rotationQuaternion.x, y: mesh.rotationQuaternion.y, z: mesh.rotationQuaternion.z, s: mesh.rotationQuaternion.w });
+
+            var bodyParameters: any = {
+                pos: [mesh.position.x, mesh.position.y, mesh.position.z],
+                //A bug in Oimo (Body class) prevents us from using rot directly.
+                rot: [0, 0, 0],
+                //For future reference, if the bug will ever be fixed.
+                realRot: [rot.x / OIMO.TO_RAD, rot.y / OIMO.TO_RAD, rot.z / OIMO.TO_RAD]
+            };
+
+            var oldQuaternion = mesh.rotationQuaternion;
+            mesh.rotationQuaternion = new Quaternion(0, 0, 0, 1);
+            mesh.computeWorldMatrix(true);
 
             switch (part.impostor) {
                 case PhysicsEngine.SphereImpostor:
@@ -164,16 +178,14 @@ module BABYLON {
                         this._checkWithEpsilon(radiusX),
                         this._checkWithEpsilon(radiusY),
                         this._checkWithEpsilon(radiusZ)) / 2;
-                    bodyParameters = {
-                        type: 'sphere',
-                        /* bug with oimo : sphere needs 3 sizes in this case */
-                        size: [size, -1, -1],
-                        pos: [mesh.position.x, mesh.position.y, mesh.position.z],
-                        rot: [mesh.rotation.x / OIMO.TO_RAD, mesh.rotation.y / OIMO.TO_RAD, mesh.rotation.z / OIMO.TO_RAD]
-                    };
+
+                    bodyParameters.type = 'sphere';
+                    bodyParameters.size = [size, size, size];
+
                     break;
 
                 case PhysicsEngine.PlaneImpostor:
+                case PhysicsEngine.CylinderImpostor:
                 case PhysicsEngine.BoxImpostor:
                     bbox = mesh.getBoundingInfo().boundingBox;
                     var min = bbox.minimumWorld;
@@ -182,16 +194,15 @@ module BABYLON {
                     var sizeX = this._checkWithEpsilon(box.x);
                     var sizeY = this._checkWithEpsilon(box.y);
                     var sizeZ = this._checkWithEpsilon(box.z);
-                    var relativePosition = mesh.position;
-                    bodyParameters = {
-                        type: 'box',
-                        size: [sizeX, sizeY, sizeZ],
-                        pos: [relativePosition.x, relativePosition.y, relativePosition.z],
-                        rot: [mesh.rotation.x / OIMO.TO_RAD, mesh.rotation.y / OIMO.TO_RAD, mesh.rotation.z / OIMO.TO_RAD]
-                    };
+
+                    bodyParameters.type = 'box';
+                    bodyParameters.size = [sizeX, sizeY, sizeZ];
+
                     break;
             }
 
+            mesh.rotationQuaternion = oldQuaternion;
+
             return bodyParameters;
         }
 
@@ -232,7 +243,7 @@ module BABYLON {
 
                     var center = mesh.getBoundingInfo().boundingBox.center;
                     body.setPosition(new OIMO.Vec3(center.x, center.y, center.z));
-                    body.setRotation(new OIMO.Vec3(mesh.rotation.x, mesh.rotation.y, mesh.rotation.z));
+                    body.setQuaternion(mesh.rotationQuaternion);
                     body.sleeping = false;
                     return;
                 }
@@ -242,11 +253,10 @@ module BABYLON {
                     registeredMesh.mesh.computeWorldMatrix(true);
 
                     var absolutePosition = registeredMesh.mesh.getAbsolutePosition();
-                    var absoluteRotation = mesh.rotation;
 
                     body = registeredMesh.body.body;
                     body.setPosition(new OIMO.Vec3(absolutePosition.x, absolutePosition.y, absolutePosition.z));
-                    body.setRotation(new OIMO.Vec3(absoluteRotation.x, absoluteRotation.y, absoluteRotation.z));
+                    body.setQuaternion(mesh.rotationQuaternion);
                     body.sleeping = false;
                     return;
                 }
@@ -314,6 +324,20 @@ module BABYLON {
             return OIMO !== undefined;
         }
 
+        public getWorldObject(): any {
+            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 {
             var lastShape = body.shapes;
             while (lastShape.next) {
@@ -332,50 +356,27 @@ module BABYLON {
 
                 var body = this._registeredMeshes[i].body.body;
                 var mesh = this._registeredMeshes[i].mesh;
-                var delta = this._registeredMeshes[i].delta;
 
-                if (!body.sleeping) {
+                if (!this._registeredMeshes[i].delta) {
+                    this._registeredMeshes[i].delta = Vector3.Zero();
+                }
 
+                if (!body.sleeping) {
+                    //TODO check that
                     if (body.shapes.next) {
                         var parentShape = this._getLastShape(body);
                         mesh.position.x = parentShape.position.x * OIMO.WORLD_SCALE;
                         mesh.position.y = parentShape.position.y * OIMO.WORLD_SCALE;
                         mesh.position.z = parentShape.position.z * OIMO.WORLD_SCALE;
-                        var mtx = Matrix.FromArray(body.getMatrix());
-
-                        if (!mesh.rotationQuaternion) {
-                            mesh.rotationQuaternion = new Quaternion(0, 0, 0, 1);
-                        }
-                        mesh.rotationQuaternion.fromRotationMatrix(mtx);
-                        mesh.computeWorldMatrix();
-
                     } else {
-                        m = body.getMatrix();
-                        mtx = Matrix.FromArray(m);
-
-                        // Body position
-                        var bodyX = mtx.m[12],
-                            bodyY = mtx.m[13],
-                            bodyZ = mtx.m[14];
-
-                        if (!delta) {
-                            mesh.position.x = bodyX;
-                            mesh.position.y = bodyY;
-                            mesh.position.z = bodyZ;
-                        } else {
-                            mesh.position.x = bodyX + delta.x;
-                            mesh.position.y = bodyY + delta.y;
-                            mesh.position.z = bodyZ + delta.z;
-                        }
-
-                        if (!mesh.rotationQuaternion) {
-                            mesh.rotationQuaternion = new Quaternion(0, 0, 0, 1);
-                        }
-                        Quaternion.FromRotationMatrixToRef(mtx, mesh.rotationQuaternion);
-                        mesh.computeWorldMatrix();
+                        mesh.position.copyFrom(body.getPosition()).addInPlace(this._registeredMeshes[i].delta);
+
                     }
+                    mesh.rotationQuaternion.copyFrom(body.getQuaternion());
+                    mesh.computeWorldMatrix();
                 }
             }
         }
     }
 }
+

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

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

+ 7 - 1
src/Physics/babylon.physicsEngine.ts

@@ -11,6 +11,8 @@
         dispose(): void;
         isSupported(): boolean;
         updateBodyPosition(mesh: AbstractMesh): void;
+        getWorldObject(): any; //Will return the physics world object of the engine used.
+        getPhysicsBodyOfMesh(mesh: AbstractMesh): any;
     }
 
     export interface PhysicsBodyCreationOptions {
@@ -85,6 +87,10 @@
             return this._currentPlugin.isSupported();
         }
 
+        public getPhysicsBodyOfMesh(mesh: AbstractMesh) {
+            return this._currentPlugin.getPhysicsBodyOfMesh(mesh);
+        }
+
         // Statics
         public static NoImpostor = 0;
         public static SphereImpostor = 1;
@@ -97,4 +103,4 @@
         public static ConvexHullImpostor = 8;
         public static Epsilon = 0.001;
     }
-}
+}

+ 0 - 1
src/Probes/babylon.reflectionProbe.js

@@ -1,7 +1,6 @@
 var BABYLON;
 (function (BABYLON) {
     var ReflectionProbe = (function () {
-        //http://localhost:61437/Playground/index%20-%20debug.html#KA93U#7
         function ReflectionProbe(name, size, scene, generateMipMaps) {
             var _this = this;
             if (generateMipMaps === void 0) { generateMipMaps = true; }

+ 0 - 1
src/Probes/babylon.reflectionProbe.ts

@@ -10,7 +10,6 @@
 
         public position = Vector3.Zero();
           
-        //http://localhost:61437/Playground/index%20-%20debug.html#KA93U#7
         constructor(public name: string, size: number, scene: Scene, generateMipMaps = true) {
             this._scene = scene;
 

+ 111 - 60
src/Shaders/default.fragment.fx

@@ -152,24 +152,72 @@ uniform vec4 diffuseRightColor;
 uniform vec4 opacityParts;
 #endif
 
-#ifdef REFLECTIONFRESNEL
-uniform vec4 reflectionLeftColor;
-uniform vec4 reflectionRightColor;
-#endif
-
 #ifdef EMISSIVEFRESNEL
 uniform vec4 emissiveLeftColor;
 uniform vec4 emissiveRightColor;
 #endif
 
+// Reflection
 #ifdef REFLECTION
-varying vec3 vReflectionUVW;
+uniform vec2 vReflectionInfos;
+
 #ifdef REFLECTIONMAP_3D
 uniform samplerCube reflectionCubeSampler;
 #else
 uniform sampler2D reflection2DSampler;
 #endif
-uniform vec2 vReflectionInfos;
+
+#ifdef REFLECTIONMAP_SKYBOX
+	varying vec3 vPositionUVW;
+#else
+	uniform mat4 reflectionMatrix;
+#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION)
+	uniform mat4 view;
+#endif
+#endif
+
+vec3 computeReflectionCoords(vec4 worldPos, vec3 worldNormal)
+{
+#ifdef REFLECTIONMAP_SPHERICAL
+	vec3 coords = vec3(view * vec4(worldNormal, 0.0));
+
+	return vec3(reflectionMatrix * vec4(coords, 1.0));
+#endif
+
+#ifdef REFLECTIONMAP_PLANAR
+	vec3 viewDir = worldPos.xyz - vEyePosition;
+	vec3 coords = normalize(reflect(viewDir, worldNormal));
+
+	return vec3(reflectionMatrix * vec4(coords, 1));
+#endif
+
+#ifdef REFLECTIONMAP_CUBIC
+	vec3 viewDir = worldPos.xyz - vEyePosition;
+	vec3 coords = reflect(viewDir, worldNormal);
+#ifdef INVERTCUBICMAP
+	coords.y = 1.0 - coords.y;
+#endif
+	return vec3(reflectionMatrix * vec4(coords, 0));
+#endif
+
+#ifdef REFLECTIONMAP_PROJECTION
+	return vec3(reflectionMatrix * (view * worldPos));
+#endif
+
+#ifdef REFLECTIONMAP_SKYBOX
+	return vPositionUVW;
+#endif
+
+#ifdef REFLECTIONMAP_EXPLICIT
+	return vec3(0, 0, 0);
+#endif
+}
+
+#ifdef REFLECTIONFRESNEL
+uniform vec4 reflectionLeftColor;
+uniform vec4 reflectionRightColor;
+#endif
+
 #endif
 
 // Shadows
@@ -506,13 +554,13 @@ void main(void) {
 	float glossiness = vSpecularColor.a;
 	vec3 specularColor = vSpecularColor.rgb;
 
-	#ifdef SPECULAR
-		vec4 specularMapColor = texture2D(specularSampler, vSpecularUV);
-		specularColor = specularMapColor.rgb;
-		#ifdef GLOSSINESS
-			glossiness = glossiness * specularMapColor.a;
-		#endif
-	#endif
+#ifdef SPECULAR
+	vec4 specularMapColor = texture2D(specularSampler, vSpecularUV);
+	specularColor = specularMapColor.rgb;
+#ifdef GLOSSINESS
+	glossiness = glossiness * specularMapColor.a;
+#endif
+#endif
 #else
 	float glossiness = 0.;
 #endif
@@ -541,11 +589,11 @@ void main(void) {
 #ifdef SHADOWVSM0
 	shadow = computeShadowWithVSM(vPositionFromLight0, shadowSampler0, shadowsInfo0.z, shadowsInfo0.x);
 #else
-	#ifdef SHADOWPCF0
-		shadow = computeShadowWithPCF(vPositionFromLight0, shadowSampler0, shadowsInfo0.y, shadowsInfo0.z, shadowsInfo0.x);
-	#else
-		shadow = computeShadow(vPositionFromLight0, shadowSampler0, shadowsInfo0.x, shadowsInfo0.z);
-	#endif
+#ifdef SHADOWPCF0
+	shadow = computeShadowWithPCF(vPositionFromLight0, shadowSampler0, shadowsInfo0.y, shadowsInfo0.z, shadowsInfo0.x);
+#else
+	shadow = computeShadow(vPositionFromLight0, shadowSampler0, shadowsInfo0.x, shadowsInfo0.z);
+#endif
 #endif
 #else
 	shadow = 1.;
@@ -573,11 +621,11 @@ void main(void) {
 #ifdef SHADOWVSM1
 	shadow = computeShadowWithVSM(vPositionFromLight1, shadowSampler1, shadowsInfo1.z, shadowsInfo1.x);
 #else
-	#ifdef SHADOWPCF1
-		shadow = computeShadowWithPCF(vPositionFromLight1, shadowSampler1, shadowsInfo1.y, shadowsInfo1.z, shadowsInfo1.x);
-	#else
-		shadow = computeShadow(vPositionFromLight1, shadowSampler1, shadowsInfo1.x, shadowsInfo1.z);
-	#endif
+#ifdef SHADOWPCF1
+	shadow = computeShadowWithPCF(vPositionFromLight1, shadowSampler1, shadowsInfo1.y, shadowsInfo1.z, shadowsInfo1.x);
+#else
+	shadow = computeShadow(vPositionFromLight1, shadowSampler1, shadowsInfo1.x, shadowsInfo1.z);
+#endif
 #endif
 #else
 	shadow = 1.;
@@ -605,11 +653,11 @@ void main(void) {
 #ifdef SHADOWVSM2
 	shadow = computeShadowWithVSM(vPositionFromLight2, shadowSampler2, shadowsInfo2.z, shadowsInfo2.x);
 #else
-	#ifdef SHADOWPCF2
-		shadow = computeShadowWithPCF(vPositionFromLight2, shadowSampler2, shadowsInfo2.y, shadowsInfo2.z, shadowsInfo2.x);
-	#else
-		shadow = computeShadow(vPositionFromLight2, shadowSampler2, shadowsInfo2.x, shadowsInfo2.z);
-	#endif	
+#ifdef SHADOWPCF2
+	shadow = computeShadowWithPCF(vPositionFromLight2, shadowSampler2, shadowsInfo2.y, shadowsInfo2.z, shadowsInfo2.x);
+#else
+	shadow = computeShadow(vPositionFromLight2, shadowSampler2, shadowsInfo2.x, shadowsInfo2.z);
+#endif	
 #endif	
 #else
 	shadow = 1.;
@@ -637,11 +685,11 @@ void main(void) {
 #ifdef SHADOWVSM3
 	shadow = computeShadowWithVSM(vPositionFromLight3, shadowSampler3, shadowsInfo3.z, shadowsInfo3.x);
 #else
-	#ifdef SHADOWPCF3
-		shadow = computeShadowWithPCF(vPositionFromLight3, shadowSampler3, shadowsInfo3.y, shadowsInfo3.z, shadowsInfo3.x);
-	#else
-		shadow = computeShadow(vPositionFromLight3, shadowSampler3, shadowsInfo3.x, shadowsInfo3.z);
-	#endif	
+#ifdef SHADOWPCF3
+	shadow = computeShadowWithPCF(vPositionFromLight3, shadowSampler3, shadowsInfo3.y, shadowsInfo3.z, shadowsInfo3.x);
+#else
+	shadow = computeShadow(vPositionFromLight3, shadowSampler3, shadowsInfo3.x, shadowsInfo3.z);
+#endif	
 #endif	
 #else
 	shadow = 1.;
@@ -655,34 +703,37 @@ void main(void) {
 	// Reflection
 	vec3 reflectionColor = vec3(0., 0., 0.);
 
+
 #ifdef REFLECTION
-	#ifdef REFLECTIONMAP_3D
-			float bias = 0.;
+	vec3 vReflectionUVW = computeReflectionCoords(vec4(vPositionW, 1.0), normalW);
 
-		#ifdef ROUGHNESS
-				bias = vReflectionInfos.y;
-		#endif
+#ifdef REFLECTIONMAP_3D
+	float bias = 0.;
 
-		#ifdef SPECULARTERM
-			#ifdef SPECULAR
-				#ifdef GLOSSINESS
-						bias *= (1.0 - specularMapColor.a);
-				#endif
-			#endif
-		#endif
+#ifdef ROUGHNESS
+	bias = vReflectionInfos.y;
+#endif
+
+#ifdef SPECULARTERM
+#ifdef SPECULAR
+#ifdef GLOSSINESS
+	bias *= (1.0 - specularMapColor.a);
+#endif
+#endif
+#endif
 
-		reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW, bias).rgb * vReflectionInfos.x * shadow;
-	#else
-		vec2 coords = vReflectionUVW.xy;
+	reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW, bias).rgb * vReflectionInfos.x * shadow;
+#else
+	vec2 coords = vReflectionUVW.xy;
 
-		#ifdef REFLECTIONMAP_PROJECTION
-			coords /= vReflectionUVW.z;
-		#endif
+#ifdef REFLECTIONMAP_PROJECTION
+	coords /= vReflectionUVW.z;
+#endif
 
-		coords.y = 1.0 - coords.y;
+	coords.y = 1.0 - coords.y;
 
-		reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.x * shadow;
-#endif	
+	reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.x * shadow;
+#endif
 
 #ifdef REFLECTIONFRESNEL
 	float reflectionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, reflectionRightColor.a, reflectionLeftColor.a);
@@ -725,7 +776,7 @@ void main(void) {
 	// Emissive
 	vec3 emissiveColor = vEmissiveColor;
 #ifdef EMISSIVE
-    emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;
+	emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;
 #endif
 
 #ifdef EMISSIVEFRESNEL
@@ -745,7 +796,7 @@ void main(void) {
 #ifdef EMISSIVEASILLUMINATION
 	vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;
 #else
-    vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;
+	vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;
 #endif
 
 #ifdef SPECULARTERM
@@ -758,11 +809,11 @@ void main(void) {
 	alpha = clamp(alpha + dot(finalSpecular, vec3(0.3, 0.59, 0.11)), 0., 1.);
 #endif
 
-// Composition
+	// Composition
 #ifdef EMISSIVEASILLUMINATION
-    vec4 color = vec4(clamp(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor + emissiveColor, 0.0, 1.0), alpha);
+	vec4 color = vec4(clamp(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor + emissiveColor, 0.0, 1.0), alpha);
 #else
-    vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);
+	vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);
 #endif
 
 #ifdef LIGHTMAP

+ 5 - 44
src/Shaders/default.vertex.fx

@@ -121,52 +121,17 @@ varying vec4 vPositionFromLight3;
 #endif
 #endif
 
-#ifdef REFLECTION
-uniform vec3 vEyePosition;
-varying vec3 vReflectionUVW;
-uniform mat4 reflectionMatrix;
-
-vec3 computeReflectionCoords(vec4 worldPos, vec3 worldNormal)
-{
-#ifdef REFLECTIONMAP_SPHERICAL
-	vec3 coords = vec3(view * vec4(worldNormal, 0.0));
-
-	return vec3(reflectionMatrix * vec4(coords, 1.0));
-#endif
-
-#ifdef REFLECTIONMAP_PLANAR
-	vec3 viewDir = worldPos.xyz - vEyePosition;
-	vec3 coords = normalize(reflect(viewDir, worldNormal));
-
-	return vec3(reflectionMatrix * vec4(coords, 1));
-#endif
-
-#ifdef REFLECTIONMAP_CUBIC
-	vec3 viewDir = worldPos.xyz - vEyePosition;
-	vec3 coords = reflect(viewDir, worldNormal);
-#ifdef INVERTCUBICMAP
-	coords.y = 1.0 - coords.y;
-#endif
-	return vec3(reflectionMatrix * vec4(coords, 0));
-#endif
-
-#ifdef REFLECTIONMAP_PROJECTION
-	return vec3(reflectionMatrix * (view * worldPos));
-#endif
-
 #ifdef REFLECTIONMAP_SKYBOX
-	return position;
-#endif
-
-#ifdef REFLECTIONMAP_EXPLICIT
-	return vec3(0, 0, 0);
-#endif
-}
+varying vec3 vPositionUVW;
 #endif
 
 void main(void) {
 	mat4 finalWorld;
 
+#ifdef REFLECTIONMAP_SKYBOX
+	vPositionUVW = position;
+#endif 
+
 #ifdef INSTANCES
 	finalWorld = mat4(world0, world1, world2, world3);
 #else
@@ -236,10 +201,6 @@ void main(void) {
 	}
 #endif
 
-#ifdef REFLECTION
-	vReflectionUVW = computeReflectionCoords(vec4(vPositionW, 1.0), vNormalW);
-#endif
-
 #ifdef EMISSIVE
 	if (vEmissiveInfos.x == 0.)
 	{

+ 10 - 0
src/babylon.scene.js

@@ -1810,6 +1810,12 @@ var BABYLON;
         Scene.prototype.getPhysicsEngine = function () {
             return this._physicsEngine;
         };
+        /**
+         * Enables physics to the current scene
+         * @param {BABYLON.Vector3} [gravity] - the scene's gravity for the physics engine
+         * @param {BABYLON.IPhysicsEnginePlugin} [plugin] - The physics engine to be used. defaults to OimoJS.
+         * @return {boolean} was the physics engine initialized
+         */
         Scene.prototype.enablePhysics = function (gravity, plugin) {
             if (this._physicsEngine) {
                 return true;
@@ -1832,6 +1838,10 @@ var BABYLON;
         Scene.prototype.isPhysicsEnabled = function () {
             return this._physicsEngine !== undefined;
         };
+        /**
+         * Sets the gravity of the physics engine (and NOT of the scene)
+         * @param {BABYLON.Vector3} [gravity] - the new gravity to be used
+         */
         Scene.prototype.setGravity = function (gravity) {
             if (!this._physicsEngine) {
                 return;

+ 13 - 3
src/babylon.scene.ts

@@ -320,7 +320,7 @@
         }
 
         public set workerCollisions(enabled: boolean) {
-        
+
             enabled = (enabled && !!Worker);
 
             this._workerCollisions = enabled;
@@ -2272,7 +2272,13 @@
             return this._physicsEngine;
         }
 
-        public enablePhysics(gravity: Vector3, plugin?: IPhysicsEnginePlugin): boolean {
+        /**
+         * Enables physics to the current scene
+         * @param {BABYLON.Vector3} [gravity] - the scene's gravity for the physics engine
+         * @param {BABYLON.IPhysicsEnginePlugin} [plugin] - The physics engine to be used. defaults to OimoJS.
+         * @return {boolean} was the physics engine initialized
+         */
+        public enablePhysics(gravity?: Vector3, plugin?: IPhysicsEnginePlugin): boolean {
             if (this._physicsEngine) {
                 return true;
             }
@@ -2302,6 +2308,10 @@
             return this._physicsEngine !== undefined;
         }
 
+        /**
+         * Sets the gravity of the physics engine (and NOT of the scene)
+         * @param {BABYLON.Vector3} [gravity] - the new gravity to be used
+         */
         public setGravity(gravity: Vector3): void {
             if (!this._physicsEngine) {
                 return;
@@ -2400,4 +2410,4 @@
             return this._getByTags(this.materials, tagsQuery, forEach).concat(this._getByTags(this.multiMaterials, tagsQuery, forEach));
         }
     }
-} 
+}