endset_three_editor 0.3.5 → 0.3.6

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.
@@ -37,7 +37,7 @@
37
37
  `,n.setAttribute("data-item-code",s.code||""),n.innerHTML=`
38
38
  <span class="item-label" style="opacity: 0.75; flex-shrink: 0;">${this.escapeHtml(s.label)}</span>
39
39
  <span class="item-value" style="font-weight: 600; color: #5dade2; text-align: right; word-break: break-all;">${this.escapeHtml(s.value)}${s.unit?`<span style="font-size:0.85em;opacity:0.7;margin-left:2px;">${this.escapeHtml(s.unit)}</span>`:""}</span>
40
- `,e.appendChild(n)})}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 E.Box3().setFromObject(e),s=new E.Vector3;t.getSize(s);const n=s.y/2+this.options.offsetY;this.css2dObject||(this.css2dObject=new Gn(this.container),this.css2dObject.name=`DataPanel_${e.name||e.uuid}`,this.css2dObject.center.set(.5,1)),this.css2dObject.position.set(0,n,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 s;this.options.title=e;const t=(s=this.container)==null?void 0:s.querySelector("[data-panel-title]");e?t?t.textContent=e:this.rebuildPanel():t&&t.remove()}getTitle(){return this.options.title||""}setItems(e){var s;this.options.items=[...e];const t=(s=this.container)==null?void 0:s.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}getItems(){return[...this.options.items||[]]}addItem(e){var s;this.options.items.push(e);const t=(s=this.container)==null?void 0:s.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}removeItem(e){var s;this.options.items=this.options.items.filter(n=>n.label!==e);const t=(s=this.container)==null?void 0:s.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}updateItem(e,t,s){var o;const n=this.options.items.find(i=>i.label===e);if(n){n.value=t,s!==void 0&&(n.unit=s);const i=(o=this.container)==null?void 0:o.querySelector("[data-panel-list]");i&&this.renderItems(i,this.options.items)}}updateItemByCode(e,t){var n;const s=this.options.items.find(o=>o.code===e);if(s){s.value=t;const o=(n=this.container)==null?void 0:n.querySelector("[data-panel-list]");o&&this.renderItems(o,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()}setOffsetY(e){if(this.options.offsetY=e,this.css2dObject&&this.attachedObject){const t=new E.Box3().setFromObject(this.attachedObject),s=new E.Vector3;t.getSize(s),this.css2dObject.position.set(0,s.y/2+e,0)}}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 Ne=new WeakMap;function Dt(r,e){const t=l.toRaw(r);Ne.set(t,e),t.userData._hasDataPanel=!0}function Se(r){return Ne.get(l.toRaw(r))||null}function Tt(r){const e=l.toRaw(r),t=Ne.get(e);t&&(t.dispose(),Ne.delete(e)),e.userData._hasDataPanel=void 0}let N=null;function Pt(r){return N?(N.domElement.parentNode!==r&&r.appendChild(N.domElement),N):(N=new Wn,N.setSize(r.clientWidth,r.clientHeight),N.domElement.style.position="absolute",N.domElement.style.top="0",N.domElement.style.left="0",N.domElement.style.pointerEvents="none",r.appendChild(N.domElement),N)}function Fn(){return N}function Ot(r,e){N&&N.render(r,e)}function Rt(r,e){N&&N.setSize(r,e)}function Nt(){N&&(N.domElement.parentNode&&N.domElement.parentNode.removeChild(N.domElement),N=null)}const y={mode:"",transformControlsMode:"translate",scene:null,camera:null,renderer:null,orbitControls:null,transformControls:null,container:null,gridHelper:null,selectedObject:null};let Te=!1,oe=!1,Ke=[];const zn=16755200;let se=null,Ye=null,Pe=null,J=[];const ge=new Map;let Ge,Oe=null,pe=null,me=null;function St(r,e="edit",t){if(y.container=r,y.mode=e,qn(),Xn(),Kn(),t&&(Kt(t.scene,e,t.dataPanels),t!=null&&t.camera)){const s=t.camera;y.camera.position.set(s.position[0],s.position[1],s.position[2]),y.camera.rotation.set(s.rotation[0],s.rotation[1],s.rotation[2]),y.camera.updateProjectionMatrix(),Ge=s.target}Zn(),Yn(),Ge&&y.orbitControls&&(y.orbitControls.target.fromArray(Ge),y.orbitControls.update()),rs(),Lt(),pe=s=>$n(s),me=()=>Jn(),e==="edit"&&r.addEventListener("click",pe),window.addEventListener("resize",me),t||Qn(),e==="edit"&&Un()}function qn(){const r=new E.WebGLRenderer({antialias:!0,alpha:!0});r.setSize(y.container.clientWidth,y.container.clientHeight),r.setPixelRatio(Math.min(window.devicePixelRatio,2)),r.shadowMap.enabled=!0,r.shadowMap.type=E.PCFSoftShadowMap,y.container.appendChild(r.domElement),y.renderer=r}function Xn(){y.scene=new E.Scene,y.scene.name="sl_scene"}function Un(){const r=new E.GridHelper(30,30,8956671,3364232);r.name="地板",r.userData.type="initFloor",y.scene.add(r),y.gridHelper=r;const e=new E.PlaneGeometry(30,30),t=new E.ShadowMaterial({opacity:.3,color:0}),s=new E.Mesh(e,t);s.rotation.x=-Math.PI/2,s.position.y=-.01,s.name="阴影接收平面",s.userData.type="initFloor",s.receiveShadow=!0,y.scene.add(s)}function Kn(){const r=y.container,e=r.clientWidth/r.clientHeight,t=new E.PerspectiveCamera(45,e,.1,1e3);t.position.set(0,6,15),t.lookAt(0,0,0),y.camera=t}function Yn(){const r=new bn(y.camera,y.renderer.domElement);r.minDistance=0,r.maxDistance=1/0,r.addEventListener("start",()=>{Te=!1}),r.addEventListener("change",()=>{Te=!0}),r.addEventListener("end",()=>{Te&&(oe=!0,setTimeout(()=>{oe=!1},200))}),y.orbitControls=r}function Zn(){const r=new Rn(y.camera,y.renderer.domElement);r.addEventListener("dragging-changed",e=>{y.orbitControls.enabled=!e.value,e.value||(oe=!0,setTimeout(()=>{oe=!1},200))}),r.addEventListener("objectChange",()=>{const e=y.selectedObject;if(Ye&&e&&Ye(e),e&&e.type==="DirectionalLight"){const t=e.userData.helper;t&&t.update&&t.update()}}),y.scene.add(r.getHelper()),y.transformControls=r}function Qn(){const r=new E.AmbientLight(16777215,.2);y.scene.add(r)}function Lt(){var r,e;Oe=requestAnimationFrame(Lt),Ue.update(),(r=y.orbitControls)==null||r.update(),(e=y.renderer)==null||e.render(y.scene,y.camera),y.scene&&y.camera&&Ot(y.scene,y.camera),y.scene&&y.scene.traverse(t=>{if(t.userData.isWater&&t.type==="Mesh"){const s=t,n=s.material;if(n.normalMap){const o=s.userData.waterSpeed||{x:.005,y:.003};n.normalMap.offset.x+=o.x,n.normalMap.offset.y+=o.y}}})}function Jn(){if(!y.container||!y.camera||!y.renderer)return;const r=y.container.clientWidth,e=y.container.clientHeight;r===0||e===0||(y.camera.aspect=r/e,y.camera.updateProjectionMatrix(),y.renderer.setSize(r,e),Rt(r,e))}function Le(r){y.selectedObject!==r&&(y.selectedObject&&y.transformControls.detach(),y.selectedObject=r,y.transformControls.attach(r),y.transformControls.setMode(y.transformControlsMode),y.transformControls.showX=!0,y.transformControls.showY=!0,y.transformControls.showZ=!0,jt(r),console.log("选中",y.selectedObject),se==null||se(r))}let G=null;function kt(r){G=r}function Re(r){G==null||G(r)}function Ht(r){y.transformControlsMode=r,y.transformControls&&y.transformControls.setMode(y.transformControlsMode)}function jt(r){$e(),r.traverse(e=>{if(e.isMesh){const t=e,s=new E.EdgesGeometry(t.geometry),n=new E.LineBasicMaterial({color:zn,depthTest:!0}),o=new E.LineSegments(s,n);e.add(o),Ke.push(o)}})}function $e(){for(const r of Ke)r.parent&&r.parent.remove(r),r.geometry.dispose(),r.material.dispose();Ke=[]}function et(){y.selectedObject&&($e(),y.transformControls.detach(),y.selectedObject=null,se==null||se(null))}function _n(r){let e;if(ge.forEach(t=>{t.userData.id==r&&(e=t),t.children&&t.children.forEach(s=>{s.name&&s.name.startsWith("DataPanel_")&&(s.visible=!1)})}),!e)return $e();e.children.forEach(t=>{t.name&&t.name.startsWith("DataPanel_")&&(t.visible=!0)}),jt(e),tt(e)}function $n(r){if(oe){oe=!1;return}const e=y.renderer.domElement.getBoundingClientRect(),t=new E.Vector2((r.clientX-e.left)/e.width*2-1,-((r.clientY-e.top)/e.height)*2+1),s=new E.Raycaster;s.setFromCamera(t,y.camera);const n=[];y.scene.traverse(i=>{(i.userData.isMovable||i.userData.type==="lightHelper")&&n.push(i)});const o=s.intersectObjects(n);if(o.length>0){let i=es(o[0].object);Le(i)}else et()}function es(r){if(r.type==="Line"){const e=r.parent;switch(e.type){case"DirectionalLightHelper":return e.light;default:return r}}return r}function tt(r,e=500){if(!y.camera||!y.orbitControls)return;let t=null;r.userData.closeUpView&&typeof r.userData.closeUpView.x=="number"&&typeof r.userData.closeUpView.y=="number"&&typeof r.userData.closeUpView.z=="number"&&(t=r.userData.closeUpView);const s=new E.Vector3;r.getWorldPosition(s);const o=new E.Box3().setFromObject(r).getSize(new E.Vector3),i=Math.max(o.x,o.y,o.z)*.5,c=Math.max(i*3.5,5),d=new E.Vector3().copy(y.camera.position).sub(s).normalize();d.lengthSq()<.001&&d.set(0,0,1);const u=s.clone().add(d.multiplyScalar(c)),A=y.camera.position.clone(),h=y.orbitControls.target.clone();new Ue.Tween({x:A.x,y:A.y,z:A.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:s.x,ty:s.y,tz:s.z},e).easing(Ue.Easing.Quadratic.InOut).onUpdate(m=>{y.camera.position.set(m.x,m.y,m.z),y.orbitControls.target.set(m.tx,m.ty,m.tz),y.orbitControls.update()}).start()}function ts(r){r.userData.id&&ge.set(String(r.userData.id),r)}function ns(r){r.userData.id&&ge.delete(String(r.userData.id))}function ss(r){r.traverse(e=>{if(e.name&&e.name.startsWith("DataPanel_")){const t=e;t.element&&t.element.parentNode&&t.element.parentNode.removeChild(t.element)}})}function ie(r,e=!1){y.scene.add(r),r.userData.isMovable&&(os(r),ke()),e&&y.mode==="edit"&&Le(r)}function Vt(r){y.selectedObject===r&&et(),ss(r),ns(r),r.userData.helper&&y.scene.remove(r.userData.helper),r.parent?r.parent.remove(r):y.scene.remove(r),is(r),ke()}function Bt(r){const e=y.scene.getObjectByProperty("uuid",r);e&&Vt(e)}function os(r){r.userData.isMovable&&r.parent===y.scene&&(J.includes(r)||J.push(r))}function is(r){const e=J.indexOf(r);e!==-1&&J.splice(e,1)}function rs(){const r=[];y.scene.children.forEach(e=>{e.userData.isMovable&&r.push(e)}),J=r,ke()}function ke(){Pe==null||Pe([...J])}function Gt(r){se=r}function Wt(r){Ye=r}function Ft(r){Pe=r}function zt(){return J}function qt(){return y.selectedObject}function as(r,e,t){if(!y.scene)return;const s=ge.get(r);if(s){const n=Se(s);n&&n.updateItemByCode(e,t)}}function ls(){return y.scene}function Xt(){return y.camera}function cs(){return y.renderer}async function Ut(){var u,A,h;G==null||G(!0),await new Promise(m=>setTimeout(m,50)),et();const r=y.scene;if(!r)return G==null||G(!1),"{}";const e=[],t=new Map,s=new Map;r.traverse(m=>{var f;if(m.userData.type==="lightHelper"&&e.push(m),m.type==="DirectionalLight"&&m.userData.helper&&(t.set(m,m.userData.helper),m.userData.helper=void 0),m.name&&m.name.startsWith("DataPanel_")){const g=m;if(g.element){const p=g.element.querySelector("[data-panel-title]"),b=[];g.element.querySelectorAll(".css2d-data-panel-item").forEach(x=>{var M,v,T;const w=x.querySelector(".item-label"),C=x.querySelector(".item-value");if(w&&C){const V=(w.textContent||"").trim(),W=((v=(M=C.childNodes[0])==null?void 0:M.textContent)==null?void 0:v.trim())||"",B=C.querySelector("span"),$=B?(B.textContent||"").trim():void 0,He=((T=x.getAttribute("data-item-code"))==null?void 0:T.trim())||void 0;b.push({label:V,value:W,unit:$,code:He})}}),m.parent&&s.set(m.parent.userData.id?m.parent.userData.id:m.parent.uuid,{title:((f=p==null?void 0:p.textContent)==null?void 0:f.trim())||"",items:b})}}}),e.forEach(m=>r.remove(m));const n=r.clone();n.children=n.children.filter(m=>m.userData.type!=="initFloor"),n.traverse(m=>{m.name&&m.name.startsWith("DataPanel_")&&m.parent&&m.parent.remove(m)});const o=n.toJSON();e.forEach(m=>r.add(m)),t.forEach((m,f)=>{f.userData.helper=m});const i={position:(u=y.camera)==null?void 0:u.position.toArray(),rotation:(A=y.camera)==null?void 0:A.rotation.toArray(),target:((h=y.orbitControls)==null?void 0:h.target.toArray())||[0,0,0]},c={};s.forEach((m,f)=>{c[f]=m});const d=JSON.stringify({scene:o,camera:i,dataPanels:c});return G==null||G(!1),d}function Kt(r,e="edit",t){var i,c,d;const s=typeof r=="string"?JSON.parse(r):r,o=new E.ObjectLoader().parse(s);o.type==="Scene"?y.scene=o:(i=y.scene)==null||i.add(o),t&&((c=y.scene)==null||c.traverse(u=>{const A=u.userData.id||u.uuid,h=t[A];if(h&&u.userData.isMovable){ts(u);const m=new _e({title:h.title,items:h.items});m.attachTo(u),m.visible=!1,console.log("panel",m),Dt(u,m)}})),e==="edit"&&((d=y.scene)==null||d.traverse(u=>{var A;if(u.type==="DirectionalLight"){const h=u;if(!h.userData.helper){const m=new E.DirectionalLightHelper(h,1);m.userData.type="lightHelper",h.userData.helper=m,(A=y.scene)==null||A.add(m)}}}))}function Yt(r){if(!r)return;if(r.type==="Mesh"){const t=r;t.geometry&&t.geometry.dispose(),t.material&&(Array.isArray(t.material)?t.material:[t.material]).forEach(n=>{n.map&&(n.map=null),n.lightMap&&(n.lightMap=null),n.aoMap&&(n.aoMap=null),n.emissiveMap&&(n.emissiveMap=null),n.bumpMap&&(n.bumpMap=null),n.normalMap&&(n.normalMap=null),n.displacementMap&&(n.displacementMap=null),n.roughnessMap&&(n.roughnessMap=null),n.metalnessMap&&(n.metalnessMap=null),n.alphaMap&&(n.alphaMap=null),n.envMap&&(n.envMap=null),n.dispose()})}const e=r.children.slice();for(const t of e)Yt(t)}function Zt(){Oe!==null&&(cancelAnimationFrame(Oe),Oe=null),pe&&y.container&&(y.container.removeEventListener("click",pe),pe=null),me&&(window.removeEventListener("resize",me),me=null),y.orbitControls&&(y.orbitControls.dispose(),y.orbitControls=null),y.transformControls&&(y.transformControls.dispose(),y.transformControls=null),y.scene&&(Yt(y.scene),y.scene=null),y.renderer&&(y.renderer.dispose(),y.renderer.domElement&&y.container&&y.container.removeChild(y.renderer.domElement),y.renderer=null),Nt(),y.camera=null,y.gridHelper=null,y.selectedObject=null,y.container=null,y.mode="",J=[],ge.clear(),ke(),Te=!1,oe=!1}const ds=/^[og]\s*(.+)?/,us=/^mtllib /,hs=/^usemtl /,As=/^usemap /,mt=/\s+/,gt=new a.Vector3,We=new a.Vector3,bt=new a.Vector3,It=new a.Vector3,z=new a.Vector3,Ee=new a.Color;function fs(){const r={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 s=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(n,o){const i=this._finalize(!1);i&&(i.inherited||i.groupCount<=0)&&this.materials.splice(i.index,1);const c={index:this.materials.length,name:n||"",mtllib:Array.isArray(o)&&o.length>0?o[o.length-1]:"",smooth:i!==void 0?i.smooth:this.smooth,groupStart:i!==void 0?i.groupEnd:0,groupEnd:-1,groupCount:-1,inherited:!1,clone:function(d){const u={index:typeof d=="number"?d: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(n){const o=this.currentMaterial();if(o&&o.groupEnd===-1&&(o.groupEnd=this.geometry.vertices.length/3,o.groupCount=o.groupEnd-o.groupStart,o.inherited=!1),n&&this.materials.length>1)for(let i=this.materials.length-1;i>=0;i--)this.materials[i].groupCount<=0&&this.materials.splice(i,1);return n&&this.materials.length===0&&this.materials.push({name:"",smooth:this.smooth}),o}},s&&s.name&&typeof s.clone=="function"){const n=s.clone(0);n.inherited=!0,this.object.materials.push(n)}this.objects.push(this.object)},finalize:function(){this.object&&typeof this.object._finalize=="function"&&this.object._finalize(!0)},parseVertexIndex:function(e,t){const s=parseInt(e,10);return(s>=0?s-1:s+t/3)*3},parseNormalIndex:function(e,t){const s=parseInt(e,10);return(s>=0?s-1:s+t/3)*3},parseUVIndex:function(e,t){const s=parseInt(e,10);return(s>=0?s-1:s+t/2)*2},addVertex:function(e,t,s){const n=this.vertices,o=this.object.geometry.vertices;o.push(n[e+0],n[e+1],n[e+2]),o.push(n[t+0],n[t+1],n[t+2]),o.push(n[s+0],n[s+1],n[s+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,s){const n=this.normals,o=this.object.geometry.normals;o.push(n[e+0],n[e+1],n[e+2]),o.push(n[t+0],n[t+1],n[t+2]),o.push(n[s+0],n[s+1],n[s+2])},addFaceNormal:function(e,t,s){const n=this.vertices,o=this.object.geometry.normals;gt.fromArray(n,e),We.fromArray(n,t),bt.fromArray(n,s),z.subVectors(bt,We),It.subVectors(gt,We),z.cross(It),z.normalize(),o.push(z.x,z.y,z.z),o.push(z.x,z.y,z.z),o.push(z.x,z.y,z.z)},addColor:function(e,t,s){const n=this.colors,o=this.object.geometry.colors;n[e]!==void 0&&o.push(n[e+0],n[e+1],n[e+2]),n[t]!==void 0&&o.push(n[t+0],n[t+1],n[t+2]),n[s]!==void 0&&o.push(n[s+0],n[s+1],n[s+2])},addUV:function(e,t,s){const n=this.uvs,o=this.object.geometry.uvs;o.push(n[e+0],n[e+1]),o.push(n[t+0],n[t+1]),o.push(n[s+0],n[s+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,s,n,o,i,c,d,u){const A=this.vertices.length;let h=this.parseVertexIndex(e,A),m=this.parseVertexIndex(t,A),f=this.parseVertexIndex(s,A);if(this.addVertex(h,m,f),this.addColor(h,m,f),c!==void 0&&c!==""){const g=this.normals.length;h=this.parseNormalIndex(c,g),m=this.parseNormalIndex(d,g),f=this.parseNormalIndex(u,g),this.addNormal(h,m,f)}else this.addFaceNormal(h,m,f);if(n!==void 0&&n!==""){const g=this.uvs.length;h=this.parseUVIndex(n,g),m=this.parseUVIndex(o,g),f=this.parseUVIndex(i,g),this.addUV(h,m,f),this.object.geometry.hasUVIndices=!0}else this.addDefaultUV()},addPointGeometry:function(e){this.object.geometry.type="Points";const t=this.vertices.length;for(let s=0,n=e.length;s<n;s++){const o=this.parseVertexIndex(e[s],t);this.addVertexPoint(o),this.addColor(o)}},addLineGeometry:function(e,t){this.object.geometry.type="Line";const s=this.vertices.length,n=this.uvs.length;for(let o=0,i=e.length;o<i;o++)this.addVertexLine(this.parseVertexIndex(e[o],s));for(let o=0,i=t.length;o<i;o++)this.addUVLine(this.parseUVIndex(t[o],n))}};return r.startObject("",!1),r}class ps extends a.Loader{constructor(e){super(e),this.materials=null}load(e,t,s,n){const o=this,i=new a.FileLoader(this.manager);i.setPath(this.path),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(e,function(c){try{t(o.parse(c))}catch(d){n?n(d):console.error(d),o.manager.itemError(e)}},s,n)}setMaterials(e){return this.materials=e,this}parse(e){const t=new fs;e.indexOf(`\r
40
+ `,e.appendChild(n)})}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 E.Box3().setFromObject(e),s=new E.Vector3;t.getSize(s);const n=s.y/2+this.options.offsetY;this.css2dObject||(this.css2dObject=new Gn(this.container),this.css2dObject.name=`DataPanel_${e.name||e.uuid}`,this.css2dObject.center.set(.5,1)),this.css2dObject.position.set(0,n,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 s;this.options.title=e;const t=(s=this.container)==null?void 0:s.querySelector("[data-panel-title]");e?t?t.textContent=e:this.rebuildPanel():t&&t.remove()}getTitle(){return this.options.title||""}setItems(e){var s;this.options.items=[...e];const t=(s=this.container)==null?void 0:s.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}getItems(){return[...this.options.items||[]]}addItem(e){var s;this.options.items.push(e);const t=(s=this.container)==null?void 0:s.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}removeItem(e){var s;this.options.items=this.options.items.filter(n=>n.label!==e);const t=(s=this.container)==null?void 0:s.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}updateItem(e,t,s){var o;const n=this.options.items.find(i=>i.label===e);if(n){n.value=t,s!==void 0&&(n.unit=s);const i=(o=this.container)==null?void 0:o.querySelector("[data-panel-list]");i&&this.renderItems(i,this.options.items)}}updateItemByCode(e,t){var n;const s=this.options.items.find(o=>o.code===e);if(s){s.value=t;const o=(n=this.container)==null?void 0:n.querySelector("[data-panel-list]");o&&this.renderItems(o,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()}setOffsetY(e){if(this.options.offsetY=e,this.css2dObject&&this.attachedObject){const t=new E.Box3().setFromObject(this.attachedObject),s=new E.Vector3;t.getSize(s),this.css2dObject.position.set(0,s.y/2+e,0)}}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 Ne=new WeakMap;function Dt(r,e){const t=l.toRaw(r);Ne.set(t,e),t.userData._hasDataPanel=!0}function Se(r){return Ne.get(l.toRaw(r))||null}function Tt(r){const e=l.toRaw(r),t=Ne.get(e);t&&(t.dispose(),Ne.delete(e)),e.userData._hasDataPanel=void 0}let N=null;function Pt(r){return N?(N.domElement.parentNode!==r&&r.appendChild(N.domElement),N):(N=new Wn,N.setSize(r.clientWidth,r.clientHeight),N.domElement.style.position="absolute",N.domElement.style.top="0",N.domElement.style.left="0",N.domElement.style.pointerEvents="none",r.appendChild(N.domElement),N)}function Fn(){return N}function Ot(r,e){N&&N.render(r,e)}function Rt(r,e){N&&N.setSize(r,e)}function Nt(){N&&(N.domElement.parentNode&&N.domElement.parentNode.removeChild(N.domElement),N=null)}const y={mode:"",transformControlsMode:"translate",scene:null,camera:null,renderer:null,orbitControls:null,transformControls:null,container:null,gridHelper:null,selectedObject:null};let Te=!1,oe=!1,Ke=[];const zn=16755200;let se=null,Ye=null,Pe=null,J=[];const ge=new Map;let Ge,Oe=null,pe=null,me=null;function St(r,e="edit",t){if(y.container=r,y.mode=e,qn(),Xn(),Kn(),t&&(Kt(t.scene,e,t.dataPanels),t!=null&&t.camera)){const s=t.camera;y.camera.position.set(s.position[0],s.position[1],s.position[2]),y.camera.rotation.set(s.rotation[0],s.rotation[1],s.rotation[2]),y.camera.updateProjectionMatrix(),Ge=s.target}Zn(),Yn(),Ge&&y.orbitControls&&(y.orbitControls.target.fromArray(Ge),y.orbitControls.update()),rs(),Lt(),pe=s=>$n(s),me=()=>Jn(),e==="edit"&&r.addEventListener("click",pe),window.addEventListener("resize",me),t||Qn(),e==="edit"&&Un()}function qn(){const r=new E.WebGLRenderer({antialias:!0,alpha:!0});r.setSize(y.container.clientWidth,y.container.clientHeight),r.setPixelRatio(Math.min(window.devicePixelRatio,2)),r.shadowMap.enabled=!0,r.shadowMap.type=E.PCFSoftShadowMap,y.container.appendChild(r.domElement),y.renderer=r}function Xn(){y.scene=new E.Scene,y.scene.name="sl_scene"}function Un(){const r=new E.GridHelper(30,30,8956671,3364232);r.name="地板",r.userData.type="initFloor",y.scene.add(r),y.gridHelper=r;const e=new E.PlaneGeometry(30,30),t=new E.ShadowMaterial({opacity:.3,color:0}),s=new E.Mesh(e,t);s.rotation.x=-Math.PI/2,s.position.y=-.01,s.name="阴影接收平面",s.userData.type="initFloor",s.receiveShadow=!0,y.scene.add(s)}function Kn(){const r=y.container,e=r.clientWidth/r.clientHeight,t=new E.PerspectiveCamera(45,e,.1,1e3);t.position.set(0,6,15),t.lookAt(0,0,0),y.camera=t}function Yn(){const r=new bn(y.camera,y.renderer.domElement);r.minDistance=0,r.maxDistance=1/0,r.addEventListener("start",()=>{Te=!1}),r.addEventListener("change",()=>{Te=!0}),r.addEventListener("end",()=>{Te&&(oe=!0,setTimeout(()=>{oe=!1},200))}),y.orbitControls=r}function Zn(){const r=new Rn(y.camera,y.renderer.domElement);r.addEventListener("dragging-changed",e=>{y.orbitControls.enabled=!e.value,e.value||(oe=!0,setTimeout(()=>{oe=!1},200))}),r.addEventListener("objectChange",()=>{const e=y.selectedObject;if(Ye&&e&&Ye(e),e&&e.type==="DirectionalLight"){const t=e.userData.helper;t&&t.update&&t.update()}}),y.scene.add(r.getHelper()),y.transformControls=r}function Qn(){const r=new E.AmbientLight(16777215,1);y.scene.add(r)}function Lt(){var r,e;Oe=requestAnimationFrame(Lt),Ue.update(),(r=y.orbitControls)==null||r.update(),(e=y.renderer)==null||e.render(y.scene,y.camera),y.scene&&y.camera&&Ot(y.scene,y.camera),y.scene&&y.scene.traverse(t=>{if(t.userData.isWater&&t.type==="Mesh"){const s=t,n=s.material;if(n.normalMap){const o=s.userData.waterSpeed||{x:.005,y:.003};n.normalMap.offset.x+=o.x,n.normalMap.offset.y+=o.y}}})}function Jn(){if(!y.container||!y.camera||!y.renderer)return;const r=y.container.clientWidth,e=y.container.clientHeight;r===0||e===0||(y.camera.aspect=r/e,y.camera.updateProjectionMatrix(),y.renderer.setSize(r,e),Rt(r,e))}function Le(r){y.selectedObject!==r&&(y.selectedObject&&y.transformControls.detach(),y.selectedObject=r,y.transformControls.attach(r),y.transformControls.setMode(y.transformControlsMode),y.transformControls.showX=!0,y.transformControls.showY=!0,y.transformControls.showZ=!0,jt(r),console.log("选中",y.selectedObject),se==null||se(r))}let G=null;function kt(r){G=r}function Re(r){G==null||G(r)}function Ht(r){y.transformControlsMode=r,y.transformControls&&y.transformControls.setMode(y.transformControlsMode)}function jt(r){$e(),r.traverse(e=>{if(e.isMesh){const t=e,s=new E.EdgesGeometry(t.geometry),n=new E.LineBasicMaterial({color:zn,depthTest:!0}),o=new E.LineSegments(s,n);e.add(o),Ke.push(o)}})}function $e(){for(const r of Ke)r.parent&&r.parent.remove(r),r.geometry.dispose(),r.material.dispose();Ke=[]}function et(){y.selectedObject&&($e(),y.transformControls.detach(),y.selectedObject=null,se==null||se(null))}function _n(r){let e;if(ge.forEach(t=>{t.userData.id==r&&(e=t),t.children&&t.children.forEach(s=>{s.name&&s.name.startsWith("DataPanel_")&&(s.visible=!1)})}),!e)return $e();e.children.forEach(t=>{t.name&&t.name.startsWith("DataPanel_")&&(t.visible=!0)}),jt(e),tt(e)}function $n(r){if(oe){oe=!1;return}const e=y.renderer.domElement.getBoundingClientRect(),t=new E.Vector2((r.clientX-e.left)/e.width*2-1,-((r.clientY-e.top)/e.height)*2+1),s=new E.Raycaster;s.setFromCamera(t,y.camera);const n=[];y.scene.traverse(i=>{(i.userData.isMovable||i.userData.type==="lightHelper")&&n.push(i)});const o=s.intersectObjects(n);if(o.length>0){let i=es(o[0].object);Le(i)}else et()}function es(r){if(r.type==="Line"){const e=r.parent;switch(e.type){case"DirectionalLightHelper":return e.light;default:return r}}return r}function tt(r,e=500){if(!y.camera||!y.orbitControls)return;let t=null;r.userData.closeUpView&&typeof r.userData.closeUpView.x=="number"&&typeof r.userData.closeUpView.y=="number"&&typeof r.userData.closeUpView.z=="number"&&(t=r.userData.closeUpView);const s=new E.Vector3;r.getWorldPosition(s);const o=new E.Box3().setFromObject(r).getSize(new E.Vector3),i=Math.max(o.x,o.y,o.z)*.5,c=Math.max(i*3.5,5),d=new E.Vector3().copy(y.camera.position).sub(s).normalize();d.lengthSq()<.001&&d.set(0,0,1);const u=s.clone().add(d.multiplyScalar(c)),A=y.camera.position.clone(),h=y.orbitControls.target.clone();new Ue.Tween({x:A.x,y:A.y,z:A.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:s.x,ty:s.y,tz:s.z},e).easing(Ue.Easing.Quadratic.InOut).onUpdate(m=>{y.camera.position.set(m.x,m.y,m.z),y.orbitControls.target.set(m.tx,m.ty,m.tz),y.orbitControls.update()}).start()}function ts(r){r.userData.id&&ge.set(String(r.userData.id),r)}function ns(r){r.userData.id&&ge.delete(String(r.userData.id))}function ss(r){r.traverse(e=>{if(e.name&&e.name.startsWith("DataPanel_")){const t=e;t.element&&t.element.parentNode&&t.element.parentNode.removeChild(t.element)}})}function ie(r,e=!1){y.scene.add(r),r.userData.isMovable&&(os(r),ke()),e&&y.mode==="edit"&&Le(r)}function Vt(r){y.selectedObject===r&&et(),ss(r),ns(r),r.userData.helper&&y.scene.remove(r.userData.helper),r.parent?r.parent.remove(r):y.scene.remove(r),is(r),ke()}function Bt(r){const e=y.scene.getObjectByProperty("uuid",r);e&&Vt(e)}function os(r){r.userData.isMovable&&r.parent===y.scene&&(J.includes(r)||J.push(r))}function is(r){const e=J.indexOf(r);e!==-1&&J.splice(e,1)}function rs(){const r=[];y.scene.children.forEach(e=>{e.userData.isMovable&&r.push(e)}),J=r,ke()}function ke(){Pe==null||Pe([...J])}function Gt(r){se=r}function Wt(r){Ye=r}function Ft(r){Pe=r}function zt(){return J}function qt(){return y.selectedObject}function as(r,e,t){if(!y.scene)return;const s=ge.get(r);if(s){const n=Se(s);n&&n.updateItemByCode(e,t)}}function ls(){return y.scene}function Xt(){return y.camera}function cs(){return y.renderer}async function Ut(){var u,A,h;G==null||G(!0),await new Promise(m=>setTimeout(m,50)),et();const r=y.scene;if(!r)return G==null||G(!1),"{}";const e=[],t=new Map,s=new Map;r.traverse(m=>{var f;if(m.userData.type==="lightHelper"&&e.push(m),m.type==="DirectionalLight"&&m.userData.helper&&(t.set(m,m.userData.helper),m.userData.helper=void 0),m.name&&m.name.startsWith("DataPanel_")){const g=m;if(g.element){const p=g.element.querySelector("[data-panel-title]"),b=[];g.element.querySelectorAll(".css2d-data-panel-item").forEach(x=>{var M,v,T;const w=x.querySelector(".item-label"),C=x.querySelector(".item-value");if(w&&C){const V=(w.textContent||"").trim(),W=((v=(M=C.childNodes[0])==null?void 0:M.textContent)==null?void 0:v.trim())||"",B=C.querySelector("span"),$=B?(B.textContent||"").trim():void 0,He=((T=x.getAttribute("data-item-code"))==null?void 0:T.trim())||void 0;b.push({label:V,value:W,unit:$,code:He})}}),m.parent&&s.set(m.parent.userData.id?m.parent.userData.id:m.parent.uuid,{title:((f=p==null?void 0:p.textContent)==null?void 0:f.trim())||"",items:b})}}}),e.forEach(m=>r.remove(m));const n=r.clone();n.children=n.children.filter(m=>m.userData.type!=="initFloor"),n.traverse(m=>{m.name&&m.name.startsWith("DataPanel_")&&m.parent&&m.parent.remove(m)});const o=n.toJSON();e.forEach(m=>r.add(m)),t.forEach((m,f)=>{f.userData.helper=m});const i={position:(u=y.camera)==null?void 0:u.position.toArray(),rotation:(A=y.camera)==null?void 0:A.rotation.toArray(),target:((h=y.orbitControls)==null?void 0:h.target.toArray())||[0,0,0]},c={};s.forEach((m,f)=>{c[f]=m});const d=JSON.stringify({scene:o,camera:i,dataPanels:c});return G==null||G(!1),d}function Kt(r,e="edit",t){var i,c,d;const s=typeof r=="string"?JSON.parse(r):r,o=new E.ObjectLoader().parse(s);o.type==="Scene"?y.scene=o:(i=y.scene)==null||i.add(o),t&&((c=y.scene)==null||c.traverse(u=>{const A=u.userData.id||u.uuid,h=t[A];if(h&&u.userData.isMovable){ts(u);const m=new _e({title:h.title,items:h.items});m.attachTo(u),m.visible=!1,console.log("panel",m),Dt(u,m)}})),e==="edit"&&((d=y.scene)==null||d.traverse(u=>{var A;if(u.type==="DirectionalLight"){const h=u;if(!h.userData.helper){const m=new E.DirectionalLightHelper(h,1);m.userData.type="lightHelper",h.userData.helper=m,(A=y.scene)==null||A.add(m)}}}))}function Yt(r){if(!r)return;if(r.type==="Mesh"){const t=r;t.geometry&&t.geometry.dispose(),t.material&&(Array.isArray(t.material)?t.material:[t.material]).forEach(n=>{n.map&&(n.map=null),n.lightMap&&(n.lightMap=null),n.aoMap&&(n.aoMap=null),n.emissiveMap&&(n.emissiveMap=null),n.bumpMap&&(n.bumpMap=null),n.normalMap&&(n.normalMap=null),n.displacementMap&&(n.displacementMap=null),n.roughnessMap&&(n.roughnessMap=null),n.metalnessMap&&(n.metalnessMap=null),n.alphaMap&&(n.alphaMap=null),n.envMap&&(n.envMap=null),n.dispose()})}const e=r.children.slice();for(const t of e)Yt(t)}function Zt(){Oe!==null&&(cancelAnimationFrame(Oe),Oe=null),pe&&y.container&&(y.container.removeEventListener("click",pe),pe=null),me&&(window.removeEventListener("resize",me),me=null),y.orbitControls&&(y.orbitControls.dispose(),y.orbitControls=null),y.transformControls&&(y.transformControls.dispose(),y.transformControls=null),y.scene&&(Yt(y.scene),y.scene=null),y.renderer&&(y.renderer.dispose(),y.renderer.domElement&&y.container&&y.container.removeChild(y.renderer.domElement),y.renderer=null),Nt(),y.camera=null,y.gridHelper=null,y.selectedObject=null,y.container=null,y.mode="",J=[],ge.clear(),ke(),Te=!1,oe=!1}const ds=/^[og]\s*(.+)?/,us=/^mtllib /,hs=/^usemtl /,As=/^usemap /,mt=/\s+/,gt=new a.Vector3,We=new a.Vector3,bt=new a.Vector3,It=new a.Vector3,z=new a.Vector3,Ee=new a.Color;function fs(){const r={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 s=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(n,o){const i=this._finalize(!1);i&&(i.inherited||i.groupCount<=0)&&this.materials.splice(i.index,1);const c={index:this.materials.length,name:n||"",mtllib:Array.isArray(o)&&o.length>0?o[o.length-1]:"",smooth:i!==void 0?i.smooth:this.smooth,groupStart:i!==void 0?i.groupEnd:0,groupEnd:-1,groupCount:-1,inherited:!1,clone:function(d){const u={index:typeof d=="number"?d: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(n){const o=this.currentMaterial();if(o&&o.groupEnd===-1&&(o.groupEnd=this.geometry.vertices.length/3,o.groupCount=o.groupEnd-o.groupStart,o.inherited=!1),n&&this.materials.length>1)for(let i=this.materials.length-1;i>=0;i--)this.materials[i].groupCount<=0&&this.materials.splice(i,1);return n&&this.materials.length===0&&this.materials.push({name:"",smooth:this.smooth}),o}},s&&s.name&&typeof s.clone=="function"){const n=s.clone(0);n.inherited=!0,this.object.materials.push(n)}this.objects.push(this.object)},finalize:function(){this.object&&typeof this.object._finalize=="function"&&this.object._finalize(!0)},parseVertexIndex:function(e,t){const s=parseInt(e,10);return(s>=0?s-1:s+t/3)*3},parseNormalIndex:function(e,t){const s=parseInt(e,10);return(s>=0?s-1:s+t/3)*3},parseUVIndex:function(e,t){const s=parseInt(e,10);return(s>=0?s-1:s+t/2)*2},addVertex:function(e,t,s){const n=this.vertices,o=this.object.geometry.vertices;o.push(n[e+0],n[e+1],n[e+2]),o.push(n[t+0],n[t+1],n[t+2]),o.push(n[s+0],n[s+1],n[s+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,s){const n=this.normals,o=this.object.geometry.normals;o.push(n[e+0],n[e+1],n[e+2]),o.push(n[t+0],n[t+1],n[t+2]),o.push(n[s+0],n[s+1],n[s+2])},addFaceNormal:function(e,t,s){const n=this.vertices,o=this.object.geometry.normals;gt.fromArray(n,e),We.fromArray(n,t),bt.fromArray(n,s),z.subVectors(bt,We),It.subVectors(gt,We),z.cross(It),z.normalize(),o.push(z.x,z.y,z.z),o.push(z.x,z.y,z.z),o.push(z.x,z.y,z.z)},addColor:function(e,t,s){const n=this.colors,o=this.object.geometry.colors;n[e]!==void 0&&o.push(n[e+0],n[e+1],n[e+2]),n[t]!==void 0&&o.push(n[t+0],n[t+1],n[t+2]),n[s]!==void 0&&o.push(n[s+0],n[s+1],n[s+2])},addUV:function(e,t,s){const n=this.uvs,o=this.object.geometry.uvs;o.push(n[e+0],n[e+1]),o.push(n[t+0],n[t+1]),o.push(n[s+0],n[s+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,s,n,o,i,c,d,u){const A=this.vertices.length;let h=this.parseVertexIndex(e,A),m=this.parseVertexIndex(t,A),f=this.parseVertexIndex(s,A);if(this.addVertex(h,m,f),this.addColor(h,m,f),c!==void 0&&c!==""){const g=this.normals.length;h=this.parseNormalIndex(c,g),m=this.parseNormalIndex(d,g),f=this.parseNormalIndex(u,g),this.addNormal(h,m,f)}else this.addFaceNormal(h,m,f);if(n!==void 0&&n!==""){const g=this.uvs.length;h=this.parseUVIndex(n,g),m=this.parseUVIndex(o,g),f=this.parseUVIndex(i,g),this.addUV(h,m,f),this.object.geometry.hasUVIndices=!0}else this.addDefaultUV()},addPointGeometry:function(e){this.object.geometry.type="Points";const t=this.vertices.length;for(let s=0,n=e.length;s<n;s++){const o=this.parseVertexIndex(e[s],t);this.addVertexPoint(o),this.addColor(o)}},addLineGeometry:function(e,t){this.object.geometry.type="Line";const s=this.vertices.length,n=this.uvs.length;for(let o=0,i=e.length;o<i;o++)this.addVertexLine(this.parseVertexIndex(e[o],s));for(let o=0,i=t.length;o<i;o++)this.addUVLine(this.parseUVIndex(t[o],n))}};return r.startObject("",!1),r}class ps extends a.Loader{constructor(e){super(e),this.materials=null}load(e,t,s,n){const o=this,i=new a.FileLoader(this.manager);i.setPath(this.path),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(e,function(c){try{t(o.parse(c))}catch(d){n?n(d):console.error(d),o.manager.itemError(e)}},s,n)}setMaterials(e){return this.materials=e,this}parse(e){const t=new fs;e.indexOf(`\r
41
41
  `)!==-1&&(e=e.replace(/\r\n/g,`
42
42
  `)),e.indexOf(`\\
43
43
  `)!==-1&&(e=e.replace(/\\\n/g,""));const s=e.split(`