endset_three_editor 0.7.3 → 0.7.4

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.
@@ -266,7 +266,7 @@
266
266
  `,i.setAttribute("data-item-code",s.code||""),i.innerHTML=`
267
267
  <span class="item-label" style="opacity: 0.9; flex-shrink: 0; letter-spacing: ${n(.3)}em;">${this.escapeHtml(s.label)}</span>
268
268
  <span class="item-value" style="font-weight: 700; color: #9ae4ff; text-shadow: 0 0 ${n(6)}em rgba(154, 228, 255, 0.25); text-align: right; word-break: break-all;">${this.escapeHtml(s.value)}${s.unit?`<span style="font-size:0.85em;opacity:0.8;margin-left:${n(2)}em;">${this.escapeHtml(s.unit)}</span>`:""}</span>
269
- `,e.appendChild(i)})}escapeHtml(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}attachTo(e){this.attachedObject&&this.attachedObject!==e&&this.detach();const t=new T.Vector3;e.getWorldPosition(t);const n=new T.Box3().setFromObject(e),s=new T.Vector3,i=new T.Vector3;n.getCenter(s),n.getSize(i);const c=n.max.y-t.y+this.options.offsetY;this.css2dObject||(this.css2dObject=new pn(this.container),this.css2dObject.name=`DataPanel_${e.name||e.uuid}`,this.css2dObject.center.set(.5,1)),this.css2dObject.position.set(this.options.offsetX,c,0),e.add(this.css2dObject),this.attachedObject=e}detach(){this.css2dObject&&this.attachedObject&&this.attachedObject.remove(this.css2dObject),this.attachedObject=null}show(){this._visible=!0,this.css2dObject&&(this.css2dObject.visible=!0)}hide(){this._visible=!1,this.css2dObject&&(this.css2dObject.visible=!1)}get visible(){return this._visible}set visible(e){e?this.show():this.hide()}setTitle(e){var n;this.options.title=e;const t=(n=this.container)==null?void 0:n.querySelector("[data-panel-title]");e?t?t.textContent=e:this.rebuildPanel():t&&t.remove()}getTitle(){return this.options.title||""}setItems(e){var n;this.options.items=[...e];const t=(n=this.container)==null?void 0:n.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}getItems(){return[...this.options.items||[]]}addItem(e){var n;this.options.items.push(e);const t=(n=this.container)==null?void 0:n.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}removeItem(e){var n;this.options.items=this.options.items.filter(s=>s.label!==e);const t=(n=this.container)==null?void 0:n.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}updateItem(e,t,n){var i;const s=this.options.items.find(o=>o.label===e);if(s){s.value=t,n!==void 0&&(s.unit=n);const o=(i=this.container)==null?void 0:i.querySelector("[data-panel-list]");o&&this.renderItems(o,this.options.items)}}updateItemByCode(e,t){var s;const n=this.options.items.find(i=>i.code===e);if(n){n.value=t;const i=(s=this.container)==null?void 0:s.querySelector("[data-panel-list]");i&&this.renderItems(i,this.options.items)}}clearItems(){var t;this.options.items=[];const e=(t=this.container)==null?void 0:t.querySelector("[data-panel-list]");e&&this.renderItems(e,[])}rebuildPanel(){const e=this._visible,t=this.attachedObject;this.css2dObject&&this.attachedObject&&this.attachedObject.remove(this.css2dObject),this.buildPanel(),t&&(this.attachedObject=t,t.add(this.css2dObject),e||this.hide())}updateOptions(e){this.options={...this.options,...e},this.rebuildPanel()}getOffsetY(){return this.options.offsetY??.1}setOffsetY(e){if(this.options.offsetY=e,this.css2dObject&&this.attachedObject){const t=new T.Vector3;this.attachedObject.getWorldPosition(t);const s=new T.Box3().setFromObject(this.attachedObject).max.y-t.y;this.css2dObject.position.set(this.options.offsetX??0,s+e,0)}}getOffsetX(){return this.options.offsetX??0}setOffsetX(e){this.options.offsetX=e,this.css2dObject&&this.attachedObject&&(this.css2dObject.position.x=e)}getWidth(){return this.options.width||"200px"}getFontSize(){return this.options.fontSize||"13px"}setWidth(e){this.options.width=e,this.container&&(this.container.style.width=e)}setFontSize(e){if(this.options.fontSize=e,this.container){this.container.style.fontSize=e;const t=this.container.querySelector("[data-panel-title]");t&&(t.style.fontSize=`calc(${e} + 2px)`)}}getElement(){return this.container}dispose(){var e;this.detach(),(e=this.container)!=null&&e.parentNode&&this.container.parentNode.removeChild(this.container),this.css2dObject=null,this.container=null,this.attachedObject=null}}const Ze=new WeakMap;function _t(l,e){const t=a.toRaw(l);Ze.set(t,e),t.userData._hasDataPanel=!0}function xe(l){return Ze.get(a.toRaw(l))||null}function At(l){const e=a.toRaw(l),t=Ze.get(e);t&&(t.dispose(),Ze.delete(e)),e.userData._hasDataPanel=void 0}let V=null;function $t(l){return V?(V.domElement.parentNode!==l&&l.appendChild(V.domElement),V):(V=new mn,V.setSize(l.clientWidth,l.clientHeight),V.domElement.style.position="absolute",V.domElement.style.top="0",V.domElement.style.left="0",V.domElement.style.pointerEvents="none",l.appendChild(V.domElement),V)}function Sn(){return V}function es(l,e){V&&V.render(l,e)}function ts(l,e){V&&V.setSize(l,e)}function ss(){V&&(V.domElement.parentNode&&V.domElement.parentNode.removeChild(V.domElement),V=null)}const x={mode:"",transformControlsMode:"translate",scene:null,camera:null,defaultMainCamera:null,renderer:null,orbitControls:null,transformControls:null,container:null,gridHelper:null,selectedObject:null};let Ge=!1,de=!1,se=null,ne=null;const wn=16755200,Ft=16733440;let it=[],Fe=[],Pe=!0,ue=null,ot=null,He=null,ie=[];const he=new Map;let Xe,ze=null,Re=null,Ne=null;function ns(l,e="edit",t){x.container=l,x.mode=e,En(),Nn(),Pn(),t&&(ys(t.scene,e,t.dataPanels,t.waters),t!=null&&t.camera&&(x.defaultMainCamera=t.camera,ut(!0))),Dn(),Ln(),Xe&&x.orbitControls&&(x.orbitControls.target.fromArray(Xe),x.orbitControls.update()),Rn(),ds(),is(),Re=n=>jn(n),Ne=()=>Wn(),e==="edit"&&l.addEventListener("click",Re),window.addEventListener("resize",Ne),t||On(),e==="edit"&&kn()}function Tn(){var i,o;const l=window.devicePixelRatio,e=((i=x.container)==null?void 0:i.clientWidth)||window.innerWidth,t=((o=x.container)==null?void 0:o.clientHeight)||window.innerHeight,n=e*l*t*l;let s;return n<=5e6?s=Math.min(l,2):n<=12e6?s=Math.min(l,1.5):n<=2e7?s=Math.min(l,1.3):s=Math.min(l,1),s}function En(){const l=Tn(),e=new T.WebGLRenderer({antialias:!0,alpha:!0});e.setSize(x.container.clientWidth,x.container.clientHeight),e.setPixelRatio(l),console.log(`[Renderer] css=${x.container.clientWidth}×${x.container.clientHeight}, dpr=${window.devicePixelRatio}, targetRatio=${l}, antialias=true`),x.container.appendChild(e.domElement),x.renderer=e}function Rn(){if(!x.renderer||!x.scene||!x.camera)return;const l=new un(x.renderer);l.addPass(new dn(x.scene,x.camera)),l.addPass(new hn);const e=window.innerWidth*window.devicePixelRatio,t=window.innerWidth*window.devicePixelRatio*window.innerHeight*window.devicePixelRatio,s=e/1920,o=Math.round(4*Math.min(Math.max(s,.6),8)),c=t>25e6?1:t>12e6?1.5:2;console.log(`[OutlinePass] totalPx=${t}, downSample=${c}, dpr=${window.devicePixelRatio}, thickness=${o}`);const A=new te(new T.Vector2(x.container.clientWidth,x.container.clientHeight),x.scene,x.camera);A.edgeStrength=8,A.edgeGlow=1.5,A.edgeThickness=o,A.visibleEdgeColor.set(Ft),A.hiddenEdgeColor.set(Ft),A.downSampleRatio=c,A.pulsePeriod=2,l.addPass(A),se=l,ne=A}function Nn(){x.scene=new T.Scene,x.scene.name="sl_scene",new T.TextureLoader().load(fn,e=>{const t=new T.PMREMGenerator(x.renderer),n=t.fromEquirectangular(e).texture;x.scene.environment=n,t.dispose()},void 0,e=>console.error("背景图加载失败:",e))}function kn(){const l=new T.GridHelper(30,30,8956671,3364232);l.name="地板",l.userData.type="initFloor",x.scene.add(l),x.gridHelper=l}function Pn(){const l=x.container,e=l.clientWidth/l.clientHeight,t=new T.PerspectiveCamera(45,e,.1,1e3);t.position.set(0,6,15),t.lookAt(0,0,0),x.camera=t}function ut(l=!1){if(!x.defaultMainCamera)return;const e=x.defaultMainCamera;if(l){x.camera.position.set(e.position[0],e.position[1],e.position[2]),x.camera.rotation.set(e.rotation[0],e.rotation[1],e.rotation[2]),x.camera.updateProjectionMatrix(),Xe=e.target;return}else ft(""),dt();if(!x.camera||!x.orbitControls)return;const t=x.camera.position.clone(),n=x.orbitControls.target.clone(),s=new T.Vector3(e.position[0],e.position[1],e.position[2]),i=e.target?new T.Vector3(e.target[0],e.target[1],e.target[2]):new T.Vector3(0,0,0);x.orbitControls.enabled=!1,new ke.Tween({x:t.x,y:t.y,z:t.z,tx:n.x,ty:n.y,tz:n.z}).to({x:s.x,y:s.y,z:s.z,tx:i.x,ty:i.y,tz:i.z},1e3).easing(ke.Easing.Quadratic.InOut).onUpdate(o=>{x.camera.position.set(o.x,o.y,o.z),x.orbitControls.target.set(o.tx,o.ty,o.tz),x.orbitControls.update()}).onComplete(()=>{Xe=e.target,x.orbitControls.enabled=!0}).start()}function Ln(){const l=new js(x.camera,x.renderer.domElement);l.minDistance=0,l.maxDistance=1/0,l.addEventListener("start",()=>{Ge=!1}),l.addEventListener("change",()=>{Ge=!0}),l.addEventListener("end",()=>{Ge&&(de=!0,setTimeout(()=>{de=!1},200))}),x.orbitControls=l}function Dn(){const l=new Qs(x.camera,x.renderer.domElement);l.addEventListener("dragging-changed",e=>{x.orbitControls.enabled=!e.value,e.value||(de=!0,setTimeout(()=>{de=!1},200))}),l.addEventListener("objectChange",()=>{const e=x.selectedObject;if(ot&&e&&ot(e),e&&e.type==="DirectionalLight"){const t=e.userData.helper;t&&t.update&&t.update()}}),x.scene.add(l.getHelper()),x.transformControls=l}function On(){const l=new T.AmbientLight(16777215,1);x.scene.add(l)}function is(){var e,t;ze=requestAnimationFrame(is),ke.update(),(e=x.orbitControls)==null||e.update(),x.mode==="run"&&se&&x.scene&&x.camera?se.render():(t=x.renderer)==null||t.render(x.scene,x.camera),x.scene&&x.camera&&es(x.scene,x.camera),Pe&&x.scene&&(Fe=[],x.scene.traverse(n=>{n.userData.isWater&&n.type==="Mesh"&&Fe.push(n)}),Pe=!1);for(let n=0;n<Fe.length;n++){const s=Fe[n],i=s.material;if(i.uniforms&&i.uniforms.time){const o=s.userData.waterTimeScale??1;i.uniforms.time.value+=1/60*o,x.camera&&i.uniforms.eye&&i.uniforms.eye.value.copy(x.camera.position);continue}if(i.normalMap){const o=s.userData.waterSpeed||{x:.005,y:.003};i.normalMap.offset.x+=o.x,i.normalMap.offset.y+=o.y}}}function Wn(){if(!x.container||!x.camera||!x.renderer)return;const l=x.container.clientWidth,e=x.container.clientHeight;l===0||e===0||(x.camera.aspect=l/e,x.camera.updateProjectionMatrix(),x.renderer.setSize(l,e),se&&se.setSize(l,e),ne&&ne.resolution.set(l,e),ts(l,e))}function qe(l){x.selectedObject!==l&&(x.selectedObject&&x.transformControls.detach(),x.selectedObject=l,x.transformControls.attach(l),x.transformControls.setMode(x.transformControlsMode),x.transformControls.showX=!0,x.transformControls.showY=!0,x.transformControls.showZ=!0,as(l),ue==null||ue(l))}let q=null;function os(l){q=l}function Ke(l){q==null||q(l)}function rs(l){x.transformControlsMode=l,x.transformControls&&x.transformControls.setMode(x.transformControlsMode)}function as(l){if(x.mode==="edit")dt(),l.traverse(t=>{if(t.isMesh){const n=t,s=new T.EdgesGeometry(n.geometry),i=new T.LineBasicMaterial({color:wn,depthTest:!0}),o=new T.LineSegments(s,i);t.add(o),it.push(o)}});else{if(!ne)return;const t=[];l.traverse(n=>{n.isMesh&&t.push(n)}),ne.selectedObjects=t}}function dt(){if(x.mode==="edit"){for(const l of it)l.parent&&l.parent.remove(l),l.geometry.dispose(),l.material.dispose();it=[]}else ne&&(ne.selectedObjects=[])}function ht(){x.selectedObject&&(dt(),x.transformControls.detach(),x.selectedObject=null,ue==null||ue(null))}function ft(l){let e=null;he.forEach(t=>{t.userData.id==l&&(e=t),t.children&&t.children.forEach(n=>{n.name&&n.name.startsWith("DataPanel_")&&(n.visible=!1)})}),e&&(e.children.forEach(t=>{t.name&&t.name.startsWith("DataPanel_")&&(t.visible=!0)}),as(e),setTimeout(()=>{ls(e)},500))}function jn(l){if(de){de=!1;return}const e=x.renderer.domElement.getBoundingClientRect(),t=new T.Vector2((l.clientX-e.left)/e.width*2-1,-((l.clientY-e.top)/e.height)*2+1),n=new T.Raycaster;n.setFromCamera(t,x.camera);const s=[];x.scene.traverse(o=>{(o.userData.isMovable||o.userData.type==="lightHelper")&&s.push(o)});const i=n.intersectObjects(s);if(i.length>0){let o=Vn(i[0].object);qe(o)}else ht()}function Vn(l){if(l.type==="Line"||l.type==="LineSegments"){const e=l.parent;if(e)switch(e.type){case"DirectionalLightHelper":return e.light;default:return e.isMesh?e:l}return l}return l}function ls(l,e=500){if(!x.camera||!x.orbitControls){console.warn("[focusOnObject] 编辑器尚未初始化或已销毁,无法执行聚焦操作。请确保已调用 initEditor()");return}if(!l){console.warn("[focusOnObject] 传入的物体为空,无法执行聚焦操作。");return}let t=null;l.userData.closeUpView&&typeof l.userData.closeUpView.x=="number"&&typeof l.userData.closeUpView.y=="number"&&typeof l.userData.closeUpView.z=="number"&&(t=l.userData.closeUpView);const n=new T.Vector3;l.getWorldPosition(n);const i=new T.Box3().setFromObject(l).getSize(new T.Vector3),o=Math.max(i.x,i.y,i.z)*.5,c=Math.max(o*3.5,5),A=new T.Vector3().copy(x.camera.position).sub(n).normalize();A.lengthSq()<.001&&A.set(0,0,1);const u=n.clone().add(A.multiplyScalar(c)),d=x.camera.position.clone(),h=x.orbitControls.target.clone();try{new ke.Tween({x:d.x,y:d.y,z:d.z,tx:h.x,ty:h.y,tz:h.z}).to({x:t?t.x:u.x,y:t?t.y:u.y,z:t?t.z:u.z,tx:n.x,ty:n.y,tz:n.z},e).easing(ke.Easing.Quadratic.InOut).onUpdate(p=>{x.camera.position.set(p.x,p.y,p.z),x.orbitControls.target.set(p.tx,p.ty,p.tz),x.orbitControls.update()}).start()}catch(p){console.error("[focusOnObject] TWEEN 动画创建失败,请检查 @tweenjs/tween.js 是否已正确安装且版本兼容(^23.1.3):",p)}}function Fn(l){l.userData.id&&he.set(String(l.userData.id),l)}function Bn(l){l.userData.id&&he.delete(String(l.userData.id))}function cs(l,e){const t=e||l.userData.id;if(t)he.set(String(t),l);else{const n=T.MathUtils.generateUUID();l.userData.id=n,he.set(n,l)}}function Un(l){l.traverse(e=>{if(e.name&&e.name.startsWith("DataPanel_")){const t=e;t.element&&t.element.parentNode&&t.element.parentNode.removeChild(t.element)}})}function oe(l,e=!1){x.scene.add(l),Pe=!0,l.userData.isMovable&&(Gn(l),Je()),e&&x.mode==="edit"&&qe(l)}function As(l){x.selectedObject===l&&ht(),Pe=!0,Un(l),Bn(l),l.userData.helper&&x.scene.remove(l.userData.helper),l.parent?l.parent.remove(l):x.scene.remove(l),Hn(l),Je()}function us(l){const e=x.scene.getObjectByProperty("uuid",l);e&&As(e)}function Gn(l){l.userData.isMovable&&l.parent===x.scene&&(ie.includes(l)||ie.push(l))}function Hn(l){const e=ie.indexOf(l);e!==-1&&ie.splice(e,1)}function ds(){const l=[];x.scene.children.forEach(e=>{e.userData.isMovable&&l.push(e)}),ie=l,Je()}function Je(){He==null||He([...ie])}function hs(l){ue=l}function fs(l){ot=l}function ps(l){He=l}function ms(){return ie}function gs(){return x.selectedObject}function zn(l,e,t){if(!x.scene)return;const n=he.get(l);if(n){const s=xe(n);s&&s.updateItemByCode(e,t)}}function Kn(){return x.scene}function bs(){return x.camera}function Zn(){return x.renderer}async function Cs(){var p,C,y;q==null||q(!0),await new Promise(f=>setTimeout(f,50)),ht();const l=x.scene;if(!l)return q==null||q(!1),"{}";const e=[],t=new Map,n=new Map,s=[],i=[];l.traverse(f=>{var m;if(f.userData.type==="lightHelper"&&e.push(f),f.type==="DirectionalLight"&&f.userData.helper&&(t.set(f,f.userData.helper),f.userData.helper=void 0),f.userData.isWater&&f.type==="Mesh"&&f.parent){const b=f,S=b.material;let I="#4fc3f7";S.uniforms&&S.uniforms.waterColor&&(I="#"+S.uniforms.waterColor.value.getHexString());const v=b.geometry,M={uuid:f.uuid,name:f.name,position:f.position.toArray(),rotation:[f.rotation.x,f.rotation.y,f.rotation.z],scale:f.scale.toArray(),color:I,timeScale:f.userData.waterTimeScale??.05,geometryType:"box",boxWidth:void 0,boxDepth:void 0,cylinderRadiusTop:void 0,cylinderRadiusBottom:void 0,cylinderRadialSegments:void 0};v.parameters&&v.parameters.radiusTop!==void 0?(M.geometryType="cylinder",M.cylinderRadiusTop=v.parameters.radiusTop,M.cylinderRadiusBottom=v.parameters.radiusBottom,M.cylinderRadialSegments=v.parameters.radialSegments):(M.geometryType="box",M.boxWidth=v.parameters.width,M.boxDepth=v.parameters.depth),s.push(M),i.push(f)}if(f.name&&f.name.startsWith("DataPanel_")){const b=f;if(b.element){const S=b.element.querySelector("[data-panel-title]"),I=[];if(b.element.querySelectorAll(".sl-css2d-data-panel-item").forEach(M=>{var E,P,N;const g=M.querySelector(".item-label"),w=M.querySelector(".item-value");if(g&&w){const k=(g.textContent||"").trim(),G=((P=(E=w.childNodes[0])==null?void 0:E.textContent)==null?void 0:P.trim())||"",ae=w.querySelector("span"),H=ae?(ae.textContent||"").trim():void 0,O=((N=M.getAttribute("data-item-code"))==null?void 0:N.trim())||void 0;I.push({label:k,value:G,unit:H,code:O})}}),f.parent){const M=b.element.style.width||"",g=b.element.style.fontSize||"",w=xe(f.parent),E=w?w.getOffsetY():.1;n.set(f.parent.userData.id?f.parent.userData.id:f.parent.uuid,{title:((m=S==null?void 0:S.textContent)==null?void 0:m.trim())||"",items:I,width:M,fontSize:g,offsetY:E,offsetX:w?w.getOffsetX():0})}}}}),e.forEach(f=>l.remove(f));const o=new Map;for(const f of i)o.set(f,f.parent),f.parent&&f.parent.remove(f);const c=l.clone();c.children=c.children.filter(f=>f.userData.type!=="initFloor"),c.traverse(f=>{f.name&&f.name.startsWith("DataPanel_")&&f.parent&&f.parent.remove(f)});const A=c.toJSON();e.forEach(f=>l.add(f));for(const f of i){const m=o.get(f);m?m.add(f):l.add(f)}t.forEach((f,m)=>{m.userData.helper=f});const u={position:(p=x.camera)==null?void 0:p.position.toArray(),rotation:(C=x.camera)==null?void 0:C.rotation.toArray(),target:((y=x.orbitControls)==null?void 0:y.target.toArray())||[0,0,0]},d={};n.forEach((f,m)=>{d[m]=f});const h=JSON.stringify({scene:A,camera:u,dataPanels:d,waters:s});return q==null||q(!1),h}function ys(l,e="edit",t,n){var c,A,u;const s=typeof l=="string"?JSON.parse(l):l,o=new T.ObjectLoader().parse(s);o.type==="Scene"?x.scene=o:(c=x.scene)==null||c.add(o),t&&((A=x.scene)==null||A.traverse(d=>{const h=d.userData.id||d.uuid,p=t[h];if(p&&d.userData.isMovable){Fn(d);const C=new ye({title:p.title,items:p.items});C.attachTo(d),C.visible=!1,p.width&&C.setWidth(p.width),p.fontSize&&C.setFontSize(p.fontSize),p.offsetY!==void 0&&C.setOffsetY(p.offsetY),p.offsetX!==void 0&&C.setOffsetX(p.offsetX),_t(d,C)}})),n&&n.length>0&&Promise.resolve().then(()=>ji).then(({addWater:d,addWaterCylinder:h})=>{for(const p of n){const C=p.geometryType||"box";let y;C==="cylinder"?y=h({radiusTop:p.cylinderRadiusTop??5,radiusBottom:p.cylinderRadiusBottom??5,radialSegments:p.cylinderRadialSegments??32,height:.8,color:p.color,scale:4}):y=d({width:p.boxWidth??10,height:p.boxDepth??10,color:p.color,scale:4}),y.position.fromArray(p.position),y.rotation.set(p.rotation[0],p.rotation[1],p.rotation[2]),y.scale.fromArray(p.scale),y.name=p.name,y.userData.waterTimeScale=p.timeScale??.05,y.userData.isWater=!0,y.userData.isMovable=!0,Pe=!0}ds()}),e==="edit"&&((u=x.scene)==null||u.traverse(d=>{var h;if(d.type==="DirectionalLight"){const p=d;if(!p.userData.helper){const C=new T.DirectionalLightHelper(p,1);C.userData.type="lightHelper",p.userData.helper=C,(h=x.scene)==null||h.add(C)}}}))}function Is(l){if(!l)return;if(l.type==="Mesh"){const t=l;t.geometry&&t.geometry.dispose(),t.material&&(Array.isArray(t.material)?t.material:[t.material]).forEach(s=>{s.map&&(s.map=null),s.lightMap&&(s.lightMap=null),s.aoMap&&(s.aoMap=null),s.emissiveMap&&(s.emissiveMap=null),s.bumpMap&&(s.bumpMap=null),s.normalMap&&(s.normalMap=null),s.displacementMap&&(s.displacementMap=null),s.roughnessMap&&(s.roughnessMap=null),s.metalnessMap&&(s.metalnessMap=null),s.alphaMap&&(s.alphaMap=null),s.envMap&&(s.envMap=null),s.dispose()})}const e=l.children.slice();for(const t of e)Is(t)}function xs(){ze!==null&&(cancelAnimationFrame(ze),ze=null),Re&&x.container&&(x.container.removeEventListener("click",Re),Re=null),Ne&&(window.removeEventListener("resize",Ne),Ne=null),x.orbitControls&&(x.orbitControls.dispose(),x.orbitControls=null),x.transformControls&&(x.transformControls.dispose(),x.transformControls=null),se&&(se.dispose(),se=null,ne=null),x.scene&&(Is(x.scene),x.scene=null),x.renderer&&(x.renderer.dispose(),x.renderer.domElement&&x.container&&x.container.removeChild(x.renderer.domElement),x.renderer=null),ss(),x.camera=null,x.gridHelper=null,x.selectedObject=null,x.container=null,x.mode="",ie=[],he.clear(),Je(),Ge=!1,de=!1}const Xn=/^[og]\s*(.+)?/,qn=/^mtllib /,Jn=/^usemtl /,Qn=/^usemap /,Bt=/\s+/,Ut=new r.Vector3,$e=new r.Vector3,Gt=new r.Vector3,Ht=new r.Vector3,J=new r.Vector3,Be=new r.Color;function Yn(){const l={objects:[],object:{},vertices:[],normals:[],colors:[],uvs:[],materials:{},materialLibraries:[],startObject:function(e,t){if(this.object&&this.object.fromDeclaration===!1){this.object.name=e,this.object.fromDeclaration=t!==!1;return}const n=this.object&&typeof this.object.currentMaterial=="function"?this.object.currentMaterial():void 0;if(this.object&&typeof this.object._finalize=="function"&&this.object._finalize(!0),this.object={name:e||"",fromDeclaration:t!==!1,geometry:{vertices:[],normals:[],colors:[],uvs:[],hasUVIndices:!1},materials:[],smooth:!0,startMaterial:function(s,i){const o=this._finalize(!1);o&&(o.inherited||o.groupCount<=0)&&this.materials.splice(o.index,1);const c={index:this.materials.length,name:s||"",mtllib:Array.isArray(i)&&i.length>0?i[i.length-1]:"",smooth:o!==void 0?o.smooth:this.smooth,groupStart:o!==void 0?o.groupEnd:0,groupEnd:-1,groupCount:-1,inherited:!1,clone:function(A){const u={index:typeof A=="number"?A:this.index,name:this.name,mtllib:this.mtllib,smooth:this.smooth,groupStart:0,groupEnd:-1,groupCount:-1,inherited:!1};return u.clone=this.clone.bind(u),u}};return this.materials.push(c),c},currentMaterial:function(){if(this.materials.length>0)return this.materials[this.materials.length-1]},_finalize:function(s){const i=this.currentMaterial();if(i&&i.groupEnd===-1&&(i.groupEnd=this.geometry.vertices.length/3,i.groupCount=i.groupEnd-i.groupStart,i.inherited=!1),s&&this.materials.length>1)for(let o=this.materials.length-1;o>=0;o--)this.materials[o].groupCount<=0&&this.materials.splice(o,1);return s&&this.materials.length===0&&this.materials.push({name:"",smooth:this.smooth}),i}},n&&n.name&&typeof n.clone=="function"){const s=n.clone(0);s.inherited=!0,this.object.materials.push(s)}this.objects.push(this.object)},finalize:function(){this.object&&typeof this.object._finalize=="function"&&this.object._finalize(!0)},parseVertexIndex:function(e,t){const n=parseInt(e,10);return(n>=0?n-1:n+t/3)*3},parseNormalIndex:function(e,t){const n=parseInt(e,10);return(n>=0?n-1:n+t/3)*3},parseUVIndex:function(e,t){const n=parseInt(e,10);return(n>=0?n-1:n+t/2)*2},addVertex:function(e,t,n){const s=this.vertices,i=this.object.geometry.vertices;i.push(s[e+0],s[e+1],s[e+2]),i.push(s[t+0],s[t+1],s[t+2]),i.push(s[n+0],s[n+1],s[n+2])},addVertexPoint:function(e){const t=this.vertices;this.object.geometry.vertices.push(t[e+0],t[e+1],t[e+2])},addVertexLine:function(e){const t=this.vertices;this.object.geometry.vertices.push(t[e+0],t[e+1],t[e+2])},addNormal:function(e,t,n){const s=this.normals,i=this.object.geometry.normals;i.push(s[e+0],s[e+1],s[e+2]),i.push(s[t+0],s[t+1],s[t+2]),i.push(s[n+0],s[n+1],s[n+2])},addFaceNormal:function(e,t,n){const s=this.vertices,i=this.object.geometry.normals;Ut.fromArray(s,e),$e.fromArray(s,t),Gt.fromArray(s,n),J.subVectors(Gt,$e),Ht.subVectors(Ut,$e),J.cross(Ht),J.normalize(),i.push(J.x,J.y,J.z),i.push(J.x,J.y,J.z),i.push(J.x,J.y,J.z)},addColor:function(e,t,n){const s=this.colors,i=this.object.geometry.colors;s[e]!==void 0&&i.push(s[e+0],s[e+1],s[e+2]),s[t]!==void 0&&i.push(s[t+0],s[t+1],s[t+2]),s[n]!==void 0&&i.push(s[n+0],s[n+1],s[n+2])},addUV:function(e,t,n){const s=this.uvs,i=this.object.geometry.uvs;i.push(s[e+0],s[e+1]),i.push(s[t+0],s[t+1]),i.push(s[n+0],s[n+1])},addDefaultUV:function(){const e=this.object.geometry.uvs;e.push(0,0),e.push(0,0),e.push(0,0)},addUVLine:function(e){const t=this.uvs;this.object.geometry.uvs.push(t[e+0],t[e+1])},addFace:function(e,t,n,s,i,o,c,A,u){const d=this.vertices.length;let h=this.parseVertexIndex(e,d),p=this.parseVertexIndex(t,d),C=this.parseVertexIndex(n,d);if(this.addVertex(h,p,C),this.addColor(h,p,C),c!==void 0&&c!==""){const y=this.normals.length;h=this.parseNormalIndex(c,y),p=this.parseNormalIndex(A,y),C=this.parseNormalIndex(u,y),this.addNormal(h,p,C)}else this.addFaceNormal(h,p,C);if(s!==void 0&&s!==""){const y=this.uvs.length;h=this.parseUVIndex(s,y),p=this.parseUVIndex(i,y),C=this.parseUVIndex(o,y),this.addUV(h,p,C),this.object.geometry.hasUVIndices=!0}else this.addDefaultUV()},addPointGeometry:function(e){this.object.geometry.type="Points";const t=this.vertices.length;for(let n=0,s=e.length;n<s;n++){const i=this.parseVertexIndex(e[n],t);this.addVertexPoint(i),this.addColor(i)}},addLineGeometry:function(e,t){this.object.geometry.type="Line";const n=this.vertices.length,s=this.uvs.length;for(let i=0,o=e.length;i<o;i++)this.addVertexLine(this.parseVertexIndex(e[i],n));for(let i=0,o=t.length;i<o;i++)this.addUVLine(this.parseUVIndex(t[i],s))}};return l.startObject("",!1),l}class _n extends r.Loader{constructor(e){super(e),this.materials=null}load(e,t,n,s){const i=this,o=new r.FileLoader(this.manager);o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,function(c){try{t(i.parse(c))}catch(A){s?s(A):console.error(A),i.manager.itemError(e)}},n,s)}setMaterials(e){return this.materials=e,this}parse(e){const t=new Yn;e.indexOf(`\r
269
+ `,e.appendChild(i)})}escapeHtml(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}attachTo(e){this.attachedObject&&this.attachedObject!==e&&this.detach();const t=new T.Vector3;e.getWorldPosition(t);const n=new T.Box3().setFromObject(e),s=new T.Vector3,i=new T.Vector3;n.getCenter(s),n.getSize(i);const c=n.max.y-t.y+this.options.offsetY;this.css2dObject||(this.css2dObject=new pn(this.container),this.css2dObject.name=`DataPanel_${e.name||e.uuid}`,this.css2dObject.center.set(.5,1)),this.css2dObject.position.set(this.options.offsetX,c,0),e.add(this.css2dObject),this.attachedObject=e}detach(){this.css2dObject&&this.attachedObject&&this.attachedObject.remove(this.css2dObject),this.attachedObject=null}show(){this._visible=!0,this.css2dObject&&(this.css2dObject.visible=!0)}hide(){this._visible=!1,this.css2dObject&&(this.css2dObject.visible=!1)}get visible(){return this._visible}set visible(e){e?this.show():this.hide()}setTitle(e){var n;this.options.title=e;const t=(n=this.container)==null?void 0:n.querySelector("[data-panel-title]");e?t?t.textContent=e:this.rebuildPanel():t&&t.remove()}getTitle(){return this.options.title||""}setItems(e){var n;this.options.items=[...e];const t=(n=this.container)==null?void 0:n.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}getItems(){return[...this.options.items||[]]}addItem(e){var n;this.options.items.push(e);const t=(n=this.container)==null?void 0:n.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}removeItem(e){var n;this.options.items=this.options.items.filter(s=>s.label!==e);const t=(n=this.container)==null?void 0:n.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}updateItem(e,t,n){var i;const s=this.options.items.find(o=>o.label===e);if(s){s.value=t,n!==void 0&&(s.unit=n);const o=(i=this.container)==null?void 0:i.querySelector("[data-panel-list]");o&&this.renderItems(o,this.options.items)}}updateItemByCode(e,t){var s;const n=this.options.items.find(i=>i.code===e);if(n){n.value=t;const i=(s=this.container)==null?void 0:s.querySelector("[data-panel-list]");i&&this.renderItems(i,this.options.items)}}clearItems(){var t;this.options.items=[];const e=(t=this.container)==null?void 0:t.querySelector("[data-panel-list]");e&&this.renderItems(e,[])}rebuildPanel(){const e=this._visible,t=this.attachedObject;this.css2dObject&&this.attachedObject&&this.attachedObject.remove(this.css2dObject),this.buildPanel(),t&&(this.attachedObject=t,t.add(this.css2dObject),e||this.hide())}updateOptions(e){this.options={...this.options,...e},this.rebuildPanel()}getOffsetY(){return this.options.offsetY??.1}setOffsetY(e){if(this.options.offsetY=e,this.css2dObject&&this.attachedObject){const t=new T.Vector3;this.attachedObject.getWorldPosition(t);const s=new T.Box3().setFromObject(this.attachedObject).max.y-t.y;this.css2dObject.position.set(this.options.offsetX??0,s+e,0)}}getOffsetX(){return this.options.offsetX??0}setOffsetX(e){this.options.offsetX=e,this.css2dObject&&this.attachedObject&&(this.css2dObject.position.x=e)}getWidth(){return this.options.width||"200px"}getFontSize(){return this.options.fontSize||"13px"}setWidth(e){this.options.width=e,this.container&&(this.container.style.width=e)}setFontSize(e){if(this.options.fontSize=e,this.container){this.container.style.fontSize=e;const t=this.container.querySelector("[data-panel-title]");t&&(t.style.fontSize=`calc(${e} + 2px)`)}}getElement(){return this.container}dispose(){var e;this.detach(),(e=this.container)!=null&&e.parentNode&&this.container.parentNode.removeChild(this.container),this.css2dObject=null,this.container=null,this.attachedObject=null}}const Ze=new WeakMap;function _t(l,e){const t=a.toRaw(l);Ze.set(t,e),t.userData._hasDataPanel=!0}function xe(l){return Ze.get(a.toRaw(l))||null}function At(l){const e=a.toRaw(l),t=Ze.get(e);t&&(t.dispose(),Ze.delete(e)),e.userData._hasDataPanel=void 0}let V=null;function $t(l){return V?(V.domElement.parentNode!==l&&l.appendChild(V.domElement),V):(V=new mn,V.setSize(l.clientWidth,l.clientHeight),V.domElement.style.position="absolute",V.domElement.style.top="0",V.domElement.style.left="0",V.domElement.style.pointerEvents="none",l.appendChild(V.domElement),V)}function Sn(){return V}function es(l,e){V&&V.render(l,e)}function ts(l,e){V&&V.setSize(l,e)}function ss(){V&&(V.domElement.parentNode&&V.domElement.parentNode.removeChild(V.domElement),V=null)}const x={mode:"",transformControlsMode:"translate",scene:null,camera:null,defaultMainCamera:null,renderer:null,orbitControls:null,transformControls:null,container:null,gridHelper:null,selectedObject:null};let Ge=!1,de=!1,se=null,ne=null;const wn=16755200,Ft=26367;let it=[],Fe=[],Pe=!0,ue=null,ot=null,He=null,ie=[];const he=new Map;let Xe,ze=null,Re=null,Ne=null;function ns(l,e="edit",t){x.container=l,x.mode=e,En(),Nn(),Pn(),t&&(ys(t.scene,e,t.dataPanels,t.waters),t!=null&&t.camera&&(x.defaultMainCamera=t.camera,ut(!0))),Dn(),Ln(),Xe&&x.orbitControls&&(x.orbitControls.target.fromArray(Xe),x.orbitControls.update()),Rn(),ds(),is(),Re=n=>jn(n),Ne=()=>Wn(),e==="edit"&&l.addEventListener("click",Re),window.addEventListener("resize",Ne),t||On(),e==="edit"&&kn()}function Tn(){var i,o;const l=window.devicePixelRatio,e=((i=x.container)==null?void 0:i.clientWidth)||window.innerWidth,t=((o=x.container)==null?void 0:o.clientHeight)||window.innerHeight,n=e*l*t*l;let s;return n<=5e6?s=Math.min(l,2):n<=12e6?s=Math.min(l,1.5):n<=2e7?s=Math.min(l,1.3):s=Math.min(l,1),s}function En(){const l=Tn(),e=new T.WebGLRenderer({antialias:!0,alpha:!0});e.setSize(x.container.clientWidth,x.container.clientHeight),e.setPixelRatio(l),console.log(`[Renderer] css=${x.container.clientWidth}×${x.container.clientHeight}, dpr=${window.devicePixelRatio}, targetRatio=${l}, antialias=true`),x.container.appendChild(e.domElement),x.renderer=e}function Rn(){if(!x.renderer||!x.scene||!x.camera)return;const l=new un(x.renderer);l.addPass(new dn(x.scene,x.camera)),l.addPass(new hn);const e=window.innerWidth*window.devicePixelRatio,t=window.innerWidth*window.devicePixelRatio*window.innerHeight*window.devicePixelRatio,s=e/1920,o=Math.round(1.5*Math.min(Math.max(s,.5),3)),c=t>25e6?2:t>12e6?1.5:2;console.log(`[OutlinePass] totalPx=${t}, downSample=${c}, dpr=${window.devicePixelRatio}, thickness=${o}`);const A=new te(new T.Vector2(x.container.clientWidth,x.container.clientHeight),x.scene,x.camera);A.edgeStrength=6,A.edgeGlow=.8,A.edgeThickness=Math.min(o,4),A.visibleEdgeColor.set(Ft),A.hiddenEdgeColor.set(Ft),A.downSampleRatio=c,A.pulsePeriod=2,l.addPass(A),se=l,ne=A}function Nn(){x.scene=new T.Scene,x.scene.name="sl_scene",new T.TextureLoader().load(fn,e=>{const t=new T.PMREMGenerator(x.renderer),n=t.fromEquirectangular(e).texture;x.scene.environment=n,t.dispose()},void 0,e=>console.error("背景图加载失败:",e))}function kn(){const l=new T.GridHelper(30,30,8956671,3364232);l.name="地板",l.userData.type="initFloor",x.scene.add(l),x.gridHelper=l}function Pn(){const l=x.container,e=l.clientWidth/l.clientHeight,t=new T.PerspectiveCamera(45,e,.1,1e3);t.position.set(0,6,15),t.lookAt(0,0,0),x.camera=t}function ut(l=!1){if(!x.defaultMainCamera)return;const e=x.defaultMainCamera;if(l){x.camera.position.set(e.position[0],e.position[1],e.position[2]),x.camera.rotation.set(e.rotation[0],e.rotation[1],e.rotation[2]),x.camera.updateProjectionMatrix(),Xe=e.target;return}else ft(""),dt();if(!x.camera||!x.orbitControls)return;const t=x.camera.position.clone(),n=x.orbitControls.target.clone(),s=new T.Vector3(e.position[0],e.position[1],e.position[2]),i=e.target?new T.Vector3(e.target[0],e.target[1],e.target[2]):new T.Vector3(0,0,0);x.orbitControls.enabled=!1,new ke.Tween({x:t.x,y:t.y,z:t.z,tx:n.x,ty:n.y,tz:n.z}).to({x:s.x,y:s.y,z:s.z,tx:i.x,ty:i.y,tz:i.z},1e3).easing(ke.Easing.Quadratic.InOut).onUpdate(o=>{x.camera.position.set(o.x,o.y,o.z),x.orbitControls.target.set(o.tx,o.ty,o.tz),x.orbitControls.update()}).onComplete(()=>{Xe=e.target,x.orbitControls.enabled=!0}).start()}function Ln(){const l=new js(x.camera,x.renderer.domElement);l.minDistance=0,l.maxDistance=1/0,l.addEventListener("start",()=>{Ge=!1}),l.addEventListener("change",()=>{Ge=!0}),l.addEventListener("end",()=>{Ge&&(de=!0,setTimeout(()=>{de=!1},200))}),x.orbitControls=l}function Dn(){const l=new Qs(x.camera,x.renderer.domElement);l.addEventListener("dragging-changed",e=>{x.orbitControls.enabled=!e.value,e.value||(de=!0,setTimeout(()=>{de=!1},200))}),l.addEventListener("objectChange",()=>{const e=x.selectedObject;if(ot&&e&&ot(e),e&&e.type==="DirectionalLight"){const t=e.userData.helper;t&&t.update&&t.update()}}),x.scene.add(l.getHelper()),x.transformControls=l}function On(){const l=new T.AmbientLight(16777215,1);x.scene.add(l)}function is(){var e,t;ze=requestAnimationFrame(is),ke.update(),(e=x.orbitControls)==null||e.update(),x.mode==="run"&&se&&x.scene&&x.camera?se.render():(t=x.renderer)==null||t.render(x.scene,x.camera),x.scene&&x.camera&&es(x.scene,x.camera),Pe&&x.scene&&(Fe=[],x.scene.traverse(n=>{n.userData.isWater&&n.type==="Mesh"&&Fe.push(n)}),Pe=!1);for(let n=0;n<Fe.length;n++){const s=Fe[n],i=s.material;if(i.uniforms&&i.uniforms.time){const o=s.userData.waterTimeScale??1;i.uniforms.time.value+=1/60*o,x.camera&&i.uniforms.eye&&i.uniforms.eye.value.copy(x.camera.position);continue}if(i.normalMap){const o=s.userData.waterSpeed||{x:.005,y:.003};i.normalMap.offset.x+=o.x,i.normalMap.offset.y+=o.y}}}function Wn(){if(!x.container||!x.camera||!x.renderer)return;const l=x.container.clientWidth,e=x.container.clientHeight;l===0||e===0||(x.camera.aspect=l/e,x.camera.updateProjectionMatrix(),x.renderer.setSize(l,e),se&&se.setSize(l,e),ne&&ne.resolution.set(l,e),ts(l,e))}function qe(l){x.selectedObject!==l&&(x.selectedObject&&x.transformControls.detach(),x.selectedObject=l,x.transformControls.attach(l),x.transformControls.setMode(x.transformControlsMode),x.transformControls.showX=!0,x.transformControls.showY=!0,x.transformControls.showZ=!0,as(l),ue==null||ue(l))}let q=null;function os(l){q=l}function Ke(l){q==null||q(l)}function rs(l){x.transformControlsMode=l,x.transformControls&&x.transformControls.setMode(x.transformControlsMode)}function as(l){if(x.mode==="edit")dt(),l.traverse(t=>{if(t.isMesh){const n=t,s=new T.EdgesGeometry(n.geometry),i=new T.LineBasicMaterial({color:wn,depthTest:!0}),o=new T.LineSegments(s,i);t.add(o),it.push(o)}});else{if(!ne)return;const t=[];l.traverse(n=>{n.isMesh&&t.push(n)}),ne.selectedObjects=t}}function dt(){if(x.mode==="edit"){for(const l of it)l.parent&&l.parent.remove(l),l.geometry.dispose(),l.material.dispose();it=[]}else ne&&(ne.selectedObjects=[])}function ht(){x.selectedObject&&(dt(),x.transformControls.detach(),x.selectedObject=null,ue==null||ue(null))}function ft(l){let e=null;he.forEach(t=>{t.userData.id==l&&(e=t),t.children&&t.children.forEach(n=>{n.name&&n.name.startsWith("DataPanel_")&&(n.visible=!1)})}),e&&(e.children.forEach(t=>{t.name&&t.name.startsWith("DataPanel_")&&(t.visible=!0)}),as(e),setTimeout(()=>{ls(e)},200))}function jn(l){if(de){de=!1;return}const e=x.renderer.domElement.getBoundingClientRect(),t=new T.Vector2((l.clientX-e.left)/e.width*2-1,-((l.clientY-e.top)/e.height)*2+1),n=new T.Raycaster;n.setFromCamera(t,x.camera);const s=[];x.scene.traverse(o=>{(o.userData.isMovable||o.userData.type==="lightHelper")&&s.push(o)});const i=n.intersectObjects(s);if(i.length>0){let o=Vn(i[0].object);qe(o)}else ht()}function Vn(l){if(l.type==="Line"||l.type==="LineSegments"){const e=l.parent;if(e)switch(e.type){case"DirectionalLightHelper":return e.light;default:return e.isMesh?e:l}return l}return l}function ls(l,e=500){if(!x.camera||!x.orbitControls){console.warn("[focusOnObject] 编辑器尚未初始化或已销毁,无法执行聚焦操作。请确保已调用 initEditor()");return}if(!l){console.warn("[focusOnObject] 传入的物体为空,无法执行聚焦操作。");return}let t=null;l.userData.closeUpView&&typeof l.userData.closeUpView.x=="number"&&typeof l.userData.closeUpView.y=="number"&&typeof l.userData.closeUpView.z=="number"&&(t=l.userData.closeUpView);const n=new T.Vector3;l.getWorldPosition(n);const i=new T.Box3().setFromObject(l).getSize(new T.Vector3),o=Math.max(i.x,i.y,i.z)*.5,c=Math.max(o*3.5,5),A=new T.Vector3().copy(x.camera.position).sub(n).normalize();A.lengthSq()<.001&&A.set(0,0,1);const u=n.clone().add(A.multiplyScalar(c)),d=x.camera.position.clone(),h=x.orbitControls.target.clone();try{new ke.Tween({x:d.x,y:d.y,z:d.z,tx:h.x,ty:h.y,tz:h.z}).to({x:t?t.x:u.x,y:t?t.y:u.y,z:t?t.z:u.z,tx:n.x,ty:n.y,tz:n.z},e).easing(ke.Easing.Quadratic.InOut).onUpdate(p=>{x.camera.position.set(p.x,p.y,p.z),x.orbitControls.target.set(p.tx,p.ty,p.tz),x.orbitControls.update()}).start()}catch(p){console.error("[focusOnObject] TWEEN 动画创建失败,请检查 @tweenjs/tween.js 是否已正确安装且版本兼容(^23.1.3):",p)}}function Fn(l){l.userData.id&&he.set(String(l.userData.id),l)}function Bn(l){l.userData.id&&he.delete(String(l.userData.id))}function cs(l,e){const t=e||l.userData.id;if(t)he.set(String(t),l);else{const n=T.MathUtils.generateUUID();l.userData.id=n,he.set(n,l)}}function Un(l){l.traverse(e=>{if(e.name&&e.name.startsWith("DataPanel_")){const t=e;t.element&&t.element.parentNode&&t.element.parentNode.removeChild(t.element)}})}function oe(l,e=!1){x.scene.add(l),Pe=!0,l.userData.isMovable&&(Gn(l),Je()),e&&x.mode==="edit"&&qe(l)}function As(l){x.selectedObject===l&&ht(),Pe=!0,Un(l),Bn(l),l.userData.helper&&x.scene.remove(l.userData.helper),l.parent?l.parent.remove(l):x.scene.remove(l),Hn(l),Je()}function us(l){const e=x.scene.getObjectByProperty("uuid",l);e&&As(e)}function Gn(l){l.userData.isMovable&&l.parent===x.scene&&(ie.includes(l)||ie.push(l))}function Hn(l){const e=ie.indexOf(l);e!==-1&&ie.splice(e,1)}function ds(){const l=[];x.scene.children.forEach(e=>{e.userData.isMovable&&l.push(e)}),ie=l,Je()}function Je(){He==null||He([...ie])}function hs(l){ue=l}function fs(l){ot=l}function ps(l){He=l}function ms(){return ie}function gs(){return x.selectedObject}function zn(l,e,t){if(!x.scene)return;const n=he.get(l);if(n){const s=xe(n);s&&s.updateItemByCode(e,t)}}function Kn(){return x.scene}function bs(){return x.camera}function Zn(){return x.renderer}async function Cs(){var p,C,y;q==null||q(!0),await new Promise(f=>setTimeout(f,50)),ht();const l=x.scene;if(!l)return q==null||q(!1),"{}";const e=[],t=new Map,n=new Map,s=[],i=[];l.traverse(f=>{var m;if(f.userData.type==="lightHelper"&&e.push(f),f.type==="DirectionalLight"&&f.userData.helper&&(t.set(f,f.userData.helper),f.userData.helper=void 0),f.userData.isWater&&f.type==="Mesh"&&f.parent){const b=f,S=b.material;let I="#4fc3f7";S.uniforms&&S.uniforms.waterColor&&(I="#"+S.uniforms.waterColor.value.getHexString());const v=b.geometry,M={uuid:f.uuid,name:f.name,position:f.position.toArray(),rotation:[f.rotation.x,f.rotation.y,f.rotation.z],scale:f.scale.toArray(),color:I,timeScale:f.userData.waterTimeScale??.05,geometryType:"box",boxWidth:void 0,boxDepth:void 0,cylinderRadiusTop:void 0,cylinderRadiusBottom:void 0,cylinderRadialSegments:void 0};v.parameters&&v.parameters.radiusTop!==void 0?(M.geometryType="cylinder",M.cylinderRadiusTop=v.parameters.radiusTop,M.cylinderRadiusBottom=v.parameters.radiusBottom,M.cylinderRadialSegments=v.parameters.radialSegments):(M.geometryType="box",M.boxWidth=v.parameters.width,M.boxDepth=v.parameters.depth),s.push(M),i.push(f)}if(f.name&&f.name.startsWith("DataPanel_")){const b=f;if(b.element){const S=b.element.querySelector("[data-panel-title]"),I=[];if(b.element.querySelectorAll(".sl-css2d-data-panel-item").forEach(M=>{var E,P,N;const g=M.querySelector(".item-label"),w=M.querySelector(".item-value");if(g&&w){const k=(g.textContent||"").trim(),G=((P=(E=w.childNodes[0])==null?void 0:E.textContent)==null?void 0:P.trim())||"",ae=w.querySelector("span"),H=ae?(ae.textContent||"").trim():void 0,O=((N=M.getAttribute("data-item-code"))==null?void 0:N.trim())||void 0;I.push({label:k,value:G,unit:H,code:O})}}),f.parent){const M=b.element.style.width||"",g=b.element.style.fontSize||"",w=xe(f.parent),E=w?w.getOffsetY():.1;n.set(f.parent.userData.id?f.parent.userData.id:f.parent.uuid,{title:((m=S==null?void 0:S.textContent)==null?void 0:m.trim())||"",items:I,width:M,fontSize:g,offsetY:E,offsetX:w?w.getOffsetX():0})}}}}),e.forEach(f=>l.remove(f));const o=new Map;for(const f of i)o.set(f,f.parent),f.parent&&f.parent.remove(f);const c=l.clone();c.children=c.children.filter(f=>f.userData.type!=="initFloor"),c.traverse(f=>{f.name&&f.name.startsWith("DataPanel_")&&f.parent&&f.parent.remove(f)});const A=c.toJSON();e.forEach(f=>l.add(f));for(const f of i){const m=o.get(f);m?m.add(f):l.add(f)}t.forEach((f,m)=>{m.userData.helper=f});const u={position:(p=x.camera)==null?void 0:p.position.toArray(),rotation:(C=x.camera)==null?void 0:C.rotation.toArray(),target:((y=x.orbitControls)==null?void 0:y.target.toArray())||[0,0,0]},d={};n.forEach((f,m)=>{d[m]=f});const h=JSON.stringify({scene:A,camera:u,dataPanels:d,waters:s});return q==null||q(!1),h}function ys(l,e="edit",t,n){var c,A,u;const s=typeof l=="string"?JSON.parse(l):l,o=new T.ObjectLoader().parse(s);o.type==="Scene"?x.scene=o:(c=x.scene)==null||c.add(o),t&&((A=x.scene)==null||A.traverse(d=>{const h=d.userData.id||d.uuid,p=t[h];if(p&&d.userData.isMovable){Fn(d);const C=new ye({title:p.title,items:p.items});C.attachTo(d),C.visible=!1,p.width&&C.setWidth(p.width),p.fontSize&&C.setFontSize(p.fontSize),p.offsetY!==void 0&&C.setOffsetY(p.offsetY),p.offsetX!==void 0&&C.setOffsetX(p.offsetX),_t(d,C)}})),n&&n.length>0&&Promise.resolve().then(()=>ji).then(({addWater:d,addWaterCylinder:h})=>{for(const p of n){const C=p.geometryType||"box";let y;C==="cylinder"?y=h({radiusTop:p.cylinderRadiusTop??5,radiusBottom:p.cylinderRadiusBottom??5,radialSegments:p.cylinderRadialSegments??32,height:.8,color:p.color,scale:4}):y=d({width:p.boxWidth??10,height:p.boxDepth??10,color:p.color,scale:4}),y.position.fromArray(p.position),y.rotation.set(p.rotation[0],p.rotation[1],p.rotation[2]),y.scale.fromArray(p.scale),y.name=p.name,y.userData.waterTimeScale=p.timeScale??.05,y.userData.isWater=!0,y.userData.isMovable=!0,Pe=!0}ds()}),e==="edit"&&((u=x.scene)==null||u.traverse(d=>{var h;if(d.type==="DirectionalLight"){const p=d;if(!p.userData.helper){const C=new T.DirectionalLightHelper(p,1);C.userData.type="lightHelper",p.userData.helper=C,(h=x.scene)==null||h.add(C)}}}))}function Is(l){if(!l)return;if(l.type==="Mesh"){const t=l;t.geometry&&t.geometry.dispose(),t.material&&(Array.isArray(t.material)?t.material:[t.material]).forEach(s=>{s.map&&(s.map=null),s.lightMap&&(s.lightMap=null),s.aoMap&&(s.aoMap=null),s.emissiveMap&&(s.emissiveMap=null),s.bumpMap&&(s.bumpMap=null),s.normalMap&&(s.normalMap=null),s.displacementMap&&(s.displacementMap=null),s.roughnessMap&&(s.roughnessMap=null),s.metalnessMap&&(s.metalnessMap=null),s.alphaMap&&(s.alphaMap=null),s.envMap&&(s.envMap=null),s.dispose()})}const e=l.children.slice();for(const t of e)Is(t)}function xs(){ze!==null&&(cancelAnimationFrame(ze),ze=null),Re&&x.container&&(x.container.removeEventListener("click",Re),Re=null),Ne&&(window.removeEventListener("resize",Ne),Ne=null),x.orbitControls&&(x.orbitControls.dispose(),x.orbitControls=null),x.transformControls&&(x.transformControls.dispose(),x.transformControls=null),se&&(se.dispose(),se=null,ne=null),x.scene&&(Is(x.scene),x.scene=null),x.renderer&&(x.renderer.dispose(),x.renderer.domElement&&x.container&&x.container.removeChild(x.renderer.domElement),x.renderer=null),ss(),x.camera=null,x.gridHelper=null,x.selectedObject=null,x.container=null,x.mode="",ie=[],he.clear(),Je(),Ge=!1,de=!1}const Xn=/^[og]\s*(.+)?/,qn=/^mtllib /,Jn=/^usemtl /,Qn=/^usemap /,Bt=/\s+/,Ut=new r.Vector3,$e=new r.Vector3,Gt=new r.Vector3,Ht=new r.Vector3,J=new r.Vector3,Be=new r.Color;function Yn(){const l={objects:[],object:{},vertices:[],normals:[],colors:[],uvs:[],materials:{},materialLibraries:[],startObject:function(e,t){if(this.object&&this.object.fromDeclaration===!1){this.object.name=e,this.object.fromDeclaration=t!==!1;return}const n=this.object&&typeof this.object.currentMaterial=="function"?this.object.currentMaterial():void 0;if(this.object&&typeof this.object._finalize=="function"&&this.object._finalize(!0),this.object={name:e||"",fromDeclaration:t!==!1,geometry:{vertices:[],normals:[],colors:[],uvs:[],hasUVIndices:!1},materials:[],smooth:!0,startMaterial:function(s,i){const o=this._finalize(!1);o&&(o.inherited||o.groupCount<=0)&&this.materials.splice(o.index,1);const c={index:this.materials.length,name:s||"",mtllib:Array.isArray(i)&&i.length>0?i[i.length-1]:"",smooth:o!==void 0?o.smooth:this.smooth,groupStart:o!==void 0?o.groupEnd:0,groupEnd:-1,groupCount:-1,inherited:!1,clone:function(A){const u={index:typeof A=="number"?A:this.index,name:this.name,mtllib:this.mtllib,smooth:this.smooth,groupStart:0,groupEnd:-1,groupCount:-1,inherited:!1};return u.clone=this.clone.bind(u),u}};return this.materials.push(c),c},currentMaterial:function(){if(this.materials.length>0)return this.materials[this.materials.length-1]},_finalize:function(s){const i=this.currentMaterial();if(i&&i.groupEnd===-1&&(i.groupEnd=this.geometry.vertices.length/3,i.groupCount=i.groupEnd-i.groupStart,i.inherited=!1),s&&this.materials.length>1)for(let o=this.materials.length-1;o>=0;o--)this.materials[o].groupCount<=0&&this.materials.splice(o,1);return s&&this.materials.length===0&&this.materials.push({name:"",smooth:this.smooth}),i}},n&&n.name&&typeof n.clone=="function"){const s=n.clone(0);s.inherited=!0,this.object.materials.push(s)}this.objects.push(this.object)},finalize:function(){this.object&&typeof this.object._finalize=="function"&&this.object._finalize(!0)},parseVertexIndex:function(e,t){const n=parseInt(e,10);return(n>=0?n-1:n+t/3)*3},parseNormalIndex:function(e,t){const n=parseInt(e,10);return(n>=0?n-1:n+t/3)*3},parseUVIndex:function(e,t){const n=parseInt(e,10);return(n>=0?n-1:n+t/2)*2},addVertex:function(e,t,n){const s=this.vertices,i=this.object.geometry.vertices;i.push(s[e+0],s[e+1],s[e+2]),i.push(s[t+0],s[t+1],s[t+2]),i.push(s[n+0],s[n+1],s[n+2])},addVertexPoint:function(e){const t=this.vertices;this.object.geometry.vertices.push(t[e+0],t[e+1],t[e+2])},addVertexLine:function(e){const t=this.vertices;this.object.geometry.vertices.push(t[e+0],t[e+1],t[e+2])},addNormal:function(e,t,n){const s=this.normals,i=this.object.geometry.normals;i.push(s[e+0],s[e+1],s[e+2]),i.push(s[t+0],s[t+1],s[t+2]),i.push(s[n+0],s[n+1],s[n+2])},addFaceNormal:function(e,t,n){const s=this.vertices,i=this.object.geometry.normals;Ut.fromArray(s,e),$e.fromArray(s,t),Gt.fromArray(s,n),J.subVectors(Gt,$e),Ht.subVectors(Ut,$e),J.cross(Ht),J.normalize(),i.push(J.x,J.y,J.z),i.push(J.x,J.y,J.z),i.push(J.x,J.y,J.z)},addColor:function(e,t,n){const s=this.colors,i=this.object.geometry.colors;s[e]!==void 0&&i.push(s[e+0],s[e+1],s[e+2]),s[t]!==void 0&&i.push(s[t+0],s[t+1],s[t+2]),s[n]!==void 0&&i.push(s[n+0],s[n+1],s[n+2])},addUV:function(e,t,n){const s=this.uvs,i=this.object.geometry.uvs;i.push(s[e+0],s[e+1]),i.push(s[t+0],s[t+1]),i.push(s[n+0],s[n+1])},addDefaultUV:function(){const e=this.object.geometry.uvs;e.push(0,0),e.push(0,0),e.push(0,0)},addUVLine:function(e){const t=this.uvs;this.object.geometry.uvs.push(t[e+0],t[e+1])},addFace:function(e,t,n,s,i,o,c,A,u){const d=this.vertices.length;let h=this.parseVertexIndex(e,d),p=this.parseVertexIndex(t,d),C=this.parseVertexIndex(n,d);if(this.addVertex(h,p,C),this.addColor(h,p,C),c!==void 0&&c!==""){const y=this.normals.length;h=this.parseNormalIndex(c,y),p=this.parseNormalIndex(A,y),C=this.parseNormalIndex(u,y),this.addNormal(h,p,C)}else this.addFaceNormal(h,p,C);if(s!==void 0&&s!==""){const y=this.uvs.length;h=this.parseUVIndex(s,y),p=this.parseUVIndex(i,y),C=this.parseUVIndex(o,y),this.addUV(h,p,C),this.object.geometry.hasUVIndices=!0}else this.addDefaultUV()},addPointGeometry:function(e){this.object.geometry.type="Points";const t=this.vertices.length;for(let n=0,s=e.length;n<s;n++){const i=this.parseVertexIndex(e[n],t);this.addVertexPoint(i),this.addColor(i)}},addLineGeometry:function(e,t){this.object.geometry.type="Line";const n=this.vertices.length,s=this.uvs.length;for(let i=0,o=e.length;i<o;i++)this.addVertexLine(this.parseVertexIndex(e[i],n));for(let i=0,o=t.length;i<o;i++)this.addUVLine(this.parseUVIndex(t[i],s))}};return l.startObject("",!1),l}class _n extends r.Loader{constructor(e){super(e),this.materials=null}load(e,t,n,s){const i=this,o=new r.FileLoader(this.manager);o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,function(c){try{t(i.parse(c))}catch(A){s?s(A):console.error(A),i.manager.itemError(e)}},n,s)}setMaterials(e){return this.materials=e,this}parse(e){const t=new Yn;e.indexOf(`\r
270
270
  `)!==-1&&(e=e.replace(/\r\n/g,`
271
271
  `)),e.indexOf(`\\
272
272
  `)!==-1&&(e=e.replace(/\\\n/g,""));const n=e.split(`