@mavonengine/editor 0.0.10 → 0.0.11

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/dist/Editor.mjs CHANGED
@@ -3,1399 +3,15 @@ import i from "@mavonengine/core/Editor/EditorHelper";
3
3
  import a from "@mavonengine/core/Game";
4
4
  import { SCENE_SAVE_PATH as o } from "@mavonengine/core/Plugins/types";
5
5
  import s from "@mavonengine/core/Utils/EventEmitter";
6
- import { AdditiveBlending as c, BoxGeometry as l, BufferGeometry as u, Color as d, Controls as f, CylinderGeometry as p, DoubleSide as m, EdgesGeometry as h, Euler as g, Float32BufferAttribute as _, Group as v, HalfFloatType as y, Line as b, LineBasicMaterial as ee, LineLoop as x, LineSegments as S, Matrix4 as C, Mesh as w, MeshBasicMaterial as te, MeshDepthMaterial as ne, NoBlending as T, Object3D as E, OctahedronGeometry as D, OrthographicCamera as re, PlaneGeometry as ie, Quaternion as O, RGBADepthPacking as ae, Raycaster as oe, ShaderMaterial as k, SphereGeometry as se, TorusGeometry as A, UniformsUtils as ce, Vector2 as j, Vector3 as M, WebGLRenderTarget as N } from "three";
7
- import { lightType as le, primitiveType as ue } from "@mavonengine/core/Scene/builtinSceneObjects";
8
- import { SCENE_FORMAT_VERSION as de } from "@mavonengine/core/Scene/types";
9
- // ../../node_modules/three/examples/jsm/controls/FlyControls.js
10
- var fe = { type: "change" }, pe = 1e-6, me = new O(), he = class extends f {
11
- constructor(e, t = null) {
12
- super(e, t), this.movementSpeed = 1, this.rollSpeed = .005, this.dragToLook = !1, this.autoForward = !1, this._moveState = {
13
- up: 0,
14
- down: 0,
15
- left: 0,
16
- right: 0,
17
- forward: 0,
18
- back: 0,
19
- pitchUp: 0,
20
- pitchDown: 0,
21
- yawLeft: 0,
22
- yawRight: 0,
23
- rollLeft: 0,
24
- rollRight: 0
25
- }, this._moveVector = new M(0, 0, 0), this._rotationVector = new M(0, 0, 0), this._lastQuaternion = new O(), this._lastPosition = new M(), this._status = 0, this._onKeyDown = ge.bind(this), this._onKeyUp = _e.bind(this), this._onPointerMove = ye.bind(this), this._onPointerDown = ve.bind(this), this._onPointerUp = be.bind(this), this._onPointerCancel = xe.bind(this), this._onContextMenu = Se.bind(this), t !== null && this.connect(t);
26
- }
27
- connect(e) {
28
- super.connect(e), window.addEventListener("keydown", this._onKeyDown), window.addEventListener("keyup", this._onKeyUp), this.domElement.addEventListener("pointermove", this._onPointerMove), this.domElement.addEventListener("pointerdown", this._onPointerDown), this.domElement.addEventListener("pointerup", this._onPointerUp), this.domElement.addEventListener("pointercancel", this._onPointerCancel), this.domElement.addEventListener("contextmenu", this._onContextMenu), this.domElement.style.touchAction = "none";
29
- }
30
- disconnect() {
31
- window.removeEventListener("keydown", this._onKeyDown), window.removeEventListener("keyup", this._onKeyUp), this.domElement.removeEventListener("pointermove", this._onPointerMove), this.domElement.removeEventListener("pointerdown", this._onPointerDown), this.domElement.removeEventListener("pointerup", this._onPointerUp), this.domElement.removeEventListener("pointercancel", this._onPointerCancel), this.domElement.removeEventListener("contextmenu", this._onContextMenu), this.domElement.style.touchAction = "";
32
- }
33
- dispose() {
34
- this.disconnect();
35
- }
36
- update(e) {
37
- if (this.enabled === !1) return;
38
- let t = this.object, n = e * this.movementSpeed, r = e * this.rollSpeed;
39
- t.translateX(this._moveVector.x * n), t.translateY(this._moveVector.y * n), t.translateZ(this._moveVector.z * n), me.set(this._rotationVector.x * r, this._rotationVector.y * r, this._rotationVector.z * r, 1).normalize(), t.quaternion.multiply(me), (this._lastPosition.distanceToSquared(t.position) > pe || 8 * (1 - this._lastQuaternion.dot(t.quaternion)) > pe) && (this.dispatchEvent(fe), this._lastQuaternion.copy(t.quaternion), this._lastPosition.copy(t.position));
40
- }
41
- _updateMovementVector() {
42
- let e = this._moveState.forward || this.autoForward && !this._moveState.back ? 1 : 0;
43
- this._moveVector.x = -this._moveState.left + this._moveState.right, this._moveVector.y = -this._moveState.down + this._moveState.up, this._moveVector.z = -e + this._moveState.back;
44
- }
45
- _updateRotationVector() {
46
- this._rotationVector.x = -this._moveState.pitchDown + this._moveState.pitchUp, this._rotationVector.y = -this._moveState.yawRight + this._moveState.yawLeft, this._rotationVector.z = -this._moveState.rollRight + this._moveState.rollLeft;
47
- }
48
- _getContainerDimensions() {
49
- return this.domElement == document ? {
50
- size: [window.innerWidth, window.innerHeight],
51
- offset: [0, 0]
52
- } : {
53
- size: [this.domElement.offsetWidth, this.domElement.offsetHeight],
54
- offset: [this.domElement.offsetLeft, this.domElement.offsetTop]
55
- };
56
- }
57
- };
58
- function ge(e) {
59
- if (!(e.altKey || this.enabled === !1)) {
60
- switch (e.code) {
61
- case "ShiftLeft":
62
- case "ShiftRight":
63
- this.movementSpeedMultiplier = .1;
64
- break;
65
- case "KeyW":
66
- this._moveState.forward = 1;
67
- break;
68
- case "KeyS":
69
- this._moveState.back = 1;
70
- break;
71
- case "KeyA":
72
- this._moveState.left = 1;
73
- break;
74
- case "KeyD":
75
- this._moveState.right = 1;
76
- break;
77
- case "KeyR":
78
- this._moveState.up = 1;
79
- break;
80
- case "KeyF":
81
- this._moveState.down = 1;
82
- break;
83
- case "ArrowUp":
84
- this._moveState.pitchUp = 1;
85
- break;
86
- case "ArrowDown":
87
- this._moveState.pitchDown = 1;
88
- break;
89
- case "ArrowLeft":
90
- this._moveState.yawLeft = 1;
91
- break;
92
- case "ArrowRight":
93
- this._moveState.yawRight = 1;
94
- break;
95
- case "KeyQ":
96
- this._moveState.rollLeft = 1;
97
- break;
98
- case "KeyE": this._moveState.rollRight = 1;
99
- }
100
- this._updateMovementVector(), this._updateRotationVector();
101
- }
102
- }
103
- function _e(e) {
104
- if (this.enabled !== !1) {
105
- switch (e.code) {
106
- case "ShiftLeft":
107
- case "ShiftRight":
108
- this.movementSpeedMultiplier = 1;
109
- break;
110
- case "KeyW":
111
- this._moveState.forward = 0;
112
- break;
113
- case "KeyS":
114
- this._moveState.back = 0;
115
- break;
116
- case "KeyA":
117
- this._moveState.left = 0;
118
- break;
119
- case "KeyD":
120
- this._moveState.right = 0;
121
- break;
122
- case "KeyR":
123
- this._moveState.up = 0;
124
- break;
125
- case "KeyF":
126
- this._moveState.down = 0;
127
- break;
128
- case "ArrowUp":
129
- this._moveState.pitchUp = 0;
130
- break;
131
- case "ArrowDown":
132
- this._moveState.pitchDown = 0;
133
- break;
134
- case "ArrowLeft":
135
- this._moveState.yawLeft = 0;
136
- break;
137
- case "ArrowRight":
138
- this._moveState.yawRight = 0;
139
- break;
140
- case "KeyQ":
141
- this._moveState.rollLeft = 0;
142
- break;
143
- case "KeyE": this._moveState.rollRight = 0;
144
- }
145
- this._updateMovementVector(), this._updateRotationVector();
146
- }
147
- }
148
- function ve(e) {
149
- if (this.enabled !== !1) {
150
- if (this.dragToLook) this._status++;
151
- else {
152
- switch (e.button) {
153
- case 0:
154
- this._moveState.forward = 1;
155
- break;
156
- case 2: this._moveState.back = 1;
157
- }
158
- this._updateMovementVector();
159
- }
160
- }
161
- }
162
- function ye(e) {
163
- if (this.enabled !== !1 && (!this.dragToLook || this._status > 0)) {
164
- let t = this._getContainerDimensions(), n = t.size[0] / 2, r = t.size[1] / 2;
165
- this._moveState.yawLeft = -(e.pageX - t.offset[0] - n) / n, this._moveState.pitchDown = (e.pageY - t.offset[1] - r) / r, this._updateRotationVector();
166
- }
167
- }
168
- function be(e) {
169
- if (this.enabled !== !1) {
170
- if (this.dragToLook) this._status--, this._moveState.yawLeft = this._moveState.pitchDown = 0;
171
- else {
172
- switch (e.button) {
173
- case 0:
174
- this._moveState.forward = 0;
175
- break;
176
- case 2: this._moveState.back = 0;
177
- }
178
- this._updateMovementVector();
179
- }
180
- this._updateRotationVector();
181
- }
182
- }
183
- function xe() {
184
- this.enabled !== !1 && (this.dragToLook ? (this._status = 0, this._moveState.yawLeft = this._moveState.pitchDown = 0) : (this._moveState.forward = 0, this._moveState.back = 0, this._updateMovementVector()), this._updateRotationVector());
185
- }
186
- function Se(e) {
187
- this.enabled !== !1 && e.preventDefault();
188
- }
189
- // ../../node_modules/three/examples/jsm/controls/TransformControls.js
190
- var P = new oe(), F = new M(), I = new M(), L = new O(), Ce = {
191
- X: new M(1, 0, 0),
192
- Y: new M(0, 1, 0),
193
- Z: new M(0, 0, 1)
194
- }, R = { type: "change" }, we = {
195
- type: "mouseDown",
196
- mode: null
197
- }, Te = {
198
- type: "mouseUp",
199
- mode: null
200
- }, Ee = { type: "objectChange" }, De = class extends f {
201
- constructor(e, t = null) {
202
- super(void 0, t);
203
- let n = new Ie(this);
204
- this._root = n;
205
- let r = new Le();
206
- this._gizmo = r, n.add(r);
207
- let i = new Re();
208
- this._plane = i, n.add(i);
209
- let a = this;
210
- function o(e, t) {
211
- let n = t;
212
- Object.defineProperty(a, e, {
213
- get: function() {
214
- return n === void 0 ? t : n;
215
- },
216
- set: function(t) {
217
- n !== t && (n = t, i[e] = t, r[e] = t, a.dispatchEvent({
218
- type: e + "-changed",
219
- value: t
220
- }), a.dispatchEvent(R));
221
- }
222
- }), a[e] = t, i[e] = t, r[e] = t;
223
- }
224
- o("camera", e), o("object", void 0), o("enabled", !0), o("axis", null), o("mode", "translate"), o("translationSnap", null), o("rotationSnap", null), o("scaleSnap", null), o("space", "world"), o("size", 1), o("dragging", !1), o("showX", !0), o("showY", !0), o("showZ", !0), o("showXY", !0), o("showYZ", !0), o("showXZ", !0), o("minX", -Infinity), o("maxX", Infinity), o("minY", -Infinity), o("maxY", Infinity), o("minZ", -Infinity), o("maxZ", Infinity);
225
- let s = new M(), c = new M(), l = new O(), u = new O(), d = new M(), f = new O(), p = new M(), m = new M(), h = new M(), g = new M();
226
- o("worldPosition", s), o("worldPositionStart", c), o("worldQuaternion", l), o("worldQuaternionStart", u), o("cameraPosition", d), o("cameraQuaternion", f), o("pointStart", p), o("pointEnd", m), o("rotationAxis", h), o("rotationAngle", 0), o("eye", g), this._offset = new M(), this._startNorm = new M(), this._endNorm = new M(), this._cameraScale = new M(), this._parentPosition = new M(), this._parentQuaternion = new O(), this._parentQuaternionInv = new O(), this._parentScale = new M(), this._worldScaleStart = new M(), this._worldQuaternionInv = new O(), this._worldScale = new M(), this._positionStart = new M(), this._quaternionStart = new O(), this._scaleStart = new M(), this._getPointer = Oe.bind(this), this._onPointerDown = Ae.bind(this), this._onPointerHover = ke.bind(this), this._onPointerMove = je.bind(this), this._onPointerUp = Me.bind(this), t !== null && this.connect(t);
227
- }
228
- connect(e) {
229
- super.connect(e), this.domElement.addEventListener("pointerdown", this._onPointerDown), this.domElement.addEventListener("pointermove", this._onPointerHover), this.domElement.addEventListener("pointerup", this._onPointerUp), this.domElement.style.touchAction = "none";
230
- }
231
- disconnect() {
232
- this.domElement.removeEventListener("pointerdown", this._onPointerDown), this.domElement.removeEventListener("pointermove", this._onPointerHover), this.domElement.removeEventListener("pointermove", this._onPointerMove), this.domElement.removeEventListener("pointerup", this._onPointerUp), this.domElement.style.touchAction = "";
233
- }
234
- getHelper() {
235
- return this._root;
236
- }
237
- pointerHover(e) {
238
- if (this.object === void 0 || this.dragging === !0) return;
239
- e !== null && P.setFromCamera(e, this.camera);
240
- let t = z(this._gizmo.picker[this.mode], P);
241
- this.axis = t ? t.object.name : null;
242
- }
243
- pointerDown(e) {
244
- if (!(this.object === void 0 || this.dragging === !0 || e != null && e.button !== 0) && this.axis !== null) {
245
- e !== null && P.setFromCamera(e, this.camera);
246
- let t = z(this._plane, P, !0);
247
- t && (this.object.updateMatrixWorld(), this.object.parent.updateMatrixWorld(), this._positionStart.copy(this.object.position), this._quaternionStart.copy(this.object.quaternion), this._scaleStart.copy(this.object.scale), this.object.matrixWorld.decompose(this.worldPositionStart, this.worldQuaternionStart, this._worldScaleStart), this.pointStart.copy(t.point).sub(this.worldPositionStart)), this.dragging = !0, we.mode = this.mode, this.dispatchEvent(we);
248
- }
249
- }
250
- pointerMove(e) {
251
- let t = this.axis, n = this.mode, r = this.object, i = this.space;
252
- if (n === "scale" ? i = "local" : (t === "E" || t === "XYZE" || t === "XYZ") && (i = "world"), r === void 0 || t === null || this.dragging === !1 || e !== null && e.button !== -1) return;
253
- e !== null && P.setFromCamera(e, this.camera);
254
- let a = z(this._plane, P, !0);
255
- if (a) {
256
- if (this.pointEnd.copy(a.point).sub(this.worldPositionStart), n === "translate") this._offset.copy(this.pointEnd).sub(this.pointStart), i === "local" && t !== "XYZ" && this._offset.applyQuaternion(this._worldQuaternionInv), t.indexOf("X") === -1 && (this._offset.x = 0), t.indexOf("Y") === -1 && (this._offset.y = 0), t.indexOf("Z") === -1 && (this._offset.z = 0), i === "local" && t !== "XYZ" ? this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale) : this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale), r.position.copy(this._offset).add(this._positionStart), this.translationSnap && (i === "local" && (r.position.applyQuaternion(L.copy(this._quaternionStart).invert()), t.search("X") !== -1 && (r.position.x = Math.round(r.position.x / this.translationSnap) * this.translationSnap), t.search("Y") !== -1 && (r.position.y = Math.round(r.position.y / this.translationSnap) * this.translationSnap), t.search("Z") !== -1 && (r.position.z = Math.round(r.position.z / this.translationSnap) * this.translationSnap), r.position.applyQuaternion(this._quaternionStart)), i === "world" && (r.parent && r.position.add(F.setFromMatrixPosition(r.parent.matrixWorld)), t.search("X") !== -1 && (r.position.x = Math.round(r.position.x / this.translationSnap) * this.translationSnap), t.search("Y") !== -1 && (r.position.y = Math.round(r.position.y / this.translationSnap) * this.translationSnap), t.search("Z") !== -1 && (r.position.z = Math.round(r.position.z / this.translationSnap) * this.translationSnap), r.parent && r.position.sub(F.setFromMatrixPosition(r.parent.matrixWorld)))), r.position.x = Math.max(this.minX, Math.min(this.maxX, r.position.x)), r.position.y = Math.max(this.minY, Math.min(this.maxY, r.position.y)), r.position.z = Math.max(this.minZ, Math.min(this.maxZ, r.position.z));
257
- else if (n === "scale") {
258
- if (t.search("XYZ") !== -1) {
259
- let e = this.pointEnd.length() / this.pointStart.length();
260
- this.pointEnd.dot(this.pointStart) < 0 && (e *= -1), I.set(e, e, e);
261
- } else F.copy(this.pointStart), I.copy(this.pointEnd), F.applyQuaternion(this._worldQuaternionInv), I.applyQuaternion(this._worldQuaternionInv), I.divide(F), t.search("X") === -1 && (I.x = 1), t.search("Y") === -1 && (I.y = 1), t.search("Z") === -1 && (I.z = 1);
262
- r.scale.copy(this._scaleStart).multiply(I), this.scaleSnap && (t.search("X") !== -1 && (r.scale.x = Math.round(r.scale.x / this.scaleSnap) * this.scaleSnap || this.scaleSnap), t.search("Y") !== -1 && (r.scale.y = Math.round(r.scale.y / this.scaleSnap) * this.scaleSnap || this.scaleSnap), t.search("Z") !== -1 && (r.scale.z = Math.round(r.scale.z / this.scaleSnap) * this.scaleSnap || this.scaleSnap));
263
- } else if (n === "rotate") {
264
- this._offset.copy(this.pointEnd).sub(this.pointStart);
265
- let e = 20 / this.worldPosition.distanceTo(F.setFromMatrixPosition(this.camera.matrixWorld)), n = !1;
266
- t === "XYZE" ? (this.rotationAxis.copy(this._offset).cross(this.eye).normalize(), this.rotationAngle = this._offset.dot(F.copy(this.rotationAxis).cross(this.eye)) * e) : (t === "X" || t === "Y" || t === "Z") && (this.rotationAxis.copy(Ce[t]), F.copy(Ce[t]), i === "local" && F.applyQuaternion(this.worldQuaternion), F.cross(this.eye), F.length() === 0 ? n = !0 : this.rotationAngle = this._offset.dot(F.normalize()) * e), (t === "E" || n) && (this.rotationAxis.copy(this.eye), this.rotationAngle = this.pointEnd.angleTo(this.pointStart), this._startNorm.copy(this.pointStart).normalize(), this._endNorm.copy(this.pointEnd).normalize(), this.rotationAngle *= this._endNorm.cross(this._startNorm).dot(this.eye) < 0 ? 1 : -1), this.rotationSnap && (this.rotationAngle = Math.round(this.rotationAngle / this.rotationSnap) * this.rotationSnap), i === "local" && t !== "E" && t !== "XYZE" ? (r.quaternion.copy(this._quaternionStart), r.quaternion.multiply(L.setFromAxisAngle(this.rotationAxis, this.rotationAngle)).normalize()) : (this.rotationAxis.applyQuaternion(this._parentQuaternionInv), r.quaternion.copy(L.setFromAxisAngle(this.rotationAxis, this.rotationAngle)), r.quaternion.multiply(this._quaternionStart).normalize());
267
- }
268
- this.dispatchEvent(R), this.dispatchEvent(Ee);
269
- }
270
- }
271
- pointerUp(e) {
272
- (e === null || e.button === 0) && (this.dragging && this.axis !== null && (Te.mode = this.mode, this.dispatchEvent(Te)), this.dragging = !1, this.axis = null);
273
- }
274
- dispose() {
275
- this.disconnect(), this._root.dispose();
276
- }
277
- attach(e) {
278
- return this.object = e, this._root.visible = !0, this;
279
- }
280
- detach() {
281
- return this.object = void 0, this.axis = null, this._root.visible = !1, this;
282
- }
283
- reset() {
284
- this.enabled && this.dragging && (this.object.position.copy(this._positionStart), this.object.quaternion.copy(this._quaternionStart), this.object.scale.copy(this._scaleStart), this.dispatchEvent(R), this.dispatchEvent(Ee), this.pointStart.copy(this.pointEnd));
285
- }
286
- getRaycaster() {
287
- return P;
288
- }
289
- getMode() {
290
- return this.mode;
291
- }
292
- setMode(e) {
293
- this.mode = e;
294
- }
295
- setTranslationSnap(e) {
296
- this.translationSnap = e;
297
- }
298
- setRotationSnap(e) {
299
- this.rotationSnap = e;
300
- }
301
- setScaleSnap(e) {
302
- this.scaleSnap = e;
303
- }
304
- setSize(e) {
305
- this.size = e;
306
- }
307
- setSpace(e) {
308
- this.space = e;
309
- }
310
- setColors(e, t, n, r) {
311
- let i = this._gizmo.materialLib;
312
- i.xAxis.color.set(e), i.yAxis.color.set(t), i.zAxis.color.set(n), i.active.color.set(r), i.xAxisTransparent.color.set(e), i.yAxisTransparent.color.set(t), i.zAxisTransparent.color.set(n), i.activeTransparent.color.set(r), i.xAxis._color && i.xAxis._color.set(e), i.yAxis._color && i.yAxis._color.set(t), i.zAxis._color && i.zAxis._color.set(n), i.active._color && i.active._color.set(r), i.xAxisTransparent._color && i.xAxisTransparent._color.set(e), i.yAxisTransparent._color && i.yAxisTransparent._color.set(t), i.zAxisTransparent._color && i.zAxisTransparent._color.set(n), i.activeTransparent._color && i.activeTransparent._color.set(r);
313
- }
314
- };
315
- function Oe(e) {
316
- if (this.domElement.ownerDocument.pointerLockElement) return {
317
- x: 0,
318
- y: 0,
319
- button: e.button
320
- };
321
- {
322
- let t = this.domElement.getBoundingClientRect();
323
- return {
324
- x: (e.clientX - t.left) / t.width * 2 - 1,
325
- y: -(e.clientY - t.top) / t.height * 2 + 1,
326
- button: e.button
327
- };
328
- }
329
- }
330
- function ke(e) {
331
- if (this.enabled) switch (e.pointerType) {
332
- case "mouse":
333
- case "pen": this.pointerHover(this._getPointer(e));
334
- }
335
- }
336
- function Ae(e) {
337
- this.enabled && (document.pointerLockElement || this.domElement.setPointerCapture(e.pointerId), this.domElement.addEventListener("pointermove", this._onPointerMove), this.pointerHover(this._getPointer(e)), this.pointerDown(this._getPointer(e)));
338
- }
339
- function je(e) {
340
- this.enabled && this.pointerMove(this._getPointer(e));
341
- }
342
- function Me(e) {
343
- this.enabled && (this.domElement.releasePointerCapture(e.pointerId), this.domElement.removeEventListener("pointermove", this._onPointerMove), this.pointerUp(this._getPointer(e)));
344
- }
345
- function z(e, t, n) {
346
- let r = t.intersectObject(e, !0);
347
- for (let e = 0; e < r.length; e++) if (r[e].object.visible || n) return r[e];
348
- return !1;
349
- }
350
- var B = new g(), V = new M(0, 1, 0), Ne = new M(0, 0, 0), Pe = new C(), H = new O(), U = new O(), W = new M(), Fe = new C(), G = new M(1, 0, 0), K = new M(0, 1, 0), q = new M(0, 0, 1), J = new M(), Y = new M(), X = new M(), Ie = class extends E {
351
- constructor(e) {
352
- super(), this.isTransformControlsRoot = !0, this.controls = e, this.visible = !1;
353
- }
354
- updateMatrixWorld(e) {
355
- let t = this.controls;
356
- t.object !== void 0 && (t.object.updateMatrixWorld(), t.object.parent === null ? console.error("TransformControls: The attached 3D object must be a part of the scene graph.") : t.object.parent.matrixWorld.decompose(t._parentPosition, t._parentQuaternion, t._parentScale), t.object.matrixWorld.decompose(t.worldPosition, t.worldQuaternion, t._worldScale), t._parentQuaternionInv.copy(t._parentQuaternion).invert(), t._worldQuaternionInv.copy(t.worldQuaternion).invert()), t.camera.updateMatrixWorld(), t.camera.matrixWorld.decompose(t.cameraPosition, t.cameraQuaternion, t._cameraScale), t.camera.isOrthographicCamera ? t.camera.getWorldDirection(t.eye).negate() : t.eye.copy(t.cameraPosition).sub(t.worldPosition).normalize(), super.updateMatrixWorld(e);
357
- }
358
- dispose() {
359
- this.traverse(function(e) {
360
- e.geometry && e.geometry.dispose(), e.material && e.material.dispose();
361
- });
362
- }
363
- }, Le = class extends E {
364
- constructor() {
365
- super(), this.isTransformControlsGizmo = !0, this.type = "TransformControlsGizmo";
366
- let e = new te({
367
- depthTest: !1,
368
- depthWrite: !1,
369
- fog: !1,
370
- toneMapped: !1,
371
- transparent: !0
372
- }), t = new ee({
373
- depthTest: !1,
374
- depthWrite: !1,
375
- fog: !1,
376
- toneMapped: !1,
377
- transparent: !0
378
- }), n = e.clone();
379
- n.opacity = .15;
380
- let r = t.clone();
381
- r.opacity = .5;
382
- let i = e.clone();
383
- i.color.setHex(16711680);
384
- let a = e.clone();
385
- a.color.setHex(65280);
386
- let o = e.clone();
387
- o.color.setHex(255);
388
- let s = e.clone();
389
- s.color.setHex(16711680), s.opacity = .5;
390
- let c = e.clone();
391
- c.color.setHex(65280), c.opacity = .5;
392
- let d = e.clone();
393
- d.color.setHex(255), d.opacity = .5;
394
- let f = e.clone();
395
- f.opacity = .25;
396
- let m = e.clone();
397
- m.color.setHex(16776960), m.opacity = .25;
398
- let h = e.clone();
399
- h.color.setHex(16776960);
400
- let g = e.clone();
401
- g.color.setHex(7895160), this.materialLib = {
402
- xAxis: i,
403
- yAxis: a,
404
- zAxis: o,
405
- active: h,
406
- xAxisTransparent: s,
407
- yAxisTransparent: c,
408
- zAxisTransparent: d,
409
- activeTransparent: m
410
- };
411
- let v = new p(0, .04, .1, 12);
412
- v.translate(0, .05, 0);
413
- let y = new l(.08, .08, .08);
414
- y.translate(0, .04, 0);
415
- let x = new u();
416
- x.setAttribute("position", new _([
417
- 0,
418
- 0,
419
- 0,
420
- 1,
421
- 0,
422
- 0
423
- ], 3));
424
- let S = new p(.0075, .0075, .5, 3);
425
- S.translate(0, .25, 0);
426
- function C(e, t) {
427
- let n = new A(e, .0075, 3, 64, t * Math.PI * 2);
428
- return n.rotateY(Math.PI / 2), n.rotateX(Math.PI / 2), n;
429
- }
430
- function ne() {
431
- let e = new u();
432
- return e.setAttribute("position", new _([
433
- 0,
434
- 0,
435
- 0,
436
- 1,
437
- 1,
438
- 1
439
- ], 3)), e;
440
- }
441
- let T = {
442
- X: [
443
- [
444
- new w(v, i),
445
- [
446
- .5,
447
- 0,
448
- 0
449
- ],
450
- [
451
- 0,
452
- 0,
453
- -Math.PI / 2
454
- ]
455
- ],
456
- [
457
- new w(v, i),
458
- [
459
- -.5,
460
- 0,
461
- 0
462
- ],
463
- [
464
- 0,
465
- 0,
466
- Math.PI / 2
467
- ]
468
- ],
469
- [
470
- new w(S, i),
471
- [
472
- 0,
473
- 0,
474
- 0
475
- ],
476
- [
477
- 0,
478
- 0,
479
- -Math.PI / 2
480
- ]
481
- ]
482
- ],
483
- Y: [
484
- [new w(v, a), [
485
- 0,
486
- .5,
487
- 0
488
- ]],
489
- [
490
- new w(v, a),
491
- [
492
- 0,
493
- -.5,
494
- 0
495
- ],
496
- [
497
- Math.PI,
498
- 0,
499
- 0
500
- ]
501
- ],
502
- [new w(S, a)]
503
- ],
504
- Z: [
505
- [
506
- new w(v, o),
507
- [
508
- 0,
509
- 0,
510
- .5
511
- ],
512
- [
513
- Math.PI / 2,
514
- 0,
515
- 0
516
- ]
517
- ],
518
- [
519
- new w(v, o),
520
- [
521
- 0,
522
- 0,
523
- -.5
524
- ],
525
- [
526
- -Math.PI / 2,
527
- 0,
528
- 0
529
- ]
530
- ],
531
- [
532
- new w(S, o),
533
- null,
534
- [
535
- Math.PI / 2,
536
- 0,
537
- 0
538
- ]
539
- ]
540
- ],
541
- XYZ: [[new w(new D(.1, 0), f), [
542
- 0,
543
- 0,
544
- 0
545
- ]]],
546
- XY: [[new w(new l(.15, .15, .01), d), [
547
- .15,
548
- .15,
549
- 0
550
- ]]],
551
- YZ: [[
552
- new w(new l(.15, .15, .01), s),
553
- [
554
- 0,
555
- .15,
556
- .15
557
- ],
558
- [
559
- 0,
560
- Math.PI / 2,
561
- 0
562
- ]
563
- ]],
564
- XZ: [[
565
- new w(new l(.15, .15, .01), c),
566
- [
567
- .15,
568
- 0,
569
- .15
570
- ],
571
- [
572
- -Math.PI / 2,
573
- 0,
574
- 0
575
- ]
576
- ]]
577
- }, re = {
578
- X: [[
579
- new w(new p(.2, 0, .6, 4), n),
580
- [
581
- .3,
582
- 0,
583
- 0
584
- ],
585
- [
586
- 0,
587
- 0,
588
- -Math.PI / 2
589
- ]
590
- ], [
591
- new w(new p(.2, 0, .6, 4), n),
592
- [
593
- -.3,
594
- 0,
595
- 0
596
- ],
597
- [
598
- 0,
599
- 0,
600
- Math.PI / 2
601
- ]
602
- ]],
603
- Y: [[new w(new p(.2, 0, .6, 4), n), [
604
- 0,
605
- .3,
606
- 0
607
- ]], [
608
- new w(new p(.2, 0, .6, 4), n),
609
- [
610
- 0,
611
- -.3,
612
- 0
613
- ],
614
- [
615
- 0,
616
- 0,
617
- Math.PI
618
- ]
619
- ]],
620
- Z: [[
621
- new w(new p(.2, 0, .6, 4), n),
622
- [
623
- 0,
624
- 0,
625
- .3
626
- ],
627
- [
628
- Math.PI / 2,
629
- 0,
630
- 0
631
- ]
632
- ], [
633
- new w(new p(.2, 0, .6, 4), n),
634
- [
635
- 0,
636
- 0,
637
- -.3
638
- ],
639
- [
640
- -Math.PI / 2,
641
- 0,
642
- 0
643
- ]
644
- ]],
645
- XYZ: [[new w(new D(.2, 0), n)]],
646
- XY: [[new w(new l(.2, .2, .01), n), [
647
- .15,
648
- .15,
649
- 0
650
- ]]],
651
- YZ: [[
652
- new w(new l(.2, .2, .01), n),
653
- [
654
- 0,
655
- .15,
656
- .15
657
- ],
658
- [
659
- 0,
660
- Math.PI / 2,
661
- 0
662
- ]
663
- ]],
664
- XZ: [[
665
- new w(new l(.2, .2, .01), n),
666
- [
667
- .15,
668
- 0,
669
- .15
670
- ],
671
- [
672
- -Math.PI / 2,
673
- 0,
674
- 0
675
- ]
676
- ]]
677
- }, ie = {
678
- START: [[
679
- new w(new D(.01, 2), r),
680
- null,
681
- null,
682
- null,
683
- "helper"
684
- ]],
685
- END: [[
686
- new w(new D(.01, 2), r),
687
- null,
688
- null,
689
- null,
690
- "helper"
691
- ]],
692
- DELTA: [[
693
- new b(ne(), r),
694
- null,
695
- null,
696
- null,
697
- "helper"
698
- ]],
699
- X: [[
700
- new b(x, r),
701
- [
702
- -1e3,
703
- 0,
704
- 0
705
- ],
706
- null,
707
- [
708
- 1e6,
709
- 1,
710
- 1
711
- ],
712
- "helper"
713
- ]],
714
- Y: [[
715
- new b(x, r),
716
- [
717
- 0,
718
- -1e3,
719
- 0
720
- ],
721
- [
722
- 0,
723
- 0,
724
- Math.PI / 2
725
- ],
726
- [
727
- 1e6,
728
- 1,
729
- 1
730
- ],
731
- "helper"
732
- ]],
733
- Z: [[
734
- new b(x, r),
735
- [
736
- 0,
737
- 0,
738
- -1e3
739
- ],
740
- [
741
- 0,
742
- -Math.PI / 2,
743
- 0
744
- ],
745
- [
746
- 1e6,
747
- 1,
748
- 1
749
- ],
750
- "helper"
751
- ]]
752
- }, O = {
753
- XYZE: [[
754
- new w(C(.5, 1), g),
755
- null,
756
- [
757
- 0,
758
- Math.PI / 2,
759
- 0
760
- ]
761
- ]],
762
- X: [[new w(C(.5, .5), i)]],
763
- Y: [[
764
- new w(C(.5, .5), a),
765
- null,
766
- [
767
- 0,
768
- 0,
769
- -Math.PI / 2
770
- ]
771
- ]],
772
- Z: [[
773
- new w(C(.5, .5), o),
774
- null,
775
- [
776
- 0,
777
- Math.PI / 2,
778
- 0
779
- ]
780
- ]],
781
- E: [[
782
- new w(C(.75, 1), m),
783
- null,
784
- [
785
- 0,
786
- Math.PI / 2,
787
- 0
788
- ]
789
- ]]
790
- }, ae = { AXIS: [[
791
- new b(x, r),
792
- [
793
- -1e3,
794
- 0,
795
- 0
796
- ],
797
- null,
798
- [
799
- 1e6,
800
- 1,
801
- 1
802
- ],
803
- "helper"
804
- ]] }, oe = {
805
- XYZE: [[new w(new se(.25, 10, 8), n)]],
806
- X: [[
807
- new w(new A(.5, .1, 4, 24), n),
808
- [
809
- 0,
810
- 0,
811
- 0
812
- ],
813
- [
814
- 0,
815
- -Math.PI / 2,
816
- -Math.PI / 2
817
- ]
818
- ]],
819
- Y: [[
820
- new w(new A(.5, .1, 4, 24), n),
821
- [
822
- 0,
823
- 0,
824
- 0
825
- ],
826
- [
827
- Math.PI / 2,
828
- 0,
829
- 0
830
- ]
831
- ]],
832
- Z: [[
833
- new w(new A(.5, .1, 4, 24), n),
834
- [
835
- 0,
836
- 0,
837
- 0
838
- ],
839
- [
840
- 0,
841
- 0,
842
- -Math.PI / 2
843
- ]
844
- ]],
845
- E: [[new w(new A(.75, .1, 2, 24), n)]]
846
- }, k = {
847
- X: [
848
- [
849
- new w(y, i),
850
- [
851
- .5,
852
- 0,
853
- 0
854
- ],
855
- [
856
- 0,
857
- 0,
858
- -Math.PI / 2
859
- ]
860
- ],
861
- [
862
- new w(S, i),
863
- [
864
- 0,
865
- 0,
866
- 0
867
- ],
868
- [
869
- 0,
870
- 0,
871
- -Math.PI / 2
872
- ]
873
- ],
874
- [
875
- new w(y, i),
876
- [
877
- -.5,
878
- 0,
879
- 0
880
- ],
881
- [
882
- 0,
883
- 0,
884
- Math.PI / 2
885
- ]
886
- ]
887
- ],
888
- Y: [
889
- [new w(y, a), [
890
- 0,
891
- .5,
892
- 0
893
- ]],
894
- [new w(S, a)],
895
- [
896
- new w(y, a),
897
- [
898
- 0,
899
- -.5,
900
- 0
901
- ],
902
- [
903
- 0,
904
- 0,
905
- Math.PI
906
- ]
907
- ]
908
- ],
909
- Z: [
910
- [
911
- new w(y, o),
912
- [
913
- 0,
914
- 0,
915
- .5
916
- ],
917
- [
918
- Math.PI / 2,
919
- 0,
920
- 0
921
- ]
922
- ],
923
- [
924
- new w(S, o),
925
- [
926
- 0,
927
- 0,
928
- 0
929
- ],
930
- [
931
- Math.PI / 2,
932
- 0,
933
- 0
934
- ]
935
- ],
936
- [
937
- new w(y, o),
938
- [
939
- 0,
940
- 0,
941
- -.5
942
- ],
943
- [
944
- -Math.PI / 2,
945
- 0,
946
- 0
947
- ]
948
- ]
949
- ],
950
- XY: [[new w(new l(.15, .15, .01), d), [
951
- .15,
952
- .15,
953
- 0
954
- ]]],
955
- YZ: [[
956
- new w(new l(.15, .15, .01), s),
957
- [
958
- 0,
959
- .15,
960
- .15
961
- ],
962
- [
963
- 0,
964
- Math.PI / 2,
965
- 0
966
- ]
967
- ]],
968
- XZ: [[
969
- new w(new l(.15, .15, .01), c),
970
- [
971
- .15,
972
- 0,
973
- .15
974
- ],
975
- [
976
- -Math.PI / 2,
977
- 0,
978
- 0
979
- ]
980
- ]],
981
- XYZ: [[new w(new l(.1, .1, .1), f)]]
982
- }, ce = {
983
- X: [[
984
- new w(new p(.2, 0, .6, 4), n),
985
- [
986
- .3,
987
- 0,
988
- 0
989
- ],
990
- [
991
- 0,
992
- 0,
993
- -Math.PI / 2
994
- ]
995
- ], [
996
- new w(new p(.2, 0, .6, 4), n),
997
- [
998
- -.3,
999
- 0,
1000
- 0
1001
- ],
1002
- [
1003
- 0,
1004
- 0,
1005
- Math.PI / 2
1006
- ]
1007
- ]],
1008
- Y: [[new w(new p(.2, 0, .6, 4), n), [
1009
- 0,
1010
- .3,
1011
- 0
1012
- ]], [
1013
- new w(new p(.2, 0, .6, 4), n),
1014
- [
1015
- 0,
1016
- -.3,
1017
- 0
1018
- ],
1019
- [
1020
- 0,
1021
- 0,
1022
- Math.PI
1023
- ]
1024
- ]],
1025
- Z: [[
1026
- new w(new p(.2, 0, .6, 4), n),
1027
- [
1028
- 0,
1029
- 0,
1030
- .3
1031
- ],
1032
- [
1033
- Math.PI / 2,
1034
- 0,
1035
- 0
1036
- ]
1037
- ], [
1038
- new w(new p(.2, 0, .6, 4), n),
1039
- [
1040
- 0,
1041
- 0,
1042
- -.3
1043
- ],
1044
- [
1045
- -Math.PI / 2,
1046
- 0,
1047
- 0
1048
- ]
1049
- ]],
1050
- XY: [[new w(new l(.2, .2, .01), n), [
1051
- .15,
1052
- .15,
1053
- 0
1054
- ]]],
1055
- YZ: [[
1056
- new w(new l(.2, .2, .01), n),
1057
- [
1058
- 0,
1059
- .15,
1060
- .15
1061
- ],
1062
- [
1063
- 0,
1064
- Math.PI / 2,
1065
- 0
1066
- ]
1067
- ]],
1068
- XZ: [[
1069
- new w(new l(.2, .2, .01), n),
1070
- [
1071
- .15,
1072
- 0,
1073
- .15
1074
- ],
1075
- [
1076
- -Math.PI / 2,
1077
- 0,
1078
- 0
1079
- ]
1080
- ]],
1081
- XYZ: [[new w(new l(.2, .2, .2), n), [
1082
- 0,
1083
- 0,
1084
- 0
1085
- ]]]
1086
- }, j = {
1087
- X: [[
1088
- new b(x, r),
1089
- [
1090
- -1e3,
1091
- 0,
1092
- 0
1093
- ],
1094
- null,
1095
- [
1096
- 1e6,
1097
- 1,
1098
- 1
1099
- ],
1100
- "helper"
1101
- ]],
1102
- Y: [[
1103
- new b(x, r),
1104
- [
1105
- 0,
1106
- -1e3,
1107
- 0
1108
- ],
1109
- [
1110
- 0,
1111
- 0,
1112
- Math.PI / 2
1113
- ],
1114
- [
1115
- 1e6,
1116
- 1,
1117
- 1
1118
- ],
1119
- "helper"
1120
- ]],
1121
- Z: [[
1122
- new b(x, r),
1123
- [
1124
- 0,
1125
- 0,
1126
- -1e3
1127
- ],
1128
- [
1129
- 0,
1130
- -Math.PI / 2,
1131
- 0
1132
- ],
1133
- [
1134
- 1e6,
1135
- 1,
1136
- 1
1137
- ],
1138
- "helper"
1139
- ]]
1140
- };
1141
- function M(e) {
1142
- let t = new E();
1143
- for (let n in e) for (let r = e[n].length; r--;) {
1144
- let i = e[n][r][0].clone(), a = e[n][r][1], o = e[n][r][2], s = e[n][r][3], c = e[n][r][4];
1145
- i.name = n, i.tag = c, a && i.position.set(a[0], a[1], a[2]), o && i.rotation.set(o[0], o[1], o[2]), s && i.scale.set(s[0], s[1], s[2]), i.updateMatrix();
1146
- let l = i.geometry.clone();
1147
- l.applyMatrix4(i.matrix), i.geometry = l, i.renderOrder = Infinity, i.position.set(0, 0, 0), i.rotation.set(0, 0, 0), i.scale.set(1, 1, 1), t.add(i);
1148
- }
1149
- return t;
1150
- }
1151
- this.gizmo = {}, this.picker = {}, this.helper = {}, this.add(this.gizmo.translate = M(T)), this.add(this.gizmo.rotate = M(O)), this.add(this.gizmo.scale = M(k)), this.add(this.picker.translate = M(re)), this.add(this.picker.rotate = M(oe)), this.add(this.picker.scale = M(ce)), this.add(this.helper.translate = M(ie)), this.add(this.helper.rotate = M(ae)), this.add(this.helper.scale = M(j)), this.picker.translate.visible = !1, this.picker.rotate.visible = !1, this.picker.scale.visible = !1;
1152
- }
1153
- updateMatrixWorld(e) {
1154
- let t = (this.mode === "scale" ? "local" : this.space) === "local" ? this.worldQuaternion : U;
1155
- this.gizmo.translate.visible = this.mode === "translate", this.gizmo.rotate.visible = this.mode === "rotate", this.gizmo.scale.visible = this.mode === "scale", this.helper.translate.visible = this.mode === "translate", this.helper.rotate.visible = this.mode === "rotate", this.helper.scale.visible = this.mode === "scale";
1156
- let n = [];
1157
- n = n.concat(this.picker[this.mode].children), n = n.concat(this.gizmo[this.mode].children), n = n.concat(this.helper[this.mode].children);
1158
- for (let e = 0; e < n.length; e++) {
1159
- let r = n[e];
1160
- r.visible = !0, r.rotation.set(0, 0, 0), r.position.copy(this.worldPosition);
1161
- let i;
1162
- if (i = this.camera.isOrthographicCamera ? (this.camera.top - this.camera.bottom) / this.camera.zoom : this.worldPosition.distanceTo(this.cameraPosition) * Math.min(1.9 * Math.tan(Math.PI * this.camera.fov / 360) / this.camera.zoom, 7), r.scale.set(1, 1, 1).multiplyScalar(i * this.size / 4), r.tag === "helper") r.visible = !1, r.name === "AXIS" ? (r.visible = !!this.axis, this.axis === "X" && (L.setFromEuler(B.set(0, 0, 0)), r.quaternion.copy(t).multiply(L), Math.abs(V.copy(G).applyQuaternion(t).dot(this.eye)) > .9 && (r.visible = !1)), this.axis === "Y" && (L.setFromEuler(B.set(0, 0, Math.PI / 2)), r.quaternion.copy(t).multiply(L), Math.abs(V.copy(K).applyQuaternion(t).dot(this.eye)) > .9 && (r.visible = !1)), this.axis === "Z" && (L.setFromEuler(B.set(0, Math.PI / 2, 0)), r.quaternion.copy(t).multiply(L), Math.abs(V.copy(q).applyQuaternion(t).dot(this.eye)) > .9 && (r.visible = !1)), this.axis === "XYZE" && (L.setFromEuler(B.set(0, Math.PI / 2, 0)), V.copy(this.rotationAxis), r.quaternion.setFromRotationMatrix(Pe.lookAt(Ne, V, K)), r.quaternion.multiply(L), r.visible = this.dragging), this.axis === "E" && (r.visible = !1)) : r.name === "START" ? (r.position.copy(this.worldPositionStart), r.visible = this.dragging) : r.name === "END" ? (r.position.copy(this.worldPosition), r.visible = this.dragging) : r.name === "DELTA" ? (r.position.copy(this.worldPositionStart), r.quaternion.copy(this.worldQuaternionStart), F.set(1e-10, 1e-10, 1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1), F.applyQuaternion(this.worldQuaternionStart.clone().invert()), r.scale.copy(F), r.visible = this.dragging) : (r.quaternion.copy(t), this.dragging ? r.position.copy(this.worldPositionStart) : r.position.copy(this.worldPosition), this.axis && (r.visible = this.axis.search(r.name) !== -1));
1163
- else {
1164
- if (r.quaternion.copy(t), this.mode === "translate" || this.mode === "scale") {
1165
- let e = .99, n = .2;
1166
- r.name === "X" && Math.abs(V.copy(G).applyQuaternion(t).dot(this.eye)) > e && (r.scale.set(1e-10, 1e-10, 1e-10), r.visible = !1), r.name === "Y" && Math.abs(V.copy(K).applyQuaternion(t).dot(this.eye)) > e && (r.scale.set(1e-10, 1e-10, 1e-10), r.visible = !1), r.name === "Z" && Math.abs(V.copy(q).applyQuaternion(t).dot(this.eye)) > e && (r.scale.set(1e-10, 1e-10, 1e-10), r.visible = !1), r.name === "XY" && Math.abs(V.copy(q).applyQuaternion(t).dot(this.eye)) < n && (r.scale.set(1e-10, 1e-10, 1e-10), r.visible = !1), r.name === "YZ" && Math.abs(V.copy(G).applyQuaternion(t).dot(this.eye)) < n && (r.scale.set(1e-10, 1e-10, 1e-10), r.visible = !1), r.name === "XZ" && Math.abs(V.copy(K).applyQuaternion(t).dot(this.eye)) < n && (r.scale.set(1e-10, 1e-10, 1e-10), r.visible = !1);
1167
- } else this.mode === "rotate" && (H.copy(t), V.copy(this.eye).applyQuaternion(L.copy(t).invert()), r.name.search("E") !== -1 && r.quaternion.setFromRotationMatrix(Pe.lookAt(this.eye, Ne, K)), r.name === "X" && (L.setFromAxisAngle(G, Math.atan2(-V.y, V.z)), L.multiplyQuaternions(H, L), r.quaternion.copy(L)), r.name === "Y" && (L.setFromAxisAngle(K, Math.atan2(V.x, V.z)), L.multiplyQuaternions(H, L), r.quaternion.copy(L)), r.name === "Z" && (L.setFromAxisAngle(q, Math.atan2(V.y, V.x)), L.multiplyQuaternions(H, L), r.quaternion.copy(L)));
1168
- r.visible = r.visible && (r.name.indexOf("X") === -1 || this.showX), r.visible = r.visible && (r.name.indexOf("Y") === -1 || this.showY), r.visible = r.visible && (r.name.indexOf("Z") === -1 || this.showZ), r.visible = r.visible && (r.name.indexOf("E") === -1 || this.showX && this.showY && this.showZ), r.visible = r.visible && (r.name.indexOf("XY") === -1 || this.showXY), r.visible = r.visible && (r.name.indexOf("YZ") === -1 || this.showYZ), r.visible = r.visible && (r.name.indexOf("XZ") === -1 || this.showXZ), r.material._color = r.material._color || r.material.color.clone(), r.material._opacity = r.material._opacity || r.material.opacity, r.material.color.copy(r.material._color), r.material.opacity = r.material._opacity, this.enabled && this.axis && (r.name === this.axis || this.axis.split("").some(function(e) {
1169
- return r.name === e;
1170
- })) && (r.material.color.copy(this.materialLib.active.color), r.material.opacity = 1);
1171
- }
1172
- }
1173
- super.updateMatrixWorld(e);
1174
- }
1175
- }, Re = class extends w {
1176
- constructor() {
1177
- super(new ie(1e5, 1e5, 2, 2), new te({
1178
- visible: !1,
1179
- wireframe: !0,
1180
- side: m,
1181
- transparent: !0,
1182
- opacity: .1,
1183
- toneMapped: !1
1184
- })), this.isTransformControlsPlane = !0, this.type = "TransformControlsPlane";
1185
- }
1186
- updateMatrixWorld(e) {
1187
- let t = this.space;
1188
- switch (this.position.copy(this.worldPosition), this.mode === "scale" && (t = "local"), J.copy(G).applyQuaternion(t === "local" ? this.worldQuaternion : U), Y.copy(K).applyQuaternion(t === "local" ? this.worldQuaternion : U), X.copy(q).applyQuaternion(t === "local" ? this.worldQuaternion : U), V.copy(Y), this.mode) {
1189
- case "translate":
1190
- case "scale":
1191
- switch (this.axis) {
1192
- case "X":
1193
- V.copy(this.eye).cross(J), W.copy(J).cross(V);
1194
- break;
1195
- case "Y":
1196
- V.copy(this.eye).cross(Y), W.copy(Y).cross(V);
1197
- break;
1198
- case "Z":
1199
- V.copy(this.eye).cross(X), W.copy(X).cross(V);
1200
- break;
1201
- case "XY":
1202
- W.copy(X);
1203
- break;
1204
- case "YZ":
1205
- W.copy(J);
1206
- break;
1207
- case "XZ":
1208
- V.copy(X), W.copy(Y);
1209
- break;
1210
- case "XYZ":
1211
- case "E": W.set(0, 0, 0);
1212
- }
1213
- break;
1214
- default: W.set(0, 0, 0);
1215
- }
1216
- W.length() === 0 ? this.quaternion.copy(this.cameraQuaternion) : (Fe.lookAt(F.set(0, 0, 0), W, V), this.quaternion.setFromRotationMatrix(Fe)), super.updateMatrixWorld(e);
1217
- }
1218
- }, ze = class {
1219
- constructor() {
1220
- this.isPass = !0, this.enabled = !0, this.needsSwap = !0, this.clear = !1, this.renderToScreen = !1;
1221
- }
1222
- setSize() {}
1223
- render() {
1224
- console.error("THREE.Pass: .render() must be implemented in derived pass.");
1225
- }
1226
- dispose() {}
1227
- }, Be = new re(-1, 1, 1, -1, 0, 1), Ve = new class extends u {
1228
- constructor() {
1229
- super(), this.setAttribute("position", new _([
1230
- -1,
1231
- 3,
1232
- 0,
1233
- -1,
1234
- -1,
1235
- 0,
1236
- 3,
1237
- -1,
1238
- 0
1239
- ], 3)), this.setAttribute("uv", new _([
1240
- 0,
1241
- 2,
1242
- 0,
1243
- 0,
1244
- 2,
1245
- 0
1246
- ], 2));
1247
- }
1248
- }(), He = class {
1249
- constructor(e) {
1250
- this._mesh = new w(Ve, e);
1251
- }
1252
- dispose() {
1253
- this._mesh.geometry.dispose();
1254
- }
1255
- render(e) {
1256
- e.render(this._mesh, Be);
1257
- }
1258
- get material() {
1259
- return this._mesh.material;
1260
- }
1261
- set material(e) {
1262
- this._mesh.material = e;
1263
- }
1264
- }, Ue = {
1265
- name: "CopyShader",
1266
- uniforms: {
1267
- tDiffuse: { value: null },
1268
- opacity: { value: 1 }
1269
- },
1270
- vertexShader: "\n\n varying vec2 vUv;\n\n void main() {\n\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n }",
1271
- fragmentShader: "\n\n uniform float opacity;\n\n uniform sampler2D tDiffuse;\n\n varying vec2 vUv;\n\n void main() {\n\n vec4 texel = texture2D( tDiffuse, vUv );\n gl_FragColor = opacity * texel;\n\n\n }"
1272
- }, We = class e extends ze {
1273
- constructor(e, t, n, r) {
1274
- super(), this.renderScene = t, this.renderCamera = n, this.selectedObjects = r === void 0 ? [] : r, this.visibleEdgeColor = new d(1, 1, 1), this.hiddenEdgeColor = new d(.1, .04, .02), this.edgeGlow = 0, this.usePatternTexture = !1, this.patternTexture = null, this.edgeThickness = 1, this.edgeStrength = 3, this.downSampleRatio = 2, this.pulsePeriod = 0, this._visibilityCache = /* @__PURE__ */ new Map(), this._selectionCache = /* @__PURE__ */ new Set(), this.resolution = e === void 0 ? new j(256, 256) : new j(e.x, e.y);
1275
- let i = Math.round(this.resolution.x / this.downSampleRatio), a = Math.round(this.resolution.y / this.downSampleRatio);
1276
- this.renderTargetMaskBuffer = new N(this.resolution.x, this.resolution.y), this.renderTargetMaskBuffer.texture.name = "OutlinePass.mask", this.renderTargetMaskBuffer.texture.generateMipmaps = !1, this.depthMaterial = new ne(), this.depthMaterial.side = m, this.depthMaterial.depthPacking = ae, this.depthMaterial.blending = T, this.prepareMaskMaterial = this._getPrepareMaskMaterial(), this.prepareMaskMaterial.side = m, this.prepareMaskMaterial.fragmentShader = s(this.prepareMaskMaterial.fragmentShader, this.renderCamera), this.renderTargetDepthBuffer = new N(this.resolution.x, this.resolution.y, { type: y }), this.renderTargetDepthBuffer.texture.name = "OutlinePass.depth", this.renderTargetDepthBuffer.texture.generateMipmaps = !1, this.renderTargetMaskDownSampleBuffer = new N(i, a, { type: y }), this.renderTargetMaskDownSampleBuffer.texture.name = "OutlinePass.depthDownSample", this.renderTargetMaskDownSampleBuffer.texture.generateMipmaps = !1, this.renderTargetBlurBuffer1 = new N(i, a, { type: y }), this.renderTargetBlurBuffer1.texture.name = "OutlinePass.blur1", this.renderTargetBlurBuffer1.texture.generateMipmaps = !1, this.renderTargetBlurBuffer2 = new N(Math.round(i / 2), Math.round(a / 2), { type: y }), this.renderTargetBlurBuffer2.texture.name = "OutlinePass.blur2", this.renderTargetBlurBuffer2.texture.generateMipmaps = !1, this.edgeDetectionMaterial = this._getEdgeDetectionMaterial(), this.renderTargetEdgeBuffer1 = new N(i, a, { type: y }), this.renderTargetEdgeBuffer1.texture.name = "OutlinePass.edge1", this.renderTargetEdgeBuffer1.texture.generateMipmaps = !1, this.renderTargetEdgeBuffer2 = new N(Math.round(i / 2), Math.round(a / 2), { type: y }), this.renderTargetEdgeBuffer2.texture.name = "OutlinePass.edge2", this.renderTargetEdgeBuffer2.texture.generateMipmaps = !1, this.separableBlurMaterial1 = this._getSeparableBlurMaterial(4), this.separableBlurMaterial1.uniforms.texSize.value.set(i, a), this.separableBlurMaterial1.uniforms.kernelRadius.value = 1, this.separableBlurMaterial2 = this._getSeparableBlurMaterial(4), this.separableBlurMaterial2.uniforms.texSize.value.set(Math.round(i / 2), Math.round(a / 2)), this.separableBlurMaterial2.uniforms.kernelRadius.value = 4, this.overlayMaterial = this._getOverlayMaterial();
1277
- let o = Ue;
1278
- this.copyUniforms = ce.clone(o.uniforms), this.materialCopy = new k({
1279
- uniforms: this.copyUniforms,
1280
- vertexShader: o.vertexShader,
1281
- fragmentShader: o.fragmentShader,
1282
- blending: T,
1283
- depthTest: !1,
1284
- depthWrite: !1
1285
- }), this.enabled = !0, this.needsSwap = !1, this._oldClearColor = new d(), this.oldClearAlpha = 1, this._fsQuad = new He(null), this.tempPulseColor1 = new d(), this.tempPulseColor2 = new d(), this.textureMatrix = new C();
1286
- function s(e, t) {
1287
- let n = t.isPerspectiveCamera ? "perspective" : "orthographic";
1288
- return e.replace(/DEPTH_TO_VIEW_Z/g, n + "DepthToViewZ");
1289
- }
1290
- }
1291
- dispose() {
1292
- this.renderTargetMaskBuffer.dispose(), this.renderTargetDepthBuffer.dispose(), this.renderTargetMaskDownSampleBuffer.dispose(), this.renderTargetBlurBuffer1.dispose(), this.renderTargetBlurBuffer2.dispose(), this.renderTargetEdgeBuffer1.dispose(), this.renderTargetEdgeBuffer2.dispose(), this.depthMaterial.dispose(), this.prepareMaskMaterial.dispose(), this.edgeDetectionMaterial.dispose(), this.separableBlurMaterial1.dispose(), this.separableBlurMaterial2.dispose(), this.overlayMaterial.dispose(), this.materialCopy.dispose(), this._fsQuad.dispose();
1293
- }
1294
- setSize(e, t) {
1295
- this.renderTargetMaskBuffer.setSize(e, t), this.renderTargetDepthBuffer.setSize(e, t);
1296
- let n = Math.round(e / this.downSampleRatio), r = Math.round(t / this.downSampleRatio);
1297
- this.renderTargetMaskDownSampleBuffer.setSize(n, r), this.renderTargetBlurBuffer1.setSize(n, r), this.renderTargetEdgeBuffer1.setSize(n, r), this.separableBlurMaterial1.uniforms.texSize.value.set(n, r), n = Math.round(n / 2), r = Math.round(r / 2), this.renderTargetBlurBuffer2.setSize(n, r), this.renderTargetEdgeBuffer2.setSize(n, r), this.separableBlurMaterial2.uniforms.texSize.value.set(n, r);
1298
- }
1299
- render(t, n, r, i, a) {
1300
- if (this.selectedObjects.length > 0) {
1301
- t.getClearColor(this._oldClearColor), this.oldClearAlpha = t.getClearAlpha();
1302
- let n = t.autoClear;
1303
- t.autoClear = !1, a && t.state.buffers.stencil.setTest(!1), t.setClearColor(16777215, 1), this._updateSelectionCache(), this._changeVisibilityOfSelectedObjects(!1);
1304
- let i = this.renderScene.background, o = this.renderScene.overrideMaterial;
1305
- if (this.renderScene.background = null, this.renderScene.overrideMaterial = this.depthMaterial, t.setRenderTarget(this.renderTargetDepthBuffer), t.clear(), t.render(this.renderScene, this.renderCamera), this._changeVisibilityOfSelectedObjects(!0), this._visibilityCache.clear(), this._updateTextureMatrix(), this._changeVisibilityOfNonSelectedObjects(!1), this.renderScene.overrideMaterial = this.prepareMaskMaterial, this.prepareMaskMaterial.uniforms.cameraNearFar.value.set(this.renderCamera.near, this.renderCamera.far), this.prepareMaskMaterial.uniforms.depthTexture.value = this.renderTargetDepthBuffer.texture, this.prepareMaskMaterial.uniforms.textureMatrix.value = this.textureMatrix, t.setRenderTarget(this.renderTargetMaskBuffer), t.clear(), t.render(this.renderScene, this.renderCamera), this._changeVisibilityOfNonSelectedObjects(!0), this._visibilityCache.clear(), this._selectionCache.clear(), this.renderScene.background = i, this.renderScene.overrideMaterial = o, this._fsQuad.material = this.materialCopy, this.copyUniforms.tDiffuse.value = this.renderTargetMaskBuffer.texture, t.setRenderTarget(this.renderTargetMaskDownSampleBuffer), t.clear(), this._fsQuad.render(t), this.tempPulseColor1.copy(this.visibleEdgeColor), this.tempPulseColor2.copy(this.hiddenEdgeColor), this.pulsePeriod > 0) {
1306
- let e = 1.25 / 2 + Math.cos(performance.now() * .01 / this.pulsePeriod) * .75 / 2;
1307
- this.tempPulseColor1.multiplyScalar(e), this.tempPulseColor2.multiplyScalar(e);
1308
- }
1309
- this._fsQuad.material = this.edgeDetectionMaterial, this.edgeDetectionMaterial.uniforms.maskTexture.value = this.renderTargetMaskDownSampleBuffer.texture, this.edgeDetectionMaterial.uniforms.texSize.value.set(this.renderTargetMaskDownSampleBuffer.width, this.renderTargetMaskDownSampleBuffer.height), this.edgeDetectionMaterial.uniforms.visibleEdgeColor.value = this.tempPulseColor1, this.edgeDetectionMaterial.uniforms.hiddenEdgeColor.value = this.tempPulseColor2, t.setRenderTarget(this.renderTargetEdgeBuffer1), t.clear(), this._fsQuad.render(t), this._fsQuad.material = this.separableBlurMaterial1, this.separableBlurMaterial1.uniforms.colorTexture.value = this.renderTargetEdgeBuffer1.texture, this.separableBlurMaterial1.uniforms.direction.value = e.BlurDirectionX, this.separableBlurMaterial1.uniforms.kernelRadius.value = this.edgeThickness, t.setRenderTarget(this.renderTargetBlurBuffer1), t.clear(), this._fsQuad.render(t), this.separableBlurMaterial1.uniforms.colorTexture.value = this.renderTargetBlurBuffer1.texture, this.separableBlurMaterial1.uniforms.direction.value = e.BlurDirectionY, t.setRenderTarget(this.renderTargetEdgeBuffer1), t.clear(), this._fsQuad.render(t), this._fsQuad.material = this.separableBlurMaterial2, this.separableBlurMaterial2.uniforms.colorTexture.value = this.renderTargetEdgeBuffer1.texture, this.separableBlurMaterial2.uniforms.direction.value = e.BlurDirectionX, t.setRenderTarget(this.renderTargetBlurBuffer2), t.clear(), this._fsQuad.render(t), this.separableBlurMaterial2.uniforms.colorTexture.value = this.renderTargetBlurBuffer2.texture, this.separableBlurMaterial2.uniforms.direction.value = e.BlurDirectionY, t.setRenderTarget(this.renderTargetEdgeBuffer2), t.clear(), this._fsQuad.render(t), this._fsQuad.material = this.overlayMaterial, this.overlayMaterial.uniforms.maskTexture.value = this.renderTargetMaskBuffer.texture, this.overlayMaterial.uniforms.edgeTexture1.value = this.renderTargetEdgeBuffer1.texture, this.overlayMaterial.uniforms.edgeTexture2.value = this.renderTargetEdgeBuffer2.texture, this.overlayMaterial.uniforms.patternTexture.value = this.patternTexture, this.overlayMaterial.uniforms.edgeStrength.value = this.edgeStrength, this.overlayMaterial.uniforms.edgeGlow.value = this.edgeGlow, this.overlayMaterial.uniforms.usePatternTexture.value = this.usePatternTexture, a && t.state.buffers.stencil.setTest(!0), t.setRenderTarget(r), this._fsQuad.render(t), t.setClearColor(this._oldClearColor, this.oldClearAlpha), t.autoClear = n;
1310
- }
1311
- this.renderToScreen && (this._fsQuad.material = this.materialCopy, this.copyUniforms.tDiffuse.value = r.texture, t.setRenderTarget(null), this._fsQuad.render(t));
1312
- }
1313
- _updateSelectionCache() {
1314
- let e = this._selectionCache;
1315
- function t(t) {
1316
- t.isMesh && e.add(t);
1317
- }
1318
- e.clear();
1319
- for (let e = 0; e < this.selectedObjects.length; e++) this.selectedObjects[e].traverse(t);
1320
- }
1321
- _changeVisibilityOfSelectedObjects(e) {
1322
- let t = this._visibilityCache;
1323
- for (let n of this._selectionCache) e === !0 ? n.visible = t.get(n) : (t.set(n, n.visible), n.visible = e);
1324
- }
1325
- _changeVisibilityOfNonSelectedObjects(e) {
1326
- let t = this._visibilityCache, n = this._selectionCache;
1327
- function r(r) {
1328
- if (r.isPoints || r.isLine || r.isLine2) e === !0 ? r.visible = t.get(r) : (t.set(r, r.visible), r.visible = e);
1329
- else if ((r.isMesh || r.isSprite) && !n.has(r)) {
1330
- let n = r.visible;
1331
- (e === !1 || t.get(r) === !0) && (r.visible = e), t.set(r, n);
1332
- }
1333
- }
1334
- this.renderScene.traverse(r);
1335
- }
1336
- _updateTextureMatrix() {
1337
- this.textureMatrix.set(.5, 0, 0, .5, 0, .5, 0, .5, 0, 0, .5, .5, 0, 0, 0, 1), this.textureMatrix.multiply(this.renderCamera.projectionMatrix), this.textureMatrix.multiply(this.renderCamera.matrixWorldInverse);
1338
- }
1339
- _getPrepareMaskMaterial() {
1340
- return new k({
1341
- uniforms: {
1342
- depthTexture: { value: null },
1343
- cameraNearFar: { value: new j(.5, .5) },
1344
- textureMatrix: { value: null }
1345
- },
1346
- vertexShader: "#include <batching_pars_vertex>\n #include <morphtarget_pars_vertex>\n #include <skinning_pars_vertex>\n\n varying vec4 projTexCoord;\n varying vec4 vPosition;\n uniform mat4 textureMatrix;\n\n void main() {\n\n #include <batching_vertex>\n #include <skinbase_vertex>\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n\n vPosition = mvPosition;\n\n vec4 worldPosition = vec4( transformed, 1.0 );\n\n #ifdef USE_INSTANCING\n\n worldPosition = instanceMatrix * worldPosition;\n\n #endif\n\n worldPosition = modelMatrix * worldPosition;\n\n projTexCoord = textureMatrix * worldPosition;\n\n }",
1347
- fragmentShader: "#include <packing>\n varying vec4 vPosition;\n varying vec4 projTexCoord;\n uniform sampler2D depthTexture;\n uniform vec2 cameraNearFar;\n\n void main() {\n\n float depth = unpackRGBAToDepth(texture2DProj( depthTexture, projTexCoord ));\n float viewZ = - DEPTH_TO_VIEW_Z( depth, cameraNearFar.x, cameraNearFar.y );\n float depthTest = (-vPosition.z > viewZ) ? 1.0 : 0.0;\n gl_FragColor = vec4(0.0, depthTest, 1.0, 1.0);\n\n }"
1348
- });
1349
- }
1350
- _getEdgeDetectionMaterial() {
1351
- return new k({
1352
- uniforms: {
1353
- maskTexture: { value: null },
1354
- texSize: { value: new j(.5, .5) },
1355
- visibleEdgeColor: { value: new M(1, 1, 1) },
1356
- hiddenEdgeColor: { value: new M(1, 1, 1) }
1357
- },
1358
- vertexShader: "varying vec2 vUv;\n\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",
1359
- fragmentShader: "varying vec2 vUv;\n\n uniform sampler2D maskTexture;\n uniform vec2 texSize;\n uniform vec3 visibleEdgeColor;\n uniform vec3 hiddenEdgeColor;\n\n void main() {\n vec2 invSize = 1.0 / texSize;\n vec4 uvOffset = vec4(1.0, 0.0, 0.0, 1.0) * vec4(invSize, invSize);\n vec4 c1 = texture2D( maskTexture, vUv + uvOffset.xy);\n vec4 c2 = texture2D( maskTexture, vUv - uvOffset.xy);\n vec4 c3 = texture2D( maskTexture, vUv + uvOffset.yw);\n vec4 c4 = texture2D( maskTexture, vUv - uvOffset.yw);\n float diff1 = (c1.r - c2.r)*0.5;\n float diff2 = (c3.r - c4.r)*0.5;\n float d = length( vec2(diff1, diff2) );\n float a1 = min(c1.g, c2.g);\n float a2 = min(c3.g, c4.g);\n float visibilityFactor = min(a1, a2);\n vec3 edgeColor = 1.0 - visibilityFactor > 0.001 ? visibleEdgeColor : hiddenEdgeColor;\n gl_FragColor = vec4(edgeColor, 1.0) * vec4(d);\n }"
1360
- });
1361
- }
1362
- _getSeparableBlurMaterial(e) {
1363
- return new k({
1364
- defines: { MAX_RADIUS: e },
1365
- uniforms: {
1366
- colorTexture: { value: null },
1367
- texSize: { value: new j(.5, .5) },
1368
- direction: { value: new j(.5, .5) },
1369
- kernelRadius: { value: 1 }
1370
- },
1371
- vertexShader: "varying vec2 vUv;\n\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",
1372
- fragmentShader: "#include <common>\n varying vec2 vUv;\n uniform sampler2D colorTexture;\n uniform vec2 texSize;\n uniform vec2 direction;\n uniform float kernelRadius;\n\n float gaussianPdf(in float x, in float sigma) {\n return 0.39894 * exp( -0.5 * x * x/( sigma * sigma))/sigma;\n }\n\n void main() {\n vec2 invSize = 1.0 / texSize;\n float sigma = kernelRadius/2.0;\n float weightSum = gaussianPdf(0.0, sigma);\n vec4 diffuseSum = texture2D( colorTexture, vUv) * weightSum;\n vec2 delta = direction * invSize * kernelRadius/float(MAX_RADIUS);\n vec2 uvOffset = delta;\n for( int i = 1; i <= MAX_RADIUS; i ++ ) {\n float x = kernelRadius * float(i) / float(MAX_RADIUS);\n float w = gaussianPdf(x, sigma);\n vec4 sample1 = texture2D( colorTexture, vUv + uvOffset);\n vec4 sample2 = texture2D( colorTexture, vUv - uvOffset);\n diffuseSum += ((sample1 + sample2) * w);\n weightSum += (2.0 * w);\n uvOffset += delta;\n }\n gl_FragColor = diffuseSum/weightSum;\n }"
1373
- });
1374
- }
1375
- _getOverlayMaterial() {
1376
- return new k({
1377
- uniforms: {
1378
- maskTexture: { value: null },
1379
- edgeTexture1: { value: null },
1380
- edgeTexture2: { value: null },
1381
- patternTexture: { value: null },
1382
- edgeStrength: { value: 1 },
1383
- edgeGlow: { value: 1 },
1384
- usePatternTexture: { value: 0 }
1385
- },
1386
- vertexShader: "varying vec2 vUv;\n\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",
1387
- fragmentShader: "varying vec2 vUv;\n\n uniform sampler2D maskTexture;\n uniform sampler2D edgeTexture1;\n uniform sampler2D edgeTexture2;\n uniform sampler2D patternTexture;\n uniform float edgeStrength;\n uniform float edgeGlow;\n uniform bool usePatternTexture;\n\n void main() {\n vec4 edgeValue1 = texture2D(edgeTexture1, vUv);\n vec4 edgeValue2 = texture2D(edgeTexture2, vUv);\n vec4 maskColor = texture2D(maskTexture, vUv);\n vec4 patternColor = texture2D(patternTexture, 6.0 * vUv);\n float visibilityFactor = 1.0 - maskColor.g > 0.0 ? 1.0 : 0.5;\n vec4 edgeValue = edgeValue1 + edgeValue2 * edgeGlow;\n vec4 finalColor = edgeStrength * maskColor.r * edgeValue;\n if(usePatternTexture)\n finalColor += + visibilityFactor * (1.0 - maskColor.r) * (1.0 - patternColor.r);\n gl_FragColor = finalColor;\n }",
1388
- blending: c,
1389
- depthTest: !1,
1390
- depthWrite: !1,
1391
- transparent: !0
1392
- });
1393
- }
1394
- };
1395
- We.BlurDirectionX = new j(1, 0), We.BlurDirectionY = new j(0, 1);
6
+ import { BoxGeometry as c, BufferGeometry as l, EdgesGeometry as u, Float32BufferAttribute as d, Group as f, Line as p, LineBasicMaterial as m, LineLoop as h, LineSegments as g, Matrix4 as _, Mesh as v, Object3D as y, Vector2 as b, Vector3 as x } from "three";
7
+ import { FlyControls as S } from "three/examples/jsm/controls/FlyControls.js";
8
+ import { TransformControls as C } from "three/examples/jsm/controls/TransformControls.js";
9
+ import { OutlinePass as w } from "three/examples/jsm/postprocessing/OutlinePass.js";
10
+ import { lightType as T, primitiveType as E } from "@mavonengine/core/Scene/builtinSceneObjects";
11
+ import { SCENE_FORMAT_VERSION as D } from "@mavonengine/core/Scene/types";
1396
12
  // src/Editor/demoScene.ts
