Skip to content

Commit

Permalink
fix: Make changes suggested by @PepperLola .
Browse files Browse the repository at this point in the history
Also included some snapping controls.
  • Loading branch information
HunterBarclay committed Sep 23, 2024
1 parent ec877bf commit bcd59b9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 20 deletions.
55 changes: 39 additions & 16 deletions fission/src/systems/scene/GizmoSceneObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -126,13 +130,32 @@ 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
}
}
})
}

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(
Expand Down
11 changes: 8 additions & 3 deletions fission/src/systems/scene/SceneRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ function save(
gizmo: GizmoSceneObject,
selectedNode?: RigidNodeId
) {
console.log("save")
if (!field?.fieldPreferences || !gizmo) {
return
}
Expand Down

0 comments on commit bcd59b9

Please sign in to comment.