@mavonengine/editor 0.0.7 → 0.0.9

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.
Files changed (35) hide show
  1. package/dist/Editor/UI/ActivityBar.d.ts +1 -1
  2. package/dist/Editor/UI/Assets/AssetStats.d.ts +3 -3
  3. package/dist/Editor/UI/Assets/Assets.d.ts +1 -1
  4. package/dist/Editor/UI/Assets/AudioPlayer.d.ts +1 -1
  5. package/dist/Editor/UI/Assets/ModelViewer.d.ts +3 -3
  6. package/dist/Editor/UI/Assets/ParticleViewer.d.ts +3 -3
  7. package/dist/Editor/UI/Assets/TextureViewer.d.ts +5 -4
  8. package/dist/Editor/UI/CanvasPanel.d.ts +1 -1
  9. package/dist/Editor/UI/CanvasToolbar.d.ts +1 -1
  10. package/dist/Editor/UI/Controllers/ControllerDebug.d.ts +1 -0
  11. package/dist/Editor/UI/Controllers/GamepadDiagram.d.ts +5 -0
  12. package/dist/Editor/UI/Controllers/useGamepads.d.ts +6 -0
  13. package/dist/Editor/UI/DockArea.d.ts +17 -0
  14. package/dist/Editor/UI/Editor.d.ts +1 -1
  15. package/dist/Editor/UI/PanelHeader.d.ts +1 -1
  16. package/dist/Editor/UI/PropertiesPanel.d.ts +1 -1
  17. package/dist/Editor/UI/SceneExplorer.d.ts +1 -1
  18. package/dist/Editor/UI/ScenePanel.d.ts +1 -0
  19. package/dist/Editor/UI/ShadeModeButtons.d.ts +1 -1
  20. package/dist/Editor/UI/StatusBar.d.ts +1 -1
  21. package/dist/Editor/UI/TabBar.d.ts +1 -1
  22. package/dist/Editor/UI/Window.d.ts +1 -1
  23. package/dist/Editor/builtinPrefabs.d.ts +4 -0
  24. package/dist/Editor/demoScene.d.ts +7 -0
  25. package/dist/Editor/panels.d.ts +22 -0
  26. package/dist/Editor/recordPrefabUsage.d.ts +7 -0
  27. package/dist/Editor.css +2 -1
  28. package/dist/Editor.d.ts +29 -5
  29. package/dist/Editor.mjs +1654 -9
  30. package/dist/global-l94NfB94.mjs +22 -0
  31. package/dist/mount-CnirMLg0.mjs +35603 -0
  32. package/dist/panels-BqmX3eap.mjs +45 -0
  33. package/package.json +20 -20
  34. package/dist/Editor-BZKTiLdQ.mjs +0 -1329
  35. package/dist/mount-DicE86w2.mjs +0 -40697