1397
- var Z = "main";
1398
- function Q(e, t, n, r) {
13
+ var O = "main";
14
+ function k(e, t, n, r) {
1399
15
  return {
1400
16
  id: e,
1401
17
  type: t,
@@ -1415,19 +31,19 @@ function Q(e, t, n, r) {
1415
31
  ...r ? { props: r } : {}
1416
32
  };
1417
33
  }
1418
- function Ge() {
1419
- let e = 5 * .707, t = (e, t, n) => Q(e, ue(t), n, { castShadow: !0 });
34
+ function A() {
35
+ let e = 5 * .707, t = (e, t, n) => k(e, E(t), n, { castShadow: !0 });
1420
36
  return {
1421
- version: de,
1422
- name: Z,
37
+ version: D,
38
+ name: O,
1423
39
  settings: {},
1424
40
  objects: [
1425
- Q("ambient_light", le("AmbientLight"), [
41
+ k("ambient_light", T("AmbientLight"), [
1426
42
  0,
1427
43
  5,
1428
44
  0
1429
45
  ]),
1430
- Q("sun", le("DirectionalLightShadow"), [
46
+ k("sun", T("DirectionalLightShadow"), [
1431
47
  10,
1432
48
  15,
1433
49
  5
@@ -1435,7 +51,7 @@ function Ge() {
1435
51
  intensity: 5,
1436
52
  castShadow: !0
1437
53
  }),
1438
- Q("ground", ue("Plane"), [
54
+ k("ground", E("Plane"), [
1439
55
  0,
1440
56
  0,
1441
57
  0
@@ -1494,7 +110,7 @@ function Ge() {
1494
110
  };
1495
111
  }
1496
112
  // src/Editor/Network/SyncStore.ts
1497
- var Ke = class {
113
+ var j = class {
1498
114
  constructor(e = 250, n = t) {
1499
115
  this.intervalMs = e, this.load = n, this.state = {}, this.listeners = /* @__PURE__ */ new Set(), this.loading = !1, this.get = () => this.state, this.subscribe = (e) => (this.listeners.add(e), this.timer || (this.timer = setInterval(() => void this.refresh(), this.intervalMs), this.refresh()), () => {
1500
116
  this.listeners.delete(e), !this.listeners.size && this.timer && (clearInterval(this.timer), this.timer = void 0);
@@ -1515,12 +131,12 @@ var Ke = class {
1515
131
  this.listeners.forEach((e) => e());
1516
132
  }
1517
133
  }
1518
- }, qe = {
134
+ }, M = {
1519
135
  synced: 5163440,
1520
136
  stale: 13537656,
1521
137
  untracked: 8947848
1522
- }, Je = 31436, Ye = 16777215, Xe = 16009031, Ze = 96, Qe = 2e3, $e = .01, et = "editor-network-overlay";
1523
- function tt(e, t, n, r) {
138
+ }, N = 31436, P = 16777215, F = 16009031, I = 96, L = 2e3, R = .01, z = "editor-network-overlay";
139
+ function B(e, t, n, r) {
1524
140
  if (n) {
1525
141
  let t = r ? n.players.find((e) => e.id === r) : void 0;
1526
142
  if (t) return t.id === e.id || t.tracked.includes(e.id) ? "synced" : "untracked";
@@ -1529,7 +145,7 @@ function tt(e, t, n, r) {
1529
145
  }
1530
146
  return t !== null && t - e.tick > 1 ? "stale" : "synced";
1531
147
  }
1532
- function nt() {
148
+ function V() {
1533
149
  let e = {
1534
150
  ghosts: !1,
1535
151
  rings: !1,
@@ -1538,27 +154,27 @@ function nt() {
1538
154
  try {
1539
155
  return {
1540
156
  ...e,
1541
- ...JSON.parse(localStorage.getItem(et) ?? "{}"),
157
+ ...JSON.parse(localStorage.getItem(z) ?? "{}"),
1542
158
  viewAs: null
1543
159
  };
1544
160
  } catch {
1545
161
  return e;
1546
162
  }
1547
163
  }
1548
- var rt = class extends s {
1549
- constructor(e = new Ke(), t = nt()) {
1550
- super(), this.group = new v(), this.ghosts = /* @__PURE__ */ new Map(), this.rings = /* @__PURE__ */ new Map(), this.errorMaterial = $(Xe), this.ringMaterial = $(Je), this.ringSelectedMaterial = $(Ye), this.sync = e, this._options = t, this.group.name = "NetworkOverlay", this.group.userData.isEditorInternal = !0;
1551
- let n = new l(1, 1, 1);
1552
- n.translate(0, .5, 0), this.boxGeometry = new h(n), n.dispose();
164
+ var H = class extends s {
165
+ constructor(e = new j(), t = V()) {
166
+ super(), this.group = new f(), this.ghosts = /* @__PURE__ */ new Map(), this.rings = /* @__PURE__ */ new Map(), this.errorMaterial = U(F), this.ringMaterial = U(N), this.ringSelectedMaterial = U(P), this.sync = e, this._options = t, this.group.name = "NetworkOverlay", this.group.userData.isEditorInternal = !0;
167
+ let n = new c(1, 1, 1);
168
+ n.translate(0, .5, 0), this.boxGeometry = new u(n), n.dispose();
1553
169
  let r = [];
1554
- for (let e = 0; e < Ze; e++) {
1555
- let t = e / Ze * Math.PI * 2;
170
+ for (let e = 0; e < I; e++) {
171
+ let t = e / I * Math.PI * 2;
1556
172
  r.push(Math.cos(t), 0, Math.sin(t));
1557
173
  }
1558
- this.ringGeometry = new u().setAttribute("position", new _(r, 3)), this.materials = {
1559
- synced: $(qe.synced),
1560
- stale: $(qe.stale),
1561
- untracked: $(qe.untracked)
174
+ this.ringGeometry = new l().setAttribute("position", new d(r, 3)), this.materials = {
175
+ synced: U(M.synced),
176
+ stale: U(M.stale),
177
+ untracked: U(M.untracked)
1562
178
  }, this.applyOptions();
1563
179
  }
1564
180
  get options() {
@@ -1570,7 +186,7 @@ var rt = class extends s {
1570
186
  ...e
1571
187
  };
1572
188
  try {
1573
- localStorage.setItem(et, JSON.stringify({
189
+ localStorage.setItem(z, JSON.stringify({
1574
190
  ghosts: this._options.ghosts,
1575
191
  rings: this._options.rings
1576
192
  }));
@@ -1591,12 +207,12 @@ var rt = class extends s {
1591
207
  let e = a.instance().network, t = this._options.ghosts ? e?.serverView : void 0, { sync: n } = this.sync.get(), r = a.instance().world.entities.items, i = performance.now(), o = /* @__PURE__ */ new Set();
1592
208
  for (let e of t?.entities.values() ?? []) {
1593
209
  let a = r.get(e.id);
1594
- if (!a && i - e.receivedAt > Qe) continue;
210
+ if (!a && i - e.receivedAt > L) continue;
1595
211
  o.add(e.id);
1596
212
  let s = this.ghosts.get(e.id) ?? this.createGhost(e.id);
1597
- s.box.position.set(e.position.x, e.position.y, e.position.z), s.box.rotation.set(e.rotation.x, e.rotation.y, e.rotation.z), s.box.scale.set(e.scale.x, e.scale.y * 2, e.scale.z), s.box.material = this.materials[tt(e, t.tick, n, this._options.viewAs)];
213
+ s.box.position.set(e.position.x, e.position.y, e.position.z), s.box.rotation.set(e.rotation.x, e.rotation.y, e.rotation.z), s.box.scale.set(e.scale.x, e.scale.y * 2, e.scale.z), s.box.material = this.materials[B(e, t.tick, n, this._options.viewAs)];
1598
214
  let c = a ? a.position.distanceTo(s.box.position) : 0;
1599
- if (s.error.visible = c > $e, s.error.visible) {
215
+ if (s.error.visible = c > R, s.error.visible) {
1600
216
  let t = s.error.geometry.getAttribute("position");
1601
217
  t.setXYZ(0, e.position.x, e.position.y, e.position.z), t.setXYZ(1, a.position.x, a.position.y, a.position.z), t.needsUpdate = !0;
1602
218
  }
@@ -1604,16 +220,16 @@ var rt = class extends s {
1604
220
  for (let [e, t] of this.ghosts) o.has(e) || (this.group.remove(t.box, t.error), t.error.geometry.dispose(), this.ghosts.delete(e));
1605
221
  }
1606
222
  createGhost(e) {
1607
- let t = it(new S(this.boxGeometry, this.materials.synced));
223
+ let t = W(new g(this.boxGeometry, this.materials.synced));
1608
224
  t.name = `ServerGhost:${e}`;
1609
- let n = new u().setAttribute("position", new _([
225
+ let n = new l().setAttribute("position", new d([
1610
226
  0,
1611
227
  0,
1612
228
  0,
1613
229
  0,
1614
230
  0,
1615
231
  0
1616
- ], 3)), r = it(new b(n, this.errorMaterial));
232
+ ], 3)), r = W(new p(n, this.errorMaterial));
1617
233
  r.frustumCulled = !1, r.visible = !1;
1618
234
  let i = {
1619
235
  box: t,
@@ -1626,7 +242,7 @@ var rt = class extends s {
1626
242
  for (let r of t) {
1627
243
  n.add(r.id);
1628
244
  let t = this.rings.get(r.id);
1629
- t || (t = it(new x(this.ringGeometry, this.ringMaterial)), t.name = `SyncRing:${r.id}`, this.rings.set(r.id, t), this.group.add(t)), t.position.set(r.position.x, r.position.y + .05, r.position.z), t.scale.setScalar(e.syncDistance), t.material = r.id === this._options.viewAs ? this.ringSelectedMaterial : this.ringMaterial;
245
+ t || (t = W(new h(this.ringGeometry, this.ringMaterial)), t.name = `SyncRing:${r.id}`, this.rings.set(r.id, t), this.group.add(t)), t.position.set(r.position.x, r.position.y + .05, r.position.z), t.scale.setScalar(e.syncDistance), t.material = r.id === this._options.viewAs ? this.ringSelectedMaterial : this.ringMaterial;
1630
246
  }
1631
247
  for (let [e, t] of this.rings) n.has(e) || (this.group.remove(t), this.rings.delete(e));
1632
248
  }
@@ -1640,8 +256,8 @@ var rt = class extends s {
1640
256
  this.unsubscribe?.(), this.unsubscribe = void 0, this.group.removeFromParent(), this.ghosts.forEach((e) => e.error.geometry.dispose()), this.ghosts.clear(), this.rings.clear(), this.boxGeometry.dispose(), this.ringGeometry.dispose(), Object.values(this.materials).forEach((e) => e.dispose()), this.errorMaterial.dispose(), this.ringMaterial.dispose(), this.ringSelectedMaterial.dispose();
1641
257
  }
1642
258
  };
1643
- function $(e) {
1644
- return new ee({
259
+ function U(e) {
260
+ return new m({
1645
261
  color: e,
1646
262
  depthTest: !1,
1647
263
  depthWrite: !1,
@@ -1649,11 +265,11 @@ function $(e) {
1649
265
  toneMapped: !1
1650
266
  });
1651
267
  }
1652
- function it(e) {
268
+ function W(e) {
1653
269
  return e.raycast = () => {}, e.renderOrder = 999, e.userData.isEditorInternal = !0, e;
1654
270
  }
1655
271
  // src/Editor.ts
1656
- var at = class t extends s {
272
+ var G = class t extends s {
1657
273
  static registerPanel(e) {
1658
274
  return r(e);
1659
275
  }
@@ -1665,14 +281,14 @@ var at = class t extends s {
1665
281
  constructor() {
1666
282
  super(), this.activeToolMode = "translate", this.shadeMode = "solid", this.originalMaterials = /* @__PURE__ */ new Map(), this.shadeOverrideMaterials = /* @__PURE__ */ new Map(), this.flatColors = /* @__PURE__ */ new Map(), this.helpers = [], this.lightHelpers = [], this._showHelpers = !0, this.abort = new AbortController(), this.activeAssetCategory = "Object", a.instance().editor = this, a.instance().logger?.info("Booting Editor"), a.instance().trigger("editorBoot", this), a.instance().trigger("uiDestroy", this);
1667
283
  let e = a.instance().activeScene;
1668
- e ? e.rebuild() : this.clearGame(), this.initEditorScene(), e || this.openDefaultScene(), a.instance().contextMenuAbort.abort(), a.instance().uiRoot.innerHTML = "", a.instance().uiRoot.style.opacity = "1", document.title = "MavonEngine | Editor", document.getElementsByTagName("body")[0].removeAttribute("onContextMenu"), Promise.all([import("./mount-BfaV9yI_.mjs"), import("./global-l94NfB94.mjs").then((e) => e.t)]).then(([{ mountEditorUI: e }]) => {
284
+ e ? e.rebuild() : this.clearGame(), this.initEditorScene(), e || this.openDefaultScene(), a.instance().contextMenuAbort.abort(), a.instance().uiRoot.innerHTML = "", a.instance().uiRoot.style.opacity = "1", document.title = "MavonEngine | Editor", document.getElementsByTagName("body")[0].removeAttribute("onContextMenu"), Promise.all([import("./mount-DAt7SAfm.mjs"), import("./global-CRVwkYpo.mjs").then((e) => e.t)]).then(([{ mountEditorUI: e }]) => {
1669
285
  this.reactRoot = e(a.instance().uiRoot);
1670
286
  }).catch((e) => {
1671
287
  a.instance().logger?.error(`The editor's UI could not be loaded: ${e?.stack ?? e}`);
1672
288
  });
1673
289
  }
1674
290
  initEditorScene() {
1675
- a.instance().camera.instance.position.set(20, 10, 20), a.instance().camera.instance.rotation.set(0, 0, 0), a.instance().camera.instance.rotateY(Math.PI / 360 * 90), a.instance().camera.instance.rotateX(Math.PI / 360 * -45), this.outlinePass = new We(new j(a.instance().sizes.width, a.instance().sizes.height), a.instance().scene, a.instance().camera.instance), a.instance().renderer.composer.addPass(this.outlinePass), this.initFlyControls(), this.networkOverlay = new rt(), this.watchScene(a.instance().activeScene), a.instance().on("sceneLoaded", (e) => {
291
+ a.instance().camera.instance.position.set(20, 10, 20), a.instance().camera.instance.rotation.set(0, 0, 0), a.instance().camera.instance.rotateY(Math.PI / 360 * 90), a.instance().camera.instance.rotateX(Math.PI / 360 * -45), this.outlinePass = new w(new b(a.instance().sizes.width, a.instance().sizes.height), a.instance().scene, a.instance().camera.instance), a.instance().renderer.composer.addPass(this.outlinePass), this.initFlyControls(), this.networkOverlay = new H(), this.watchScene(a.instance().activeScene), a.instance().on("sceneLoaded", (e) => {
1676
292
  this.deselect(), this.watchScene(e), this.trigger("sceneChanged");
1677
293
  }), window.addEventListener("keydown", (e) => {
1678
294
  (e.ctrlKey || e.metaKey) && e.code === "KeyS" && (e.preventDefault(), this.saveScene());
@@ -1698,7 +314,7 @@ var at = class t extends s {
1698
314
  this.shadeMode = e, n(a.instance().scene, e, this.originalMaterials, this.shadeOverrideMaterials, this.flatColors);
1699
315
  }
1700
316
  initFlyControls() {
1701
- this.flyControls = new he(a.instance().camera.instance, a.instance().canvas), this.flyControls.autoForward = !1, this.flyControls.dragToLook = !0, this.flyControls.movementSpeed = 10, this.flyControls.rollSpeed = .5;
317
+ this.flyControls = new S(a.instance().camera.instance, a.instance().canvas), this.flyControls.autoForward = !1, this.flyControls.dragToLook = !0, this.flyControls.movementSpeed = 10, this.flyControls.rollSpeed = .5;
1702
318
  }
1703
319
  handleItemDelete() {
1704
320
  a.instance().input.on("keydown", (e) => {
@@ -1706,7 +322,7 @@ var at = class t extends s {
1706
322
  let e = this.activeItem;
1707
323
  for (; e.parent && e.parent !== a.instance().scene;) e = e.parent;
1708
324
  e.traverse((e) => {
1709
- e instanceof w && (e.geometry?.dispose(), Array.isArray(e.material) ? e.material.forEach((e) => e.dispose()) : e.material?.dispose());
325
+ e instanceof v && (e.geometry?.dispose(), Array.isArray(e.material) ? e.material.forEach((e) => e.dispose()) : e.material?.dispose());
1710
326
  }), this.deselect();
1711
327
  let t = i.from(e), n = a.instance().activeScene, r = n?.entryOfObject3D(e) ?? (t?.owner && n?.getEntries().find((e) => e.object === t.owner));
1712
328
  n && r ? n.remove(r.data.id) : t?.owner ? t.owner.destroy() : (t && (t.dispose(), this.helpers = this.helpers.filter((e) => e !== t)), a.instance().scene.remove(e)), this.trigger("sceneChanged");
@@ -1723,12 +339,12 @@ var at = class t extends s {
1723
339
  if (e.button === 0) {
1724
340
  if (this.transformControls && (this.transformControls.dragging || this.transformControls.axis !== null)) return;
1725
341
  let e = a.instance().input.getPointerWorldPosition(void 0, null, !0);
1726
- e instanceof E ? this.selectObject(e) : this.deselect();
342
+ e instanceof y ? this.selectObject(e) : this.deselect();
1727
343
  }
1728
344
  }
1729
345
  handleHelperTool() {
1730
346
  if (!this.transformControls) {
1731
- this.transformControls = new De(a.instance().camera.instance, a.instance().canvas), this.transformControls.addEventListener("dragging-changed", (e) => {
347
+ this.transformControls = new C(a.instance().camera.instance, a.instance().canvas), this.transformControls.addEventListener("dragging-changed", (e) => {
1732
348
  this.flyControls.enabled = !e.value, e.value || this.initFlyControls();
1733
349
  });
1734
350
  let e = this.transformControls.getHelper();
@@ -1771,9 +387,9 @@ var at = class t extends s {
1771
387
  }
1772
388
  async openDefaultScene() {
1773
389
  try {
1774
- await a.instance().openScene(Z);
390
+ await a.instance().openScene(O);
1775
391
  } catch {
1776
- a.instance().logger?.info(`No scenes/${Z}.json yet, opening a demo scene. Save it with Ctrl+S`), a.instance().loadScene(Ge(), Z);
392
+ a.instance().logger?.info(`No scenes/${O}.json yet, opening a demo scene. Save it with Ctrl+S`), a.instance().loadScene(A(), O);
1777
393
  }
1778
394
  }
1779
395
  watchScene(e) {
@@ -1781,7 +397,7 @@ var at = class t extends s {
1781
397
  }
1782
398
  clearGame() {
1783
399
  a.instance().world.destroy(), a.instance().world.entities.items.clear(), a.instance().scene.traverse((e) => {
1784
- e instanceof w && (e.geometry?.dispose(), Array.isArray(e.material) ? e.material.forEach((e) => e.dispose()) : e.material?.dispose());
400
+ e instanceof v && (e.geometry?.dispose(), Array.isArray(e.material) ? e.material.forEach((e) => e.dispose()) : e.material?.dispose());
1785
401
  }), a.instance().scene.clear();
1786
402
  }
1787
403
  addHelper(e) {
@@ -1806,11 +422,11 @@ var at = class t extends s {
1806
422
  }
1807
423
  updateCamera(e) {
1808
424
  this.flyControls.update(e);
1809
- let t = a.instance().camera.instance, n = new M();
1810
- t.getWorldDirection(n), t.quaternion.setFromRotationMatrix(new C().lookAt(new M(), n, new M(0, 1, 0)));
425
+ let t = a.instance().camera.instance, n = new x();
426
+ t.getWorldDirection(n), t.quaternion.setFromRotationMatrix(new _().lookAt(new x(), n, new x(0, 1, 0)));
1811
427
  }
1812
428
  destroy() {
1813
429
  this.abort.abort(), this.reactRoot.unmount(), this.outlinePass.dispose(), this.networkOverlay.dispose(), this.shadeOverrideMaterials.forEach((e) => e.dispose()), this.shadeOverrideMaterials.clear(), this.originalMaterials.clear(), this.flatColors.clear();
1814
430
  }
1815
431
  };
1816
- export { at as default, r as registerEditorPanel, e as unregisterEditorPanel };
432
+ export { G as default, r as registerEditorPanel, e as unregisterEditorPanel };