Просмотр исходного кода

Fixed cameras and lights when in right handed mode

David Catuhe 9 лет назад
Родитель
Сommit
9619e67f9d

Разница между файлами не показана из-за своего большого размера
+ 25 - 24
dist/preview release/babylon.core.js


Разница между файлами не показана из-за своего большого размера
+ 2740 - 2739
dist/preview release/babylon.d.ts


Разница между файлами не показана из-за своего большого размера
+ 37 - 36
dist/preview release/babylon.js


+ 89 - 13
dist/preview release/babylon.max.js

@@ -11132,7 +11132,12 @@ var BABYLON;
                 effect.setFloat4(positionUniformName, this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, 0);
                 return;
             }
-            effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, 0);
+            if (this.getScene().useRightHandedSystem) {
+                effect.setFloat4(positionUniformName, -this.position.x, -this.position.y, -this.position.z, 0);
+            }
+            else {
+                effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, 0);
+            }
         };
         PointLight.prototype.needCube = function () {
             return true;
@@ -11240,14 +11245,29 @@ var BABYLON;
                 }
                 this.computeTransformedPosition();
                 BABYLON.Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this._transformedDirection);
-                effect.setFloat4(positionUniformName, this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, this.exponent);
+                if (this.getScene().useRightHandedSystem) {
+                    effect.setFloat4(positionUniformName, -this.transformedPosition.x, -this.transformedPosition.y, -this.transformedPosition.z, this.exponent);
+                }
+                else {
+                    effect.setFloat4(positionUniformName, this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, this.exponent);
+                }
                 normalizeDirection = BABYLON.Vector3.Normalize(this._transformedDirection);
             }
             else {
-                effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, this.exponent);
+                if (this.getScene().useRightHandedSystem) {
+                    effect.setFloat4(positionUniformName, -this.position.x, -this.position.y, -this.position.z, this.exponent);
+                }
+                else {
+                    effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, this.exponent);
+                }
                 normalizeDirection = BABYLON.Vector3.Normalize(this.direction);
             }