@@ -1,1329 +0,0 @@
1
- import { Quaternion as M, 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 M();
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 M(), 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 M(), _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" }, Me = { type: "mouseDown", mode: null }, Se = { 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 St(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 M(), R = new M(), Q = new l(), N = new M(), $ = 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 M(), this._parentQuaternionInv = new M(), this._parentScale = new l(), this._worldScaleStart = new l(), this._worldQuaternionInv = new M(), this._worldScale = new l(), this._positionStart = new l(), this._quaternionStart = new M(), 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 = Mt.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, Me.mode = this.mode, this.dispatchEvent(Me);
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 && (Se.mode = this.mode, this.dispatchEvent(Se)), 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 Mt(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 M(), oe = new M(), 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 St 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 S = new j(_, 75e-4, 3, 64, J * Math.PI * 2);
478
- return S.rotateY(Math.PI / 2), S.rotateX(Math.PI / 2), S;
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 S in _)
659
- for (let Z = _[S].length; Z--; ) {
660
- const w = _[S][Z][0].clone(), ee = _[S][Z][1], te = _[S][Z][2], ie = _[S][Z][3], ze = _[S][Z][4];
661
- w.name = S, 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
- uniforms: {
819
- tDiffuse: { value: null },
820
- opacity: { value: 1 }
821
- },
822
- vertexShader: (
823
- /* glsl */
824
- `
825
-
826
- varying vec2 vUv;
827
-
828
- void main() {
829
-
830
- vUv = uv;
831
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
832
-
833
- }`
834
- ),
835
- fragmentShader: (
836
- /* glsl */
837
- `
838
-
839
- uniform float opacity;
840
-
841
- uniform sampler2D tDiffuse;
842
-
843
- varying vec2 vUv;
844
-
845
- void main() {
846
-
847
- vec4 texel = texture2D( tDiffuse, vUv );
848
- gl_FragColor = opacity * texel;
849
-
850
-
851
- }`
852
- )
853
- };
854
- class A extends Pt {
855
- /**
856
- * Constructs a new outline pass.
857
- *
858
- * @param {Vector2} [resolution] - The effect's resolution.
859
- * @param {Scene} scene - The scene to render.
860
- * @param {Camera} camera - The camera.
861
- * @param {Array<Object3D>} [selectedObjects] - The selected 3D objects that should receive an outline.
862
- *
863
- */
864
- constructor(e, t, n, s) {
865
- 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);
866
- const r = Math.round(this.resolution.x / this.downSampleRatio), i = Math.round(this.resolution.y / this.downSampleRatio);
867
- 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;
868
- const a = 4, d = 4;
869
- 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();
870
- const f = Dt;
871
- this.copyUniforms = Fe.clone(f.uniforms), this.materialCopy = new V({
872
- uniforms: this.copyUniforms,
873
- vertexShader: f.vertexShader,
874
- fragmentShader: f.fragmentShader,
875
- blending: we,
876
- depthTest: !1,
877
- depthWrite: !1
878
- }), 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();
879
- function D(R, Q) {
880
- const N = Q.isPerspectiveCamera ? "perspective" : "orthographic";
881
- return R.replace(/DEPTH_TO_VIEW_Z/g, N + "DepthToViewZ");
882
- }
883
- }
884
- /**
885
- * Frees the GPU-related resources allocated by this instance. Call this
886
- * method whenever the pass is no longer used in your app.
887
- */
888
- dispose() {
889
- 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();
890
- }
891
- /**
892
- * Sets the size of the pass.
893
- *
894
- * @param {number} width - The width to set.
895
- * @param {number} height - The width to set.
896
- */
897
- setSize(e, t) {
898
- this.renderTargetMaskBuffer.setSize(e, t), this.renderTargetDepthBuffer.setSize(e, t);
899
- let n = Math.round(e / this.downSampleRatio), s = Math.round(t / this.downSampleRatio);
900
- 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);
901
- }
902
- /**
903
- * Performs the Outline pass.
904
- *
905
- * @param {WebGLRenderer} renderer - The renderer.
906
- * @param {WebGLRenderTarget} writeBuffer - The write buffer. This buffer is intended as the rendering
907
- * destination for the pass.
908
- * @param {WebGLRenderTarget} readBuffer - The read buffer. The pass can access the result from the
909
- * previous pass from this buffer.
910
- * @param {number} deltaTime - The delta time in seconds.
911
- * @param {boolean} maskActive - Whether masking is active or not.
912
- */
913
- render(e, t, n, s, r) {
914
- if (this.selectedObjects.length > 0) {
915
- e.getClearColor(this._oldClearColor), this.oldClearAlpha = e.getClearAlpha();
916
- const i = e.autoClear;
917
- e.autoClear = !1, r && e.state.buffers.stencil.setTest(!1), e.setClearColor(16777215, 1), this._updateSelectionCache(), this._changeVisibilityOfSelectedObjects(!1);
918
- const a = this.renderScene.background, d = this.renderScene.overrideMaterial;
919
- 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) {
920
- const f = 0.625 + Math.cos(performance.now() * 0.01 / this.pulsePeriod) * 0.75 / 2;
921
- this.tempPulseColor1.multiplyScalar(f), this.tempPulseColor2.multiplyScalar(f);
922
- }
923
- 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;
924
- }
925
- this.renderToScreen && (this._fsQuad.material = this.materialCopy, this.copyUniforms.tDiffuse.value = n.texture, e.setRenderTarget(null), this._fsQuad.render(e));
926
- }
927
- // internals
928
- _updateSelectionCache() {
929
- const e = this._selectionCache;
930
- function t(n) {
931
- n.isMesh && e.add(n);
932
- }
933
- e.clear();
934
- for (let n = 0; n < this.selectedObjects.length; n++)
935
- this.selectedObjects[n].traverse(t);
936
- }
937
- _changeVisibilityOfSelectedObjects(e) {
938
- const t = this._visibilityCache;
939
- for (const n of this._selectionCache)
940
- e === !0 ? n.visible = t.get(n) : (t.set(n, n.visible), n.visible = e);
941
- }
942
- _changeVisibilityOfNonSelectedObjects(e) {
943
- const t = this._visibilityCache, n = this._selectionCache;
944
- function s(r) {
945
- if (r.isMesh || r.isSprite) {
946
- if (!n.has(r)) {
947
- const i = r.visible;
948
- (e === !1 || t.get(r) === !0) && (r.visible = e), t.set(r, i);
949
- }
950
- } else (r.isPoints || r.isLine) && (e === !0 ? r.visible = t.get(r) : (t.set(r, r.visible), r.visible = e));
951
- }
952
- this.renderScene.traverse(s);
953
- }
954
- _updateTextureMatrix() {
955
- this.textureMatrix.set(
956
- 0.5,
957
- 0,
958
- 0,
959
- 0.5,
960
- 0,
961
- 0.5,
962
- 0,
963
- 0.5,
964
- 0,
965
- 0,
966
- 0.5,
967
- 0.5,
968
- 0,
969
- 0,
970
- 0,
971
- 1
972
- ), this.textureMatrix.multiply(this.renderCamera.projectionMatrix), this.textureMatrix.multiply(this.renderCamera.matrixWorldInverse);
973
- }
974
- _getPrepareMaskMaterial() {
975
- return new V({
976
- uniforms: {
977
- depthTexture: { value: null },
978
- cameraNearFar: { value: new k(0.5, 0.5) },
979
- textureMatrix: { value: null }
980
- },
981
- vertexShader: `#include <batching_pars_vertex>
982
- #include <morphtarget_pars_vertex>
983
- #include <skinning_pars_vertex>
984
-
985
- varying vec4 projTexCoord;
986
- varying vec4 vPosition;
987
- uniform mat4 textureMatrix;
988
-
989
- void main() {
990
-
991
- #include <batching_vertex>
992
- #include <skinbase_vertex>
993
- #include <begin_vertex>
994
- #include <morphtarget_vertex>
995
- #include <skinning_vertex>
996
- #include <project_vertex>
997
-
998
- vPosition = mvPosition;
999
-
1000
- vec4 worldPosition = vec4( transformed, 1.0 );
1001
-
1002
- #ifdef USE_INSTANCING
1003
-
1004
- worldPosition = instanceMatrix * worldPosition;
1005
-
1006
- #endif
1007
-
1008
- worldPosition = modelMatrix * worldPosition;
1009
-
1010
- projTexCoord = textureMatrix * worldPosition;
1011
-
1012
- }`,
1013
- fragmentShader: `#include <packing>
1014
- varying vec4 vPosition;
1015
- varying vec4 projTexCoord;
1016
- uniform sampler2D depthTexture;
1017
- uniform vec2 cameraNearFar;
1018
-
1019
- void main() {
1020
-
1021
- float depth = unpackRGBAToDepth(texture2DProj( depthTexture, projTexCoord ));
1022
- float viewZ = - DEPTH_TO_VIEW_Z( depth, cameraNearFar.x, cameraNearFar.y );
1023
- float depthTest = (-vPosition.z > viewZ) ? 1.0 : 0.0;
1024
- gl_FragColor = vec4(0.0, depthTest, 1.0, 1.0);
1025
-
1026
- }`
1027
- });
1028
- }
1029
- _getEdgeDetectionMaterial() {
1030
- return new V({
1031
- uniforms: {
1032
- maskTexture: { value: null },
1033
- texSize: { value: new k(0.5, 0.5) },
1034
- visibleEdgeColor: { value: new l(1, 1, 1) },
1035
- hiddenEdgeColor: { value: new l(1, 1, 1) }
1036
- },
1037
- vertexShader: `varying vec2 vUv;
1038
-
1039
- void main() {
1040
- vUv = uv;
1041
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
1042
- }`,
1043
- fragmentShader: `varying vec2 vUv;
1044
-
1045
- uniform sampler2D maskTexture;
1046
- uniform vec2 texSize;
1047
- uniform vec3 visibleEdgeColor;
1048
- uniform vec3 hiddenEdgeColor;
1049
-
1050
- void main() {
1051
- vec2 invSize = 1.0 / texSize;
1052
- vec4 uvOffset = vec4(1.0, 0.0, 0.0, 1.0) * vec4(invSize, invSize);
1053
- vec4 c1 = texture2D( maskTexture, vUv + uvOffset.xy);
1054
- vec4 c2 = texture2D( maskTexture, vUv - uvOffset.xy);
1055
- vec4 c3 = texture2D( maskTexture, vUv + uvOffset.yw);
1056
- vec4 c4 = texture2D( maskTexture, vUv - uvOffset.yw);
1057
- float diff1 = (c1.r - c2.r)*0.5;
1058
- float diff2 = (c3.r - c4.r)*0.5;
1059
- float d = length( vec2(diff1, diff2) );
1060
- float a1 = min(c1.g, c2.g);
1061
- float a2 = min(c3.g, c4.g);
1062
- float visibilityFactor = min(a1, a2);
1063
- vec3 edgeColor = 1.0 - visibilityFactor > 0.001 ? visibleEdgeColor : hiddenEdgeColor;
1064
- gl_FragColor = vec4(edgeColor, 1.0) * vec4(d);
1065
- }`
1066
- });
1067
- }
1068
- _getSeparableBlurMaterial(e) {
1069
- return new V({
1070
- defines: {
1071
- MAX_RADIUS: e
1072
- },
1073
- uniforms: {
1074
- colorTexture: { value: null },
1075
- texSize: { value: new k(0.5, 0.5) },
1076
- direction: { value: new k(0.5, 0.5) },
1077
- kernelRadius: { value: 1 }
1078
- },
1079
- vertexShader: `varying vec2 vUv;
1080
-
1081
- void main() {
1082
- vUv = uv;
1083
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
1084
- }`,
1085
- fragmentShader: `#include <common>
1086
- varying vec2 vUv;
1087
- uniform sampler2D colorTexture;
1088
- uniform vec2 texSize;
1089
- uniform vec2 direction;
1090
- uniform float kernelRadius;
1091
-
1092
- float gaussianPdf(in float x, in float sigma) {
1093
- return 0.39894 * exp( -0.5 * x * x/( sigma * sigma))/sigma;
1094
- }
1095
-
1096
- void main() {
1097
- vec2 invSize = 1.0 / texSize;
1098
- float sigma = kernelRadius/2.0;
1099
- float weightSum = gaussianPdf(0.0, sigma);
1100
- vec4 diffuseSum = texture2D( colorTexture, vUv) * weightSum;
1101
- vec2 delta = direction * invSize * kernelRadius/float(MAX_RADIUS);
1102
- vec2 uvOffset = delta;
1103
- for( int i = 1; i <= MAX_RADIUS; i ++ ) {
1104
- float x = kernelRadius * float(i) / float(MAX_RADIUS);
1105
- float w = gaussianPdf(x, sigma);
1106
- vec4 sample1 = texture2D( colorTexture, vUv + uvOffset);
1107
- vec4 sample2 = texture2D( colorTexture, vUv - uvOffset);
1108
- diffuseSum += ((sample1 + sample2) * w);
1109
- weightSum += (2.0 * w);
1110
- uvOffset += delta;
1111
- }
1112
- gl_FragColor = diffuseSum/weightSum;
1113
- }`
1114
- });
1115
- }
1116
- _getOverlayMaterial() {
1117
- return new V({
1118
- uniforms: {
1119
- maskTexture: { value: null },
1120
- edgeTexture1: { value: null },
1121
- edgeTexture2: { value: null },
1122
- patternTexture: { value: null },
1123
- edgeStrength: { value: 1 },
1124
- edgeGlow: { value: 1 },
1125
- usePatternTexture: { value: 0 }
1126
- },
1127
- vertexShader: `varying vec2 vUv;
1128
-
1129
- void main() {
1130
- vUv = uv;
1131
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
1132
- }`,
1133
- fragmentShader: `varying vec2 vUv;
1134
-
1135
- uniform sampler2D maskTexture;
1136
- uniform sampler2D edgeTexture1;
1137
- uniform sampler2D edgeTexture2;
1138
- uniform sampler2D patternTexture;
1139
- uniform float edgeStrength;
1140
- uniform float edgeGlow;
1141
- uniform bool usePatternTexture;
1142
-
1143
- void main() {
1144
- vec4 edgeValue1 = texture2D(edgeTexture1, vUv);
1145
- vec4 edgeValue2 = texture2D(edgeTexture2, vUv);
1146
- vec4 maskColor = texture2D(maskTexture, vUv);
1147
- vec4 patternColor = texture2D(patternTexture, 6.0 * vUv);
1148
- float visibilityFactor = 1.0 - maskColor.g > 0.0 ? 1.0 : 0.5;
1149
- vec4 edgeValue = edgeValue1 + edgeValue2 * edgeGlow;
1150
- vec4 finalColor = edgeStrength * maskColor.r * edgeValue;
1151
- if(usePatternTexture)
1152
- finalColor += + visibilityFactor * (1.0 - maskColor.r) * (1.0 - patternColor.r);
1153
- gl_FragColor = finalColor;
1154
- }`,
1155
- blending: Ve,
1156
- depthTest: !1,
1157
- depthWrite: !1,
1158
- transparent: !0
1159
- });
1160
- }
1161
- }
1162
- A.BlurDirectionX = new k(1, 0);
1163
- A.BlurDirectionY = new k(0, 1);
1164
- function Bt(h, e, t, n, s) {
1165
- h.traverse((r) => {
1166
- var i, a;
1167
- if (r instanceof o)
1168
- if (e === "solid") {
1169
- (i = n.get(r.uuid)) == null || i.dispose(), n.delete(r.uuid);
1170
- const d = t.get(r.uuid);
1171
- d && (r.material = d, t.delete(r.uuid));
1172
- } else {
1173
- 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);
1174
- const d = s.get(r.uuid), f = new me(
1175
- e === "wireframe" ? { wireframe: !0, color: d } : { color: d }
1176
- );
1177
- n.set(r.uuid, f), r.material = f;
1178
- }
1179
- });
1180
- }
1181
- class Ce extends rt {
1182
- constructor() {
1183
- var e;
1184
- 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) => {
1185
- var n, s;
1186
- 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());
1187
- }), 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([
1188
- import("./mount-DicE86w2.mjs"),
1189
- Promise.resolve({ })
1190
- ]).then(([{ mountEditorUI: t }]) => {
1191
- this.reactRoot = t(c.instance().uiRoot);
1192
- });
1193
- }
1194
- /**
1195
- * The editor should only be instantiated when button is pressed
1196
- */
1197
- static registerListener() {
1198
- c.instance().input.on("keydown", (e) => {
1199
- (e.code === "Insert" || e.code === "Period") && (c.instance().editor = new Ce());
1200
- });
1201
- }
1202
- initEditorScene() {
1203
- 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(
1204
- new k(c.instance().sizes.width, c.instance().sizes.height),
1205
- c.instance().scene,
1206
- c.instance().camera.instance
1207
- ), c.instance().renderer.composer.addPass(this.outlinePass), this.initFlyControls();
1208
- const e = new We(new l(0, 5, 0)), t = new qe(new l(10, 15, 5));
1209
- t.instance.intensity = 5;
1210
- const n = new Ke(new l(0, 0, 0), 50, 50);
1211
- n.setReceiveShadow(!0), n.instance instanceof o && n.instance.material.color.set("#ffbe6f");
1212
- const s = 5, r = [
1213
- new Ne(new l(s, 0.5, 0)),
1214
- new $e(new l(s * 0.707, 1, s * 0.707)),
1215
- new Je(new l(0, 0.5, s)),
1216
- new et(new l(-s * 0.707, 0.5, s * 0.707)),
1217
- new tt(new l(-s, 1, 0)),
1218
- new it(new l(-s * 0.707, 1, -s * 0.707)),
1219
- new st(new l(0, 1, -s)),
1220
- new nt(new l(s * 0.707, 1, -s * 0.707)),
1221
- new at(new l(0, 3.5, 0))
1222
- ];
1223
- r.forEach((a) => a.setCastShadow(!0));
1224
- const i = {};
1225
- [e, t, n, ...r].forEach((a) => i[a.id] = a), c.instance().world.add(i), this.trigger("sceneChanged"), c.instance().input.on("mousedown", (a) => {
1226
- a.target === c.instance().canvas && this.handleCanvasClick(a);
1227
- }), c.instance().input.on("keydown", (a) => {
1228
- a.code === "Escape" && this.activeItem && this.deselect();
1229
- }), this.handleItemDelete(), this.on("setTransformMode", (a) => {
1230
- var d, f;
1231
- this.activeToolMode = a, (d = this.transformControls) == null || d.setMode(a), (f = c.instance().logger) == null || f.info(`Setting editor tool mode: ${a}`);
1232
- }), this.on("setShadeMode", (a) => {
1233
- this.applyShadeMode(a);
1234
- }), this.on("assetDropped", () => {
1235
- this.shadeMode !== "solid" && this.applyShadeMode(this.shadeMode);
1236
- }), this.initAssetsFilter();
1237
- }
1238
- initAssetsFilter() {
1239
- this.availableAssetCategories = [
1240
- ...new Set(Object.entries(c.instance().resources.items).map(([e, t]) => t.constructor.name))
1241
- ];
1242
- }
1243
- setActiveAssetCategory(e) {
1244
- this.activeAssetCategory = e;
1245
- }
1246
- applyShadeMode(e) {
1247
- this.shadeMode = e, Bt(c.instance().scene, e, this.originalMaterials, this.shadeOverrideMaterials, this.flatColors);
1248
- }
1249
- initFlyControls() {
1250
- 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;
1251
- }
1252
- handleItemDelete() {
1253
- c.instance().input.on("keydown", (e) => {
1254
- if (e.code === "Delete" && this.activeItem) {
1255
- let t = this.activeItem;
1256
- for (; t.parent && t.parent !== c.instance().scene; )
1257
- t = t.parent;
1258
- t.traverse((s) => {
1259
- var r, i;
1260
- 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());
1261
- }), this.deselect();
1262
- const n = Ge.from(t);
1263
- 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");
1264
- }
1265
- });
1266
- }
1267
- deselect() {
1268
- var e;
1269
- (e = this.transformControls) == null || e.detach(), this.outlinePass.selectedObjects = [], this.activeItem = null, this.trigger("objectDeselected");
1270
- }
1271
- selectObject(e) {
1272
- this.activeItem = e, this.trigger("objectSelected", this.activeItem), this.outlinePass.selectedObjects = [this.activeItem], this.handleHelperTool();
1273
- }
1274
- handleCanvasClick(e) {
1275
- if (e.button === 0) {
1276
- if (this.transformControls && (this.transformControls.dragging || this.transformControls.axis !== null))
1277
- return;
1278
- const t = c.instance().input.getPointerWorldPosition(void 0, null, !0);
1279
- t instanceof le ? this.selectObject(t) : this.deselect();
1280
- }
1281
- }
1282
- handleHelperTool() {
1283
- if (!this.transformControls) {
1284
- this.transformControls = new vt(
1285
- c.instance().camera.instance,
1286
- c.instance().canvas
1287
- ), this.transformControls.addEventListener("dragging-changed", (t) => {
1288
- this.flyControls.enabled = !t.value, t.value || this.initFlyControls();
1289
- });
1290
- const e = this.transformControls.getHelper();
1291
- e.userData.isEditorInternal = !0, c.instance().scene.add(e);
1292
- }
1293
- this.transformControls.setMode(this.activeToolMode), this.transformControls.attach(this.activeItem);
1294
- }
1295
- addHelper(e) {
1296
- this.helpers.push(e), this._showHelpers || (e.mesh.visible = !1, e.label.domElement.style.display = "none");
1297
- }
1298
- removeHelper(e) {
1299
- this.helpers = this.helpers.filter((t) => t !== e);
1300
- }
1301
- addLightHelper(e) {
1302
- this.lightHelpers.push(e), this._showHelpers || (e.visible = !1);
1303
- }
1304
- removeLightHelper(e) {
1305
- this.lightHelpers = this.lightHelpers.filter((t) => t !== e);
1306
- }
1307
- setShowHelpers(e) {
1308
- this._showHelpers = e, this.helpers.forEach((t) => {
1309
- t.mesh.visible = e, t.label.domElement.style.display = e ? "" : "none";
1310
- }), this.lightHelpers.forEach((t) => t.visible = e);
1311
- }
1312
- update(e) {
1313
- this.updateCamera(e), this.helpers.forEach((t) => t.update(e));
1314
- }
1315
- updateCamera(e) {
1316
- this.flyControls.update(e);
1317
- const t = c.instance().camera.instance, n = new l();
1318
- t.getWorldDirection(n), t.quaternion.setFromRotationMatrix(
1319
- new ce().lookAt(new l(), n, new l(0, 1, 0))
1320
- );
1321
- }
1322
- destroy() {
1323
- this.reactRoot.unmount(), this.outlinePass.dispose(), this.shadeOverrideMaterials.forEach((e) => e.dispose()), this.shadeOverrideMaterials.clear(), this.originalMaterials.clear(), this.flatColors.clear();
1324
- }
1325
- }
1326
- export {
1327
- Ce as E,
1328
- Bt as a
1329
- };