@mavonengine/editor 0.0.2 → 0.0.3

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.
@@ -0,0 +1,1333 @@
1
+ import { Quaternion as S, Controls as Ee, Vector3 as l, Raycaster as Le, Object3D as le, MeshBasicMaterial as me, LineBasicMaterial as Xe, CylinderGeometry as g, BoxGeometry as v, BufferGeometry as pe, Float32BufferAttribute as he, Mesh as o, OctahedronGeometry as se, Line as B, TorusGeometry as j, SphereGeometry as He, Euler as Oe, Matrix4 as ce, PlaneGeometry as Ye, DoubleSide as fe, OrthographicCamera as Ze, Color as F, Vector2 as k, WebGLRenderTarget as X, MeshDepthMaterial as Ue, RGBADepthPacking as je, NoBlending as we, HalfFloatType as U, UniformsUtils as Fe, ShaderMaterial as V, AdditiveBlending as Ve } from "three";
2
+ import Ge from "@mavonengine/core/Editor/EditorHelper";
3
+ import c from "@mavonengine/core/Game";
4
+ import { AmbientLightPrimitive as We, DirectionalLightShadowPrimitive as qe } from "@mavonengine/core/Prefab/Lights/index";
5
+ import { PlanePrimitive as Ke, BoxPrimitive as Ne, SpherePrimitive as $e, ConePrimitive as Je, CylinderPrimitive as et, OctahedronPrimitive as tt, DodecahedronPrimitive as it, CapsulePrimitive as st, IcosahedronPrimitive as nt, TorusKnotPrimitive as at } from "@mavonengine/core/Prefab/Primitives/index";
6
+ import rt from "@mavonengine/core/Utils/EventEmitter";
7
+ const ot = { type: "change" }, ge = 1e-6, ye = new S();
8
+ class lt extends Ee {
9
+ /**
10
+ * Constructs a new controls instance.
11
+ *
12
+ * @param {Object3D} object - The object that is managed by the controls.
13
+ * @param {?HTMLDOMElement} domElement - The HTML element used for event listeners.
14
+ */
15
+ constructor(e, t = null) {
16
+ super(e, t), this.movementSpeed = 1, this.rollSpeed = 5e-3, this.dragToLook = !1, this.autoForward = !1, this._moveState = { up: 0, down: 0, left: 0, right: 0, forward: 0, back: 0, pitchUp: 0, pitchDown: 0, yawLeft: 0, yawRight: 0, rollLeft: 0, rollRight: 0 }, this._moveVector = new l(0, 0, 0), this._rotationVector = new l(0, 0, 0), this._lastQuaternion = new S(), this._lastPosition = new l(), this._status = 0, this._onKeyDown = ht.bind(this), this._onKeyUp = ct.bind(this), this._onPointerMove = dt.bind(this), this._onPointerDown = ut.bind(this), this._onPointerUp = pt.bind(this), this._onPointerCancel = ft.bind(this), this._onContextMenu = mt.bind(this), t !== null && this.connect(t);
17
+ }
18
+ connect(e) {
19
+ 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);
20
+ }
21
+ disconnect() {
22
+ 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);
23
+ }
24
+ dispose() {
25
+ this.disconnect();
26
+ }
27
+ update(e) {
28
+ if (this.enabled === !1) return;
29
+ const t = this.object, n = e * this.movementSpeed, s = e * this.rollSpeed;
30
+ t.translateX(this._moveVector.x * n), t.translateY(this._moveVector.y * n), t.translateZ(this._moveVector.z * n), ye.set(this._rotationVector.x * s, this._rotationVector.y * s, this._rotationVector.z * s, 1).normalize(), t.quaternion.multiply(ye), (this._lastPosition.distanceToSquared(t.position) > ge || 8 * (1 - this._lastQuaternion.dot(t.quaternion)) > ge) && (this.dispatchEvent(ot), this._lastQuaternion.copy(t.quaternion), this._lastPosition.copy(t.position));
31
+ }
32
+ // private
33
+ _updateMovementVector() {
34
+ const e = this._moveState.forward || this.autoForward && !this._moveState.back ? 1 : 0;
35
+ 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;
36
+ }
37
+ _updateRotationVector() {
38
+ 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;
39
+ }
40
+ _getContainerDimensions() {
41
+ return this.domElement != document ? {
42
+ size: [this.domElement.offsetWidth, this.domElement.offsetHeight],
43
+ offset: [this.domElement.offsetLeft, this.domElement.offsetTop]
44
+ } : {
45
+ size: [window.innerWidth, window.innerHeight],
46
+ offset: [0, 0]
47
+ };
48
+ }
49
+ }
50
+ function ht(h) {
51
+ if (!(h.altKey || this.enabled === !1)) {
52
+ switch (h.code) {
53
+ case "ShiftLeft":
54
+ case "ShiftRight":
55
+ this.movementSpeedMultiplier = 0.1;
56
+ break;
57
+ case "KeyW":
58
+ this._moveState.forward = 1;
59
+ break;
60
+ case "KeyS":
61
+ this._moveState.back = 1;
62
+ break;
63
+ case "KeyA":
64
+ this._moveState.left = 1;
65
+ break;
66
+ case "KeyD":
67
+ this._moveState.right = 1;
68
+ break;
69
+ case "KeyR":
70
+ this._moveState.up = 1;
71
+ break;
72
+ case "KeyF":
73
+ this._moveState.down = 1;
74
+ break;
75
+ case "ArrowUp":
76
+ this._moveState.pitchUp = 1;
77
+ break;
78
+ case "ArrowDown":
79
+ this._moveState.pitchDown = 1;
80
+ break;
81
+ case "ArrowLeft":
82
+ this._moveState.yawLeft = 1;
83
+ break;
84
+ case "ArrowRight":
85
+ this._moveState.yawRight = 1;
86
+ break;
87
+ case "KeyQ":
88
+ this._moveState.rollLeft = 1;
89
+ break;
90
+ case "KeyE":
91
+ this._moveState.rollRight = 1;
92
+ break;
93
+ }
94
+ this._updateMovementVector(), this._updateRotationVector();
95
+ }
96
+ }
97
+ function ct(h) {
98
+ if (this.enabled !== !1) {
99
+ switch (h.code) {
100
+ case "ShiftLeft":
101
+ case "ShiftRight":
102
+ this.movementSpeedMultiplier = 1;
103
+ break;
104
+ case "KeyW":
105
+ this._moveState.forward = 0;
106
+ break;
107
+ case "KeyS":
108
+ this._moveState.back = 0;
109
+ break;
110
+ case "KeyA":
111
+ this._moveState.left = 0;
112
+ break;
113
+ case "KeyD":
114
+ this._moveState.right = 0;
115
+ break;
116
+ case "KeyR":
117
+ this._moveState.up = 0;
118
+ break;
119
+ case "KeyF":
120
+ this._moveState.down = 0;
121
+ break;
122
+ case "ArrowUp":
123
+ this._moveState.pitchUp = 0;
124
+ break;
125
+ case "ArrowDown":
126
+ this._moveState.pitchDown = 0;
127
+ break;
128
+ case "ArrowLeft":
129
+ this._moveState.yawLeft = 0;
130
+ break;
131
+ case "ArrowRight":
132
+ this._moveState.yawRight = 0;
133
+ break;
134
+ case "KeyQ":
135
+ this._moveState.rollLeft = 0;
136
+ break;
137
+ case "KeyE":
138
+ this._moveState.rollRight = 0;
139
+ break;
140
+ }
141
+ this._updateMovementVector(), this._updateRotationVector();
142
+ }
143
+ }
144
+ function ut(h) {
145
+ if (this.enabled !== !1)
146
+ if (this.dragToLook)
147
+ this._status++;
148
+ else {
149
+ switch (h.button) {
150
+ case 0:
151
+ this._moveState.forward = 1;
152
+ break;
153
+ case 2:
154
+ this._moveState.back = 1;
155
+ break;
156
+ }
157
+ this._updateMovementVector();
158
+ }
159
+ }
160
+ function dt(h) {
161
+ if (this.enabled !== !1 && (!this.dragToLook || this._status > 0)) {
162
+ const e = this._getContainerDimensions(), t = e.size[0] / 2, n = e.size[1] / 2;
163
+ this._moveState.yawLeft = -(h.pageX - e.offset[0] - t) / t, this._moveState.pitchDown = (h.pageY - e.offset[1] - n) / n, this._updateRotationVector();
164
+ }
165
+ }
166
+ function pt(h) {
167
+ if (this.enabled !== !1) {
168
+ if (this.dragToLook)
169
+ this._status--, this._moveState.yawLeft = this._moveState.pitchDown = 0;
170
+ else {
171
+ switch (h.button) {
172
+ case 0:
173
+ this._moveState.forward = 0;
174
+ break;
175
+ case 2:
176
+ this._moveState.back = 0;
177
+ break;
178
+ }
179
+ this._updateMovementVector();
180
+ }
181
+ this._updateRotationVector();
182
+ }
183
+ }
184
+ function ft() {
185
+ 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());
186
+ }
187
+ function mt(h) {
188
+ this.enabled !== !1 && h.preventDefault();
189
+ }
190
+ const H = new Le(), m = new l(), I = new l(), p = new S(), _e = {
191
+ X: new l(1, 0, 0),
192
+ Y: new l(0, 1, 0),
193
+ Z: new l(0, 0, 1)
194
+ }, ue = { type: "change" }, Se = { type: "mouseDown", mode: null }, Me = { type: "mouseUp", mode: null }, xe = { type: "objectChange" };
195
+ class vt extends Ee {
196
+ /**
197
+ * Constructs a new controls instance.
198
+ *
199
+ * @param {Camera} camera - The camera of the rendered scene.
200
+ * @param {?HTMLDOMElement} domElement - The HTML element used for event listeners.
201
+ */
202
+ constructor(e, t = null) {
203
+ super(void 0, t);
204
+ const n = new Mt(this);
205
+ this._root = n;
206
+ const s = new xt();
207
+ this._gizmo = s, n.add(s);
208
+ const r = new bt();
209
+ this._plane = r, n.add(r);
210
+ const i = this;
211
+ function a(y, z) {
212
+ let Y = z;
213
+ Object.defineProperty(i, y, {
214
+ get: function() {
215
+ return Y !== void 0 ? Y : z;
216
+ },
217
+ set: function(L) {
218
+ Y !== L && (Y = L, r[y] = L, s[y] = L, i.dispatchEvent({ type: y + "-changed", value: L }), i.dispatchEvent(ue));
219
+ }
220
+ }), i[y] = z, r[y] = z, s[y] = z;
221
+ }
222
+ a("camera", e), a("object", void 0), a("enabled", !0), a("axis", null), a("mode", "translate"), a("translationSnap", null), a("rotationSnap", null), a("scaleSnap", null), a("space", "world"), a("size", 1), a("dragging", !1), a("showX", !0), a("showY", !0), a("showZ", !0), a("minX", -1 / 0), a("maxX", 1 / 0), a("minY", -1 / 0), a("maxY", 1 / 0), a("minZ", -1 / 0), a("maxZ", 1 / 0);
223
+ const d = new l(), f = new l(), D = new S(), R = new S(), Q = new l(), N = new S(), $ = new l(), P = new l(), T = new l(), x = 0, E = new l();
224
+ a("worldPosition", d), a("worldPositionStart", f), a("worldQuaternion", D), a("worldQuaternionStart", R), a("cameraPosition", Q), a("cameraQuaternion", N), a("pointStart", $), a("pointEnd", P), a("rotationAxis", T), a("rotationAngle", x), a("eye", E), this._offset = new l(), this._startNorm = new l(), this._endNorm = new l(), this._cameraScale = new l(), this._parentPosition = new l(), this._parentQuaternion = new S(), this._parentQuaternionInv = new S(), this._parentScale = new l(), this._worldScaleStart = new l(), this._worldQuaternionInv = new S(), this._worldScale = new l(), this._positionStart = new l(), this._quaternionStart = new S(), this._scaleStart = new l(), this._getPointer = wt.bind(this), this._onPointerDown = yt.bind(this), this._onPointerHover = gt.bind(this), this._onPointerMove = _t.bind(this), this._onPointerUp = St.bind(this), t !== null && this.connect(t);
225
+ }
226
+ connect(e) {
227
+ 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";
228
+ }
229
+ disconnect() {
230
+ 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 = "auto";
231
+ }
232
+ /**
233
+ * Returns the visual representation of the controls. Add the helper to your scene to
234
+ * visually transform the attached 3D object.
235
+ *
236
+ * @return {TransformControlsRoot} The helper.
237
+ */
238
+ getHelper() {
239
+ return this._root;
240
+ }
241
+ pointerHover(e) {
242
+ if (this.object === void 0 || this.dragging === !0) return;
243
+ e !== null && H.setFromCamera(e, this.camera);
244
+ const t = de(this._gizmo.picker[this.mode], H);
245
+ t ? this.axis = t.object.name : this.axis = null;
246
+ }
247
+ pointerDown(e) {
248
+ if (!(this.object === void 0 || this.dragging === !0 || e != null && e.button !== 0) && this.axis !== null) {
249
+ e !== null && H.setFromCamera(e, this.camera);
250
+ const t = de(this._plane, H, !0);
251
+ 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, Se.mode = this.mode, this.dispatchEvent(Se);
252
+ }
253
+ }
254
+ pointerMove(e) {
255
+ const t = this.axis, n = this.mode, s = this.object;
256
+ let r = this.space;
257
+ if (n === "scale" ? r = "local" : (t === "E" || t === "XYZE" || t === "XYZ") && (r = "world"), s === void 0 || t === null || this.dragging === !1 || e !== null && e.button !== -1) return;
258
+ e !== null && H.setFromCamera(e, this.camera);
259
+ const i = de(this._plane, H, !0);
260
+ if (i) {
261
+ if (this.pointEnd.copy(i.point).sub(this.worldPositionStart), n === "translate")
262
+ this._offset.copy(this.pointEnd).sub(this.pointStart), r === "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), r === "local" && t !== "XYZ" ? this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale) : this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale), s.position.copy(this._offset).add(this._positionStart), this.translationSnap && (r === "local" && (s.position.applyQuaternion(p.copy(this._quaternionStart).invert()), t.search("X") !== -1 && (s.position.x = Math.round(s.position.x / this.translationSnap) * this.translationSnap), t.search("Y") !== -1 && (s.position.y = Math.round(s.position.y / this.translationSnap) * this.translationSnap), t.search("Z") !== -1 && (s.position.z = Math.round(s.position.z / this.translationSnap) * this.translationSnap), s.position.applyQuaternion(this._quaternionStart)), r === "world" && (s.parent && s.position.add(m.setFromMatrixPosition(s.parent.matrixWorld)), t.search("X") !== -1 && (s.position.x = Math.round(s.position.x / this.translationSnap) * this.translationSnap), t.search("Y") !== -1 && (s.position.y = Math.round(s.position.y / this.translationSnap) * this.translationSnap), t.search("Z") !== -1 && (s.position.z = Math.round(s.position.z / this.translationSnap) * this.translationSnap), s.parent && s.position.sub(m.setFromMatrixPosition(s.parent.matrixWorld)))), s.position.x = Math.max(this.minX, Math.min(this.maxX, s.position.x)), s.position.y = Math.max(this.minY, Math.min(this.maxY, s.position.y)), s.position.z = Math.max(this.minZ, Math.min(this.maxZ, s.position.z));
263
+ else if (n === "scale") {
264
+ if (t.search("XYZ") !== -1) {
265
+ let a = this.pointEnd.length() / this.pointStart.length();
266
+ this.pointEnd.dot(this.pointStart) < 0 && (a *= -1), I.set(a, a, a);
267
+ } else
268
+ m.copy(this.pointStart), I.copy(this.pointEnd), m.applyQuaternion(this._worldQuaternionInv), I.applyQuaternion(this._worldQuaternionInv), I.divide(m), t.search("X") === -1 && (I.x = 1), t.search("Y") === -1 && (I.y = 1), t.search("Z") === -1 && (I.z = 1);
269
+ s.scale.copy(this._scaleStart).multiply(I), this.scaleSnap && (t.search("X") !== -1 && (s.scale.x = Math.round(s.scale.x / this.scaleSnap) * this.scaleSnap || this.scaleSnap), t.search("Y") !== -1 && (s.scale.y = Math.round(s.scale.y / this.scaleSnap) * this.scaleSnap || this.scaleSnap), t.search("Z") !== -1 && (s.scale.z = Math.round(s.scale.z / this.scaleSnap) * this.scaleSnap || this.scaleSnap));
270
+ } else if (n === "rotate") {
271
+ this._offset.copy(this.pointEnd).sub(this.pointStart);
272
+ const a = 20 / this.worldPosition.distanceTo(m.setFromMatrixPosition(this.camera.matrixWorld));
273
+ let d = !1;
274
+ t === "XYZE" ? (this.rotationAxis.copy(this._offset).cross(this.eye).normalize(), this.rotationAngle = this._offset.dot(m.copy(this.rotationAxis).cross(this.eye)) * a) : (t === "X" || t === "Y" || t === "Z") && (this.rotationAxis.copy(_e[t]), m.copy(_e[t]), r === "local" && m.applyQuaternion(this.worldQuaternion), m.cross(this.eye), m.length() === 0 ? d = !0 : this.rotationAngle = this._offset.dot(m.normalize()) * a), (t === "E" || d) && (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), r === "local" && t !== "E" && t !== "XYZE" ? (s.quaternion.copy(this._quaternionStart), s.quaternion.multiply(p.setFromAxisAngle(this.rotationAxis, this.rotationAngle)).normalize()) : (this.rotationAxis.applyQuaternion(this._parentQuaternionInv), s.quaternion.copy(p.setFromAxisAngle(this.rotationAxis, this.rotationAngle)), s.quaternion.multiply(this._quaternionStart).normalize());
275
+ }
276
+ this.dispatchEvent(ue), this.dispatchEvent(xe);
277
+ }
278
+ }
279
+ pointerUp(e) {
280
+ e !== null && e.button !== 0 || (this.dragging && this.axis !== null && (Me.mode = this.mode, this.dispatchEvent(Me)), this.dragging = !1, this.axis = null);
281
+ }
282
+ dispose() {
283
+ this.disconnect(), this._root.dispose();
284
+ }
285
+ /**
286
+ * Sets the 3D object that should be transformed and ensures the controls UI is visible.
287
+ *
288
+ * @param {Object3D} object - The 3D object that should be transformed.
289
+ * @return {TransformControls} A reference to this controls.
290
+ */
291
+ attach(e) {
292
+ return this.object = e, this._root.visible = !0, this;
293
+ }
294
+ /**
295
+ * Removes the current 3D object from the controls and makes the helper UI invisible.
296
+ *
297
+ * @return {TransformControls} A reference to this controls.
298
+ */
299
+ detach() {
300
+ return this.object = void 0, this.axis = null, this._root.visible = !1, this;
301
+ }
302
+ /**
303
+ * Resets the object's position, rotation and scale to when the current transform began.
304
+ */
305
+ reset() {
306
+ this.enabled && this.dragging && (this.object.position.copy(this._positionStart), this.object.quaternion.copy(this._quaternionStart), this.object.scale.copy(this._scaleStart), this.dispatchEvent(ue), this.dispatchEvent(xe), this.pointStart.copy(this.pointEnd));
307
+ }
308
+ /**
309
+ * Returns the raycaster that is used for user interaction. This object is shared between all
310
+ * instances of `TransformControls`.
311
+ *
312
+ * @returns {Raycaster} The internal raycaster.
313
+ */
314
+ getRaycaster() {
315
+ return H;
316
+ }
317
+ /**
318
+ * Returns the transformation mode.
319
+ *
320
+ * @returns {'translate'|'rotate'|'scale'} The transformation mode.
321
+ */
322
+ getMode() {
323
+ return this.mode;
324
+ }
325
+ /**
326
+ * Sets the given transformation mode.
327
+ *
328
+ * @param {'translate'|'rotate'|'scale'} mode - The transformation mode to set.
329
+ */
330
+ setMode(e) {
331
+ this.mode = e;
332
+ }
333
+ /**
334
+ * Sets the translation snap.
335
+ *
336
+ * @param {?number} translationSnap - The translation snap to set.
337
+ */
338
+ setTranslationSnap(e) {
339
+ this.translationSnap = e;
340
+ }
341
+ /**
342
+ * Sets the rotation snap.
343
+ *
344
+ * @param {?number} rotationSnap - The rotation snap to set.
345
+ */
346
+ setRotationSnap(e) {
347
+ this.rotationSnap = e;
348
+ }
349
+ /**
350
+ * Sets the scale snap.
351
+ *
352
+ * @param {?number} scaleSnap - The scale snap to set.
353
+ */
354
+ setScaleSnap(e) {
355
+ this.scaleSnap = e;
356
+ }
357
+ /**
358
+ * Sets the size of the helper UI.
359
+ *
360
+ * @param {number} size - The size to set.
361
+ */
362
+ setSize(e) {
363
+ this.size = e;
364
+ }
365
+ /**
366
+ * Sets the coordinate space in which transformations are applied.
367
+ *
368
+ * @param {'world'|'local'} space - The space to set.
369
+ */
370
+ setSpace(e) {
371
+ this.space = e;
372
+ }
373
+ }
374
+ function wt(h) {
375
+ if (this.domElement.ownerDocument.pointerLockElement)
376
+ return {
377
+ x: 0,
378
+ y: 0,
379
+ button: h.button
380
+ };
381
+ {
382
+ const e = this.domElement.getBoundingClientRect();
383
+ return {
384
+ x: (h.clientX - e.left) / e.width * 2 - 1,
385
+ y: -(h.clientY - e.top) / e.height * 2 + 1,
386
+ button: h.button
387
+ };
388
+ }
389
+ }
390
+ function gt(h) {
391
+ if (this.enabled)
392
+ switch (h.pointerType) {
393
+ case "mouse":
394
+ case "pen":
395
+ this.pointerHover(this._getPointer(h));
396
+ break;
397
+ }
398
+ }
399
+ function yt(h) {
400
+ this.enabled && (document.pointerLockElement || this.domElement.setPointerCapture(h.pointerId), this.domElement.addEventListener("pointermove", this._onPointerMove), this.pointerHover(this._getPointer(h)), this.pointerDown(this._getPointer(h)));
401
+ }
402
+ function _t(h) {
403
+ this.enabled && this.pointerMove(this._getPointer(h));
404
+ }
405
+ function St(h) {
406
+ this.enabled && (this.domElement.releasePointerCapture(h.pointerId), this.domElement.removeEventListener("pointermove", this._onPointerMove), this.pointerUp(this._getPointer(h)));
407
+ }
408
+ function de(h, e, t) {
409
+ const n = e.intersectObject(h, !0);
410
+ for (let s = 0; s < n.length; s++)
411
+ if (n[s].object.visible || t)
412
+ return n[s];
413
+ return !1;
414
+ }
415
+ const ne = new Oe(), u = new l(0, 1, 0), be = new l(0, 0, 0), Pe = new ce(), ae = new S(), oe = new S(), b = new l(), Te = new ce(), q = new l(1, 0, 0), O = new l(0, 1, 0), K = new l(0, 0, 1), re = new l(), G = new l(), W = new l();
416
+ class Mt extends le {
417
+ constructor(e) {
418
+ super(), this.isTransformControlsRoot = !0, this.controls = e, this.visible = !1;
419
+ }
420
+ // updateMatrixWorld updates key transformation variables
421
+ updateMatrixWorld(e) {
422
+ const t = this.controls;
423
+ 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);
424
+ }
425
+ dispose() {
426
+ this.traverse(function(e) {
427
+ e.geometry && e.geometry.dispose(), e.material && e.material.dispose();
428
+ });
429
+ }
430
+ }
431
+ class xt extends le {
432
+ constructor() {
433
+ super(), this.isTransformControlsGizmo = !0, this.type = "TransformControlsGizmo";
434
+ const e = new me({
435
+ depthTest: !1,
436
+ depthWrite: !1,
437
+ fog: !1,
438
+ toneMapped: !1,
439
+ transparent: !0
440
+ }), t = new Xe({
441
+ depthTest: !1,
442
+ depthWrite: !1,
443
+ fog: !1,
444
+ toneMapped: !1,
445
+ transparent: !0
446
+ }), n = e.clone();
447
+ n.opacity = 0.15;
448
+ const s = t.clone();
449
+ s.opacity = 0.5;
450
+ const r = e.clone();
451
+ r.color.setHex(16711680);
452
+ const i = e.clone();
453
+ i.color.setHex(65280);
454
+ const a = e.clone();
455
+ a.color.setHex(255);
456
+ const d = e.clone();
457
+ d.color.setHex(16711680), d.opacity = 0.5;
458
+ const f = e.clone();
459
+ f.color.setHex(65280), f.opacity = 0.5;
460
+ const D = e.clone();
461
+ D.color.setHex(255), D.opacity = 0.5;
462
+ const R = e.clone();
463
+ R.opacity = 0.25;
464
+ const Q = e.clone();
465
+ Q.color.setHex(16776960), Q.opacity = 0.25, e.clone().color.setHex(16776960);
466
+ const $ = e.clone();
467
+ $.color.setHex(7895160);
468
+ const P = new g(0, 0.04, 0.1, 12);
469
+ P.translate(0, 0.05, 0);
470
+ const T = new v(0.08, 0.08, 0.08);
471
+ T.translate(0, 0.04, 0);
472
+ const x = new pe();
473
+ x.setAttribute("position", new he([0, 0, 0, 1, 0, 0], 3));
474
+ const E = new g(75e-4, 75e-4, 0.5, 3);
475
+ E.translate(0, 0.25, 0);
476
+ function y(_, J) {
477
+ const M = new j(_, 75e-4, 3, 64, J * Math.PI * 2);
478
+ return M.rotateY(Math.PI / 2), M.rotateX(Math.PI / 2), M;
479
+ }
480
+ function z() {
481
+ const _ = new pe();
482
+ return _.setAttribute("position", new he([0, 0, 0, 1, 1, 1], 3)), _;
483
+ }
484
+ const Y = {
485
+ X: [
486
+ [new o(P, r), [0.5, 0, 0], [0, 0, -Math.PI / 2]],
487
+ [new o(P, r), [-0.5, 0, 0], [0, 0, Math.PI / 2]],
488
+ [new o(E, r), [0, 0, 0], [0, 0, -Math.PI / 2]]
489
+ ],
490
+ Y: [
491
+ [new o(P, i), [0, 0.5, 0]],
492
+ [new o(P, i), [0, -0.5, 0], [Math.PI, 0, 0]],
493
+ [new o(E, i)]
494
+ ],
495
+ Z: [
496
+ [new o(P, a), [0, 0, 0.5], [Math.PI / 2, 0, 0]],
497
+ [new o(P, a), [0, 0, -0.5], [-Math.PI / 2, 0, 0]],
498
+ [new o(E, a), null, [Math.PI / 2, 0, 0]]
499
+ ],
500
+ XYZ: [
501
+ [new o(new se(0.1, 0), R.clone()), [0, 0, 0]]
502
+ ],
503
+ XY: [
504
+ [new o(new v(0.15, 0.15, 0.01), D.clone()), [0.15, 0.15, 0]]
505
+ ],
506
+ YZ: [
507
+ [new o(new v(0.15, 0.15, 0.01), d.clone()), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]
508
+ ],
509
+ XZ: [
510
+ [new o(new v(0.15, 0.15, 0.01), f.clone()), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]
511
+ ]
512
+ }, L = {
513
+ X: [
514
+ [new o(new g(0.2, 0, 0.6, 4), n), [0.3, 0, 0], [0, 0, -Math.PI / 2]],
515
+ [new o(new g(0.2, 0, 0.6, 4), n), [-0.3, 0, 0], [0, 0, Math.PI / 2]]
516
+ ],
517
+ Y: [
518
+ [new o(new g(0.2, 0, 0.6, 4), n), [0, 0.3, 0]],
519
+ [new o(new g(0.2, 0, 0.6, 4), n), [0, -0.3, 0], [0, 0, Math.PI]]
520
+ ],
521
+ Z: [
522
+ [new o(new g(0.2, 0, 0.6, 4), n), [0, 0, 0.3], [Math.PI / 2, 0, 0]],
523
+ [new o(new g(0.2, 0, 0.6, 4), n), [0, 0, -0.3], [-Math.PI / 2, 0, 0]]
524
+ ],
525
+ XYZ: [
526
+ [new o(new se(0.2, 0), n)]
527
+ ],
528
+ XY: [
529
+ [new o(new v(0.2, 0.2, 0.01), n), [0.15, 0.15, 0]]
530
+ ],
531
+ YZ: [
532
+ [new o(new v(0.2, 0.2, 0.01), n), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]
533
+ ],
534
+ XZ: [
535
+ [new o(new v(0.2, 0.2, 0.01), n), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]
536
+ ]
537
+ }, ke = {
538
+ START: [
539
+ [new o(new se(0.01, 2), s), null, null, null, "helper"]
540
+ ],
541
+ END: [
542
+ [new o(new se(0.01, 2), s), null, null, null, "helper"]
543
+ ],
544
+ DELTA: [
545
+ [new B(z(), s), null, null, null, "helper"]
546
+ ],
547
+ X: [
548
+ [new B(x, s.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], "helper"]
549
+ ],
550
+ Y: [
551
+ [new B(x, s.clone()), [0, -1e3, 0], [0, 0, Math.PI / 2], [1e6, 1, 1], "helper"]
552
+ ],
553
+ Z: [
554
+ [new B(x, s.clone()), [0, 0, -1e3], [0, -Math.PI / 2, 0], [1e6, 1, 1], "helper"]
555
+ ]
556
+ }, De = {
557
+ XYZE: [
558
+ [new o(y(0.5, 1), $), null, [0, Math.PI / 2, 0]]
559
+ ],
560
+ X: [
561
+ [new o(y(0.5, 0.5), r)]
562
+ ],
563
+ Y: [
564
+ [new o(y(0.5, 0.5), i), null, [0, 0, -Math.PI / 2]]
565
+ ],
566
+ Z: [
567
+ [new o(y(0.5, 0.5), a), null, [0, Math.PI / 2, 0]]
568
+ ],
569
+ E: [
570
+ [new o(y(0.75, 1), Q), null, [0, Math.PI / 2, 0]]
571
+ ]
572
+ }, Be = {
573
+ AXIS: [
574
+ [new B(x, s.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], "helper"]
575
+ ]
576
+ }, Ie = {
577
+ XYZE: [
578
+ [new o(new He(0.25, 10, 8), n)]
579
+ ],
580
+ X: [
581
+ [new o(new j(0.5, 0.1, 4, 24), n), [0, 0, 0], [0, -Math.PI / 2, -Math.PI / 2]]
582
+ ],
583
+ Y: [
584
+ [new o(new j(0.5, 0.1, 4, 24), n), [0, 0, 0], [Math.PI / 2, 0, 0]]
585
+ ],
586
+ Z: [
587
+ [new o(new j(0.5, 0.1, 4, 24), n), [0, 0, 0], [0, 0, -Math.PI / 2]]
588
+ ],
589
+ E: [
590
+ [new o(new j(0.75, 0.1, 2, 24), n)]
591
+ ]
592
+ }, Ae = {
593
+ X: [
594
+ [new o(T, r), [0.5, 0, 0], [0, 0, -Math.PI / 2]],
595
+ [new o(E, r), [0, 0, 0], [0, 0, -Math.PI / 2]],
596
+ [new o(T, r), [-0.5, 0, 0], [0, 0, Math.PI / 2]]
597
+ ],
598
+ Y: [
599
+ [new o(T, i), [0, 0.5, 0]],
600
+ [new o(E, i)],
601
+ [new o(T, i), [0, -0.5, 0], [0, 0, Math.PI]]
602
+ ],
603
+ Z: [
604
+ [new o(T, a), [0, 0, 0.5], [Math.PI / 2, 0, 0]],
605
+ [new o(E, a), [0, 0, 0], [Math.PI / 2, 0, 0]],
606
+ [new o(T, a), [0, 0, -0.5], [-Math.PI / 2, 0, 0]]
607
+ ],
608
+ XY: [
609
+ [new o(new v(0.15, 0.15, 0.01), D), [0.15, 0.15, 0]]
610
+ ],
611
+ YZ: [
612
+ [new o(new v(0.15, 0.15, 0.01), d), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]
613
+ ],
614
+ XZ: [
615
+ [new o(new v(0.15, 0.15, 0.01), f), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]
616
+ ],
617
+ XYZ: [
618
+ [new o(new v(0.1, 0.1, 0.1), R.clone())]
619
+ ]
620
+ }, Re = {
621
+ X: [
622
+ [new o(new g(0.2, 0, 0.6, 4), n), [0.3, 0, 0], [0, 0, -Math.PI / 2]],
623
+ [new o(new g(0.2, 0, 0.6, 4), n), [-0.3, 0, 0], [0, 0, Math.PI / 2]]
624
+ ],
625
+ Y: [
626
+ [new o(new g(0.2, 0, 0.6, 4), n), [0, 0.3, 0]],
627
+ [new o(new g(0.2, 0, 0.6, 4), n), [0, -0.3, 0], [0, 0, Math.PI]]
628
+ ],
629
+ Z: [
630
+ [new o(new g(0.2, 0, 0.6, 4), n), [0, 0, 0.3], [Math.PI / 2, 0, 0]],
631
+ [new o(new g(0.2, 0, 0.6, 4), n), [0, 0, -0.3], [-Math.PI / 2, 0, 0]]
632
+ ],
633
+ XY: [
634
+ [new o(new v(0.2, 0.2, 0.01), n), [0.15, 0.15, 0]]
635
+ ],
636
+ YZ: [
637
+ [new o(new v(0.2, 0.2, 0.01), n), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]
638
+ ],
639
+ XZ: [
640
+ [new o(new v(0.2, 0.2, 0.01), n), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]
641
+ ],
642
+ XYZ: [
643
+ [new o(new v(0.2, 0.2, 0.2), n), [0, 0, 0]]
644
+ ]
645
+ }, Qe = {
646
+ X: [
647
+ [new B(x, s.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], "helper"]
648
+ ],
649
+ Y: [
650
+ [new B(x, s.clone()), [0, -1e3, 0], [0, 0, Math.PI / 2], [1e6, 1, 1], "helper"]
651
+ ],
652
+ Z: [
653
+ [new B(x, s.clone()), [0, 0, -1e3], [0, -Math.PI / 2, 0], [1e6, 1, 1], "helper"]
654
+ ]
655
+ };
656
+ function C(_) {
657
+ const J = new le();
658
+ for (const M in _)
659
+ for (let Z = _[M].length; Z--; ) {
660
+ const w = _[M][Z][0].clone(), ee = _[M][Z][1], te = _[M][Z][2], ie = _[M][Z][3], ze = _[M][Z][4];
661
+ w.name = M, w.tag = ze, ee && w.position.set(ee[0], ee[1], ee[2]), te && w.rotation.set(te[0], te[1], te[2]), ie && w.scale.set(ie[0], ie[1], ie[2]), w.updateMatrix();
662
+ const ve = w.geometry.clone();
663
+ ve.applyMatrix4(w.matrix), w.geometry = ve, w.renderOrder = 1 / 0, w.position.set(0, 0, 0), w.rotation.set(0, 0, 0), w.scale.set(1, 1, 1), J.add(w);
664
+ }
665
+ return J;
666
+ }
667
+ this.gizmo = {}, this.picker = {}, this.helper = {}, this.add(this.gizmo.translate = C(Y)), this.add(this.gizmo.rotate = C(De)), this.add(this.gizmo.scale = C(Ae)), this.add(this.picker.translate = C(L)), this.add(this.picker.rotate = C(Ie)), this.add(this.picker.scale = C(Re)), this.add(this.helper.translate = C(ke)), this.add(this.helper.rotate = C(Be)), this.add(this.helper.scale = C(Qe)), this.picker.translate.visible = !1, this.picker.rotate.visible = !1, this.picker.scale.visible = !1;
668
+ }
669
+ // updateMatrixWorld will update transformations and appearance of individual handles
670
+ updateMatrixWorld(e) {
671
+ const n = (this.mode === "scale" ? "local" : this.space) === "local" ? this.worldQuaternion : oe;
672
+ 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";
673
+ let s = [];
674
+ s = s.concat(this.picker[this.mode].children), s = s.concat(this.gizmo[this.mode].children), s = s.concat(this.helper[this.mode].children);
675
+ for (let r = 0; r < s.length; r++) {
676
+ const i = s[r];
677
+ i.visible = !0, i.rotation.set(0, 0, 0), i.position.copy(this.worldPosition);
678
+ let a;
679
+ if (this.camera.isOrthographicCamera ? a = (this.camera.top - this.camera.bottom) / this.camera.zoom : a = this.worldPosition.distanceTo(this.cameraPosition) * Math.min(1.9 * Math.tan(Math.PI * this.camera.fov / 360) / this.camera.zoom, 7), i.scale.set(1, 1, 1).multiplyScalar(a * this.size / 4), i.tag === "helper") {
680
+ i.visible = !1, i.name === "AXIS" ? (i.visible = !!this.axis, this.axis === "X" && (p.setFromEuler(ne.set(0, 0, 0)), i.quaternion.copy(n).multiply(p), Math.abs(u.copy(q).applyQuaternion(n).dot(this.eye)) > 0.9 && (i.visible = !1)), this.axis === "Y" && (p.setFromEuler(ne.set(0, 0, Math.PI / 2)), i.quaternion.copy(n).multiply(p), Math.abs(u.copy(O).applyQuaternion(n).dot(this.eye)) > 0.9 && (i.visible = !1)), this.axis === "Z" && (p.setFromEuler(ne.set(0, Math.PI / 2, 0)), i.quaternion.copy(n).multiply(p), Math.abs(u.copy(K).applyQuaternion(n).dot(this.eye)) > 0.9 && (i.visible = !1)), this.axis === "XYZE" && (p.setFromEuler(ne.set(0, Math.PI / 2, 0)), u.copy(this.rotationAxis), i.quaternion.setFromRotationMatrix(Pe.lookAt(be, u, O)), i.quaternion.multiply(p), i.visible = this.dragging), this.axis === "E" && (i.visible = !1)) : i.name === "START" ? (i.position.copy(this.worldPositionStart), i.visible = this.dragging) : i.name === "END" ? (i.position.copy(this.worldPosition), i.visible = this.dragging) : i.name === "DELTA" ? (i.position.copy(this.worldPositionStart), i.quaternion.copy(this.worldQuaternionStart), m.set(1e-10, 1e-10, 1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1), m.applyQuaternion(this.worldQuaternionStart.clone().invert()), i.scale.copy(m), i.visible = this.dragging) : (i.quaternion.copy(n), this.dragging ? i.position.copy(this.worldPositionStart) : i.position.copy(this.worldPosition), this.axis && (i.visible = this.axis.search(i.name) !== -1));
681
+ continue;
682
+ }
683
+ i.quaternion.copy(n), this.mode === "translate" || this.mode === "scale" ? (i.name === "X" && Math.abs(u.copy(q).applyQuaternion(n).dot(this.eye)) > 0.99 && (i.scale.set(1e-10, 1e-10, 1e-10), i.visible = !1), i.name === "Y" && Math.abs(u.copy(O).applyQuaternion(n).dot(this.eye)) > 0.99 && (i.scale.set(1e-10, 1e-10, 1e-10), i.visible = !1), i.name === "Z" && Math.abs(u.copy(K).applyQuaternion(n).dot(this.eye)) > 0.99 && (i.scale.set(1e-10, 1e-10, 1e-10), i.visible = !1), i.name === "XY" && Math.abs(u.copy(K).applyQuaternion(n).dot(this.eye)) < 0.2 && (i.scale.set(1e-10, 1e-10, 1e-10), i.visible = !1), i.name === "YZ" && Math.abs(u.copy(q).applyQuaternion(n).dot(this.eye)) < 0.2 && (i.scale.set(1e-10, 1e-10, 1e-10), i.visible = !1), i.name === "XZ" && Math.abs(u.copy(O).applyQuaternion(n).dot(this.eye)) < 0.2 && (i.scale.set(1e-10, 1e-10, 1e-10), i.visible = !1)) : this.mode === "rotate" && (ae.copy(n), u.copy(this.eye).applyQuaternion(p.copy(n).invert()), i.name.search("E") !== -1 && i.quaternion.setFromRotationMatrix(Pe.lookAt(this.eye, be, O)), i.name === "X" && (p.setFromAxisAngle(q, Math.atan2(-u.y, u.z)), p.multiplyQuaternions(ae, p), i.quaternion.copy(p)), i.name === "Y" && (p.setFromAxisAngle(O, Math.atan2(u.x, u.z)), p.multiplyQuaternions(ae, p), i.quaternion.copy(p)), i.name === "Z" && (p.setFromAxisAngle(K, Math.atan2(u.y, u.x)), p.multiplyQuaternions(ae, p), i.quaternion.copy(p))), i.visible = i.visible && (i.name.indexOf("X") === -1 || this.showX), i.visible = i.visible && (i.name.indexOf("Y") === -1 || this.showY), i.visible = i.visible && (i.name.indexOf("Z") === -1 || this.showZ), i.visible = i.visible && (i.name.indexOf("E") === -1 || this.showX && this.showY && this.showZ), i.material._color = i.material._color || i.material.color.clone(), i.material._opacity = i.material._opacity || i.material.opacity, i.material.color.copy(i.material._color), i.material.opacity = i.material._opacity, this.enabled && this.axis && (i.name === this.axis || this.axis.split("").some(function(d) {
684
+ return i.name === d;
685
+ })) && (i.material.color.setHex(16776960), i.material.opacity = 1);
686
+ }
687
+ super.updateMatrixWorld(e);
688
+ }
689
+ }
690
+ class bt extends o {
691
+ constructor() {
692
+ super(
693
+ new Ye(1e5, 1e5, 2, 2),
694
+ new me({ visible: !1, wireframe: !0, side: fe, transparent: !0, opacity: 0.1, toneMapped: !1 })
695
+ ), this.isTransformControlsPlane = !0, this.type = "TransformControlsPlane";
696
+ }
697
+ updateMatrixWorld(e) {
698
+ let t = this.space;
699
+ switch (this.position.copy(this.worldPosition), this.mode === "scale" && (t = "local"), re.copy(q).applyQuaternion(t === "local" ? this.worldQuaternion : oe), G.copy(O).applyQuaternion(t === "local" ? this.worldQuaternion : oe), W.copy(K).applyQuaternion(t === "local" ? this.worldQuaternion : oe), u.copy(G), this.mode) {
700
+ case "translate":
701
+ case "scale":
702
+ switch (this.axis) {
703
+ case "X":
704
+ u.copy(this.eye).cross(re), b.copy(re).cross(u);
705
+ break;
706
+ case "Y":
707
+ u.copy(this.eye).cross(G), b.copy(G).cross(u);
708
+ break;
709
+ case "Z":
710
+ u.copy(this.eye).cross(W), b.copy(W).cross(u);
711
+ break;
712
+ case "XY":
713
+ b.copy(W);
714
+ break;
715
+ case "YZ":
716
+ b.copy(re);
717
+ break;
718
+ case "XZ":
719
+ u.copy(W), b.copy(G);
720
+ break;
721
+ case "XYZ":
722
+ case "E":
723
+ b.set(0, 0, 0);
724
+ break;
725
+ }
726
+ break;
727
+ case "rotate":
728
+ default:
729
+ b.set(0, 0, 0);
730
+ }
731
+ b.length() === 0 ? this.quaternion.copy(this.cameraQuaternion) : (Te.lookAt(m.set(0, 0, 0), b, u), this.quaternion.setFromRotationMatrix(Te)), super.updateMatrixWorld(e);
732
+ }
733
+ }
734
+ class Pt {
735
+ /**
736
+ * Constructs a new pass.
737
+ */
738
+ constructor() {
739
+ this.isPass = !0, this.enabled = !0, this.needsSwap = !0, this.clear = !1, this.renderToScreen = !1;
740
+ }
741
+ /**
742
+ * Sets the size of the pass.
743
+ *
744
+ * @abstract
745
+ * @param {number} width - The width to set.
746
+ * @param {number} height - The width to set.
747
+ */
748
+ setSize() {
749
+ }
750
+ /**
751
+ * This method holds the render logic of a pass. It must be implemented in all derived classes.
752
+ *
753
+ * @abstract
754
+ * @param {WebGLRenderer} renderer - The renderer.
755
+ * @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
756
+ * destination for the pass.
757
+ * @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
758
+ * previous pass from this buffer.
759
+ * @param {number} deltaTime - The delta time in seconds.
760
+ * @param {boolean} maskActive - Whether masking is active or not.
761
+ */
762
+ render() {
763
+ console.error("THREE.Pass: .render() must be implemented in derived pass.");
764
+ }
765
+ /**
766
+ * Frees the GPU-related resources allocated by this instance. Call this
767
+ * method whenever the pass is no longer used in your app.
768
+ *
769
+ * @abstract
770
+ */
771
+ dispose() {
772
+ }
773
+ }
774
+ const Tt = new Ze(-1, 1, 1, -1, 0, 1);
775
+ class Et extends pe {
776
+ constructor() {
777
+ super(), this.setAttribute("position", new he([-1, 3, 0, -1, -1, 0, 3, -1, 0], 3)), this.setAttribute("uv", new he([0, 2, 0, 0, 2, 0], 2));
778
+ }
779
+ }
780
+ const Ct = new Et();
781
+ class kt {
782
+ /**
783
+ * Constructs a new full screen quad.
784
+ *
785
+ * @param {?Material} material - The material to render te full screen quad with.
786
+ */
787
+ constructor(e) {
788
+ this._mesh = new o(Ct, e);
789
+ }
790
+ /**
791
+ * Frees the GPU-related resources allocated by this instance. Call this
792
+ * method whenever the instance is no longer used in your app.
793
+ */
794
+ dispose() {
795
+ this._mesh.geometry.dispose();
796
+ }
797
+ /**
798
+ * Renders the full screen quad.
799
+ *
800
+ * @param {WebGLRenderer} renderer - The renderer.
801
+ */
802
+ render(e) {
803
+ e.render(this._mesh, Tt);
804
+ }
805
+ /**
806
+ * The quad's material.
807
+ *
808
+ * @type {?Material}
809
+ */
810
+ get material() {
811
+ return this._mesh.material;
812
+ }
813
+ set material(e) {
814
+ this._mesh.material = e;
815
+ }
816
+ }
817
+ const Dt = {
818
+ name: "CopyShader",
819
+ uniforms: {
820
+ tDiffuse: { value: null },
821
+ opacity: { value: 1 }
822
+ },
823
+ vertexShader: (
824
+ /* glsl */
825
+ `
826
+
827
+ varying vec2 vUv;
828
+
829
+ void main() {
830
+
831
+ vUv = uv;
832
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
833
+
834
+ }`
835
+ ),
836
+ fragmentShader: (
837
+ /* glsl */
838
+ `
839
+
840
+ uniform float opacity;
841
+
842
+ uniform sampler2D tDiffuse;
843
+
844
+ varying vec2 vUv;
845
+
846
+ void main() {
847
+
848
+ vec4 texel = texture2D( tDiffuse, vUv );
849
+ gl_FragColor = opacity * texel;
850
+
851
+
852
+ }`
853
+ )
854
+ };
855
+ class A extends Pt {
856
+ /**
857
+ * Constructs a new outline pass.
858
+ *
859
+ * @param {Vector2} [resolution] - The effect's resolution.
860
+ * @param {Scene} scene - The scene to render.
861
+ * @param {Camera} camera - The camera.
862
+ * @param {Array<Object3D>} [selectedObjects] - The selected 3D objects that should receive an outline.
863
+ *
864
+ */
865
+ constructor(e, t, n, s) {
866
+ super(), this.renderScene = t, this.renderCamera = n, this.selectedObjects = s !== void 0 ? s : [], this.visibleEdgeColor = new F(1, 1, 1), this.hiddenEdgeColor = new F(0.1, 0.04, 0.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 k(e.x, e.y) : new k(256, 256);
867
+ const r = Math.round(this.resolution.x / this.downSampleRatio), i = Math.round(this.resolution.y / this.downSampleRatio);
868
+ this.renderTargetMaskBuffer = new X(this.resolution.x, this.resolution.y), this.renderTargetMaskBuffer.texture.name = "OutlinePass.mask", this.renderTargetMaskBuffer.texture.generateMipmaps = !1, this.depthMaterial = new Ue(), this.depthMaterial.side = fe, this.depthMaterial.depthPacking = je, this.depthMaterial.blending = we, this.prepareMaskMaterial = this._getPrepareMaskMaterial(), this.prepareMaskMaterial.side = fe, this.prepareMaskMaterial.fragmentShader = D(this.prepareMaskMaterial.fragmentShader, this.renderCamera), this.renderTargetDepthBuffer = new X(this.resolution.x, this.resolution.y, { type: U }), this.renderTargetDepthBuffer.texture.name = "OutlinePass.depth", this.renderTargetDepthBuffer.texture.generateMipmaps = !1, this.renderTargetMaskDownSampleBuffer = new X(r, i, { type: U }), this.renderTargetMaskDownSampleBuffer.texture.name = "OutlinePass.depthDownSample", this.renderTargetMaskDownSampleBuffer.texture.generateMipmaps = !1, this.renderTargetBlurBuffer1 = new X(r, i, { type: U }), this.renderTargetBlurBuffer1.texture.name = "OutlinePass.blur1", this.renderTargetBlurBuffer1.texture.generateMipmaps = !1, this.renderTargetBlurBuffer2 = new X(Math.round(r / 2), Math.round(i / 2), { type: U }), this.renderTargetBlurBuffer2.texture.name = "OutlinePass.blur2", this.renderTargetBlurBuffer2.texture.generateMipmaps = !1, this.edgeDetectionMaterial = this._getEdgeDetectionMaterial(), this.renderTargetEdgeBuffer1 = new X(r, i, { type: U }), this.renderTargetEdgeBuffer1.texture.name = "OutlinePass.edge1", this.renderTargetEdgeBuffer1.texture.generateMipmaps = !1, this.renderTargetEdgeBuffer2 = new X(Math.round(r / 2), Math.round(i / 2), { type: U }), this.renderTargetEdgeBuffer2.texture.name = "OutlinePass.edge2", this.renderTargetEdgeBuffer2.texture.generateMipmaps = !1;
869
+ const a = 4, d = 4;
870
+ this.separableBlurMaterial1 = this._getSeparableBlurMaterial(a), this.separableBlurMaterial1.uniforms.texSize.value.set(r, i), this.separableBlurMaterial1.uniforms.kernelRadius.value = 1, this.separableBlurMaterial2 = this._getSeparableBlurMaterial(d), this.separableBlurMaterial2.uniforms.texSize.value.set(Math.round(r / 2), Math.round(i / 2)), this.separableBlurMaterial2.uniforms.kernelRadius.value = d, this.overlayMaterial = this._getOverlayMaterial();
871
+ const f = Dt;
872
+ this.copyUniforms = Fe.clone(f.uniforms), this.materialCopy = new V({
873
+ uniforms: this.copyUniforms,
874
+ vertexShader: f.vertexShader,
875
+ fragmentShader: f.fragmentShader,
876
+ blending: we,
877
+ depthTest: !1,
878
+ depthWrite: !1
879
+ }), this.enabled = !0, this.needsSwap = !1, this._oldClearColor = new F(), this.oldClearAlpha = 1, this._fsQuad = new kt(null), this.tempPulseColor1 = new F(), this.tempPulseColor2 = new F(), this.textureMatrix = new ce();
880
+ function D(R, Q) {
881
+ const N = Q.isPerspectiveCamera ? "perspective" : "orthographic";
882
+ return R.replace(/DEPTH_TO_VIEW_Z/g, N + "DepthToViewZ");
883
+ }
884
+ }
885
+ /**
886
+ * Frees the GPU-related resources allocated by this instance. Call this
887
+ * method whenever the pass is no longer used in your app.
888
+ */
889
+ dispose() {
890
+ 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();
891
+ }
892
+ /**
893
+ * Sets the size of the pass.
894
+ *
895
+ * @param {number} width - The width to set.
896
+ * @param {number} height - The width to set.
897
+ */
898
+ setSize(e, t) {
899
+ this.renderTargetMaskBuffer.setSize(e, t), this.renderTargetDepthBuffer.setSize(e, t);
900
+ let n = Math.round(e / this.downSampleRatio), s = Math.round(t / this.downSampleRatio);
901
+ this.renderTargetMaskDownSampleBuffer.setSize(n, s), this.renderTargetBlurBuffer1.setSize(n, s), this.renderTargetEdgeBuffer1.setSize(n, s), this.separableBlurMaterial1.uniforms.texSize.value.set(n, s), n = Math.round(n / 2), s = Math.round(s / 2), this.renderTargetBlurBuffer2.setSize(n, s), this.renderTargetEdgeBuffer2.setSize(n, s), this.separableBlurMaterial2.uniforms.texSize.value.set(n, s);
902
+ }
903
+ /**
904
+ * Performs the Outline pass.
905
+ *
906
+ * @param {WebGLRenderer} renderer - The renderer.
907
+ * @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
908
+ * destination for the pass.
909
+ * @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
910
+ * previous pass from this buffer.
911
+ * @param {number} deltaTime - The delta time in seconds.
912
+ * @param {boolean} maskActive - Whether masking is active or not.
913
+ */
914
+ render(e, t, n, s, r) {
915
+ if (this.selectedObjects.length > 0) {
916
+ e.getClearColor(this._oldClearColor), this.oldClearAlpha = e.getClearAlpha();
917
+ const i = e.autoClear;
918
+ e.autoClear = !1, r && e.state.buffers.stencil.setTest(!1), e.setClearColor(16777215, 1), this._updateSelectionCache(), this._changeVisibilityOfSelectedObjects(!1);
919
+ const a = this.renderScene.background, d = this.renderScene.overrideMaterial;
920
+ if (this.renderScene.background = null, this.renderScene.overrideMaterial = this.depthMaterial, e.setRenderTarget(this.renderTargetDepthBuffer), e.clear(), e.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, e.setRenderTarget(this.renderTargetMaskBuffer), e.clear(), e.render(this.renderScene, this.renderCamera), this._changeVisibilityOfNonSelectedObjects(!0), this._visibilityCache.clear(), this._selectionCache.clear(), this.renderScene.background = a, this.renderScene.overrideMaterial = d, this._fsQuad.material = this.materialCopy, this.copyUniforms.tDiffuse.value = this.renderTargetMaskBuffer.texture, e.setRenderTarget(this.renderTargetMaskDownSampleBuffer), e.clear(), this._fsQuad.render(e), this.tempPulseColor1.copy(this.visibleEdgeColor), this.tempPulseColor2.copy(this.hiddenEdgeColor), this.pulsePeriod > 0) {
921
+ const f = 0.625 + Math.cos(performance.now() * 0.01 / this.pulsePeriod) * 0.75 / 2;
922
+ this.tempPulseColor1.multiplyScalar(f), this.tempPulseColor2.multiplyScalar(f);
923
+ }
924
+ 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, e.setRenderTarget(this.renderTargetEdgeBuffer1), e.clear(), this._fsQuad.render(e), this._fsQuad.material = this.separableBlurMaterial1, this.separableBlurMaterial1.uniforms.colorTexture.value = this.renderTargetEdgeBuffer1.texture, this.separableBlurMaterial1.uniforms.direction.value = A.BlurDirectionX, this.separableBlurMaterial1.uniforms.kernelRadius.value = this.edgeThickness, e.setRenderTarget(this.renderTargetBlurBuffer1), e.clear(), this._fsQuad.render(e), this.separableBlurMaterial1.uniforms.colorTexture.value = this.renderTargetBlurBuffer1.texture, this.separableBlurMaterial1.uniforms.direction.value = A.BlurDirectionY, e.setRenderTarget(this.renderTargetEdgeBuffer1), e.clear(), this._fsQuad.render(e), this._fsQuad.material = this.separableBlurMaterial2, this.separableBlurMaterial2.uniforms.colorTexture.value = this.renderTargetEdgeBuffer1.texture, this.separableBlurMaterial2.uniforms.direction.value = A.BlurDirectionX, e.setRenderTarget(this.renderTargetBlurBuffer2), e.clear(), this._fsQuad.render(e), this.separableBlurMaterial2.uniforms.colorTexture.value = this.renderTargetBlurBuffer2.texture, this.separableBlurMaterial2.uniforms.direction.value = A.BlurDirectionY, e.setRenderTarget(this.renderTargetEdgeBuffer2), e.clear(), this._fsQuad.render(e), 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, r && e.state.buffers.stencil.setTest(!0), e.setRenderTarget(n), this._fsQuad.render(e), e.setClearColor(this._oldClearColor, this.oldClearAlpha), e.autoClear = i;
925
+ }
926
+ this.renderToScreen && (this._fsQuad.material = this.materialCopy, this.copyUniforms.tDiffuse.value = n.texture, e.setRenderTarget(null), this._fsQuad.render(e));
927
+ }
928
+ // internals
929
+ _updateSelectionCache() {
930
+ const e = this._selectionCache;
931
+ function t(n) {
932
+ n.isMesh && e.add(n);
933
+ }
934
+ e.clear();
935
+ for (let n = 0; n < this.selectedObjects.length; n++)
936
+ this.selectedObjects[n].traverse(t);
937
+ }
938
+ _changeVisibilityOfSelectedObjects(e) {
939
+ const t = this._visibilityCache;
940
+ for (const n of this._selectionCache)
941
+ e === !0 ? n.visible = t.get(n) : (t.set(n, n.visible), n.visible = e);
942
+ }
943
+ _changeVisibilityOfNonSelectedObjects(e) {
944
+ const t = this._visibilityCache, n = this._selectionCache;
945
+ function s(r) {
946
+ if (r.isMesh || r.isSprite) {
947
+ if (!n.has(r)) {
948
+ const i = r.visible;
949
+ (e === !1 || t.get(r) === !0) && (r.visible = e), t.set(r, i);
950
+ }
951
+ } else (r.isPoints || r.isLine) && (e === !0 ? r.visible = t.get(r) : (t.set(r, r.visible), r.visible = e));
952
+ }
953
+ this.renderScene.traverse(s);
954
+ }
955
+ _updateTextureMatrix() {
956
+ this.textureMatrix.set(
957
+ 0.5,
958
+ 0,
959
+ 0,
960
+ 0.5,
961
+ 0,
962
+ 0.5,
963
+ 0,
964
+ 0.5,
965
+ 0,
966
+ 0,
967
+ 0.5,
968
+ 0.5,
969
+ 0,
970
+ 0,
971
+ 0,
972
+ 1
973
+ ), this.textureMatrix.multiply(this.renderCamera.projectionMatrix), this.textureMatrix.multiply(this.renderCamera.matrixWorldInverse);
974
+ }
975
+ _getPrepareMaskMaterial() {
976
+ return new V({
977
+ uniforms: {
978
+ depthTexture: { value: null },
979
+ cameraNearFar: { value: new k(0.5, 0.5) },
980
+ textureMatrix: { value: null }
981
+ },
982
+ vertexShader: `#include <batching_pars_vertex>
983
+ #include <morphtarget_pars_vertex>
984
+ #include <skinning_pars_vertex>
985
+
986
+ varying vec4 projTexCoord;
987
+ varying vec4 vPosition;
988
+ uniform mat4 textureMatrix;
989
+
990
+ void main() {
991
+
992
+ #include <batching_vertex>
993
+ #include <skinbase_vertex>
994
+ #include <begin_vertex>
995
+ #include <morphtarget_vertex>
996
+ #include <skinning_vertex>
997
+ #include <project_vertex>
998
+
999
+ vPosition = mvPosition;
1000
+
1001
+ vec4 worldPosition = vec4( transformed, 1.0 );
1002
+
1003
+ #ifdef USE_INSTANCING
1004
+
1005
+ worldPosition = instanceMatrix * worldPosition;
1006
+
1007
+ #endif
1008
+
1009
+ worldPosition = modelMatrix * worldPosition;
1010
+
1011
+ projTexCoord = textureMatrix * worldPosition;
1012
+
1013
+ }`,
1014
+ fragmentShader: `#include <packing>
1015
+ varying vec4 vPosition;
1016
+ varying vec4 projTexCoord;
1017
+ uniform sampler2D depthTexture;
1018
+ uniform vec2 cameraNearFar;
1019
+
1020
+ void main() {
1021
+
1022
+ float depth = unpackRGBAToDepth(texture2DProj( depthTexture, projTexCoord ));
1023
+ float viewZ = - DEPTH_TO_VIEW_Z( depth, cameraNearFar.x, cameraNearFar.y );
1024
+ float depthTest = (-vPosition.z > viewZ) ? 1.0 : 0.0;
1025
+ gl_FragColor = vec4(0.0, depthTest, 1.0, 1.0);
1026
+
1027
+ }`
1028
+ });
1029
+ }
1030
+ _getEdgeDetectionMaterial() {
1031
+ return new V({
1032
+ uniforms: {
1033
+ maskTexture: { value: null },
1034
+ texSize: { value: new k(0.5, 0.5) },
1035
+ visibleEdgeColor: { value: new l(1, 1, 1) },
1036
+ hiddenEdgeColor: { value: new l(1, 1, 1) }
1037
+ },
1038
+ vertexShader: `varying vec2 vUv;
1039
+
1040
+ void main() {
1041
+ vUv = uv;
1042
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
1043
+ }`,
1044
+ fragmentShader: `varying vec2 vUv;
1045
+
1046
+ uniform sampler2D maskTexture;
1047
+ uniform vec2 texSize;
1048
+ uniform vec3 visibleEdgeColor;
1049
+ uniform vec3 hiddenEdgeColor;
1050
+
1051
+ void main() {
1052
+ vec2 invSize = 1.0 / texSize;
1053
+ vec4 uvOffset = vec4(1.0, 0.0, 0.0, 1.0) * vec4(invSize, invSize);
1054
+ vec4 c1 = texture2D( maskTexture, vUv + uvOffset.xy);
1055
+ vec4 c2 = texture2D( maskTexture, vUv - uvOffset.xy);
1056
+ vec4 c3 = texture2D( maskTexture, vUv + uvOffset.yw);
1057
+ vec4 c4 = texture2D( maskTexture, vUv - uvOffset.yw);
1058
+ float diff1 = (c1.r - c2.r)*0.5;
1059
+ float diff2 = (c3.r - c4.r)*0.5;
1060
+ float d = length( vec2(diff1, diff2) );
1061
+ float a1 = min(c1.g, c2.g);
1062
+ float a2 = min(c3.g, c4.g);
1063
+ float visibilityFactor = min(a1, a2);
1064
+ vec3 edgeColor = 1.0 - visibilityFactor > 0.001 ? visibleEdgeColor : hiddenEdgeColor;
1065
+ gl_FragColor = vec4(edgeColor, 1.0) * vec4(d);
1066
+ }`
1067
+ });
1068
+ }
1069
+ _getSeparableBlurMaterial(e) {
1070
+ return new V({
1071
+ defines: {
1072
+ MAX_RADIUS: e
1073
+ },
1074
+ uniforms: {
1075
+ colorTexture: { value: null },
1076
+ texSize: { value: new k(0.5, 0.5) },
1077
+ direction: { value: new k(0.5, 0.5) },
1078
+ kernelRadius: { value: 1 }
1079
+ },
1080
+ vertexShader: `varying vec2 vUv;
1081
+
1082
+ void main() {
1083
+ vUv = uv;
1084
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
1085
+ }`,
1086
+ fragmentShader: `#include <common>
1087
+ varying vec2 vUv;
1088
+ uniform sampler2D colorTexture;
1089
+ uniform vec2 texSize;
1090
+ uniform vec2 direction;
1091
+ uniform float kernelRadius;
1092
+
1093
+ float gaussianPdf(in float x, in float sigma) {
1094
+ return 0.39894 * exp( -0.5 * x * x/( sigma * sigma))/sigma;
1095
+ }
1096
+
1097
+ void main() {
1098
+ vec2 invSize = 1.0 / texSize;
1099
+ float sigma = kernelRadius/2.0;
1100
+ float weightSum = gaussianPdf(0.0, sigma);
1101
+ vec4 diffuseSum = texture2D( colorTexture, vUv) * weightSum;
1102
+ vec2 delta = direction * invSize * kernelRadius/float(MAX_RADIUS);
1103
+ vec2 uvOffset = delta;
1104
+ for( int i = 1; i <= MAX_RADIUS; i ++ ) {
1105
+ float x = kernelRadius * float(i) / float(MAX_RADIUS);
1106
+ float w = gaussianPdf(x, sigma);
1107
+ vec4 sample1 = texture2D( colorTexture, vUv + uvOffset);
1108
+ vec4 sample2 = texture2D( colorTexture, vUv - uvOffset);
1109
+ diffuseSum += ((sample1 + sample2) * w);
1110
+ weightSum += (2.0 * w);
1111
+ uvOffset += delta;
1112
+ }
1113
+ gl_FragColor = diffuseSum/weightSum;
1114
+ }`
1115
+ });
1116
+ }
1117
+ _getOverlayMaterial() {
1118
+ return new V({
1119
+ uniforms: {
1120
+ maskTexture: { value: null },
1121
+ edgeTexture1: { value: null },
1122
+ edgeTexture2: { value: null },
1123
+ patternTexture: { value: null },
1124
+ edgeStrength: { value: 1 },
1125
+ edgeGlow: { value: 1 },
1126
+ usePatternTexture: { value: 0 }
1127
+ },
1128
+ vertexShader: `varying vec2 vUv;
1129
+
1130
+ void main() {
1131
+ vUv = uv;
1132
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
1133
+ }`,
1134
+ fragmentShader: `varying vec2 vUv;
1135
+
1136
+ uniform sampler2D maskTexture;
1137
+ uniform sampler2D edgeTexture1;
1138
+ uniform sampler2D edgeTexture2;
1139
+ uniform sampler2D patternTexture;
1140
+ uniform float edgeStrength;
1141
+ uniform float edgeGlow;
1142
+ uniform bool usePatternTexture;
1143
+
1144
+ void main() {
1145
+ vec4 edgeValue1 = texture2D(edgeTexture1, vUv);
1146
+ vec4 edgeValue2 = texture2D(edgeTexture2, vUv);
1147
+ vec4 maskColor = texture2D(maskTexture, vUv);
1148
+ vec4 patternColor = texture2D(patternTexture, 6.0 * vUv);
1149
+ float visibilityFactor = 1.0 - maskColor.g > 0.0 ? 1.0 : 0.5;
1150
+ vec4 edgeValue = edgeValue1 + edgeValue2 * edgeGlow;
1151
+ vec4 finalColor = edgeStrength * maskColor.r * edgeValue;
1152
+ if(usePatternTexture)
1153
+ finalColor += + visibilityFactor * (1.0 - maskColor.r) * (1.0 - patternColor.r);
1154
+ gl_FragColor = finalColor;
1155
+ }`,
1156
+ blending: Ve,
1157
+ depthTest: !1,
1158
+ depthWrite: !1,
1159
+ transparent: !0
1160
+ });
1161
+ }
1162
+ }
1163
+ A.BlurDirectionX = new k(1, 0);
1164
+ A.BlurDirectionY = new k(0, 1);
1165
+ function Bt(h, e, t, n, s) {
1166
+ h.traverse((r) => {
1167
+ var i, a;
1168
+ if (r instanceof o)
1169
+ if (e === "solid") {
1170
+ (i = n.get(r.uuid)) == null || i.dispose(), n.delete(r.uuid);
1171
+ const d = t.get(r.uuid);
1172
+ d && (r.material = d, t.delete(r.uuid));
1173
+ } else {
1174
+ t.has(r.uuid) || t.set(r.uuid, r.material), (a = n.get(r.uuid)) == null || a.dispose(), s.has(r.uuid) || s.set(r.uuid, Math.random() * 16777215);
1175
+ const d = s.get(r.uuid), f = new me(
1176
+ e === "wireframe" ? { wireframe: !0, color: d } : { color: d }
1177
+ );
1178
+ n.set(r.uuid, f), r.material = f;
1179
+ }
1180
+ });
1181
+ }
1182
+ class Ce extends rt {
1183
+ constructor() {
1184
+ var e;
1185
+ 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.activeAssetCategory = "Object", c.instance().editor = this, (e = c.instance().logger) == null || e.info("Booting Editor"), c.instance().trigger("editorBoot", this), c.instance().trigger("uiDestroy", this), c.instance().world.destroy(), c.instance().scene.traverse((t) => {
1186
+ var n, s;
1187
+ t instanceof o && ((n = t.geometry) == null || n.dispose(), Array.isArray(t.material) ? t.material.forEach((r) => r.dispose()) : (s = t.material) == null || s.dispose());
1188
+ }), c.instance().scene.clear(), this.initEditorScene(), c.instance().contextMenuAbort.abort(), c.instance().uiRoot.innerHTML = "", c.instance().uiRoot.style.opacity = "1", document.title = "MavonEngine | Editor", document.getElementsByTagName("body")[0].removeAttribute("onContextMenu"), Promise.all([
1189
+ import("./mount-wt1eaFr0.mjs"),
1190
+ Promise.resolve({ })
1191
+ ]).then(([{ mountEditorUI: t }]) => {
1192
+ this.reactRoot = t(c.instance().uiRoot);
1193
+ });
1194
+ }
1195
+ /**
1196
+ * The editor should only be instantiated when button is pressed
1197
+ */
1198
+ static registerListener() {
1199
+ c.instance().input.on("keydown", (e) => {
1200
+ (e.code === "Insert" || e.code === "Period") && (c.instance().editor = new Ce());
1201
+ });
1202
+ }
1203
+ initEditorScene() {
1204
+ c.instance().camera.instance.position.set(20, 10, 20), c.instance().camera.instance.rotation.set(0, 0, 0), c.instance().camera.instance.rotateY(Math.PI / 360 * 90), c.instance().camera.instance.rotateX(Math.PI / 360 * -45), this.outlinePass = new A(
1205
+ new k(c.instance().sizes.width, c.instance().sizes.height),
1206
+ c.instance().scene,
1207
+ c.instance().camera.instance
1208
+ ), c.instance().renderer.composer.addPass(this.outlinePass), this.initFlyControls();
1209
+ const e = new We(new l(0, 5, 0)), t = new qe(new l(10, 15, 5));
1210
+ t.instance.intensity = 5;
1211
+ const n = new Ke(new l(0, 0, 0), 50, 50);
1212
+ n.setReceiveShadow(!0), n.instance instanceof o && n.instance.material.color.set("#ffbe6f");
1213
+ const s = 5, r = [
1214
+ new Ne(new l(s, 0.5, 0)),
1215
+ new $e(new l(s * 0.707, 1, s * 0.707)),
1216
+ new Je(new l(0, 0.5, s)),
1217
+ new et(new l(-s * 0.707, 0.5, s * 0.707)),
1218
+ new tt(new l(-s, 1, 0)),
1219
+ new it(new l(-s * 0.707, 1, -s * 0.707)),
1220
+ new st(new l(0, 1, -s)),
1221
+ new nt(new l(s * 0.707, 1, -s * 0.707)),
1222
+ new at(new l(0, 3.5, 0))
1223
+ ];
1224
+ r.forEach((a) => a.setCastShadow(!0));
1225
+ const i = {};
1226
+ [e, t, n, ...r].forEach((a) => i[a.id] = a), c.instance().world.add(i), this.trigger("sceneChanged"), c.instance().input.on("mousedown", (a) => {
1227
+ a.target === c.instance().canvas && this.handleCanvasClick(a);
1228
+ }), c.instance().input.on("keydown", (a) => {
1229
+ a.code === "Escape" && this.activeItem && this.deselect();
1230
+ }), this.handleItemDelete(), this.on("setTransformMode", (a) => {
1231
+ var d, f;
1232
+ this.activeToolMode = a, (d = this.transformControls) == null || d.setMode(a), (f = c.instance().logger) == null || f.info(`Setting editor tool mode: ${a}`);
1233
+ }), this.on("setShadeMode", (a) => {
1234
+ this.applyShadeMode(a);
1235
+ }), this.on("assetDropped", () => {
1236
+ this.shadeMode !== "solid" && this.applyShadeMode(this.shadeMode);
1237
+ }), this.initAssetsFilter();
1238
+ }
1239
+ initAssetsFilter() {
1240
+ this.availableAssetCategories = [
1241
+ ...new Set(Object.entries(c.instance().resources.items).map(([e, t]) => t.constructor.name))
1242
+ ];
1243
+ }
1244
+ setActiveAssetCategory(e) {
1245
+ this.activeAssetCategory = e;
1246
+ }
1247
+ applyShadeMode(e) {
1248
+ this.shadeMode = e, Bt(c.instance().scene, e, this.originalMaterials, this.shadeOverrideMaterials, this.flatColors);
1249
+ }
1250
+ initFlyControls() {
1251
+ this.flyControls = new lt(c.instance().camera.instance, c.instance().canvas), this.flyControls.autoForward = !1, this.flyControls.dragToLook = !0, this.flyControls.movementSpeed = 10, this.flyControls.rollSpeed = 0.5;
1252
+ }
1253
+ handleItemDelete() {
1254
+ c.instance().input.on("keydown", (e) => {
1255
+ if (e.code === "Delete" && this.activeItem) {
1256
+ let t = this.activeItem;
1257
+ for (; t.parent && t.parent !== c.instance().scene; )
1258
+ t = t.parent;
1259
+ t.traverse((s) => {
1260
+ var r, i;
1261
+ s instanceof o && ((r = s.geometry) == null || r.dispose(), Array.isArray(s.material) ? s.material.forEach((a) => a.dispose()) : (i = s.material) == null || i.dispose());
1262
+ }), this.deselect();
1263
+ const n = Ge.from(t);
1264
+ n != null && n.owner ? n.owner.destroy() : (n && (n.dispose(), this.helpers = this.helpers.filter((s) => s !== n)), c.instance().scene.remove(t)), this.trigger("sceneChanged");
1265
+ }
1266
+ });
1267
+ }
1268
+ deselect() {
1269
+ var e;
1270
+ (e = this.transformControls) == null || e.detach(), this.outlinePass.selectedObjects = [], this.activeItem = null, this.trigger("objectDeselected");
1271
+ }
1272
+ selectObject(e) {
1273
+ this.activeItem = e, this.trigger("objectSelected", this.activeItem), this.outlinePass.selectedObjects = [this.activeItem], this.handleHelperTool();
1274
+ }
1275
+ handleCanvasClick(e) {
1276
+ if (e.button === 0) {
1277
+ if (this.transformControls && (this.transformControls.dragging || this.transformControls.axis !== null))
1278
+ return;
1279
+ const t = c.instance().input.getPointerWorldPosition(void 0, null, !0);
1280
+ t instanceof le ? this.selectObject(t) : this.deselect();
1281
+ }
1282
+ }
1283
+ handleHelperTool() {
1284
+ if (!this.transformControls) {
1285
+ this.transformControls = new vt(
1286
+ c.instance().camera.instance,
1287
+ c.instance().canvas
1288
+ ), this.transformControls.addEventListener("dragging-changed", (t) => {
1289
+ this.flyControls.enabled = !t.value, t.value || this.initFlyControls();
1290
+ });
1291
+ const e = this.transformControls.getHelper();
1292
+ e.userData.isEditorInternal = !0, c.instance().scene.add(e);
1293
+ }
1294
+ this.transformControls.setMode(this.activeToolMode), this.transformControls.attach(this.activeItem);
1295
+ }
1296
+ addHelper(e) {
1297
+ this.helpers.push(e), this._showHelpers || (e.mesh.visible = !1, e.label.domElement.style.display = "none");
1298
+ }
1299
+ removeHelper(e) {
1300
+ this.helpers = this.helpers.filter((t) => t !== e);
1301
+ }
1302
+ addLightHelper(e) {
1303
+ this.lightHelpers.push(e), this._showHelpers || (e.visible = !1);
1304
+ }
1305
+ removeLightHelper(e) {
1306
+ this.lightHelpers = this.lightHelpers.filter((t) => t !== e);
1307
+ }
1308
+ setShowHelpers(e) {
1309
+ this._showHelpers = e, this.helpers.forEach((t) => {
1310
+ t.mesh.visible = e, t.label.domElement.style.display = e ? "" : "none";
1311
+ }), this.lightHelpers.forEach((t) => t.visible = e);
1312
+ }
1313
+ update(e) {
1314
+ this.updateCamera(e), this.helpers.forEach((t) => t.update(e));
1315
+ }
1316
+ updateCamera(e) {
1317
+ this.flyControls.update(e);
1318
+ const t = c.instance().camera.instance, n = new l();
1319
+ t.getWorldDirection(n), t.quaternion.setFromRotationMatrix(
1320
+ new ce().lookAt(new l(), n, new l(0, 1, 0))
1321
+ );
1322
+ }
1323
+ destroy() {
1324
+ this.reactRoot.unmount(), this.outlinePass.dispose(), this.shadeOverrideMaterials.forEach((e) => e.dispose()), this.shadeOverrideMaterials.clear(), this.originalMaterials.clear(), this.flatColors.clear();
1325
+ }
1326
+ }
1327
+ export {
1328
+ Dt as C,
1329
+ Ce as E,
1330
+ kt as F,
1331
+ Pt as P,
1332
+ Bt as a
1333
+ };