فهرست منبع

Merge pull request #7733 from CedricGuillemet/gizmoScale1Axis

1 dimension axis scale for boundingbox gizmo
David Catuhe 5 سال پیش
والد
کامیت
9c2545797a

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

@@ -8,6 +8,8 @@
 - NME Frames are now resizable from the corners ([Kyle Belfort](https://github.com/belfortk)
 - Refactored React refs from old string API to React.createRef() API ([Kyle Belfort](https://github.com/belfortk)
 
+- Scale on one axis for `BoundingBoxGizmo` ([cedricguillemet](https://github.com/cedricguillemet))
+
 ### Engine
 
 - Allow logging of shader code when a compilation error occurs ([Popov72](https://github.com/Popov72))

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

BIN
tests/validation/ReferenceImages/Gizmos.png


BIN
tests/validation/ReferenceImages/nested_BBG.png


BIN
tests/validation/ReferenceImages/simulatePointer.png


+ 1 - 1
tests/validation/config.json

@@ -133,7 +133,7 @@
         },
         {
             "title": "Simulate pointer",
-            "playgroundId": "#8MGKWK#78",
+            "playgroundId": "#8MGKWK#196",
             "referenceImage": "simulatePointer.png"
         },
         {