u-space 0.0.28 → 0.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/Viewer-BKNV67Jj.cjs +1 -0
- package/dist/Viewer-Cs_y7IiH.js +1256 -0
- package/dist/index.cjs +3 -3
- package/dist/index.js +1715 -1497
- package/dist/plugins/atmosphere/AgxToneMapping.d.ts +1 -1
- package/dist/plugins/atmosphere/index.cjs +1 -1
- package/dist/plugins/atmosphere/index.js +4 -4
- package/dist/plugins/curve-movement/index.cjs +1 -1
- package/dist/plugins/curve-movement/index.js +1 -1
- package/dist/plugins/fire/index.cjs +1 -1
- package/dist/plugins/fire/index.js +5 -5
- package/dist/plugins/object-controls/index.cjs +1 -1
- package/dist/plugins/object-controls/index.js +4 -4
- package/dist/plugins/tiles/index.cjs +1 -1
- package/dist/plugins/tiles/index.js +5 -5
- package/dist/plugins/u-manager/index.cjs +51 -51
- package/dist/plugins/u-manager/index.d.ts +1 -1
- package/dist/plugins/u-manager/index.js +8330 -8637
- package/dist/plugins/u-manager/loaders/SceneEditableBatchLayer.d.ts +17 -0
- package/dist/plugins/u-manager/loaders/SceneInstancedLayer.d.ts +3 -3
- package/dist/plugins/u-manager/loaders/SceneLoader.d.ts +20 -3
- package/dist/plugins/u-manager/loaders/UManagerLoader.d.ts +4 -4
- package/dist/plugins/u-manager/semantics/objects/BuildingGroup.d.ts +12 -5
- package/dist/plugins/u-manager/semantics/objects/FacilityInstancedLayer.d.ts +4 -4
- package/dist/plugins/u-manager/semantics/objects/FloorMesh.d.ts +28 -22
- package/dist/plugins/u-manager/semantics/objects/SemanticGroup.d.ts +6 -6
- package/dist/protocol-C-OMPz15.js +10 -0
- package/dist/protocol-IUAzx0lk.cjs +1 -0
- package/dist/src/batches/EditableGeometryBatchLayer.d.ts +50 -0
- package/dist/src/batches/ModelInstancedLayer.d.ts +42 -0
- package/dist/src/batches/index.d.ts +2 -0
- package/dist/src/effects/TSLEffects.d.ts +24 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/instances/InstanceObject.d.ts +57 -0
- package/dist/src/instances/index.d.ts +1 -0
- package/dist/src/interactions/MeshBVHRaycast.d.ts +9 -0
- package/dist/src/interactions/index.d.ts +1 -0
- package/dist/src/viewers/RenderPipeline.d.ts +37 -0
- package/dist/src/viewers/ReversedDepthSSGICompat.d.ts +10 -0
- package/dist/src/viewers/ReversedDepthSSRCompat.d.ts +20 -0
- package/dist/src/viewers/Viewer.d.ts +3 -1
- package/dist/src/viewers/renderInvalidation.d.ts +2 -0
- package/dist/src/worker/FrameTimingWindow.d.ts +16 -0
- package/dist/src/worker/OffscreenViewerHost.d.ts +20 -0
- package/dist/src/worker/WorkerDomTarget.d.ts +44 -0
- package/dist/src/worker/createWorkerViewer.d.ts +18 -0
- package/dist/src/worker/index.d.ts +2 -0
- package/dist/src/worker/installWorkerImageLoader.d.ts +5 -0
- package/dist/src/worker/protocol.d.ts +102 -0
- package/dist/src/worker/runtime.d.ts +2 -0
- package/dist/worker/index.cjs +1 -0
- package/dist/worker/index.js +224 -0
- package/dist/worker/runtime.cjs +1 -0
- package/dist/worker/runtime.js +418 -0
- package/docs/api-batches.md +112 -0
- package/docs/api-effects.md +2 -2
- package/docs/api-interactions.md +8 -0
- package/docs/api-managers.md +1 -1
- package/docs/api-objects.md +207 -0
- package/docs/api-plugin-u-manager.md +245 -96
- package/docs/api-render-pipeline.md +103 -5
- package/docs/api-viewer.md +188 -1
- package/docs/changelog.md +69 -6
- package/docs/examples-guide.md +111 -17
- package/docs/getting-started.md +1 -1
- package/docs/index.md +11 -4
- package/docs/mcp.md +29 -14
- package/docs/release.md +95 -0
- package/package.json +27 -4
- package/dist/plugins/u-manager/instances/SemanticInstanceObject.d.ts +0 -37
- package/dist/plugins/u-manager/instances/SemanticModelInstancedLayer.d.ts +0 -33
- package/dist/plugins/u-manager/instances/index.d.ts +0 -2
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("./Viewer-BKNV67Jj.cjs"),o=require("three/webgpu"),Ke=require("three/addons/loaders/GLTFLoader.js"),gt=require("three/addons/loaders/FBXLoader.js"),yt=require("three/addons/loaders/OBJLoader.js"),bt=require("three/addons/loaders/STLLoader.js"),xt=require("three/addons/loaders/DRACOLoader.js"),wt=require("three/addons/loaders/KTX2Loader.js"),ge=require("three/addons/libs/meshopt_decoder.module.js"),Mt=require("three/addons/loaders/HDRLoader.js"),pe=require("three/addons/utils/SkeletonUtils.js"),f=require("three/tsl"),St=require("three/addons/tsl/display/OutlineNode.js"),M=require("three/addons/libs/tween.module.js"),It=require("three/addons/utils/BufferGeometryUtils.js"),vt=require("three/addons/renderers/CSS2DRenderer.js"),qe=require("three/addons/renderers/CSS3DRenderer.js");class Et extends o.EventDispatcher{scene;camera;domElement;_container;_selected=new Set;_boxSelectionEnabled=!1;_isSelecting=!1;_startPoint=new o.Vector2;_endPoint=new o.Vector2;_selectionBox=null;_deep=!0;targetObjects=null;constructor(e,t,s){super(),this.domElement=e,this._container=e.parentElement??e,this.scene=t,this.camera=s}get selected(){return this._selected}get selectedArray(){return Array.from(this._selected)}select(e){const t=Array.isArray(e)?e:[e],s=[];for(const n of t)this._selected.has(n)||(this._selected.add(n),s.push(n));s.length>0&&(this.dispatchEvent({type:"select",objects:s}),this.dispatchEvent({type:"change",selected:this._selected}))}deselect(e){const t=Array.isArray(e)?e:[e],s=[];for(const n of t)this._selected.delete(n)&&s.push(n);s.length>0&&(this.dispatchEvent({type:"deselect",objects:s}),this.dispatchEvent({type:"change",selected:this._selected}))}toggle(e){this._selected.has(e)?this.deselect(e):this.select(e)}clear(){if(this._selected.size===0)return;const e=Array.from(this._selected);this._selected.clear(),this.dispatchEvent({type:"deselect",objects:e}),this.dispatchEvent({type:"change",selected:this._selected})}isSelected(e){return this._selected.has(e)}enableBoxSelection(e={}){this._boxSelectionEnabled||(this._boxSelectionEnabled=!0,this._deep=e.deep??!0,this._selectionBox=document.createElement("div"),this._selectionBox.style.cssText=`
|
|
2
2
|
position: absolute;
|
|
3
3
|
border: 1px dashed #55aaff;
|
|
4
4
|
background: rgba(75, 160, 255, 0.15);
|
|
5
5
|
pointer-events: none;
|
|
6
6
|
display: none;
|
|
7
7
|
z-index: 9999;
|
|
8
|
-
`,e.className&&(this._selectionBox.className=e.className),this._container.style.position=this._container.style.position||"relative",this._container.appendChild(this._selectionBox),this.domElement.addEventListener("pointerdown",this._onBoxPointerDown),this.domElement.addEventListener("pointermove",this._onBoxPointerMove),this.domElement.addEventListener("pointerup",this._onBoxPointerUp))}disableBoxSelection(){this._boxSelectionEnabled&&(this._boxSelectionEnabled=!1,this.domElement.removeEventListener("pointerdown",this._onBoxPointerDown),this.domElement.removeEventListener("pointermove",this._onBoxPointerMove),this.domElement.removeEventListener("pointerup",this._onBoxPointerUp),this._selectionBox&&(this._selectionBox.remove(),this._selectionBox=null))}setCamera(e){this.camera=e}_onBoxPointerDown=e=>{if(e.button!==0)return;this._isSelecting=!0;const t=this._container.getBoundingClientRect();this._startPoint.set(e.clientX-t.left,e.clientY-t.top),this._endPoint.copy(this._startPoint),this._selectionBox&&(this._selectionBox.style.display="block",this._updateBoxElement())};_onBoxPointerMove=e=>{if(!this._isSelecting)return;const t=this._container.getBoundingClientRect();this._endPoint.set(e.clientX-t.left,e.clientY-t.top),this._updateBoxElement()};_onBoxPointerUp=()=>{if(!this._isSelecting)return;this._isSelecting=!1,this._selectionBox&&(this._selectionBox.style.display="none");const e=this._getObjectsInBox();this.clear(),e.length>0&&this.select(e)};_updateBoxElement(){if(!this._selectionBox)return;const e=Math.min(this._startPoint.x,this._endPoint.x),t=Math.min(this._startPoint.y,this._endPoint.y),s=Math.abs(this._endPoint.x-this._startPoint.x),n=Math.abs(this._endPoint.y-this._startPoint.y);this._selectionBox.style.left=`${e}px`,this._selectionBox.style.top=`${t}px`,this._selectionBox.style.width=`${s}px`,this._selectionBox.style.height=`${n}px`}_getObjectsInBox(){const e=this._container.getBoundingClientRect(),t=e.width,s=e.height,n=new r.Vector2(this._startPoint.x/t*2-1,-(this._startPoint.y/s)*2+1),i=new r.Vector2(this._endPoint.x/t*2-1,-(this._endPoint.y/s)*2+1),a=new r.Box2(new r.Vector2(Math.min(n.x,i.x),Math.min(n.y,i.y)),new r.Vector2(Math.max(n.x,i.x),Math.max(n.y,i.y))),o=this.targetObjects||this.scene.children,c=[],l=new r.Matrix4;l.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse);const d=u=>{if(!u.visible)return;const m=new r.Vector3;if(m.setFromMatrixPosition(u.matrixWorld),m.applyMatrix4(l),m.z>-1&&m.z<1&&a.containsPoint(new r.Vector2(m.x,m.y))&&c.push(u),this._deep)for(const g of u.children)d(g)};for(const u of o)d(u);return c}dispose(){this.disableBoxSelection(),this._selected.clear()}}function $(h,e){const t=h;if(t.setSemanticVisible){t.setSemanticVisible(e);return}h.visible=e,t.markSemanticRenderDirty?.()}class ue{idMap=new Map;nameMap=new Map;typeMap=new Map;objectIds=new Map;allObjects=new Set;add(e,t){if(this.idMap.has(e)){console.warn(`ObjectManager: Object with id ${e} already exists.`);return}this.idMap.set(e,t),this.allObjects.add(t),this.objectIds.has(t)||this.objectIds.set(t,new Set),this.objectIds.get(t).add(e),t.name&&(this.nameMap.has(t.name)||this.nameMap.set(t.name,new Set),this.nameMap.get(t.name).add(t)),t.type&&(this.typeMap.has(t.type)||this.typeMap.set(t.type,new Set),this.typeMap.get(t.type).add(t))}getById(e){return this.idMap.get(e)}getByName(e){return this.nameMap.get(e)||new Set}getByType(e){return this.typeMap.get(e)||new Set}getObjectIds(e){return this.objectIds.get(e)||new Set}remove(e){const t=this.objectIds.get(e);if(t){for(const s of t)this.idMap.delete(s);this.objectIds.delete(e)}if(e.name&&this.nameMap.has(e.name)){const s=this.nameMap.get(e.name);s.delete(e),s.size===0&&this.nameMap.delete(e.name)}if(e.type&&this.typeMap.has(e.type)){const s=this.typeMap.get(e.type);s.delete(e),s.size===0&&this.typeMap.delete(e.type)}this.allObjects.delete(e)}removeById(e){const t=this.idMap.get(e);t&&this.remove(t)}removeByName(e){const t=this.getByName(e);for(const s of t)this.remove(s)}removeByType(e){const t=this.getByType(e);for(const s of t)this.remove(s)}clear(){this.idMap.clear(),this.nameMap.clear(),this.typeMap.clear(),this.objectIds.clear(),this.allObjects.clear()}getAll(){return this.allObjects}get size(){return this.allObjects.size}show(e){const t=this.idMap.get(e);t&&$(t,!0)}hide(e){const t=this.idMap.get(e);t&&$(t,!1)}isolate(e){const t=new Set(e);for(const s of this.allObjects){const n=this.objectIds.get(s)??new Set;$(s,[...n].some(i=>t.has(i)))}}setOpacity(e,t){const s=this.idMap.get(e);if(!s)return;const n=s;if(n.setSemanticOpacity){n.setSemanticOpacity(t);return}s.traverse(i=>{if(!i.isMesh)return;const a=i.material;if(!a)return;const o=Array.isArray(a)?a:[a];for(const c of o)c.transparent=t<1,c.opacity=t,c.needsUpdate=!0})}getBoundingBox(e){const t=new r.Box3;if(e){const s=this.idMap.get(e);s&&t.setFromObject(s)}else for(const s of this.allObjects)t.expandByObject(s);return t}forEach(e){for(const t of this.allObjects){const s=this.objectIds.get(t)||new Set;e(t,s)}}filter(e){const t=[];for(const s of this.allObjects)e(s)&&t.push(s);return t}showAll(){for(const e of this.allObjects)$(e,!0)}}class We{scenes=new Map;_activeSceneKey=null;add(e,t){this.scenes.set(e,t)}create(e,t={}){const s=new r.Scene;return t.background!==void 0&&(s.background=new r.Color(t.background)),this.scenes.set(e,s),s}get(e){return this.scenes.get(e)}remove(e){this.scenes.delete(e),this._activeSceneKey===e&&(this._activeSceneKey=null)}get activeKey(){return this._activeSceneKey}set activeKey(e){this._activeSceneKey=e}keys(){return Array.from(this.scenes.keys())}serialize(e){const t=this.scenes.get(e);if(!t)return null;let s=null;return t.background instanceof r.Color&&(s=`#${t.background.getHexString()}`),{name:t.name||e,background:s,environmentRotation:{x:t.environmentRotation?.x??0,y:t.environmentRotation?.y??0,z:t.environmentRotation?.z??0},children:t.children.map(n=>n.name||n.uuid)}}clear(){this.scenes.clear(),this._activeSceneKey=null}get size(){return this.scenes.size}}class qe{scene;lights=new Map;helpers=new Map;constructor(e){this.scene=e}addAmbient(e,t={}){const{color:s=16777215,intensity:n=.5}=t,i=new r.AmbientLight(s,n);return i.name=e,this._register(e,i),i}addDirectional(e,t={}){const{color:s=16777215,intensity:n=1,position:i={x:5,y:10,z:5},castShadow:a=!1,shadowMapSize:o=1024}=t,c=new r.DirectionalLight(s,n);return c.position.set(i.x,i.y,i.z),c.castShadow=a,a&&c.shadow.mapSize.setScalar(o),c.name=e,this._register(e,c),c}addPoint(e,t={}){const{color:s=16777215,intensity:n=1,distance:i=0,decay:a=2,position:o={x:0,y:5,z:0},castShadow:c=!1}=t,l=new r.PointLight(s,n,i,a);return l.position.set(o.x,o.y,o.z),l.castShadow=c,l.name=e,this._register(e,l),l}addSpot(e,t={}){const{color:s=16777215,intensity:n=1,distance:i=0,angle:a=Math.PI/6,penumbra:o=.1,decay:c=2,position:l={x:0,y:10,z:0},target:d,castShadow:u=!1}=t,m=new r.SpotLight(s,n,i,a,o,c);return m.position.set(l.x,l.y,l.z),d&&m.target.position.set(d.x,d.y,d.z),m.castShadow=u,m.name=e,this._register(e,m),m}addHemisphere(e,t={}){const{skyColor:s=8900331,groundColor:n=3549447,intensity:i=.6}=t,a=new r.HemisphereLight(s,n,i);return a.name=e,this._register(e,a),a}applyPreset(e){switch(this.removeAll(),e){case"indoor":this.addAmbient("preset_ambient",{intensity:.4}),this.addPoint("preset_point1",{position:{x:0,y:3,z:0},intensity:1,castShadow:!0}),this.addPoint("preset_point2",{position:{x:3,y:2,z:-3},intensity:.5});break;case"outdoor":this.addHemisphere("preset_hemi",{skyColor:8900331,groundColor:3549447,intensity:.6}),this.addDirectional("preset_sun",{position:{x:10,y:20,z:10},intensity:1.5,castShadow:!0,shadowMapSize:2048});break;case"studio":this.addAmbient("preset_ambient",{intensity:.3}),this.addDirectional("preset_key",{position:{x:5,y:8,z:5},intensity:1.2,castShadow:!0}),this.addDirectional("preset_fill",{position:{x:-5,y:5,z:-2},intensity:.6}),this.addDirectional("preset_back",{position:{x:0,y:5,z:-8},intensity:.4});break;case"warehouse":this.addAmbient("preset_ambient",{intensity:.2}),this.addPoint("preset_light1",{position:{x:-5,y:6,z:-5},intensity:2,distance:20}),this.addPoint("preset_light2",{position:{x:5,y:6,z:-5},intensity:2,distance:20}),this.addPoint("preset_light3",{position:{x:-5,y:6,z:5},intensity:2,distance:20}),this.addPoint("preset_light4",{position:{x:5,y:6,z:5},intensity:2,distance:20});break}}get(e){return this.lights.get(e)}remove(e){const t=this.lights.get(e);t&&(this.scene.remove(t),this.lights.delete(e)),this.hideHelper(e)}removeAll(){const e=Array.from(this.lights.keys());for(const t of e)this.remove(t)}showHelper(e){if(this.helpers.has(e))return;const t=this.lights.get(e);if(!t)return;let s=null;t instanceof r.DirectionalLight?s=new r.DirectionalLightHelper(t,1):t instanceof r.PointLight?s=new r.PointLightHelper(t,.5):t instanceof r.SpotLight?s=new r.SpotLightHelper(t):t instanceof r.HemisphereLight&&(s=new r.HemisphereLightHelper(t,1)),s&&(this.scene.add(s),this.helpers.set(e,s))}hideHelper(e){const t=this.helpers.get(e);t&&(this.scene.remove(t),this.helpers.delete(e))}showAllHelpers(){for(const[e]of this.lights)this.showHelper(e)}hideAllHelpers(){const e=Array.from(this.helpers.keys());for(const t of e)this.hideHelper(t)}_register(e,t){this.lights.has(e)&&this.remove(e),this.lights.set(e,t),this.scene.add(t)}dispose(){this.removeAll(),this.hideAllHelpers()}}class pe extends r.RenderPipeline{scene;camera;scenePass;needsUpdateOutputNode;#t;#e;#s=!1;#r={strength:1,radius:0,threshold:0};#n=null;#a=!1;#o={sliceCount:1,stepCount:12,aoIntensity:1,giIntensity:10,radius:12,thickness:1};#u=null;#l=!1;#h=null;#p=null;#d;#c;#m=!1;#g=!0;constructor(...e){const[t,s,n]=e;super(t),this.scene=s,this.camera=n,this.scenePass=p.pass(s,n),this.needsUpdateOutputNode=!0,this.#t=new Set,this.#e=[],this.#d=new Set,this.#c=new Map,this.#f()}get currentOutputNode(){return this.scenePass}addOverlayPass(e){this.#t.add(e),this.needsUpdateOutputNode=!0}removeOverlayPass(e){this.#t.delete(e),this.needsUpdateOutputNode=!0}setCamera(e){this.camera=e,this.#i()}setCurrentOutputNode(e){this.setOutputComposer(()=>e)}resetCurrentOutputNode(){this.setOutputComposer(null)}setOutputComposer(e){this.#p=e,this.needsUpdateOutputNode=!0}addOutputEffect(e){return this.#d.add(e),this.needsUpdateOutputNode=!0,this}removeOutputEffect(e){return this.#d.delete(e),this.needsUpdateOutputNode=!0,this}addMRTChannel(e,t){return this.#c.get(e)===t?this:(this.#c.set(e,t),this.#i(),this)}removeMRTChannel(e){return this.#c.delete(e)&&this.#i(),this}enableBloom(e){e&&Object.assign(this.#r,e),this.#s=!0,this.#i()}disableBloom(){this.#s=!1,this.#n=null,this.#i()}updateBloom(e){Object.assign(this.#r,e),this.#s&&(this.needsUpdateOutputNode=!0)}enableSSGI(e){e&&Object.assign(this.#o,e),this.#a=!0,this.#i()}disableSSGI(){this.#a=!1,this.#u=null,this.#i()}updateSSGI(e){if(Object.assign(this.#o,e),this.#u){const t=this.#u;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)}}enableTRAA(){this.#l=!0,this.#i()}disableTRAA(){this.#l=!1,this.#h=null,this.#i()}#i(){const e=this.scenePass;this.scenePass=p.pass(this.scene,this.camera),this.#f(),this.needsUpdateOutputNode=!0,e.dispose()}#f(){if(this.#s||this.#a||this.#l||this.#c.size>0){const t={output:p.output};this.#c.forEach((s,n)=>{n!=="output"&&(t[n]=s)}),this.#s&&(t.emissive=p.emissive),this.#a&&(t.normal=p.normalView),this.#l&&(t.velocity=p.velocity),this.scenePass.setMRT(p.mrt(t))}}#y(){for(const e of this.#e)e.dispose();this.#e=[]}#w(){let e=this.scenePass.getTextureNode();if(this.#a)if(!(this.camera instanceof r.PerspectiveCamera))console.warn("RenderPipeline: SSGI requires a PerspectiveCamera, skipping.");else{const t=this.scenePass.getTextureNode(),s=this.scenePass.getTextureNode("depth"),n=this.scenePass.getTextureNode("normal"),i=Ie.ssgi(t,s,n,this.camera);i.sliceCount.value=this.#o.sliceCount,i.stepCount.value=this.#o.stepCount,i.aoIntensity.value=this.#o.aoIntensity,i.giIntensity.value=this.#o.giIntensity,i.radius.value=this.#o.radius,i.thickness.value=this.#o.thickness,this.#u=i,e=p.add(e,i),this.#e.push(i)}if(this.#s){const t=this.scenePass.getTextureNode("emissive");this.#n=Re.bloom(t,this.#r.strength,this.#r.radius,this.#r.threshold),e=p.add(e,this.#n),this.#e.push(this.#n)}return e}#v(e){e?(this.#m||(this.#g=this.outputColorTransform),this.outputColorTransform=!1):this.#m&&(this.outputColorTransform=this.#g),this.#m=e}#b(){this.#y();let e,t=!1,s=!1;const n=this.#p!==null;if(n?e=this.#p(this.scenePass):this.#s||this.#a?e=this.#w():e=this.#d.size>0?this.scenePass.getTextureNode():this.scenePass,n||this.#d.forEach(i=>{t||=i.includesTemporalAntialias===!0,s||=i.includesOutputTransform===!0,e=i(this.scenePass,e)}),this.#v(s),this.#l&&!t){const i=this.scenePass.getTextureNode("depth"),a=this.scenePass.getTextureNode("velocity");this.#h=De.traa(e,i,a,this.camera),this.#e.push(this.#h),e=this.#h}else this.#h=null;this.#t.size>0&&this.#t.forEach(i=>{const a=p.blendColor(e,i);this.#e.push(a),e=a}),this.outputNode=e,this.needsUpdate=!0}render(){this.needsUpdateOutputNode&&(this.#b(),this.needsUpdateOutputNode=!1),super.render()}dispose(){this.#y(),this.scenePass.dispose(),super.dispose()}}const Ke={Vector2:r.Vector2,Vector3:r.Vector3,Vector4:r.Vector4,Quaternion:r.Quaternion,Matrix4:r.Matrix4,Spherical:r.Spherical,Box3:r.Box3,Sphere:r.Sphere,Raycaster:r.Raycaster};ce.install({THREE:Ke});class me extends ce{constructor(...e){super(...e),this.minDistance=.2,this.smoothTime=.2,this.dollySpeed=.2}absoluteRotations(){this.azimuthAngle=Qe(this.azimuthAngle,0)}async flyToBox(e,t={}){if(e.isEmpty())return console.warn("CameraControls.flyToBox: The provided Box3 is empty."),!1;this.absoluteRotations();const{viewpoint:s="frontTop",enableTransition:n=!0,padding:i=.1,cover:a=!1}=t,o=[];if(s!=="current"){const c=ne[s.toUpperCase()]??ne.FRONTTOP,l=c.theta,d=c.phi;o.push(this.fitToBox(e,n,{paddingLeft:i,paddingRight:i,paddingTop:i,paddingBottom:i,cover:a})),o.push(this.rotateTo(l,d,n))}else{const c=new r.Sphere;e.getBoundingSphere(c),c.radius+=i,o.push(this.fitToSphere(c,n))}return await Promise.all(o),!0}async flyToObject(e,t={}){const s=new r.Box3().setFromObject(e);return this.flyToBox(s,t)}async flyTo(e,t,s={}){const{enableTransition:n=!0}=s;return this.absoluteRotations(),this.setLookAt(e.x,e.y,e.z,t.x,t.y,t.z,n)}getCameraViewpoint(){const e=new r.Vector3,t=new r.Vector3;return this.getPosition(e),this.getTarget(t),{position:{x:e.x,y:e.y,z:e.z},target:{x:t.x,y:t.y,z:t.z},zoom:this.camera.zoom}}lock(){this.enabled=!1}unlock(){this.enabled=!0}async setViewMode(e,t=!0){if(e==="2d"){const s=new r.Vector3;this.getTarget(s),await this.rotateTo(0,0,t),this.minPolarAngle=0,this.maxPolarAngle=0}else this.minPolarAngle=0,this.maxPolarAngle=Math.PI,await this.rotateTo(0,Math.PI/4,t)}async setCameraViewpoint(e,t=!0){const{position:s,target:n,zoom:i=this.camera.zoom}=e;return Promise.all([this.zoomTo(i,t),this.setLookAt(s.x,s.y,s.z,n.x,n.y,n.z,t)])}}const ne={LEFT:new r.Spherical(0,Math.PI/2,-Math.PI/2),RIGHT:new r.Spherical(0,Math.PI/2,Math.PI/2),FRONT:new r.Spherical(0,Math.PI/2,0),BACK:new r.Spherical(0,Math.PI/2,Math.PI),TOP:new r.Spherical(0,0,0),BOTTOM:new r.Spherical(0,Math.PI,0),FRONTTOP:new r.Spherical(0,Math.PI/4,0),BACKTOP:new r.Spherical(0,Math.PI/4,Math.PI),LEFTTOP:new r.Spherical(0,Math.PI/4,-Math.PI/2),RIGHTTOP:new r.Spherical(0,Math.PI/4,Math.PI/2),LEFTFRONTTOP:new r.Spherical(0,Math.PI/4,-Math.PI/4),RIGHTFRONTTOP:new r.Spherical(0,Math.PI/4,Math.PI/4),LEFTBACKTOP:new r.Spherical(0,Math.PI/4,-Math.PI/4*3),RIGHTBACKTOP:new r.Spherical(0,Math.PI/4,Math.PI/4*3)};function Qe(h,e){const t=h-e;return r.MathUtils.euclideanModulo(t+Math.PI,Math.PI*2)-Math.PI}class ge{environment=new Ne.RoomEnvironment;renderer;pmremGenerator;envMap=null;constructor(e){this.renderer=e,this.pmremGenerator=new r.PMREMGenerator(e)}update(){this.envMap||(this.envMap=this.pmremGenerator.fromScene(this.environment).texture)}dispose(){this.pmremGenerator.dispose(),this.envMap?.dispose()}}const W=128;class Xe extends ze.ViewHelper{viewer;overlayPass;constructor(e){super(e.camera,e.el),this.viewer=e;const t=new r.OrthographicCamera(-2,2,2,-2,0,4);t.position.set(0,0,2),this.overlayPass=p.pass(this,t),this.setLabels("x","y","z")}_update=()=>{this.quaternion.copy(this.viewer.camera.quaternion).invert();const e=this.location;let t,s;e.left!==null?t=e.left:t=this.viewer.el.offsetWidth-W-e.right,e.top!==null?s=e.top:s=this.viewer.el.offsetHeight-W-e.bottom,this.overlayPass.setViewport(t,s,W,W)};enable(){return this.viewer.renderPipeline.addOverlayPass(this.overlayPass),this.viewer.addEventListener("beforeRender",this._update),this.viewer.render(),this}disable(){return this.viewer.renderPipeline.removeOverlayPass(this.overlayPass),this.viewer.removeEventListener("beforeRender",this._update),this.viewer.render(),this}}const fe="position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;overflow:hidden;",Ye=fe+"z-index:0;",Je=fe+"z-index:1;";class ye{el;css2dRenderer=null;css3dRenderer=null;constructor(e){this.el=e,getComputedStyle(e).position==="static"&&(e.style.position="relative")}initCSS2DRenderer(){const e=new Y.CSS2DRenderer;return e.setSize(this.el.clientWidth,this.el.clientHeight),e.domElement.style.cssText=Je,this.el.appendChild(e.domElement),this.css2dRenderer=e,e}initCSS3DRenderer(){const e=new k.CSS3DRenderer;return e.setSize(this.el.clientWidth,this.el.clientHeight),e.domElement.style.cssText=Ye,this.el.appendChild(e.domElement),this.css3dRenderer=e,e}createCSS2DObject(e){return this.css2dRenderer||this.initCSS2DRenderer(),new Y.CSS2DObject(e)}createCSS25DObject(e){return this.css3dRenderer||this.initCSS3DRenderer(),new k.CSS3DSprite(e)}createCSS3DObject(e){return this.css3dRenderer||this.initCSS3DRenderer(),new k.CSS3DObject(e)}render(e,t){this.css2dRenderer&&this.css2dRenderer.render(e,t),this.css3dRenderer&&this.css3dRenderer.render(e,t)}resize(e,t){this.css2dRenderer&&this.css2dRenderer.setSize(e,t),this.css3dRenderer&&this.css3dRenderer.setSize(e,t)}dispose(){this.css2dRenderer&&(this.el.removeChild(this.css2dRenderer.domElement),this.css2dRenderer=null),this.css3dRenderer&&(this.el.removeChild(this.css3dRenderer.domElement),this.css3dRenderer=null)}}const Ze="timestamp-query";class et{el;renderer;container;drawCallsText;frameCallsText;trianglesText;pointsText;linesText;timestampText;_enabled=!1;#t=!1;constructor(e,t){this.el=e,this.renderer=t;const s=document.createElement("div");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;function n(a,o=!0){const c=document.createElement("span");return o&&(c.style.marginLeft="6px"),c.innerText=a,c}function i(){return document.createElement("br")}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())}update(){if(this._enabled){const{render:e}=this.renderer.info;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){this.timestampText.innerText="0";return}this.#n(r.TimestampQuery.RENDER).then(t=>{this._enabled&&(this.timestampText.innerText=t?.toFixed(2)??"0")}),this.#n(r.TimestampQuery.COMPUTE)}}enable(){this._enabled=!0,this.#r(!0),this.el.appendChild(this.container)}disable(){this._enabled=!1,this.#r(!1),this.#a(),this.container.remove()}dispose(){this.disable()}#e(){return this.renderer.backend}#s(){try{return this.renderer.hasFeature(Ze)}catch{return!0}}#r(e){const t=this.#e();if(!t){this.#t=!1;return}t.trackTimestamp=e&&this.#s(),this.#t=t.trackTimestamp===!0}#n(e){const t=this.#e()?.timestampQueryPool?.[e];return t?.resolveQueriesAsync?Promise.resolve(t.resolveQueriesAsync()).catch(()=>{}):Promise.resolve(void 0)}#a(){this.#n(r.TimestampQuery.RENDER),this.#n(r.TimestampQuery.COMPUTE)}}r.Cache.enabled=!0;class tt extends r.EventDispatcher{el;renderer;scene;camera;info;controls;renderPipeline;timer;roomEnvironment;interactionManager;objectManager;viewerHelper;cssRenderer;frameCount=1;frameloop="demand";constructor({el:e,rendererOptions:t}){super(),this.el=e,this.renderer=this._initRenderer(t),this.scene=this.createScene(),this.camera=this.createPerspectiveCamera(),this.info=new et(this.el,this.renderer),this.controls=new me(this.camera,this.renderer.domElement),this.renderPipeline=new pe(this.renderer,this.scene,this.camera),this.timer=new r.Timer,this.roomEnvironment=new ge(this.renderer),this.interactionManager=new de(this.renderer.domElement,this.scene,this.camera),this.objectManager=new ue,this.viewerHelper=new Xe(this),this.cssRenderer=new ye(this.el),window.addEventListener("resize",this.onWindowResize)}onWindowResize=()=>{const e=this.el.clientWidth,t=this.el.clientHeight;this.camera instanceof r.PerspectiveCamera?(this.camera.aspect=e/t,this.camera.updateProjectionMatrix()):this.camera instanceof r.OrthographicCamera&&(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()};async init(){await this.renderer.init(),this.roomEnvironment.update(),this.scene.environment=this.roomEnvironment.envMap}setCamera(e){this.camera=e,this.controls.camera=e,this.interactionManager.setCamera(e),this.renderPipeline.setCamera(e),this.onWindowResize(),this.dispatchEvent({type:"cameraChange",camera:e})}setCameraByType(e){e==="perspective"&&!(this.camera instanceof r.PerspectiveCamera)?this.setCamera(this.createPerspectiveCamera()):e==="orthographic"&&!(this.camera instanceof r.OrthographicCamera)&&this.setCamera(this.createOrthographicCamera())}render(e=1){return this.frameCount+=e,new Promise(t=>{const s=()=>{this.removeEventListener("afterRender",s),t()};this.addEventListener("afterRender",s)})}animate=e=>{this.timer.update(e);const t=this.timer.getDelta();this.dispatchEvent({type:"beforeControlsUpdate",time:e,delta:t});let s=this.controls.update(t);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}))};_initRenderer(e){const t=new r.WebGPURenderer({reversedDepthBuffer:!0,antialias:!1,depth:!1,trackTimestamp:!1,...e});return t.setSize(this.el.clientWidth,this.el.clientHeight),t.shadowMap.enabled=!0,t.shadowMap.type=r.PCFShadowMap,t.toneMapping=r.AgXToneMapping,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}createScene(){const e=new r.Scene;return e.background=new r.Color(0),e}createPerspectiveCamera(){const e=new r.PerspectiveCamera(50,this.el.clientWidth/this.el.clientHeight,.1,1e5);return e.position.setScalar(5),e}createOrthographicCamera(){const e=new r.OrthographicCamera(-this.el.clientWidth/2,this.el.clientWidth/2,this.el.clientHeight/2,-this.el.clientHeight/2,.1,1e5);return e.position.setScalar(5),e}resize(e,t){e!==void 0&&t!==void 0&&(this.el.style.width=`${e}px`,this.el.style.height=`${t}px`),this.onWindowResize()}async screenshot(e={}){const{type:t="image/png",quality:s=1}=e,n=this.el.clientWidth,i=this.el.clientHeight,a=e.width&&e.height;a&&this.renderer.setSize(e.width,e.height),await this.render();const o=this.renderer.domElement.toDataURL(t,s);return a&&(this.renderer.setSize(n,i),this.onWindowResize()),o}setBackground(e){e===null?this.scene.background=null:e instanceof r.Color||typeof e=="number"||typeof e=="string"?this.scene.background=new r.Color(e):this.scene.background=e,this.render()}setEnvironment(e){this.scene.environment=e,this.render()}enableShadow(){this.renderer.shadowMap.enabled=!0,this.render()}disableShadow(){this.renderer.shadowMap.enabled=!1,this.render()}enableFog(e={}){const{color:t=13421772,near:s=10,far:n=100}=e;this.scene.fog=new r.Fog(t,s,n),this.render()}enableFogExp2(e={}){const{color:t=13421772,density:s=.01}=e;this.scene.fog=new r.FogExp2(t,s),this.render()}disableFog(){this.scene.fog=null,this.render()}dispose(){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()}}class we extends le.GLTFLoader{constructor(e){super(e)}parse(e,t,s,n){if(st(e.slice(0,8))==="SBMG----"){const a=nt(e.slice(8));return super.parse(a,t,s,n)}else return super.parse(e,t,s,n)}}function st(h){return new TextDecoder().decode(new Uint8Array(h))}function nt(h){const e=new DataView(h);for(let t=0;t<e.byteLength;t++){const s=e.getUint8(t),n=(s>>4&15)+(s<<4&240);e.setUint8(t,n)}return e.buffer}const it=8,rt=130,ie=66,at="SBK-----",ot="SBM-----",ve=new TextDecoder,ct=new TextEncoder;function lt(h){let e=it;const t=new Uint8Array(h,0,e);if(ve.decode(t)!==at)return h;e+=rt;const n=new Uint8Array(h,0,e);if(n[40]===1){const a=ct.encode(ot),o=new Uint8Array([n[41]]),c=ht(n),l=dt(c);let d=ie%l.length;const u=e+ie,m=new Uint8Array(h,u),g=new Uint8Array(m.length);for(let b=0;b<m.length;b++)g[b]=m[b]^l[d],d=(d+1)%l.length;const f=new Uint8Array(a.length+o.length+g.length);return f.set(a),f.set(o,a.length),f.set(g,a.length+o.length),f.buffer}}function ht(h){const e=new Uint8Array(128);return e.set(h.slice(42,74),0),e.set(h.slice(74,138),32),e.set(h.slice(8,40),96),e}function dt(h){const e=new Uint8Array(64);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}const ut=(h,e,t)=>{const s=h.buffer.slice(t,t+e);let n=ve.decode(s);return n=n.replace("\\","/"),n.startsWith("Maps/")||(n=`Maps/${n}`),n},pt=(h,e,t)=>{const[s,n,i,a,o]=e,c=t||a<1;return new r.MeshStandardNodeMaterial({name:h,color:new r.Color(s,n,i),opacity:a,transparent:c,alphaTest:.01,side:o})},mt=h=>h?.toLowerCase().endsWith(".png")??!1;class gt{data;options;textureLoader;littleEndian=!0;materials=new Map;constructor(e,t){this.data=e,this.options=t,this.textureLoader=new r.TextureLoader(t.manager),this.textureLoader.setCrossOrigin(t.crossOrigin),this.textureLoader.setRequestHeader(t.requestHeader)}parse(e,t){let s=this.data;const n=lt(this.data);n&&(s=n);const i=new DataView(s);let a=8;const o=i.getUint8(a);a+=1,o===1?this._parseV2(i,a,e):o===2?this._parseV2(i,a,e):o===3?this._parseV3(i,a,e):t?.(new Error(`SBMLoader: Unsupported SBM version: ${o}`))}_parseV2(e,t,s){const n=new r.Group,i=e.getUint16(t,this.littleEndian);t+=2;const a=e.getUint16(t,this.littleEndian);t+=2;for(let o=0;o<i;++o){const c=e.getUint16(t,this.littleEndian).toString();t+=2,t+=4,t+=4,t+=4,t+=4;const l=e.getFloat32(t,this.littleEndian);t+=4;const d=e.getFloat32(t,this.littleEndian);t+=4;const u=e.getFloat32(t,this.littleEndian);t+=4;const m=e.getFloat32(t,this.littleEndian);t+=4,t+=4,t+=4,t+=4,t+=4;let g=e.getUint8(t);t+=1,g===0?g=r.FrontSide:g===1?g=r.BackSide:g===2&&(g=r.DoubleSide);const f=e.getUint16(t,this.littleEndian);t+=2;const b=f>0?ut(e,f,t):"";if(t+=f,!this.materials.has(c)){const S=pt(c,[l,d,u,m,g],mt(b));this.materials.set(c,S),b&&this.options.path&&this.textureLoader.load(r.LoaderUtils.resolveURL(b,this.options.path),v=>{v.colorSpace=r.SRGBColorSpace,v.wrapS=r.RepeatWrapping,v.wrapT=r.RepeatWrapping,v.flipY=!1,v.anisotropy=16,S.map=v})}}for(let o=0;o<a;++o){const c=e.getUint16(t,this.littleEndian).toString();t+=2;const l=e.getUint16(t,this.littleEndian).toString();t+=2;const d=[],u=[],m=[],g=[],f=e.getUint16(t,this.littleEndian);if(t+=2,f>0)for(let w=0;w<f;w++){const x=new r.Vector3;x.setX(e.getFloat32(t,this.littleEndian)),t+=4,x.setY(e.getFloat32(t,this.littleEndian)),t+=4,x.setZ(e.getFloat32(t,this.littleEndian)),t+=4,d.push(x)}const b=e.getUint16(t,this.littleEndian);if(t+=2,b>0)for(let w=0;w<b;w++)t+=4,t+=4,t+=4;const C=e.getUint16(t,this.littleEndian);if(t+=2,C>0)for(let w=0;w<C;w++){const x=new r.Vector2;x.setX(e.getFloat32(t,this.littleEndian)),t+=4,x.setY(e.getFloat32(t,this.littleEndian)),t+=4,u.push(x)}const S=e.getUint16(t,this.littleEndian);if(t+=2,S>0)for(let w=0;w<S;w++){const x=e.getUint16(t,this.littleEndian);t+=2;const L=e.getUint16(t,this.littleEndian);t+=2;const B=e.getUint16(t,this.littleEndian);t+=2;const T=[x,L,B];m.push(T),u.length>0&&g.push([u[T[0]],u[T[1]],u[T[2]]])}const v=[],M=[];for(let w=0;w<m.length;w++){const x=m[w],L=d[x[0]],B=d[x[1]],T=d[x[2]];v.push(...L.toArray(),...B.toArray(),...T.toArray());let V=new r.Vector2,z=new r.Vector2,I=new r.Vector2;const D=g[w];D!==void 0&&(V=D[0],z=D[1],I=D[2]),M.push(...V.toArray(),...z.toArray(),...I.toArray())}const _=new Float32Array(v),P=new Float32Array(M),E=new r.BufferGeometry;if(_.length>0&&E.setAttribute("position",new r.BufferAttribute(_,3)),P.length>0&&E.setAttribute("uv",new r.BufferAttribute(P,2)),E.computeVertexNormals(),this.materials.has(l)){const w=new r.Mesh(E,this.materials.get(l));w.name=c,w.castShadow=!0,w.receiveShadow=!0,n.add(w)}}s(n)}_parseV3(e,t,s){const n=new r.Group;console.warn("SBMLoader: SBM version 3 is not supported yet."),s(n)}}class be extends r.Loader{load(e,t,s,n){let i;if(this.resourcePath!=="")i=this.resourcePath;else if(this.path!==""){const c=r.LoaderUtils.extractUrlBase(e);i=r.LoaderUtils.resolveURL(c,this.path)}else i=r.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const a=c=>{n?n(c):console.error(c),this.manager.itemError(e),this.manager.itemEnd(e)},o=new r.FileLoader(this.manager);o.setPath(this.path),o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,c=>{try{this.parse(c,i,l=>{t(l),this.manager.itemEnd(e)},a)}catch(l){a(l)}},s,a)}parse(e,t,s,n){const i=new TextDecoder().decode(e.slice(0,8));if(i!=="SBK-----"&&i!=="SBM-----"){n?.(new Error(`SBMLoader: Invalid SBM format: ${i}`));return}new gt(e,{path:t,crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager}).parse(s,n)}parseAsync(e,t){return new Promise((s,n)=>{this.parse(e,t,i=>{s(i)},i=>{n(i)})})}}const ft=["map","alphaMap","aoMap","bumpMap","clearcoatMap","clearcoatNormalMap","clearcoatRoughnessMap","displacementMap","emissiveMap","envMap","gradientMap","iridescenceMap","iridescenceThicknessMap","lightMap","matcap","metalnessMap","normalMap","roughnessMap","sheenColorMap","sheenRoughnessMap","specularColorMap","specularIntensityMap","specularMap","thicknessMap","transmissionMap"];function j(h){return h.traverse(e=>{if(!(e instanceof r.Mesh))return;const t=Array.isArray(e.material)?e.material:[e.material];for(const s of t){if(!s)continue;let n=!1;for(const i of ft){const a=s[i];a?.isTexture&&a.image==null&&(a.dispose(),s[i]=null,n=!0)}n&&(s.needsUpdate=!0)}}),h}class O{static CACHE_NAME="u-space-model-loader-cache";static fileLoader=new r.FileLoader().setResponseType("arraybuffer");static dracoLoader=new He.DRACOLoader().setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${r.REVISION}.0/examples/jsm/libs/draco/`);static ktx2Loader=new Fe.KTX2Loader().setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${r.REVISION}.0/examples/jsm/libs/basis/`);static gltfLoader=new le.GLTFLoader().setDRACOLoader(O.dracoLoader).setKTX2Loader(O.ktx2Loader).setMeshoptDecoder(se.MeshoptDecoder);static sbmxLoader=new we().setDRACOLoader(O.dracoLoader).setKTX2Loader(O.ktx2Loader).setMeshoptDecoder(se.MeshoptDecoder);static sbmLoader=new be;static fbxLoader=new je.FBXLoader;static objLoader=new ke.OBJLoader;static stlLoader=new Ue.STLLoader;static setLoadingManager(e){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}static async setRenderer(e){await e.init(),this.ktx2Loader.detectSupport(e)}static setDracoPath(e){this.dracoLoader.setDecoderPath(e)}static setKTX2Path(e){this.ktx2Loader.setTranscoderPath(e)}static async loadAsync(e,t={persistent:!0}){const s=e.split(".").pop()?.split("?")[0].toLowerCase();let n;switch(t.persistent&&typeof caches<"u"?n=await this.getPersistentData(e):n=await this.fileLoader.loadAsync(e),s){case"gltf":case"glb":const i=await this.gltfLoader.parseAsync(n,r.LoaderUtils.extractUrlBase(e));return i.scene.animations=i.animations,j(i.scene);case"sbmx":const a=await this.sbmxLoader.parseAsync(n,r.LoaderUtils.extractUrlBase(e));return a.scene.animations=a.animations,j(a.scene);case"sbm":const o=await this.sbmLoader.parseAsync(n,r.LoaderUtils.extractUrlBase(e));return j(o);case"fbx":const c=this.fbxLoader.parse(n,r.LoaderUtils.extractUrlBase(e));return j(c);case"obj":const l=new TextDecoder().decode(n),d=this.objLoader.parse(l);return j(d);case"stl":const u=this.stlLoader.parse(n);return new r.Mesh(u,new r.MeshStandardNodeMaterial);default:throw new Error(`Unsupported model format: ${s}`)}}static async getPersistentData(e){try{const t=await caches.open(this.CACHE_NAME),s=await t.match(e);if(s)return await s.arrayBuffer();const n=await this.fileLoader.loadAsync(e),i=new Response(n);return await t.put(e,i),n}catch(t){return console.warn(`[LoaderManager] Failed to use Cache API for ${e}:`,t),await this.fileLoader.loadAsync(e)}}}class yt{static textureLoader=new r.TextureLoader;static hdrLoader=new Ge.HDRLoader;static cubeTextureLoader=new r.CubeTextureLoader;static setLoadingManager(e){this.textureLoader.manager=e,this.hdrLoader.manager=e,this.cubeTextureLoader.manager=e}static async loadAsyncTexture(e){return await this.textureLoader.loadAsync(e)}static async loadAsyncHDR(e){const t=await this.hdrLoader.loadAsync(e);return t.mapping=r.EquirectangularReflectionMapping,t}static async loadAsyncCubeTexture(e,t){return this.cubeTextureLoader.setPath(e),await this.cubeTextureLoader.loadAsync(t)}}class R extends r.Mesh{isBaseMesh=!0;type="BaseMesh";castShadow=!0;receiveShadow=!0;ignoreInvisibleWhenRaycast=!0;constructor(...e){super(...e)}raycast(e,t){return this.visible===!1&&this.ignoreInvisibleWhenRaycast===!0?!1:super.raycast(e,t)}}class Z extends r.Group{isBaseGroup=!0;type="BaseGroup";ignoreInvisibleWhenRaycast=!0;constructor(...e){super(...e)}raycast(e,t){return this.visible===!1&&this.ignoreInvisibleWhenRaycast===!0?!1:super.raycast(e,t)}}class xe extends r.Sprite{isBaseSprite=!0;type="BaseSprite";ignoreInvisibleWhenRaycast=!0;constructor(...e){super(...e)}raycast(e,t){return this.visible===!1&&this.ignoreInvisibleWhenRaycast===!0?!1:super.raycast(e,t)}}class U extends Z{isModel=!0;type="Model";static memoryCache=new Map;mixer=null;animations=[];actions=new Map;constructor(){super()}async loadAsync(e){const{url:t,cache:s=!0,persistent:n=!0}=e;try{let i;s?U.memoryCache.has(t)?i=U.memoryCache.get(t):(i=O.loadAsync(t,{persistent:n}),U.memoryCache.set(t,i)):i=O.loadAsync(t,{persistent:n});const a=await i,o=Ve.clone(a);return this.add(o),o.animations&&o.animations.length>0&&(this.animations=o.animations,this.mixer=new r.AnimationMixer(o)),o}catch(i){return console.error(`[Model] Failed to load model from ${t}:`,i),null}}playAnimation(e,t={}){if(!this.mixer||this.animations.length===0)return null;const{loop:s=!0,repetitions:n=1/0,timeScale:i=1,clampWhenFinished:a=!1}=t;let o;if(e===void 0?o=this.animations[0]:typeof e=="number"?o=this.animations[e]:o=this.animations.find(l=>l.name===e),!o)return console.warn(`[Model] Animation not found: ${e}`),null;let c=this.actions.get(o.name);return c||(c=this.mixer.clipAction(o),this.actions.set(o.name,c)),c.setLoop(s?r.LoopRepeat:r.LoopOnce,n),c.clampWhenFinished=a,c.timeScale=i,c.reset().play(),c}playAllAnimations(e={}){return this.animations.map((t,s)=>this.playAnimation(s,e)).filter(t=>t!==null)}stopAnimation(e){if(!this.mixer)return;if(e===void 0){this.mixer.stopAllAction();return}let t;typeof e=="number"?t=this.animations[e]?.name:t=e,t&&this.actions.get(t)?.stop()}updateAnimation(e){this.mixer?.update(e)}getBoundingBox(){return new r.Box3().setFromObject(this)}getCenter(){const e=new r.Vector3;return this.getBoundingBox().getCenter(e),e}setMaterial(e){this.traverse(t=>{t instanceof r.Mesh&&(t.material=e)})}static clearMemoryCache(){this.memoryCache.clear()}static async clearPersistentCache(){typeof caches<"u"&&await caches.delete("u-space-loader-cache")}}class Se extends R{isSphereMesh=!0;type="SphereMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new r.SphereGeometry(e?.radius,e?.widthSegments,e?.heightSegments,e?.phiStart,e?.phiLength,e?.thetaStart,e?.thetaLength),this.material=new r.MeshStandardNodeMaterial(t)}}class J extends R{isTubeMesh=!0;type="TubeMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new r.TubeGeometry(e?.path,e?.tubularSegments,e?.radius,e?.radialSegments,e?.closed),this.material=new r.MeshStandardNodeMaterial(t)}}class wt extends Z{isTopology=!0;type="Topology";parameters={nodeColor:255,nodeRadius:.5,edgeColor:65280,edgeRadius:.1,pathColor:16711935,pathRadius:.2};nodes=new Map;adjacencyMap=new Map;graphGroup=null;pathMeshes=[];constructor(e){super(),e&&Object.assign(this.parameters,e)}addNode(e,t){this.nodes.has(e)&&console.warn(`[Topology] Node ${e} already exists. Overwriting.`),this.nodes.set(e,t),this.adjacencyMap.has(e)||this.adjacencyMap.set(e,new Map)}removeNode(e){if(!this.nodes.has(e)){console.warn(`[Topology] Node ${e} does not exist.`);return}this.nodes.delete(e),this.adjacencyMap.delete(e)}addEdge(e,t,s,n=!0){const i=this.nodes.get(e),a=this.nodes.get(t);if(!i||!a){console.error(`[Topology] Cannot add edge. One or both nodes not found: ${e}, ${t}`);return}const o=s??i.distanceTo(a);this.getNeighbors(e)?.set(t,o),n&&this.getNeighbors(t)?.set(e,o)}removeEdge(e,t,s=!0){this.getNeighbors(e)?.delete(t),s&&this.getNeighbors(t)?.delete(e)}getShortestPath(e,t){if(!this.nodes.has(e)||!this.nodes.has(t))return console.warn("[Topology] Start or End node not found."),[];const s=new Map,n=new Map,i=new Set;for(const[c]of this.nodes)s.set(c,1/0),n.set(c,null),i.add(c);for(s.set(e,0);i.size>0;){let c=null,l=1/0;for(const u of i){const m=s.get(u);m<l&&(l=m,c=u)}if(c===null||c===t||l===1/0)break;i.delete(c);const d=this.adjacencyMap?.get(c);if(d)for(const[u,m]of d){if(!i.has(u))continue;const g=s.get(c)+m;g<s.get(u)&&(s.set(u,g),n.set(u,c))}}const a=[];let o=t;if(n.get(t)===null&&e!==t)return[];for(;o!==null;){const c=this.nodes.get(o);c&&a.unshift(c),o=n.get(o)||null}return a}renderGraph(){this.clearGraph(),this.graphGroup=new r.Group;const e=new Se({geometryParameters:{radius:this.parameters.nodeRadius,widthSegments:16,heightSegments:16},materialParameters:{color:this.parameters.nodeColor}});this.nodes.forEach((s,n)=>{const i=e.clone();i.position.copy(s),Object.assign(i.userData,{id:n,type:"node"}),this.graphGroup.add(i)});const t=new Set;this.adjacencyMap.forEach((s,n)=>{s.forEach((i,a)=>{const o=[n,a].sort().join("-");if(t.has(o))return;t.add(o);const c=this.nodes.get(n),l=this.nodes.get(a);if(c&&l){const d=new r.LineCurve3(c,l),u=new J({geometryParameters:{path:d,tubularSegments:1,radius:this.parameters.edgeRadius,radialSegments:8,closed:!1},materialParameters:{color:this.parameters.edgeColor}});Object.assign(u.userData,{from:n,to:a,weight:i,type:"edge"}),this.graphGroup.add(u)}})}),this.add(this.graphGroup)}clearGraph(){this.graphGroup&&(this.remove(this.graphGroup),this.graphGroup.traverse(e=>{e instanceof r.Mesh&&(e.geometry.dispose(),e.material.dispose())}),this.graphGroup=null)}renderPath(e,t=this.parameters.pathColor){if(e.length<2)return;const s=new r.CatmullRomCurve3(e,!1,"catmullrom",0),n=new J({geometryParameters:{path:s,tubularSegments:e.length*10,radius:this.parameters.pathRadius,closed:!1},materialParameters:{color:t}});return this.add(n),this.pathMeshes.push(n),n}clearPaths(){this.pathMeshes.forEach(e=>{this.remove(e),e.geometry.dispose(),e.material.dispose()}),this.pathMeshes=[]}exportData(){const e={};this.nodes.forEach((n,i)=>{e[i]={x:n.x,y:n.y,z:n.z}});const t=[],s=new Set;return this.adjacencyMap.forEach((n,i)=>{n.forEach((a,o)=>{const c=[i,o].sort().join("-");s.has(c)||(s.add(c),t.push({from:i,to:o,weight:a}))})}),{nodes:e,edges:t}}importData(e){this.clearGraph(),this.clearPaths(),this.nodes.clear(),this.adjacencyMap.clear(),Object.entries(e.nodes).forEach(([t,s])=>{this.addNode(t,new r.Vector3(s.x,s.y,s.z))}),e.edges.forEach(({from:t,to:s,weight:n})=>{this.addEdge(t,s,n)}),this.renderGraph()}dispose(){this.clearGraph(),this.clearPaths()}getNeighbors(e){return this.adjacencyMap.get(e)}}class vt extends xe{isPoi=!0;type="Poi";parameters={img:"",text:"",fontSize:32,fontFamily:"Arial",color:"#ffffff",iconSize:64,padding:10,backgroundColor:"rgba(0, 0, 0, 0)",borderRadius:8,textPosition:"right",scaleFactor:.01};_canvas=document.createElement("canvas");_lastParametersJSON="";constructor(e={}){super(new r.SpriteNodeMaterial),Object.assign(this.parameters,e),this.updateAsync()}async updateAsync(e={}){Object.assign(this.parameters,e);const t=JSON.stringify(this.parameters);if(t===this._lastParametersJSON)return;this._lastParametersJSON=t;const s=this._canvas,n=s.getContext("2d");if(!n)return;n.font=`${this.parameters.fontSize}px ${this.parameters.fontFamily}`;let i=null;this.parameters.img&&(i=await this._loadImage(this.parameters.img));const{text:a,fontSize:o,color:c,iconSize:l,padding:d,backgroundColor:u,borderRadius:m,textPosition:g,scaleFactor:f}=this.parameters,b=n.measureText(a),C=a?b.width:0,S=a?o:0;let v=0,M=0,_=0,P=0,E=0,w=0;const x=!!i,L=!!a;if(x&&L)switch(g){case"top":v=Math.max(l,C),M=l+d+S,E=(v-C)/2,w=S/2,_=(v-l)/2,P=S+d;break;case"bottom":v=Math.max(l,C),M=l+d+S,_=(v-l)/2,P=0,E=(v-C)/2,w=l+d+S/2;break;case"left":v=l+d+C,M=Math.max(l,S),E=0,w=M/2,_=C+d,P=(M-l)/2;break;default:v=l+d+C,M=Math.max(l,S),_=0,P=(M-l)/2,E=l+d,w=M/2;break}else x?(v=l,M=l,_=0,P=0):L&&(v=C,M=S,E=0,w=S/2);const B=v+d*2,T=M+d*2;if(s.width=B,s.height=T,n.font=`${o}px ${this.parameters.fontFamily}`,u&&(n.fillStyle=u,this._drawRoundedRect(n,0,0,B,T,m),n.fill()),x&&n.drawImage(i,_+d,P+d,l,l),L){n.fillStyle=c;const I=n.measureText(a),D=I.actualBoundingBoxAscent+I.actualBoundingBoxDescent,Ae=I.actualBoundingBoxAscent-D/2;n.textBaseline="alphabetic",n.fillText(a,E+d,w+d+Ae)}const V=this.material.map,z=new r.CanvasTexture(s);z.colorSpace=r.SRGBColorSpace,this.material.map=z,V?.dispose(),this.scale.set(B*f,T*f,1)}_loadImage(e){return new Promise((t,s)=>{if(typeof e=="string"){const n=new Image;n.crossOrigin="Anonymous",n.onload=()=>t(n),n.onerror=()=>s(new Error(`Failed to load image: ${e}`)),n.src=e}else t(e)})}_drawRoundedRect(e,t,s,n,i,a){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+i-a),e.quadraticCurveTo(t+n,s+i,t+n-a,s+i),e.lineTo(t+a,s+i),e.quadraticCurveTo(t,s+i,t,s+i-a),e.lineTo(t,s+a),e.quadraticCurveTo(t,s,t+a,s),e.closePath()}dispose(){this.material.map?.dispose(),this.material.dispose()}}class ee extends R{isShapeMesh=!0;type="ShapeMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new r.ShapeGeometry(e?.shape,e?.curveSegments),this.material=new r.MeshStandardNodeMaterial(t),this.geometry.rotateX(-Math.PI/2)}static createFromPoints(e,t={}){return new ee({...t,geometryParameters:{...t.geometryParameters,shape:new r.Shape(e.map(s=>new r.Vector2(s.x,-s.z)))}})}}class te extends R{isExtrudeMesh=!0;type="ExtrudeMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new r.ExtrudeGeometry(e?.shape,e?.options),this.material=new r.MeshStandardNodeMaterial(t),this.geometry.rotateX(-Math.PI/2)}static createFromPoints(e,t={}){return e&&e.length===0&&(e=void 0),new te({...t,geometryParameters:{...t.geometryParameters,shape:new r.Shape(e?.map(s=>new r.Vector2(s.x,-s.z)))}})}}class bt extends R{isPlaneMesh=!0;type="PlaneMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new r.PlaneGeometry(e?.width,e?.height,e?.widthSegments,e?.heightSegments),this.material=new r.MeshStandardNodeMaterial(t)}}class xt extends R{isCircleMesh=!0;type="CircleMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(new r.CircleGeometry(e?.radius,e?.segments,e?.thetaStart,e?.thetaLength),new r.MeshStandardNodeMaterial(t)),this.geometry.rotateX(-Math.PI/2)}}class A{static traverseMeshes(e,t){e.traverse(s=>{s instanceof r.Mesh&&t(s)})}}class St{static flow(e={}){const{baseColor:t=16777215,flowColor:s=65280,speed:n=1,scale:i=3,intensity:a=4}=e,o=p.color(new r.Color(t)),c=p.color(new r.Color(s)),l=p.uv().x.mul(i).sub(p.time.mul(n)),d=p.pow(p.sin(l).add(1).mul(.5),a);return p.mix(o,c,d)}static breathe(e={}){const{baseColor:t=16777215,breathColor:s=65280,speed:n=1,intensity:i=2}=e,a=p.color(new r.Color(t)),o=p.color(new r.Color(s)),c=p.sin(p.time.mul(n)).add(1).mul(.5),l=p.pow(c,i);return p.mix(a,o,l)}static fluid(e={}){const{baseColor:t=16777215,flowColor:s=255,speed:n=1,scale:i=1,intensity:a=1,distortion:o=.5}=e,c=p.color(new r.Color(t)),l=p.color(new r.Color(s)),d=p.uv().mul(i),u=p.time.mul(n),m=p.mx_noise_float(d.add(u),1,0),g=d.add(m.mul(o)),f=p.mx_noise_float(g,1,0).add(1).mul(.5),b=p.pow(f,a);return p.mix(c,l,b)}}function Ct(h){}const N="uSpaceHighlight",G=`${N}/enabled`,Ce=`${N}/opacity`,Me=`${N}/color`,Ee=`${N}/overwrite`,Te=`${N}/multiplyOpacity`,q=`${N}/instancedOriginalOpacity`,X="uSpaceBreathe",K=`${X}/enabled`,_e=`${X}/color`,Pe=`${X}/speed`,Oe=`${X}/intensity`,Q=new WeakMap,Mt=p.Fn(()=>{const h=p.userData(G,"uint"),e=p.userData(Me,"uint"),t=p.userData(Ee,"uint"),s=oe(e),n=p.materialColor.mul(s),i=p.select(t.greaterThan(0),s,n),a=p.select(h.greaterThan(0),i,p.materialColor),o=p.userData(K,"uint"),c=p.userData(_e,"uint"),l=p.userData(Pe,"float"),d=p.userData(Oe,"float"),u=oe(c),m=p.sin(p.time.mul(l)).add(1).mul(.5),g=p.pow(m,d),f=p.mix(a,u,g);return p.select(o.greaterThan(0),f,a)})(),Et=p.Fn(()=>{const h=p.userData(G,"uint"),e=p.userData(Ce,"float"),t=p.userData(Te,"uint"),s=p.select(t.greaterThan(0),p.materialOpacity.mul(e),e);return p.select(h.greaterThan(0),s,p.materialOpacity)})();function H(h){return Array.isArray(h.material)?h.material:[h.material]}function re(h){H(h).forEach(t=>{if(!t)return;let s=Q.get(t);s||(s={colorNode:t.colorNode,opacityNode:t.opacityNode,transparent:t.transparent,depthWrite:t.depthWrite,activeMeshes:new Set},Q.set(t,s)),s.activeMeshes.add(h),t.transparent=!0,t.colorNode=Mt,t.opacityNode=Et,t.needsUpdate=!0})}function ae(h){const e=h.userData[G],t=h.userData[K];if(e||t)return;H(h).forEach(n=>{if(!n)return;const i=Q.get(n);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,Q.delete(n)))})}function Tt(h,e,t,s){const n=h,i=n.setSemanticHighlight;if(i)return i.call(h,e,t,s),!0;const a=n.setSemanticColor,o=n.setSemanticOpacity,c=n.getSemanticOpacity,l=n.getSemanticColor,d=n.hasSemanticColor;return!a||!o?!1:(h.userData[q]===void 0&&(h.userData[q]={hasColor:d?.call(h)??!1,color:l?.call(h,new r.Color).getHex()??16777215,opacity:c?.call(h)??1}),a.call(h,e),o.call(h,t),!0)}function _t(h){const e=h,t=e.clearSemanticHighlight;if(t)return t.call(h),!0;const s=e.resetSemanticColor,n=e.setSemanticColor,i=e.setSemanticOpacity;if(!s||!i)return!1;const a=h.userData[q];return a&&(a.hasColor&&n?n.call(h,a.color):s.call(h),i.call(h,a.opacity),Reflect.deleteProperty(h.userData,q)),!0}class F{static highlightColor(e,t={}){const s=Array.isArray(e)?e:[e],{opacity:n=.5,color:i=16711680,overwrite:a=!1,depthWrite:o,multiplyOpacity:c=!1}=t,l=new r.Color(i).getHex();for(const d of s)Tt(d,i,n,a)||A.traverseMeshes(d,u=>{u.userData[G]=1,u.userData[Ce]=n,u.userData[Me]=l,u.userData[Ee]=a?1:0,u.userData[Te]=c?1:0,re(u),o!==void 0&&H(u).forEach(g=>{g&&(g.depthWrite=o)})})}static removeHighlightColor(e){const t=Array.isArray(e)?e:[e];for(const s of t)_t(s)||A.traverseMeshes(s,n=>{n.userData[G]=0,ae(n)})}static breatheColor(e,t={}){const s=Array.isArray(e)?e:[e],n=Object.assign({color:65280,speed:1,intensity:2},t);n.color=new r.Color(n.color).getHex();for(const i of s)A.traverseMeshes(i,a=>{a.userData[K]=1,a.userData[_e]=n.color,a.userData[Pe]=n.speed,a.userData[Oe]=n.intensity,re(a)})}static removeBreatheColor(e){const t=Array.isArray(e)?e:[e];for(const s of t)A.traverseMeshes(s,n=>{n.userData[K]=0,ae(n)})}static wireframe(e,t=!0){const s=Array.isArray(e)?e:[e];for(const n of s)A.traverseMeshes(n,i=>{H(i).forEach(a=>{if(!a)return;const o=a;o.wireframe=t,o.needsUpdate=!0})})}static removeWireframe(e){F.wireframe(e,!1)}static fadeIn(e,t={}){const{duration:s=500}=t;return F._fade(e,0,1,s)}static fadeOut(e,t={}){const{duration:s=500}=t;return F._fade(e,1,0,s)}static _fade(e,t,s,n){const i=Array.isArray(e)?e:[e],a=new Map;for(const o of i)A.traverseMeshes(o,c=>{H(c).forEach(l=>{if(!l||a.has(l))return;const d=l.opacity,u=l.transparent,m=s>=1?d:s;a.set(l,{material:l,targetOpacity:m,originalOpacity:d,originalTransparent:u}),l.transparent=!0,l.opacity=t,l.needsUpdate=!0})});return a.size===0?Promise.resolve():new Promise(o=>{const c=performance.now();let l=0;const d=()=>{const u=performance.now()-c,m=Math.min(u/n,1);if(!i[0].parent){cancelAnimationFrame(l),o();return}for(const{material:f,targetOpacity:b}of a.values())f.opacity=t+(b-t)*m,f.needsUpdate=!0;if(m<1)l=requestAnimationFrame(d);else{if(s>=1)for(const{material:f,originalOpacity:b,originalTransparent:C}of a.values())f.opacity=b,f.transparent=C,f.needsUpdate=!0;o()}};l=requestAnimationFrame(d)})}}const oe=h=>{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);return p.vec3(e,t,s)};class Le extends y.Tween{viewer;constructor(e,t){super(t),this.viewer=e}_update=({time:e})=>{this.update(e)&&this.viewer.render()};easingByMode(e){const t=Ot[e];return super.easing(t)}start(e,t){return this.viewer.addEventListener("afterControlsUpdate",this._update),super.start(e,t)}stop(){return this.viewer.removeEventListener("afterControlsUpdate",this._update),super.stop()}}function Pt(h,e,t,s={},n,i){return new Promise((a,o)=>{const{duration:c=1e3,delay:l=0,repeat:d=!1,mode:u="Linear.None",yoyo:m=!1}=s,g=new Le(h,e).to(t,c).easingByMode(u).delay(l).onUpdate(f=>{n?.(f,g)}).onComplete(()=>{a()}).onStop(()=>{o("animation stop")}).onStart(()=>{i?.(g)});typeof d=="number"?g.repeat(d):typeof d=="boolean"&&d&&g.repeat(1/0),m&&g.repeatDelay(20),g.yoyo(m),g.start()})}const Ot={"Linear.None":y.Easing.Linear.None,"Quadratic.In":y.Easing.Quadratic.In,"Quadratic.Out":y.Easing.Quadratic.Out,"Quadratic.InOut":y.Easing.Quadratic.InOut,"Cubic.In":y.Easing.Cubic.In,"Cubic.Out":y.Easing.Cubic.Out,"Cubic.InOut":y.Easing.Cubic.InOut,"Quartic.In":y.Easing.Quartic.In,"Quartic.Out":y.Easing.Quartic.Out,"Quartic.InOut":y.Easing.Quartic.InOut,"Quintic.In":y.Easing.Quintic.In,"Quintic.Out":y.Easing.Quintic.Out,"Quintic.InOut":y.Easing.Quintic.InOut,"Sinusoidal.In":y.Easing.Sinusoidal.In,"Sinusoidal.Out":y.Easing.Sinusoidal.Out,"Sinusoidal.InOut":y.Easing.Sinusoidal.InOut,"Exponential.In":y.Easing.Exponential.In,"Exponential.Out":y.Easing.Exponential.Out,"Exponential.InOut":y.Easing.Exponential.InOut,"Circular.In":y.Easing.Circular.In,"Circular.Out":y.Easing.Circular.Out,"Circular.InOut":y.Easing.Circular.InOut,"Elastic.In":y.Easing.Elastic.In,"Elastic.Out":y.Easing.Elastic.Out,"Elastic.InOut":y.Easing.Elastic.InOut,"Back.In":y.Easing.Back.In,"Back.Out":y.Easing.Back.Out,"Back.InOut":y.Easing.Back.InOut,"Bounce.In":y.Easing.Bounce.In,"Bounce.Out":y.Easing.Bounce.Out,"Bounce.InOut":y.Easing.Bounce.InOut};class Lt{scene;planes=new Map;helpers=new Map;group;constructor(e){this.scene=e,this.group=new r.ClippingGroup,this.group.name="__clippingToolGroup",this.scene.add(this.group)}attach(){const e=[...this.scene.children];for(const t of e)t!==this.group&&this.group.add(t)}detach(){const e=[...this.group.children];for(const t of e)this.helpers.has(t.name)||this.scene.add(t)}enable(){this.group.enabled=!0}disable(){this.group.enabled=!1}addPlane(e,t={}){const{normal:s={x:0,y:-1,z:0},constant:n=0,showHelper:i=!1,helperSize:a=5,helperColor:o=16711680}=t,c=new r.Plane(new r.Vector3(s.x,s.y,s.z),n);return this.planes.set(e,c),this._syncPlanes(),i&&this.showHelper(e,a,o),c}addBox(e,t,s={}){const{showHelpers:n=!1,helperColor:i=16711680}=s,a=t.min,o=t.max,c=[{suffix:"+x",normal:{x:-1,y:0,z:0},constant:o.x},{suffix:"-x",normal:{x:1,y:0,z:0},constant:-a.x},{suffix:"+y",normal:{x:0,y:-1,z:0},constant:o.y},{suffix:"-y",normal:{x:0,y:1,z:0},constant:-a.y},{suffix:"+z",normal:{x:0,y:0,z:-1},constant:o.z},{suffix:"-z",normal:{x:0,y:0,z:1},constant:-a.z}],l=[];for(const d of c){const u=`${e}_${d.suffix}`;this.addPlane(u,{normal:d.normal,constant:d.constant,showHelper:n,helperColor:i}),l.push(u)}return l}addBoxFromObject(e,t,s=0,n={}){const i=new r.Box3().setFromObject(t);return i.expandByScalar(s),this.addBox(e,i,n)}setPlaneConstant(e,t){const s=this.planes.get(e);s&&(s.constant=t)}removePlane(e){this.planes.delete(e),this.hideHelper(e),this._syncPlanes()}removeBox(e){const t=["+x","-x","+y","-y","+z","-z"];for(const s of t)this.removePlane(`${e}_${s}`)}removeAll(){const e=Array.from(this.helpers.keys());for(const t of e)this.hideHelper(t);this.planes.clear(),this._syncPlanes()}showHelper(e,t=5,s=16711680){this.hideHelper(e);const n=this.planes.get(e);if(!n)return;const i=new r.PlaneHelper(n,t,new r.Color(s).getHex());i.name=e,this.helpers.set(e,i),this.scene.add(i)}hideHelper(e){const t=this.helpers.get(e);t&&(this.scene.remove(t),t.dispose(),this.helpers.delete(e))}get(e){return this.planes.get(e)}_syncPlanes(){this.group.clippingPlanes=Array.from(this.planes.values())}dispose(){this.detach(),this.removeAll(),this.scene.remove(this.group)}}class Bt{scene;measurements=new Map;_idCounter=0;constructor(e){this.scene=e}measureDistance(e,t,s={}){const{lineColor:n=16776960}=s,i=new r.Vector3(e.x,e.y,e.z),a=new r.Vector3(t.x,t.y,t.z),o=i.distanceTo(a),c=`measure_dist_${this._idCounter++}`,l=new r.Group;l.name=c;const d=new r.BufferGeometry().setFromPoints([i,a]),u=new r.LineBasicMaterial({color:n}),m=new r.Line(d,u);l.add(m),this.scene.add(l);const g={id:c,type:"distance",value:o,unit:"m",points:[i,a],object:l};return this.measurements.set(c,g),g}measureArea(e,t={}){const{lineColor:s=65280}=t;if(e.length<3)throw new Error("MeasureTool.measureArea requires at least 3 points");const n=e.map(g=>new r.Vector3(g.x,g.y,g.z)),i=this._calculatePolygonArea(n),a=`measure_area_${this._idCounter++}`,o=new r.Group;o.name=a;const c=[...n,n[0]],l=new r.BufferGeometry().setFromPoints(c),d=new r.LineBasicMaterial({color:s}),u=new r.Line(l,d);o.add(u),this.scene.add(o);const m={id:a,type:"area",value:i,unit:"m²",points:n,object:o};return this.measurements.set(a,m),m}measureAngle(e,t,s,n={}){const{lineColor:i=16746496}=n,a=new r.Vector3(e.x,e.y,e.z),o=new r.Vector3(t.x,t.y,t.z),c=new r.Vector3(s.x,s.y,s.z),l=a.clone().sub(o).normalize(),d=c.clone().sub(o).normalize(),m=Math.acos(Math.max(-1,Math.min(1,l.dot(d))))*180/Math.PI,g=`measure_angle_${this._idCounter++}`,f=new r.Group;f.name=g;const b=new r.BufferGeometry().setFromPoints([a,o,c]),C=new r.LineBasicMaterial({color:i}),S=new r.Line(b,C);f.add(S),this.scene.add(f);const v={id:g,type:"angle",value:m,unit:"°",points:[a,o,c],object:f};return this.measurements.set(g,v),v}get(e){return this.measurements.get(e)}remove(e){const t=this.measurements.get(e);t&&(this.scene.remove(t.object),t.object.traverse(s=>{s.geometry?.dispose(),s.material?.dispose()}),this.measurements.delete(e))}removeAll(){const e=Array.from(this.measurements.keys());for(const t of e)this.remove(t)}getAll(){return Array.from(this.measurements.values())}_calculatePolygonArea(e){const t=e.length,s=new r.Vector3;for(let i=0;i<t;i++){const a=e[i],o=e[(i+1)%t],c=new r.Vector3().crossVectors(a,o);s.add(c)}const n=new r.Vector3;if(t>=3){const i=e[1].clone().sub(e[0]),a=e[2].clone().sub(e[0]);n.crossVectors(i,a).normalize()}return Math.abs(s.dot(n))/2}dispose(){this.removeAll()}}class At{scene;annotations=new Map;_idCounter=0;_createCSSObject=null;constructor(e){this.scene=e}setCSSObjectFactory(e){this._createCSSObject=e}add(e,t){this.annotations.has(e)&&this.remove(e);const s=new r.Group;s.name=`annotation_${e}`;const n=new r.Vector3(t.position.x,t.position.y,t.position.z);s.position.copy(n);const i=document.createElement("div");if(i.innerHTML=t.content,i.style.cssText=`
|
|
8
|
+
`,e.className&&(this._selectionBox.className=e.className),this._container.style.position=this._container.style.position||"relative",this._container.appendChild(this._selectionBox),this.domElement.addEventListener("pointerdown",this._onBoxPointerDown),this.domElement.addEventListener("pointermove",this._onBoxPointerMove),this.domElement.addEventListener("pointerup",this._onBoxPointerUp))}disableBoxSelection(){this._boxSelectionEnabled&&(this._boxSelectionEnabled=!1,this.domElement.removeEventListener("pointerdown",this._onBoxPointerDown),this.domElement.removeEventListener("pointermove",this._onBoxPointerMove),this.domElement.removeEventListener("pointerup",this._onBoxPointerUp),this._selectionBox&&(this._selectionBox.remove(),this._selectionBox=null))}setCamera(e){this.camera=e}_onBoxPointerDown=e=>{if(e.button!==0)return;this._isSelecting=!0;const t=this._container.getBoundingClientRect();this._startPoint.set(e.clientX-t.left,e.clientY-t.top),this._endPoint.copy(this._startPoint),this._selectionBox&&(this._selectionBox.style.display="block",this._updateBoxElement())};_onBoxPointerMove=e=>{if(!this._isSelecting)return;const t=this._container.getBoundingClientRect();this._endPoint.set(e.clientX-t.left,e.clientY-t.top),this._updateBoxElement()};_onBoxPointerUp=()=>{if(!this._isSelecting)return;this._isSelecting=!1,this._selectionBox&&(this._selectionBox.style.display="none");const e=this._getObjectsInBox();this.clear(),e.length>0&&this.select(e)};_updateBoxElement(){if(!this._selectionBox)return;const e=Math.min(this._startPoint.x,this._endPoint.x),t=Math.min(this._startPoint.y,this._endPoint.y),s=Math.abs(this._endPoint.x-this._startPoint.x),n=Math.abs(this._endPoint.y-this._startPoint.y);this._selectionBox.style.left=`${e}px`,this._selectionBox.style.top=`${t}px`,this._selectionBox.style.width=`${s}px`,this._selectionBox.style.height=`${n}px`}_getObjectsInBox(){const e=this._container.getBoundingClientRect(),t=e.width,s=e.height,n=new o.Vector2(this._startPoint.x/t*2-1,-(this._startPoint.y/s)*2+1),r=new o.Vector2(this._endPoint.x/t*2-1,-(this._endPoint.y/s)*2+1),a=new o.Box2(new o.Vector2(Math.min(n.x,r.x),Math.min(n.y,r.y)),new o.Vector2(Math.max(n.x,r.x),Math.max(n.y,r.y))),c=this.targetObjects||this.scene.children,l=[],h=new o.Matrix4;h.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse);const u=d=>{if(!d.visible)return;const p=new o.Vector3;if(p.setFromMatrixPosition(d.matrixWorld),p.applyMatrix4(h),p.z>-1&&p.z<1&&a.containsPoint(new o.Vector2(p.x,p.y))&&l.push(d),this._deep)for(const m of d.children)u(m)};for(const d of c)u(d);return l}dispose(){this.disableBoxSelection(),this._selected.clear()}}class Bt{scenes=new Map;_activeSceneKey=null;add(e,t){this.scenes.set(e,t)}create(e,t={}){const s=new o.Scene;return t.background!==void 0&&(s.background=new o.Color(t.background)),this.scenes.set(e,s),s}get(e){return this.scenes.get(e)}remove(e){this.scenes.delete(e),this._activeSceneKey===e&&(this._activeSceneKey=null)}get activeKey(){return this._activeSceneKey}set activeKey(e){this._activeSceneKey=e}keys(){return Array.from(this.scenes.keys())}serialize(e){const t=this.scenes.get(e);if(!t)return null;let s=null;return t.background instanceof o.Color&&(s=`#${t.background.getHexString()}`),{name:t.name||e,background:s,environmentRotation:{x:t.environmentRotation?.x??0,y:t.environmentRotation?.y??0,z:t.environmentRotation?.z??0},children:t.children.map(n=>n.name||n.uuid)}}clear(){this.scenes.clear(),this._activeSceneKey=null}get size(){return this.scenes.size}}class Ct{scene;lights=new Map;helpers=new Map;constructor(e){this.scene=e}addAmbient(e,t={}){const{color:s=16777215,intensity:n=.5}=t,r=new o.AmbientLight(s,n);return r.name=e,this._register(e,r),r}addDirectional(e,t={}){const{color:s=16777215,intensity:n=1,position:r={x:5,y:10,z:5},castShadow:a=!1,shadowMapSize:c=1024}=t,l=new o.DirectionalLight(s,n);return l.position.set(r.x,r.y,r.z),l.castShadow=a,a&&l.shadow.mapSize.setScalar(c),l.name=e,this._register(e,l),l}addPoint(e,t={}){const{color:s=16777215,intensity:n=1,distance:r=0,decay:a=2,position:c={x:0,y:5,z:0},castShadow:l=!1}=t,h=new o.PointLight(s,n,r,a);return h.position.set(c.x,c.y,c.z),h.castShadow=l,h.name=e,this._register(e,h),h}addSpot(e,t={}){const{color:s=16777215,intensity:n=1,distance:r=0,angle:a=Math.PI/6,penumbra:c=.1,decay:l=2,position:h={x:0,y:10,z:0},target:u,castShadow:d=!1}=t,p=new o.SpotLight(s,n,r,a,c,l);return p.position.set(h.x,h.y,h.z),u&&p.target.position.set(u.x,u.y,u.z),p.castShadow=d,p.name=e,this._register(e,p),p}addHemisphere(e,t={}){const{skyColor:s=8900331,groundColor:n=3549447,intensity:r=.6}=t,a=new o.HemisphereLight(s,n,r);return a.name=e,this._register(e,a),a}applyPreset(e){switch(this.removeAll(),e){case"indoor":this.addAmbient("preset_ambient",{intensity:.4}),this.addPoint("preset_point1",{position:{x:0,y:3,z:0},intensity:1,castShadow:!0}),this.addPoint("preset_point2",{position:{x:3,y:2,z:-3},intensity:.5});break;case"outdoor":this.addHemisphere("preset_hemi",{skyColor:8900331,groundColor:3549447,intensity:.6}),this.addDirectional("preset_sun",{position:{x:10,y:20,z:10},intensity:1.5,castShadow:!0,shadowMapSize:2048});break;case"studio":this.addAmbient("preset_ambient",{intensity:.3}),this.addDirectional("preset_key",{position:{x:5,y:8,z:5},intensity:1.2,castShadow:!0}),this.addDirectional("preset_fill",{position:{x:-5,y:5,z:-2},intensity:.6}),this.addDirectional("preset_back",{position:{x:0,y:5,z:-8},intensity:.4});break;case"warehouse":this.addAmbient("preset_ambient",{intensity:.2}),this.addPoint("preset_light1",{position:{x:-5,y:6,z:-5},intensity:2,distance:20}),this.addPoint("preset_light2",{position:{x:5,y:6,z:-5},intensity:2,distance:20}),this.addPoint("preset_light3",{position:{x:-5,y:6,z:5},intensity:2,distance:20}),this.addPoint("preset_light4",{position:{x:5,y:6,z:5},intensity:2,distance:20});break}}get(e){return this.lights.get(e)}remove(e){const t=this.lights.get(e);t&&(this.scene.remove(t),this.lights.delete(e)),this.hideHelper(e)}removeAll(){const e=Array.from(this.lights.keys());for(const t of e)this.remove(t)}showHelper(e){if(this.helpers.has(e))return;const t=this.lights.get(e);if(!t)return;let s=null;t instanceof o.DirectionalLight?s=new o.DirectionalLightHelper(t,1):t instanceof o.PointLight?s=new o.PointLightHelper(t,.5):t instanceof o.SpotLight?s=new o.SpotLightHelper(t):t instanceof o.HemisphereLight&&(s=new o.HemisphereLightHelper(t,1)),s&&(this.scene.add(s),this.helpers.set(e,s))}hideHelper(e){const t=this.helpers.get(e);t&&(this.scene.remove(t),this.helpers.delete(e))}showAllHelpers(){for(const[e]of this.lights)this.showHelper(e)}hideAllHelpers(){const e=Array.from(this.helpers.keys());for(const t of e)this.hideHelper(t)}_register(e,t){this.lights.has(e)&&this.remove(e),this.lights.set(e,t),this.scene.add(t)}dispose(){this.removeAll(),this.hideAllHelpers()}}class Xe extends Ke.GLTFLoader{constructor(e){super(e)}parse(e,t,s,n){if(_t(e.slice(0,8))==="SBMG----"){const a=Ot(e.slice(8));return super.parse(a,t,s,n)}else return super.parse(e,t,s,n)}}function _t(i){return new TextDecoder().decode(new Uint8Array(i))}function Ot(i){const e=new DataView(i);for(let t=0;t<e.byteLength;t++){const s=e.getUint8(t),n=(s>>4&15)+(s<<4&240);e.setUint8(t,n)}return e.buffer}const At=8,Lt=130,ye=66,Tt="SBK-----",Nt="SBM-----",Qe=new TextDecoder,Pt=new TextEncoder;function Dt(i){let e=At;const t=new Uint8Array(i,0,e);if(Qe.decode(t)!==Tt)return i;e+=Lt;const n=new Uint8Array(i,0,e);if(n[40]===1){const a=Pt.encode(Nt),c=new Uint8Array([n[41]]),l=Rt(n),h=jt(l);let u=ye%h.length;const d=e+ye,p=new Uint8Array(i,d),m=new Uint8Array(p.length);for(let w=0;w<p.length;w++)m[w]=p[w]^h[u],u=(u+1)%h.length;const g=new Uint8Array(a.length+c.length+m.length);return g.set(a),g.set(c,a.length),g.set(m,a.length+c.length),g.buffer}}function Rt(i){const e=new Uint8Array(128);return e.set(i.slice(42,74),0),e.set(i.slice(74,138),32),e.set(i.slice(8,40),96),e}function jt(i){const e=new Uint8Array(64);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}const zt=(i,e,t)=>{const s=i.buffer.slice(t,t+e);let n=Qe.decode(s);return n=n.replace("\\","/"),n.startsWith("Maps/")||(n=`Maps/${n}`),n},Ut=(i,e,t)=>{const[s,n,r,a,c]=e,l=t||a<1;return new o.MeshStandardNodeMaterial({name:i,color:new o.Color(s,n,r),opacity:a,transparent:l,alphaTest:.01,side:c})},kt=i=>i?.toLowerCase().endsWith(".png")??!1;class Gt{data;options;textureLoader;littleEndian=!0;materials=new Map;constructor(e,t){this.data=e,this.options=t,this.textureLoader=new o.TextureLoader(t.manager),this.textureLoader.setCrossOrigin(t.crossOrigin),this.textureLoader.setRequestHeader(t.requestHeader)}parse(e,t){let s=this.data;const n=Dt(this.data);n&&(s=n);const r=new DataView(s);let a=8;const c=r.getUint8(a);a+=1,c===1?this._parseV2(r,a,e):c===2?this._parseV2(r,a,e):c===3?this._parseV3(r,a,e):t?.(new Error(`SBMLoader: Unsupported SBM version: ${c}`))}_parseV2(e,t,s){const n=new o.Group,r=e.getUint16(t,this.littleEndian);t+=2;const a=e.getUint16(t,this.littleEndian);t+=2;for(let c=0;c<r;++c){const l=e.getUint16(t,this.littleEndian).toString();t+=2,t+=4,t+=4,t+=4,t+=4;const h=e.getFloat32(t,this.littleEndian);t+=4;const u=e.getFloat32(t,this.littleEndian);t+=4;const d=e.getFloat32(t,this.littleEndian);t+=4;const p=e.getFloat32(t,this.littleEndian);t+=4,t+=4,t+=4,t+=4,t+=4;let m=e.getUint8(t);t+=1,m===0?m=o.FrontSide:m===1?m=o.BackSide:m===2&&(m=o.DoubleSide);const g=e.getUint16(t,this.littleEndian);t+=2;const w=g>0?zt(e,g,t):"";if(t+=g,!this.materials.has(l)){const S=Ut(l,[h,u,d,p,m],kt(w));this.materials.set(l,S),w&&this.options.path&&this.textureLoader.load(o.LoaderUtils.resolveURL(w,this.options.path),b=>{b.colorSpace=o.SRGBColorSpace,b.wrapS=o.RepeatWrapping,b.wrapT=o.RepeatWrapping,b.flipY=!1,b.anisotropy=16,S.map=b})}}for(let c=0;c<a;++c){const l=e.getUint16(t,this.littleEndian).toString();t+=2;const h=e.getUint16(t,this.littleEndian).toString();t+=2;const u=[],d=[],p=[],m=[],g=e.getUint16(t,this.littleEndian);if(t+=2,g>0)for(let x=0;x<g;x++){const O=new o.Vector3;O.setX(e.getFloat32(t,this.littleEndian)),t+=4,O.setY(e.getFloat32(t,this.littleEndian)),t+=4,O.setZ(e.getFloat32(t,this.littleEndian)),t+=4,u.push(O)}const w=e.getUint16(t,this.littleEndian);if(t+=2,w>0)for(let x=0;x<w;x++)t+=4,t+=4,t+=4;const E=e.getUint16(t,this.littleEndian);if(t+=2,E>0)for(let x=0;x<E;x++){const O=new o.Vector2;O.setX(e.getFloat32(t,this.littleEndian)),t+=4,O.setY(e.getFloat32(t,this.littleEndian)),t+=4,d.push(O)}const S=e.getUint16(t,this.littleEndian);if(t+=2,S>0)for(let x=0;x<S;x++){const O=e.getUint16(t,this.littleEndian);t+=2;const R=e.getUint16(t,this.littleEndian);t+=2;const T=e.getUint16(t,this.littleEndian);t+=2;const N=[O,R,T];p.push(N),d.length>0&&m.push([d[N[0]],d[N[1]],d[N[2]]])}const b=[],v=[];for(let x=0;x<p.length;x++){const O=p[x],R=u[O[0]],T=u[O[1]],N=u[O[2]];b.push(...R.toArray(),...T.toArray(),...N.toArray());let F=new o.Vector2,P=new o.Vector2,y=new o.Vector2;const _=m[x];_!==void 0&&(F=_[0],P=_[1],y=_[2]),v.push(...F.toArray(),...P.toArray(),...y.toArray())}const C=new Float32Array(b),A=new Float32Array(v),L=new o.BufferGeometry;if(C.length>0&&L.setAttribute("position",new o.BufferAttribute(C,3)),A.length>0&&L.setAttribute("uv",new o.BufferAttribute(A,2)),L.computeVertexNormals(),this.materials.has(h)){const x=new o.Mesh(L,this.materials.get(h));x.name=l,x.castShadow=!0,x.receiveShadow=!0,n.add(x)}}s(n)}_parseV3(e,t,s){const n=new o.Group;console.warn("SBMLoader: SBM version 3 is not supported yet."),s(n)}}class Ye extends o.Loader{load(e,t,s,n){let r;if(this.resourcePath!=="")r=this.resourcePath;else if(this.path!==""){const l=o.LoaderUtils.extractUrlBase(e);r=o.LoaderUtils.resolveURL(l,this.path)}else r=o.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const a=l=>{n?n(l):console.error(l),this.manager.itemError(e),this.manager.itemEnd(e)},c=new o.FileLoader(this.manager);c.setPath(this.path),c.setResponseType("arraybuffer"),c.setRequestHeader(this.requestHeader),c.setWithCredentials(this.withCredentials),c.load(e,l=>{try{this.parse(l,r,h=>{t(h),this.manager.itemEnd(e)},a)}catch(h){a(h)}},s,a)}parse(e,t,s,n){const r=new TextDecoder().decode(e.slice(0,8));if(r!=="SBK-----"&&r!=="SBM-----"){n?.(new Error(`SBMLoader: Invalid SBM format: ${r}`));return}new Gt(e,{path:t,crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager}).parse(s,n)}parseAsync(e,t){return new Promise((s,n)=>{this.parse(e,t,r=>{s(r)},r=>{n(r)})})}}const Wt=["map","alphaMap","aoMap","bumpMap","clearcoatMap","clearcoatNormalMap","clearcoatRoughnessMap","displacementMap","emissiveMap","envMap","gradientMap","iridescenceMap","iridescenceThicknessMap","lightMap","matcap","metalnessMap","normalMap","roughnessMap","sheenColorMap","sheenRoughnessMap","specularColorMap","specularIntensityMap","specularMap","thicknessMap","transmissionMap"];function Q(i){return i.traverse(e=>{if(!(e instanceof o.Mesh))return;const t=Array.isArray(e.material)?e.material:[e.material];for(const s of t){if(!s)continue;let n=!1;for(const r of Wt){const a=s[r];a?.isTexture&&a.image==null&&(a.dispose(),s[r]=null,n=!0)}n&&(s.needsUpdate=!0)}}),i}class U{static CACHE_NAME="u-space-model-loader-cache";static fileLoader=new o.FileLoader().setResponseType("arraybuffer");static dracoLoader=new xt.DRACOLoader().setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${o.REVISION}.0/examples/jsm/libs/draco/`);static ktx2Loader=new wt.KTX2Loader().setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${o.REVISION}.0/examples/jsm/libs/basis/`);static gltfLoader=new Ke.GLTFLoader().setDRACOLoader(U.dracoLoader).setKTX2Loader(U.ktx2Loader).setMeshoptDecoder(ge.MeshoptDecoder);static sbmxLoader=new Xe().setDRACOLoader(U.dracoLoader).setKTX2Loader(U.ktx2Loader).setMeshoptDecoder(ge.MeshoptDecoder);static sbmLoader=new Ye;static fbxLoader=new gt.FBXLoader;static objLoader=new yt.OBJLoader;static stlLoader=new bt.STLLoader;static setLoadingManager(e){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}static async setRenderer(e){await e.init(),this.ktx2Loader.detectSupport(e)}static setDracoPath(e){this.dracoLoader.setDecoderPath(e)}static setKTX2Path(e){this.ktx2Loader.setTranscoderPath(e)}static async loadAsync(e,t={persistent:!0}){const s=e.split(".").pop()?.split("?")[0].toLowerCase();let n;switch(t.persistent&&typeof caches<"u"?n=await this.getPersistentData(e):n=await this.fileLoader.loadAsync(e),s){case"gltf":case"glb":const r=await this.gltfLoader.parseAsync(n,o.LoaderUtils.extractUrlBase(e));return r.scene.animations=r.animations,Q(r.scene);case"sbmx":const a=await this.sbmxLoader.parseAsync(n,o.LoaderUtils.extractUrlBase(e));return a.scene.animations=a.animations,Q(a.scene);case"sbm":const c=await this.sbmLoader.parseAsync(n,o.LoaderUtils.extractUrlBase(e));return Q(c);case"fbx":const l=this.fbxLoader.parse(n,o.LoaderUtils.extractUrlBase(e));return Q(l);case"obj":const h=new TextDecoder().decode(n),u=this.objLoader.parse(h);return Q(u);case"stl":const d=this.stlLoader.parse(n);return new o.Mesh(d,new o.MeshStandardNodeMaterial);default:throw new Error(`Unsupported model format: ${s}`)}}static async getPersistentData(e){try{const t=await caches.open(this.CACHE_NAME),s=await t.match(e);if(s)return await s.arrayBuffer();const n=await this.fileLoader.loadAsync(e),r=new Response(n);return await t.put(e,r),n}catch(t){return console.warn(`[LoaderManager] Failed to use Cache API for ${e}:`,t),await this.fileLoader.loadAsync(e)}}}class Ft{static textureLoader=new o.TextureLoader;static hdrLoader=new Mt.HDRLoader;static cubeTextureLoader=new o.CubeTextureLoader;static setLoadingManager(e){this.textureLoader.manager=e,this.hdrLoader.manager=e,this.cubeTextureLoader.manager=e}static async loadAsyncTexture(e){return await this.textureLoader.loadAsync(e)}static async loadAsyncHDR(e){const t=await this.hdrLoader.loadAsync(e);return t.mapping=o.EquirectangularReflectionMapping,t}static async loadAsyncCubeTexture(e,t){return this.cubeTextureLoader.setPath(e),await this.cubeTextureLoader.loadAsync(t)}}class k extends o.Mesh{isBaseMesh=!0;type="BaseMesh";castShadow=!0;receiveShadow=!0;ignoreInvisibleWhenRaycast=!0;constructor(...e){super(...e)}raycast(e,t){return this.visible===!1&&this.ignoreInvisibleWhenRaycast===!0?!1:super.raycast(e,t)}}class K extends o.Group{isBaseGroup=!0;type="BaseGroup";ignoreInvisibleWhenRaycast=!0;constructor(...e){super(...e)}raycast(e,t){return this.visible===!1&&this.ignoreInvisibleWhenRaycast===!0?!1:super.raycast(e,t)}}class Je extends o.Sprite{isBaseSprite=!0;type="BaseSprite";ignoreInvisibleWhenRaycast=!0;constructor(...e){super(...e)}raycast(e,t){return this.visible===!1&&this.ignoreInvisibleWhenRaycast===!0?!1:super.raycast(e,t)}}class J extends K{isModel=!0;type="Model";static memoryCache=new Map;mixer=null;animations=[];actions=new Map;constructor(){super()}async loadAsync(e){const{url:t,cache:s=!0,persistent:n=!0}=e;try{let r;s?J.memoryCache.has(t)?r=J.memoryCache.get(t):(r=U.loadAsync(t,{persistent:n}),J.memoryCache.set(t,r)):r=U.loadAsync(t,{persistent:n});const a=await r,c=pe.clone(a);return this.add(c),c.animations&&c.animations.length>0&&(this.animations=c.animations,this.mixer=new o.AnimationMixer(c)),c}catch(r){return console.error(`[Model] Failed to load model from ${t}:`,r),null}}playAnimation(e,t={}){if(!this.mixer||this.animations.length===0)return null;const{loop:s=!0,repetitions:n=1/0,timeScale:r=1,clampWhenFinished:a=!1}=t;let c;if(e===void 0?c=this.animations[0]:typeof e=="number"?c=this.animations[e]:c=this.animations.find(h=>h.name===e),!c)return console.warn(`[Model] Animation not found: ${e}`),null;let l=this.actions.get(c.name);return l||(l=this.mixer.clipAction(c),this.actions.set(c.name,l)),l.setLoop(s?o.LoopRepeat:o.LoopOnce,n),l.clampWhenFinished=a,l.timeScale=r,l.reset().play(),l}playAllAnimations(e={}){return this.animations.map((t,s)=>this.playAnimation(s,e)).filter(t=>t!==null)}stopAnimation(e){if(!this.mixer)return;if(e===void 0){this.mixer.stopAllAction();return}let t;typeof e=="number"?t=this.animations[e]?.name:t=e,t&&this.actions.get(t)?.stop()}updateAnimation(e){this.mixer?.update(e)}getBoundingBox(){return new o.Box3().setFromObject(this)}getCenter(){const e=new o.Vector3;return this.getBoundingBox().getCenter(e),e}setMaterial(e){this.traverse(t=>{t instanceof o.Mesh&&(t.material=e)})}static clearMemoryCache(){this.memoryCache.clear()}static async clearPersistentCache(){typeof caches<"u"&&await caches.delete("u-space-loader-cache")}}class Ze extends k{isSphereMesh=!0;type="SphereMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new o.SphereGeometry(e?.radius,e?.widthSegments,e?.heightSegments,e?.phiStart,e?.phiLength,e?.thetaStart,e?.thetaLength),this.material=new o.MeshStandardNodeMaterial(t)}}class le extends k{isTubeMesh=!0;type="TubeMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new o.TubeGeometry(e?.path,e?.tubularSegments,e?.radius,e?.radialSegments,e?.closed),this.material=new o.MeshStandardNodeMaterial(t)}}class Ht extends K{isTopology=!0;type="Topology";parameters={nodeColor:255,nodeRadius:.5,edgeColor:65280,edgeRadius:.1,pathColor:16711935,pathRadius:.2};nodes=new Map;adjacencyMap=new Map;graphGroup=null;pathMeshes=[];constructor(e){super(),e&&Object.assign(this.parameters,e)}addNode(e,t){this.nodes.has(e)&&console.warn(`[Topology] Node ${e} already exists. Overwriting.`),this.nodes.set(e,t),this.adjacencyMap.has(e)||this.adjacencyMap.set(e,new Map)}removeNode(e){if(!this.nodes.has(e)){console.warn(`[Topology] Node ${e} does not exist.`);return}this.nodes.delete(e),this.adjacencyMap.delete(e)}addEdge(e,t,s,n=!0){const r=this.nodes.get(e),a=this.nodes.get(t);if(!r||!a){console.error(`[Topology] Cannot add edge. One or both nodes not found: ${e}, ${t}`);return}const c=s??r.distanceTo(a);this.getNeighbors(e)?.set(t,c),n&&this.getNeighbors(t)?.set(e,c)}removeEdge(e,t,s=!0){this.getNeighbors(e)?.delete(t),s&&this.getNeighbors(t)?.delete(e)}getShortestPath(e,t){if(!this.nodes.has(e)||!this.nodes.has(t))return console.warn("[Topology] Start or End node not found."),[];const s=new Map,n=new Map,r=new Set;for(const[l]of this.nodes)s.set(l,1/0),n.set(l,null),r.add(l);for(s.set(e,0);r.size>0;){let l=null,h=1/0;for(const d of r){const p=s.get(d);p<h&&(h=p,l=d)}if(l===null||l===t||h===1/0)break;r.delete(l);const u=this.adjacencyMap?.get(l);if(u)for(const[d,p]of u){if(!r.has(d))continue;const m=s.get(l)+p;m<s.get(d)&&(s.set(d,m),n.set(d,l))}}const a=[];let c=t;if(n.get(t)===null&&e!==t)return[];for(;c!==null;){const l=this.nodes.get(c);l&&a.unshift(l),c=n.get(c)||null}return a}renderGraph(){this.clearGraph(),this.graphGroup=new o.Group;const e=new Ze({geometryParameters:{radius:this.parameters.nodeRadius,widthSegments:16,heightSegments:16},materialParameters:{color:this.parameters.nodeColor}});this.nodes.forEach((s,n)=>{const r=e.clone();r.position.copy(s),Object.assign(r.userData,{id:n,type:"node"}),this.graphGroup.add(r)});const t=new Set;this.adjacencyMap.forEach((s,n)=>{s.forEach((r,a)=>{const c=[n,a].sort().join("-");if(t.has(c))return;t.add(c);const l=this.nodes.get(n),h=this.nodes.get(a);if(l&&h){const u=new o.LineCurve3(l,h),d=new le({geometryParameters:{path:u,tubularSegments:1,radius:this.parameters.edgeRadius,radialSegments:8,closed:!1},materialParameters:{color:this.parameters.edgeColor}});Object.assign(d.userData,{from:n,to:a,weight:r,type:"edge"}),this.graphGroup.add(d)}})}),this.add(this.graphGroup)}clearGraph(){this.graphGroup&&(this.remove(this.graphGroup),this.graphGroup.traverse(e=>{e instanceof o.Mesh&&(e.geometry.dispose(),e.material.dispose())}),this.graphGroup=null)}renderPath(e,t=this.parameters.pathColor){if(e.length<2)return;const s=new o.CatmullRomCurve3(e,!1,"catmullrom",0),n=new le({geometryParameters:{path:s,tubularSegments:e.length*10,radius:this.parameters.pathRadius,closed:!1},materialParameters:{color:t}});return this.add(n),this.pathMeshes.push(n),n}clearPaths(){this.pathMeshes.forEach(e=>{this.remove(e),e.geometry.dispose(),e.material.dispose()}),this.pathMeshes=[]}exportData(){const e={};this.nodes.forEach((n,r)=>{e[r]={x:n.x,y:n.y,z:n.z}});const t=[],s=new Set;return this.adjacencyMap.forEach((n,r)=>{n.forEach((a,c)=>{const l=[r,c].sort().join("-");s.has(l)||(s.add(l),t.push({from:r,to:c,weight:a}))})}),{nodes:e,edges:t}}importData(e){this.clearGraph(),this.clearPaths(),this.nodes.clear(),this.adjacencyMap.clear(),Object.entries(e.nodes).forEach(([t,s])=>{this.addNode(t,new o.Vector3(s.x,s.y,s.z))}),e.edges.forEach(({from:t,to:s,weight:n})=>{this.addEdge(t,s,n)}),this.renderGraph()}dispose(){this.clearGraph(),this.clearPaths()}getNeighbors(e){return this.adjacencyMap.get(e)}}class $t extends Je{isPoi=!0;type="Poi";parameters={img:"",text:"",fontSize:32,fontFamily:"Arial",color:"#ffffff",iconSize:64,padding:10,backgroundColor:"rgba(0, 0, 0, 0)",borderRadius:8,textPosition:"right",scaleFactor:.01};_canvas=document.createElement("canvas");_lastParametersJSON="";constructor(e={}){super(new o.SpriteNodeMaterial),Object.assign(this.parameters,e),this.updateAsync()}async updateAsync(e={}){Object.assign(this.parameters,e);const t=JSON.stringify(this.parameters);if(t===this._lastParametersJSON)return;this._lastParametersJSON=t;const s=this._canvas,n=s.getContext("2d");if(!n)return;n.font=`${this.parameters.fontSize}px ${this.parameters.fontFamily}`;let r=null;this.parameters.img&&(r=await this._loadImage(this.parameters.img));const{text:a,fontSize:c,color:l,iconSize:h,padding:u,backgroundColor:d,borderRadius:p,textPosition:m,scaleFactor:g}=this.parameters,w=n.measureText(a),E=a?w.width:0,S=a?c:0;let b=0,v=0,C=0,A=0,L=0,x=0;const O=!!r,R=!!a;if(O&&R)switch(m){case"top":b=Math.max(h,E),v=h+u+S,L=(b-E)/2,x=S/2,C=(b-h)/2,A=S+u;break;case"bottom":b=Math.max(h,E),v=h+u+S,C=(b-h)/2,A=0,L=(b-E)/2,x=h+u+S/2;break;case"left":b=h+u+E,v=Math.max(h,S),L=0,x=v/2,C=E+u,A=(v-h)/2;break;default:b=h+u+E,v=Math.max(h,S),C=0,A=(v-h)/2,L=h+u,x=v/2;break}else O?(b=h,v=h,C=0,A=0):R&&(b=E,v=S,L=0,x=S/2);const T=b+u*2,N=v+u*2;if(s.width=T,s.height=N,n.font=`${c}px ${this.parameters.fontFamily}`,d&&(n.fillStyle=d,this._drawRoundedRect(n,0,0,T,N,p),n.fill()),O&&n.drawImage(r,C+u,A+u,h,h),R){n.fillStyle=l;const y=n.measureText(a),_=y.actualBoundingBoxAscent+y.actualBoundingBoxDescent,I=y.actualBoundingBoxAscent-_/2;n.textBaseline="alphabetic",n.fillText(a,L+u,x+u+I)}const F=this.material.map,P=new o.CanvasTexture(s);P.colorSpace=o.SRGBColorSpace,this.material.map=P,F?.dispose(),this.scale.set(T*g,N*g,1)}_loadImage(e){return new Promise((t,s)=>{if(typeof e=="string"){const n=new Image;n.crossOrigin="Anonymous",n.onload=()=>t(n),n.onerror=()=>s(new Error(`Failed to load image: ${e}`)),n.src=e}else t(e)})}_drawRoundedRect(e,t,s,n,r,a){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()}dispose(){this.material.map?.dispose(),this.material.dispose()}}class fe extends k{isShapeMesh=!0;type="ShapeMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new o.ShapeGeometry(e?.shape,e?.curveSegments),this.material=new o.MeshStandardNodeMaterial(t),this.geometry.rotateX(-Math.PI/2)}static createFromPoints(e,t={}){return new fe({...t,geometryParameters:{...t.geometryParameters,shape:new o.Shape(e.map(s=>new o.Vector2(s.x,-s.z)))}})}}class me extends k{isExtrudeMesh=!0;type="ExtrudeMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new o.ExtrudeGeometry(e?.shape,e?.options),this.material=new o.MeshStandardNodeMaterial(t),this.geometry.rotateX(-Math.PI/2)}static createFromPoints(e,t={}){return e&&e.length===0&&(e=void 0),new me({...t,geometryParameters:{...t.geometryParameters,shape:new o.Shape(e?.map(s=>new o.Vector2(s.x,-s.z)))}})}}class Vt extends k{isPlaneMesh=!0;type="PlaneMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new o.PlaneGeometry(e?.width,e?.height,e?.widthSegments,e?.heightSegments),this.material=new o.MeshStandardNodeMaterial(t)}}class Kt extends k{isCircleMesh=!0;type="CircleMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(new o.CircleGeometry(e?.radius,e?.segments,e?.thetaStart,e?.thetaLength),new o.MeshStandardNodeMaterial(t)),this.geometry.rotateX(-Math.PI/2)}}class G{static traverseMeshes(e,t){e.traverse(s=>{s instanceof o.Mesh&&t(s)})}}const qt=3,Xt=1,Qt=0,Yt=2,Jt=.001,be=new o.Vector3,H=new o.Vector3,Zt=new o.Quaternion;function xe(i){return i.isInstanceObject===!0}function we(i){let e=!1;return i.traverse(t=>{if(e)return;const s=t;e=s.isMesh===!0||s.isSprite===!0}),e}function es(i){let e=i;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}function Me(i){return i===void 0||!Number.isFinite(i)||i<=0?Yt:i}class ts{static flow(e={}){const{baseColor:t=16777215,flowColor:s=65280,speed:n=1,scale:r=3,intensity:a=4}=e,c=f.color(new o.Color(t)),l=f.color(new o.Color(s)),h=f.uv().x.mul(r).sub(f.time.mul(n)),u=f.pow(f.sin(h).add(1).mul(.5),a);return f.mix(c,l,u)}static breathe(e={}){const{baseColor:t=16777215,breathColor:s=65280,speed:n=1,intensity:r=2}=e,a=f.color(new o.Color(t)),c=f.color(new o.Color(s)),l=f.sin(f.time.mul(n)).add(1).mul(.5),h=f.pow(l,r);return f.mix(a,c,h)}static fluid(e={}){const{baseColor:t=16777215,flowColor:s=255,speed:n=1,scale:r=1,intensity:a=1,distortion:c=.5}=e,l=f.color(new o.Color(t)),h=f.color(new o.Color(s)),u=f.uv().mul(r),d=f.time.mul(n),p=f.mx_noise_float(u.add(d),1,0),m=u.add(p.mul(c)),g=f.mx_noise_float(m,1,0).add(1).mul(.5),w=f.pow(g,a);return f.mix(l,h,w)}static outline(e={}){let t=[...e.selectedObjects??[]];const s=[],n=new Map,r=new o.Box3;let a=null,c=null,l=null,h=null,u=null,d=e.instanceBoundsProxy??!0,p=e.instanceBoundsPadding??0,m=e.instanceBoundsMinSize??Jt,g=Me(e.downSampleRatio);const w=f.uniform(e.edgeStrength??qt),E=f.uniform(e.edgeThickness??Xt),S=f.uniform(e.edgeGlow??Qt),b=f.uniform(new o.Color(e.visibleEdgeColor??16777215)),v=f.uniform(new o.Color(e.hiddenEdgeColor??5125686)),C=()=>(h??=new o.BoxGeometry(1,1,1),h),A=()=>(u||(u=new o.MeshBasicNodeMaterial({color:16777215}),u.colorWrite=!1,u.depthWrite=!1,u.name="u-space.outline.instanceBoundsProxy"),u),L=y=>{const{source:_,mesh:I}=y,B=_.getInstanceBoundingBox?.(r,!0);if(!B||B.isEmpty()||!es(_)){I.visible=!1;return}B.getCenter(be),B.getSize(H);const D=Math.max(0,p),X=Math.max(0,m);H.set(Math.max(H.x+D*2,X),Math.max(H.y+D*2,X),Math.max(H.z+D*2,X)),I.visible=!0,I.layers.mask=_.layers.mask,I.matrix.compose(be,Zt,H),I.matrixWorldNeedsUpdate=!0},x=y=>{y.unsubscribe?.(),y.mesh.removeFromParent()},O=(y,_)=>{let I=n.get(y);if(!I){const B=new o.Mesh(C(),A());B.name=`u-space.outline.instanceBoundsProxy:${y.uuid}`,B.matrixAutoUpdate=!1,B.castShadow=!1,B.receiveShadow=!1,B.frustumCulled=!1,B.raycast=()=>{},B.userData.instanceObject=y,I={source:y,mesh:B,unsubscribe:y.onInstanceRenderDirty?.(()=>L(I))??null},n.set(y,I)}return I.mesh.parent!==_&&(I.mesh.removeFromParent(),_.add(I.mesh)),L(I),I.mesh.visible?I.mesh:null},R=(y,_)=>{const I=y.getInstanceRenderObject?.();return I&&we(I)?I:we(y)?y:d&&y.getInstanceBoundingBox?O(y,_):null},T=y=>{const _=new Set,I=new Set;for(const B of t){const D=xe(B)?R(B,y):B;D&&(_.add(D),xe(B)&&n.get(B)?.mesh===D&&I.add(B))}n.forEach((B,D)=>{I.has(D)||(x(B),n.delete(D))}),s.length=0,_.forEach(B=>s.push(B))},N=()=>{a?.dispose(),a=null},F=(y,_)=>{if(a&&c===y&&l===_)return a.downSampleRatio=g,a;N(),c=y,l=_,a=St.outline(y,_,{selectedObjects:s,edgeThickness:E,edgeGlow:S,downSampleRatio:g});const I=a.updateBefore.bind(a);return a.updateBefore=B=>(T(y),I(B)),a},P=((y,_)=>{const I=y.scene,B=y.camera;T(I);const D=F(I,B),X=D.visibleEdge.mul(b).add(D.hiddenEdge.mul(v)).mul(w);return f.add(_,f.vec4(X,0))});return Object.defineProperties(P,{outlineNode:{get:()=>a},selectedObjects:{get:()=>t}}),P.setSelectedObjects=y=>(t=[...y],c&&T(c),P),P.update=y=>(y.edgeStrength!==void 0&&(w.value=y.edgeStrength),y.edgeThickness!==void 0&&(E.value=y.edgeThickness),y.edgeGlow!==void 0&&(S.value=y.edgeGlow),y.visibleEdgeColor!==void 0&&b.value.set(y.visibleEdgeColor),y.hiddenEdgeColor!==void 0&&v.value.set(y.hiddenEdgeColor),y.instanceBoundsProxy!==void 0&&(d=y.instanceBoundsProxy),y.instanceBoundsPadding!==void 0&&(p=y.instanceBoundsPadding),y.instanceBoundsMinSize!==void 0&&(m=y.instanceBoundsMinSize),y.downSampleRatio!==void 0&&(g=Me(y.downSampleRatio),a&&(a.downSampleRatio=g)),c&&T(c),P),P.dispose=()=>{N(),n.forEach(x),n.clear(),h?.dispose(),u?.dispose(),h=null,u=null,t=[],s.length=0,c=null,l=null},P}}function ss(i){}const q="uSpaceHighlight",ee=`${q}/enabled`,et=`${q}/opacity`,tt=`${q}/color`,st=`${q}/overwrite`,nt=`${q}/multiplyOpacity`,re=`${q}/instancedOriginalOpacity`,oe="uSpaceBreathe",ie=`${oe}/enabled`,rt=`${oe}/color`,it=`${oe}/speed`,at=`${oe}/intensity`,ae=new WeakMap,ns=f.Fn(()=>{const i=f.userData(ee,"uint"),e=f.userData(tt,"uint"),t=f.userData(st,"uint"),s=ve(e),n=f.materialColor.mul(s),r=f.select(t.greaterThan(0),s,n),a=f.select(i.greaterThan(0),r,f.materialColor),c=f.userData(ie,"uint"),l=f.userData(rt,"uint"),h=f.userData(it,"float"),u=f.userData(at,"float"),d=ve(l),p=f.sin(f.time.mul(h)).add(1).mul(.5),m=f.pow(p,u),g=f.mix(a,d,m);return f.select(c.greaterThan(0),g,a)})(),rs=f.Fn(()=>{const i=f.userData(ee,"uint"),e=f.userData(et,"float"),t=f.userData(nt,"uint"),s=f.select(t.greaterThan(0),f.materialOpacity.mul(e),e);return f.select(i.greaterThan(0),s,f.materialOpacity)})();function Z(i){return Array.isArray(i.material)?i.material:[i.material]}function Se(i){Z(i).forEach(t=>{if(!t)return;let s=ae.get(t);s||(s={colorNode:t.colorNode,opacityNode:t.opacityNode,transparent:t.transparent,depthWrite:t.depthWrite,activeMeshes:new Set},ae.set(t,s)),s.activeMeshes.add(i),t.transparent=!0,t.colorNode=ns,t.opacityNode=rs,t.needsUpdate=!0})}function Ie(i){const e=i.userData[ee],t=i.userData[ie];if(e||t)return;Z(i).forEach(n=>{if(!n)return;const r=ae.get(n);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,ae.delete(n)))})}function is(i,e,t,s){const n=i,r=n.setInstanceHighlight;if(r)return r.call(i,e,t,s),!0;const a=n.setInstanceColor,c=n.setInstanceOpacity,l=n.getInstanceOpacity,h=n.getInstanceColor,u=n.hasInstanceColor;return!a||!c?!1:(i.userData[re]===void 0&&(i.userData[re]={hasColor:u?.call(i)??!1,color:h?.call(i,new o.Color).getHex()??16777215,opacity:l?.call(i)??1}),a.call(i,e),c.call(i,t),!0)}function as(i){const e=i,t=e.clearInstanceHighlight;if(t)return t.call(i),!0;const s=e.resetInstanceColor,n=e.setInstanceColor,r=e.setInstanceOpacity;if(!s||!r)return!1;const a=i.userData[re];return a&&(a.hasColor&&n?n.call(i,a.color):s.call(i),r.call(i,a.opacity),Reflect.deleteProperty(i.userData,re)),!0}class W{static highlightColor(e,t={}){const s=Array.isArray(e)?e:[e],{opacity:n=.5,color:r=16711680,overwrite:a=!1,depthWrite:c,multiplyOpacity:l=!1}=t,h=new o.Color(r).getHex();for(const u of s)is(u,r,n,a)||G.traverseMeshes(u,d=>{d.userData[ee]=1,d.userData[et]=n,d.userData[tt]=h,d.userData[st]=a?1:0,d.userData[nt]=l?1:0,Se(d),c!==void 0&&Z(d).forEach(m=>{m&&(m.depthWrite=c)})})}static removeHighlightColor(e){const t=Array.isArray(e)?e:[e];for(const s of t)as(s)||G.traverseMeshes(s,n=>{n.userData[ee]=0,Ie(n)})}static breatheColor(e,t={}){const s=Array.isArray(e)?e:[e],n=Object.assign({color:65280,speed:1,intensity:2},t);n.color=new o.Color(n.color).getHex();for(const r of s)G.traverseMeshes(r,a=>{a.userData[ie]=1,a.userData[rt]=n.color,a.userData[it]=n.speed,a.userData[at]=n.intensity,Se(a)})}static removeBreatheColor(e){const t=Array.isArray(e)?e:[e];for(const s of t)G.traverseMeshes(s,n=>{n.userData[ie]=0,Ie(n)})}static wireframe(e,t=!0){const s=Array.isArray(e)?e:[e];for(const n of s)G.traverseMeshes(n,r=>{Z(r).forEach(a=>{if(!a)return;const c=a;c.wireframe=t,c.needsUpdate=!0})})}static removeWireframe(e){W.wireframe(e,!1)}static fadeIn(e,t={}){const{duration:s=500}=t;return W._fade(e,0,1,s)}static fadeOut(e,t={}){const{duration:s=500}=t;return W._fade(e,1,0,s)}static _fade(e,t,s,n){const r=Array.isArray(e)?e:[e],a=new Map;for(const c of r)G.traverseMeshes(c,l=>{Z(l).forEach(h=>{if(!h||a.has(h))return;const u=h.opacity,d=h.transparent,p=s>=1?u:s;a.set(h,{material:h,targetOpacity:p,originalOpacity:u,originalTransparent:d}),h.transparent=!0,h.opacity=t,h.needsUpdate=!0})});return a.size===0?Promise.resolve():new Promise(c=>{const l=performance.now();let h=0;const u=()=>{const d=performance.now()-l,p=Math.min(d/n,1);if(!r[0].parent){cancelAnimationFrame(h),c();return}for(const{material:g,targetOpacity:w}of a.values())g.opacity=t+(w-t)*p,g.needsUpdate=!0;if(p<1)h=requestAnimationFrame(u);else{if(s>=1)for(const{material:g,originalOpacity:w,originalTransparent:E}of a.values())g.opacity=w,g.transparent=E,g.needsUpdate=!0;c()}};h=requestAnimationFrame(u)})}}const ve=i=>{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);return f.vec3(e,t,s)};class ot extends M.Tween{viewer;constructor(e,t){super(t),this.viewer=e}_update=({time:e})=>{const t=this.update(e);this.viewer.invalidate(),t||this.viewer.removeEventListener("afterControlsUpdate",this._update)};easingByMode(e){const t=cs[e];return super.easing(t)}start(e,t){return this.viewer.addEventListener("afterControlsUpdate",this._update),super.start(e,t)}stop(){return this.viewer.removeEventListener("afterControlsUpdate",this._update),super.stop()}}function os(i,e,t,s={},n,r){return new Promise((a,c)=>{const{duration:l=1e3,delay:h=0,repeat:u=!1,mode:d="Linear.None",yoyo:p=!1}=s,m=new ot(i,e).to(t,l).easingByMode(d).delay(h).onUpdate(g=>{n?.(g,m)}).onComplete(()=>{a()}).onStop(()=>{c("animation stop")}).onStart(()=>{r?.(m)});typeof u=="number"?m.repeat(u):typeof u=="boolean"&&u&&m.repeat(1/0),p&&m.repeatDelay(20),m.yoyo(p),m.start()})}const cs={"Linear.None":M.Easing.Linear.None,"Quadratic.In":M.Easing.Quadratic.In,"Quadratic.Out":M.Easing.Quadratic.Out,"Quadratic.InOut":M.Easing.Quadratic.InOut,"Cubic.In":M.Easing.Cubic.In,"Cubic.Out":M.Easing.Cubic.Out,"Cubic.InOut":M.Easing.Cubic.InOut,"Quartic.In":M.Easing.Quartic.In,"Quartic.Out":M.Easing.Quartic.Out,"Quartic.InOut":M.Easing.Quartic.InOut,"Quintic.In":M.Easing.Quintic.In,"Quintic.Out":M.Easing.Quintic.Out,"Quintic.InOut":M.Easing.Quintic.InOut,"Sinusoidal.In":M.Easing.Sinusoidal.In,"Sinusoidal.Out":M.Easing.Sinusoidal.Out,"Sinusoidal.InOut":M.Easing.Sinusoidal.InOut,"Exponential.In":M.Easing.Exponential.In,"Exponential.Out":M.Easing.Exponential.Out,"Exponential.InOut":M.Easing.Exponential.InOut,"Circular.In":M.Easing.Circular.In,"Circular.Out":M.Easing.Circular.Out,"Circular.InOut":M.Easing.Circular.InOut,"Elastic.In":M.Easing.Elastic.In,"Elastic.Out":M.Easing.Elastic.Out,"Elastic.InOut":M.Easing.Elastic.InOut,"Back.In":M.Easing.Back.In,"Back.Out":M.Easing.Back.Out,"Back.InOut":M.Easing.Back.InOut,"Bounce.In":M.Easing.Bounce.In,"Bounce.Out":M.Easing.Bounce.Out,"Bounce.InOut":M.Easing.Bounce.InOut};class ls{scene;planes=new Map;helpers=new Map;group;constructor(e){this.scene=e,this.group=new o.ClippingGroup,this.group.name="__clippingToolGroup",this.scene.add(this.group)}attach(){const e=[...this.scene.children];for(const t of e)t!==this.group&&this.group.add(t)}detach(){const e=[...this.group.children];for(const t of e)this.helpers.has(t.name)||this.scene.add(t)}enable(){this.group.enabled=!0}disable(){this.group.enabled=!1}addPlane(e,t={}){const{normal:s={x:0,y:-1,z:0},constant:n=0,showHelper:r=!1,helperSize:a=5,helperColor:c=16711680}=t,l=new o.Plane(new o.Vector3(s.x,s.y,s.z),n);return this.planes.set(e,l),this._syncPlanes(),r&&this.showHelper(e,a,c),l}addBox(e,t,s={}){const{showHelpers:n=!1,helperColor:r=16711680}=s,a=t.min,c=t.max,l=[{suffix:"+x",normal:{x:-1,y:0,z:0},constant:c.x},{suffix:"-x",normal:{x:1,y:0,z:0},constant:-a.x},{suffix:"+y",normal:{x:0,y:-1,z:0},constant:c.y},{suffix:"-y",normal:{x:0,y:1,z:0},constant:-a.y},{suffix:"+z",normal:{x:0,y:0,z:-1},constant:c.z},{suffix:"-z",normal:{x:0,y:0,z:1},constant:-a.z}],h=[];for(const u of l){const d=`${e}_${u.suffix}`;this.addPlane(d,{normal:u.normal,constant:u.constant,showHelper:n,helperColor:r}),h.push(d)}return h}addBoxFromObject(e,t,s=0,n={}){const r=new o.Box3().setFromObject(t);return r.expandByScalar(s),this.addBox(e,r,n)}setPlaneConstant(e,t){const s=this.planes.get(e);s&&(s.constant=t)}removePlane(e){this.planes.delete(e),this.hideHelper(e),this._syncPlanes()}removeBox(e){const t=["+x","-x","+y","-y","+z","-z"];for(const s of t)this.removePlane(`${e}_${s}`)}removeAll(){const e=Array.from(this.helpers.keys());for(const t of e)this.hideHelper(t);this.planes.clear(),this._syncPlanes()}showHelper(e,t=5,s=16711680){this.hideHelper(e);const n=this.planes.get(e);if(!n)return;const r=new o.PlaneHelper(n,t,new o.Color(s).getHex());r.name=e,this.helpers.set(e,r),this.scene.add(r)}hideHelper(e){const t=this.helpers.get(e);t&&(this.scene.remove(t),t.dispose(),this.helpers.delete(e))}get(e){return this.planes.get(e)}_syncPlanes(){this.group.clippingPlanes=Array.from(this.planes.values())}dispose(){this.detach(),this.removeAll(),this.scene.remove(this.group)}}class hs{scene;measurements=new Map;_idCounter=0;constructor(e){this.scene=e}measureDistance(e,t,s={}){const{lineColor:n=16776960}=s,r=new o.Vector3(e.x,e.y,e.z),a=new o.Vector3(t.x,t.y,t.z),c=r.distanceTo(a),l=`measure_dist_${this._idCounter++}`,h=new o.Group;h.name=l;const u=new o.BufferGeometry().setFromPoints([r,a]),d=new o.LineBasicMaterial({color:n}),p=new o.Line(u,d);h.add(p),this.scene.add(h);const m={id:l,type:"distance",value:c,unit:"m",points:[r,a],object:h};return this.measurements.set(l,m),m}measureArea(e,t={}){const{lineColor:s=65280}=t;if(e.length<3)throw new Error("MeasureTool.measureArea requires at least 3 points");const n=e.map(m=>new o.Vector3(m.x,m.y,m.z)),r=this._calculatePolygonArea(n),a=`measure_area_${this._idCounter++}`,c=new o.Group;c.name=a;const l=[...n,n[0]],h=new o.BufferGeometry().setFromPoints(l),u=new o.LineBasicMaterial({color:s}),d=new o.Line(h,u);c.add(d),this.scene.add(c);const p={id:a,type:"area",value:r,unit:"m²",points:n,object:c};return this.measurements.set(a,p),p}measureAngle(e,t,s,n={}){const{lineColor:r=16746496}=n,a=new o.Vector3(e.x,e.y,e.z),c=new o.Vector3(t.x,t.y,t.z),l=new o.Vector3(s.x,s.y,s.z),h=a.clone().sub(c).normalize(),u=l.clone().sub(c).normalize(),p=Math.acos(Math.max(-1,Math.min(1,h.dot(u))))*180/Math.PI,m=`measure_angle_${this._idCounter++}`,g=new o.Group;g.name=m;const w=new o.BufferGeometry().setFromPoints([a,c,l]),E=new o.LineBasicMaterial({color:r}),S=new o.Line(w,E);g.add(S),this.scene.add(g);const b={id:m,type:"angle",value:p,unit:"°",points:[a,c,l],object:g};return this.measurements.set(m,b),b}get(e){return this.measurements.get(e)}remove(e){const t=this.measurements.get(e);t&&(this.scene.remove(t.object),t.object.traverse(s=>{s.geometry?.dispose(),s.material?.dispose()}),this.measurements.delete(e))}removeAll(){const e=Array.from(this.measurements.keys());for(const t of e)this.remove(t)}getAll(){return Array.from(this.measurements.values())}_calculatePolygonArea(e){const t=e.length,s=new o.Vector3;for(let r=0;r<t;r++){const a=e[r],c=e[(r+1)%t],l=new o.Vector3().crossVectors(a,c);s.add(l)}const n=new o.Vector3;if(t>=3){const r=e[1].clone().sub(e[0]),a=e[2].clone().sub(e[0]);n.crossVectors(r,a).normalize()}return Math.abs(s.dot(n))/2}dispose(){this.removeAll()}}class us{scene;annotations=new Map;_idCounter=0;_createCSSObject=null;constructor(e){this.scene=e}setCSSObjectFactory(e){this._createCSSObject=e}add(e,t){this.annotations.has(e)&&this.remove(e);const s=new o.Group;s.name=`annotation_${e}`;const n=new o.Vector3(t.position.x,t.position.y,t.position.z);s.position.copy(n);const r=document.createElement("div");if(r.innerHTML=t.content,r.style.cssText=`
|
|
9
9
|
padding: 4px 8px;
|
|
10
10
|
background: rgba(0, 0, 0, 0.75);
|
|
11
11
|
color: #fff;
|
|
@@ -13,4 +13,4 @@
|
|
|
13
13
|
border-radius: 4px;
|
|
14
14
|
pointer-events: auto;
|
|
15
15
|
white-space: nowrap;
|
|
16
|
-
`,t.labelStyle)for(const l of Object.keys(t.labelStyle)){const d=t.labelStyle[l];d!==void 0&&(i.style[l]=d)}let a=null;const o=t.labelOffset||{x:0,y:2,z:0};if(t.showLeaderLine!==!1){const{lineColor:l=16777215}=t,d=new r.BufferGeometry().setFromPoints([new r.Vector3(0,0,0),new r.Vector3(o.x,o.y,o.z)]),u=new r.LineBasicMaterial({color:l});a=new r.Line(d,u),s.add(a)}if(this._createCSSObject){const l=this._createCSSObject(i);l.position.set(o.x,o.y,o.z),s.add(l)}this.scene.add(s);const c={id:e,options:t,group:s,labelElement:i,line:a};return this.annotations.set(e,c),c}addText(e,t,s={}){const n=`annotation_${this._idCounter++}`;return this.add(n,{position:t,content:e,...s})}updateContent(e,t){const s=this.annotations.get(e);s&&(s.labelElement.innerHTML=t,s.options.content=t)}updatePosition(e,t){const s=this.annotations.get(e);s&&(s.group.position.set(t.x,t.y,t.z),s.options.position=t)}show(e){const t=this.annotations.get(e);t&&(t.group.visible=!0)}hide(e){const t=this.annotations.get(e);t&&(t.group.visible=!1)}get(e){return this.annotations.get(e)}remove(e){const t=this.annotations.get(e);if(t){const s=[...t.group.children];for(const n of s)t.group.remove(n),n.geometry?.dispose(),n.material?.dispose();this.scene.remove(t.group),this.annotations.delete(e)}}removeAll(){const e=Array.from(this.annotations.keys());for(const t of e)this.remove(t)}showAll(){for(const e of this.annotations.values())e.group.visible=!0}hideAll(){for(const e of this.annotations.values())e.group.visible=!1}keys(){return Array.from(this.annotations.keys())}get size(){return this.annotations.size}dispose(){this.removeAll()}}const Be="0.0.28";window.__USPACE__={version:Be};Object.defineProperty(exports,"CSS2DObject",{enumerable:!0,get:()=>Y.CSS2DObject});Object.defineProperty(exports,"CSS3DObject",{enumerable:!0,get:()=>k.CSS3DObject});Object.defineProperty(exports,"CSS3DSprite",{enumerable:!0,get:()=>k.CSS3DSprite});exports.AnnotationManager=At;exports.BaseGroup=Z;exports.BaseMesh=R;exports.BaseSprite=xe;exports.CSSRenderer=ye;exports.CameraControls=me;exports.CircleMesh=xt;exports.ClippingTool=Lt;exports.ExtrudeMesh=te;exports.InteractionEvent=he;exports.InteractionManager=de;exports.LightManager=qe;exports.MaterialEffects=F;exports.MeasureTool=Bt;exports.Model=U;exports.ModelLoaderManager=O;exports.ObjectManager=ue;exports.ObjectUtils=A;exports.PlaneMesh=bt;exports.Poi=vt;exports.RenderPipeline=pe;exports.RoomEnvironment=ge;exports.SBMLoader=be;exports.SBMXLoader=we;exports.SceneManager=We;exports.Selection=$e;exports.ShapeMesh=ee;exports.SphereMesh=Se;exports.TSLEffects=St;exports.TextureLoaderManager=yt;exports.Topology=wt;exports.TubeMesh=J;exports.Tween=Le;exports.Viewer=tt;exports.reinterpretType=Ct;exports.tweenAnimation=Pt;exports.version=Be;
|
|
16
|
+
`,t.labelStyle)for(const h of Object.keys(t.labelStyle)){const u=t.labelStyle[h];u!==void 0&&(r.style[h]=u)}let a=null;const c=t.labelOffset||{x:0,y:2,z:0};if(t.showLeaderLine!==!1){const{lineColor:h=16777215}=t,u=new o.BufferGeometry().setFromPoints([new o.Vector3(0,0,0),new o.Vector3(c.x,c.y,c.z)]),d=new o.LineBasicMaterial({color:h});a=new o.Line(u,d),s.add(a)}if(this._createCSSObject){const h=this._createCSSObject(r);h.position.set(c.x,c.y,c.z),s.add(h)}this.scene.add(s);const l={id:e,options:t,group:s,labelElement:r,line:a};return this.annotations.set(e,l),l}addText(e,t,s={}){const n=`annotation_${this._idCounter++}`;return this.add(n,{position:t,content:e,...s})}updateContent(e,t){const s=this.annotations.get(e);s&&(s.labelElement.innerHTML=t,s.options.content=t)}updatePosition(e,t){const s=this.annotations.get(e);s&&(s.group.position.set(t.x,t.y,t.z),s.options.position=t)}show(e){const t=this.annotations.get(e);t&&(t.group.visible=!0)}hide(e){const t=this.annotations.get(e);t&&(t.group.visible=!1)}get(e){return this.annotations.get(e)}remove(e){const t=this.annotations.get(e);if(t){const s=[...t.group.children];for(const n of s)t.group.remove(n),n.geometry?.dispose(),n.material?.dispose();this.scene.remove(t.group),this.annotations.delete(e)}}removeAll(){const e=Array.from(this.annotations.keys());for(const t of e)this.remove(t)}showAll(){for(const e of this.annotations.values())e.group.visible=!0}hideAll(){for(const e of this.annotations.values())e.group.visible=!1}keys(){return Array.from(this.annotations.keys())}get size(){return this.annotations.size}dispose(){this.removeAll()}}const Ee=new o.Matrix4,ds=1e-6,ps=1e-6,Be="uSpaceInstanceOriginalMaterialState",he=0,ne=1,ct=2;function fs(i){let e=i;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}function ms(i,e){const t=i.elements,s=e.elements;for(let n=0;n<16;n++)if(Math.abs(t[n]-s[n])>ds)return!1;return!0}function lt(i){const e=i.material;return Array.isArray(e)?e:[e]}function ht(i){const e=i.userData,t=e[Be];if(t)return t;const s={transparent:i.transparent,opacity:i.opacity};return e[Be]=s,s}function gs(i,e){i.traverse(t=>{const s=t;s.isMesh&<(s).forEach(n=>{if(!n)return;const r=n,a=ht(r),c=a.opacity*e;r.transparent=a.transparent||c<1,r.opacity=c,r.needsUpdate=!0})})}function ys(i){i.traverse(e=>{const t=e;t.isMesh&<(t).forEach(s=>{if(!s)return;const n=s,r=ht(n);n.transparent=r.transparent,n.opacity=r.opacity,n.needsUpdate=!0})})}class bs extends K{isInstanceObject=!0;type="InstanceObject";instanceId="";instanceKind="";instanceName="";geometry=new o.BufferGeometry;boundingBox=null;boundingSphere=null;#t={color:null,colorMode:he,opacity:1};#a=null;#s=null;#e=null;#n=null;#r=new Set;#o=new o.Matrix4;#c=!1;#l=!0;#h=!1;#d;constructor(e={}){super(),this.#d=e.boundsName??"InstanceBounds"}setInstanceIdentity(e){let t=!1;if(e.id!==void 0){const s=e.id??"";this.instanceId!==s&&(this.instanceId=s,t=!0)}if(e.kind!==void 0){const s=e.kind??"";this.instanceKind!==s&&(this.instanceKind=s,t=!0)}if(e.name!==void 0){const s=e.name??"";this.instanceName!==s&&(this.instanceName=s,t=!0)}return t&&this.markInstanceRenderDirty(),this}setInstanceBounds(e){if(e.isEmpty())return this;this.#s&&this.remove(this.#s);const t=new o.BufferGeometry;t.boundingBox=e.clone();const s=new o.Object3D;return s.name=this.#d,s.visible=!1,s.geometry=t,s.raycast=()=>{},this.#s=s,this.add(s),this.#p(),this.markInstanceRenderDirty(),this}setInstanceRenderObject(e){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.#u(),this.#p(),this.markInstanceRenderDirty(),this}getInstanceRenderObject(){return this.#e}setInstanceMaterializer(e){return this.#n=e,this}hasInstanceMaterializer(e){return this.#n===e}clearInstanceMaterializer(e){return(e===void 0||this.#n===e)&&(this.#n=null),this}materialize(){return this.#n?.()??this.#e??null}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new o.Box3),this.getInstanceBoundingBox(this.boundingBox,!1)}computeBoundingSphere(){if(this.boundingSphere===null&&(this.boundingSphere=new o.Sphere),this.boundingBox===null&&this.computeBoundingBox(),!this.boundingBox||this.boundingBox.isEmpty()){this.boundingSphere.makeEmpty();return}this.boundingBox.getBoundingSphere(this.boundingSphere)}getInstanceBoundingBox(e=new o.Box3,t=!1){const s=this.#s?.geometry?.boundingBox;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),Ee.copy(this.matrixWorld).invert(),e.applyMatrix4(Ee)),e):e.makeEmpty()}setInstanceVisible(e){return this.visible===e?this:(this.visible=e,this.markInstanceRenderDirty(),this)}setInstanceColor(e){return this.#t.color=new o.Color(e),this.#t.colorMode=ne,this.#u(),this.markInstanceRenderDirty(),this}resetInstanceColor(){return this.#t.color===null?this:(this.#t.color=null,this.#t.colorMode=he,this.#u(),this.markInstanceRenderDirty(),this)}setInstanceOpacity(e){const t=Math.max(0,Math.min(1,e));return Math.abs(this.#t.opacity-t)<=ps?this:(this.#t.opacity=t,this.#u(),this.markInstanceRenderDirty(),this)}getInstanceColor(e=new o.Color){const t=this.#f();return t.color?e.copy(t.color):e.setRGB(1,1,1)}hasInstanceColor(){return this.#f().color!==null}getInstanceOpacity(){return this.#f().opacity}setInstanceHighlight(e,t,s=!1){return this.#a={color:new o.Color(e),colorMode:s?ne:ct,opacity:Math.max(0,Math.min(1,t))},this.#u(),this.markInstanceRenderDirty(),this}clearInstanceHighlight(){return this.#a===null?this:(this.#a=null,this.#u(),this.markInstanceRenderDirty(),this)}getInstanceColorMode(){return this.#f().colorMode}onInstanceRenderDirty(e){return this.#r.add(e),()=>this.#r.delete(e)}markInstanceRenderDirty(){return this.#r.forEach(e=>e()),this}updateMatrixWorld(e){super.updateMatrixWorld(e),this.#i()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.#i()}#i(){const e=fs(this);(!this.#c||!ms(this.matrixWorld,this.#o)||!this.#h||e!==this.#l)&&(this.#c=!0,this.#h=!0,this.#o.copy(this.matrixWorld),this.#l=e,this.markInstanceRenderDirty())}#p(){this.boundingBox=null,this.boundingSphere=null}#f(){return this.#a??this.#t}#u(){if(!this.#e)return;const e=this.#f();if(e.color){ys(this.#e),W.highlightColor(this.#e,{color:e.color,opacity:e.opacity,overwrite:e.colorMode===ne,multiplyOpacity:!0});return}W.removeHighlightColor(this.#e),gs(this.#e,e.opacity)}}function xs(i){return i.isInstanceObject===!0}const ws=new Set(["MeshBasicMaterial","MeshLambertMaterial","MeshPhongMaterial","MeshStandardMaterial","MeshPhysicalMaterial"]),Ce=new WeakMap;let Ms=1;const _e=new o.Matrix4,Y=new o.Matrix4,Oe=new o.Matrix4;function Ss(i,e,t=1e-6){const s=i.elements,n=e.elements;for(let r=0;r<16;r++)if(Math.abs(s[r]-n[r])>t)return!1;return!0}function ut(i){let e=i;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}function Is(i){const e=i.source.data;if(!e||typeof e!="object"&&typeof e!="function")return`texture:${i.uuid}`;let t=Ce.get(e);return t===void 0&&(t=Ms++,Ce.set(e,t)),`source:${t}`}function vs(i){return JSON.stringify([Is(i),i.mapping,i.channel,i.wrapS,i.wrapT,i.magFilter,i.minFilter,i.anisotropy,i.format,i.internalFormat,i.type,i.offset.toArray(),i.repeat.toArray(),i.center.toArray(),i.rotation,i.matrixAutoUpdate,i.matrix.toArray(),i.generateMipmaps,i.premultiplyAlpha,i.flipY,i.unpackAlignment,i.colorSpace,"compareFunction"in i?i.compareFunction:null])}function ue(i){if(Array.isArray(i))return i.map(ue);if(!i||typeof i!="object")return i;const e=i;return Object.fromEntries(Object.keys(e).sort().map(t=>[t,ue(e[t])]))}function de(i,e){if(Array.isArray(i))return i.map(s=>de(s,e));if(!i||typeof i!="object")return typeof i=="string"?e.get(i)??i:i;const t=i;return Object.fromEntries(Object.keys(t).filter(s=>s!=="metadata"&&s!=="uuid"&&s!=="name").sort().map(s=>[s,de(t[s],e)]))}function Es(i){if(!ws.has(i.type)||i.transparent||i.opacity<.999||i.visible===!1)return null;const e=i;if(Object.keys(e).some(r=>r.endsWith("Node")&&e[r]!=null)||Object.hasOwn(i,"onBeforeCompile"))return null;const t=new Map;Object.values(e).forEach(r=>{r instanceof o.Texture&&t.set(r.uuid,vs(r))});const s={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},n=i.toJSON(s);return JSON.stringify(ue(de(n,t)))}function Bs(i){if(Object.keys(i.morphAttributes).length>0||i.drawRange.start!==0||i.drawRange.count!==1/0)return null;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]);return e.some(t=>t===null)?null:JSON.stringify([i.index?.array.constructor.name??"non-indexed",e])}function Cs(i,e){const t=[],s=new Set,n=new Set,r=!e&&(i.animations.length>0||i.mixer!==null);return r&&n.add("animation"),i.updateWorldMatrix(!0,!0),_e.copy(i.matrixWorld).invert(),i.traverseVisible(a=>{if(!(a instanceof o.Mesh))return;if(r){s.add(a);return}if(a instanceof o.SkinnedMesh){s.add(a),n.add("skinned");return}if(a.morphTargetInfluences){s.add(a),n.add("morph");return}if(Array.isArray(a.material)){s.add(a),n.add("material-array");return}const c=Es(a.material),l=Bs(a.geometry);if(!c){s.add(a),n.add(a.material.transparent||a.material.opacity<.999?"transparent":`material:${a.material.type}`);return}if(!l){s.add(a),n.add("geometry-layout");return}if(a.matrixWorld.determinant()<=0){s.add(a),n.add("negative-scale");return}t.push({mesh:a,localMatrix:_e.clone().multiply(a.matrixWorld),materialKey:c,geometryKey:l})}),t.length===0&&s.size===0&&n.add("empty"),{meshes:t,fallbackMeshes:s,fallbackReasons:n}}function _s(i,e){const t=pe.clone(i),s=[],n=[];return i.traverse(r=>{r instanceof o.Mesh&&s.push(r)}),t.traverse(r=>{r instanceof o.Mesh&&n.push(r)}),s.forEach((r,a)=>{e.has(r)&&n[a]&&(n[a].visible=!1)}),t}function Os(i){const e=pe.clone(i),t=new Map,s=n=>{let r=t.get(n);return r||(r=n.clone(),t.set(n,r)),r};return e.traverse(n=>{n instanceof o.Mesh&&(n.material=Array.isArray(n.material)?n.material.map(s):s(n.material))}),e}function As(i){return Math.max(1,Math.ceil(Math.sqrt(Math.max(1,i))))}function Ls(i){const e=new o.DataTexture(new Float32Array(i*i*4),i,i,o.RGBAFormat,o.FloatType);return e.magFilter=o.NearestFilter,e.minFilter=o.NearestFilter,e.generateMipmaps=!1,e.needsUpdate=!0,e}function Ts(i,e){const t=i.clone(),s=f.attribute("batchObjectIndex","float").toInt(),n=f.int(f.textureSize(f.textureLoad(e),f.int(0)).x).toConst(),r=s.mod(n).toConst(),a=s.div(n).toConst(),c=f.textureLoad(e,f.ivec2(r,a)),l=t.colorNode??f.materialColor,h=f.select(c.a.greaterThan(1.5),l.mul(c.rgb),c.rgb);return t.colorNode=f.select(c.a.greaterThan(.5),h,l),t.maskNode=c.a.greaterThan(-.5),t.needsUpdate=!0,t}function Ae(i){let e=0,t=i.parent;for(;t;)e++,t=t.parent;return e}class Ns extends k{objectIndices;states;#t;constructor(e,t,s,n){super(e,t),this.objectIndices=s,this.states=n,this.userData.editableGeometryBatch=!0}raycast(e,t){if(this.visible===!1&&this.ignoreInvisibleWhenRaycast===!0)return!1;this.#t===void 0&&(this.#t=j.getGeometryBoundsTree(this.geometry));const s=[];this.#t?this.#t.raycastObject3D(this,e,s):super.raycast(e,s),s.forEach(n=>{const r=n.faceIndex;if(r==null)return;const a=r*3,c=this.geometry.index?.getX(a)??a,l=this.objectIndices[c],h=l===void 0?void 0:this.states[l],u=h?.instance;!h||h.materialized||!u||!ut(u)||u.getInstanceOpacity()<=.001||(n.object=u,n.batchObjectIndex=l,t.push(n))})}}class Ps extends K{isEditableGeometryBatchLayer=!0;type="EditableGeometryBatchLayer";options;stats={instances:0,sourceMeshes:0,batches:0,drawCallsSaved:0,vertices:0,indices:0,unsupportedInstances:0,unsupportedByReason:{}};#t=[];#a=new Set;#s=[];#e=new Map;#n=new Set;#r=null;#o=new o.Matrix4;#c=!1;#l=!1;#h=!1;constructor(e={}){super(),this.name="EditableGeometryBatches",this.options={maxVerticesPerBatch:e.maxVerticesPerBatch??15e5,maxIndicesPerBatch:e.maxIndicesPerBatch??45e5,freezeAnimations:e.freezeAnimations??!1}}addSource(e){if(this.#l)throw new Error("EditableGeometryBatchLayer has been disposed.");if(this.#c)throw new Error("EditableGeometryBatchLayer has already been built.");const{key:t,template:s,instances:n}=e,r=new Set;n.forEach(h=>{if(r.has(h)||this.#a.has(h))throw new Error("EditableGeometryBatchLayer cannot batch the same InstanceObject more than once.");r.add(h)});const{meshes:a,fallbackMeshes:c,fallbackReasons:l}=Cs(s,this.options.freezeAnimations);return r.forEach(h=>this.#a.add(h)),this.#t.push({key:t,template:s,instances:[...n],meshes:a,fallbackMeshes:c,fallbackReasons:l,bounds:new o.Box3().setFromObject(s)}),a.length>0}build(){if(this.#l)throw new Error("EditableGeometryBatchLayer has been disposed.");if(this.#c)throw new Error("EditableGeometryBatchLayer.build() can only be called once.");this.#c=!0,this.updateWorldMatrix(!0,!1),this.#o.copy(this.matrixWorld).invert();const e=[],t=new Map,s=(r,a,c,l)=>{if(c.length===0)return;const h=l.size>0?[...l]:["unknown"];e.push({key:r.key,template:a,instances:c,reasons:h}),h.forEach(u=>{this.stats.unsupportedByReason[u]=(this.stats.unsupportedByReason[u]??0)+c.length})};this.#t.forEach(r=>{const a=[],c=[];r.instances.forEach(h=>{h.updateWorldMatrix(!0,!1),Y.multiplyMatrices(this.#o,h.matrixWorld),Y.determinant()<=0?c.push(h):a.push({instance:h,matrix:Y.clone()})});const l=r.fallbackReasons.size>0?r.fallbackReasons:new Set(["unknown"]);if(r.meshes.length===0){s(r,r.template,a.map(({instance:h})=>h),l),s(r,r.template,c,new Set([...l,"negative-scale"]));return}r.fallbackMeshes.size>0&&s(r,_s(r.template,new Set(r.meshes.map(({mesh:h})=>h))),a.map(({instance:h})=>h),l),s(r,r.template,c,new Set([...r.fallbackReasons,"negative-scale"])),a.forEach(({instance:h,matrix:u})=>{const d=this.#s.length,p=()=>this.materialize(h),m={instance:h,template:r.template,initialMatrix:u,objectIndex:d,materialized:!1,materializer:p,unsubscribe:()=>{}};m.unsubscribe=h.onInstanceRenderDirty(()=>this.#p(m)),this.#s.push(m),this.#e.set(h,m),h.setInstanceBounds(r.bounds),h.setInstanceMaterializer(p),this.#n.add(m),r.meshes.forEach(({mesh:g,localMatrix:w,materialKey:E,geometryKey:S})=>{Oe.multiplyMatrices(u,w);const b=g.geometry.clone().applyMatrix4(Oe),v=b.getAttribute("position");b.setAttribute("batchObjectIndex",new o.Float32BufferAttribute(new Float32Array(v.count).fill(d),1));const C=JSON.stringify([E,S,g.castShadow,g.receiveShadow,g.renderOrder]),A=t.get(C),L={geometry:b,material:g.material,castShadow:g.castShadow,receiveShadow:g.receiveShadow,renderOrder:g.renderOrder,objectIndices:new Array(v.count).fill(d)};A?A.push(L):t.set(C,[L]),this.stats.sourceMeshes++,this.stats.vertices+=v.count,this.stats.indices+=b.index?.count??v.count})})}),this.stats.instances=this.#s.length,this.stats.unsupportedInstances=e.reduce((r,a)=>r+a.instances.length,0);const n=As(this.#s.length);return this.#r=Ls(n),this.#i(),t.forEach(r=>this.#d(r)),this.stats.batches=this.children.length,this.stats.drawCallsSaved=Math.max(0,this.stats.sourceMeshes-this.stats.batches),this.children.forEach(r=>{r instanceof o.Mesh&&(r.onBeforeRender=()=>this.#i())}),{stats:{...this.stats},unsupported:e}}materialize(e){const t=this.#e.get(e);if(!t||t.materialized)return e.getInstanceRenderObject();const s=Os(t.template);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.#n.add(t),this.dispatchEvent({type:"materialize",instance:e,object:s}),s}#d(e){const t=[];let s=[],n=0,r=0;e.forEach(a=>{const c=a.geometry.getAttribute("position").count,l=a.geometry.index?.count??c;s.length>0&&(n+c>this.options.maxVerticesPerBatch||r+l>this.options.maxIndicesPerBatch)&&(t.push(s),s=[],n=0,r=0),s.push(a),n+=c,r+=l}),s.length>0&&t.push(s),t.forEach(a=>{const c=It.mergeGeometries(a.map(p=>p.geometry),!1);if(a.forEach(p=>p.geometry.dispose()),!c||!this.#r)return;c.computeBoundingBox(),c.computeBoundingSphere();const l=a[0],h=a.flatMap(p=>p.objectIndices),u=Ts(l.material,this.#r),d=new Ns(c,u,h,this.#s);d.name=`EditableGeometryBatch:${this.children.length}`,d.castShadow=l.castShadow,d.receiveShadow=l.receiveShadow,d.renderOrder=l.renderOrder,d.matrixAutoUpdate=!1,this.add(d)})}#i(){if(!(!this.#r||this.#n.size===0||this.#h)){this.#h=!0;try{this.updateWorldMatrix(!0,!1),this.#o.copy(this.matrixWorld).invert();const e=this.#r.image.data;[...this.#n].sort((t,s)=>Ae(t.instance)-Ae(s.instance)).forEach(t=>{const{instance:s,objectIndex:n}=t;s.updateWorldMatrix(!0,!1),Y.multiplyMatrices(this.#o,s.matrixWorld),!t.materialized&&s.getInstanceRenderObject()!==null&&!s.hasInstanceMaterializer(t.materializer)&&(t.materialized=!0),!t.materialized&&!Ss(Y,t.initialMatrix)&&this.materialize(s),!t.materialized&&s.getInstanceOpacity()<.999&&this.materialize(s);const r=n*4,a=!t.materialized&&ut(s)&&s.getInstanceOpacity()>.001,c=s.getInstanceColor();e[r]=c.r,e[r+1]=c.g,e[r+2]=c.b,e[r+3]=a?s.getInstanceColorMode():-1,this.#n.delete(t)}),this.#r.needsUpdate=!0}finally{this.#h=!1}this.#n.size>0&&this.#i()}}#p(e){this.#n.add(e),this.#i()}dispose(){this.#l||(this.#l=!0,this.#s.forEach(e=>{e.unsubscribe(),e.instance.clearInstanceMaterializer(e.materializer)}),this.#s.length=0,this.#e.clear(),this.#a.clear(),this.#n.clear(),this.#t.length=0,this.#r?.dispose(),this.#r=null,this.traverse(e=>{if(!(e instanceof o.Mesh))return;e.geometry.dispose(),(Array.isArray(e.material)?e.material:[e.material]).forEach(s=>s.dispose())}),this.clear())}}const Le=new o.Matrix4,te=new o.Matrix4,Te=new o.Matrix4,Ne=new o.Matrix4,Pe=new o.Box3,De=new o.Sphere,Re=new o.Sphere,Ds=new o.Frustum,$=new o.Color,je=new o.Vector2,ze=new o.Vector3,Ue=new o.Matrix4,ke=new o.Matrix4,Ge=new o.Sphere,se=[],dt=1e-6,z=1e-6,pt=.999,Rs=0,We=1;function js(i,e,t){const s=i.elements;for(let n=0;n<16;n++)if(Math.abs(s[n]-e[t+n])>dt)return!1;return!0}function zs(i,e,t,s){return Math.abs(i.r-t[s])<=z&&Math.abs(i.g-t[s+1])<=z&&Math.abs(i.b-t[s+2])<=z&&Math.abs(e-t[s+3])<=z}function Fe(i,e){const t=i.elements,s=e.elements;for(let n=0;n<16;n++)if(Math.abs(t[n]-s[n])>dt)return!1;return!0}function ce(i){let e=i;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}function Us(i){const e=i.geometry.morphAttributes;return Object.values(e).some(t=>t?.length)}function ks(i){const e=i.material;if(!Array.isArray(e))return!0;if(e.length===0||!e.every(Boolean))return!1;const t=i.geometry.groups;return t.length===0?!1:t.every(s=>{const n=s.materialIndex??0;return Number.isInteger(s.start)&&s.start>=0&&Number.isInteger(s.count)&&s.count>0&&Number.isInteger(n)&&n>=0&&n<e.length})}function Gs(i){return!i.isSkinnedMesh&&!Us(i)&&ks(i)}function He(i){return Array.isArray(i)?i:[i]}function ft(i){return i.transparent||i.opacity<pt}function $e(i,e,t){const s=i.clone(),n=f.instancedBufferAttribute(e,"vec4",4,0),r=f.instancedBufferAttribute(t,"float",1,0),a=s.colorNode??f.materialColor,c=s.opacityNode?f.float(s.opacityNode):f.materialOpacity,l=f.select(n.a.greaterThan(1.5),a.mul(n.rgb),n.rgb);return s.colorNode=f.select(n.a.greaterThan(.5),l,a),s.opacityNode=c.mul(r),s.transparent=ft(i),s.needsUpdate=!0,s}function Ws(i,e,t){return Array.isArray(i)?i.map(s=>$e(s,e,t)):$e(i,e,t)}function Fs(i){const e=[],t=new o.Matrix4;let s=!1;return i.updateWorldMatrix(!0,!0),t.copy(i.matrixWorld).invert(),i.traverse(n=>{if(!s&&!(!(n instanceof o.Mesh)||!n.visible)){if(!Gs(n)){s=!0;return}n.updateWorldMatrix(!0,!1),e.push({mesh:n,localMatrix:t.clone().multiply(n.matrixWorld)})}}),s?[]:e}function Hs(i){const e=new o.Box3;return i.forEach(({mesh:t,localMatrix:s})=>{const n=t.geometry;n.boundingBox||n.computeBoundingBox(),n.boundingBox&&(Pe.copy(n.boundingBox).applyMatrix4(s),e.union(Pe))}),e}function V(i){const e=i;"needsUpdate"in e&&(e.needsUpdate=!0)}function Ve(i,e=We){let t=Math.max(We,e);for(;t<i;)t*=2;return t}function $s(i){return i!==null&&typeof i=="object"&&Symbol.iterator in i}class Vs extends K{isModelInstancedLayer=!0;type="ModelInstancedLayer";#t=[];#a=new Map;#s=new Map;#e=new Map;#n=!0;#r=!1;#o=!0;#c=Rs;#l;#h;constructor(e={}){super(),this.name=e.name??"ModelInstances",this.#l=e.instanceKind??"",this.#h=e.getHitUserData??(()=>({}))}get instanceKind(){return this.#l}getInstances(){const e=[];return this.#i(t=>e.push(t)),e}getInstanceById(e){return this.#x(),this.#e.get(e)}hasInstance(e){return this.#x(),this.#e.has(e)}getInstanceCulling(){return{enabled:this.#r,frustum:this.#o,minScreenRadius:this.#c}}setInstanceCulling(e={}){let t=!1;if(e.enabled!==void 0&&this.#r!==e.enabled&&(this.#r=e.enabled,t=!0),e.frustum!==void 0&&this.#o!==e.frustum&&(this.#o=e.frustum,t=!0),e.minScreenRadius!==void 0){const s=Math.max(0,e.minScreenRadius);Math.abs(this.#c-s)>z&&(this.#c=s,t=!0)}return t&&this.#t.forEach(s=>this.#v(s)),this}setInstanceVisible(e){return this.visible!==e&&(this.visible=e),this.#i(t=>{t.setInstanceVisible(e)}),this}setInstanceColor(e){return this.#i(t=>{t.setInstanceColor(e)}),this}resetInstanceColor(){return this.#i(e=>{e.resetInstanceColor()}),this}setInstanceOpacity(e){return this.#i(t=>{t.setInstanceOpacity(e)}),this}setInstanceHighlight(e,t,s=!1){return this.#i(n=>{n.setInstanceHighlight(e,t,s)}),this}clearInstanceHighlight(){return this.#i(e=>{e.clearInstanceHighlight()}),this}reserveBatch(e,t,s){const n=Math.floor(s);return n<=0?!1:this.#d(e,t,n)!==null}addInstance(e,t,s){return this.addInstances(e,t,[s])}addInstances(e,t,s){if(s.length===0)return!1;const n=this.#a.has(e),r=this.#d(e,t,s.length);if(!r)return!1;const a=[],c=new Set;return s.forEach(l=>{c.has(l)||(c.add(l),this.#s.get(l)===r)||a.push(l)}),a.length===0?!0:this.#B(a)?(a.forEach(l=>{const h=this.#s.get(l);h&&h!==r&&this.#S(h,l)}),this.#M(r,r.instances.length+a.length),a.forEach(l=>{l.setInstanceBounds(r.templateBounds),r.instances.push(l),this.#s.set(l,r),r.unsubscribeByInstance.set(l,l.onInstanceRenderDirty(()=>{this.#g(),this.#y(r)}))}),this.#g(),this.#b(r),this.#y(r),!0):(!n&&r.instances.length===0&&this.#m(r),!1)}removeInstance(e){return this.removeInstances([e])>0}removeInstances(e){const t=new Set,s=new Set,n=typeof e=="string"||!$s(e)?[e]:e;for(const a of n)typeof a=="string"?t.add(a):this.#s.has(a)&&s.add(a);t.size>0&&(this.#x(),t.forEach(a=>{const c=this.#e.get(a);c&&s.add(c)}));let r=0;return s.forEach(a=>{const c=this.#s.get(a);c&&this.#S(c,a)&&r++}),r}removeBatch(e){const t=this.#a.get(e);return t?(this.#m(t),!0):!1}clearBatches(){return[...this.#a.values()].forEach(e=>this.#m(e)),this}#d(e,t,s){const n=this.#a.get(e);if(n)return this.#M(n,s),n;if(t.animations?.length)return null;const r=Fs(t);if(r.length===0)return null;const a=Hs(r),c=new o.Group;c.name=e,this.add(c);const l={url:e,batch:c,templateMeshes:r,templateBounds:a,records:[],instances:[],unsubscribeByInstance:new Map,capacity:Ve(s)};return r.forEach(({mesh:h,localMatrix:u},d)=>{const p=this.#p(l,h,u,d);l.records.push(p),this.#t.push(p)}),this.#a.set(e,l),this.#b(l),l}#i(e){const t=new Set;this.#a.forEach(s=>{s.instances.forEach(n=>{t.has(n)||(t.add(n),e(n))})})}#p(e,t,s,n){const r=new o.InstancedBufferAttribute(new Float32Array(e.capacity*4),4),a=new o.InstancedBufferAttribute(new Float32Array(e.capacity).fill(1),1);r.setUsage(o.DynamicDrawUsage),a.setUsage(o.DynamicDrawUsage);const c=Ws(t.material,r,a),l=He(c),h=He(t.material).some(ft),u=new o.InstancedMesh(t.geometry,c,e.capacity);u.instanceMatrix=new o.StorageInstancedBufferAttribute(e.capacity,16),u.count=0,u.name=t.name||`${e.url}#${n}`,u.castShadow=t.castShadow,u.receiveShadow=t.receiveShadow,u.frustumCulled=!0,u.matrixAutoUpdate=!1,u.instanceMatrix.setUsage(o.DynamicDrawUsage),u.userData.url=e.url;const d=new o.Mesh(t.geometry,c);d.matrixAutoUpdate=!1;const p={batchRecord:e,mesh:u,boundsTree:void 0,raycastMesh:d,localMatrix:s.clone(),fullBoundingSphere:new o.Sphere,materials:l,hasSourceTransparency:h,colorAttribute:r,opacityAttribute:a,renderedInstances:[],visibleInstances:[],lastCameraMatrixWorldInverse:new o.Matrix4,lastCameraProjectionMatrix:new o.Matrix4,lastViewportHeight:0,hasLastCameraState:!1,dirty:!0};u.userData.getInstanceObjectByRenderIndex=g=>p.renderedInstances[g],u.userData.raycastAcceleration="lazy";const m=u.raycast.bind(u);return u.raycast=(g,w)=>{if(this.#E(p),!this.#f(p,g))return;p.boundsTree===void 0&&(p.boundsTree=j.getGeometryBoundsTree(p.mesh.geometry),p.mesh.userData.raycastAcceleration=p.boundsTree?"three-mesh-bvh":"default");const E=w.length;p.boundsTree?this.#u(p,g,w):m(g,w);for(let S=E;S<w.length;){const b=w[S],v=b.instanceId;if(v===void 0){S++;continue}const C=p.renderedInstances[v];if(!C||!ce(C)){w.splice(S,1);continue}b.object=C,b.instanceObject=C,b.instanceObjectId=C.instanceId,b.instanceKind=C.instanceKind||this.#l,b.instanceName=C.instanceName,b.instanceIndex=v,Object.assign(b,this.#h(C,v)),S++}},u.onBeforeRender=(g,w,E)=>this.#E(p,g,E),e.batch.add(u),p}#f(e,t){const{mesh:s}=e;return s.count===0?!1:(s.boundingSphere===null&&s.computeBoundingSphere(),s.boundingSphere?(Ge.copy(s.boundingSphere).applyMatrix4(s.matrixWorld),t.ray.intersectsSphere(Ge)):!0)}#u(e,t,s){const{mesh:n,boundsTree:r,raycastMesh:a}=e;if(!(!r||n.count===0)){a.geometry=n.geometry,a.material=n.material;for(let c=0;c<n.count;c++)n.getMatrixAt(c,Ue),ke.multiplyMatrices(n.matrixWorld,Ue),a.matrixWorld.copy(ke),se.length=0,r.raycastObject3D(a,t,se),se.forEach(l=>{l.instanceId=c,l.object=n,s.push(l)}),se.length=0}}#M(e,t){if(t<=e.capacity)return;e.capacity=Ve(t,e.capacity);const s=new Set(e.records);s.forEach(n=>this.#I(n)),this.#t=this.#t.filter(n=>!s.has(n)),e.records=e.templateMeshes.map(({mesh:n,localMatrix:r},a)=>{const c=this.#p(e,n,r,a);return this.#t.push(c),c}),this.#y(e)}#S(e,t){const s=e.instances.indexOf(t);return s===-1?!1:(e.instances.splice(s,1),e.records.forEach(n=>n.visibleInstances.splice(s,1)),this.#s.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))}#m(e){e.unsubscribeByInstance.forEach(s=>s()),e.instances.forEach(s=>this.#s.delete(s)),e.unsubscribeByInstance.clear(),e.instances.length=0,this.#g();const t=new Set(e.records);t.forEach(s=>this.#I(s)),this.#t=this.#t.filter(s=>!t.has(s)),e.records.length=0,e.templateMeshes.length=0,this.#a.delete(e.url),this.remove(e.batch)}#I(e){e.batchRecord.batch.remove(e.mesh),e.mesh.dispose(),e.materials.forEach(t=>t.dispose())}#b(e){Object.assign(e.batch.userData,{url:e.url,count:e.instances.length,capacity:e.capacity,instanceKind:this.#l}),delete e.batch.userData.sceneInstances,delete e.batch.userData.facilities,e.records.forEach(t=>{delete t.mesh.userData.instances})}#B(e){const t=new Set(e),s=new Map;for(const r of e){const{instanceId:a}=r;if(!a)continue;const c=s.get(a);if(c&&c!==r)return!1;s.set(a,r)}let n=!0;return s.forEach((r,a)=>{n&&this.#i(c=>{!n||t.has(c)||c.instanceId===a&&(n=!1)})}),n}#x(){if(!this.#n)return;this.#e.clear();const e=new Set;this.#i(t=>{const{instanceId:s}=t;if(!s||e.has(s))return;const n=this.#e.get(s);if(n&&n!==t){this.#e.delete(s),e.add(s);return}this.#e.set(s,t)}),this.#n=!1}#g(){this.#n=!0}#y(e){e.records.forEach(t=>this.#v(t))}#v(e){e.dirty=!0,e.hasLastCameraState=!1,e.mesh.visible=!0,e.mesh.frustumCulled=!1,V(e.batchRecord.batch)}#E(e,t,s){const n=this.#_(t),r=this.#O(e,s,n);!e.dirty&&!this.#C(e)&&!r||this.#N(e,s,n)}#C(e){const{instances:t}=e.batchRecord;for(let s=0;s<t.length;s++)if(e.visibleInstances[s]!==ce(t[s]))return e.dirty=!0,V(e.batchRecord.batch),!0;return!1}#_(e){return e?.getDrawingBufferSize?(e.getDrawingBufferSize(je),je.y):0}#O(e,t,s){return this.#w(t,s)?e.hasLastCameraState?!Fe(e.lastCameraMatrixWorldInverse,t.matrixWorldInverse)||!Fe(e.lastCameraProjectionMatrix,t.projectionMatrix)||Math.abs(e.lastViewportHeight-s)>z:!0:!1}#w(e,t){return this.#r&&e!==void 0&&(this.#o||this.#c>0&&t>0)}#A(e,t){if(!this.#w(e,t))return null;let s=null;return this.#o&&(Ne.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),s=Ds.setFromProjectionMatrix(Ne)),{camera:e,frustum:s,viewportHeight:t}}#L(e,t){return t?t.frustum&&!t.frustum.intersectsSphere(e)?!1:this.#c<=0||t.viewportHeight<=0?!0:this.#T(e,t.camera,t.viewportHeight)>=this.#c:!0}#T(e,t,s){const n=Math.abs(t.projectionMatrix.elements[5]);if(n<=z)return 1/0;if(t.isOrthographicCamera)return e.radius*n*s*.5;ze.copy(e.center).applyMatrix4(t.matrixWorldInverse);const r=-ze.z;return r<=z?1/0:e.radius*n*s*.5/r}#N(e,t,s=0){this.updateWorldMatrix(!0,!1),Le.copy(this.matrixWorld).invert();const n=e.mesh.instanceMatrix.array,r=e.colorAttribute.array,a=e.opacityAttribute.array,c=e.mesh.geometry;let l=!1,h=!1,u=!1,d=0,p=0,m=!1;const g=e.mesh.count,w=this.#A(t,s);c.boundingSphere||c.computeBoundingSphere(),e.fullBoundingSphere.makeEmpty(),e.renderedInstances.length=0,e.batchRecord.instances.forEach((b,v)=>{const C=ce(b);e.visibleInstances[v]=C,b.updateWorldMatrix(!0,!1),te.multiplyMatrices(Le,b.matrixWorld).multiply(e.localMatrix);const A=b.getInstanceOpacity();if(!(C&&A>z)||(p++,c.boundingSphere&&(De.copy(c.boundingSphere).applyMatrix4(te),e.fullBoundingSphere.union(De),w&&(Te.multiplyMatrices(b.matrixWorld,e.localMatrix),Re.copy(c.boundingSphere).applyMatrix4(Te),!this.#L(Re,w)))))return;const x=d,O=x*16;js(te,n,O)||(e.mesh.setMatrixAt(x,te),l=!0),$.copy(b.getInstanceColor($));const R=b.getInstanceColorMode(),T=x*4;zs($,R,r,T)||(e.colorAttribute.setXYZW(x,$.r,$.g,$.b,R),h=!0),A<pt&&(m=!0),Math.abs(A-a[x])>z&&(e.opacityAttribute.setX(x,A),u=!0),e.renderedInstances[x]=b,d++}),e.mesh.count=d,g!==d&&(l=!0,h=!0,u=!0,V(e.batchRecord.batch));const E=p>0;e.mesh.visible!==E&&(e.mesh.visible=E,V(e.batchRecord.batch)),e.mesh.frustumCulled!==!0&&(e.mesh.frustumCulled=!0,V(e.batchRecord.batch)),l&&(e.mesh.instanceMatrix.needsUpdate=!0),h&&(e.colorAttribute.needsUpdate=!0),u&&(e.opacityAttribute.needsUpdate=!0),e.mesh.boundingSphere===null&&(e.mesh.boundingSphere=new o.Sphere),e.mesh.boundingSphere.copy(e.fullBoundingSphere);const S=e.hasSourceTransparency||m;e.materials.forEach(b=>{b.transparent!==S&&(b.transparent=S,b.needsUpdate=!0,V(e.batchRecord.batch))}),t&&this.#w(t,s)?(e.lastCameraMatrixWorldInverse.copy(t.matrixWorldInverse),e.lastCameraProjectionMatrix.copy(t.projectionMatrix),e.lastViewportHeight=s,e.hasLastCameraState=!0):e.hasLastCameraState=!1,e.dirty=!1}}const mt="0.0.30";typeof window<"u"&&(window.__USPACE__={version:mt});exports.CSSRenderer=j.CSSRenderer;exports.CameraControls=j.CameraControls;exports.InteractionEvent=j.InteractionEvent;exports.InteractionManager=j.InteractionManager;exports.ObjectManager=j.ObjectManager;exports.RenderPipeline=j.RenderPipeline;exports.RoomEnvironment=j.RoomEnvironment;exports.Viewer=j.Viewer;exports.enableMeshBVHRaycast=j.enableMeshBVHRaycast;exports.getGeometryBoundsTree=j.getGeometryBoundsTree;Object.defineProperty(exports,"CSS2DObject",{enumerable:!0,get:()=>vt.CSS2DObject});Object.defineProperty(exports,"CSS3DObject",{enumerable:!0,get:()=>qe.CSS3DObject});Object.defineProperty(exports,"CSS3DSprite",{enumerable:!0,get:()=>qe.CSS3DSprite});exports.AnnotationManager=us;exports.BaseGroup=K;exports.BaseMesh=k;exports.BaseSprite=Je;exports.CircleMesh=Kt;exports.ClippingTool=ls;exports.EditableGeometryBatchLayer=Ps;exports.ExtrudeMesh=me;exports.INSTANCE_COLOR_MODE_NONE=he;exports.INSTANCE_COLOR_MODE_OVERRIDE=ne;exports.INSTANCE_COLOR_MODE_TINT=ct;exports.InstanceObject=bs;exports.LightManager=Ct;exports.MaterialEffects=W;exports.MeasureTool=hs;exports.Model=J;exports.ModelInstancedLayer=Vs;exports.ModelLoaderManager=U;exports.ObjectUtils=G;exports.PlaneMesh=Vt;exports.Poi=$t;exports.SBMLoader=Ye;exports.SBMXLoader=Xe;exports.SceneManager=Bt;exports.Selection=Et;exports.ShapeMesh=fe;exports.SphereMesh=Ze;exports.TSLEffects=ts;exports.TextureLoaderManager=Ft;exports.Topology=Ht;exports.TubeMesh=le;exports.Tween=ot;exports.isInstanceObject=xs;exports.reinterpretType=ss;exports.tweenAnimation=os;exports.version=mt;
|