Skip to content

Commit

Permalink
1 dimension axis scale for boundingbox gizmo
Browse files Browse the repository at this point in the history
  • Loading branch information
CedricGuillemet committed Feb 27, 2020
1 parent 93e42eb commit 8ca8e9b
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/Gizmos/boundingBoxGizmo.ts
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -502,6 +517,7 @@ export class BoundingBoxGizmo extends Gizmo {
scaleBoxes[index].scaling.set(this.scaleBoxSize, this.scaleBoxSize, this.scaleBoxSize);
}
}
index++;
}
}
}
Expand Down

0 comments on commit 8ca8e9b

Please sign in to comment.