From bcd59b9fc1307d2595566123c075ce6fe1722eaa Mon Sep 17 00:00:00 2001 From: HunterBarclay Date: Mon, 23 Sep 2024 00:21:29 -0600 Subject: [PATCH] fix: Make changes suggested by @PepperLola . Also included some snapping controls. --- fission/src/systems/scene/GizmoSceneObject.ts | 55 +++++++++++++------ fission/src/systems/scene/SceneRenderer.ts | 11 +++- .../scoring/ZoneConfigInterface.tsx | 1 - 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/fission/src/systems/scene/GizmoSceneObject.ts b/fission/src/systems/scene/GizmoSceneObject.ts index 036d6e8ec..8ac9a92d5 100644 --- a/fission/src/systems/scene/GizmoSceneObject.ts +++ b/fission/src/systems/scene/GizmoSceneObject.ts @@ -94,28 +94,32 @@ class GizmoSceneObject extends SceneObject { const gizmoDragging = World.SceneRenderer.IsAnyGizmoDragging() World.SceneRenderer.orbitControls.enabled = !event.value && !gizmoDragging - if (event.target.mode === "translate") { - // disable other gizmos when translating - Array.from(World.SceneRenderer.sceneObjects.values()) - .filter(obj => obj instanceof GizmoSceneObject) - .forEach(obj => { + const isShift = InputSystem.isKeyPressed("ShiftRight") || InputSystem.isKeyPressed("ShiftLeft") + const isAlt = InputSystem.isKeyPressed("AltRight") || InputSystem.isKeyPressed("AltLeft") + + switch (event.target.mode) { + case "translate": { + // snap if alt is pressed + event.target.translationSnap = isAlt ? 0.1 : null + + // disable other gizmos when translating + const gizmos = [...World.SceneRenderer.gizmosOnMirabuf.values()] + gizmos.forEach(obj => { if (obj.gizmo.object === event.target.object && obj.gizmo.mode !== "translate") { obj.gizmo.dragging = false obj.gizmo.enabled = !event.value return } }) - } else if ( - event.target.mode === "scale" && - (InputSystem.isKeyPressed("ShiftRight") || InputSystem.isKeyPressed("ShiftLeft")) - ) { - // scale uniformly if shift is pressed - event.target.axis = "XYZE" - } else if (event.target.mode === "rotate") { - // scale on all axes - Array.from(World.SceneRenderer.sceneObjects.values()) - .filter(obj => obj instanceof GizmoSceneObject) - .forEach(obj => { + break + } + case "rotate": { + // snap if alt is pressed + event.target.rotationSnap = isAlt ? (Math.PI * (1.0 / 12.0)) : null + + // disable scale gizmos added to the same object + const gizmos = [...World.SceneRenderer.gizmosOnMirabuf.values()] + gizmos.forEach(obj => { if ( obj.gizmo.mode === "scale" && event.target !== obj.gizmo && @@ -126,6 +130,20 @@ class GizmoSceneObject extends SceneObject { return } }) + break + } + case "scale": { + // snap if alt is pressed + event.target.setScaleSnap(isAlt ? 0.1 : null) + + // scale uniformly if shift is pressed + event.target.axis = isShift ? "XYZE" : null + break + } + default: { + console.error("Invalid gizmo state") + break + } } }) } @@ -133,6 +151,11 @@ class GizmoSceneObject extends SceneObject { public Update(): void { this._gizmo.updateMatrixWorld() + if (!this.gizmo.object) { + console.error("No object added to gizmo") + return + } + // updating the size of the gizmo based on the distance from the camera const mainCameraFovRadians = (Math.PI * (this._mainCamera.fov * 0.5)) / 180 this._gizmo.setSize( diff --git a/fission/src/systems/scene/SceneRenderer.ts b/fission/src/systems/scene/SceneRenderer.ts index 2c7bef9d4..716c048fa 100644 --- a/fission/src/systems/scene/SceneRenderer.ts +++ b/fission/src/systems/scene/SceneRenderer.ts @@ -57,6 +57,13 @@ class SceneRenderer extends WorldSystem { return this._orbitControls } + /** + * Collection that maps Mirabuf objects to active GizmoSceneObjects + */ + public get gizmosOnMirabuf() { + return this._gizmosOnMirabuf + } + public constructor() { super() @@ -341,9 +348,7 @@ class SceneRenderer extends WorldSystem { /** returns whether any gizmos are being currently dragged */ public IsAnyGizmoDragging(): boolean { - return Array.from(this._sceneObjects.values()) - .filter(obj => obj instanceof GizmoSceneObject) - .some(obj => obj.gizmo.dragging) + return [...this._gizmosOnMirabuf.values()].some(obj => obj.gizmo.dragging) } /** diff --git a/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ZoneConfigInterface.tsx b/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ZoneConfigInterface.tsx index 33af4d1fa..95af682a3 100644 --- a/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ZoneConfigInterface.tsx +++ b/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ZoneConfigInterface.tsx @@ -55,7 +55,6 @@ function save( gizmo: GizmoSceneObject, selectedNode?: RigidNodeId ) { - console.log("save") if (!field?.fieldPreferences || !gizmo) { return }