-            effect.setFloat4(directionUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, Math.cos(this.angle * 0.5));
+            if (this.getScene().useRightHandedSystem) {
+                effect.setFloat4(directionUniformName, -normalizeDirection.x, -normalizeDirection.y, -normalizeDirection.z, Math.cos(this.angle * 0.5));
+            }
+            else {
+                effect.setFloat4(directionUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, Math.cos(this.angle * 0.5));
+            }
         };
         SpotLight.prototype._getWorldMatrix = function () {
             if (!this._worldMatrix) {
@@ -11300,7 +11320,12 @@ var BABYLON;
         };
         HemisphericLight.prototype.transferToEffect = function (effect, directionUniformName, groundColorUniformName) {
             var normalizeDirection = BABYLON.Vector3.Normalize(this.direction);
-            effect.setFloat4(directionUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, 0);
+            if (this.getScene().useRightHandedSystem) {
+                effect.setFloat4(directionUniformName, -normalizeDirection.x, -normalizeDirection.y, -normalizeDirection.z, 0);
+            }
+            else {
+                effect.setFloat4(directionUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, 0);
+            }
             effect.setColor3(groundColorUniformName, this.groundColor.scale(this.intensity));
         };
         HemisphericLight.prototype._getWorldMatrix = function () {
@@ -11419,7 +11444,12 @@ var BABYLON;
                 effect.setFloat4(directionUniformName, this._transformedDirection.x, this._transformedDirection.y, this._transformedDirection.z, 1);
                 return;
             }
-            effect.setFloat4(directionUniformName, this.direction.x, this.direction.y, this.direction.z, 1);
+            if (this.getScene().useRightHandedSystem) {
+                effect.setFloat4(directionUniformName, this.direction.x, this.direction.y, this.direction.z, -1);
+            }
+            else {
+                effect.setFloat4(directionUniformName, this.direction.x, this.direction.y, this.direction.z, 1);
+            }
         };
         DirectionalLight.prototype._getWorldMatrix = function () {
             if (!this._worldMatrix) {
@@ -13304,7 +13334,12 @@ var BABYLON;
                             offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
                             offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
                         }
-                        camera.cameraRotation.y += offsetX / _this.angularSensibility;
+                        if (_this.camera.getScene().useRightHandedSystem) {
+                            camera.cameraRotation.y -= offsetX / _this.angularSensibility;
+                        }
+                        else {
+                            camera.cameraRotation.y += offsetX / _this.angularSensibility;
+                        }
                         camera.cameraRotation.x += offsetY / _this.angularSensibility;
                         _this.previousPosition = {
                             x: evt.clientX,
@@ -13421,6 +13456,9 @@ var BABYLON;
                     else if (this.keysDown.indexOf(keyCode) !== -1) {
                         camera._localDirection.copyFromFloats(0, 0, -speed);
                     }
+                    if (camera.getScene().useRightHandedSystem) {
+                        camera._localDirection.z *= -1;
+                    }
                     camera.getViewMatrix().invertToRef(camera._cameraTransformMatrix);
                     BABYLON.Vector3.TransformNormalToRef(camera._localDirection, camera._cameraTransformMatrix, camera._transformedDirection);
                     camera.cameraDirection.addInPlace(camera._transformedDirection);
@@ -15135,8 +15173,13 @@ var BABYLON;
             this.inputs.checkInputs();
             // Inertia
             if (this.inertialAlphaOffset !== 0 || this.inertialBetaOffset !== 0 || this.inertialRadiusOffset !== 0) {
-                this.alpha += this.beta <= 0 ? -this.inertialAlphaOffset : this.inertialAlphaOffset;
                 this.beta += this.inertialBetaOffset;
+                if (this.getScene().useRightHandedSystem) {
+                    this.alpha -= this.beta <= 0 ? -this.inertialAlphaOffset : this.inertialAlphaOffset;
+                }
+                else {
+                    this.alpha += this.beta <= 0 ? -this.inertialAlphaOffset : this.inertialAlphaOffset;
+                }
                 this.radius -= this.inertialRadiusOffset;
                 this.inertialAlphaOffset *= this.inertia;
                 this.inertialBetaOffset *= this.inertia;
@@ -21346,6 +21389,30 @@ var BABYLON;
     var MeshBuilder = (function () {
         function MeshBuilder() {
         }
+        MeshBuilder.updateSideOrientationForRightHandedSystem = function (orientation, scene) {
+            if (!scene.useRightHandedSystem) {
+                if (orientation === undefined || orientation === null) {
+                    return BABYLON.Mesh.FRONTSIDE;
+                }
+                switch (orientation) {
+                    case BABYLON.Mesh.FRONTSIDE:
+                    case BABYLON.Mesh.DEFAULTSIDE:
+                        return BABYLON.Mesh.FRONTSIDE;
+                    default:
+                        return BABYLON.Mesh.BACKSIDE;
+                }
+            }
+            if (orientation === undefined || orientation === null) {
+                return BABYLON.Mesh.BACKSIDE;
+            }
+            switch (orientation) {
+                case BABYLON.Mesh.FRONTSIDE:
+                case BABYLON.Mesh.DEFAULTSIDE:
+                    return BABYLON.Mesh.BACKSIDE;
+                default:
+                    return BABYLON.Mesh.FRONTSIDE;
+            }
+        };
         /**
          * Creates a box mesh.
          * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#box
@@ -21359,6 +21426,7 @@ var BABYLON;
          */
         MeshBuilder.CreateBox = function (name, options, scene) {
             var box = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreateBox(options);
             vertexData.applyToMesh(box, options.updatable);
             return box;
@@ -21377,6 +21445,7 @@ var BABYLON;
          */
         MeshBuilder.CreateSphere = function (name, options, scene) {
             var sphere = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreateSphere(options);
             vertexData.applyToMesh(sphere, options.updatable);
             return sphere;
@@ -21393,6 +21462,7 @@ var BABYLON;
          */
         MeshBuilder.CreateDisc = function (name, options, scene) {
             var disc = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreateDisc(options);
             vertexData.applyToMesh(disc, options.updatable);
             return disc;
@@ -21410,6 +21480,7 @@ var BABYLON;
          */
         MeshBuilder.CreateIcoSphere = function (name, options, scene) {
             var sphere = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreateIcoSphere(options);
             vertexData.applyToMesh(sphere, options.updatable);
             return sphere;
@@ -21436,7 +21507,7 @@ var BABYLON;
             var closeArray = options.closeArray;
             var closePath = options.closePath;
             var offset = options.offset;
-            var sideOrientation = options.sideOrientation;
+            var sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var instance = options.instance;
             var updatable = options.updatable;
             if (instance) {
@@ -21558,6 +21629,7 @@ var BABYLON;
          */
         MeshBuilder.CreateCylinder = function (name, options, scene) {
             var cylinder = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreateCylinder(options);
             vertexData.applyToMesh(cylinder, options.updatable);
             return cylinder;
@@ -21574,6 +21646,7 @@ var BABYLON;
          */
         MeshBuilder.CreateTorus = function (name, options, scene) {
             var torus = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreateTorus(options);
             vertexData.applyToMesh(torus, options.updatable);
             return torus;
@@ -21591,6 +21664,7 @@ var BABYLON;
          */
         MeshBuilder.CreateTorusKnot = function (name, options, scene) {
             var torusKnot = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreateTorusKnot(options);
             vertexData.applyToMesh(torusKnot, options.updatable);
             return torusKnot;
@@ -21744,7 +21818,7 @@ var BABYLON;
             var rotation = options.rotation || 0;
             var cap = (options.cap === 0) ? 0 : options.cap || BABYLON.Mesh.NO_CAP;
             var updatable = options.updatable;
-            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
+            var sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var instance = options.instance;
             var invertUV = options.invertUV || false;
             return MeshBuilder._ExtrudeShapeGeneric(name, shape, path, scale, rotation, null, null, false, false, cap, false, scene, updatable, sideOrientation, instance, invertUV);
@@ -21793,7 +21867,7 @@ var BABYLON;
             var ribbonClosePath = options.ribbonClosePath || false;
             var cap = (options.cap === 0) ? 0 : options.cap || BABYLON.Mesh.NO_CAP;
             var updatable = options.updatable;
-            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
+            var sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var instance = options.instance;
             var invertUV = options.invertUV || false;
             return MeshBuilder._ExtrudeShapeGeneric(name, shape, path, null, null, scaleFunction, rotationFunction, ribbonCloseArray, ribbonClosePath, cap, true, scene, updatable, sideOrientation, instance, invertUV);
@@ -21822,7 +21896,7 @@ var BABYLON;
             var radius = options.radius || 1;
             var tessellation = options.tessellation || 64;
             var updatable = options.updatable;
-            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
+            var sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var cap = options.cap || BABYLON.Mesh.NO_CAP;
             var pi2 = Math.PI * 2;
             var paths = new Array();
@@ -21865,6 +21939,7 @@ var BABYLON;
          */
         MeshBuilder.CreatePlane = function (name, options, scene) {
             var plane = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreatePlane(options);
             vertexData.applyToMesh(plane, options.updatable);
             if (options.sourcePlane) {
@@ -22010,7 +22085,7 @@ var BABYLON;
             var cap = options.cap || BABYLON.Mesh.NO_CAP;
             var invertUV = options.invertUV || false;
             var updatable = options.updatable;
-            var sideOrientation = options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
+            var sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var instance = options.instance;
             options.arc = (options.arc <= 0.0 || options.arc > 1.0) ? 1.0 : options.arc || 1.0;
             // tube geometry
@@ -22116,6 +22191,7 @@ var BABYLON;
          */
         MeshBuilder.CreatePolyhedron = function (name, options, scene) {
             var polyhedron = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreatePolyhedron(options);
             vertexData.applyToMesh(polyhedron, options.updatable);
             return polyhedron;

Разница между файлами не показана из-за своего большого размера
+ 39 - 38
dist/preview release/babylon.noworker.js


+ 3 - 0
src/Cameras/Inputs/babylon.freecamera.input.keyboard.js

@@ -84,6 +84,9 @@ var BABYLON;
                     else if (this.keysDown.indexOf(keyCode) !== -1) {
                         camera._localDirection.copyFromFloats(0, 0, -speed);
                     }
+                    if (camera.getScene().useRightHandedSystem) {
+                        camera._localDirection.z *= -1;
+                    }
                     camera.getViewMatrix().invertToRef(camera._cameraTransformMatrix);
                     BABYLON.Vector3.TransformNormalToRef(camera._localDirection, camera._cameraTransformMatrix, camera._transformedDirection);
                     camera.cameraDirection.addInPlace(camera._transformedDirection);

+ 4 - 0
src/Cameras/Inputs/babylon.freecamera.input.keyboard.ts

@@ -94,6 +94,10 @@ module BABYLON {
                         camera._localDirection.copyFromFloats(0, 0, -speed);
                     }
 
+                    if (camera.getScene().useRightHandedSystem) {
+                        camera._localDirection.z *= -1;
+                    }
+
                     camera.getViewMatrix().invertToRef(camera._cameraTransformMatrix);
                     Vector3.TransformNormalToRef(camera._localDirection, camera._cameraTransformMatrix, camera._transformedDirection);
                     camera.cameraDirection.addInPlace(camera._transformedDirection);

+ 6 - 1
src/Cameras/Inputs/babylon.freecamera.input.mouse.js

@@ -62,7 +62,12 @@ var BABYLON;
                             offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
                             offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
                         }
-                        camera.cameraRotation.y += offsetX / _this.angularSensibility;
+                        if (_this.camera.getScene().useRightHandedSystem) {
+                            camera.cameraRotation.y -= offsetX / _this.angularSensibility;
+                        }
+                        else {
+                            camera.cameraRotation.y += offsetX / _this.angularSensibility;
+                        }
                         camera.cameraRotation.x += offsetY / _this.angularSensibility;
                         _this.previousPosition = {
                             x: evt.clientX,

+ 5 - 1
src/Cameras/Inputs/babylon.freecamera.input.mouse.ts

@@ -70,7 +70,11 @@ module BABYLON {
                             offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
                         }
 
-                        camera.cameraRotation.y += offsetX / this.angularSensibility;
+                        if (this.camera.getScene().useRightHandedSystem) {
+                            camera.cameraRotation.y -= offsetX / this.angularSensibility;
+                        } else {
+                            camera.cameraRotation.y += offsetX / this.angularSensibility;                            
+                        }
                         camera.cameraRotation.x += offsetY / this.angularSensibility;
 
                         this.previousPosition = {

+ 6 - 1
src/Cameras/babylon.arcRotateCamera.js

@@ -282,8 +282,13 @@ var BABYLON;
             this.inputs.checkInputs();
             // Inertia
             if (this.inertialAlphaOffset !== 0 || this.inertialBetaOffset !== 0 || this.inertialRadiusOffset !== 0) {
-                this.alpha += this.beta <= 0 ? -this.inertialAlphaOffset : this.inertialAlphaOffset;
                 this.beta += this.inertialBetaOffset;
+                if (this.getScene().useRightHandedSystem) {
+                    this.alpha -= this.beta <= 0 ? -this.inertialAlphaOffset : this.inertialAlphaOffset;
+                }
+                else {
+                    this.alpha += this.beta <= 0 ? -this.inertialAlphaOffset : this.inertialAlphaOffset;
+                }
                 this.radius -= this.inertialRadiusOffset;
                 this.inertialAlphaOffset *= this.inertia;
                 this.inertialBetaOffset *= this.inertia;

+ 8 - 2
src/Cameras/babylon.arcRotateCamera.ts

@@ -285,8 +285,14 @@
             this.inputs.checkInputs();
             // Inertia
             if (this.inertialAlphaOffset !== 0 || this.inertialBetaOffset !== 0 || this.inertialRadiusOffset !== 0) {
-                this.alpha += this.beta <= 0 ? -this.inertialAlphaOffset : this.inertialAlphaOffset;
-                this.beta += this.inertialBetaOffset;
+                this.beta += this.inertialBetaOffset;                    
+
+                if (this.getScene().useRightHandedSystem) {
+                    this.alpha -= this.beta <= 0 ? -this.inertialAlphaOffset : this.inertialAlphaOffset;
+                } else {
+                    this.alpha += this.beta <= 0 ? -this.inertialAlphaOffset : this.inertialAlphaOffset;
+                }
+
                 this.radius -= this.inertialRadiusOffset;
                 this.inertialAlphaOffset *= this.inertia;
                 this.inertialBetaOffset *= this.inertia;

+ 6 - 1
src/Lights/babylon.directionalLight.js

@@ -99,7 +99,12 @@ var BABYLON;
                 effect.setFloat4(directionUniformName, this._transformedDirection.x, this._transformedDirection.y, this._transformedDirection.z, 1);
                 return;
             }
-            effect.setFloat4(directionUniformName, this.direction.x, this.direction.y, this.direction.z, 1);
+            if (this.getScene().useRightHandedSystem) {
+                effect.setFloat4(directionUniformName, this.direction.x, this.direction.y, this.direction.z, -1);
+            }
+            else {
+                effect.setFloat4(directionUniformName, this.direction.x, this.direction.y, this.direction.z, 1);
+            }
         };
         DirectionalLight.prototype._getWorldMatrix = function () {
             if (!this._worldMatrix) {

+ 5 - 1
src/Lights/babylon.directionalLight.ts

@@ -130,7 +130,11 @@
                 return;
             }
 
-            effect.setFloat4(directionUniformName, this.direction.x, this.direction.y, this.direction.z, 1);
+            if (this.getScene().useRightHandedSystem) {
+                effect.setFloat4(directionUniformName, this.direction.x, this.direction.y, this.direction.z, -1);
+            } else {
+                effect.setFloat4(directionUniformName, this.direction.x, this.direction.y, this.direction.z, 1);
+            }
         }
 
         public _getWorldMatrix(): Matrix {

+ 6 - 1
src/Lights/babylon.hemisphericLight.js

@@ -27,7 +27,12 @@ var BABYLON;
         };
         HemisphericLight.prototype.transferToEffect = function (effect, directionUniformName, groundColorUniformName) {
             var normalizeDirection = BABYLON.Vector3.Normalize(this.direction);
-            effect.setFloat4(directionUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, 0);
+            if (this.getScene().useRightHandedSystem) {
+                effect.setFloat4(directionUniformName, -normalizeDirection.x, -normalizeDirection.y, -normalizeDirection.z, 0);
+            }
+            else {
+                effect.setFloat4(directionUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, 0);
+            }
             effect.setColor3(groundColorUniformName, this.groundColor.scale(this.intensity));
         };
         HemisphericLight.prototype._getWorldMatrix = function () {

+ 13 - 1
src/Lights/babylon.hemisphericLight.ts

@@ -25,7 +25,19 @@
 
         public transferToEffect(effect: Effect, directionUniformName: string, groundColorUniformName: string): void {
             var normalizeDirection = Vector3.Normalize(this.direction);
-            effect.setFloat4(directionUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, 0);
+            if (this.getScene().useRightHandedSystem) {
+                effect.setFloat4(directionUniformName,
+                    -normalizeDirection.x,
+                    -normalizeDirection.y,
+                    -normalizeDirection.z,
+                    0);
+            } else {
+                effect.setFloat4(directionUniformName,
+                    normalizeDirection.x,
+                    normalizeDirection.y,
+                    normalizeDirection.z,
+                    0);
+            }
             effect.setColor3(groundColorUniformName, this.groundColor.scale(this.intensity));
         }
 

+ 6 - 1
src/Lights/babylon.pointLight.js

@@ -36,7 +36,12 @@ var BABYLON;
                 effect.setFloat4(positionUniformName, this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, 0);
                 return;
             }
-            effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, 0);
+            if (this.getScene().useRightHandedSystem) {
+                effect.setFloat4(positionUniformName, -this.position.x, -this.position.y, -this.position.z, 0);
+            }
+            else {
+                effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, 0);
+            }
         };
         PointLight.prototype.needCube = function () {
             return true;

+ 5 - 1
src/Lights/babylon.pointLight.ts

@@ -39,7 +39,11 @@
                 return;
             }
 
-            effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, 0);
+            if (this.getScene().useRightHandedSystem) {
+                effect.setFloat4(positionUniformName, -this.position.x, -this.position.y, -this.position.z, 0);
+            } else {
+                effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, 0);
+            }
         }
 
         public needCube(): boolean {

+ 18 - 3
src/Lights/babylon.spotLight.js

@@ -61,14 +61,29 @@ var BABYLON;
                 }
                 this.computeTransformedPosition();
                 BABYLON.Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this._transformedDirection);
-                effect.setFloat4(positionUniformName, this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, this.exponent);
+                if (this.getScene().useRightHandedSystem) {
+                    effect.setFloat4(positionUniformName, -this.transformedPosition.x, -this.transformedPosition.y, -this.transformedPosition.z, this.exponent);
+                }
+                else {
+                    effect.setFloat4(positionUniformName, this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, this.exponent);
+                }
                 normalizeDirection = BABYLON.Vector3.Normalize(this._transformedDirection);
             }
             else {
-                effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, this.exponent);
+                if (this.getScene().useRightHandedSystem) {
+                    effect.setFloat4(positionUniformName, -this.position.x, -this.position.y, -this.position.z, this.exponent);
+                }
+                else {
+                    effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, this.exponent);
+                }
                 normalizeDirection = BABYLON.Vector3.Normalize(this.direction);
             }
-            effect.setFloat4(directionUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, Math.cos(this.angle * 0.5));
+            if (this.getScene().useRightHandedSystem) {
+                effect.setFloat4(directionUniformName, -normalizeDirection.x, -normalizeDirection.y, -normalizeDirection.z, Math.cos(this.angle * 0.5));
+            }
+            else {
+                effect.setFloat4(directionUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, Math.cos(this.angle * 0.5));
+            }
         };
         SpotLight.prototype._getWorldMatrix = function () {
             if (!this._worldMatrix) {

+ 40 - 3
src/Lights/babylon.spotLight.ts

@@ -81,14 +81,51 @@
                 
                 Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this._transformedDirection);
 
-                effect.setFloat4(positionUniformName, this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, this.exponent);
+                if (this.getScene().useRightHandedSystem) {
+                    effect.setFloat4(positionUniformName,
+                        -this.transformedPosition.x,
+                        -this.transformedPosition.y,
+                        -this.transformedPosition.z,
+                        this.exponent);
+                } else {
+                    effect.setFloat4(positionUniformName,
+                        this.transformedPosition.x,
+                        this.transformedPosition.y,
+                        this.transformedPosition.z,
+                        this.exponent);
+                }
                 normalizeDirection = Vector3.Normalize(this._transformedDirection);
             } else {
-                effect.setFloat4(positionUniformName, this.position.x, this.position.y, this.position.z, this.exponent);
+                if (this.getScene().useRightHandedSystem) {
+                    effect.setFloat4(positionUniformName,
+                        -this.position.x,
+                        -this.position.y,
+                        -this.position.z,
+                        this.exponent);
+                } else {
+                    effect.setFloat4(positionUniformName,
+                        this.position.x,
+                        this.position.y,
+                        this.position.z,
+                        this.exponent);                    
+                }
                 normalizeDirection = Vector3.Normalize(this.direction);
             }
 
-            effect.setFloat4(directionUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, Math.cos(this.angle * 0.5));
+            if (this.getScene().useRightHandedSystem) {
+                effect.setFloat4(directionUniformName,
+                    -normalizeDirection.x,
+                    -normalizeDirection.y,
+                    -normalizeDirection.z,
+                    Math.cos(this.angle * 0.5));
+            } else {
+                effect.setFloat4(directionUniformName,
+                    normalizeDirection.x,
+                    normalizeDirection.y,
+                    normalizeDirection.z,
+                    Math.cos(this.angle * 0.5));
+                
+            }
         }
 
         public _getWorldMatrix(): Matrix {

+ 38 - 5
src/Mesh/babylon.meshBuilder.js

@@ -3,6 +3,30 @@ var BABYLON;
     var MeshBuilder = (function () {
         function MeshBuilder() {
         }
+        MeshBuilder.updateSideOrientationForRightHandedSystem = function (orientation, scene) {
+            if (!scene.useRightHandedSystem) {
+                if (orientation === undefined || orientation === null) {
+                    return BABYLON.Mesh.FRONTSIDE;
+                }
+                switch (orientation) {
+                    case BABYLON.Mesh.FRONTSIDE:
+                    case BABYLON.Mesh.DEFAULTSIDE:
+                        return BABYLON.Mesh.FRONTSIDE;
+                    default:
+                        return BABYLON.Mesh.BACKSIDE;
+                }
+            }
+            if (orientation === undefined || orientation === null) {
+                return BABYLON.Mesh.BACKSIDE;
+            }
+            switch (orientation) {
+                case BABYLON.Mesh.FRONTSIDE:
+                case BABYLON.Mesh.DEFAULTSIDE:
+                    return BABYLON.Mesh.BACKSIDE;
+                default:
+                    return BABYLON.Mesh.FRONTSIDE;
+            }
+        };
         /**
          * Creates a box mesh.
          * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#box
@@ -16,6 +40,7 @@ var BABYLON;
          */
         MeshBuilder.CreateBox = function (name, options, scene) {
             var box = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreateBox(options);
             vertexData.applyToMesh(box, options.updatable);
             return box;
@@ -34,6 +59,7 @@ var BABYLON;
          */
         MeshBuilder.CreateSphere = function (name, options, scene) {
             var sphere = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreateSphere(options);
             vertexData.applyToMesh(sphere, options.updatable);
             return sphere;
@@ -50,6 +76,7 @@ var BABYLON;
          */
         MeshBuilder.CreateDisc = function (name, options, scene) {
             var disc = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreateDisc(options);
             vertexData.applyToMesh(disc, options.updatable);
             return disc;
@@ -67,6 +94,7 @@ var BABYLON;
          */
         MeshBuilder.CreateIcoSphere = function (name, options, scene) {
             var sphere = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreateIcoSphere(options);
             vertexData.applyToMesh(sphere, options.updatable);
             return sphere;
@@ -93,7 +121,7 @@ var BABYLON;
             var closeArray = options.closeArray;
             var closePath = options.closePath;
             var offset = options.offset;
-            var sideOrientation = options.sideOrientation;
+            var sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var instance = options.instance;
             var updatable = options.updatable;
             if (instance) {
@@ -215,6 +243,7 @@ var BABYLON;
          */
         MeshBuilder.CreateCylinder = function (name, options, scene) {
             var cylinder = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreateCylinder(options);
             vertexData.applyToMesh(cylinder, options.updatable);
             return cylinder;
@@ -231,6 +260,7 @@ var BABYLON;
          */
         MeshBuilder.CreateTorus = function (name, options, scene) {
             var torus = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreateTorus(options);
             vertexData.applyToMesh(torus, options.updatable);
             return torus;
@@ -248,6 +278,7 @@ var BABYLON;
          */
         MeshBuilder.CreateTorusKnot = function (name, options, scene) {
             var torusKnot = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreateTorusKnot(options);
             vertexData.applyToMesh(torusKnot, options.updatable);
             return torusKnot;
@@ -401,7 +432,7 @@ var BABYLON;
             var rotation = options.rotation || 0;
             var cap = (options.cap === 0) ? 0 : options.cap || BABYLON.Mesh.NO_CAP;
             var updatable = options.updatable;
-            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
+            var sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var instance = options.instance;
             var invertUV = options.invertUV || false;
             return MeshBuilder._ExtrudeShapeGeneric(name, shape, path, scale, rotation, null, null, false, false, cap, false, scene, updatable, sideOrientation, instance, invertUV);
@@ -450,7 +481,7 @@ var BABYLON;
             var ribbonClosePath = options.ribbonClosePath || false;
             var cap = (options.cap === 0) ? 0 : options.cap || BABYLON.Mesh.NO_CAP;
             var updatable = options.updatable;
-            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
+            var sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var instance = options.instance;
             var invertUV = options.invertUV || false;
             return MeshBuilder._ExtrudeShapeGeneric(name, shape, path, null, null, scaleFunction, rotationFunction, ribbonCloseArray, ribbonClosePath, cap, true, scene, updatable, sideOrientation, instance, invertUV);
@@ -479,7 +510,7 @@ var BABYLON;
             var radius = options.radius || 1;
             var tessellation = options.tessellation || 64;
             var updatable = options.updatable;
-            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
+            var sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var cap = options.cap || BABYLON.Mesh.NO_CAP;
             var pi2 = Math.PI * 2;
             var paths = new Array();
@@ -522,6 +553,7 @@ var BABYLON;
          */
         MeshBuilder.CreatePlane = function (name, options, scene) {
             var plane = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreatePlane(options);
             vertexData.applyToMesh(plane, options.updatable);
             if (options.sourcePlane) {
@@ -667,7 +699,7 @@ var BABYLON;
             var cap = options.cap || BABYLON.Mesh.NO_CAP;
             var invertUV = options.invertUV || false;
             var updatable = options.updatable;
-            var sideOrientation = options.sideOrientation || BABYLON.Mesh.DEFAULTSIDE;
+            var sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var instance = options.instance;
             options.arc = (options.arc <= 0.0 || options.arc > 1.0) ? 1.0 : options.arc || 1.0;
             // tube geometry
@@ -773,6 +805,7 @@ var BABYLON;
          */
         MeshBuilder.CreatePolyhedron = function (name, options, scene) {
             var polyhedron = new BABYLON.Mesh(name, scene);
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var vertexData = BABYLON.VertexData.CreatePolyhedron(options);
             vertexData.applyToMesh(polyhedron, options.updatable);
             return polyhedron;

+ 58 - 5
src/Mesh/babylon.meshBuilder.ts

@@ -1,5 +1,33 @@
 module BABYLON {
     export class MeshBuilder {
+        private static updateSideOrientationForRightHandedSystem(orientation: number, scene: Scene): number {
+            if (!scene.useRightHandedSystem) {
+                if (orientation === undefined || orientation === null) {
+                    return Mesh.FRONTSIDE;
+                }
+
+                switch (orientation) {
+                    case Mesh.FRONTSIDE:
+                    case Mesh.DEFAULTSIDE:
+                        return Mesh.FRONTSIDE;
+                    default:
+                        return Mesh.BACKSIDE;
+                }
+            }
+
+            if (orientation === undefined || orientation === null) {
+                return Mesh.BACKSIDE;
+            }
+
+            switch (orientation) {
+                case Mesh.FRONTSIDE:
+                case Mesh.DEFAULTSIDE:
+                    return Mesh.BACKSIDE;
+                default:
+                    return Mesh.FRONTSIDE;
+            }
+        }
+
         /**
          * Creates a box mesh.  
          * tuto : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#box  
@@ -13,6 +41,9 @@
          */
         public static CreateBox(name: string, options: { size?: number, width?: number, height?: number, depth?: number, faceUV?: Vector4[], faceColors?: Color4[], sideOrientation?: number, updatable?: boolean }, scene: Scene): Mesh {
             var box = new Mesh(name, scene);
+
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
+
             var vertexData = VertexData.CreateBox(options);
 
             vertexData.applyToMesh(box, options.updatable);
@@ -34,6 +65,9 @@
          */
         public static CreateSphere(name: string, options: { segments?: number, diameter?: number, diameterX?: number, diameterY?: number, diameterZ?: number, arc?: number, slice?: number, sideOrientation?: number, updatable?: boolean }, scene: any): Mesh {
             var sphere = new Mesh(name, scene);
+
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
+
             var vertexData = VertexData.CreateSphere(options);
 
             vertexData.applyToMesh(sphere, options.updatable);
@@ -53,6 +87,9 @@
          */
         public static CreateDisc(name: string, options: { radius?: number, tessellation?: number, arc?: number, updatable?: boolean, sideOrientation?: number }, scene: Scene): Mesh {
             var disc = new Mesh(name, scene);
+
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
+
             var vertexData = VertexData.CreateDisc(options);
 
             vertexData.applyToMesh(disc, options.updatable);
@@ -73,6 +110,9 @@
          */
         public static CreateIcoSphere(name: string, options: { radius?: number, radiusX?: number, radiusY?: number, radiusZ?: number, flat?: boolean, subdivisions?: number, sideOrientation?: number, updatable?: boolean }, scene: Scene): Mesh {
             var sphere = new Mesh(name, scene);
+
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
+
             var vertexData = VertexData.CreateIcoSphere(options);
 
             vertexData.applyToMesh(sphere, options.updatable);
@@ -101,7 +141,7 @@
             var closeArray = options.closeArray;
             var closePath = options.closePath;
             var offset = options.offset;
-            var sideOrientation = options.sideOrientation;
+            var sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var instance = options.instance;
             var updatable = options.updatable;
 
@@ -232,6 +272,9 @@
          */
         public static CreateCylinder(name: string, options: { height?: number, diameterTop?: number, diameterBottom?: number, diameter?: number, tessellation?: number, subdivisions?: number, arc?: number, faceColors?: Color4[], faceUV?: Vector4[], updatable?: boolean, hasRings?: boolean, enclose?: boolean, sideOrientation?: number }, scene: any): Mesh {
             var cylinder = new Mesh(name, scene);
+
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
+
             var vertexData = VertexData.CreateCylinder(options);
 
             vertexData.applyToMesh(cylinder, options.updatable);
@@ -251,6 +294,9 @@
          */
         public static CreateTorus(name: string, options: { diameter?: number, thickness?: number, tessellation?: number, updatable?: boolean, sideOrientation?: number }, scene: any): Mesh {
             var torus = new Mesh(name, scene);
+
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
+
             var vertexData = VertexData.CreateTorus(options);
 
             vertexData.applyToMesh(torus, options.updatable);
@@ -271,6 +317,9 @@
          */
         public static CreateTorusKnot(name: string, options: { radius?: number, tube?: number, radialSegments?: number, tubularSegments?: number, p?: number, q?: number, updatable?: boolean, sideOrientation?: number }, scene: any): Mesh {
             var torusKnot = new Mesh(name, scene);
+
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
+
             var vertexData = VertexData.CreateTorusKnot(options);
 
             vertexData.applyToMesh(torusKnot, options.updatable);
@@ -433,7 +482,7 @@
             var rotation = options.rotation || 0;
             var cap = (options.cap === 0) ? 0 : options.cap || Mesh.NO_CAP;
             var updatable = options.updatable;
-            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || Mesh.DEFAULTSIDE;
+            var sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var instance = options.instance;
             var invertUV = options.invertUV || false;
 
@@ -484,7 +533,7 @@
             var ribbonClosePath = options.ribbonClosePath || false;
             var cap = (options.cap === 0) ? 0 : options.cap || Mesh.NO_CAP;
             var updatable = options.updatable;
-            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || Mesh.DEFAULTSIDE;
+            var sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var instance = options.instance;
             var invertUV = options.invertUV || false;
             return MeshBuilder._ExtrudeShapeGeneric(name, shape, path, null, null, scaleFunction, rotationFunction, ribbonCloseArray, ribbonClosePath, cap, true, scene, updatable, sideOrientation, instance, invertUV);
@@ -514,7 +563,7 @@
             var radius = options.radius || 1;
             var tessellation = options.tessellation || 64;
             var updatable = options.updatable;
-            var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || Mesh.DEFAULTSIDE;
+            var sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var cap = options.cap || Mesh.NO_CAP;
             var pi2 = Math.PI * 2;
             var paths = new Array();
@@ -560,6 +609,8 @@
         public static CreatePlane(name: string, options: { size?: number, width?: number, height?: number, sideOrientation?: number, updatable?: boolean, sourcePlane?: Plane }, scene: Scene): Mesh {
             var plane = new Mesh(name, scene);
 
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
+
             var vertexData = VertexData.CreatePlane(options);
 
             vertexData.applyToMesh(plane, options.updatable);
@@ -731,7 +782,7 @@
             var cap = options.cap || Mesh.NO_CAP;
             var invertUV = options.invertUV || false;
             var updatable = options.updatable;
-            var sideOrientation = options.sideOrientation || Mesh.DEFAULTSIDE;
+            var sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
             var instance = options.instance;
             options.arc = (options.arc <= 0.0 || options.arc > 1.0) ? 1.0 : options.arc || 1.0;
 
@@ -844,6 +895,8 @@
         public static CreatePolyhedron(name: string, options: { type?: number, size?: number, sizeX?: number, sizeY?: number, sizeZ?: number, custom?: any, faceUV?: Vector4[], faceColors?: Color4[], flat?: boolean, updatable?: boolean, sideOrientation?: number }, scene: Scene): Mesh {
             var polyhedron = new Mesh(name, scene);
 
+            options.sideOrientation = this.updateSideOrientationForRightHandedSystem(options.sideOrientation, scene);
+
             var vertexData = VertexData.CreatePolyhedron(options);
 
             vertexData.applyToMesh(polyhedron, options.updatable);