u-space 0.0.29 → 0.0.31

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 (90) hide show
  1. package/README.md +9 -0
  2. package/dist/Viewer-BKNV67Jj.cjs +1 -0
  3. package/dist/Viewer-Cs_y7IiH.js +1256 -0
  4. package/dist/getTransferables-C97JPUVf.cjs +1 -0
  5. package/dist/getTransferables-DrzSmiCR.js +43 -0
  6. package/dist/index.cjs +3 -3
  7. package/dist/index.js +2280 -1542
  8. package/dist/modelDecodeProtocol-D1Apm9iG.cjs +1 -0
  9. package/dist/modelDecodeProtocol-wDB7ksYw.js +56 -0
  10. package/dist/plugins/atmosphere/AgxToneMapping.d.ts +1 -1
  11. package/dist/plugins/atmosphere/index.cjs +1 -1
  12. package/dist/plugins/atmosphere/index.js +4 -4
  13. package/dist/plugins/curve-movement/index.cjs +1 -1
  14. package/dist/plugins/curve-movement/index.js +1 -1
  15. package/dist/plugins/fire/index.cjs +1 -1
  16. package/dist/plugins/fire/index.js +5 -5
  17. package/dist/plugins/object-controls/index.cjs +1 -1
  18. package/dist/plugins/object-controls/index.js +4 -4
  19. package/dist/plugins/tiles/index.cjs +1 -1
  20. package/dist/plugins/tiles/index.js +5 -5
  21. package/dist/plugins/u-manager/index.cjs +48 -48
  22. package/dist/plugins/u-manager/index.d.ts +1 -1
  23. package/dist/plugins/u-manager/index.js +8126 -8660
  24. package/dist/plugins/u-manager/loaders/SceneEditableBatchLayer.d.ts +17 -0
  25. package/dist/plugins/u-manager/loaders/SceneInstancedLayer.d.ts +3 -3
  26. package/dist/plugins/u-manager/loaders/SceneLoader.d.ts +11 -3
  27. package/dist/plugins/u-manager/semantics/objects/BuildingGroup.d.ts +4 -5
  28. package/dist/plugins/u-manager/semantics/objects/FacilityInstancedLayer.d.ts +4 -4
  29. package/dist/plugins/u-manager/semantics/objects/FloorMesh.d.ts +20 -22
  30. package/dist/plugins/u-manager/semantics/objects/SemanticGroup.d.ts +2 -3
  31. package/dist/protocol-C-OMPz15.js +10 -0
  32. package/dist/protocol-IUAzx0lk.cjs +1 -0
  33. package/dist/src/batches/EditableGeometryBatchLayer.d.ts +50 -0
  34. package/dist/src/batches/ModelInstancedLayer.d.ts +42 -0
  35. package/dist/src/batches/index.d.ts +2 -0
  36. package/dist/src/effects/TSLEffects.d.ts +24 -1
  37. package/dist/src/index.d.ts +2 -0
  38. package/dist/src/instances/InstanceObject.d.ts +57 -0
  39. package/dist/src/instances/index.d.ts +1 -0
  40. package/dist/src/interactions/MeshBVHRaycast.d.ts +9 -0
  41. package/dist/src/interactions/index.d.ts +1 -0
  42. package/dist/src/loaders/ModelDecodeWorkerClient.d.ts +31 -0
  43. package/dist/src/loaders/ModelLoaderManager.d.ts +15 -2
  44. package/dist/src/loaders/buildDecodedGltfModel.d.ts +4 -0
  45. package/dist/src/loaders/index.d.ts +1 -0
  46. package/dist/src/objects/Model.d.ts +1 -0
  47. package/dist/src/viewers/RenderPipeline.d.ts +37 -0
  48. package/dist/src/viewers/ReversedDepthSSGICompat.d.ts +10 -0
  49. package/dist/src/viewers/ReversedDepthSSRCompat.d.ts +20 -0
  50. package/dist/src/viewers/Viewer.d.ts +3 -1
  51. package/dist/src/viewers/renderInvalidation.d.ts +2 -0
  52. package/dist/src/worker/FrameTimingWindow.d.ts +16 -0
  53. package/dist/src/worker/OffscreenViewerHost.d.ts +20 -0
  54. package/dist/src/worker/WorkerDomTarget.d.ts +44 -0
  55. package/dist/src/worker/createWorkerViewer.d.ts +18 -0
  56. package/dist/src/worker/decodeGltfModel.d.ts +10 -0
  57. package/dist/src/worker/getTransferables.d.ts +1 -0
  58. package/dist/src/worker/index.d.ts +3 -0
  59. package/dist/src/worker/installWorkerImageLoader.d.ts +8 -0
  60. package/dist/src/worker/model-decoder.d.ts +13 -0
  61. package/dist/src/worker/modelDecodeProtocol.d.ts +205 -0
  62. package/dist/src/worker/protocol.d.ts +102 -0
  63. package/dist/src/worker/runtime.d.ts +2 -0
  64. package/dist/src/worker/workerImageUtils.d.ts +8 -0
  65. package/dist/worker/index.cjs +1 -0
  66. package/dist/worker/index.js +226 -0
  67. package/dist/worker/model-decoder.cjs +1 -0
  68. package/dist/worker/model-decoder.js +339 -0
  69. package/dist/worker/runtime.cjs +1 -0
  70. package/dist/worker/runtime.js +412 -0
  71. package/dist/workerImageUtils-lmOMyTQN.cjs +1 -0
  72. package/dist/workerImageUtils-mQD3TQ1N.js +105 -0
  73. package/docs/api-batches.md +112 -0
  74. package/docs/api-effects.md +2 -2
  75. package/docs/api-interactions.md +8 -0
  76. package/docs/api-managers.md +1 -1
  77. package/docs/api-objects.md +207 -0
  78. package/docs/api-plugin-u-manager.md +193 -102
  79. package/docs/api-render-pipeline.md +103 -5
  80. package/docs/api-viewer.md +232 -1
  81. package/docs/changelog.md +68 -12
  82. package/docs/examples-guide.md +104 -20
  83. package/docs/getting-started.md +1 -1
  84. package/docs/index.md +11 -4
  85. package/docs/mcp.md +30 -14
  86. package/docs/release.md +97 -0
  87. package/package.json +35 -4
  88. package/dist/plugins/u-manager/instances/SemanticInstanceObject.d.ts +0 -51
  89. package/dist/plugins/u-manager/instances/SemanticModelInstancedLayer.d.ts +0 -42
  90. package/dist/plugins/u-manager/instances/index.d.ts +0 -2
