@tonybfox/threejs-tools 1.0.0
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/README.md +321 -0
- package/dist/asset-loader/index.cjs +376 -0
- package/dist/asset-loader/index.cjs.map +1 -0
- package/dist/asset-loader/index.d.mts +101 -0
- package/dist/asset-loader/index.d.ts +101 -0
- package/dist/asset-loader/index.mjs +7 -0
- package/dist/asset-loader/index.mjs.map +1 -0
- package/dist/camera/index.cjs +313 -0
- package/dist/camera/index.cjs.map +1 -0
- package/dist/camera/index.d.mts +82 -0
- package/dist/camera/index.d.ts +82 -0
- package/dist/camera/index.mjs +7 -0
- package/dist/camera/index.mjs.map +1 -0
- package/dist/chunk-5DP6WDB3.mjs +1161 -0
- package/dist/chunk-5DP6WDB3.mjs.map +1 -0
- package/dist/chunk-BJKSICFA.mjs +1579 -0
- package/dist/chunk-BJKSICFA.mjs.map +1 -0
- package/dist/chunk-BYRZCHE7.mjs +277 -0
- package/dist/chunk-BYRZCHE7.mjs.map +1 -0
- package/dist/chunk-EIROAPF7.mjs +387 -0
- package/dist/chunk-EIROAPF7.mjs.map +1 -0
- package/dist/chunk-EQDOX34V.mjs +164 -0
- package/dist/chunk-EQDOX34V.mjs.map +1 -0
- package/dist/chunk-IIAZ2WJJ.mjs +405 -0
- package/dist/chunk-IIAZ2WJJ.mjs.map +1 -0
- package/dist/chunk-L4VIIJZD.mjs +340 -0
- package/dist/chunk-L4VIIJZD.mjs.map +1 -0
- package/dist/chunk-P35QJCOG.mjs +339 -0
- package/dist/chunk-P35QJCOG.mjs.map +1 -0
- package/dist/chunk-R64RVBRM.mjs +394 -0
- package/dist/chunk-R64RVBRM.mjs.map +1 -0
- package/dist/compass/index.cjs +375 -0
- package/dist/compass/index.cjs.map +1 -0
- package/dist/compass/index.d.mts +58 -0
- package/dist/compass/index.d.ts +58 -0
- package/dist/compass/index.mjs +7 -0
- package/dist/compass/index.mjs.map +1 -0
- package/dist/grid/index.cjs +200 -0
- package/dist/grid/index.cjs.map +1 -0
- package/dist/grid/index.d.mts +43 -0
- package/dist/grid/index.d.ts +43 -0
- package/dist/grid/index.mjs +7 -0
- package/dist/grid/index.mjs.map +1 -0
- package/dist/index.cjs +5049 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.mjs +47 -0
- package/dist/index.mjs.map +1 -0
- package/dist/measurements/index.cjs +1198 -0
- package/dist/measurements/index.cjs.map +1 -0
- package/dist/measurements/index.d.mts +449 -0
- package/dist/measurements/index.d.ts +449 -0
- package/dist/measurements/index.mjs +9 -0
- package/dist/measurements/index.mjs.map +1 -0
- package/dist/sunlight/index.cjs +441 -0
- package/dist/sunlight/index.cjs.map +1 -0
- package/dist/sunlight/index.d.mts +92 -0
- package/dist/sunlight/index.d.ts +92 -0
- package/dist/sunlight/index.mjs +7 -0
- package/dist/sunlight/index.mjs.map +1 -0
- package/dist/terrain/index.cjs +423 -0
- package/dist/terrain/index.cjs.map +1 -0
- package/dist/terrain/index.d.mts +219 -0
- package/dist/terrain/index.d.ts +219 -0
- package/dist/terrain/index.mjs +7 -0
- package/dist/terrain/index.mjs.map +1 -0
- package/dist/transform-controls/index.cjs +1587 -0
- package/dist/transform-controls/index.cjs.map +1 -0
- package/dist/transform-controls/index.d.mts +162 -0
- package/dist/transform-controls/index.d.ts +162 -0
- package/dist/transform-controls/index.mjs +13 -0
- package/dist/transform-controls/index.mjs.map +1 -0
- package/dist/view-helper/index.cjs +430 -0
- package/dist/view-helper/index.cjs.map +1 -0
- package/dist/view-helper/index.d.mts +75 -0
- package/dist/view-helper/index.d.ts +75 -0
- package/dist/view-helper/index.mjs +7 -0
- package/dist/view-helper/index.mjs.map +1 -0
- package/package.json +124 -0
|
@@ -0,0 +1,1579 @@
|
|
|
1
|
+
// packages/transform-controls/src/TransformControls.ts
|
|
2
|
+
import {
|
|
3
|
+
BoxGeometry,
|
|
4
|
+
BufferGeometry,
|
|
5
|
+
Controls,
|
|
6
|
+
CylinderGeometry,
|
|
7
|
+
DoubleSide,
|
|
8
|
+
Euler,
|
|
9
|
+
Float32BufferAttribute,
|
|
10
|
+
Line,
|
|
11
|
+
LineBasicMaterial,
|
|
12
|
+
Matrix4,
|
|
13
|
+
Mesh,
|
|
14
|
+
MeshBasicMaterial,
|
|
15
|
+
Object3D,
|
|
16
|
+
OctahedronGeometry,
|
|
17
|
+
PlaneGeometry,
|
|
18
|
+
Quaternion,
|
|
19
|
+
Raycaster,
|
|
20
|
+
TorusGeometry,
|
|
21
|
+
Vector3,
|
|
22
|
+
Box3
|
|
23
|
+
} from "three";
|
|
24
|
+
import { CSS2DObject } from "three/examples/jsm/renderers/CSS2DRenderer.js";
|
|
25
|
+
var _raycaster = new Raycaster();
|
|
26
|
+
var _tempVector = new Vector3();
|
|
27
|
+
var _tempVector2 = new Vector3();
|
|
28
|
+
var _tempQuaternion = new Quaternion();
|
|
29
|
+
var _unit = {
|
|
30
|
+
X: new Vector3(1, 0, 0),
|
|
31
|
+
Y: new Vector3(0, 1, 0),
|
|
32
|
+
Z: new Vector3(0, 0, 1)
|
|
33
|
+
};
|
|
34
|
+
var _changeEvent = { type: "change" };
|
|
35
|
+
var _mouseDownEvent = { type: "mouseDown", mode: null };
|
|
36
|
+
var _mouseUpEvent = { type: "mouseUp", mode: null };
|
|
37
|
+
var _objectChangeEvent = { type: "objectChange" };
|
|
38
|
+
var TransformControls = class extends Controls {
|
|
39
|
+
/**
|
|
40
|
+
* Constructs a new controls instance.
|
|
41
|
+
*
|
|
42
|
+
* @param {Camera} camera - The camera of the rendered scene.
|
|
43
|
+
* @param {?HTMLDOMElement} domElement - The HTML element used for event listeners.
|
|
44
|
+
*/
|
|
45
|
+
constructor(camera, domElement = null) {
|
|
46
|
+
super(void 0, domElement);
|
|
47
|
+
const root = new TransformControlsRoot(this);
|
|
48
|
+
this._root = root;
|
|
49
|
+
const gizmo = new TransformControlsGizmo();
|
|
50
|
+
this._gizmo = gizmo;
|
|
51
|
+
root.add(gizmo);
|
|
52
|
+
const plane = new TransformControlsPlane();
|
|
53
|
+
this._plane = plane;
|
|
54
|
+
root.add(plane);
|
|
55
|
+
const scope = this;
|
|
56
|
+
this._overlay = document.createElement("div");
|
|
57
|
+
this._overlay.classList.add("absolute");
|
|
58
|
+
this._overlay.classList.add("bottom-2");
|
|
59
|
+
this._overlay.classList.add("left-80");
|
|
60
|
+
this._overlay.classList.add("z-50");
|
|
61
|
+
this._overlay.classList.add("bg-gray-700");
|
|
62
|
+
this._overlay.classList.add("bg-opacity-70");
|
|
63
|
+
this._overlay.classList.add("text-white");
|
|
64
|
+
this._overlay.classList.add("p-2");
|
|
65
|
+
this._overlay.classList.add("rounded-md");
|
|
66
|
+
this._overlay.classList.add("border");
|
|
67
|
+
this._overlay.classList.add("border-gray-500");
|
|
68
|
+
this._overlay.classList.add("hidden");
|
|
69
|
+
if (domElement) {
|
|
70
|
+
domElement.appendChild(this._overlay);
|
|
71
|
+
}
|
|
72
|
+
const labelDiv = document.createElement("div");
|
|
73
|
+
labelDiv.className = "distance-label";
|
|
74
|
+
labelDiv.style.padding = "4px 8px";
|
|
75
|
+
labelDiv.style.background = "rgba(0, 0, 0, 0.8)";
|
|
76
|
+
labelDiv.style.border = "1px solid rgba(255, 255, 255, 0.3)";
|
|
77
|
+
labelDiv.style.borderRadius = "4px";
|
|
78
|
+
labelDiv.style.color = "#fff";
|
|
79
|
+
labelDiv.style.fontSize = "12px";
|
|
80
|
+
labelDiv.style.fontFamily = "monospace";
|
|
81
|
+
labelDiv.style.whiteSpace = "nowrap";
|
|
82
|
+
labelDiv.style.pointerEvents = "none";
|
|
83
|
+
labelDiv.style.userSelect = "none";
|
|
84
|
+
labelDiv.textContent = "0.00";
|
|
85
|
+
this._distanceLabel = new CSS2DObject(labelDiv);
|
|
86
|
+
this._distanceLabel.visible = false;
|
|
87
|
+
root.add(this._distanceLabel);
|
|
88
|
+
const angleLabelDiv = document.createElement("div");
|
|
89
|
+
angleLabelDiv.className = "rotation-angle-label";
|
|
90
|
+
angleLabelDiv.style.padding = "4px 8px";
|
|
91
|
+
angleLabelDiv.style.background = "rgba(0, 0, 0, 0.8)";
|
|
92
|
+
angleLabelDiv.style.border = "1px solid rgba(255, 255, 255, 0.3)";
|
|
93
|
+
angleLabelDiv.style.borderRadius = "4px";
|
|
94
|
+
angleLabelDiv.style.color = "#fff";
|
|
95
|
+
angleLabelDiv.style.fontSize = "12px";
|
|
96
|
+
angleLabelDiv.style.fontFamily = "monospace";
|
|
97
|
+
angleLabelDiv.style.whiteSpace = "nowrap";
|
|
98
|
+
angleLabelDiv.style.pointerEvents = "none";
|
|
99
|
+
angleLabelDiv.style.userSelect = "none";
|
|
100
|
+
angleLabelDiv.textContent = "0\xB0";
|
|
101
|
+
this._rotationAngleLabel = new CSS2DObject(angleLabelDiv);
|
|
102
|
+
this._rotationAngleLabel.visible = false;
|
|
103
|
+
root.add(this._rotationAngleLabel);
|
|
104
|
+
this._rotationArc = null;
|
|
105
|
+
function defineProperty(propName, defaultValue) {
|
|
106
|
+
let propValue = defaultValue;
|
|
107
|
+
Object.defineProperty(scope, propName, {
|
|
108
|
+
get: function() {
|
|
109
|
+
return propValue !== void 0 ? propValue : defaultValue;
|
|
110
|
+
},
|
|
111
|
+
set: function(value) {
|
|
112
|
+
if (propValue !== value) {
|
|
113
|
+
propValue = value;
|
|
114
|
+
plane[propName] = value;
|
|
115
|
+
gizmo[propName] = value;
|
|
116
|
+
scope.dispatchEvent({
|
|
117
|
+
type: propName + "-changed",
|
|
118
|
+
value
|
|
119
|
+
});
|
|
120
|
+
scope.dispatchEvent(_changeEvent);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
scope[propName] = defaultValue;
|
|
125
|
+
plane[propName] = defaultValue;
|
|
126
|
+
gizmo[propName] = defaultValue;
|
|
127
|
+
}
|
|
128
|
+
defineProperty("camera", camera);
|
|
129
|
+
defineProperty("object", void 0);
|
|
130
|
+
defineProperty("enabled", true);
|
|
131
|
+
defineProperty("axis", null);
|
|
132
|
+
defineProperty("mode", "all");
|
|
133
|
+
defineProperty("translationSnap", null);
|
|
134
|
+
defineProperty("rotationSnap", null);
|
|
135
|
+
defineProperty("scaleSnap", null);
|
|
136
|
+
defineProperty("space", "world");
|
|
137
|
+
defineProperty("size", 0.75);
|
|
138
|
+
defineProperty("dragging", false);
|
|
139
|
+
defineProperty("activeMode", "translate");
|
|
140
|
+
defineProperty("showX", true);
|
|
141
|
+
defineProperty("showY", true);
|
|
142
|
+
defineProperty("showZ", true);
|
|
143
|
+
defineProperty("minX", -Infinity);
|
|
144
|
+
defineProperty("maxX", Infinity);
|
|
145
|
+
defineProperty("minY", -Infinity);
|
|
146
|
+
defineProperty("maxY", Infinity);
|
|
147
|
+
defineProperty("minZ", -Infinity);
|
|
148
|
+
defineProperty("maxZ", Infinity);
|
|
149
|
+
defineProperty("minRotation", -2 * Math.PI);
|
|
150
|
+
defineProperty("maxRotation", 2 * Math.PI);
|
|
151
|
+
const worldPosition = new Vector3();
|
|
152
|
+
const worldPositionStart = new Vector3();
|
|
153
|
+
const worldQuaternion = new Quaternion();
|
|
154
|
+
const worldQuaternionStart = new Quaternion();
|
|
155
|
+
const cameraPosition = new Vector3();
|
|
156
|
+
const cameraQuaternion = new Quaternion();
|
|
157
|
+
const pointStart = new Vector3();
|
|
158
|
+
const pointEnd = new Vector3();
|
|
159
|
+
const rotationAxis = new Vector3();
|
|
160
|
+
const rotationAngle = 0;
|
|
161
|
+
const eye = new Vector3();
|
|
162
|
+
defineProperty("worldPosition", worldPosition);
|
|
163
|
+
defineProperty("worldPositionStart", worldPositionStart);
|
|
164
|
+
defineProperty("worldQuaternion", worldQuaternion);
|
|
165
|
+
defineProperty("worldQuaternionStart", worldQuaternionStart);
|
|
166
|
+
defineProperty("cameraPosition", cameraPosition);
|
|
167
|
+
defineProperty("cameraQuaternion", cameraQuaternion);
|
|
168
|
+
defineProperty("pointStart", pointStart);
|
|
169
|
+
defineProperty("pointEnd", pointEnd);
|
|
170
|
+
defineProperty("rotationAxis", rotationAxis);
|
|
171
|
+
defineProperty("rotationAngle", rotationAngle);
|
|
172
|
+
defineProperty("eye", eye);
|
|
173
|
+
this._offset = new Vector3();
|
|
174
|
+
this._startNorm = new Vector3();
|
|
175
|
+
this._endNorm = new Vector3();
|
|
176
|
+
this._cameraScale = new Vector3();
|
|
177
|
+
this._parentPosition = new Vector3();
|
|
178
|
+
this._parentQuaternion = new Quaternion();
|
|
179
|
+
this._parentQuaternionInv = new Quaternion();
|
|
180
|
+
this._parentScale = new Vector3();
|
|
181
|
+
this._worldScaleStart = new Vector3();
|
|
182
|
+
this._worldQuaternionInv = new Quaternion();
|
|
183
|
+
this._worldScale = new Vector3();
|
|
184
|
+
this._tempPosition = new Vector3();
|
|
185
|
+
this._positionStart = new Vector3();
|
|
186
|
+
this._quaternionStart = new Quaternion();
|
|
187
|
+
this._scaleStart = new Vector3();
|
|
188
|
+
this._getPointer = getPointer.bind(this);
|
|
189
|
+
this._onPointerDown = onPointerDown.bind(this);
|
|
190
|
+
this._onPointerHover = onPointerHover.bind(this);
|
|
191
|
+
this._onPointerMove = onPointerMove.bind(this);
|
|
192
|
+
this._onPointerUp = onPointerUp.bind(this);
|
|
193
|
+
if (domElement !== null) {
|
|
194
|
+
this.connect(domElement);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
connect(element) {
|
|
198
|
+
super.connect(element);
|
|
199
|
+
if (this.domElement?.parentNode) {
|
|
200
|
+
this.domElement.parentNode.appendChild(this._overlay);
|
|
201
|
+
}
|
|
202
|
+
this.domElement?.addEventListener("pointerdown", this._onPointerDown);
|
|
203
|
+
this.domElement?.addEventListener("pointermove", this._onPointerHover);
|
|
204
|
+
this.domElement?.addEventListener("pointerup", this._onPointerUp);
|
|
205
|
+
if (this.domElement) {
|
|
206
|
+
this.domElement.style.touchAction = "none";
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
disconnect() {
|
|
210
|
+
if (this._overlay.parentNode) {
|
|
211
|
+
this._overlay.parentNode.removeChild(this._overlay);
|
|
212
|
+
}
|
|
213
|
+
this.domElement?.removeEventListener("pointerdown", this._onPointerDown);
|
|
214
|
+
this.domElement?.removeEventListener("pointermove", this._onPointerHover);
|
|
215
|
+
this.domElement?.removeEventListener("pointermove", this._onPointerMove);
|
|
216
|
+
this.domElement?.removeEventListener("pointerup", this._onPointerUp);
|
|
217
|
+
if (this.domElement) {
|
|
218
|
+
this.domElement.style.touchAction = "auto";
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Returns the visual representation of the controls. Add the helper to your scene to
|
|
223
|
+
* visually transform the attached 3D object.
|
|
224
|
+
*
|
|
225
|
+
* @return {TransformControlsRoot} The helper.
|
|
226
|
+
*/
|
|
227
|
+
getHelper() {
|
|
228
|
+
return this._root;
|
|
229
|
+
}
|
|
230
|
+
pointerHover(pointer) {
|
|
231
|
+
if (this.object === void 0 || this.dragging === true) return;
|
|
232
|
+
if (pointer !== null) _raycaster.setFromCamera(pointer, this.camera);
|
|
233
|
+
let intersect = null;
|
|
234
|
+
if (this.mode === "all") {
|
|
235
|
+
intersect = intersectObjectWithRay(
|
|
236
|
+
this._gizmo.picker["scale"],
|
|
237
|
+
_raycaster
|
|
238
|
+
);
|
|
239
|
+
if (!intersect) {
|
|
240
|
+
intersect = intersectObjectWithRay(
|
|
241
|
+
this._gizmo.picker["rotate"],
|
|
242
|
+
_raycaster
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
if (!intersect) {
|
|
246
|
+
intersect = intersectObjectWithRay(
|
|
247
|
+
this._gizmo.picker["translate"],
|
|
248
|
+
_raycaster
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
} else {
|
|
252
|
+
intersect = intersectObjectWithRay(
|
|
253
|
+
this._gizmo.picker[this.mode],
|
|
254
|
+
_raycaster
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
if (intersect) {
|
|
258
|
+
this.axis = intersect.object.name;
|
|
259
|
+
} else {
|
|
260
|
+
this.axis = null;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
pointerDown(pointer) {
|
|
264
|
+
if (this.object === void 0 || this.dragging === true || pointer != null && pointer.button !== 0)
|
|
265
|
+
return;
|
|
266
|
+
if (this.axis !== null) {
|
|
267
|
+
if (pointer !== null) _raycaster.setFromCamera(pointer, this.camera);
|
|
268
|
+
if (this.mode === "all") {
|
|
269
|
+
let intersect = intersectObjectWithRay(
|
|
270
|
+
this._gizmo.picker["scale"],
|
|
271
|
+
_raycaster
|
|
272
|
+
);
|
|
273
|
+
if (intersect && intersect.object.name === this.axis) {
|
|
274
|
+
this.activeMode = "scale";
|
|
275
|
+
} else {
|
|
276
|
+
intersect = intersectObjectWithRay(
|
|
277
|
+
this._gizmo.picker["rotate"],
|
|
278
|
+
_raycaster
|
|
279
|
+
);
|
|
280
|
+
if (intersect && intersect.object.name === this.axis) {
|
|
281
|
+
this.activeMode = "rotate";
|
|
282
|
+
} else {
|
|
283
|
+
this.activeMode = "translate";
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
} else {
|
|
287
|
+
this.activeMode = this.mode;
|
|
288
|
+
}
|
|
289
|
+
const planeIntersect = intersectObjectWithRay(
|
|
290
|
+
this._plane,
|
|
291
|
+
_raycaster,
|
|
292
|
+
true
|
|
293
|
+
);
|
|
294
|
+
if (planeIntersect) {
|
|
295
|
+
this.object.updateMatrixWorld();
|
|
296
|
+
this.object.parent.updateMatrixWorld();
|
|
297
|
+
this._positionStart.copy(this.object.position);
|
|
298
|
+
this._quaternionStart.copy(this.object.quaternion);
|
|
299
|
+
this._scaleStart.copy(this.object.scale);
|
|
300
|
+
const boundingBoxCenter = calculateBoundingBoxCenter(this.object);
|
|
301
|
+
this.worldPositionStart.copy(boundingBoxCenter);
|
|
302
|
+
this.object.matrixWorld.decompose(
|
|
303
|
+
this._tempPosition,
|
|
304
|
+
// Use temporary variable for position
|
|
305
|
+
this.worldQuaternionStart,
|
|
306
|
+
this._worldScaleStart
|
|
307
|
+
);
|
|
308
|
+
this.pointStart.copy(planeIntersect.point).sub(this.worldPositionStart);
|
|
309
|
+
}
|
|
310
|
+
this.dragging = true;
|
|
311
|
+
_mouseDownEvent.mode = this.mode === "all" ? this.activeMode : this.mode;
|
|
312
|
+
this.dispatchEvent(_mouseDownEvent);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
pointerMove(pointer) {
|
|
316
|
+
const axis = this.axis;
|
|
317
|
+
const mode = this.mode === "all" ? this.activeMode : this.mode;
|
|
318
|
+
const object = this.object;
|
|
319
|
+
let space = this.space;
|
|
320
|
+
if (mode === "scale") {
|
|
321
|
+
space = "local";
|
|
322
|
+
} else if (axis === "E" || axis === "XYZE" || axis === "XYZ") {
|
|
323
|
+
space = "world";
|
|
324
|
+
}
|
|
325
|
+
if (object === void 0 || axis === null || this.dragging === false || pointer !== null && pointer.button !== -1) {
|
|
326
|
+
this._updateDistanceOverlay();
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (pointer !== null) _raycaster.setFromCamera(pointer, this.camera);
|
|
330
|
+
const planeIntersect = intersectObjectWithRay(this._plane, _raycaster, true);
|
|
331
|
+
if (!planeIntersect) return;
|
|
332
|
+
this.pointEnd.copy(planeIntersect.point).sub(this.worldPositionStart);
|
|
333
|
+
if (mode === "translate") {
|
|
334
|
+
this._offset.copy(this.pointEnd).sub(this.pointStart);
|
|
335
|
+
if (space === "local" && axis !== "XYZ") {
|
|
336
|
+
this._offset.applyQuaternion(this._worldQuaternionInv);
|
|
337
|
+
}
|
|
338
|
+
if (axis.indexOf("X") === -1) this._offset.x = 0;
|
|
339
|
+
if (axis.indexOf("Y") === -1) this._offset.y = 0;
|
|
340
|
+
if (axis.indexOf("Z") === -1) this._offset.z = 0;
|
|
341
|
+
if (space === "local" && axis !== "XYZ") {
|
|
342
|
+
this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale);
|
|
343
|
+
} else {
|
|
344
|
+
this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale);
|
|
345
|
+
}
|
|
346
|
+
object.position.copy(this._offset).add(this._positionStart);
|
|
347
|
+
if (this.translationSnap) {
|
|
348
|
+
if (space === "local") {
|
|
349
|
+
object.position.applyQuaternion(
|
|
350
|
+
_tempQuaternion.copy(this._quaternionStart).invert()
|
|
351
|
+
);
|
|
352
|
+
if (axis.search("X") !== -1) {
|
|
353
|
+
object.position.x = Math.round(object.position.x / this.translationSnap) * this.translationSnap;
|
|
354
|
+
}
|
|
355
|
+
if (axis.search("Y") !== -1) {
|
|
356
|
+
object.position.y = Math.round(object.position.y / this.translationSnap) * this.translationSnap;
|
|
357
|
+
}
|
|
358
|
+
if (axis.search("Z") !== -1) {
|
|
359
|
+
object.position.z = Math.round(object.position.z / this.translationSnap) * this.translationSnap;
|
|
360
|
+
}
|
|
361
|
+
object.position.applyQuaternion(this._quaternionStart);
|
|
362
|
+
}
|
|
363
|
+
if (space === "world") {
|
|
364
|
+
if (object.parent) {
|
|
365
|
+
object.position.add(
|
|
366
|
+
_tempVector.setFromMatrixPosition(object.parent.matrixWorld)
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
if (axis.search("X") !== -1) {
|
|
370
|
+
object.position.x = Math.round(object.position.x / this.translationSnap) * this.translationSnap;
|
|
371
|
+
}
|
|
372
|
+
if (axis.search("Y") !== -1) {
|
|
373
|
+
object.position.y = Math.round(object.position.y / this.translationSnap) * this.translationSnap;
|
|
374
|
+
}
|
|
375
|
+
if (axis.search("Z") !== -1) {
|
|
376
|
+
object.position.z = Math.round(object.position.z / this.translationSnap) * this.translationSnap;
|
|
377
|
+
}
|
|
378
|
+
if (object.parent) {
|
|
379
|
+
object.position.sub(
|
|
380
|
+
_tempVector.setFromMatrixPosition(object.parent.matrixWorld)
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
object.position.x = Math.max(
|
|
386
|
+
this.minX,
|
|
387
|
+
Math.min(this.maxX, object.position.x)
|
|
388
|
+
);
|
|
389
|
+
object.position.y = Math.max(
|
|
390
|
+
this.minY,
|
|
391
|
+
Math.min(this.maxY, object.position.y)
|
|
392
|
+
);
|
|
393
|
+
object.position.z = Math.max(
|
|
394
|
+
this.minZ,
|
|
395
|
+
Math.min(this.maxZ, object.position.z)
|
|
396
|
+
);
|
|
397
|
+
} else if (mode === "scale") {
|
|
398
|
+
if (axis.search("XYZ") !== -1) {
|
|
399
|
+
let d = this.pointEnd.length() / this.pointStart.length();
|
|
400
|
+
if (this.pointEnd.dot(this.pointStart) < 0) d *= -1;
|
|
401
|
+
_tempVector2.set(d, d, d);
|
|
402
|
+
} else {
|
|
403
|
+
_tempVector.copy(this.pointStart);
|
|
404
|
+
_tempVector2.copy(this.pointEnd);
|
|
405
|
+
_tempVector.applyQuaternion(this._worldQuaternionInv);
|
|
406
|
+
_tempVector2.applyQuaternion(this._worldQuaternionInv);
|
|
407
|
+
_tempVector2.divide(_tempVector);
|
|
408
|
+
if (axis.search("X") === -1) {
|
|
409
|
+
_tempVector2.x = 1;
|
|
410
|
+
}
|
|
411
|
+
if (axis.search("Y") === -1) {
|
|
412
|
+
_tempVector2.y = 1;
|
|
413
|
+
}
|
|
414
|
+
if (axis.search("Z") === -1) {
|
|
415
|
+
_tempVector2.z = 1;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
object.scale.copy(this._scaleStart).multiply(_tempVector2);
|
|
419
|
+
if (this.scaleSnap) {
|
|
420
|
+
if (axis.search("X") !== -1) {
|
|
421
|
+
object.scale.x = Math.round(object.scale.x / this.scaleSnap) * this.scaleSnap || this.scaleSnap;
|
|
422
|
+
}
|
|
423
|
+
if (axis.search("Y") !== -1) {
|
|
424
|
+
object.scale.y = Math.round(object.scale.y / this.scaleSnap) * this.scaleSnap || this.scaleSnap;
|
|
425
|
+
}
|
|
426
|
+
if (axis.search("Z") !== -1) {
|
|
427
|
+
object.scale.z = Math.round(object.scale.z / this.scaleSnap) * this.scaleSnap || this.scaleSnap;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
} else if (mode === "rotate") {
|
|
431
|
+
this._offset.copy(this.pointEnd).sub(this.pointStart);
|
|
432
|
+
const ROTATION_SPEED = 20 / this.worldPosition.distanceTo(
|
|
433
|
+
_tempVector.setFromMatrixPosition(this.camera.matrixWorld)
|
|
434
|
+
);
|
|
435
|
+
let _inPlaneRotation = false;
|
|
436
|
+
if (axis === "XYZE") {
|
|
437
|
+
this.rotationAxis.copy(this._offset).cross(this.eye).normalize();
|
|
438
|
+
this.rotationAngle = this._offset.dot(
|
|
439
|
+
_tempVector.copy(this.rotationAxis).cross(this.eye)
|
|
440
|
+
) * ROTATION_SPEED;
|
|
441
|
+
} else if (axis === "X" || axis === "Y" || axis === "Z") {
|
|
442
|
+
this.rotationAxis.copy(_unit[axis]);
|
|
443
|
+
_tempVector.copy(_unit[axis]);
|
|
444
|
+
if (space === "local") {
|
|
445
|
+
_tempVector.applyQuaternion(this.worldQuaternion);
|
|
446
|
+
}
|
|
447
|
+
_tempVector.cross(this.eye);
|
|
448
|
+
if (_tempVector.length() === 0) {
|
|
449
|
+
_inPlaneRotation = true;
|
|
450
|
+
} else {
|
|
451
|
+
this.rotationAngle = this._offset.dot(_tempVector.normalize()) * ROTATION_SPEED;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (axis === "E" || _inPlaneRotation) {
|
|
455
|
+
this.rotationAxis.copy(this.eye);
|
|
456
|
+
this.rotationAngle = this.pointEnd.angleTo(this.pointStart);
|
|
457
|
+
this._startNorm.copy(this.pointStart).normalize();
|
|
458
|
+
this._endNorm.copy(this.pointEnd).normalize();
|
|
459
|
+
this.rotationAngle *= this._endNorm.cross(this._startNorm).dot(this.eye) < 0 ? 1 : -1;
|
|
460
|
+
}
|
|
461
|
+
if (this.rotationSnap)
|
|
462
|
+
this.rotationAngle = Math.round(this.rotationAngle / this.rotationSnap) * this.rotationSnap;
|
|
463
|
+
this.rotationAngle = Math.max(
|
|
464
|
+
this.minRotation,
|
|
465
|
+
Math.min(this.maxRotation, this.rotationAngle)
|
|
466
|
+
);
|
|
467
|
+
if (space === "local" && axis !== "E" && axis !== "XYZE") {
|
|
468
|
+
object.quaternion.copy(this._quaternionStart);
|
|
469
|
+
object.quaternion.multiply(
|
|
470
|
+
_tempQuaternion.setFromAxisAngle(
|
|
471
|
+
this.rotationAxis,
|
|
472
|
+
this.rotationAngle
|
|
473
|
+
)
|
|
474
|
+
).normalize();
|
|
475
|
+
} else {
|
|
476
|
+
this.rotationAxis.applyQuaternion(this._parentQuaternionInv);
|
|
477
|
+
object.quaternion.copy(
|
|
478
|
+
_tempQuaternion.setFromAxisAngle(
|
|
479
|
+
this.rotationAxis,
|
|
480
|
+
this.rotationAngle
|
|
481
|
+
)
|
|
482
|
+
);
|
|
483
|
+
object.quaternion.multiply(this._quaternionStart).normalize();
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
this.dispatchEvent(_changeEvent);
|
|
487
|
+
this.dispatchEvent(_objectChangeEvent);
|
|
488
|
+
this._updateDistanceOverlay();
|
|
489
|
+
}
|
|
490
|
+
pointerUp(pointer) {
|
|
491
|
+
if (pointer !== null && pointer.button !== 0) return;
|
|
492
|
+
if (this.dragging && this.axis !== null) {
|
|
493
|
+
_mouseUpEvent.mode = this.mode;
|
|
494
|
+
this.dispatchEvent(_mouseUpEvent);
|
|
495
|
+
}
|
|
496
|
+
this.dragging = false;
|
|
497
|
+
this.axis = null;
|
|
498
|
+
this._updateDistanceOverlay();
|
|
499
|
+
}
|
|
500
|
+
dispose() {
|
|
501
|
+
this.disconnect();
|
|
502
|
+
this._root.dispose();
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Sets the 3D object that should be transformed and ensures the controls UI is visible.
|
|
506
|
+
*
|
|
507
|
+
* @param {Object3D} object - The 3D object that should be transformed.
|
|
508
|
+
* @return {TransformControls} A reference to this controls.
|
|
509
|
+
*/
|
|
510
|
+
attach(object) {
|
|
511
|
+
this.object = object;
|
|
512
|
+
this._root.visible = true;
|
|
513
|
+
return this;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Removes the current 3D object from the controls and makes the helper UI invisible.
|
|
517
|
+
*
|
|
518
|
+
* @return {TransformControls} A reference to this controls.
|
|
519
|
+
*/
|
|
520
|
+
detach() {
|
|
521
|
+
this.object = void 0;
|
|
522
|
+
this.axis = null;
|
|
523
|
+
this._root.visible = false;
|
|
524
|
+
return this;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Resets the object's position, rotation and scale to when the current transform began.
|
|
528
|
+
*/
|
|
529
|
+
reset() {
|
|
530
|
+
if (!this.enabled) return;
|
|
531
|
+
if (this.dragging) {
|
|
532
|
+
this.object.position.copy(this._positionStart);
|
|
533
|
+
this.object.quaternion.copy(this._quaternionStart);
|
|
534
|
+
this.object.scale.copy(this._scaleStart);
|
|
535
|
+
this.dispatchEvent(_changeEvent);
|
|
536
|
+
this.dispatchEvent(_objectChangeEvent);
|
|
537
|
+
this.pointStart.copy(this.pointEnd);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Returns the raycaster that is used for user interaction. This object is shared between all
|
|
542
|
+
* instances of `TransformControls`.
|
|
543
|
+
*
|
|
544
|
+
* @returns {Raycaster} The internal raycaster.
|
|
545
|
+
*/
|
|
546
|
+
getRaycaster() {
|
|
547
|
+
return _raycaster;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Returns the transformation mode.
|
|
551
|
+
*
|
|
552
|
+
* @returns {'translate'|'rotate'|'scale'} The transformation mode.
|
|
553
|
+
*/
|
|
554
|
+
getMode() {
|
|
555
|
+
return this.mode;
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Sets the given transformation mode.
|
|
559
|
+
*
|
|
560
|
+
* @param {'translate'|'rotate'|'scale'|'all'} mode - The transformation mode to set.
|
|
561
|
+
*/
|
|
562
|
+
setMode(mode) {
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Sets the translation snap.
|
|
566
|
+
*
|
|
567
|
+
* @param {?number} translationSnap - The translation snap to set.
|
|
568
|
+
*/
|
|
569
|
+
setTranslationSnap(translationSnap) {
|
|
570
|
+
this.translationSnap = translationSnap;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Sets the rotation snap.
|
|
574
|
+
*
|
|
575
|
+
* @param {?number} rotationSnap - The rotation snap to set.
|
|
576
|
+
*/
|
|
577
|
+
setRotationSnap(rotationSnap) {
|
|
578
|
+
this.rotationSnap = rotationSnap;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Sets the minimum rotation angle limit (in radians).
|
|
582
|
+
*
|
|
583
|
+
* @param {number} minRotation - The minimum rotation angle to set (in radians).
|
|
584
|
+
*/
|
|
585
|
+
setMinRotation(minRotation) {
|
|
586
|
+
this.minRotation = minRotation;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Sets the maximum rotation angle limit (in radians).
|
|
590
|
+
*
|
|
591
|
+
* @param {number} maxRotation - The maximum rotation angle to set (in radians).
|
|
592
|
+
*/
|
|
593
|
+
setMaxRotation(maxRotation) {
|
|
594
|
+
this.maxRotation = maxRotation;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Sets the scale snap.
|
|
598
|
+
*
|
|
599
|
+
* @param {?number} scaleSnap - The scale snap to set.
|
|
600
|
+
*/
|
|
601
|
+
setScaleSnap(scaleSnap) {
|
|
602
|
+
this.scaleSnap = scaleSnap;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Sets the size of the helper UI.
|
|
606
|
+
*
|
|
607
|
+
* @param {number} size - The size to set.
|
|
608
|
+
*/
|
|
609
|
+
setSize(size) {
|
|
610
|
+
this.size = size;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Sets the coordinate space in which transformations are applied.
|
|
614
|
+
*
|
|
615
|
+
* @param {'world'|'local'} space - The space to set.
|
|
616
|
+
*/
|
|
617
|
+
setSpace(space) {
|
|
618
|
+
this.space = space;
|
|
619
|
+
}
|
|
620
|
+
_updateDistanceOverlay() {
|
|
621
|
+
if (!this.object || !this.dragging) {
|
|
622
|
+
this._overlay.classList.add("hidden");
|
|
623
|
+
this._distanceLabel.visible = false;
|
|
624
|
+
this._rotationAngleLabel.visible = false;
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
if (this.mode === "translate" || this.mode === "all" && this.activeMode === "translate") {
|
|
628
|
+
const xDistance = this.object.position.x - this._positionStart.x;
|
|
629
|
+
const yDistance = this.object.position.y - this._positionStart.y;
|
|
630
|
+
const zDistance = this.object.position.z - this._positionStart.z;
|
|
631
|
+
const totalDistance = Math.sqrt(
|
|
632
|
+
xDistance * xDistance + yDistance * yDistance + zDistance * zDistance
|
|
633
|
+
);
|
|
634
|
+
const midPoint = new Vector3(
|
|
635
|
+
(this._positionStart.x + this.object.position.x) / 2,
|
|
636
|
+
(this._positionStart.y + this.object.position.y) / 2,
|
|
637
|
+
(this._positionStart.z + this.object.position.z) / 2
|
|
638
|
+
);
|
|
639
|
+
this._distanceLabel.position.copy(midPoint);
|
|
640
|
+
this._distanceLabel.visible = true;
|
|
641
|
+
this._rotationAngleLabel.visible = false;
|
|
642
|
+
this._distanceLabel.element.textContent = `${totalDistance.toFixed(3)}`;
|
|
643
|
+
this._overlay.textContent = `X: ${xDistance.toFixed(2)} Y: ${yDistance.toFixed(2)} Z: ${zDistance.toFixed(2)}`;
|
|
644
|
+
} else if (this.mode === "rotate" || this.mode === "all" && this.activeMode === "rotate") {
|
|
645
|
+
this._distanceLabel.visible = false;
|
|
646
|
+
const angleDegrees = this.rotationAngle * 180 / Math.PI;
|
|
647
|
+
const labelRadius = 0.55;
|
|
648
|
+
const labelAngle = this.rotationAngle / 2;
|
|
649
|
+
const labelPos = new Vector3();
|
|
650
|
+
if (this.axis === "X" || this.axis === "Y" || this.axis === "Z") {
|
|
651
|
+
const axisvec = _unit[this.axis];
|
|
652
|
+
const perpVector = new Vector3();
|
|
653
|
+
if (Math.abs(axisvec.dot(this.pointStart.clone().normalize())) > 0.99) {
|
|
654
|
+
perpVector.copy(this.eye).cross(axisvec).normalize();
|
|
655
|
+
} else {
|
|
656
|
+
perpVector.copy(this.pointStart).normalize();
|
|
657
|
+
}
|
|
658
|
+
const rotQuat = new Quaternion().setFromAxisAngle(axisvec, labelAngle);
|
|
659
|
+
perpVector.applyQuaternion(rotQuat);
|
|
660
|
+
if (this.space === "local") {
|
|
661
|
+
perpVector.applyQuaternion(this.worldQuaternion);
|
|
662
|
+
}
|
|
663
|
+
perpVector.multiplyScalar(labelRadius);
|
|
664
|
+
labelPos.copy(this.worldPosition).add(perpVector);
|
|
665
|
+
} else {
|
|
666
|
+
labelPos.copy(this.worldPosition);
|
|
667
|
+
const offsetDir = this.pointStart.clone().normalize();
|
|
668
|
+
if (this.space === "local") {
|
|
669
|
+
offsetDir.applyQuaternion(this.worldQuaternion);
|
|
670
|
+
}
|
|
671
|
+
offsetDir.multiplyScalar(labelRadius);
|
|
672
|
+
labelPos.add(offsetDir);
|
|
673
|
+
}
|
|
674
|
+
this._rotationAngleLabel.position.copy(labelPos);
|
|
675
|
+
this._rotationAngleLabel.visible = true;
|
|
676
|
+
this._rotationAngleLabel.element.textContent = `${Math.abs(angleDegrees).toFixed(1)}\xB0`;
|
|
677
|
+
this._overlay.textContent = `X: ${(this.object.rotation.x * (180 / Math.PI)).toFixed(2)}\xB0 Y: ${(this.object.rotation.y * (180 / Math.PI)).toFixed(2)}\xB0 Z: ${(this.object.rotation.z * (180 / Math.PI)).toFixed(2)}\xB0`;
|
|
678
|
+
} else if (this.mode === "scale") {
|
|
679
|
+
this._distanceLabel.visible = false;
|
|
680
|
+
this._rotationAngleLabel.visible = false;
|
|
681
|
+
this._overlay.textContent = `X: ${this.object.scale.x.toFixed(2)} Y: ${this.object.scale.y.toFixed(2)} Z: ${this.object.scale.z.toFixed(2)}`;
|
|
682
|
+
}
|
|
683
|
+
this._overlay.classList.remove("hidden");
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
function getPointer(event) {
|
|
687
|
+
if (this.domElement.ownerDocument.pointerLockElement) {
|
|
688
|
+
return {
|
|
689
|
+
x: 0,
|
|
690
|
+
y: 0,
|
|
691
|
+
button: event.button
|
|
692
|
+
};
|
|
693
|
+
} else {
|
|
694
|
+
const rect = this.domElement.getBoundingClientRect();
|
|
695
|
+
return {
|
|
696
|
+
x: (event.clientX - rect.left) / rect.width * 2 - 1,
|
|
697
|
+
y: -(event.clientY - rect.top) / rect.height * 2 + 1,
|
|
698
|
+
button: event.button
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
function onPointerHover(event) {
|
|
703
|
+
if (!this.enabled) return;
|
|
704
|
+
switch (event.pointerType) {
|
|
705
|
+
case "mouse":
|
|
706
|
+
case "pen":
|
|
707
|
+
this.pointerHover(this._getPointer(event));
|
|
708
|
+
break;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
function onPointerDown(event) {
|
|
712
|
+
if (!this.enabled) return;
|
|
713
|
+
if (!document.pointerLockElement) {
|
|
714
|
+
this.domElement.setPointerCapture(event.pointerId);
|
|
715
|
+
}
|
|
716
|
+
this.domElement.addEventListener("pointermove", this._onPointerMove);
|
|
717
|
+
this.pointerHover(this._getPointer(event));
|
|
718
|
+
this.pointerDown(this._getPointer(event));
|
|
719
|
+
}
|
|
720
|
+
function onPointerMove(event) {
|
|
721
|
+
if (!this.enabled) return;
|
|
722
|
+
this.pointerMove(this._getPointer(event));
|
|
723
|
+
}
|
|
724
|
+
function onPointerUp(event) {
|
|
725
|
+
if (!this.enabled) return;
|
|
726
|
+
this.domElement.releasePointerCapture(event.pointerId);
|
|
727
|
+
this.domElement.removeEventListener("pointermove", this._onPointerMove);
|
|
728
|
+
this.pointerUp(this._getPointer(event));
|
|
729
|
+
}
|
|
730
|
+
function intersectObjectWithRay(object, raycaster, includeInvisible) {
|
|
731
|
+
const allIntersections = raycaster.intersectObject(object, true);
|
|
732
|
+
for (let i = 0; i < allIntersections.length; i++) {
|
|
733
|
+
if (allIntersections[i].object.visible || includeInvisible) {
|
|
734
|
+
return allIntersections[i];
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
return false;
|
|
738
|
+
}
|
|
739
|
+
var _tempEuler = new Euler();
|
|
740
|
+
var _alignVector = new Vector3(0, 1, 0);
|
|
741
|
+
var _zeroVector = new Vector3(0, 0, 0);
|
|
742
|
+
var _lookAtMatrix = new Matrix4();
|
|
743
|
+
var _tempQuaternion2 = new Quaternion();
|
|
744
|
+
var _identityQuaternion = new Quaternion();
|
|
745
|
+
var _dirVector = new Vector3();
|
|
746
|
+
var _tempMatrix = new Matrix4();
|
|
747
|
+
var _unitX = new Vector3(1, 0, 0);
|
|
748
|
+
var _unitY = new Vector3(0, 1, 0);
|
|
749
|
+
var _unitZ = new Vector3(0, 0, 1);
|
|
750
|
+
var _v1 = new Vector3();
|
|
751
|
+
var _v2 = new Vector3();
|
|
752
|
+
var _v3 = new Vector3();
|
|
753
|
+
function calculateBoundingBoxCenter(object) {
|
|
754
|
+
const box = new Box3();
|
|
755
|
+
object.traverse((child) => {
|
|
756
|
+
if (child.isMesh && child.geometry) {
|
|
757
|
+
child.geometry.computeBoundingBox();
|
|
758
|
+
box.expandByObject(child);
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
if (box.isEmpty()) {
|
|
762
|
+
return object.getWorldPosition(new Vector3());
|
|
763
|
+
}
|
|
764
|
+
const center = new Vector3();
|
|
765
|
+
box.getCenter(center);
|
|
766
|
+
return center;
|
|
767
|
+
}
|
|
768
|
+
var TransformControlsRoot = class extends Object3D {
|
|
769
|
+
constructor(controls) {
|
|
770
|
+
super();
|
|
771
|
+
this.isTransformControlsRoot = true;
|
|
772
|
+
this.controls = controls;
|
|
773
|
+
this.visible = false;
|
|
774
|
+
}
|
|
775
|
+
// updateMatrixWorld updates key transformation variables
|
|
776
|
+
updateMatrixWorld(force) {
|
|
777
|
+
const controls = this.controls;
|
|
778
|
+
if (controls.object !== void 0) {
|
|
779
|
+
controls.object.updateMatrixWorld();
|
|
780
|
+
if (controls.object.parent === null) {
|
|
781
|
+
console.error(
|
|
782
|
+
"TransformControls: The attached 3D object must be a part of the scene graph."
|
|
783
|
+
);
|
|
784
|
+
} else {
|
|
785
|
+
controls.object.parent.matrixWorld.decompose(
|
|
786
|
+
controls._parentPosition,
|
|
787
|
+
controls._parentQuaternion,
|
|
788
|
+
controls._parentScale
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
const boundingBoxCenter = calculateBoundingBoxCenter(controls.object);
|
|
792
|
+
controls.worldPosition.copy(boundingBoxCenter);
|
|
793
|
+
controls.object.matrixWorld.decompose(
|
|
794
|
+
controls._tempPosition,
|
|
795
|
+
// Use temporary variable for position
|
|
796
|
+
controls.worldQuaternion,
|
|
797
|
+
controls._worldScale
|
|
798
|
+
);
|
|
799
|
+
controls._parentQuaternionInv.copy(controls._parentQuaternion).invert();
|
|
800
|
+
controls._worldQuaternionInv.copy(controls.worldQuaternion).invert();
|
|
801
|
+
}
|
|
802
|
+
controls.camera.updateMatrixWorld();
|
|
803
|
+
controls.camera.matrixWorld.decompose(
|
|
804
|
+
controls.cameraPosition,
|
|
805
|
+
controls.cameraQuaternion,
|
|
806
|
+
controls._cameraScale
|
|
807
|
+
);
|
|
808
|
+
if (controls.camera.isOrthographicCamera) {
|
|
809
|
+
controls.eye.copy(controls.cameraPosition).sub(controls.worldPosition).normalize();
|
|
810
|
+
} else {
|
|
811
|
+
controls.eye.copy(controls.cameraPosition).sub(controls.worldPosition).normalize();
|
|
812
|
+
}
|
|
813
|
+
super.updateMatrixWorld(force);
|
|
814
|
+
}
|
|
815
|
+
dispose() {
|
|
816
|
+
this.traverse(function(child) {
|
|
817
|
+
if (child.geometry) child.geometry.dispose();
|
|
818
|
+
if (child.material) child.material.dispose();
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
};
|
|
822
|
+
var TransformControlsGizmo = class extends Object3D {
|
|
823
|
+
constructor() {
|
|
824
|
+
super();
|
|
825
|
+
this.isTransformControlsGizmo = true;
|
|
826
|
+
this.type = "TransformControlsGizmo";
|
|
827
|
+
const gizmoMaterial = new MeshBasicMaterial({
|
|
828
|
+
depthTest: false,
|
|
829
|
+
depthWrite: false,
|
|
830
|
+
fog: false,
|
|
831
|
+
toneMapped: false,
|
|
832
|
+
transparent: true
|
|
833
|
+
});
|
|
834
|
+
const gizmoLineMaterial = new LineBasicMaterial({
|
|
835
|
+
depthTest: false,
|
|
836
|
+
depthWrite: false,
|
|
837
|
+
fog: false,
|
|
838
|
+
toneMapped: false,
|
|
839
|
+
transparent: true
|
|
840
|
+
});
|
|
841
|
+
const matInvisible = gizmoMaterial.clone();
|
|
842
|
+
matInvisible.opacity = 0.15;
|
|
843
|
+
const matHelper = gizmoLineMaterial.clone();
|
|
844
|
+
matHelper.opacity = 0.5;
|
|
845
|
+
const matRed = gizmoMaterial.clone();
|
|
846
|
+
matRed.color.setHex(15549272);
|
|
847
|
+
const matGreen = gizmoMaterial.clone();
|
|
848
|
+
matGreen.color.setHex(8571929);
|
|
849
|
+
const matBlue = gizmoMaterial.clone();
|
|
850
|
+
matBlue.color.setHex(3245547);
|
|
851
|
+
const matRedTransparent = gizmoMaterial.clone();
|
|
852
|
+
matRedTransparent.color.setHex(15549272);
|
|
853
|
+
matRedTransparent.opacity = 0.5;
|
|
854
|
+
const matGreenTransparent = gizmoMaterial.clone();
|
|
855
|
+
matGreenTransparent.color.setHex(8571929);
|
|
856
|
+
matGreenTransparent.opacity = 0.5;
|
|
857
|
+
const matBlueTransparent = gizmoMaterial.clone();
|
|
858
|
+
matBlueTransparent.color.setHex(3245547);
|
|
859
|
+
matBlueTransparent.opacity = 0.5;
|
|
860
|
+
const matWhiteTransparent = gizmoMaterial.clone();
|
|
861
|
+
matWhiteTransparent.opacity = 0.25;
|
|
862
|
+
const matYellowTransparent = gizmoMaterial.clone();
|
|
863
|
+
matYellowTransparent.color.setHex(16776960);
|
|
864
|
+
matYellowTransparent.opacity = 0.25;
|
|
865
|
+
const matYellow = gizmoMaterial.clone();
|
|
866
|
+
matYellow.color.setHex(16776960);
|
|
867
|
+
const matGray = gizmoMaterial.clone();
|
|
868
|
+
matGray.color.setHex(7895160);
|
|
869
|
+
const arrowGeometry = new CylinderGeometry(0, 0.04, 0.1, 12);
|
|
870
|
+
arrowGeometry.translate(0, 0.05, 0);
|
|
871
|
+
const scaleHandleGeometry = new BoxGeometry(0.08, 0.08, 0.08);
|
|
872
|
+
scaleHandleGeometry.translate(0, 0.04, 0);
|
|
873
|
+
const lineGeometry = new BufferGeometry();
|
|
874
|
+
lineGeometry.setAttribute(
|
|
875
|
+
"position",
|
|
876
|
+
new Float32BufferAttribute([0, 0, 0, 1, 0, 0], 3)
|
|
877
|
+
);
|
|
878
|
+
const lineGeometry2 = new CylinderGeometry(0.02, 0.02, 0.5, 3);
|
|
879
|
+
lineGeometry2.translate(0, 0.25, 0);
|
|
880
|
+
function CircleGeometry(radius, arc) {
|
|
881
|
+
const geometry = new TorusGeometry(radius, 0.02, 3, 64, arc * Math.PI * 2);
|
|
882
|
+
geometry.rotateY(Math.PI / 2);
|
|
883
|
+
geometry.rotateX(Math.PI / 2);
|
|
884
|
+
return geometry;
|
|
885
|
+
}
|
|
886
|
+
function TranslateHelperGeometry() {
|
|
887
|
+
const geometry = new BufferGeometry();
|
|
888
|
+
geometry.setAttribute(
|
|
889
|
+
"position",
|
|
890
|
+
new Float32BufferAttribute([0, 0, 0, 1, 1, 1], 3)
|
|
891
|
+
);
|
|
892
|
+
return geometry;
|
|
893
|
+
}
|
|
894
|
+
const gizmoTranslate = {
|
|
895
|
+
X: [
|
|
896
|
+
[new Mesh(arrowGeometry, matRed), [0.5, 0, 0], [0, 0, -Math.PI / 2]],
|
|
897
|
+
[new Mesh(lineGeometry2, matRed), [0, 0, 0], [0, 0, -Math.PI / 2]]
|
|
898
|
+
],
|
|
899
|
+
Y: [
|
|
900
|
+
[new Mesh(arrowGeometry, matGreen), [0, 0.5, 0]],
|
|
901
|
+
[new Mesh(lineGeometry2, matGreen)]
|
|
902
|
+
],
|
|
903
|
+
Z: [
|
|
904
|
+
[new Mesh(arrowGeometry, matBlue), [0, 0, 0.5], [Math.PI / 2, 0, 0]],
|
|
905
|
+
[new Mesh(lineGeometry2, matBlue), null, [Math.PI / 2, 0, 0]]
|
|
906
|
+
]
|
|
907
|
+
};
|
|
908
|
+
const pickerTranslate = {
|
|
909
|
+
X: [
|
|
910
|
+
[
|
|
911
|
+
new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible),
|
|
912
|
+
[0.3, 0, 0],
|
|
913
|
+
[0, 0, -Math.PI / 2]
|
|
914
|
+
],
|
|
915
|
+
[
|
|
916
|
+
new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible),
|
|
917
|
+
[-0.3, 0, 0],
|
|
918
|
+
[0, 0, Math.PI / 2]
|
|
919
|
+
]
|
|
920
|
+
],
|
|
921
|
+
Y: [
|
|
922
|
+
[
|
|
923
|
+
new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible),
|
|
924
|
+
[0, 0.3, 0]
|
|
925
|
+
],
|
|
926
|
+
[
|
|
927
|
+
new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible),
|
|
928
|
+
[0, -0.3, 0],
|
|
929
|
+
[0, 0, Math.PI]
|
|
930
|
+
]
|
|
931
|
+
],
|
|
932
|
+
Z: [
|
|
933
|
+
[
|
|
934
|
+
new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible),
|
|
935
|
+
[0, 0, 0.3],
|
|
936
|
+
[Math.PI / 2, 0, 0]
|
|
937
|
+
],
|
|
938
|
+
[
|
|
939
|
+
new Mesh(new CylinderGeometry(0.2, 0, 0.6, 4), matInvisible),
|
|
940
|
+
[0, 0, -0.3],
|
|
941
|
+
[-Math.PI / 2, 0, 0]
|
|
942
|
+
]
|
|
943
|
+
]
|
|
944
|
+
};
|
|
945
|
+
const helperTranslate = {
|
|
946
|
+
START: [
|
|
947
|
+
[
|
|
948
|
+
new Mesh(new OctahedronGeometry(0.01, 2), matHelper),
|
|
949
|
+
null,
|
|
950
|
+
null,
|
|
951
|
+
null,
|
|
952
|
+
"helper"
|
|
953
|
+
]
|
|
954
|
+
],
|
|
955
|
+
END: [
|
|
956
|
+
[
|
|
957
|
+
new Mesh(new OctahedronGeometry(0.01, 2), matHelper),
|
|
958
|
+
null,
|
|
959
|
+
null,
|
|
960
|
+
null,
|
|
961
|
+
"helper"
|
|
962
|
+
]
|
|
963
|
+
],
|
|
964
|
+
DELTA: [
|
|
965
|
+
[
|
|
966
|
+
new Line(TranslateHelperGeometry(), matHelper),
|
|
967
|
+
null,
|
|
968
|
+
null,
|
|
969
|
+
null,
|
|
970
|
+
"helper"
|
|
971
|
+
]
|
|
972
|
+
]
|
|
973
|
+
};
|
|
974
|
+
const gizmoRotate = {
|
|
975
|
+
X: [[new Mesh(CircleGeometry(0.45, 0.25), matRed)]],
|
|
976
|
+
Y: [
|
|
977
|
+
[
|
|
978
|
+
new Mesh(CircleGeometry(0.45, 0.25), matGreen),
|
|
979
|
+
null,
|
|
980
|
+
[0, 0, -Math.PI / 2]
|
|
981
|
+
]
|
|
982
|
+
],
|
|
983
|
+
Z: [
|
|
984
|
+
[
|
|
985
|
+
new Mesh(CircleGeometry(0.45, 0.25), matBlue),
|
|
986
|
+
null,
|
|
987
|
+
[0, Math.PI / 2, 0]
|
|
988
|
+
]
|
|
989
|
+
]
|
|
990
|
+
};
|
|
991
|
+
const helperRotate = {
|
|
992
|
+
AXIS: [],
|
|
993
|
+
START: [
|
|
994
|
+
[new Line(lineGeometry.clone(), matHelper), null, null, null, "helper"]
|
|
995
|
+
],
|
|
996
|
+
END: [
|
|
997
|
+
[new Line(lineGeometry.clone(), matHelper), null, null, null, "helper"]
|
|
998
|
+
],
|
|
999
|
+
ARC: [
|
|
1000
|
+
[new Line(new BufferGeometry(), matHelper), null, null, null, "helper"]
|
|
1001
|
+
]
|
|
1002
|
+
};
|
|
1003
|
+
const pickerRotate = {
|
|
1004
|
+
X: [[new Mesh(CircleGeometry(0.45, 0.25), matRed)]],
|
|
1005
|
+
Y: [
|
|
1006
|
+
[
|
|
1007
|
+
new Mesh(CircleGeometry(0.45, 0.25), matGreen),
|
|
1008
|
+
null,
|
|
1009
|
+
[0, 0, -Math.PI / 2]
|
|
1010
|
+
]
|
|
1011
|
+
],
|
|
1012
|
+
Z: [
|
|
1013
|
+
[
|
|
1014
|
+
new Mesh(CircleGeometry(0.45, 0.25), matBlue),
|
|
1015
|
+
null,
|
|
1016
|
+
[0, Math.PI / 2, 0]
|
|
1017
|
+
]
|
|
1018
|
+
]
|
|
1019
|
+
};
|
|
1020
|
+
const gizmoScale = {
|
|
1021
|
+
X: [
|
|
1022
|
+
[
|
|
1023
|
+
new Mesh(scaleHandleGeometry, matRed),
|
|
1024
|
+
[0.7, 0, 0],
|
|
1025
|
+
[0, 0, -Math.PI / 2]
|
|
1026
|
+
]
|
|
1027
|
+
],
|
|
1028
|
+
Y: [[new Mesh(scaleHandleGeometry, matGreen), [0, 0.7, 0]]],
|
|
1029
|
+
Z: [
|
|
1030
|
+
[
|
|
1031
|
+
new Mesh(scaleHandleGeometry, matBlue),
|
|
1032
|
+
[0, 0, 0.7],
|
|
1033
|
+
[Math.PI / 2, 0, 0]
|
|
1034
|
+
]
|
|
1035
|
+
]
|
|
1036
|
+
};
|
|
1037
|
+
const pickerScale = {
|
|
1038
|
+
X: [
|
|
1039
|
+
[
|
|
1040
|
+
new Mesh(new BoxGeometry(0.2, 0.2, 0.2), matInvisible),
|
|
1041
|
+
[0.7, 0, 0],
|
|
1042
|
+
[0, 0, -Math.PI / 2]
|
|
1043
|
+
]
|
|
1044
|
+
],
|
|
1045
|
+
Y: [
|
|
1046
|
+
[new Mesh(new BoxGeometry(0.2, 0.2, 0.2), matInvisible), [0, 0.7, 0]]
|
|
1047
|
+
],
|
|
1048
|
+
Z: [
|
|
1049
|
+
[
|
|
1050
|
+
new Mesh(new BoxGeometry(0.2, 0.2, 0.2), matInvisible),
|
|
1051
|
+
[0, 0, 0.7],
|
|
1052
|
+
[Math.PI / 2, 0, 0]
|
|
1053
|
+
]
|
|
1054
|
+
]
|
|
1055
|
+
};
|
|
1056
|
+
const helperScale = {
|
|
1057
|
+
X: [],
|
|
1058
|
+
Y: [],
|
|
1059
|
+
Z: []
|
|
1060
|
+
};
|
|
1061
|
+
function setupGizmo(gizmoMap) {
|
|
1062
|
+
const gizmo = new Object3D();
|
|
1063
|
+
for (const name in gizmoMap) {
|
|
1064
|
+
for (let i = gizmoMap[name].length; i--; ) {
|
|
1065
|
+
const object = gizmoMap[name][i][0].clone();
|
|
1066
|
+
object.userData.type = "gizmo";
|
|
1067
|
+
const position = gizmoMap[name][i][1];
|
|
1068
|
+
const rotation = gizmoMap[name][i][2];
|
|
1069
|
+
const scale = gizmoMap[name][i][3];
|
|
1070
|
+
const tag = gizmoMap[name][i][4];
|
|
1071
|
+
object.name = name;
|
|
1072
|
+
object.tag = tag;
|
|
1073
|
+
if (position) {
|
|
1074
|
+
object.position.set(position[0], position[1], position[2]);
|
|
1075
|
+
}
|
|
1076
|
+
if (rotation) {
|
|
1077
|
+
object.rotation.set(rotation[0], rotation[1], rotation[2]);
|
|
1078
|
+
}
|
|
1079
|
+
if (scale) {
|
|
1080
|
+
object.scale.set(scale[0], scale[1], scale[2]);
|
|
1081
|
+
}
|
|
1082
|
+
object.updateMatrix();
|
|
1083
|
+
const tempGeometry = object.geometry.clone();
|
|
1084
|
+
tempGeometry.applyMatrix4(object.matrix);
|
|
1085
|
+
object.geometry = tempGeometry;
|
|
1086
|
+
object.renderOrder = Infinity;
|
|
1087
|
+
object.position.set(0, 0, 0);
|
|
1088
|
+
object.rotation.set(0, 0, 0);
|
|
1089
|
+
object.scale.set(1, 1, 1);
|
|
1090
|
+
gizmo.add(object);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
return gizmo;
|
|
1094
|
+
}
|
|
1095
|
+
this.gizmo = {};
|
|
1096
|
+
this.picker = {};
|
|
1097
|
+
this.helper = {};
|
|
1098
|
+
this.add(this.gizmo["translate"] = setupGizmo(gizmoTranslate));
|
|
1099
|
+
this.add(this.gizmo["rotate"] = setupGizmo(gizmoRotate));
|
|
1100
|
+
this.add(this.gizmo["scale"] = setupGizmo(gizmoScale));
|
|
1101
|
+
this.add(this.picker["translate"] = setupGizmo(pickerTranslate));
|
|
1102
|
+
this.add(this.picker["rotate"] = setupGizmo(pickerRotate));
|
|
1103
|
+
this.add(this.picker["scale"] = setupGizmo(pickerScale));
|
|
1104
|
+
this.add(this.helper["translate"] = setupGizmo(helperTranslate));
|
|
1105
|
+
this.add(this.helper["rotate"] = setupGizmo(helperRotate));
|
|
1106
|
+
this.add(this.helper["scale"] = setupGizmo(helperScale));
|
|
1107
|
+
this.picker["translate"].visible = false;
|
|
1108
|
+
this.picker["rotate"].visible = false;
|
|
1109
|
+
this.picker["scale"].visible = false;
|
|
1110
|
+
}
|
|
1111
|
+
// updateMatrixWorld will update transformations and appearance of individual handles
|
|
1112
|
+
updateMatrixWorld(force) {
|
|
1113
|
+
const space = this.mode === "scale" ? "local" : this.space;
|
|
1114
|
+
const quaternion = space === "local" ? this.worldQuaternion : _identityQuaternion;
|
|
1115
|
+
if (this.mode === "all") {
|
|
1116
|
+
this.gizmo["translate"].visible = true;
|
|
1117
|
+
this.gizmo["rotate"].visible = true;
|
|
1118
|
+
this.gizmo["scale"].visible = true;
|
|
1119
|
+
this.helper["translate"].visible = true;
|
|
1120
|
+
this.helper["rotate"].visible = true;
|
|
1121
|
+
this.helper["scale"].visible = false;
|
|
1122
|
+
} else {
|
|
1123
|
+
this.gizmo["translate"].visible = this.mode === "translate";
|
|
1124
|
+
this.gizmo["rotate"].visible = this.mode === "rotate";
|
|
1125
|
+
this.gizmo["scale"].visible = this.mode === "scale";
|
|
1126
|
+
this.helper["translate"].visible = this.mode === "translate";
|
|
1127
|
+
this.helper["rotate"].visible = this.mode === "rotate";
|
|
1128
|
+
this.helper["scale"].visible = this.mode === "scale";
|
|
1129
|
+
}
|
|
1130
|
+
let handles = [];
|
|
1131
|
+
if (this.mode === "all") {
|
|
1132
|
+
handles = handles.concat(this.picker["translate"].children);
|
|
1133
|
+
handles = handles.concat(this.picker["rotate"].children);
|
|
1134
|
+
handles = handles.concat(this.picker["scale"].children);
|
|
1135
|
+
handles = handles.concat(this.gizmo["translate"].children);
|
|
1136
|
+
handles = handles.concat(this.gizmo["rotate"].children);
|
|
1137
|
+
handles = handles.concat(this.gizmo["scale"].children);
|
|
1138
|
+
handles = handles.concat(this.helper["translate"].children);
|
|
1139
|
+
handles = handles.concat(this.helper["rotate"].children);
|
|
1140
|
+
} else {
|
|
1141
|
+
handles = handles.concat(this.picker[this.mode].children);
|
|
1142
|
+
handles = handles.concat(this.gizmo[this.mode].children);
|
|
1143
|
+
handles = handles.concat(this.helper[this.mode].children);
|
|
1144
|
+
}
|
|
1145
|
+
for (let i = 0; i < handles.length; i++) {
|
|
1146
|
+
const handle = handles[i];
|
|
1147
|
+
handle.visible = true;
|
|
1148
|
+
handle.rotation.set(0, 0, 0);
|
|
1149
|
+
handle.position.copy(this.worldPosition);
|
|
1150
|
+
let factor;
|
|
1151
|
+
if (this.camera.isOrthographicCamera) {
|
|
1152
|
+
factor = (this.camera.top - this.camera.bottom) / this.camera.zoom;
|
|
1153
|
+
} else {
|
|
1154
|
+
factor = this.worldPosition.distanceTo(this.cameraPosition) * Math.min(
|
|
1155
|
+
1.9 * Math.tan(Math.PI * this.camera.fov / 360) / this.camera.zoom,
|
|
1156
|
+
7
|
|
1157
|
+
);
|
|
1158
|
+
}
|
|
1159
|
+
handle.scale.set(1, 1, 1).multiplyScalar(factor * this.size / 4);
|
|
1160
|
+
if (handle.tag === "helper") {
|
|
1161
|
+
handle.visible = false;
|
|
1162
|
+
if (handle.name === "AXIS") {
|
|
1163
|
+
handle.visible = !!this.axis;
|
|
1164
|
+
if (this.axis === "X") {
|
|
1165
|
+
_tempQuaternion.setFromEuler(_tempEuler.set(0, 0, 0));
|
|
1166
|
+
handle.quaternion.copy(quaternion).multiply(_tempQuaternion);
|
|
1167
|
+
if (Math.abs(
|
|
1168
|
+
_alignVector.copy(_unitX).applyQuaternion(quaternion).dot(this.eye)
|
|
1169
|
+
) > 0.9) {
|
|
1170
|
+
handle.visible = false;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
if (this.axis === "Y") {
|
|
1174
|
+
_tempQuaternion.setFromEuler(_tempEuler.set(0, 0, Math.PI / 2));
|
|
1175
|
+
handle.quaternion.copy(quaternion).multiply(_tempQuaternion);
|
|
1176
|
+
if (Math.abs(
|
|
1177
|
+
_alignVector.copy(_unitY).applyQuaternion(quaternion).dot(this.eye)
|
|
1178
|
+
) > 0.9) {
|
|
1179
|
+
handle.visible = false;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
if (this.axis === "Z") {
|
|
1183
|
+
_tempQuaternion.setFromEuler(_tempEuler.set(0, Math.PI / 2, 0));
|
|
1184
|
+
handle.quaternion.copy(quaternion).multiply(_tempQuaternion);
|
|
1185
|
+
if (Math.abs(
|
|
1186
|
+
_alignVector.copy(_unitZ).applyQuaternion(quaternion).dot(this.eye)
|
|
1187
|
+
) > 0.9) {
|
|
1188
|
+
handle.visible = false;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
if (this.axis === "XYZE") {
|
|
1192
|
+
_tempQuaternion.setFromEuler(_tempEuler.set(0, Math.PI / 2, 0));
|
|
1193
|
+
_alignVector.copy(this.rotationAxis);
|
|
1194
|
+
handle.quaternion.setFromRotationMatrix(
|
|
1195
|
+
_lookAtMatrix.lookAt(_zeroVector, _alignVector, _unitY)
|
|
1196
|
+
);
|
|
1197
|
+
handle.quaternion.multiply(_tempQuaternion);
|
|
1198
|
+
handle.visible = this.dragging;
|
|
1199
|
+
}
|
|
1200
|
+
if (this.axis === "E") {
|
|
1201
|
+
handle.visible = false;
|
|
1202
|
+
}
|
|
1203
|
+
} else if (handle.name === "START") {
|
|
1204
|
+
if (this.mode === "rotate" || this.mode === "all") {
|
|
1205
|
+
handle.position.copy(this.worldPosition);
|
|
1206
|
+
const isRotating = this.mode === "rotate" || this.mode === "all" && this.activeMode === "rotate";
|
|
1207
|
+
handle.visible = this.dragging && isRotating;
|
|
1208
|
+
if (handle.visible) {
|
|
1209
|
+
const rotSpace = this.space;
|
|
1210
|
+
if (rotSpace === "local") {
|
|
1211
|
+
handle.quaternion.copy(this.worldQuaternionStart);
|
|
1212
|
+
} else {
|
|
1213
|
+
handle.quaternion.copy(_identityQuaternion);
|
|
1214
|
+
}
|
|
1215
|
+
let rotAxis = new Vector3();
|
|
1216
|
+
if (this.axis === "X" || this.axis === "Y" || this.axis === "Z") {
|
|
1217
|
+
rotAxis.copy(_unit[this.axis]);
|
|
1218
|
+
} else if (this.axis === "E" || this.axis === "XYZE") {
|
|
1219
|
+
rotAxis.copy(this.rotationAxis);
|
|
1220
|
+
if (rotSpace === "local") {
|
|
1221
|
+
rotAxis.applyQuaternion(
|
|
1222
|
+
this.worldQuaternionStart.clone().invert()
|
|
1223
|
+
);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
let startPoint = this.pointStart.clone();
|
|
1227
|
+
if (rotSpace === "local") {
|
|
1228
|
+
startPoint.applyQuaternion(
|
|
1229
|
+
this.worldQuaternionStart.clone().invert()
|
|
1230
|
+
);
|
|
1231
|
+
}
|
|
1232
|
+
const dotProduct = startPoint.dot(rotAxis);
|
|
1233
|
+
startPoint.sub(rotAxis.clone().multiplyScalar(dotProduct));
|
|
1234
|
+
startPoint.normalize();
|
|
1235
|
+
startPoint.multiplyScalar(0.45);
|
|
1236
|
+
const startLineGeometry = new BufferGeometry();
|
|
1237
|
+
startLineGeometry.setAttribute(
|
|
1238
|
+
"position",
|
|
1239
|
+
new Float32BufferAttribute(
|
|
1240
|
+
[0, 0, 0, startPoint.x, startPoint.y, startPoint.z],
|
|
1241
|
+
3
|
|
1242
|
+
)
|
|
1243
|
+
);
|
|
1244
|
+
handle.geometry.dispose();
|
|
1245
|
+
handle.geometry = startLineGeometry;
|
|
1246
|
+
}
|
|
1247
|
+
} else {
|
|
1248
|
+
handle.position.copy(this.worldPositionStart);
|
|
1249
|
+
handle.visible = this.dragging && this.mode === "translate";
|
|
1250
|
+
}
|
|
1251
|
+
} else if (handle.name === "ARC") {
|
|
1252
|
+
const isRotating = this.mode === "rotate" || this.mode === "all" && this.activeMode === "rotate";
|
|
1253
|
+
handle.visible = this.dragging && isRotating;
|
|
1254
|
+
if (handle.visible && this.rotationAngle !== 0) {
|
|
1255
|
+
handle.position.copy(this.worldPosition);
|
|
1256
|
+
const rotSpace = this.space;
|
|
1257
|
+
if (rotSpace === "local") {
|
|
1258
|
+
handle.quaternion.copy(this.worldQuaternionStart);
|
|
1259
|
+
} else {
|
|
1260
|
+
handle.quaternion.copy(_identityQuaternion);
|
|
1261
|
+
}
|
|
1262
|
+
const arcRadius = 0.45;
|
|
1263
|
+
const segments = Math.max(
|
|
1264
|
+
8,
|
|
1265
|
+
Math.floor(Math.abs(this.rotationAngle) * 50)
|
|
1266
|
+
);
|
|
1267
|
+
const arcPoints = [];
|
|
1268
|
+
let rotAxis = new Vector3();
|
|
1269
|
+
if (this.axis === "X" || this.axis === "Y" || this.axis === "Z") {
|
|
1270
|
+
rotAxis.copy(_unit[this.axis]);
|
|
1271
|
+
if (rotSpace !== "local") {
|
|
1272
|
+
}
|
|
1273
|
+
} else if (this.axis === "E" || this.axis === "XYZE") {
|
|
1274
|
+
rotAxis.copy(this.rotationAxis);
|
|
1275
|
+
if (rotSpace === "local") {
|
|
1276
|
+
rotAxis.applyQuaternion(
|
|
1277
|
+
this.worldQuaternionStart.clone().invert()
|
|
1278
|
+
);
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
let startDir = this.pointStart.clone();
|
|
1282
|
+
if (rotSpace === "local") {
|
|
1283
|
+
startDir.applyQuaternion(
|
|
1284
|
+
this.worldQuaternionStart.clone().invert()
|
|
1285
|
+
);
|
|
1286
|
+
}
|
|
1287
|
+
const dotProduct = startDir.dot(rotAxis);
|
|
1288
|
+
startDir.sub(rotAxis.clone().multiplyScalar(dotProduct));
|
|
1289
|
+
startDir.normalize();
|
|
1290
|
+
for (let j = 0; j <= segments; j++) {
|
|
1291
|
+
const angle = this.rotationAngle * j / segments;
|
|
1292
|
+
const point = startDir.clone();
|
|
1293
|
+
const arcQuat = new Quaternion().setFromAxisAngle(rotAxis, angle);
|
|
1294
|
+
point.applyQuaternion(arcQuat);
|
|
1295
|
+
point.multiplyScalar(arcRadius);
|
|
1296
|
+
arcPoints.push(point.x, point.y, point.z);
|
|
1297
|
+
}
|
|
1298
|
+
const arcGeometry = new BufferGeometry();
|
|
1299
|
+
arcGeometry.setAttribute(
|
|
1300
|
+
"position",
|
|
1301
|
+
new Float32BufferAttribute(arcPoints, 3)
|
|
1302
|
+
);
|
|
1303
|
+
handle.geometry.dispose();
|
|
1304
|
+
handle.geometry = arcGeometry;
|
|
1305
|
+
}
|
|
1306
|
+
} else if (handle.name === "END") {
|
|
1307
|
+
if (this.mode === "rotate" || this.mode === "all") {
|
|
1308
|
+
handle.position.copy(this.worldPosition);
|
|
1309
|
+
const isRotating = this.mode === "rotate" || this.mode === "all" && this.activeMode === "rotate";
|
|
1310
|
+
handle.visible = this.dragging && isRotating;
|
|
1311
|
+
if (handle.visible) {
|
|
1312
|
+
const rotSpace = this.space;
|
|
1313
|
+
if (rotSpace === "local") {
|
|
1314
|
+
handle.quaternion.copy(this.worldQuaternionStart);
|
|
1315
|
+
} else {
|
|
1316
|
+
handle.quaternion.copy(_identityQuaternion);
|
|
1317
|
+
}
|
|
1318
|
+
const endLineGeometry = new BufferGeometry();
|
|
1319
|
+
let rotAxis = new Vector3();
|
|
1320
|
+
if (this.axis === "X" || this.axis === "Y" || this.axis === "Z") {
|
|
1321
|
+
rotAxis.copy(_unit[this.axis]);
|
|
1322
|
+
} else if (this.axis === "E" || this.axis === "XYZE") {
|
|
1323
|
+
rotAxis.copy(this.rotationAxis);
|
|
1324
|
+
if (rotSpace === "local") {
|
|
1325
|
+
rotAxis.applyQuaternion(
|
|
1326
|
+
this.worldQuaternionStart.clone().invert()
|
|
1327
|
+
);
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
let startDir = this.pointStart.clone();
|
|
1331
|
+
if (rotSpace === "local") {
|
|
1332
|
+
startDir.applyQuaternion(
|
|
1333
|
+
this.worldQuaternionStart.clone().invert()
|
|
1334
|
+
);
|
|
1335
|
+
}
|
|
1336
|
+
const dotProduct = startDir.dot(rotAxis);
|
|
1337
|
+
startDir.sub(rotAxis.clone().multiplyScalar(dotProduct));
|
|
1338
|
+
startDir.normalize();
|
|
1339
|
+
const endPoint = startDir.clone();
|
|
1340
|
+
const arcQuat = new Quaternion().setFromAxisAngle(
|
|
1341
|
+
rotAxis,
|
|
1342
|
+
this.rotationAngle
|
|
1343
|
+
);
|
|
1344
|
+
endPoint.applyQuaternion(arcQuat);
|
|
1345
|
+
endPoint.multiplyScalar(0.45);
|
|
1346
|
+
endLineGeometry.setAttribute(
|
|
1347
|
+
"position",
|
|
1348
|
+
new Float32BufferAttribute(
|
|
1349
|
+
[0, 0, 0, endPoint.x, endPoint.y, endPoint.z],
|
|
1350
|
+
3
|
|
1351
|
+
)
|
|
1352
|
+
);
|
|
1353
|
+
handle.geometry.dispose();
|
|
1354
|
+
handle.geometry = endLineGeometry;
|
|
1355
|
+
}
|
|
1356
|
+
} else {
|
|
1357
|
+
handle.position.copy(this.worldPosition);
|
|
1358
|
+
handle.visible = false;
|
|
1359
|
+
}
|
|
1360
|
+
} else if (handle.name === "DELTA") {
|
|
1361
|
+
handle.position.copy(this.worldPositionStart);
|
|
1362
|
+
handle.quaternion.copy(this.worldQuaternionStart);
|
|
1363
|
+
_tempVector.set(1e-10, 1e-10, 1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1);
|
|
1364
|
+
_tempVector.applyQuaternion(
|
|
1365
|
+
this.worldQuaternionStart.clone().invert()
|
|
1366
|
+
);
|
|
1367
|
+
handle.scale.copy(_tempVector);
|
|
1368
|
+
handle.visible = this.dragging;
|
|
1369
|
+
} else {
|
|
1370
|
+
handle.quaternion.copy(quaternion);
|
|
1371
|
+
if (this.dragging) {
|
|
1372
|
+
handle.position.copy(this.worldPositionStart);
|
|
1373
|
+
} else {
|
|
1374
|
+
handle.position.copy(this.worldPosition);
|
|
1375
|
+
}
|
|
1376
|
+
if (this.axis) {
|
|
1377
|
+
handle.visible = this.axis.search(handle.name) !== -1;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
continue;
|
|
1381
|
+
}
|
|
1382
|
+
handle.quaternion.copy(quaternion);
|
|
1383
|
+
if (this.mode === "translate" || this.mode === "scale") {
|
|
1384
|
+
const AXIS_HIDE_THRESHOLD = 0.99;
|
|
1385
|
+
const PLANE_HIDE_THRESHOLD = 0.2;
|
|
1386
|
+
if (handle.name === "X") {
|
|
1387
|
+
if (Math.abs(
|
|
1388
|
+
_alignVector.copy(_unitX).applyQuaternion(quaternion).dot(this.eye)
|
|
1389
|
+
) > AXIS_HIDE_THRESHOLD) {
|
|
1390
|
+
handle.scale.set(1e-10, 1e-10, 1e-10);
|
|
1391
|
+
handle.visible = false;
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
if (handle.name === "Y") {
|
|
1395
|
+
if (Math.abs(
|
|
1396
|
+
_alignVector.copy(_unitY).applyQuaternion(quaternion).dot(this.eye)
|
|
1397
|
+
) > AXIS_HIDE_THRESHOLD) {
|
|
1398
|
+
handle.scale.set(1e-10, 1e-10, 1e-10);
|
|
1399
|
+
handle.visible = false;
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
if (handle.name === "Z") {
|
|
1403
|
+
if (Math.abs(
|
|
1404
|
+
_alignVector.copy(_unitZ).applyQuaternion(quaternion).dot(this.eye)
|
|
1405
|
+
) > AXIS_HIDE_THRESHOLD) {
|
|
1406
|
+
handle.scale.set(1e-10, 1e-10, 1e-10);
|
|
1407
|
+
handle.visible = false;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
if (handle.name === "XY") {
|
|
1411
|
+
if (Math.abs(
|
|
1412
|
+
_alignVector.copy(_unitZ).applyQuaternion(quaternion).dot(this.eye)
|
|
1413
|
+
) < PLANE_HIDE_THRESHOLD) {
|
|
1414
|
+
handle.scale.set(1e-10, 1e-10, 1e-10);
|
|
1415
|
+
handle.visible = false;
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
if (handle.name === "YZ") {
|
|
1419
|
+
if (Math.abs(
|
|
1420
|
+
_alignVector.copy(_unitX).applyQuaternion(quaternion).dot(this.eye)
|
|
1421
|
+
) < PLANE_HIDE_THRESHOLD) {
|
|
1422
|
+
handle.scale.set(1e-10, 1e-10, 1e-10);
|
|
1423
|
+
handle.visible = false;
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
if (handle.name === "XZ") {
|
|
1427
|
+
if (Math.abs(
|
|
1428
|
+
_alignVector.copy(_unitY).applyQuaternion(quaternion).dot(this.eye)
|
|
1429
|
+
) < PLANE_HIDE_THRESHOLD) {
|
|
1430
|
+
handle.scale.set(1e-10, 1e-10, 1e-10);
|
|
1431
|
+
handle.visible = false;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
} else if (this.mode === "rotate") {
|
|
1435
|
+
_tempQuaternion2.copy(quaternion);
|
|
1436
|
+
_alignVector.copy(this.eye).applyQuaternion(_tempQuaternion.copy(quaternion).invert());
|
|
1437
|
+
if (handle.name.search("E") !== -1) {
|
|
1438
|
+
handle.quaternion.setFromRotationMatrix(
|
|
1439
|
+
_lookAtMatrix.lookAt(this.eye, _zeroVector, _unitY)
|
|
1440
|
+
);
|
|
1441
|
+
}
|
|
1442
|
+
if (handle.name === "X") {
|
|
1443
|
+
_tempQuaternion.setFromAxisAngle(
|
|
1444
|
+
_unitX,
|
|
1445
|
+
Math.atan2(-_alignVector.y, _alignVector.z)
|
|
1446
|
+
);
|
|
1447
|
+
_tempQuaternion.multiplyQuaternions(_tempQuaternion2, _tempQuaternion);
|
|
1448
|
+
handle.quaternion.copy(_tempQuaternion);
|
|
1449
|
+
}
|
|
1450
|
+
if (handle.name === "Y") {
|
|
1451
|
+
_tempQuaternion.setFromAxisAngle(
|
|
1452
|
+
_unitY,
|
|
1453
|
+
Math.atan2(_alignVector.x, _alignVector.z)
|
|
1454
|
+
);
|
|
1455
|
+
_tempQuaternion.multiplyQuaternions(_tempQuaternion2, _tempQuaternion);
|
|
1456
|
+
handle.quaternion.copy(_tempQuaternion);
|
|
1457
|
+
}
|
|
1458
|
+
if (handle.name === "Z") {
|
|
1459
|
+
_tempQuaternion.setFromAxisAngle(
|
|
1460
|
+
_unitZ,
|
|
1461
|
+
Math.atan2(_alignVector.y, _alignVector.x)
|
|
1462
|
+
);
|
|
1463
|
+
_tempQuaternion.multiplyQuaternions(_tempQuaternion2, _tempQuaternion);
|
|
1464
|
+
handle.quaternion.copy(_tempQuaternion);
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
handle.visible = handle.visible && (handle.name.indexOf("X") === -1 || this.showX);
|
|
1468
|
+
handle.visible = handle.visible && (handle.name.indexOf("Y") === -1 || this.showY);
|
|
1469
|
+
handle.visible = handle.visible && (handle.name.indexOf("Z") === -1 || this.showZ);
|
|
1470
|
+
handle.visible = handle.visible && (handle.name.indexOf("E") === -1 || this.showX && this.showY && this.showZ);
|
|
1471
|
+
handle.material._color = handle.material._color || handle.material.color.clone();
|
|
1472
|
+
handle.material._opacity = handle.material._opacity || handle.material.opacity;
|
|
1473
|
+
handle.material.color.copy(handle.material._color);
|
|
1474
|
+
handle.material.opacity = handle.material._opacity;
|
|
1475
|
+
if (this.dragging) {
|
|
1476
|
+
handle.material.opacity = 0.2;
|
|
1477
|
+
}
|
|
1478
|
+
if (this.enabled && this.axis) {
|
|
1479
|
+
if (handle.name === this.axis) {
|
|
1480
|
+
handle.material.color.setHex(16776960);
|
|
1481
|
+
if (!this.dragging) {
|
|
1482
|
+
handle.material.opacity = 1;
|
|
1483
|
+
}
|
|
1484
|
+
} else if (this.axis.split("").some(function(a) {
|
|
1485
|
+
return handle.name === a;
|
|
1486
|
+
})) {
|
|
1487
|
+
handle.material.color.setHex(16776960);
|
|
1488
|
+
if (!this.dragging) {
|
|
1489
|
+
handle.material.opacity = 1;
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
super.updateMatrixWorld(force);
|
|
1495
|
+
}
|
|
1496
|
+
};
|
|
1497
|
+
var TransformControlsPlane = class extends Mesh {
|
|
1498
|
+
constructor() {
|
|
1499
|
+
super(
|
|
1500
|
+
new PlaneGeometry(1e5, 1e5, 2, 2),
|
|
1501
|
+
new MeshBasicMaterial({
|
|
1502
|
+
visible: false,
|
|
1503
|
+
wireframe: true,
|
|
1504
|
+
side: DoubleSide,
|
|
1505
|
+
transparent: true,
|
|
1506
|
+
opacity: 0.1,
|
|
1507
|
+
toneMapped: false
|
|
1508
|
+
})
|
|
1509
|
+
);
|
|
1510
|
+
this.isTransformControlsPlane = true;
|
|
1511
|
+
this.type = "TransformControlsPlane";
|
|
1512
|
+
}
|
|
1513
|
+
updateMatrixWorld(force) {
|
|
1514
|
+
let space = this.space;
|
|
1515
|
+
this.position.copy(this.worldPosition);
|
|
1516
|
+
if (this.mode === "scale") space = "local";
|
|
1517
|
+
_v1.copy(_unitX).applyQuaternion(
|
|
1518
|
+
space === "local" ? this.worldQuaternion : _identityQuaternion
|
|
1519
|
+
);
|
|
1520
|
+
_v2.copy(_unitY).applyQuaternion(
|
|
1521
|
+
space === "local" ? this.worldQuaternion : _identityQuaternion
|
|
1522
|
+
);
|
|
1523
|
+
_v3.copy(_unitZ).applyQuaternion(
|
|
1524
|
+
space === "local" ? this.worldQuaternion : _identityQuaternion
|
|
1525
|
+
);
|
|
1526
|
+
_alignVector.copy(_v2);
|
|
1527
|
+
switch (this.mode) {
|
|
1528
|
+
case "translate":
|
|
1529
|
+
case "scale":
|
|
1530
|
+
switch (this.axis) {
|
|
1531
|
+
case "X":
|
|
1532
|
+
_alignVector.copy(this.eye).cross(_v1);
|
|
1533
|
+
_dirVector.copy(_v1).cross(_alignVector);
|
|
1534
|
+
break;
|
|
1535
|
+
case "Y":
|
|
1536
|
+
_alignVector.copy(this.eye).cross(_v2);
|
|
1537
|
+
_dirVector.copy(_v2).cross(_alignVector);
|
|
1538
|
+
break;
|
|
1539
|
+
case "Z":
|
|
1540
|
+
_alignVector.copy(this.eye).cross(_v3);
|
|
1541
|
+
_dirVector.copy(_v3).cross(_alignVector);
|
|
1542
|
+
break;
|
|
1543
|
+
case "XY":
|
|
1544
|
+
_dirVector.copy(_v3);
|
|
1545
|
+
break;
|
|
1546
|
+
case "YZ":
|
|
1547
|
+
_dirVector.copy(_v1);
|
|
1548
|
+
break;
|
|
1549
|
+
case "XZ":
|
|
1550
|
+
_alignVector.copy(_v3);
|
|
1551
|
+
_dirVector.copy(_v2);
|
|
1552
|
+
break;
|
|
1553
|
+
case "XYZ":
|
|
1554
|
+
case "E":
|
|
1555
|
+
_dirVector.set(0, 0, 0);
|
|
1556
|
+
break;
|
|
1557
|
+
}
|
|
1558
|
+
break;
|
|
1559
|
+
case "rotate":
|
|
1560
|
+
default:
|
|
1561
|
+
_dirVector.set(0, 0, 0);
|
|
1562
|
+
}
|
|
1563
|
+
if (_dirVector.length() === 0) {
|
|
1564
|
+
this.quaternion.copy(this.cameraQuaternion);
|
|
1565
|
+
} else {
|
|
1566
|
+
_tempMatrix.lookAt(_tempVector.set(0, 0, 0), _dirVector, _alignVector);
|
|
1567
|
+
this.quaternion.setFromRotationMatrix(_tempMatrix);
|
|
1568
|
+
}
|
|
1569
|
+
super.updateMatrixWorld(force);
|
|
1570
|
+
}
|
|
1571
|
+
};
|
|
1572
|
+
|
|
1573
|
+
export {
|
|
1574
|
+
TransformControls,
|
|
1575
|
+
calculateBoundingBoxCenter,
|
|
1576
|
+
TransformControlsGizmo,
|
|
1577
|
+
TransformControlsPlane
|
|
1578
|
+
};
|
|
1579
|
+
//# sourceMappingURL=chunk-BJKSICFA.mjs.map
|