소스 검색

1 dimension axis scale for boundingbox gizmo

Cedric Guillemet 5 년 전
부모
커밋
8ca8e9be49
1개의 변경된 파일25개의 추가작업 그리고 9개의 파일을 삭제
  1. 25 9
      src/Gizmos/boundingBoxGizmo.ts

+ 25 - 9
src/Gizmos/boundingBoxGizmo.ts

@@ -248,14 +248,19 @@ export class BoundingBoxGizmo extends Gizmo {
         // Create scale cubes
         this._scaleBoxesParent = new AbstractMesh("", gizmoLayer.utilityLayerScene);
         this._scaleBoxesParent.rotationQuaternion = new Quaternion();
-        for (var i = 0; i < 2; i++) {
-            for (var j = 0; j < 2; j++) {
-                for (var k = 0; k < 2; k++) {
+        for (var i = 0; i < 3; i++) {
+            for (var j = 0; j < 3; j++) {
+                for (var k = 0; k < 3; k++) {
+                    // create box for relevant axis
+                    let zeroAxisCount = ((i === 1) ? 1 : 0) + ((j === 1) ? 1 : 0) + ((k === 1) ? 1 : 0);
+                    if (zeroAxisCount === 1 || zeroAxisCount === 3) {
+                        continue;
+                    }
                     let box = BoxBuilder.CreateBox("", { size: 1 }, gizmoLayer.utilityLayerScene);
                     box.material = this.coloredMaterial;
 
                     // Dragging logic
-                    let dragAxis = new Vector3(i == 0 ? -1 : 1, j == 0 ? -1 : 1, k == 0 ? -1 : 1);
+                    let dragAxis = new Vector3(i - 1, j - 1, k - 1);
                     var _dragBehavior = new PointerDragBehavior({ dragAxis: dragAxis });
                     _dragBehavior.moveAttached = false;
                     box.addBehavior(_dragBehavior);
@@ -270,6 +275,12 @@ export class BoundingBoxGizmo extends Gizmo {
                             PivotTools._RemoveAndStorePivotPoint(this.attachedMesh);
                             var relativeDragDistance = (event.dragDistance / this._boundingDimensions.length()) * this._anchorMesh.scaling.length();
                             var deltaScale = new Vector3(relativeDragDistance, relativeDragDistance, relativeDragDistance);
+                            if (zeroAxisCount === 2) {
+                                // scale on 1 axis when using the anchor box in the face middle
+                                deltaScale.x *= Math.abs(dragAxis.x);
+                                deltaScale.y *= Math.abs(dragAxis.y);
+                                deltaScale.z *= Math.abs(dragAxis.z);
+                            }
                             deltaScale.scaleInPlace(this._scaleDragSpeed);
                             this.updateBoundingBox();
                             if (this.scalePivot) {
@@ -487,12 +498,16 @@ export class BoundingBoxGizmo extends Gizmo {
 
     private _updateScaleBoxes() {
         var scaleBoxes = this._scaleBoxesParent.getChildMeshes();
-        for (var i = 0; i < 2; i++) {
-            for (var j = 0; j < 2; j++) {
-                for (var k = 0; k < 2; k++) {
-                    var index = ((i * 4) + (j * 2)) + k;
+        var index = 0;
+        for (var i = 0; i < 3; i++) {
+            for (var j = 0; j < 3; j++) {
+                for (var k = 0; k < 3; k++) {
+                    let zeroAxisCount = ((i === 1) ? 1 : 0) + ((j === 1) ? 1 : 0) + ((k === 1) ? 1 : 0);
+                    if (zeroAxisCount === 1 || zeroAxisCount === 3) {
+                        continue;
+                    }
                     if (scaleBoxes[index]) {
-                        scaleBoxes[index].position.set(this._boundingDimensions.x * i, this._boundingDimensions.y * j, this._boundingDimensions.z * k);
+                        scaleBoxes[index].position.set(this._boundingDimensions.x * (i / 2), this._boundingDimensions.y * (j / 2), this._boundingDimensions.z * (k / 2 ));
                         scaleBoxes[index].position.addInPlace(new Vector3(-this._boundingDimensions.x / 2, -this._boundingDimensions.y / 2, -this._boundingDimensions.z / 2));
                         if (this.fixedDragMeshScreenSize && this.gizmoLayer.utilityLayerScene.activeCamera) {
                             scaleBoxes[index].absolutePosition.subtractToRef(this.gizmoLayer.utilityLayerScene.activeCamera.position, this._tmpVector);
@@ -502,6 +517,7 @@ export class BoundingBoxGizmo extends Gizmo {
                             scaleBoxes[index].scaling.set(this.scaleBoxSize, this.scaleBoxSize, this.scaleBoxSize);
                         }
                     }
+                    index++;
                 }
             }
         }