@flighthq/gizmo 0.4.1-edge.37.ff47e13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +9 -0
- package/README.md +17 -0
- package/dist/contract.d.ts +3 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +3 -0
- package/dist/contract.js.map +1 -0
- package/dist/gizmoState.d.ts +17 -0
- package/dist/gizmoState.d.ts.map +1 -0
- package/dist/gizmoState.js +587 -0
- package/dist/gizmoState.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/node2dGizmoFeatures.d.ts +3 -0
- package/dist/node2dGizmoFeatures.d.ts.map +1 -0
- package/dist/node2dGizmoFeatures.js +22 -0
- package/dist/node2dGizmoFeatures.js.map +1 -0
- package/package.json +57 -0
- package/src/gizmoState.test.ts +872 -0
- package/src/gizmoTreeShaking.test.ts +35 -0
- package/src/node2dGizmoFeatures.test.ts +51 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013-2026 Joshua Granick and other contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @flighthq/gizmo
|
|
2
|
+
|
|
3
|
+
Generic selection transform gizmos with fixed 2D overlay handles
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @flighthq/gizmo
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Import the supported application-facing API from `@flighthq/gizmo`. The `@flighthq/gizmo/contract` export is the wider package-to-package contract used to compose Flight itself.
|
|
12
|
+
|
|
13
|
+
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
|
+
|
|
15
|
+
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
+
- [Source for @flighthq/gizmo@0.4.1-edge.37.ff47e13](https://github.com/flighthq/flight/tree/ff47e13b6a3d240aead13b8373c7844a660897f7/packages/gizmo)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/ff47e13b6a3d240aead13b8373c7844a660897f7/LICENSE.md)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC"}
|
package/dist/contract.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { GizmoCreateOptions, GizmoMode, GizmoPivot, GizmoSignals, GizmoSpace, GizmoState, HierarchyNodeAny } from '@flighthq/types/contract';
|
|
2
|
+
export declare function createGizmoState<NodeType extends HierarchyNodeAny>(options: Readonly<GizmoCreateOptions<NodeType>>): GizmoState<NodeType>;
|
|
3
|
+
export declare function disposeGizmoState<NodeType extends HierarchyNodeAny>(state: GizmoState<NodeType>): void;
|
|
4
|
+
export declare function getGizmoMode<NodeType extends HierarchyNodeAny>(state: Readonly<GizmoState<NodeType>>): GizmoMode;
|
|
5
|
+
export declare function getGizmoSignals<NodeType extends HierarchyNodeAny>(state: Readonly<GizmoState<NodeType>>): Readonly<GizmoSignals>;
|
|
6
|
+
export declare function getGizmoSpace<NodeType extends HierarchyNodeAny>(state: Readonly<GizmoState<NodeType>>): GizmoSpace;
|
|
7
|
+
export declare function setGizmoCustomPivot<NodeType extends HierarchyNodeAny>(state: GizmoState<NodeType>, x: number, y: number): void;
|
|
8
|
+
export declare function setGizmoMode<NodeType extends HierarchyNodeAny>(state: GizmoState<NodeType>, mode: GizmoMode): void;
|
|
9
|
+
export declare function setGizmoPivot<NodeType extends HierarchyNodeAny>(state: GizmoState<NodeType>, pivot: GizmoPivot): void;
|
|
10
|
+
export declare function setGizmoSelectionOutlineColor<NodeType extends HierarchyNodeAny>(state: GizmoState<NodeType>, color: number): void;
|
|
11
|
+
export declare function setGizmoSelectionOutlineEnabled<NodeType extends HierarchyNodeAny>(state: GizmoState<NodeType>, enabled: boolean): void;
|
|
12
|
+
export declare function setGizmoSnapRotation<NodeType extends HierarchyNodeAny>(state: GizmoState<NodeType>, degrees: number): void;
|
|
13
|
+
export declare function setGizmoSnapScale<NodeType extends HierarchyNodeAny>(state: GizmoState<NodeType>, step: number): void;
|
|
14
|
+
export declare function setGizmoSnapTranslate<NodeType extends HierarchyNodeAny>(state: GizmoState<NodeType>, worldUnits: number): void;
|
|
15
|
+
export declare function setGizmoSpace<NodeType extends HierarchyNodeAny>(state: GizmoState<NodeType>, space: GizmoSpace): void;
|
|
16
|
+
export declare function updateGizmo<NodeType extends HierarchyNodeAny>(state: GizmoState<NodeType>): void;
|
|
17
|
+
//# sourceMappingURL=gizmoState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gizmoState.d.ts","sourceRoot":"","sources":["../src/gizmoState.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAGV,kBAAkB,EAElB,SAAS,EAET,UAAU,EACV,YAAY,EACZ,UAAU,EACV,UAAU,EAEV,gBAAgB,EAQjB,MAAM,0BAA0B,CAAC;AAkElC,wBAAgB,gBAAgB,CAAC,QAAQ,SAAS,gBAAgB,EAChE,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,GAC9C,UAAU,CAAC,QAAQ,CAAC,CAmDtB;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,SAAS,gBAAgB,EAAE,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,GAAG,IAAI,CAatG;AAED,wBAAgB,YAAY,CAAC,QAAQ,SAAS,gBAAgB,EAAE,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,CAEhH;AAED,wBAAgB,eAAe,CAAC,QAAQ,SAAS,gBAAgB,EAC/D,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,GACpC,QAAQ,CAAC,YAAY,CAAC,CAExB;AAED,wBAAgB,aAAa,CAAC,QAAQ,SAAS,gBAAgB,EAAE,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,GAAG,UAAU,CAElH;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,SAAS,gBAAgB,EACnE,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC3B,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,GACR,IAAI,CAIN;AAED,wBAAgB,YAAY,CAAC,QAAQ,SAAS,gBAAgB,EAAE,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,SAAS,GAAG,IAAI,CAKlH;AAED,wBAAgB,aAAa,CAAC,QAAQ,SAAS,gBAAgB,EAAE,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAErH;AAED,wBAAgB,6BAA6B,CAAC,QAAQ,SAAS,gBAAgB,EAC7E,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC3B,KAAK,EAAE,MAAM,GACZ,IAAI,CAEN;AAED,wBAAgB,+BAA+B,CAAC,QAAQ,SAAS,gBAAgB,EAC/E,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC3B,OAAO,EAAE,OAAO,GACf,IAAI,CAEN;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,SAAS,gBAAgB,EACpE,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC3B,OAAO,EAAE,MAAM,GACd,IAAI,CAEN;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,SAAS,gBAAgB,EAAE,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAEpH;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,SAAS,gBAAgB,EACrE,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC3B,UAAU,EAAE,MAAM,GACjB,IAAI,CAEN;AAED,wBAAgB,aAAa,CAAC,QAAQ,SAAS,gBAAgB,EAAE,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAErH;AAED,wBAAgB,WAAW,CAAC,QAAQ,SAAS,gBAAgB,EAAE,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,GAAG,IAAI,CA0BhG"}
|
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
import { projectCamera2DPoint, unprojectCamera2DPoint } from '@flighthq/camera/contract';
|
|
2
|
+
import { createRectangle, createVector2 } from '@flighthq/geometry/contract';
|
|
3
|
+
import { enableInteractionSignals, setNodeCursor, setNodeHitArea, setNodeHitTestEnabled, } from '@flighthq/interaction/contract';
|
|
4
|
+
import { DEG_TO_RAD, RAD_TO_DEG } from '@flighthq/math/contract';
|
|
5
|
+
import { addNodeChild, getNodeParent, invalidateNodeAppearance, invalidateNodeLocalTransform, removeNodeChild, } from '@flighthq/node/contract';
|
|
6
|
+
import { createDisplayObject } from '@flighthq/scene2d/contract';
|
|
7
|
+
import { getActiveNode, getSelectedNodes } from '@flighthq/selection/contract';
|
|
8
|
+
import { appendShapeBeginFill, appendShapeCircle, appendShapeEndFill, appendShapeLineStyle, appendShapeLineTo, appendShapeMoveTo, appendShapePolygon, appendShapeRectangle, clearShapeCommands, createShape, } from '@flighthq/shape/contract';
|
|
9
|
+
import { connectSignal, createSignal, disconnectSignal, emitSignal } from '@flighthq/signals/contract';
|
|
10
|
+
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
11
|
+
export function createGizmoState(options) {
|
|
12
|
+
const state = {
|
|
13
|
+
[EntityRuntimeKey]: undefined,
|
|
14
|
+
};
|
|
15
|
+
const overlayRoot = createDisplayObject({ name: 'GizmoRoot' });
|
|
16
|
+
const outline = createShape({ name: 'GizmoSelectionOutline' });
|
|
17
|
+
const handleRoot = createDisplayObject({ name: 'GizmoHandleRoot' });
|
|
18
|
+
const runtime = {
|
|
19
|
+
binding: null,
|
|
20
|
+
bounds: createRectangle(),
|
|
21
|
+
camera: options.camera,
|
|
22
|
+
cleanups: [],
|
|
23
|
+
customPivotX: 0,
|
|
24
|
+
customPivotY: 0,
|
|
25
|
+
disposed: false,
|
|
26
|
+
drag: null,
|
|
27
|
+
features: options.features,
|
|
28
|
+
handleRoot,
|
|
29
|
+
handles: createGizmoHandles(handleRoot),
|
|
30
|
+
mode: 'translate',
|
|
31
|
+
nodeBounds: createRectangle(),
|
|
32
|
+
outline,
|
|
33
|
+
outlineColor: defaultOutlineColor,
|
|
34
|
+
outlineEnabled: true,
|
|
35
|
+
outlinePoints: new Array(8).fill(Number.NaN),
|
|
36
|
+
overlay: options.overlayScene,
|
|
37
|
+
overlayRoot,
|
|
38
|
+
pivot: 'center',
|
|
39
|
+
pivotScreen: createVector2(),
|
|
40
|
+
pivotWorld: createVector2(),
|
|
41
|
+
snapRotation: 0,
|
|
42
|
+
snapScale: 0,
|
|
43
|
+
snapTranslate: 0,
|
|
44
|
+
space: 'world',
|
|
45
|
+
scratchPoint: createVector2(),
|
|
46
|
+
selection: options.selection,
|
|
47
|
+
signals: {
|
|
48
|
+
onRotate: createSignal(),
|
|
49
|
+
onScale: createSignal(),
|
|
50
|
+
onTransformBegin: createSignal(),
|
|
51
|
+
onTransformEnd: createSignal(),
|
|
52
|
+
onTranslate: createSignal(),
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
state[EntityRuntimeKey] = runtime;
|
|
56
|
+
addNodeChild(overlayRoot, outline);
|
|
57
|
+
addNodeChild(overlayRoot, handleRoot);
|
|
58
|
+
addNodeChild(options.overlayScene.root, overlayRoot);
|
|
59
|
+
connectGizmoHandles(runtime);
|
|
60
|
+
updateGizmo(state);
|
|
61
|
+
return state;
|
|
62
|
+
}
|
|
63
|
+
export function disposeGizmoState(state) {
|
|
64
|
+
const runtime = getGizmoRuntime(state);
|
|
65
|
+
if (runtime.disposed)
|
|
66
|
+
return;
|
|
67
|
+
finishGizmoTransform(runtime);
|
|
68
|
+
runtime.disposed = true;
|
|
69
|
+
for (let i = runtime.cleanups.length - 1; i >= 0; i--)
|
|
70
|
+
runtime.cleanups[i]();
|
|
71
|
+
runtime.cleanups.length = 0;
|
|
72
|
+
const parent = getNodeParent(runtime.overlayRoot);
|
|
73
|
+
if (parent !== null)
|
|
74
|
+
removeNodeChild(parent, runtime.overlayRoot);
|
|
75
|
+
runtime.camera = null;
|
|
76
|
+
runtime.features = null;
|
|
77
|
+
runtime.overlay = null;
|
|
78
|
+
runtime.selection = null;
|
|
79
|
+
}
|
|
80
|
+
export function getGizmoMode(state) {
|
|
81
|
+
return getGizmoRuntime(state).mode;
|
|
82
|
+
}
|
|
83
|
+
export function getGizmoSignals(state) {
|
|
84
|
+
return getGizmoRuntime(state).signals;
|
|
85
|
+
}
|
|
86
|
+
export function getGizmoSpace(state) {
|
|
87
|
+
return getGizmoRuntime(state).space;
|
|
88
|
+
}
|
|
89
|
+
export function setGizmoCustomPivot(state, x, y) {
|
|
90
|
+
const runtime = getGizmoRuntime(state);
|
|
91
|
+
runtime.customPivotX = x;
|
|
92
|
+
runtime.customPivotY = y;
|
|
93
|
+
}
|
|
94
|
+
export function setGizmoMode(state, mode) {
|
|
95
|
+
const runtime = getGizmoRuntime(state);
|
|
96
|
+
if (runtime.mode === mode)
|
|
97
|
+
return;
|
|
98
|
+
finishGizmoTransform(runtime);
|
|
99
|
+
runtime.mode = mode;
|
|
100
|
+
}
|
|
101
|
+
export function setGizmoPivot(state, pivot) {
|
|
102
|
+
getGizmoRuntime(state).pivot = pivot;
|
|
103
|
+
}
|
|
104
|
+
export function setGizmoSelectionOutlineColor(state, color) {
|
|
105
|
+
getGizmoRuntime(state).outlineColor = color >>> 0;
|
|
106
|
+
}
|
|
107
|
+
export function setGizmoSelectionOutlineEnabled(state, enabled) {
|
|
108
|
+
getGizmoRuntime(state).outlineEnabled = enabled;
|
|
109
|
+
}
|
|
110
|
+
export function setGizmoSnapRotation(state, degrees) {
|
|
111
|
+
getGizmoRuntime(state).snapRotation = normalizeGizmoSnap(degrees);
|
|
112
|
+
}
|
|
113
|
+
export function setGizmoSnapScale(state, step) {
|
|
114
|
+
getGizmoRuntime(state).snapScale = normalizeGizmoSnap(step);
|
|
115
|
+
}
|
|
116
|
+
export function setGizmoSnapTranslate(state, worldUnits) {
|
|
117
|
+
getGizmoRuntime(state).snapTranslate = normalizeGizmoSnap(worldUnits);
|
|
118
|
+
}
|
|
119
|
+
export function setGizmoSpace(state, space) {
|
|
120
|
+
getGizmoRuntime(state).space = space;
|
|
121
|
+
}
|
|
122
|
+
export function updateGizmo(state) {
|
|
123
|
+
const runtime = getGizmoRuntime(state);
|
|
124
|
+
if (runtime.disposed)
|
|
125
|
+
return;
|
|
126
|
+
const selection = runtime.selection;
|
|
127
|
+
const selected = getSelectedNodes(selection);
|
|
128
|
+
if (!computeGizmoBounds(runtime, selected)) {
|
|
129
|
+
finishGizmoTransform(runtime);
|
|
130
|
+
setGizmoNodeVisible(runtime.overlayRoot, false);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
setGizmoNodeVisible(runtime.overlayRoot, true);
|
|
134
|
+
resolveGizmoPivot(runtime);
|
|
135
|
+
projectCamera2DPoint(runtime.camera, runtime.pivotWorld.x, runtime.pivotWorld.y, runtime.pivotScreen);
|
|
136
|
+
setGizmoNodeTransform(runtime.handleRoot, runtime.pivotScreen.x, runtime.pivotScreen.y, resolveGizmoScreenRotation(runtime));
|
|
137
|
+
setGizmoNodeVisible(runtime.handleRoot, runtime.mode !== 'none');
|
|
138
|
+
updateGizmoHandleVisibility(runtime, runtime.mode);
|
|
139
|
+
setGizmoNodeVisible(runtime.outline, runtime.outlineEnabled);
|
|
140
|
+
updateGizmoOutline(runtime);
|
|
141
|
+
updateGizmoHandleLayout(runtime);
|
|
142
|
+
}
|
|
143
|
+
function computeGizmoBounds(runtime, selected) {
|
|
144
|
+
const features = runtime.features;
|
|
145
|
+
let found = false;
|
|
146
|
+
let minX = Infinity;
|
|
147
|
+
let minY = Infinity;
|
|
148
|
+
let maxX = -Infinity;
|
|
149
|
+
let maxY = -Infinity;
|
|
150
|
+
for (let i = 0; i < selected.length; i++) {
|
|
151
|
+
if (!features.getWorldBoundsRectangle(runtime.nodeBounds, selected[i]))
|
|
152
|
+
continue;
|
|
153
|
+
const bounds = runtime.nodeBounds;
|
|
154
|
+
const x0 = Math.min(bounds.x, bounds.x + bounds.width);
|
|
155
|
+
const y0 = Math.min(bounds.y, bounds.y + bounds.height);
|
|
156
|
+
const x1 = Math.max(bounds.x, bounds.x + bounds.width);
|
|
157
|
+
const y1 = Math.max(bounds.y, bounds.y + bounds.height);
|
|
158
|
+
minX = Math.min(minX, x0);
|
|
159
|
+
minY = Math.min(minY, y0);
|
|
160
|
+
maxX = Math.max(maxX, x1);
|
|
161
|
+
maxY = Math.max(maxY, y1);
|
|
162
|
+
found = true;
|
|
163
|
+
}
|
|
164
|
+
if (!found)
|
|
165
|
+
return false;
|
|
166
|
+
runtime.bounds.x = minX;
|
|
167
|
+
runtime.bounds.y = minY;
|
|
168
|
+
runtime.bounds.width = maxX - minX;
|
|
169
|
+
runtime.bounds.height = maxY - minY;
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
function connectGizmoHandle(runtime, handle) {
|
|
173
|
+
const signals = enableInteractionSignals(handle.node);
|
|
174
|
+
const onPointerDown = (data) => startGizmoTransform(runtime, handle.kind, data);
|
|
175
|
+
const onPointerMove = (data) => updateGizmoTransform(runtime, data);
|
|
176
|
+
const onPointerEnd = (data) => {
|
|
177
|
+
if (runtime.drag?.pointerId === data.pointerId)
|
|
178
|
+
finishGizmoTransform(runtime);
|
|
179
|
+
};
|
|
180
|
+
connectSignal(signals.onPointerDown, onPointerDown);
|
|
181
|
+
connectSignal(signals.onPointerMove, onPointerMove);
|
|
182
|
+
connectSignal(signals.onPointerUp, onPointerEnd);
|
|
183
|
+
connectSignal(signals.onPointerCancel, onPointerEnd);
|
|
184
|
+
connectSignal(signals.onReleaseOutside, onPointerEnd);
|
|
185
|
+
runtime.cleanups.push(() => {
|
|
186
|
+
disconnectSignal(signals.onPointerDown, onPointerDown);
|
|
187
|
+
disconnectSignal(signals.onPointerMove, onPointerMove);
|
|
188
|
+
disconnectSignal(signals.onPointerUp, onPointerEnd);
|
|
189
|
+
disconnectSignal(signals.onPointerCancel, onPointerEnd);
|
|
190
|
+
disconnectSignal(signals.onReleaseOutside, onPointerEnd);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
function connectGizmoHandles(runtime) {
|
|
194
|
+
for (let i = 0; i < runtime.handles.length; i++)
|
|
195
|
+
connectGizmoHandle(runtime, runtime.handles[i]);
|
|
196
|
+
}
|
|
197
|
+
function createGizmoHandle(kind, placement) {
|
|
198
|
+
const node = createShape({ name: `Gizmo${toGizmoHandleName(placement)}Handle` });
|
|
199
|
+
setNodeHitTestEnabled(node, true);
|
|
200
|
+
setNodeCursor(node, getGizmoHandleCursor(kind));
|
|
201
|
+
drawGizmoHandle(node, kind);
|
|
202
|
+
return { kind, node, placement };
|
|
203
|
+
}
|
|
204
|
+
function createGizmoHandles(handleRoot) {
|
|
205
|
+
const handles = [
|
|
206
|
+
createGizmoHandle('rotate', 'rotate'),
|
|
207
|
+
createGizmoHandle('translate-x', 'translate-x'),
|
|
208
|
+
createGizmoHandle('translate-y', 'translate-y'),
|
|
209
|
+
createGizmoHandle('translate-xy', 'translate-xy'),
|
|
210
|
+
createGizmoHandle('scale-x', 'scale-east'),
|
|
211
|
+
createGizmoHandle('scale-x', 'scale-west'),
|
|
212
|
+
createGizmoHandle('scale-y', 'scale-north'),
|
|
213
|
+
createGizmoHandle('scale-y', 'scale-south'),
|
|
214
|
+
createGizmoHandle('scale-xy', 'scale-northeast'),
|
|
215
|
+
createGizmoHandle('scale-xy', 'scale-northwest'),
|
|
216
|
+
createGizmoHandle('scale-xy', 'scale-southeast'),
|
|
217
|
+
createGizmoHandle('scale-xy', 'scale-southwest'),
|
|
218
|
+
];
|
|
219
|
+
for (let i = 0; i < handles.length; i++)
|
|
220
|
+
addNodeChild(handleRoot, handles[i].node);
|
|
221
|
+
return handles;
|
|
222
|
+
}
|
|
223
|
+
function drawGizmoAxis(shape, color, endX, endY) {
|
|
224
|
+
appendShapeLineStyle(shape, 2, color, 1, false, 'none');
|
|
225
|
+
appendShapeMoveTo(shape, endX === 0 ? 0 : Math.sign(endX) * handleCenterSize, endY === 0 ? 0 : Math.sign(endY) * handleCenterSize);
|
|
226
|
+
appendShapeLineTo(shape, endX, endY);
|
|
227
|
+
}
|
|
228
|
+
function drawGizmoHandle(shape, kind) {
|
|
229
|
+
switch (kind) {
|
|
230
|
+
case 'rotate':
|
|
231
|
+
drawGizmoRotateHandle(shape, minimumRotateRadius);
|
|
232
|
+
break;
|
|
233
|
+
case 'translate-x':
|
|
234
|
+
drawGizmoAxis(shape, xAxisColor, handleLength, 0);
|
|
235
|
+
appendShapeBeginFill(shape, xAxisColor);
|
|
236
|
+
appendShapePolygon(shape, [
|
|
237
|
+
handleLength,
|
|
238
|
+
0,
|
|
239
|
+
handleLength - arrowSize,
|
|
240
|
+
-arrowSize,
|
|
241
|
+
handleLength - arrowSize,
|
|
242
|
+
arrowSize,
|
|
243
|
+
]);
|
|
244
|
+
appendShapeEndFill(shape);
|
|
245
|
+
setNodeHitArea(shape, createRectangle(handleCenterSize, -hitThickness, handleLength - handleCenterSize, hitThickness * 2));
|
|
246
|
+
break;
|
|
247
|
+
case 'translate-y':
|
|
248
|
+
drawGizmoAxis(shape, yAxisColor, 0, -handleLength);
|
|
249
|
+
appendShapeBeginFill(shape, yAxisColor);
|
|
250
|
+
appendShapePolygon(shape, [
|
|
251
|
+
0,
|
|
252
|
+
-handleLength,
|
|
253
|
+
-arrowSize,
|
|
254
|
+
-handleLength + arrowSize,
|
|
255
|
+
arrowSize,
|
|
256
|
+
-handleLength + arrowSize,
|
|
257
|
+
]);
|
|
258
|
+
appendShapeEndFill(shape);
|
|
259
|
+
setNodeHitArea(shape, createRectangle(-hitThickness, -handleLength, hitThickness * 2, handleLength - handleCenterSize));
|
|
260
|
+
break;
|
|
261
|
+
case 'translate-xy':
|
|
262
|
+
appendShapeBeginFill(shape, centerColor, 0.9);
|
|
263
|
+
appendShapeRectangle(shape, -handleCenterSize, -handleCenterSize, handleCenterSize * 2, handleCenterSize * 2);
|
|
264
|
+
appendShapeEndFill(shape);
|
|
265
|
+
setNodeHitArea(shape, createRectangle(-handleCenterSize, -handleCenterSize, handleCenterSize * 2, handleCenterSize * 2));
|
|
266
|
+
break;
|
|
267
|
+
case 'scale-x':
|
|
268
|
+
appendShapeBeginFill(shape, xAxisColor);
|
|
269
|
+
appendShapeRectangle(shape, -scaleBoxSize / 2, -scaleBoxSize / 2, scaleBoxSize, scaleBoxSize);
|
|
270
|
+
appendShapeEndFill(shape);
|
|
271
|
+
setNodeHitArea(shape, createRectangle(-hitThickness, -hitThickness, hitThickness * 2, hitThickness * 2));
|
|
272
|
+
break;
|
|
273
|
+
case 'scale-y':
|
|
274
|
+
appendShapeBeginFill(shape, yAxisColor);
|
|
275
|
+
appendShapeRectangle(shape, -scaleBoxSize / 2, -scaleBoxSize / 2, scaleBoxSize, scaleBoxSize);
|
|
276
|
+
appendShapeEndFill(shape);
|
|
277
|
+
setNodeHitArea(shape, createRectangle(-hitThickness, -hitThickness, hitThickness * 2, hitThickness * 2));
|
|
278
|
+
break;
|
|
279
|
+
case 'scale-xy':
|
|
280
|
+
appendShapeBeginFill(shape, centerColor, 0.9);
|
|
281
|
+
appendShapeRectangle(shape, -scaleBoxSize / 2, -scaleBoxSize / 2, scaleBoxSize, scaleBoxSize);
|
|
282
|
+
appendShapeEndFill(shape);
|
|
283
|
+
setNodeHitArea(shape, createRectangle(-hitThickness, -hitThickness, hitThickness * 2, hitThickness * 2));
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function drawGizmoRotateHandle(shape, radius) {
|
|
288
|
+
clearShapeCommands(shape);
|
|
289
|
+
appendShapeLineStyle(shape, 3, rotateColor, 1, false, 'none');
|
|
290
|
+
appendShapeCircle(shape, 0, 0, radius);
|
|
291
|
+
setNodeHitArea(shape, createRectangle(-radius - 6, -radius - 6, radius * 2 + 12, radius * 2 + 12));
|
|
292
|
+
}
|
|
293
|
+
function finishGizmoTransform(runtime) {
|
|
294
|
+
if (runtime.drag === null)
|
|
295
|
+
return;
|
|
296
|
+
runtime.drag = null;
|
|
297
|
+
emitSignal(runtime.signals.onTransformEnd);
|
|
298
|
+
}
|
|
299
|
+
function getGizmoHandleCursor(kind) {
|
|
300
|
+
if (kind === 'translate-x')
|
|
301
|
+
return 'ew-resize';
|
|
302
|
+
if (kind === 'translate-y')
|
|
303
|
+
return 'ns-resize';
|
|
304
|
+
if (kind === 'scale-x')
|
|
305
|
+
return 'ew-resize';
|
|
306
|
+
if (kind === 'scale-y')
|
|
307
|
+
return 'ns-resize';
|
|
308
|
+
if (kind === 'scale-xy')
|
|
309
|
+
return 'nwse-resize';
|
|
310
|
+
if (kind === 'rotate')
|
|
311
|
+
return 'nesw-resize';
|
|
312
|
+
return 'move';
|
|
313
|
+
}
|
|
314
|
+
function getGizmoRuntime(state) {
|
|
315
|
+
return state[EntityRuntimeKey];
|
|
316
|
+
}
|
|
317
|
+
function getGizmoTransformMode(kind) {
|
|
318
|
+
if (kind === 'rotate')
|
|
319
|
+
return 'rotate';
|
|
320
|
+
if (kind === 'scale-x' || kind === 'scale-y' || kind === 'scale-xy')
|
|
321
|
+
return 'scale';
|
|
322
|
+
return 'translate';
|
|
323
|
+
}
|
|
324
|
+
function normalizeDegrees(degrees) {
|
|
325
|
+
let value = degrees % 360;
|
|
326
|
+
if (value > 180)
|
|
327
|
+
value -= 360;
|
|
328
|
+
else if (value < -180)
|
|
329
|
+
value += 360;
|
|
330
|
+
return value;
|
|
331
|
+
}
|
|
332
|
+
function normalizeGizmoSnap(value) {
|
|
333
|
+
return value > 0 && Number.isFinite(value) ? value : 0;
|
|
334
|
+
}
|
|
335
|
+
function resolveGizmoPivot(runtime) {
|
|
336
|
+
if (runtime.mode !== 'rotate' && runtime.mode !== 'scale') {
|
|
337
|
+
setGizmoPivotToBoundsCenter(runtime);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (runtime.pivot === 'custom') {
|
|
341
|
+
runtime.pivotWorld.x = runtime.customPivotX;
|
|
342
|
+
runtime.pivotWorld.y = runtime.customPivotY;
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (runtime.pivot === 'origin') {
|
|
346
|
+
runtime.features.getWorldOrigin(runtime.pivotWorld, getActiveNode(runtime.selection));
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
setGizmoPivotToBoundsCenter(runtime);
|
|
350
|
+
}
|
|
351
|
+
function setGizmoPivotToBoundsCenter(runtime) {
|
|
352
|
+
runtime.pivotWorld.x = runtime.bounds.x + runtime.bounds.width * 0.5;
|
|
353
|
+
runtime.pivotWorld.y = runtime.bounds.y + runtime.bounds.height * 0.5;
|
|
354
|
+
}
|
|
355
|
+
function resolveGizmoScreenRotation(runtime) {
|
|
356
|
+
if (runtime.space === 'world')
|
|
357
|
+
return 0;
|
|
358
|
+
const worldRotation = runtime.features.getWorldRotation(getActiveNode(runtime.selection));
|
|
359
|
+
return worldRotation - runtime.camera.rotation * RAD_TO_DEG;
|
|
360
|
+
}
|
|
361
|
+
function setGizmoNodeTransform(node, x, y, rotation) {
|
|
362
|
+
if (node.x === x && node.y === y && node.rotation === rotation)
|
|
363
|
+
return;
|
|
364
|
+
node.x = x;
|
|
365
|
+
node.y = y;
|
|
366
|
+
node.rotation = rotation;
|
|
367
|
+
invalidateNodeLocalTransform(node);
|
|
368
|
+
}
|
|
369
|
+
function setGizmoNodeVisible(node, visible) {
|
|
370
|
+
if (node.visible === visible)
|
|
371
|
+
return;
|
|
372
|
+
node.visible = visible;
|
|
373
|
+
invalidateNodeAppearance(node);
|
|
374
|
+
}
|
|
375
|
+
function snapGizmoDelta(value, step) {
|
|
376
|
+
return step === 0 ? value : Math.round(value / step) * step;
|
|
377
|
+
}
|
|
378
|
+
function snapGizmoScale(value, step) {
|
|
379
|
+
return step === 0 ? value : 1 + Math.round((value - 1) / step) * step;
|
|
380
|
+
}
|
|
381
|
+
function startGizmoTransform(runtime, handle, data) {
|
|
382
|
+
const mode = getGizmoTransformMode(handle);
|
|
383
|
+
if (runtime.disposed || runtime.drag !== null || runtime.mode !== mode)
|
|
384
|
+
return;
|
|
385
|
+
const active = getActiveNode(runtime.selection);
|
|
386
|
+
const axisRotation = runtime.space === 'local' && active !== null
|
|
387
|
+
? runtime.features.getWorldRotation(active)
|
|
388
|
+
: runtime.camera.rotation * RAD_TO_DEG;
|
|
389
|
+
runtime.drag = {
|
|
390
|
+
axisRotation,
|
|
391
|
+
handle,
|
|
392
|
+
mode,
|
|
393
|
+
pivotScreenX: runtime.pivotScreen.x,
|
|
394
|
+
pivotScreenY: runtime.pivotScreen.y,
|
|
395
|
+
pointerId: data.pointerId,
|
|
396
|
+
screenRotation: runtime.handleRoot.rotation * DEG_TO_RAD,
|
|
397
|
+
startScreenX: data.x,
|
|
398
|
+
startScreenY: data.y,
|
|
399
|
+
};
|
|
400
|
+
emitSignal(runtime.signals.onTransformBegin);
|
|
401
|
+
}
|
|
402
|
+
function toGizmoHandleName(placement) {
|
|
403
|
+
if (placement === 'rotate')
|
|
404
|
+
return 'Rotate';
|
|
405
|
+
if (placement === 'scale-east')
|
|
406
|
+
return 'ScaleEast';
|
|
407
|
+
if (placement === 'scale-west')
|
|
408
|
+
return 'ScaleWest';
|
|
409
|
+
if (placement === 'scale-north')
|
|
410
|
+
return 'ScaleNorth';
|
|
411
|
+
if (placement === 'scale-south')
|
|
412
|
+
return 'ScaleSouth';
|
|
413
|
+
if (placement === 'scale-northeast')
|
|
414
|
+
return 'ScaleNortheast';
|
|
415
|
+
if (placement === 'scale-northwest')
|
|
416
|
+
return 'ScaleNorthwest';
|
|
417
|
+
if (placement === 'scale-southeast')
|
|
418
|
+
return 'ScaleSoutheast';
|
|
419
|
+
if (placement === 'scale-southwest')
|
|
420
|
+
return 'ScaleSouthwest';
|
|
421
|
+
if (placement === 'translate-x')
|
|
422
|
+
return 'TranslateX';
|
|
423
|
+
if (placement === 'translate-y')
|
|
424
|
+
return 'TranslateY';
|
|
425
|
+
return 'TranslateXY';
|
|
426
|
+
}
|
|
427
|
+
function updateGizmoHandleVisibility(runtime, mode) {
|
|
428
|
+
for (let i = 0; i < runtime.handles.length; i++) {
|
|
429
|
+
const handle = runtime.handles[i];
|
|
430
|
+
setGizmoNodeVisible(handle.node, getGizmoTransformMode(handle.kind) === mode);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
function updateGizmoOutline(runtime) {
|
|
434
|
+
const bounds = runtime.bounds;
|
|
435
|
+
const points = runtime.outlinePoints;
|
|
436
|
+
projectCamera2DPoint(runtime.camera, bounds.x, bounds.y, runtime.scratchPoint);
|
|
437
|
+
points[0] = runtime.scratchPoint.x;
|
|
438
|
+
points[1] = runtime.scratchPoint.y;
|
|
439
|
+
projectCamera2DPoint(runtime.camera, bounds.x + bounds.width, bounds.y, runtime.scratchPoint);
|
|
440
|
+
points[2] = runtime.scratchPoint.x;
|
|
441
|
+
points[3] = runtime.scratchPoint.y;
|
|
442
|
+
projectCamera2DPoint(runtime.camera, bounds.x + bounds.width, bounds.y + bounds.height, runtime.scratchPoint);
|
|
443
|
+
points[4] = runtime.scratchPoint.x;
|
|
444
|
+
points[5] = runtime.scratchPoint.y;
|
|
445
|
+
projectCamera2DPoint(runtime.camera, bounds.x, bounds.y + bounds.height, runtime.scratchPoint);
|
|
446
|
+
points[6] = runtime.scratchPoint.x;
|
|
447
|
+
points[7] = runtime.scratchPoint.y;
|
|
448
|
+
clearShapeCommands(runtime.outline);
|
|
449
|
+
appendShapeLineStyle(runtime.outline, 1, (runtime.outlineColor >>> 8) & 0xffffff, (runtime.outlineColor & 0xff) / 0xff, false, 'none');
|
|
450
|
+
appendShapeMoveTo(runtime.outline, points[0], points[1]);
|
|
451
|
+
appendShapeLineTo(runtime.outline, points[2], points[3]);
|
|
452
|
+
appendShapeLineTo(runtime.outline, points[4], points[5]);
|
|
453
|
+
appendShapeLineTo(runtime.outline, points[6], points[7]);
|
|
454
|
+
appendShapeLineTo(runtime.outline, points[0], points[1]);
|
|
455
|
+
}
|
|
456
|
+
function updateGizmoHandleLayout(runtime) {
|
|
457
|
+
const radians = runtime.handleRoot.rotation * DEG_TO_RAD;
|
|
458
|
+
const cos = Math.cos(radians);
|
|
459
|
+
const sin = Math.sin(radians);
|
|
460
|
+
let minX = Infinity;
|
|
461
|
+
let minY = Infinity;
|
|
462
|
+
let maxX = -Infinity;
|
|
463
|
+
let maxY = -Infinity;
|
|
464
|
+
for (let i = 0; i < runtime.outlinePoints.length; i += 2) {
|
|
465
|
+
const deltaX = runtime.outlinePoints[i] - runtime.pivotScreen.x;
|
|
466
|
+
const deltaY = runtime.outlinePoints[i + 1] - runtime.pivotScreen.y;
|
|
467
|
+
const localX = deltaX * cos + deltaY * sin;
|
|
468
|
+
const localY = -deltaX * sin + deltaY * cos;
|
|
469
|
+
minX = Math.min(minX, localX);
|
|
470
|
+
minY = Math.min(minY, localY);
|
|
471
|
+
maxX = Math.max(maxX, localX);
|
|
472
|
+
maxY = Math.max(maxY, localY);
|
|
473
|
+
}
|
|
474
|
+
const centerX = (minX + maxX) * 0.5;
|
|
475
|
+
const centerY = (minY + maxY) * 0.5;
|
|
476
|
+
const rotateRadius = Math.max(minimumRotateRadius, Math.hypot(Math.max(Math.abs(minX), Math.abs(maxX)), Math.max(Math.abs(minY), Math.abs(maxY))) + rotatePadding);
|
|
477
|
+
for (let i = 0; i < runtime.handles.length; i++) {
|
|
478
|
+
const handle = runtime.handles[i];
|
|
479
|
+
if (handle.placement === 'rotate') {
|
|
480
|
+
drawGizmoRotateHandle(handle.node, rotateRadius);
|
|
481
|
+
}
|
|
482
|
+
else if (handle.placement === 'scale-east') {
|
|
483
|
+
setGizmoNodeTransform(handle.node, maxX, centerY, 0);
|
|
484
|
+
}
|
|
485
|
+
else if (handle.placement === 'scale-west') {
|
|
486
|
+
setGizmoNodeTransform(handle.node, minX, centerY, 0);
|
|
487
|
+
}
|
|
488
|
+
else if (handle.placement === 'scale-north') {
|
|
489
|
+
setGizmoNodeTransform(handle.node, centerX, minY, 0);
|
|
490
|
+
}
|
|
491
|
+
else if (handle.placement === 'scale-south') {
|
|
492
|
+
setGizmoNodeTransform(handle.node, centerX, maxY, 0);
|
|
493
|
+
}
|
|
494
|
+
else if (handle.placement === 'scale-northeast') {
|
|
495
|
+
setGizmoNodeTransform(handle.node, maxX, minY, 0);
|
|
496
|
+
}
|
|
497
|
+
else if (handle.placement === 'scale-northwest') {
|
|
498
|
+
setGizmoNodeTransform(handle.node, minX, minY, 0);
|
|
499
|
+
}
|
|
500
|
+
else if (handle.placement === 'scale-southeast') {
|
|
501
|
+
setGizmoNodeTransform(handle.node, maxX, maxY, 0);
|
|
502
|
+
}
|
|
503
|
+
else if (handle.placement === 'scale-southwest') {
|
|
504
|
+
setGizmoNodeTransform(handle.node, minX, maxY, 0);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function updateGizmoScale(runtime, drag, screenX, screenY, uniform) {
|
|
509
|
+
const cos = Math.cos(drag.screenRotation);
|
|
510
|
+
const sin = Math.sin(drag.screenRotation);
|
|
511
|
+
const startX = drag.startScreenX - drag.pivotScreenX;
|
|
512
|
+
const startY = drag.startScreenY - drag.pivotScreenY;
|
|
513
|
+
const currentX = screenX - drag.pivotScreenX;
|
|
514
|
+
const currentY = screenY - drag.pivotScreenY;
|
|
515
|
+
const startLocalX = startX * cos + startY * sin;
|
|
516
|
+
const startLocalY = -startX * sin + startY * cos;
|
|
517
|
+
const currentLocalX = currentX * cos + currentY * sin;
|
|
518
|
+
const currentLocalY = -currentX * sin + currentY * cos;
|
|
519
|
+
let scaleX = 1;
|
|
520
|
+
let scaleY = 1;
|
|
521
|
+
if (drag.handle === 'scale-x') {
|
|
522
|
+
if (Math.abs(startLocalX) > Number.EPSILON)
|
|
523
|
+
scaleX = currentLocalX / startLocalX;
|
|
524
|
+
if (uniform)
|
|
525
|
+
scaleY = scaleX;
|
|
526
|
+
}
|
|
527
|
+
else if (drag.handle === 'scale-y') {
|
|
528
|
+
if (Math.abs(startLocalY) > Number.EPSILON)
|
|
529
|
+
scaleY = currentLocalY / startLocalY;
|
|
530
|
+
if (uniform)
|
|
531
|
+
scaleX = scaleY;
|
|
532
|
+
}
|
|
533
|
+
else {
|
|
534
|
+
const startLength = Math.hypot(startLocalX, startLocalY);
|
|
535
|
+
const currentLength = Math.hypot(currentLocalX, currentLocalY);
|
|
536
|
+
const uniform = startLength > Number.EPSILON ? currentLength / startLength : 1;
|
|
537
|
+
scaleX = uniform;
|
|
538
|
+
scaleY = uniform;
|
|
539
|
+
}
|
|
540
|
+
emitSignal(runtime.signals.onScale, snapGizmoScale(scaleX, runtime.snapScale), snapGizmoScale(scaleY, runtime.snapScale));
|
|
541
|
+
}
|
|
542
|
+
function updateGizmoTransform(runtime, data) {
|
|
543
|
+
const drag = runtime.drag;
|
|
544
|
+
if (drag === null || drag.pointerId !== data.pointerId)
|
|
545
|
+
return;
|
|
546
|
+
if (drag.mode === 'translate')
|
|
547
|
+
updateGizmoTranslation(runtime, drag, data.x, data.y);
|
|
548
|
+
else if (drag.mode === 'rotate') {
|
|
549
|
+
const start = Math.atan2(drag.startScreenY - drag.pivotScreenY, drag.startScreenX - drag.pivotScreenX);
|
|
550
|
+
const current = Math.atan2(data.y - drag.pivotScreenY, data.x - drag.pivotScreenX);
|
|
551
|
+
const degrees = normalizeDegrees((current - start) * RAD_TO_DEG);
|
|
552
|
+
emitSignal(runtime.signals.onRotate, snapGizmoDelta(degrees, runtime.snapRotation));
|
|
553
|
+
}
|
|
554
|
+
else
|
|
555
|
+
updateGizmoScale(runtime, drag, data.x, data.y, data.shiftKey);
|
|
556
|
+
}
|
|
557
|
+
function updateGizmoTranslation(runtime, drag, screenX, screenY) {
|
|
558
|
+
unprojectCamera2DPoint(runtime.camera, drag.startScreenX, drag.startScreenY, runtime.pivotWorld);
|
|
559
|
+
unprojectCamera2DPoint(runtime.camera, screenX, screenY, runtime.scratchPoint);
|
|
560
|
+
const deltaX = runtime.scratchPoint.x - runtime.pivotWorld.x;
|
|
561
|
+
const deltaY = runtime.scratchPoint.y - runtime.pivotWorld.y;
|
|
562
|
+
const radians = drag.axisRotation * DEG_TO_RAD;
|
|
563
|
+
const cos = Math.cos(radians);
|
|
564
|
+
const sin = Math.sin(radians);
|
|
565
|
+
let localX = deltaX * cos + deltaY * sin;
|
|
566
|
+
let localY = -deltaX * sin + deltaY * cos;
|
|
567
|
+
if (drag.handle === 'translate-x')
|
|
568
|
+
localY = 0;
|
|
569
|
+
else if (drag.handle === 'translate-y')
|
|
570
|
+
localX = 0;
|
|
571
|
+
localX = snapGizmoDelta(localX, runtime.snapTranslate);
|
|
572
|
+
localY = snapGizmoDelta(localY, runtime.snapTranslate);
|
|
573
|
+
emitSignal(runtime.signals.onTranslate, localX * cos - localY * sin, localX * sin + localY * cos);
|
|
574
|
+
}
|
|
575
|
+
const arrowSize = 7;
|
|
576
|
+
const centerColor = 0x42a5f5;
|
|
577
|
+
const handleCenterSize = 7;
|
|
578
|
+
const handleLength = 72;
|
|
579
|
+
const hitThickness = 9;
|
|
580
|
+
const defaultOutlineColor = 0x4488ffff;
|
|
581
|
+
const minimumRotateRadius = 52;
|
|
582
|
+
const rotatePadding = 20;
|
|
583
|
+
const rotateColor = 0xffca28;
|
|
584
|
+
const scaleBoxSize = 11;
|
|
585
|
+
const xAxisColor = 0xef5350;
|
|
586
|
+
const yAxisColor = 0x66bb6a;
|
|
587
|
+
//# sourceMappingURL=gizmoState.js.map
|