Przeglądaj źródła

Fix setDirection

David Catuhe 6 lat temu
rodzic
commit
0744a8dd4b

+ 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);
                         }
                     }

+ 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) {

+ 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);
             }