Explorar o código

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

David Catuhe %!s(int64=6) %!d(string=hai) anos
pai
achega
d769cfa624

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

@@ -95,6 +95,7 @@
 ### Materials Library
 
 ## Bug fixes
+- Fixed TransformNode.setDirection (orientation was wrong) ([Deltakosh](https://github.com/deltakosh))
 - Fixed ArcRotateCamera control when upVector was modified ([Deltakosh](https://github.com/deltakosh))
 - Fixed anaglyph mode for Free and Universal cameras ([Deltakosh](https://github.com/deltakosh))
 - Fixed FileLoader's loading of a skybox, & added a parsed value for whether to create with PBR or STDMaterial ([Palmer-JC](https://github.com/Palmer-JC))

+ 2 - 2
gui/src/3D/controls/cylinderPanel.ts

@@ -39,10 +39,10 @@ export class CylinderPanel extends VolumeBasedPanel {
 
         switch (this.orientation) {
             case Container3D.FACEORIGIN_ORIENTATION:
-                mesh.lookAt(new BABYLON.Vector3(-newPos.x, newPos.y, -newPos.z));
+                mesh.lookAt(new BABYLON.Vector3(2 * newPos.x, newPos.y, 2 * newPos.z));
                 break;
             case Container3D.FACEORIGINREVERSED_ORIENTATION:
-                mesh.lookAt(new BABYLON.Vector3(2 * newPos.x, newPos.y, 2 * newPos.z));
+                mesh.lookAt(new BABYLON.Vector3(-newPos.x, newPos.y, -newPos.z));
                 break;
             case Container3D.FACEFORWARD_ORIENTATION:
                 break;

+ 2 - 2
gui/src/3D/controls/planePanel.ts

@@ -22,12 +22,12 @@ export class PlanePanel extends VolumeBasedPanel {
         switch (this.orientation) {
             case Container3D.FACEORIGIN_ORIENTATION:
             case Container3D.FACEFORWARD_ORIENTATION:
-                target.addInPlace(new BABYLON.Vector3(0, 0, -1));
+                target.addInPlace(new BABYLON.Vector3(0, 0, 1));
                 mesh.lookAt(target);
                 break;
             case Container3D.FACEFORWARDREVERSED_ORIENTATION:
             case Container3D.FACEORIGINREVERSED_ORIENTATION:
-                target.addInPlace(new BABYLON.Vector3(0, 0, 1));
+                target.addInPlace(new BABYLON.Vector3(0, 0, -1));
                 mesh.lookAt(target);
                 break;
         }

+ 2 - 2
gui/src/3D/controls/scatterPanel.ts

@@ -39,11 +39,11 @@ export class ScatterPanel extends VolumeBasedPanel {
         switch (this.orientation) {
             case Container3D.FACEORIGIN_ORIENTATION:
             case Container3D.FACEFORWARD_ORIENTATION:
-                mesh.lookAt(new Vector3(0, 0, -1));
+                mesh.lookAt(new Vector3(0, 0, 1));
                 break;
             case Container3D.FACEFORWARDREVERSED_ORIENTATION:
             case Container3D.FACEORIGINREVERSED_ORIENTATION:
-                mesh.lookAt(new Vector3(0, 0, 1));
+                mesh.lookAt(new Vector3(0, 0, -1));
                 break;
         }
 

+ 2 - 2
gui/src/3D/controls/spherePanel.ts

@@ -40,10 +40,10 @@ export class SpherePanel extends VolumeBasedPanel {
 
         switch (this.orientation) {
             case Container3D.FACEORIGIN_ORIENTATION:
-                mesh.lookAt(new BABYLON.Vector3(-newPos.x, -newPos.y, -newPos.z));
+                mesh.lookAt(new BABYLON.Vector3(2 * newPos.x, 2 * newPos.y, 2 * newPos.z));
                 break;
             case Container3D.FACEORIGINREVERSED_ORIENTATION:
-                mesh.lookAt(new BABYLON.Vector3(2 * newPos.x, 2 * newPos.y, 2 * newPos.z));
+                mesh.lookAt(new BABYLON.Vector3(-newPos.x, -newPos.y, -newPos.z));
                 break;
             case Container3D.FACEFORWARD_ORIENTATION:
                 break;

+ 25 - 25
src/Behaviors/Mesh/babylon.pointerDragBehavior.ts

@@ -48,15 +48,15 @@ module BABYLON {
          *  * dragPlaneNormal normal of the current drag plane used during the drag
          *  * dragPlanePoint in world space where the drag intersects the drag plane
          */
-        public onDragObservable = new Observable<{delta: Vector3, dragPlanePoint: Vector3, dragPlaneNormal: Vector3, dragDistance: number, pointerId: number}>();
+        public onDragObservable = new Observable<{ delta: Vector3, dragPlanePoint: Vector3, dragPlaneNormal: Vector3, dragDistance: number, pointerId: number }>();
         /**
          *  Fires each time a drag begins (eg. mouse down on mesh)
          */
-        public onDragStartObservable = new Observable<{dragPlanePoint: Vector3, pointerId: number}>();
+        public onDragStartObservable = new Observable<{ dragPlanePoint: Vector3, pointerId: number }>();
         /**
          *  Fires each time a drag ends (eg. mouse release after drag)
          */
-        public onDragEndObservable = new Observable<{dragPlanePoint: Vector3, pointerId: number}>();
+        public onDragEndObservable = new Observable<{ dragPlanePoint: Vector3, pointerId: number }>();
         /**
          *  If the attached mesh should be moved when dragged
          */
@@ -76,12 +76,12 @@ module BABYLON {
          */
         public useObjectOrienationForDragging = true;
 
-        private _options: {dragAxis?: Vector3, dragPlaneNormal?: Vector3};
+        private _options: { dragAxis?: Vector3, dragPlaneNormal?: Vector3 };
         /**
          * Creates a pointer drag behavior that can be attached to a mesh
          * @param options The drag axis or normal of the plane that will be dragged across. If no options are specified the drag plane will always face the ray's origin (eg. camera)
          */
-        constructor(options?: {dragAxis?: Vector3, dragPlaneNormal?: Vector3}) {
+        constructor(options?: { dragAxis?: Vector3, dragPlaneNormal?: Vector3 }) {
             this._options = options ? options : {};
 
             var optionCount = 0;
@@ -106,7 +106,7 @@ module BABYLON {
         /**
          *  Initializes the behavior
          */
-        public init() {}
+        public init() { }
 
         private _tmpVector = new Vector3(0, 0, 0);
         private _alternatePickedPoint = new Vector3(0, 0, 0);
@@ -125,7 +125,7 @@ module BABYLON {
             if (!PointerDragBehavior._planeScene) {
                 if (this._debugMode) {
                     PointerDragBehavior._planeScene = this._scene;
-                }else {
+                } else {
                     PointerDragBehavior._planeScene = new BABYLON.Scene(this._scene.getEngine());
                     PointerDragBehavior._planeScene.detachControl();
                     this._scene.getEngine().scenes.pop();
@@ -154,11 +154,11 @@ module BABYLON {
                     if (!this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.hit && pointerInfo.pickInfo.pickedMesh && pointerInfo.pickInfo.pickedPoint && pointerInfo.pickInfo.ray && pickPredicate(pointerInfo.pickInfo.pickedMesh)) {
                         this._startDrag((<PointerEvent>pointerInfo.event).pointerId, pointerInfo.pickInfo.ray, pointerInfo.pickInfo.pickedPoint);
                     }
-                }else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERUP) {
+                } else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERUP) {
                     if (this.currentDraggingPointerID == (<PointerEvent>pointerInfo.event).pointerId) {
                         this.releaseDrag();
                     }
-                }else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERMOVE) {
+                } else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERMOVE) {
                     var pointerId = (<PointerEvent>pointerInfo.event).pointerId;
 
                     // If drag was started with anyMouseID specified, set pointerID to the next mouse that moved
@@ -180,7 +180,7 @@ module BABYLON {
 
                         if (this.currentDraggingPointerID == pointerId && this.dragging) {
                             this._moveDrag(pointerInfo.pickInfo.ray);
-                         }
+                        }
                     }
                 }
             });
@@ -203,7 +203,7 @@ module BABYLON {
          */
         public releaseDrag() {
             this.dragging = false;
-            this.onDragEndObservable.notifyObservers({dragPlanePoint: this.lastDragPosition, pointerId: this.currentDraggingPointerID});
+            this.onDragEndObservable.notifyObservers({ dragPlanePoint: this.lastDragPosition, pointerId: this.currentDraggingPointerID });
             this.currentDraggingPointerID = -1;
             this._moving = false;
 
@@ -214,7 +214,7 @@ module BABYLON {
         }
 
         private _startDragRay = new BABYLON.Ray(new BABYLON.Vector3(), new BABYLON.Vector3());
-        private _lastPointerRay: {[key: number]: Ray} = {};
+        private _lastPointerRay: { [key: number]: Ray } = {};
         /**
          * Simulates the start of a pointer drag event on the behavior
          * @param pointerId pointerID of the pointer that should be simulated (Default: Any mouse pointer ID)
@@ -224,7 +224,7 @@ module BABYLON {
         public startDrag(pointerId: number = PointerDragBehavior._AnyMouseID, fromRay?: Ray, startPickedPoint?: Vector3) {
             this._startDrag(pointerId, fromRay, startPickedPoint);
 
-            var lastRay =  this._lastPointerRay[pointerId];
+            var lastRay = this._lastPointerRay[pointerId];
             if (pointerId === PointerDragBehavior._AnyMouseID) {
                 lastRay = this._lastPointerRay[<any>Object.keys(this._lastPointerRay)[0]];
             }
@@ -245,7 +245,7 @@ module BABYLON {
             if (fromRay) {
                 this._startDragRay.direction.copyFrom(fromRay.direction);
                 this._startDragRay.origin.copyFrom(fromRay.origin);
-            }else {
+            } else {
                 this._startDragRay.origin.copyFrom(this._scene.activeCamera.position);
                 this._attachedNode.getWorldMatrix().getTranslationToRef(this._tmpVector);
                 this._tmpVector.subtractToRef(this._scene.activeCamera.position, this._startDragRay.direction);
@@ -258,7 +258,7 @@ module BABYLON {
                 this.dragging = true;
                 this.currentDraggingPointerID = pointerId;
                 this.lastDragPosition.copyFrom(pickedPoint);
-                this.onDragStartObservable.notifyObservers({dragPlanePoint: pickedPoint, pointerId: this.currentDraggingPointerID});
+                this.onDragStartObservable.notifyObservers({ dragPlanePoint: pickedPoint, pointerId: this.currentDraggingPointerID });
                 this._targetPosition.copyFrom((this._attachedNode).absolutePosition);
 
                 // Detatch camera controls
@@ -266,7 +266,7 @@ module BABYLON {
                     if (this._scene.activeCamera.inputs.attachedElement) {
                         this._attachedElement = this._scene.activeCamera.inputs.attachedElement;
                         this._scene.activeCamera.detachControl(this._scene.activeCamera.inputs.attachedElement);
-                    }else {
+                    } else {
                         this._attachedElement = null;
                     }
                 }
@@ -294,12 +294,12 @@ module BABYLON {
                     pickedPoint.subtractToRef(this.lastDragPosition, this._tmpVector);
                     dragLength = BABYLON.Vector3.Dot(this._tmpVector, this._worldDragAxis);
                     this._worldDragAxis.scaleToRef(dragLength, this._dragDelta);
-                }else {
+                } else {
                     dragLength = this._dragDelta.length();
                     pickedPoint.subtractToRef(this.lastDragPosition, this._dragDelta);
                 }
                 this._targetPosition.addInPlace(this._dragDelta);
-                this.onDragObservable.notifyObservers({dragDistance: dragLength, delta: this._dragDelta, dragPlanePoint: pickedPoint, dragPlaneNormal: this._dragPlane.forward, pointerId: this.currentDraggingPointerID});
+                this.onDragObservable.notifyObservers({ dragDistance: dragLength, delta: this._dragDelta, dragPlanePoint: pickedPoint, dragPlaneNormal: this._dragPlane.forward, pointerId: this.currentDraggingPointerID });
                 this.lastDragPosition.copyFrom(pickedPoint);
             }
         }
@@ -332,15 +332,15 @@ module BABYLON {
                     this._alternatePickedPoint.addInPlace(this._tmpVector);
                     this._alternatePickedPoint.addInPlace((this._attachedNode).absolutePosition);
                     return this._alternatePickedPoint;
-                }else {
+                } else {
                     return null;
                 }
             }
 
-            var pickResult = PointerDragBehavior._planeScene.pickWithRay(ray, (m) => {return m == this._dragPlane; });
+            var pickResult = PointerDragBehavior._planeScene.pickWithRay(ray, (m) => { return m == this._dragPlane; });
             if (pickResult && pickResult.hit && pickResult.pickedMesh && pickResult.pickedPoint) {
                 return pickResult.pickedPoint;
-            }else {
+            } else {
                 return null;
             }
         }
@@ -372,14 +372,14 @@ module BABYLON {
                 this._lookAt.normalize();
 
                 this._dragPlane.position.copyFrom(this._pointA);
-                this._pointA.subtractToRef(this._lookAt, this._lookAt);
+                this._pointA.addToRef(this._lookAt, this._lookAt);
                 this._dragPlane.lookAt(this._lookAt);
-            }else if (this._options.dragPlaneNormal) {
+            } else if (this._options.dragPlaneNormal) {
                 this.useObjectOrienationForDragging ? Vector3.TransformCoordinatesToRef(this._options.dragPlaneNormal, this._attachedNode.getWorldMatrix().getRotationMatrix(), this._localAxis) : this._localAxis.copyFrom(this._options.dragPlaneNormal);
                 this._dragPlane.position.copyFrom(this._pointA);
-                this._pointA.subtractToRef(this._localAxis, this._lookAt);
+                this._pointA.addToRef(this._localAxis, this._lookAt);
                 this._dragPlane.lookAt(this._lookAt);
-            }else {
+            } else {
                 this._dragPlane.position.copyFrom(this._pointA);
                 this._dragPlane.lookAt(ray.origin);
             }

+ 6 - 6
src/Behaviors/Mesh/babylon.sixDofDragBehavior.ts

@@ -62,7 +62,7 @@ module BABYLON {
         /**
          *  Initializes the behavior
          */
-        public init() {}
+        public init() { }
 
         /**
          * Attaches the scale behavior the passed in mesh
@@ -103,7 +103,7 @@ module BABYLON {
 
                         // Set position and orientation of the controller
                         this._virtualOriginMesh.position.copyFrom(pointerInfo.pickInfo.ray.origin);
-                        this._virtualOriginMesh.lookAt(pointerInfo.pickInfo.ray.origin.subtract(pointerInfo.pickInfo.ray.direction));
+                        this._virtualOriginMesh.lookAt(pointerInfo.pickInfo.ray.origin.add(pointerInfo.pickInfo.ray.direction));
 
                         // Attach the virtual drag mesh to the virtual origin mesh so it can be dragged
                         this._virtualOriginMesh.removeChild(this._virtualDragMesh);
@@ -128,14 +128,14 @@ module BABYLON {
                             if (this._scene.activeCamera.inputs.attachedElement) {
                                 attachedElement = this._scene.activeCamera.inputs.attachedElement;
                                 this._scene.activeCamera.detachControl(this._scene.activeCamera.inputs.attachedElement);
-                            }else {
+                            } else {
                                 attachedElement = null;
                             }
                         }
                         BoundingBoxGizmo._RestorePivotPoint(pickedMesh);
                         this.onDragStartObservable.notifyObservers({});
                     }
-                }else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERUP) {
+                } else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERUP) {
                     if (this.currentDraggingPointerID == (<PointerEvent>pointerInfo.event).pointerId) {
                         this.dragging = false;
                         this._moving = false;
@@ -149,7 +149,7 @@ module BABYLON {
                         }
                         this.onDragEndObservable.notifyObservers({});
                     }
-                }else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERMOVE) {
+                } else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERMOVE) {
                     if (this.currentDraggingPointerID == (<PointerEvent>pointerInfo.event).pointerId && this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.ray && pickedMesh) {
                         var zDragFactor = this.zDragFactor;
                         if (this._scene.activeCamera && this._scene.activeCamera.cameraRigMode == Camera.RIG_MODE_NONE) {
@@ -171,7 +171,7 @@ module BABYLON {
 
                         // Update the controller position
                         this._virtualOriginMesh.position.copyFrom(pointerInfo.pickInfo.ray.origin);
-                        this._virtualOriginMesh.lookAt(pointerInfo.pickInfo.ray.origin.subtract(pointerInfo.pickInfo.ray.direction));
+                        this._virtualOriginMesh.lookAt(pointerInfo.pickInfo.ray.origin.add(pointerInfo.pickInfo.ray.direction));
                         this._virtualOriginMesh.removeChild(this._virtualDragMesh);
 
                         // Move the virtualObjectsPosition into the picked mesh's space if needed

+ 3 - 10
src/Debug/babylon.axesViewer.ts

@@ -10,7 +10,6 @@ module BABYLON.Debug {
         private _xAxis: TransformNode;
         private _yAxis: TransformNode;
         private _zAxis: TransformNode;
-        private _tmpVector = new Vector3();
         private _scaleLinesFactor = 4;
         private _instanced = false;
 
@@ -73,13 +72,10 @@ module BABYLON.Debug {
             }
 
             this._xAxis = xAxis;
-            this._xAxis.rotationQuaternion = new Quaternion();
             this._xAxis.scaling.setAll(this.scaleLines * this._scaleLinesFactor);
             this._yAxis = yAxis;
-            this._yAxis.rotationQuaternion = new Quaternion();
             this._yAxis.scaling.setAll(this.scaleLines * this._scaleLinesFactor);
             this._zAxis = zAxis;
-            this._zAxis.rotationQuaternion = new Quaternion();
             this._zAxis.scaling.setAll(this.scaleLines * this._scaleLinesFactor);
 
             if (renderingGroupId != null) {
@@ -101,18 +97,15 @@ module BABYLON.Debug {
          */
         public update(position: Vector3, xaxis: Vector3, yaxis: Vector3, zaxis: Vector3): void {
             this._xAxis.position.copyFrom(position);
-            xaxis.scaleToRef(-1, this._tmpVector);
-            this._xAxis.setDirection(this._tmpVector);
+            this._xAxis.setDirection(xaxis);
             this._xAxis.scaling.setAll(this.scaleLines * this._scaleLinesFactor);
 
             this._yAxis.position.copyFrom(position);
-            yaxis.scaleToRef(-1, this._tmpVector);
-            this._yAxis.setDirection(this._tmpVector);
+            this._yAxis.setDirection(yaxis);
             this._yAxis.scaling.setAll(this.scaleLines * this._scaleLinesFactor);
 
             this._zAxis.position.copyFrom(position);
-            zaxis.scaleToRef(-1, this._tmpVector);
-            this._zAxis.setDirection(this._tmpVector);
+            this._zAxis.setDirection(zaxis);
             this._zAxis.scaling.setAll(this.scaleLines * this._scaleLinesFactor);
         }
 

+ 1 - 1
src/Gizmos/babylon.axisDragGizmo.ts

@@ -69,7 +69,7 @@ module BABYLON {
             // Build mesh on root node
             var arrow = AxisDragGizmo._CreateArrow(gizmoLayer.utilityLayerScene, coloredMaterial);
 
-            arrow.lookAt(this._rootMesh.position.subtract(dragAxis));
+            arrow.lookAt(this._rootMesh.position.add(dragAxis));
             arrow.scaling.scaleInPlace(1 / 3);
             arrow.parent = this._rootMesh;
 

+ 9 - 9
src/Gizmos/babylon.axisScaleGizmo.ts

@@ -17,7 +17,7 @@ module BABYLON {
          * Event that fires each time the gizmo snaps to a new location.
          * * snapDistance is the the change in distance
          */
-        public onSnapObservable = new Observable<{snapDistance: number}>();
+        public onSnapObservable = new Observable<{ snapDistance: number }>();
         /**
          * If the scaling operation should be done on all axis (default: false)
          */
@@ -42,8 +42,8 @@ module BABYLON {
 
             // Build mesh on root node
             var arrow = new BABYLON.AbstractMesh("", gizmoLayer.utilityLayerScene);
-            var arrowMesh = BABYLON.MeshBuilder.CreateBox("yPosMesh", {size: 0.4}, gizmoLayer.utilityLayerScene);
-            var arrowTail = BABYLON.MeshBuilder.CreateLines("yPosMesh", {points: [new Vector3(0, 0, 0), new Vector3(0, 1.1, 0)]}, gizmoLayer.utilityLayerScene);
+            var arrowMesh = BABYLON.MeshBuilder.CreateBox("yPosMesh", { size: 0.4 }, gizmoLayer.utilityLayerScene);
+            var arrowTail = BABYLON.MeshBuilder.CreateLines("yPosMesh", { points: [new Vector3(0, 0, 0), new Vector3(0, 1.1, 0)] }, gizmoLayer.utilityLayerScene);
             arrowTail.color = this._coloredMaterial.emissiveColor;
             arrow.addChild(arrowMesh);
             arrow.addChild(arrowTail);
@@ -56,18 +56,18 @@ module BABYLON {
             arrowTail.scaling.scaleInPlace(0.26);
             arrowTail.rotation.x = Math.PI / 2;
             arrowTail.material = this._coloredMaterial;
-            arrow.lookAt(this._rootMesh.position.subtract(dragAxis));
+            arrow.lookAt(this._rootMesh.position.add(dragAxis));
             this._rootMesh.addChild(arrow);
             arrow.scaling.scaleInPlace(1 / 3);
 
             // Add drag behavior to handle events when the gizmo is dragged
-            this.dragBehavior = new PointerDragBehavior({dragAxis: dragAxis});
+            this.dragBehavior = new PointerDragBehavior({ dragAxis: dragAxis });
             this.dragBehavior.moveAttached = false;
             this._rootMesh.addBehavior(this.dragBehavior);
 
             var currentSnapDragDistance = 0;
             var tmpVector = new Vector3();
-            var tmpSnapEvent = {snapDistance: 0};
+            var tmpSnapEvent = { snapDistance: 0 };
             this.dragBehavior.onDragObservable.add((event) => {
                 if (this.attachedMesh) {
                     // Snapping logic
@@ -78,19 +78,19 @@ module BABYLON {
                         if (tmpVector.y < 0) {
                             tmpVector.scaleInPlace(-1);
                         }
-                    }else {
+                    } else {
                         tmpVector.copyFrom(dragAxis);
                     }
                     if (this.snapDistance == 0) {
                         tmpVector.scaleToRef(event.dragDistance, tmpVector);
-                    }else {
+                    } else {
                         currentSnapDragDistance += event.dragDistance;
                         if (Math.abs(currentSnapDragDistance) > this.snapDistance) {
                             dragSteps = Math.floor(currentSnapDragDistance / this.snapDistance);
                             currentSnapDragDistance = currentSnapDragDistance % this.snapDistance;
                             tmpVector.scaleToRef(this.snapDistance * dragSteps, tmpVector);
                             snapped = true;
-                        }else {
+                        } else {
                             tmpVector.scaleInPlace(0);
                         }
                     }

+ 5 - 5
src/Gizmos/babylon.boundingBoxGizmo.ts

@@ -256,7 +256,7 @@ module BABYLON {
                                     this._boundingDimensions.multiplyToRef(this.scalePivot, this._tmpVector);
                                     Vector3.TransformCoordinatesToRef(this._tmpVector, this._tmpRotationMatrix, this._tmpVector);
                                     this._anchorMesh.position.addInPlace(this._tmpVector);
-                                }else {
+                                } else {
                                     // Scale from the position of the opposite corner
                                     box.absolutePosition.subtractToRef(this._anchorMesh.position, this._tmpVector);
                                     this._anchorMesh.position.subtractInPlace(this._tmpVector);
@@ -312,7 +312,7 @@ module BABYLON {
                 // Only update the bouding box if scaling has changed
                 if (this.attachedMesh && !this._existingMeshScale.equals(this.attachedMesh.scaling)) {
                     this.updateBoundingBox();
-                }else if (this.fixedDragMeshScreenSize) {
+                } else if (this.fixedDragMeshScreenSize) {
                     this._updateRotationSpheres();
                     this._updateScaleBoxes();
                 }
@@ -396,17 +396,17 @@ module BABYLON {
                         if (i == 0) {
                             rotateSpheres[index].position.set(this._boundingDimensions.x / 2, this._boundingDimensions.y * j, this._boundingDimensions.z * k);
                             rotateSpheres[index].position.addInPlace(new BABYLON.Vector3(-this._boundingDimensions.x / 2, -this._boundingDimensions.y / 2, -this._boundingDimensions.z / 2));
-                            rotateSpheres[index].lookAt(Vector3.Cross(Vector3.Right(), rotateSpheres[index].position.normalizeToNew()).normalizeToNew().add(rotateSpheres[index].position));
+                            rotateSpheres[index].lookAt(Vector3.Cross(rotateSpheres[index].position.normalizeToNew(), Vector3.Right()).normalizeToNew().add(rotateSpheres[index].position));
                         }
                         if (i == 1) {
                             rotateSpheres[index].position.set(this._boundingDimensions.x * j, this._boundingDimensions.y / 2, this._boundingDimensions.z * k);
                             rotateSpheres[index].position.addInPlace(new BABYLON.Vector3(-this._boundingDimensions.x / 2, -this._boundingDimensions.y / 2, -this._boundingDimensions.z / 2));
-                            rotateSpheres[index].lookAt(Vector3.Cross(Vector3.Up(), rotateSpheres[index].position.normalizeToNew()).normalizeToNew().add(rotateSpheres[index].position));
+                            rotateSpheres[index].lookAt(Vector3.Cross(rotateSpheres[index].position.normalizeToNew(), Vector3.Up()).normalizeToNew().add(rotateSpheres[index].position));
                         }
                         if (i == 2) {
                             rotateSpheres[index].position.set(this._boundingDimensions.x * j, this._boundingDimensions.y * k, this._boundingDimensions.z / 2);
                             rotateSpheres[index].position.addInPlace(new BABYLON.Vector3(-this._boundingDimensions.x / 2, -this._boundingDimensions.y / 2, -this._boundingDimensions.z / 2));
-                            rotateSpheres[index].lookAt(Vector3.Cross(Vector3.Forward(), rotateSpheres[index].position.normalizeToNew()).normalizeToNew().add(rotateSpheres[index].position));
+                            rotateSpheres[index].lookAt(Vector3.Cross(rotateSpheres[index].position.normalizeToNew(), Vector3.Forward()).normalizeToNew().add(rotateSpheres[index].position));
                         }
                         if (this.fixedDragMeshScreenSize && this.gizmoLayer.utilityLayerScene.activeCamera) {
                             rotateSpheres[index].absolutePosition.subtractToRef(this.gizmoLayer.utilityLayerScene.activeCamera.position, this._tmpVector);

+ 10 - 10
src/Gizmos/babylon.planeRotationGizmo.ts

@@ -17,7 +17,7 @@ module BABYLON {
          * Event that fires each time the gizmo snaps to a new location.
          * * snapDistance is the the change in distance
          */
-        public onSnapObservable = new Observable<{snapDistance: number}>();
+        public onSnapObservable = new Observable<{ snapDistance: number }>();
 
         /**
          * Creates a PlaneRotationGizmo
@@ -56,14 +56,14 @@ module BABYLON {
             rotationMesh.material = coloredMaterial;
             rotationMesh.rotation.x = Math.PI / 2;
             parentMesh.addChild(rotationMesh);
-            parentMesh.lookAt(this._rootMesh.position.subtract(planeNormal));
+            parentMesh.lookAt(this._rootMesh.position.add(planeNormal));
 
             this._rootMesh.addChild(parentMesh);
             parentMesh.scaling.scaleInPlace(1 / 3);
             // Add drag behavior to handle events when the gizmo is dragged
-            this.dragBehavior = new PointerDragBehavior({dragPlaneNormal: planeNormal});
+            this.dragBehavior = new PointerDragBehavior({ dragPlaneNormal: planeNormal });
             this.dragBehavior.moveAttached = false;
-            this.dragBehavior.maxDragAngle =  Math.PI * 9 / 20;
+            this.dragBehavior.maxDragAngle = Math.PI * 9 / 20;
             this.dragBehavior._useAlternatePickedPointAboveMaxDragAngle = true;
             this._rootMesh.addBehavior(this.dragBehavior);
 
@@ -79,7 +79,7 @@ module BABYLON {
             var planeNormalTowardsCamera = new Vector3();
             var localPlaneNormalTowardsCamera = new Vector3();
 
-            var tmpSnapEvent = {snapDistance: 0};
+            var tmpSnapEvent = { snapDistance: 0 };
             var currentSnapDragDistance = 0;
             var tmpMatrix = new BABYLON.Matrix();
             var tmpVector = new BABYLON.Vector3();
@@ -121,7 +121,7 @@ module BABYLON {
                             currentSnapDragDistance = currentSnapDragDistance % this.snapDistance;
                             angle = this.snapDistance * dragSteps;
                             snapped = true;
-                        }else {
+                        } else {
                             angle = 0;
                         }
                     }
@@ -144,13 +144,13 @@ module BABYLON {
                         BABYLON.Quaternion.RotationYawPitchRollToRef(tmpVector.y, -tmpVector.x, -tmpVector.z, amountToRotate);
                     }
 
-                     if (this.updateGizmoRotationToMatchAttachedMesh) {
+                    if (this.updateGizmoRotationToMatchAttachedMesh) {
                         // Rotate selected mesh quaternion over fixed axis
                         this.attachedMesh.rotationQuaternion.multiplyToRef(amountToRotate, this.attachedMesh.rotationQuaternion);
-                     }else {
-                         // Rotate selected mesh quaternion over rotated axis
+                    } else {
+                        // Rotate selected mesh quaternion over rotated axis
                         amountToRotate.multiplyToRef(this.attachedMesh.rotationQuaternion, this.attachedMesh.rotationQuaternion);
-                     }
+                    }
 
                     lastDragPosition.copyFrom(event.dragPlanePoint);
                     if (snapped) {

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

@@ -695,7 +695,7 @@ module BABYLON {
 
             if (options.sourcePlane) {
                 plane.translate(options.sourcePlane.normal, -options.sourcePlane.d);
-                plane.setDirection(options.sourcePlane.normal);
+                plane.setDirection(options.sourcePlane.normal.scale(-1));
             }
 
             return plane;

+ 2 - 2
src/Mesh/babylon.transformNode.ts

@@ -526,9 +526,9 @@ module BABYLON {
          * @returns this TransformNode
          */
         public setDirection(localAxis: Vector3, yawCor: number = 0, pitchCor: number = 0, rollCor: number = 0): TransformNode {
-            var yaw = Math.atan2(localAxis.z, localAxis.x) + 3 * Math.PI / 2;
+            var yaw = -Math.atan2(localAxis.z, localAxis.x) + Math.PI / 2;
             var len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);
-            var pitch = Math.atan2(localAxis.y, len);
+            var pitch = -Math.atan2(localAxis.y, len);
             if (this.rotationQuaternion) {
                 Quaternion.RotationYawPitchRollToRef(yaw + yawCor, pitch + pitchCor, rollCor, this.rotationQuaternion);
             }