package/dist/index.js CHANGED
@@ -1,211 +1,23 @@
1
- import { Raycaster as De, Vector2 as C, EventDispatcher as ke, Box2 as at, Matrix4 as je, Vector3 as v, Box3 as V, Scene as Ue, Color as T, AmbientLight as ct, DirectionalLight as we, PointLight as ve, SpotLight as be, HemisphereLight as xe, DirectionalLightHelper as ht, PointLightHelper as lt, SpotLightHelper as dt, HemisphereLightHelper as pt, RenderPipeline as ut, PerspectiveCamera as se, Sphere as fe, Spherical as M, Quaternion as mt, Vector4 as ft, MathUtils as gt, PMREMGenerator as yt, OrthographicCamera as ne, TimestampQuery as Z, Cache as wt, Timer as vt, WebGPURenderer as bt, PCFShadowMap as xt, AgXToneMapping as St, Fog as Ct, FogExp2 as Tt, MeshStandardNodeMaterial as L, Loader as Mt, LoaderUtils as R, FileLoader as He, TextureLoader as Fe, Group as I, SRGBColorSpace as Ge, RepeatWrapping as Se, BufferGeometry as Q, BufferAttribute as Ce, Mesh as k, FrontSide as _t, BackSide as Et, DoubleSide as Pt, REVISION as Te, CubeTextureLoader as Ot, EquirectangularReflectionMapping as At, Sprite as Bt, AnimationMixer as Rt, LoopRepeat as It, LoopOnce as Lt, SphereGeometry as zt, TubeGeometry as Nt, LineCurve3 as Dt, CatmullRomCurve3 as kt, SpriteNodeMaterial as jt, CanvasTexture as Ut, ShapeGeometry as Ht, Shape as $e, ExtrudeGeometry as Ft, PlaneGeometry as Gt, CircleGeometry as $t, ClippingGroup as Wt, Plane as Kt, PlaneHelper as Qt, LineBasicMaterial as ie, Line as re } from "three/webgpu";
2
- import { pass as ge, mrt as qt, output as Xt, add as Me, blendColor as Yt, emissive as Vt, normalView as Jt, velocity as Zt, color as H, uv as _e, time as oe, pow as ae, sin as ye, mix as ce, mx_noise_float as Ee, Fn as We, userData as O, materialColor as Pe, select as q, materialOpacity as Oe, vec3 as es } from "three/tsl";
3
- import { bloom as ts } from "three/addons/tsl/display/BloomNode.js";
4
- import { ssgi as ss } from "three/addons/tsl/display/SSGINode.js";
5
- import { traa as ns } from "three/addons/tsl/display/TRAANode.js";
6
- import Ke from "camera-controls";
7
- import { RoomEnvironment as is } from "three/addons/environments/RoomEnvironment.js";
8
- import { ViewHelper as rs } from "three/addons/helpers/ViewHelper.js";
9
- import { CSS2DRenderer as os, CSS2DObject as as } from "three/addons/renderers/CSS2DRenderer.js";
10
- import { CSS2DObject as $n } from "three/addons/renderers/CSS2DRenderer.js";
11
- import { CSS3DRenderer as cs, CSS3DSprite as hs, CSS3DObject as ls } from "three/addons/renderers/CSS3DRenderer.js";
12
- import { CSS3DObject as Kn, CSS3DSprite as Qn } from "three/addons/renderers/CSS3DRenderer.js";
13
- import { GLTFLoader as Qe } from "three/addons/loaders/GLTFLoader.js";
14
- import { FBXLoader as ds } from "three/addons/loaders/FBXLoader.js";
15
- import { OBJLoader as ps } from "three/addons/loaders/OBJLoader.js";
16
- import { STLLoader as us } from "three/addons/loaders/STLLoader.js";
17
- import { DRACOLoader as ms } from "three/addons/loaders/DRACOLoader.js";
18
- import { KTX2Loader as fs } from "three/addons/loaders/KTX2Loader.js";
19
- import { MeshoptDecoder as Ae } from "three/addons/libs/meshopt_decoder.module.js";
20
- import { HDRLoader as gs } from "three/addons/loaders/HDRLoader.js";
21
- import { clone as ys } from "three/addons/utils/SkeletonUtils.js";
22
- import { Easing as f, Tween as ws } from "three/addons/libs/tween.module.js";
23
- class vs {
24
- /** The type of event (e.g., 'click', 'pointerdown'). */
25
- type;
26
- /** The original 3D object that triggered the event. */
27
- target;
28
- /** The current 3D object during the bubbling phase. */
29
- currentTarget;
30
- /** The intersection data from raycasting, or null if not applicable. */
31
- intersect;
32
- /** The original DOM event, or undefined if not applicable. */
33
- originalEvent;
34
- _propagationStopped = !1;
35
- constructor(e) {
36
- this.type = e.type, this.target = e.target, this.currentTarget = e.target, this.intersect = e.intersect, this.originalEvent = e.originalEvent;
37
- }
38
- /**
39
- * Stops the event from bubbling up the parent chain.
40
- */
41
- stopPropagation() {
42
- this._propagationStopped = !0;
43
- }
44
- /**
45
- * Returns true if `stopPropagation()` has been called.
46
- */
47
- get propagationStopped() {
48
- return this._propagationStopped;
49
- }
50
- }
51
- class bs {
52
- domElement;
53
- scene;
54
- camera;
55
- raycaster = new De();
56
- pointer = new C();
57
- hoveredObject = null;
58
- pointerDownTime = 0;
59
- pointerDownPos = new C();
60
- clickTimer = null;
61
- longPressThreshold = 500;
62
- moveThreshold = 0.01;
63
- /**
64
- * The objects to check for intersections. default to all children of the scene (including nested).
65
- */
66
- targetObjects;
67
- /**
68
- * Whether to enable pointer move events (pointermove, pointerenter, pointerleave).
69
- * Disabled by default for performance optimization.
70
- */
71
- pointerMoveEventsEnabled = !1;
72
- /**
73
- * Whether interaction is enabled globally.
74
- */
75
- _enabled = !0;
76
- /**
77
- * Objects excluded from raycasting (via addIgnore or setInteractable(false)).
78
- */
79
- _excludeSet = /* @__PURE__ */ new Set();
80
- constructor(e, t, s) {
81
- this.domElement = e, this.scene = t, this.camera = s, this.raycaster.params.Points.threshold = 0.1, this.raycaster.params.Line.threshold = 0.1, this.targetObjects = this.scene.children, this._bindEvents();
82
- }
83
- /**
84
- * Updates the camera reference (useful when switching cameras).
85
- */
86
- setCamera(e) {
87
- this.camera = e;
88
- }
89
- /**
90
- * Enable all interactions.
91
- */
92
- enable() {
93
- this._enabled = !0;
94
- }
95
- /**
96
- * Disable all interactions.
97
- */
98
- disable() {
99
- this._enabled = !1;
100
- }
101
- /**
102
- * Set whether a specific object is interactable.
103
- * When set to false, the object and its children are excluded from raycasting.
104
- */
105
- setInteractable(e, t) {
106
- t ? this._excludeSet.delete(e) : this._excludeSet.add(e);
107
- }
108
- /**
109
- * Add an object to the exclude list (will not receive any events).
110
- * Alias for `setInteractable(object, false)`.
111
- */
112
- addIgnore(e) {
113
- this._excludeSet.add(e);
114
- }
115
- /**
116
- * Remove an object from the exclude list.
117
- * Alias for `setInteractable(object, true)`.
118
- */
119
- removeIgnore(e) {
120
- this._excludeSet.delete(e);
121
- }
122
- _bindEvents() {
123
- this.domElement.addEventListener("click", this._onClick), this.domElement.addEventListener("dblclick", this._onDblClick), this.domElement.addEventListener("contextmenu", this._onContextMenu), this.domElement.addEventListener("pointerdown", this._onPointerDown), this.domElement.addEventListener("pointerup", this._onPointerUp), this.domElement.addEventListener("pointermove", this._onPointerMove);
124
- }
125
- _updatePointer(e) {
126
- const t = this.domElement.getBoundingClientRect();
127
- this.pointer.x = (e.clientX - t.left) / t.width * 2 - 1, this.pointer.y = -((e.clientY - t.top) / t.height) * 2 + 1;
128
- }
129
- _getIntersects() {
130
- this.raycaster.setFromCamera(this.pointer, this.camera);
131
- const e = this.raycaster.intersectObjects(this.targetObjects, !0);
132
- return this._excludeSet.size > 0 ? e.filter((t) => {
133
- let s = t.object;
134
- for (; s; ) {
135
- if (this._excludeSet.has(s))
136
- return !1;
137
- s = s.parent;
138
- }
139
- return !0;
140
- }) : e;
141
- }
142
- /**
143
- * Dispatches an event to the target object and bubbles up the parent chain.
144
- */
145
- _dispatchToTarget(e, t, s, n) {
146
- const i = new vs({
147
- type: e,
148
- target: t,
149
- intersect: s,
150
- originalEvent: n
151
- });
152
- let r = t;
153
- for (; r && !i.propagationStopped; )
154
- i.currentTarget = r, r.dispatchEvent({ type: e, event: i }), r = r.parent;
155
- }
156
- /**
157
- * Handles a DOM event by raycasting and dispatching to the first intersected object.
158
- */
159
- _handleEvent(e, t) {
160
- if (!this._enabled) return;
161
- this._updatePointer(t);
162
- const s = this._getIntersects();
163
- if (s.length === 0) return;
164
- const n = s[0];
165
- this._dispatchToTarget(e, n.object, n, t);
166
- }
167
- _onClick = (e) => {
168
- const t = Date.now() - this.pointerDownTime, s = this.pointer.distanceTo(this.pointerDownPos);
169
- if (!(t > this.longPressThreshold || s > this.moveThreshold)) {
170
- if (this.clickTimer) {
171
- clearTimeout(this.clickTimer), this.clickTimer = null;
172
- return;
173
- }
174
- this.clickTimer = setTimeout(() => {
175
- this._handleEvent("click", e), this.clickTimer = null;
176
- }, 200);
177
- }
178
- };
179
- _onDblClick = (e) => {
180
- this.clickTimer && (clearTimeout(this.clickTimer), this.clickTimer = null), this._handleEvent("dblclick", e);
181
- };
182
- _onContextMenu = (e) => {
183
- e.preventDefault();
184
- };
185
- _onPointerDown = (e) => {
186
- this.pointerDownTime = Date.now(), this._updatePointer(e), this.pointerDownPos.copy(this.pointer), this._handleEvent("pointerdown", e);
187
- };
188
- _onPointerUp = (e) => {
189
- if (this._updatePointer(e), e.button === 2) {
190
- const t = Date.now() - this.pointerDownTime, s = this.pointer.distanceTo(this.pointerDownPos);
191
- t <= this.longPressThreshold && s <= this.moveThreshold && this._handleEvent("rightclick", e);
192
- }
193
- this._handleEvent("pointerup", e);
194
- };
195
- _onPointerMove = (e) => {
196
- if (!this._enabled || !this.pointerMoveEventsEnabled) return;
197
- this._updatePointer(e);
198
- const t = this._getIntersects(), s = t.length > 0 ? t[0].object : null, n = t.length > 0 ? t[0] : null;
199
- this.hoveredObject !== s && (this.hoveredObject && this._dispatchToTarget("pointerleave", this.hoveredObject, null, e), this.hoveredObject = s, s && n && this._dispatchToTarget("pointerenter", s, n, e)), s && n && this._dispatchToTarget("pointermove", s, n, e);
200
- };
201
- /**
202
- * Cleans up event listeners.
203
- */
204
- dispose() {
205
- this.domElement.removeEventListener("click", this._onClick), this.domElement.removeEventListener("dblclick", this._onDblClick), this.domElement.removeEventListener("contextmenu", this._onContextMenu), this.domElement.removeEventListener("pointerdown", this._onPointerDown), this.domElement.removeEventListener("pointerup", this._onPointerUp), this.domElement.removeEventListener("pointermove", this._onPointerMove), this.clickTimer && (clearTimeout(this.clickTimer), this.clickTimer = null), this.hoveredObject = null, this._excludeSet.clear();
206
- }
207
- }
208
- class En extends ke {
1
+ import { g as jt } from "./Viewer-Cs_y7IiH.js";
2
+ import { C as vi, a as Si, I as Ii, b as Ei, O as Ci, R as Ai, c as Oi, V as Bi, e as _i } from "./Viewer-Cs_y7IiH.js";
3
+ import { EventDispatcher as hs, Vector2 as j, Box2 as ds, Matrix4 as R, Vector3 as D, Scene as us, Color as P, AmbientLight as ps, DirectionalLight as Fe, PointLight as He, SpotLight as $e, HemisphereLight as Ge, DirectionalLightHelper as fs, PointLightHelper as ms, SpotLightHelper as gs, HemisphereLightHelper as ys, MeshStandardNodeMaterial as q, Loader as bs, LoaderUtils as he, FileLoader as Wt, TextureLoader as Ft, Group as W, SRGBColorSpace as Se, RepeatWrapping as Ie, BufferGeometry as G, BufferAttribute as Pe, Mesh as k, FrontSide as ws, BackSide as xs, DoubleSide as Ht, InterleavedBufferAttribute as Ke, MeshStandardMaterial as Ms, LinearSRGBColorSpace as qe, InterleavedBuffer as vs, Texture as $t, NearestFilter as Ee, LinearFilter as Ve, LinearMipmapLinearFilter as Ss, NearestMipmapLinearFilter as Is, LinearMipmapNearestFilter as Es, NearestMipmapNearestFilter as Cs, MirroredRepeatWrapping as Xe, ClampToEdgeWrapping as Ye, NoColorSpace as fe, REVISION as Qe, LoadingManager as As, CubeTextureLoader as Os, EquirectangularReflectionMapping as Bs, Sprite as _s, AnimationMixer as Ts, LoopRepeat as Ls, LoopOnce as Ns, Box3 as K, SphereGeometry as Ds, TubeGeometry as Ps, LineCurve3 as Rs, CatmullRomCurve3 as ks, SpriteNodeMaterial as zs, CanvasTexture as Us, ShapeGeometry as js, Shape as Gt, ExtrudeGeometry as Ws, PlaneGeometry as Fs, CircleGeometry as Hs, Quaternion as $s, BoxGeometry as Gs, MeshBasicNodeMaterial as Ks, ClippingGroup as qs, Plane as Vs, PlaneHelper as Xs, LineBasicMaterial as ye, Line as be, Object3D as Ys, Sphere as ne, Float32BufferAttribute as Qs, SkinnedMesh as Js, DataTexture as Zs, RGBAFormat as en, FloatType as tn, Frustum as sn, InstancedBufferAttribute as Je, DynamicDrawUsage as Te, InstancedMesh as nn, StorageInstancedBufferAttribute as rn } from "three/webgpu";
4
+ import { GLTFLoader as Re } from "three/addons/loaders/GLTFLoader.js";
5
+ import { FBXLoader as Ze } from "three/addons/loaders/FBXLoader.js";
6
+ import { OBJLoader as an } from "three/addons/loaders/OBJLoader.js";
7
+ import { STLLoader as on } from "three/addons/loaders/STLLoader.js";
8
+ import { DRACOLoader as cn } from "three/addons/loaders/DRACOLoader.js";
9
+ import { KTX2Loader as ln } from "three/addons/loaders/KTX2Loader.js";
10
+ import { MeshoptDecoder as Le } from "three/addons/libs/meshopt_decoder.module.js";
11
+ import { M as et, v as hn, U as Kt } from "./modelDecodeProtocol-wDB7ksYw.js";
12
+ import { HDRLoader as dn } from "three/addons/loaders/HDRLoader.js";
13
+ import { clone as We } from "three/addons/utils/SkeletonUtils.js";
14
+ import { color as Y, uv as tt, time as we, pow as xe, sin as ke, mix as Me, mx_noise_float as st, uniform as ae, add as un, vec4 as pn, Fn as qt, userData as F, materialColor as Ce, select as $, materialOpacity as ze, vec3 as fn, attribute as mn, int as nt, textureSize as gn, textureLoad as rt, ivec2 as yn, instancedBufferAttribute as it, float as bn } from "three/tsl";
15
+ import { outline as wn } from "three/addons/tsl/display/OutlineNode.js";
16
+ import { Easing as T, Tween as xn } from "three/addons/libs/tween.module.js";
17
+ import { mergeGeometries as Mn } from "three/addons/utils/BufferGeometryUtils.js";
18
+ import { CSS2DObject as Li } from "three/addons/renderers/CSS2DRenderer.js";
19
+ import { CSS3DObject as Di, CSS3DSprite as Pi } from "three/addons/renderers/CSS3DRenderer.js";
20
+ class si extends hs {
209
21
  scene;
210
22
  camera;
211
23
  domElement;
@@ -215,8 +27,8 @@ class En extends ke {
215
27
  // Box selection state
216
28
  _boxSelectionEnabled = !1;
217
29
  _isSelecting = !1;
218
- _startPoint = new C();
219
- _endPoint = new C();
30
+ _startPoint = new j();
31
+ _endPoint = new j();
220
32
  _selectionBox = null;
221
33
  _deep = !0;
222
34
  /**
@@ -315,226 +127,33 @@ class En extends ke {
315
127
  this._selectionBox.style.left = `${e}px`, this._selectionBox.style.top = `${t}px`, this._selectionBox.style.width = `${s}px`, this._selectionBox.style.height = `${n}px`;
316
128
  }
317
129
  _getObjectsInBox() {
318
- const e = this._container.getBoundingClientRect(), t = e.width, s = e.height, n = new C(
130
+ const e = this._container.getBoundingClientRect(), t = e.width, s = e.height, n = new j(
319
131
  this._startPoint.x / t * 2 - 1,
320
132
  -(this._startPoint.y / s) * 2 + 1
321
- ), i = new C(
133
+ ), r = new j(
322
134
  this._endPoint.x / t * 2 - 1,
323
135
  -(this._endPoint.y / s) * 2 + 1
324
- ), r = new at(
325
- new C(Math.min(n.x, i.x), Math.min(n.y, i.y)),
326
- new C(Math.max(n.x, i.x), Math.max(n.y, i.y))
327
- ), o = this.targetObjects || this.scene.children, a = [], c = new je();
328
- c.multiplyMatrices(this.camera.projectionMatrix, this.camera.matrixWorldInverse);
329
- const l = (d) => {
136
+ ), a = new ds(
137
+ new j(Math.min(n.x, r.x), Math.min(n.y, r.y)),
138
+ new j(Math.max(n.x, r.x), Math.max(n.y, r.y))
139
+ ), o = this.targetObjects || this.scene.children, c = [], l = new R();
140
+ l.multiplyMatrices(this.camera.projectionMatrix, this.camera.matrixWorldInverse);
141
+ const h = (d) => {
330
142
  if (!d.visible) return;
331
- const p = new v();
332
- if (p.setFromMatrixPosition(d.matrixWorld), p.applyMatrix4(c), p.z > -1 && p.z < 1 && r.containsPoint(new C(p.x, p.y)) && a.push(d), this._deep)
333
- for (const u of d.children)
334
- l(u);
143
+ const u = new D();
144
+ if (u.setFromMatrixPosition(d.matrixWorld), u.applyMatrix4(l), u.z > -1 && u.z < 1 && a.containsPoint(new j(u.x, u.y)) && c.push(d), this._deep)
145
+ for (const p of d.children)
146
+ h(p);
335
147
  };
336
148
  for (const d of o)
337
- l(d);
338
- return a;
149
+ h(d);
150
+ return c;
339
151
  }
340
152
  dispose() {
341
153
  this.disableBoxSelection(), this._selected.clear();
342
154
  }
343
155
  }
344
- function ee(h, e) {
345
- const t = h;
346
- if (t.setSemanticVisible) {
347
- t.setSemanticVisible(e);
348
- return;
349
- }
350
- h.visible = e, t.markSemanticRenderDirty?.();
351
- }
352
- class xs {
353
- idMap = /* @__PURE__ */ new Map();
354
- nameMap = /* @__PURE__ */ new Map();
355
- typeMap = /* @__PURE__ */ new Map();
356
- objectIds = /* @__PURE__ */ new Map();
357
- allObjects = /* @__PURE__ */ new Set();
358
- /**
359
- * Add an object with a custom id.
360
- * One object can have multiple ids.
361
- */
362
- add(e, t) {
363
- if (this.idMap.has(e)) {
364
- console.warn(`ObjectManager: Object with id ${e} already exists.`);
365
- return;
366
- }
367
- this.idMap.set(e, t), this.allObjects.add(t), this.objectIds.has(t) || this.objectIds.set(t, /* @__PURE__ */ new Set()), this.objectIds.get(t).add(e), t.name && (this.nameMap.has(t.name) || this.nameMap.set(t.name, /* @__PURE__ */ new Set()), this.nameMap.get(t.name).add(t)), t.type && (this.typeMap.has(t.type) || this.typeMap.set(t.type, /* @__PURE__ */ new Set()), this.typeMap.get(t.type).add(t));
368
- }
369
- /**
370
- * Get an object by its custom id.
371
- */
372
- getById(e) {
373
- return this.idMap.get(e);
374
- }
375
- /**
376
- * Get all objects with a given name.
377
- */
378
- getByName(e) {
379
- return this.nameMap.get(e) || /* @__PURE__ */ new Set();
380
- }
381
- /**
382
- * Get all objects with a given type.
383
- */
384
- getByType(e) {
385
- return this.typeMap.get(e) || /* @__PURE__ */ new Set();
386
- }
387
- /**
388
- * Get all ids associated with an object.
389
- */
390
- getObjectIds(e) {
391
- return this.objectIds.get(e) || /* @__PURE__ */ new Set();
392
- }
393
- /**
394
- * Remove an object and all its associated ids.
395
- */
396
- remove(e) {
397
- const t = this.objectIds.get(e);
398
- if (t) {
399
- for (const s of t)
400
- this.idMap.delete(s);
401
- this.objectIds.delete(e);
402
- }
403
- if (e.name && this.nameMap.has(e.name)) {
404
- const s = this.nameMap.get(e.name);
405
- s.delete(e), s.size === 0 && this.nameMap.delete(e.name);
406
- }
407
- if (e.type && this.typeMap.has(e.type)) {
408
- const s = this.typeMap.get(e.type);
409
- s.delete(e), s.size === 0 && this.typeMap.delete(e.type);
410
- }
411
- this.allObjects.delete(e);
412
- }
413
- /**
414
- * Remove an object by its id.
415
- */
416
- removeById(e) {
417
- const t = this.idMap.get(e);
418
- t && this.remove(t);
419
- }
420
- /**
421
- * Remove all objects with a given name.
422
- */
423
- removeByName(e) {
424
- const t = this.getByName(e);
425
- for (const s of t)
426
- this.remove(s);
427
- }
428
- /**
429
- * Remove all objects with a given type.
430
- */
431
- removeByType(e) {
432
- const t = this.getByType(e);
433
- for (const s of t)
434
- this.remove(s);
435
- }
436
- /**
437
- * Clear all cached objects.
438
- */
439
- clear() {
440
- this.idMap.clear(), this.nameMap.clear(), this.typeMap.clear(), this.objectIds.clear(), this.allObjects.clear();
441
- }
442
- /**
443
- * Get all cached objects as a Set.
444
- */
445
- getAll() {
446
- return this.allObjects;
447
- }
448
- /**
449
- * Get the number of unique cached objects.
450
- */
451
- get size() {
452
- return this.allObjects.size;
453
- }
454
- /**
455
- * Show an object by id.
456
- */
457
- show(e) {
458
- const t = this.idMap.get(e);
459
- t && ee(t, !0);
460
- }
461
- /**
462
- * Hide an object by id.
463
- */
464
- hide(e) {
465
- const t = this.idMap.get(e);
466
- t && ee(t, !1);
467
- }
468
- /**
469
- * Show only the specified objects, hide all others.
470
- */
471
- isolate(e) {
472
- const t = new Set(e);
473
- for (const s of this.allObjects) {
474
- const n = this.objectIds.get(s) ?? /* @__PURE__ */ new Set();
475
- ee(s, [...n].some((i) => t.has(i)));
476
- }
477
- }
478
- /**
479
- * Set the opacity of an object's materials.
480
- */
481
- setOpacity(e, t) {
482
- const s = this.idMap.get(e);
483
- if (!s) return;
484
- const n = s;
485
- if (n.setSemanticOpacity) {
486
- n.setSemanticOpacity(t);
487
- return;
488
- }
489
- s.traverse((i) => {
490
- if (!i.isMesh) return;
491
- const r = i.material;
492
- if (!r) return;
493
- const o = Array.isArray(r) ? r : [r];
494
- for (const a of o)
495
- a.transparent = t < 1, a.opacity = t, a.needsUpdate = !0;
496
- });
497
- }
498
- /**
499
- * Get the bounding box of an object by id, or all objects if no id provided.
500
- */
501
- getBoundingBox(e) {
502
- const t = new V();
503
- if (e) {
504
- const s = this.idMap.get(e);
505
- s && t.setFromObject(s);
506
- } else
507
- for (const s of this.allObjects)
508
- t.expandByObject(s);
509
- return t;
510
- }
511
- /**
512
- * Iterate over all managed objects.
513
- */
514
- forEach(e) {
515
- for (const t of this.allObjects) {
516
- const s = this.objectIds.get(t) || /* @__PURE__ */ new Set();
517
- e(t, s);
518
- }
519
- }
520
- /**
521
- * Filter objects by a predicate.
522
- */
523
- filter(e) {
524
- const t = [];
525
- for (const s of this.allObjects)
526
- e(s) && t.push(s);
527
- return t;
528
- }
529
- /**
530
- * Show all managed objects.
531
- */
532
- showAll() {
533
- for (const e of this.allObjects)
534
- ee(e, !0);
535
- }
536
- }
537
- class Pn {
156
+ class ni {
538
157
  scenes = /* @__PURE__ */ new Map();
539
158
  _activeSceneKey = null;
540
159
  /**
@@ -547,8 +166,8 @@ class Pn {
547
166
  * Create and register a new scene.
548
167
  */
549
168
  create(e, t = {}) {
550
- const s = new Ue();
551
- return t.background !== void 0 && (s.background = new T(t.background)), this.scenes.set(e, s), s;
169
+ const s = new us();
170
+ return t.background !== void 0 && (s.background = new P(t.background)), this.scenes.set(e, s), s;
552
171
  }
553
172
  /**
554
173
  * Get a scene by key.
@@ -587,7 +206,7 @@ class Pn {
587
206
  const t = this.scenes.get(e);
588
207
  if (!t) return null;
589
208
  let s = null;
590
- return t.background instanceof T && (s = `#${t.background.getHexString()}`), {
209
+ return t.background instanceof P && (s = `#${t.background.getHexString()}`), {
591
210
  name: t.name || e,
592
211
  background: s,
593
212
  environmentRotation: {
@@ -608,7 +227,7 @@ class Pn {
608
227
  return this.scenes.size;
609
228
  }
610
229
  }
611
- class On {
230
+ class ri {
612
231
  scene;
613
232
  lights = /* @__PURE__ */ new Map();
614
233
  helpers = /* @__PURE__ */ new Map();
@@ -616,34 +235,34 @@ class On {
616
235
  this.scene = e;
617
236
  }
618
237
  addAmbient(e, t = {}) {
619
- const { color: s = 16777215, intensity: n = 0.5 } = t, i = new ct(s, n);
620
- return i.name = e, this._register(e, i), i;
238
+ const { color: s = 16777215, intensity: n = 0.5 } = t, r = new ps(s, n);
239
+ return r.name = e, this._register(e, r), r;
621
240
  }
622
241
  addDirectional(e, t = {}) {
623
- const { color: s = 16777215, intensity: n = 1, position: i = { x: 5, y: 10, z: 5 }, castShadow: r = !1, shadowMapSize: o = 1024 } = t, a = new we(s, n);
624
- return a.position.set(i.x, i.y, i.z), a.castShadow = r, r && a.shadow.mapSize.setScalar(o), a.name = e, this._register(e, a), a;
242
+ const { color: s = 16777215, intensity: n = 1, position: r = { x: 5, y: 10, z: 5 }, castShadow: a = !1, shadowMapSize: o = 1024 } = t, c = new Fe(s, n);
243
+ return c.position.set(r.x, r.y, r.z), c.castShadow = a, a && c.shadow.mapSize.setScalar(o), c.name = e, this._register(e, c), c;
625
244
  }
626
245
  addPoint(e, t = {}) {
627
- const { color: s = 16777215, intensity: n = 1, distance: i = 0, decay: r = 2, position: o = { x: 0, y: 5, z: 0 }, castShadow: a = !1 } = t, c = new ve(s, n, i, r);
628
- return c.position.set(o.x, o.y, o.z), c.castShadow = a, c.name = e, this._register(e, c), c;
246
+ const { color: s = 16777215, intensity: n = 1, distance: r = 0, decay: a = 2, position: o = { x: 0, y: 5, z: 0 }, castShadow: c = !1 } = t, l = new He(s, n, r, a);
247
+ return l.position.set(o.x, o.y, o.z), l.castShadow = c, l.name = e, this._register(e, l), l;
629
248
  }
630
249
  addSpot(e, t = {}) {
631
250
  const {
632
251
  color: s = 16777215,
633
252
  intensity: n = 1,
634
- distance: i = 0,
635
- angle: r = Math.PI / 6,
253
+ distance: r = 0,
254
+ angle: a = Math.PI / 6,
636
255
  penumbra: o = 0.1,
637
- decay: a = 2,
638
- position: c = { x: 0, y: 10, z: 0 },
639
- target: l,
256
+ decay: c = 2,
257
+ position: l = { x: 0, y: 10, z: 0 },
258
+ target: h,
640
259
  castShadow: d = !1
641
- } = t, p = new be(s, n, i, r, o, a);
642
- return p.position.set(c.x, c.y, c.z), l && p.target.position.set(l.x, l.y, l.z), p.castShadow = d, p.name = e, this._register(e, p), p;
260
+ } = t, u = new $e(s, n, r, a, o, c);
261
+ return u.position.set(l.x, l.y, l.z), h && u.target.position.set(h.x, h.y, h.z), u.castShadow = d, u.name = e, this._register(e, u), u;
643
262
  }
644
263
  addHemisphere(e, t = {}) {
645
- const { skyColor: s = 8900331, groundColor: n = 3549447, intensity: i = 0.6 } = t, r = new xe(s, n, i);
646
- return r.name = e, this._register(e, r), r;
264
+ const { skyColor: s = 8900331, groundColor: n = 3549447, intensity: r = 0.6 } = t, a = new Ge(s, n, r);
265
+ return a.name = e, this._register(e, a), a;
647
266
  }
648
267
  /**
649
268
  * Apply a lighting preset to the scene.
@@ -693,7 +312,7 @@ class On {
693
312
  const t = this.lights.get(e);
694
313
  if (!t) return;
695
314
  let s = null;
696
- t instanceof we ? s = new ht(t, 1) : t instanceof ve ? s = new lt(t, 0.5) : t instanceof be ? s = new dt(t) : t instanceof xe && (s = new pt(t, 1)), s && (this.scene.add(s), this.helpers.set(e, s));
315
+ t instanceof Fe ? s = new fs(t, 1) : t instanceof He ? s = new ms(t, 0.5) : t instanceof $e ? s = new gs(t) : t instanceof Ge && (s = new ys(t, 1)), s && (this.scene.add(s), this.helpers.set(e, s));
697
316
  }
698
317
  /**
699
318
  * Hide (remove) the helper for a light.
@@ -724,795 +343,643 @@ class On {
724
343
  this.removeAll(), this.hideAllHelpers();
725
344
  }
726
345
  }
727
- class Ss extends ut {
728
- scene;
729
- camera;
730
- scenePass;
731
- needsUpdateOutputNode;
732
- #t;
733
- #e;
734
- #s = !1;
735
- #r = { strength: 1, radius: 0, threshold: 0 };
736
- #n = null;
737
- #o = !1;
738
- #a = {
739
- sliceCount: 1,
740
- stepCount: 12,
741
- aoIntensity: 1,
742
- giIntensity: 10,
743
- radius: 12,
744
- thickness: 1
745
- };
746
- #p = null;
747
- #h = !1;
748
- #l = null;
749
- #u = null;
750
- #d;
751
- #c;
752
- #m = !1;
753
- #f = !0;
754
- constructor(...e) {
755
- const [t, s, n] = e;
756
- super(t), this.scene = s, this.camera = n, this.scenePass = ge(s, n), this.needsUpdateOutputNode = !0, this.#t = /* @__PURE__ */ new Set(), this.#e = [], this.#d = /* @__PURE__ */ new Set(), this.#c = /* @__PURE__ */ new Map(), this.#g();
757
- }
758
- /** @deprecated Use `scenePass` instead */
759
- get currentOutputNode() {
760
- return this.scenePass;
761
- }
762
- addOverlayPass(e) {
763
- this.#t.add(e), this.needsUpdateOutputNode = !0;
764
- }
765
- removeOverlayPass(e) {
766
- this.#t.delete(e), this.needsUpdateOutputNode = !0;
767
- }
768
- setCamera(e) {
769
- this.camera = e, this.#i();
770
- }
771
- /** @deprecated Use `setOutputComposer` instead */
772
- setCurrentOutputNode(e) {
773
- this.setOutputComposer(() => e);
774
- }
775
- /** @deprecated Use `setOutputComposer(null)` instead */
776
- resetCurrentOutputNode() {
777
- this.setOutputComposer(null);
778
- }
779
- setOutputComposer(e) {
780
- this.#u = e, this.needsUpdateOutputNode = !0;
781
- }
782
- addOutputEffect(e) {
783
- return this.#d.add(e), this.needsUpdateOutputNode = !0, this;
784
- }
785
- removeOutputEffect(e) {
786
- return this.#d.delete(e), this.needsUpdateOutputNode = !0, this;
787
- }
788
- addMRTChannel(e, t) {
789
- return this.#c.get(e) === t ? this : (this.#c.set(e, t), this.#i(), this);
790
- }
791
- removeMRTChannel(e) {
792
- return this.#c.delete(e) && this.#i(), this;
793
- }
794
- enableBloom(e) {
795
- e && Object.assign(this.#r, e), this.#s = !0, this.#i();
796
- }
797
- disableBloom() {
798
- this.#s = !1, this.#n = null, this.#i();
799
- }
800
- updateBloom(e) {
801
- Object.assign(this.#r, e), this.#s && (this.needsUpdateOutputNode = !0);
802
- }
803
- enableSSGI(e) {
804
- e && Object.assign(this.#a, e), this.#o = !0, this.#i();
805
- }
806
- disableSSGI() {
807
- this.#o = !1, this.#p = null, this.#i();
808
- }
809
- updateSSGI(e) {
810
- if (Object.assign(this.#a, e), this.#p) {
811
- const t = this.#p;
812
- e.sliceCount !== void 0 && (t.sliceCount.value = e.sliceCount), e.stepCount !== void 0 && (t.stepCount.value = e.stepCount), e.aoIntensity !== void 0 && (t.aoIntensity.value = e.aoIntensity), e.giIntensity !== void 0 && (t.giIntensity.value = e.giIntensity), e.radius !== void 0 && (t.radius.value = e.radius), e.thickness !== void 0 && (t.thickness.value = e.thickness);
813
- }
814
- }
815
- enableTRAA() {
816
- this.#h = !0, this.#i();
817
- }
818
- disableTRAA() {
819
- this.#h = !1, this.#l = null, this.#i();
820
- }
821
- #i() {
822
- const e = this.scenePass;
823
- this.scenePass = ge(this.scene, this.camera), this.#g(), this.needsUpdateOutputNode = !0, e.dispose();
824
- }
825
- #g() {
826
- if (this.#s || this.#o || this.#h || this.#c.size > 0) {
827
- const t = { output: Xt };
828
- this.#c.forEach((s, n) => {
829
- n !== "output" && (t[n] = s);
830
- }), this.#s && (t.emissive = Vt), this.#o && (t.normal = Jt), this.#h && (t.velocity = Zt), this.scenePass.setMRT(qt(t));
831
- }
832
- }
833
- #y() {
834
- for (const e of this.#e)
835
- e.dispose();
836
- this.#e = [];
837
- }
838
- #w() {
839
- let e = this.scenePass.getTextureNode();
840
- if (this.#o)
841
- if (!(this.camera instanceof se))
842
- console.warn("RenderPipeline: SSGI requires a PerspectiveCamera, skipping.");
843
- else {
844
- const t = this.scenePass.getTextureNode(), s = this.scenePass.getTextureNode("depth"), n = this.scenePass.getTextureNode("normal"), i = ss(t, s, n, this.camera);
845
- i.sliceCount.value = this.#a.sliceCount, i.stepCount.value = this.#a.stepCount, i.aoIntensity.value = this.#a.aoIntensity, i.giIntensity.value = this.#a.giIntensity, i.radius.value = this.#a.radius, i.thickness.value = this.#a.thickness, this.#p = i, e = Me(e, i), this.#e.push(i);
846
- }
847
- if (this.#s) {
848
- const t = this.scenePass.getTextureNode("emissive");
849
- this.#n = ts(
850
- t,
851
- this.#r.strength,
852
- this.#r.radius,
853
- this.#r.threshold
854
- ), e = Me(e, this.#n), this.#e.push(this.#n);
855
- }
856
- return e;
857
- }
858
- #v(e) {
859
- e ? (this.#m || (this.#f = this.outputColorTransform), this.outputColorTransform = !1) : this.#m && (this.outputColorTransform = this.#f), this.#m = e;
860
- }
861
- #b() {
862
- this.#y();
863
- let e, t = !1, s = !1;
864
- const n = this.#u !== null;
865
- if (n ? e = this.#u(this.scenePass) : this.#s || this.#o ? e = this.#w() : e = this.#d.size > 0 ? this.scenePass.getTextureNode() : this.scenePass, n || this.#d.forEach((i) => {
866
- t ||= i.includesTemporalAntialias === !0, s ||= i.includesOutputTransform === !0, e = i(this.scenePass, e);
867
- }), this.#v(s), this.#h && !t) {
868
- const i = this.scenePass.getTextureNode("depth"), r = this.scenePass.getTextureNode("velocity");
869
- this.#l = ns(e, i, r, this.camera), this.#e.push(this.#l), e = this.#l;
870
- } else
871
- this.#l = null;
872
- this.#t.size > 0 && this.#t.forEach((i) => {
873
- const r = Yt(e, i);
874
- this.#e.push(r), e = r;
875
- }), this.outputNode = e, this.needsUpdate = !0;
876
- }
877
- render() {
878
- this.needsUpdateOutputNode && (this.#b(), this.needsUpdateOutputNode = !1), super.render();
879
- }
880
- dispose() {
881
- this.#y(), this.scenePass.dispose(), super.dispose();
882
- }
883
- }
884
- const Cs = {
885
- Vector2: C,
886
- Vector3: v,
887
- Vector4: ft,
888
- Quaternion: mt,
889
- Matrix4: je,
890
- Spherical: M,
891
- Box3: V,
892
- Sphere: fe,
893
- Raycaster: De
894
- };
895
- Ke.install({ THREE: Cs });
896
- class Ts extends Ke {
897
- constructor(...e) {
898
- super(...e), this.minDistance = 0.2, this.smoothTime = 0.2, this.dollySpeed = 0.2;
899
- }
900
- /**
901
- * Set absolute angle for azimuth to avoid spinning
902
- */
903
- absoluteRotations() {
904
- this.azimuthAngle = _s(this.azimuthAngle, 0);
905
- }
906
- async flyToBox(e, t = {}) {
907
- if (e.isEmpty())
908
- return console.warn("CameraControls.flyToBox: The provided Box3 is empty."), !1;
909
- this.absoluteRotations();
910
- const { viewpoint: s = "frontTop", enableTransition: n = !0, padding: i = 0.1, cover: r = !1 } = t;
911
- if (s !== "current") {
912
- const o = s.toUpperCase(), a = Be[o] ?? Be.FRONTTOP, c = a.theta, l = a.phi;
913
- if (await this.rotateTo(c, l, n), Ms.has(o))
914
- await this.fitToBox(e, n, {
915
- paddingLeft: i,
916
- paddingRight: i,
917
- paddingTop: i,
918
- paddingBottom: i,
919
- cover: r
920
- });
921
- else {
922
- const d = new fe();
923
- e.getBoundingSphere(d), d.radius += i, await this.fitToSphere(d, n);
924
- }
925
- } else {
926
- const o = new fe();
927
- e.getBoundingSphere(o), o.radius += i, await this.fitToSphere(o, n);
928
- }
929
- return !0;
930
- }
931
- async flyToObject(e, t = {}) {
932
- const s = new V().setFromObject(e);
933
- return this.flyToBox(s, t);
934
- }
935
- /**
936
- * Fly camera to a specific position and look-at target.
937
- */
938
- async flyTo(e, t, s = {}) {
939
- const { enableTransition: n = !0 } = s;
940
- return this.absoluteRotations(), this.setLookAt(e.x, e.y, e.z, t.x, t.y, t.z, n);
941
- }
942
- /**
943
- * Get the current camera viewpoint data (position, target, zoom).
944
- */
945
- getCameraViewpoint() {
946
- const e = new v(), t = new v();
947
- return this.getPosition(e), this.getTarget(t), {
948
- position: { x: e.x, y: e.y, z: e.z },
949
- target: { x: t.x, y: t.y, z: t.z },
950
- zoom: this.camera.zoom
951
- };
952
- }
953
- /**
954
- * Lock camera controls (disable all user interaction).
955
- */
956
- lock() {
957
- this.enabled = !1;
958
- }
959
- /**
960
- * Unlock camera controls (re-enable user interaction).
961
- */
962
- unlock() {
963
- this.enabled = !0;
964
- }
965
- /**
966
- * Switch between 2D top-down and 3D perspective views.
967
- */
968
- async setViewMode(e, t = !0) {
969
- if (e === "2d") {
970
- const s = new v();
971
- this.getTarget(s), await this.rotateTo(0, 0, t), this.minPolarAngle = 0, this.maxPolarAngle = 0;
972
- } else
973
- this.minPolarAngle = 0, this.maxPolarAngle = Math.PI, await this.rotateTo(0, Math.PI / 4, t);
974
- }
975
- async setCameraViewpoint(e, t = !0) {
976
- const { position: s, target: n, zoom: i = this.camera.zoom } = e;
977
- return Promise.all([
978
- this.zoomTo(i, t),
979
- this.setLookAt(s.x, s.y, s.z, n.x, n.y, n.z, t)
980
- ]);
981
- }
982
- }
983
- const Be = {
984
- LEFT: new M(0, Math.PI / 2, -Math.PI / 2),
985
- RIGHT: new M(0, Math.PI / 2, Math.PI / 2),
986
- FRONT: new M(0, Math.PI / 2, 0),
987
- BACK: new M(0, Math.PI / 2, Math.PI),
988
- TOP: new M(0, 0, 0),
989
- BOTTOM: new M(0, Math.PI, 0),
990
- FRONTTOP: new M(0, Math.PI / 4, 0),
991
- BACKTOP: new M(0, Math.PI / 4, Math.PI),
992
- LEFTTOP: new M(0, Math.PI / 4, -Math.PI / 2),
993
- RIGHTTOP: new M(0, Math.PI / 4, Math.PI / 2),
994
- LEFTFRONTTOP: new M(0, Math.PI / 4, -Math.PI / 4),
995
- RIGHTFRONTTOP: new M(0, Math.PI / 4, Math.PI / 4),
996
- LEFTBACKTOP: new M(0, Math.PI / 4, -Math.PI / 4 * 3),
997
- RIGHTBACKTOP: new M(0, Math.PI / 4, Math.PI / 4 * 3)
998
- }, Ms = /* @__PURE__ */ new Set(["LEFT", "RIGHT", "FRONT", "BACK", "TOP", "BOTTOM"]);
999
- function _s(h, e) {
1000
- const t = h - e;
1001
- return gt.euclideanModulo(t + Math.PI, Math.PI * 2) - Math.PI;
1002
- }
1003
- class Es {
1004
- environment = new is();
1005
- renderer;
1006
- pmremGenerator;
1007
- envMap = null;
1008
- constructor(e) {
1009
- this.renderer = e, this.pmremGenerator = new yt(e);
1010
- }
1011
- update() {
1012
- this.envMap || (this.envMap = this.pmremGenerator.fromScene(this.environment).texture);
1013
- }
1014
- dispose() {
1015
- this.pmremGenerator.dispose(), this.envMap?.dispose();
1016
- }
1017
- }
1018
- const te = 128;
1019
- class Ps extends rs {
1020
- viewer;
1021
- overlayPass;
1022
- constructor(e) {
1023
- super(e.camera, e.el), this.viewer = e;
1024
- const t = new ne(-2, 2, 2, -2, 0, 4);
1025
- t.position.set(0, 0, 2), this.overlayPass = ge(this, t), this.setLabels("x", "y", "z");
1026
- }
1027
- _update = () => {
1028
- this.quaternion.copy(this.viewer.camera.quaternion).invert();
1029
- const e = this.location;
1030
- let t, s;
1031
- e.left !== null ? t = e.left : t = this.viewer.el.offsetWidth - te - e.right, e.top !== null ? s = e.top : s = this.viewer.el.offsetHeight - te - e.bottom, this.overlayPass.setViewport(t, s, te, te);
1032
- };
1033
- enable() {
1034
- return this.viewer.renderPipeline.addOverlayPass(this.overlayPass), this.viewer.addEventListener("beforeRender", this._update), this.viewer.render(), this;
1035
- }
1036
- disable() {
1037
- return this.viewer.renderPipeline.removeOverlayPass(this.overlayPass), this.viewer.removeEventListener("beforeRender", this._update), this.viewer.render(), this;
1038
- }
1039
- }
1040
- const qe = "position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;overflow:hidden;", Os = qe + "z-index:0;", As = qe + "z-index:1;";
1041
- class Bs {
1042
- el;
1043
- css2dRenderer = null;
1044
- css3dRenderer = null;
1045
- constructor(e) {
1046
- this.el = e, getComputedStyle(e).position === "static" && (e.style.position = "relative");
1047
- }
1048
- initCSS2DRenderer() {
1049
- const e = new os();
1050
- return e.setSize(this.el.clientWidth, this.el.clientHeight), e.domElement.style.cssText = As, this.el.appendChild(e.domElement), this.css2dRenderer = e, e;
1051
- }
1052
- initCSS3DRenderer() {
1053
- const e = new cs();
1054
- return e.setSize(this.el.clientWidth, this.el.clientHeight), e.domElement.style.cssText = Os, this.el.appendChild(e.domElement), this.css3dRenderer = e, e;
1055
- }
1056
- createCSS2DObject(e) {
1057
- return this.css2dRenderer || this.initCSS2DRenderer(), new as(e);
1058
- }
1059
- createCSS25DObject(e) {
1060
- return this.css3dRenderer || this.initCSS3DRenderer(), new hs(e);
1061
- }
1062
- createCSS3DObject(e) {
1063
- return this.css3dRenderer || this.initCSS3DRenderer(), new ls(e);
1064
- }
1065
- render(e, t) {
1066
- this.css2dRenderer && this.css2dRenderer.render(e, t), this.css3dRenderer && this.css3dRenderer.render(e, t);
1067
- }
1068
- resize(e, t) {
1069
- this.css2dRenderer && this.css2dRenderer.setSize(e, t), this.css3dRenderer && this.css3dRenderer.setSize(e, t);
1070
- }
1071
- dispose() {
1072
- this.css2dRenderer && (this.el.removeChild(this.css2dRenderer.domElement), this.css2dRenderer = null), this.css3dRenderer && (this.el.removeChild(this.css3dRenderer.domElement), this.css3dRenderer = null);
1073
- }
1074
- }
1075
- const Rs = "timestamp-query";
1076
- class Is {
1077
- el;
1078
- renderer;
1079
- container;
1080
- drawCallsText;
1081
- frameCallsText;
1082
- trianglesText;
1083
- pointsText;
1084
- linesText;
1085
- timestampText;
1086
- _enabled = !1;
1087
- #t = !1;
1088
- constructor(e, t) {
1089
- this.el = e, this.renderer = t;
1090
- const s = document.createElement("div");
1091
- s.style.position = "absolute", s.style.left = "12px", s.style.bottom = "12px", s.style.fontSize = "12px", s.style.color = "#fff", s.style.pointerEvents = "none", this.container = s;
1092
- function n(r, o = !0) {
1093
- const a = document.createElement("span");
1094
- return o && (a.style.marginLeft = "6px"), a.innerText = r, a;
1095
- }
1096
- function i() {
1097
- return document.createElement("br");
1098
- }
1099
- this.drawCallsText = n("0"), this.frameCallsText = n("0"), this.trianglesText = n("0"), this.linesText = n("0"), this.pointsText = n("0"), this.timestampText = n("0"), this.container.appendChild(n("draw calls", !1)), this.container.appendChild(this.drawCallsText), this.container.appendChild(i()), this.container.appendChild(n("frame calls", !1)), this.container.appendChild(this.frameCallsText), this.container.appendChild(i()), this.container.appendChild(n("triangles", !1)), this.container.appendChild(this.trianglesText), this.container.appendChild(i()), this.container.appendChild(n("points", !1)), this.container.appendChild(this.pointsText), this.container.appendChild(i()), this.container.appendChild(n("lines", !1)), this.container.appendChild(this.linesText), this.container.appendChild(i()), this.container.appendChild(n("timestamp", !1)), this.container.appendChild(this.timestampText), this.container.appendChild(i());
1100
- }
1101
- update() {
1102
- if (this._enabled) {
1103
- const { render: e } = this.renderer.info;
1104
- if (this.drawCallsText.innerText = e.drawCalls.toString(), this.frameCallsText.innerText = e.frameCalls.toString(), this.trianglesText.innerText = e.triangles.toString(), this.pointsText.innerText = e.points.toString(), this.linesText.innerText = e.lines.toString(), !this.#t) {
1105
- this.timestampText.innerText = "0";
1106
- return;
1107
- }
1108
- this.#n(Z.RENDER).then((t) => {
1109
- this._enabled && (this.timestampText.innerText = t?.toFixed(2) ?? "0");
1110
- }), this.#n(Z.COMPUTE);
1111
- }
1112
- }
1113
- enable() {
1114
- this._enabled = !0, this.#r(!0), this.el.appendChild(this.container);
1115
- }
1116
- disable() {
1117
- this._enabled = !1, this.#r(!1), this.#o(), this.container.remove();
1118
- }
1119
- dispose() {
1120
- this.disable();
1121
- }
1122
- #e() {
1123
- return this.renderer.backend;
1124
- }
1125
- #s() {
1126
- try {
1127
- return this.renderer.hasFeature(Rs);
1128
- } catch {
1129
- return !0;
1130
- }
1131
- }
1132
- #r(e) {
1133
- const t = this.#e();
1134
- if (!t) {
1135
- this.#t = !1;
1136
- return;
1137
- }
1138
- t.trackTimestamp = e && this.#s(), this.#t = t.trackTimestamp === !0;
1139
- }
1140
- #n(e) {
1141
- const t = this.#e()?.timestampQueryPool?.[e];
1142
- return t?.resolveQueriesAsync ? Promise.resolve(t.resolveQueriesAsync()).catch(() => {
1143
- }) : Promise.resolve(void 0);
1144
- }
1145
- #o() {
1146
- this.#n(Z.RENDER), this.#n(Z.COMPUTE);
1147
- }
1148
- }
1149
- wt.enabled = !0;
1150
- class An extends ke {
1151
- el;
1152
- renderer;
1153
- scene;
1154
- camera;
1155
- info;
1156
- controls;
1157
- renderPipeline;
1158
- timer;
1159
- roomEnvironment;
1160
- interactionManager;
1161
- objectManager;
1162
- viewerHelper;
1163
- cssRenderer;
1164
- frameCount = 1;
1165
- frameloop = "demand";
1166
- constructor({ el: e, rendererOptions: t }) {
1167
- super(), this.el = e, this.renderer = this._initRenderer(t), this.scene = this.createScene(), this.camera = this.createPerspectiveCamera(), this.info = new Is(this.el, this.renderer), this.controls = new Ts(this.camera, this.renderer.domElement), this.renderPipeline = new Ss(this.renderer, this.scene, this.camera), this.timer = new vt(), this.roomEnvironment = new Es(this.renderer), this.interactionManager = new bs(this.renderer.domElement, this.scene, this.camera), this.objectManager = new xs(), this.viewerHelper = new Ps(this), this.cssRenderer = new Bs(this.el), window.addEventListener("resize", this.onWindowResize);
1168
- }
1169
- onWindowResize = () => {
1170
- const e = this.el.clientWidth, t = this.el.clientHeight;
1171
- this.camera instanceof se ? (this.camera.aspect = e / t, this.camera.updateProjectionMatrix()) : this.camera instanceof ne && (this.camera.left = -e / 2, this.camera.right = e / 2, this.camera.top = t / 2, this.camera.bottom = -t / 2, this.camera.updateProjectionMatrix()), this.renderer.setSize(e, t), this.cssRenderer.resize(e, t), this.render();
1172
- };
1173
- async init() {
1174
- await this.renderer.init(), this.roomEnvironment.update(), this.scene.environment = this.roomEnvironment.envMap;
1175
- }
1176
- setCamera(e) {
1177
- this.camera = e, this.controls.camera = e, this.interactionManager.setCamera(e), this.renderPipeline.setCamera(e), this.onWindowResize(), this.dispatchEvent({ type: "cameraChange", camera: e });
1178
- }
1179
- setCameraByType(e) {
1180
- e === "perspective" && !(this.camera instanceof se) ? this.setCamera(this.createPerspectiveCamera()) : e === "orthographic" && !(this.camera instanceof ne) && this.setCamera(this.createOrthographicCamera());
1181
- }
1182
- render(e = 1) {
1183
- return this.frameCount += e, new Promise((t) => {
1184
- const s = () => {
1185
- this.removeEventListener("afterRender", s), t();
1186
- };
1187
- this.addEventListener("afterRender", s);
1188
- });
1189
- }
1190
- animate = (e) => {
1191
- this.timer.update(e);
1192
- const t = this.timer.getDelta();
1193
- this.dispatchEvent({ type: "beforeControlsUpdate", time: e, delta: t });
1194
- let s = this.controls.update(t);
1195
- this.dispatchEvent({ type: "afterControlsUpdate", time: e, delta: t }), this.frameCount > 0 && (this.frameCount--, s = !0), this.frameloop === "always" && (s = !0), s && (this.dispatchEvent({ type: "beforeRender", time: e, delta: t }), this.renderer.info.reset(), this.renderPipeline.render(), this.cssRenderer.render(this.scene, this.camera), this.info.update(), this.dispatchEvent({ type: "afterRender", time: e, delta: t }));
1196
- };
1197
- _initRenderer(e) {
1198
- const t = new bt({
1199
- reversedDepthBuffer: !0,
1200
- antialias: !1,
1201
- depth: !1,
1202
- trackTimestamp: !1,
1203
- ...e
1204
- });
1205
- return t.setSize(this.el.clientWidth, this.el.clientHeight), t.shadowMap.enabled = !0, t.shadowMap.type = xt, t.toneMapping = St, t.toneMappingExposure = 1, t.info.autoReset = !1, t.setPixelRatio(Math.min(window.devicePixelRatio, 1.5)), t.setAnimationLoop(this.animate), this.el.appendChild(t.domElement), t;
1206
- }
1207
- createScene() {
1208
- const e = new Ue();
1209
- return e.background = new T(0), e;
1210
- }
1211
- createPerspectiveCamera() {
1212
- const e = new se(50, this.el.clientWidth / this.el.clientHeight, 0.1, 1e5);
1213
- return e.position.setScalar(5), e;
1214
- }
1215
- createOrthographicCamera() {
1216
- const e = new ne(
1217
- -this.el.clientWidth / 2,
1218
- this.el.clientWidth / 2,
1219
- this.el.clientHeight / 2,
1220
- -this.el.clientHeight / 2,
1221
- 0.1,
1222
- 1e5
1223
- );
1224
- return e.position.setScalar(5), e;
1225
- }
1226
- /**
1227
- * Manually trigger a resize update.
1228
- */
1229
- resize(e, t) {
1230
- e !== void 0 && t !== void 0 && (this.el.style.width = `${e}px`, this.el.style.height = `${t}px`), this.onWindowResize();
1231
- }
1232
- /**
1233
- * Capture a screenshot of the current render.
1234
- */
1235
- async screenshot(e = {}) {
1236
- const { type: t = "image/png", quality: s = 1 } = e, n = this.el.clientWidth, i = this.el.clientHeight, r = e.width && e.height;
1237
- r && this.renderer.setSize(e.width, e.height), await this.render();
1238
- const o = this.renderer.domElement.toDataURL(t, s);
1239
- return r && (this.renderer.setSize(n, i), this.onWindowResize()), o;
1240
- }
1241
- /**
1242
- * Set the scene background color, texture, or null.
1243
- */
1244
- setBackground(e) {
1245
- e === null ? this.scene.background = null : e instanceof T || typeof e == "number" || typeof e == "string" ? this.scene.background = new T(e) : this.scene.background = e, this.render();
1246
- }
1247
- /**
1248
- * Set the scene environment map for reflections / IBL.
1249
- */
1250
- setEnvironment(e) {
1251
- this.scene.environment = e, this.render();
1252
- }
1253
- /**
1254
- * Enable shadow rendering.
1255
- */
1256
- enableShadow() {
1257
- this.renderer.shadowMap.enabled = !0, this.render();
1258
- }
1259
- /**
1260
- * Disable shadow rendering.
1261
- */
1262
- disableShadow() {
1263
- this.renderer.shadowMap.enabled = !1, this.render();
1264
- }
1265
- /**
1266
- * Enable linear fog.
1267
- */
1268
- enableFog(e = {}) {
1269
- const { color: t = 13421772, near: s = 10, far: n = 100 } = e;
1270
- this.scene.fog = new Ct(t, s, n), this.render();
1271
- }
1272
- /**
1273
- * Enable exponential fog.
1274
- */
1275
- enableFogExp2(e = {}) {
1276
- const { color: t = 13421772, density: s = 0.01 } = e;
1277
- this.scene.fog = new Tt(t, s), this.render();
1278
- }
1279
- /**
1280
- * Disable fog.
1281
- */
1282
- disableFog() {
1283
- this.scene.fog = null, this.render();
1284
- }
1285
- dispose() {
1286
- this.el.removeChild(this.renderer.domElement), window.removeEventListener("resize", this.onWindowResize), this.info.dispose(), this.interactionManager.dispose(), this.roomEnvironment.dispose(), this.cssRenderer.dispose(), this.renderPipeline.dispose(), this.renderer.dispose();
1287
- }
1288
- }
1289
- class Ls extends Qe {
346
+ class at extends Re {
1290
347
  constructor(e) {
1291
348
  super(e);
1292
349
  }
1293
350
  parse(e, t, s, n) {
1294
- if (zs(e.slice(0, 8)) === "SBMG----") {
1295
- const r = Ns(e.slice(8));
1296
- return super.parse(r, t, s, n);
351
+ if (vn(e.slice(0, 8)) === "SBMG----") {
352
+ const a = Sn(e.slice(8));
353
+ return super.parse(a, t, s, n);
1297
354
  } else
1298
355
  return super.parse(e, t, s, n);
1299
356
  }
1300
357
  }
1301
- function zs(h) {
1302
- return new TextDecoder().decode(new Uint8Array(h));
358
+ function vn(i) {
359
+ return new TextDecoder().decode(new Uint8Array(i));
1303
360
  }
1304
- function Ns(h) {
1305
- const e = new DataView(h);
361
+ function Sn(i) {
362
+ const e = new DataView(i);
1306
363
  for (let t = 0; t < e.byteLength; t++) {
1307
364
  const s = e.getUint8(t), n = (s >> 4 & 15) + (s << 4 & 240);
1308
365
  e.setUint8(t, n);
1309
366
  }
1310
367
  return e.buffer;
1311
368
  }
1312
- const Ds = 8, ks = 130, Re = 66, js = "SBK-----", Us = "SBM-----", Xe = new TextDecoder(), Hs = new TextEncoder();
1313
- function Fs(h) {
1314
- let e = Ds;
1315
- const t = new Uint8Array(h, 0, e);
1316
- if (Xe.decode(t) !== js)
1317
- return h;
1318
- e += ks;
1319
- const n = new Uint8Array(h, 0, e);
369
+ const In = 8, En = 130, ot = 66, Cn = "SBK-----", An = "SBM-----", Vt = new TextDecoder(), On = new TextEncoder();
370
+ function Bn(i) {
371
+ let e = In;
372
+ const t = new Uint8Array(i, 0, e);
373
+ if (Vt.decode(t) !== Cn)
374
+ return i;
375
+ e += En;
376
+ const n = new Uint8Array(i, 0, e);
1320
377
  if (n[40] === 1) {
1321
- const r = Hs.encode(Us), o = new Uint8Array([n[41]]), a = Gs(n), c = $s(a);
1322
- let l = Re % c.length;
1323
- const d = e + Re, p = new Uint8Array(h, d), u = new Uint8Array(p.length);
1324
- for (let w = 0; w < p.length; w++)
1325
- u[w] = p[w] ^ c[l], l = (l + 1) % c.length;
1326
- const m = new Uint8Array(r.length + o.length + u.length);
1327
- return m.set(r), m.set(o, r.length), m.set(u, r.length + o.length), m.buffer;
378
+ const a = On.encode(An), o = new Uint8Array([n[41]]), c = _n(n), l = Tn(c);
379
+ let h = ot % l.length;
380
+ const d = e + ot, u = new Uint8Array(i, d), p = new Uint8Array(u.length);
381
+ for (let I = 0; I < u.length; I++)
382
+ p[I] = u[I] ^ l[h], h = (h + 1) % l.length;
383
+ const x = new Uint8Array(a.length + o.length + p.length);
384
+ return x.set(a), x.set(o, a.length), x.set(p, a.length + o.length), x.buffer;
1328
385
  }
1329
386
  }
1330
- function Gs(h) {
387
+ function _n(i) {
1331
388
  const e = new Uint8Array(128);
1332
- return e.set(h.slice(42, 74), 0), e.set(h.slice(74, 138), 32), e.set(h.slice(8, 40), 96), e;
389
+ return e.set(i.slice(42, 74), 0), e.set(i.slice(74, 138), 32), e.set(i.slice(8, 40), 96), e;
1333
390
  }
1334
- function $s(h) {
391
+ function Tn(i) {
1335
392
  const e = new Uint8Array(64);
1336
- return e.set(h.slice(0, 8), 0), e.set(h.slice(24, 32), 8), e.set(h.slice(40, 56), 16), e.set(h.slice(64, 88), 32), e.set(h.slice(96, 104), 56), e;
393
+ return e.set(i.slice(0, 8), 0), e.set(i.slice(24, 32), 8), e.set(i.slice(40, 56), 16), e.set(i.slice(64, 88), 32), e.set(i.slice(96, 104), 56), e;
1337
394
  }
1338
- const Ws = (h, e, t) => {
1339
- const s = h.buffer.slice(t, t + e);
1340
- let n = Xe.decode(s);
395
+ const Ln = (i, e, t) => {
396
+ const s = i.buffer.slice(t, t + e);
397
+ let n = Vt.decode(s);
1341
398
  return n = n.replace("\\", "/"), n.startsWith("Maps/") || (n = `Maps/${n}`), n;
1342
- }, Ks = (h, e, t) => {
1343
- const [s, n, i, r, o] = e, a = t || r < 1;
1344
- return new L({
1345
- name: h,
1346
- color: new T(s, n, i),
1347
- opacity: r,
1348
- transparent: a,
399
+ }, Nn = (i, e, t) => {
400
+ const [s, n, r, a, o] = e, c = t || a < 1;
401
+ return new q({
402
+ name: i,
403
+ color: new P(s, n, r),
404
+ opacity: a,
405
+ transparent: c,
1349
406
  alphaTest: 0.01,
1350
407
  side: o
1351
408
  });
1352
- }, Qs = (h) => h?.toLowerCase().endsWith(".png") ?? !1;
1353
- class qs {
409
+ }, Dn = (i) => i?.toLowerCase().endsWith(".png") ?? !1;
410
+ class Pn {
1354
411
  data;
1355
412
  options;
1356
413
  textureLoader;
1357
414
  littleEndian = !0;
1358
415
  materials = /* @__PURE__ */ new Map();
1359
416
  constructor(e, t) {
1360
- this.data = e, this.options = t, this.textureLoader = new Fe(t.manager), this.textureLoader.setCrossOrigin(t.crossOrigin), this.textureLoader.setRequestHeader(t.requestHeader);
417
+ this.data = e, this.options = t, this.textureLoader = new Ft(t.manager), this.textureLoader.setCrossOrigin(t.crossOrigin), this.textureLoader.setRequestHeader(t.requestHeader);
1361
418
  }
1362
419
  parse(e, t) {
1363
420
  let s = this.data;
1364
- const n = Fs(this.data);
421
+ const n = Bn(this.data);
1365
422
  n && (s = n);
1366
- const i = new DataView(s);
1367
- let r = 8;
1368
- const o = i.getUint8(r);
1369
- r += 1, o === 1 ? this._parseV2(i, r, e) : o === 2 ? this._parseV2(i, r, e) : o === 3 ? this._parseV3(i, r, e) : t?.(new Error(`SBMLoader: Unsupported SBM version: ${o}`));
423
+ const r = new DataView(s);
424
+ let a = 8;
425
+ const o = r.getUint8(a);
426
+ a += 1, o === 1 ? this._parseV2(r, a, e) : o === 2 ? this._parseV2(r, a, e) : o === 3 ? this._parseV3(r, a, e) : t?.(new Error(`SBMLoader: Unsupported SBM version: ${o}`));
1370
427
  }
1371
428
  _parseV2(e, t, s) {
1372
- const n = new I(), i = e.getUint16(t, this.littleEndian);
429
+ const n = new W(), r = e.getUint16(t, this.littleEndian);
1373
430
  t += 2;
1374
- const r = e.getUint16(t, this.littleEndian);
431
+ const a = e.getUint16(t, this.littleEndian);
1375
432
  t += 2;
1376
- for (let o = 0; o < i; ++o) {
1377
- const a = e.getUint16(t, this.littleEndian).toString();
433
+ for (let o = 0; o < r; ++o) {
434
+ const c = e.getUint16(t, this.littleEndian).toString();
1378
435
  t += 2, t += 4, t += 4, t += 4, t += 4;
1379
- const c = e.getFloat32(t, this.littleEndian);
1380
- t += 4;
1381
436
  const l = e.getFloat32(t, this.littleEndian);
1382
437
  t += 4;
438
+ const h = e.getFloat32(t, this.littleEndian);
439
+ t += 4;
1383
440
  const d = e.getFloat32(t, this.littleEndian);
1384
441
  t += 4;
1385
- const p = e.getFloat32(t, this.littleEndian);
442
+ const u = e.getFloat32(t, this.littleEndian);
1386
443
  t += 4, t += 4, t += 4, t += 4, t += 4;
1387
- let u = e.getUint8(t);
1388
- t += 1, u === 0 ? u = _t : u === 1 ? u = Et : u === 2 && (u = Pt);
1389
- const m = e.getUint16(t, this.littleEndian);
444
+ let p = e.getUint8(t);
445
+ t += 1, p === 0 ? p = ws : p === 1 ? p = xs : p === 2 && (p = Ht);
446
+ const x = e.getUint16(t, this.littleEndian);
1390
447
  t += 2;
1391
- const w = m > 0 ? Ws(e, m, t) : "";
1392
- if (t += m, !this.materials.has(a)) {
1393
- const x = Ks(a, [c, l, d, p, u], Qs(w));
1394
- this.materials.set(a, x), w && this.options.path && this.textureLoader.load(R.resolveURL(w, this.options.path), (y) => {
1395
- y.colorSpace = Ge, y.wrapS = Se, y.wrapT = Se, y.flipY = !1, y.anisotropy = 16, x.map = y;
448
+ const I = x > 0 ? Ln(e, x, t) : "";
449
+ if (t += x, !this.materials.has(c)) {
450
+ const C = Nn(c, [l, h, d, u, p], Dn(I));
451
+ this.materials.set(c, C), I && this.options.path && this.textureLoader.load(he.resolveURL(I, this.options.path), (y) => {
452
+ y.colorSpace = Se, y.wrapS = Ie, y.wrapT = Ie, y.flipY = !1, y.anisotropy = 16, C.map = y;
1396
453
  });
1397
454
  }
1398
455
  }
1399
- for (let o = 0; o < r; ++o) {
1400
- const a = e.getUint16(t, this.littleEndian).toString();
1401
- t += 2;
456
+ for (let o = 0; o < a; ++o) {
1402
457
  const c = e.getUint16(t, this.littleEndian).toString();
1403
458
  t += 2;
1404
- const l = [], d = [], p = [], u = [], m = e.getUint16(t, this.littleEndian);
1405
- if (t += 2, m > 0)
1406
- for (let g = 0; g < m; g++) {
1407
- const b = new v();
1408
- b.setX(e.getFloat32(t, this.littleEndian)), t += 4, b.setY(e.getFloat32(t, this.littleEndian)), t += 4, b.setZ(e.getFloat32(t, this.littleEndian)), t += 4, l.push(b);
459
+ const l = e.getUint16(t, this.littleEndian).toString();
460
+ t += 2;
461
+ const h = [], d = [], u = [], p = [], x = e.getUint16(t, this.littleEndian);
462
+ if (t += 2, x > 0)
463
+ for (let b = 0; b < x; b++) {
464
+ const S = new D();
465
+ S.setX(e.getFloat32(t, this.littleEndian)), t += 4, S.setY(e.getFloat32(t, this.littleEndian)), t += 4, S.setZ(e.getFloat32(t, this.littleEndian)), t += 4, h.push(S);
1409
466
  }
1410
- const w = e.getUint16(t, this.littleEndian);
1411
- if (t += 2, w > 0)
1412
- for (let g = 0; g < w; g++)
467
+ const I = e.getUint16(t, this.littleEndian);
468
+ if (t += 2, I > 0)
469
+ for (let b = 0; b < I; b++)
1413
470
  t += 4, t += 4, t += 4;
1414
- const S = e.getUint16(t, this.littleEndian);
1415
- if (t += 2, S > 0)
1416
- for (let g = 0; g < S; g++) {
1417
- const b = new C();
1418
- b.setX(e.getFloat32(t, this.littleEndian)), t += 4, b.setY(e.getFloat32(t, this.littleEndian)), t += 4, d.push(b);
471
+ const _ = e.getUint16(t, this.littleEndian);
472
+ if (t += 2, _ > 0)
473
+ for (let b = 0; b < _; b++) {
474
+ const S = new j();
475
+ S.setX(e.getFloat32(t, this.littleEndian)), t += 4, S.setY(e.getFloat32(t, this.littleEndian)), t += 4, d.push(S);
1419
476
  }
1420
- const x = e.getUint16(t, this.littleEndian);
1421
- if (t += 2, x > 0)
1422
- for (let g = 0; g < x; g++) {
1423
- const b = e.getUint16(t, this.littleEndian);
477
+ const C = e.getUint16(t, this.littleEndian);
478
+ if (t += 2, C > 0)
479
+ for (let b = 0; b < C; b++) {
480
+ const S = e.getUint16(t, this.littleEndian);
1424
481
  t += 2;
1425
- const z = e.getUint16(t, this.littleEndian);
482
+ const A = e.getUint16(t, this.littleEndian);
1426
483
  t += 2;
1427
- const N = e.getUint16(t, this.littleEndian);
484
+ const v = e.getUint16(t, this.littleEndian);
1428
485
  t += 2;
1429
- const P = [b, z, N];
1430
- p.push(P), d.length > 0 && u.push([d[P[0]], d[P[1]], d[P[2]]]);
486
+ const E = [S, A, v];
487
+ u.push(E), d.length > 0 && p.push([d[E[0]], d[E[1]], d[E[2]]]);
1431
488
  }
1432
- const y = [], _ = [];
1433
- for (let g = 0; g < p.length; g++) {
1434
- const b = p[g], z = l[b[0]], N = l[b[1]], P = l[b[2]];
1435
- y.push(...z.toArray(), ...N.toArray(), ...P.toArray());
1436
- let J = new C(), W = new C(), j = new C();
1437
- const U = u[g];
1438
- U !== void 0 && (J = U[0], W = U[1], j = U[2]), _.push(...J.toArray(), ...W.toArray(), ...j.toArray());
489
+ const y = [], w = [];
490
+ for (let b = 0; b < u.length; b++) {
491
+ const S = u[b], A = h[S[0]], v = h[S[1]], E = h[S[2]];
492
+ y.push(...A.toArray(), ...v.toArray(), ...E.toArray());
493
+ let z = new j(), N = new j(), f = new j();
494
+ const L = p[b];
495
+ L !== void 0 && (z = L[0], N = L[1], f = L[2]), w.push(...z.toArray(), ...N.toArray(), ...f.toArray());
1439
496
  }
1440
- const A = new Float32Array(y), B = new Float32Array(_), E = new Q();
1441
- if (A.length > 0 && E.setAttribute("position", new Ce(A, 3)), B.length > 0 && E.setAttribute("uv", new Ce(B, 2)), E.computeVertexNormals(), this.materials.has(c)) {
1442
- const g = new k(E, this.materials.get(c));
1443
- g.name = a, g.castShadow = !0, g.receiveShadow = !0, n.add(g);
497
+ const g = new Float32Array(y), m = new Float32Array(w), M = new G();
498
+ if (g.length > 0 && M.setAttribute("position", new Pe(g, 3)), m.length > 0 && M.setAttribute("uv", new Pe(m, 2)), M.computeVertexNormals(), this.materials.has(l)) {
499
+ const b = new k(M, this.materials.get(l));
500
+ b.name = c, b.castShadow = !0, b.receiveShadow = !0, n.add(b);
1444
501
  }
1445
502
  }
1446
503
  s(n);
1447
504
  }
1448
505
  _parseV3(e, t, s) {
1449
- const n = new I();
506
+ const n = new W();
1450
507
  console.warn("SBMLoader: SBM version 3 is not supported yet."), s(n);
1451
508
  }
1452
509
  }
1453
- class Xs extends Mt {
510
+ class ct extends bs {
1454
511
  load(e, t, s, n) {
1455
- let i;
512
+ let r;
1456
513
  if (this.resourcePath !== "")
1457
- i = this.resourcePath;
514
+ r = this.resourcePath;
1458
515
  else if (this.path !== "") {
1459
- const a = R.extractUrlBase(e);
1460
- i = R.resolveURL(a, this.path);
516
+ const c = he.extractUrlBase(e);
517
+ r = he.resolveURL(c, this.path);
1461
518
  } else
1462
- i = R.extractUrlBase(e);
519
+ r = he.extractUrlBase(e);
1463
520
  this.manager.itemStart(e);
1464
- const r = (a) => {
1465
- n ? n(a) : console.error(a), this.manager.itemError(e), this.manager.itemEnd(e);
1466
- }, o = new He(this.manager);
521
+ const a = (c) => {
522
+ n ? n(c) : console.error(c), this.manager.itemError(e), this.manager.itemEnd(e);
523
+ }, o = new Wt(this.manager);
1467
524
  o.setPath(this.path), o.setResponseType("arraybuffer"), o.setRequestHeader(this.requestHeader), o.setWithCredentials(this.withCredentials), o.load(
1468
525
  e,
1469
- (a) => {
526
+ (c) => {
1470
527
  try {
1471
528
  this.parse(
1472
- a,
1473
- i,
1474
- (c) => {
1475
- t(c), this.manager.itemEnd(e);
529
+ c,
530
+ r,
531
+ (l) => {
532
+ t(l), this.manager.itemEnd(e);
1476
533
  },
1477
- r
534
+ a
1478
535
  );
1479
- } catch (c) {
1480
- r(c);
536
+ } catch (l) {
537
+ a(l);
1481
538
  }
1482
539
  },
1483
540
  s,
1484
- r
541
+ a
1485
542
  );
1486
543
  }
1487
544
  parse(e, t, s, n) {
1488
- const i = new TextDecoder().decode(e.slice(0, 8));
1489
- if (i !== "SBK-----" && i !== "SBM-----") {
1490
- n?.(new Error(`SBMLoader: Invalid SBM format: ${i}`));
545
+ const r = new TextDecoder().decode(e.slice(0, 8));
546
+ if (r !== "SBK-----" && r !== "SBM-----") {
547
+ n?.(new Error(`SBMLoader: Invalid SBM format: ${r}`));
1491
548
  return;
1492
549
  }
1493
- new qs(e, {
550
+ new Pn(e, {
1494
551
  path: t,
1495
552
  crossOrigin: this.crossOrigin,
1496
553
  requestHeader: this.requestHeader,
1497
554
  manager: this.manager
1498
555
  }).parse(s, n);
1499
556
  }
1500
- parseAsync(e, t) {
1501
- return new Promise((s, n) => {
1502
- this.parse(
1503
- e,
1504
- t,
1505
- (i) => {
1506
- s(i);
1507
- },
1508
- (i) => {
1509
- n(i);
1510
- }
1511
- );
1512
- });
557
+ parseAsync(e, t) {
558
+ return new Promise((s, n) => {
559
+ this.parse(
560
+ e,
561
+ t,
562
+ (r) => {
563
+ s(r);
564
+ },
565
+ (r) => {
566
+ n(r);
567
+ }
568
+ );
569
+ });
570
+ }
571
+ }
572
+ const Rn = {
573
+ 5120: Int8Array,
574
+ 5121: Uint8Array,
575
+ 5122: Int16Array,
576
+ 5123: Uint16Array,
577
+ 5125: Uint32Array,
578
+ 5126: Float32Array
579
+ }, kn = {
580
+ SCALAR: 1,
581
+ VEC2: 2,
582
+ VEC3: 3,
583
+ VEC4: 4,
584
+ MAT2: 4,
585
+ MAT3: 9,
586
+ MAT4: 16
587
+ }, zn = {
588
+ POSITION: "position",
589
+ NORMAL: "normal",
590
+ TANGENT: "tangent",
591
+ TEXCOORD_0: "uv",
592
+ TEXCOORD_1: "uv1",
593
+ TEXCOORD_2: "uv2",
594
+ TEXCOORD_3: "uv3",
595
+ COLOR_0: "color"
596
+ };
597
+ function oe(i, e) {
598
+ e && typeof e == "object" && !Array.isArray(e) && Object.assign(i.userData, e);
599
+ }
600
+ function Un(i) {
601
+ if (i.protocolVersion !== et)
602
+ throw new Error(
603
+ `Unsupported model decode protocol ${i.protocolVersion}; expected ${et}.`
604
+ );
605
+ const { document: e, buffers: t, images: s } = i;
606
+ hn(e);
607
+ const n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), l = (w) => {
608
+ const g = n.get(w);
609
+ if (g) return g;
610
+ const m = e.accessors?.[w];
611
+ if (!m || m.bufferView === void 0)
612
+ throw new Error(`Decoded glTF references missing accessor ${w}.`);
613
+ const M = e.bufferViews?.[m.bufferView];
614
+ if (!M) throw new Error(`Decoded glTF references missing bufferView ${m.bufferView}.`);
615
+ const b = t[M.buffer];
616
+ if (!b) throw new Error(`Decoded glTF references missing buffer ${M.buffer}.`);
617
+ const S = Rn[m.componentType], A = kn[m.type];
618
+ if (!S || !A)
619
+ throw new Error(`Unsupported decoded glTF accessor type ${m.componentType}/${m.type}.`);
620
+ const v = S.BYTES_PER_ELEMENT, E = M.byteOffset ?? 0, z = m.byteOffset ?? 0;
621
+ let N;
622
+ const f = A * v;
623
+ if (M.byteStride && M.byteStride !== f) {
624
+ if (M.byteStride % v !== 0 || z % v !== 0)
625
+ throw new Error(`Decoded glTF accessor ${w} has an invalid interleaved alignment.`);
626
+ const L = Math.floor(z / M.byteStride), O = [
627
+ m.bufferView,
628
+ m.componentType,
629
+ L,
630
+ m.count
631
+ ].join(":");
632
+ let B = r.get(O);
633
+ if (!B) {
634
+ const U = new S(
635
+ b,
636
+ E + L * M.byteStride,
637
+ m.count * M.byteStride / v
638
+ );
639
+ B = new vs(U, M.byteStride / v), r.set(O, B);
640
+ }
641
+ N = new Ke(
642
+ B,
643
+ A,
644
+ z % M.byteStride / v,
645
+ m.normalized ?? !1
646
+ );
647
+ } else {
648
+ const L = new S(
649
+ b,
650
+ E + z,
651
+ m.count * A
652
+ );
653
+ N = new Pe(L, A, m.normalized ?? !1);
654
+ }
655
+ return N.name = m.name ?? "", n.set(w, N), N;
656
+ }, h = (w, g, m) => {
657
+ const M = `${w}:${g}:${m}`, b = c.get(M);
658
+ if (b) return b;
659
+ const S = e.textures?.[w];
660
+ if (!S || S.source === void 0)
661
+ throw new Error(`Decoded glTF references missing texture ${w}.`);
662
+ const A = s[S.source];
663
+ if (!A) throw new Error(`Decoded glTF references missing image ${S.source}.`);
664
+ const v = S.sampler === void 0 ? void 0 : e.samplers?.[S.sampler], E = new $t(A);
665
+ return E.name = S.name ?? e.images?.[S.source]?.name ?? "", E.flipY = !1, E.colorSpace = g, E.channel = m, E.magFilter = v?.magFilter === 9728 ? Ee : Ve, E.minFilter = (() => {
666
+ switch (v?.minFilter) {
667
+ case 9728:
668
+ return Ee;
669
+ case 9729:
670
+ return Ve;
671
+ case 9984:
672
+ return Cs;
673
+ case 9985:
674
+ return Es;
675
+ case 9986:
676
+ return Is;
677
+ default:
678
+ return Ss;
679
+ }
680
+ })(), E.wrapS = (() => {
681
+ switch (v?.wrapS) {
682
+ case 33071:
683
+ return Ye;
684
+ case 33648:
685
+ return Xe;
686
+ default:
687
+ return Ie;
688
+ }
689
+ })(), E.wrapT = (() => {
690
+ switch (v?.wrapT) {
691
+ case 33071:
692
+ return Ye;
693
+ case 33648:
694
+ return Xe;
695
+ default:
696
+ return Ie;
697
+ }
698
+ })(), E.needsUpdate = !0, c.set(M, E), E;
699
+ }, d = (w, g, m, M) => {
700
+ m && (w[g] = h(m.index, M, m.texCoord ?? 0));
701
+ }, u = (w, g, m, M) => {
702
+ const b = [
703
+ w ?? "default",
704
+ g ? "derivative-tangents" : "",
705
+ m ? "vertex-colors" : "",
706
+ M ? "flat-shading" : ""
707
+ ].join(":"), S = o.get(b);
708
+ if (S) return S;
709
+ const A = w === void 0 ? void 0 : e.materials?.[w];
710
+ if (w !== void 0 && !A)
711
+ throw new Error(`Decoded glTF references missing material ${w}.`);
712
+ const v = A ?? {}, E = v.pbrMetallicRoughness ?? {}, z = E.baseColorFactor ?? [1, 1, 1, 1], N = v.alphaMode ?? "OPAQUE", f = new Ms({
713
+ color: new P().setRGB(
714
+ z[0] ?? 1,
715
+ z[1] ?? 1,
716
+ z[2] ?? 1,
717
+ qe
718
+ ),
719
+ opacity: z[3] ?? 1,
720
+ metalness: E.metallicFactor ?? 1,
721
+ roughness: E.roughnessFactor ?? 1,
722
+ transparent: N === "BLEND",
723
+ depthWrite: N !== "BLEND",
724
+ alphaTest: N === "MASK" ? v.alphaCutoff ?? 0.5 : 0
725
+ });
726
+ return v.doubleSided && (f.side = Ht), f.vertexColors = m, f.flatShading = M, f.name = v.name ?? "", d(f, "map", E.baseColorTexture, Se), d(f, "metalnessMap", E.metallicRoughnessTexture, fe), d(f, "roughnessMap", E.metallicRoughnessTexture, fe), d(f, "normalMap", v.normalTexture, fe), d(f, "aoMap", v.occlusionTexture, fe), d(f, "emissiveMap", v.emissiveTexture, Se), v.normalTexture?.scale !== void 0 && (f.normalScale = new j(
727
+ v.normalTexture.scale,
728
+ v.normalTexture.scale
729
+ )), g && (f.normalScale.y *= -1), v.occlusionTexture?.strength !== void 0 && (f.aoMapIntensity = v.occlusionTexture.strength), v.emissiveFactor && f.emissive.setRGB(
730
+ v.emissiveFactor[0] ?? 0,
731
+ v.emissiveFactor[1] ?? 0,
732
+ v.emissiveFactor[2] ?? 0,
733
+ qe
734
+ ), oe(f, v.extras), o.set(b, f), f;
735
+ }, p = (w, g) => {
736
+ const m = `${w}:${g}`, M = a.get(m);
737
+ if (M) return M;
738
+ const b = e.meshes?.[w]?.primitives[g];
739
+ if (!b) throw new Error(`Decoded glTF references missing primitive ${m}.`);
740
+ const S = new G();
741
+ for (const [A, v] of Object.entries(b.attributes)) {
742
+ const E = zn[A] ?? A.toLowerCase();
743
+ S.setAttribute(E, l(v));
744
+ }
745
+ if (b.indices !== void 0) {
746
+ const A = l(b.indices);
747
+ if (A instanceof Ke)
748
+ throw new Error(`Decoded glTF index accessor ${b.indices} cannot be interleaved.`);
749
+ S.setIndex(A);
750
+ }
751
+ return a.set(m, S), S;
752
+ }, x = (w) => {
753
+ const g = e.meshes?.[w];
754
+ if (!g) throw new Error(`Decoded glTF references missing mesh ${w}.`);
755
+ const m = g.primitives.map((b, S) => {
756
+ const A = new k(
757
+ p(w, S),
758
+ u(
759
+ b.material,
760
+ b.attributes.TANGENT === void 0,
761
+ b.attributes.COLOR_0 !== void 0,
762
+ b.attributes.NORMAL === void 0
763
+ )
764
+ );
765
+ return A.name = g.name ?? "", A;
766
+ });
767
+ if (m.length === 1)
768
+ return oe(m[0], g.extras), m[0];
769
+ const M = new W();
770
+ return M.name = g.name ?? "", M.add(...m), oe(M, g.extras), M;
771
+ }, I = (w) => {
772
+ const g = e.nodes?.[w];
773
+ if (!g) throw new Error(`Decoded glTF references missing node ${w}.`);
774
+ const m = g.mesh === void 0 ? new W() : x(g.mesh);
775
+ m.name = g.name ?? m.name, g.matrix ? new R().fromArray(g.matrix).decompose(m.position, m.quaternion, m.scale) : (g.translation && m.position.fromArray(g.translation), g.rotation && m.quaternion.fromArray(g.rotation), g.scale && m.scale.fromArray(g.scale)), oe(m, g.extras);
776
+ for (const M of g.children ?? [])
777
+ m.add(I(M));
778
+ return m;
779
+ }, _ = e.scene ?? 0, C = e.scenes?.[_];
780
+ if (!C) throw new Error(`Decoded glTF references missing scene ${_}.`);
781
+ const y = new W();
782
+ y.name = C.name ?? "", oe(y, C.extras);
783
+ for (const w of C.nodes ?? []) y.add(I(w));
784
+ return y.animations = [], y;
785
+ }
786
+ const jn = 256;
787
+ function Wn(i) {
788
+ return i instanceof Error ? { message: i.message, name: i.name, stack: i.stack } : { message: String(i) };
789
+ }
790
+ function Fn(i) {
791
+ const e = new Error(i.message);
792
+ return e.name = i.name ?? "Error", e.stack = i.stack, e;
793
+ }
794
+ class ve extends Error {
795
+ name = "ModelDecodeWorkerUnavailableError";
796
+ constructor(e, t) {
797
+ super(e, t);
798
+ }
799
+ }
800
+ function Hn(i, e, t = jn) {
801
+ if (i.images.length !== i.imageKeys.length)
802
+ throw new Error("Decoded model image identities do not match its image payload.");
803
+ const s = [];
804
+ for (let n = 0; n < i.images.length; n++) {
805
+ const r = i.imageKeys[n], a = i.images[n], o = e.get(r);
806
+ if (o)
807
+ e.delete(r), e.set(r, o), o !== a && a.close(), i.images[n] = o;
808
+ else
809
+ for (e.set(r, a), s.push(r); e.size > Math.max(0, t); ) {
810
+ const c = e.keys().next().value;
811
+ if (c === void 0) break;
812
+ e.delete(c);
813
+ }
814
+ }
815
+ return s;
816
+ }
817
+ class $n {
818
+ worker;
819
+ #s;
820
+ #a = 1;
821
+ #t = /* @__PURE__ */ new Map();
822
+ #e = /* @__PURE__ */ new Map();
823
+ #r = !1;
824
+ constructor(e, t = {}) {
825
+ this.worker = e, this.#s = t.onFatal, e.addEventListener("message", this.#o), e.addEventListener("error", this.#l), e.addEventListener("messageerror", this.#d);
826
+ }
827
+ get disposed() {
828
+ return this.#r;
829
+ }
830
+ supports(e) {
831
+ const t = e.split(/[?#]/, 1)[0].split(".").pop()?.toLowerCase();
832
+ return t === "sbmx" || t === "gltf" || t === "glb";
833
+ }
834
+ async loadAsync(e, t = {}) {
835
+ if (this.#r)
836
+ throw new ve("Model decode Worker is unavailable.");
837
+ const s = this.#a++, { signal: n, loadingManager: r, ...a } = t;
838
+ if (n?.aborted) throw n.reason ?? new DOMException("Aborted", "AbortError");
839
+ const o = await new Promise((l, h) => {
840
+ const d = {
841
+ resolve: l,
842
+ reject: h,
843
+ manager: r,
844
+ rootUrl: e,
845
+ resources: /* @__PURE__ */ new Map()
846
+ };
847
+ if (r?.itemStart(e), n) {
848
+ const u = () => {
849
+ this.#t.delete(s), this.#h(d, n.reason ?? new DOMException("Aborted", "AbortError")), h(n.reason ?? new DOMException("Aborted", "AbortError"));
850
+ try {
851
+ this.#n({ type: "cancel", id: s });
852
+ } catch {
853
+ }
854
+ };
855
+ d.cleanup = () => n.removeEventListener("abort", u), n.addEventListener("abort", u, { once: !0 });
856
+ }
857
+ this.#t.set(s, d);
858
+ try {
859
+ this.#n({ type: "decode", id: s, url: e, options: a });
860
+ } catch (u) {
861
+ this.#t.delete(s), d.cleanup?.();
862
+ const p = u instanceof Error ? u : new Error(String(u));
863
+ this.#h(d, p), h(p);
864
+ }
865
+ }), c = [];
866
+ try {
867
+ return c.push(...Hn(o, this.#e)), Un(o);
868
+ } catch (l) {
869
+ const h = /* @__PURE__ */ new Set();
870
+ for (const d of c) {
871
+ const u = o.imageKeys.indexOf(d), p = this.#e.get(d) ?? o.images[u];
872
+ this.#e.get(d) === p && this.#e.delete(d), p && !h.has(p) && (p.close(), h.add(p));
873
+ }
874
+ throw l;
875
+ } finally {
876
+ try {
877
+ this.#n({ type: "ack", id: s });
878
+ } catch {
879
+ }
880
+ }
881
+ }
882
+ dispose() {
883
+ if (!this.#r) {
884
+ this.#r = !0;
885
+ try {
886
+ this.#n({ type: "dispose" });
887
+ } catch {
888
+ }
889
+ this.#i(), this.worker.terminate(), this.#p(new ve("Model decode Worker was disposed.")), this.#e.clear();
890
+ }
891
+ }
892
+ #n(e) {
893
+ this.worker.postMessage(e);
894
+ }
895
+ #o = (e) => {
896
+ const t = e.data;
897
+ if (t.type === "disposed") return;
898
+ if (t.type === "resolve-resource") {
899
+ this.#c(t.id, t.resourceId, t.url);
900
+ return;
901
+ }
902
+ if (t.type === "resource-complete") {
903
+ const n = this.#t.get(t.id), r = n?.resources.get(t.resourceId);
904
+ n && r !== void 0 && (n.resources.delete(t.resourceId), t.ok || n.manager?.itemError(r), n.manager?.itemEnd(r));
905
+ return;
906
+ }
907
+ const s = this.#t.get(t.id);
908
+ if (!s) {
909
+ if (t.type === "decoded") {
910
+ t.packet.images.forEach((n) => n.close());
911
+ try {
912
+ this.#n({ type: "ack", id: t.id });
913
+ } catch {
914
+ }
915
+ }
916
+ return;
917
+ }
918
+ if (this.#t.delete(t.id), s.cleanup?.(), t.type === "decoded")
919
+ this.#h(s), s.resolve(t.packet);
920
+ else if (t.type === "unsupported")
921
+ this.#h(s, void 0, !1), s.reject(new Kt(t.reason));
922
+ else {
923
+ const n = Fn(t.error);
924
+ this.#h(s, n), s.reject(n);
925
+ }
926
+ };
927
+ #c(e, t, s) {
928
+ const n = this.#t.get(e);
929
+ if (!n) {
930
+ try {
931
+ this.#n({
932
+ type: "resource-resolved",
933
+ id: e,
934
+ resourceId: t,
935
+ error: { message: "The model decode request is no longer active.", name: "AbortError" }
936
+ });
937
+ } catch {
938
+ }
939
+ return;
940
+ }
941
+ let r;
942
+ try {
943
+ r = n.manager?.resolveURL(s) ?? s, n.manager?.itemStart(r), n.manager && n.resources.set(t, r), this.#n({ type: "resource-resolved", id: e, resourceId: t, url: r });
944
+ } catch (a) {
945
+ r !== void 0 && n.resources.delete(t) && (n.manager?.itemError(r), n.manager?.itemEnd(r));
946
+ try {
947
+ this.#n({ type: "resource-resolved", id: e, resourceId: t, error: Wn(a) });
948
+ } catch (o) {
949
+ this.#u(o instanceof Error ? o : new Error(String(o)));
950
+ }
951
+ }
952
+ }
953
+ #l = (e) => {
954
+ this.#u(e.error instanceof Error ? e.error : new Error(e.message));
955
+ };
956
+ #d = () => {
957
+ this.#u(new Error("Failed to deserialize a model decode Worker response."));
958
+ };
959
+ #u(e) {
960
+ if (this.#r) return;
961
+ this.#r = !0, this.#i(), this.worker.terminate();
962
+ const t = new ve(
963
+ `Model decode Worker failed: ${e.message}`,
964
+ { cause: e }
965
+ );
966
+ this.#p(t), this.#e.clear(), this.#s?.(t);
967
+ }
968
+ #i() {
969
+ this.worker.removeEventListener("message", this.#o), this.worker.removeEventListener("error", this.#l), this.worker.removeEventListener("messageerror", this.#d);
970
+ }
971
+ #h(e, t, s = t !== void 0) {
972
+ for (const n of e.resources.values())
973
+ t && e.manager?.itemError(n), e.manager?.itemEnd(n);
974
+ e.resources.clear(), s && e.manager?.itemError(e.rootUrl), e.manager?.itemEnd(e.rootUrl);
975
+ }
976
+ #p(e) {
977
+ for (const t of this.#t.values())
978
+ t.cleanup?.(), this.#h(t, e), t.reject(e);
979
+ this.#t.clear();
1513
980
  }
1514
981
  }
1515
- const Ys = [
982
+ const Gn = [
1516
983
  "map",
1517
984
  "alphaMap",
1518
985
  "aoMap",
@@ -1539,36 +1006,59 @@ const Ys = [
1539
1006
  "thicknessMap",
1540
1007
  "transmissionMap"
1541
1008
  ];
1542
- function K(h) {
1543
- return h.traverse((e) => {
1009
+ function ce(i) {
1010
+ return i.traverse((e) => {
1544
1011
  if (!(e instanceof k)) return;
1545
1012
  const t = Array.isArray(e.material) ? e.material : [e.material];
1546
1013
  for (const s of t) {
1547
1014
  if (!s) continue;
1548
1015
  let n = !1;
1549
- for (const i of Ys) {
1550
- const r = s[i];
1551
- r?.isTexture && r.image == null && (r.dispose(), s[i] = null, n = !0);
1016
+ for (const r of Gn) {
1017
+ const a = s[r];
1018
+ a?.isTexture && a.image == null && (a.dispose(), s[r] = null, n = !0);
1552
1019
  }
1553
1020
  n && (s.needsUpdate = !0);
1554
1021
  }
1555
- }), h;
1022
+ }), i;
1556
1023
  }
1557
- class D {
1024
+ class V {
1558
1025
  static CACHE_NAME = "u-space-model-loader-cache";
1559
- static fileLoader = new He().setResponseType("arraybuffer");
1560
- static dracoLoader = new ms().setDecoderPath(
1561
- `https://cdn.jsdelivr.net/npm/three@0.${Te}.0/examples/jsm/libs/draco/`
1026
+ static fileLoader = new Wt().setResponseType("arraybuffer");
1027
+ static dracoLoader = new cn().setDecoderPath(
1028
+ `https://cdn.jsdelivr.net/npm/three@0.${Qe}.0/examples/jsm/libs/draco/`
1562
1029
  );
1563
- static ktx2Loader = new fs().setTranscoderPath(
1564
- `https://cdn.jsdelivr.net/npm/three@0.${Te}.0/examples/jsm/libs/basis/`
1030
+ static ktx2Loader = new ln().setTranscoderPath(
1031
+ `https://cdn.jsdelivr.net/npm/three@0.${Qe}.0/examples/jsm/libs/basis/`
1565
1032
  );
1566
- static gltfLoader = new Qe().setDRACOLoader(D.dracoLoader).setKTX2Loader(D.ktx2Loader).setMeshoptDecoder(Ae);
1567
- static sbmxLoader = new Ls().setDRACOLoader(D.dracoLoader).setKTX2Loader(D.ktx2Loader).setMeshoptDecoder(Ae);
1568
- static sbmLoader = new Xs();
1569
- static fbxLoader = new ds();
1570
- static objLoader = new ps();
1571
- static stlLoader = new us();
1033
+ static gltfLoader = new Re().setDRACOLoader(V.dracoLoader).setKTX2Loader(V.ktx2Loader).setMeshoptDecoder(Le);
1034
+ static sbmxLoader = new at().setDRACOLoader(V.dracoLoader).setKTX2Loader(V.ktx2Loader).setMeshoptDecoder(Le);
1035
+ static sbmLoader = new ct();
1036
+ static fbxLoader = new Ze();
1037
+ static objLoader = new an();
1038
+ static stlLoader = new on();
1039
+ static decodeWorkerClient = null;
1040
+ /**
1041
+ * Routes supported static glTF/GLB/SBMX models through a dedicated decoder
1042
+ * Worker. ModelLoaderManager owns the supplied Worker and terminates it when
1043
+ * replaced or cleared. The returned disposer only clears this specific
1044
+ * Worker, so a late owner cleanup cannot terminate a newer replacement.
1045
+ */
1046
+ static setDecodeWorker(e) {
1047
+ const t = this.decodeWorkerClient;
1048
+ if (this.decodeWorkerClient = null, t?.dispose(), !e) return () => {
1049
+ };
1050
+ let s;
1051
+ return s = new $n(e, {
1052
+ onFatal: () => {
1053
+ this.decodeWorkerClient === s && (this.decodeWorkerClient = null);
1054
+ }
1055
+ }), this.decodeWorkerClient = s, () => {
1056
+ this.decodeWorkerClient === s && (this.decodeWorkerClient = null, s.dispose());
1057
+ };
1058
+ }
1059
+ static get decodeWorkerEnabled() {
1060
+ return this.decodeWorkerClient !== null && !this.decodeWorkerClient.disposed;
1061
+ }
1572
1062
  static setLoadingManager(e) {
1573
1063
  this.fileLoader.manager = e, this.dracoLoader.manager = e, this.ktx2Loader.manager = e, this.gltfLoader.manager = e, this.sbmxLoader.manager = e, this.sbmLoader.manager = e, this.fbxLoader.manager = e, this.objLoader.manager = e, this.stlLoader.manager = e;
1574
1064
  }
@@ -1591,48 +1081,124 @@ class D {
1591
1081
  this.ktx2Loader.setTranscoderPath(e);
1592
1082
  }
1593
1083
  static async loadAsync(e, t = { persistent: !0 }) {
1594
- const s = e.split(".").pop()?.split("?")[0].toLowerCase();
1595
- let n;
1596
- switch (t.persistent && typeof caches < "u" ? n = await this.getPersistentData(e) : n = await this.fileLoader.loadAsync(e), s) {
1597
- case "gltf":
1598
- case "glb":
1599
- const i = await this.gltfLoader.parseAsync(n, R.extractUrlBase(e));
1600
- return i.scene.animations = i.animations, K(i.scene);
1601
- case "sbmx":
1602
- const r = await this.sbmxLoader.parseAsync(n, R.extractUrlBase(e));
1603
- return r.scene.animations = r.animations, K(r.scene);
1604
- case "sbm":
1605
- const o = await this.sbmLoader.parseAsync(n, R.extractUrlBase(e));
1606
- return K(o);
1607
- case "fbx":
1608
- const a = this.fbxLoader.parse(n, R.extractUrlBase(e));
1609
- return K(a);
1610
- case "obj":
1611
- const c = new TextDecoder().decode(n), l = this.objLoader.parse(c);
1612
- return K(l);
1613
- case "stl":
1614
- const d = this.stlLoader.parse(n);
1615
- return new k(d, new L());
1616
- default:
1617
- throw new Error(`Unsupported model format: ${s}`);
1084
+ const s = e.split(/[?#]/, 1)[0].split(".").pop()?.toLowerCase(), n = t.persistent ?? !0, r = t.signal;
1085
+ this.throwIfAborted(r);
1086
+ const a = this.decodeWorkerClient;
1087
+ if (a?.supports(e)) {
1088
+ const h = this.fileLoader.manager.resolveURL(e), d = typeof location > "u" ? e : new URL(e, location.href).href, u = typeof location > "u" ? h : new URL(h, location.href).href;
1089
+ try {
1090
+ return await a.loadAsync(u, {
1091
+ persistent: n,
1092
+ headers: this.fileLoader.requestHeader,
1093
+ credentials: this.fileLoader.withCredentials ? "include" : "same-origin",
1094
+ resourceBaseUrl: d,
1095
+ signal: r,
1096
+ loadingManager: this.fileLoader.manager
1097
+ });
1098
+ } catch (p) {
1099
+ if (this.throwIfAborted(r), !(p instanceof Kt) && !(p instanceof ve)) throw p;
1100
+ console.info(`[ModelLoaderManager] Decode Worker fallback for ${e}: ${p.message}`);
1101
+ }
1102
+ }
1103
+ const o = await this.loadSourceBuffer(e, n, r);
1104
+ this.throwIfAborted(r);
1105
+ const c = he.extractUrlBase(e), l = this.createParseLoadingManager(r);
1106
+ try {
1107
+ switch (s) {
1108
+ case "gltf":
1109
+ case "glb": {
1110
+ const d = await this.configureGltfLoader(new Re(l.manager)).parseAsync(o, c);
1111
+ return this.throwIfAborted(r), d.scene.animations = d.animations, ce(d.scene);
1112
+ }
1113
+ case "sbmx": {
1114
+ const d = await this.configureGltfLoader(new at(l.manager)).parseAsync(o, c);
1115
+ return this.throwIfAborted(r), d.scene.animations = d.animations, ce(d.scene);
1116
+ }
1117
+ case "sbm": {
1118
+ const d = await new ct(l.manager).setCrossOrigin(this.sbmLoader.crossOrigin).setRequestHeader(this.sbmLoader.requestHeader).setWithCredentials(this.sbmLoader.withCredentials).parseAsync(o, c);
1119
+ return this.throwIfAborted(r), ce(d);
1120
+ }
1121
+ case "fbx": {
1122
+ const d = new Ze(l.manager).setCrossOrigin(this.fbxLoader.crossOrigin).setRequestHeader(this.fbxLoader.requestHeader).setWithCredentials(this.fbxLoader.withCredentials).parse(o, c);
1123
+ return this.throwIfAborted(r), ce(d);
1124
+ }
1125
+ case "obj": {
1126
+ const h = new TextDecoder().decode(o), d = this.objLoader.parse(h);
1127
+ return this.throwIfAborted(r), ce(d);
1128
+ }
1129
+ case "stl": {
1130
+ const h = this.stlLoader.parse(o);
1131
+ return this.throwIfAborted(r), new k(h, new q());
1132
+ }
1133
+ default:
1134
+ throw new Error(`Unsupported model format: ${s}`);
1135
+ }
1136
+ } finally {
1137
+ l.cleanup();
1618
1138
  }
1619
1139
  }
1620
- static async getPersistentData(e) {
1140
+ static configureGltfLoader(e) {
1141
+ return e.setDRACOLoader(this.dracoLoader).setKTX2Loader(this.ktx2Loader).setMeshoptDecoder(Le).setCrossOrigin(this.gltfLoader.crossOrigin).setRequestHeader(this.gltfLoader.requestHeader).setWithCredentials(this.gltfLoader.withCredentials), e;
1142
+ }
1143
+ static createParseLoadingManager(e) {
1144
+ this.throwIfAborted(e);
1145
+ const t = this.fileLoader.manager, s = new As();
1146
+ s.setURLModifier((r) => t.resolveURL(r)), s.itemStart = (r) => t.itemStart(r), s.itemEnd = (r) => t.itemEnd(r), s.itemError = (r) => t.itemError(r);
1147
+ const n = () => s.abort();
1148
+ return e?.addEventListener("abort", n, { once: !0 }), {
1149
+ manager: s,
1150
+ cleanup: () => e?.removeEventListener("abort", n)
1151
+ };
1152
+ }
1153
+ static async loadSourceBuffer(e, t, s) {
1154
+ this.throwIfAborted(s);
1155
+ const n = this.fileLoader.manager, r = n.resolveURL(e);
1156
+ n.itemStart(r);
1621
1157
  try {
1622
- const t = await caches.open(this.CACHE_NAME), s = await t.match(e);
1623
- if (s)
1624
- return await s.arrayBuffer();
1625
- const n = await this.fileLoader.loadAsync(e), i = new Response(n);
1626
- return await t.put(e, i), n;
1627
- } catch (t) {
1628
- return console.warn(`[LoaderManager] Failed to use Cache API for ${e}:`, t), await this.fileLoader.loadAsync(e);
1158
+ let a;
1159
+ if (t && typeof caches < "u")
1160
+ try {
1161
+ a = await caches.open(this.CACHE_NAME);
1162
+ const d = await a.match(r);
1163
+ if (this.throwIfAborted(s), d) {
1164
+ const u = await d.arrayBuffer();
1165
+ return this.throwIfAborted(s), u;
1166
+ }
1167
+ } catch (d) {
1168
+ this.throwIfAborted(s), console.warn(`[ModelLoaderManager] Failed to read Cache Storage for ${r}:`, d);
1169
+ }
1170
+ const o = n.abortController.signal, c = s && typeof AbortSignal.any == "function" ? AbortSignal.any([s, o]) : s ?? o, l = await fetch(r, {
1171
+ headers: this.fileLoader.requestHeader,
1172
+ credentials: this.fileLoader.withCredentials ? "include" : "same-origin",
1173
+ signal: c
1174
+ });
1175
+ if (!l.ok)
1176
+ throw new Error(
1177
+ `Failed to load model ${r}: ${l.status} ${l.statusText}`
1178
+ );
1179
+ const h = await l.arrayBuffer();
1180
+ if (this.throwIfAborted(s), a)
1181
+ try {
1182
+ await a.put(r, new Response(h.slice(0)));
1183
+ } catch (d) {
1184
+ this.throwIfAborted(s), console.warn(`[ModelLoaderManager] Failed to write Cache Storage for ${r}:`, d);
1185
+ }
1186
+ return h;
1187
+ } catch (a) {
1188
+ throw n.itemError(r), a;
1189
+ } finally {
1190
+ n.itemEnd(r);
1629
1191
  }
1630
1192
  }
1193
+ static throwIfAborted(e) {
1194
+ if (e?.aborted)
1195
+ throw e.reason ?? new DOMException("Aborted", "AbortError");
1196
+ }
1631
1197
  }
1632
- class Bn {
1633
- static textureLoader = new Fe();
1634
- static hdrLoader = new gs();
1635
- static cubeTextureLoader = new Ot();
1198
+ class ii {
1199
+ static textureLoader = new Ft();
1200
+ static hdrLoader = new dn();
1201
+ static cubeTextureLoader = new Os();
1636
1202
  static setLoadingManager(e) {
1637
1203
  this.textureLoader.manager = e, this.hdrLoader.manager = e, this.cubeTextureLoader.manager = e;
1638
1204
  }
@@ -1641,13 +1207,13 @@ class Bn {
1641
1207
  }
1642
1208
  static async loadAsyncHDR(e) {
1643
1209
  const t = await this.hdrLoader.loadAsync(e);
1644
- return t.mapping = At, t;
1210
+ return t.mapping = Bs, t;
1645
1211
  }
1646
1212
  static async loadAsyncCubeTexture(e, t) {
1647
1213
  return this.cubeTextureLoader.setPath(e), await this.cubeTextureLoader.loadAsync(t);
1648
1214
  }
1649
1215
  }
1650
- class G extends k {
1216
+ class X extends k {
1651
1217
  isBaseMesh = !0;
1652
1218
  type = "BaseMesh";
1653
1219
  castShadow = !0;
@@ -1660,7 +1226,7 @@ class G extends k {
1660
1226
  return this.visible === !1 && this.ignoreInvisibleWhenRaycast === !0 ? !1 : super.raycast(e, t);
1661
1227
  }
1662
1228
  }
1663
- class Ye extends I {
1229
+ class pe extends W {
1664
1230
  isBaseGroup = !0;
1665
1231
  type = "BaseGroup";
1666
1232
  ignoreInvisibleWhenRaycast = !0;
@@ -1671,7 +1237,7 @@ class Ye extends I {
1671
1237
  return this.visible === !1 && this.ignoreInvisibleWhenRaycast === !0 ? !1 : super.raycast(e, t);
1672
1238
  }
1673
1239
  }
1674
- class Vs extends Bt {
1240
+ class Kn extends _s {
1675
1241
  isBaseSprite = !0;
1676
1242
  type = "BaseSprite";
1677
1243
  ignoreInvisibleWhenRaycast = !0;
@@ -1682,7 +1248,7 @@ class Vs extends Bt {
1682
1248
  return this.visible === !1 && this.ignoreInvisibleWhenRaycast === !0 ? !1 : super.raycast(e, t);
1683
1249
  }
1684
1250
  }
1685
- class he extends Ye {
1251
+ class te extends pe {
1686
1252
  isModel = !0;
1687
1253
  type = "Model";
1688
1254
  static memoryCache = /* @__PURE__ */ new Map();
@@ -1693,24 +1259,34 @@ class he extends Ye {
1693
1259
  super();
1694
1260
  }
1695
1261
  async loadAsync(e) {
1696
- const { url: t, cache: s = !0, persistent: n = !0 } = e;
1262
+ const { url: t, cache: s = !0, persistent: n = !0, signal: r } = e;
1697
1263
  try {
1698
- let i;
1699
- s ? he.memoryCache.has(t) ? i = he.memoryCache.get(t) : (i = D.loadAsync(t, { persistent: n }), he.memoryCache.set(t, i)) : i = D.loadAsync(t, { persistent: n });
1700
- const r = await i, o = ys(r);
1701
- return this.add(o), o.animations && o.animations.length > 0 && (this.animations = o.animations, this.mixer = new Rt(o)), o;
1702
- } catch (i) {
1703
- return console.error(`[Model] Failed to load model from ${t}:`, i), null;
1264
+ let a;
1265
+ if (s && !r)
1266
+ if (te.memoryCache.has(t))
1267
+ a = te.memoryCache.get(t);
1268
+ else {
1269
+ const h = V.loadAsync(t, { persistent: n, signal: r }).catch((d) => {
1270
+ throw te.memoryCache.get(t) === h && te.memoryCache.delete(t), d;
1271
+ });
1272
+ te.memoryCache.set(t, h), a = h;
1273
+ }
1274
+ else
1275
+ a = V.loadAsync(t, { persistent: n, signal: r });
1276
+ const o = await a, c = We(o);
1277
+ return this.add(c), c.animations && c.animations.length > 0 && (this.animations = c.animations, this.mixer = new Ts(c)), c;
1278
+ } catch (a) {
1279
+ return console.error(`[Model] Failed to load model from ${t}:`, a), null;
1704
1280
  }
1705
1281
  }
1706
1282
  playAnimation(e, t = {}) {
1707
1283
  if (!this.mixer || this.animations.length === 0) return null;
1708
- const { loop: s = !0, repetitions: n = 1 / 0, timeScale: i = 1, clampWhenFinished: r = !1 } = t;
1284
+ const { loop: s = !0, repetitions: n = 1 / 0, timeScale: r = 1, clampWhenFinished: a = !1 } = t;
1709
1285
  let o;
1710
- if (e === void 0 ? o = this.animations[0] : typeof e == "number" ? o = this.animations[e] : o = this.animations.find((c) => c.name === e), !o)
1286
+ if (e === void 0 ? o = this.animations[0] : typeof e == "number" ? o = this.animations[e] : o = this.animations.find((l) => l.name === e), !o)
1711
1287
  return console.warn(`[Model] Animation not found: ${e}`), null;
1712
- let a = this.actions.get(o.name);
1713
- return a || (a = this.mixer.clipAction(o), this.actions.set(o.name, a)), a.setLoop(s ? It : Lt, n), a.clampWhenFinished = r, a.timeScale = i, a.reset().play(), a;
1288
+ let c = this.actions.get(o.name);
1289
+ return c || (c = this.mixer.clipAction(o), this.actions.set(o.name, c)), c.setLoop(s ? Ls : Ns, n), c.clampWhenFinished = a, c.timeScale = r, c.reset().play(), c;
1714
1290
  }
1715
1291
  playAllAnimations(e = {}) {
1716
1292
  return this.animations.map((t, s) => this.playAnimation(s, e)).filter((t) => t !== null);
@@ -1731,13 +1307,13 @@ class he extends Ye {
1731
1307
  * Get the axis-aligned bounding box of this model.
1732
1308
  */
1733
1309
  getBoundingBox() {
1734
- return new V().setFromObject(this);
1310
+ return new K().setFromObject(this);
1735
1311
  }
1736
1312
  /**
1737
1313
  * Get the center point of this model's bounding box.
1738
1314
  */
1739
1315
  getCenter() {
1740
- const e = new v();
1316
+ const e = new D();
1741
1317
  return this.getBoundingBox().getCenter(e), e;
1742
1318
  }
1743
1319
  /**
@@ -1752,14 +1328,14 @@ class he extends Ye {
1752
1328
  this.memoryCache.clear();
1753
1329
  }
1754
1330
  static async clearPersistentCache() {
1755
- typeof caches < "u" && await caches.delete("u-space-loader-cache");
1331
+ typeof caches < "u" && await caches.delete("u-space-model-loader-cache");
1756
1332
  }
1757
1333
  }
1758
- class Js extends G {
1334
+ class qn extends X {
1759
1335
  isSphereMesh = !0;
1760
1336
  type = "SphereMesh";
1761
1337
  constructor({ geometryParameters: e, materialParameters: t } = {}) {
1762
- super(), this.geometry = new zt(
1338
+ super(), this.geometry = new Ds(
1763
1339
  e?.radius,
1764
1340
  e?.widthSegments,
1765
1341
  e?.heightSegments,
@@ -1767,23 +1343,23 @@ class Js extends G {
1767
1343
  e?.phiLength,
1768
1344
  e?.thetaStart,
1769
1345
  e?.thetaLength
1770
- ), this.material = new L(t);
1346
+ ), this.material = new q(t);
1771
1347
  }
1772
1348
  }
1773
- class Ie extends G {
1349
+ class lt extends X {
1774
1350
  isTubeMesh = !0;
1775
1351
  type = "TubeMesh";
1776
1352
  constructor({ geometryParameters: e, materialParameters: t } = {}) {
1777
- super(), this.geometry = new Nt(
1353
+ super(), this.geometry = new Ps(
1778
1354
  e?.path,
1779
1355
  e?.tubularSegments,
1780
1356
  e?.radius,
1781
1357
  e?.radialSegments,
1782
1358
  e?.closed
1783
- ), this.material = new L(t);
1359
+ ), this.material = new q(t);
1784
1360
  }
1785
1361
  }
1786
- class Rn extends Ye {
1362
+ class ai extends pe {
1787
1363
  isTopology = !0;
1788
1364
  type = "Topology";
1789
1365
  // Visuals
@@ -1829,12 +1405,12 @@ class Rn extends Ye {
1829
1405
  * @param bidirectional If true, adds the reverse edge as well. Default true.
1830
1406
  */
1831
1407
  addEdge(e, t, s, n = !0) {
1832
- const i = this.nodes.get(e), r = this.nodes.get(t);
1833
- if (!i || !r) {
1408
+ const r = this.nodes.get(e), a = this.nodes.get(t);
1409
+ if (!r || !a) {
1834
1410
  console.error(`[Topology] Cannot add edge. One or both nodes not found: ${e}, ${t}`);
1835
1411
  return;
1836
1412
  }
1837
- const o = s ?? i.distanceTo(r);
1413
+ const o = s ?? r.distanceTo(a);
1838
1414
  this.getNeighbors(e)?.set(t, o), n && this.getNeighbors(t)?.set(e, o);
1839
1415
  }
1840
1416
  /**
@@ -1852,42 +1428,42 @@ class Rn extends Ye {
1852
1428
  getShortestPath(e, t) {
1853
1429
  if (!this.nodes.has(e) || !this.nodes.has(t))
1854
1430
  return console.warn("[Topology] Start or End node not found."), [];
1855
- const s = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set();
1856
- for (const [a] of this.nodes)
1857
- s.set(a, 1 / 0), n.set(a, null), i.add(a);
1858
- for (s.set(e, 0); i.size > 0; ) {
1859
- let a = null, c = 1 / 0;
1860
- for (const d of i) {
1861
- const p = s.get(d);
1862
- p < c && (c = p, a = d);
1431
+ const s = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
1432
+ for (const [c] of this.nodes)
1433
+ s.set(c, 1 / 0), n.set(c, null), r.add(c);
1434
+ for (s.set(e, 0); r.size > 0; ) {
1435
+ let c = null, l = 1 / 0;
1436
+ for (const d of r) {
1437
+ const u = s.get(d);
1438
+ u < l && (l = u, c = d);
1863
1439
  }
1864
- if (a === null || a === t || c === 1 / 0)
1440
+ if (c === null || c === t || l === 1 / 0)
1865
1441
  break;
1866
- i.delete(a);
1867
- const l = this.adjacencyMap?.get(a);
1868
- if (l)
1869
- for (const [d, p] of l) {
1870
- if (!i.has(d)) continue;
1871
- const u = s.get(a) + p;
1872
- u < s.get(d) && (s.set(d, u), n.set(d, a));
1442
+ r.delete(c);
1443
+ const h = this.adjacencyMap?.get(c);
1444
+ if (h)
1445
+ for (const [d, u] of h) {
1446
+ if (!r.has(d)) continue;
1447
+ const p = s.get(c) + u;
1448
+ p < s.get(d) && (s.set(d, p), n.set(d, c));
1873
1449
  }
1874
1450
  }
1875
- const r = [];
1451
+ const a = [];
1876
1452
  let o = t;
1877
1453
  if (n.get(t) === null && e !== t)
1878
1454
  return [];
1879
1455
  for (; o !== null; ) {
1880
- const a = this.nodes.get(o);
1881
- a && r.unshift(a), o = n.get(o) || null;
1456
+ const c = this.nodes.get(o);
1457
+ c && a.unshift(c), o = n.get(o) || null;
1882
1458
  }
1883
- return r;
1459
+ return a;
1884
1460
  }
1885
1461
  /**
1886
1462
  * Renders the entire topology graph structure using TubeGeometry and Spheres.
1887
1463
  */
1888
1464
  renderGraph() {
1889
- this.clearGraph(), this.graphGroup = new I();
1890
- const e = new Js({
1465
+ this.clearGraph(), this.graphGroup = new W();
1466
+ const e = new qn({
1891
1467
  geometryParameters: {
1892
1468
  radius: this.parameters.nodeRadius,
1893
1469
  widthSegments: 16,
@@ -1898,20 +1474,20 @@ class Rn extends Ye {
1898
1474
  }
1899
1475
  });
1900
1476
  this.nodes.forEach((s, n) => {
1901
- const i = e.clone();
1902
- i.position.copy(s), Object.assign(i.userData, { id: n, type: "node" }), this.graphGroup.add(i);
1477
+ const r = e.clone();
1478
+ r.position.copy(s), Object.assign(r.userData, { id: n, type: "node" }), this.graphGroup.add(r);
1903
1479
  });
1904
1480
  const t = /* @__PURE__ */ new Set();
1905
1481
  this.adjacencyMap.forEach((s, n) => {
1906
- s.forEach((i, r) => {
1907
- const o = [n, r].sort().join("-");
1482
+ s.forEach((r, a) => {
1483
+ const o = [n, a].sort().join("-");
1908
1484
  if (t.has(o)) return;
1909
1485
  t.add(o);
1910
- const a = this.nodes.get(n), c = this.nodes.get(r);
1911
- if (a && c) {
1912
- const l = new Dt(a, c), d = new Ie({
1486
+ const c = this.nodes.get(n), l = this.nodes.get(a);
1487
+ if (c && l) {
1488
+ const h = new Rs(c, l), d = new lt({
1913
1489
  geometryParameters: {
1914
- path: l,
1490
+ path: h,
1915
1491
  tubularSegments: 1,
1916
1492
  radius: this.parameters.edgeRadius,
1917
1493
  radialSegments: 8,
@@ -1921,7 +1497,7 @@ class Rn extends Ye {
1921
1497
  color: this.parameters.edgeColor
1922
1498
  }
1923
1499
  });
1924
- Object.assign(d.userData, { from: n, to: r, weight: i, type: "edge" }), this.graphGroup.add(d);
1500
+ Object.assign(d.userData, { from: n, to: a, weight: r, type: "edge" }), this.graphGroup.add(d);
1925
1501
  }
1926
1502
  });
1927
1503
  }), this.add(this.graphGroup);
@@ -1936,7 +1512,7 @@ class Rn extends Ye {
1936
1512
  */
1937
1513
  renderPath(e, t = this.parameters.pathColor) {
1938
1514
  if (e.length < 2) return;
1939
- const s = new kt(e, !1, "catmullrom", 0), n = new Ie({
1515
+ const s = new ks(e, !1, "catmullrom", 0), n = new lt({
1940
1516
  geometryParameters: {
1941
1517
  path: s,
1942
1518
  tubularSegments: e.length * 10,
@@ -1957,14 +1533,14 @@ class Rn extends Ye {
1957
1533
  /** Export nodes and edges as a JSON-serializable object. */
1958
1534
  exportData() {
1959
1535
  const e = {};
1960
- this.nodes.forEach((n, i) => {
1961
- e[i] = { x: n.x, y: n.y, z: n.z };
1536
+ this.nodes.forEach((n, r) => {
1537
+ e[r] = { x: n.x, y: n.y, z: n.z };
1962
1538
  });
1963
1539
  const t = [], s = /* @__PURE__ */ new Set();
1964
- return this.adjacencyMap.forEach((n, i) => {
1965
- n.forEach((r, o) => {
1966
- const a = [i, o].sort().join("-");
1967
- s.has(a) || (s.add(a), t.push({ from: i, to: o, weight: r }));
1540
+ return this.adjacencyMap.forEach((n, r) => {
1541
+ n.forEach((a, o) => {
1542
+ const c = [r, o].sort().join("-");
1543
+ s.has(c) || (s.add(c), t.push({ from: r, to: o, weight: a }));
1968
1544
  });
1969
1545
  }), { nodes: e, edges: t };
1970
1546
  }
@@ -1974,7 +1550,7 @@ class Rn extends Ye {
1974
1550
  */
1975
1551
  importData(e) {
1976
1552
  this.clearGraph(), this.clearPaths(), this.nodes.clear(), this.adjacencyMap.clear(), Object.entries(e.nodes).forEach(([t, s]) => {
1977
- this.addNode(t, new v(s.x, s.y, s.z));
1553
+ this.addNode(t, new D(s.x, s.y, s.z));
1978
1554
  }), e.edges.forEach(({ from: t, to: s, weight: n }) => {
1979
1555
  this.addEdge(t, s, n);
1980
1556
  }), this.renderGraph();
@@ -1986,7 +1562,7 @@ class Rn extends Ye {
1986
1562
  return this.adjacencyMap.get(e);
1987
1563
  }
1988
1564
  }
1989
- class In extends Vs {
1565
+ class oi extends Kn {
1990
1566
  isPoi = !0;
1991
1567
  type = "Poi";
1992
1568
  parameters = {
@@ -2005,7 +1581,7 @@ class In extends Vs {
2005
1581
  _canvas = document.createElement("canvas");
2006
1582
  _lastParametersJSON = "";
2007
1583
  constructor(e = {}) {
2008
- super(new jt()), Object.assign(this.parameters, e), this.updateAsync();
1584
+ super(new zs()), Object.assign(this.parameters, e), this.updateAsync();
2009
1585
  }
2010
1586
  /**
2011
1587
  * Update the POI with new parameters
@@ -2019,35 +1595,35 @@ class In extends Vs {
2019
1595
  const s = this._canvas, n = s.getContext("2d");
2020
1596
  if (!n) return;
2021
1597
  n.font = `${this.parameters.fontSize}px ${this.parameters.fontFamily}`;
2022
- let i = null;
2023
- this.parameters.img && (i = await this._loadImage(this.parameters.img));
2024
- const { text: r, fontSize: o, color: a, iconSize: c, padding: l, backgroundColor: d, borderRadius: p, textPosition: u, scaleFactor: m } = this.parameters, w = n.measureText(r), S = r ? w.width : 0, x = r ? o : 0;
2025
- let y = 0, _ = 0, A = 0, B = 0, E = 0, g = 0;
2026
- const b = !!i, z = !!r;
2027
- if (b && z)
2028
- switch (u) {
1598
+ let r = null;
1599
+ this.parameters.img && (r = await this._loadImage(this.parameters.img));
1600
+ const { text: a, fontSize: o, color: c, iconSize: l, padding: h, backgroundColor: d, borderRadius: u, textPosition: p, scaleFactor: x } = this.parameters, I = n.measureText(a), _ = a ? I.width : 0, C = a ? o : 0;
1601
+ let y = 0, w = 0, g = 0, m = 0, M = 0, b = 0;
1602
+ const S = !!r, A = !!a;
1603
+ if (S && A)
1604
+ switch (p) {
2029
1605
  case "top":
2030
- y = Math.max(c, S), _ = c + l + x, E = (y - S) / 2, g = x / 2, A = (y - c) / 2, B = x + l;
1606
+ y = Math.max(l, _), w = l + h + C, M = (y - _) / 2, b = C / 2, g = (y - l) / 2, m = C + h;
2031
1607
  break;
2032
1608
  case "bottom":
2033
- y = Math.max(c, S), _ = c + l + x, A = (y - c) / 2, B = 0, E = (y - S) / 2, g = c + l + x / 2;
1609
+ y = Math.max(l, _), w = l + h + C, g = (y - l) / 2, m = 0, M = (y - _) / 2, b = l + h + C / 2;
2034
1610
  break;
2035
1611
  case "left":
2036
- y = c + l + S, _ = Math.max(c, x), E = 0, g = _ / 2, A = S + l, B = (_ - c) / 2;
1612
+ y = l + h + _, w = Math.max(l, C), M = 0, b = w / 2, g = _ + h, m = (w - l) / 2;
2037
1613
  break;
2038
1614
  default:
2039
- y = c + l + S, _ = Math.max(c, x), A = 0, B = (_ - c) / 2, E = c + l, g = _ / 2;
1615
+ y = l + h + _, w = Math.max(l, C), g = 0, m = (w - l) / 2, M = l + h, b = w / 2;
2040
1616
  break;
2041
1617
  }
2042
- else b ? (y = c, _ = c, A = 0, B = 0) : z && (y = S, _ = x, E = 0, g = x / 2);
2043
- const N = y + l * 2, P = _ + l * 2;
2044
- if (s.width = N, s.height = P, n.font = `${o}px ${this.parameters.fontFamily}`, d && (n.fillStyle = d, this._drawRoundedRect(n, 0, 0, N, P, p), n.fill()), b && n.drawImage(i, A + l, B + l, c, c), z) {
2045
- n.fillStyle = a;
2046
- const j = n.measureText(r), U = j.actualBoundingBoxAscent + j.actualBoundingBoxDescent, ot = j.actualBoundingBoxAscent - U / 2;
2047
- n.textBaseline = "alphabetic", n.fillText(r, E + l, g + l + ot);
1618
+ else S ? (y = l, w = l, g = 0, m = 0) : A && (y = _, w = C, M = 0, b = C / 2);
1619
+ const v = y + h * 2, E = w + h * 2;
1620
+ if (s.width = v, s.height = E, n.font = `${o}px ${this.parameters.fontFamily}`, d && (n.fillStyle = d, this._drawRoundedRect(n, 0, 0, v, E, u), n.fill()), S && n.drawImage(r, g + h, m + h, l, l), A) {
1621
+ n.fillStyle = c;
1622
+ const f = n.measureText(a), L = f.actualBoundingBoxAscent + f.actualBoundingBoxDescent, O = f.actualBoundingBoxAscent - L / 2;
1623
+ n.textBaseline = "alphabetic", n.fillText(a, M + h, b + h + O);
2048
1624
  }
2049
- const J = this.material.map, W = new Ut(s);
2050
- W.colorSpace = Ge, this.material.map = W, J?.dispose(), this.scale.set(N * m, P * m, 1);
1625
+ const z = this.material.map, N = new Us(s);
1626
+ N.colorSpace = Se, this.material.map = N, z?.dispose(), this.scale.set(v * x, E * x, 1);
2051
1627
  }
2052
1628
  _loadImage(e) {
2053
1629
  return new Promise((t, s) => {
@@ -2058,169 +1634,265 @@ class In extends Vs {
2058
1634
  t(e);
2059
1635
  });
2060
1636
  }
2061
- _drawRoundedRect(e, t, s, n, i, r) {
2062
- e.beginPath(), e.moveTo(t + r, s), e.lineTo(t + n - r, s), e.quadraticCurveTo(t + n, s, t + n, s + r), e.lineTo(t + n, s + i - r), e.quadraticCurveTo(t + n, s + i, t + n - r, s + i), e.lineTo(t + r, s + i), e.quadraticCurveTo(t, s + i, t, s + i - r), e.lineTo(t, s + r), e.quadraticCurveTo(t, s, t + r, s), e.closePath();
1637
+ _drawRoundedRect(e, t, s, n, r, a) {
1638
+ e.beginPath(), e.moveTo(t + a, s), e.lineTo(t + n - a, s), e.quadraticCurveTo(t + n, s, t + n, s + a), e.lineTo(t + n, s + r - a), e.quadraticCurveTo(t + n, s + r, t + n - a, s + r), e.lineTo(t + a, s + r), e.quadraticCurveTo(t, s + r, t, s + r - a), e.lineTo(t, s + a), e.quadraticCurveTo(t, s, t + a, s), e.closePath();
2063
1639
  }
2064
1640
  dispose() {
2065
1641
  this.material.map?.dispose(), this.material.dispose();
2066
1642
  }
2067
1643
  }
2068
- class Ve extends G {
1644
+ class Xt extends X {
2069
1645
  isShapeMesh = !0;
2070
1646
  type = "ShapeMesh";
2071
1647
  constructor({ geometryParameters: e, materialParameters: t } = {}) {
2072
- super(), this.geometry = new Ht(e?.shape, e?.curveSegments), this.material = new L(t), this.geometry.rotateX(-Math.PI / 2);
1648
+ super(), this.geometry = new js(e?.shape, e?.curveSegments), this.material = new q(t), this.geometry.rotateX(-Math.PI / 2);
2073
1649
  }
2074
1650
  static createFromPoints(e, t = {}) {
2075
- return new Ve({
1651
+ return new Xt({
2076
1652
  ...t,
2077
1653
  geometryParameters: {
2078
1654
  ...t.geometryParameters,
2079
- shape: new $e(e.map((s) => new C(s.x, -s.z)))
1655
+ shape: new Gt(e.map((s) => new j(s.x, -s.z)))
2080
1656
  }
2081
1657
  });
2082
1658
  }
2083
1659
  }
2084
- class Je extends G {
1660
+ class Yt extends X {
2085
1661
  isExtrudeMesh = !0;
2086
1662
  type = "ExtrudeMesh";
2087
1663
  constructor({ geometryParameters: e, materialParameters: t } = {}) {
2088
- super(), this.geometry = new Ft(e?.shape, e?.options), this.material = new L(t), this.geometry.rotateX(-Math.PI / 2);
1664
+ super(), this.geometry = new Ws(e?.shape, e?.options), this.material = new q(t), this.geometry.rotateX(-Math.PI / 2);
2089
1665
  }
2090
1666
  static createFromPoints(e, t = {}) {
2091
- return e && e.length === 0 && (e = void 0), new Je({
1667
+ return e && e.length === 0 && (e = void 0), new Yt({
2092
1668
  ...t,
2093
1669
  geometryParameters: {
2094
1670
  ...t.geometryParameters,
2095
- shape: new $e(e?.map((s) => new C(s.x, -s.z)))
1671
+ shape: new Gt(e?.map((s) => new j(s.x, -s.z)))
2096
1672
  }
2097
1673
  });
2098
1674
  }
2099
1675
  }
2100
- class Ln extends G {
1676
+ class ci extends X {
2101
1677
  isPlaneMesh = !0;
2102
1678
  type = "PlaneMesh";
2103
1679
  constructor({ geometryParameters: e, materialParameters: t } = {}) {
2104
- super(), this.geometry = new Gt(
1680
+ super(), this.geometry = new Fs(
2105
1681
  e?.width,
2106
1682
  e?.height,
2107
1683
  e?.widthSegments,
2108
1684
  e?.heightSegments
2109
- ), this.material = new L(t);
1685
+ ), this.material = new q(t);
2110
1686
  }
2111
1687
  }
2112
- class zn extends G {
1688
+ class li extends X {
2113
1689
  isCircleMesh = !0;
2114
1690
  type = "CircleMesh";
2115
1691
  constructor({ geometryParameters: e, materialParameters: t } = {}) {
2116
1692
  super(
2117
- new $t(
1693
+ new Hs(
2118
1694
  e?.radius,
2119
1695
  e?.segments,
2120
1696
  e?.thetaStart,
2121
1697
  e?.thetaLength
2122
1698
  ),
2123
- new L(t)
1699
+ new q(t)
2124
1700
  ), this.geometry.rotateX(-Math.PI / 2);
2125
1701
  }
2126
1702
  }
2127
- class F {
1703
+ class Q {
2128
1704
  static traverseMeshes(e, t) {
2129
1705
  e.traverse((s) => {
2130
1706
  s instanceof k && t(s);
2131
1707
  });
2132
1708
  }
2133
1709
  }
2134
- class Nn {
1710
+ const Vn = 3, Xn = 1, Yn = 0, Qn = 2, Jn = 1e-3, ht = new D(), J = new D(), Zn = new $s();
1711
+ function dt(i) {
1712
+ return i.isInstanceObject === !0;
1713
+ }
1714
+ function ut(i) {
1715
+ let e = !1;
1716
+ return i.traverse((t) => {
1717
+ if (e) return;
1718
+ const s = t;
1719
+ e = s.isMesh === !0 || s.isSprite === !0;
1720
+ }), e;
1721
+ }
1722
+ function er(i) {
1723
+ let e = i;
1724
+ for (; e; ) {
1725
+ if (!e.visible) return !1;
1726
+ e = e.parent;
1727
+ }
1728
+ return !0;
1729
+ }
1730
+ function pt(i) {
1731
+ return i === void 0 || !Number.isFinite(i) || i <= 0 ? Qn : i;
1732
+ }
1733
+ class hi {
2135
1734
  static flow(e = {}) {
2136
- const { baseColor: t = 16777215, flowColor: s = 65280, speed: n = 1, scale: i = 3, intensity: r = 4 } = e, o = H(new T(t)), a = H(new T(s)), c = _e().x.mul(i).sub(oe.mul(n)), l = ae(ye(c).add(1).mul(0.5), r);
2137
- return ce(o, a, l);
1735
+ const { baseColor: t = 16777215, flowColor: s = 65280, speed: n = 1, scale: r = 3, intensity: a = 4 } = e, o = Y(new P(t)), c = Y(new P(s)), l = tt().x.mul(r).sub(we.mul(n)), h = xe(ke(l).add(1).mul(0.5), a);
1736
+ return Me(o, c, h);
2138
1737
  }
2139
1738
  static breathe(e = {}) {
2140
- const { baseColor: t = 16777215, breathColor: s = 65280, speed: n = 1, intensity: i = 2 } = e, r = H(new T(t)), o = H(new T(s)), a = ye(oe.mul(n)).add(1).mul(0.5), c = ae(a, i);
2141
- return ce(r, o, c);
1739
+ const { baseColor: t = 16777215, breathColor: s = 65280, speed: n = 1, intensity: r = 2 } = e, a = Y(new P(t)), o = Y(new P(s)), c = ke(we.mul(n)).add(1).mul(0.5), l = xe(c, r);
1740
+ return Me(a, o, l);
2142
1741
  }
2143
1742
  static fluid(e = {}) {
2144
1743
  const {
2145
1744
  baseColor: t = 16777215,
2146
1745
  flowColor: s = 255,
2147
1746
  speed: n = 1,
2148
- scale: i = 1,
2149
- intensity: r = 1,
1747
+ scale: r = 1,
1748
+ intensity: a = 1,
2150
1749
  distortion: o = 0.5
2151
- } = e, a = H(new T(t)), c = H(new T(s)), l = _e().mul(i), d = oe.mul(n), p = Ee(l.add(d), 1, 0), u = l.add(p.mul(o)), m = Ee(u, 1, 0).add(1).mul(0.5), w = ae(m, r);
2152
- return ce(a, c, w);
1750
+ } = e, c = Y(new P(t)), l = Y(new P(s)), h = tt().mul(r), d = we.mul(n), u = st(h.add(d), 1, 0), p = h.add(u.mul(o)), x = st(p, 1, 0).add(1).mul(0.5), I = xe(x, a);
1751
+ return Me(c, l, I);
1752
+ }
1753
+ static outline(e = {}) {
1754
+ let t = [...e.selectedObjects ?? []];
1755
+ const s = [], n = /* @__PURE__ */ new Map(), r = new K();
1756
+ let a = null, o = null, c = null, l = null, h = null, d = e.instanceBoundsProxy ?? !0, u = e.instanceBoundsPadding ?? 0, p = e.instanceBoundsMinSize ?? Jn, x = pt(e.downSampleRatio);
1757
+ const I = ae(e.edgeStrength ?? Vn), _ = ae(e.edgeThickness ?? Xn), C = ae(e.edgeGlow ?? Yn), y = ae(new P(e.visibleEdgeColor ?? 16777215)), w = ae(new P(e.hiddenEdgeColor ?? 5125686)), g = () => (l ??= new Gs(1, 1, 1), l), m = () => (h || (h = new Ks({ color: 16777215 }), h.colorWrite = !1, h.depthWrite = !1, h.name = "u-space.outline.instanceBoundsProxy"), h), M = (f) => {
1758
+ const { source: L, mesh: O } = f, B = L.getInstanceBoundingBox?.(r, !0);
1759
+ if (!B || B.isEmpty() || !er(L)) {
1760
+ O.visible = !1;
1761
+ return;
1762
+ }
1763
+ B.getCenter(ht), B.getSize(J);
1764
+ const U = Math.max(0, u), ie = Math.max(0, p);
1765
+ J.set(
1766
+ Math.max(J.x + U * 2, ie),
1767
+ Math.max(J.y + U * 2, ie),
1768
+ Math.max(J.z + U * 2, ie)
1769
+ ), O.visible = !0, O.layers.mask = L.layers.mask, O.matrix.compose(ht, Zn, J), O.matrixWorldNeedsUpdate = !0;
1770
+ }, b = (f) => {
1771
+ f.unsubscribe?.(), f.mesh.removeFromParent();
1772
+ }, S = (f, L) => {
1773
+ let O = n.get(f);
1774
+ if (!O) {
1775
+ const B = new k(g(), m());
1776
+ B.name = `u-space.outline.instanceBoundsProxy:${f.uuid}`, B.matrixAutoUpdate = !1, B.castShadow = !1, B.receiveShadow = !1, B.frustumCulled = !1, B.raycast = () => {
1777
+ }, B.userData.instanceObject = f, O = {
1778
+ source: f,
1779
+ mesh: B,
1780
+ unsubscribe: f.onInstanceRenderDirty?.(() => M(O)) ?? null
1781
+ }, n.set(f, O);
1782
+ }
1783
+ return O.mesh.parent !== L && (O.mesh.removeFromParent(), L.add(O.mesh)), M(O), O.mesh.visible ? O.mesh : null;
1784
+ }, A = (f, L) => {
1785
+ const O = f.getInstanceRenderObject?.();
1786
+ return O && ut(O) ? O : ut(f) ? f : d && f.getInstanceBoundingBox ? S(f, L) : null;
1787
+ }, v = (f) => {
1788
+ const L = /* @__PURE__ */ new Set(), O = /* @__PURE__ */ new Set();
1789
+ for (const B of t) {
1790
+ const U = dt(B) ? A(B, f) : B;
1791
+ U && (L.add(U), dt(B) && n.get(B)?.mesh === U && O.add(B));
1792
+ }
1793
+ n.forEach((B, U) => {
1794
+ O.has(U) || (b(B), n.delete(U));
1795
+ }), s.length = 0, L.forEach((B) => s.push(B));
1796
+ }, E = () => {
1797
+ a?.dispose(), a = null;
1798
+ }, z = (f, L) => {
1799
+ if (a && o === f && c === L)
1800
+ return a.downSampleRatio = x, a;
1801
+ E(), o = f, c = L, a = wn(f, L, {
1802
+ selectedObjects: s,
1803
+ edgeThickness: _,
1804
+ edgeGlow: C,
1805
+ downSampleRatio: x
1806
+ });
1807
+ const O = a.updateBefore.bind(a);
1808
+ return a.updateBefore = (B) => (v(f), O(B)), a;
1809
+ }, N = ((f, L) => {
1810
+ const O = f.scene, B = f.camera;
1811
+ v(O);
1812
+ const U = z(O, B), ie = U.visibleEdge.mul(y).add(U.hiddenEdge.mul(w)).mul(I);
1813
+ return un(L, pn(ie, 0));
1814
+ });
1815
+ return Object.defineProperties(N, {
1816
+ outlineNode: {
1817
+ get: () => a
1818
+ },
1819
+ selectedObjects: {
1820
+ get: () => t
1821
+ }
1822
+ }), N.setSelectedObjects = (f) => (t = [...f], o && v(o), N), N.update = (f) => (f.edgeStrength !== void 0 && (I.value = f.edgeStrength), f.edgeThickness !== void 0 && (_.value = f.edgeThickness), f.edgeGlow !== void 0 && (C.value = f.edgeGlow), f.visibleEdgeColor !== void 0 && y.value.set(f.visibleEdgeColor), f.hiddenEdgeColor !== void 0 && w.value.set(f.hiddenEdgeColor), f.instanceBoundsProxy !== void 0 && (d = f.instanceBoundsProxy), f.instanceBoundsPadding !== void 0 && (u = f.instanceBoundsPadding), f.instanceBoundsMinSize !== void 0 && (p = f.instanceBoundsMinSize), f.downSampleRatio !== void 0 && (x = pt(f.downSampleRatio), a && (a.downSampleRatio = x)), o && v(o), N), N.dispose = () => {
1823
+ E(), n.forEach(b), n.clear(), l?.dispose(), h?.dispose(), l = null, h = null, t = [], s.length = 0, o = null, c = null;
1824
+ }, N;
2153
1825
  }
2154
1826
  }
2155
- function Dn(h) {
1827
+ function di(i) {
2156
1828
  }
2157
- const $ = "uSpaceHighlight", Y = `${$}/enabled`, Ze = `${$}/opacity`, et = `${$}/color`, tt = `${$}/overwrite`, st = `${$}/multiplyOpacity`, de = `${$}/instancedOriginalOpacity`, me = "uSpaceBreathe", pe = `${me}/enabled`, nt = `${me}/color`, it = `${me}/speed`, rt = `${me}/intensity`, ue = /* @__PURE__ */ new WeakMap(), Zs = We(() => {
2158
- const h = O(Y, "uint"), e = O(et, "uint"), t = O(tt, "uint"), s = Ne(e), n = Pe.mul(s), i = q(t.greaterThan(0), s, n), r = q(h.greaterThan(0), i, Pe), o = O(pe, "uint"), a = O(nt, "uint"), c = O(it, "float"), l = O(rt, "float"), d = Ne(a), p = ye(oe.mul(c)).add(1).mul(0.5), u = ae(p, l), m = ce(r, d, u);
2159
- return q(o.greaterThan(0), m, r);
2160
- })(), en = We(() => {
2161
- const h = O(Y, "uint"), e = O(Ze, "float"), t = O(st, "uint"), s = q(t.greaterThan(0), Oe.mul(e), e);
2162
- return q(h.greaterThan(0), s, Oe);
1829
+ const re = "uSpaceHighlight", ue = `${re}/enabled`, Qt = `${re}/opacity`, Jt = `${re}/color`, Zt = `${re}/overwrite`, es = `${re}/multiplyOpacity`, Ae = `${re}/instancedOriginalOpacity`, _e = "uSpaceBreathe", Oe = `${_e}/enabled`, ts = `${_e}/color`, ss = `${_e}/speed`, ns = `${_e}/intensity`, Be = /* @__PURE__ */ new WeakMap(), tr = qt(() => {
1830
+ const i = F(ue, "uint"), e = F(Jt, "uint"), t = F(Zt, "uint"), s = gt(e), n = Ce.mul(s), r = $(t.greaterThan(0), s, n), a = $(i.greaterThan(0), r, Ce), o = F(Oe, "uint"), c = F(ts, "uint"), l = F(ss, "float"), h = F(ns, "float"), d = gt(c), u = ke(we.mul(l)).add(1).mul(0.5), p = xe(u, h), x = Me(a, d, p);
1831
+ return $(o.greaterThan(0), x, a);
1832
+ })(), sr = qt(() => {
1833
+ const i = F(ue, "uint"), e = F(Qt, "float"), t = F(es, "uint"), s = $(t.greaterThan(0), ze.mul(e), e);
1834
+ return $(i.greaterThan(0), s, ze);
2163
1835
  })();
2164
- function X(h) {
2165
- return Array.isArray(h.material) ? h.material : [h.material];
1836
+ function de(i) {
1837
+ return Array.isArray(i.material) ? i.material : [i.material];
2166
1838
  }
2167
- function Le(h) {
2168
- X(h).forEach((t) => {
1839
+ function ft(i) {
1840
+ de(i).forEach((t) => {
2169
1841
  if (!t) return;
2170
- let s = ue.get(t);
1842
+ let s = Be.get(t);
2171
1843
  s || (s = {
2172
1844
  colorNode: t.colorNode,
2173
1845
  opacityNode: t.opacityNode,
2174
1846
  transparent: t.transparent,
2175
1847
  depthWrite: t.depthWrite,
2176
1848
  activeMeshes: /* @__PURE__ */ new Set()
2177
- }, ue.set(t, s)), s.activeMeshes.add(h), t.transparent = !0, t.colorNode = Zs, t.opacityNode = en, t.needsUpdate = !0;
1849
+ }, Be.set(t, s)), s.activeMeshes.add(i), t.transparent = !0, t.colorNode = tr, t.opacityNode = sr, t.needsUpdate = !0;
2178
1850
  });
2179
1851
  }
2180
- function ze(h) {
2181
- const e = h.userData[Y], t = h.userData[pe];
1852
+ function mt(i) {
1853
+ const e = i.userData[ue], t = i.userData[Oe];
2182
1854
  if (e || t) return;
2183
- X(h).forEach((n) => {
1855
+ de(i).forEach((n) => {
2184
1856
  if (!n) return;
2185
- const i = ue.get(n);
2186
- i && (i.activeMeshes.delete(h), !(i.activeMeshes.size > 0) && (n.colorNode = i.colorNode, n.opacityNode = i.opacityNode, n.transparent = i.transparent, n.depthWrite = i.depthWrite, n.needsUpdate = !0, ue.delete(n)));
1857
+ const r = Be.get(n);
1858
+ r && (r.activeMeshes.delete(i), !(r.activeMeshes.size > 0) && (n.colorNode = r.colorNode, n.opacityNode = r.opacityNode, n.transparent = r.transparent, n.depthWrite = r.depthWrite, n.needsUpdate = !0, Be.delete(n)));
2187
1859
  });
2188
1860
  }
2189
- function tn(h, e, t, s) {
2190
- const n = h, i = n.setSemanticHighlight;
2191
- if (i)
2192
- return i.call(h, e, t, s), !0;
2193
- const r = n.setSemanticColor, o = n.setSemanticOpacity, a = n.getSemanticOpacity, c = n.getSemanticColor, l = n.hasSemanticColor;
2194
- return !r || !o ? !1 : (h.userData[de] === void 0 && (h.userData[de] = {
2195
- hasColor: l?.call(h) ?? !1,
2196
- color: c?.call(h, new T()).getHex() ?? 16777215,
2197
- opacity: a?.call(h) ?? 1
2198
- }), r.call(h, e), o.call(h, t), !0);
2199
- }
2200
- function sn(h) {
2201
- const e = h, t = e.clearSemanticHighlight;
1861
+ function nr(i, e, t, s) {
1862
+ const n = i, r = n.setInstanceHighlight;
1863
+ if (r)
1864
+ return r.call(i, e, t, s), !0;
1865
+ const a = n.setInstanceColor, o = n.setInstanceOpacity, c = n.getInstanceOpacity, l = n.getInstanceColor, h = n.hasInstanceColor;
1866
+ return !a || !o ? !1 : (i.userData[Ae] === void 0 && (i.userData[Ae] = {
1867
+ hasColor: h?.call(i) ?? !1,
1868
+ color: l?.call(i, new P()).getHex() ?? 16777215,
1869
+ opacity: c?.call(i) ?? 1
1870
+ }), a.call(i, e), o.call(i, t), !0);
1871
+ }
1872
+ function rr(i) {
1873
+ const e = i, t = e.clearInstanceHighlight;
2202
1874
  if (t)
2203
- return t.call(h), !0;
2204
- const s = e.resetSemanticColor, n = e.setSemanticColor, i = e.setSemanticOpacity;
2205
- if (!s || !i) return !1;
2206
- const r = h.userData[de];
2207
- return r && (r.hasColor && n ? n.call(h, r.color) : s.call(h), i.call(h, r.opacity), Reflect.deleteProperty(h.userData, de)), !0;
1875
+ return t.call(i), !0;
1876
+ const s = e.resetInstanceColor, n = e.setInstanceColor, r = e.setInstanceOpacity;
1877
+ if (!s || !r) return !1;
1878
+ const a = i.userData[Ae];
1879
+ return a && (a.hasColor && n ? n.call(i, a.color) : s.call(i), r.call(i, a.opacity), Reflect.deleteProperty(i.userData, Ae)), !0;
2208
1880
  }
2209
- class le {
1881
+ class se {
2210
1882
  static highlightColor(e, t = {}) {
2211
- const s = Array.isArray(e) ? e : [e], { opacity: n = 0.5, color: i = 16711680, overwrite: r = !1, depthWrite: o, multiplyOpacity: a = !1 } = t, c = new T(i).getHex();
2212
- for (const l of s)
2213
- tn(l, i, n, r) || F.traverseMeshes(l, (d) => {
2214
- d.userData[Y] = 1, d.userData[Ze] = n, d.userData[et] = c, d.userData[tt] = r ? 1 : 0, d.userData[st] = a ? 1 : 0, Le(d), o !== void 0 && X(d).forEach((u) => {
2215
- u && (u.depthWrite = o);
1883
+ const s = Array.isArray(e) ? e : [e], { opacity: n = 0.5, color: r = 16711680, overwrite: a = !1, depthWrite: o, multiplyOpacity: c = !1 } = t, l = new P(r).getHex();
1884
+ for (const h of s)
1885
+ nr(h, r, n, a) || Q.traverseMeshes(h, (d) => {
1886
+ d.userData[ue] = 1, d.userData[Qt] = n, d.userData[Jt] = l, d.userData[Zt] = a ? 1 : 0, d.userData[es] = c ? 1 : 0, ft(d), o !== void 0 && de(d).forEach((p) => {
1887
+ p && (p.depthWrite = o);
2216
1888
  });
2217
1889
  });
2218
1890
  }
2219
1891
  static removeHighlightColor(e) {
2220
1892
  const t = Array.isArray(e) ? e : [e];
2221
1893
  for (const s of t)
2222
- sn(s) || F.traverseMeshes(s, (n) => {
2223
- n.userData[Y] = 0, ze(n);
1894
+ rr(s) || Q.traverseMeshes(s, (n) => {
1895
+ n.userData[ue] = 0, mt(n);
2224
1896
  });
2225
1897
  }
2226
1898
  static breatheColor(e, t = {}) {
@@ -2232,17 +1904,17 @@ class le {
2232
1904
  },
2233
1905
  t
2234
1906
  );
2235
- n.color = new T(n.color).getHex();
2236
- for (const i of s)
2237
- F.traverseMeshes(i, (r) => {
2238
- r.userData[pe] = 1, r.userData[nt] = n.color, r.userData[it] = n.speed, r.userData[rt] = n.intensity, Le(r);
1907
+ n.color = new P(n.color).getHex();
1908
+ for (const r of s)
1909
+ Q.traverseMeshes(r, (a) => {
1910
+ a.userData[Oe] = 1, a.userData[ts] = n.color, a.userData[ss] = n.speed, a.userData[ns] = n.intensity, ft(a);
2239
1911
  });
2240
1912
  }
2241
1913
  static removeBreatheColor(e) {
2242
1914
  const t = Array.isArray(e) ? e : [e];
2243
1915
  for (const s of t)
2244
- F.traverseMeshes(s, (n) => {
2245
- n.userData[pe] = 0, ze(n);
1916
+ Q.traverseMeshes(s, (n) => {
1917
+ n.userData[Oe] = 0, mt(n);
2246
1918
  });
2247
1919
  }
2248
1920
  /**
@@ -2251,10 +1923,10 @@ class le {
2251
1923
  static wireframe(e, t = !0) {
2252
1924
  const s = Array.isArray(e) ? e : [e];
2253
1925
  for (const n of s)
2254
- F.traverseMeshes(n, (i) => {
2255
- X(i).forEach((r) => {
2256
- if (!r) return;
2257
- const o = r;
1926
+ Q.traverseMeshes(n, (r) => {
1927
+ de(r).forEach((a) => {
1928
+ if (!a) return;
1929
+ const o = a;
2258
1930
  o.wireframe = t, o.needsUpdate = !0;
2259
1931
  });
2260
1932
  });
@@ -2263,7 +1935,7 @@ class le {
2263
1935
  * Remove wireframe mode.
2264
1936
  */
2265
1937
  static removeWireframe(e) {
2266
- le.wireframe(e, !1);
1938
+ se.wireframe(e, !1);
2267
1939
  }
2268
1940
  /**
2269
1941
  * Fade in object(s) from fully transparent to original opacity.
@@ -2271,7 +1943,7 @@ class le {
2271
1943
  */
2272
1944
  static fadeIn(e, t = {}) {
2273
1945
  const { duration: s = 500 } = t;
2274
- return le._fade(e, 0, 1, s);
1946
+ return se._fade(e, 0, 1, s);
2275
1947
  }
2276
1948
  /**
2277
1949
  * Fade out object(s) to fully transparent.
@@ -2279,61 +1951,62 @@ class le {
2279
1951
  */
2280
1952
  static fadeOut(e, t = {}) {
2281
1953
  const { duration: s = 500 } = t;
2282
- return le._fade(e, 1, 0, s);
1954
+ return se._fade(e, 1, 0, s);
2283
1955
  }
2284
1956
  static _fade(e, t, s, n) {
2285
- const i = Array.isArray(e) ? e : [e], r = /* @__PURE__ */ new Map();
2286
- for (const o of i)
2287
- F.traverseMeshes(o, (a) => {
2288
- X(a).forEach((c) => {
2289
- if (!c || r.has(c)) return;
2290
- const l = c.opacity, d = c.transparent, p = s >= 1 ? l : s;
2291
- r.set(c, {
2292
- material: c,
2293
- targetOpacity: p,
2294
- originalOpacity: l,
1957
+ const r = Array.isArray(e) ? e : [e], a = /* @__PURE__ */ new Map();
1958
+ for (const o of r)
1959
+ Q.traverseMeshes(o, (c) => {
1960
+ de(c).forEach((l) => {
1961
+ if (!l || a.has(l)) return;
1962
+ const h = l.opacity, d = l.transparent, u = s >= 1 ? h : s;
1963
+ a.set(l, {
1964
+ material: l,
1965
+ targetOpacity: u,
1966
+ originalOpacity: h,
2295
1967
  originalTransparent: d
2296
- }), c.transparent = !0, c.opacity = t, c.needsUpdate = !0;
1968
+ }), l.transparent = !0, l.opacity = t, l.needsUpdate = !0;
2297
1969
  });
2298
1970
  });
2299
- return r.size === 0 ? Promise.resolve() : new Promise((o) => {
2300
- const a = performance.now();
2301
- let c = 0;
2302
- const l = () => {
2303
- const d = performance.now() - a, p = Math.min(d / n, 1);
2304
- if (!i[0].parent) {
2305
- cancelAnimationFrame(c), o();
1971
+ return a.size === 0 ? Promise.resolve() : new Promise((o) => {
1972
+ const c = performance.now();
1973
+ let l = 0;
1974
+ const h = () => {
1975
+ const d = performance.now() - c, u = Math.min(d / n, 1);
1976
+ if (!r[0].parent) {
1977
+ cancelAnimationFrame(l), o();
2306
1978
  return;
2307
1979
  }
2308
- for (const { material: m, targetOpacity: w } of r.values())
2309
- m.opacity = t + (w - t) * p, m.needsUpdate = !0;
2310
- if (p < 1)
2311
- c = requestAnimationFrame(l);
1980
+ for (const { material: x, targetOpacity: I } of a.values())
1981
+ x.opacity = t + (I - t) * u, x.needsUpdate = !0;
1982
+ if (u < 1)
1983
+ l = requestAnimationFrame(h);
2312
1984
  else {
2313
1985
  if (s >= 1)
2314
- for (const { material: m, originalOpacity: w, originalTransparent: S } of r.values())
2315
- m.opacity = w, m.transparent = S, m.needsUpdate = !0;
1986
+ for (const { material: x, originalOpacity: I, originalTransparent: _ } of a.values())
1987
+ x.opacity = I, x.transparent = _, x.needsUpdate = !0;
2316
1988
  o();
2317
1989
  }
2318
1990
  };
2319
- c = requestAnimationFrame(l);
1991
+ l = requestAnimationFrame(h);
2320
1992
  });
2321
1993
  }
2322
1994
  }
2323
- const Ne = (h) => {
2324
- const e = h.shiftRight(16).bitAnd(255).toFloat().div(255), t = h.shiftRight(8).bitAnd(255).toFloat().div(255), s = h.bitAnd(255).toFloat().div(255);
2325
- return es(e, t, s);
1995
+ const gt = (i) => {
1996
+ const e = i.shiftRight(16).bitAnd(255).toFloat().div(255), t = i.shiftRight(8).bitAnd(255).toFloat().div(255), s = i.bitAnd(255).toFloat().div(255);
1997
+ return fn(e, t, s);
2326
1998
  };
2327
- class nn extends ws {
1999
+ class ir extends xn {
2328
2000
  viewer;
2329
2001
  constructor(e, t) {
2330
2002
  super(t), this.viewer = e;
2331
2003
  }
2332
2004
  _update = ({ time: e }) => {
2333
- this.update(e) && this.viewer.render();
2005
+ const t = this.update(e);
2006
+ this.viewer.invalidate(), t || this.viewer.removeEventListener("afterControlsUpdate", this._update);
2334
2007
  };
2335
2008
  easingByMode(e) {
2336
- const t = rn[e];
2009
+ const t = ar[e];
2337
2010
  return super.easing(t);
2338
2011
  }
2339
2012
  start(e, t) {
@@ -2343,54 +2016,54 @@ class nn extends ws {
2343
2016
  return this.viewer.removeEventListener("afterControlsUpdate", this._update), super.stop();
2344
2017
  }
2345
2018
  }
2346
- function kn(h, e, t, s = {}, n, i) {
2347
- return new Promise((r, o) => {
2348
- const { duration: a = 1e3, delay: c = 0, repeat: l = !1, mode: d = "Linear.None", yoyo: p = !1 } = s, u = new nn(h, e).to(t, a).easingByMode(d).delay(c).onUpdate((m) => {
2349
- n?.(m, u);
2019
+ function ui(i, e, t, s = {}, n, r) {
2020
+ return new Promise((a, o) => {
2021
+ const { duration: c = 1e3, delay: l = 0, repeat: h = !1, mode: d = "Linear.None", yoyo: u = !1 } = s, p = new ir(i, e).to(t, c).easingByMode(d).delay(l).onUpdate((x) => {
2022
+ n?.(x, p);
2350
2023
  }).onComplete(() => {
2351
- r();
2024
+ a();
2352
2025
  }).onStop(() => {
2353
2026
  o("animation stop");
2354
2027
  }).onStart(() => {
2355
- i?.(u);
2028
+ r?.(p);
2356
2029
  });
2357
- typeof l == "number" ? u.repeat(l) : typeof l == "boolean" && l && u.repeat(1 / 0), p && u.repeatDelay(20), u.yoyo(p), u.start();
2030
+ typeof h == "number" ? p.repeat(h) : typeof h == "boolean" && h && p.repeat(1 / 0), u && p.repeatDelay(20), p.yoyo(u), p.start();
2358
2031
  });
2359
2032
  }
2360
- const rn = {
2361
- "Linear.None": f.Linear.None,
2362
- "Quadratic.In": f.Quadratic.In,
2363
- "Quadratic.Out": f.Quadratic.Out,
2364
- "Quadratic.InOut": f.Quadratic.InOut,
2365
- "Cubic.In": f.Cubic.In,
2366
- "Cubic.Out": f.Cubic.Out,
2367
- "Cubic.InOut": f.Cubic.InOut,
2368
- "Quartic.In": f.Quartic.In,
2369
- "Quartic.Out": f.Quartic.Out,
2370
- "Quartic.InOut": f.Quartic.InOut,
2371
- "Quintic.In": f.Quintic.In,
2372
- "Quintic.Out": f.Quintic.Out,
2373
- "Quintic.InOut": f.Quintic.InOut,
2374
- "Sinusoidal.In": f.Sinusoidal.In,
2375
- "Sinusoidal.Out": f.Sinusoidal.Out,
2376
- "Sinusoidal.InOut": f.Sinusoidal.InOut,
2377
- "Exponential.In": f.Exponential.In,
2378
- "Exponential.Out": f.Exponential.Out,
2379
- "Exponential.InOut": f.Exponential.InOut,
2380
- "Circular.In": f.Circular.In,
2381
- "Circular.Out": f.Circular.Out,
2382
- "Circular.InOut": f.Circular.InOut,
2383
- "Elastic.In": f.Elastic.In,
2384
- "Elastic.Out": f.Elastic.Out,
2385
- "Elastic.InOut": f.Elastic.InOut,
2386
- "Back.In": f.Back.In,
2387
- "Back.Out": f.Back.Out,
2388
- "Back.InOut": f.Back.InOut,
2389
- "Bounce.In": f.Bounce.In,
2390
- "Bounce.Out": f.Bounce.Out,
2391
- "Bounce.InOut": f.Bounce.InOut
2033
+ const ar = {
2034
+ "Linear.None": T.Linear.None,
2035
+ "Quadratic.In": T.Quadratic.In,
2036
+ "Quadratic.Out": T.Quadratic.Out,
2037
+ "Quadratic.InOut": T.Quadratic.InOut,
2038
+ "Cubic.In": T.Cubic.In,
2039
+ "Cubic.Out": T.Cubic.Out,
2040
+ "Cubic.InOut": T.Cubic.InOut,
2041
+ "Quartic.In": T.Quartic.In,
2042
+ "Quartic.Out": T.Quartic.Out,
2043
+ "Quartic.InOut": T.Quartic.InOut,
2044
+ "Quintic.In": T.Quintic.In,
2045
+ "Quintic.Out": T.Quintic.Out,
2046
+ "Quintic.InOut": T.Quintic.InOut,
2047
+ "Sinusoidal.In": T.Sinusoidal.In,
2048
+ "Sinusoidal.Out": T.Sinusoidal.Out,
2049
+ "Sinusoidal.InOut": T.Sinusoidal.InOut,
2050
+ "Exponential.In": T.Exponential.In,
2051
+ "Exponential.Out": T.Exponential.Out,
2052
+ "Exponential.InOut": T.Exponential.InOut,
2053
+ "Circular.In": T.Circular.In,
2054
+ "Circular.Out": T.Circular.Out,
2055
+ "Circular.InOut": T.Circular.InOut,
2056
+ "Elastic.In": T.Elastic.In,
2057
+ "Elastic.Out": T.Elastic.Out,
2058
+ "Elastic.InOut": T.Elastic.InOut,
2059
+ "Back.In": T.Back.In,
2060
+ "Back.Out": T.Back.Out,
2061
+ "Back.InOut": T.Back.InOut,
2062
+ "Bounce.In": T.Bounce.In,
2063
+ "Bounce.Out": T.Bounce.Out,
2064
+ "Bounce.InOut": T.Bounce.InOut
2392
2065
  };
2393
- class jn {
2066
+ class pi {
2394
2067
  scene;
2395
2068
  planes = /* @__PURE__ */ new Map();
2396
2069
  helpers = /* @__PURE__ */ new Map();
@@ -2399,7 +2072,7 @@ class jn {
2399
2072
  */
2400
2073
  group;
2401
2074
  constructor(e) {
2402
- this.scene = e, this.group = new Wt(), this.group.name = "__clippingToolGroup", this.scene.add(this.group);
2075
+ this.scene = e, this.group = new qs(), this.group.name = "__clippingToolGroup", this.scene.add(this.group);
2403
2076
  }
2404
2077
  /**
2405
2078
  * Move all current scene children (except the clipping group itself) into the ClippingGroup,
@@ -2437,37 +2110,37 @@ class jn {
2437
2110
  const {
2438
2111
  normal: s = { x: 0, y: -1, z: 0 },
2439
2112
  constant: n = 0,
2440
- showHelper: i = !1,
2441
- helperSize: r = 5,
2113
+ showHelper: r = !1,
2114
+ helperSize: a = 5,
2442
2115
  helperColor: o = 16711680
2443
- } = t, a = new Kt(new v(s.x, s.y, s.z), n);
2444
- return this.planes.set(e, a), this._syncPlanes(), i && this.showHelper(e, r, o), a;
2116
+ } = t, c = new Vs(new D(s.x, s.y, s.z), n);
2117
+ return this.planes.set(e, c), this._syncPlanes(), r && this.showHelper(e, a, o), c;
2445
2118
  }
2446
2119
  /**
2447
2120
  * Add six clipping planes that form a box around a Box3.
2448
2121
  * Returns the six plane ids: `${id}_+x`, `${id}_-x`, etc.
2449
2122
  */
2450
2123
  addBox(e, t, s = {}) {
2451
- const { showHelpers: n = !1, helperColor: i = 16711680 } = s, r = t.min, o = t.max, a = [
2124
+ const { showHelpers: n = !1, helperColor: r = 16711680 } = s, a = t.min, o = t.max, c = [
2452
2125
  { suffix: "+x", normal: { x: -1, y: 0, z: 0 }, constant: o.x },
2453
- { suffix: "-x", normal: { x: 1, y: 0, z: 0 }, constant: -r.x },
2126
+ { suffix: "-x", normal: { x: 1, y: 0, z: 0 }, constant: -a.x },
2454
2127
  { suffix: "+y", normal: { x: 0, y: -1, z: 0 }, constant: o.y },
2455
- { suffix: "-y", normal: { x: 0, y: 1, z: 0 }, constant: -r.y },
2128
+ { suffix: "-y", normal: { x: 0, y: 1, z: 0 }, constant: -a.y },
2456
2129
  { suffix: "+z", normal: { x: 0, y: 0, z: -1 }, constant: o.z },
2457
- { suffix: "-z", normal: { x: 0, y: 0, z: 1 }, constant: -r.z }
2458
- ], c = [];
2459
- for (const l of a) {
2460
- const d = `${e}_${l.suffix}`;
2461
- this.addPlane(d, { normal: l.normal, constant: l.constant, showHelper: n, helperColor: i }), c.push(d);
2130
+ { suffix: "-z", normal: { x: 0, y: 0, z: 1 }, constant: -a.z }
2131
+ ], l = [];
2132
+ for (const h of c) {
2133
+ const d = `${e}_${h.suffix}`;
2134
+ this.addPlane(d, { normal: h.normal, constant: h.constant, showHelper: n, helperColor: r }), l.push(d);
2462
2135
  }
2463
- return c;
2136
+ return l;
2464
2137
  }
2465
2138
  /**
2466
2139
  * Add a clipping box from an object's bounding box with optional padding.
2467
2140
  */
2468
2141
  addBoxFromObject(e, t, s = 0, n = {}) {
2469
- const i = new V().setFromObject(t);
2470
- return i.expandByScalar(s), this.addBox(e, i, n);
2142
+ const r = new K().setFromObject(t);
2143
+ return r.expandByScalar(s), this.addBox(e, r, n);
2471
2144
  }
2472
2145
  /**
2473
2146
  * Update a plane's constant (distance from origin).
@@ -2506,8 +2179,8 @@ class jn {
2506
2179
  this.hideHelper(e);
2507
2180
  const n = this.planes.get(e);
2508
2181
  if (!n) return;
2509
- const i = new Qt(n, t, new T(s).getHex());
2510
- i.name = e, this.helpers.set(e, i), this.scene.add(i);
2182
+ const r = new Xs(n, t, new P(s).getHex());
2183
+ r.name = e, this.helpers.set(e, r), this.scene.add(r);
2511
2184
  }
2512
2185
  /**
2513
2186
  * Hide a plane helper.
@@ -2532,7 +2205,7 @@ class jn {
2532
2205
  this.detach(), this.removeAll(), this.scene.remove(this.group);
2533
2206
  }
2534
2207
  }
2535
- class Un {
2208
+ class fi {
2536
2209
  scene;
2537
2210
  measurements = /* @__PURE__ */ new Map();
2538
2211
  _idCounter = 0;
@@ -2543,19 +2216,19 @@ class Un {
2543
2216
  * Measure distance between two points.
2544
2217
  */
2545
2218
  measureDistance(e, t, s = {}) {
2546
- const { lineColor: n = 16776960 } = s, i = new v(e.x, e.y, e.z), r = new v(t.x, t.y, t.z), o = i.distanceTo(r), a = `measure_dist_${this._idCounter++}`, c = new I();
2547
- c.name = a;
2548
- const l = new Q().setFromPoints([i, r]), d = new ie({ color: n }), p = new re(l, d);
2549
- c.add(p), this.scene.add(c);
2550
- const u = {
2551
- id: a,
2219
+ const { lineColor: n = 16776960 } = s, r = new D(e.x, e.y, e.z), a = new D(t.x, t.y, t.z), o = r.distanceTo(a), c = `measure_dist_${this._idCounter++}`, l = new W();
2220
+ l.name = c;
2221
+ const h = new G().setFromPoints([r, a]), d = new ye({ color: n }), u = new be(h, d);
2222
+ l.add(u), this.scene.add(l);
2223
+ const p = {
2224
+ id: c,
2552
2225
  type: "distance",
2553
2226
  value: o,
2554
2227
  unit: "m",
2555
- points: [i, r],
2556
- object: c
2228
+ points: [r, a],
2229
+ object: l
2557
2230
  };
2558
- return this.measurements.set(a, u), u;
2231
+ return this.measurements.set(c, p), p;
2559
2232
  }
2560
2233
  /**
2561
2234
  * Measure the area of a polygon defined by 3+ coplanar points.
@@ -2564,37 +2237,37 @@ class Un {
2564
2237
  const { lineColor: s = 65280 } = t;
2565
2238
  if (e.length < 3)
2566
2239
  throw new Error("MeasureTool.measureArea requires at least 3 points");
2567
- const n = e.map((u) => new v(u.x, u.y, u.z)), i = this._calculatePolygonArea(n), r = `measure_area_${this._idCounter++}`, o = new I();
2568
- o.name = r;
2569
- const a = [...n, n[0]], c = new Q().setFromPoints(a), l = new ie({ color: s }), d = new re(c, l);
2240
+ const n = e.map((p) => new D(p.x, p.y, p.z)), r = this._calculatePolygonArea(n), a = `measure_area_${this._idCounter++}`, o = new W();
2241
+ o.name = a;
2242
+ const c = [...n, n[0]], l = new G().setFromPoints(c), h = new ye({ color: s }), d = new be(l, h);
2570
2243
  o.add(d), this.scene.add(o);
2571
- const p = {
2572
- id: r,
2244
+ const u = {
2245
+ id: a,
2573
2246
  type: "area",
2574
- value: i,
2247
+ value: r,
2575
2248
  unit: "m²",
2576
2249
  points: n,
2577
2250
  object: o
2578
2251
  };
2579
- return this.measurements.set(r, p), p;
2252
+ return this.measurements.set(a, u), u;
2580
2253
  }
2581
2254
  /**
2582
2255
  * Measure the angle between three points (vertex at the middle point).
2583
2256
  */
2584
2257
  measureAngle(e, t, s, n = {}) {
2585
- const { lineColor: i = 16746496 } = n, r = new v(e.x, e.y, e.z), o = new v(t.x, t.y, t.z), a = new v(s.x, s.y, s.z), c = r.clone().sub(o).normalize(), l = a.clone().sub(o).normalize(), p = Math.acos(Math.max(-1, Math.min(1, c.dot(l)))) * 180 / Math.PI, u = `measure_angle_${this._idCounter++}`, m = new I();
2586
- m.name = u;
2587
- const w = new Q().setFromPoints([r, o, a]), S = new ie({ color: i }), x = new re(w, S);
2588
- m.add(x), this.scene.add(m);
2258
+ const { lineColor: r = 16746496 } = n, a = new D(e.x, e.y, e.z), o = new D(t.x, t.y, t.z), c = new D(s.x, s.y, s.z), l = a.clone().sub(o).normalize(), h = c.clone().sub(o).normalize(), u = Math.acos(Math.max(-1, Math.min(1, l.dot(h)))) * 180 / Math.PI, p = `measure_angle_${this._idCounter++}`, x = new W();
2259
+ x.name = p;
2260
+ const I = new G().setFromPoints([a, o, c]), _ = new ye({ color: r }), C = new be(I, _);
2261
+ x.add(C), this.scene.add(x);
2589
2262
  const y = {
2590
- id: u,
2263
+ id: p,
2591
2264
  type: "angle",
2592
- value: p,
2265
+ value: u,
2593
2266
  unit: "°",
2594
- points: [r, o, a],
2595
- object: m
2267
+ points: [a, o, c],
2268
+ object: x
2596
2269
  };
2597
- return this.measurements.set(u, y), y;
2270
+ return this.measurements.set(p, y), y;
2598
2271
  }
2599
2272
  /**
2600
2273
  * Get a measurement result by id.
@@ -2629,15 +2302,15 @@ class Un {
2629
2302
  * Calculate polygon area using cross product method (Newell's method).
2630
2303
  */
2631
2304
  _calculatePolygonArea(e) {
2632
- const t = e.length, s = new v();
2633
- for (let i = 0; i < t; i++) {
2634
- const r = e[i], o = e[(i + 1) % t], a = new v().crossVectors(r, o);
2635
- s.add(a);
2305
+ const t = e.length, s = new D();
2306
+ for (let r = 0; r < t; r++) {
2307
+ const a = e[r], o = e[(r + 1) % t], c = new D().crossVectors(a, o);
2308
+ s.add(c);
2636
2309
  }
2637
- const n = new v();
2310
+ const n = new D();
2638
2311
  if (t >= 3) {
2639
- const i = e[1].clone().sub(e[0]), r = e[2].clone().sub(e[0]);
2640
- n.crossVectors(i, r).normalize();
2312
+ const r = e[1].clone().sub(e[0]), a = e[2].clone().sub(e[0]);
2313
+ n.crossVectors(r, a).normalize();
2641
2314
  }
2642
2315
  return Math.abs(s.dot(n)) / 2;
2643
2316
  }
@@ -2645,7 +2318,7 @@ class Un {
2645
2318
  this.removeAll();
2646
2319
  }
2647
2320
  }
2648
- class Hn {
2321
+ class mi {
2649
2322
  scene;
2650
2323
  annotations = /* @__PURE__ */ new Map();
2651
2324
  _idCounter = 0;
@@ -2665,12 +2338,12 @@ class Hn {
2665
2338
  */
2666
2339
  add(e, t) {
2667
2340
  this.annotations.has(e) && this.remove(e);
2668
- const s = new I();
2341
+ const s = new W();
2669
2342
  s.name = `annotation_${e}`;
2670
- const n = new v(t.position.x, t.position.y, t.position.z);
2343
+ const n = new D(t.position.x, t.position.y, t.position.z);
2671
2344
  s.position.copy(n);
2672
- const i = document.createElement("div");
2673
- if (i.innerHTML = t.content, i.style.cssText = `
2345
+ const r = document.createElement("div");
2346
+ if (r.innerHTML = t.content, r.style.cssText = `
2674
2347
  padding: 4px 8px;
2675
2348
  background: rgba(0, 0, 0, 0.75);
2676
2349
  color: #fff;
@@ -2679,32 +2352,32 @@ class Hn {
2679
2352
  pointer-events: auto;
2680
2353
  white-space: nowrap;
2681
2354
  `, t.labelStyle)
2682
- for (const c of Object.keys(t.labelStyle)) {
2683
- const l = t.labelStyle[c];
2684
- l !== void 0 && (i.style[c] = l);
2355
+ for (const l of Object.keys(t.labelStyle)) {
2356
+ const h = t.labelStyle[l];
2357
+ h !== void 0 && (r.style[l] = h);
2685
2358
  }
2686
- let r = null;
2359
+ let a = null;
2687
2360
  const o = t.labelOffset || { x: 0, y: 2, z: 0 };
2688
2361
  if (t.showLeaderLine !== !1) {
2689
- const { lineColor: c = 16777215 } = t, l = new Q().setFromPoints([
2690
- new v(0, 0, 0),
2691
- new v(o.x, o.y, o.z)
2692
- ]), d = new ie({ color: c });
2693
- r = new re(l, d), s.add(r);
2362
+ const { lineColor: l = 16777215 } = t, h = new G().setFromPoints([
2363
+ new D(0, 0, 0),
2364
+ new D(o.x, o.y, o.z)
2365
+ ]), d = new ye({ color: l });
2366
+ a = new be(h, d), s.add(a);
2694
2367
  }
2695
2368
  if (this._createCSSObject) {
2696
- const c = this._createCSSObject(i);
2697
- c.position.set(o.x, o.y, o.z), s.add(c);
2369
+ const l = this._createCSSObject(r);
2370
+ l.position.set(o.x, o.y, o.z), s.add(l);
2698
2371
  }
2699
2372
  this.scene.add(s);
2700
- const a = {
2373
+ const c = {
2701
2374
  id: e,
2702
2375
  options: t,
2703
2376
  group: s,
2704
- labelElement: i,
2705
- line: r
2377
+ labelElement: r,
2378
+ line: a
2706
2379
  };
2707
- return this.annotations.set(e, a), a;
2380
+ return this.annotations.set(e, c), c;
2708
2381
  }
2709
2382
  /**
2710
2383
  * Quick-add a text annotation.
@@ -2798,47 +2471,1112 @@ class Hn {
2798
2471
  this.removeAll();
2799
2472
  }
2800
2473
  }
2801
- const on = "0.0.29";
2802
- window.__USPACE__ = { version: on };
2474
+ const yt = new R(), or = 1e-6, cr = 1e-6, bt = "uSpaceInstanceOriginalMaterialState", wt = 0, Ne = 1, lr = 2;
2475
+ function hr(i) {
2476
+ let e = i;
2477
+ for (; e; ) {
2478
+ if (!e.visible) return !1;
2479
+ e = e.parent;
2480
+ }
2481
+ return !0;
2482
+ }
2483
+ function dr(i, e) {
2484
+ const t = i.elements, s = e.elements;
2485
+ for (let n = 0; n < 16; n++)
2486
+ if (Math.abs(t[n] - s[n]) > or) return !1;
2487
+ return !0;
2488
+ }
2489
+ function rs(i) {
2490
+ const e = i.material;
2491
+ return Array.isArray(e) ? e : [e];
2492
+ }
2493
+ function is(i) {
2494
+ const e = i.userData, t = e[bt];
2495
+ if (t) return t;
2496
+ const s = {
2497
+ transparent: i.transparent,
2498
+ opacity: i.opacity
2499
+ };
2500
+ return e[bt] = s, s;
2501
+ }
2502
+ function ur(i, e) {
2503
+ i.traverse((t) => {
2504
+ const s = t;
2505
+ s.isMesh && rs(s).forEach((n) => {
2506
+ if (!n) return;
2507
+ const r = n, a = is(r), o = a.opacity * e;
2508
+ r.transparent = a.transparent || o < 1, r.opacity = o, r.needsUpdate = !0;
2509
+ });
2510
+ });
2511
+ }
2512
+ function pr(i) {
2513
+ i.traverse((e) => {
2514
+ const t = e;
2515
+ t.isMesh && rs(t).forEach((s) => {
2516
+ if (!s) return;
2517
+ const n = s, r = is(n);
2518
+ n.transparent = r.transparent, n.opacity = r.opacity, n.needsUpdate = !0;
2519
+ });
2520
+ });
2521
+ }
2522
+ class gi extends pe {
2523
+ isInstanceObject = !0;
2524
+ type = "InstanceObject";
2525
+ instanceId = "";
2526
+ instanceKind = "";
2527
+ instanceName = "";
2528
+ geometry = new G();
2529
+ boundingBox = null;
2530
+ boundingSphere = null;
2531
+ #s = {
2532
+ color: null,
2533
+ colorMode: wt,
2534
+ opacity: 1
2535
+ };
2536
+ #a = null;
2537
+ #t = null;
2538
+ #e = null;
2539
+ #r = null;
2540
+ #n = /* @__PURE__ */ new Set();
2541
+ #o = new R();
2542
+ #c = !1;
2543
+ #l = !0;
2544
+ #d = !1;
2545
+ #u;
2546
+ constructor(e = {}) {
2547
+ super(), this.#u = e.boundsName ?? "InstanceBounds";
2548
+ }
2549
+ setInstanceIdentity(e) {
2550
+ let t = !1;
2551
+ if (e.id !== void 0) {
2552
+ const s = e.id ?? "";
2553
+ this.instanceId !== s && (this.instanceId = s, t = !0);
2554
+ }
2555
+ if (e.kind !== void 0) {
2556
+ const s = e.kind ?? "";
2557
+ this.instanceKind !== s && (this.instanceKind = s, t = !0);
2558
+ }
2559
+ if (e.name !== void 0) {
2560
+ const s = e.name ?? "";
2561
+ this.instanceName !== s && (this.instanceName = s, t = !0);
2562
+ }
2563
+ return t && this.markInstanceRenderDirty(), this;
2564
+ }
2565
+ setInstanceBounds(e) {
2566
+ if (e.isEmpty()) return this;
2567
+ this.#t && this.remove(this.#t);
2568
+ const t = new G();
2569
+ t.boundingBox = e.clone();
2570
+ const s = new Ys();
2571
+ return s.name = this.#u, s.visible = !1, s.geometry = t, s.raycast = () => {
2572
+ }, this.#t = s, this.add(s), this.#h(), this.markInstanceRenderDirty(), this;
2573
+ }
2574
+ setInstanceRenderObject(e) {
2575
+ return this.#e && this.#e !== e && this.#e.parent === this && this.remove(this.#e), this.#e = e, e && e.parent !== this && this.add(e), this.#f(), this.#h(), this.markInstanceRenderDirty(), this;
2576
+ }
2577
+ getInstanceRenderObject() {
2578
+ return this.#e;
2579
+ }
2580
+ setInstanceMaterializer(e) {
2581
+ return this.#r = e, this;
2582
+ }
2583
+ hasInstanceMaterializer(e) {
2584
+ return this.#r === e;
2585
+ }
2586
+ clearInstanceMaterializer(e) {
2587
+ return (e === void 0 || this.#r === e) && (this.#r = null), this;
2588
+ }
2589
+ materialize() {
2590
+ return this.#r?.() ?? this.#e ?? null;
2591
+ }
2592
+ computeBoundingBox() {
2593
+ this.boundingBox === null && (this.boundingBox = new K()), this.getInstanceBoundingBox(this.boundingBox, !1);
2594
+ }
2595
+ computeBoundingSphere() {
2596
+ if (this.boundingSphere === null && (this.boundingSphere = new ne()), this.boundingBox === null && this.computeBoundingBox(), !this.boundingBox || this.boundingBox.isEmpty()) {
2597
+ this.boundingSphere.makeEmpty();
2598
+ return;
2599
+ }
2600
+ this.boundingBox.getBoundingSphere(this.boundingSphere);
2601
+ }
2602
+ getInstanceBoundingBox(e = new K(), t = !1) {
2603
+ const s = this.#t?.geometry?.boundingBox;
2604
+ return s ? (e.copy(s), t && (this.updateWorldMatrix(!0, !1), e.applyMatrix4(this.matrixWorld)), e) : this.#e ? (e.setFromObject(this.#e), t || (this.updateWorldMatrix(!0, !1), yt.copy(this.matrixWorld).invert(), e.applyMatrix4(yt)), e) : e.makeEmpty();
2605
+ }
2606
+ setInstanceVisible(e) {
2607
+ return this.visible === e ? this : (this.visible = e, this.markInstanceRenderDirty(), this);
2608
+ }
2609
+ setInstanceColor(e) {
2610
+ return this.#s.color = new P(e), this.#s.colorMode = Ne, this.#f(), this.markInstanceRenderDirty(), this;
2611
+ }
2612
+ resetInstanceColor() {
2613
+ return this.#s.color === null ? this : (this.#s.color = null, this.#s.colorMode = wt, this.#f(), this.markInstanceRenderDirty(), this);
2614
+ }
2615
+ setInstanceOpacity(e) {
2616
+ const t = Math.max(0, Math.min(1, e));
2617
+ return Math.abs(this.#s.opacity - t) <= cr ? this : (this.#s.opacity = t, this.#f(), this.markInstanceRenderDirty(), this);
2618
+ }
2619
+ getInstanceColor(e = new P()) {
2620
+ const t = this.#p();
2621
+ return t.color ? e.copy(t.color) : e.setRGB(1, 1, 1);
2622
+ }
2623
+ hasInstanceColor() {
2624
+ return this.#p().color !== null;
2625
+ }
2626
+ getInstanceOpacity() {
2627
+ return this.#p().opacity;
2628
+ }
2629
+ setInstanceHighlight(e, t, s = !1) {
2630
+ return this.#a = {
2631
+ color: new P(e),
2632
+ colorMode: s ? Ne : lr,
2633
+ opacity: Math.max(0, Math.min(1, t))
2634
+ }, this.#f(), this.markInstanceRenderDirty(), this;
2635
+ }
2636
+ clearInstanceHighlight() {
2637
+ return this.#a === null ? this : (this.#a = null, this.#f(), this.markInstanceRenderDirty(), this);
2638
+ }
2639
+ getInstanceColorMode() {
2640
+ return this.#p().colorMode;
2641
+ }
2642
+ onInstanceRenderDirty(e) {
2643
+ return this.#n.add(e), () => this.#n.delete(e);
2644
+ }
2645
+ markInstanceRenderDirty() {
2646
+ return this.#n.forEach((e) => e()), this;
2647
+ }
2648
+ updateMatrixWorld(e) {
2649
+ super.updateMatrixWorld(e), this.#i();
2650
+ }
2651
+ updateWorldMatrix(e, t) {
2652
+ super.updateWorldMatrix(e, t), this.#i();
2653
+ }
2654
+ #i() {
2655
+ const e = hr(this);
2656
+ (!this.#c || !dr(this.matrixWorld, this.#o) || !this.#d || e !== this.#l) && (this.#c = !0, this.#d = !0, this.#o.copy(this.matrixWorld), this.#l = e, this.markInstanceRenderDirty());
2657
+ }
2658
+ #h() {
2659
+ this.boundingBox = null, this.boundingSphere = null;
2660
+ }
2661
+ #p() {
2662
+ return this.#a ?? this.#s;
2663
+ }
2664
+ #f() {
2665
+ if (!this.#e) return;
2666
+ const e = this.#p();
2667
+ if (e.color) {
2668
+ pr(this.#e), se.highlightColor(this.#e, {
2669
+ color: e.color,
2670
+ opacity: e.opacity,
2671
+ overwrite: e.colorMode === Ne,
2672
+ multiplyOpacity: !0
2673
+ });
2674
+ return;
2675
+ }
2676
+ se.removeHighlightColor(this.#e), ur(this.#e, e.opacity);
2677
+ }
2678
+ }
2679
+ function yi(i) {
2680
+ return i.isInstanceObject === !0;
2681
+ }
2682
+ const fr = /* @__PURE__ */ new Set([
2683
+ "MeshBasicMaterial",
2684
+ "MeshLambertMaterial",
2685
+ "MeshPhongMaterial",
2686
+ "MeshStandardMaterial",
2687
+ "MeshPhysicalMaterial"
2688
+ ]), xt = /* @__PURE__ */ new WeakMap();
2689
+ let mr = 1;
2690
+ const Mt = new R(), le = new R(), vt = new R();
2691
+ function gr(i, e, t = 1e-6) {
2692
+ const s = i.elements, n = e.elements;
2693
+ for (let r = 0; r < 16; r++)
2694
+ if (Math.abs(s[r] - n[r]) > t) return !1;
2695
+ return !0;
2696
+ }
2697
+ function as(i) {
2698
+ let e = i;
2699
+ for (; e; ) {
2700
+ if (!e.visible) return !1;
2701
+ e = e.parent;
2702
+ }
2703
+ return !0;
2704
+ }
2705
+ function yr(i) {
2706
+ const e = i.source.data;
2707
+ if (!e || typeof e != "object" && typeof e != "function")
2708
+ return `texture:${i.uuid}`;
2709
+ let t = xt.get(e);
2710
+ return t === void 0 && (t = mr++, xt.set(e, t)), `source:${t}`;
2711
+ }
2712
+ function br(i) {
2713
+ return JSON.stringify([
2714
+ yr(i),
2715
+ i.mapping,
2716
+ i.channel,
2717
+ i.wrapS,
2718
+ i.wrapT,
2719
+ i.magFilter,
2720
+ i.minFilter,
2721
+ i.anisotropy,
2722
+ i.format,
2723
+ i.internalFormat,
2724
+ i.type,
2725
+ i.offset.toArray(),
2726
+ i.repeat.toArray(),
2727
+ i.center.toArray(),
2728
+ i.rotation,
2729
+ i.matrixAutoUpdate,
2730
+ i.matrix.toArray(),
2731
+ i.generateMipmaps,
2732
+ i.premultiplyAlpha,
2733
+ i.flipY,
2734
+ i.unpackAlignment,
2735
+ i.colorSpace,
2736
+ "compareFunction" in i ? i.compareFunction : null
2737
+ ]);
2738
+ }
2739
+ function Ue(i) {
2740
+ if (Array.isArray(i)) return i.map(Ue);
2741
+ if (!i || typeof i != "object") return i;
2742
+ const e = i;
2743
+ return Object.fromEntries(
2744
+ Object.keys(e).sort().map((t) => [t, Ue(e[t])])
2745
+ );
2746
+ }
2747
+ function je(i, e) {
2748
+ if (Array.isArray(i)) return i.map((s) => je(s, e));
2749
+ if (!i || typeof i != "object")
2750
+ return typeof i == "string" ? e.get(i) ?? i : i;
2751
+ const t = i;
2752
+ return Object.fromEntries(
2753
+ Object.keys(t).filter((s) => s !== "metadata" && s !== "uuid" && s !== "name").sort().map((s) => [s, je(t[s], e)])
2754
+ );
2755
+ }
2756
+ function wr(i) {
2757
+ if (!fr.has(i.type) || i.transparent || i.opacity < 0.999 || i.visible === !1) return null;
2758
+ const e = i;
2759
+ if (Object.keys(e).some((r) => r.endsWith("Node") && e[r] != null) || Object.hasOwn(i, "onBeforeCompile")) return null;
2760
+ const t = /* @__PURE__ */ new Map();
2761
+ Object.values(e).forEach((r) => {
2762
+ r instanceof $t && t.set(r.uuid, br(r));
2763
+ });
2764
+ const s = {
2765
+ geometries: {},
2766
+ materials: {},
2767
+ textures: {},
2768
+ images: {},
2769
+ shapes: {},
2770
+ skeletons: {},
2771
+ animations: {},
2772
+ nodes: {}
2773
+ }, n = i.toJSON(s);
2774
+ return JSON.stringify(Ue(je(n, t)));
2775
+ }
2776
+ function xr(i) {
2777
+ if (Object.keys(i.morphAttributes).length > 0 || i.drawRange.start !== 0 || i.drawRange.count !== 1 / 0) return null;
2778
+ const e = Object.entries(i.attributes).sort(([t], [s]) => t.localeCompare(s)).map(([t, s]) => "isInterleavedBufferAttribute" in s ? null : [t, s.itemSize, s.normalized, s.array.constructor.name, s.gpuType]);
2779
+ return e.some((t) => t === null) ? null : JSON.stringify([
2780
+ i.index?.array.constructor.name ?? "non-indexed",
2781
+ e
2782
+ ]);
2783
+ }
2784
+ function Mr(i, e) {
2785
+ const t = [], s = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = !e && (i.animations.length > 0 || i.mixer !== null);
2786
+ return r && n.add("animation"), i.updateWorldMatrix(!0, !0), Mt.copy(i.matrixWorld).invert(), i.traverseVisible((a) => {
2787
+ if (!(a instanceof k)) return;
2788
+ if (r) {
2789
+ s.add(a);
2790
+ return;
2791
+ }
2792
+ if (a instanceof Js) {
2793
+ s.add(a), n.add("skinned");
2794
+ return;
2795
+ }
2796
+ if (a.morphTargetInfluences) {
2797
+ s.add(a), n.add("morph");
2798
+ return;
2799
+ }
2800
+ if (Array.isArray(a.material)) {
2801
+ s.add(a), n.add("material-array");
2802
+ return;
2803
+ }
2804
+ const o = wr(a.material), c = xr(a.geometry);
2805
+ if (!o) {
2806
+ s.add(a), n.add(a.material.transparent || a.material.opacity < 0.999 ? "transparent" : `material:${a.material.type}`);
2807
+ return;
2808
+ }
2809
+ if (!c) {
2810
+ s.add(a), n.add("geometry-layout");
2811
+ return;
2812
+ }
2813
+ if (a.matrixWorld.determinant() <= 0) {
2814
+ s.add(a), n.add("negative-scale");
2815
+ return;
2816
+ }
2817
+ t.push({
2818
+ mesh: a,
2819
+ localMatrix: Mt.clone().multiply(a.matrixWorld),
2820
+ materialKey: o,
2821
+ geometryKey: c
2822
+ });
2823
+ }), t.length === 0 && s.size === 0 && n.add("empty"), {
2824
+ meshes: t,
2825
+ fallbackMeshes: s,
2826
+ fallbackReasons: n
2827
+ };
2828
+ }
2829
+ function vr(i, e) {
2830
+ const t = We(i), s = [], n = [];
2831
+ return i.traverse((r) => {
2832
+ r instanceof k && s.push(r);
2833
+ }), t.traverse((r) => {
2834
+ r instanceof k && n.push(r);
2835
+ }), s.forEach((r, a) => {
2836
+ e.has(r) && n[a] && (n[a].visible = !1);
2837
+ }), t;
2838
+ }
2839
+ function Sr(i) {
2840
+ const e = We(i), t = /* @__PURE__ */ new Map(), s = (n) => {
2841
+ let r = t.get(n);
2842
+ return r || (r = n.clone(), t.set(n, r)), r;
2843
+ };
2844
+ return e.traverse((n) => {
2845
+ n instanceof k && (n.material = Array.isArray(n.material) ? n.material.map(s) : s(n.material));
2846
+ }), e;
2847
+ }
2848
+ function Ir(i) {
2849
+ return Math.max(1, Math.ceil(Math.sqrt(Math.max(1, i))));
2850
+ }
2851
+ function Er(i) {
2852
+ const e = new Zs(new Float32Array(i * i * 4), i, i, en, tn);
2853
+ return e.magFilter = Ee, e.minFilter = Ee, e.generateMipmaps = !1, e.needsUpdate = !0, e;
2854
+ }
2855
+ function Cr(i, e) {
2856
+ const t = i.clone(), s = mn("batchObjectIndex", "float").toInt(), n = nt(gn(rt(e), nt(0)).x).toConst(), r = s.mod(n).toConst(), a = s.div(n).toConst(), o = rt(e, yn(r, a)), c = t.colorNode ?? Ce, l = $(o.a.greaterThan(1.5), c.mul(o.rgb), o.rgb);
2857
+ return t.colorNode = $(o.a.greaterThan(0.5), l, c), t.maskNode = o.a.greaterThan(-0.5), t.needsUpdate = !0, t;
2858
+ }
2859
+ function St(i) {
2860
+ let e = 0, t = i.parent;
2861
+ for (; t; )
2862
+ e++, t = t.parent;
2863
+ return e;
2864
+ }
2865
+ class Ar extends X {
2866
+ objectIndices;
2867
+ states;
2868
+ #s;
2869
+ constructor(e, t, s, n) {
2870
+ super(e, t), this.objectIndices = s, this.states = n, this.userData.editableGeometryBatch = !0;
2871
+ }
2872
+ raycast(e, t) {
2873
+ if (this.visible === !1 && this.ignoreInvisibleWhenRaycast === !0)
2874
+ return !1;
2875
+ this.#s === void 0 && (this.#s = jt(this.geometry));
2876
+ const s = [];
2877
+ this.#s ? this.#s.raycastObject3D(this, e, s) : super.raycast(e, s), s.forEach((n) => {
2878
+ const r = n.faceIndex;
2879
+ if (r == null) return;
2880
+ const a = r * 3, o = this.geometry.index?.getX(a) ?? a, c = this.objectIndices[o], l = c === void 0 ? void 0 : this.states[c], h = l?.instance;
2881
+ !l || l.materialized || !h || !as(h) || h.getInstanceOpacity() <= 1e-3 || (n.object = h, n.batchObjectIndex = c, t.push(n));
2882
+ });
2883
+ }
2884
+ }
2885
+ class bi extends pe {
2886
+ isEditableGeometryBatchLayer = !0;
2887
+ type = "EditableGeometryBatchLayer";
2888
+ options;
2889
+ stats = {
2890
+ instances: 0,
2891
+ sourceMeshes: 0,
2892
+ batches: 0,
2893
+ drawCallsSaved: 0,
2894
+ vertices: 0,
2895
+ indices: 0,
2896
+ unsupportedInstances: 0,
2897
+ unsupportedByReason: {}
2898
+ };
2899
+ #s = [];
2900
+ #a = /* @__PURE__ */ new Set();
2901
+ #t = [];
2902
+ #e = /* @__PURE__ */ new Map();
2903
+ #r = /* @__PURE__ */ new Set();
2904
+ #n = null;
2905
+ #o = new R();
2906
+ #c = !1;
2907
+ #l = !1;
2908
+ #d = !1;
2909
+ constructor(e = {}) {
2910
+ super(), this.name = "EditableGeometryBatches", this.options = {
2911
+ maxVerticesPerBatch: e.maxVerticesPerBatch ?? 15e5,
2912
+ maxIndicesPerBatch: e.maxIndicesPerBatch ?? 45e5,
2913
+ freezeAnimations: e.freezeAnimations ?? !1
2914
+ };
2915
+ }
2916
+ addSource(e) {
2917
+ if (this.#l) throw new Error("EditableGeometryBatchLayer has been disposed.");
2918
+ if (this.#c) throw new Error("EditableGeometryBatchLayer has already been built.");
2919
+ const { key: t, template: s, instances: n } = e, r = /* @__PURE__ */ new Set();
2920
+ n.forEach((l) => {
2921
+ if (r.has(l) || this.#a.has(l))
2922
+ throw new Error(
2923
+ "EditableGeometryBatchLayer cannot batch the same InstanceObject more than once."
2924
+ );
2925
+ r.add(l);
2926
+ });
2927
+ const { meshes: a, fallbackMeshes: o, fallbackReasons: c } = Mr(
2928
+ s,
2929
+ this.options.freezeAnimations
2930
+ );
2931
+ return r.forEach((l) => this.#a.add(l)), this.#s.push({
2932
+ key: t,
2933
+ template: s,
2934
+ instances: [...n],
2935
+ meshes: a,
2936
+ fallbackMeshes: o,
2937
+ fallbackReasons: c,
2938
+ bounds: new K().setFromObject(s)
2939
+ }), a.length > 0;
2940
+ }
2941
+ build() {
2942
+ if (this.#l) throw new Error("EditableGeometryBatchLayer has been disposed.");
2943
+ if (this.#c) throw new Error("EditableGeometryBatchLayer.build() can only be called once.");
2944
+ this.#c = !0, this.updateWorldMatrix(!0, !1), this.#o.copy(this.matrixWorld).invert();
2945
+ const e = [], t = /* @__PURE__ */ new Map(), s = (r, a, o, c) => {
2946
+ if (o.length === 0) return;
2947
+ const l = c.size > 0 ? [...c] : ["unknown"];
2948
+ e.push({ key: r.key, template: a, instances: o, reasons: l }), l.forEach((h) => {
2949
+ this.stats.unsupportedByReason[h] = (this.stats.unsupportedByReason[h] ?? 0) + o.length;
2950
+ });
2951
+ };
2952
+ this.#s.forEach((r) => {
2953
+ const a = [], o = [];
2954
+ r.instances.forEach((l) => {
2955
+ l.updateWorldMatrix(!0, !1), le.multiplyMatrices(this.#o, l.matrixWorld), le.determinant() <= 0 ? o.push(l) : a.push({ instance: l, matrix: le.clone() });
2956
+ });
2957
+ const c = r.fallbackReasons.size > 0 ? r.fallbackReasons : /* @__PURE__ */ new Set(["unknown"]);
2958
+ if (r.meshes.length === 0) {
2959
+ s(
2960
+ r,
2961
+ r.template,
2962
+ a.map(({ instance: l }) => l),
2963
+ c
2964
+ ), s(
2965
+ r,
2966
+ r.template,
2967
+ o,
2968
+ /* @__PURE__ */ new Set([...c, "negative-scale"])
2969
+ );
2970
+ return;
2971
+ }
2972
+ r.fallbackMeshes.size > 0 && s(
2973
+ r,
2974
+ vr(
2975
+ r.template,
2976
+ new Set(r.meshes.map(({ mesh: l }) => l))
2977
+ ),
2978
+ a.map(({ instance: l }) => l),
2979
+ c
2980
+ ), s(
2981
+ r,
2982
+ r.template,
2983
+ o,
2984
+ /* @__PURE__ */ new Set([...r.fallbackReasons, "negative-scale"])
2985
+ ), a.forEach(({ instance: l, matrix: h }) => {
2986
+ const d = this.#t.length, u = () => this.materialize(l), p = {
2987
+ instance: l,
2988
+ template: r.template,
2989
+ initialMatrix: h,
2990
+ objectIndex: d,
2991
+ materialized: !1,
2992
+ materializer: u,
2993
+ unsubscribe: () => {
2994
+ }
2995
+ };
2996
+ p.unsubscribe = l.onInstanceRenderDirty(() => this.#h(p)), this.#t.push(p), this.#e.set(l, p), l.setInstanceBounds(r.bounds), l.setInstanceMaterializer(u), this.#r.add(p), r.meshes.forEach(({ mesh: x, localMatrix: I, materialKey: _, geometryKey: C }) => {
2997
+ vt.multiplyMatrices(h, I);
2998
+ const y = x.geometry.clone().applyMatrix4(vt), w = y.getAttribute("position");
2999
+ y.setAttribute(
3000
+ "batchObjectIndex",
3001
+ new Qs(new Float32Array(w.count).fill(d), 1)
3002
+ );
3003
+ const g = JSON.stringify([
3004
+ _,
3005
+ C,
3006
+ x.castShadow,
3007
+ x.receiveShadow,
3008
+ x.renderOrder
3009
+ ]), m = t.get(g), M = {
3010
+ geometry: y,
3011
+ material: x.material,
3012
+ castShadow: x.castShadow,
3013
+ receiveShadow: x.receiveShadow,
3014
+ renderOrder: x.renderOrder,
3015
+ objectIndices: new Array(w.count).fill(d)
3016
+ };
3017
+ m ? m.push(M) : t.set(g, [M]), this.stats.sourceMeshes++, this.stats.vertices += w.count, this.stats.indices += y.index?.count ?? w.count;
3018
+ });
3019
+ });
3020
+ }), this.stats.instances = this.#t.length, this.stats.unsupportedInstances = e.reduce((r, a) => r + a.instances.length, 0);
3021
+ const n = Ir(this.#t.length);
3022
+ return this.#n = Er(n), this.#i(), t.forEach((r) => this.#u(r)), this.stats.batches = this.children.length, this.stats.drawCallsSaved = Math.max(0, this.stats.sourceMeshes - this.stats.batches), this.children.forEach((r) => {
3023
+ r instanceof k && (r.onBeforeRender = () => this.#i());
3024
+ }), { stats: { ...this.stats }, unsupported: e };
3025
+ }
3026
+ materialize(e) {
3027
+ const t = this.#e.get(e);
3028
+ if (!t || t.materialized) return e.getInstanceRenderObject();
3029
+ const s = Sr(t.template);
3030
+ return s.position.set(0, 0, 0), s.quaternion.identity(), s.scale.set(1, 1, 1), s.matrix.identity(), t.materialized = !0, e.setInstanceRenderObject(s), s.updateWorldMatrix(!0, !0), this.#r.add(t), this.dispatchEvent({ type: "materialize", instance: e, object: s }), s;
3031
+ }
3032
+ #u(e) {
3033
+ const t = [];
3034
+ let s = [], n = 0, r = 0;
3035
+ e.forEach((a) => {
3036
+ const o = a.geometry.getAttribute("position").count, c = a.geometry.index?.count ?? o;
3037
+ s.length > 0 && (n + o > this.options.maxVerticesPerBatch || r + c > this.options.maxIndicesPerBatch) && (t.push(s), s = [], n = 0, r = 0), s.push(a), n += o, r += c;
3038
+ }), s.length > 0 && t.push(s), t.forEach((a) => {
3039
+ const o = Mn(a.map((u) => u.geometry), !1);
3040
+ if (a.forEach((u) => u.geometry.dispose()), !o || !this.#n) return;
3041
+ o.computeBoundingBox(), o.computeBoundingSphere();
3042
+ const c = a[0], l = a.flatMap((u) => u.objectIndices), h = Cr(c.material, this.#n), d = new Ar(
3043
+ o,
3044
+ h,
3045
+ l,
3046
+ this.#t
3047
+ );
3048
+ d.name = `EditableGeometryBatch:${this.children.length}`, d.castShadow = c.castShadow, d.receiveShadow = c.receiveShadow, d.renderOrder = c.renderOrder, d.matrixAutoUpdate = !1, this.add(d);
3049
+ });
3050
+ }
3051
+ #i() {
3052
+ if (!(!this.#n || this.#r.size === 0 || this.#d)) {
3053
+ this.#d = !0;
3054
+ try {
3055
+ this.updateWorldMatrix(!0, !1), this.#o.copy(this.matrixWorld).invert();
3056
+ const e = this.#n.image.data;
3057
+ [...this.#r].sort((t, s) => St(t.instance) - St(s.instance)).forEach((t) => {
3058
+ const { instance: s, objectIndex: n } = t;
3059
+ s.updateWorldMatrix(!0, !1), le.multiplyMatrices(this.#o, s.matrixWorld), !t.materialized && s.getInstanceRenderObject() !== null && !s.hasInstanceMaterializer(t.materializer) && (t.materialized = !0), !t.materialized && !gr(le, t.initialMatrix) && this.materialize(s), !t.materialized && s.getInstanceOpacity() < 0.999 && this.materialize(s);
3060
+ const r = n * 4, a = !t.materialized && as(s) && s.getInstanceOpacity() > 1e-3, o = s.getInstanceColor();
3061
+ e[r] = o.r, e[r + 1] = o.g, e[r + 2] = o.b, e[r + 3] = a ? s.getInstanceColorMode() : -1, this.#r.delete(t);
3062
+ }), this.#n.needsUpdate = !0;
3063
+ } finally {
3064
+ this.#d = !1;
3065
+ }
3066
+ this.#r.size > 0 && this.#i();
3067
+ }
3068
+ }
3069
+ #h(e) {
3070
+ this.#r.add(e), this.#i();
3071
+ }
3072
+ dispose() {
3073
+ this.#l || (this.#l = !0, this.#t.forEach((e) => {
3074
+ e.unsubscribe(), e.instance.clearInstanceMaterializer(e.materializer);
3075
+ }), this.#t.length = 0, this.#e.clear(), this.#a.clear(), this.#r.clear(), this.#s.length = 0, this.#n?.dispose(), this.#n = null, this.traverse((e) => {
3076
+ if (!(e instanceof k)) return;
3077
+ e.geometry.dispose(), (Array.isArray(e.material) ? e.material : [e.material]).forEach((s) => s.dispose());
3078
+ }), this.clear());
3079
+ }
3080
+ }
3081
+ const It = new R(), me = new R(), Et = new R(), Ct = new R(), At = new K(), Ot = new ne(), Bt = new ne(), Or = new sn(), Z = new P(), _t = new j(), Tt = new D(), Lt = new R(), Nt = new R(), Dt = new ne(), ge = [], os = 1e-6, H = 1e-6, cs = 0.999, Br = 0, Pt = 1;
3082
+ function _r(i, e, t) {
3083
+ const s = i.elements;
3084
+ for (let n = 0; n < 16; n++)
3085
+ if (Math.abs(s[n] - e[t + n]) > os) return !1;
3086
+ return !0;
3087
+ }
3088
+ function Tr(i, e, t, s) {
3089
+ return Math.abs(i.r - t[s]) <= H && Math.abs(i.g - t[s + 1]) <= H && Math.abs(i.b - t[s + 2]) <= H && Math.abs(e - t[s + 3]) <= H;
3090
+ }
3091
+ function Rt(i, e) {
3092
+ const t = i.elements, s = e.elements;
3093
+ for (let n = 0; n < 16; n++)
3094
+ if (Math.abs(t[n] - s[n]) > os) return !1;
3095
+ return !0;
3096
+ }
3097
+ function De(i) {
3098
+ let e = i;
3099
+ for (; e; ) {
3100
+ if (!e.visible) return !1;
3101
+ e = e.parent;
3102
+ }
3103
+ return !0;
3104
+ }
3105
+ function Lr(i) {
3106
+ const e = i.geometry.morphAttributes;
3107
+ return Object.values(e).some((t) => t?.length);
3108
+ }
3109
+ function Nr(i) {
3110
+ const e = i.material;
3111
+ if (!Array.isArray(e)) return !0;
3112
+ if (e.length === 0 || !e.every(Boolean)) return !1;
3113
+ const t = i.geometry.groups;
3114
+ return t.length === 0 ? !1 : t.every((s) => {
3115
+ const n = s.materialIndex ?? 0;
3116
+ return Number.isInteger(s.start) && s.start >= 0 && Number.isInteger(s.count) && s.count > 0 && Number.isInteger(n) && n >= 0 && n < e.length;
3117
+ });
3118
+ }
3119
+ function Dr(i) {
3120
+ return !i.isSkinnedMesh && !Lr(i) && Nr(i);
3121
+ }
3122
+ function kt(i) {
3123
+ return Array.isArray(i) ? i : [i];
3124
+ }
3125
+ function ls(i) {
3126
+ return i.transparent || i.opacity < cs;
3127
+ }
3128
+ function zt(i, e, t) {
3129
+ const s = i.clone(), n = it(e, "vec4", 4, 0), r = it(t, "float", 1, 0), a = s.colorNode ?? Ce, o = s.opacityNode ? bn(s.opacityNode) : ze, c = $(n.a.greaterThan(1.5), a.mul(n.rgb), n.rgb);
3130
+ return s.colorNode = $(n.a.greaterThan(0.5), c, a), s.opacityNode = o.mul(r), s.transparent = ls(i), s.needsUpdate = !0, s;
3131
+ }
3132
+ function Pr(i, e, t) {
3133
+ return Array.isArray(i) ? i.map((s) => zt(s, e, t)) : zt(i, e, t);
3134
+ }
3135
+ function Rr(i) {
3136
+ const e = [], t = new R();
3137
+ let s = !1;
3138
+ return i.updateWorldMatrix(!0, !0), t.copy(i.matrixWorld).invert(), i.traverse((n) => {
3139
+ if (!s && !(!(n instanceof k) || !n.visible)) {
3140
+ if (!Dr(n)) {
3141
+ s = !0;
3142
+ return;
3143
+ }
3144
+ n.updateWorldMatrix(!0, !1), e.push({
3145
+ mesh: n,
3146
+ localMatrix: t.clone().multiply(n.matrixWorld)
3147
+ });
3148
+ }
3149
+ }), s ? [] : e;
3150
+ }
3151
+ function kr(i) {
3152
+ const e = new K();
3153
+ return i.forEach(({ mesh: t, localMatrix: s }) => {
3154
+ const n = t.geometry;
3155
+ n.boundingBox || n.computeBoundingBox(), n.boundingBox && (At.copy(n.boundingBox).applyMatrix4(s), e.union(At));
3156
+ }), e;
3157
+ }
3158
+ function ee(i) {
3159
+ const e = i;
3160
+ "needsUpdate" in e && (e.needsUpdate = !0);
3161
+ }
3162
+ function Ut(i, e = Pt) {
3163
+ let t = Math.max(Pt, e);
3164
+ for (; t < i; )
3165
+ t *= 2;
3166
+ return t;
3167
+ }
3168
+ function zr(i) {
3169
+ return i !== null && typeof i == "object" && Symbol.iterator in i;
3170
+ }
3171
+ class wi extends pe {
3172
+ isModelInstancedLayer = !0;
3173
+ type = "ModelInstancedLayer";
3174
+ #s = [];
3175
+ #a = /* @__PURE__ */ new Map();
3176
+ #t = /* @__PURE__ */ new Map();
3177
+ #e = /* @__PURE__ */ new Map();
3178
+ #r = !0;
3179
+ #n = !1;
3180
+ #o = !0;
3181
+ #c = Br;
3182
+ #l;
3183
+ #d;
3184
+ constructor(e = {}) {
3185
+ super(), this.name = e.name ?? "ModelInstances", this.#l = e.instanceKind ?? "", this.#d = e.getHitUserData ?? (() => ({}));
3186
+ }
3187
+ get instanceKind() {
3188
+ return this.#l;
3189
+ }
3190
+ getInstances() {
3191
+ const e = [];
3192
+ return this.#i((t) => e.push(t)), e;
3193
+ }
3194
+ getInstanceById(e) {
3195
+ return this.#w(), this.#e.get(e);
3196
+ }
3197
+ hasInstance(e) {
3198
+ return this.#w(), this.#e.has(e);
3199
+ }
3200
+ getInstanceCulling() {
3201
+ return {
3202
+ enabled: this.#n,
3203
+ frustum: this.#o,
3204
+ minScreenRadius: this.#c
3205
+ };
3206
+ }
3207
+ setInstanceCulling(e = {}) {
3208
+ let t = !1;
3209
+ if (e.enabled !== void 0 && this.#n !== e.enabled && (this.#n = e.enabled, t = !0), e.frustum !== void 0 && this.#o !== e.frustum && (this.#o = e.frustum, t = !0), e.minScreenRadius !== void 0) {
3210
+ const s = Math.max(0, e.minScreenRadius);
3211
+ Math.abs(this.#c - s) > H && (this.#c = s, t = !0);
3212
+ }
3213
+ return t && this.#s.forEach((s) => this.#I(s)), this;
3214
+ }
3215
+ setInstanceVisible(e) {
3216
+ return this.visible !== e && (this.visible = e), this.#i((t) => {
3217
+ t.setInstanceVisible(e);
3218
+ }), this;
3219
+ }
3220
+ setInstanceColor(e) {
3221
+ return this.#i((t) => {
3222
+ t.setInstanceColor(e);
3223
+ }), this;
3224
+ }
3225
+ resetInstanceColor() {
3226
+ return this.#i((e) => {
3227
+ e.resetInstanceColor();
3228
+ }), this;
3229
+ }
3230
+ setInstanceOpacity(e) {
3231
+ return this.#i((t) => {
3232
+ t.setInstanceOpacity(e);
3233
+ }), this;
3234
+ }
3235
+ setInstanceHighlight(e, t, s = !1) {
3236
+ return this.#i((n) => {
3237
+ n.setInstanceHighlight(e, t, s);
3238
+ }), this;
3239
+ }
3240
+ clearInstanceHighlight() {
3241
+ return this.#i((e) => {
3242
+ e.clearInstanceHighlight();
3243
+ }), this;
3244
+ }
3245
+ reserveBatch(e, t, s) {
3246
+ const n = Math.floor(s);
3247
+ return n <= 0 ? !1 : this.#u(e, t, n) !== null;
3248
+ }
3249
+ addInstance(e, t, s) {
3250
+ return this.addInstances(e, t, [s]);
3251
+ }
3252
+ addInstances(e, t, s) {
3253
+ if (s.length === 0) return !1;
3254
+ const n = this.#a.has(e), r = this.#u(e, t, s.length);
3255
+ if (!r) return !1;
3256
+ const a = [], o = /* @__PURE__ */ new Set();
3257
+ return s.forEach((c) => {
3258
+ o.has(c) || (o.add(c), this.#t.get(c) === r) || a.push(c);
3259
+ }), a.length === 0 ? !0 : this.#C(a) ? (a.forEach((c) => {
3260
+ const l = this.#t.get(c);
3261
+ l && l !== r && this.#v(l, c);
3262
+ }), this.#M(r, r.instances.length + a.length), a.forEach((c) => {
3263
+ c.setInstanceBounds(r.templateBounds), r.instances.push(c), this.#t.set(c, r), r.unsubscribeByInstance.set(
3264
+ c,
3265
+ c.onInstanceRenderDirty(() => {
3266
+ this.#g(), this.#y(r);
3267
+ })
3268
+ );
3269
+ }), this.#g(), this.#b(r), this.#y(r), !0) : (!n && r.instances.length === 0 && this.#m(r), !1);
3270
+ }
3271
+ removeInstance(e) {
3272
+ return this.removeInstances([e]) > 0;
3273
+ }
3274
+ removeInstances(e) {
3275
+ const t = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), n = typeof e == "string" || !zr(e) ? [e] : e;
3276
+ for (const a of n)
3277
+ typeof a == "string" ? t.add(a) : this.#t.has(a) && s.add(a);
3278
+ t.size > 0 && (this.#w(), t.forEach((a) => {
3279
+ const o = this.#e.get(a);
3280
+ o && s.add(o);
3281
+ }));
3282
+ let r = 0;
3283
+ return s.forEach((a) => {
3284
+ const o = this.#t.get(a);
3285
+ o && this.#v(o, a) && r++;
3286
+ }), r;
3287
+ }
3288
+ removeBatch(e) {
3289
+ const t = this.#a.get(e);
3290
+ return t ? (this.#m(t), !0) : !1;
3291
+ }
3292
+ clearBatches() {
3293
+ return [...this.#a.values()].forEach((e) => this.#m(e)), this;
3294
+ }
3295
+ #u(e, t, s) {
3296
+ const n = this.#a.get(e);
3297
+ if (n)
3298
+ return this.#M(n, s), n;
3299
+ if (t.animations?.length) return null;
3300
+ const r = Rr(t);
3301
+ if (r.length === 0) return null;
3302
+ const a = kr(r), o = new W();
3303
+ o.name = e, this.add(o);
3304
+ const c = {
3305
+ url: e,
3306
+ batch: o,
3307
+ templateMeshes: r,
3308
+ templateBounds: a,
3309
+ records: [],
3310
+ instances: [],
3311
+ unsubscribeByInstance: /* @__PURE__ */ new Map(),
3312
+ capacity: Ut(s)
3313
+ };
3314
+ return r.forEach(({ mesh: l, localMatrix: h }, d) => {
3315
+ const u = this.#h(c, l, h, d);
3316
+ c.records.push(u), this.#s.push(u);
3317
+ }), this.#a.set(e, c), this.#b(c), c;
3318
+ }
3319
+ #i(e) {
3320
+ const t = /* @__PURE__ */ new Set();
3321
+ this.#a.forEach((s) => {
3322
+ s.instances.forEach((n) => {
3323
+ t.has(n) || (t.add(n), e(n));
3324
+ });
3325
+ });
3326
+ }
3327
+ #h(e, t, s, n) {
3328
+ const r = new Je(new Float32Array(e.capacity * 4), 4), a = new Je(new Float32Array(e.capacity).fill(1), 1);
3329
+ r.setUsage(Te), a.setUsage(Te);
3330
+ const o = Pr(
3331
+ t.material,
3332
+ r,
3333
+ a
3334
+ ), c = kt(o), l = kt(t.material).some(
3335
+ ls
3336
+ ), h = new nn(t.geometry, o, e.capacity);
3337
+ h.instanceMatrix = new rn(e.capacity, 16), h.count = 0, h.name = t.name || `${e.url}#${n}`, h.castShadow = t.castShadow, h.receiveShadow = t.receiveShadow, h.frustumCulled = !0, h.matrixAutoUpdate = !1, h.instanceMatrix.setUsage(Te), h.userData.url = e.url;
3338
+ const d = new k(t.geometry, o);
3339
+ d.matrixAutoUpdate = !1;
3340
+ const u = {
3341
+ batchRecord: e,
3342
+ mesh: h,
3343
+ boundsTree: void 0,
3344
+ raycastMesh: d,
3345
+ localMatrix: s.clone(),
3346
+ fullBoundingSphere: new ne(),
3347
+ materials: c,
3348
+ hasSourceTransparency: l,
3349
+ colorAttribute: r,
3350
+ opacityAttribute: a,
3351
+ renderedInstances: [],
3352
+ visibleInstances: [],
3353
+ lastCameraMatrixWorldInverse: new R(),
3354
+ lastCameraProjectionMatrix: new R(),
3355
+ lastViewportHeight: 0,
3356
+ hasLastCameraState: !1,
3357
+ dirty: !0
3358
+ };
3359
+ h.userData.getInstanceObjectByRenderIndex = (x) => u.renderedInstances[x], h.userData.raycastAcceleration = "lazy";
3360
+ const p = h.raycast.bind(h);
3361
+ return h.raycast = (x, I) => {
3362
+ if (this.#E(u), !this.#p(u, x)) return;
3363
+ u.boundsTree === void 0 && (u.boundsTree = jt(u.mesh.geometry), u.mesh.userData.raycastAcceleration = u.boundsTree ? "three-mesh-bvh" : "default");
3364
+ const _ = I.length;
3365
+ u.boundsTree ? this.#f(u, x, I) : p(x, I);
3366
+ for (let C = _; C < I.length; ) {
3367
+ const y = I[C], w = y.instanceId;
3368
+ if (w === void 0) {
3369
+ C++;
3370
+ continue;
3371
+ }
3372
+ const g = u.renderedInstances[w];
3373
+ if (!g || !De(g)) {
3374
+ I.splice(C, 1);
3375
+ continue;
3376
+ }
3377
+ y.object = g, y.instanceObject = g, y.instanceObjectId = g.instanceId, y.instanceKind = g.instanceKind || this.#l, y.instanceName = g.instanceName, y.instanceIndex = w, Object.assign(y, this.#d(g, w)), C++;
3378
+ }
3379
+ }, h.onBeforeRender = (x, I, _) => this.#E(u, x, _), e.batch.add(h), u;
3380
+ }
3381
+ #p(e, t) {
3382
+ const { mesh: s } = e;
3383
+ return s.count === 0 ? !1 : (s.boundingSphere === null && s.computeBoundingSphere(), s.boundingSphere ? (Dt.copy(s.boundingSphere).applyMatrix4(s.matrixWorld), t.ray.intersectsSphere(Dt)) : !0);
3384
+ }
3385
+ #f(e, t, s) {
3386
+ const { mesh: n, boundsTree: r, raycastMesh: a } = e;
3387
+ if (!(!r || n.count === 0)) {
3388
+ a.geometry = n.geometry, a.material = n.material;
3389
+ for (let o = 0; o < n.count; o++)
3390
+ n.getMatrixAt(o, Lt), Nt.multiplyMatrices(n.matrixWorld, Lt), a.matrixWorld.copy(Nt), ge.length = 0, r.raycastObject3D(a, t, ge), ge.forEach((c) => {
3391
+ c.instanceId = o, c.object = n, s.push(c);
3392
+ }), ge.length = 0;
3393
+ }
3394
+ }
3395
+ #M(e, t) {
3396
+ if (t <= e.capacity) return;
3397
+ e.capacity = Ut(t, e.capacity);
3398
+ const s = new Set(e.records);
3399
+ s.forEach((n) => this.#S(n)), this.#s = this.#s.filter((n) => !s.has(n)), e.records = e.templateMeshes.map(({ mesh: n, localMatrix: r }, a) => {
3400
+ const o = this.#h(e, n, r, a);
3401
+ return this.#s.push(o), o;
3402
+ }), this.#y(e);
3403
+ }
3404
+ #v(e, t) {
3405
+ const s = e.instances.indexOf(t);
3406
+ return s === -1 ? !1 : (e.instances.splice(s, 1), e.records.forEach((n) => n.visibleInstances.splice(s, 1)), this.#t.delete(t), this.#g(), e.unsubscribeByInstance.get(t)?.(), e.unsubscribeByInstance.delete(t), e.instances.length === 0 ? (this.#m(e), !0) : (this.#b(e), this.#y(e), !0));
3407
+ }
3408
+ #m(e) {
3409
+ e.unsubscribeByInstance.forEach((s) => s()), e.instances.forEach((s) => this.#t.delete(s)), e.unsubscribeByInstance.clear(), e.instances.length = 0, this.#g();
3410
+ const t = new Set(e.records);
3411
+ t.forEach((s) => this.#S(s)), this.#s = this.#s.filter((s) => !t.has(s)), e.records.length = 0, e.templateMeshes.length = 0, this.#a.delete(e.url), this.remove(e.batch);
3412
+ }
3413
+ #S(e) {
3414
+ e.batchRecord.batch.remove(e.mesh), e.mesh.dispose(), e.materials.forEach((t) => t.dispose());
3415
+ }
3416
+ #b(e) {
3417
+ Object.assign(e.batch.userData, {
3418
+ url: e.url,
3419
+ count: e.instances.length,
3420
+ capacity: e.capacity,
3421
+ instanceKind: this.#l
3422
+ }), delete e.batch.userData.sceneInstances, delete e.batch.userData.facilities, e.records.forEach((t) => {
3423
+ delete t.mesh.userData.instances;
3424
+ });
3425
+ }
3426
+ #C(e) {
3427
+ const t = new Set(e), s = /* @__PURE__ */ new Map();
3428
+ for (const r of e) {
3429
+ const { instanceId: a } = r;
3430
+ if (!a) continue;
3431
+ const o = s.get(a);
3432
+ if (o && o !== r) return !1;
3433
+ s.set(a, r);
3434
+ }
3435
+ let n = !0;
3436
+ return s.forEach((r, a) => {
3437
+ n && this.#i((o) => {
3438
+ !n || t.has(o) || o.instanceId === a && (n = !1);
3439
+ });
3440
+ }), n;
3441
+ }
3442
+ #w() {
3443
+ if (!this.#r) return;
3444
+ this.#e.clear();
3445
+ const e = /* @__PURE__ */ new Set();
3446
+ this.#i((t) => {
3447
+ const { instanceId: s } = t;
3448
+ if (!s || e.has(s)) return;
3449
+ const n = this.#e.get(s);
3450
+ if (n && n !== t) {
3451
+ this.#e.delete(s), e.add(s);
3452
+ return;
3453
+ }
3454
+ this.#e.set(s, t);
3455
+ }), this.#r = !1;
3456
+ }
3457
+ #g() {
3458
+ this.#r = !0;
3459
+ }
3460
+ #y(e) {
3461
+ e.records.forEach((t) => this.#I(t));
3462
+ }
3463
+ #I(e) {
3464
+ e.dirty = !0, e.hasLastCameraState = !1, e.mesh.visible = !0, e.mesh.frustumCulled = !1, ee(e.batchRecord.batch);
3465
+ }
3466
+ #E(e, t, s) {
3467
+ const n = this.#O(t), r = this.#B(e, s, n);
3468
+ !e.dirty && !this.#A(e) && !r || this.#N(e, s, n);
3469
+ }
3470
+ #A(e) {
3471
+ const { instances: t } = e.batchRecord;
3472
+ for (let s = 0; s < t.length; s++)
3473
+ if (e.visibleInstances[s] !== De(t[s]))
3474
+ return e.dirty = !0, ee(e.batchRecord.batch), !0;
3475
+ return !1;
3476
+ }
3477
+ #O(e) {
3478
+ return e?.getDrawingBufferSize ? (e.getDrawingBufferSize(_t), _t.y) : 0;
3479
+ }
3480
+ #B(e, t, s) {
3481
+ return this.#x(t, s) ? e.hasLastCameraState ? !Rt(e.lastCameraMatrixWorldInverse, t.matrixWorldInverse) || !Rt(e.lastCameraProjectionMatrix, t.projectionMatrix) || Math.abs(e.lastViewportHeight - s) > H : !0 : !1;
3482
+ }
3483
+ #x(e, t) {
3484
+ return this.#n && e !== void 0 && (this.#o || this.#c > 0 && t > 0);
3485
+ }
3486
+ #_(e, t) {
3487
+ if (!this.#x(e, t)) return null;
3488
+ let s = null;
3489
+ return this.#o && (Ct.multiplyMatrices(e.projectionMatrix, e.matrixWorldInverse), s = Or.setFromProjectionMatrix(Ct)), { camera: e, frustum: s, viewportHeight: t };
3490
+ }
3491
+ #T(e, t) {
3492
+ return t ? t.frustum && !t.frustum.intersectsSphere(e) ? !1 : this.#c <= 0 || t.viewportHeight <= 0 ? !0 : this.#L(e, t.camera, t.viewportHeight) >= this.#c : !0;
3493
+ }
3494
+ #L(e, t, s) {
3495
+ const n = Math.abs(t.projectionMatrix.elements[5]);
3496
+ if (n <= H) return 1 / 0;
3497
+ if (t.isOrthographicCamera)
3498
+ return e.radius * n * s * 0.5;
3499
+ Tt.copy(e.center).applyMatrix4(t.matrixWorldInverse);
3500
+ const r = -Tt.z;
3501
+ return r <= H ? 1 / 0 : e.radius * n * s * 0.5 / r;
3502
+ }
3503
+ #N(e, t, s = 0) {
3504
+ this.updateWorldMatrix(!0, !1), It.copy(this.matrixWorld).invert();
3505
+ const n = e.mesh.instanceMatrix.array, r = e.colorAttribute.array, a = e.opacityAttribute.array, o = e.mesh.geometry;
3506
+ let c = !1, l = !1, h = !1, d = 0, u = 0, p = !1;
3507
+ const x = e.mesh.count, I = this.#_(t, s);
3508
+ o.boundingSphere || o.computeBoundingSphere(), e.fullBoundingSphere.makeEmpty(), e.renderedInstances.length = 0, e.batchRecord.instances.forEach((y, w) => {
3509
+ const g = De(y);
3510
+ e.visibleInstances[w] = g, y.updateWorldMatrix(!0, !1), me.multiplyMatrices(It, y.matrixWorld).multiply(e.localMatrix);
3511
+ const m = y.getInstanceOpacity();
3512
+ if (!(g && m > H) || (u++, o.boundingSphere && (Ot.copy(o.boundingSphere).applyMatrix4(me), e.fullBoundingSphere.union(Ot), I && (Et.multiplyMatrices(y.matrixWorld, e.localMatrix), Bt.copy(o.boundingSphere).applyMatrix4(Et), !this.#T(Bt, I)))))
3513
+ return;
3514
+ const b = d, S = b * 16;
3515
+ _r(me, n, S) || (e.mesh.setMatrixAt(b, me), c = !0), Z.copy(y.getInstanceColor(Z));
3516
+ const A = y.getInstanceColorMode(), v = b * 4;
3517
+ Tr(Z, A, r, v) || (e.colorAttribute.setXYZW(b, Z.r, Z.g, Z.b, A), l = !0), m < cs && (p = !0), Math.abs(m - a[b]) > H && (e.opacityAttribute.setX(b, m), h = !0), e.renderedInstances[b] = y, d++;
3518
+ }), e.mesh.count = d, x !== d && (c = !0, l = !0, h = !0, ee(e.batchRecord.batch));
3519
+ const _ = u > 0;
3520
+ e.mesh.visible !== _ && (e.mesh.visible = _, ee(e.batchRecord.batch)), e.mesh.frustumCulled !== !0 && (e.mesh.frustumCulled = !0, ee(e.batchRecord.batch)), c && (e.mesh.instanceMatrix.needsUpdate = !0), l && (e.colorAttribute.needsUpdate = !0), h && (e.opacityAttribute.needsUpdate = !0), e.mesh.boundingSphere === null && (e.mesh.boundingSphere = new ne()), e.mesh.boundingSphere.copy(e.fullBoundingSphere);
3521
+ const C = e.hasSourceTransparency || p;
3522
+ e.materials.forEach((y) => {
3523
+ y.transparent !== C && (y.transparent = C, y.needsUpdate = !0, ee(e.batchRecord.batch));
3524
+ }), t && this.#x(t, s) ? (e.lastCameraMatrixWorldInverse.copy(t.matrixWorldInverse), e.lastCameraProjectionMatrix.copy(t.projectionMatrix), e.lastViewportHeight = s, e.hasLastCameraState = !0) : e.hasLastCameraState = !1, e.dirty = !1;
3525
+ }
3526
+ }
3527
+ const Ur = "0.0.31";
3528
+ typeof window < "u" && (window.__USPACE__ = { version: Ur });
2803
3529
  export {
2804
- Hn as AnnotationManager,
2805
- Ye as BaseGroup,
2806
- G as BaseMesh,
2807
- Vs as BaseSprite,
2808
- $n as CSS2DObject,
2809
- Kn as CSS3DObject,
2810
- Qn as CSS3DSprite,
2811
- Bs as CSSRenderer,
2812
- Ts as CameraControls,
2813
- zn as CircleMesh,
2814
- jn as ClippingTool,
2815
- Je as ExtrudeMesh,
2816
- vs as InteractionEvent,
2817
- bs as InteractionManager,
2818
- On as LightManager,
2819
- le as MaterialEffects,
2820
- Un as MeasureTool,
2821
- he as Model,
2822
- D as ModelLoaderManager,
2823
- xs as ObjectManager,
2824
- F as ObjectUtils,
2825
- Ln as PlaneMesh,
2826
- In as Poi,
2827
- Ss as RenderPipeline,
2828
- Es as RoomEnvironment,
2829
- Xs as SBMLoader,
2830
- Ls as SBMXLoader,
2831
- Pn as SceneManager,
2832
- En as Selection,
2833
- Ve as ShapeMesh,
2834
- Js as SphereMesh,
2835
- Nn as TSLEffects,
2836
- Bn as TextureLoaderManager,
2837
- Rn as Topology,
2838
- Ie as TubeMesh,
2839
- nn as Tween,
2840
- An as Viewer,
2841
- Dn as reinterpretType,
2842
- kn as tweenAnimation,
2843
- on as version
3530
+ mi as AnnotationManager,
3531
+ pe as BaseGroup,
3532
+ X as BaseMesh,
3533
+ Kn as BaseSprite,
3534
+ Li as CSS2DObject,
3535
+ Di as CSS3DObject,
3536
+ Pi as CSS3DSprite,
3537
+ vi as CSSRenderer,
3538
+ Si as CameraControls,
3539
+ li as CircleMesh,
3540
+ pi as ClippingTool,
3541
+ bi as EditableGeometryBatchLayer,
3542
+ Yt as ExtrudeMesh,
3543
+ wt as INSTANCE_COLOR_MODE_NONE,
3544
+ Ne as INSTANCE_COLOR_MODE_OVERRIDE,
3545
+ lr as INSTANCE_COLOR_MODE_TINT,
3546
+ gi as InstanceObject,
3547
+ Ii as InteractionEvent,
3548
+ Ei as InteractionManager,
3549
+ ri as LightManager,
3550
+ se as MaterialEffects,
3551
+ fi as MeasureTool,
3552
+ te as Model,
3553
+ $n as ModelDecodeWorkerClient,
3554
+ ve as ModelDecodeWorkerUnavailableError,
3555
+ wi as ModelInstancedLayer,
3556
+ V as ModelLoaderManager,
3557
+ Ci as ObjectManager,
3558
+ Q as ObjectUtils,
3559
+ ci as PlaneMesh,
3560
+ oi as Poi,
3561
+ Ai as RenderPipeline,
3562
+ Oi as RoomEnvironment,
3563
+ ct as SBMLoader,
3564
+ at as SBMXLoader,
3565
+ ni as SceneManager,
3566
+ si as Selection,
3567
+ Xt as ShapeMesh,
3568
+ qn as SphereMesh,
3569
+ hi as TSLEffects,
3570
+ ii as TextureLoaderManager,
3571
+ ai as Topology,
3572
+ lt as TubeMesh,
3573
+ ir as Tween,
3574
+ Bi as Viewer,
3575
+ _i as enableMeshBVHRaycast,
3576
+ jt as getGeometryBoundsTree,
3577
+ yi as isInstanceObject,
3578
+ di as reinterpretType,
3579
+ Hn as reuseDecodedImageContent,
3580
+ ui as tweenAnimation,
3581
+ Ur as version
2844
3582
  };