Skip to content

Commit

Permalink
enabled transform tools based on selection
Browse files Browse the repository at this point in the history
  • Loading branch information
slimbuck committed Oct 16, 2024
1 parent 37e5611 commit d4df0be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/tools/transform-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class TransformTool {

// reattach the gizmo to the pivot
const reattach = () => {
if (!active) {
if (!active || !events.invoke('selection')) {
gizmo.detach();
} else {
pivot = events.invoke('pivot') as Pivot;
Expand All @@ -76,6 +76,7 @@ class TransformTool {

events.on('pivot.placed', reattach);
events.on('pivot.moved', reattach);
events.on('selection.changed', reattach);

events.on('camera.resize', () => {
scene.events.on('camera.resize', () => updateGizmoSize(gizmo, scene.graphicsDevice));
Expand Down
14 changes: 6 additions & 8 deletions src/ui/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,13 @@ class Transform extends Container {
input.on('slider:mouseup', mouseup);
});

// toggle ui availability based on selection
events.on('selection.changed', (selection) => {
positionVector.enabled = rotationVector.enabled = scaleInput.enabled = !!selection;
});

events.on('pivot.placed', (pivot: Pivot) => {
if (pivot) {
// enable inputs
updateUI(pivot);
positionVector.enabled = rotationVector.enabled = scaleInput.enabled = true;
} else {
// disable inputs
positionVector.enabled = rotationVector.enabled = scaleInput.enabled = false;
}
updateUI(pivot);
});

events.on('pivot.moved', (pivot: Pivot) => {
Expand Down

0 comments on commit d4df0be

Please sign in to comment.