u-space 0.0.16 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +3 -3
- package/dist/index.js +165 -140
- package/dist/plugins/atmosphere/Atmosphere.d.ts +47 -3
- package/dist/plugins/atmosphere/index.cjs +1 -1
- package/dist/plugins/atmosphere/index.js +299 -3
- package/dist/plugins/u-manager/index.cjs +18 -18
- package/dist/plugins/u-manager/index.js +1463 -1455
- package/dist/plugins/u-manager/semantics/FloorMesh.d.ts +24 -3
- package/dist/src/viewers/RenderPipeline.d.ts +8 -0
- package/docs/api-objects.md +2 -0
- package/docs/api-plugin-atmosphere.md +104 -2
- package/docs/api-render-pipeline.md +20 -4
- package/docs/changelog.md +30 -0
- package/docs/index.md +1 -1
- package/docs/mcp.md +1 -1
- package/package.json +2 -3
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("three/webgpu"),u=require("three/tsl"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("three/webgpu"),u=require("three/tsl"),Oe=require("three/addons/tsl/display/BloomNode.js"),Le=require("three/addons/tsl/display/SSGINode.js"),Ae=require("three/addons/tsl/display/TRAANode.js"),re=require("camera-controls"),Be=require("three/addons/environments/RoomEnvironment.js"),Re=require("three/addons/helpers/ViewHelper.js"),K=require("three/addons/renderers/CSS2DRenderer.js"),D=require("three/addons/renderers/CSS3DRenderer.js"),ae=require("three/addons/loaders/GLTFLoader.js"),Ie=require("three/addons/loaders/FBXLoader.js"),je=require("three/addons/loaders/OBJLoader.js"),Ne=require("three/addons/loaders/STLLoader.js"),ze=require("three/addons/loaders/DRACOLoader.js"),De=require("three/addons/loaders/KTX2Loader.js"),Z=require("three/addons/libs/meshopt_decoder.module.js"),ke=require("three/addons/loaders/HDRLoader.js"),Ue=require("three/addons/utils/SkeletonUtils.js"),f=require("three/addons/libs/tween.module.js");class oe{type;target;currentTarget;intersect;originalEvent;_propagationStopped=!1;constructor(e){this.type=e.type,this.target=e.target,this.currentTarget=e.target,this.intersect=e.intersect,this.originalEvent=e.originalEvent}stopPropagation(){this._propagationStopped=!0}get propagationStopped(){return this._propagationStopped}}class ce{domElement;scene;camera;raycaster=new i.Raycaster;pointer=new i.Vector2;hoveredObject=null;pointerDownTime=0;pointerDownPos=new i.Vector2;clickTimer=null;longPressThreshold=500;moveThreshold=.01;targetObjects;pointerMoveEventsEnabled=!1;_enabled=!0;_excludeSet=new Set;constructor(e,t,s){this.domElement=e,this.scene=t,this.camera=s,this.raycaster.params.Points.threshold=.1,this.raycaster.params.Line.threshold=.1,this.targetObjects=this.scene.children,this._bindEvents()}setCamera(e){this.camera=e}enable(){this._enabled=!0}disable(){this._enabled=!1}setInteractable(e,t){t?this._excludeSet.delete(e):this._excludeSet.add(e)}addIgnore(e){this._excludeSet.add(e)}removeIgnore(e){this._excludeSet.delete(e)}_bindEvents(){this.domElement.addEventListener("click",this._onClick),this.domElement.addEventListener("dblclick",this._onDblClick),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointerup",this._onPointerUp),this.domElement.addEventListener("pointermove",this._onPointerMove)}_updatePointer(e){const t=this.domElement.getBoundingClientRect();this.pointer.x=(e.clientX-t.left)/t.width*2-1,this.pointer.y=-((e.clientY-t.top)/t.height)*2+1}_getIntersects(){this.raycaster.setFromCamera(this.pointer,this.camera);const e=this.raycaster.intersectObjects(this.targetObjects,!0);return this._excludeSet.size>0?e.filter(t=>{let s=t.object;for(;s;){if(this._excludeSet.has(s))return!1;s=s.parent}return!0}):e}_dispatchToTarget(e,t,s,n){const r=new oe({type:e,target:t,intersect:s,originalEvent:n});let a=t;for(;a&&!r.propagationStopped;)r.currentTarget=a,a.dispatchEvent({type:e,event:r}),a=a.parent}_handleEvent(e,t){if(!this._enabled)return;this._updatePointer(t);const s=this._getIntersects();if(s.length===0)return;const n=s[0];this._dispatchToTarget(e,n.object,n,t)}_onClick=e=>{const t=Date.now()-this.pointerDownTime,s=this.pointer.distanceTo(this.pointerDownPos);if(!(t>this.longPressThreshold||s>this.moveThreshold)){if(this.clickTimer){clearTimeout(this.clickTimer),this.clickTimer=null;return}this.clickTimer=setTimeout(()=>{this._handleEvent("click",e),this.clickTimer=null},200)}};_onDblClick=e=>{this.clickTimer&&(clearTimeout(this.clickTimer),this.clickTimer=null),this._handleEvent("dblclick",e)};_onContextMenu=e=>{e.preventDefault()};_onPointerDown=e=>{this.pointerDownTime=Date.now(),this._updatePointer(e),this.pointerDownPos.copy(this.pointer),this._handleEvent("pointerdown",e)};_onPointerUp=e=>{if(this._updatePointer(e),e.button===2){const t=Date.now()-this.pointerDownTime,s=this.pointer.distanceTo(this.pointerDownPos);t<=this.longPressThreshold&&s<=this.moveThreshold&&this._handleEvent("rightclick",e)}this._handleEvent("pointerup",e)};_onPointerMove=e=>{if(!this._enabled||!this.pointerMoveEventsEnabled)return;this._updatePointer(e);const t=this._getIntersects(),s=t.length>0?t[0].object:null,n=t.length>0?t[0]:null;this.hoveredObject!==s&&(this.hoveredObject&&this._dispatchToTarget("pointerleave",this.hoveredObject,null,e),this.hoveredObject=s,s&&n&&this._dispatchToTarget("pointerenter",s,n,e)),s&&n&&this._dispatchToTarget("pointermove",s,n,e)};dispose(){this.domElement.removeEventListener("click",this._onClick),this.domElement.removeEventListener("dblclick",this._onDblClick),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.clickTimer&&(clearTimeout(this.clickTimer),this.clickTimer=null),this.hoveredObject=null,this._excludeSet.clear()}}class He extends i.EventDispatcher{scene;camera;domElement;_container;_selected=new Set;_boxSelectionEnabled=!1;_isSelecting=!1;_startPoint=new i.Vector2;_endPoint=new i.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 i.Vector2(this._startPoint.x/t*2-1,-(this._startPoint.y/s)*2+1),r=new i.Vector2(this._endPoint.x/t*2-1,-(this._endPoint.y/s)*2+1),a=new i.Box2(new i.Vector2(Math.min(n.x,r.x),Math.min(n.y,r.y)),new i.Vector2(Math.max(n.x,r.x),Math.max(n.y,r.y))),o=this.targetObjects||this.scene.children,c=[],l=new i.Matrix4;l.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse);const d=p=>{if(!p.visible)return;const m=new i.Vector3;if(m.setFromMatrixPosition(p.matrixWorld),m.applyMatrix4(l),m.z>-1&&m.z<1&&a.containsPoint(new i.Vector2(m.x,m.y))&&c.push(p),this._deep)for(const g of p.children)d(g)};for(const p of o)d(p);return c}dispose(){this.disableBoxSelection(),this._selected.clear()}}class le{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.visible=!0)}hide(e){const t=this.idMap.get(e);t&&(t.visible=!1)}isolate(e){const t=new Set(e);for(const[s,n]of this.idMap)n.visible=t.has(s)}setOpacity(e,t){const s=this.idMap.get(e);s&&s.traverse(n=>{if(!n.isMesh)return;const r=n.material;if(!r)return;const a=Array.isArray(r)?r:[r];for(const o of a)o.transparent=t<1,o.opacity=t,o.needsUpdate=!0})}getBoundingBox(e){const t=new i.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.visible=!0}}class Ge{scenes=new Map;_activeSceneKey=null;add(e,t){this.scenes.set(e,t)}create(e,t={}){const s=new i.Scene;return t.background!==void 0&&(s.background=new i.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 i.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 Fe{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 i.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:o=1024}=t,c=new i.DirectionalLight(s,n);return c.position.set(r.x,r.y,r.z),c.castShadow=a,a&&c.shadow.mapSize.setScalar(o),c.name=e,this._register(e,c),c}addPoint(e,t={}){const{color:s=16777215,intensity:n=1,distance:r=0,decay:a=2,position:o={x:0,y:5,z:0},castShadow:c=!1}=t,l=new i.PointLight(s,n,r,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:r=0,angle:a=Math.PI/6,penumbra:o=.1,decay:c=2,position:l={x:0,y:10,z:0},target:d,castShadow:p=!1}=t,m=new i.SpotLight(s,n,r,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=p,m.name=e,this._register(e,m),m}addHemisphere(e,t={}){const{skyColor:s=8900331,groundColor:n=3549447,intensity:r=.6}=t,a=new i.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 i.DirectionalLight?s=new i.DirectionalLightHelper(t,1):t instanceof i.PointLight?s=new i.PointLightHelper(t,.5):t instanceof i.SpotLight?s=new i.SpotLightHelper(t):t instanceof i.HemisphereLight&&(s=new i.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 he extends i.RenderPipeline{scene;camera;scenePass;needsUpdateOutputNode;#r;#t;#s=!1;#a={strength:1,radius:0,threshold:0};#c=null;#i=!1;#e={sliceCount:1,stepCount:12,aoIntensity:1,giIntensity:10,radius:12,thickness:1};#l=null;#o=!1;#h=null;#d=null;constructor(...e){const[t,s,n]=e;super(t),this.scene=s,this.camera=n,this.scenePass=u.pass(s,n),this.needsUpdateOutputNode=!0,this.#r=new Set,this.#t=[],this.#p()}get currentOutputNode(){return this.scenePass}addOverlayPass(e){this.#r.add(e),this.needsUpdateOutputNode=!0}removeOverlayPass(e){this.#r.delete(e),this.needsUpdateOutputNode=!0}setCamera(e){this.camera=e,this.#n()}setCurrentOutputNode(e){this.setOutputComposer(()=>e)}resetCurrentOutputNode(){this.setOutputComposer(null)}setOutputComposer(e){this.#d=e,this.needsUpdateOutputNode=!0}enableBloom(e){e&&Object.assign(this.#a,e),this.#s=!0,this.#n()}disableBloom(){this.#s=!1,this.#c=null,this.#n()}updateBloom(e){Object.assign(this.#a,e),this.#s&&(this.needsUpdateOutputNode=!0)}enableSSGI(e){e&&Object.assign(this.#e,e),this.#i=!0,this.#n()}disableSSGI(){this.#i=!1,this.#l=null,this.#n()}updateSSGI(e){if(Object.assign(this.#e,e),this.#l){const t=this.#l;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.#o=!0,this.#n()}disableTRAA(){this.#o=!1,this.#h=null,this.#n()}#n(){const e=this.scenePass;this.scenePass=u.pass(this.scene,this.camera),this.#p(),this.needsUpdateOutputNode=!0,e.dispose()}#p(){if(this.#s||this.#i||this.#o){const t={output:u.output};this.#s&&(t.emissive=u.emissive),this.#i&&(t.normal=u.normalView),this.#o&&(t.velocity=u.velocity),this.scenePass.setMRT(u.mrt(t))}}#u(){for(const e of this.#t)e.dispose();this.#t=[]}#m(){let e=this.scenePass.getTextureNode();if(this.#i)if(!(this.camera instanceof i.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"),r=Oe.ssgi(t,s,n,this.camera);r.sliceCount.value=this.#e.sliceCount,r.stepCount.value=this.#e.stepCount,r.aoIntensity.value=this.#e.aoIntensity,r.giIntensity.value=this.#e.giIntensity,r.radius.value=this.#e.radius,r.thickness.value=this.#e.thickness,this.#l=r,e=u.add(e,r),this.#t.push(r)}if(this.#s){const t=this.scenePass.getTextureNode("emissive");this.#c=Le.bloom(t,this.#a.strength,this.#a.radius,this.#a.threshold),e=u.add(e,this.#c),this.#t.push(this.#c)}return e}#g(){this.#u();let e;if(this.#d?e=this.#d(this.scenePass):this.#s||this.#i?e=this.#m():e=this.scenePass,this.#o){const t=this.scenePass.getTextureNode("depth"),s=this.scenePass.getTextureNode("velocity");this.#h=Ae.traa(e,t,s,this.camera),this.#t.push(this.#h),e=this.#h}this.#r.size>0&&this.#r.forEach(t=>{const s=u.blendColor(e,t);this.#t.push(s),e=s}),this.outputNode=e,this.needsUpdate=!0}render(){this.needsUpdateOutputNode&&(this.#g(),this.needsUpdateOutputNode=!1),super.render()}dispose(){this.#u(),this.scenePass.dispose(),super.dispose()}}const Ve={Vector2:i.Vector2,Vector3:i.Vector3,Vector4:i.Vector4,Quaternion:i.Quaternion,Matrix4:i.Matrix4,Spherical:i.Spherical,Box3:i.Box3,Sphere:i.Sphere,Raycaster:i.Raycaster};re.install({THREE:Ve});class de extends re{constructor(...e){super(...e),this.minDistance=.2,this.smoothTime=.2,this.dollySpeed=.2}absoluteRotations(){this.azimuthAngle=We(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:r=.1,cover:a=!1}=t,o=[];if(s!=="current"){const c=ee[s.toUpperCase()]??ee.FRONTTOP,l=c.theta,d=c.phi;o.push(this.fitToBox(e,n,{paddingLeft:r,paddingRight:r,paddingTop:r,paddingBottom:r,cover:a})),o.push(this.rotateTo(l,d,n))}else{const c=new i.Sphere;e.getBoundingSphere(c),c.radius+=r,o.push(this.fitToSphere(c,n))}return await Promise.all(o),!0}async flyToObject(e,t={}){const s=new i.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 i.Vector3,t=new i.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 i.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:r=this.camera.zoom}=e;return Promise.all([this.zoomTo(r,t),this.setLookAt(s.x,s.y,s.z,n.x,n.y,n.z,t)])}}const ee={LEFT:new i.Spherical(0,Math.PI/2,-Math.PI/2),RIGHT:new i.Spherical(0,Math.PI/2,Math.PI/2),FRONT:new i.Spherical(0,Math.PI/2,0),BACK:new i.Spherical(0,Math.PI/2,Math.PI),TOP:new i.Spherical(0,0,0),BOTTOM:new i.Spherical(0,Math.PI,0),FRONTTOP:new i.Spherical(0,Math.PI/4,0),BACKTOP:new i.Spherical(0,Math.PI/4,Math.PI),LEFTTOP:new i.Spherical(0,Math.PI/4,-Math.PI/2),RIGHTTOP:new i.Spherical(0,Math.PI/4,Math.PI/2),LEFTFRONTTOP:new i.Spherical(0,Math.PI/4,-Math.PI/4),RIGHTFRONTTOP:new i.Spherical(0,Math.PI/4,Math.PI/4),LEFTBACKTOP:new i.Spherical(0,Math.PI/4,-Math.PI/4*3),RIGHTBACKTOP:new i.Spherical(0,Math.PI/4,Math.PI/4*3)};function We(h,e){const t=h-e;return i.MathUtils.euclideanModulo(t+Math.PI,Math.PI*2)-Math.PI}class pe{environment=new Be.RoomEnvironment;renderer;pmremGenerator;envMap=null;constructor(e){this.renderer=e,this.pmremGenerator=new i.PMREMGenerator(e)}update(){this.envMap||(this.envMap=this.pmremGenerator.fromScene(this.environment).texture)}dispose(){this.pmremGenerator.dispose(),this.envMap?.dispose()}}const F=128;class $e extends Re.ViewHelper{viewer;overlayPass;constructor(e){super(e.camera,e.el),this.viewer=e;const t=new i.OrthographicCamera(-2,2,2,-2,0,4);t.position.set(0,0,2),this.overlayPass=u.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-F-e.right,e.top!==null?s=e.top:s=this.viewer.el.offsetHeight-F-e.bottom,this.overlayPass.setViewport(t,s,F,F)};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 ue="position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;overflow:hidden;",qe=ue+"z-index:0;",Ke=ue+"z-index:1;";class me{el;css2dRenderer=null;css3dRenderer=null;constructor(e){this.el=e,getComputedStyle(e).position==="static"&&(e.style.position="relative")}initCSS2DRenderer(){const e=new K.CSS2DRenderer;return e.setSize(this.el.clientWidth,this.el.clientHeight),e.domElement.style.cssText=Ke,this.el.appendChild(e.domElement),this.css2dRenderer=e,e}initCSS3DRenderer(){const e=new D.CSS3DRenderer;return e.setSize(this.el.clientWidth,this.el.clientHeight),e.domElement.style.cssText=qe,this.el.appendChild(e.domElement),this.css3dRenderer=e,e}createCSS2DObject(e){return this.css2dRenderer||this.initCSS2DRenderer(),new K.CSS2DObject(e)}createCSS25DObject(e){return this.css3dRenderer||this.initCSS3DRenderer(),new D.CSS3DSprite(e)}createCSS3DObject(e){return this.css3dRenderer||this.initCSS3DRenderer(),new D.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)}}class Xe{el;renderer;container;drawCallsText;frameCallsText;trianglesText;pointsText;linesText;timestampText;_enabled=!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 r(){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(r()),this.container.appendChild(n("frame calls",!1)),this.container.appendChild(this.frameCallsText),this.container.appendChild(r()),this.container.appendChild(n("triangles",!1)),this.container.appendChild(this.trianglesText),this.container.appendChild(r()),this.container.appendChild(n("points",!1)),this.container.appendChild(this.pointsText),this.container.appendChild(r()),this.container.appendChild(n("lines",!1)),this.container.appendChild(this.linesText),this.container.appendChild(r()),this.container.appendChild(n("timestamp",!1)),this.container.appendChild(this.timestampText),this.container.appendChild(r())}update(){if(this._enabled){const{render:e}=this.renderer.info;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.renderer.resolveTimestampsAsync(i.TimestampQuery.RENDER).then(t=>{this.timestampText.innerText=t?.toFixed(2)??"0"})}}enable(){this._enabled=!0,this.el.appendChild(this.container)}disable(){this._enabled=!1,this.container.remove()}dispose(){this.disable()}}i.Cache.enabled=!0;class Qe extends i.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 Xe(this.el,this.renderer),this.controls=new de(this.camera,this.renderer.domElement),this.renderPipeline=new he(this.renderer,this.scene,this.camera),this.timer=new i.Timer,this.roomEnvironment=new pe(this.renderer),this.interactionManager=new ce(this.renderer.domElement,this.scene,this.camera),this.objectManager=new le,this.viewerHelper=new $e(this),this.cssRenderer=new me(this.el),window.addEventListener("resize",this.onWindowResize)}onWindowResize=()=>{const e=this.el.clientWidth,t=this.el.clientHeight;this.camera instanceof i.PerspectiveCamera?(this.camera.aspect=e/t,this.camera.updateProjectionMatrix()):this.camera instanceof i.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 i.PerspectiveCamera)?this.setCamera(this.createPerspectiveCamera()):e==="orthographic"&&!(this.camera instanceof i.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 i.WebGPURenderer({logarithmicDepthBuffer:!0,antialias:!1,depth:!1,trackTimestamp:!0,...e});return t.setSize(this.el.clientWidth,this.el.clientHeight),t.shadowMap.enabled=!0,t.shadowMap.type=i.PCFShadowMap,t.toneMapping=i.AgXToneMapping,t.toneMappingExposure=1,t.info.autoReset=!1,t.setPixelRatio(window.devicePixelRatio),t.setAnimationLoop(this.animate),this.el.appendChild(t.domElement),t}createScene(){const e=new i.Scene;return e.background=new i.Color(0),e}createPerspectiveCamera(){const e=new i.PerspectiveCamera(50,this.el.clientWidth/this.el.clientHeight,.1,1e5);return e.position.setScalar(5),e}createOrthographicCamera(){const e=new i.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,r=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,r),this.onWindowResize()),o}setBackground(e){e===null?this.scene.background=null:e instanceof i.Color||typeof e=="number"||typeof e=="string"?this.scene.background=new i.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 i.Fog(t,s,n),this.render()}enableFogExp2(e={}){const{color:t=13421772,density:s=.01}=e;this.scene.fog=new i.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 ge extends ae.GLTFLoader{constructor(e){super(e)}parse(e,t,s,n){if(Ye(e.slice(0,8))==="SBMG----"){const a=Je(e.slice(8));return super.parse(a,t,s,n)}else return super.parse(e,t,s,n)}}function Ye(h){return new TextDecoder().decode(new Uint8Array(h))}function Je(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 Ze=8,et=130,te=66,tt="SBK-----",st="SBM-----",fe=new TextDecoder,nt=new TextEncoder;function it(h){let e=Ze;const t=new Uint8Array(h,0,e);if(fe.decode(t)!==tt)return h;e+=et;const n=new Uint8Array(h,0,e);if(n[40]===1){const a=nt.encode(st),o=new Uint8Array([n[41]]),c=rt(n),l=at(c);let d=te%l.length;const p=e+te,m=new Uint8Array(h,p),g=new Uint8Array(m.length);for(let v=0;v<m.length;v++)g[v]=m[v]^l[d],d=(d+1)%l.length;const y=new Uint8Array(a.length+o.length+g.length);return y.set(a),y.set(o,a.length),y.set(g,a.length+o.length),y.buffer}}function rt(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 at(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 ot=(h,e,t)=>{const s=h.buffer.slice(t,t+e);let n=fe.decode(s);return n=n.replace("\\","/"),n.startsWith("Maps/")||(n=`Maps/${n}`),n},ct=(h,e,t)=>{const[s,n,r,a,o]=e,c=t||a<1;return new i.MeshStandardNodeMaterial({name:h,color:new i.Color(s,n,r),opacity:a,transparent:c,alphaTest:.01,side:o})},lt=h=>h?.toLowerCase().endsWith(".png")??!1;class ht{data;options;textureLoader;littleEndian=!0;materials=new Map;constructor(e,t){this.data=e,this.options=t,this.textureLoader=new i.TextureLoader(t.manager),this.textureLoader.setCrossOrigin(t.crossOrigin),this.textureLoader.setRequestHeader(t.requestHeader)}parse(e,t){let s=this.data;const n=it(this.data);n&&(s=n);const r=new DataView(s);let a=8;const o=r.getUint8(a);a+=1,o===1?this._parseV2(r,a,e):o===2?this._parseV2(r,a,e):o===3?this._parseV3(r,a,e):t?.(new Error(`SBMLoader: Unsupported SBM version: ${o}`))}_parseV2(e,t,s){const n=new i.Group,r=e.getUint16(t,this.littleEndian);t+=2;const a=e.getUint16(t,this.littleEndian);t+=2;for(let o=0;o<r;++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 p=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=i.FrontSide:g===1?g=i.BackSide:g===2&&(g=i.DoubleSide);const y=e.getUint16(t,this.littleEndian);t+=2;const v=y>0?ot(e,y,t):"";if(t+=y,!this.materials.has(c)){const S=ct(c,[l,d,p,m,g],lt(v));this.materials.set(c,S),v&&this.options.path&&this.textureLoader.load(i.LoaderUtils.resolveURL(v,this.options.path),b=>{b.colorSpace=i.SRGBColorSpace,b.wrapS=i.RepeatWrapping,b.wrapT=i.RepeatWrapping,b.flipY=!1,b.anisotropy=16,S.map=b})}}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=[],p=[],m=[],g=[],y=e.getUint16(t,this.littleEndian);if(t+=2,y>0)for(let w=0;w<y;w++){const x=new i.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 v=e.getUint16(t,this.littleEndian);if(t+=2,v>0)for(let w=0;w<v;w++)t+=4,t+=4,t+=4;const M=e.getUint16(t,this.littleEndian);if(t+=2,M>0)for(let w=0;w<M;w++){const x=new i.Vector2;x.setX(e.getFloat32(t,this.littleEndian)),t+=4,x.setY(e.getFloat32(t,this.littleEndian)),t+=4,p.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 O=e.getUint16(t,this.littleEndian);t+=2;const A=e.getUint16(t,this.littleEndian);t+=2;const E=[x,O,A];m.push(E),p.length>0&&g.push([p[E[0]],p[E[1]],p[E[2]]])}const b=[],C=[];for(let w=0;w<m.length;w++){const x=m[w],O=d[x[0]],A=d[x[1]],E=d[x[2]];b.push(...O.toArray(),...A.toArray(),...E.toArray());let G=new i.Vector2,z=new i.Vector2,I=new i.Vector2;const j=g[w];j!==void 0&&(G=j[0],z=j[1],I=j[2]),C.push(...G.toArray(),...z.toArray(),...I.toArray())}const T=new Float32Array(b),P=new Float32Array(C),_=new i.BufferGeometry;if(T.length>0&&_.setAttribute("position",new i.BufferAttribute(T,3)),P.length>0&&_.setAttribute("uv",new i.BufferAttribute(P,2)),_.computeVertexNormals(),this.materials.has(l)){const w=new i.Mesh(_,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 i.Group;console.warn("SBMLoader: SBM version 3 is not supported yet."),s(n)}}class ye extends i.Loader{load(e,t,s,n){let r;if(this.resourcePath!=="")r=this.resourcePath;else if(this.path!==""){const c=i.LoaderUtils.extractUrlBase(e);r=i.LoaderUtils.resolveURL(c,this.path)}else r=i.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 i.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,r,l=>{t(l),this.manager.itemEnd(e)},a)}catch(l){a(l)}},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 ht(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 dt=["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 N(h){return h.traverse(e=>{if(!(e instanceof i.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 dt){const a=s[r];a?.isTexture&&a.image==null&&(a.dispose(),s[r]=null,n=!0)}n&&(s.needsUpdate=!0)}}),h}class L{static CACHE_NAME="u-space-model-loader-cache";static fileLoader=new i.FileLoader().setResponseType("arraybuffer");static dracoLoader=new Ne.DRACOLoader().setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${i.REVISION}.0/examples/jsm/libs/draco/`);static ktx2Loader=new De.KTX2Loader().setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${i.REVISION}.0/examples/jsm/libs/basis/`);static gltfLoader=new ae.GLTFLoader().setDRACOLoader(L.dracoLoader).setKTX2Loader(L.ktx2Loader).setMeshoptDecoder(Z.MeshoptDecoder);static sbmxLoader=new ge().setDRACOLoader(L.dracoLoader).setKTX2Loader(L.ktx2Loader).setMeshoptDecoder(Z.MeshoptDecoder);static sbmLoader=new ye;static fbxLoader=new Ie.FBXLoader;static objLoader=new je.OBJLoader;static stlLoader=new ze.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,i.LoaderUtils.extractUrlBase(e));return r.scene.animations=r.animations,N(r.scene);case"sbmx":const a=await this.sbmxLoader.parseAsync(n,i.LoaderUtils.extractUrlBase(e));return a.scene.animations=a.animations,N(a.scene);case"sbm":const o=await this.sbmLoader.parseAsync(n,i.LoaderUtils.extractUrlBase(e));return N(o);case"fbx":const c=this.fbxLoader.parse(n,i.LoaderUtils.extractUrlBase(e));return N(c);case"obj":const l=new TextDecoder().decode(n),d=this.objLoader.parse(l);return N(d);case"stl":const p=this.stlLoader.parse(n);return new i.Mesh(p,new i.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 pt{static textureLoader=new i.TextureLoader;static hdrLoader=new ke.HDRLoader;static cubeTextureLoader=new i.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=i.EquirectangularReflectionMapping,t}static async loadAsyncCubeTexture(e,t){return this.cubeTextureLoader.setPath(e),await this.cubeTextureLoader.loadAsync(t)}}class R extends i.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 Q extends i.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 we extends i.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 k extends Q{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?k.memoryCache.has(t)?r=k.memoryCache.get(t):(r=L.loadAsync(t,{persistent:n}),k.memoryCache.set(t,r)):r=L.loadAsync(t,{persistent:n});const a=await r,o=Ue.clone(a);return this.add(o),o.animations&&o.animations.length>0&&(this.animations=o.animations,this.mixer=new i.AnimationMixer(o)),o}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 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?i.LoopRepeat:i.LoopOnce,n),c.clampWhenFinished=a,c.timeScale=r,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 i.Box3().setFromObject(this)}getCenter(){const e=new i.Vector3;return this.getBoundingBox().getCenter(e),e}setMaterial(e){this.traverse(t=>{t instanceof i.Mesh&&(t.material=e)})}static clearMemoryCache(){this.memoryCache.clear()}static async clearPersistentCache(){typeof caches<"u"&&await caches.delete("u-space-loader-cache")}}class be extends R{isSphereMesh=!0;type="SphereMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new i.SphereGeometry(e?.radius,e?.widthSegments,e?.heightSegments,e?.phiStart,e?.phiLength,e?.thetaStart,e?.thetaLength),this.material=new i.MeshStandardNodeMaterial(t)}}class X extends R{isTubeMesh=!0;type="TubeMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new i.TubeGeometry(e?.path,e?.tubularSegments,e?.radius,e?.radialSegments,e?.closed),this.material=new i.MeshStandardNodeMaterial(t)}}class ut extends Q{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 o=s??r.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,r=new Set;for(const[c]of this.nodes)s.set(c,1/0),n.set(c,null),r.add(c);for(s.set(e,0);r.size>0;){let c=null,l=1/0;for(const p of r){const m=s.get(p);m<l&&(l=m,c=p)}if(c===null||c===t||l===1/0)break;r.delete(c);const d=this.adjacencyMap?.get(c);if(d)for(const[p,m]of d){if(!r.has(p))continue;const g=s.get(c)+m;g<s.get(p)&&(s.set(p,g),n.set(p,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 i.Group;const e=new be({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 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 i.LineCurve3(c,l),p=new X({geometryParameters:{path:d,tubularSegments:1,radius:this.parameters.edgeRadius,radialSegments:8,closed:!1},materialParameters:{color:this.parameters.edgeColor}});Object.assign(p.userData,{from:n,to:a,weight:r,type:"edge"}),this.graphGroup.add(p)}})}),this.add(this.graphGroup)}clearGraph(){this.graphGroup&&(this.remove(this.graphGroup),this.graphGroup.traverse(e=>{e instanceof i.Mesh&&(e.geometry.dispose(),e.material.dispose())}),this.graphGroup=null)}renderPath(e,t=this.parameters.pathColor){if(e.length<2)return;const s=new i.CatmullRomCurve3(e,!1,"catmullrom",0),n=new X({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,o)=>{const c=[r,o].sort().join("-");s.has(c)||(s.add(c),t.push({from:r,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 i.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 mt extends we{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 i.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:o,color:c,iconSize:l,padding:d,backgroundColor:p,borderRadius:m,textPosition:g,scaleFactor:y}=this.parameters,v=n.measureText(a),M=a?v.width:0,S=a?o:0;let b=0,C=0,T=0,P=0,_=0,w=0;const x=!!r,O=!!a;if(x&&O)switch(g){case"top":b=Math.max(l,M),C=l+d+S,_=(b-M)/2,w=S/2,T=(b-l)/2,P=S+d;break;case"bottom":b=Math.max(l,M),C=l+d+S,T=(b-l)/2,P=0,_=(b-M)/2,w=l+d+S/2;break;case"left":b=l+d+M,C=Math.max(l,S),_=0,w=C/2,T=M+d,P=(C-l)/2;break;default:b=l+d+M,C=Math.max(l,S),T=0,P=(C-l)/2,_=l+d,w=C/2;break}else x?(b=l,C=l,T=0,P=0):O&&(b=M,C=S,_=0,w=S/2);const A=b+d*2,E=C+d*2;if(s.width=A,s.height=E,n.font=`${o}px ${this.parameters.fontFamily}`,p&&(n.fillStyle=p,this._drawRoundedRect(n,0,0,A,E,m),n.fill()),x&&n.drawImage(r,T+d,P+d,l,l),O){n.fillStyle=c;const I=n.measureText(a),j=I.actualBoundingBoxAscent+I.actualBoundingBoxDescent,Pe=I.actualBoundingBoxAscent-j/2;n.textBaseline="alphabetic",n.fillText(a,_+d,w+d+Pe)}const G=this.material.map,z=new i.CanvasTexture(s);z.colorSpace=i.SRGBColorSpace,this.material.map=z,G?.dispose(),this.scale.set(A*y,E*y,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 Y extends R{isShapeMesh=!0;type="ShapeMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new i.ShapeGeometry(e?.shape,e?.curveSegments),this.material=new i.MeshStandardNodeMaterial(t),this.geometry.rotateX(-Math.PI/2)}static createFromPoints(e,t={}){return new Y({...t,geometryParameters:{...t.geometryParameters,shape:new i.Shape(e.map(s=>new i.Vector2(s.x,-s.z)))}})}}class J extends R{isExtrudeMesh=!0;type="ExtrudeMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new i.ExtrudeGeometry(e?.shape,e?.options),this.material=new i.MeshStandardNodeMaterial(t),this.geometry.rotateX(-Math.PI/2)}static createFromPoints(e,t={}){return e&&e.length===0&&(e=void 0),new J({...t,geometryParameters:{...t.geometryParameters,shape:new i.Shape(e?.map(s=>new i.Vector2(s.x,-s.z)))}})}}class gt extends R{isPlaneMesh=!0;type="PlaneMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new i.PlaneGeometry(e?.width,e?.height,e?.widthSegments,e?.heightSegments),this.material=new i.MeshStandardNodeMaterial(t)}}class ft extends R{isCircleMesh=!0;type="CircleMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(new i.CircleGeometry(e?.radius,e?.segments,e?.thetaStart,e?.thetaLength),new i.MeshStandardNodeMaterial(t)),this.geometry.rotateX(-Math.PI/2)}}class B{static traverseMeshes(e,t){e.traverse(s=>{s instanceof i.Mesh&&t(s)})}}class yt{static flow(e={}){const{baseColor:t=16777215,flowColor:s=65280,speed:n=1,scale:r=3,intensity:a=4}=e,o=u.color(new i.Color(t)),c=u.color(new i.Color(s)),l=u.uv().x.mul(r).sub(u.time.mul(n)),d=u.pow(u.sin(l).add(1).mul(.5),a);return u.mix(o,c,d)}static breathe(e={}){const{baseColor:t=16777215,breathColor:s=65280,speed:n=1,intensity:r=2}=e,a=u.color(new i.Color(t)),o=u.color(new i.Color(s)),c=u.sin(u.time.mul(n)).add(1).mul(.5),l=u.pow(c,r);return u.mix(a,o,l)}static fluid(e={}){const{baseColor:t=16777215,flowColor:s=255,speed:n=1,scale:r=1,intensity:a=1,distortion:o=.5}=e,c=u.color(new i.Color(t)),l=u.color(new i.Color(s)),d=u.uv().mul(r),p=u.time.mul(n),m=u.mx_noise_float(d.add(p),1,0),g=d.add(m.mul(o)),y=u.mx_noise_float(g,1,0).add(1).mul(.5),v=u.pow(y,a);return u.mix(c,l,v)}}function wt(h){}const $="uSpaceHighlight",H=`${$}/enabled`,ve=`${$}/opacity`,xe=`${$}/color`,Se=`${$}/overwrite`,q="uSpaceBreathe",V=`${q}/enabled`,Me=`${q}/color`,Ce=`${q}/speed`,_e=`${q}/intensity`,W=new WeakMap,bt=u.Fn(()=>{const h=u.userData(H,"uint"),e=u.userData(xe,"uint"),t=u.userData(Se,"uint"),s=ie(e),n=u.materialColor.mul(s),r=u.select(t.greaterThan(0),s,n),a=u.select(h.greaterThan(0),r,u.materialColor),o=u.userData(V,"uint"),c=u.userData(Me,"uint"),l=u.userData(Ce,"float"),d=u.userData(_e,"float"),p=ie(c),m=u.sin(u.time.mul(l)).add(1).mul(.5),g=u.pow(m,d),y=u.mix(a,p,g);return u.select(o.greaterThan(0),y,a)})(),vt=u.Fn(()=>{const h=u.userData(H,"uint"),e=u.userData(ve,"float");return u.select(h.greaterThan(0),e,u.materialOpacity)})();function se(h){const e=h.material;if(!e||Array.isArray(e))return;let t=W.get(e);t||(t={colorNode:e.colorNode,opacityNode:e.opacityNode,transparent:e.transparent,depthWrite:e.depthWrite,activeMeshes:new Set},W.set(e,t)),t.activeMeshes.add(h),e.transparent=!0,e.colorNode=bt,e.opacityNode=vt,e.needsUpdate=!0}function ne(h){const e=h.userData[H],t=h.userData[V];if(e||t)return;const s=h.material;if(!s||Array.isArray(s))return;const n=W.get(s);n&&(n.activeMeshes.delete(h),!(n.activeMeshes.size>0)&&(s.colorNode=n.colorNode,s.opacityNode=n.opacityNode,s.transparent=n.transparent,s.depthWrite=n.depthWrite,s.needsUpdate=!0,W.delete(s)))}class U{static highlightColor(e,t={}){const s=Array.isArray(e)?e:[e],{opacity:n=.5,color:r=16711680,overwrite:a=!1,depthWrite:o}=t,c=new i.Color(r).getHex();for(const l of s)B.traverseMeshes(l,d=>{if(d.userData[H]=1,d.userData[ve]=n,d.userData[xe]=c,d.userData[Se]=a?1:0,se(d),o!==void 0){const p=d.material;p&&!Array.isArray(p)&&(p.depthWrite=o)}})}static removeHighlightColor(e){const t=Array.isArray(e)?e:[e];for(const s of t)B.traverseMeshes(s,n=>{n.userData[H]=0,ne(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 i.Color(n.color).getHex();for(const r of s)B.traverseMeshes(r,a=>{a.userData[V]=1,a.userData[Me]=n.color,a.userData[Ce]=n.speed,a.userData[_e]=n.intensity,se(a)})}static removeBreatheColor(e){const t=Array.isArray(e)?e:[e];for(const s of t)B.traverseMeshes(s,n=>{n.userData[V]=0,ne(n)})}static wireframe(e,t=!0){const s=Array.isArray(e)?e:[e];for(const n of s)B.traverseMeshes(n,r=>{const a=r.material;!a||Array.isArray(a)||(a.wireframe=t,a.needsUpdate=!0)})}static removeWireframe(e){U.wireframe(e,!1)}static fadeIn(e,t={}){const{duration:s=500}=t;return U._fade(e,0,1,s)}static fadeOut(e,t={}){const{duration:s=500}=t;return U._fade(e,1,0,s)}static _fade(e,t,s,n){const r=Array.isArray(e)?e:[e],a=[];for(const o of r)B.traverseMeshes(o,c=>{const l=c.material;!l||Array.isArray(l)||(l.transparent=!0,l.opacity=t,l.needsUpdate=!0,a.push({material:l,targetOpacity:s}))});return a.length===0?Promise.resolve():new Promise(o=>{const c=performance.now();let l=0;const d=()=>{const p=performance.now()-c,m=Math.min(p/n,1);if(!r[0].parent){cancelAnimationFrame(l),o();return}for(const{material:y,targetOpacity:v}of a)y.opacity=t+(v-t)*m,y.needsUpdate=!0;if(m<1)l=requestAnimationFrame(d);else{if(s>=1)for(const{material:y}of a)y.transparent=!1;o()}};l=requestAnimationFrame(d)})}}const ie=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 u.vec3(e,t,s)};class Ee extends f.Tween{viewer;constructor(e,t){super(t),this.viewer=e}_update=({time:e})=>{this.update(e)&&this.viewer.render()};easingByMode(e){const t=St[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 xt(h,e,t,s={},n,r){return new Promise((a,o)=>{const{duration:c=1e3,delay:l=0,repeat:d=!1,mode:p="Linear.None",yoyo:m=!1}=s,g=new Ee(h,e).to(t,c).easingByMode(p).delay(l).onUpdate(y=>{n?.(y,g)}).onComplete(()=>{a()}).onStop(()=>{o("animation stop")}).onStart(()=>{r?.(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 St={"Linear.None":f.Easing.Linear.None,"Quadratic.In":f.Easing.Quadratic.In,"Quadratic.Out":f.Easing.Quadratic.Out,"Quadratic.InOut":f.Easing.Quadratic.InOut,"Cubic.In":f.Easing.Cubic.In,"Cubic.Out":f.Easing.Cubic.Out,"Cubic.InOut":f.Easing.Cubic.InOut,"Quartic.In":f.Easing.Quartic.In,"Quartic.Out":f.Easing.Quartic.Out,"Quartic.InOut":f.Easing.Quartic.InOut,"Quintic.In":f.Easing.Quintic.In,"Quintic.Out":f.Easing.Quintic.Out,"Quintic.InOut":f.Easing.Quintic.InOut,"Sinusoidal.In":f.Easing.Sinusoidal.In,"Sinusoidal.Out":f.Easing.Sinusoidal.Out,"Sinusoidal.InOut":f.Easing.Sinusoidal.InOut,"Exponential.In":f.Easing.Exponential.In,"Exponential.Out":f.Easing.Exponential.Out,"Exponential.InOut":f.Easing.Exponential.InOut,"Circular.In":f.Easing.Circular.In,"Circular.Out":f.Easing.Circular.Out,"Circular.InOut":f.Easing.Circular.InOut,"Elastic.In":f.Easing.Elastic.In,"Elastic.Out":f.Easing.Elastic.Out,"Elastic.InOut":f.Easing.Elastic.InOut,"Back.In":f.Easing.Back.In,"Back.Out":f.Easing.Back.Out,"Back.InOut":f.Easing.Back.InOut,"Bounce.In":f.Easing.Bounce.In,"Bounce.Out":f.Easing.Bounce.Out,"Bounce.InOut":f.Easing.Bounce.InOut};class Mt{scene;planes=new Map;helpers=new Map;group;constructor(e){this.scene=e,this.group=new i.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:o=16711680}=t,c=new i.Plane(new i.Vector3(s.x,s.y,s.z),n);return this.planes.set(e,c),this._syncPlanes(),r&&this.showHelper(e,a,o),c}addBox(e,t,s={}){const{showHelpers:n=!1,helperColor:r=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 p=`${e}_${d.suffix}`;this.addPlane(p,{normal:d.normal,constant:d.constant,showHelper:n,helperColor:r}),l.push(p)}return l}addBoxFromObject(e,t,s=0,n={}){const r=new i.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 i.PlaneHelper(n,t,new i.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 Ct{scene;measurements=new Map;_idCounter=0;constructor(e){this.scene=e}measureDistance(e,t,s={}){const{lineColor:n=16776960}=s,r=new i.Vector3(e.x,e.y,e.z),a=new i.Vector3(t.x,t.y,t.z),o=r.distanceTo(a),c=`measure_dist_${this._idCounter++}`,l=new i.Group;l.name=c;const d=new i.BufferGeometry().setFromPoints([r,a]),p=new i.LineBasicMaterial({color:n}),m=new i.Line(d,p);l.add(m),this.scene.add(l);const g={id:c,type:"distance",value:o,unit:"m",points:[r,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 i.Vector3(g.x,g.y,g.z)),r=this._calculatePolygonArea(n),a=`measure_area_${this._idCounter++}`,o=new i.Group;o.name=a;const c=[...n,n[0]],l=new i.BufferGeometry().setFromPoints(c),d=new i.LineBasicMaterial({color:s}),p=new i.Line(l,d);o.add(p),this.scene.add(o);const m={id:a,type:"area",value:r,unit:"m²",points:n,object:o};return this.measurements.set(a,m),m}measureAngle(e,t,s,n={}){const{lineColor:r=16746496}=n,a=new i.Vector3(e.x,e.y,e.z),o=new i.Vector3(t.x,t.y,t.z),c=new i.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++}`,y=new i.Group;y.name=g;const v=new i.BufferGeometry().setFromPoints([a,o,c]),M=new i.LineBasicMaterial({color:r}),S=new i.Line(v,M);y.add(S),this.scene.add(y);const b={id:g,type:"angle",value:m,unit:"°",points:[a,o,c],object:y};return this.measurements.set(g,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 i.Vector3;for(let r=0;r<t;r++){const a=e[r],o=e[(r+1)%t],c=new i.Vector3().crossVectors(a,o);s.add(c)}const n=new i.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 _t{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 i.Group;s.name=`annotation_${e}`;const n=new i.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=`
|
|
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 i.Vector2(this._startPoint.x/t*2-1,-(this._startPoint.y/s)*2+1),r=new i.Vector2(this._endPoint.x/t*2-1,-(this._endPoint.y/s)*2+1),a=new i.Box2(new i.Vector2(Math.min(n.x,r.x),Math.min(n.y,r.y)),new i.Vector2(Math.max(n.x,r.x),Math.max(n.y,r.y))),o=this.targetObjects||this.scene.children,c=[],h=new i.Matrix4;h.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse);const d=p=>{if(!p.visible)return;const m=new i.Vector3;if(m.setFromMatrixPosition(p.matrixWorld),m.applyMatrix4(h),m.z>-1&&m.z<1&&a.containsPoint(new i.Vector2(m.x,m.y))&&c.push(p),this._deep)for(const g of p.children)d(g)};for(const p of o)d(p);return c}dispose(){this.disableBoxSelection(),this._selected.clear()}}class he{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.visible=!0)}hide(e){const t=this.idMap.get(e);t&&(t.visible=!1)}isolate(e){const t=new Set(e);for(const[s,n]of this.idMap)n.visible=t.has(s)}setOpacity(e,t){const s=this.idMap.get(e);s&&s.traverse(n=>{if(!n.isMesh)return;const r=n.material;if(!r)return;const a=Array.isArray(r)?r:[r];for(const o of a)o.transparent=t<1,o.opacity=t,o.needsUpdate=!0})}getBoundingBox(e){const t=new i.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.visible=!0}}class Ge{scenes=new Map;_activeSceneKey=null;add(e,t){this.scenes.set(e,t)}create(e,t={}){const s=new i.Scene;return t.background!==void 0&&(s.background=new i.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 i.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 Fe{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 i.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:o=1024}=t,c=new i.DirectionalLight(s,n);return c.position.set(r.x,r.y,r.z),c.castShadow=a,a&&c.shadow.mapSize.setScalar(o),c.name=e,this._register(e,c),c}addPoint(e,t={}){const{color:s=16777215,intensity:n=1,distance:r=0,decay:a=2,position:o={x:0,y:5,z:0},castShadow:c=!1}=t,h=new i.PointLight(s,n,r,a);return h.position.set(o.x,o.y,o.z),h.castShadow=c,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:o=.1,decay:c=2,position:h={x:0,y:10,z:0},target:d,castShadow:p=!1}=t,m=new i.SpotLight(s,n,r,a,o,c);return m.position.set(h.x,h.y,h.z),d&&m.target.position.set(d.x,d.y,d.z),m.castShadow=p,m.name=e,this._register(e,m),m}addHemisphere(e,t={}){const{skyColor:s=8900331,groundColor:n=3549447,intensity:r=.6}=t,a=new i.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 i.DirectionalLight?s=new i.DirectionalLightHelper(t,1):t instanceof i.PointLight?s=new i.PointLightHelper(t,.5):t instanceof i.SpotLight?s=new i.SpotLightHelper(t):t instanceof i.HemisphereLight&&(s=new i.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 le extends i.RenderPipeline{scene;camera;scenePass;needsUpdateOutputNode;#a;#s;#n=!1;#o={strength:1,radius:0,threshold:0};#d=null;#i=!1;#t={sliceCount:1,stepCount:12,aoIntensity:1,giIntensity:10,radius:12,thickness:1};#p=null;#c=!1;#h=null;#u=null;#l;#r;#m=!1;#g=!0;constructor(...e){const[t,s,n]=e;super(t),this.scene=s,this.camera=n,this.scenePass=u.pass(s,n),this.needsUpdateOutputNode=!0,this.#a=new Set,this.#s=[],this.#l=new Set,this.#r=new Map,this.#f()}get currentOutputNode(){return this.scenePass}addOverlayPass(e){this.#a.add(e),this.needsUpdateOutputNode=!0}removeOverlayPass(e){this.#a.delete(e),this.needsUpdateOutputNode=!0}setCamera(e){this.camera=e,this.#e()}setCurrentOutputNode(e){this.setOutputComposer(()=>e)}resetCurrentOutputNode(){this.setOutputComposer(null)}setOutputComposer(e){this.#u=e,this.needsUpdateOutputNode=!0}addOutputEffect(e){return this.#l.add(e),this.needsUpdateOutputNode=!0,this}removeOutputEffect(e){return this.#l.delete(e),this.needsUpdateOutputNode=!0,this}addMRTChannel(e,t){return this.#r.get(e)===t?this:(this.#r.set(e,t),this.#e(),this)}removeMRTChannel(e){return this.#r.delete(e)&&this.#e(),this}enableBloom(e){e&&Object.assign(this.#o,e),this.#n=!0,this.#e()}disableBloom(){this.#n=!1,this.#d=null,this.#e()}updateBloom(e){Object.assign(this.#o,e),this.#n&&(this.needsUpdateOutputNode=!0)}enableSSGI(e){e&&Object.assign(this.#t,e),this.#i=!0,this.#e()}disableSSGI(){this.#i=!1,this.#p=null,this.#e()}updateSSGI(e){if(Object.assign(this.#t,e),this.#p){const t=this.#p;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.#c=!0,this.#e()}disableTRAA(){this.#c=!1,this.#h=null,this.#e()}#e(){const e=this.scenePass;this.scenePass=u.pass(this.scene,this.camera),this.#f(),this.needsUpdateOutputNode=!0,e.dispose()}#f(){if(this.#n||this.#i||this.#c||this.#r.size>0){const t={output:u.output};this.#r.forEach((s,n)=>{n!=="output"&&(t[n]=s)}),this.#n&&(t.emissive=u.emissive),this.#i&&(t.normal=u.normalView),this.#c&&(t.velocity=u.velocity),this.scenePass.setMRT(u.mrt(t))}}#y(){for(const e of this.#s)e.dispose();this.#s=[]}#w(){let e=this.scenePass.getTextureNode();if(this.#i)if(!(this.camera instanceof i.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"),r=Le.ssgi(t,s,n,this.camera);r.sliceCount.value=this.#t.sliceCount,r.stepCount.value=this.#t.stepCount,r.aoIntensity.value=this.#t.aoIntensity,r.giIntensity.value=this.#t.giIntensity,r.radius.value=this.#t.radius,r.thickness.value=this.#t.thickness,this.#p=r,e=u.add(e,r),this.#s.push(r)}if(this.#n){const t=this.scenePass.getTextureNode("emissive");this.#d=Oe.bloom(t,this.#o.strength,this.#o.radius,this.#o.threshold),e=u.add(e,this.#d),this.#s.push(this.#d)}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.#u!==null;if(n?e=this.#u(this.scenePass):this.#n||this.#i?e=this.#w():e=this.#l.size>0?this.scenePass.getTextureNode():this.scenePass,n||this.#l.forEach(r=>{t||=r.includesTemporalAntialias===!0,s||=r.includesOutputTransform===!0,e=r(this.scenePass,e)}),this.#v(s),this.#c&&!t){const r=this.scenePass.getTextureNode("depth"),a=this.scenePass.getTextureNode("velocity");this.#h=Ae.traa(e,r,a,this.camera),this.#s.push(this.#h),e=this.#h}else this.#h=null;this.#a.size>0&&this.#a.forEach(r=>{const a=u.blendColor(e,r);this.#s.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 Ve={Vector2:i.Vector2,Vector3:i.Vector3,Vector4:i.Vector4,Quaternion:i.Quaternion,Matrix4:i.Matrix4,Spherical:i.Spherical,Box3:i.Box3,Sphere:i.Sphere,Raycaster:i.Raycaster};re.install({THREE:Ve});class de extends re{constructor(...e){super(...e),this.minDistance=.2,this.smoothTime=.2,this.dollySpeed=.2}absoluteRotations(){this.azimuthAngle=We(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:r=.1,cover:a=!1}=t,o=[];if(s!=="current"){const c=ee[s.toUpperCase()]??ee.FRONTTOP,h=c.theta,d=c.phi;o.push(this.fitToBox(e,n,{paddingLeft:r,paddingRight:r,paddingTop:r,paddingBottom:r,cover:a})),o.push(this.rotateTo(h,d,n))}else{const c=new i.Sphere;e.getBoundingSphere(c),c.radius+=r,o.push(this.fitToSphere(c,n))}return await Promise.all(o),!0}async flyToObject(e,t={}){const s=new i.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 i.Vector3,t=new i.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 i.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:r=this.camera.zoom}=e;return Promise.all([this.zoomTo(r,t),this.setLookAt(s.x,s.y,s.z,n.x,n.y,n.z,t)])}}const ee={LEFT:new i.Spherical(0,Math.PI/2,-Math.PI/2),RIGHT:new i.Spherical(0,Math.PI/2,Math.PI/2),FRONT:new i.Spherical(0,Math.PI/2,0),BACK:new i.Spherical(0,Math.PI/2,Math.PI),TOP:new i.Spherical(0,0,0),BOTTOM:new i.Spherical(0,Math.PI,0),FRONTTOP:new i.Spherical(0,Math.PI/4,0),BACKTOP:new i.Spherical(0,Math.PI/4,Math.PI),LEFTTOP:new i.Spherical(0,Math.PI/4,-Math.PI/2),RIGHTTOP:new i.Spherical(0,Math.PI/4,Math.PI/2),LEFTFRONTTOP:new i.Spherical(0,Math.PI/4,-Math.PI/4),RIGHTFRONTTOP:new i.Spherical(0,Math.PI/4,Math.PI/4),LEFTBACKTOP:new i.Spherical(0,Math.PI/4,-Math.PI/4*3),RIGHTBACKTOP:new i.Spherical(0,Math.PI/4,Math.PI/4*3)};function We(l,e){const t=l-e;return i.MathUtils.euclideanModulo(t+Math.PI,Math.PI*2)-Math.PI}class pe{environment=new Be.RoomEnvironment;renderer;pmremGenerator;envMap=null;constructor(e){this.renderer=e,this.pmremGenerator=new i.PMREMGenerator(e)}update(){this.envMap||(this.envMap=this.pmremGenerator.fromScene(this.environment).texture)}dispose(){this.pmremGenerator.dispose(),this.envMap?.dispose()}}const F=128;class $e extends Re.ViewHelper{viewer;overlayPass;constructor(e){super(e.camera,e.el),this.viewer=e;const t=new i.OrthographicCamera(-2,2,2,-2,0,4);t.position.set(0,0,2),this.overlayPass=u.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-F-e.right,e.top!==null?s=e.top:s=this.viewer.el.offsetHeight-F-e.bottom,this.overlayPass.setViewport(t,s,F,F)};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 ue="position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;overflow:hidden;",qe=ue+"z-index:0;",Ke=ue+"z-index:1;";class me{el;css2dRenderer=null;css3dRenderer=null;constructor(e){this.el=e,getComputedStyle(e).position==="static"&&(e.style.position="relative")}initCSS2DRenderer(){const e=new K.CSS2DRenderer;return e.setSize(this.el.clientWidth,this.el.clientHeight),e.domElement.style.cssText=Ke,this.el.appendChild(e.domElement),this.css2dRenderer=e,e}initCSS3DRenderer(){const e=new D.CSS3DRenderer;return e.setSize(this.el.clientWidth,this.el.clientHeight),e.domElement.style.cssText=qe,this.el.appendChild(e.domElement),this.css3dRenderer=e,e}createCSS2DObject(e){return this.css2dRenderer||this.initCSS2DRenderer(),new K.CSS2DObject(e)}createCSS25DObject(e){return this.css3dRenderer||this.initCSS3DRenderer(),new D.CSS3DSprite(e)}createCSS3DObject(e){return this.css3dRenderer||this.initCSS3DRenderer(),new D.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)}}class Xe{el;renderer;container;drawCallsText;frameCallsText;trianglesText;pointsText;linesText;timestampText;_enabled=!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 r(){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(r()),this.container.appendChild(n("frame calls",!1)),this.container.appendChild(this.frameCallsText),this.container.appendChild(r()),this.container.appendChild(n("triangles",!1)),this.container.appendChild(this.trianglesText),this.container.appendChild(r()),this.container.appendChild(n("points",!1)),this.container.appendChild(this.pointsText),this.container.appendChild(r()),this.container.appendChild(n("lines",!1)),this.container.appendChild(this.linesText),this.container.appendChild(r()),this.container.appendChild(n("timestamp",!1)),this.container.appendChild(this.timestampText),this.container.appendChild(r())}update(){if(this._enabled){const{render:e}=this.renderer.info;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.renderer.resolveTimestampsAsync(i.TimestampQuery.RENDER).then(t=>{this.timestampText.innerText=t?.toFixed(2)??"0"})}}enable(){this._enabled=!0,this.el.appendChild(this.container)}disable(){this._enabled=!1,this.container.remove()}dispose(){this.disable()}}i.Cache.enabled=!0;class Qe extends i.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 Xe(this.el,this.renderer),this.controls=new de(this.camera,this.renderer.domElement),this.renderPipeline=new le(this.renderer,this.scene,this.camera),this.timer=new i.Timer,this.roomEnvironment=new pe(this.renderer),this.interactionManager=new ce(this.renderer.domElement,this.scene,this.camera),this.objectManager=new he,this.viewerHelper=new $e(this),this.cssRenderer=new me(this.el),window.addEventListener("resize",this.onWindowResize)}onWindowResize=()=>{const e=this.el.clientWidth,t=this.el.clientHeight;this.camera instanceof i.PerspectiveCamera?(this.camera.aspect=e/t,this.camera.updateProjectionMatrix()):this.camera instanceof i.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 i.PerspectiveCamera)?this.setCamera(this.createPerspectiveCamera()):e==="orthographic"&&!(this.camera instanceof i.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 i.WebGPURenderer({logarithmicDepthBuffer:!0,antialias:!1,depth:!1,trackTimestamp:!0,...e});return t.setSize(this.el.clientWidth,this.el.clientHeight),t.shadowMap.enabled=!0,t.shadowMap.type=i.PCFShadowMap,t.toneMapping=i.AgXToneMapping,t.toneMappingExposure=1,t.info.autoReset=!1,t.setPixelRatio(window.devicePixelRatio),t.setAnimationLoop(this.animate),this.el.appendChild(t.domElement),t}createScene(){const e=new i.Scene;return e.background=new i.Color(0),e}createPerspectiveCamera(){const e=new i.PerspectiveCamera(50,this.el.clientWidth/this.el.clientHeight,.1,1e5);return e.position.setScalar(5),e}createOrthographicCamera(){const e=new i.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,r=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,r),this.onWindowResize()),o}setBackground(e){e===null?this.scene.background=null:e instanceof i.Color||typeof e=="number"||typeof e=="string"?this.scene.background=new i.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 i.Fog(t,s,n),this.render()}enableFogExp2(e={}){const{color:t=13421772,density:s=.01}=e;this.scene.fog=new i.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 ge extends ae.GLTFLoader{constructor(e){super(e)}parse(e,t,s,n){if(Ye(e.slice(0,8))==="SBMG----"){const a=Je(e.slice(8));return super.parse(a,t,s,n)}else return super.parse(e,t,s,n)}}function Ye(l){return new TextDecoder().decode(new Uint8Array(l))}function Je(l){const e=new DataView(l);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 Ze=8,et=130,te=66,tt="SBK-----",st="SBM-----",fe=new TextDecoder,nt=new TextEncoder;function it(l){let e=Ze;const t=new Uint8Array(l,0,e);if(fe.decode(t)!==tt)return l;e+=et;const n=new Uint8Array(l,0,e);if(n[40]===1){const a=nt.encode(st),o=new Uint8Array([n[41]]),c=rt(n),h=at(c);let d=te%h.length;const p=e+te,m=new Uint8Array(l,p),g=new Uint8Array(m.length);for(let b=0;b<m.length;b++)g[b]=m[b]^h[d],d=(d+1)%h.length;const y=new Uint8Array(a.length+o.length+g.length);return y.set(a),y.set(o,a.length),y.set(g,a.length+o.length),y.buffer}}function rt(l){const e=new Uint8Array(128);return e.set(l.slice(42,74),0),e.set(l.slice(74,138),32),e.set(l.slice(8,40),96),e}function at(l){const e=new Uint8Array(64);return e.set(l.slice(0,8),0),e.set(l.slice(24,32),8),e.set(l.slice(40,56),16),e.set(l.slice(64,88),32),e.set(l.slice(96,104),56),e}const ot=(l,e,t)=>{const s=l.buffer.slice(t,t+e);let n=fe.decode(s);return n=n.replace("\\","/"),n.startsWith("Maps/")||(n=`Maps/${n}`),n},ct=(l,e,t)=>{const[s,n,r,a,o]=e,c=t||a<1;return new i.MeshStandardNodeMaterial({name:l,color:new i.Color(s,n,r),opacity:a,transparent:c,alphaTest:.01,side:o})},ht=l=>l?.toLowerCase().endsWith(".png")??!1;class lt{data;options;textureLoader;littleEndian=!0;materials=new Map;constructor(e,t){this.data=e,this.options=t,this.textureLoader=new i.TextureLoader(t.manager),this.textureLoader.setCrossOrigin(t.crossOrigin),this.textureLoader.setRequestHeader(t.requestHeader)}parse(e,t){let s=this.data;const n=it(this.data);n&&(s=n);const r=new DataView(s);let a=8;const o=r.getUint8(a);a+=1,o===1?this._parseV2(r,a,e):o===2?this._parseV2(r,a,e):o===3?this._parseV3(r,a,e):t?.(new Error(`SBMLoader: Unsupported SBM version: ${o}`))}_parseV2(e,t,s){const n=new i.Group,r=e.getUint16(t,this.littleEndian);t+=2;const a=e.getUint16(t,this.littleEndian);t+=2;for(let o=0;o<r;++o){const c=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 d=e.getFloat32(t,this.littleEndian);t+=4;const p=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=i.FrontSide:g===1?g=i.BackSide:g===2&&(g=i.DoubleSide);const y=e.getUint16(t,this.littleEndian);t+=2;const b=y>0?ot(e,y,t):"";if(t+=y,!this.materials.has(c)){const S=ct(c,[h,d,p,m,g],ht(b));this.materials.set(c,S),b&&this.options.path&&this.textureLoader.load(i.LoaderUtils.resolveURL(b,this.options.path),v=>{v.colorSpace=i.SRGBColorSpace,v.wrapS=i.RepeatWrapping,v.wrapT=i.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 h=e.getUint16(t,this.littleEndian).toString();t+=2;const d=[],p=[],m=[],g=[],y=e.getUint16(t,this.littleEndian);if(t+=2,y>0)for(let w=0;w<y;w++){const x=new i.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 M=e.getUint16(t,this.littleEndian);if(t+=2,M>0)for(let w=0;w<M;w++){const x=new i.Vector2;x.setX(e.getFloat32(t,this.littleEndian)),t+=4,x.setY(e.getFloat32(t,this.littleEndian)),t+=4,p.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 A=e.getUint16(t,this.littleEndian);t+=2;const E=[x,L,A];m.push(E),p.length>0&&g.push([p[E[0]],p[E[1]],p[E[2]]])}const v=[],C=[];for(let w=0;w<m.length;w++){const x=m[w],L=d[x[0]],A=d[x[1]],E=d[x[2]];v.push(...L.toArray(),...A.toArray(),...E.toArray());let G=new i.Vector2,N=new i.Vector2,I=new i.Vector2;const j=g[w];j!==void 0&&(G=j[0],N=j[1],I=j[2]),C.push(...G.toArray(),...N.toArray(),...I.toArray())}const T=new Float32Array(v),P=new Float32Array(C),_=new i.BufferGeometry;if(T.length>0&&_.setAttribute("position",new i.BufferAttribute(T,3)),P.length>0&&_.setAttribute("uv",new i.BufferAttribute(P,2)),_.computeVertexNormals(),this.materials.has(h)){const w=new i.Mesh(_,this.materials.get(h));w.name=c,w.castShadow=!0,w.receiveShadow=!0,n.add(w)}}s(n)}_parseV3(e,t,s){const n=new i.Group;console.warn("SBMLoader: SBM version 3 is not supported yet."),s(n)}}class ye extends i.Loader{load(e,t,s,n){let r;if(this.resourcePath!=="")r=this.resourcePath;else if(this.path!==""){const c=i.LoaderUtils.extractUrlBase(e);r=i.LoaderUtils.resolveURL(c,this.path)}else r=i.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 i.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,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 lt(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 dt=["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 z(l){return l.traverse(e=>{if(!(e instanceof i.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 dt){const a=s[r];a?.isTexture&&a.image==null&&(a.dispose(),s[r]=null,n=!0)}n&&(s.needsUpdate=!0)}}),l}class O{static CACHE_NAME="u-space-model-loader-cache";static fileLoader=new i.FileLoader().setResponseType("arraybuffer");static dracoLoader=new ze.DRACOLoader().setDecoderPath(`https://cdn.jsdelivr.net/npm/three@0.${i.REVISION}.0/examples/jsm/libs/draco/`);static ktx2Loader=new De.KTX2Loader().setTranscoderPath(`https://cdn.jsdelivr.net/npm/three@0.${i.REVISION}.0/examples/jsm/libs/basis/`);static gltfLoader=new ae.GLTFLoader().setDRACOLoader(O.dracoLoader).setKTX2Loader(O.ktx2Loader).setMeshoptDecoder(Z.MeshoptDecoder);static sbmxLoader=new ge().setDRACOLoader(O.dracoLoader).setKTX2Loader(O.ktx2Loader).setMeshoptDecoder(Z.MeshoptDecoder);static sbmLoader=new ye;static fbxLoader=new Ie.FBXLoader;static objLoader=new je.OBJLoader;static stlLoader=new Ne.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,i.LoaderUtils.extractUrlBase(e));return r.scene.animations=r.animations,z(r.scene);case"sbmx":const a=await this.sbmxLoader.parseAsync(n,i.LoaderUtils.extractUrlBase(e));return a.scene.animations=a.animations,z(a.scene);case"sbm":const o=await this.sbmLoader.parseAsync(n,i.LoaderUtils.extractUrlBase(e));return z(o);case"fbx":const c=this.fbxLoader.parse(n,i.LoaderUtils.extractUrlBase(e));return z(c);case"obj":const h=new TextDecoder().decode(n),d=this.objLoader.parse(h);return z(d);case"stl":const p=this.stlLoader.parse(n);return new i.Mesh(p,new i.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 pt{static textureLoader=new i.TextureLoader;static hdrLoader=new ke.HDRLoader;static cubeTextureLoader=new i.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=i.EquirectangularReflectionMapping,t}static async loadAsyncCubeTexture(e,t){return this.cubeTextureLoader.setPath(e),await this.cubeTextureLoader.loadAsync(t)}}class R extends i.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 Q extends i.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 we extends i.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 k extends Q{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?k.memoryCache.has(t)?r=k.memoryCache.get(t):(r=O.loadAsync(t,{persistent:n}),k.memoryCache.set(t,r)):r=O.loadAsync(t,{persistent:n});const a=await r,o=Ue.clone(a);return this.add(o),o.animations&&o.animations.length>0&&(this.animations=o.animations,this.mixer=new i.AnimationMixer(o)),o}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 o;if(e===void 0?o=this.animations[0]:typeof e=="number"?o=this.animations[e]:o=this.animations.find(h=>h.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?i.LoopRepeat:i.LoopOnce,n),c.clampWhenFinished=a,c.timeScale=r,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 i.Box3().setFromObject(this)}getCenter(){const e=new i.Vector3;return this.getBoundingBox().getCenter(e),e}setMaterial(e){this.traverse(t=>{t instanceof i.Mesh&&(t.material=e)})}static clearMemoryCache(){this.memoryCache.clear()}static async clearPersistentCache(){typeof caches<"u"&&await caches.delete("u-space-loader-cache")}}class ve extends R{isSphereMesh=!0;type="SphereMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new i.SphereGeometry(e?.radius,e?.widthSegments,e?.heightSegments,e?.phiStart,e?.phiLength,e?.thetaStart,e?.thetaLength),this.material=new i.MeshStandardNodeMaterial(t)}}class X extends R{isTubeMesh=!0;type="TubeMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new i.TubeGeometry(e?.path,e?.tubularSegments,e?.radius,e?.radialSegments,e?.closed),this.material=new i.MeshStandardNodeMaterial(t)}}class ut extends Q{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 o=s??r.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,r=new Set;for(const[c]of this.nodes)s.set(c,1/0),n.set(c,null),r.add(c);for(s.set(e,0);r.size>0;){let c=null,h=1/0;for(const p of r){const m=s.get(p);m<h&&(h=m,c=p)}if(c===null||c===t||h===1/0)break;r.delete(c);const d=this.adjacencyMap?.get(c);if(d)for(const[p,m]of d){if(!r.has(p))continue;const g=s.get(c)+m;g<s.get(p)&&(s.set(p,g),n.set(p,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 i.Group;const e=new ve({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 o=[n,a].sort().join("-");if(t.has(o))return;t.add(o);const c=this.nodes.get(n),h=this.nodes.get(a);if(c&&h){const d=new i.LineCurve3(c,h),p=new X({geometryParameters:{path:d,tubularSegments:1,radius:this.parameters.edgeRadius,radialSegments:8,closed:!1},materialParameters:{color:this.parameters.edgeColor}});Object.assign(p.userData,{from:n,to:a,weight:r,type:"edge"}),this.graphGroup.add(p)}})}),this.add(this.graphGroup)}clearGraph(){this.graphGroup&&(this.remove(this.graphGroup),this.graphGroup.traverse(e=>{e instanceof i.Mesh&&(e.geometry.dispose(),e.material.dispose())}),this.graphGroup=null)}renderPath(e,t=this.parameters.pathColor){if(e.length<2)return;const s=new i.CatmullRomCurve3(e,!1,"catmullrom",0),n=new X({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,o)=>{const c=[r,o].sort().join("-");s.has(c)||(s.add(c),t.push({from:r,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 i.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 mt extends we{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 i.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:o,color:c,iconSize:h,padding:d,backgroundColor:p,borderRadius:m,textPosition:g,scaleFactor:y}=this.parameters,b=n.measureText(a),M=a?b.width:0,S=a?o:0;let v=0,C=0,T=0,P=0,_=0,w=0;const x=!!r,L=!!a;if(x&&L)switch(g){case"top":v=Math.max(h,M),C=h+d+S,_=(v-M)/2,w=S/2,T=(v-h)/2,P=S+d;break;case"bottom":v=Math.max(h,M),C=h+d+S,T=(v-h)/2,P=0,_=(v-M)/2,w=h+d+S/2;break;case"left":v=h+d+M,C=Math.max(h,S),_=0,w=C/2,T=M+d,P=(C-h)/2;break;default:v=h+d+M,C=Math.max(h,S),T=0,P=(C-h)/2,_=h+d,w=C/2;break}else x?(v=h,C=h,T=0,P=0):L&&(v=M,C=S,_=0,w=S/2);const A=v+d*2,E=C+d*2;if(s.width=A,s.height=E,n.font=`${o}px ${this.parameters.fontFamily}`,p&&(n.fillStyle=p,this._drawRoundedRect(n,0,0,A,E,m),n.fill()),x&&n.drawImage(r,T+d,P+d,h,h),L){n.fillStyle=c;const I=n.measureText(a),j=I.actualBoundingBoxAscent+I.actualBoundingBoxDescent,Pe=I.actualBoundingBoxAscent-j/2;n.textBaseline="alphabetic",n.fillText(a,_+d,w+d+Pe)}const G=this.material.map,N=new i.CanvasTexture(s);N.colorSpace=i.SRGBColorSpace,this.material.map=N,G?.dispose(),this.scale.set(A*y,E*y,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 Y extends R{isShapeMesh=!0;type="ShapeMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new i.ShapeGeometry(e?.shape,e?.curveSegments),this.material=new i.MeshStandardNodeMaterial(t),this.geometry.rotateX(-Math.PI/2)}static createFromPoints(e,t={}){return new Y({...t,geometryParameters:{...t.geometryParameters,shape:new i.Shape(e.map(s=>new i.Vector2(s.x,-s.z)))}})}}class J extends R{isExtrudeMesh=!0;type="ExtrudeMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new i.ExtrudeGeometry(e?.shape,e?.options),this.material=new i.MeshStandardNodeMaterial(t),this.geometry.rotateX(-Math.PI/2)}static createFromPoints(e,t={}){return e&&e.length===0&&(e=void 0),new J({...t,geometryParameters:{...t.geometryParameters,shape:new i.Shape(e?.map(s=>new i.Vector2(s.x,-s.z)))}})}}class gt extends R{isPlaneMesh=!0;type="PlaneMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(),this.geometry=new i.PlaneGeometry(e?.width,e?.height,e?.widthSegments,e?.heightSegments),this.material=new i.MeshStandardNodeMaterial(t)}}class ft extends R{isCircleMesh=!0;type="CircleMesh";constructor({geometryParameters:e,materialParameters:t}={}){super(new i.CircleGeometry(e?.radius,e?.segments,e?.thetaStart,e?.thetaLength),new i.MeshStandardNodeMaterial(t)),this.geometry.rotateX(-Math.PI/2)}}class B{static traverseMeshes(e,t){e.traverse(s=>{s instanceof i.Mesh&&t(s)})}}class yt{static flow(e={}){const{baseColor:t=16777215,flowColor:s=65280,speed:n=1,scale:r=3,intensity:a=4}=e,o=u.color(new i.Color(t)),c=u.color(new i.Color(s)),h=u.uv().x.mul(r).sub(u.time.mul(n)),d=u.pow(u.sin(h).add(1).mul(.5),a);return u.mix(o,c,d)}static breathe(e={}){const{baseColor:t=16777215,breathColor:s=65280,speed:n=1,intensity:r=2}=e,a=u.color(new i.Color(t)),o=u.color(new i.Color(s)),c=u.sin(u.time.mul(n)).add(1).mul(.5),h=u.pow(c,r);return u.mix(a,o,h)}static fluid(e={}){const{baseColor:t=16777215,flowColor:s=255,speed:n=1,scale:r=1,intensity:a=1,distortion:o=.5}=e,c=u.color(new i.Color(t)),h=u.color(new i.Color(s)),d=u.uv().mul(r),p=u.time.mul(n),m=u.mx_noise_float(d.add(p),1,0),g=d.add(m.mul(o)),y=u.mx_noise_float(g,1,0).add(1).mul(.5),b=u.pow(y,a);return u.mix(c,h,b)}}function wt(l){}const $="uSpaceHighlight",H=`${$}/enabled`,be=`${$}/opacity`,xe=`${$}/color`,Se=`${$}/overwrite`,q="uSpaceBreathe",V=`${q}/enabled`,Me=`${q}/color`,Ce=`${q}/speed`,_e=`${q}/intensity`,W=new WeakMap,vt=u.Fn(()=>{const l=u.userData(H,"uint"),e=u.userData(xe,"uint"),t=u.userData(Se,"uint"),s=ie(e),n=u.materialColor.mul(s),r=u.select(t.greaterThan(0),s,n),a=u.select(l.greaterThan(0),r,u.materialColor),o=u.userData(V,"uint"),c=u.userData(Me,"uint"),h=u.userData(Ce,"float"),d=u.userData(_e,"float"),p=ie(c),m=u.sin(u.time.mul(h)).add(1).mul(.5),g=u.pow(m,d),y=u.mix(a,p,g);return u.select(o.greaterThan(0),y,a)})(),bt=u.Fn(()=>{const l=u.userData(H,"uint"),e=u.userData(be,"float");return u.select(l.greaterThan(0),e,u.materialOpacity)})();function se(l){const e=l.material;if(!e||Array.isArray(e))return;let t=W.get(e);t||(t={colorNode:e.colorNode,opacityNode:e.opacityNode,transparent:e.transparent,depthWrite:e.depthWrite,activeMeshes:new Set},W.set(e,t)),t.activeMeshes.add(l),e.transparent=!0,e.colorNode=vt,e.opacityNode=bt,e.needsUpdate=!0}function ne(l){const e=l.userData[H],t=l.userData[V];if(e||t)return;const s=l.material;if(!s||Array.isArray(s))return;const n=W.get(s);n&&(n.activeMeshes.delete(l),!(n.activeMeshes.size>0)&&(s.colorNode=n.colorNode,s.opacityNode=n.opacityNode,s.transparent=n.transparent,s.depthWrite=n.depthWrite,s.needsUpdate=!0,W.delete(s)))}class U{static highlightColor(e,t={}){const s=Array.isArray(e)?e:[e],{opacity:n=.5,color:r=16711680,overwrite:a=!1,depthWrite:o}=t,c=new i.Color(r).getHex();for(const h of s)B.traverseMeshes(h,d=>{if(d.userData[H]=1,d.userData[be]=n,d.userData[xe]=c,d.userData[Se]=a?1:0,se(d),o!==void 0){const p=d.material;p&&!Array.isArray(p)&&(p.depthWrite=o)}})}static removeHighlightColor(e){const t=Array.isArray(e)?e:[e];for(const s of t)B.traverseMeshes(s,n=>{n.userData[H]=0,ne(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 i.Color(n.color).getHex();for(const r of s)B.traverseMeshes(r,a=>{a.userData[V]=1,a.userData[Me]=n.color,a.userData[Ce]=n.speed,a.userData[_e]=n.intensity,se(a)})}static removeBreatheColor(e){const t=Array.isArray(e)?e:[e];for(const s of t)B.traverseMeshes(s,n=>{n.userData[V]=0,ne(n)})}static wireframe(e,t=!0){const s=Array.isArray(e)?e:[e];for(const n of s)B.traverseMeshes(n,r=>{const a=r.material;!a||Array.isArray(a)||(a.wireframe=t,a.needsUpdate=!0)})}static removeWireframe(e){U.wireframe(e,!1)}static fadeIn(e,t={}){const{duration:s=500}=t;return U._fade(e,0,1,s)}static fadeOut(e,t={}){const{duration:s=500}=t;return U._fade(e,1,0,s)}static _fade(e,t,s,n){const r=Array.isArray(e)?e:[e],a=[];for(const o of r)B.traverseMeshes(o,c=>{const h=c.material;!h||Array.isArray(h)||(h.transparent=!0,h.opacity=t,h.needsUpdate=!0,a.push({material:h,targetOpacity:s}))});return a.length===0?Promise.resolve():new Promise(o=>{const c=performance.now();let h=0;const d=()=>{const p=performance.now()-c,m=Math.min(p/n,1);if(!r[0].parent){cancelAnimationFrame(h),o();return}for(const{material:y,targetOpacity:b}of a)y.opacity=t+(b-t)*m,y.needsUpdate=!0;if(m<1)h=requestAnimationFrame(d);else{if(s>=1)for(const{material:y}of a)y.transparent=!1;o()}};h=requestAnimationFrame(d)})}}const ie=l=>{const e=l.shiftRight(16).bitAnd(255).toFloat().div(255),t=l.shiftRight(8).bitAnd(255).toFloat().div(255),s=l.bitAnd(255).toFloat().div(255);return u.vec3(e,t,s)};class Ee extends f.Tween{viewer;constructor(e,t){super(t),this.viewer=e}_update=({time:e})=>{this.update(e)&&this.viewer.render()};easingByMode(e){const t=St[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 xt(l,e,t,s={},n,r){return new Promise((a,o)=>{const{duration:c=1e3,delay:h=0,repeat:d=!1,mode:p="Linear.None",yoyo:m=!1}=s,g=new Ee(l,e).to(t,c).easingByMode(p).delay(h).onUpdate(y=>{n?.(y,g)}).onComplete(()=>{a()}).onStop(()=>{o("animation stop")}).onStart(()=>{r?.(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 St={"Linear.None":f.Easing.Linear.None,"Quadratic.In":f.Easing.Quadratic.In,"Quadratic.Out":f.Easing.Quadratic.Out,"Quadratic.InOut":f.Easing.Quadratic.InOut,"Cubic.In":f.Easing.Cubic.In,"Cubic.Out":f.Easing.Cubic.Out,"Cubic.InOut":f.Easing.Cubic.InOut,"Quartic.In":f.Easing.Quartic.In,"Quartic.Out":f.Easing.Quartic.Out,"Quartic.InOut":f.Easing.Quartic.InOut,"Quintic.In":f.Easing.Quintic.In,"Quintic.Out":f.Easing.Quintic.Out,"Quintic.InOut":f.Easing.Quintic.InOut,"Sinusoidal.In":f.Easing.Sinusoidal.In,"Sinusoidal.Out":f.Easing.Sinusoidal.Out,"Sinusoidal.InOut":f.Easing.Sinusoidal.InOut,"Exponential.In":f.Easing.Exponential.In,"Exponential.Out":f.Easing.Exponential.Out,"Exponential.InOut":f.Easing.Exponential.InOut,"Circular.In":f.Easing.Circular.In,"Circular.Out":f.Easing.Circular.Out,"Circular.InOut":f.Easing.Circular.InOut,"Elastic.In":f.Easing.Elastic.In,"Elastic.Out":f.Easing.Elastic.Out,"Elastic.InOut":f.Easing.Elastic.InOut,"Back.In":f.Easing.Back.In,"Back.Out":f.Easing.Back.Out,"Back.InOut":f.Easing.Back.InOut,"Bounce.In":f.Easing.Bounce.In,"Bounce.Out":f.Easing.Bounce.Out,"Bounce.InOut":f.Easing.Bounce.InOut};class Mt{scene;planes=new Map;helpers=new Map;group;constructor(e){this.scene=e,this.group=new i.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:o=16711680}=t,c=new i.Plane(new i.Vector3(s.x,s.y,s.z),n);return this.planes.set(e,c),this._syncPlanes(),r&&this.showHelper(e,a,o),c}addBox(e,t,s={}){const{showHelpers:n=!1,helperColor:r=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}],h=[];for(const d of c){const p=`${e}_${d.suffix}`;this.addPlane(p,{normal:d.normal,constant:d.constant,showHelper:n,helperColor:r}),h.push(p)}return h}addBoxFromObject(e,t,s=0,n={}){const r=new i.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 i.PlaneHelper(n,t,new i.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 Ct{scene;measurements=new Map;_idCounter=0;constructor(e){this.scene=e}measureDistance(e,t,s={}){const{lineColor:n=16776960}=s,r=new i.Vector3(e.x,e.y,e.z),a=new i.Vector3(t.x,t.y,t.z),o=r.distanceTo(a),c=`measure_dist_${this._idCounter++}`,h=new i.Group;h.name=c;const d=new i.BufferGeometry().setFromPoints([r,a]),p=new i.LineBasicMaterial({color:n}),m=new i.Line(d,p);h.add(m),this.scene.add(h);const g={id:c,type:"distance",value:o,unit:"m",points:[r,a],object:h};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 i.Vector3(g.x,g.y,g.z)),r=this._calculatePolygonArea(n),a=`measure_area_${this._idCounter++}`,o=new i.Group;o.name=a;const c=[...n,n[0]],h=new i.BufferGeometry().setFromPoints(c),d=new i.LineBasicMaterial({color:s}),p=new i.Line(h,d);o.add(p),this.scene.add(o);const m={id:a,type:"area",value:r,unit:"m²",points:n,object:o};return this.measurements.set(a,m),m}measureAngle(e,t,s,n={}){const{lineColor:r=16746496}=n,a=new i.Vector3(e.x,e.y,e.z),o=new i.Vector3(t.x,t.y,t.z),c=new i.Vector3(s.x,s.y,s.z),h=a.clone().sub(o).normalize(),d=c.clone().sub(o).normalize(),m=Math.acos(Math.max(-1,Math.min(1,h.dot(d))))*180/Math.PI,g=`measure_angle_${this._idCounter++}`,y=new i.Group;y.name=g;const b=new i.BufferGeometry().setFromPoints([a,o,c]),M=new i.LineBasicMaterial({color:r}),S=new i.Line(b,M);y.add(S),this.scene.add(y);const v={id:g,type:"angle",value:m,unit:"°",points:[a,o,c],object:y};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 i.Vector3;for(let r=0;r<t;r++){const a=e[r],o=e[(r+1)%t],c=new i.Vector3().crossVectors(a,o);s.add(c)}const n=new i.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 _t{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 i.Group;s.name=`annotation_${e}`;const n=new i.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[
|
|
16
|
+
`,t.labelStyle)for(const[h,d]of Object.entries(t.labelStyle))d!==void 0&&(r.style[h]=d);let a=null;const o=t.labelOffset||{x:0,y:2,z:0};if(t.showLeaderLine!==!1){const{lineColor:h=16777215}=t,d=new i.BufferGeometry().setFromPoints([new i.Vector3(0,0,0),new i.Vector3(o.x,o.y,o.z)]),p=new i.LineBasicMaterial({color:h});a=new i.Line(d,p),s.add(a)}if(this._createCSSObject){const h=this._createCSSObject(r);h.position.set(o.x,o.y,o.z),s.add(h)}this.scene.add(s);const c={id:e,options:t,group:s,labelElement:r,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 Te="0.0.19";window.__USPACE__={version:Te};Object.defineProperty(exports,"CSS2DObject",{enumerable:!0,get:()=>K.CSS2DObject});Object.defineProperty(exports,"CSS3DObject",{enumerable:!0,get:()=>D.CSS3DObject});Object.defineProperty(exports,"CSS3DSprite",{enumerable:!0,get:()=>D.CSS3DSprite});exports.AnnotationManager=_t;exports.BaseGroup=Q;exports.BaseMesh=R;exports.BaseSprite=we;exports.CSSRenderer=me;exports.CameraControls=de;exports.CircleMesh=ft;exports.ClippingTool=Mt;exports.ExtrudeMesh=J;exports.InteractionEvent=oe;exports.InteractionManager=ce;exports.LightManager=Fe;exports.MaterialEffects=U;exports.MeasureTool=Ct;exports.Model=k;exports.ModelLoaderManager=O;exports.ObjectManager=he;exports.ObjectUtils=B;exports.PlaneMesh=gt;exports.Poi=mt;exports.RenderPipeline=le;exports.RoomEnvironment=pe;exports.SBMLoader=ye;exports.SBMXLoader=ge;exports.SceneManager=Ge;exports.Selection=He;exports.ShapeMesh=Y;exports.SphereMesh=ve;exports.TSLEffects=yt;exports.TextureLoaderManager=pt;exports.Topology=ut;exports.TubeMesh=X;exports.Tween=Ee;exports.Viewer=Qe;exports.reinterpretType=wt;exports.tweenAnimation=xt;exports.version=Te;
|