iflow-engine-base 2.1.2 → 2.1.3
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.
|
@@ -968,7 +968,7 @@
|
|
|
968
968
|
`))&&M<P&&C<k.byteLength;)B+=V,M+=V.length,C+=128,V+=String.fromCharCode.apply(null,new Uint16Array(k.subarray(C,C+128)));return-1<E?(k.pos+=M+E+1,B+V.slice(0,E)):!1},m=function(k){const P=/^#\?(\S+)/,I=/^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,z=/^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,C=/^\s*FORMAT=(\S+)\s*$/,E=/^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,M={valid:0,string:"",comments:"",programtype:"RGBE",format:"",gamma:1,exposure:1,width:0,height:0};let B,V;for((k.pos>=k.byteLength||!(B=d(k)))&&r(1,"no header found"),(V=B.match(P))||r(3,"bad initial token"),M.valid|=1,M.programtype=V[1],M.string+=B+`
|
|
969
969
|
`;B=d(k),B!==!1;){if(M.string+=B+`
|
|
970
970
|
`,B.charAt(0)==="#"){M.comments+=B+`
|
|
971
|
-
`;continue}if((V=B.match(I))&&(M.gamma=parseFloat(V[1])),(V=B.match(z))&&(M.exposure=parseFloat(V[1])),(V=B.match(C))&&(M.valid|=2,M.format=V[1]),(V=B.match(E))&&(M.valid|=4,M.height=parseInt(V[1],10),M.width=parseInt(V[2],10)),M.valid&2&&M.valid&4)break}return M.valid&2||r(3,"missing format specifier"),M.valid&4||r(3,"missing image size specifier"),M},p=function(k,P,I){const z=P;if(z<8||z>32767||k[0]!==2||k[1]!==2||k[2]&128)return new Uint8Array(k);z!==(k[2]<<8|k[3])&&r(3,"wrong scanline width");const C=new Uint8Array(4*P*I);C.length||r(4,"unable to allocate buffer space");let E=0,M=0;const B=4*z,V=new Uint8Array(4),U=new Uint8Array(B);let H=I;for(;H>0&&M<k.byteLength;){M+4>k.byteLength&&r(1),V[0]=k[M++],V[1]=k[M++],V[2]=k[M++],V[3]=k[M++],(V[0]!=2||V[1]!=2||(V[2]<<8|V[3])!=z)&&r(3,"bad rgbe scanline format");let G=0,$;for(;G<B&&M<k.byteLength;){$=k[M++];const N=$>128;if(N&&($-=128),($===0||G+$>B)&&r(3,"bad scanline data"),N){const te=k[M++];for(let ee=0;ee<$;ee++)U[G++]=te}else U.set(k.subarray(M,M+$),G),G+=$,M+=$}const F=z;for(let N=0;N<F;N++){let te=0;C[E]=U[N+te],te+=z,C[E+1]=U[N+te],te+=z,C[E+2]=U[N+te],te+=z,C[E+3]=U[N+te],E+=4}H--}return C},f=function(k,P,I,z){const C=k[P+3],E=Math.pow(2,C-128)/255;I[z+0]=k[P+0]*E,I[z+1]=k[P+1]*E,I[z+2]=k[P+2]*E,I[z+3]=1},u=function(k,P,I,z){const C=k[P+3],E=Math.pow(2,C-128)/255;I[z+0]=_.DataUtils.toHalfFloat(Math.min(k[P+0]*E,65504)),I[z+1]=_.DataUtils.toHalfFloat(Math.min(k[P+1]*E,65504)),I[z+2]=_.DataUtils.toHalfFloat(Math.min(k[P+2]*E,65504)),I[z+3]=_.DataUtils.toHalfFloat(1)},g=new Uint8Array(e);g.pos=0;const y=m(g),w=y.width,x=y.height,v=p(g.subarray(g.pos),w,x);let b,D,T;switch(this.type){case _.FloatType:T=v.length/4;const k=new Float32Array(T*4);for(let I=0;I<T;I++)f(v,I*4,k,I*4);b=k,D=_.FloatType;break;case _.HalfFloatType:T=v.length/4;const P=new Uint16Array(T*4);for(let I=0;I<T;I++)u(v,I*4,P,I*4);b=P,D=_.HalfFloatType;break;default:throw new Error("THREE.HDRLoader: Unsupported type: "+this.type)}return{width:w,height:x,data:b,header:y.string,gamma:y.gamma,exposure:y.exposure,type:D}}setDataType(e){return this.type=e,this}load(e,t,n,i){function s(r,a){switch(r.type){case _.FloatType:case _.HalfFloatType:r.colorSpace=_.LinearSRGBColorSpace,r.minFilter=_.LinearFilter,r.magFilter=_.LinearFilter,r.generateMipmaps=!1,r.flipY=!0;break}t&&t(r,a)}return super.load(e,s,n,i)}}function Jc(){return new S.Scene}function Qc(o,e){o.appendChild(e.domElement)}function eh(o,e,t){var n=new Object;n.visible=!0;let i=null,s,r,a=[];n.init=function(){s||(h(),c(),d())},n.Hide=function(){s.style.display="none",n.visible=!1},n.Show=function(){s.style.display="block",n.visible=!0},n.RenderScene=function(){n.camera.quaternion.copy(e.camera.quaternion);const f=new S.Vector3(0,0,1).applyQuaternion(e.camera.quaternion);n.camera.position.copy(f.multiplyScalar(100)),n.sceneOrtho.renderer.render(n.sceneOrtho,n.camera)},n.ToggleDirectionView=function(f){var u=new S.Vector3(0,0,0);f=="top"?u=new S.Vector3(0,1,1e-5):f=="down"?u=new S.Vector3(0,-1,1e-5):f=="front"?u=new S.Vector3(0,0,1):f=="left"?u=new S.Vector3(-1,0,0):f=="back"?u=new S.Vector3(0,0,-1):f=="right"?u=new S.Vector3(1,0,0):f=="top_front"?u=new S.Vector3(1,1,0):f=="top_left"?u=new S.Vector3(0,1,-1):f=="top_back"?u=new S.Vector3(-1,1,0):f=="top_right"?u=new S.Vector3(0,1,1):f=="down_front"?u=new S.Vector3(1,-1,0):f=="down_left"?u=new S.Vector3(0,-1,-1):f=="down_back"?u=new S.Vector3(-1,-1,0):f=="down_right"?u=new S.Vector3(0,-1,1):f=="front_right"?u=new S.Vector3(1,0,1):f=="right_back"?u=new S.Vector3(-1,0,1):f=="back_left"?u=new S.Vector3(-1,0,-1):f=="left_front"?u=new S.Vector3(1,0,-1):f=="top_left_front"?u=new S.Vector3(1,1,-1):f=="top_front_right"?u=new S.Vector3(1,1,1):f=="top_right_back"?u=new S.Vector3(-1,1,1):f=="top_back_left"?u=new S.Vector3(-1,1,-1):f=="button_left_front"?u=new S.Vector3(1,-1,-1):f=="button_front_right"?u=new S.Vector3(1,-1,1):f=="button_right_back"?u=new S.Vector3(-1,1,1):f=="button_back_left"&&(u=new S.Vector3(-1,-1,-1));var g=o.octreeBox.getBoundingBox(),y=g.min,w=g.max,x=y.clone().add(w.clone()).multiplyScalar(.5),v=x.clone().add(u.multiplyScalar(1*w.distanceTo(y)));l(e.camera.position,v,o.controls.target.clone(),x)},n.GetCameraPose=function(){var f=e.camera.quaternion,u=e.camera.position,g=o.controls.target,y={quaternion:f,position:u,target:g};return y},n.ReductionCameraPose=function(f,u=1e3,g){var y=new S.Quaternion(f.quaternion._x,f.quaternion._y,f.quaternion._z,f.quaternion._w),w=new S.Vector3(f.position.x,f.position.y,f.position.z),x=new S.Vector3(f.target.x,f.target.y,f.target.z);let v=!1;l(e.camera.position,w,o.controls.target.clone(),x,e.camera.quaternion,y,u,b=>{g&&(v||(g(b),v=!0))}),g&&setTimeout(()=>{v||(g(!0),v=!0)},u+10)},n.CameraGoHome=function(){var f=o.octreeBox.getBoundingBox(),u=f.min.clone().add(f.max.clone()).multiplyScalar(.5);let g=new S.Vector3(1,1,1);var y=f.max.distanceTo(f.min),w=u.clone().add(g.multiplyScalar(y*.5));if(e.camera.isOrthographicCamera){var x=o.container.clientWidth/o.container.clientHeight,v=y*.6;e.camera.left=-v*x,e.camera.right=v*x,e.camera.top=v,e.camera.bottom=-v,e.camera.zoom=1,e.camera.updateProjectionMatrix()}o.controlModule.orbitControls.origin=u.clone(),l(e.camera.position,w,o.controls.target.clone(),u)},n.zoomToBox=function(f){if(e.camera.isOrthographicCamera){let N=function(){i=requestAnimationFrame(N),F.update()};var u=f.min.clone().add(f.max.clone()).multiplyScalar(.5),g=e.camera.position.clone().sub(o.controls.target.clone()).normalize(),y=e.camera.position.distanceTo(o.controls.target),w=u.clone().add(g.multiplyScalar(y)),x=e.camera.zoom,v=new S.Vector3(1,0,0).applyQuaternion(e.camera.quaternion),b=new S.Vector3(0,1,0).applyQuaternion(e.camera.quaternion),D=[new S.Vector3(f.min.x,f.min.y,f.min.z),new S.Vector3(f.max.x,f.min.y,f.min.z),new S.Vector3(f.min.x,f.max.y,f.min.z),new S.Vector3(f.max.x,f.max.y,f.min.z),new S.Vector3(f.min.x,f.min.y,f.max.z),new S.Vector3(f.max.x,f.min.y,f.max.z),new S.Vector3(f.min.x,f.max.y,f.max.z),new S.Vector3(f.max.x,f.max.y,f.max.z)],T=1/0,k=-1/0,P=1/0,I=-1/0;for(var z of D){var C=z.dot(v),E=z.dot(b);T=Math.min(T,C),k=Math.max(k,C),P=Math.min(P,E),I=Math.max(I,E)}var M=(k-T)/2,B=(I-P)/2,V=(e.camera.right-e.camera.left)/2,U=(e.camera.top-e.camera.bottom)/2;x=Math.min(V/M,U/B)*.75;var H=e.camera.position.clone(),G=o.controls.target.clone(),$=e.camera.zoom,F=new hn.Tween({x1:H.x,y1:H.y,z1:H.z,x2:G.x,y2:G.y,z2:G.z,zoom:$}).to({x1:w.x,y1:w.y,z1:w.z,x2:u.x,y2:u.y,z2:u.z,zoom:x},1e3);F.onUpdate(function(te){o.controls&&(e.camera.position.set(te.x1,te.y1,te.z1),o.controls.target.set(te.x2,te.y2,te.z2),e.camera.isOrthographicCamera&&(e.camera.zoom=te.zoom,e.camera.updateProjectionMatrix()),o.controls.auto=!0,o.controls.update(),n.RenderScene())}),F.onComplete(function(){o.controls&&(o.controls.auto=!1,n.RenderScene(),cancelAnimationFrame(i),i=null)}),F.easing(hn.Easing.Cubic.InOut),F.start(),N()}else{var u=f.min.clone().add(f.max.clone()).multiplyScalar(.5);let ee=e.camera.position.clone().sub(o.controls.target.clone()).normalize();var w=u.clone().add(ee.multiplyScalar(2*f.max.distanceTo(f.min)));l(e.camera.position,w,o.controls.target.clone(),u)}};function l(f,u,g,y,w,x,v=1e3,b){var D;w&&x?(D=new hn.Tween({x1:f.x,y1:f.y,z1:f.z,x2:g.x,y2:g.y,z2:g.z,_x:w._x,_y:w._y,_z:w._z,_w:w._w}),D.to({x1:u.x,y1:u.y,z1:u.z,x2:y.x,y2:y.y,z2:y.z,_x:x._x,_y:x._y,_z:x._z,_w:x._w},v)):(D=new hn.Tween({x1:f.x,y1:f.y,z1:f.z,x2:g.x,y2:g.y,z2:g.z}),D.to({x1:u.x,y1:u.y,z1:u.z,x2:y.x,y2:y.y,z2:y.z},v)),D.onUpdate(function(k){o.controls&&(w&&x?(e.camera.quaternion._x=k._x,e.camera.quaternion._y=k._y,e.camera.quaternion._z=k._z,e.camera.quaternion._w=k._w):o.controls.auto=!0,e.camera.position.x=k.x1,e.camera.position.y=k.y1,e.camera.position.z=k.z1,o.controls.target.x=k.x2,o.controls.target.y=k.y2,o.controls.target.z=k.z2,o.controls.update(),n.RenderScene())}),D.onComplete(function(k){o.controls&&(o.controls.auto=!1,n.RenderScene(),b&&b(!0),cancelAnimationFrame(i),i=null)}),D.easing(hn.Easing.Cubic.InOut);function T(k){i=requestAnimationFrame(T),D.update()}D.start(),T()}function h(){s=document.createElement("div"),s.className="ViewCube",t.appendChild(s),r=document.createElement("div"),r.className="viewSettingWrapper",r.innerHTML="...",s.appendChild(r);var f=document.createElement("div");f.className="homeViewWrapper",f.addEventListener("mousedown",function(){console.log("归位"),n.CameraGoHome()}),s.appendChild(f);const u=document.createElement("div");u.className="cameraToggleWrapper",u.title="切换正交/透视视图",u.innerHTML="⊞",u.addEventListener("mousedown",function(v){v.stopPropagation(),console.log("切换视图"),n.ToggleCameraType(),w()}),s.appendChild(u);const g=document.createElement("div");g.className="screenshotWrapper",g.title="截图",g.innerHTML="📷",g.addEventListener("mousedown",function(v){v.stopPropagation(),console.log("截图"),n.TakeScreenshot(),w()}),s.appendChild(g);const y=document.createElement("div");y.className="fullscreenWrapper",y.title="全屏",y.innerHTML="⛶",y.addEventListener("mousedown",function(v){v.stopPropagation(),console.log("全屏"),n.ToggleFullscreen(),w()}),s.appendChild(y),r.addEventListener("mousedown",function(v){v.stopPropagation(),u.classList.contains("show")?(w(),console.log("隐藏功能按钮")):(x(),console.log("显示功能按钮"))});function w(){u.classList.remove("show"),g.classList.remove("show"),y.classList.remove("show")}function x(){u.classList.add("show"),g.classList.add("show"),y.classList.add("show")}}function c(){n.sceneOrtho=Jc();var g=t.clientWidth,y=t.clientWidth,f=g>y?g/y:y/g,u=300;n.camera=new S.OrthographicCamera(u*f/-2,u*f/2,u/2,u/-2,.01,1e4);var g=s.clientWidth,y=s.clientHeight,w=new S.WebGLRenderer({alpha:!0});w.setSize(g,y),w.setClearAlpha(0),n.sceneOrtho.renderer=w;let x=new S.AmbientLight(16777215,.8);n.sceneOrtho.add(x),Qc(s,w)}function d(){const f="/assets/viewcube/";let u=[{label:"右",icon:f+"cn_right.png"},{label:"左",icon:f+"cn_left.png"},{label:"顶",icon:f+"cn_top.png"},{label:"底",icon:f+"cn_bottom.png"},{label:"前",icon:f+"cn_front.png"},{label:"后",icon:f+"cn_back.png"}];var g=[];for(const w of u)g.push(new S.MeshBasicMaterial({color:16777215,map:new S.TextureLoader().load(w.icon)}));new S.MeshLambertMaterial({color:255});var y=new S.Mesh(new S.BoxGeometry(110,110,110),g);n.sceneOrtho.add(y),m(122),s.addEventListener("mousedown",w=>{var x={};x.x=w.offsetX/s.clientWidth*2-1,x.y=-(w.offsetY/s.clientHeight)*2+1;var v=new S.Raycaster;v.setFromCamera(x,n.camera);const b=v.intersectObjects(a,!1);b.length>0&&n.ToggleDirectionView(b[0].object.name)}),s.addEventListener("mousemove",w=>{var x={};x.x=w.offsetX/s.clientWidth*2-1,x.y=-(w.offsetY/s.clientHeight)*2+1;var v=new S.Raycaster;v.setFromCamera(x,n.camera);const b=v.intersectObjects(a,!1);for(var D of a)D.material.opacity=.01;b.length>0&&(b[0].object.material.opacity=.2)})}function m(f){for(var u=f*.5-20,g=[{name:"right",a:30,b:75,c:75,point:new S.Vector3(u,0,0)},{name:"back",a:75,b:75,c:30,point:new S.Vector3(0,0,-u)},{name:"left",a:30,b:75,c:75,point:new S.Vector3(-u,0,0)},{name:"front",a:75,b:75,c:30,point:new S.Vector3(0,0,u)},{name:"top",a:75,b:30,c:75,point:new S.Vector3(0,u,0)},{name:"button",a:75,b:30,c:75,point:new S.Vector3(0,-u,0)}],y=[{name:"top_right_back",a:30,b:30,c:30,point:new S.Vector3(-u,u,u)},{name:"button_front_right",a:30,b:30,c:30,point:new S.Vector3(-u,-u,u)},{name:"top_front_right",a:30,b:30,c:30,point:new S.Vector3(u,u,u)},{name:"button_right_back",a:30,b:30,c:30,point:new S.Vector3(u,-u,u)},{name:"top_back_left",a:30,b:30,c:30,point:new S.Vector3(-u,u,-u)},{name:"button_back_left",a:30,b:30,c:30,point:new S.Vector3(-u,-u,-u)},{name:"top_left_front",a:30,b:30,c:30,point:new S.Vector3(u,u,-u)},{name:"button_left_front",a:30,b:30,c:30,point:new S.Vector3(u,-u,-u)}],w=[{name:"top_front",a:30,b:30,c:75,point:new S.Vector3(u,u,0)},{name:"top_right",a:75,b:30,c:30,point:new S.Vector3(0,u,u)},{name:"top_back",a:30,b:30,c:75,point:new S.Vector3(-u,u,0)},{name:"top_left",a:75,b:30,c:30,point:new S.Vector3(0,u,-u)},{name:"button_front",a:30,b:30,c:75,point:new S.Vector3(u,-u,0)},{name:"button_right",a:75,b:30,c:30,point:new S.Vector3(0,-u,u)},{name:"button_back",a:30,b:30,c:75,point:new S.Vector3(-u,-u,0)},{name:"button_left",a:75,b:30,c:30,point:new S.Vector3(0,-u,-u)},{name:"front_right",a:30,b:75,c:30,point:new S.Vector3(u,0,u)},{name:"right_back",a:30,b:75,c:30,point:new S.Vector3(-u,0,u)},{name:"back_left",a:30,b:75,c:30,point:new S.Vector3(-u,0,-u)},{name:"left_front",a:30,b:75,c:30,point:new S.Vector3(u,0,-u)}],x=0;x<g.length;x++)a.push(p(g[x]));for(var x=0;x<y.length;x++)a.push(p(y[x]));for(var x=0;x<w.length;x++)a.push(p(w[x]))}function p(f){const u=new S.BoxGeometry(f.a,f.b,f.c),g=new S.MeshBasicMaterial({color:"blue",transparent:!0,opacity:.01}),y=new S.Matrix4().makeTranslation(f.point.x,f.point.y,f.point.z);let w=u.applyMatrix4(y),x=new S.Mesh(w,g);return x.name=f.name,n.sceneOrtho.add(x),x}return n.ToggleCameraType=function(){o.cameraModule.switchCurrentCamera()},n.TakeScreenshot=function(){try{if(!o.renderer){console.error("渲染器未初始化");return}o.renderer.render(e,e.camera);const u=o.renderer.domElement.toDataURL("image/png"),g=document.createElement("a"),y=new Date().toISOString().replaceAll(/[:.]/g,"-");g.download=`screenshot_${y}.png`,g.href=u,g.click(),console.log("截图已保存")}catch(f){console.error("截图失败:",f)}},n.ToggleFullscreen=function(){const f=t||document.documentElement;!document.fullscreenElement&&!document.webkitFullscreenElement&&!document.mozFullScreenElement&&!document.msFullscreenElement?(f.requestFullscreen?f.requestFullscreen():f.webkitRequestFullscreen?f.webkitRequestFullscreen():f.mozRequestFullScreen?f.mozRequestFullScreen():f.msRequestFullscreen&&f.msRequestFullscreen(),console.log("已进入全屏模式")):(document.exitFullscreen?document.exitFullscreen():document.webkitExitFullscreen?document.webkitExitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.msExitFullscreen&&document.msExitFullscreen(),console.log("已退出全屏模式"))},n}class th{engine;cubeTool;constructor(e){this.engine=e}init(){this.cubeTool=eh(this.engine,this.engine.scene,this.engine.container),this.cubeTool.init()}CameraGoHome(){this.cubeTool.CameraGoHome()}zoomToModel(e){this.cubeTool.zoomToBox(e)}hide(){}}function nh(o){let e=new Object;return e.getBoundingBox=function(){let t=o.models,n=new S.Vector3(1e8,1e9,1e10),i=new S.Vector3(-1e8,-1e9,-1e10);t.forEach(d=>{let m=d.boundingBox.min,p=d.boundingBox.max;m.x<n.x&&(n.x=m.x),m.y<n.y&&(n.y=m.y),m.z<n.z&&(n.z=m.z),p.x>i.x&&(i.x=p.x),p.y>i.y&&(i.y=p.y),p.z>i.z&&(i.z=p.z)});let s=Math.min(n.x,i.x),r=Math.min(n.y,i.y),a=Math.min(n.z,i.z),l=Math.max(n.x,i.x),h=Math.max(n.y,i.y),c=Math.max(n.z,i.z);return{min:new S.Vector3(s,r,a),max:new S.Vector3(l,h,c)}},e.rayInterationModel=function(t){let n=[];return o.engineStatus.models.forEach(r=>{r.info.lods.forEach(a=>{let l=a.octreeBox;s(t,l,r)})}),n=n.filter(r=>r instanceof S.Mesh),t.intersectObjects(n,!1);function s(r,a,l){if(a==null)return;let h=new S.Vector3(a.min.X*.3048,a.min.Z*.3048,-a.min.Y*.3048),c=new S.Vector3(a.max.X*.3048,a.max.Z*.3048,-a.max.Y*.3048),d=new S.Vector3(Math.min(h.x,c.X),Math.min(h.y,c.y),Math.min(h.z,c.z)),m=new S.Vector3(Math.max(c.x,h.x),Math.max(c.y,h.y),Math.max(c.z,h.z)),p=new S.Box3(d,m),f=r.ray.intersectsBox(p);if(!(f==null||f==!1))if(a.children==null||a.children.length==0){if(a.elements!=null)for(var u of a.elements){let g=o.engineStatus.hideModels.find(v=>v.url==l.url)?.ids;if(g!=null&&g.includes(u))continue;let y=o.engineStatus.translucentModels.find(v=>v.url==l.url)?.ids;if(y!=null&&y.includes(u))continue;let x=o.models.find(v=>v.url==l.url).nodesMap.get(u);x!=null&&!x.instance&&x.infos.map(b=>b.mesh).forEach(b=>{n.push(b)})}}else{if(a.elements!=null)for(var u of a.elements){let y=o.engineStatus.hideModels.find(b=>b.url==l.url)?.ids;if(y!=null&&y.includes(u))continue;let w=o.engineStatus.translucentModels.find(b=>b.url==l.url)?.ids;if(w!=null&&w.includes(u))continue;let v=o.models.find(b=>b.url==l.url).nodesMap.get(u);v!=null&&!v.instance&&v.infos.map(D=>D.mesh).forEach(D=>{n.push(D)})}for(let g of a.children)s(r,g,l)}}},e}class ih{engine;isDrawing=!1;startPoint=new S.Vector2;endPoint=new S.Vector2;selectionBox=null;worldToScreen=null;boundMouseDown;boundMouseMove;boundMouseUp;boundKeyDown;constructor(e){this.engine=e,this.boundMouseDown=this.onMouseDown.bind(this),this.boundMouseMove=this.onMouseMove.bind(this),this.boundMouseUp=this.onMouseUp.bind(this),this.boundKeyDown=this.onKeyDown.bind(this)}init(){this.createSelectionBoxElement(),this.engine.scene&&this.engine.camera&&this.engine.renderer&&(this.worldToScreen=new ze(this.engine.camera,this.engine.renderer,this.engine.scene))}active(){this.engine.controlModule.disActive();const e=this.engine.renderer?.domElement;e&&(e.addEventListener("mousedown",this.boundMouseDown),e.addEventListener("mousemove",this.boundMouseMove),e.addEventListener("mouseup",this.boundMouseUp),e.style.cursor="crosshair"),window.addEventListener("keydown",this.boundKeyDown)}disActive(){this.engine.controlModule.active();const e=this.engine.renderer?.domElement;e&&(e.removeEventListener("mousedown",this.boundMouseDown),e.removeEventListener("mousemove",this.boundMouseMove),e.removeEventListener("mouseup",this.boundMouseUp),e.style.cursor="default"),window.removeEventListener("keydown",this.boundKeyDown),this.isDrawing&&this.endDrawing()}createSelectionBoxElement(){this.selectionBox=document.createElement("div"),this.selectionBox.style.position="absolute",this.selectionBox.style.border="2px dashed #00aaff",this.selectionBox.style.backgroundColor="rgba(0, 170, 255, 0.1)",this.selectionBox.style.pointerEvents="none",this.selectionBox.style.display="none",this.selectionBox.style.zIndex="1000",this.selectionBox.style.boxSizing="border-box";const e=this.engine.renderer?.domElement;e&&e.parentElement&&e.parentElement.appendChild(this.selectionBox)}onMouseDown(e){e.button!==0||!this.engine.renderer?.domElement||(this.startPoint.set(e.offsetX,e.offsetY),this.endPoint.copy(this.startPoint),this.isDrawing=!0,this.selectionBox&&(this.selectionBox.style.display="block",this.updateSelectionBoxUI()),e.preventDefault(),e.stopPropagation())}onMouseMove(e){!this.isDrawing||!this.engine.renderer?.domElement||(this.endPoint.set(e.offsetX,e.offsetY),this.updateSelectionBoxUI(),e.preventDefault(),e.stopPropagation())}onMouseUp(e){this.isDrawing&&(this.endDrawing(),this.performZoom(),e.preventDefault(),e.stopPropagation(),this.disActive())}onKeyDown(e){e.key==="Escape"&&(this.disActive(),e.preventDefault(),e.stopPropagation())}endDrawing(){this.isDrawing&&(this.isDrawing=!1,this.selectionBox&&(this.selectionBox.style.display="none"))}updateSelectionBoxUI(){if(!this.selectionBox||!this.engine.renderer?.domElement)return;const t=Math.min(this.startPoint.x,this.endPoint.x),n=Math.min(this.startPoint.y,this.endPoint.y),i=Math.abs(this.endPoint.x-this.startPoint.x),s=Math.abs(this.endPoint.y-this.startPoint.y);this.selectionBox.style.left=`${t}px`,this.selectionBox.style.top=`${n}px`,this.selectionBox.style.width=`${i}px`,this.selectionBox.style.height=`${s}px`}performZoom(){const e=Math.abs(this.endPoint.x-this.startPoint.x),t=Math.abs(this.endPoint.y-this.startPoint.y);if(e<5||t<5)return;if(!this.worldToScreen){console.warn("RangeScale: 坐标转换工具未初始化");return}const n=Math.min(this.startPoint.x,this.endPoint.x),i=Math.max(this.startPoint.x,this.endPoint.x),s=Math.min(this.startPoint.y,this.endPoint.y),r=Math.max(this.startPoint.y,this.endPoint.y),a=[],l=[{x:n,y:s},{x:i,y:s},{x:i,y:r},{x:n,y:r}];for(const c of l){const d=this.worldToScreen.screenToWorld(c.x,c.y);d&&a.push(d)}if(a.length<3){console.warn("RangeScale: 框选区域未命中模型,无法执行缩放操作");return}if(a.length<3){console.warn("RangeScale: 无法将屏幕区域转换为世界坐标");return}const h=new S.Box3;for(const c of a)h.expandByPoint(c);if(h.isEmpty()){console.warn("RangeScale: 计算得到的包围盒无效");return}this.fitCameraToBoundingBox(h)}fitCameraToBoundingBox(e){const t=this.engine.camera,n=this.engine.controls;if(!t||!n){console.warn("RangeScale: 相机或控制器未初始化");return}const i=new S.Vector3;e.getCenter(i);const s=new S.Vector3;e.getSize(s);const r=Math.max(s.x,s.y,s.z);if(t instanceof S.PerspectiveCamera){const a=t.fov*(Math.PI/180),h=r/(2*Math.tan(a/2))*1.2,c=new S.Vector3;t.getWorldDirection(c);const d=i.clone().sub(t.position);c.dot(d.normalize())<0&&c.negate();const p=i.clone().sub(c.multiplyScalar(h));t.position.copy(p),n.target&&n.target.copy(i),t.lookAt(i),n.update()}else if(t instanceof S.OrthographicCamera){const l=r*1.2,h=this.engine.renderer?.domElement,c=h?h.width/h.height:1;t.left=-l*c/2,t.right=l*c/2,t.top=l/2,t.bottom=-l/2,t.updateProjectionMatrix();const d=new S.Vector3;t.getWorldDirection(d);const m=r*1.5,p=i.clone().sub(d.multiplyScalar(m));t.position.copy(p),n.target&&n.target.copy(i),t.lookAt(i),n.update()}}}class sh{engine;ground=null;constructor(e){this.engine=e}init(){}setStatsVisible(e){this.engine.stats?.dom&&(this.engine.stats.dom.style.display=e?"block":"none")}setAmbientLightIntensity(e){const t=this.engine.scene.children.find(n=>n instanceof S.AmbientLight);t&&(t.intensity=e)}setAmbientLightColor(e){const t=this.engine.scene.children.find(n=>n instanceof S.AmbientLight);t&&t.color.set(e)}setDirectionalLightIntensity(e){const t=this.engine.scene.children.find(n=>n instanceof S.DirectionalLight);t&&(t.intensity=e)}setDirectionalLightColor(e){const t=this.engine.scene.children.find(n=>n instanceof S.DirectionalLight);t&&t.color.set(e)}setShadowQuality(e){const t=this.engine.scene.children.find(n=>n instanceof S.DirectionalLight);if(t?.shadow){const i={low:1024,medium:2048,high:4096,ultra:8192}[e];t.shadow.mapSize.width=i,t.shadow.mapSize.height=i,t.shadow.map?.dispose(),t.shadow.map=null}}setDirectionalLightShadow(e){const t=this.engine.scene.children.find(n=>n instanceof S.DirectionalLight);t&&(t.castShadow=e),this.engine.renderer&&(this.engine.renderer.shadowMap.enabled=e)}setGTAOEnabled(e){if(!this.engine.composerModule?.composer){console.warn("Composer not initialized");return}const t=this.engine.composerModule.composer,n=t.passes.find(i=>i instanceof Ne);if(e)if(n)n.enabled=!0;else{const{width:i,height:s}=this.engine.deviceModule.getContainerSize(),r=new Ne(this.engine.scene,this.engine.camera,i,s);r.output=Ne.OUTPUT.Default,r.blendIntensity=.5,r.updateGtaoMaterial&&r.updateGtaoMaterial({radius:1,distanceExponent:1,thickness:1,scale:1,distanceFallOff:1,screenSpaceRadius:!0});const a=t.passes.findIndex(l=>l.constructor.name==="RenderPass");t.passes.splice(a+1,0,r)}else n&&(n.enabled=!1)}setSceneSaturation(e){if(!this.engine.composerModule?.saturationPass){console.warn("Saturation pass not initialized");return}this.engine.composerModule.saturationPass.uniforms.saturation.value=e}setSceneContrast(e){if(!this.engine.composerModule?.saturationPass){console.warn("Saturation pass not initialized");return}this.engine.composerModule.saturationPass.uniforms.contrast.value=e}setGroundEnabled(e,t){if(e)if(this.ground)this.ground.visible=!0;else{const n=t?.size??100,i=t?.color??8421504,s=t?.opacity??.3,r=new S.PlaneGeometry(n,n),a=new S.MeshStandardMaterial({color:i,transparent:!0,opacity:s,side:S.DoubleSide});this.ground=new S.Mesh(r,a),this.ground.rotation.x=-Math.PI/2,this.ground.position.y=0,this.ground.receiveShadow=!0,this.ground.name="ground",this.engine.scene.add(this.ground)}else this.ground&&(this.ground.visible=!1)}setHDRBackground(e){e?(this.engine.scene.background=e,this.engine.scene.environment=e):(this.engine.scene.background=null,this.engine.scene.environment=null)}}function it(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(o){var e=Math.random()*16|0,t=o=="x"?e:e&3|8;return t.toString(16)})}class st{engine;handelBehaved;setting;constructor(e){this.engine=e,this.handelBehaved=Ci(e),this.handelBehaved.init(this,null),this.setting={unit:"m",precision:3}}getSetting(){return this.setting}saveSetting(e){this.setting=e}active(){this.handelBehaved.active()}disActive(){this.handelBehaved.disActive()}getMeasureText(e,t){if(e==null)return null;let n=this.setting.unit,i=n;return t==1?n=="mm"?e=e*1e3:n=="cm"?e=e*100:n=="dm"?e=e*10:n=="m"?e=e*1:n=="km"&&(e=e*.001):t==2&&(n=="mm"?e=e*1e3*1e3:n=="cm"?e=e*100*100:n=="dm"?e=e*10*10:n=="m"?e=e*1*1:n=="km"&&(e=e*.001*.001),i=i+"²"),e.toFixed(this.setting.precision)+" "+i}cancelCurrentSelectedAnnotation(){let e=this.engine.measure.annotationData;for(let t in e)e[t].forEach(n=>{n.highlight==!0&&(n.highlight=!1,n.container.classList.remove("Hight"),n.container.getElementsByTagName("svg")[0].classList.remove("Hight"))})}handelKeyEscDown(){this.cancelCurrentSelectedAnnotation();let e=this.engine.measure.annotationData;for(let t in e)for(let n=e[t].length-1;n>=0;n--){let i=e[t][n];i.isSelect==!0&&(i.container.remove(),e[t].splice(n,1))}this.engine.measure.clearAllPoints()}handelKeyDeleteDown(){let e=this.engine.measure.annotationData;for(let t in e)for(let n=e[t].length-1;n>=0;n--){let i=e[t][n];i.highlight==!0&&(i.container.remove(),e[t].splice(n,1))}}clearHighlight(){let e=this.engine.measure.annotationData;for(let t in e)e[t].forEach(n=>{n.highlight=!1,n.container.classList.remove("Hight"),n.container.getElementsByTagName("svg")[0].classList.remove("Hight")})}drawNormalAnnotation(){let e=this;this.engine.measure.annotationData.normalAnnotation.forEach(f=>{p(f)}),this.engine.measure.annotationData.elevationAnnotation.forEach(f=>{m(f)}),this.engine.measure.annotationData.coordinateAnnotation.forEach(f=>{d(f)}),this.engine.measure.annotationData.angleAnnotation.forEach(f=>{l(f)}),this.engine.measure.annotationData.areaAnnotation.forEach(f=>{h(f)}),this.engine.measure.annotationData.slopeAnnotation.forEach(f=>{c(f)});function l(f){if(f.container==null){let T=['<svg class="measureSvg">','<circle cx="50" cy="50" r="5" fill="#f99d0b" />','<circle cx="50" cy="50" r="5" fill="#f99d0b" />','<circle cx="50" cy="50" r="5" fill="#f99d0b" />','<polyline stroke="orange" stroke-width="2" points="0,0 0,0" style="fill: none; opacity: 1;"/>','<polyline stroke="orange" stroke-width="2" points="0,0 0,0" style="fill: none; opacity: 1;"/>','<rect x="0" y="0" width="80" height="25" class="measureBack" />','<text x="40" y="16" text-anchor="middle" class="measureLabel">'+f.text+"</text>","</svg>"].join("");f.container=document.createElement("div"),f.container.className="angle-annotation",f.container.id=f.id,f.container.style.pointerEvents="none",f.container.innerHTML=T,e.engine.measure.annotationContainer.appendChild(f.container),f.container.getElementsByTagName("svg")[0].addEventListener("click",function(){e.clearHighlight(),f.container.getElementsByTagName("svg")[0].classList.add("Hight"),f.highlight=!0,e.engine.events.trigger(_e.MeasureClick,f)})}let u=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point1),g=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point2),y=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point3),w=e.engine.reactBoundingClientRect.left,x=e.engine.reactBoundingClientRect.top;u.x+=w,u.y+=x,g.x+=w,g.y+=x,y.x+=w,y.y+=x;let v=f.container;v.getElementsByTagName("circle")[0].setAttribute("cx",u.x),v.getElementsByTagName("circle")[0].setAttribute("cy",u.y),v.getElementsByTagName("circle")[1].setAttribute("cx",g.x),v.getElementsByTagName("circle")[1].setAttribute("cy",g.y),v.getElementsByTagName("circle")[2].setAttribute("cx",y.x),v.getElementsByTagName("circle")[2].setAttribute("cy",y.y),v.getElementsByTagName("polyline")[0].setAttribute("points",u.x+","+u.y+" "+g.x+","+g.y),v.getElementsByTagName("polyline")[1].setAttribute("points",g.x+","+g.y+" "+y.x+","+y.y);let b=g.x,D=g.y-30;v.getElementsByTagName("rect")[0].setAttribute("x",b-40),v.getElementsByTagName("rect")[0].setAttribute("y",D-12.5),v.getElementsByTagName("text")[0].setAttribute("x",b),v.getElementsByTagName("text")[0].setAttribute("y",D+4),v.getElementsByTagName("text")[0].innerHTML=f.text,v.style.top="0px",v.style.left="0px"}function h(f){if(f.container==null){let k=['<svg class="measureSvg">','<polygon fill="rgba(255, 165, 0, 0.3)" stroke="orange" stroke-width="2" points="" style="opacity: 0.3;"/>','<polyline stroke="orange" stroke-width="2" points="" style="fill: none; opacity: 1;"/>','<rect x="0" y="0" width="80" height="25" class="measureBack" />','<text x="40" y="16" text-anchor="middle" class="measureLabel">'+e.getMeasureText(f.text,2)+"</text>","</svg>"].join("");f.container=document.createElement("div"),f.container.className="area-annotation",f.container.id=f.id,f.container.innerHTML=k,e.engine.measure.annotationContainer.appendChild(f.container),f.container.getElementsByTagName("svg")[0].addEventListener("click",function(){e.clearHighlight(),f.container.getElementsByTagName("svg")[0].classList.add("Hight"),f.highlight=!0,e.engine.events.trigger(_e.MeasureClick,f)})}if(!f.points||f.points.length<3)return;let u=e.engine.reactBoundingClientRect.left,g=e.engine.reactBoundingClientRect.top,y=[],w=0,x=0;for(let k=0;k<f.points.length;k++){let P=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.points[k]);P.x+=u,P.y+=g,y.push(P),w+=P.x,x+=P.y}w=w/y.length,x=x/y.length;let v=y.map(k=>k.x+","+k.y).join(" "),b=f.container;b.getElementsByTagName("polygon")[0].setAttribute("points",v),b.getElementsByTagName("polyline")[0].setAttribute("points",v);let D=w,T=x;b.getElementsByTagName("rect")[0].setAttribute("x",D-40),b.getElementsByTagName("rect")[0].setAttribute("y",T-12.5),b.getElementsByTagName("text")[0].setAttribute("x",D),b.getElementsByTagName("text")[0].setAttribute("y",T+4),b.getElementsByTagName("text")[0].innerHTML=e.getMeasureText(f.text,2),b.style.top="0px",b.style.left="0px"}function c(f){if(f.container==null){let D=['<svg class="measureSvg">',"<defs>",'<marker id="slope-arrow-'+f.id+'" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto" markerUnits="strokeWidth">','<path d="M0,0 L0,6 L9,3 z" fill="orange" stroke="orange" />',"</marker>","</defs>",'<polyline stroke="orange" stroke-width="2" points="0,0 0,0" marker-end="url(#slope-arrow-'+f.id+')" style="fill: none; opacity: 1;"/>','<rect x="0" y="0" width="100" height="25" class="measureBack" />','<text x="50" y="16" text-anchor="middle" class="measureLabel">'+f.text+"</text>","</svg>"].join("");f.container=document.createElement("div"),f.container.className="slope-annotation",f.container.id=f.id,f.container.innerHTML=D,e.engine.measure.annotationContainer.appendChild(f.container),f.container.getElementsByTagName("svg")[0].addEventListener("click",function(){e.clearHighlight(),f.container.getElementsByTagName("svg")[0].classList.add("Hight"),f.highlight=!0,e.engine.events.trigger(_e.MeasureClick,f)})}let u=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point1),g=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point2),y=e.engine.reactBoundingClientRect.left,w=e.engine.reactBoundingClientRect.top;u.x+=y,u.y+=w,g.x+=y,g.y+=w;let x=f.container;x.getElementsByTagName("polyline")[0].setAttribute("points",u.x+","+u.y+" "+g.x+","+g.y);let v=(u.x+g.x)/2,b=(u.y+g.y)/2-30;x.getElementsByTagName("rect")[0].setAttribute("x",v-50),x.getElementsByTagName("rect")[0].setAttribute("y",b-12.5),x.getElementsByTagName("text")[0].setAttribute("x",v),x.getElementsByTagName("text")[0].setAttribute("y",b+4),x.getElementsByTagName("text")[0].innerHTML=f.text,x.style.top="0px",x.style.left="0px"}function d(f){if(f.container==null){let T=['<svg class="measureSvg">','<circle cx="0" cy="0" r="5" fill="#f99d0b" />','<rect x="0" y="-25" width="100" height="25" class="measureBack" />','<text x="40" y="-11" text-anchor="middle" class="measureLabel">X: '+e.getMeasureText(f.textX,1)+"</text>",'<rect x="0" y="-10" width="100" height="25" class="measureBack" />','<text x="40" y="25" text-anchor="middle" class="measureLabel">Y: '+e.getMeasureText(-f.textZ,1)+"</text>",'<rect x="0" y="10" width="100" height="25" class="measureBack" />','<text x="40" y="51" text-anchor="middle" class="measureLabel">Z: '+e.getMeasureText(f.textY,1)+"</text>","</svg>"].join("");f.container=document.createElement("div"),f.container.className="coordinate-annotation",f.container.id=f.id,f.container.style.position="absolute",f.container.style.pointerEvents="none",f.container.innerHTML=T,e.engine.measure.annotationContainer.appendChild(f.container),f.container.getElementsByTagName("svg")[0].addEventListener("click",function(){e.clearHighlight(),f.container.getElementsByTagName("svg")[0].classList.add("Hight"),f.highlight=!0,e.engine.events.trigger(_e.MeasureClick,f)})}let u=f.container,g=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point),y=e.engine.reactBoundingClientRect.left,w=e.engine.reactBoundingClientRect.top;g.x+=y,g.y+=w,u.style.top="0px",u.style.left="0px";let x=u.getElementsByTagName("circle")[0];x&&(x.setAttribute("cx",g.x),x.setAttribute("cy",g.y));let v=u.getElementsByTagName("rect"),b=u.getElementsByTagName("text"),D=-55;v[0]&&(v[0].setAttribute("x",g.x+10),v[0].setAttribute("y",g.y+10+D)),b[0]&&(b[0].setAttribute("x",g.x+10+40),b[0].setAttribute("y",g.y+10+16+D)),v[1]&&(v[1].setAttribute("x",g.x+10),v[1].setAttribute("y",g.y+10+30+D)),b[1]&&(b[1].setAttribute("x",g.x+10+40),b[1].setAttribute("y",g.y+10+46+D)),v[2]&&(v[2].setAttribute("x",g.x+10),v[2].setAttribute("y",g.y+10+60+D)),b[2]&&(b[2].setAttribute("x",g.x+10+40),b[2].setAttribute("y",g.y+10+76+D)),b[0]&&(b[0].innerHTML="X: "+e.getMeasureText(f.textX,1)),b[1]&&(b[1].innerHTML="Y: "+e.getMeasureText(-f.textZ,1)),b[2]&&(b[2].innerHTML="Z: "+e.getMeasureText(f.textY,1))}function m(f){if(f.container==null){let x=['<svg width="100" height="50" class="measureSvg">','<rect x="0" y="0" width="80" height="25" class="measureBack" />','<text x="40" y="16" text-anchor="middle" class="measureLabel">'+e.getMeasureText(f.text,1)+"</text>",'<polyline stroke="#f99d0b" stroke-width="2" points="80,32 0,32 16,48 32,32" style="fill: none; opacity: 1;"/>',"</svg>"].join("");f.container=document.createElement("div"),f.container.className="elevation-annotation",f.container.id=f.id,f.container.style.position="absolute",f.container.style.pointerEvents="none",f.container.innerHTML=x,e.engine.measure.annotationContainer.appendChild(f.container),f.container.getElementsByTagName("svg")[0].addEventListener("click",function(){e.clearHighlight(),f.container.getElementsByTagName("svg")[0].classList.add("Hight"),f.highlight=!0,e.engine.events.trigger(_e.MeasureClick,f)})}let u=f.container,g=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point),y=e.engine.reactBoundingClientRect.left,w=e.engine.reactBoundingClientRect.top;u.style.top=g.y+w-48+"px",u.style.left=g.x+y-16+"px",u.getElementsByTagName("text")[0].innerHTML=e.getMeasureText(f.text,1)}function p(f){if(f.container==null){let v=['<svg class="measureSvg">','<circle cx="50" cy="50" r="5" fill="#f99d0b" />','<circle cx="50" cy="50" r="5" fill="#f99d0b" />','<polyline stroke="orange" stroke-width="2" points="80,32 0,32" style="fill: none; opacity: 1;"/>','<rect x="0" y="0" width="80" height="25" class="measureBack" />','<text x="40" y="16" text-anchor="middle" class="measureLabel">'+e.getMeasureText(f.text,1)+"</text>","</svg>"].join("");f.container=document.createElement("div"),f.container.className="normal-annotation",f.container.id=f.id,f.container.innerHTML=v,e.engine.measure.annotationContainer.appendChild(f.container),f.container.getElementsByTagName("svg")[0].addEventListener("click",function(){e.clearHighlight(),f.container.getElementsByTagName("svg")[0].classList.add("Hight"),f.highlight=!0,e.engine.events.trigger(_e.MeasureClick,f)})}let u=f.container;if(f.point1==null||f.point2==null){u.style.display="none";return}else u.style.display="block";let g=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point1),y=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point2),w=e.engine.reactBoundingClientRect.left,x=e.engine.reactBoundingClientRect.top;g.x+=w,g.y+=x,y.x+=w,y.y+=x,u.getElementsByTagName("polyline")[0].setAttribute("points",g.x+","+g.y+" "+y.x+","+y.y),u.getElementsByTagName("circle")[0].setAttribute("cx",g.x),u.getElementsByTagName("circle")[0].setAttribute("cy",g.y),u.getElementsByTagName("circle")[1].setAttribute("cx",y.x),u.getElementsByTagName("circle")[1].setAttribute("cy",y.y),u.getElementsByTagName("rect")[0].setAttribute("x",g.x*.5+y.x*.5-40),u.getElementsByTagName("rect")[0].setAttribute("y",g.y*.5+y.y*.5-12.5),u.getElementsByTagName("text")[0].setAttribute("x",g.x*.5+y.x*.5+40-40),u.getElementsByTagName("text")[0].setAttribute("y",g.y*.5+y.y*.5+16-12.5),u.getElementsByTagName("text")[0].innerHTML=e.getMeasureText(f.text,1),u.style.top="0px",u.style.left="0px"}}}class rh{engine;isActive=!1;tools;points=[];behavior;catchDir=0;type="point";constructor(e){this.engine=e,this.tools=new st(e)}active(){this.engine.measure.tools.cancelCurrentSelectedAnnotation(),this.isActive=!0,this.behavior=this.engine.handelBehaved,this.behavior.init(this),this.behavior.active();let e=this.engine.measure.annotationData.normalAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1)}disActive(){this.isActive=!1,this.behavior?.disActive()}clearAllPoints(){this.points=[]}setDirection(e){this.catchDir=e}setSelectType(e){this.type=e}getMeshesMinMaxY(e){if(!Array.isArray(e)||e.length===0)return null;let t=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(let i=0;i<e.length;i++){const s=e[i];if(!s)continue;typeof s.updateMatrixWorld=="function"&&s.updateMatrixWorld(!0);const r=new S.Box3().setFromObject(s);!Number.isFinite(r.min.y)||!Number.isFinite(r.max.y)||(r.min.y<t&&(t=r.min.y),r.max.y>n&&(n=r.max.y))}return!Number.isFinite(t)||!Number.isFinite(n)?null:{minY:t,maxY:n}}handleMouseClick(e){if(e.catch==null)return;let t=e.catch.point;if(this.type=="element"){let s=this.engine.interactionModule.getCatchMeshs(e);var n=this.getMeshesMinMaxY(s);this.catchDir==0?t.set(t.x,n?.minY,t.z):t.set(t.x,n?.maxY,t.z)}else t=e.catch.point;if(this.points.length==0){this.points.push(t);return}let i=this.engine.measure.annotationData.normalAnnotation.find(s=>s.isSelect==!0);i!=null&&(i.isSelect=!1)}handleMouseMove(e){if(e.catch==null||this.points.length==0)return;let t=this.engine.measure.annotationData.normalAnnotation.find(i=>i.isSelect==!0);t==null&&(t={text:null,id:it(),isSelect:!0,type:"clear-height"},this.engine.measure.annotationData.normalAnnotation.push(t));let n=e.catch;if(this.type=="element"){let i=e.catch.point.clone();i.set(i.x,this.points[0].y,i.z);let s=new S.Raycaster(i.add(new S.Vector3(0,.01,0)),new S.Vector3(0,this.catchDir==0?-1:1,0));n.point=this.points[0];const r=this.engine.octreeBox.rayInterationModel(s);if(r.length===0){t.point2=null;return}t.point1=i,t.point2=r[0].point,t.text=t.point1.clone().distanceTo(t.point2.clone()),this.engine.events.trigger(_e.MeasureChanged,t)}else{let i=new S.Raycaster(e.catch.point.clone().add(new S.Vector3(0,.01,0)),new S.Vector3(0,this.catchDir==0?-1:1,0));const s=this.engine.octreeBox.rayInterationModel(i);if(s.length===0){t.point2=null;return}t.point1=n.point,t.point2=s[0].point,t.text=t.point1.clone().distanceTo(t.point2.clone()),this.engine.events.trigger(_e.MeasureChanged,t)}}}class oh{engine;tools;isActive=!1;points=[];behavior;constructor(e){this.engine=e,this.tools=new st(e)}active(){this.engine.measure.tools.cancelCurrentSelectedAnnotation(),this.isActive=!0,this.points=[],this.behavior=this.engine.handelBehaved,this.behavior.init(this,{showCatch:!0}),this.behavior.active();let e=this.engine.measure.annotationData.normalAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1)}disActive(){this.points=[],this.isActive=!1,this.engine.handelBehaved.disActive()}clearAllPoints(){this.points=[]}handleMouseClick(e){if(e.catch==null)return;let t=e.catch;if(this.points.length==0)this.points.push(t.point);else if(this.points.length==1){let n=this.engine.measure.annotationData.normalAnnotation.find(i=>i.isSelect==!0);if(n==null)return;n.point2=t.point,n.isSelect=!1,this.points=[],this.engine.events.trigger(_e.MeasureChanged,n)}}handleMouseMove(e){if(e.catch==null)return;let t=e.catch;if(t!=null&&this.points.length==1){let n=this.engine.measure.annotationData.normalAnnotation.find(i=>i.isSelect==!0);n==null&&(n={id:it(),point1:this.points[0].clone(),point2:t.point.clone(),text:this.points[0].clone().distanceTo(t.point.clone()),type:"distance",isSelect:!0},this.engine.measure.annotationData.normalAnnotation.push(n)),n.point2=t.point,n.text=n.point1.clone().distanceTo(n.point2.clone())}}}class ah{engine;isActive=!1;tools;points=[];behavior;constructor(e){this.engine=e,this.tools=new st(e)}active(){this.engine.measure.tools.cancelCurrentSelectedAnnotation(),this.isActive=!0,this.behavior=this.engine.handelBehaved,this.behavior.init(this),this.behavior.active();let e=this.engine.measure.annotationData.normalAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1)}disActive(){this.isActive=!1,this.behavior?.disActive()}clearAllPoints(){this.points=[]}handleMouseClick(e){if(e.catch==null)return;if(this.points.length==0){this.points.push(e.catch.point);return}let t=this.engine.measure.annotationData.normalAnnotation.find(n=>n.isSelect==!0);t!=null&&(t.isSelect=!1)}handleMouseMove(e){if(e.catch==null||this.points.length==0)return;let t=this.engine.measure.annotationData.normalAnnotation.find(r=>r.isSelect==!0);t==null&&(t={text:null,id:it(),isSelect:!0,type:"clear-distance"},this.engine.measure.annotationData.normalAnnotation.push(t));let n=new S.Raycaster(e.catch.point.clone().add(e.catch.face.normal.clone().setLength(.01)),e.catch.face.normal);const i=this.engine.octreeBox.rayInterationModel(n);if(i.length==0){t.point2=null;return}let s=e.catch;t.point1=s.point,t.point2=i[0].point,t.text=t.point1.clone().distanceTo(t.point2.clone()),this.engine.events.trigger(_e.MeasureChanged,t)}}class lh{engine;isActive=!1;tools;points=[];behavior;constructor(e){this.engine=e,this.tools=new st(e)}active(){this.engine.measure.tools.cancelCurrentSelectedAnnotation(),this.behavior=this.engine.handelBehaved,this.behavior.init(this),this.behavior.active(),this.isActive=!0;let e=this.engine.measure.annotationData.normalAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1)}disActive(){this.isActive=!1,this.behavior?.disActive()}clearAllPoints(){this.points=[]}handleMouseMove(e){if(e.catch==null)return;let t=this.engine.measure.annotationData.elevationAnnotation.find(n=>n.isSelect==!0);t==null&&(t={id:it(),point:e.catch.point.clone(),text:e.catch.point.y,isSelect:!0,type:"elevation"},this.engine.measure.annotationData.elevationAnnotation.push(t)),t.point=e.catch.point.clone(),t.text=e.catch.point.y}handleMouseClick(e){if(e.catch==null)return;let t=this.engine.measure.annotationData.elevationAnnotation.find(n=>n.isSelect==!0);t!=null&&(t.isSelect=!1,t.point=e.catch.point.clone(),t.text=e.catch.point.y,this.engine.events.trigger(_e.MeasureChanged,t))}}class ch{engine;isActive=!1;tools;points=[];behavior;constructor(e){this.engine=e,this.tools=new st(e)}active(){this.engine.measure.tools.cancelCurrentSelectedAnnotation(),this.behavior=this.engine.handelBehaved,this.behavior.init(this),this.behavior.active(),this.isActive=!0;let e=this.engine.measure.annotationData.normalAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1)}disActive(){this.isActive=!1,this.behavior?.disActive()}clearAllPoints(){this.points=[]}handleMouseUp(e){this.engine.deviceType!="PC"&&this.createMeasure()}handleMouseMove(e){if(e.catch==null)return;let t=this.engine.measure.annotationData.coordinateAnnotation.find(n=>n.isSelect==!0);t==null&&(t={id:it(),point:e.catch.point.clone(),text:Math.round(e.catch.point.y)+" m",isSelect:!0,type:"point"},this.engine.measure.annotationData.coordinateAnnotation.push(t)),t.point=e.catch.point.clone(),t.textX=e.catch.point.x,t.textY=e.catch.point.y,t.textZ=e.catch.point.z,console.log("有在移动")}handleMouseClick(e){if(e.catch==null)return;let t=this.engine.measure.annotationData.coordinateAnnotation.find(n=>n.isSelect==!0);t!=null&&(t.point=e.catch.point.clone(),t.textX=e.catch.point.x,t.textY=e.catch.point.y,t.textZ=e.catch.point.z,this.engine.events.trigger(_e.MeasureChanged,t))}createMeasure(){let e=this.engine.measure.annotationData.coordinateAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1,this.engine.events.trigger(_e.MeasureChanged,e))}}class hh{engine;tools;points=[];behavior;constructor(e){this.engine=e,this.tools=new st(e)}active(){this.engine.measure.tools.cancelCurrentSelectedAnnotation(),this.points=[],this.behavior=this.engine.handelBehaved,this.behavior.init(this),this.behavior.active();let e=this.engine.measure.annotationData.normalAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1)}disActive(){this.points=[],this.behavior?.disActive()}clearAllPoints(){this.points=[]}calculateAngle(e,t,n){const i=new S.Vector3().subVectors(e,t),s=new S.Vector3().subVectors(n,t),r=i.length(),a=s.length();if(r===0||a===0)return 0;const h=i.dot(s)/(r*a),c=Math.max(-1,Math.min(1,h));return Math.acos(c)*(180/Math.PI)}handleMouseClick(e){if(e.catch==null)return;let t=e.catch;if(this.points.length==0)this.points.push(t.point);else if(this.points.length==1)this.points.push(t.point);else if(this.points.length==2){let n=this.engine.measure.annotationData.angleAnnotation.find(i=>i.isSelect==!0);if(n==null)return;n.point3=t.point.clone(),n.angle=this.calculateAngle(n.point1,n.point2,n.point3),n.text=n.angle.toFixed(2)+"°",n.isSelect=!1,n.type="angle",this.points=[],this.engine.events.trigger(_e.MeasureChanged,n)}}handleMouseMove(e){if(e.catch!=null&&this.points.length!=1&&this.points.length==2){let t=this.engine.measure.annotationData.angleAnnotation.find(n=>n.isSelect==!0);t==null&&(t={id:it(),point1:this.points[0].clone(),point2:this.points[1].clone(),point3:e.catch.point.clone(),angle:0,text:"0.00°",isSelect:!0,type:"angle"},this.engine.measure.annotationData.angleAnnotation.push(t)),t.point3=e.catch.point.clone(),t.angle=this.calculateAngle(t.point1,t.point2,t.point3),t.text=t.angle.toFixed(2)+"°",console.log("角度",t.text)}}}class uh{engine;tools;points=[];behavior;constructor(e){this.engine=e,this.tools=new st(e)}active(){this.engine.measure.tools.cancelCurrentSelectedAnnotation(),this.points=[],this.behavior=this.engine.handelBehaved,this.behavior.init(this),this.behavior.active();let e=this.engine.measure.annotationData.normalAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1)}disActive(){this.points=[],this.behavior?.disActive()}clearAllPoints(){this.points=[]}calculateArea(e){if(e.length<3)return 0;let t=0;const n=e.length;for(let i=0;i<n;i++){const s=(i+1)%n;t+=e[i].x*e[s].z,t-=e[s].x*e[i].z}return t=Math.abs(t)/2,t}handleMouseClick(e){if(e.catch==null)return;let t=e.catch;if(this.points.push(t.point.clone()),this.points.length>=3){let n=this.engine.measure.annotationData.areaAnnotation.find(i=>i.isSelect==!0);n==null?(n={id:it(),points:this.points.map(i=>i.clone()),area:0,text:0,isSelect:!0,type:"area"},this.engine.measure.annotationData.areaAnnotation.push(n)):(this.points.push(t.point.clone()),n.points=this.points.map(i=>i.clone())),n.area=this.calculateArea(n.points),n.text=n.area,console.log("面积",n.text)}}handleMouseMove(e){if(e.catch!=null&&this.points.length>=2){let t=this.engine.measure.annotationData.areaAnnotation.find(n=>n.isSelect==!0);if(t==null){if(this.points.length>=2){let n=this.points.map(i=>i.clone());n.push(e.catch.point.clone()),n.length>=3&&(t={id:it(),points:n,area:0,text:0,isSelect:!0,type:"area"},this.engine.measure.annotationData.areaAnnotation.push(t))}}else if(t.points.length>0){const n=t.points.length-1;t.points[n]=e.catch.point.clone()}else t.points=this.points.map(n=>n.clone()),t.points.push(e.catch.point.clone());t&&t.points.length>=3&&(t.area=this.calculateArea(t.points),t.text=t.area)}}handelKeyEnterDown(){this.finishMeasure()}finishMeasure(){this.points=this.points.slice(0,this.points.length-1);let e=this.engine.measure.annotationData.areaAnnotation.find(t=>t.isSelect==!0);e!=null&&e.points.length>=3&&(e.points.length>this.points.length&&(e.points=this.points.map(t=>t.clone())),e.area=this.calculateArea(e.points),e.text=e.area,e.isSelect=!1,this.points=[],this.engine.events.trigger(_e.MeasureChanged,e))}}class dh{engine;tools;points=[];behavior;constructor(e){this.engine=e,this.tools=new st(e)}active(){this.engine.measure.tools.cancelCurrentSelectedAnnotation(),this.points=[],this.behavior=this.engine.handelBehaved,this.behavior.init(this),this.behavior.active();let e=this.engine.measure.annotationData.normalAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1)}disActive(){this.points=[],this.behavior?.disActive()}clearAllPoints(){this.points=[]}calculateSlope(e,t){const n=t.y-e.y,i=t.x-e.x,s=t.z-e.z,r=Math.sqrt(i*i+s*s);if(r===0)return{percentage:0,angle:0,heightDiff:n,horizontalDist:0,type:"slope"};const a=n/r*100,h=Math.atan(n/r)*(180/Math.PI);return{percentage:a,angle:h,heightDiff:n,horizontalDist:r,type:"slope"}}handleMouseClick(e){if(e.catch==null)return;let t=e.catch;if(this.points.length==0)this.points.push(t.point);else if(this.points.length==1){let n=this.engine.measure.annotationData.slopeAnnotation.find(s=>s.isSelect==!0);if(n==null)return;console.log("进来了"),n.point2=t.point.clone();const i=this.calculateSlope(n.point1,n.point2);n.slopePercentage=i.percentage,n.slopeAngle=i.angle,n.heightDiff=i.heightDiff,n.horizontalDist=i.horizontalDist,n.text=i.percentage.toFixed(2)+"% ("+i.angle.toFixed(2)+"°)",n.isSelect=!1,this.points=[],this.engine.events.trigger(_e.MeasureChanged,n)}}handleMouseMove(e){if(e.catch==null)return;let t=e.catch;if(t!=null&&this.points.length==1){let n=this.engine.measure.annotationData.slopeAnnotation.find(s=>s.isSelect==!0);n==null&&(n={id:it(),point1:this.points[0].clone(),point2:t.point.clone(),slopePercentage:0,slopeAngle:0,heightDiff:0,horizontalDist:0,text:"0.00% (0.00°)",isSelect:!0,type:"slope"},this.engine.measure.annotationData.slopeAnnotation.push(n)),n.point2=t.point.clone();const i=this.calculateSlope(n.point1,n.point2);n.slopePercentage=i.percentage,n.slopeAngle=i.angle,n.heightDiff=i.heightDiff,n.horizontalDist=i.horizontalDist,n.text=i.percentage.toFixed(2)+"% ("+i.angle.toFixed(2)+"°)"}}}class fh{isActive=!1;engine;clearHeightMeasure;distanceMeasure;clearDistanceMeasure;elevationMeasure;pointMeasure;angleMeasure;areaMeasure;slopeMeasure;tools;annotationContainer;annotationData={normalAnnotation:[],textAnnotation:[],coordinateAnnotation:[],angleAnnotation:[],distanceAnnotation:[],areaAnnotation:[],slopeAnnotation:[],elevationAnnotation:[],volumeAnnotation:[]};constructor(e){this.engine=e,this.clearHeightMeasure=new rh(e),this.distanceMeasure=new oh(e),this.clearDistanceMeasure=new ah(e),this.elevationMeasure=new lh(e),this.pointMeasure=new ch(e),this.angleMeasure=new hh(e),this.areaMeasure=new uh(e),this.slopeMeasure=new dh(e),this.tools=new st(e),this.annotationContainer=document.createElement("div"),this.annotationContainer.className="annotation-container",e.container.appendChild(this.annotationContainer)}active(){this.isActive=!0,this.engine.modelEdge.loadModelEdge(),this.tools.active()}disActive(){this.tools.disActive(),this.clearAll(),this.isActive=!1,this.clearHeightMeasure.disActive(),this.distanceMeasure.disActive(),this.clearDistanceMeasure.disActive(),this.elevationMeasure.disActive(),this.pointMeasure.disActive(),this.angleMeasure.disActive(),this.areaMeasure.disActive(),this.slopeMeasure.disActive(),this.engine.interactionModule.init(),this.engine.interactionModule.active()}clearAllPoints(){this.clearHeightMeasure.clearAllPoints(),this.distanceMeasure.clearAllPoints(),this.clearDistanceMeasure.clearAllPoints(),this.elevationMeasure.clearAllPoints(),this.pointMeasure.clearAllPoints(),this.angleMeasure.clearAllPoints(),this.areaMeasure.clearAllPoints(),this.slopeMeasure.clearAllPoints()}clearAll(){e(this.annotationData.normalAnnotation),e(this.annotationData.textAnnotation),e(this.annotationData.coordinateAnnotation),e(this.annotationData.angleAnnotation),e(this.annotationData.distanceAnnotation),e(this.annotationData.areaAnnotation),e(this.annotationData.slopeAnnotation),e(this.annotationData.elevationAnnotation),e(this.annotationData.volumeAnnotation);function e(t){for(let n=0;n<t.length;n++)t[n].container.remove();t=[]}}saveSetting(e){this.tools.saveSetting(e)}getSetting(){return this.tools.getSetting()}update(){this.isActive&&this.tools.drawNormalAnnotation()}}const Gr=0,ph=1,mh=2,Wr=2,Ki=1.25,Xr=1,Ie=32,Me=Ie/4,Zr=65535,gh=Math.pow(2,-24),Yi=Symbol("SKIP_GENERATION");function yh(o){return o.index?o.index.count:o.attributes.position.count}function Dt(o){return yh(o)/3}function wh(o,e=ArrayBuffer){return o>65535?new Uint32Array(new e(4*o)):new Uint16Array(new e(2*o))}function xh(o,e){if(!o.index){const t=o.attributes.position.count,n=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=wh(t,n);o.setIndex(new _.BufferAttribute(i,1));for(let s=0;s<t;s++)i[s]=s}}function qr(o,e){const t=Dt(o),n=e||o.drawRange,i=n.start/3,s=(n.start+n.count)/3,r=Math.max(0,i),a=Math.min(t,s)-r;return[{offset:Math.floor(r),count:Math.floor(a)}]}function Kr(o,e){if(!o.groups||!o.groups.length)return qr(o,e);const t=[],n=e||o.drawRange,i=n.start/3,s=(n.start+n.count)/3,r=Dt(o),a=[];for(const c of o.groups){const{start:d,count:m}=c,p=d/3,f=isFinite(m)?m:r*3-d,u=(d+f)/3;p<s&&u>i&&(a.push({pos:Math.max(i,p),isStart:!0}),a.push({pos:Math.min(s,u),isStart:!1}))}a.sort((c,d)=>c.pos!==d.pos?c.pos-d.pos:c.type==="end"?-1:1);let l=0,h=null;for(const c of a){const d=c.pos;l!==0&&d!==h&&t.push({offset:h,count:d-h}),l+=c.isStart?1:-1,h=d}return t}function $i(o,e,t,n,i){let s=1/0,r=1/0,a=1/0,l=-1/0,h=-1/0,c=-1/0,d=1/0,m=1/0,p=1/0,f=-1/0,u=-1/0,g=-1/0;const y=o.offset||0;for(let w=(e-y)*6,x=(e+t-y)*6;w<x;w+=6){const v=o[w+0],b=o[w+1],D=v-b,T=v+b;D<s&&(s=D),T>l&&(l=T),v<d&&(d=v),v>f&&(f=v);const k=o[w+2],P=o[w+3],I=k-P,z=k+P;I<r&&(r=I),z>h&&(h=z),k<m&&(m=k),k>u&&(u=k);const C=o[w+4],E=o[w+5],M=C-E,B=C+E;M<a&&(a=M),B>c&&(c=B),C<p&&(p=C),C>g&&(g=C)}n[0]=s,n[1]=r,n[2]=a,n[3]=l,n[4]=h,n[5]=c,i[0]=d,i[1]=m,i[2]=p,i[3]=f,i[4]=u,i[5]=g}function Yr(o,e,t=null,n=null,i=null){const s=o.attributes.position,r=o.index?o.index.array:null,a=s.normalized;if(i===null)i=new Float32Array(t*6),i.offset=e;else if(e<0||t+e>i.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const l=s.array,h=s.offset||0;let c=3;s.isInterleavedBufferAttribute&&(c=s.data.stride);const d=["getX","getY","getZ"],m=i.offset;for(let p=e,f=e+t;p<f;p++){const g=(n?n[p]:p)*3,y=(p-m)*6;let w=g+0,x=g+1,v=g+2;r&&(w=r[w],x=r[x],v=r[v]),a||(w=w*c+h,x=x*c+h,v=v*c+h);for(let b=0;b<3;b++){let D,T,k;a?(D=s[d[b]](w),T=s[d[b]](x),k=s[d[b]](v)):(D=l[w+b],T=l[x+b],k=l[v+b]);let P=D;T<P&&(P=T),k<P&&(P=k);let I=D;T>I&&(I=T),k>I&&(I=k);const z=(I-P)/2,C=b*2;i[y+C+0]=P+z,i[y+C+1]=z+(Math.abs(P)+z)*gh}}return i}function we(o,e,t){return t.min.x=e[o],t.min.y=e[o+1],t.min.z=e[o+2],t.max.x=e[o+3],t.max.y=e[o+4],t.max.z=e[o+5],t}function $r(o){let e=-1,t=-1/0;for(let n=0;n<3;n++){const i=o[n+3]-o[n];i>t&&(t=i,e=n)}return e}function Hr(o,e){e.set(o)}function Jr(o,e,t){let n,i;for(let s=0;s<3;s++){const r=s+3;n=o[s],i=e[s],t[s]=n<i?n:i,n=o[r],i=e[r],t[r]=n>i?n:i}}function Yn(o,e,t){for(let n=0;n<3;n++){const i=e[o+2*n],s=e[o+2*n+1],r=i-s,a=i+s;r<t[n]&&(t[n]=r),a>t[n+3]&&(t[n+3]=a)}}function un(o){const e=o[3]-o[0],t=o[4]-o[1],n=o[5]-o[2];return 2*(e*t+t*n+n*e)}const rt=32,vh=(o,e)=>o.candidate-e.candidate,ft=new Array(rt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),$n=new Float32Array(6);function bh(o,e,t,n,i,s){let r=-1,a=0;if(s===Gr)r=$r(e),r!==-1&&(a=(e[r]+e[r+3])/2);else if(s===ph)r=$r(o),r!==-1&&(a=_h(t,n,i,r));else if(s===mh){const l=un(o);let h=Ki*i;const c=t.offset||0,d=(n-c)*6,m=(n+i-c)*6;for(let p=0;p<3;p++){const f=e[p],y=(e[p+3]-f)/rt;if(i<rt/4){const w=[...ft];w.length=i;let x=0;for(let b=d;b<m;b+=6,x++){const D=w[x];D.candidate=t[b+2*p],D.count=0;const{bounds:T,leftCacheBounds:k,rightCacheBounds:P}=D;for(let I=0;I<3;I++)P[I]=1/0,P[I+3]=-1/0,k[I]=1/0,k[I+3]=-1/0,T[I]=1/0,T[I+3]=-1/0;Yn(b,t,T)}w.sort(vh);let v=i;for(let b=0;b<v;b++){const D=w[b];for(;b+1<v&&w[b+1].candidate===D.candidate;)w.splice(b+1,1),v--}for(let b=d;b<m;b+=6){const D=t[b+2*p];for(let T=0;T<v;T++){const k=w[T];D>=k.candidate?Yn(b,t,k.rightCacheBounds):(Yn(b,t,k.leftCacheBounds),k.count++)}}for(let b=0;b<v;b++){const D=w[b],T=D.count,k=i-D.count,P=D.leftCacheBounds,I=D.rightCacheBounds;let z=0;T!==0&&(z=un(P)/l);let C=0;k!==0&&(C=un(I)/l);const E=Xr+Ki*(z*T+C*k);E<h&&(r=p,h=E,a=D.candidate)}}else{for(let v=0;v<rt;v++){const b=ft[v];b.count=0,b.candidate=f+y+v*y;const D=b.bounds;for(let T=0;T<3;T++)D[T]=1/0,D[T+3]=-1/0}for(let v=d;v<m;v+=6){let T=~~((t[v+2*p]-f)/y);T>=rt&&(T=rt-1);const k=ft[T];k.count++,Yn(v,t,k.bounds)}const w=ft[rt-1];Hr(w.bounds,w.rightCacheBounds);for(let v=rt-2;v>=0;v--){const b=ft[v],D=ft[v+1];Jr(b.bounds,D.rightCacheBounds,b.rightCacheBounds)}let x=0;for(let v=0;v<rt-1;v++){const b=ft[v],D=b.count,T=b.bounds,P=ft[v+1].rightCacheBounds;D!==0&&(x===0?Hr(T,$n):Jr(T,$n,$n)),x+=D;let I=0,z=0;x!==0&&(I=un($n)/l);const C=i-x;C!==0&&(z=un(P)/l);const E=Xr+Ki*(I*x+z*C);E<h&&(r=p,h=E,a=b.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${s} used.`);return{axis:r,pos:a}}function _h(o,e,t,n){let i=0;const s=o.offset;for(let r=e,a=e+t;r<a;r++)i+=o[(r-s)*6+n*2];return i/t}class Hi{constructor(){this.boundingData=new Float32Array(6)}}function Mh(o,e,t,n,i,s){let r=n,a=n+i-1;const l=s.pos,h=s.axis*2,c=t.offset||0;for(;;){for(;r<=a&&t[(r-c)*6+h]<l;)r++;for(;r<=a&&t[(a-c)*6+h]>=l;)a--;if(r<a){for(let d=0;d<3;d++){let m=e[r*3+d];e[r*3+d]=e[a*3+d],e[a*3+d]=m}for(let d=0;d<6;d++){const m=r-c,p=a-c,f=t[m*6+d];t[m*6+d]=t[p*6+d],t[p*6+d]=f}r++,a--}else return r}}function Sh(o,e,t,n,i,s){let r=n,a=n+i-1;const l=s.pos,h=s.axis*2,c=t.offset||0;for(;;){for(;r<=a&&t[(r-c)*6+h]<l;)r++;for(;r<=a&&t[(a-c)*6+h]>=l;)a--;if(r<a){let d=o[r];o[r]=o[a],o[a]=d;for(let m=0;m<6;m++){const p=r-c,f=a-c,u=t[p*6+m];t[p*6+m]=t[f*6+m],t[f*6+m]=u}r++,a--}else return r}}let Qr,Hn,Ji,eo;const Ah=Math.pow(2,32);function Qi(o){return"count"in o?1:1+Qi(o.left)+Qi(o.right)}function Ch(o,e,t){return Qr=new Float32Array(t),Hn=new Uint32Array(t),Ji=new Uint16Array(t),eo=new Uint8Array(t),es(o,e)}function es(o,e){const t=o/4,n=o/2,i="count"in e,s=e.boundingData;for(let r=0;r<6;r++)Qr[t+r]=s[r];if(i)return e.buffer?(eo.set(new Uint8Array(e.buffer),o),o+e.buffer.byteLength):(Hn[t+6]=e.offset,Ji[n+14]=e.count,Ji[n+15]=Zr,o+Ie);{const{left:r,right:a,splitAxis:l}=e,h=o+Ie;let c=es(h,r);const d=o/Ie,p=c/Ie-d;if(p>Ah)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return Hn[t+6]=p,Hn[t+7]=l,es(c,a)}}function Th(o,e,t){const i=(o.index?o.index.count:o.attributes.position.count)/3>2**16,s=t.reduce((c,d)=>c+d.count,0),r=i?4:2,a=e?new SharedArrayBuffer(s*r):new ArrayBuffer(s*r),l=i?new Uint32Array(a):new Uint16Array(a);let h=0;for(let c=0;c<t.length;c++){const{offset:d,count:m}=t[c];for(let p=0;p<m;p++)l[h+p]=d+p;h+=m}return l}function Ph(o,e,t,n,i){const{maxDepth:s,verbose:r,maxLeafTris:a,strategy:l,onProgress:h,indirect:c}=i,d=o._indirectBuffer,m=o.geometry,p=m.index?m.index.array:null,f=c?Sh:Mh,u=Dt(m),g=new Float32Array(6);let y=!1;const w=new Hi;return $i(e,t,n,w.boundingData,g),v(w,t,n,g),w;function x(b){h&&h(b/u)}function v(b,D,T,k=null,P=0){if(!y&&P>=s&&(y=!0,r&&(console.warn(`MeshBVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`),console.warn(m))),T<=a||P>=s)return x(D+T),b.offset=D,b.count=T,b;const I=bh(b.boundingData,k,e,D,T,l);if(I.axis===-1)return x(D+T),b.offset=D,b.count=T,b;const z=f(d,p,e,D,T,I);if(z===D||z===D+T)x(D+T),b.offset=D,b.count=T;else{b.splitAxis=I.axis;const C=new Hi,E=D,M=z-D;b.left=C,$i(e,E,M,C.boundingData,g),v(C,E,M,g,P+1);const B=new Hi,V=z,U=T-M;b.right=B,$i(e,V,U,B.boundingData,g),v(B,V,U,g,P+1)}return b}}function Dh(o,e){const t=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=o.geometry;let i,s;if(e.indirect){const r=Kr(n,e.range),a=Th(n,e.useSharedArrayBuffer,r);o._indirectBuffer=a,i=Yr(n,0,a.length,a),s=[{offset:0,count:a.length}]}else{xh(n,e);const r=qr(n,e.range)[0];i=Yr(n,r.offset,r.count),s=Kr(n,e.range)}o._roots=s.map(r=>{const a=Ph(o,i,r.offset,r.count,e),l=Qi(a),h=new t(Ie*l);return Ch(0,a,h),h})}class ot{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let n=1/0,i=-1/0;for(let s=0,r=e.length;s<r;s++){const l=e[s][t];n=l<n?l:n,i=l>i?l:i}this.min=n,this.max=i}setFromPoints(e,t){let n=1/0,i=-1/0;for(let s=0,r=t.length;s<r;s++){const a=t[s],l=e.dot(a);n=l<n?l:n,i=l>i?l:i}this.min=n,this.max=i}isSeparated(e){return this.min>e.max||e.min>this.max}}ot.prototype.setFromBox=(function(){const o=new _.Vector3;return function(t,n){const i=n.min,s=n.max;let r=1/0,a=-1/0;for(let l=0;l<=1;l++)for(let h=0;h<=1;h++)for(let c=0;c<=1;c++){o.x=i.x*l+s.x*(1-l),o.y=i.y*h+s.y*(1-h),o.z=i.z*c+s.z*(1-c);const d=t.dot(o);r=Math.min(d,r),a=Math.max(d,a)}this.min=r,this.max=a}})();const kh=(function(){const o=new _.Vector3,e=new _.Vector3,t=new _.Vector3;return function(i,s,r){const a=i.start,l=o,h=s.start,c=e;t.subVectors(a,h),o.subVectors(i.end,i.start),e.subVectors(s.end,s.start);const d=t.dot(c),m=c.dot(l),p=c.dot(c),f=t.dot(l),g=l.dot(l)*p-m*m;let y,w;g!==0?y=(d*m-f*p)/g:y=0,w=(d+y*m)/p,r.x=y,r.y=w}})(),ts=(function(){const o=new _.Vector2,e=new _.Vector3,t=new _.Vector3;return function(i,s,r,a){kh(i,s,o);let l=o.x,h=o.y;if(l>=0&&l<=1&&h>=0&&h<=1){i.at(l,r),s.at(h,a);return}else if(l>=0&&l<=1){h<0?s.at(0,a):s.at(1,a),i.closestPointToPoint(a,!0,r);return}else if(h>=0&&h<=1){l<0?i.at(0,r):i.at(1,r),s.closestPointToPoint(r,!0,a);return}else{let c;l<0?c=i.start:c=i.end;let d;h<0?d=s.start:d=s.end;const m=e,p=t;if(i.closestPointToPoint(d,!0,e),s.closestPointToPoint(c,!0,t),m.distanceToSquared(d)<=p.distanceToSquared(c)){r.copy(m),a.copy(d);return}else{r.copy(c),a.copy(p);return}}}})(),Ih=(function(){const o=new _.Vector3,e=new _.Vector3,t=new _.Plane,n=new _.Line3;return function(s,r){const{radius:a,center:l}=s,{a:h,b:c,c:d}=r;if(n.start=h,n.end=c,n.closestPointToPoint(l,!0,o).distanceTo(l)<=a||(n.start=h,n.end=d,n.closestPointToPoint(l,!0,o).distanceTo(l)<=a)||(n.start=c,n.end=d,n.closestPointToPoint(l,!0,o).distanceTo(l)<=a))return!0;const u=r.getPlane(t);if(Math.abs(u.distanceToPoint(l))<=a){const y=u.projectPoint(l,e);if(r.containsPoint(y))return!0}return!1}})(),Lh=["x","y","z"],at=1e-15,to=at*at;function je(o){return Math.abs(o)<at}class Ge extends _.Triangle{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new _.Vector3),this.satBounds=new Array(4).fill().map(()=>new ot),this.points=[this.a,this.b,this.c],this.plane=new _.Plane,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new _.Line3,this.needsUpdate=!0}intersectsSphere(e){return Ih(e,this)}update(){const e=this.a,t=this.b,n=this.c,i=this.points,s=this.satAxes,r=this.satBounds,a=s[0],l=r[0];this.getNormal(a),l.setFromPoints(a,i);const h=s[1],c=r[1];h.subVectors(e,t),c.setFromPoints(h,i);const d=s[2],m=r[2];d.subVectors(t,n),m.setFromPoints(d,i);const p=s[3],f=r[3];p.subVectors(n,e),f.setFromPoints(p,i);const u=h.length(),g=d.length(),y=p.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,u<at?g<at||y<at?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(n)):g<at?y<at?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):y<at&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(a,e),this.needsUpdate=!1}}Ge.prototype.closestPointToSegment=(function(){const o=new _.Vector3,e=new _.Vector3,t=new _.Line3;return function(i,s=null,r=null){const{start:a,end:l}=i,h=this.points;let c,d=1/0;for(let m=0;m<3;m++){const p=(m+1)%3;t.start.copy(h[m]),t.end.copy(h[p]),ts(t,i,o,e),c=o.distanceToSquared(e),c<d&&(d=c,s&&s.copy(o),r&&r.copy(e))}return this.closestPointToPoint(a,o),c=a.distanceToSquared(o),c<d&&(d=c,s&&s.copy(o),r&&r.copy(a)),this.closestPointToPoint(l,o),c=l.distanceToSquared(o),c<d&&(d=c,s&&s.copy(o),r&&r.copy(l)),Math.sqrt(d)}})(),Ge.prototype.intersectsTriangle=(function(){const o=new Ge,e=new ot,t=new ot,n=new _.Vector3,i=new _.Vector3,s=new _.Vector3,r=new _.Vector3,a=new _.Line3,l=new _.Line3,h=new _.Vector3,c=new _.Vector2,d=new _.Vector2;function m(x,v,b,D){const T=n;!x.isDegenerateIntoPoint&&!x.isDegenerateIntoSegment?T.copy(x.plane.normal):T.copy(v.plane.normal);const k=x.satBounds,P=x.satAxes;for(let C=1;C<4;C++){const E=k[C],M=P[C];if(e.setFromPoints(M,v.points),E.isSeparated(e)||(r.copy(T).cross(M),e.setFromPoints(r,x.points),t.setFromPoints(r,v.points),e.isSeparated(t)))return!1}const I=v.satBounds,z=v.satAxes;for(let C=1;C<4;C++){const E=I[C],M=z[C];if(e.setFromPoints(M,x.points),E.isSeparated(e)||(r.crossVectors(T,M),e.setFromPoints(r,x.points),t.setFromPoints(r,v.points),e.isSeparated(t)))return!1}return b&&(D||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),b.start.set(0,0,0),b.end.set(0,0,0)),!0}function p(x,v,b,D,T,k,P,I,z,C,E){let M=P/(P-I);C.x=D+(T-D)*M,E.start.subVectors(v,x).multiplyScalar(M).add(x),M=P/(P-z),C.y=D+(k-D)*M,E.end.subVectors(b,x).multiplyScalar(M).add(x)}function f(x,v,b,D,T,k,P,I,z,C,E){if(T>0)p(x.c,x.a,x.b,D,v,b,z,P,I,C,E);else if(k>0)p(x.b,x.a,x.c,b,v,D,I,P,z,C,E);else if(I*z>0||P!=0)p(x.a,x.b,x.c,v,b,D,P,I,z,C,E);else if(I!=0)p(x.b,x.a,x.c,b,v,D,I,P,z,C,E);else if(z!=0)p(x.c,x.a,x.b,D,v,b,z,P,I,C,E);else return!0;return!1}function u(x,v,b,D){const T=v.degenerateSegment,k=x.plane.distanceToPoint(T.start),P=x.plane.distanceToPoint(T.end);return je(k)?je(P)?m(x,v,b,D):(b&&(b.start.copy(T.start),b.end.copy(T.start)),x.containsPoint(T.start)):je(P)?(b&&(b.start.copy(T.end),b.end.copy(T.end)),x.containsPoint(T.end)):x.plane.intersectLine(T,n)!=null?(b&&(b.start.copy(n),b.end.copy(n)),x.containsPoint(n)):!1}function g(x,v,b){const D=v.a;return je(x.plane.distanceToPoint(D))&&x.containsPoint(D)?(b&&(b.start.copy(D),b.end.copy(D)),!0):!1}function y(x,v,b){const D=x.degenerateSegment,T=v.a;return D.closestPointToPoint(T,!0,n),T.distanceToSquared(n)<to?(b&&(b.start.copy(T),b.end.copy(T)),!0):!1}function w(x,v,b,D){if(x.isDegenerateIntoSegment)if(v.isDegenerateIntoSegment){const T=x.degenerateSegment,k=v.degenerateSegment,P=i,I=s;T.delta(P),k.delta(I);const z=n.subVectors(k.start,T.start),C=P.x*I.y-P.y*I.x;if(je(C))return!1;const E=(z.x*I.y-z.y*I.x)/C,M=-(P.x*z.y-P.y*z.x)/C;if(E<0||E>1||M<0||M>1)return!1;const B=T.start.z+P.z*E,V=k.start.z+I.z*M;return je(B-V)?(b&&(b.start.copy(T.start).addScaledVector(P,E),b.end.copy(T.start).addScaledVector(P,E)),!0):!1}else return v.isDegenerateIntoPoint?y(x,v,b):u(v,x,b,D);else{if(x.isDegenerateIntoPoint)return v.isDegenerateIntoPoint?v.a.distanceToSquared(x.a)<to?(b&&(b.start.copy(x.a),b.end.copy(x.a)),!0):!1:v.isDegenerateIntoSegment?y(v,x,b):g(v,x,b);if(v.isDegenerateIntoPoint)return g(x,v,b);if(v.isDegenerateIntoSegment)return u(x,v,b,D)}}return function(v,b=null,D=!1){this.needsUpdate&&this.update(),v.isExtendedTriangle?v.needsUpdate&&v.update():(o.copy(v),o.update(),v=o);const T=w(this,v,b,D);if(T!==void 0)return T;const k=this.plane,P=v.plane;let I=P.distanceToPoint(this.a),z=P.distanceToPoint(this.b),C=P.distanceToPoint(this.c);je(I)&&(I=0),je(z)&&(z=0),je(C)&&(C=0);const E=I*z,M=I*C;if(E>0&&M>0)return!1;let B=k.distanceToPoint(v.a),V=k.distanceToPoint(v.b),U=k.distanceToPoint(v.c);je(B)&&(B=0),je(V)&&(V=0),je(U)&&(U=0);const H=B*V,G=B*U;if(H>0&&G>0)return!1;i.copy(k.normal),s.copy(P.normal);const $=i.cross(s);let F=0,N=Math.abs($.x);const te=Math.abs($.y);te>N&&(N=te,F=1),Math.abs($.z)>N&&(F=2);const Y=Lh[F],ce=this.a[Y],fe=this.b[Y],se=this.c[Y],oe=v.a[Y],ue=v.b[Y],pe=v.c[Y];if(f(this,ce,fe,se,E,M,I,z,C,c,a))return m(this,v,b,D);if(f(v,oe,ue,pe,H,G,B,V,U,d,l))return m(this,v,b,D);if(c.y<c.x){const Ae=c.y;c.y=c.x,c.x=Ae,h.copy(a.start),a.start.copy(a.end),a.end.copy(h)}if(d.y<d.x){const Ae=d.y;d.y=d.x,d.x=Ae,h.copy(l.start),l.start.copy(l.end),l.end.copy(h)}return c.y<d.x||d.y<c.x?!1:(b&&(d.x>c.x?b.start.copy(l.start):b.start.copy(a.start),d.y<c.y?b.end.copy(l.end):b.end.copy(a.end)),!0)}})(),Ge.prototype.distanceToPoint=(function(){const o=new _.Vector3;return function(t){return this.closestPointToPoint(t,o),t.distanceTo(o)}})(),Ge.prototype.distanceToTriangle=(function(){const o=new _.Vector3,e=new _.Vector3,t=["a","b","c"],n=new _.Line3,i=new _.Line3;return function(r,a=null,l=null){const h=a||l?n:null;if(this.intersectsTriangle(r,h))return(a||l)&&(a&&h.getCenter(a),l&&h.getCenter(l)),0;let c=1/0;for(let d=0;d<3;d++){let m;const p=t[d],f=r[p];this.closestPointToPoint(f,o),m=f.distanceToSquared(o),m<c&&(c=m,a&&a.copy(o),l&&l.copy(f));const u=this[p];r.closestPointToPoint(u,o),m=u.distanceToSquared(o),m<c&&(c=m,a&&a.copy(u),l&&l.copy(o))}for(let d=0;d<3;d++){const m=t[d],p=t[(d+1)%3];n.set(this[m],this[p]);for(let f=0;f<3;f++){const u=t[f],g=t[(f+1)%3];i.set(r[u],r[g]),ts(n,i,o,e);const y=o.distanceToSquared(e);y<c&&(c=y,a&&a.copy(o),l&&l.copy(e))}}return Math.sqrt(c)}})();class Le{constructor(e,t,n){this.isOrientedBox=!0,this.min=new _.Vector3,this.max=new _.Vector3,this.matrix=new _.Matrix4,this.invMatrix=new _.Matrix4,this.points=new Array(8).fill().map(()=>new _.Vector3),this.satAxes=new Array(3).fill().map(()=>new _.Vector3),this.satBounds=new Array(3).fill().map(()=>new ot),this.alignedSatBounds=new Array(3).fill().map(()=>new ot),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),n&&this.matrix.copy(n)}set(e,t,n){this.min.copy(e),this.max.copy(t),this.matrix.copy(n),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}Le.prototype.update=(function(){return function(){const e=this.matrix,t=this.min,n=this.max,i=this.points;for(let h=0;h<=1;h++)for(let c=0;c<=1;c++)for(let d=0;d<=1;d++){const m=1*h|2*c|4*d,p=i[m];p.x=h?n.x:t.x,p.y=c?n.y:t.y,p.z=d?n.z:t.z,p.applyMatrix4(e)}const s=this.satBounds,r=this.satAxes,a=i[0];for(let h=0;h<3;h++){const c=r[h],d=s[h],m=1<<h,p=i[m];c.subVectors(a,p),d.setFromPoints(c,i)}const l=this.alignedSatBounds;l[0].setFromPointsField(i,"x"),l[1].setFromPointsField(i,"y"),l[2].setFromPointsField(i,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})(),Le.prototype.intersectsBox=(function(){const o=new ot;return function(t){this.needsUpdate&&this.update();const n=t.min,i=t.max,s=this.satBounds,r=this.satAxes,a=this.alignedSatBounds;if(o.min=n.x,o.max=i.x,a[0].isSeparated(o)||(o.min=n.y,o.max=i.y,a[1].isSeparated(o))||(o.min=n.z,o.max=i.z,a[2].isSeparated(o)))return!1;for(let l=0;l<3;l++){const h=r[l],c=s[l];if(o.setFromBox(h,t),c.isSeparated(o))return!1}return!0}})(),Le.prototype.intersectsTriangle=(function(){const o=new Ge,e=new Array(3),t=new ot,n=new ot,i=new _.Vector3;return function(r){this.needsUpdate&&this.update(),r.isExtendedTriangle?r.needsUpdate&&r.update():(o.copy(r),o.update(),r=o);const a=this.satBounds,l=this.satAxes;e[0]=r.a,e[1]=r.b,e[2]=r.c;for(let m=0;m<3;m++){const p=a[m],f=l[m];if(t.setFromPoints(f,e),p.isSeparated(t))return!1}const h=r.satBounds,c=r.satAxes,d=this.points;for(let m=0;m<3;m++){const p=h[m],f=c[m];if(t.setFromPoints(f,d),p.isSeparated(t))return!1}for(let m=0;m<3;m++){const p=l[m];for(let f=0;f<4;f++){const u=c[f];if(i.crossVectors(p,u),t.setFromPoints(i,e),n.setFromPoints(i,d),t.isSeparated(n))return!1}}return!0}})(),Le.prototype.closestPointToPoint=(function(){return function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}})(),Le.prototype.distanceToPoint=(function(){const o=new _.Vector3;return function(t){return this.closestPointToPoint(t,o),t.distanceTo(o)}})(),Le.prototype.distanceToBox=(function(){const o=["x","y","z"],e=new Array(12).fill().map(()=>new _.Line3),t=new Array(12).fill().map(()=>new _.Line3),n=new _.Vector3,i=new _.Vector3;return function(r,a=0,l=null,h=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(l||h)&&(r.getCenter(i),this.closestPointToPoint(i,n),r.closestPointToPoint(n,i),l&&l.copy(n),h&&h.copy(i)),0;const c=a*a,d=r.min,m=r.max,p=this.points;let f=1/0;for(let g=0;g<8;g++){const y=p[g];i.copy(y).clamp(d,m);const w=y.distanceToSquared(i);if(w<f&&(f=w,l&&l.copy(y),h&&h.copy(i),w<c))return Math.sqrt(w)}let u=0;for(let g=0;g<3;g++)for(let y=0;y<=1;y++)for(let w=0;w<=1;w++){const x=(g+1)%3,v=(g+2)%3,b=y<<x|w<<v,D=1<<g|y<<x|w<<v,T=p[b],k=p[D];e[u].set(T,k);const I=o[g],z=o[x],C=o[v],E=t[u],M=E.start,B=E.end;M[I]=d[I],M[z]=y?d[z]:m[z],M[C]=w?d[C]:m[z],B[I]=m[I],B[z]=y?d[z]:m[z],B[C]=w?d[C]:m[z],u++}for(let g=0;g<=1;g++)for(let y=0;y<=1;y++)for(let w=0;w<=1;w++){i.x=g?m.x:d.x,i.y=y?m.y:d.y,i.z=w?m.z:d.z,this.closestPointToPoint(i,n);const x=i.distanceToSquared(n);if(x<f&&(f=x,l&&l.copy(n),h&&h.copy(i),x<c))return Math.sqrt(x)}for(let g=0;g<12;g++){const y=e[g];for(let w=0;w<12;w++){const x=t[w];ts(y,x,n,i);const v=n.distanceToSquared(i);if(v<f&&(f=v,l&&l.copy(n),h&&h.copy(i),v<c))return Math.sqrt(v)}}return Math.sqrt(f)}})();class ns{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class Eh extends ns{constructor(){super(()=>new Ge)}}const We=new Eh;function Se(o,e){return e[o+15]===Zr}function Ue(o,e){return e[o+6]}function Xe(o,e){return e[o+14]}function Te(o){return o+Me}function Pe(o,e){const t=e[o+6];return o+t*Me}function is(o,e){return e[o+7]}function Qd(o){return o}class Bh{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=n=>{t&&e.push(t),t=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const me=new Bh;let pt,qt;const Kt=[],Jn=new ns(()=>new _.Box3);function Oh(o,e,t,n,i,s){pt=Jn.getPrimitive(),qt=Jn.getPrimitive(),Kt.push(pt,qt),me.setBuffer(o._roots[e]);const r=ss(0,o.geometry,t,n,i,s);me.clearBuffer(),Jn.releasePrimitive(pt),Jn.releasePrimitive(qt),Kt.pop(),Kt.pop();const a=Kt.length;return a>0&&(qt=Kt[a-1],pt=Kt[a-2]),r}function ss(o,e,t,n,i=null,s=0,r=0){const{float32Array:a,uint16Array:l,uint32Array:h}=me;let c=o*2;if(Se(c,l)){const m=Ue(o,h),p=Xe(c,l);return we(o,a,pt),n(m,p,!1,r,s+o/Me,pt)}else{let I=function(C){const{uint16Array:E,uint32Array:M}=me;let B=C*2;for(;!Se(B,E);)C=Te(C),B=C*2;return Ue(C,M)},z=function(C){const{uint16Array:E,uint32Array:M}=me;let B=C*2;for(;!Se(B,E);)C=Pe(C,M),B=C*2;return Ue(C,M)+Xe(B,E)};const m=Te(o),p=Pe(o,h);let f=m,u=p,g,y,w,x;if(i&&(w=pt,x=qt,we(f,a,w),we(u,a,x),g=i(w),y=i(x),y<g)){f=p,u=m;const C=g;g=y,y=C,w=x}w||(w=pt,we(f,a,w));const v=Se(f*2,l),b=t(w,v,g,r+1,s+f/Me);let D;if(b===Wr){const C=I(f),M=z(f)-C;D=n(C,M,!0,r+1,s+f/Me,w)}else D=b&&ss(f,e,t,n,i,s,r+1);if(D)return!0;x=qt,we(u,a,x);const T=Se(u*2,l),k=t(x,T,y,r+1,s+u/Me);let P;if(k===Wr){const C=I(u),M=z(u)-C;P=n(C,M,!0,r+1,s+u/Me,x)}else P=k&&ss(u,e,t,n,i,s,r+1);return!!P}}const dn=new _.Vector3,rs=new _.Vector3;function zh(o,e,t={},n=0,i=1/0){const s=n*n,r=i*i;let a=1/0,l=null;if(o.shapecast({boundsTraverseOrder:c=>(dn.copy(e).clamp(c.min,c.max),dn.distanceToSquared(e)),intersectsBounds:(c,d,m)=>m<a&&m<r,intersectsTriangle:(c,d)=>{c.closestPointToPoint(e,dn);const m=e.distanceToSquared(dn);return m<a&&(rs.copy(dn),a=m,l=d),m<s}}),a===1/0)return null;const h=Math.sqrt(a);return t.point?t.point.copy(rs):t.point=rs.clone(),t.distance=h,t.faceIndex=l,t}const Qn=parseInt(_.REVISION)>=169,Nh=parseInt(_.REVISION)<=161,kt=new _.Vector3,It=new _.Vector3,Lt=new _.Vector3,ei=new _.Vector2,ti=new _.Vector2,ni=new _.Vector2,no=new _.Vector3,io=new _.Vector3,so=new _.Vector3,fn=new _.Vector3;function Rh(o,e,t,n,i,s,r,a){let l;if(s===_.BackSide?l=o.intersectTriangle(n,t,e,!0,i):l=o.intersectTriangle(e,t,n,s!==_.DoubleSide,i),l===null)return null;const h=o.origin.distanceTo(i);return h<r||h>a?null:{distance:h,point:i.clone()}}function ro(o,e,t,n,i,s,r,a,l,h,c){kt.fromBufferAttribute(e,s),It.fromBufferAttribute(e,r),Lt.fromBufferAttribute(e,a);const d=Rh(o,kt,It,Lt,fn,l,h,c);if(d){if(n){ei.fromBufferAttribute(n,s),ti.fromBufferAttribute(n,r),ni.fromBufferAttribute(n,a),d.uv=new _.Vector2;const p=_.Triangle.getInterpolation(fn,kt,It,Lt,ei,ti,ni,d.uv);Qn||(d.uv=p)}if(i){ei.fromBufferAttribute(i,s),ti.fromBufferAttribute(i,r),ni.fromBufferAttribute(i,a),d.uv1=new _.Vector2;const p=_.Triangle.getInterpolation(fn,kt,It,Lt,ei,ti,ni,d.uv1);Qn||(d.uv1=p),Nh&&(d.uv2=d.uv1)}if(t){no.fromBufferAttribute(t,s),io.fromBufferAttribute(t,r),so.fromBufferAttribute(t,a),d.normal=new _.Vector3;const p=_.Triangle.getInterpolation(fn,kt,It,Lt,no,io,so,d.normal);d.normal.dot(o.direction)>0&&d.normal.multiplyScalar(-1),Qn||(d.normal=p)}const m={a:s,b:r,c:a,normal:new _.Vector3,materialIndex:0};if(_.Triangle.getNormal(kt,It,Lt,m.normal),d.face=m,d.faceIndex=s,Qn){const p=new _.Vector3;_.Triangle.getBarycoord(fn,kt,It,Lt,p),d.barycoord=p}}return d}function oo(o){return o&&o.isMaterial?o.side:o}function ii(o,e,t,n,i,s,r){const a=n*3;let l=a+0,h=a+1,c=a+2;const{index:d,groups:m}=o;o.index&&(l=d.getX(l),h=d.getX(h),c=d.getX(c));const{position:p,normal:f,uv:u,uv1:g}=o.attributes;if(Array.isArray(e)){const y=n*3;for(let w=0,x=m.length;w<x;w++){const{start:v,count:b,materialIndex:D}=m[w];if(y>=v&&y<v+b){const T=oo(e[D]),k=ro(t,p,f,u,g,l,h,c,T,s,r);if(k)if(k.faceIndex=n,k.face.materialIndex=D,i)i.push(k);else return k}}}else{const y=oo(e),w=ro(t,p,f,u,g,l,h,c,y,s,r);if(w)if(w.faceIndex=n,w.face.materialIndex=0,i)i.push(w);else return w}return null}function be(o,e,t,n){const i=o.a,s=o.b,r=o.c;let a=e,l=e+1,h=e+2;t&&(a=t.getX(a),l=t.getX(l),h=t.getX(h)),i.x=n.getX(a),i.y=n.getY(a),i.z=n.getZ(a),s.x=n.getX(l),s.y=n.getY(l),s.z=n.getZ(l),r.x=n.getX(h),r.y=n.getY(h),r.z=n.getZ(h)}function Fh(o,e,t,n,i,s,r,a){const{geometry:l,_indirectBuffer:h}=o;for(let c=n,d=n+i;c<d;c++)ii(l,e,t,c,s,r,a)}function Uh(o,e,t,n,i,s,r){const{geometry:a,_indirectBuffer:l}=o;let h=1/0,c=null;for(let d=n,m=n+i;d<m;d++){let p;p=ii(a,e,t,d,null,s,r),p&&p.distance<h&&(c=p,h=p.distance)}return c}function Vh(o,e,t,n,i,s,r){const{geometry:a}=t,{index:l}=a,h=a.attributes.position;for(let c=o,d=e+o;c<d;c++){let m;if(m=c,be(r,m*3,l,h),r.needsUpdate=!0,n(r,m,i,s))return!0}return!1}function jh(o,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=o.geometry,n=t.index?t.index.array:null,i=t.attributes.position;let s,r,a,l,h=0;const c=o._roots;for(let m=0,p=c.length;m<p;m++)s=c[m],r=new Uint32Array(s),a=new Uint16Array(s),l=new Float32Array(s),d(0,h),h+=s.byteLength;function d(m,p,f=!1){const u=m*2;if(Se(u,a)){const g=r[m+6],y=a[u+14];let w=1/0,x=1/0,v=1/0,b=-1/0,D=-1/0,T=-1/0;for(let k=3*g,P=3*(g+y);k<P;k++){let I=n[k];const z=i.getX(I),C=i.getY(I),E=i.getZ(I);z<w&&(w=z),z>b&&(b=z),C<x&&(x=C),C>D&&(D=C),E<v&&(v=E),E>T&&(T=E)}return l[m+0]!==w||l[m+1]!==x||l[m+2]!==v||l[m+3]!==b||l[m+4]!==D||l[m+5]!==T?(l[m+0]=w,l[m+1]=x,l[m+2]=v,l[m+3]=b,l[m+4]=D,l[m+5]=T,!0):!1}else{const g=Te(m),y=Pe(m,r);let w=f,x=!1,v=!1;if(e){if(!w){const I=g/Me+p/Ie,z=y/Me+p/Ie;x=e.has(I),v=e.has(z),w=!x&&!v}}else x=!0,v=!0;const b=w||x,D=w||v;let T=!1;b&&(T=d(g,p,w));let k=!1;D&&(k=d(y,p,w));const P=T||k;if(P)for(let I=0;I<3;I++){const z=g+I,C=y+I,E=l[z],M=l[z+3],B=l[C],V=l[C+3];l[m+I]=E<B?E:B,l[m+I+3]=M>V?M:V}return P}}}function mt(o,e,t,n,i){let s,r,a,l,h,c;const d=1/t.direction.x,m=1/t.direction.y,p=1/t.direction.z,f=t.origin.x,u=t.origin.y,g=t.origin.z;let y=e[o],w=e[o+3],x=e[o+1],v=e[o+3+1],b=e[o+2],D=e[o+3+2];return d>=0?(s=(y-f)*d,r=(w-f)*d):(s=(w-f)*d,r=(y-f)*d),m>=0?(a=(x-u)*m,l=(v-u)*m):(a=(v-u)*m,l=(x-u)*m),s>l||a>r||((a>s||isNaN(s))&&(s=a),(l<r||isNaN(r))&&(r=l),p>=0?(h=(b-g)*p,c=(D-g)*p):(h=(D-g)*p,c=(b-g)*p),s>c||h>r)?!1:((h>s||s!==s)&&(s=h),(c<r||r!==r)&&(r=c),s<=i&&r>=n)}function Gh(o,e,t,n,i,s,r,a){const{geometry:l,_indirectBuffer:h}=o;for(let c=n,d=n+i;c<d;c++){let m=h?h[c]:c;ii(l,e,t,m,s,r,a)}}function Wh(o,e,t,n,i,s,r){const{geometry:a,_indirectBuffer:l}=o;let h=1/0,c=null;for(let d=n,m=n+i;d<m;d++){let p;p=ii(a,e,t,l?l[d]:d,null,s,r),p&&p.distance<h&&(c=p,h=p.distance)}return c}function Xh(o,e,t,n,i,s,r){const{geometry:a}=t,{index:l}=a,h=a.attributes.position;for(let c=o,d=e+o;c<d;c++){let m;if(m=t.resolveTriangleIndex(c),be(r,m*3,l,h),r.needsUpdate=!0,n(r,m,i,s))return!0}return!1}function Zh(o,e,t,n,i,s,r){me.setBuffer(o._roots[e]),os(0,o,t,n,i,s,r),me.clearBuffer()}function os(o,e,t,n,i,s,r){const{float32Array:a,uint16Array:l,uint32Array:h}=me,c=o*2;if(Se(c,l)){const m=Ue(o,h),p=Xe(c,l);Fh(e,t,n,m,p,i,s,r)}else{const m=Te(o);mt(m,a,n,s,r)&&os(m,e,t,n,i,s,r);const p=Pe(o,h);mt(p,a,n,s,r)&&os(p,e,t,n,i,s,r)}}const qh=["x","y","z"];function Kh(o,e,t,n,i,s){me.setBuffer(o._roots[e]);const r=as(0,o,t,n,i,s);return me.clearBuffer(),r}function as(o,e,t,n,i,s){const{float32Array:r,uint16Array:a,uint32Array:l}=me;let h=o*2;if(Se(h,a)){const d=Ue(o,l),m=Xe(h,a);return Uh(e,t,n,d,m,i,s)}else{const d=is(o,l),m=qh[d],f=n.direction[m]>=0;let u,g;f?(u=Te(o),g=Pe(o,l)):(u=Pe(o,l),g=Te(o));const w=mt(u,r,n,i,s)?as(u,e,t,n,i,s):null;if(w){const b=w.point[m];if(f?b<=r[g+d]:b>=r[g+d+3])return w}const v=mt(g,r,n,i,s)?as(g,e,t,n,i,s):null;return w&&v?w.distance<=v.distance?w:v:w||v||null}}const si=new _.Box3,Yt=new Ge,$t=new Ge,pn=new _.Matrix4,ao=new Le,ri=new Le;function Yh(o,e,t,n){me.setBuffer(o._roots[e]);const i=ls(0,o,t,n);return me.clearBuffer(),i}function ls(o,e,t,n,i=null){const{float32Array:s,uint16Array:r,uint32Array:a}=me;let l=o*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),ao.set(t.boundingBox.min,t.boundingBox.max,n),i=ao),Se(l,r)){const c=e.geometry,d=c.index,m=c.attributes.position,p=t.index,f=t.attributes.position,u=Ue(o,a),g=Xe(l,r);if(pn.copy(n).invert(),t.boundsTree)return we(o,s,ri),ri.matrix.copy(pn),ri.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:w=>ri.intersectsBox(w),intersectsTriangle:w=>{w.a.applyMatrix4(n),w.b.applyMatrix4(n),w.c.applyMatrix4(n),w.needsUpdate=!0;for(let x=u*3,v=(g+u)*3;x<v;x+=3)if(be($t,x,d,m),$t.needsUpdate=!0,w.intersectsTriangle($t))return!0;return!1}});{const y=Dt(t);for(let w=u*3,x=(g+u)*3;w<x;w+=3){be(Yt,w,d,m),Yt.a.applyMatrix4(pn),Yt.b.applyMatrix4(pn),Yt.c.applyMatrix4(pn),Yt.needsUpdate=!0;for(let v=0,b=y*3;v<b;v+=3)if(be($t,v,p,f),$t.needsUpdate=!0,Yt.intersectsTriangle($t))return!0}}}else{const c=Te(o),d=Pe(o,a);return we(c,s,si),!!(i.intersectsBox(si)&&ls(c,e,t,n,i)||(we(d,s,si),i.intersectsBox(si)&&ls(d,e,t,n,i)))}}const oi=new _.Matrix4,cs=new Le,mn=new Le,$h=new _.Vector3,Hh=new _.Vector3,Jh=new _.Vector3,Qh=new _.Vector3;function eu(o,e,t,n={},i={},s=0,r=1/0){e.boundingBox||e.computeBoundingBox(),cs.set(e.boundingBox.min,e.boundingBox.max,t),cs.needsUpdate=!0;const a=o.geometry,l=a.attributes.position,h=a.index,c=e.attributes.position,d=e.index,m=We.getPrimitive(),p=We.getPrimitive();let f=$h,u=Hh,g=null,y=null;i&&(g=Jh,y=Qh);let w=1/0,x=null,v=null;return oi.copy(t).invert(),mn.matrix.copy(oi),o.shapecast({boundsTraverseOrder:b=>cs.distanceToBox(b),intersectsBounds:(b,D,T)=>T<w&&T<r?(D&&(mn.min.copy(b.min),mn.max.copy(b.max),mn.needsUpdate=!0),!0):!1,intersectsRange:(b,D)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:k=>mn.distanceToBox(k),intersectsBounds:(k,P,I)=>I<w&&I<r,intersectsRange:(k,P)=>{for(let I=k,z=k+P;I<z;I++){be(p,3*I,d,c),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let C=b,E=b+D;C<E;C++){be(m,3*C,h,l),m.needsUpdate=!0;const M=m.distanceToTriangle(p,f,g);if(M<w&&(u.copy(f),y&&y.copy(g),w=M,x=C,v=I),M<s)return!0}}}});{const T=Dt(e);for(let k=0,P=T;k<P;k++){be(p,3*k,d,c),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let I=b,z=b+D;I<z;I++){be(m,3*I,h,l),m.needsUpdate=!0;const C=m.distanceToTriangle(p,f,g);if(C<w&&(u.copy(f),y&&y.copy(g),w=C,x=I,v=k),C<s)return!0}}}}}),We.releasePrimitive(m),We.releasePrimitive(p),w===1/0?null:(n.point?n.point.copy(u):n.point=u.clone(),n.distance=w,n.faceIndex=x,i&&(i.point?i.point.copy(y):i.point=y.clone(),i.point.applyMatrix4(oi),u.applyMatrix4(oi),i.distance=u.sub(i.point).length(),i.faceIndex=v),n)}function tu(o,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=o.geometry,n=t.index?t.index.array:null,i=t.attributes.position;let s,r,a,l,h=0;const c=o._roots;for(let m=0,p=c.length;m<p;m++)s=c[m],r=new Uint32Array(s),a=new Uint16Array(s),l=new Float32Array(s),d(0,h),h+=s.byteLength;function d(m,p,f=!1){const u=m*2;if(Se(u,a)){const g=r[m+6],y=a[u+14];let w=1/0,x=1/0,v=1/0,b=-1/0,D=-1/0,T=-1/0;for(let k=g,P=g+y;k<P;k++){const I=3*o.resolveTriangleIndex(k);for(let z=0;z<3;z++){let C=I+z;C=n?n[C]:C;const E=i.getX(C),M=i.getY(C),B=i.getZ(C);E<w&&(w=E),E>b&&(b=E),M<x&&(x=M),M>D&&(D=M),B<v&&(v=B),B>T&&(T=B)}}return l[m+0]!==w||l[m+1]!==x||l[m+2]!==v||l[m+3]!==b||l[m+4]!==D||l[m+5]!==T?(l[m+0]=w,l[m+1]=x,l[m+2]=v,l[m+3]=b,l[m+4]=D,l[m+5]=T,!0):!1}else{const g=Te(m),y=Pe(m,r);let w=f,x=!1,v=!1;if(e){if(!w){const I=g/Me+p/Ie,z=y/Me+p/Ie;x=e.has(I),v=e.has(z),w=!x&&!v}}else x=!0,v=!0;const b=w||x,D=w||v;let T=!1;b&&(T=d(g,p,w));let k=!1;D&&(k=d(y,p,w));const P=T||k;if(P)for(let I=0;I<3;I++){const z=g+I,C=y+I,E=l[z],M=l[z+3],B=l[C],V=l[C+3];l[m+I]=E<B?E:B,l[m+I+3]=M>V?M:V}return P}}}function nu(o,e,t,n,i,s,r){me.setBuffer(o._roots[e]),hs(0,o,t,n,i,s,r),me.clearBuffer()}function hs(o,e,t,n,i,s,r){const{float32Array:a,uint16Array:l,uint32Array:h}=me,c=o*2;if(Se(c,l)){const m=Ue(o,h),p=Xe(c,l);Gh(e,t,n,m,p,i,s,r)}else{const m=Te(o);mt(m,a,n,s,r)&&hs(m,e,t,n,i,s,r);const p=Pe(o,h);mt(p,a,n,s,r)&&hs(p,e,t,n,i,s,r)}}const iu=["x","y","z"];function su(o,e,t,n,i,s){me.setBuffer(o._roots[e]);const r=us(0,o,t,n,i,s);return me.clearBuffer(),r}function us(o,e,t,n,i,s){const{float32Array:r,uint16Array:a,uint32Array:l}=me;let h=o*2;if(Se(h,a)){const d=Ue(o,l),m=Xe(h,a);return Wh(e,t,n,d,m,i,s)}else{const d=is(o,l),m=iu[d],f=n.direction[m]>=0;let u,g;f?(u=Te(o),g=Pe(o,l)):(u=Pe(o,l),g=Te(o));const w=mt(u,r,n,i,s)?us(u,e,t,n,i,s):null;if(w){const b=w.point[m];if(f?b<=r[g+d]:b>=r[g+d+3])return w}const v=mt(g,r,n,i,s)?us(g,e,t,n,i,s):null;return w&&v?w.distance<=v.distance?w:v:w||v||null}}const ai=new _.Box3,Ht=new Ge,Jt=new Ge,gn=new _.Matrix4,lo=new Le,li=new Le;function ru(o,e,t,n){me.setBuffer(o._roots[e]);const i=ds(0,o,t,n);return me.clearBuffer(),i}function ds(o,e,t,n,i=null){const{float32Array:s,uint16Array:r,uint32Array:a}=me;let l=o*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),lo.set(t.boundingBox.min,t.boundingBox.max,n),i=lo),Se(l,r)){const c=e.geometry,d=c.index,m=c.attributes.position,p=t.index,f=t.attributes.position,u=Ue(o,a),g=Xe(l,r);if(gn.copy(n).invert(),t.boundsTree)return we(o,s,li),li.matrix.copy(gn),li.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:w=>li.intersectsBox(w),intersectsTriangle:w=>{w.a.applyMatrix4(n),w.b.applyMatrix4(n),w.c.applyMatrix4(n),w.needsUpdate=!0;for(let x=u,v=g+u;x<v;x++)if(be(Jt,3*e.resolveTriangleIndex(x),d,m),Jt.needsUpdate=!0,w.intersectsTriangle(Jt))return!0;return!1}});{const y=Dt(t);for(let w=u,x=g+u;w<x;w++){const v=e.resolveTriangleIndex(w);be(Ht,3*v,d,m),Ht.a.applyMatrix4(gn),Ht.b.applyMatrix4(gn),Ht.c.applyMatrix4(gn),Ht.needsUpdate=!0;for(let b=0,D=y*3;b<D;b+=3)if(be(Jt,b,p,f),Jt.needsUpdate=!0,Ht.intersectsTriangle(Jt))return!0}}}else{const c=Te(o),d=Pe(o,a);return we(c,s,ai),!!(i.intersectsBox(ai)&&ds(c,e,t,n,i)||(we(d,s,ai),i.intersectsBox(ai)&&ds(d,e,t,n,i)))}}const ci=new _.Matrix4,fs=new Le,yn=new Le,ou=new _.Vector3,au=new _.Vector3,lu=new _.Vector3,cu=new _.Vector3;function hu(o,e,t,n={},i={},s=0,r=1/0){e.boundingBox||e.computeBoundingBox(),fs.set(e.boundingBox.min,e.boundingBox.max,t),fs.needsUpdate=!0;const a=o.geometry,l=a.attributes.position,h=a.index,c=e.attributes.position,d=e.index,m=We.getPrimitive(),p=We.getPrimitive();let f=ou,u=au,g=null,y=null;i&&(g=lu,y=cu);let w=1/0,x=null,v=null;return ci.copy(t).invert(),yn.matrix.copy(ci),o.shapecast({boundsTraverseOrder:b=>fs.distanceToBox(b),intersectsBounds:(b,D,T)=>T<w&&T<r?(D&&(yn.min.copy(b.min),yn.max.copy(b.max),yn.needsUpdate=!0),!0):!1,intersectsRange:(b,D)=>{if(e.boundsTree){const T=e.boundsTree;return T.shapecast({boundsTraverseOrder:k=>yn.distanceToBox(k),intersectsBounds:(k,P,I)=>I<w&&I<r,intersectsRange:(k,P)=>{for(let I=k,z=k+P;I<z;I++){const C=T.resolveTriangleIndex(I);be(p,3*C,d,c),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let E=b,M=b+D;E<M;E++){const B=o.resolveTriangleIndex(E);be(m,3*B,h,l),m.needsUpdate=!0;const V=m.distanceToTriangle(p,f,g);if(V<w&&(u.copy(f),y&&y.copy(g),w=V,x=E,v=I),V<s)return!0}}}})}else{const T=Dt(e);for(let k=0,P=T;k<P;k++){be(p,3*k,d,c),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let I=b,z=b+D;I<z;I++){const C=o.resolveTriangleIndex(I);be(m,3*C,h,l),m.needsUpdate=!0;const E=m.distanceToTriangle(p,f,g);if(E<w&&(u.copy(f),y&&y.copy(g),w=E,x=I,v=k),E<s)return!0}}}}}),We.releasePrimitive(m),We.releasePrimitive(p),w===1/0?null:(n.point?n.point.copy(u):n.point=u.clone(),n.distance=w,n.faceIndex=x,i&&(i.point?i.point.copy(y):i.point=y.clone(),i.point.applyMatrix4(ci),u.applyMatrix4(ci),i.distance=u.sub(i.point).length(),i.faceIndex=v),n)}function uu(){return typeof SharedArrayBuffer<"u"}const wn=new me.constructor,hi=new me.constructor,gt=new ns(()=>new _.Box3),Qt=new _.Box3,en=new _.Box3,ps=new _.Box3,ms=new _.Box3;let gs=!1;function du(o,e,t,n){if(gs)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");gs=!0;const i=o._roots,s=e._roots;let r,a=0,l=0;const h=new _.Matrix4().copy(t).invert();for(let c=0,d=i.length;c<d;c++){wn.setBuffer(i[c]),l=0;const m=gt.getPrimitive();we(0,wn.float32Array,m),m.applyMatrix4(h);for(let p=0,f=s.length;p<f&&(hi.setBuffer(s[p]),r=Ke(0,0,t,h,n,a,l,0,0,m),hi.clearBuffer(),l+=s[p].byteLength/Ie,!r);p++);if(gt.releasePrimitive(m),wn.clearBuffer(),a+=i[c].byteLength/Ie,r)break}return gs=!1,r}function Ke(o,e,t,n,i,s=0,r=0,a=0,l=0,h=null,c=!1){let d,m;c?(d=hi,m=wn):(d=wn,m=hi);const p=d.float32Array,f=d.uint32Array,u=d.uint16Array,g=m.float32Array,y=m.uint32Array,w=m.uint16Array,x=o*2,v=e*2,b=Se(x,u),D=Se(v,w);let T=!1;if(D&&b)c?T=i(Ue(e,y),Xe(e*2,w),Ue(o,f),Xe(o*2,u),l,r+e/Me,a,s+o/Me):T=i(Ue(o,f),Xe(o*2,u),Ue(e,y),Xe(e*2,w),a,s+o/Me,l,r+e/Me);else if(D){const k=gt.getPrimitive();we(e,g,k),k.applyMatrix4(t);const P=Te(o),I=Pe(o,f);we(P,p,Qt),we(I,p,en);const z=k.intersectsBox(Qt),C=k.intersectsBox(en);T=z&&Ke(e,P,n,t,i,r,s,l,a+1,k,!c)||C&&Ke(e,I,n,t,i,r,s,l,a+1,k,!c),gt.releasePrimitive(k)}else{const k=Te(e),P=Pe(e,y);we(k,g,ps),we(P,g,ms);const I=h.intersectsBox(ps),z=h.intersectsBox(ms);if(I&&z)T=Ke(o,k,t,n,i,s,r,a,l+1,h,c)||Ke(o,P,t,n,i,s,r,a,l+1,h,c);else if(I)if(b)T=Ke(o,k,t,n,i,s,r,a,l+1,h,c);else{const C=gt.getPrimitive();C.copy(ps).applyMatrix4(t);const E=Te(o),M=Pe(o,f);we(E,p,Qt),we(M,p,en);const B=C.intersectsBox(Qt),V=C.intersectsBox(en);T=B&&Ke(k,E,n,t,i,r,s,l,a+1,C,!c)||V&&Ke(k,M,n,t,i,r,s,l,a+1,C,!c),gt.releasePrimitive(C)}else if(z)if(b)T=Ke(o,P,t,n,i,s,r,a,l+1,h,c);else{const C=gt.getPrimitive();C.copy(ms).applyMatrix4(t);const E=Te(o),M=Pe(o,f);we(E,p,Qt),we(M,p,en);const B=C.intersectsBox(Qt),V=C.intersectsBox(en);T=B&&Ke(P,E,n,t,i,r,s,l,a+1,C,!c)||V&&Ke(P,M,n,t,i,r,s,l,a+1,C,!c),gt.releasePrimitive(C)}}return T}const ui=new Le,co=new _.Box3,fu={strategy:Gr,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class ys{static serialize(e,t={}){t={cloneBuffers:!0,...t};const n=e.geometry,i=e._roots,s=e._indirectBuffer,r=n.getIndex(),a={version:1,roots:null,index:null,indirectBuffer:null};return t.cloneBuffers?(a.roots=i.map(l=>l.slice()),a.index=r?r.array.slice():null,a.indirectBuffer=s?s.slice():null):(a.roots=i,a.index=r?r.array:null,a.indirectBuffer=s),a}static deserialize(e,t,n={}){n={setIndex:!0,indirect:!!e.indirectBuffer,...n};const{index:i,roots:s,indirectBuffer:r}=e;e.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),l(s));const a=new ys(t,{...n,[Yi]:!0});if(a._roots=s,a._indirectBuffer=r||null,n.setIndex){const h=t.getIndex();if(h===null){const c=new _.BufferAttribute(e.index,1,!1);t.setIndex(c)}else h.array!==i&&(h.array.set(i),h.needsUpdate=!0)}return a;function l(h){for(let c=0;c<h.length;c++){const d=h[c],m=new Uint32Array(d),p=new Uint16Array(d);for(let f=0,u=d.byteLength/Ie;f<u;f++){const g=Me*f,y=2*g;Se(y,p)||(m[g+6]=m[g+6]/Me-f)}}}}get indirect(){return!!this._indirectBuffer}constructor(e,t={}){if(e.isBufferGeometry){if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t=Object.assign({...fu,[Yi]:!1},t),t.useSharedArrayBuffer&&!uu())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[Yi]||(Dh(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new _.Box3))),this.resolveTriangleIndex=t.indirect?n=>this._indirectBuffer[n]:n=>n}shiftTriangleOffsets(e){const t=this._indirectBuffer;if(t)for(let n=0,i=t.length;n<i;n++)t[n]+=e;else{const n=this._roots;for(let i=0;i<n.length;i++){const s=n[i],r=new Uint32Array(s),a=new Uint16Array(s),l=s.byteLength/Ie;for(let h=0;h<l;h++){const c=Me*h,d=2*c;Se(d,a)&&(r[c+6]+=e)}}}}refit(e=null){return(this.indirect?tu:jh)(this,e)}traverse(e,t=0){const n=this._roots[t],i=new Uint32Array(n),s=new Uint16Array(n);r(0);function r(a,l=0){const h=a*2,c=Se(h,s);if(c){const d=i[a+6],m=s[h+14];e(l,c,new Float32Array(n,a*4,6),d,m)}else{const d=Te(a),m=Pe(a,i),p=is(a,i);e(l,c,new Float32Array(n,a*4,6),p)||(r(d,l+1),r(m,l+1))}}}raycast(e,t=_.FrontSide,n=0,i=1/0){const s=this._roots,r=[],a=this.indirect?nu:Zh;for(let l=0,h=s.length;l<h;l++)a(this,l,t,e,r,n,i);return r}raycastFirst(e,t=_.FrontSide,n=0,i=1/0){const s=this._roots;let r=null;const a=this.indirect?su:Kh;for(let l=0,h=s.length;l<h;l++){const c=a(this,l,t,e,n,i);c!=null&&(r==null||c.distance<r.distance)&&(r=c)}return r}intersectsGeometry(e,t){let n=!1;const i=this._roots,s=this.indirect?ru:Yh;for(let r=0,a=i.length;r<a&&(n=s(this,r,e,t),!n);r++);return n}shapecast(e){const t=We.getPrimitive(),n=this.indirect?Xh:Vh;let{boundsTraverseOrder:i,intersectsBounds:s,intersectsRange:r,intersectsTriangle:a}=e;if(r&&a){const d=r;r=(m,p,f,u,g)=>d(m,p,f,u,g)?!0:n(m,p,this,a,f,u,t)}else r||(a?r=(d,m,p,f)=>n(d,m,this,a,p,f,t):r=(d,m,p)=>p);let l=!1,h=0;const c=this._roots;for(let d=0,m=c.length;d<m;d++){const p=c[d];if(l=Oh(this,d,s,r,i,h),l)break;h+=p.byteLength/Ie}return We.releasePrimitive(t),l}bvhcast(e,t,n){let{intersectsRanges:i,intersectsTriangles:s}=n;const r=We.getPrimitive(),a=this.geometry.index,l=this.geometry.attributes.position,h=this.indirect?f=>{const u=this.resolveTriangleIndex(f);be(r,u*3,a,l)}:f=>{be(r,f*3,a,l)},c=We.getPrimitive(),d=e.geometry.index,m=e.geometry.attributes.position,p=e.indirect?f=>{const u=e.resolveTriangleIndex(f);be(c,u*3,d,m)}:f=>{be(c,f*3,d,m)};if(s){const f=(u,g,y,w,x,v,b,D)=>{for(let T=y,k=y+w;T<k;T++){p(T),c.a.applyMatrix4(t),c.b.applyMatrix4(t),c.c.applyMatrix4(t),c.needsUpdate=!0;for(let P=u,I=u+g;P<I;P++)if(h(P),r.needsUpdate=!0,s(r,c,P,T,x,v,b,D))return!0}return!1};if(i){const u=i;i=function(g,y,w,x,v,b,D,T){return u(g,y,w,x,v,b,D,T)?!0:f(g,y,w,x,v,b,D,T)}}else i=f}return du(this,e,t,i)}intersectsBox(e,t){return ui.set(e.min,e.max,t),ui.needsUpdate=!0,this.shapecast({intersectsBounds:n=>ui.intersectsBox(n),intersectsTriangle:n=>ui.intersectsTriangle(n)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,n={},i={},s=0,r=1/0){return(this.indirect?hu:eu)(this,e,t,n,i,s,r)}closestPointToPoint(e,t={},n=0,i=1/0){return zh(this,e,t,n,i)}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(n=>{we(0,new Float32Array(n),co),e.union(co)}),e}}const ho=1e-6,pu=ho*.5,uo=Math.pow(10,-Math.log10(ho)),mu=pu*uo;function tt(o){return~~(o*uo+mu)}function gu(o){return`${tt(o.x)},${tt(o.y)}`}function fo(o){return`${tt(o.x)},${tt(o.y)},${tt(o.z)}`}function yu(o){return`${tt(o.x)},${tt(o.y)},${tt(o.z)},${tt(o.w)}`}function wu(o,e,t){t.direction.subVectors(e,o).normalize();const n=o.dot(t.direction);return t.origin.copy(o).addScaledVector(t.direction,-n),t}function po(){return typeof SharedArrayBuffer<"u"}function xu(o){if(o.buffer instanceof SharedArrayBuffer)return o;const e=o.constructor,t=o.buffer,n=new SharedArrayBuffer(t.byteLength),i=new Uint8Array(t);return new Uint8Array(n).set(i,0),new e(n)}function vu(o,e=ArrayBuffer){return o>65535?new Uint32Array(new e(4*o)):new Uint16Array(new e(2*o))}function bu(o,e){if(!o.index){const t=o.attributes.position.count,n=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=vu(t,n);o.setIndex(new _.BufferAttribute(i,1));for(let s=0;s<t;s++)i[s]=s}}function _u(o){return o.index?o.index.count:o.attributes.position.count}function ws(o){return _u(o)/3}const Mu=1e-8,Su=new _.Vector3;function Au(o){return~~(o/3)}function Cu(o){return o%3}function mo(o,e){return o.start-e.start}function go(o,e){return Su.subVectors(e,o.origin).dot(o.direction)}function Tu(o,e,t,n=Mu){o.sort(mo),e.sort(mo);for(let a=0;a<o.length;a++){const l=o[a];for(let h=0;h<e.length;h++){const c=e[h];if(!(c.start>l.end)){if(l.end<c.start||c.end<l.start)continue;if(l.start<=c.start&&l.end>=c.end)s(c.end,l.end)||o.splice(a+1,0,{start:c.end,end:l.end,index:l.index}),l.end=c.start,c.start=0,c.end=0;else if(l.start>=c.start&&l.end<=c.end)s(l.end,c.end)||e.splice(h+1,0,{start:l.end,end:c.end,index:c.index}),c.end=l.start,l.start=0,l.end=0;else if(l.start<=c.start&&l.end<=c.end){const d=l.end;l.end=c.start,c.start=d}else if(l.start>=c.start&&l.end>=c.end){const d=c.end;c.end=l.start,l.start=d}else throw new Error}if(t.has(l.index)||t.set(l.index,[]),t.has(c.index)||t.set(c.index,[]),t.get(l.index).push(c.index),t.get(c.index).push(l.index),r(c)&&(e.splice(h,1),h--),r(l)){o.splice(a,1),a--;break}}}i(o),i(e);function i(a){for(let l=0;l<a.length;l++)r(a[l])&&(a.splice(l,1),l--)}function s(a,l){return Math.abs(l-a)<n}function r(a){return Math.abs(a.end-a.start)<n}}const yo=1e-5,wo=1e-4;class Pu{constructor(){this._rays=[]}addRay(e){this._rays.push(e)}findClosestRay(e){const t=this._rays,n=e.clone();n.direction.multiplyScalar(-1);let i=1/0,s=null;for(let l=0,h=t.length;l<h;l++){const c=t[l];if(r(c,e)&&r(c,n))continue;const d=a(c,e),m=a(c,n),p=Math.min(d,m);p<i&&(i=p,s=c)}return s;function r(l,h){const c=l.origin.distanceTo(h.origin)>yo;return l.direction.angleTo(h.direction)>wo||c}function a(l,h){const c=l.origin.distanceTo(h.origin),d=l.direction.angleTo(h.direction);return c/yo+d/wo}}}const xs=new _.Vector3,vs=new _.Vector3,di=new _.Ray;function Du(o,e,t){const n=o.attributes,i=o.index,s=n.position,r=new Map,a=new Map,l=Array.from(e),h=new Pu;for(let c=0,d=l.length;c<d;c++){const m=l[c],p=Au(m),f=Cu(m);let u=3*p+f,g=3*p+(f+1)%3;i&&(u=i.getX(u),g=i.getX(g)),xs.fromBufferAttribute(s,u),vs.fromBufferAttribute(s,g),wu(xs,vs,di);let y,w=h.findClosestRay(di);w===null&&(w=di.clone(),h.addRay(w)),a.has(w)||a.set(w,{forward:[],reverse:[],ray:w}),y=a.get(w);let x=go(w,xs),v=go(w,vs);x>v&&([x,v]=[v,x]),di.direction.dot(w.direction)<0?y.reverse.push({start:x,end:v,index:m}):y.forward.push({start:x,end:v,index:m})}return a.forEach(({forward:c,reverse:d},m)=>{Tu(c,d,r,t),c.length===0&&d.length===0&&a.delete(m)}),{disjointConnectivityMap:r,fragmentMap:a}}const ku=new _.Vector2,bs=new _.Vector3,Iu=new _.Vector4,_s=["","",""];class Lu{constructor(e=null){this.data=null,this.disjointConnections=null,this.unmatchedDisjointEdges=null,this.unmatchedEdges=-1,this.matchedEdges=-1,this.useDrawRange=!0,this.useAllAttributes=!1,this.matchDisjointEdges=!1,this.degenerateEpsilon=1e-8,e&&this.updateFrom(e)}getSiblingTriangleIndex(e,t){const n=this.data[e*3+t];return n===-1?-1:~~(n/3)}getSiblingEdgeIndex(e,t){const n=this.data[e*3+t];return n===-1?-1:n%3}getDisjointSiblingTriangleIndices(e,t){const n=e*3+t,i=this.disjointConnections.get(n);return i?i.map(s=>~~(s/3)):[]}getDisjointSiblingEdgeIndices(e,t){const n=e*3+t,i=this.disjointConnections.get(n);return i?i.map(s=>s%3):[]}isFullyConnected(){return this.unmatchedEdges===0}updateFrom(e){const{useAllAttributes:t,useDrawRange:n,matchDisjointEdges:i,degenerateEpsilon:s}=this,r=t?x:w,a=new Map,{attributes:l}=e,h=t?Object.keys(l):null,c=e.index,d=l.position;let m=ws(e);const p=m;let f=0;n&&(f=e.drawRange.start,e.drawRange.count!==1/0&&(m=~~(e.drawRange.count/3)));let u=this.data;(!u||u.length<3*p)&&(u=new Int32Array(3*p)),u.fill(-1);let g=0,y=new Set;for(let v=f,b=m*3+f;v<b;v+=3){const D=v;for(let T=0;T<3;T++){let k=D+T;c&&(k=c.getX(k)),_s[T]=r(k)}for(let T=0;T<3;T++){const k=(T+1)%3,P=_s[T],I=_s[k],z=`${I}_${P}`;if(a.has(z)){const C=D+T,E=a.get(z);u[C]=E,u[E]=C,a.delete(z),g+=2,y.delete(E)}else{const C=`${P}_${I}`,E=D+T;a.set(C,E),y.add(E)}}}if(i){const{fragmentMap:v,disjointConnectivityMap:b}=Du(e,y,s);y.clear(),v.forEach(({forward:D,reverse:T})=>{D.forEach(({index:k})=>y.add(k)),T.forEach(({index:k})=>y.add(k))}),this.unmatchedDisjointEdges=v,this.disjointConnections=b,g=m*3-y.size}this.matchedEdges=g,this.unmatchedEdges=y.size,this.data=u;function w(v){return bs.fromBufferAttribute(d,v),fo(bs)}function x(v){let b="";for(let D=0,T=h.length;D<T;D++){const k=l[h[D]];let P;switch(k.itemSize){case 1:P=tt(k.getX(v));break;case 2:P=gu(ku.fromBufferAttribute(k,v));break;case 3:P=fo(bs.fromBufferAttribute(k,v));break;case 4:P=yu(Iu.fromBufferAttribute(k,v));break}b!==""&&(b+="|"),b+=P}return b}}}class fi extends _.Mesh{constructor(...e){super(...e),this.isBrush=!0,this._previousMatrix=new _.Matrix4,this._previousMatrix.elements.fill(0)}markUpdated(){this._previousMatrix.copy(this.matrix)}isDirty(){const{matrix:e,_previousMatrix:t}=this,n=e.elements,i=t.elements;for(let s=0;s<16;s++)if(n[s]!==i[s])return!0;return!1}prepareGeometry(){const e=this.geometry,t=e.attributes,n=po();if(n)for(const i in t){const s=t[i];if(s.isInterleavedBufferAttribute)throw new Error("Brush: InterleavedBufferAttributes are not supported.");s.array=xu(s.array)}if(e.boundsTree||(bu(e,{useSharedArrayBuffer:n}),e.boundsTree=new ys(e,{maxLeafTris:3,indirect:!0,useSharedArrayBuffer:n})),e.halfEdges||(e.halfEdges=new Lu(e)),!e.groupIndices){const i=ws(e),s=new Uint16Array(i),r=e.groups;for(let a=0,l=r.length;a<l;a++){const{start:h,count:c}=r[a];for(let d=h/3,m=(h+c)/3;d<m;d++)s[d]=a}e.groupIndices=s}}disposeCacheData(){const{geometry:e}=this;e.halfEdges=null,e.boundsTree=null,e.groupIndices=null}}const Eu=1e-14,Ms=new _.Vector3,xo=new _.Vector3,vo=new _.Vector3;function yt(o,e=Eu){Ms.subVectors(o.b,o.a),xo.subVectors(o.c,o.a),vo.subVectors(o.b,o.c);const t=Ms.angleTo(xo),n=Ms.angleTo(vo),i=Math.PI-t-n;return Math.abs(t)<e||Math.abs(n)<e||Math.abs(i)<e||o.a.distanceToSquared(o.b)<e||o.a.distanceToSquared(o.c)<e||o.b.distanceToSquared(o.c)<e}const Ss=1e-10,xn=1e-10,Bu=1e-10,lt=new _.Line3,xe=new _.Line3,ct=new _.Vector3,As=new _.Vector3,bo=new _.Vector3,pi=new _.Plane,Cs=new Ge;class Ou{constructor(){this._pool=[],this._index=0}getTriangle(){return this._index>=this._pool.length&&this._pool.push(new _.Triangle),this._pool[this._index++]}clear(){this._index=0}reset(){this._pool.length=0,this._index=0}}class zu{constructor(){this.trianglePool=new Ou,this.triangles=[],this.normal=new _.Vector3,this.coplanarTriangleUsed=!1}initialize(e){this.reset();const{triangles:t,trianglePool:n,normal:i}=this;if(Array.isArray(e))for(let s=0,r=e.length;s<r;s++){const a=e[s];if(s===0)a.getNormal(i);else if(Math.abs(1-a.getNormal(ct).dot(i))>Ss)throw new Error("Triangle Splitter: Cannot initialize with triangles that have different normals.");const l=n.getTriangle();l.copy(a),t.push(l)}else{e.getNormal(i);const s=n.getTriangle();s.copy(e),t.push(s)}}splitByTriangle(e){const{normal:t,triangles:n}=this;if(e.getNormal(As).normalize(),Math.abs(1-Math.abs(As.dot(t)))<Bu){this.coplanarTriangleUsed=!0;for(let s=0,r=n.length;s<r;s++){const a=n[s];a.coplanarCount=0}const i=[e.a,e.b,e.c];for(let s=0;s<3;s++){const r=(s+1)%3,a=i[s],l=i[r];ct.subVectors(l,a).normalize(),bo.crossVectors(As,ct),pi.setFromNormalAndCoplanarPoint(bo,a),this.splitByPlane(pi,e)}}else e.getPlane(pi),this.splitByPlane(pi,e)}splitByPlane(e,t){const{triangles:n,trianglePool:i}=this;Cs.copy(t),Cs.needsUpdate=!0;for(let s=0,r=n.length;s<r;s++){const a=n[s];if(!Cs.intersectsTriangle(a,lt,!0))continue;const{a:l,b:h,c}=a;let d=0,m=-1,p=!1,f=[],u=[];const g=[l,h,c];for(let y=0;y<3;y++){const w=(y+1)%3;lt.start.copy(g[y]),lt.end.copy(g[w]);const x=e.distanceToPoint(lt.start),v=e.distanceToPoint(lt.end);if(Math.abs(x)<xn&&Math.abs(v)<xn){p=!0;break}if(x>0?f.push(y):u.push(y),Math.abs(x)<xn)continue;let b=!!e.intersectLine(lt,ct);!b&&Math.abs(v)<xn&&(ct.copy(lt.end),b=!0),b&&!(ct.distanceTo(lt.start)<Ss)&&(ct.distanceTo(lt.end)<Ss&&(m=y),d===0?xe.start.copy(ct):xe.end.copy(ct),d++)}if(!p&&d===2&&xe.distance()>xn)if(m!==-1){m=(m+1)%3;let y=0;y===m&&(y=(y+1)%3);let w=y+1;w===m&&(w=(w+1)%3);const x=i.getTriangle();x.a.copy(g[w]),x.b.copy(xe.end),x.c.copy(xe.start),yt(x)||n.push(x),a.a.copy(g[y]),a.b.copy(xe.start),a.c.copy(xe.end),yt(a)&&(n.splice(s,1),s--,r--)}else{const y=f.length>=2?u[0]:f[0];if(y===0){let D=xe.start;xe.start=xe.end,xe.end=D}const w=(y+1)%3,x=(y+2)%3,v=i.getTriangle(),b=i.getTriangle();g[w].distanceToSquared(xe.start)<g[x].distanceToSquared(xe.end)?(v.a.copy(g[w]),v.b.copy(xe.start),v.c.copy(xe.end),b.a.copy(g[w]),b.b.copy(g[x]),b.c.copy(xe.start)):(v.a.copy(g[x]),v.b.copy(xe.start),v.c.copy(xe.end),b.a.copy(g[w]),b.b.copy(g[x]),b.c.copy(xe.end)),a.a.copy(g[y]),a.b.copy(xe.end),a.c.copy(xe.start),yt(v)||n.push(v),yt(b)||n.push(b),yt(a)&&(n.splice(s,1),s--,r--)}else d===3&&console.warn("TriangleClipper: Coplanar clip not handled")}}reset(){this.triangles.length=0,this.trianglePool.clear(),this.coplanarTriangleUsed=!1}}function Nu(o){return o=~~o,o+4-o%4}class _o{constructor(e,t=500){this.expansionFactor=1.5,this.type=e,this.length=0,this.array=null,this.setSize(t)}setType(e){if(this.length!==0)throw new Error("TypeBackedArray: Cannot change the type while there is used data in the buffer.");const t=this.array.buffer;this.array=new e(t),this.type=e}setSize(e){if(this.array&&e===this.array.length)return;const t=this.type,n=po()?SharedArrayBuffer:ArrayBuffer,i=new t(new n(Nu(e*t.BYTES_PER_ELEMENT)));this.array&&i.set(this.array,0),this.array=i}expand(){const{array:e,expansionFactor:t}=this;this.setSize(e.length*t)}push(...e){let{array:t,length:n}=this;n+e.length>t.length&&(this.expand(),t=this.array);for(let i=0,s=e.length;i<s;i++)t[n+i]=e[i];this.length+=e.length}clear(){this.length=0}}class Ru{constructor(){this.groupAttributes=[{}],this.groupCount=0}getType(e){return this.groupAttributes[0][e].type}getItemSize(e){return this.groupAttributes[0][e].itemSize}getNormalized(e){return this.groupAttributes[0][e].normalized}getCount(e){if(this.groupCount<=e)return 0;const t=this.getGroupAttrArray("position",e);return t.length/t.itemSize}getTotalLength(e){const{groupCount:t,groupAttributes:n}=this;let i=0;for(let s=0;s<t;s++){const r=n[s];i+=r[e].length}return i}getGroupAttrSet(e=0){const{groupAttributes:t}=this;if(t[e])return this.groupCount=Math.max(this.groupCount,e+1),t[e];const n=t[0];for(this.groupCount=Math.max(this.groupCount,e+1);e>=t.length;){const i={};t.push(i);for(const s in n){const r=n[s],a=new _o(r.type);a.itemSize=r.itemSize,a.normalized=r.normalized,i[s]=a}}return t[e]}getGroupAttrArray(e,t=0){const{groupAttributes:n}=this;if(!n[0][e])throw new Error(`TypedAttributeData: Attribute with "${e}" has not been initialized`);return this.getGroupAttrSet(t)[e]}initializeArray(e,t,n,i){const{groupAttributes:s}=this,a=s[0][e];if(a){if(a.type!==t)for(let l=0,h=s.length;l<h;l++){const c=s[l][e];c.setType(t),c.itemSize=n,c.normalized=i}}else for(let l=0,h=s.length;l<h;l++){const c=new _o(t);c.itemSize=n,c.normalized=i,s[l][e]=c}}clear(){this.groupCount=0;const{groupAttributes:e}=this;e.forEach(t=>{for(const n in t)t[n].clear()})}delete(e){this.groupAttributes.forEach(t=>{delete t[e]})}reset(){this.groupAttributes=[],this.groupCount=0}}class Mo{constructor(){this.intersectionSet={},this.ids=[]}add(e,t){const{intersectionSet:n,ids:i}=this;n[e]||(n[e]=[],i.push(e)),n[e].push(t)}}const Fu=0,Uu=1,Vu=2,So=3,ju=4,Ao=5,Co=6,Ze=new _.Ray,To=new _.Matrix4,Ee=new _.Triangle,ht=new _.Vector3,Po=new _.Vector4,Do=new _.Vector4,ko=new _.Vector4,Ts=new _.Vector4,mi=new _.Vector4,gi=new _.Vector4,Io=new _.Line3,Ps=new _.Vector3,Ds=1e-8,Gu=1e-15,Et=-1,Bt=1,yi=-2,wi=2,vn=0,Ot=1,ks=2,Wu=1e-14;let xi=null;function Lo(o){xi=o}function Eo(o,e){o.getMidpoint(Ze.origin),o.getNormal(Ze.direction);const t=e.raycastFirst(Ze,_.DoubleSide);return!!(t&&Ze.direction.dot(t.face.normal)>0)?Et:Bt}function Xu(o,e){function t(){return Math.random()-.5}o.getNormal(Ps),Ze.direction.copy(Ps),o.getMidpoint(Ze.origin);const n=3;let i=0,s=1/0;for(let r=0;r<n;r++){Ze.direction.x+=t()*Ds,Ze.direction.y+=t()*Ds,Ze.direction.z+=t()*Ds,Ze.direction.multiplyScalar(-1);const a=e.raycastFirst(Ze,_.DoubleSide);if(!!(a&&Ze.direction.dot(a.face.normal)>0)&&i++,a!==null&&(s=Math.min(s,a.distance)),s<=Gu)return a.face.normal.dot(Ps)>0?wi:yi;if(i/n>.5||(r-i+1)/n>.5)break}return i/n>.5?Et:Bt}function Zu(o,e){const t=new Mo,n=new Mo;return To.copy(o.matrixWorld).invert().multiply(e.matrixWorld),o.geometry.boundsTree.bvhcast(e.geometry.boundsTree,To,{intersectsTriangles(i,s,r,a){if(!yt(i)&&!yt(s)){let l=i.intersectsTriangle(s,Io,!0);if(!l){const h=i.plane,c=s.plane,d=h.normal,m=c.normal;d.dot(m)===1&&Math.abs(h.constant-c.constant)<Wu&&(l=!0)}if(l){let h=o.geometry.boundsTree.resolveTriangleIndex(r),c=e.geometry.boundsTree.resolveTriangleIndex(a);t.add(h,c),n.add(c,h),xi&&(xi.addEdge(Io),xi.addIntersectingTriangles(r,i,a,s))}}return!1}}),{aIntersections:t,bIntersections:n}}function qu(o,e,t,n,i,s,r=!1){const a=t.attributes,l=t.index,h=o*3,c=l.getX(h+0),d=l.getX(h+1),m=l.getX(h+2);for(const p in s){const f=a[p],u=s[p];if(!(p in a))throw new Error(`CSG Operations: Attribute ${p} not available on geometry.`);const g=f.itemSize;p==="position"?(Ee.a.fromBufferAttribute(f,c).applyMatrix4(n),Ee.b.fromBufferAttribute(f,d).applyMatrix4(n),Ee.c.fromBufferAttribute(f,m).applyMatrix4(n),Is(Ee.a,Ee.b,Ee.c,e,3,u,r)):p==="normal"?(Ee.a.fromBufferAttribute(f,c).applyNormalMatrix(i),Ee.b.fromBufferAttribute(f,d).applyNormalMatrix(i),Ee.c.fromBufferAttribute(f,m).applyNormalMatrix(i),r&&(Ee.a.multiplyScalar(-1),Ee.b.multiplyScalar(-1),Ee.c.multiplyScalar(-1)),Is(Ee.a,Ee.b,Ee.c,e,3,u,r,!0)):(Po.fromBufferAttribute(f,c),Do.fromBufferAttribute(f,d),ko.fromBufferAttribute(f,m),Is(Po,Do,ko,e,g,u,r))}}function Ku(o,e,t,n,i,s,r,a=!1){Ls(o,n,i,s,r,a),Ls(a?t:e,n,i,s,r,a),Ls(a?e:t,n,i,s,r,a)}function Bo(o,e,t=!1){switch(o){case Fu:if(e===Bt||e===wi&&!t)return Ot;break;case Uu:if(t){if(e===Et)return vn}else if(e===Bt||e===yi)return Ot;break;case Vu:if(t){if(e===Bt||e===yi)return Ot}else if(e===Et)return vn;break;case ju:if(e===Et)return vn;if(e===Bt)return Ot;break;case So:if(e===Et||e===wi&&!t)return Ot;break;case Ao:if(!t&&(e===Bt||e===yi))return Ot;break;case Co:if(!t&&(e===Et||e===wi))return Ot;break;default:throw new Error(`Unrecognized CSG operation enum "${o}".`)}return ks}function Is(o,e,t,n,i,s,r=!1,a=!1){const l=h=>{s.push(h.x),i>1&&s.push(h.y),i>2&&s.push(h.z),i>3&&s.push(h.w)};Ts.set(0,0,0,0).addScaledVector(o,n.a.x).addScaledVector(e,n.a.y).addScaledVector(t,n.a.z),mi.set(0,0,0,0).addScaledVector(o,n.b.x).addScaledVector(e,n.b.y).addScaledVector(t,n.b.z),gi.set(0,0,0,0).addScaledVector(o,n.c.x).addScaledVector(e,n.c.y).addScaledVector(t,n.c.z),a&&(Ts.normalize(),mi.normalize(),gi.normalize()),l(Ts),r?(l(gi),l(mi)):(l(mi),l(gi))}function Ls(o,e,t,n,i,s=!1){for(const r in i){const a=e[r],l=i[r];if(!(r in e))throw new Error(`CSG Operations: Attribute ${r} no available on geometry.`);const h=a.itemSize;r==="position"?(ht.fromBufferAttribute(a,o).applyMatrix4(t),l.push(ht.x,ht.y,ht.z)):r==="normal"?(ht.fromBufferAttribute(a,o).applyNormalMatrix(n),s&&ht.multiplyScalar(-1),l.push(ht.x,ht.y,ht.z)):(l.push(a.getX(o)),h>1&&l.push(a.getY(o)),h>2&&l.push(a.getZ(o)),h>3&&l.push(a.getW(o)))}}class Yu{constructor(e){this.triangle=new _.Triangle().copy(e),this.intersects={}}addTriangle(e,t){this.intersects[e]=new _.Triangle().copy(t)}getIntersectArray(){const e=[],{intersects:t}=this;for(const n in t)e.push(t[n]);return e}}class Oo{constructor(){this.data={}}addTriangleIntersection(e,t,n,i){const{data:s}=this;s[e]||(s[e]=new Yu(t)),s[e].addTriangle(n,i)}getTrianglesAsArray(e=null){const{data:t}=this,n=[];if(e!==null)e in t&&n.push(t[e].triangle);else for(const i in t)n.push(t[i].triangle);return n}getTriangleIndices(){return Object.keys(this.data).map(e=>parseInt(e))}getIntersectionIndices(e){const{data:t}=this;return t[e]?Object.keys(t[e].intersects).map(n=>parseInt(n)):[]}getIntersectionsAsArray(e=null,t=null){const{data:n}=this,i=new Set,s=[],r=a=>{if(n[a])if(t!==null)n[a].intersects[t]&&s.push(n[a].intersects[t]);else{const l=n[a].intersects;for(const h in l)i.has(h)||(i.add(h),s.push(l[h]))}};if(e!==null)r(e);else for(const a in n)r(a);return s}reset(){this.data={}}}class $u{constructor(){this.enabled=!1,this.triangleIntersectsA=new Oo,this.triangleIntersectsB=new Oo,this.intersectionEdges=[]}addIntersectingTriangles(e,t,n,i){const{triangleIntersectsA:s,triangleIntersectsB:r}=this;s.addTriangleIntersection(e,t,n,i),r.addTriangleIntersection(n,i,e,t)}addEdge(e){this.intersectionEdges.push(e.clone())}reset(){this.triangleIntersectsA.reset(),this.triangleIntersectsB.reset(),this.intersectionEdges=[]}init(){this.enabled&&(this.reset(),Lo(this))}complete(){this.enabled&&Lo(null)}}const wt=new _.Matrix4,vi=new _.Matrix3,zt=new _.Triangle,bi=new _.Triangle,xt=new _.Triangle,_i=new _.Triangle,Ye=[],Nt=[];function Hu(o){for(const e of o)return e}function Ju(o,e,t,n,i,s={}){const{useGroups:r=!0}=s,{aIntersections:a,bIntersections:l}=Zu(o,e),h=[];let c=null,d;return d=r?0:-1,zo(o,e,a,t,!1,n,i,d),No(o,e,a,t,!1,i,d),t.findIndex(p=>p!==Co&&p!==Ao)!==-1&&(d=r?o.geometry.groups.length||1:-1,zo(e,o,l,t,!0,n,i,d),No(e,o,l,t,!0,i,d)),Ye.length=0,Nt.length=0,{groups:h,materials:c}}function zo(o,e,t,n,i,s,r,a=0){const l=o.matrixWorld.determinant()<0;wt.copy(e.matrixWorld).invert().multiply(o.matrixWorld),vi.getNormalMatrix(o.matrixWorld).multiplyScalar(l?-1:1);const h=o.geometry.groupIndices,c=o.geometry.index,d=o.geometry.attributes.position,m=e.geometry.boundsTree,p=e.geometry.index,f=e.geometry.attributes.position,u=t.ids,g=t.intersectionSet;for(let y=0,w=u.length;y<w;y++){const x=u[y],v=a===-1?0:h[x]+a,b=3*x,D=c.getX(b+0),T=c.getX(b+1),k=c.getX(b+2);zt.a.fromBufferAttribute(d,D).applyMatrix4(wt),zt.b.fromBufferAttribute(d,T).applyMatrix4(wt),zt.c.fromBufferAttribute(d,k).applyMatrix4(wt),s.reset(),s.initialize(zt);const P=g[x];for(let z=0,C=P.length;z<C;z++){const E=3*P[z],M=p.getX(E+0),B=p.getX(E+1),V=p.getX(E+2);bi.a.fromBufferAttribute(f,M),bi.b.fromBufferAttribute(f,B),bi.c.fromBufferAttribute(f,V),s.splitByTriangle(bi)}const I=s.triangles;for(let z=0,C=I.length;z<C;z++){const E=I[z],M=s.coplanarTriangleUsed?Xu(E,m):Eo(E,m);Ye.length=0,Nt.length=0;for(let B=0,V=n.length;B<V;B++){const U=Bo(n[B],M,i);U!==ks&&(Nt.push(U),Ye.push(r[B].getGroupAttrSet(v)))}if(Ye.length!==0){zt.getBarycoord(E.a,_i.a),zt.getBarycoord(E.b,_i.b),zt.getBarycoord(E.c,_i.c);for(let B=0,V=Ye.length;B<V;B++){const U=Ye[B],G=Nt[B]===vn;qu(x,_i,o.geometry,o.matrixWorld,vi,U,l!==G)}}}}return u.length}function No(o,e,t,n,i,s,r=0){const a=o.matrixWorld.determinant()<0;wt.copy(e.matrixWorld).invert().multiply(o.matrixWorld),vi.getNormalMatrix(o.matrixWorld).multiplyScalar(a?-1:1);const l=e.geometry.boundsTree,h=o.geometry.groupIndices,c=o.geometry.index,d=o.geometry.attributes,m=d.position,p=[],f=o.geometry.halfEdges,u=new Set,g=ws(o.geometry);for(let y=0,w=g;y<w;y++)y in t.intersectionSet||u.add(y);for(;u.size>0;){const y=Hu(u);u.delete(y),p.push(y);const w=3*y,x=c.getX(w+0),v=c.getX(w+1),b=c.getX(w+2);xt.a.fromBufferAttribute(m,x).applyMatrix4(wt),xt.b.fromBufferAttribute(m,v).applyMatrix4(wt),xt.c.fromBufferAttribute(m,b).applyMatrix4(wt);const D=Eo(xt,l);Nt.length=0,Ye.length=0;for(let T=0,k=n.length;T<k;T++){const P=Bo(n[T],D,i);P!==ks&&(Nt.push(P),Ye.push(s[T]))}for(;p.length>0;){const T=p.pop();for(let k=0;k<3;k++){const P=f.getSiblingTriangleIndex(T,k);P!==-1&&u.has(P)&&(p.push(P),u.delete(P))}if(Ye.length!==0){const k=3*T,P=c.getX(k+0),I=c.getX(k+1),z=c.getX(k+2),C=r===-1?0:h[T]+r;if(xt.a.fromBufferAttribute(m,P),xt.b.fromBufferAttribute(m,I),xt.c.fromBufferAttribute(m,z),!yt(xt))for(let E=0,M=Ye.length;E<M;E++){const B=Nt[E],V=Ye[E].getGroupAttrSet(C),U=B===vn;Ku(P,I,z,d,o.matrixWorld,vi,V,U!==a)}}}}}function Qu(o){for(let e=0;e<o.length-1;e++){const t=o[e],n=o[e+1];if(t.materialIndex===n.materialIndex){const i=t.start,s=n.start+n.count;n.start=i,n.count=s-i,o.splice(e,1),e--}}}function ed(o,e,t,n){t.clear();const i=o.attributes;for(let s=0,r=n.length;s<r;s++){const a=n[s],l=i[a];t.initializeArray(a,l.array.constructor,l.itemSize,l.normalized)}for(const s in t.attributes)n.includes(s)||t.delete(s);for(const s in e.attributes)n.includes(s)||(e.deleteAttribute(s),e.dispose())}function td(o,e,t){let n=!1,i=-1;const s=o.attributes,r=e.groupAttributes[0];for(const l in r){const h=e.getTotalLength(l),c=e.getType(l),d=e.getItemSize(l),m=e.getNormalized(l);let p=s[l];(!p||p.array.length<h)&&(p=new _.BufferAttribute(new c(h),d,m),o.setAttribute(l,p),n=!0);let f=0;for(let u=0,g=Math.min(t.length,e.groupCount);u<g;u++){const y=t[u].index,{array:w,type:x,length:v}=e.groupAttributes[y][l],b=new x(w.buffer,0,v);p.array.set(b,f),f+=b.length}p.needsUpdate=!0,i=h/p.itemSize}if(o.index){const l=o.index.array;if(l.length<i)o.index=null,n=!0;else for(let h=0,c=l.length;h<c;h++)l[h]=h}let a=0;o.clearGroups();for(let l=0,h=Math.min(t.length,e.groupCount);l<h;l++){const{index:c,materialIndex:d}=t[l],m=e.getCount(c);m!==0&&(o.addGroup(a,m,d),a+=m)}o.setDrawRange(0,i),o.boundsTree=null,n&&o.dispose()}function Ro(o,e){let t=e;return Array.isArray(e)||(t=[],o.forEach(n=>{t[n.materialIndex]=e})),t}class nd{constructor(){this.triangleSplitter=new zu,this.attributeData=[],this.attributes=["position","uv","normal"],this.useGroups=!0,this.consolidateGroups=!0,this.debug=new $u}getGroupRanges(e){return!this.useGroups||e.groups.length===0?[{start:0,count:1/0,materialIndex:0}]:e.groups.map(t=>({...t}))}evaluate(e,t,n,i=new fi){let s=!0;if(Array.isArray(n)||(n=[n]),Array.isArray(i)||(i=[i],s=!1),i.length!==n.length)throw new Error("Evaluator: operations and target array passed as different sizes.");e.prepareGeometry(),t.prepareGeometry();const{triangleSplitter:r,attributeData:a,attributes:l,useGroups:h,consolidateGroups:c,debug:d}=this;for(;a.length<i.length;)a.push(new Ru);i.forEach((y,w)=>{ed(e.geometry,y.geometry,a[w],l)}),d.init(),Ju(e,t,n,r,a,{useGroups:h}),d.complete();const m=this.getGroupRanges(e.geometry),p=Ro(m,e.material),f=this.getGroupRanges(t.geometry),u=Ro(f,t.material);f.forEach(y=>y.materialIndex+=p.length);let g=[...m,...f].map((y,w)=>({...y,index:w}));if(h){const y=[...p,...u];c&&(g=g.map(x=>{const v=y[x.materialIndex];return x.materialIndex=y.indexOf(v),x}).sort((x,v)=>x.materialIndex-v.materialIndex));const w=[];for(let x=0,v=y.length;x<v;x++){let b=!1;for(let D=0,T=g.length;D<T;D++){const k=g[D];k.materialIndex===x&&(b=!0,k.materialIndex=w.length)}b&&w.push(y[x])}i.forEach(x=>{x.material=w})}else g=[{start:0,count:1/0,index:0,materialIndex:0}],i.forEach(y=>{y.material=p[0]});return i.forEach((y,w)=>{const x=y.geometry;td(x,a[w],g),c&&Qu(x.groups)}),s?i:i[0]}evaluateHierarchy(e,t=new fi){e.updateMatrixWorld(!0);const n=(s,r)=>{const a=s.children;for(let l=0,h=a.length;l<h;l++){const c=a[l];c.isOperationGroup?n(c,r):r(c)}},i=s=>{const r=s.children;let a=!1;for(let h=0,c=r.length;h<c;h++){const d=r[h];a=i(d)||a}const l=s.isDirty();if(l&&s.markUpdated(),a&&!s.isOperationGroup){let h;return n(s,c=>{h?h=this.evaluate(h,c,c.operation):h=this.evaluate(s,c,c.operation)}),s._cachedGeometry=h.geometry,s._cachedMaterials=h.material,!0}else return a||l};return i(e),t.geometry=e._cachedGeometry,t.material=e._cachedMaterials,t}reset(){this.triangleSplitter.reset()}}class id{engine;planeObjects=[];planes=[];isActive=!1;evaluator;geometryCache=new Map;sectionMeshes=new Map;planeGroup;planeSize=1e3;sourceMeshes=new Map;planeThickness=.01;updateThrottleTime=100;lastUpdateTime=0;pendingUpdate=!1;updateTimer=null;cacheExpireTime=3e4;planeStates=new Map;constructor(e,t={}){this.engine=e,this.evaluator=new nd,this.planeGroup=new S.Group,this.planeGroup.name="CSG_ClippingPlanes_Optimized",t.updateThrottleTime!==void 0&&(this.updateThrottleTime=t.updateThrottleTime),t.cacheExpireTime!==void 0&&(this.cacheExpireTime=t.cacheExpireTime),t.planeThickness!==void 0&&(this.planeThickness=t.planeThickness),this.evaluator.attributes=["position","normal"],this.evaluator.useGroups=!1}init(){this.calculateSceneSize(),this.engine.scene.add(this.planeGroup),this.planes.forEach((e,t)=>{const n=this.createEmptySectionMesh(e,t);this.planeGroup.add(n),this.sectionMeshes.set(`plane_${t}`,n),this.planeObjects.push(n),this.planeStates.set(t,{constant:e.constant,normal:e.normal.clone()})})}createEmptySectionMesh(e,t){const n=new S.BufferGeometry,i=new S.MeshStandardMaterial({color:new S.Color(33023),metalness:.1,roughness:.75,side:S.DoubleSide,depthWrite:!0,depthTest:!0,clippingPlanes:this.planes.filter((r,a)=>a!==t)}),s=new S.Mesh(n,i);return s.name=`CSG_Section_Optimized_${t}`,s.visible=!1,s.renderOrder=t+1,s}active(){this.isActive=!0,this.requestUpdate(),this.planeObjects.forEach(e=>{e.visible=!0})}disActive(){this.isActive=!1,this.planeObjects.forEach(e=>{e.visible=!1}),this.updateTimer&&(clearTimeout(this.updateTimer),this.updateTimer=null)}setSourceMeshes(e){this.sourceMeshes.clear(),e.forEach(t=>{const n=t.uuid;this.sourceMeshes.set(n,t)}),this.isActive&&this.requestUpdate()}addSourceMesh(e){const t=e.uuid;this.sourceMeshes.has(t)||(this.sourceMeshes.set(t,e),this.isActive&&this.requestUpdate())}removeSourceMesh(e){const t=e.uuid;this.sourceMeshes.delete(t)&&(this.clearMeshCache(t),this.isActive&&this.requestUpdate())}requestUpdate(){if(!this.isActive)return;const e=Date.now(),t=e-this.lastUpdateTime;t>=this.updateThrottleTime?(this.lastUpdateTime=e,this.pendingUpdate=!1):(this.pendingUpdate=!0,this.updateTimer&&clearTimeout(this.updateTimer),this.updateTimer=setTimeout(()=>{this.pendingUpdate&&this.isActive&&(this.lastUpdateTime=Date.now(),this.pendingUpdate=!1),this.updateTimer=null},this.updateThrottleTime-t))}updateAllSections(){this.isActive&&(this.planes.forEach((e,t)=>{if(Math.abs(e.constant)<99999)this.hasPlaneChanged(t,e)&&(this.updateSection(e,t),this.updatePlaneState(t,e));else{const n=this.sectionMeshes.get(`plane_${t}`);n&&(n.visible=!1)}}),this.cleanExpiredCache())}hasPlaneChanged(e,t){const n=this.planeStates.get(e);if(!n)return!0;const i=Math.abs(n.constant-t.constant)>1e-4,s=!n.normal.equals(t.normal);return i||s}updatePlaneState(e,t){this.planeStates.set(e,{constant:t.constant,normal:t.normal.clone()})}getPlaneHash(e){const t=e.normal,n=e.constant;return`${t.x.toFixed(4)}_${t.y.toFixed(4)}_${t.z.toFixed(4)}_${n.toFixed(4)}`}getCacheKey(e,t){return`${e}_plane_${t}`}updateSection(e,t){const n=this.sectionMeshes.get(`plane_${t}`);if(!n)return;const i=this.getPlaneHash(e),s=[];if(this.sourceMeshes.forEach((r,a)=>{const l=this.getCacheKey(a,t),h=this.geometryCache.get(l);if(h&&h.planeHash===i)s.push(h.geometry.clone()),h.timestamp=Date.now();else try{const c=this.createPlaneBrush(e),d=new fi(r.geometry);r.updateMatrixWorld(!0),d.matrix.copy(r.matrixWorld),d.updateMatrixWorld();const m=this.evaluator.evaluate(c,d,So);m&&m.geometry.attributes.position.count>0?(s.push(m.geometry),this.geometryCache.set(l,{geometry:m.geometry.clone(),planeHash:i,timestamp:Date.now()})):this.geometryCache.delete(l)}catch(c){console.warn(`CSG intersection failed for mesh ${a}:`,c)}}),s.length>0){const r=this.mergeGeometries(s);n.geometry&&n.geometry.dispose(),n.geometry=r,n.visible=!0,n.position.set(0,0,0),n.rotation.set(0,0,0),n.scale.set(1,1,1),n.updateMatrixWorld()}else n.visible=!1;s.forEach(r=>r.dispose())}clearMeshCache(e){const t=[];this.geometryCache.forEach((n,i)=>{i.startsWith(e)&&(n.geometry.dispose(),t.push(i))}),t.forEach(n=>this.geometryCache.delete(n))}cleanExpiredCache(){const e=Date.now(),t=[];this.geometryCache.forEach((n,i)=>{e-n.timestamp>this.cacheExpireTime&&(n.geometry.dispose(),t.push(i))}),t.forEach(n=>this.geometryCache.delete(n))}clearAllCache(){this.geometryCache.forEach(e=>{e.geometry.dispose()}),this.geometryCache.clear()}createPlaneBrush(e){const t=new S.BoxGeometry(this.planeSize,this.planeThickness,this.planeSize);t.translate(0,e.constant,0),t.applyQuaternion(new S.Quaternion().setFromUnitVectors(new S.Vector3(0,-1,0),e.normal));const n=new S.Mesh(t),i=new fi(t);return i.matrix.copy(n.matrixWorld),i.updateMatrixWorld(),i}mergeGeometries(e){if(e.length===1)return e[0].clone();const t=new S.BufferGeometry,n=[],i=[],s=[];let r=0;return e.forEach(a=>{const l=a.attributes.position,h=a.attributes.normal;for(let c=0;c<l.count;c++)n.push(l.getX(c),l.getY(c),l.getZ(c));if(h)for(let c=0;c<h.count;c++)i.push(h.getX(c),h.getY(c),h.getZ(c));if(a.index)for(let c=0;c<a.index.count;c++)s.push(a.index.getX(c)+r);r+=l.count}),t.setAttribute("position",new S.Float32BufferAttribute(n,3)),i.length>0?t.setAttribute("normal",new S.Float32BufferAttribute(i,3)):t.computeVertexNormals(),s.length>0&&t.setIndex(s),t}calculateSceneSize(){const e=new S.Box3;if(this.engine.scene.traverse(t=>{if(t.isMesh&&t.geometry){const n=new S.Box3().setFromObject(t);e.union(n)}}),e.isEmpty())this.planeSize=1e3;else{const t=e.getSize(new S.Vector3),n=Math.max(t.x,t.y,t.z);this.planeSize=n*3}}update(){this.isActive&&this.pendingUpdate&&!this.updateTimer&&this.requestUpdate()}dispose(){this.updateTimer&&(clearTimeout(this.updateTimer),this.updateTimer=null),this.clearAllCache(),this.planeObjects.forEach(e=>{e.geometry&&e.geometry.dispose(),e.material&&(Array.isArray(e.material)?e.material.forEach(t=>t.dispose()):e.material.dispose())}),this.sectionMeshes.clear(),this.planeObjects=[],this.sourceMeshes.clear(),this.planeGroup.parent&&this.planeGroup.parent.remove(this.planeGroup)}setSectionColor(e){this.planeObjects.forEach(t=>{t.material instanceof S.MeshStandardMaterial&&t.material.color.set(e)})}getCacheStats(){return{cacheSize:this.geometryCache.size,sourceMeshCount:this.sourceMeshes.size,sectionMeshCount:this.sectionMeshes.size}}setPlaneThickness(e){if(e<=0){console.warn("Plane thickness must be positive");return}this.planeThickness=e,this.clearAllCache(),this.isActive&&this.requestUpdate()}getPlaneThickness(){return this.planeThickness}showSections(){this.sectionMeshes.forEach(e=>{e.geometry?.attributes.position?.count&&e.geometry.attributes.position.count>0&&(e.visible=!0)})}hideSections(){this.sectionMeshes.forEach(e=>{e.visible=!1})}showSection(){this.planeGroup.visible=!0}hideSection(){this.planeGroup.visible=!1}toggleSectionsVisibility(){let e=!1;return this.sectionMeshes.forEach(t=>{t.visible&&(e=!0)}),e?(this.hideSections(),!1):(this.showSections(),!0)}toggleSectionVisibility(e){const t=this.sectionMeshes.get(`plane_${e}`);return t?(t.visible=!t.visible,t.visible):!1}}class sd{engine;isActive=!1;box;pickPoint;pickNormal;pickMesh;box_;plane;meshs;isDrag=!1;maxBox;csgClipping=null;useCsgClipping=!1;constructor(e,t){this.engine=e,this.meshs=[],t?.useCsgClipping!==void 0&&(this.useCsgClipping=t.useCsgClipping),this.useCsgClipping&&this.initCsgClipping()}initCsgClipping(){this.csgClipping=new id(this.engine,{updateThrottleTime:150,cacheExpireTime:45e3}),this.csgClipping.planes=this.engine.sectionPlane,this.csgClipping.init()}active(){this.isActive||(this.engine.handelBehaved.init(this),this.engine.handelBehaved.active(),this.engine.scene.children.filter(e=>e.type=="Group"&&e.name=="ClippingBox").forEach(e=>{e.children.forEach(t=>{t.name.includes("face")||(t.visible=!0)})}),this.isActive=!0,this.init())}disActive(){this.init(),this.isActive=!1,this.engine.handelBehaved.disActive(),this.csgClipping&&this.csgClipping.disActive(),this.engine.scene.children.filter(e=>e.type=="Group"&&e.name=="ClippingBox").forEach(e=>{e.children.forEach(t=>{t.name.includes("face")||(t.visible=!1)})}),this.engine.interactionModule.init(),this.engine.interactionModule.active()}disabled(){this.isActive=!1,this.engine.handelBehaved.disActive(),this.engine.interactionModule.init(),this.engine.interactionModule.active(),this.engine.scene.children.filter(e=>e.type=="Group"&&e.name=="ClippingBox").forEach(e=>{e.children.forEach(t=>{t.name.includes("face")||(t.visible=!1)})})}recover(){this.isActive||(this.engine.handelBehaved.init(this),this.engine.handelBehaved.active(),this.engine.scene.children.filter(e=>e.type=="Group"&&e.name=="ClippingBox").forEach(e=>{e.children.forEach(t=>{t.name.includes("face")||(t.visible=!0)})}),this.isActive=!0)}init(){let e=this.engine.octreeBox.getBoundingBox();this.maxBox=JSON.parse(JSON.stringify(e)),this.box=e,this.updata_face(e)}getboxXyz(){return{minX:this.box.min.x,minY:this.box.min.y,minZ:this.box.min.z,maxX:this.box.max.x,maxY:this.box.max.y,maxZ:this.box.max.z}}setboxXyz(e){this.box.min.x=e.minX,this.box.min.y=e.minY,this.box.min.z=e.minZ,this.box.max.x=e.maxX,this.box.max.y=e.maxY,this.box.max.z=e.maxZ,this.updata_face(this.box)}setBox(e){this.box=e,this.updata_face(e)}reverseBox(){}handleMouseDown(e){this.isDrag=!0;const t=e.raycaster.intersectObjects(this.meshs,!1);if(t!=null&&t.length>0)if(this.pickPoint=t[0].point,this.pickNormal=t[0].face.normal,this.engine.controls.enabled=!1,this.pickMesh=t[0].object,this.box_={min:this.box.min.clone(),max:this.box.max.clone()},this.pickNormal.y==0){const n=new S.Plane;n.setFromNormalAndCoplanarPoint(new S.Vector3(0,1,0),this.pickPoint),this.plane=n}else{let n=new S.Vector3(this.engine.camera.position.x,this.pickPoint.y,this.engine.camera.position.z);const i=new S.Plane;i.setFromNormalAndCoplanarPoint(n.clone().sub(this.pickPoint.clone()).setLength(1),this.pickPoint),this.plane=i}}handleMouseUp(e){this.isDrag=!1,this.pickPoint=null,this.pickNormal=null,this.pickMesh=null,this.engine.controls.enabled=!0,this.csgClipping&&this.isActive}handleMouseMove(e){this.meshs.forEach(n=>{n.material.opacity=0});const t=e.raycaster.intersectObjects(this.meshs,!1);if(t!=null&&t.length>0&&(t[0].object.material.opacity=.05),this.pickPoint!=null){const n=new S.Vector3;if(e.raycaster.ray.intersectPlane(this.plane,n)){let i=n.clone().sub(this.pickPoint.clone()).dot(this.pickNormal.clone());this.pickMesh.name=="前"||this.pickMesh.name=="左"||this.pickMesh.name=="底"?this.box.min=this.box_.min.clone().add(this.pickNormal.clone().setLength(i)):this.box.max=this.box_.max.clone().add(this.pickNormal.clone().setLength(i)),this.updata_face(this.box),this.calculate_ratio()}}}calculate_ratio(){let e=this.maxBox.max.x-this.maxBox.min.x,t=this.maxBox.max.y-this.maxBox.min.y,n=this.maxBox.max.z-this.maxBox.min.z,i=(this.box.min.x-this.maxBox.min.x)/e*100,s=(this.box.max.x-this.maxBox.min.x)/e*100,r=(this.box.min.y-this.maxBox.min.y)/t*100,a=(this.box.max.y-this.maxBox.min.y)/t*100,l=(this.box.min.z-this.maxBox.min.z)/n*100,h=(this.box.max.z-this.maxBox.min.z)/n*100;i<0&&(i=0),s<0&&(s=0),r<0&&(r=0),a<0&&(a=0),l<0&&(l=0),h<0&&(h=0),i>100&&(i=100),s>100&&(s=100),r>100&&(r=100),a>100&&(a=100),l>100&&(l=100),h>100&&(h=100);let c={x:{min:i,max:s},y:{min:r,max:a},z:{min:l,max:h}};this.engine.events.trigger(_e.SectionMove,c)}updata_face(e){let t=this,n=[new S.Vector3(e.min.x,e.min.y,e.min.z),new S.Vector3(e.max.x,e.min.y,e.min.z),new S.Vector3(e.max.x,e.max.y,e.min.z),new S.Vector3(e.min.x,e.max.y,e.min.z)],i=[new S.Vector3(e.min.x,e.min.y,e.max.z),new S.Vector3(e.max.x,e.min.y,e.max.z),new S.Vector3(e.max.x,e.max.y,e.max.z),new S.Vector3(e.min.x,e.max.y,e.max.z)],s=[new S.Vector3(e.max.x,e.min.y,e.max.z),new S.Vector3(e.max.x,e.min.y,e.min.z),new S.Vector3(e.max.x,e.max.y,e.min.z),new S.Vector3(e.max.x,e.max.y,e.max.z)],r=[new S.Vector3(e.min.x,e.min.y,e.min.z),new S.Vector3(e.min.x,e.min.y,e.max.z),new S.Vector3(e.min.x,e.max.y,e.max.z),new S.Vector3(e.min.x,e.max.y,e.min.z)],a=[new S.Vector3(e.min.x,e.max.y,e.min.z),new S.Vector3(e.max.x,e.max.y,e.min.z),new S.Vector3(e.max.x,e.max.y,e.max.z),new S.Vector3(e.min.x,e.max.y,e.max.z)],l=[new S.Vector3(e.min.x,e.min.y,e.min.z),new S.Vector3(e.max.x,e.min.y,e.min.z),new S.Vector3(e.max.x,e.min.y,e.max.z),new S.Vector3(e.min.x,e.min.y,e.max.z)];h(n,new S.Vector3(0,0,-1),"前"),h(i,new S.Vector3(0,0,1),"后"),h(s,new S.Vector3(1,0,0),"右"),h(r,new S.Vector3(-1,0,0),"左"),h(a,new S.Vector3(0,1,0),"顶"),h(l,new S.Vector3(0,-1,0),"底");function h(c,d,m){const p=new S.BufferGeometry,f=new Float32Array([c[0].x,c[0].y,c[0].z,c[1].x,c[1].y,c[1].z,c[2].x,c[2].y,c[2].z,c[3].x,c[3].y,c[3].z]),u=[0,1,2,0,2,3];p.setAttribute("position",new S.BufferAttribute(f,3)),p.setIndex(u);let g=t.engine.scene.children.find(D=>D.type=="Group"&&D.name=="ClippingBox");g==null&&(g=new S.Group,g.name="ClippingBox",t.engine.scene.add(g));let y=t.meshs.find(D=>D.name==m);if(y==null){const D=new S.MeshBasicMaterial({color:65280,transparent:!0,opacity:0,side:S.DoubleSide});D.polygonOffset=!0,D.polygonOffsetFactor=1,D.polygonOffsetUnits=4;const T=new S.Mesh(p,D);T.normal=d,T.name=m,g.add(T),t.meshs.push(T)}else y.geometry=p;const w=new Float32Array([c[0].x,c[0].y,c[0].z,c[1].x,c[1].y,c[1].z,c[2].x,c[2].y,c[2].z,c[3].x,c[3].y,c[3].z,c[0].x,c[0].y,c[0].z]);let x=new S.LineBasicMaterial({color:255}),v=new S.BufferGeometry;v.setAttribute("position",new S.BufferAttribute(w,3));let b=t.meshs.find(D=>D.name==m+"Line");b==null&&(b=new S.Line(v,x),b.name=m+"Line",g.add(b),t.meshs.push(b)),b.geometry=v,b.material=x,m=="前"||m=="左"||m=="底"?t.engine.sectionPlane.find(D=>D.name==m).setFromNormalAndCoplanarPoint(d.clone().setLength(-1),e.min):t.engine.sectionPlane.find(D=>D.name==m).setFromNormalAndCoplanarPoint(d.clone().setLength(-1),e.max),t.engine.scene.children.filter(D=>D.type=="Mesh"&&D.url).forEach(D=>{D.material&&Array.isArray(D.material)?D.material.forEach(T=>{T.clippingPlanes=t.engine.sectionPlane}):D.material.clippingPlanes=t.engine.sectionPlane})}}}class rd{engine;isActive=!1;isDrag=!1;meshs=[];box;pickPoint;pickNormal;pickMesh;box_;plane;angleX=0;angleY=0;angleZ=0;direction=1;normal=new S.Vector3(0,0,1);distance=0;center=null;current_center=null;constructor(e){this.engine=e,this.meshs=[],this.box=null}active(){if(this.isActive==!0)return;this.isActive=!0,this.engine.scene.children.filter(t=>t.type=="Group"&&t.name=="ClippingBox").forEach(t=>{t.children.forEach(n=>{n.name.includes("face")&&(n.visible=!0)})}),this.engine.handelBehaved.init(this),this.engine.handelBehaved.active();let e=this;e.engine.scene.children.filter(t=>t.type=="Mesh"&&t.url).forEach(t=>{t.material&&Array.isArray(t.material)?t.material.forEach(n=>{n.clippingPlanes=e.engine.sectionPlane}):t.material.clippingPlanes=e.engine.sectionPlane,e.engine.clipping.clippingStencil?.addMesh(e.engine.sectionPlane.find(n=>n.name=="face"),t)}),this.init()}disActive(){this.init(),this.isActive=!1,this.engine.handelBehaved.disActive();const e=this.engine.sectionPlane.find(t=>t.name=="face");e&&(e.constant=1e5),this.engine.scene.children.filter(t=>t.type=="Group"&&t.name=="ClippingBox").forEach(t=>{t.children.forEach(n=>{n.name.includes("face")&&(n.visible=!1)})})}init(){let e=this.engine.octreeBox.getBoundingBox();this.box=e,this.updata_face(0)}disabled(){this.isActive=!1,this.engine.handelBehaved.disActive(),this.engine.interactionModule.init(),this.engine.interactionModule.active(),this.engine.scene.children.filter(e=>e.type=="Group"&&e.name=="ClippingBox").forEach(e=>{e.children.forEach(t=>{t.name.includes("face")&&(t.visible=!1)})})}recover(){this.isActive||(this.engine.handelBehaved.init(this),this.engine.handelBehaved.active(),this.engine.scene.children.filter(e=>e.type=="Group"&&e.name=="ClippingBox").forEach(e=>{e.children.forEach(t=>{t.name.includes("face")&&(t.visible=!0)})}),this.isActive=!0)}setFaceAngle(e,t,n){this.angleX=e,this.angleY=t,this.angleZ=n,this.normal=new S.Vector3(0,1,0).applyAxisAngle(new S.Vector3(1,0,0),e).applyAxisAngle(new S.Vector3(0,0,1),t).applyAxisAngle(new S.Vector3(0,1,0),n),this.normal.normalize(),this.updata_face(0)}setFaceNormal(e,t=0){this.normal=e,this.distance=t,this.updata_face(t)}reverse(){this.direction=this.direction*-1,this.updata_face(this.distance)}getFaceAngle(){return{angleX:this.angleX,angleY:this.angleY,angleZ:this.angleZ,direction:this.direction}}updata_face(e){let t=this,n=t.engine.scene.children.find(P=>P.type=="Group"&&P.name=="ClippingBox");n==null&&(n=new S.Group,n.name="ClippingBox",t.engine.scene.add(n));let i=new S.Vector3(1,0,0),s=new S.Vector3(0,1,0),r=new S.Vector3(0,0,1),a,l,h=this.normal.clone().normalize(),c=Math.abs(h.dot(i)),d=Math.abs(h.dot(s)),m=Math.abs(h.dot(r));c<=d&&c<=m?a=i:d<=c&&d<=m?a=s:a=r,a=a.clone().sub(h.clone().multiplyScalar(a.dot(h))).normalize(),l=new S.Vector3().crossVectors(h,a).normalize();let p=null;this.center==null?(p=new S.Vector3((this.box.min.x+this.box.max.x)/2,(this.box.min.y+this.box.max.y)/2,(this.box.min.z+this.box.max.z)/2),this.center=p.clone()):p=this.center.clone();let f=this.box.max.x-this.box.min.x,u=this.box.max.y-this.box.min.y,g=this.box.max.z-this.box.min.z,y=Math.max(Math.abs(a.x)*f,Math.abs(a.y)*u,Math.abs(a.z)*g),w=Math.max(Math.abs(l.x)*f,Math.abs(l.y)*u,Math.abs(l.z)*g),x=p.clone().add(a.clone().multiplyScalar(-y/2)).add(l.clone().multiplyScalar(-w/2)),v=p.clone().add(a.clone().multiplyScalar(y/2)).add(l.clone().multiplyScalar(-w/2)),b=p.clone().add(a.clone().multiplyScalar(y/2)).add(l.clone().multiplyScalar(w/2)),D=p.clone().add(a.clone().multiplyScalar(-y/2)).add(l.clone().multiplyScalar(w/2));x.add(h.clone().multiplyScalar(e)),v.add(h.clone().multiplyScalar(e)),b.add(h.clone().multiplyScalar(e)),D.add(h.clone().multiplyScalar(e)),this.current_center=p.clone().add(h.clone().multiplyScalar(e)),k([x,v,b,D],h,"face");function k(P,I,z){const C=new S.BufferGeometry,E=new Float32Array([P[0].x,P[0].y,P[0].z,P[1].x,P[1].y,P[1].z,P[2].x,P[2].y,P[2].z,P[3].x,P[3].y,P[3].z]),M=[0,1,2,0,2,3];C.setAttribute("position",new S.BufferAttribute(E,3)),C.setIndex(M);let B=t.meshs.find($=>$.name==z);if(B==null){const $=new S.MeshBasicMaterial({color:65280,transparent:!0,opacity:.02,side:S.DoubleSide});$.polygonOffset=!0,$.polygonOffsetFactor=1,$.polygonOffsetUnits=4;const F=new S.Mesh(C,$);F.normal=I,F.name=z,n.add(F),t.meshs.push(F)}else B.geometry=C;const V=new Float32Array([P[0].x,P[0].y,P[0].z,P[1].x,P[1].y,P[1].z,P[2].x,P[2].y,P[2].z,P[3].x,P[3].y,P[3].z,P[0].x,P[0].y,P[0].z]);let U=new S.LineBasicMaterial({color:255}),H=new S.BufferGeometry;H.setAttribute("position",new S.BufferAttribute(V,3));let G=t.meshs.find($=>$.name==z+"Line");G==null&&(G=new S.Line(H,U),G.name=z+"Line",n.add(G),t.meshs.push(G)),G.geometry=H,G.material=U,t.engine.sectionPlane.find($=>$.name==z).setFromNormalAndCoplanarPoint(I.clone().setLength(t.direction),P[0])}}handleMouseDown(e){this.isDrag=!0;const t=e.raycaster.intersectObjects(this.meshs,!1);if(t!=null&&t.length>0)if(this.pickPoint=t[0].point,this.pickNormal=t[0].face.normal,this.engine.controls.enabled=!1,this.pickMesh=t[0].object,this.box_={min:this.box.min.clone(),max:this.box.max.clone()},this.center=this.current_center.clone(),this.pickNormal.y==0){const n=new S.Plane;n.setFromNormalAndCoplanarPoint(new S.Vector3(0,1,0),this.pickPoint),this.plane=n}else{let n=new S.Vector3(this.engine.camera.position.x,this.pickPoint.y,this.engine.camera.position.z);const i=new S.Plane;i.setFromNormalAndCoplanarPoint(n.clone().sub(this.pickPoint.clone()).setLength(1),this.pickPoint),this.plane=i}}handleMouseUp(e){this.isDrag=!1,this.pickPoint=null,this.pickNormal=null,this.pickMesh=null,this.engine.controls.enabled=!0}handleMouseMove(e){this.meshs.forEach(n=>{n.material.opacity=0});const t=e.raycaster.intersectObjects(this.meshs,!1);if(t!=null&&t.length>0&&(t[0].object.material.opacity=.05),this.pickPoint!=null){const n=new S.Vector3;if(e.raycaster.ray.intersectPlane(this.plane,n)){let i=n.clone().sub(this.pickPoint.clone()).dot(this.pickNormal.clone());this.distance=i,this.updata_face(this.distance)}}}}class od{engine;callback_;constructor(e){this.engine=e}init(){this.engine.handelBehaved.init(this,{showCatch:!0}),this.engine.handelBehaved.active()}catch_face(e){this.callback_=e}handleMouseMove(e){}handleMouseClick(e){let t=e.catch.normal;this.engine.handelBehaved.disActive(),this.callback_({dir:t,position:e.catch.point})}}class ad{engine;sectionBox;sectionFace;clippingStencil;currentClippingMode="";constructor(e){this.engine=e;let t=new S.Plane(new S.Vector3(0,0,1),1e5);t.name="前";let n=new S.Plane(new S.Vector3(0,0,1),1e5);n.name="左";let i=new S.Plane(new S.Vector3(0,0,1),1e5);i.name="后";let s=new S.Plane(new S.Vector3(0,0,1),1e5);s.name="右";let r=new S.Plane(new S.Vector3(0,0,1),1e5);r.name="顶";let a=new S.Plane(new S.Vector3(0,0,1),1e5);a.name="底";let l=new S.Plane(new S.Vector3(0,0,1),1e5);l.name="face",this.engine.sectionPlane=[t,n,i,s,r,a,l]}init(){this.sectionBox=new sd(this.engine),this.sectionFace=new rd(this.engine)}scaleBox(){let e=this.engine.octreeBox.getBoundingBox();this.sectionBox.setBox(e)}clippingModel(e){let t=[];e.forEach(s=>{let r=this.engine.models.find(a=>a.url===s.url);s.ids.forEach(a=>{r.nodesMap.get(a).infos.forEach(l=>{t.push(l.box)})})}),this.active("box");let n=i(t);this.sectionBox.setBox(n);function i(s){let r=new S.Vector3(1e8,1e9,1e10),a=new S.Vector3(-1e8,-1e9,-1e10);return s.forEach(l=>{l.min.x<r.x&&(r.x=l.min.x),l.min.y<r.y&&(r.y=l.min.y),l.min.z<r.z&&(r.z=l.min.z),l.max.x>a.x&&(a.x=l.max.x),l.max.y>a.y&&(a.y=l.max.y),l.max.z>a.z&&(a.z=l.max.z)}),new S.Box3(r,a)}}updateClippingValue(e){let t=this.sectionBox.maxBox,n=t.min.x+(t.max.x-t.min.x)*e.x.min*.01,i=t.min.y+(t.max.y-t.min.y)*e.y.min*.01,s=t.min.z+(t.max.z-t.min.z)*e.z.min*.01,r=t.min.x+(t.max.x-t.min.x)*e.x.max*.01,a=t.min.y+(t.max.y-t.min.y)*e.y.max*.01,l=t.min.z+(t.max.z-t.min.z)*e.z.max*.01;this.sectionBox.setboxXyz({minX:n,minY:i,minZ:s,maxX:r,maxY:a,maxZ:l})}active(e){if(this.sectionFace.disActive(),this.sectionBox.disActive(),this.currentClippingMode=e,e=="x")this.sectionFace.init(),this.sectionFace.active(),this.sectionFace.setFaceAngle(Math.PI/2,0,0);else if(e=="y")this.sectionFace.init(),this.sectionFace.active(),this.sectionFace.setFaceAngle(0,Math.PI/2,0);else if(e=="z")this.sectionFace.init(),this.sectionFace.active(),this.sectionFace.setFaceAngle(0,0,Math.PI/2);else if(e=="box")this.sectionBox.init(),this.sectionBox.active();else if(e=="face"){let t=new od(this.engine);t.init(),t.catch_face(n=>{this.sectionFace.init(),this.sectionFace.active();let i=this.engine.octreeBox.getBoundingBox(),s=n.position.clone().sub(i.min.clone().add(i.max.clone()).setLength(.5)),r=new S.Vector3(n.dir.x,n.dir.y,n.dir.z),a=s.dot(r);this.sectionFace.setFaceNormal(n.dir,a)})}}disabled(){this.currentClippingMode=="box"?this.sectionBox.disabled():this.sectionFace.disabled()}recover(){this.currentClippingMode=="box"?this.sectionBox.recover():this.sectionFace.recover()}reverse(){this.sectionFace.reverse()}disActive(){this.sectionFace.disActive(),this.sectionBox.disActive(),this.currentClippingMode=""}}class ld{engine;constructor(e){this.engine=e}getLevelTreeData(){let e=[];return this.engine.engineStatus.models.forEach(t=>{e.push({children:t.info.modelTree.modelTreeLevel,name:t.info.baseInfo.name,url:t.url})}),e}getTypeTreeData(){let e=[];return this.engine.engineStatus.models.forEach(t=>{e.push({children:t.info.modelTree.modelTreeType,name:t.info.baseInfo.name,url:t.url})}),e}getMajorTreeData(){let e=[];return this.engine.engineStatus.models.forEach(t=>{e.push({children:t.info.modelTree.modelTreeMajor,name:t.info.baseInfo.name,url:t.url})}),e}}class cd{engine;constructor(e){this.engine=e}getEngineInfo(){let e=0,t=0,n=0;return!this.engine||!this.engine.scene?{totalVertices:0,totalTriangles:0,meshCount:0}:(this.engine.scene.traverse(i=>{if(i instanceof S.Mesh){const s=i.geometry;if(s&&s.attributes){const r=s.attributes.position;if(r){const a=r.count;e+=a;let l=0;s.index?l=s.index.count/3:l=a/3,t+=l}}}}),this.engine.engineStatus.models.forEach(i=>{n=n+i.info.modelEdge.length}),{totalVertices:Math.floor(e),totalTriangles:Math.floor(t),meshCount:n})}}class hd{engine;constructor(e){this.engine=e}init(){}getModelProperties(e,t,n){let i=this.engine.engineStatus.models.find(r=>r.url===e);i.properties==null&&Dr(e+"/property",r=>{let a=JSON.parse(r);i.properties=a,setTimeout(()=>{s(a,t,n)},100)}),s(i.properties,t,n);function s(r,a,l){let h=[],c=r.models[a.toString()||""],d=c.map(m=>m[0]);d=d.filter((m,p)=>d.indexOf(m)===p),d.forEach(m=>{let p={name:r.categorys[m],children:[]};h.push(p),c.filter(f=>f[0]===m).forEach(f=>{p.children.push({name:r.names[f[1]],value:r.values[f[2]]})})}),l?.({properties:h,materials:h})}}}class ud{engine;constructor(e){this.engine=e}getModelTypes(){let e=[];return this.engine.engineStatus.models.forEach(t=>{t.info.modelMapper.forEach(i=>{e.push(i.typeName)})}),e=e.filter((t,n,i)=>i.indexOf(t)===n),e}getModelMajors(){let e=[];return this.engine.engineStatus.models.forEach(t=>{t.info.modelMapper.forEach(i=>{e.push(i.majorName)})}),e=e.filter((t,n,i)=>i.indexOf(t)===n),e}getModelLevels(){let e=[];return this.engine.engineStatus.models.forEach(t=>{t.info.modelMapper.forEach(i=>{e.push(i.levelName)})}),e=e.filter((t,n,i)=>i.indexOf(t)===n),e}getModelMappers(e){}getModelMapper(e,t){let n=this.engine.engineStatus.models.find(r=>r.url==e);return n?n.info.modelMapper.find(r=>r.id==t):null}getModelsWithLevelType(e,t,n=null){let i=[];return this.engine.engineStatus.models.forEach(s=>{let r={url:s.url,ids:[]};i.push(r),s.info.modelMapper.filter(l=>l.levelName===e&&l.typeName===t).forEach(l=>{r.ids.push(Number(l.id))})}),n&&n(i),i}getModelsWithType(e,t=null){let n=[];return this.engine.engineStatus.models.forEach(i=>{let s={url:i.url,ids:[]};n.push(s),i.info.modelMapper.filter(a=>a.typeName===e).forEach(a=>{s.ids.push(Number(a.id))})}),t&&t(n),n}getModelsWithLevel(e,t){let n=[];return this.engine.engineStatus.models.forEach(i=>{let s={url:i.url,ids:[]};n.push(s),i.info.modelMapper.filter(a=>a.levelName===e).forEach(a=>{s.ids.push(Number(a.id))})}),t&&t(n),n}getModelsWithMajor(e,t){let n=[];return this.engine.engineStatus.models.forEach(i=>{let s={url:i.url,ids:[]};n.push(s),i.info.modelMapper.filter(a=>a.majorName===e).forEach(a=>{s.ids.push(Number(a.id))})}),t&&t(n),n}}class dd{engine;isActive=!1;groupEdge;material;modelEdgeLoaded=!1;indexes=new Map;constructor(e){this.engine=e,this.groupEdge=this.engine.scene.getObjectByName("groupEdge"),this.material=new S.LineBasicMaterial({color:"#000000",depthTest:!0,transparent:!0,opacity:.3}),this.material.clippingPlanes=this.engine.sectionPlane}active(){this.isActive=!0,this.groupEdge.visible=!0,this.engine.scene.traverse(e=>{e.isMesh&&e.material&&(Array.isArray(e.material)?e.material:[e.material]).forEach(n=>{n.polygonOffset=!0,n.polygonOffsetFactor=1,n.polygonOffsetUnits=4})}),this.show()}disActive(){this.isActive=!1,this.groupEdge.visible=!1,this.engine.scene.traverse(e=>{e.isMesh&&e.material&&(Array.isArray(e.material)?e.material:[e.material]).forEach(n=>{n.polygonOffset=!1})})}loadModelEdge(){this.modelEdgeLoaded||(this.engine.engineStatus.models.forEach(e=>{if(!this.groupEdge.children.find(n=>n.url==e.url)){let n=e.info,i=[],s=new Map;n.modelEdge.forEach(r=>{let a=i.length;for(let l=0;l<r.points.length;l++)r.points[l].length==2&&(i.push(r.points[l][0].X),i.push(r.points[l][0].Z),i.push(-r.points[l][0].Y),i.push(r.points[l][1].X),i.push(r.points[l][1].Z),i.push(-r.points[l][1].Y));s.set(Number(r.id),[a,i.length,r.points])}),this.indexes.set(e.url,s)}}),this.modelEdgeLoaded=!0)}show(){this.modelEdgeLoaded||this.loadModelEdge(),this.indexes.forEach((e,t)=>{let n=[];e.forEach((r,a)=>{r[2].forEach((l,h)=>{l.length==2&&(n.push(l[0].X),n.push(l[0].Z),n.push(-l[0].Y),n.push(l[1].X),n.push(l[1].Z),n.push(-l[1].Y))})});let i=new S.BufferGeometry;i.setAttribute("position",new S.Float32BufferAttribute(n,3));let s=new S.LineSegments(i,this.material);s.url=t,this.groupEdge.add(s)})}getModelEdge(e,t){let n=this.indexes.get(e);if(n){let i=n.get(t);if(i)return i.slice()}return null}hideModelEdge(e,t){let n=this.indexes.get(e);if(n){let i=n.get(t);if(i){let[s,r,a]=i,l=this.groupEdge.children.find(h=>h.url==e);if(l){let h=l.geometry.attributes.position.array;for(let c=s;c<r;c++)h[c]=NaN;l.geometry.attributes.position.needsUpdate=!0}}}}showModelEdge(e,t){let n=this.indexes.get(e);if(n){let i=n.get(t);if(i){let[s,r,a]=i,l=this.groupEdge.children.find(h=>h.url==e);if(l){let h=l.geometry.attributes.position.array,c=0;for(let d=s;d<r;d+=3){const m=Math.floor(c/6),p=c%6>=3;if(a[m]&&a[m].length===2){const f=p?a[m][1]:a[m][0];h[d]=f.X,h[d+1]=f.Z,h[d+2]=-f.Y}c+=3}l.geometry.attributes.position.needsUpdate=!0}}}}}class fd{config;constructor(e){this.config={temperature:.7,maxTokens:2e4,timeout:3e5,...e}}async chat(e){const t=new AbortController,n=setTimeout(()=>t.abort(),this.config.timeout);try{const i=await fetch(`${this.config.baseURL}/chat/completions`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.config.apiKey}`},body:JSON.stringify({model:this.config.model,messages:e,temperature:this.config.temperature,max_tokens:this.config.maxTokens,stream:!1}),signal:t.signal});if(clearTimeout(n),!i.ok){const r=await i.json().catch(()=>({}));throw new Error(`API请求失败 (${i.status}): ${r.error?.message||r.message||i.statusText}`)}return(await i.json()).choices?.[0]?.message?.content||""}catch(i){throw clearTimeout(n),i.name==="AbortError"?new Error("请求超时,请重试"):i.message.includes("Failed to fetch")?new Error(`网络请求失败,请检查:
|
|
971
|
+
`;continue}if((V=B.match(I))&&(M.gamma=parseFloat(V[1])),(V=B.match(z))&&(M.exposure=parseFloat(V[1])),(V=B.match(C))&&(M.valid|=2,M.format=V[1]),(V=B.match(E))&&(M.valid|=4,M.height=parseInt(V[1],10),M.width=parseInt(V[2],10)),M.valid&2&&M.valid&4)break}return M.valid&2||r(3,"missing format specifier"),M.valid&4||r(3,"missing image size specifier"),M},p=function(k,P,I){const z=P;if(z<8||z>32767||k[0]!==2||k[1]!==2||k[2]&128)return new Uint8Array(k);z!==(k[2]<<8|k[3])&&r(3,"wrong scanline width");const C=new Uint8Array(4*P*I);C.length||r(4,"unable to allocate buffer space");let E=0,M=0;const B=4*z,V=new Uint8Array(4),U=new Uint8Array(B);let H=I;for(;H>0&&M<k.byteLength;){M+4>k.byteLength&&r(1),V[0]=k[M++],V[1]=k[M++],V[2]=k[M++],V[3]=k[M++],(V[0]!=2||V[1]!=2||(V[2]<<8|V[3])!=z)&&r(3,"bad rgbe scanline format");let G=0,$;for(;G<B&&M<k.byteLength;){$=k[M++];const N=$>128;if(N&&($-=128),($===0||G+$>B)&&r(3,"bad scanline data"),N){const te=k[M++];for(let ee=0;ee<$;ee++)U[G++]=te}else U.set(k.subarray(M,M+$),G),G+=$,M+=$}const F=z;for(let N=0;N<F;N++){let te=0;C[E]=U[N+te],te+=z,C[E+1]=U[N+te],te+=z,C[E+2]=U[N+te],te+=z,C[E+3]=U[N+te],E+=4}H--}return C},f=function(k,P,I,z){const C=k[P+3],E=Math.pow(2,C-128)/255;I[z+0]=k[P+0]*E,I[z+1]=k[P+1]*E,I[z+2]=k[P+2]*E,I[z+3]=1},u=function(k,P,I,z){const C=k[P+3],E=Math.pow(2,C-128)/255;I[z+0]=_.DataUtils.toHalfFloat(Math.min(k[P+0]*E,65504)),I[z+1]=_.DataUtils.toHalfFloat(Math.min(k[P+1]*E,65504)),I[z+2]=_.DataUtils.toHalfFloat(Math.min(k[P+2]*E,65504)),I[z+3]=_.DataUtils.toHalfFloat(1)},g=new Uint8Array(e);g.pos=0;const y=m(g),w=y.width,x=y.height,v=p(g.subarray(g.pos),w,x);let b,D,T;switch(this.type){case _.FloatType:T=v.length/4;const k=new Float32Array(T*4);for(let I=0;I<T;I++)f(v,I*4,k,I*4);b=k,D=_.FloatType;break;case _.HalfFloatType:T=v.length/4;const P=new Uint16Array(T*4);for(let I=0;I<T;I++)u(v,I*4,P,I*4);b=P,D=_.HalfFloatType;break;default:throw new Error("THREE.HDRLoader: Unsupported type: "+this.type)}return{width:w,height:x,data:b,header:y.string,gamma:y.gamma,exposure:y.exposure,type:D}}setDataType(e){return this.type=e,this}load(e,t,n,i){function s(r,a){switch(r.type){case _.FloatType:case _.HalfFloatType:r.colorSpace=_.LinearSRGBColorSpace,r.minFilter=_.LinearFilter,r.magFilter=_.LinearFilter,r.generateMipmaps=!1,r.flipY=!0;break}t&&t(r,a)}return super.load(e,s,n,i)}}function Jc(){return new S.Scene}function Qc(o,e){o.appendChild(e.domElement)}function eh(o,e,t){var n=new Object;n.visible=!0;let i=null,s,r,a=[];n.init=function(){s||(h(),c(),d())},n.Hide=function(){s.style.display="none",n.visible=!1},n.Show=function(){s.style.display="block",n.visible=!0},n.RenderScene=function(){n.camera.quaternion.copy(e.camera.quaternion);const f=new S.Vector3(0,0,1).applyQuaternion(e.camera.quaternion);n.camera.position.copy(f.multiplyScalar(100)),n.sceneOrtho.renderer.render(n.sceneOrtho,n.camera)},n.ToggleDirectionView=function(f){var u=new S.Vector3(0,0,0);f=="top"?u=new S.Vector3(0,1,1e-5):f=="down"?u=new S.Vector3(0,-1,1e-5):f=="front"?u=new S.Vector3(0,0,1):f=="left"?u=new S.Vector3(-1,0,0):f=="back"?u=new S.Vector3(0,0,-1):f=="right"?u=new S.Vector3(1,0,0):f=="top_front"?u=new S.Vector3(1,1,0):f=="top_left"?u=new S.Vector3(0,1,-1):f=="top_back"?u=new S.Vector3(-1,1,0):f=="top_right"?u=new S.Vector3(0,1,1):f=="down_front"?u=new S.Vector3(1,-1,0):f=="down_left"?u=new S.Vector3(0,-1,-1):f=="down_back"?u=new S.Vector3(-1,-1,0):f=="down_right"?u=new S.Vector3(0,-1,1):f=="front_right"?u=new S.Vector3(1,0,1):f=="right_back"?u=new S.Vector3(-1,0,1):f=="back_left"?u=new S.Vector3(-1,0,-1):f=="left_front"?u=new S.Vector3(1,0,-1):f=="top_left_front"?u=new S.Vector3(1,1,-1):f=="top_front_right"?u=new S.Vector3(1,1,1):f=="top_right_back"?u=new S.Vector3(-1,1,1):f=="top_back_left"?u=new S.Vector3(-1,1,-1):f=="button_left_front"?u=new S.Vector3(1,-1,-1):f=="button_front_right"?u=new S.Vector3(1,-1,1):f=="button_right_back"?u=new S.Vector3(-1,1,1):f=="button_back_left"&&(u=new S.Vector3(-1,-1,-1));var g=o.octreeBox.getBoundingBox(),y=g.min,w=g.max,x=y.clone().add(w.clone()).multiplyScalar(.5),v=x.clone().add(u.multiplyScalar(1*w.distanceTo(y)));l(e.camera.position,v,o.controls.target.clone(),x)},n.GetCameraPose=function(){var f=e.camera.quaternion,u=e.camera.position,g=o.controls.target,y={quaternion:f,position:u,target:g};return y},n.ReductionCameraPose=function(f,u=1e3,g){var y=new S.Quaternion(f.quaternion._x,f.quaternion._y,f.quaternion._z,f.quaternion._w),w=new S.Vector3(f.position.x,f.position.y,f.position.z),x=new S.Vector3(f.target.x,f.target.y,f.target.z);let v=!1;l(e.camera.position,w,o.controls.target.clone(),x,e.camera.quaternion,y,u,b=>{g&&(v||(g(b),v=!0))}),g&&setTimeout(()=>{v||(g(!0),v=!0)},u+10)},n.CameraGoHome=function(){var f=o.octreeBox.getBoundingBox(),u=f.min.clone().add(f.max.clone()).multiplyScalar(.5);let g=new S.Vector3(1,1,1);var y=f.max.distanceTo(f.min),w=u.clone().add(g.multiplyScalar(y*.5));if(e.camera.isOrthographicCamera){var x=o.container.clientWidth/o.container.clientHeight,v=y*.6;e.camera.left=-v*x,e.camera.right=v*x,e.camera.top=v,e.camera.bottom=-v,e.camera.zoom=1,e.camera.updateProjectionMatrix()}o.controlModule.orbitControls.origin=u.clone(),l(e.camera.position,w,o.controls.target.clone(),u)},n.zoomToBox=function(f){if(e.camera.isOrthographicCamera){let N=function(){i=requestAnimationFrame(N),F.update()};var u=f.min.clone().add(f.max.clone()).multiplyScalar(.5),g=e.camera.position.clone().sub(o.controls.target.clone()).normalize(),y=e.camera.position.distanceTo(o.controls.target),w=u.clone().add(g.multiplyScalar(y)),x=e.camera.zoom,v=new S.Vector3(1,0,0).applyQuaternion(e.camera.quaternion),b=new S.Vector3(0,1,0).applyQuaternion(e.camera.quaternion),D=[new S.Vector3(f.min.x,f.min.y,f.min.z),new S.Vector3(f.max.x,f.min.y,f.min.z),new S.Vector3(f.min.x,f.max.y,f.min.z),new S.Vector3(f.max.x,f.max.y,f.min.z),new S.Vector3(f.min.x,f.min.y,f.max.z),new S.Vector3(f.max.x,f.min.y,f.max.z),new S.Vector3(f.min.x,f.max.y,f.max.z),new S.Vector3(f.max.x,f.max.y,f.max.z)],T=1/0,k=-1/0,P=1/0,I=-1/0;for(var z of D){var C=z.dot(v),E=z.dot(b);T=Math.min(T,C),k=Math.max(k,C),P=Math.min(P,E),I=Math.max(I,E)}var M=(k-T)/2,B=(I-P)/2,V=(e.camera.right-e.camera.left)/2,U=(e.camera.top-e.camera.bottom)/2;x=Math.min(V/M,U/B)*.75;var H=e.camera.position.clone(),G=o.controls.target.clone(),$=e.camera.zoom,F=new hn.Tween({x1:H.x,y1:H.y,z1:H.z,x2:G.x,y2:G.y,z2:G.z,zoom:$}).to({x1:w.x,y1:w.y,z1:w.z,x2:u.x,y2:u.y,z2:u.z,zoom:x},1e3);F.onUpdate(function(te){o.controls&&(e.camera.position.set(te.x1,te.y1,te.z1),o.controls.target.set(te.x2,te.y2,te.z2),e.camera.isOrthographicCamera&&(e.camera.zoom=te.zoom,e.camera.updateProjectionMatrix()),o.controls.auto=!0,o.controls.update(),n.RenderScene())}),F.onComplete(function(){o.controls&&(o.controls.auto=!1,n.RenderScene(),cancelAnimationFrame(i),i=null)}),F.easing(hn.Easing.Cubic.InOut),F.start(),N()}else{var u=f.min.clone().add(f.max.clone()).multiplyScalar(.5);let ee=e.camera.position.clone().sub(o.controls.target.clone()).normalize();var w=u.clone().add(ee.multiplyScalar(2*f.max.distanceTo(f.min)));l(e.camera.position,w,o.controls.target.clone(),u)}};function l(f,u,g,y,w,x,v=1e3,b){var D;w&&x?(D=new hn.Tween({x1:f.x,y1:f.y,z1:f.z,x2:g.x,y2:g.y,z2:g.z,_x:w._x,_y:w._y,_z:w._z,_w:w._w}),D.to({x1:u.x,y1:u.y,z1:u.z,x2:y.x,y2:y.y,z2:y.z,_x:x._x,_y:x._y,_z:x._z,_w:x._w},v)):(D=new hn.Tween({x1:f.x,y1:f.y,z1:f.z,x2:g.x,y2:g.y,z2:g.z}),D.to({x1:u.x,y1:u.y,z1:u.z,x2:y.x,y2:y.y,z2:y.z},v)),D.onUpdate(function(k){o.controls&&(w&&x?(e.camera.quaternion._x=k._x,e.camera.quaternion._y=k._y,e.camera.quaternion._z=k._z,e.camera.quaternion._w=k._w):o.controls.auto=!0,e.camera.position.x=k.x1,e.camera.position.y=k.y1,e.camera.position.z=k.z1,o.controls.target.x=k.x2,o.controls.target.y=k.y2,o.controls.target.z=k.z2,o.controls.update(),n.RenderScene())}),D.onComplete(function(k){o.controls&&(o.controls.auto=!1,n.RenderScene(),b&&b(!0),cancelAnimationFrame(i),i=null)}),D.easing(hn.Easing.Cubic.InOut);function T(k){i=requestAnimationFrame(T),D.update()}D.start(),T()}function h(){s=document.createElement("div"),s.className="ViewCube",t.appendChild(s),r=document.createElement("div"),r.className="viewSettingWrapper",r.innerHTML="...",s.appendChild(r);var f=document.createElement("div");f.className="homeViewWrapper",f.addEventListener("mousedown",function(){console.log("归位"),n.CameraGoHome()}),s.appendChild(f);const u=document.createElement("div");u.className="cameraToggleWrapper",u.title="切换正交/透视视图",u.innerHTML="⊞",u.addEventListener("mousedown",function(v){v.stopPropagation(),console.log("切换视图"),n.ToggleCameraType(),w()}),s.appendChild(u);const g=document.createElement("div");g.className="screenshotWrapper",g.title="截图",g.innerHTML="📷",g.addEventListener("mousedown",function(v){v.stopPropagation(),console.log("截图"),n.TakeScreenshot(),w()}),s.appendChild(g);const y=document.createElement("div");y.className="fullscreenWrapper",y.title="全屏",y.innerHTML="⛶",y.addEventListener("mousedown",function(v){v.stopPropagation(),console.log("全屏"),n.ToggleFullscreen(),w()}),s.appendChild(y),r.addEventListener("mousedown",function(v){v.stopPropagation(),u.classList.contains("show")?(w(),console.log("隐藏功能按钮")):(x(),console.log("显示功能按钮"))});function w(){u.classList.remove("show"),g.classList.remove("show"),y.classList.remove("show")}function x(){u.classList.add("show"),g.classList.add("show"),y.classList.add("show")}}function c(){n.sceneOrtho=Jc();var g=t.clientWidth,y=t.clientWidth,f=g>y?g/y:y/g,u=300;n.camera=new S.OrthographicCamera(u*f/-2,u*f/2,u/2,u/-2,.01,1e4);var g=s.clientWidth,y=s.clientHeight,w=new S.WebGLRenderer({alpha:!0});w.setSize(g,y),w.setClearAlpha(0),n.sceneOrtho.renderer=w;let x=new S.AmbientLight(16777215,.8);n.sceneOrtho.add(x),Qc(s,w)}function d(){const f="/assets/viewcube/";let u=[{label:"右",icon:f+"cn_right.png"},{label:"左",icon:f+"cn_left.png"},{label:"顶",icon:f+"cn_top.png"},{label:"底",icon:f+"cn_bottom.png"},{label:"前",icon:f+"cn_front.png"},{label:"后",icon:f+"cn_back.png"}];var g=[];for(const w of u)g.push(new S.MeshBasicMaterial({color:16777215,map:new S.TextureLoader().load(w.icon)}));new S.MeshLambertMaterial({color:255});var y=new S.Mesh(new S.BoxGeometry(110,110,110),g);n.sceneOrtho.add(y),m(122),s.addEventListener("mousedown",w=>{var x={};x.x=w.offsetX/s.clientWidth*2-1,x.y=-(w.offsetY/s.clientHeight)*2+1;var v=new S.Raycaster;v.setFromCamera(x,n.camera);const b=v.intersectObjects(a,!1);b.length>0&&n.ToggleDirectionView(b[0].object.name)}),s.addEventListener("mousemove",w=>{var x={};x.x=w.offsetX/s.clientWidth*2-1,x.y=-(w.offsetY/s.clientHeight)*2+1;var v=new S.Raycaster;v.setFromCamera(x,n.camera);const b=v.intersectObjects(a,!1);for(var D of a)D.material.opacity=.01;b.length>0&&(b[0].object.material.opacity=.2)})}function m(f){for(var u=f*.5-20,g=[{name:"right",a:30,b:75,c:75,point:new S.Vector3(u,0,0)},{name:"back",a:75,b:75,c:30,point:new S.Vector3(0,0,-u)},{name:"left",a:30,b:75,c:75,point:new S.Vector3(-u,0,0)},{name:"front",a:75,b:75,c:30,point:new S.Vector3(0,0,u)},{name:"top",a:75,b:30,c:75,point:new S.Vector3(0,u,0)},{name:"button",a:75,b:30,c:75,point:new S.Vector3(0,-u,0)}],y=[{name:"top_right_back",a:30,b:30,c:30,point:new S.Vector3(-u,u,u)},{name:"button_front_right",a:30,b:30,c:30,point:new S.Vector3(-u,-u,u)},{name:"top_front_right",a:30,b:30,c:30,point:new S.Vector3(u,u,u)},{name:"button_right_back",a:30,b:30,c:30,point:new S.Vector3(u,-u,u)},{name:"top_back_left",a:30,b:30,c:30,point:new S.Vector3(-u,u,-u)},{name:"button_back_left",a:30,b:30,c:30,point:new S.Vector3(-u,-u,-u)},{name:"top_left_front",a:30,b:30,c:30,point:new S.Vector3(u,u,-u)},{name:"button_left_front",a:30,b:30,c:30,point:new S.Vector3(u,-u,-u)}],w=[{name:"top_front",a:30,b:30,c:75,point:new S.Vector3(u,u,0)},{name:"top_right",a:75,b:30,c:30,point:new S.Vector3(0,u,u)},{name:"top_back",a:30,b:30,c:75,point:new S.Vector3(-u,u,0)},{name:"top_left",a:75,b:30,c:30,point:new S.Vector3(0,u,-u)},{name:"button_front",a:30,b:30,c:75,point:new S.Vector3(u,-u,0)},{name:"button_right",a:75,b:30,c:30,point:new S.Vector3(0,-u,u)},{name:"button_back",a:30,b:30,c:75,point:new S.Vector3(-u,-u,0)},{name:"button_left",a:75,b:30,c:30,point:new S.Vector3(0,-u,-u)},{name:"front_right",a:30,b:75,c:30,point:new S.Vector3(u,0,u)},{name:"right_back",a:30,b:75,c:30,point:new S.Vector3(-u,0,u)},{name:"back_left",a:30,b:75,c:30,point:new S.Vector3(-u,0,-u)},{name:"left_front",a:30,b:75,c:30,point:new S.Vector3(u,0,-u)}],x=0;x<g.length;x++)a.push(p(g[x]));for(var x=0;x<y.length;x++)a.push(p(y[x]));for(var x=0;x<w.length;x++)a.push(p(w[x]))}function p(f){const u=new S.BoxGeometry(f.a,f.b,f.c),g=new S.MeshBasicMaterial({color:"blue",transparent:!0,opacity:.01}),y=new S.Matrix4().makeTranslation(f.point.x,f.point.y,f.point.z);let w=u.applyMatrix4(y),x=new S.Mesh(w,g);return x.name=f.name,n.sceneOrtho.add(x),x}return n.ToggleCameraType=function(){o.cameraModule.switchCurrentCamera()},n.TakeScreenshot=function(){try{if(!o.renderer){console.error("渲染器未初始化");return}o.renderer.render(e,e.camera);const u=o.renderer.domElement.toDataURL("image/png"),g=document.createElement("a"),y=new Date().toISOString().replaceAll(/[:.]/g,"-");g.download=`screenshot_${y}.png`,g.href=u,g.click(),console.log("截图已保存")}catch(f){console.error("截图失败:",f)}},n.ToggleFullscreen=function(){const f=t||document.documentElement;!document.fullscreenElement&&!document.webkitFullscreenElement&&!document.mozFullScreenElement&&!document.msFullscreenElement?(f.requestFullscreen?f.requestFullscreen():f.webkitRequestFullscreen?f.webkitRequestFullscreen():f.mozRequestFullScreen?f.mozRequestFullScreen():f.msRequestFullscreen&&f.msRequestFullscreen(),console.log("已进入全屏模式")):(document.exitFullscreen?document.exitFullscreen():document.webkitExitFullscreen?document.webkitExitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.msExitFullscreen&&document.msExitFullscreen(),console.log("已退出全屏模式"))},n}class th{engine;cubeTool;constructor(e){this.engine=e}init(){this.cubeTool=eh(this.engine,this.engine.scene,this.engine.container),this.cubeTool.init()}CameraGoHome(){this.cubeTool.CameraGoHome()}zoomToModel(e){this.cubeTool.zoomToBox(e)}hide(){}}function nh(o){let e=new Object;return e.getBoundingBox=function(){let t=o.models,n=new S.Vector3(1e8,1e9,1e10),i=new S.Vector3(-1e8,-1e9,-1e10);t.forEach(d=>{let m=d.boundingBox.min,p=d.boundingBox.max;m.x<n.x&&(n.x=m.x),m.y<n.y&&(n.y=m.y),m.z<n.z&&(n.z=m.z),p.x>i.x&&(i.x=p.x),p.y>i.y&&(i.y=p.y),p.z>i.z&&(i.z=p.z)});let s=Math.min(n.x,i.x),r=Math.min(n.y,i.y),a=Math.min(n.z,i.z),l=Math.max(n.x,i.x),h=Math.max(n.y,i.y),c=Math.max(n.z,i.z);return{min:new S.Vector3(s,r,a),max:new S.Vector3(l,h,c)}},e.rayInterationModel=function(t){let n=[];return o.engineStatus.models.forEach(r=>{r.info.lods.forEach(a=>{let l=a.octreeBox;s(t,l,r)})}),n=n.filter(r=>r instanceof S.Mesh),t.intersectObjects(n,!1);function s(r,a,l){if(a==null)return;let h=new S.Vector3(a.min.X*.3048,a.min.Z*.3048,-a.min.Y*.3048),c=new S.Vector3(a.max.X*.3048,a.max.Z*.3048,-a.max.Y*.3048),d=new S.Vector3(Math.min(h.x,c.X),Math.min(h.y,c.y),Math.min(h.z,c.z)),m=new S.Vector3(Math.max(c.x,h.x),Math.max(c.y,h.y),Math.max(c.z,h.z)),p=new S.Box3(d,m),f=r.ray.intersectsBox(p);if(!(f==null||f==!1))if(a.children==null||a.children.length==0){if(a.elements!=null)for(var u of a.elements){let g=o.engineStatus.hideModels.find(v=>v.url==l.url)?.ids;if(g!=null&&g.includes(u))continue;let y=o.engineStatus.translucentModels.find(v=>v.url==l.url)?.ids;if(y!=null&&y.includes(u))continue;let x=o.models.find(v=>v.url==l.url).nodesMap.get(u);x!=null&&!x.instance&&x.infos.map(b=>b.mesh).forEach(b=>{n.push(b)})}}else{if(a.elements!=null)for(var u of a.elements){let y=o.engineStatus.hideModels.find(b=>b.url==l.url)?.ids;if(y!=null&&y.includes(u))continue;let w=o.engineStatus.translucentModels.find(b=>b.url==l.url)?.ids;if(w!=null&&w.includes(u))continue;let v=o.models.find(b=>b.url==l.url).nodesMap.get(u);v!=null&&!v.instance&&v.infos.map(D=>D.mesh).forEach(D=>{n.push(D)})}for(let g of a.children)s(r,g,l)}}},e}class ih{engine;isDrawing=!1;startPoint=new S.Vector2;endPoint=new S.Vector2;selectionBox=null;worldToScreen=null;boundMouseDown;boundMouseMove;boundMouseUp;boundKeyDown;constructor(e){this.engine=e,this.boundMouseDown=this.onMouseDown.bind(this),this.boundMouseMove=this.onMouseMove.bind(this),this.boundMouseUp=this.onMouseUp.bind(this),this.boundKeyDown=this.onKeyDown.bind(this)}init(){this.createSelectionBoxElement(),this.engine.scene&&this.engine.camera&&this.engine.renderer&&(this.worldToScreen=new ze(this.engine.camera,this.engine.renderer,this.engine.scene))}active(){this.engine.controlModule.disActive();const e=this.engine.renderer?.domElement;e&&(e.addEventListener("mousedown",this.boundMouseDown),e.addEventListener("mousemove",this.boundMouseMove),e.addEventListener("mouseup",this.boundMouseUp),e.style.cursor="crosshair"),window.addEventListener("keydown",this.boundKeyDown)}disActive(){this.engine.controlModule.active();const e=this.engine.renderer?.domElement;e&&(e.removeEventListener("mousedown",this.boundMouseDown),e.removeEventListener("mousemove",this.boundMouseMove),e.removeEventListener("mouseup",this.boundMouseUp),e.style.cursor="default"),window.removeEventListener("keydown",this.boundKeyDown),this.isDrawing&&this.endDrawing()}createSelectionBoxElement(){this.selectionBox=document.createElement("div"),this.selectionBox.style.position="absolute",this.selectionBox.style.border="2px dashed #00aaff",this.selectionBox.style.backgroundColor="rgba(0, 170, 255, 0.1)",this.selectionBox.style.pointerEvents="none",this.selectionBox.style.display="none",this.selectionBox.style.zIndex="1000",this.selectionBox.style.boxSizing="border-box";const e=this.engine.renderer?.domElement;e&&e.parentElement&&e.parentElement.appendChild(this.selectionBox)}onMouseDown(e){e.button!==0||!this.engine.renderer?.domElement||(this.startPoint.set(e.offsetX,e.offsetY),this.endPoint.copy(this.startPoint),this.isDrawing=!0,this.selectionBox&&(this.selectionBox.style.display="block",this.updateSelectionBoxUI()),e.preventDefault(),e.stopPropagation())}onMouseMove(e){!this.isDrawing||!this.engine.renderer?.domElement||(this.endPoint.set(e.offsetX,e.offsetY),this.updateSelectionBoxUI(),e.preventDefault(),e.stopPropagation())}onMouseUp(e){this.isDrawing&&(this.endDrawing(),this.performZoom(),e.preventDefault(),e.stopPropagation(),this.disActive())}onKeyDown(e){e.key==="Escape"&&(this.disActive(),e.preventDefault(),e.stopPropagation())}endDrawing(){this.isDrawing&&(this.isDrawing=!1,this.selectionBox&&(this.selectionBox.style.display="none"))}updateSelectionBoxUI(){if(!this.selectionBox||!this.engine.renderer?.domElement)return;const t=Math.min(this.startPoint.x,this.endPoint.x),n=Math.min(this.startPoint.y,this.endPoint.y),i=Math.abs(this.endPoint.x-this.startPoint.x),s=Math.abs(this.endPoint.y-this.startPoint.y);this.selectionBox.style.left=`${t}px`,this.selectionBox.style.top=`${n}px`,this.selectionBox.style.width=`${i}px`,this.selectionBox.style.height=`${s}px`}performZoom(){const e=Math.abs(this.endPoint.x-this.startPoint.x),t=Math.abs(this.endPoint.y-this.startPoint.y);if(e<5||t<5)return;if(!this.worldToScreen){console.warn("RangeScale: 坐标转换工具未初始化");return}const n=Math.min(this.startPoint.x,this.endPoint.x),i=Math.max(this.startPoint.x,this.endPoint.x),s=Math.min(this.startPoint.y,this.endPoint.y),r=Math.max(this.startPoint.y,this.endPoint.y),a=[],l=[{x:n,y:s},{x:i,y:s},{x:i,y:r},{x:n,y:r}];for(const c of l){const d=this.worldToScreen.screenToWorld(c.x,c.y);d&&a.push(d)}if(a.length<3){console.warn("RangeScale: 框选区域未命中模型,无法执行缩放操作");return}if(a.length<3){console.warn("RangeScale: 无法将屏幕区域转换为世界坐标");return}const h=new S.Box3;for(const c of a)h.expandByPoint(c);if(h.isEmpty()){console.warn("RangeScale: 计算得到的包围盒无效");return}this.fitCameraToBoundingBox(h)}fitCameraToBoundingBox(e){const t=this.engine.camera,n=this.engine.controls;if(!t||!n){console.warn("RangeScale: 相机或控制器未初始化");return}const i=new S.Vector3;e.getCenter(i);const s=new S.Vector3;e.getSize(s);const r=Math.max(s.x,s.y,s.z);if(t instanceof S.PerspectiveCamera){const a=t.fov*(Math.PI/180),h=r/(2*Math.tan(a/2))*1.2,c=new S.Vector3;t.getWorldDirection(c);const d=i.clone().sub(t.position);c.dot(d.normalize())<0&&c.negate();const p=i.clone().sub(c.multiplyScalar(h));t.position.copy(p),n.target&&n.target.copy(i),t.lookAt(i),n.update()}else if(t instanceof S.OrthographicCamera){const l=r*1.2,h=this.engine.renderer?.domElement,c=h?h.width/h.height:1;t.left=-l*c/2,t.right=l*c/2,t.top=l/2,t.bottom=-l/2,t.updateProjectionMatrix();const d=new S.Vector3;t.getWorldDirection(d);const m=r*1.5,p=i.clone().sub(d.multiplyScalar(m));t.position.copy(p),n.target&&n.target.copy(i),t.lookAt(i),n.update()}}}class sh{engine;ground=null;constructor(e){this.engine=e}init(){}setStatsVisible(e){this.engine.stats?.dom&&(this.engine.stats.dom.style.display=e?"block":"none")}setAmbientLightIntensity(e){const t=this.engine.scene.children.find(n=>n instanceof S.AmbientLight);t&&(t.intensity=e)}setAmbientLightColor(e){const t=this.engine.scene.children.find(n=>n instanceof S.AmbientLight);t&&t.color.set(e)}setDirectionalLightIntensity(e){const t=this.engine.scene.children.find(n=>n instanceof S.DirectionalLight);t&&(t.intensity=e)}setDirectionalLightColor(e){const t=this.engine.scene.children.find(n=>n instanceof S.DirectionalLight);t&&t.color.set(e)}setShadowQuality(e){const t=this.engine.scene.children.find(n=>n instanceof S.DirectionalLight);if(t?.shadow){const i={low:1024,medium:2048,high:4096,ultra:8192}[e];t.shadow.mapSize.width=i,t.shadow.mapSize.height=i,t.shadow.map?.dispose(),t.shadow.map=null}}setDirectionalLightShadow(e){const t=this.engine.scene.children.find(n=>n instanceof S.DirectionalLight);t&&(t.castShadow=e),this.engine.renderer&&(this.engine.renderer.shadowMap.enabled=e)}setGTAOEnabled(e){if(!this.engine.composerModule?.composer){console.warn("Composer not initialized");return}const t=this.engine.composerModule.composer,n=t.passes.find(i=>i instanceof Ne);if(e)if(n)n.enabled=!0;else{const{width:i,height:s}=this.engine.deviceModule.getContainerSize(),r=new Ne(this.engine.scene,this.engine.camera,i,s);r.output=Ne.OUTPUT.Default,r.blendIntensity=.5,r.updateGtaoMaterial&&r.updateGtaoMaterial({radius:1,distanceExponent:1,thickness:1,scale:1,distanceFallOff:1,screenSpaceRadius:!0});const a=t.passes.findIndex(l=>l.constructor.name==="RenderPass");t.passes.splice(a+1,0,r)}else n&&(n.enabled=!1)}setSceneSaturation(e){if(!this.engine.composerModule?.saturationPass){console.warn("Saturation pass not initialized");return}this.engine.composerModule.saturationPass.uniforms.saturation.value=e}setSceneContrast(e){if(!this.engine.composerModule?.saturationPass){console.warn("Saturation pass not initialized");return}this.engine.composerModule.saturationPass.uniforms.contrast.value=e}setGroundEnabled(e,t){if(e)if(this.ground)this.ground.visible=!0;else{const n=t?.size??100,i=t?.color??8421504,s=t?.opacity??.3,r=new S.PlaneGeometry(n,n),a=new S.MeshStandardMaterial({color:i,transparent:!0,opacity:s,side:S.DoubleSide});this.ground=new S.Mesh(r,a),this.ground.rotation.x=-Math.PI/2,this.ground.position.y=0,this.ground.receiveShadow=!0,this.ground.name="ground",this.engine.scene.add(this.ground)}else this.ground&&(this.ground.visible=!1)}setHDRBackground(e){e?(this.engine.scene.background=e,this.engine.scene.environment=e):(this.engine.scene.background=null,this.engine.scene.environment=null)}}function it(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(o){var e=Math.random()*16|0,t=o=="x"?e:e&3|8;return t.toString(16)})}class st{engine;handelBehaved;setting;constructor(e){this.engine=e,this.handelBehaved=Ci(e),this.handelBehaved.init(this,null),this.setting={unit:"m",precision:3}}getSetting(){return this.setting}saveSetting(e){this.setting=e}active(){this.handelBehaved.active()}disActive(){this.handelBehaved.disActive()}getMeasureText(e,t){if(e==null)return null;let n=this.setting.unit,i=n;return t==1?n=="mm"?e=e*1e3:n=="cm"?e=e*100:n=="dm"?e=e*10:n=="m"?e=e*1:n=="km"&&(e=e*.001):t==2&&(n=="mm"?e=e*1e3*1e3:n=="cm"?e=e*100*100:n=="dm"?e=e*10*10:n=="m"?e=e*1*1:n=="km"&&(e=e*.001*.001),i=i+"²"),e.toFixed(this.setting.precision)+" "+i}cancelCurrentSelectedAnnotation(){let e=this.engine.measure.annotationData;for(let t in e)e[t].forEach(n=>{n.highlight==!0&&(n.highlight=!1,n.container.classList.remove("Hight"),n.container.getElementsByTagName("svg")[0].classList.remove("Hight"))})}handelKeyEscDown(){this.cancelCurrentSelectedAnnotation();let e=this.engine.measure.annotationData;for(let t in e)for(let n=e[t].length-1;n>=0;n--){let i=e[t][n];i.isSelect==!0&&(i.container.remove(),e[t].splice(n,1))}this.engine.measure.clearAllPoints()}handelKeyDeleteDown(){let e=this.engine.measure.annotationData;for(let t in e)for(let n=e[t].length-1;n>=0;n--){let i=e[t][n];i.highlight==!0&&(i.container.remove(),e[t].splice(n,1))}}clearHighlight(){let e=this.engine.measure.annotationData;for(let t in e)e[t].forEach(n=>{n.highlight=!1,n.container.classList.remove("Hight"),n.container.getElementsByTagName("svg")[0].classList.remove("Hight")})}drawNormalAnnotation(){let e=this;this.engine.measure.annotationData.normalAnnotation.forEach(f=>{p(f)}),this.engine.measure.annotationData.elevationAnnotation.forEach(f=>{m(f)}),this.engine.measure.annotationData.coordinateAnnotation.forEach(f=>{d(f)}),this.engine.measure.annotationData.angleAnnotation.forEach(f=>{l(f)}),this.engine.measure.annotationData.areaAnnotation.forEach(f=>{h(f)}),this.engine.measure.annotationData.slopeAnnotation.forEach(f=>{c(f)});function l(f){if(f.container==null){let T=['<svg class="measureSvg">','<circle cx="50" cy="50" r="5" fill="#f99d0b" />','<circle cx="50" cy="50" r="5" fill="#f99d0b" />','<circle cx="50" cy="50" r="5" fill="#f99d0b" />','<polyline stroke="orange" stroke-width="2" points="0,0 0,0" style="fill: none; opacity: 1;"/>','<polyline stroke="orange" stroke-width="2" points="0,0 0,0" style="fill: none; opacity: 1;"/>','<rect x="0" y="0" width="80" height="25" class="measureBack" />','<text x="40" y="16" text-anchor="middle" class="measureLabel">'+f.text+"</text>","</svg>"].join("");f.container=document.createElement("div"),f.container.className="angle-annotation",f.container.id=f.id,f.container.style.pointerEvents="none",f.container.innerHTML=T,e.engine.measure.annotationContainer.appendChild(f.container),f.container.getElementsByTagName("svg")[0].addEventListener("click",function(){e.clearHighlight(),f.container.getElementsByTagName("svg")[0].classList.add("Hight"),f.highlight=!0,e.engine.events.trigger(_e.MeasureClick,f)})}let u=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point1),g=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point2),y=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point3),w=e.engine.reactBoundingClientRect.left,x=e.engine.reactBoundingClientRect.top;u.x+=w,u.y+=x,g.x+=w,g.y+=x,y.x+=w,y.y+=x;let v=f.container;v.getElementsByTagName("circle")[0].setAttribute("cx",u.x),v.getElementsByTagName("circle")[0].setAttribute("cy",u.y),v.getElementsByTagName("circle")[1].setAttribute("cx",g.x),v.getElementsByTagName("circle")[1].setAttribute("cy",g.y),v.getElementsByTagName("circle")[2].setAttribute("cx",y.x),v.getElementsByTagName("circle")[2].setAttribute("cy",y.y),v.getElementsByTagName("polyline")[0].setAttribute("points",u.x+","+u.y+" "+g.x+","+g.y),v.getElementsByTagName("polyline")[1].setAttribute("points",g.x+","+g.y+" "+y.x+","+y.y);let b=g.x,D=g.y-30;v.getElementsByTagName("rect")[0].setAttribute("x",b-40),v.getElementsByTagName("rect")[0].setAttribute("y",D-12.5),v.getElementsByTagName("text")[0].setAttribute("x",b),v.getElementsByTagName("text")[0].setAttribute("y",D+4),v.getElementsByTagName("text")[0].innerHTML=f.text,v.style.top="0px",v.style.left="0px"}function h(f){if(f.container==null){let k=['<svg class="measureSvg">','<polygon fill="rgba(255, 165, 0, 0.3)" stroke="orange" stroke-width="2" points="" style="opacity: 0.3;"/>','<polyline stroke="orange" stroke-width="2" points="" style="fill: none; opacity: 1;"/>','<rect x="0" y="0" width="80" height="25" class="measureBack" />','<text x="40" y="16" text-anchor="middle" class="measureLabel">'+e.getMeasureText(f.text,2)+"</text>","</svg>"].join("");f.container=document.createElement("div"),f.container.className="area-annotation",f.container.id=f.id,f.container.innerHTML=k,e.engine.measure.annotationContainer.appendChild(f.container),f.container.getElementsByTagName("svg")[0].addEventListener("click",function(){e.clearHighlight(),f.container.getElementsByTagName("svg")[0].classList.add("Hight"),f.highlight=!0,e.engine.events.trigger(_e.MeasureClick,f)})}if(!f.points||f.points.length<3)return;let u=e.engine.reactBoundingClientRect.left,g=e.engine.reactBoundingClientRect.top,y=[],w=0,x=0;for(let k=0;k<f.points.length;k++){let P=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.points[k]);P.x+=u,P.y+=g,y.push(P),w+=P.x,x+=P.y}w=w/y.length,x=x/y.length;let v=y.map(k=>k.x+","+k.y).join(" "),b=f.container;b.getElementsByTagName("polygon")[0].setAttribute("points",v),b.getElementsByTagName("polyline")[0].setAttribute("points",v);let D=w,T=x;b.getElementsByTagName("rect")[0].setAttribute("x",D-40),b.getElementsByTagName("rect")[0].setAttribute("y",T-12.5),b.getElementsByTagName("text")[0].setAttribute("x",D),b.getElementsByTagName("text")[0].setAttribute("y",T+4),b.getElementsByTagName("text")[0].innerHTML=e.getMeasureText(f.text,2),b.style.top="0px",b.style.left="0px"}function c(f){if(f.container==null){let D=['<svg class="measureSvg">',"<defs>",'<marker id="slope-arrow-'+f.id+'" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto" markerUnits="strokeWidth">','<path d="M0,0 L0,6 L9,3 z" fill="orange" stroke="orange" />',"</marker>","</defs>",'<polyline stroke="orange" stroke-width="2" points="0,0 0,0" marker-end="url(#slope-arrow-'+f.id+')" style="fill: none; opacity: 1;"/>','<rect x="0" y="0" width="100" height="25" class="measureBack" />','<text x="50" y="16" text-anchor="middle" class="measureLabel">'+f.text+"</text>","</svg>"].join("");f.container=document.createElement("div"),f.container.className="slope-annotation",f.container.id=f.id,f.container.innerHTML=D,e.engine.measure.annotationContainer.appendChild(f.container),f.container.getElementsByTagName("svg")[0].addEventListener("click",function(){e.clearHighlight(),f.container.getElementsByTagName("svg")[0].classList.add("Hight"),f.highlight=!0,e.engine.events.trigger(_e.MeasureClick,f)})}let u=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point1),g=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point2),y=e.engine.reactBoundingClientRect.left,w=e.engine.reactBoundingClientRect.top;u.x+=y,u.y+=w,g.x+=y,g.y+=w;let x=f.container;x.getElementsByTagName("polyline")[0].setAttribute("points",u.x+","+u.y+" "+g.x+","+g.y);let v=(u.x+g.x)/2,b=(u.y+g.y)/2-30;x.getElementsByTagName("rect")[0].setAttribute("x",v-50),x.getElementsByTagName("rect")[0].setAttribute("y",b-12.5),x.getElementsByTagName("text")[0].setAttribute("x",v),x.getElementsByTagName("text")[0].setAttribute("y",b+4),x.getElementsByTagName("text")[0].innerHTML=f.text,x.style.top="0px",x.style.left="0px"}function d(f){if(f.container==null){let T=['<svg class="measureSvg">','<circle cx="0" cy="0" r="5" fill="#f99d0b" />','<rect x="0" y="-25" width="100" height="25" class="measureBack" />','<text x="40" y="-11" text-anchor="middle" class="measureLabel">X: '+e.getMeasureText(f.textX,1)+"</text>",'<rect x="0" y="-10" width="100" height="25" class="measureBack" />','<text x="40" y="25" text-anchor="middle" class="measureLabel">Y: '+e.getMeasureText(-f.textZ,1)+"</text>",'<rect x="0" y="10" width="100" height="25" class="measureBack" />','<text x="40" y="51" text-anchor="middle" class="measureLabel">Z: '+e.getMeasureText(f.textY,1)+"</text>","</svg>"].join("");f.container=document.createElement("div"),f.container.className="coordinate-annotation",f.container.id=f.id,f.container.style.position="absolute",f.container.style.pointerEvents="none",f.container.innerHTML=T,e.engine.measure.annotationContainer.appendChild(f.container),f.container.getElementsByTagName("svg")[0].addEventListener("click",function(){e.clearHighlight(),f.container.getElementsByTagName("svg")[0].classList.add("Hight"),f.highlight=!0,e.engine.events.trigger(_e.MeasureClick,f)})}let u=f.container,g=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point),y=e.engine.reactBoundingClientRect.left,w=e.engine.reactBoundingClientRect.top;g.x+=y,g.y+=w,u.style.top="0px",u.style.left="0px";let x=u.getElementsByTagName("circle")[0];x&&(x.setAttribute("cx",g.x),x.setAttribute("cy",g.y));let v=u.getElementsByTagName("rect"),b=u.getElementsByTagName("text"),D=-55;v[0]&&(v[0].setAttribute("x",g.x+10),v[0].setAttribute("y",g.y+10+D)),b[0]&&(b[0].setAttribute("x",g.x+10+40),b[0].setAttribute("y",g.y+10+16+D)),v[1]&&(v[1].setAttribute("x",g.x+10),v[1].setAttribute("y",g.y+10+30+D)),b[1]&&(b[1].setAttribute("x",g.x+10+40),b[1].setAttribute("y",g.y+10+46+D)),v[2]&&(v[2].setAttribute("x",g.x+10),v[2].setAttribute("y",g.y+10+60+D)),b[2]&&(b[2].setAttribute("x",g.x+10+40),b[2].setAttribute("y",g.y+10+76+D)),b[0]&&(b[0].innerHTML="X: "+e.getMeasureText(f.textX,1)),b[1]&&(b[1].innerHTML="Y: "+e.getMeasureText(-f.textZ,1)),b[2]&&(b[2].innerHTML="Z: "+e.getMeasureText(f.textY,1))}function m(f){if(f.container==null){let x=['<svg width="100" height="50" class="measureSvg">','<rect x="0" y="0" width="80" height="25" class="measureBack" />','<text x="40" y="16" text-anchor="middle" class="measureLabel">'+e.getMeasureText(f.text,1)+"</text>",'<polyline stroke="#f99d0b" stroke-width="2" points="80,32 0,32 16,48 32,32" style="fill: none; opacity: 1;"/>',"</svg>"].join("");f.container=document.createElement("div"),f.container.className="elevation-annotation",f.container.id=f.id,f.container.style.position="absolute",f.container.style.pointerEvents="none",f.container.innerHTML=x,e.engine.measure.annotationContainer.appendChild(f.container),f.container.getElementsByTagName("svg")[0].addEventListener("click",function(){e.clearHighlight(),f.container.getElementsByTagName("svg")[0].classList.add("Hight"),f.highlight=!0,e.engine.events.trigger(_e.MeasureClick,f)})}let u=f.container,g=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point),y=e.engine.reactBoundingClientRect.left,w=e.engine.reactBoundingClientRect.top;u.style.top=g.y+w-48+"px",u.style.left=g.x+y-16+"px",u.getElementsByTagName("text")[0].innerHTML=e.getMeasureText(f.text,1)}function p(f){if(f.container==null){let v=['<svg class="measureSvg">','<circle cx="50" cy="50" r="5" fill="#f99d0b" />','<circle cx="50" cy="50" r="5" fill="#f99d0b" />','<polyline stroke="orange" stroke-width="2" points="80,32 0,32" style="fill: none; opacity: 1;"/>','<rect x="0" y="0" width="80" height="25" class="measureBack" />','<text x="40" y="16" text-anchor="middle" class="measureLabel">'+e.getMeasureText(f.text,1)+"</text>","</svg>"].join("");f.container=document.createElement("div"),f.container.className="normal-annotation",f.container.id=f.id,f.container.innerHTML=v,e.engine.measure.annotationContainer.appendChild(f.container),f.container.getElementsByTagName("svg")[0].addEventListener("click",function(){e.clearHighlight(),f.container.getElementsByTagName("svg")[0].classList.add("Hight"),f.highlight=!0,e.engine.events.trigger(_e.MeasureClick,f)})}let u=f.container;if(f.point1==null||f.point2==null){u.style.display="none";return}else u.style.display="block";let g=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point1),y=new ze(e.engine.camera,e.engine.renderer,e.engine.scene).worldToScreen(f.point2),w=e.engine.reactBoundingClientRect.left,x=e.engine.reactBoundingClientRect.top;g.x+=w,g.y+=x,y.x+=w,y.y+=x,u.getElementsByTagName("polyline")[0].setAttribute("points",g.x+","+g.y+" "+y.x+","+y.y),u.getElementsByTagName("circle")[0].setAttribute("cx",g.x),u.getElementsByTagName("circle")[0].setAttribute("cy",g.y),u.getElementsByTagName("circle")[1].setAttribute("cx",y.x),u.getElementsByTagName("circle")[1].setAttribute("cy",y.y),u.getElementsByTagName("rect")[0].setAttribute("x",g.x*.5+y.x*.5-40),u.getElementsByTagName("rect")[0].setAttribute("y",g.y*.5+y.y*.5-12.5),u.getElementsByTagName("text")[0].setAttribute("x",g.x*.5+y.x*.5+40-40),u.getElementsByTagName("text")[0].setAttribute("y",g.y*.5+y.y*.5+16-12.5),u.getElementsByTagName("text")[0].innerHTML=e.getMeasureText(f.text,1),u.style.top="0px",u.style.left="0px"}}}class rh{engine;isActive=!1;tools;points=[];behavior;catchDir=0;type="point";constructor(e){this.engine=e,this.tools=new st(e)}active(){this.engine.measure.tools.cancelCurrentSelectedAnnotation(),this.isActive=!0,this.behavior=this.engine.handelBehaved,this.behavior.init(this),this.behavior.active();let e=this.engine.measure.annotationData.normalAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1)}disActive(){this.isActive=!1,this.behavior?.disActive()}clearAllPoints(){this.points=[]}setDirection(e){this.catchDir=e}setSelectType(e){this.type=e}getMeshesMinMaxY(e){if(!Array.isArray(e)||e.length===0)return null;let t=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(let i=0;i<e.length;i++){const s=e[i];if(!s)continue;typeof s.updateMatrixWorld=="function"&&s.updateMatrixWorld(!0);const r=new S.Box3().setFromObject(s);!Number.isFinite(r.min.y)||!Number.isFinite(r.max.y)||(r.min.y<t&&(t=r.min.y),r.max.y>n&&(n=r.max.y))}return!Number.isFinite(t)||!Number.isFinite(n)?null:{minY:t,maxY:n}}handleMouseClick(e){if(e.catch==null)return;let t=e.catch.point;if(this.type=="element"){let s=this.engine.interactionModule.getCatchMeshs(e);var n=this.getMeshesMinMaxY(s);this.catchDir==0?t.set(t.x,n?.minY,t.z):t.set(t.x,n?.maxY,t.z)}else t=e.catch.point;if(this.points.length==0){this.points.push(t);return}let i=this.engine.measure.annotationData.normalAnnotation.find(s=>s.isSelect==!0);i!=null&&(i.isSelect=!1)}handleMouseMove(e){if(e.catch==null||this.points.length==0)return;let t=this.engine.measure.annotationData.normalAnnotation.find(i=>i.isSelect==!0);t==null&&(t={text:null,id:it(),isSelect:!0,type:"clear-height"},this.engine.measure.annotationData.normalAnnotation.push(t));let n=e.catch;if(this.type=="element"){let i=e.catch.point.clone();i.set(i.x,this.points[0].y,i.z);let s=new S.Raycaster(i.add(new S.Vector3(0,.01,0)),new S.Vector3(0,this.catchDir==0?-1:1,0));n.point=this.points[0];const r=this.engine.octreeBox.rayInterationModel(s);if(r.length===0){t.point2=null;return}t.point1=i,t.point2=r[0].point,t.text=t.point1.clone().distanceTo(t.point2.clone()),this.engine.events.trigger(_e.MeasureChanged,t)}else{let i=new S.Raycaster(e.catch.point.clone().add(new S.Vector3(0,.01,0)),new S.Vector3(0,this.catchDir==0?-1:1,0));const s=this.engine.octreeBox.rayInterationModel(i);if(s.length===0){t.point2=null;return}t.point1=n.point,t.point2=s[0].point,t.text=t.point1.clone().distanceTo(t.point2.clone()),this.engine.events.trigger(_e.MeasureChanged,t)}}}class oh{engine;tools;isActive=!1;points=[];behavior;constructor(e){this.engine=e,this.tools=new st(e)}active(){this.engine.measure.tools.cancelCurrentSelectedAnnotation(),this.isActive=!0,this.points=[],this.behavior=this.engine.handelBehaved,this.behavior.init(this,{showCatch:!0}),this.behavior.active();let e=this.engine.measure.annotationData.normalAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1)}disActive(){this.points=[],this.isActive=!1,this.engine.handelBehaved.disActive()}clearAllPoints(){this.points=[]}handleMouseClick(e){if(e.catch==null)return;let t=e.catch;if(this.points.length==0)this.points.push(t.point);else if(this.points.length==1){let n=this.engine.measure.annotationData.normalAnnotation.find(i=>i.isSelect==!0);if(n==null)return;n.point2=t.point,n.isSelect=!1,this.points=[],this.engine.events.trigger(_e.MeasureChanged,n)}}handleMouseMove(e){if(e.catch==null)return;let t=e.catch;if(t!=null&&this.points.length==1){let n=this.engine.measure.annotationData.normalAnnotation.find(i=>i.isSelect==!0);n==null&&(n={id:it(),point1:this.points[0].clone(),point2:t.point.clone(),text:this.points[0].clone().distanceTo(t.point.clone()),type:"distance",isSelect:!0},this.engine.measure.annotationData.normalAnnotation.push(n)),n.point2=t.point,n.text=n.point1.clone().distanceTo(n.point2.clone())}}}class ah{engine;isActive=!1;tools;points=[];behavior;constructor(e){this.engine=e,this.tools=new st(e)}active(){this.engine.measure.tools.cancelCurrentSelectedAnnotation(),this.isActive=!0,this.behavior=this.engine.handelBehaved,this.behavior.init(this),this.behavior.active();let e=this.engine.measure.annotationData.normalAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1)}disActive(){this.isActive=!1,this.behavior?.disActive()}clearAllPoints(){this.points=[]}handleMouseClick(e){if(e.catch==null)return;if(this.points.length==0){this.points.push(e.catch.point);return}let t=this.engine.measure.annotationData.normalAnnotation.find(n=>n.isSelect==!0);t!=null&&(t.isSelect=!1)}handleMouseMove(e){if(e.catch==null||this.points.length==0)return;let t=this.engine.measure.annotationData.normalAnnotation.find(r=>r.isSelect==!0);t==null&&(t={text:null,id:it(),isSelect:!0,type:"clear-distance"},this.engine.measure.annotationData.normalAnnotation.push(t));let n=new S.Raycaster(e.catch.point.clone().add(e.catch.face.normal.clone().setLength(.01)),e.catch.face.normal);const i=this.engine.octreeBox.rayInterationModel(n);if(i.length==0){t.point2=null;return}let s=e.catch;t.point1=s.point,t.point2=i[0].point,t.text=t.point1.clone().distanceTo(t.point2.clone()),this.engine.events.trigger(_e.MeasureChanged,t)}}class lh{engine;isActive=!1;tools;points=[];behavior;constructor(e){this.engine=e,this.tools=new st(e)}active(){this.engine.measure.tools.cancelCurrentSelectedAnnotation(),this.behavior=this.engine.handelBehaved,this.behavior.init(this),this.behavior.active(),this.isActive=!0;let e=this.engine.measure.annotationData.normalAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1)}disActive(){this.isActive=!1,this.behavior?.disActive()}clearAllPoints(){this.points=[]}handleMouseMove(e){if(e.catch==null)return;let t=this.engine.measure.annotationData.elevationAnnotation.find(n=>n.isSelect==!0);t==null&&(t={id:it(),point:e.catch.point.clone(),text:e.catch.point.y,isSelect:!0,type:"elevation"},this.engine.measure.annotationData.elevationAnnotation.push(t)),t.point=e.catch.point.clone(),t.text=e.catch.point.y}handleMouseClick(e){if(e.catch==null)return;let t=this.engine.measure.annotationData.elevationAnnotation.find(n=>n.isSelect==!0);t!=null&&(t.isSelect=!1,t.point=e.catch.point.clone(),t.text=e.catch.point.y,this.engine.events.trigger(_e.MeasureChanged,t))}}class ch{engine;isActive=!1;tools;points=[];behavior;constructor(e){this.engine=e,this.tools=new st(e)}active(){this.engine.measure.tools.cancelCurrentSelectedAnnotation(),this.behavior=this.engine.handelBehaved,this.behavior.init(this),this.behavior.active(),this.isActive=!0;let e=this.engine.measure.annotationData.normalAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1)}disActive(){this.isActive=!1,this.behavior?.disActive()}clearAllPoints(){this.points=[]}handleMouseUp(e){this.engine.deviceType!="PC"&&this.createMeasure()}handleMouseMove(e){if(e.catch==null)return;let t=this.engine.measure.annotationData.coordinateAnnotation.find(n=>n.isSelect==!0);t==null&&(t={id:it(),point:e.catch.point.clone(),text:Math.round(e.catch.point.y)+" m",isSelect:!0,type:"point"},this.engine.measure.annotationData.coordinateAnnotation.push(t)),t.point=e.catch.point.clone(),t.textX=e.catch.point.x,t.textY=e.catch.point.y,t.textZ=e.catch.point.z}handleMouseClick(e){if(e.catch==null)return;let t=this.engine.measure.annotationData.coordinateAnnotation.find(n=>n.isSelect==!0);t!=null&&(t.point=e.catch.point.clone(),t.textX=e.catch.point.x,t.textY=e.catch.point.y,t.textZ=e.catch.point.z,t.isSelect=!1,this.engine.events.trigger(_e.MeasureChanged,t))}createMeasure(){let e=this.engine.measure.annotationData.coordinateAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1,this.engine.events.trigger(_e.MeasureChanged,e))}}class hh{engine;tools;points=[];behavior;constructor(e){this.engine=e,this.tools=new st(e)}active(){this.engine.measure.tools.cancelCurrentSelectedAnnotation(),this.points=[],this.behavior=this.engine.handelBehaved,this.behavior.init(this),this.behavior.active();let e=this.engine.measure.annotationData.normalAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1)}disActive(){this.points=[],this.behavior?.disActive()}clearAllPoints(){this.points=[]}calculateAngle(e,t,n){const i=new S.Vector3().subVectors(e,t),s=new S.Vector3().subVectors(n,t),r=i.length(),a=s.length();if(r===0||a===0)return 0;const h=i.dot(s)/(r*a),c=Math.max(-1,Math.min(1,h));return Math.acos(c)*(180/Math.PI)}handleMouseClick(e){if(e.catch==null)return;let t=e.catch;if(this.points.length==0)this.points.push(t.point);else if(this.points.length==1)this.points.push(t.point);else if(this.points.length==2){let n=this.engine.measure.annotationData.angleAnnotation.find(i=>i.isSelect==!0);if(n==null)return;n.point3=t.point.clone(),n.angle=this.calculateAngle(n.point1,n.point2,n.point3),n.text=n.angle.toFixed(2)+"°",n.isSelect=!1,n.type="angle",this.points=[],this.engine.events.trigger(_e.MeasureChanged,n)}}handleMouseMove(e){if(e.catch!=null&&this.points.length!=1&&this.points.length==2){let t=this.engine.measure.annotationData.angleAnnotation.find(n=>n.isSelect==!0);t==null&&(t={id:it(),point1:this.points[0].clone(),point2:this.points[1].clone(),point3:e.catch.point.clone(),angle:0,text:"0.00°",isSelect:!0,type:"angle"},this.engine.measure.annotationData.angleAnnotation.push(t)),t.point3=e.catch.point.clone(),t.angle=this.calculateAngle(t.point1,t.point2,t.point3),t.text=t.angle.toFixed(2)+"°",console.log("角度",t.text)}}}class uh{engine;tools;points=[];behavior;constructor(e){this.engine=e,this.tools=new st(e)}active(){this.engine.measure.tools.cancelCurrentSelectedAnnotation(),this.points=[],this.behavior=this.engine.handelBehaved,this.behavior.init(this),this.behavior.active();let e=this.engine.measure.annotationData.normalAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1)}disActive(){this.points=[],this.behavior?.disActive()}clearAllPoints(){this.points=[]}calculateArea(e){if(e.length<3)return 0;let t=0;const n=e.length;for(let i=0;i<n;i++){const s=(i+1)%n;t+=e[i].x*e[s].z,t-=e[s].x*e[i].z}return t=Math.abs(t)/2,t}handleMouseClick(e){if(e.catch==null)return;let t=e.catch;if(this.points.push(t.point.clone()),this.points.length>=3){let n=this.engine.measure.annotationData.areaAnnotation.find(i=>i.isSelect==!0);n==null?(n={id:it(),points:this.points.map(i=>i.clone()),area:0,text:0,isSelect:!0,type:"area"},this.engine.measure.annotationData.areaAnnotation.push(n)):(this.points.push(t.point.clone()),n.points=this.points.map(i=>i.clone())),n.area=this.calculateArea(n.points),n.text=n.area,console.log("面积",n.text)}}handleMouseMove(e){if(e.catch!=null&&this.points.length>=2){let t=this.engine.measure.annotationData.areaAnnotation.find(n=>n.isSelect==!0);if(t==null){if(this.points.length>=2){let n=this.points.map(i=>i.clone());n.push(e.catch.point.clone()),n.length>=3&&(t={id:it(),points:n,area:0,text:0,isSelect:!0,type:"area"},this.engine.measure.annotationData.areaAnnotation.push(t))}}else if(t.points.length>0){const n=t.points.length-1;t.points[n]=e.catch.point.clone()}else t.points=this.points.map(n=>n.clone()),t.points.push(e.catch.point.clone());t&&t.points.length>=3&&(t.area=this.calculateArea(t.points),t.text=t.area)}}handelKeyEnterDown(){this.finishMeasure()}finishMeasure(){this.points=this.points.slice(0,this.points.length-1);let e=this.engine.measure.annotationData.areaAnnotation.find(t=>t.isSelect==!0);e!=null&&e.points.length>=3&&(e.points.length>this.points.length&&(e.points=this.points.map(t=>t.clone())),e.area=this.calculateArea(e.points),e.text=e.area,e.isSelect=!1,this.points=[],this.engine.events.trigger(_e.MeasureChanged,e))}}class dh{engine;tools;points=[];behavior;constructor(e){this.engine=e,this.tools=new st(e)}active(){this.engine.measure.tools.cancelCurrentSelectedAnnotation(),this.points=[],this.behavior=this.engine.handelBehaved,this.behavior.init(this),this.behavior.active();let e=this.engine.measure.annotationData.normalAnnotation.find(t=>t.isSelect==!0);e!=null&&(e.isSelect=!1)}disActive(){this.points=[],this.behavior?.disActive()}clearAllPoints(){this.points=[]}calculateSlope(e,t){const n=t.y-e.y,i=t.x-e.x,s=t.z-e.z,r=Math.sqrt(i*i+s*s);if(r===0)return{percentage:0,angle:0,heightDiff:n,horizontalDist:0,type:"slope"};const a=n/r*100,h=Math.atan(n/r)*(180/Math.PI);return{percentage:a,angle:h,heightDiff:n,horizontalDist:r,type:"slope"}}handleMouseClick(e){if(e.catch==null)return;let t=e.catch;if(this.points.length==0)this.points.push(t.point);else if(this.points.length==1){let n=this.engine.measure.annotationData.slopeAnnotation.find(s=>s.isSelect==!0);if(n==null)return;console.log("进来了"),n.point2=t.point.clone();const i=this.calculateSlope(n.point1,n.point2);n.slopePercentage=i.percentage,n.slopeAngle=i.angle,n.heightDiff=i.heightDiff,n.horizontalDist=i.horizontalDist,n.text=i.percentage.toFixed(2)+"% ("+i.angle.toFixed(2)+"°)",n.isSelect=!1,this.points=[],this.engine.events.trigger(_e.MeasureChanged,n)}}handleMouseMove(e){if(e.catch==null)return;let t=e.catch;if(t!=null&&this.points.length==1){let n=this.engine.measure.annotationData.slopeAnnotation.find(s=>s.isSelect==!0);n==null&&(n={id:it(),point1:this.points[0].clone(),point2:t.point.clone(),slopePercentage:0,slopeAngle:0,heightDiff:0,horizontalDist:0,text:"0.00% (0.00°)",isSelect:!0,type:"slope"},this.engine.measure.annotationData.slopeAnnotation.push(n)),n.point2=t.point.clone();const i=this.calculateSlope(n.point1,n.point2);n.slopePercentage=i.percentage,n.slopeAngle=i.angle,n.heightDiff=i.heightDiff,n.horizontalDist=i.horizontalDist,n.text=i.percentage.toFixed(2)+"% ("+i.angle.toFixed(2)+"°)"}}}class fh{isActive=!1;engine;clearHeightMeasure;distanceMeasure;clearDistanceMeasure;elevationMeasure;pointMeasure;angleMeasure;areaMeasure;slopeMeasure;tools;annotationContainer;annotationData={normalAnnotation:[],textAnnotation:[],coordinateAnnotation:[],angleAnnotation:[],distanceAnnotation:[],areaAnnotation:[],slopeAnnotation:[],elevationAnnotation:[],volumeAnnotation:[]};constructor(e){this.engine=e,this.clearHeightMeasure=new rh(e),this.distanceMeasure=new oh(e),this.clearDistanceMeasure=new ah(e),this.elevationMeasure=new lh(e),this.pointMeasure=new ch(e),this.angleMeasure=new hh(e),this.areaMeasure=new uh(e),this.slopeMeasure=new dh(e),this.tools=new st(e),this.annotationContainer=document.createElement("div"),this.annotationContainer.className="annotation-container",e.container.appendChild(this.annotationContainer)}active(){this.isActive=!0,this.engine.modelEdge.loadModelEdge(),this.tools.active()}disActive(){this.tools.disActive(),this.clearAll(),this.isActive=!1,this.clearHeightMeasure.disActive(),this.distanceMeasure.disActive(),this.clearDistanceMeasure.disActive(),this.elevationMeasure.disActive(),this.pointMeasure.disActive(),this.angleMeasure.disActive(),this.areaMeasure.disActive(),this.slopeMeasure.disActive(),this.engine.interactionModule.init(),this.engine.interactionModule.active()}clearAllPoints(){this.clearHeightMeasure.clearAllPoints(),this.distanceMeasure.clearAllPoints(),this.clearDistanceMeasure.clearAllPoints(),this.elevationMeasure.clearAllPoints(),this.pointMeasure.clearAllPoints(),this.angleMeasure.clearAllPoints(),this.areaMeasure.clearAllPoints(),this.slopeMeasure.clearAllPoints()}clearAll(){e(this.annotationData.normalAnnotation),e(this.annotationData.textAnnotation),e(this.annotationData.coordinateAnnotation),e(this.annotationData.angleAnnotation),e(this.annotationData.distanceAnnotation),e(this.annotationData.areaAnnotation),e(this.annotationData.slopeAnnotation),e(this.annotationData.elevationAnnotation),e(this.annotationData.volumeAnnotation);function e(t){for(let n=0;n<t.length;n++)t[n].container.remove();t=[]}}saveSetting(e){this.tools.saveSetting(e)}getSetting(){return this.tools.getSetting()}update(){this.isActive&&this.tools.drawNormalAnnotation()}}const Gr=0,ph=1,mh=2,Wr=2,Ki=1.25,Xr=1,Ie=32,Me=Ie/4,Zr=65535,gh=Math.pow(2,-24),Yi=Symbol("SKIP_GENERATION");function yh(o){return o.index?o.index.count:o.attributes.position.count}function Dt(o){return yh(o)/3}function wh(o,e=ArrayBuffer){return o>65535?new Uint32Array(new e(4*o)):new Uint16Array(new e(2*o))}function xh(o,e){if(!o.index){const t=o.attributes.position.count,n=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=wh(t,n);o.setIndex(new _.BufferAttribute(i,1));for(let s=0;s<t;s++)i[s]=s}}function qr(o,e){const t=Dt(o),n=e||o.drawRange,i=n.start/3,s=(n.start+n.count)/3,r=Math.max(0,i),a=Math.min(t,s)-r;return[{offset:Math.floor(r),count:Math.floor(a)}]}function Kr(o,e){if(!o.groups||!o.groups.length)return qr(o,e);const t=[],n=e||o.drawRange,i=n.start/3,s=(n.start+n.count)/3,r=Dt(o),a=[];for(const c of o.groups){const{start:d,count:m}=c,p=d/3,f=isFinite(m)?m:r*3-d,u=(d+f)/3;p<s&&u>i&&(a.push({pos:Math.max(i,p),isStart:!0}),a.push({pos:Math.min(s,u),isStart:!1}))}a.sort((c,d)=>c.pos!==d.pos?c.pos-d.pos:c.type==="end"?-1:1);let l=0,h=null;for(const c of a){const d=c.pos;l!==0&&d!==h&&t.push({offset:h,count:d-h}),l+=c.isStart?1:-1,h=d}return t}function $i(o,e,t,n,i){let s=1/0,r=1/0,a=1/0,l=-1/0,h=-1/0,c=-1/0,d=1/0,m=1/0,p=1/0,f=-1/0,u=-1/0,g=-1/0;const y=o.offset||0;for(let w=(e-y)*6,x=(e+t-y)*6;w<x;w+=6){const v=o[w+0],b=o[w+1],D=v-b,T=v+b;D<s&&(s=D),T>l&&(l=T),v<d&&(d=v),v>f&&(f=v);const k=o[w+2],P=o[w+3],I=k-P,z=k+P;I<r&&(r=I),z>h&&(h=z),k<m&&(m=k),k>u&&(u=k);const C=o[w+4],E=o[w+5],M=C-E,B=C+E;M<a&&(a=M),B>c&&(c=B),C<p&&(p=C),C>g&&(g=C)}n[0]=s,n[1]=r,n[2]=a,n[3]=l,n[4]=h,n[5]=c,i[0]=d,i[1]=m,i[2]=p,i[3]=f,i[4]=u,i[5]=g}function Yr(o,e,t=null,n=null,i=null){const s=o.attributes.position,r=o.index?o.index.array:null,a=s.normalized;if(i===null)i=new Float32Array(t*6),i.offset=e;else if(e<0||t+e>i.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const l=s.array,h=s.offset||0;let c=3;s.isInterleavedBufferAttribute&&(c=s.data.stride);const d=["getX","getY","getZ"],m=i.offset;for(let p=e,f=e+t;p<f;p++){const g=(n?n[p]:p)*3,y=(p-m)*6;let w=g+0,x=g+1,v=g+2;r&&(w=r[w],x=r[x],v=r[v]),a||(w=w*c+h,x=x*c+h,v=v*c+h);for(let b=0;b<3;b++){let D,T,k;a?(D=s[d[b]](w),T=s[d[b]](x),k=s[d[b]](v)):(D=l[w+b],T=l[x+b],k=l[v+b]);let P=D;T<P&&(P=T),k<P&&(P=k);let I=D;T>I&&(I=T),k>I&&(I=k);const z=(I-P)/2,C=b*2;i[y+C+0]=P+z,i[y+C+1]=z+(Math.abs(P)+z)*gh}}return i}function we(o,e,t){return t.min.x=e[o],t.min.y=e[o+1],t.min.z=e[o+2],t.max.x=e[o+3],t.max.y=e[o+4],t.max.z=e[o+5],t}function $r(o){let e=-1,t=-1/0;for(let n=0;n<3;n++){const i=o[n+3]-o[n];i>t&&(t=i,e=n)}return e}function Hr(o,e){e.set(o)}function Jr(o,e,t){let n,i;for(let s=0;s<3;s++){const r=s+3;n=o[s],i=e[s],t[s]=n<i?n:i,n=o[r],i=e[r],t[r]=n>i?n:i}}function Yn(o,e,t){for(let n=0;n<3;n++){const i=e[o+2*n],s=e[o+2*n+1],r=i-s,a=i+s;r<t[n]&&(t[n]=r),a>t[n+3]&&(t[n+3]=a)}}function un(o){const e=o[3]-o[0],t=o[4]-o[1],n=o[5]-o[2];return 2*(e*t+t*n+n*e)}const rt=32,vh=(o,e)=>o.candidate-e.candidate,ft=new Array(rt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),$n=new Float32Array(6);function bh(o,e,t,n,i,s){let r=-1,a=0;if(s===Gr)r=$r(e),r!==-1&&(a=(e[r]+e[r+3])/2);else if(s===ph)r=$r(o),r!==-1&&(a=_h(t,n,i,r));else if(s===mh){const l=un(o);let h=Ki*i;const c=t.offset||0,d=(n-c)*6,m=(n+i-c)*6;for(let p=0;p<3;p++){const f=e[p],y=(e[p+3]-f)/rt;if(i<rt/4){const w=[...ft];w.length=i;let x=0;for(let b=d;b<m;b+=6,x++){const D=w[x];D.candidate=t[b+2*p],D.count=0;const{bounds:T,leftCacheBounds:k,rightCacheBounds:P}=D;for(let I=0;I<3;I++)P[I]=1/0,P[I+3]=-1/0,k[I]=1/0,k[I+3]=-1/0,T[I]=1/0,T[I+3]=-1/0;Yn(b,t,T)}w.sort(vh);let v=i;for(let b=0;b<v;b++){const D=w[b];for(;b+1<v&&w[b+1].candidate===D.candidate;)w.splice(b+1,1),v--}for(let b=d;b<m;b+=6){const D=t[b+2*p];for(let T=0;T<v;T++){const k=w[T];D>=k.candidate?Yn(b,t,k.rightCacheBounds):(Yn(b,t,k.leftCacheBounds),k.count++)}}for(let b=0;b<v;b++){const D=w[b],T=D.count,k=i-D.count,P=D.leftCacheBounds,I=D.rightCacheBounds;let z=0;T!==0&&(z=un(P)/l);let C=0;k!==0&&(C=un(I)/l);const E=Xr+Ki*(z*T+C*k);E<h&&(r=p,h=E,a=D.candidate)}}else{for(let v=0;v<rt;v++){const b=ft[v];b.count=0,b.candidate=f+y+v*y;const D=b.bounds;for(let T=0;T<3;T++)D[T]=1/0,D[T+3]=-1/0}for(let v=d;v<m;v+=6){let T=~~((t[v+2*p]-f)/y);T>=rt&&(T=rt-1);const k=ft[T];k.count++,Yn(v,t,k.bounds)}const w=ft[rt-1];Hr(w.bounds,w.rightCacheBounds);for(let v=rt-2;v>=0;v--){const b=ft[v],D=ft[v+1];Jr(b.bounds,D.rightCacheBounds,b.rightCacheBounds)}let x=0;for(let v=0;v<rt-1;v++){const b=ft[v],D=b.count,T=b.bounds,P=ft[v+1].rightCacheBounds;D!==0&&(x===0?Hr(T,$n):Jr(T,$n,$n)),x+=D;let I=0,z=0;x!==0&&(I=un($n)/l);const C=i-x;C!==0&&(z=un(P)/l);const E=Xr+Ki*(I*x+z*C);E<h&&(r=p,h=E,a=b.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${s} used.`);return{axis:r,pos:a}}function _h(o,e,t,n){let i=0;const s=o.offset;for(let r=e,a=e+t;r<a;r++)i+=o[(r-s)*6+n*2];return i/t}class Hi{constructor(){this.boundingData=new Float32Array(6)}}function Mh(o,e,t,n,i,s){let r=n,a=n+i-1;const l=s.pos,h=s.axis*2,c=t.offset||0;for(;;){for(;r<=a&&t[(r-c)*6+h]<l;)r++;for(;r<=a&&t[(a-c)*6+h]>=l;)a--;if(r<a){for(let d=0;d<3;d++){let m=e[r*3+d];e[r*3+d]=e[a*3+d],e[a*3+d]=m}for(let d=0;d<6;d++){const m=r-c,p=a-c,f=t[m*6+d];t[m*6+d]=t[p*6+d],t[p*6+d]=f}r++,a--}else return r}}function Sh(o,e,t,n,i,s){let r=n,a=n+i-1;const l=s.pos,h=s.axis*2,c=t.offset||0;for(;;){for(;r<=a&&t[(r-c)*6+h]<l;)r++;for(;r<=a&&t[(a-c)*6+h]>=l;)a--;if(r<a){let d=o[r];o[r]=o[a],o[a]=d;for(let m=0;m<6;m++){const p=r-c,f=a-c,u=t[p*6+m];t[p*6+m]=t[f*6+m],t[f*6+m]=u}r++,a--}else return r}}let Qr,Hn,Ji,eo;const Ah=Math.pow(2,32);function Qi(o){return"count"in o?1:1+Qi(o.left)+Qi(o.right)}function Ch(o,e,t){return Qr=new Float32Array(t),Hn=new Uint32Array(t),Ji=new Uint16Array(t),eo=new Uint8Array(t),es(o,e)}function es(o,e){const t=o/4,n=o/2,i="count"in e,s=e.boundingData;for(let r=0;r<6;r++)Qr[t+r]=s[r];if(i)return e.buffer?(eo.set(new Uint8Array(e.buffer),o),o+e.buffer.byteLength):(Hn[t+6]=e.offset,Ji[n+14]=e.count,Ji[n+15]=Zr,o+Ie);{const{left:r,right:a,splitAxis:l}=e,h=o+Ie;let c=es(h,r);const d=o/Ie,p=c/Ie-d;if(p>Ah)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return Hn[t+6]=p,Hn[t+7]=l,es(c,a)}}function Th(o,e,t){const i=(o.index?o.index.count:o.attributes.position.count)/3>2**16,s=t.reduce((c,d)=>c+d.count,0),r=i?4:2,a=e?new SharedArrayBuffer(s*r):new ArrayBuffer(s*r),l=i?new Uint32Array(a):new Uint16Array(a);let h=0;for(let c=0;c<t.length;c++){const{offset:d,count:m}=t[c];for(let p=0;p<m;p++)l[h+p]=d+p;h+=m}return l}function Ph(o,e,t,n,i){const{maxDepth:s,verbose:r,maxLeafTris:a,strategy:l,onProgress:h,indirect:c}=i,d=o._indirectBuffer,m=o.geometry,p=m.index?m.index.array:null,f=c?Sh:Mh,u=Dt(m),g=new Float32Array(6);let y=!1;const w=new Hi;return $i(e,t,n,w.boundingData,g),v(w,t,n,g),w;function x(b){h&&h(b/u)}function v(b,D,T,k=null,P=0){if(!y&&P>=s&&(y=!0,r&&(console.warn(`MeshBVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`),console.warn(m))),T<=a||P>=s)return x(D+T),b.offset=D,b.count=T,b;const I=bh(b.boundingData,k,e,D,T,l);if(I.axis===-1)return x(D+T),b.offset=D,b.count=T,b;const z=f(d,p,e,D,T,I);if(z===D||z===D+T)x(D+T),b.offset=D,b.count=T;else{b.splitAxis=I.axis;const C=new Hi,E=D,M=z-D;b.left=C,$i(e,E,M,C.boundingData,g),v(C,E,M,g,P+1);const B=new Hi,V=z,U=T-M;b.right=B,$i(e,V,U,B.boundingData,g),v(B,V,U,g,P+1)}return b}}function Dh(o,e){const t=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=o.geometry;let i,s;if(e.indirect){const r=Kr(n,e.range),a=Th(n,e.useSharedArrayBuffer,r);o._indirectBuffer=a,i=Yr(n,0,a.length,a),s=[{offset:0,count:a.length}]}else{xh(n,e);const r=qr(n,e.range)[0];i=Yr(n,r.offset,r.count),s=Kr(n,e.range)}o._roots=s.map(r=>{const a=Ph(o,i,r.offset,r.count,e),l=Qi(a),h=new t(Ie*l);return Ch(0,a,h),h})}class ot{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let n=1/0,i=-1/0;for(let s=0,r=e.length;s<r;s++){const l=e[s][t];n=l<n?l:n,i=l>i?l:i}this.min=n,this.max=i}setFromPoints(e,t){let n=1/0,i=-1/0;for(let s=0,r=t.length;s<r;s++){const a=t[s],l=e.dot(a);n=l<n?l:n,i=l>i?l:i}this.min=n,this.max=i}isSeparated(e){return this.min>e.max||e.min>this.max}}ot.prototype.setFromBox=(function(){const o=new _.Vector3;return function(t,n){const i=n.min,s=n.max;let r=1/0,a=-1/0;for(let l=0;l<=1;l++)for(let h=0;h<=1;h++)for(let c=0;c<=1;c++){o.x=i.x*l+s.x*(1-l),o.y=i.y*h+s.y*(1-h),o.z=i.z*c+s.z*(1-c);const d=t.dot(o);r=Math.min(d,r),a=Math.max(d,a)}this.min=r,this.max=a}})();const kh=(function(){const o=new _.Vector3,e=new _.Vector3,t=new _.Vector3;return function(i,s,r){const a=i.start,l=o,h=s.start,c=e;t.subVectors(a,h),o.subVectors(i.end,i.start),e.subVectors(s.end,s.start);const d=t.dot(c),m=c.dot(l),p=c.dot(c),f=t.dot(l),g=l.dot(l)*p-m*m;let y,w;g!==0?y=(d*m-f*p)/g:y=0,w=(d+y*m)/p,r.x=y,r.y=w}})(),ts=(function(){const o=new _.Vector2,e=new _.Vector3,t=new _.Vector3;return function(i,s,r,a){kh(i,s,o);let l=o.x,h=o.y;if(l>=0&&l<=1&&h>=0&&h<=1){i.at(l,r),s.at(h,a);return}else if(l>=0&&l<=1){h<0?s.at(0,a):s.at(1,a),i.closestPointToPoint(a,!0,r);return}else if(h>=0&&h<=1){l<0?i.at(0,r):i.at(1,r),s.closestPointToPoint(r,!0,a);return}else{let c;l<0?c=i.start:c=i.end;let d;h<0?d=s.start:d=s.end;const m=e,p=t;if(i.closestPointToPoint(d,!0,e),s.closestPointToPoint(c,!0,t),m.distanceToSquared(d)<=p.distanceToSquared(c)){r.copy(m),a.copy(d);return}else{r.copy(c),a.copy(p);return}}}})(),Ih=(function(){const o=new _.Vector3,e=new _.Vector3,t=new _.Plane,n=new _.Line3;return function(s,r){const{radius:a,center:l}=s,{a:h,b:c,c:d}=r;if(n.start=h,n.end=c,n.closestPointToPoint(l,!0,o).distanceTo(l)<=a||(n.start=h,n.end=d,n.closestPointToPoint(l,!0,o).distanceTo(l)<=a)||(n.start=c,n.end=d,n.closestPointToPoint(l,!0,o).distanceTo(l)<=a))return!0;const u=r.getPlane(t);if(Math.abs(u.distanceToPoint(l))<=a){const y=u.projectPoint(l,e);if(r.containsPoint(y))return!0}return!1}})(),Lh=["x","y","z"],at=1e-15,to=at*at;function je(o){return Math.abs(o)<at}class Ge extends _.Triangle{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new _.Vector3),this.satBounds=new Array(4).fill().map(()=>new ot),this.points=[this.a,this.b,this.c],this.plane=new _.Plane,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new _.Line3,this.needsUpdate=!0}intersectsSphere(e){return Ih(e,this)}update(){const e=this.a,t=this.b,n=this.c,i=this.points,s=this.satAxes,r=this.satBounds,a=s[0],l=r[0];this.getNormal(a),l.setFromPoints(a,i);const h=s[1],c=r[1];h.subVectors(e,t),c.setFromPoints(h,i);const d=s[2],m=r[2];d.subVectors(t,n),m.setFromPoints(d,i);const p=s[3],f=r[3];p.subVectors(n,e),f.setFromPoints(p,i);const u=h.length(),g=d.length(),y=p.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,u<at?g<at||y<at?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(n)):g<at?y<at?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):y<at&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(a,e),this.needsUpdate=!1}}Ge.prototype.closestPointToSegment=(function(){const o=new _.Vector3,e=new _.Vector3,t=new _.Line3;return function(i,s=null,r=null){const{start:a,end:l}=i,h=this.points;let c,d=1/0;for(let m=0;m<3;m++){const p=(m+1)%3;t.start.copy(h[m]),t.end.copy(h[p]),ts(t,i,o,e),c=o.distanceToSquared(e),c<d&&(d=c,s&&s.copy(o),r&&r.copy(e))}return this.closestPointToPoint(a,o),c=a.distanceToSquared(o),c<d&&(d=c,s&&s.copy(o),r&&r.copy(a)),this.closestPointToPoint(l,o),c=l.distanceToSquared(o),c<d&&(d=c,s&&s.copy(o),r&&r.copy(l)),Math.sqrt(d)}})(),Ge.prototype.intersectsTriangle=(function(){const o=new Ge,e=new ot,t=new ot,n=new _.Vector3,i=new _.Vector3,s=new _.Vector3,r=new _.Vector3,a=new _.Line3,l=new _.Line3,h=new _.Vector3,c=new _.Vector2,d=new _.Vector2;function m(x,v,b,D){const T=n;!x.isDegenerateIntoPoint&&!x.isDegenerateIntoSegment?T.copy(x.plane.normal):T.copy(v.plane.normal);const k=x.satBounds,P=x.satAxes;for(let C=1;C<4;C++){const E=k[C],M=P[C];if(e.setFromPoints(M,v.points),E.isSeparated(e)||(r.copy(T).cross(M),e.setFromPoints(r,x.points),t.setFromPoints(r,v.points),e.isSeparated(t)))return!1}const I=v.satBounds,z=v.satAxes;for(let C=1;C<4;C++){const E=I[C],M=z[C];if(e.setFromPoints(M,x.points),E.isSeparated(e)||(r.crossVectors(T,M),e.setFromPoints(r,x.points),t.setFromPoints(r,v.points),e.isSeparated(t)))return!1}return b&&(D||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),b.start.set(0,0,0),b.end.set(0,0,0)),!0}function p(x,v,b,D,T,k,P,I,z,C,E){let M=P/(P-I);C.x=D+(T-D)*M,E.start.subVectors(v,x).multiplyScalar(M).add(x),M=P/(P-z),C.y=D+(k-D)*M,E.end.subVectors(b,x).multiplyScalar(M).add(x)}function f(x,v,b,D,T,k,P,I,z,C,E){if(T>0)p(x.c,x.a,x.b,D,v,b,z,P,I,C,E);else if(k>0)p(x.b,x.a,x.c,b,v,D,I,P,z,C,E);else if(I*z>0||P!=0)p(x.a,x.b,x.c,v,b,D,P,I,z,C,E);else if(I!=0)p(x.b,x.a,x.c,b,v,D,I,P,z,C,E);else if(z!=0)p(x.c,x.a,x.b,D,v,b,z,P,I,C,E);else return!0;return!1}function u(x,v,b,D){const T=v.degenerateSegment,k=x.plane.distanceToPoint(T.start),P=x.plane.distanceToPoint(T.end);return je(k)?je(P)?m(x,v,b,D):(b&&(b.start.copy(T.start),b.end.copy(T.start)),x.containsPoint(T.start)):je(P)?(b&&(b.start.copy(T.end),b.end.copy(T.end)),x.containsPoint(T.end)):x.plane.intersectLine(T,n)!=null?(b&&(b.start.copy(n),b.end.copy(n)),x.containsPoint(n)):!1}function g(x,v,b){const D=v.a;return je(x.plane.distanceToPoint(D))&&x.containsPoint(D)?(b&&(b.start.copy(D),b.end.copy(D)),!0):!1}function y(x,v,b){const D=x.degenerateSegment,T=v.a;return D.closestPointToPoint(T,!0,n),T.distanceToSquared(n)<to?(b&&(b.start.copy(T),b.end.copy(T)),!0):!1}function w(x,v,b,D){if(x.isDegenerateIntoSegment)if(v.isDegenerateIntoSegment){const T=x.degenerateSegment,k=v.degenerateSegment,P=i,I=s;T.delta(P),k.delta(I);const z=n.subVectors(k.start,T.start),C=P.x*I.y-P.y*I.x;if(je(C))return!1;const E=(z.x*I.y-z.y*I.x)/C,M=-(P.x*z.y-P.y*z.x)/C;if(E<0||E>1||M<0||M>1)return!1;const B=T.start.z+P.z*E,V=k.start.z+I.z*M;return je(B-V)?(b&&(b.start.copy(T.start).addScaledVector(P,E),b.end.copy(T.start).addScaledVector(P,E)),!0):!1}else return v.isDegenerateIntoPoint?y(x,v,b):u(v,x,b,D);else{if(x.isDegenerateIntoPoint)return v.isDegenerateIntoPoint?v.a.distanceToSquared(x.a)<to?(b&&(b.start.copy(x.a),b.end.copy(x.a)),!0):!1:v.isDegenerateIntoSegment?y(v,x,b):g(v,x,b);if(v.isDegenerateIntoPoint)return g(x,v,b);if(v.isDegenerateIntoSegment)return u(x,v,b,D)}}return function(v,b=null,D=!1){this.needsUpdate&&this.update(),v.isExtendedTriangle?v.needsUpdate&&v.update():(o.copy(v),o.update(),v=o);const T=w(this,v,b,D);if(T!==void 0)return T;const k=this.plane,P=v.plane;let I=P.distanceToPoint(this.a),z=P.distanceToPoint(this.b),C=P.distanceToPoint(this.c);je(I)&&(I=0),je(z)&&(z=0),je(C)&&(C=0);const E=I*z,M=I*C;if(E>0&&M>0)return!1;let B=k.distanceToPoint(v.a),V=k.distanceToPoint(v.b),U=k.distanceToPoint(v.c);je(B)&&(B=0),je(V)&&(V=0),je(U)&&(U=0);const H=B*V,G=B*U;if(H>0&&G>0)return!1;i.copy(k.normal),s.copy(P.normal);const $=i.cross(s);let F=0,N=Math.abs($.x);const te=Math.abs($.y);te>N&&(N=te,F=1),Math.abs($.z)>N&&(F=2);const Y=Lh[F],ce=this.a[Y],fe=this.b[Y],se=this.c[Y],oe=v.a[Y],ue=v.b[Y],pe=v.c[Y];if(f(this,ce,fe,se,E,M,I,z,C,c,a))return m(this,v,b,D);if(f(v,oe,ue,pe,H,G,B,V,U,d,l))return m(this,v,b,D);if(c.y<c.x){const Ae=c.y;c.y=c.x,c.x=Ae,h.copy(a.start),a.start.copy(a.end),a.end.copy(h)}if(d.y<d.x){const Ae=d.y;d.y=d.x,d.x=Ae,h.copy(l.start),l.start.copy(l.end),l.end.copy(h)}return c.y<d.x||d.y<c.x?!1:(b&&(d.x>c.x?b.start.copy(l.start):b.start.copy(a.start),d.y<c.y?b.end.copy(l.end):b.end.copy(a.end)),!0)}})(),Ge.prototype.distanceToPoint=(function(){const o=new _.Vector3;return function(t){return this.closestPointToPoint(t,o),t.distanceTo(o)}})(),Ge.prototype.distanceToTriangle=(function(){const o=new _.Vector3,e=new _.Vector3,t=["a","b","c"],n=new _.Line3,i=new _.Line3;return function(r,a=null,l=null){const h=a||l?n:null;if(this.intersectsTriangle(r,h))return(a||l)&&(a&&h.getCenter(a),l&&h.getCenter(l)),0;let c=1/0;for(let d=0;d<3;d++){let m;const p=t[d],f=r[p];this.closestPointToPoint(f,o),m=f.distanceToSquared(o),m<c&&(c=m,a&&a.copy(o),l&&l.copy(f));const u=this[p];r.closestPointToPoint(u,o),m=u.distanceToSquared(o),m<c&&(c=m,a&&a.copy(u),l&&l.copy(o))}for(let d=0;d<3;d++){const m=t[d],p=t[(d+1)%3];n.set(this[m],this[p]);for(let f=0;f<3;f++){const u=t[f],g=t[(f+1)%3];i.set(r[u],r[g]),ts(n,i,o,e);const y=o.distanceToSquared(e);y<c&&(c=y,a&&a.copy(o),l&&l.copy(e))}}return Math.sqrt(c)}})();class Le{constructor(e,t,n){this.isOrientedBox=!0,this.min=new _.Vector3,this.max=new _.Vector3,this.matrix=new _.Matrix4,this.invMatrix=new _.Matrix4,this.points=new Array(8).fill().map(()=>new _.Vector3),this.satAxes=new Array(3).fill().map(()=>new _.Vector3),this.satBounds=new Array(3).fill().map(()=>new ot),this.alignedSatBounds=new Array(3).fill().map(()=>new ot),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),n&&this.matrix.copy(n)}set(e,t,n){this.min.copy(e),this.max.copy(t),this.matrix.copy(n),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}Le.prototype.update=(function(){return function(){const e=this.matrix,t=this.min,n=this.max,i=this.points;for(let h=0;h<=1;h++)for(let c=0;c<=1;c++)for(let d=0;d<=1;d++){const m=1*h|2*c|4*d,p=i[m];p.x=h?n.x:t.x,p.y=c?n.y:t.y,p.z=d?n.z:t.z,p.applyMatrix4(e)}const s=this.satBounds,r=this.satAxes,a=i[0];for(let h=0;h<3;h++){const c=r[h],d=s[h],m=1<<h,p=i[m];c.subVectors(a,p),d.setFromPoints(c,i)}const l=this.alignedSatBounds;l[0].setFromPointsField(i,"x"),l[1].setFromPointsField(i,"y"),l[2].setFromPointsField(i,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})(),Le.prototype.intersectsBox=(function(){const o=new ot;return function(t){this.needsUpdate&&this.update();const n=t.min,i=t.max,s=this.satBounds,r=this.satAxes,a=this.alignedSatBounds;if(o.min=n.x,o.max=i.x,a[0].isSeparated(o)||(o.min=n.y,o.max=i.y,a[1].isSeparated(o))||(o.min=n.z,o.max=i.z,a[2].isSeparated(o)))return!1;for(let l=0;l<3;l++){const h=r[l],c=s[l];if(o.setFromBox(h,t),c.isSeparated(o))return!1}return!0}})(),Le.prototype.intersectsTriangle=(function(){const o=new Ge,e=new Array(3),t=new ot,n=new ot,i=new _.Vector3;return function(r){this.needsUpdate&&this.update(),r.isExtendedTriangle?r.needsUpdate&&r.update():(o.copy(r),o.update(),r=o);const a=this.satBounds,l=this.satAxes;e[0]=r.a,e[1]=r.b,e[2]=r.c;for(let m=0;m<3;m++){const p=a[m],f=l[m];if(t.setFromPoints(f,e),p.isSeparated(t))return!1}const h=r.satBounds,c=r.satAxes,d=this.points;for(let m=0;m<3;m++){const p=h[m],f=c[m];if(t.setFromPoints(f,d),p.isSeparated(t))return!1}for(let m=0;m<3;m++){const p=l[m];for(let f=0;f<4;f++){const u=c[f];if(i.crossVectors(p,u),t.setFromPoints(i,e),n.setFromPoints(i,d),t.isSeparated(n))return!1}}return!0}})(),Le.prototype.closestPointToPoint=(function(){return function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}})(),Le.prototype.distanceToPoint=(function(){const o=new _.Vector3;return function(t){return this.closestPointToPoint(t,o),t.distanceTo(o)}})(),Le.prototype.distanceToBox=(function(){const o=["x","y","z"],e=new Array(12).fill().map(()=>new _.Line3),t=new Array(12).fill().map(()=>new _.Line3),n=new _.Vector3,i=new _.Vector3;return function(r,a=0,l=null,h=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(l||h)&&(r.getCenter(i),this.closestPointToPoint(i,n),r.closestPointToPoint(n,i),l&&l.copy(n),h&&h.copy(i)),0;const c=a*a,d=r.min,m=r.max,p=this.points;let f=1/0;for(let g=0;g<8;g++){const y=p[g];i.copy(y).clamp(d,m);const w=y.distanceToSquared(i);if(w<f&&(f=w,l&&l.copy(y),h&&h.copy(i),w<c))return Math.sqrt(w)}let u=0;for(let g=0;g<3;g++)for(let y=0;y<=1;y++)for(let w=0;w<=1;w++){const x=(g+1)%3,v=(g+2)%3,b=y<<x|w<<v,D=1<<g|y<<x|w<<v,T=p[b],k=p[D];e[u].set(T,k);const I=o[g],z=o[x],C=o[v],E=t[u],M=E.start,B=E.end;M[I]=d[I],M[z]=y?d[z]:m[z],M[C]=w?d[C]:m[z],B[I]=m[I],B[z]=y?d[z]:m[z],B[C]=w?d[C]:m[z],u++}for(let g=0;g<=1;g++)for(let y=0;y<=1;y++)for(let w=0;w<=1;w++){i.x=g?m.x:d.x,i.y=y?m.y:d.y,i.z=w?m.z:d.z,this.closestPointToPoint(i,n);const x=i.distanceToSquared(n);if(x<f&&(f=x,l&&l.copy(n),h&&h.copy(i),x<c))return Math.sqrt(x)}for(let g=0;g<12;g++){const y=e[g];for(let w=0;w<12;w++){const x=t[w];ts(y,x,n,i);const v=n.distanceToSquared(i);if(v<f&&(f=v,l&&l.copy(n),h&&h.copy(i),v<c))return Math.sqrt(v)}}return Math.sqrt(f)}})();class ns{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class Eh extends ns{constructor(){super(()=>new Ge)}}const We=new Eh;function Se(o,e){return e[o+15]===Zr}function Ue(o,e){return e[o+6]}function Xe(o,e){return e[o+14]}function Te(o){return o+Me}function Pe(o,e){const t=e[o+6];return o+t*Me}function is(o,e){return e[o+7]}function Qd(o){return o}class Bh{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=n=>{t&&e.push(t),t=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const me=new Bh;let pt,qt;const Kt=[],Jn=new ns(()=>new _.Box3);function Oh(o,e,t,n,i,s){pt=Jn.getPrimitive(),qt=Jn.getPrimitive(),Kt.push(pt,qt),me.setBuffer(o._roots[e]);const r=ss(0,o.geometry,t,n,i,s);me.clearBuffer(),Jn.releasePrimitive(pt),Jn.releasePrimitive(qt),Kt.pop(),Kt.pop();const a=Kt.length;return a>0&&(qt=Kt[a-1],pt=Kt[a-2]),r}function ss(o,e,t,n,i=null,s=0,r=0){const{float32Array:a,uint16Array:l,uint32Array:h}=me;let c=o*2;if(Se(c,l)){const m=Ue(o,h),p=Xe(c,l);return we(o,a,pt),n(m,p,!1,r,s+o/Me,pt)}else{let I=function(C){const{uint16Array:E,uint32Array:M}=me;let B=C*2;for(;!Se(B,E);)C=Te(C),B=C*2;return Ue(C,M)},z=function(C){const{uint16Array:E,uint32Array:M}=me;let B=C*2;for(;!Se(B,E);)C=Pe(C,M),B=C*2;return Ue(C,M)+Xe(B,E)};const m=Te(o),p=Pe(o,h);let f=m,u=p,g,y,w,x;if(i&&(w=pt,x=qt,we(f,a,w),we(u,a,x),g=i(w),y=i(x),y<g)){f=p,u=m;const C=g;g=y,y=C,w=x}w||(w=pt,we(f,a,w));const v=Se(f*2,l),b=t(w,v,g,r+1,s+f/Me);let D;if(b===Wr){const C=I(f),M=z(f)-C;D=n(C,M,!0,r+1,s+f/Me,w)}else D=b&&ss(f,e,t,n,i,s,r+1);if(D)return!0;x=qt,we(u,a,x);const T=Se(u*2,l),k=t(x,T,y,r+1,s+u/Me);let P;if(k===Wr){const C=I(u),M=z(u)-C;P=n(C,M,!0,r+1,s+u/Me,x)}else P=k&&ss(u,e,t,n,i,s,r+1);return!!P}}const dn=new _.Vector3,rs=new _.Vector3;function zh(o,e,t={},n=0,i=1/0){const s=n*n,r=i*i;let a=1/0,l=null;if(o.shapecast({boundsTraverseOrder:c=>(dn.copy(e).clamp(c.min,c.max),dn.distanceToSquared(e)),intersectsBounds:(c,d,m)=>m<a&&m<r,intersectsTriangle:(c,d)=>{c.closestPointToPoint(e,dn);const m=e.distanceToSquared(dn);return m<a&&(rs.copy(dn),a=m,l=d),m<s}}),a===1/0)return null;const h=Math.sqrt(a);return t.point?t.point.copy(rs):t.point=rs.clone(),t.distance=h,t.faceIndex=l,t}const Qn=parseInt(_.REVISION)>=169,Nh=parseInt(_.REVISION)<=161,kt=new _.Vector3,It=new _.Vector3,Lt=new _.Vector3,ei=new _.Vector2,ti=new _.Vector2,ni=new _.Vector2,no=new _.Vector3,io=new _.Vector3,so=new _.Vector3,fn=new _.Vector3;function Rh(o,e,t,n,i,s,r,a){let l;if(s===_.BackSide?l=o.intersectTriangle(n,t,e,!0,i):l=o.intersectTriangle(e,t,n,s!==_.DoubleSide,i),l===null)return null;const h=o.origin.distanceTo(i);return h<r||h>a?null:{distance:h,point:i.clone()}}function ro(o,e,t,n,i,s,r,a,l,h,c){kt.fromBufferAttribute(e,s),It.fromBufferAttribute(e,r),Lt.fromBufferAttribute(e,a);const d=Rh(o,kt,It,Lt,fn,l,h,c);if(d){if(n){ei.fromBufferAttribute(n,s),ti.fromBufferAttribute(n,r),ni.fromBufferAttribute(n,a),d.uv=new _.Vector2;const p=_.Triangle.getInterpolation(fn,kt,It,Lt,ei,ti,ni,d.uv);Qn||(d.uv=p)}if(i){ei.fromBufferAttribute(i,s),ti.fromBufferAttribute(i,r),ni.fromBufferAttribute(i,a),d.uv1=new _.Vector2;const p=_.Triangle.getInterpolation(fn,kt,It,Lt,ei,ti,ni,d.uv1);Qn||(d.uv1=p),Nh&&(d.uv2=d.uv1)}if(t){no.fromBufferAttribute(t,s),io.fromBufferAttribute(t,r),so.fromBufferAttribute(t,a),d.normal=new _.Vector3;const p=_.Triangle.getInterpolation(fn,kt,It,Lt,no,io,so,d.normal);d.normal.dot(o.direction)>0&&d.normal.multiplyScalar(-1),Qn||(d.normal=p)}const m={a:s,b:r,c:a,normal:new _.Vector3,materialIndex:0};if(_.Triangle.getNormal(kt,It,Lt,m.normal),d.face=m,d.faceIndex=s,Qn){const p=new _.Vector3;_.Triangle.getBarycoord(fn,kt,It,Lt,p),d.barycoord=p}}return d}function oo(o){return o&&o.isMaterial?o.side:o}function ii(o,e,t,n,i,s,r){const a=n*3;let l=a+0,h=a+1,c=a+2;const{index:d,groups:m}=o;o.index&&(l=d.getX(l),h=d.getX(h),c=d.getX(c));const{position:p,normal:f,uv:u,uv1:g}=o.attributes;if(Array.isArray(e)){const y=n*3;for(let w=0,x=m.length;w<x;w++){const{start:v,count:b,materialIndex:D}=m[w];if(y>=v&&y<v+b){const T=oo(e[D]),k=ro(t,p,f,u,g,l,h,c,T,s,r);if(k)if(k.faceIndex=n,k.face.materialIndex=D,i)i.push(k);else return k}}}else{const y=oo(e),w=ro(t,p,f,u,g,l,h,c,y,s,r);if(w)if(w.faceIndex=n,w.face.materialIndex=0,i)i.push(w);else return w}return null}function be(o,e,t,n){const i=o.a,s=o.b,r=o.c;let a=e,l=e+1,h=e+2;t&&(a=t.getX(a),l=t.getX(l),h=t.getX(h)),i.x=n.getX(a),i.y=n.getY(a),i.z=n.getZ(a),s.x=n.getX(l),s.y=n.getY(l),s.z=n.getZ(l),r.x=n.getX(h),r.y=n.getY(h),r.z=n.getZ(h)}function Fh(o,e,t,n,i,s,r,a){const{geometry:l,_indirectBuffer:h}=o;for(let c=n,d=n+i;c<d;c++)ii(l,e,t,c,s,r,a)}function Uh(o,e,t,n,i,s,r){const{geometry:a,_indirectBuffer:l}=o;let h=1/0,c=null;for(let d=n,m=n+i;d<m;d++){let p;p=ii(a,e,t,d,null,s,r),p&&p.distance<h&&(c=p,h=p.distance)}return c}function Vh(o,e,t,n,i,s,r){const{geometry:a}=t,{index:l}=a,h=a.attributes.position;for(let c=o,d=e+o;c<d;c++){let m;if(m=c,be(r,m*3,l,h),r.needsUpdate=!0,n(r,m,i,s))return!0}return!1}function jh(o,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=o.geometry,n=t.index?t.index.array:null,i=t.attributes.position;let s,r,a,l,h=0;const c=o._roots;for(let m=0,p=c.length;m<p;m++)s=c[m],r=new Uint32Array(s),a=new Uint16Array(s),l=new Float32Array(s),d(0,h),h+=s.byteLength;function d(m,p,f=!1){const u=m*2;if(Se(u,a)){const g=r[m+6],y=a[u+14];let w=1/0,x=1/0,v=1/0,b=-1/0,D=-1/0,T=-1/0;for(let k=3*g,P=3*(g+y);k<P;k++){let I=n[k];const z=i.getX(I),C=i.getY(I),E=i.getZ(I);z<w&&(w=z),z>b&&(b=z),C<x&&(x=C),C>D&&(D=C),E<v&&(v=E),E>T&&(T=E)}return l[m+0]!==w||l[m+1]!==x||l[m+2]!==v||l[m+3]!==b||l[m+4]!==D||l[m+5]!==T?(l[m+0]=w,l[m+1]=x,l[m+2]=v,l[m+3]=b,l[m+4]=D,l[m+5]=T,!0):!1}else{const g=Te(m),y=Pe(m,r);let w=f,x=!1,v=!1;if(e){if(!w){const I=g/Me+p/Ie,z=y/Me+p/Ie;x=e.has(I),v=e.has(z),w=!x&&!v}}else x=!0,v=!0;const b=w||x,D=w||v;let T=!1;b&&(T=d(g,p,w));let k=!1;D&&(k=d(y,p,w));const P=T||k;if(P)for(let I=0;I<3;I++){const z=g+I,C=y+I,E=l[z],M=l[z+3],B=l[C],V=l[C+3];l[m+I]=E<B?E:B,l[m+I+3]=M>V?M:V}return P}}}function mt(o,e,t,n,i){let s,r,a,l,h,c;const d=1/t.direction.x,m=1/t.direction.y,p=1/t.direction.z,f=t.origin.x,u=t.origin.y,g=t.origin.z;let y=e[o],w=e[o+3],x=e[o+1],v=e[o+3+1],b=e[o+2],D=e[o+3+2];return d>=0?(s=(y-f)*d,r=(w-f)*d):(s=(w-f)*d,r=(y-f)*d),m>=0?(a=(x-u)*m,l=(v-u)*m):(a=(v-u)*m,l=(x-u)*m),s>l||a>r||((a>s||isNaN(s))&&(s=a),(l<r||isNaN(r))&&(r=l),p>=0?(h=(b-g)*p,c=(D-g)*p):(h=(D-g)*p,c=(b-g)*p),s>c||h>r)?!1:((h>s||s!==s)&&(s=h),(c<r||r!==r)&&(r=c),s<=i&&r>=n)}function Gh(o,e,t,n,i,s,r,a){const{geometry:l,_indirectBuffer:h}=o;for(let c=n,d=n+i;c<d;c++){let m=h?h[c]:c;ii(l,e,t,m,s,r,a)}}function Wh(o,e,t,n,i,s,r){const{geometry:a,_indirectBuffer:l}=o;let h=1/0,c=null;for(let d=n,m=n+i;d<m;d++){let p;p=ii(a,e,t,l?l[d]:d,null,s,r),p&&p.distance<h&&(c=p,h=p.distance)}return c}function Xh(o,e,t,n,i,s,r){const{geometry:a}=t,{index:l}=a,h=a.attributes.position;for(let c=o,d=e+o;c<d;c++){let m;if(m=t.resolveTriangleIndex(c),be(r,m*3,l,h),r.needsUpdate=!0,n(r,m,i,s))return!0}return!1}function Zh(o,e,t,n,i,s,r){me.setBuffer(o._roots[e]),os(0,o,t,n,i,s,r),me.clearBuffer()}function os(o,e,t,n,i,s,r){const{float32Array:a,uint16Array:l,uint32Array:h}=me,c=o*2;if(Se(c,l)){const m=Ue(o,h),p=Xe(c,l);Fh(e,t,n,m,p,i,s,r)}else{const m=Te(o);mt(m,a,n,s,r)&&os(m,e,t,n,i,s,r);const p=Pe(o,h);mt(p,a,n,s,r)&&os(p,e,t,n,i,s,r)}}const qh=["x","y","z"];function Kh(o,e,t,n,i,s){me.setBuffer(o._roots[e]);const r=as(0,o,t,n,i,s);return me.clearBuffer(),r}function as(o,e,t,n,i,s){const{float32Array:r,uint16Array:a,uint32Array:l}=me;let h=o*2;if(Se(h,a)){const d=Ue(o,l),m=Xe(h,a);return Uh(e,t,n,d,m,i,s)}else{const d=is(o,l),m=qh[d],f=n.direction[m]>=0;let u,g;f?(u=Te(o),g=Pe(o,l)):(u=Pe(o,l),g=Te(o));const w=mt(u,r,n,i,s)?as(u,e,t,n,i,s):null;if(w){const b=w.point[m];if(f?b<=r[g+d]:b>=r[g+d+3])return w}const v=mt(g,r,n,i,s)?as(g,e,t,n,i,s):null;return w&&v?w.distance<=v.distance?w:v:w||v||null}}const si=new _.Box3,Yt=new Ge,$t=new Ge,pn=new _.Matrix4,ao=new Le,ri=new Le;function Yh(o,e,t,n){me.setBuffer(o._roots[e]);const i=ls(0,o,t,n);return me.clearBuffer(),i}function ls(o,e,t,n,i=null){const{float32Array:s,uint16Array:r,uint32Array:a}=me;let l=o*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),ao.set(t.boundingBox.min,t.boundingBox.max,n),i=ao),Se(l,r)){const c=e.geometry,d=c.index,m=c.attributes.position,p=t.index,f=t.attributes.position,u=Ue(o,a),g=Xe(l,r);if(pn.copy(n).invert(),t.boundsTree)return we(o,s,ri),ri.matrix.copy(pn),ri.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:w=>ri.intersectsBox(w),intersectsTriangle:w=>{w.a.applyMatrix4(n),w.b.applyMatrix4(n),w.c.applyMatrix4(n),w.needsUpdate=!0;for(let x=u*3,v=(g+u)*3;x<v;x+=3)if(be($t,x,d,m),$t.needsUpdate=!0,w.intersectsTriangle($t))return!0;return!1}});{const y=Dt(t);for(let w=u*3,x=(g+u)*3;w<x;w+=3){be(Yt,w,d,m),Yt.a.applyMatrix4(pn),Yt.b.applyMatrix4(pn),Yt.c.applyMatrix4(pn),Yt.needsUpdate=!0;for(let v=0,b=y*3;v<b;v+=3)if(be($t,v,p,f),$t.needsUpdate=!0,Yt.intersectsTriangle($t))return!0}}}else{const c=Te(o),d=Pe(o,a);return we(c,s,si),!!(i.intersectsBox(si)&&ls(c,e,t,n,i)||(we(d,s,si),i.intersectsBox(si)&&ls(d,e,t,n,i)))}}const oi=new _.Matrix4,cs=new Le,mn=new Le,$h=new _.Vector3,Hh=new _.Vector3,Jh=new _.Vector3,Qh=new _.Vector3;function eu(o,e,t,n={},i={},s=0,r=1/0){e.boundingBox||e.computeBoundingBox(),cs.set(e.boundingBox.min,e.boundingBox.max,t),cs.needsUpdate=!0;const a=o.geometry,l=a.attributes.position,h=a.index,c=e.attributes.position,d=e.index,m=We.getPrimitive(),p=We.getPrimitive();let f=$h,u=Hh,g=null,y=null;i&&(g=Jh,y=Qh);let w=1/0,x=null,v=null;return oi.copy(t).invert(),mn.matrix.copy(oi),o.shapecast({boundsTraverseOrder:b=>cs.distanceToBox(b),intersectsBounds:(b,D,T)=>T<w&&T<r?(D&&(mn.min.copy(b.min),mn.max.copy(b.max),mn.needsUpdate=!0),!0):!1,intersectsRange:(b,D)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:k=>mn.distanceToBox(k),intersectsBounds:(k,P,I)=>I<w&&I<r,intersectsRange:(k,P)=>{for(let I=k,z=k+P;I<z;I++){be(p,3*I,d,c),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let C=b,E=b+D;C<E;C++){be(m,3*C,h,l),m.needsUpdate=!0;const M=m.distanceToTriangle(p,f,g);if(M<w&&(u.copy(f),y&&y.copy(g),w=M,x=C,v=I),M<s)return!0}}}});{const T=Dt(e);for(let k=0,P=T;k<P;k++){be(p,3*k,d,c),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let I=b,z=b+D;I<z;I++){be(m,3*I,h,l),m.needsUpdate=!0;const C=m.distanceToTriangle(p,f,g);if(C<w&&(u.copy(f),y&&y.copy(g),w=C,x=I,v=k),C<s)return!0}}}}}),We.releasePrimitive(m),We.releasePrimitive(p),w===1/0?null:(n.point?n.point.copy(u):n.point=u.clone(),n.distance=w,n.faceIndex=x,i&&(i.point?i.point.copy(y):i.point=y.clone(),i.point.applyMatrix4(oi),u.applyMatrix4(oi),i.distance=u.sub(i.point).length(),i.faceIndex=v),n)}function tu(o,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=o.geometry,n=t.index?t.index.array:null,i=t.attributes.position;let s,r,a,l,h=0;const c=o._roots;for(let m=0,p=c.length;m<p;m++)s=c[m],r=new Uint32Array(s),a=new Uint16Array(s),l=new Float32Array(s),d(0,h),h+=s.byteLength;function d(m,p,f=!1){const u=m*2;if(Se(u,a)){const g=r[m+6],y=a[u+14];let w=1/0,x=1/0,v=1/0,b=-1/0,D=-1/0,T=-1/0;for(let k=g,P=g+y;k<P;k++){const I=3*o.resolveTriangleIndex(k);for(let z=0;z<3;z++){let C=I+z;C=n?n[C]:C;const E=i.getX(C),M=i.getY(C),B=i.getZ(C);E<w&&(w=E),E>b&&(b=E),M<x&&(x=M),M>D&&(D=M),B<v&&(v=B),B>T&&(T=B)}}return l[m+0]!==w||l[m+1]!==x||l[m+2]!==v||l[m+3]!==b||l[m+4]!==D||l[m+5]!==T?(l[m+0]=w,l[m+1]=x,l[m+2]=v,l[m+3]=b,l[m+4]=D,l[m+5]=T,!0):!1}else{const g=Te(m),y=Pe(m,r);let w=f,x=!1,v=!1;if(e){if(!w){const I=g/Me+p/Ie,z=y/Me+p/Ie;x=e.has(I),v=e.has(z),w=!x&&!v}}else x=!0,v=!0;const b=w||x,D=w||v;let T=!1;b&&(T=d(g,p,w));let k=!1;D&&(k=d(y,p,w));const P=T||k;if(P)for(let I=0;I<3;I++){const z=g+I,C=y+I,E=l[z],M=l[z+3],B=l[C],V=l[C+3];l[m+I]=E<B?E:B,l[m+I+3]=M>V?M:V}return P}}}function nu(o,e,t,n,i,s,r){me.setBuffer(o._roots[e]),hs(0,o,t,n,i,s,r),me.clearBuffer()}function hs(o,e,t,n,i,s,r){const{float32Array:a,uint16Array:l,uint32Array:h}=me,c=o*2;if(Se(c,l)){const m=Ue(o,h),p=Xe(c,l);Gh(e,t,n,m,p,i,s,r)}else{const m=Te(o);mt(m,a,n,s,r)&&hs(m,e,t,n,i,s,r);const p=Pe(o,h);mt(p,a,n,s,r)&&hs(p,e,t,n,i,s,r)}}const iu=["x","y","z"];function su(o,e,t,n,i,s){me.setBuffer(o._roots[e]);const r=us(0,o,t,n,i,s);return me.clearBuffer(),r}function us(o,e,t,n,i,s){const{float32Array:r,uint16Array:a,uint32Array:l}=me;let h=o*2;if(Se(h,a)){const d=Ue(o,l),m=Xe(h,a);return Wh(e,t,n,d,m,i,s)}else{const d=is(o,l),m=iu[d],f=n.direction[m]>=0;let u,g;f?(u=Te(o),g=Pe(o,l)):(u=Pe(o,l),g=Te(o));const w=mt(u,r,n,i,s)?us(u,e,t,n,i,s):null;if(w){const b=w.point[m];if(f?b<=r[g+d]:b>=r[g+d+3])return w}const v=mt(g,r,n,i,s)?us(g,e,t,n,i,s):null;return w&&v?w.distance<=v.distance?w:v:w||v||null}}const ai=new _.Box3,Ht=new Ge,Jt=new Ge,gn=new _.Matrix4,lo=new Le,li=new Le;function ru(o,e,t,n){me.setBuffer(o._roots[e]);const i=ds(0,o,t,n);return me.clearBuffer(),i}function ds(o,e,t,n,i=null){const{float32Array:s,uint16Array:r,uint32Array:a}=me;let l=o*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),lo.set(t.boundingBox.min,t.boundingBox.max,n),i=lo),Se(l,r)){const c=e.geometry,d=c.index,m=c.attributes.position,p=t.index,f=t.attributes.position,u=Ue(o,a),g=Xe(l,r);if(gn.copy(n).invert(),t.boundsTree)return we(o,s,li),li.matrix.copy(gn),li.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:w=>li.intersectsBox(w),intersectsTriangle:w=>{w.a.applyMatrix4(n),w.b.applyMatrix4(n),w.c.applyMatrix4(n),w.needsUpdate=!0;for(let x=u,v=g+u;x<v;x++)if(be(Jt,3*e.resolveTriangleIndex(x),d,m),Jt.needsUpdate=!0,w.intersectsTriangle(Jt))return!0;return!1}});{const y=Dt(t);for(let w=u,x=g+u;w<x;w++){const v=e.resolveTriangleIndex(w);be(Ht,3*v,d,m),Ht.a.applyMatrix4(gn),Ht.b.applyMatrix4(gn),Ht.c.applyMatrix4(gn),Ht.needsUpdate=!0;for(let b=0,D=y*3;b<D;b+=3)if(be(Jt,b,p,f),Jt.needsUpdate=!0,Ht.intersectsTriangle(Jt))return!0}}}else{const c=Te(o),d=Pe(o,a);return we(c,s,ai),!!(i.intersectsBox(ai)&&ds(c,e,t,n,i)||(we(d,s,ai),i.intersectsBox(ai)&&ds(d,e,t,n,i)))}}const ci=new _.Matrix4,fs=new Le,yn=new Le,ou=new _.Vector3,au=new _.Vector3,lu=new _.Vector3,cu=new _.Vector3;function hu(o,e,t,n={},i={},s=0,r=1/0){e.boundingBox||e.computeBoundingBox(),fs.set(e.boundingBox.min,e.boundingBox.max,t),fs.needsUpdate=!0;const a=o.geometry,l=a.attributes.position,h=a.index,c=e.attributes.position,d=e.index,m=We.getPrimitive(),p=We.getPrimitive();let f=ou,u=au,g=null,y=null;i&&(g=lu,y=cu);let w=1/0,x=null,v=null;return ci.copy(t).invert(),yn.matrix.copy(ci),o.shapecast({boundsTraverseOrder:b=>fs.distanceToBox(b),intersectsBounds:(b,D,T)=>T<w&&T<r?(D&&(yn.min.copy(b.min),yn.max.copy(b.max),yn.needsUpdate=!0),!0):!1,intersectsRange:(b,D)=>{if(e.boundsTree){const T=e.boundsTree;return T.shapecast({boundsTraverseOrder:k=>yn.distanceToBox(k),intersectsBounds:(k,P,I)=>I<w&&I<r,intersectsRange:(k,P)=>{for(let I=k,z=k+P;I<z;I++){const C=T.resolveTriangleIndex(I);be(p,3*C,d,c),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let E=b,M=b+D;E<M;E++){const B=o.resolveTriangleIndex(E);be(m,3*B,h,l),m.needsUpdate=!0;const V=m.distanceToTriangle(p,f,g);if(V<w&&(u.copy(f),y&&y.copy(g),w=V,x=E,v=I),V<s)return!0}}}})}else{const T=Dt(e);for(let k=0,P=T;k<P;k++){be(p,3*k,d,c),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let I=b,z=b+D;I<z;I++){const C=o.resolveTriangleIndex(I);be(m,3*C,h,l),m.needsUpdate=!0;const E=m.distanceToTriangle(p,f,g);if(E<w&&(u.copy(f),y&&y.copy(g),w=E,x=I,v=k),E<s)return!0}}}}}),We.releasePrimitive(m),We.releasePrimitive(p),w===1/0?null:(n.point?n.point.copy(u):n.point=u.clone(),n.distance=w,n.faceIndex=x,i&&(i.point?i.point.copy(y):i.point=y.clone(),i.point.applyMatrix4(ci),u.applyMatrix4(ci),i.distance=u.sub(i.point).length(),i.faceIndex=v),n)}function uu(){return typeof SharedArrayBuffer<"u"}const wn=new me.constructor,hi=new me.constructor,gt=new ns(()=>new _.Box3),Qt=new _.Box3,en=new _.Box3,ps=new _.Box3,ms=new _.Box3;let gs=!1;function du(o,e,t,n){if(gs)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");gs=!0;const i=o._roots,s=e._roots;let r,a=0,l=0;const h=new _.Matrix4().copy(t).invert();for(let c=0,d=i.length;c<d;c++){wn.setBuffer(i[c]),l=0;const m=gt.getPrimitive();we(0,wn.float32Array,m),m.applyMatrix4(h);for(let p=0,f=s.length;p<f&&(hi.setBuffer(s[p]),r=Ke(0,0,t,h,n,a,l,0,0,m),hi.clearBuffer(),l+=s[p].byteLength/Ie,!r);p++);if(gt.releasePrimitive(m),wn.clearBuffer(),a+=i[c].byteLength/Ie,r)break}return gs=!1,r}function Ke(o,e,t,n,i,s=0,r=0,a=0,l=0,h=null,c=!1){let d,m;c?(d=hi,m=wn):(d=wn,m=hi);const p=d.float32Array,f=d.uint32Array,u=d.uint16Array,g=m.float32Array,y=m.uint32Array,w=m.uint16Array,x=o*2,v=e*2,b=Se(x,u),D=Se(v,w);let T=!1;if(D&&b)c?T=i(Ue(e,y),Xe(e*2,w),Ue(o,f),Xe(o*2,u),l,r+e/Me,a,s+o/Me):T=i(Ue(o,f),Xe(o*2,u),Ue(e,y),Xe(e*2,w),a,s+o/Me,l,r+e/Me);else if(D){const k=gt.getPrimitive();we(e,g,k),k.applyMatrix4(t);const P=Te(o),I=Pe(o,f);we(P,p,Qt),we(I,p,en);const z=k.intersectsBox(Qt),C=k.intersectsBox(en);T=z&&Ke(e,P,n,t,i,r,s,l,a+1,k,!c)||C&&Ke(e,I,n,t,i,r,s,l,a+1,k,!c),gt.releasePrimitive(k)}else{const k=Te(e),P=Pe(e,y);we(k,g,ps),we(P,g,ms);const I=h.intersectsBox(ps),z=h.intersectsBox(ms);if(I&&z)T=Ke(o,k,t,n,i,s,r,a,l+1,h,c)||Ke(o,P,t,n,i,s,r,a,l+1,h,c);else if(I)if(b)T=Ke(o,k,t,n,i,s,r,a,l+1,h,c);else{const C=gt.getPrimitive();C.copy(ps).applyMatrix4(t);const E=Te(o),M=Pe(o,f);we(E,p,Qt),we(M,p,en);const B=C.intersectsBox(Qt),V=C.intersectsBox(en);T=B&&Ke(k,E,n,t,i,r,s,l,a+1,C,!c)||V&&Ke(k,M,n,t,i,r,s,l,a+1,C,!c),gt.releasePrimitive(C)}else if(z)if(b)T=Ke(o,P,t,n,i,s,r,a,l+1,h,c);else{const C=gt.getPrimitive();C.copy(ms).applyMatrix4(t);const E=Te(o),M=Pe(o,f);we(E,p,Qt),we(M,p,en);const B=C.intersectsBox(Qt),V=C.intersectsBox(en);T=B&&Ke(P,E,n,t,i,r,s,l,a+1,C,!c)||V&&Ke(P,M,n,t,i,r,s,l,a+1,C,!c),gt.releasePrimitive(C)}}return T}const ui=new Le,co=new _.Box3,fu={strategy:Gr,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class ys{static serialize(e,t={}){t={cloneBuffers:!0,...t};const n=e.geometry,i=e._roots,s=e._indirectBuffer,r=n.getIndex(),a={version:1,roots:null,index:null,indirectBuffer:null};return t.cloneBuffers?(a.roots=i.map(l=>l.slice()),a.index=r?r.array.slice():null,a.indirectBuffer=s?s.slice():null):(a.roots=i,a.index=r?r.array:null,a.indirectBuffer=s),a}static deserialize(e,t,n={}){n={setIndex:!0,indirect:!!e.indirectBuffer,...n};const{index:i,roots:s,indirectBuffer:r}=e;e.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),l(s));const a=new ys(t,{...n,[Yi]:!0});if(a._roots=s,a._indirectBuffer=r||null,n.setIndex){const h=t.getIndex();if(h===null){const c=new _.BufferAttribute(e.index,1,!1);t.setIndex(c)}else h.array!==i&&(h.array.set(i),h.needsUpdate=!0)}return a;function l(h){for(let c=0;c<h.length;c++){const d=h[c],m=new Uint32Array(d),p=new Uint16Array(d);for(let f=0,u=d.byteLength/Ie;f<u;f++){const g=Me*f,y=2*g;Se(y,p)||(m[g+6]=m[g+6]/Me-f)}}}}get indirect(){return!!this._indirectBuffer}constructor(e,t={}){if(e.isBufferGeometry){if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t=Object.assign({...fu,[Yi]:!1},t),t.useSharedArrayBuffer&&!uu())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[Yi]||(Dh(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new _.Box3))),this.resolveTriangleIndex=t.indirect?n=>this._indirectBuffer[n]:n=>n}shiftTriangleOffsets(e){const t=this._indirectBuffer;if(t)for(let n=0,i=t.length;n<i;n++)t[n]+=e;else{const n=this._roots;for(let i=0;i<n.length;i++){const s=n[i],r=new Uint32Array(s),a=new Uint16Array(s),l=s.byteLength/Ie;for(let h=0;h<l;h++){const c=Me*h,d=2*c;Se(d,a)&&(r[c+6]+=e)}}}}refit(e=null){return(this.indirect?tu:jh)(this,e)}traverse(e,t=0){const n=this._roots[t],i=new Uint32Array(n),s=new Uint16Array(n);r(0);function r(a,l=0){const h=a*2,c=Se(h,s);if(c){const d=i[a+6],m=s[h+14];e(l,c,new Float32Array(n,a*4,6),d,m)}else{const d=Te(a),m=Pe(a,i),p=is(a,i);e(l,c,new Float32Array(n,a*4,6),p)||(r(d,l+1),r(m,l+1))}}}raycast(e,t=_.FrontSide,n=0,i=1/0){const s=this._roots,r=[],a=this.indirect?nu:Zh;for(let l=0,h=s.length;l<h;l++)a(this,l,t,e,r,n,i);return r}raycastFirst(e,t=_.FrontSide,n=0,i=1/0){const s=this._roots;let r=null;const a=this.indirect?su:Kh;for(let l=0,h=s.length;l<h;l++){const c=a(this,l,t,e,n,i);c!=null&&(r==null||c.distance<r.distance)&&(r=c)}return r}intersectsGeometry(e,t){let n=!1;const i=this._roots,s=this.indirect?ru:Yh;for(let r=0,a=i.length;r<a&&(n=s(this,r,e,t),!n);r++);return n}shapecast(e){const t=We.getPrimitive(),n=this.indirect?Xh:Vh;let{boundsTraverseOrder:i,intersectsBounds:s,intersectsRange:r,intersectsTriangle:a}=e;if(r&&a){const d=r;r=(m,p,f,u,g)=>d(m,p,f,u,g)?!0:n(m,p,this,a,f,u,t)}else r||(a?r=(d,m,p,f)=>n(d,m,this,a,p,f,t):r=(d,m,p)=>p);let l=!1,h=0;const c=this._roots;for(let d=0,m=c.length;d<m;d++){const p=c[d];if(l=Oh(this,d,s,r,i,h),l)break;h+=p.byteLength/Ie}return We.releasePrimitive(t),l}bvhcast(e,t,n){let{intersectsRanges:i,intersectsTriangles:s}=n;const r=We.getPrimitive(),a=this.geometry.index,l=this.geometry.attributes.position,h=this.indirect?f=>{const u=this.resolveTriangleIndex(f);be(r,u*3,a,l)}:f=>{be(r,f*3,a,l)},c=We.getPrimitive(),d=e.geometry.index,m=e.geometry.attributes.position,p=e.indirect?f=>{const u=e.resolveTriangleIndex(f);be(c,u*3,d,m)}:f=>{be(c,f*3,d,m)};if(s){const f=(u,g,y,w,x,v,b,D)=>{for(let T=y,k=y+w;T<k;T++){p(T),c.a.applyMatrix4(t),c.b.applyMatrix4(t),c.c.applyMatrix4(t),c.needsUpdate=!0;for(let P=u,I=u+g;P<I;P++)if(h(P),r.needsUpdate=!0,s(r,c,P,T,x,v,b,D))return!0}return!1};if(i){const u=i;i=function(g,y,w,x,v,b,D,T){return u(g,y,w,x,v,b,D,T)?!0:f(g,y,w,x,v,b,D,T)}}else i=f}return du(this,e,t,i)}intersectsBox(e,t){return ui.set(e.min,e.max,t),ui.needsUpdate=!0,this.shapecast({intersectsBounds:n=>ui.intersectsBox(n),intersectsTriangle:n=>ui.intersectsTriangle(n)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,n={},i={},s=0,r=1/0){return(this.indirect?hu:eu)(this,e,t,n,i,s,r)}closestPointToPoint(e,t={},n=0,i=1/0){return zh(this,e,t,n,i)}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(n=>{we(0,new Float32Array(n),co),e.union(co)}),e}}const ho=1e-6,pu=ho*.5,uo=Math.pow(10,-Math.log10(ho)),mu=pu*uo;function tt(o){return~~(o*uo+mu)}function gu(o){return`${tt(o.x)},${tt(o.y)}`}function fo(o){return`${tt(o.x)},${tt(o.y)},${tt(o.z)}`}function yu(o){return`${tt(o.x)},${tt(o.y)},${tt(o.z)},${tt(o.w)}`}function wu(o,e,t){t.direction.subVectors(e,o).normalize();const n=o.dot(t.direction);return t.origin.copy(o).addScaledVector(t.direction,-n),t}function po(){return typeof SharedArrayBuffer<"u"}function xu(o){if(o.buffer instanceof SharedArrayBuffer)return o;const e=o.constructor,t=o.buffer,n=new SharedArrayBuffer(t.byteLength),i=new Uint8Array(t);return new Uint8Array(n).set(i,0),new e(n)}function vu(o,e=ArrayBuffer){return o>65535?new Uint32Array(new e(4*o)):new Uint16Array(new e(2*o))}function bu(o,e){if(!o.index){const t=o.attributes.position.count,n=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=vu(t,n);o.setIndex(new _.BufferAttribute(i,1));for(let s=0;s<t;s++)i[s]=s}}function _u(o){return o.index?o.index.count:o.attributes.position.count}function ws(o){return _u(o)/3}const Mu=1e-8,Su=new _.Vector3;function Au(o){return~~(o/3)}function Cu(o){return o%3}function mo(o,e){return o.start-e.start}function go(o,e){return Su.subVectors(e,o.origin).dot(o.direction)}function Tu(o,e,t,n=Mu){o.sort(mo),e.sort(mo);for(let a=0;a<o.length;a++){const l=o[a];for(let h=0;h<e.length;h++){const c=e[h];if(!(c.start>l.end)){if(l.end<c.start||c.end<l.start)continue;if(l.start<=c.start&&l.end>=c.end)s(c.end,l.end)||o.splice(a+1,0,{start:c.end,end:l.end,index:l.index}),l.end=c.start,c.start=0,c.end=0;else if(l.start>=c.start&&l.end<=c.end)s(l.end,c.end)||e.splice(h+1,0,{start:l.end,end:c.end,index:c.index}),c.end=l.start,l.start=0,l.end=0;else if(l.start<=c.start&&l.end<=c.end){const d=l.end;l.end=c.start,c.start=d}else if(l.start>=c.start&&l.end>=c.end){const d=c.end;c.end=l.start,l.start=d}else throw new Error}if(t.has(l.index)||t.set(l.index,[]),t.has(c.index)||t.set(c.index,[]),t.get(l.index).push(c.index),t.get(c.index).push(l.index),r(c)&&(e.splice(h,1),h--),r(l)){o.splice(a,1),a--;break}}}i(o),i(e);function i(a){for(let l=0;l<a.length;l++)r(a[l])&&(a.splice(l,1),l--)}function s(a,l){return Math.abs(l-a)<n}function r(a){return Math.abs(a.end-a.start)<n}}const yo=1e-5,wo=1e-4;class Pu{constructor(){this._rays=[]}addRay(e){this._rays.push(e)}findClosestRay(e){const t=this._rays,n=e.clone();n.direction.multiplyScalar(-1);let i=1/0,s=null;for(let l=0,h=t.length;l<h;l++){const c=t[l];if(r(c,e)&&r(c,n))continue;const d=a(c,e),m=a(c,n),p=Math.min(d,m);p<i&&(i=p,s=c)}return s;function r(l,h){const c=l.origin.distanceTo(h.origin)>yo;return l.direction.angleTo(h.direction)>wo||c}function a(l,h){const c=l.origin.distanceTo(h.origin),d=l.direction.angleTo(h.direction);return c/yo+d/wo}}}const xs=new _.Vector3,vs=new _.Vector3,di=new _.Ray;function Du(o,e,t){const n=o.attributes,i=o.index,s=n.position,r=new Map,a=new Map,l=Array.from(e),h=new Pu;for(let c=0,d=l.length;c<d;c++){const m=l[c],p=Au(m),f=Cu(m);let u=3*p+f,g=3*p+(f+1)%3;i&&(u=i.getX(u),g=i.getX(g)),xs.fromBufferAttribute(s,u),vs.fromBufferAttribute(s,g),wu(xs,vs,di);let y,w=h.findClosestRay(di);w===null&&(w=di.clone(),h.addRay(w)),a.has(w)||a.set(w,{forward:[],reverse:[],ray:w}),y=a.get(w);let x=go(w,xs),v=go(w,vs);x>v&&([x,v]=[v,x]),di.direction.dot(w.direction)<0?y.reverse.push({start:x,end:v,index:m}):y.forward.push({start:x,end:v,index:m})}return a.forEach(({forward:c,reverse:d},m)=>{Tu(c,d,r,t),c.length===0&&d.length===0&&a.delete(m)}),{disjointConnectivityMap:r,fragmentMap:a}}const ku=new _.Vector2,bs=new _.Vector3,Iu=new _.Vector4,_s=["","",""];class Lu{constructor(e=null){this.data=null,this.disjointConnections=null,this.unmatchedDisjointEdges=null,this.unmatchedEdges=-1,this.matchedEdges=-1,this.useDrawRange=!0,this.useAllAttributes=!1,this.matchDisjointEdges=!1,this.degenerateEpsilon=1e-8,e&&this.updateFrom(e)}getSiblingTriangleIndex(e,t){const n=this.data[e*3+t];return n===-1?-1:~~(n/3)}getSiblingEdgeIndex(e,t){const n=this.data[e*3+t];return n===-1?-1:n%3}getDisjointSiblingTriangleIndices(e,t){const n=e*3+t,i=this.disjointConnections.get(n);return i?i.map(s=>~~(s/3)):[]}getDisjointSiblingEdgeIndices(e,t){const n=e*3+t,i=this.disjointConnections.get(n);return i?i.map(s=>s%3):[]}isFullyConnected(){return this.unmatchedEdges===0}updateFrom(e){const{useAllAttributes:t,useDrawRange:n,matchDisjointEdges:i,degenerateEpsilon:s}=this,r=t?x:w,a=new Map,{attributes:l}=e,h=t?Object.keys(l):null,c=e.index,d=l.position;let m=ws(e);const p=m;let f=0;n&&(f=e.drawRange.start,e.drawRange.count!==1/0&&(m=~~(e.drawRange.count/3)));let u=this.data;(!u||u.length<3*p)&&(u=new Int32Array(3*p)),u.fill(-1);let g=0,y=new Set;for(let v=f,b=m*3+f;v<b;v+=3){const D=v;for(let T=0;T<3;T++){let k=D+T;c&&(k=c.getX(k)),_s[T]=r(k)}for(let T=0;T<3;T++){const k=(T+1)%3,P=_s[T],I=_s[k],z=`${I}_${P}`;if(a.has(z)){const C=D+T,E=a.get(z);u[C]=E,u[E]=C,a.delete(z),g+=2,y.delete(E)}else{const C=`${P}_${I}`,E=D+T;a.set(C,E),y.add(E)}}}if(i){const{fragmentMap:v,disjointConnectivityMap:b}=Du(e,y,s);y.clear(),v.forEach(({forward:D,reverse:T})=>{D.forEach(({index:k})=>y.add(k)),T.forEach(({index:k})=>y.add(k))}),this.unmatchedDisjointEdges=v,this.disjointConnections=b,g=m*3-y.size}this.matchedEdges=g,this.unmatchedEdges=y.size,this.data=u;function w(v){return bs.fromBufferAttribute(d,v),fo(bs)}function x(v){let b="";for(let D=0,T=h.length;D<T;D++){const k=l[h[D]];let P;switch(k.itemSize){case 1:P=tt(k.getX(v));break;case 2:P=gu(ku.fromBufferAttribute(k,v));break;case 3:P=fo(bs.fromBufferAttribute(k,v));break;case 4:P=yu(Iu.fromBufferAttribute(k,v));break}b!==""&&(b+="|"),b+=P}return b}}}class fi extends _.Mesh{constructor(...e){super(...e),this.isBrush=!0,this._previousMatrix=new _.Matrix4,this._previousMatrix.elements.fill(0)}markUpdated(){this._previousMatrix.copy(this.matrix)}isDirty(){const{matrix:e,_previousMatrix:t}=this,n=e.elements,i=t.elements;for(let s=0;s<16;s++)if(n[s]!==i[s])return!0;return!1}prepareGeometry(){const e=this.geometry,t=e.attributes,n=po();if(n)for(const i in t){const s=t[i];if(s.isInterleavedBufferAttribute)throw new Error("Brush: InterleavedBufferAttributes are not supported.");s.array=xu(s.array)}if(e.boundsTree||(bu(e,{useSharedArrayBuffer:n}),e.boundsTree=new ys(e,{maxLeafTris:3,indirect:!0,useSharedArrayBuffer:n})),e.halfEdges||(e.halfEdges=new Lu(e)),!e.groupIndices){const i=ws(e),s=new Uint16Array(i),r=e.groups;for(let a=0,l=r.length;a<l;a++){const{start:h,count:c}=r[a];for(let d=h/3,m=(h+c)/3;d<m;d++)s[d]=a}e.groupIndices=s}}disposeCacheData(){const{geometry:e}=this;e.halfEdges=null,e.boundsTree=null,e.groupIndices=null}}const Eu=1e-14,Ms=new _.Vector3,xo=new _.Vector3,vo=new _.Vector3;function yt(o,e=Eu){Ms.subVectors(o.b,o.a),xo.subVectors(o.c,o.a),vo.subVectors(o.b,o.c);const t=Ms.angleTo(xo),n=Ms.angleTo(vo),i=Math.PI-t-n;return Math.abs(t)<e||Math.abs(n)<e||Math.abs(i)<e||o.a.distanceToSquared(o.b)<e||o.a.distanceToSquared(o.c)<e||o.b.distanceToSquared(o.c)<e}const Ss=1e-10,xn=1e-10,Bu=1e-10,lt=new _.Line3,xe=new _.Line3,ct=new _.Vector3,As=new _.Vector3,bo=new _.Vector3,pi=new _.Plane,Cs=new Ge;class Ou{constructor(){this._pool=[],this._index=0}getTriangle(){return this._index>=this._pool.length&&this._pool.push(new _.Triangle),this._pool[this._index++]}clear(){this._index=0}reset(){this._pool.length=0,this._index=0}}class zu{constructor(){this.trianglePool=new Ou,this.triangles=[],this.normal=new _.Vector3,this.coplanarTriangleUsed=!1}initialize(e){this.reset();const{triangles:t,trianglePool:n,normal:i}=this;if(Array.isArray(e))for(let s=0,r=e.length;s<r;s++){const a=e[s];if(s===0)a.getNormal(i);else if(Math.abs(1-a.getNormal(ct).dot(i))>Ss)throw new Error("Triangle Splitter: Cannot initialize with triangles that have different normals.");const l=n.getTriangle();l.copy(a),t.push(l)}else{e.getNormal(i);const s=n.getTriangle();s.copy(e),t.push(s)}}splitByTriangle(e){const{normal:t,triangles:n}=this;if(e.getNormal(As).normalize(),Math.abs(1-Math.abs(As.dot(t)))<Bu){this.coplanarTriangleUsed=!0;for(let s=0,r=n.length;s<r;s++){const a=n[s];a.coplanarCount=0}const i=[e.a,e.b,e.c];for(let s=0;s<3;s++){const r=(s+1)%3,a=i[s],l=i[r];ct.subVectors(l,a).normalize(),bo.crossVectors(As,ct),pi.setFromNormalAndCoplanarPoint(bo,a),this.splitByPlane(pi,e)}}else e.getPlane(pi),this.splitByPlane(pi,e)}splitByPlane(e,t){const{triangles:n,trianglePool:i}=this;Cs.copy(t),Cs.needsUpdate=!0;for(let s=0,r=n.length;s<r;s++){const a=n[s];if(!Cs.intersectsTriangle(a,lt,!0))continue;const{a:l,b:h,c}=a;let d=0,m=-1,p=!1,f=[],u=[];const g=[l,h,c];for(let y=0;y<3;y++){const w=(y+1)%3;lt.start.copy(g[y]),lt.end.copy(g[w]);const x=e.distanceToPoint(lt.start),v=e.distanceToPoint(lt.end);if(Math.abs(x)<xn&&Math.abs(v)<xn){p=!0;break}if(x>0?f.push(y):u.push(y),Math.abs(x)<xn)continue;let b=!!e.intersectLine(lt,ct);!b&&Math.abs(v)<xn&&(ct.copy(lt.end),b=!0),b&&!(ct.distanceTo(lt.start)<Ss)&&(ct.distanceTo(lt.end)<Ss&&(m=y),d===0?xe.start.copy(ct):xe.end.copy(ct),d++)}if(!p&&d===2&&xe.distance()>xn)if(m!==-1){m=(m+1)%3;let y=0;y===m&&(y=(y+1)%3);let w=y+1;w===m&&(w=(w+1)%3);const x=i.getTriangle();x.a.copy(g[w]),x.b.copy(xe.end),x.c.copy(xe.start),yt(x)||n.push(x),a.a.copy(g[y]),a.b.copy(xe.start),a.c.copy(xe.end),yt(a)&&(n.splice(s,1),s--,r--)}else{const y=f.length>=2?u[0]:f[0];if(y===0){let D=xe.start;xe.start=xe.end,xe.end=D}const w=(y+1)%3,x=(y+2)%3,v=i.getTriangle(),b=i.getTriangle();g[w].distanceToSquared(xe.start)<g[x].distanceToSquared(xe.end)?(v.a.copy(g[w]),v.b.copy(xe.start),v.c.copy(xe.end),b.a.copy(g[w]),b.b.copy(g[x]),b.c.copy(xe.start)):(v.a.copy(g[x]),v.b.copy(xe.start),v.c.copy(xe.end),b.a.copy(g[w]),b.b.copy(g[x]),b.c.copy(xe.end)),a.a.copy(g[y]),a.b.copy(xe.end),a.c.copy(xe.start),yt(v)||n.push(v),yt(b)||n.push(b),yt(a)&&(n.splice(s,1),s--,r--)}else d===3&&console.warn("TriangleClipper: Coplanar clip not handled")}}reset(){this.triangles.length=0,this.trianglePool.clear(),this.coplanarTriangleUsed=!1}}function Nu(o){return o=~~o,o+4-o%4}class _o{constructor(e,t=500){this.expansionFactor=1.5,this.type=e,this.length=0,this.array=null,this.setSize(t)}setType(e){if(this.length!==0)throw new Error("TypeBackedArray: Cannot change the type while there is used data in the buffer.");const t=this.array.buffer;this.array=new e(t),this.type=e}setSize(e){if(this.array&&e===this.array.length)return;const t=this.type,n=po()?SharedArrayBuffer:ArrayBuffer,i=new t(new n(Nu(e*t.BYTES_PER_ELEMENT)));this.array&&i.set(this.array,0),this.array=i}expand(){const{array:e,expansionFactor:t}=this;this.setSize(e.length*t)}push(...e){let{array:t,length:n}=this;n+e.length>t.length&&(this.expand(),t=this.array);for(let i=0,s=e.length;i<s;i++)t[n+i]=e[i];this.length+=e.length}clear(){this.length=0}}class Ru{constructor(){this.groupAttributes=[{}],this.groupCount=0}getType(e){return this.groupAttributes[0][e].type}getItemSize(e){return this.groupAttributes[0][e].itemSize}getNormalized(e){return this.groupAttributes[0][e].normalized}getCount(e){if(this.groupCount<=e)return 0;const t=this.getGroupAttrArray("position",e);return t.length/t.itemSize}getTotalLength(e){const{groupCount:t,groupAttributes:n}=this;let i=0;for(let s=0;s<t;s++){const r=n[s];i+=r[e].length}return i}getGroupAttrSet(e=0){const{groupAttributes:t}=this;if(t[e])return this.groupCount=Math.max(this.groupCount,e+1),t[e];const n=t[0];for(this.groupCount=Math.max(this.groupCount,e+1);e>=t.length;){const i={};t.push(i);for(const s in n){const r=n[s],a=new _o(r.type);a.itemSize=r.itemSize,a.normalized=r.normalized,i[s]=a}}return t[e]}getGroupAttrArray(e,t=0){const{groupAttributes:n}=this;if(!n[0][e])throw new Error(`TypedAttributeData: Attribute with "${e}" has not been initialized`);return this.getGroupAttrSet(t)[e]}initializeArray(e,t,n,i){const{groupAttributes:s}=this,a=s[0][e];if(a){if(a.type!==t)for(let l=0,h=s.length;l<h;l++){const c=s[l][e];c.setType(t),c.itemSize=n,c.normalized=i}}else for(let l=0,h=s.length;l<h;l++){const c=new _o(t);c.itemSize=n,c.normalized=i,s[l][e]=c}}clear(){this.groupCount=0;const{groupAttributes:e}=this;e.forEach(t=>{for(const n in t)t[n].clear()})}delete(e){this.groupAttributes.forEach(t=>{delete t[e]})}reset(){this.groupAttributes=[],this.groupCount=0}}class Mo{constructor(){this.intersectionSet={},this.ids=[]}add(e,t){const{intersectionSet:n,ids:i}=this;n[e]||(n[e]=[],i.push(e)),n[e].push(t)}}const Fu=0,Uu=1,Vu=2,So=3,ju=4,Ao=5,Co=6,Ze=new _.Ray,To=new _.Matrix4,Ee=new _.Triangle,ht=new _.Vector3,Po=new _.Vector4,Do=new _.Vector4,ko=new _.Vector4,Ts=new _.Vector4,mi=new _.Vector4,gi=new _.Vector4,Io=new _.Line3,Ps=new _.Vector3,Ds=1e-8,Gu=1e-15,Et=-1,Bt=1,yi=-2,wi=2,vn=0,Ot=1,ks=2,Wu=1e-14;let xi=null;function Lo(o){xi=o}function Eo(o,e){o.getMidpoint(Ze.origin),o.getNormal(Ze.direction);const t=e.raycastFirst(Ze,_.DoubleSide);return!!(t&&Ze.direction.dot(t.face.normal)>0)?Et:Bt}function Xu(o,e){function t(){return Math.random()-.5}o.getNormal(Ps),Ze.direction.copy(Ps),o.getMidpoint(Ze.origin);const n=3;let i=0,s=1/0;for(let r=0;r<n;r++){Ze.direction.x+=t()*Ds,Ze.direction.y+=t()*Ds,Ze.direction.z+=t()*Ds,Ze.direction.multiplyScalar(-1);const a=e.raycastFirst(Ze,_.DoubleSide);if(!!(a&&Ze.direction.dot(a.face.normal)>0)&&i++,a!==null&&(s=Math.min(s,a.distance)),s<=Gu)return a.face.normal.dot(Ps)>0?wi:yi;if(i/n>.5||(r-i+1)/n>.5)break}return i/n>.5?Et:Bt}function Zu(o,e){const t=new Mo,n=new Mo;return To.copy(o.matrixWorld).invert().multiply(e.matrixWorld),o.geometry.boundsTree.bvhcast(e.geometry.boundsTree,To,{intersectsTriangles(i,s,r,a){if(!yt(i)&&!yt(s)){let l=i.intersectsTriangle(s,Io,!0);if(!l){const h=i.plane,c=s.plane,d=h.normal,m=c.normal;d.dot(m)===1&&Math.abs(h.constant-c.constant)<Wu&&(l=!0)}if(l){let h=o.geometry.boundsTree.resolveTriangleIndex(r),c=e.geometry.boundsTree.resolveTriangleIndex(a);t.add(h,c),n.add(c,h),xi&&(xi.addEdge(Io),xi.addIntersectingTriangles(r,i,a,s))}}return!1}}),{aIntersections:t,bIntersections:n}}function qu(o,e,t,n,i,s,r=!1){const a=t.attributes,l=t.index,h=o*3,c=l.getX(h+0),d=l.getX(h+1),m=l.getX(h+2);for(const p in s){const f=a[p],u=s[p];if(!(p in a))throw new Error(`CSG Operations: Attribute ${p} not available on geometry.`);const g=f.itemSize;p==="position"?(Ee.a.fromBufferAttribute(f,c).applyMatrix4(n),Ee.b.fromBufferAttribute(f,d).applyMatrix4(n),Ee.c.fromBufferAttribute(f,m).applyMatrix4(n),Is(Ee.a,Ee.b,Ee.c,e,3,u,r)):p==="normal"?(Ee.a.fromBufferAttribute(f,c).applyNormalMatrix(i),Ee.b.fromBufferAttribute(f,d).applyNormalMatrix(i),Ee.c.fromBufferAttribute(f,m).applyNormalMatrix(i),r&&(Ee.a.multiplyScalar(-1),Ee.b.multiplyScalar(-1),Ee.c.multiplyScalar(-1)),Is(Ee.a,Ee.b,Ee.c,e,3,u,r,!0)):(Po.fromBufferAttribute(f,c),Do.fromBufferAttribute(f,d),ko.fromBufferAttribute(f,m),Is(Po,Do,ko,e,g,u,r))}}function Ku(o,e,t,n,i,s,r,a=!1){Ls(o,n,i,s,r,a),Ls(a?t:e,n,i,s,r,a),Ls(a?e:t,n,i,s,r,a)}function Bo(o,e,t=!1){switch(o){case Fu:if(e===Bt||e===wi&&!t)return Ot;break;case Uu:if(t){if(e===Et)return vn}else if(e===Bt||e===yi)return Ot;break;case Vu:if(t){if(e===Bt||e===yi)return Ot}else if(e===Et)return vn;break;case ju:if(e===Et)return vn;if(e===Bt)return Ot;break;case So:if(e===Et||e===wi&&!t)return Ot;break;case Ao:if(!t&&(e===Bt||e===yi))return Ot;break;case Co:if(!t&&(e===Et||e===wi))return Ot;break;default:throw new Error(`Unrecognized CSG operation enum "${o}".`)}return ks}function Is(o,e,t,n,i,s,r=!1,a=!1){const l=h=>{s.push(h.x),i>1&&s.push(h.y),i>2&&s.push(h.z),i>3&&s.push(h.w)};Ts.set(0,0,0,0).addScaledVector(o,n.a.x).addScaledVector(e,n.a.y).addScaledVector(t,n.a.z),mi.set(0,0,0,0).addScaledVector(o,n.b.x).addScaledVector(e,n.b.y).addScaledVector(t,n.b.z),gi.set(0,0,0,0).addScaledVector(o,n.c.x).addScaledVector(e,n.c.y).addScaledVector(t,n.c.z),a&&(Ts.normalize(),mi.normalize(),gi.normalize()),l(Ts),r?(l(gi),l(mi)):(l(mi),l(gi))}function Ls(o,e,t,n,i,s=!1){for(const r in i){const a=e[r],l=i[r];if(!(r in e))throw new Error(`CSG Operations: Attribute ${r} no available on geometry.`);const h=a.itemSize;r==="position"?(ht.fromBufferAttribute(a,o).applyMatrix4(t),l.push(ht.x,ht.y,ht.z)):r==="normal"?(ht.fromBufferAttribute(a,o).applyNormalMatrix(n),s&&ht.multiplyScalar(-1),l.push(ht.x,ht.y,ht.z)):(l.push(a.getX(o)),h>1&&l.push(a.getY(o)),h>2&&l.push(a.getZ(o)),h>3&&l.push(a.getW(o)))}}class Yu{constructor(e){this.triangle=new _.Triangle().copy(e),this.intersects={}}addTriangle(e,t){this.intersects[e]=new _.Triangle().copy(t)}getIntersectArray(){const e=[],{intersects:t}=this;for(const n in t)e.push(t[n]);return e}}class Oo{constructor(){this.data={}}addTriangleIntersection(e,t,n,i){const{data:s}=this;s[e]||(s[e]=new Yu(t)),s[e].addTriangle(n,i)}getTrianglesAsArray(e=null){const{data:t}=this,n=[];if(e!==null)e in t&&n.push(t[e].triangle);else for(const i in t)n.push(t[i].triangle);return n}getTriangleIndices(){return Object.keys(this.data).map(e=>parseInt(e))}getIntersectionIndices(e){const{data:t}=this;return t[e]?Object.keys(t[e].intersects).map(n=>parseInt(n)):[]}getIntersectionsAsArray(e=null,t=null){const{data:n}=this,i=new Set,s=[],r=a=>{if(n[a])if(t!==null)n[a].intersects[t]&&s.push(n[a].intersects[t]);else{const l=n[a].intersects;for(const h in l)i.has(h)||(i.add(h),s.push(l[h]))}};if(e!==null)r(e);else for(const a in n)r(a);return s}reset(){this.data={}}}class $u{constructor(){this.enabled=!1,this.triangleIntersectsA=new Oo,this.triangleIntersectsB=new Oo,this.intersectionEdges=[]}addIntersectingTriangles(e,t,n,i){const{triangleIntersectsA:s,triangleIntersectsB:r}=this;s.addTriangleIntersection(e,t,n,i),r.addTriangleIntersection(n,i,e,t)}addEdge(e){this.intersectionEdges.push(e.clone())}reset(){this.triangleIntersectsA.reset(),this.triangleIntersectsB.reset(),this.intersectionEdges=[]}init(){this.enabled&&(this.reset(),Lo(this))}complete(){this.enabled&&Lo(null)}}const wt=new _.Matrix4,vi=new _.Matrix3,zt=new _.Triangle,bi=new _.Triangle,xt=new _.Triangle,_i=new _.Triangle,Ye=[],Nt=[];function Hu(o){for(const e of o)return e}function Ju(o,e,t,n,i,s={}){const{useGroups:r=!0}=s,{aIntersections:a,bIntersections:l}=Zu(o,e),h=[];let c=null,d;return d=r?0:-1,zo(o,e,a,t,!1,n,i,d),No(o,e,a,t,!1,i,d),t.findIndex(p=>p!==Co&&p!==Ao)!==-1&&(d=r?o.geometry.groups.length||1:-1,zo(e,o,l,t,!0,n,i,d),No(e,o,l,t,!0,i,d)),Ye.length=0,Nt.length=0,{groups:h,materials:c}}function zo(o,e,t,n,i,s,r,a=0){const l=o.matrixWorld.determinant()<0;wt.copy(e.matrixWorld).invert().multiply(o.matrixWorld),vi.getNormalMatrix(o.matrixWorld).multiplyScalar(l?-1:1);const h=o.geometry.groupIndices,c=o.geometry.index,d=o.geometry.attributes.position,m=e.geometry.boundsTree,p=e.geometry.index,f=e.geometry.attributes.position,u=t.ids,g=t.intersectionSet;for(let y=0,w=u.length;y<w;y++){const x=u[y],v=a===-1?0:h[x]+a,b=3*x,D=c.getX(b+0),T=c.getX(b+1),k=c.getX(b+2);zt.a.fromBufferAttribute(d,D).applyMatrix4(wt),zt.b.fromBufferAttribute(d,T).applyMatrix4(wt),zt.c.fromBufferAttribute(d,k).applyMatrix4(wt),s.reset(),s.initialize(zt);const P=g[x];for(let z=0,C=P.length;z<C;z++){const E=3*P[z],M=p.getX(E+0),B=p.getX(E+1),V=p.getX(E+2);bi.a.fromBufferAttribute(f,M),bi.b.fromBufferAttribute(f,B),bi.c.fromBufferAttribute(f,V),s.splitByTriangle(bi)}const I=s.triangles;for(let z=0,C=I.length;z<C;z++){const E=I[z],M=s.coplanarTriangleUsed?Xu(E,m):Eo(E,m);Ye.length=0,Nt.length=0;for(let B=0,V=n.length;B<V;B++){const U=Bo(n[B],M,i);U!==ks&&(Nt.push(U),Ye.push(r[B].getGroupAttrSet(v)))}if(Ye.length!==0){zt.getBarycoord(E.a,_i.a),zt.getBarycoord(E.b,_i.b),zt.getBarycoord(E.c,_i.c);for(let B=0,V=Ye.length;B<V;B++){const U=Ye[B],G=Nt[B]===vn;qu(x,_i,o.geometry,o.matrixWorld,vi,U,l!==G)}}}}return u.length}function No(o,e,t,n,i,s,r=0){const a=o.matrixWorld.determinant()<0;wt.copy(e.matrixWorld).invert().multiply(o.matrixWorld),vi.getNormalMatrix(o.matrixWorld).multiplyScalar(a?-1:1);const l=e.geometry.boundsTree,h=o.geometry.groupIndices,c=o.geometry.index,d=o.geometry.attributes,m=d.position,p=[],f=o.geometry.halfEdges,u=new Set,g=ws(o.geometry);for(let y=0,w=g;y<w;y++)y in t.intersectionSet||u.add(y);for(;u.size>0;){const y=Hu(u);u.delete(y),p.push(y);const w=3*y,x=c.getX(w+0),v=c.getX(w+1),b=c.getX(w+2);xt.a.fromBufferAttribute(m,x).applyMatrix4(wt),xt.b.fromBufferAttribute(m,v).applyMatrix4(wt),xt.c.fromBufferAttribute(m,b).applyMatrix4(wt);const D=Eo(xt,l);Nt.length=0,Ye.length=0;for(let T=0,k=n.length;T<k;T++){const P=Bo(n[T],D,i);P!==ks&&(Nt.push(P),Ye.push(s[T]))}for(;p.length>0;){const T=p.pop();for(let k=0;k<3;k++){const P=f.getSiblingTriangleIndex(T,k);P!==-1&&u.has(P)&&(p.push(P),u.delete(P))}if(Ye.length!==0){const k=3*T,P=c.getX(k+0),I=c.getX(k+1),z=c.getX(k+2),C=r===-1?0:h[T]+r;if(xt.a.fromBufferAttribute(m,P),xt.b.fromBufferAttribute(m,I),xt.c.fromBufferAttribute(m,z),!yt(xt))for(let E=0,M=Ye.length;E<M;E++){const B=Nt[E],V=Ye[E].getGroupAttrSet(C),U=B===vn;Ku(P,I,z,d,o.matrixWorld,vi,V,U!==a)}}}}}function Qu(o){for(let e=0;e<o.length-1;e++){const t=o[e],n=o[e+1];if(t.materialIndex===n.materialIndex){const i=t.start,s=n.start+n.count;n.start=i,n.count=s-i,o.splice(e,1),e--}}}function ed(o,e,t,n){t.clear();const i=o.attributes;for(let s=0,r=n.length;s<r;s++){const a=n[s],l=i[a];t.initializeArray(a,l.array.constructor,l.itemSize,l.normalized)}for(const s in t.attributes)n.includes(s)||t.delete(s);for(const s in e.attributes)n.includes(s)||(e.deleteAttribute(s),e.dispose())}function td(o,e,t){let n=!1,i=-1;const s=o.attributes,r=e.groupAttributes[0];for(const l in r){const h=e.getTotalLength(l),c=e.getType(l),d=e.getItemSize(l),m=e.getNormalized(l);let p=s[l];(!p||p.array.length<h)&&(p=new _.BufferAttribute(new c(h),d,m),o.setAttribute(l,p),n=!0);let f=0;for(let u=0,g=Math.min(t.length,e.groupCount);u<g;u++){const y=t[u].index,{array:w,type:x,length:v}=e.groupAttributes[y][l],b=new x(w.buffer,0,v);p.array.set(b,f),f+=b.length}p.needsUpdate=!0,i=h/p.itemSize}if(o.index){const l=o.index.array;if(l.length<i)o.index=null,n=!0;else for(let h=0,c=l.length;h<c;h++)l[h]=h}let a=0;o.clearGroups();for(let l=0,h=Math.min(t.length,e.groupCount);l<h;l++){const{index:c,materialIndex:d}=t[l],m=e.getCount(c);m!==0&&(o.addGroup(a,m,d),a+=m)}o.setDrawRange(0,i),o.boundsTree=null,n&&o.dispose()}function Ro(o,e){let t=e;return Array.isArray(e)||(t=[],o.forEach(n=>{t[n.materialIndex]=e})),t}class nd{constructor(){this.triangleSplitter=new zu,this.attributeData=[],this.attributes=["position","uv","normal"],this.useGroups=!0,this.consolidateGroups=!0,this.debug=new $u}getGroupRanges(e){return!this.useGroups||e.groups.length===0?[{start:0,count:1/0,materialIndex:0}]:e.groups.map(t=>({...t}))}evaluate(e,t,n,i=new fi){let s=!0;if(Array.isArray(n)||(n=[n]),Array.isArray(i)||(i=[i],s=!1),i.length!==n.length)throw new Error("Evaluator: operations and target array passed as different sizes.");e.prepareGeometry(),t.prepareGeometry();const{triangleSplitter:r,attributeData:a,attributes:l,useGroups:h,consolidateGroups:c,debug:d}=this;for(;a.length<i.length;)a.push(new Ru);i.forEach((y,w)=>{ed(e.geometry,y.geometry,a[w],l)}),d.init(),Ju(e,t,n,r,a,{useGroups:h}),d.complete();const m=this.getGroupRanges(e.geometry),p=Ro(m,e.material),f=this.getGroupRanges(t.geometry),u=Ro(f,t.material);f.forEach(y=>y.materialIndex+=p.length);let g=[...m,...f].map((y,w)=>({...y,index:w}));if(h){const y=[...p,...u];c&&(g=g.map(x=>{const v=y[x.materialIndex];return x.materialIndex=y.indexOf(v),x}).sort((x,v)=>x.materialIndex-v.materialIndex));const w=[];for(let x=0,v=y.length;x<v;x++){let b=!1;for(let D=0,T=g.length;D<T;D++){const k=g[D];k.materialIndex===x&&(b=!0,k.materialIndex=w.length)}b&&w.push(y[x])}i.forEach(x=>{x.material=w})}else g=[{start:0,count:1/0,index:0,materialIndex:0}],i.forEach(y=>{y.material=p[0]});return i.forEach((y,w)=>{const x=y.geometry;td(x,a[w],g),c&&Qu(x.groups)}),s?i:i[0]}evaluateHierarchy(e,t=new fi){e.updateMatrixWorld(!0);const n=(s,r)=>{const a=s.children;for(let l=0,h=a.length;l<h;l++){const c=a[l];c.isOperationGroup?n(c,r):r(c)}},i=s=>{const r=s.children;let a=!1;for(let h=0,c=r.length;h<c;h++){const d=r[h];a=i(d)||a}const l=s.isDirty();if(l&&s.markUpdated(),a&&!s.isOperationGroup){let h;return n(s,c=>{h?h=this.evaluate(h,c,c.operation):h=this.evaluate(s,c,c.operation)}),s._cachedGeometry=h.geometry,s._cachedMaterials=h.material,!0}else return a||l};return i(e),t.geometry=e._cachedGeometry,t.material=e._cachedMaterials,t}reset(){this.triangleSplitter.reset()}}class id{engine;planeObjects=[];planes=[];isActive=!1;evaluator;geometryCache=new Map;sectionMeshes=new Map;planeGroup;planeSize=1e3;sourceMeshes=new Map;planeThickness=.01;updateThrottleTime=100;lastUpdateTime=0;pendingUpdate=!1;updateTimer=null;cacheExpireTime=3e4;planeStates=new Map;constructor(e,t={}){this.engine=e,this.evaluator=new nd,this.planeGroup=new S.Group,this.planeGroup.name="CSG_ClippingPlanes_Optimized",t.updateThrottleTime!==void 0&&(this.updateThrottleTime=t.updateThrottleTime),t.cacheExpireTime!==void 0&&(this.cacheExpireTime=t.cacheExpireTime),t.planeThickness!==void 0&&(this.planeThickness=t.planeThickness),this.evaluator.attributes=["position","normal"],this.evaluator.useGroups=!1}init(){this.calculateSceneSize(),this.engine.scene.add(this.planeGroup),this.planes.forEach((e,t)=>{const n=this.createEmptySectionMesh(e,t);this.planeGroup.add(n),this.sectionMeshes.set(`plane_${t}`,n),this.planeObjects.push(n),this.planeStates.set(t,{constant:e.constant,normal:e.normal.clone()})})}createEmptySectionMesh(e,t){const n=new S.BufferGeometry,i=new S.MeshStandardMaterial({color:new S.Color(33023),metalness:.1,roughness:.75,side:S.DoubleSide,depthWrite:!0,depthTest:!0,clippingPlanes:this.planes.filter((r,a)=>a!==t)}),s=new S.Mesh(n,i);return s.name=`CSG_Section_Optimized_${t}`,s.visible=!1,s.renderOrder=t+1,s}active(){this.isActive=!0,this.requestUpdate(),this.planeObjects.forEach(e=>{e.visible=!0})}disActive(){this.isActive=!1,this.planeObjects.forEach(e=>{e.visible=!1}),this.updateTimer&&(clearTimeout(this.updateTimer),this.updateTimer=null)}setSourceMeshes(e){this.sourceMeshes.clear(),e.forEach(t=>{const n=t.uuid;this.sourceMeshes.set(n,t)}),this.isActive&&this.requestUpdate()}addSourceMesh(e){const t=e.uuid;this.sourceMeshes.has(t)||(this.sourceMeshes.set(t,e),this.isActive&&this.requestUpdate())}removeSourceMesh(e){const t=e.uuid;this.sourceMeshes.delete(t)&&(this.clearMeshCache(t),this.isActive&&this.requestUpdate())}requestUpdate(){if(!this.isActive)return;const e=Date.now(),t=e-this.lastUpdateTime;t>=this.updateThrottleTime?(this.lastUpdateTime=e,this.pendingUpdate=!1):(this.pendingUpdate=!0,this.updateTimer&&clearTimeout(this.updateTimer),this.updateTimer=setTimeout(()=>{this.pendingUpdate&&this.isActive&&(this.lastUpdateTime=Date.now(),this.pendingUpdate=!1),this.updateTimer=null},this.updateThrottleTime-t))}updateAllSections(){this.isActive&&(this.planes.forEach((e,t)=>{if(Math.abs(e.constant)<99999)this.hasPlaneChanged(t,e)&&(this.updateSection(e,t),this.updatePlaneState(t,e));else{const n=this.sectionMeshes.get(`plane_${t}`);n&&(n.visible=!1)}}),this.cleanExpiredCache())}hasPlaneChanged(e,t){const n=this.planeStates.get(e);if(!n)return!0;const i=Math.abs(n.constant-t.constant)>1e-4,s=!n.normal.equals(t.normal);return i||s}updatePlaneState(e,t){this.planeStates.set(e,{constant:t.constant,normal:t.normal.clone()})}getPlaneHash(e){const t=e.normal,n=e.constant;return`${t.x.toFixed(4)}_${t.y.toFixed(4)}_${t.z.toFixed(4)}_${n.toFixed(4)}`}getCacheKey(e,t){return`${e}_plane_${t}`}updateSection(e,t){const n=this.sectionMeshes.get(`plane_${t}`);if(!n)return;const i=this.getPlaneHash(e),s=[];if(this.sourceMeshes.forEach((r,a)=>{const l=this.getCacheKey(a,t),h=this.geometryCache.get(l);if(h&&h.planeHash===i)s.push(h.geometry.clone()),h.timestamp=Date.now();else try{const c=this.createPlaneBrush(e),d=new fi(r.geometry);r.updateMatrixWorld(!0),d.matrix.copy(r.matrixWorld),d.updateMatrixWorld();const m=this.evaluator.evaluate(c,d,So);m&&m.geometry.attributes.position.count>0?(s.push(m.geometry),this.geometryCache.set(l,{geometry:m.geometry.clone(),planeHash:i,timestamp:Date.now()})):this.geometryCache.delete(l)}catch(c){console.warn(`CSG intersection failed for mesh ${a}:`,c)}}),s.length>0){const r=this.mergeGeometries(s);n.geometry&&n.geometry.dispose(),n.geometry=r,n.visible=!0,n.position.set(0,0,0),n.rotation.set(0,0,0),n.scale.set(1,1,1),n.updateMatrixWorld()}else n.visible=!1;s.forEach(r=>r.dispose())}clearMeshCache(e){const t=[];this.geometryCache.forEach((n,i)=>{i.startsWith(e)&&(n.geometry.dispose(),t.push(i))}),t.forEach(n=>this.geometryCache.delete(n))}cleanExpiredCache(){const e=Date.now(),t=[];this.geometryCache.forEach((n,i)=>{e-n.timestamp>this.cacheExpireTime&&(n.geometry.dispose(),t.push(i))}),t.forEach(n=>this.geometryCache.delete(n))}clearAllCache(){this.geometryCache.forEach(e=>{e.geometry.dispose()}),this.geometryCache.clear()}createPlaneBrush(e){const t=new S.BoxGeometry(this.planeSize,this.planeThickness,this.planeSize);t.translate(0,e.constant,0),t.applyQuaternion(new S.Quaternion().setFromUnitVectors(new S.Vector3(0,-1,0),e.normal));const n=new S.Mesh(t),i=new fi(t);return i.matrix.copy(n.matrixWorld),i.updateMatrixWorld(),i}mergeGeometries(e){if(e.length===1)return e[0].clone();const t=new S.BufferGeometry,n=[],i=[],s=[];let r=0;return e.forEach(a=>{const l=a.attributes.position,h=a.attributes.normal;for(let c=0;c<l.count;c++)n.push(l.getX(c),l.getY(c),l.getZ(c));if(h)for(let c=0;c<h.count;c++)i.push(h.getX(c),h.getY(c),h.getZ(c));if(a.index)for(let c=0;c<a.index.count;c++)s.push(a.index.getX(c)+r);r+=l.count}),t.setAttribute("position",new S.Float32BufferAttribute(n,3)),i.length>0?t.setAttribute("normal",new S.Float32BufferAttribute(i,3)):t.computeVertexNormals(),s.length>0&&t.setIndex(s),t}calculateSceneSize(){const e=new S.Box3;if(this.engine.scene.traverse(t=>{if(t.isMesh&&t.geometry){const n=new S.Box3().setFromObject(t);e.union(n)}}),e.isEmpty())this.planeSize=1e3;else{const t=e.getSize(new S.Vector3),n=Math.max(t.x,t.y,t.z);this.planeSize=n*3}}update(){this.isActive&&this.pendingUpdate&&!this.updateTimer&&this.requestUpdate()}dispose(){this.updateTimer&&(clearTimeout(this.updateTimer),this.updateTimer=null),this.clearAllCache(),this.planeObjects.forEach(e=>{e.geometry&&e.geometry.dispose(),e.material&&(Array.isArray(e.material)?e.material.forEach(t=>t.dispose()):e.material.dispose())}),this.sectionMeshes.clear(),this.planeObjects=[],this.sourceMeshes.clear(),this.planeGroup.parent&&this.planeGroup.parent.remove(this.planeGroup)}setSectionColor(e){this.planeObjects.forEach(t=>{t.material instanceof S.MeshStandardMaterial&&t.material.color.set(e)})}getCacheStats(){return{cacheSize:this.geometryCache.size,sourceMeshCount:this.sourceMeshes.size,sectionMeshCount:this.sectionMeshes.size}}setPlaneThickness(e){if(e<=0){console.warn("Plane thickness must be positive");return}this.planeThickness=e,this.clearAllCache(),this.isActive&&this.requestUpdate()}getPlaneThickness(){return this.planeThickness}showSections(){this.sectionMeshes.forEach(e=>{e.geometry?.attributes.position?.count&&e.geometry.attributes.position.count>0&&(e.visible=!0)})}hideSections(){this.sectionMeshes.forEach(e=>{e.visible=!1})}showSection(){this.planeGroup.visible=!0}hideSection(){this.planeGroup.visible=!1}toggleSectionsVisibility(){let e=!1;return this.sectionMeshes.forEach(t=>{t.visible&&(e=!0)}),e?(this.hideSections(),!1):(this.showSections(),!0)}toggleSectionVisibility(e){const t=this.sectionMeshes.get(`plane_${e}`);return t?(t.visible=!t.visible,t.visible):!1}}class sd{engine;isActive=!1;box;pickPoint;pickNormal;pickMesh;box_;plane;meshs;isDrag=!1;maxBox;csgClipping=null;useCsgClipping=!1;constructor(e,t){this.engine=e,this.meshs=[],t?.useCsgClipping!==void 0&&(this.useCsgClipping=t.useCsgClipping),this.useCsgClipping&&this.initCsgClipping()}initCsgClipping(){this.csgClipping=new id(this.engine,{updateThrottleTime:150,cacheExpireTime:45e3}),this.csgClipping.planes=this.engine.sectionPlane,this.csgClipping.init()}active(){this.isActive||(this.engine.handelBehaved.init(this),this.engine.handelBehaved.active(),this.engine.scene.children.filter(e=>e.type=="Group"&&e.name=="ClippingBox").forEach(e=>{e.children.forEach(t=>{t.name.includes("face")||(t.visible=!0)})}),this.isActive=!0,this.init())}disActive(){this.init(),this.isActive=!1,this.engine.handelBehaved.disActive(),this.csgClipping&&this.csgClipping.disActive(),this.engine.scene.children.filter(e=>e.type=="Group"&&e.name=="ClippingBox").forEach(e=>{e.children.forEach(t=>{t.name.includes("face")||(t.visible=!1)})}),this.engine.interactionModule.init(),this.engine.interactionModule.active()}disabled(){this.isActive=!1,this.engine.handelBehaved.disActive(),this.engine.interactionModule.init(),this.engine.interactionModule.active(),this.engine.scene.children.filter(e=>e.type=="Group"&&e.name=="ClippingBox").forEach(e=>{e.children.forEach(t=>{t.name.includes("face")||(t.visible=!1)})})}recover(){this.isActive||(this.engine.handelBehaved.init(this),this.engine.handelBehaved.active(),this.engine.scene.children.filter(e=>e.type=="Group"&&e.name=="ClippingBox").forEach(e=>{e.children.forEach(t=>{t.name.includes("face")||(t.visible=!0)})}),this.isActive=!0)}init(){let e=this.engine.octreeBox.getBoundingBox();this.maxBox=JSON.parse(JSON.stringify(e)),this.box=e,this.updata_face(e)}getboxXyz(){return{minX:this.box.min.x,minY:this.box.min.y,minZ:this.box.min.z,maxX:this.box.max.x,maxY:this.box.max.y,maxZ:this.box.max.z}}setboxXyz(e){this.box.min.x=e.minX,this.box.min.y=e.minY,this.box.min.z=e.minZ,this.box.max.x=e.maxX,this.box.max.y=e.maxY,this.box.max.z=e.maxZ,this.updata_face(this.box)}setBox(e){this.box=e,this.updata_face(e)}reverseBox(){}handleMouseDown(e){this.isDrag=!0;const t=e.raycaster.intersectObjects(this.meshs,!1);if(t!=null&&t.length>0)if(this.pickPoint=t[0].point,this.pickNormal=t[0].face.normal,this.engine.controls.enabled=!1,this.pickMesh=t[0].object,this.box_={min:this.box.min.clone(),max:this.box.max.clone()},this.pickNormal.y==0){const n=new S.Plane;n.setFromNormalAndCoplanarPoint(new S.Vector3(0,1,0),this.pickPoint),this.plane=n}else{let n=new S.Vector3(this.engine.camera.position.x,this.pickPoint.y,this.engine.camera.position.z);const i=new S.Plane;i.setFromNormalAndCoplanarPoint(n.clone().sub(this.pickPoint.clone()).setLength(1),this.pickPoint),this.plane=i}}handleMouseUp(e){this.isDrag=!1,this.pickPoint=null,this.pickNormal=null,this.pickMesh=null,this.engine.controls.enabled=!0,this.csgClipping&&this.isActive}handleMouseMove(e){this.meshs.forEach(n=>{n.material.opacity=0});const t=e.raycaster.intersectObjects(this.meshs,!1);if(t!=null&&t.length>0&&(t[0].object.material.opacity=.05),this.pickPoint!=null){const n=new S.Vector3;if(e.raycaster.ray.intersectPlane(this.plane,n)){let i=n.clone().sub(this.pickPoint.clone()).dot(this.pickNormal.clone());this.pickMesh.name=="前"||this.pickMesh.name=="左"||this.pickMesh.name=="底"?this.box.min=this.box_.min.clone().add(this.pickNormal.clone().setLength(i)):this.box.max=this.box_.max.clone().add(this.pickNormal.clone().setLength(i)),this.updata_face(this.box),this.calculate_ratio()}}}calculate_ratio(){let e=this.maxBox.max.x-this.maxBox.min.x,t=this.maxBox.max.y-this.maxBox.min.y,n=this.maxBox.max.z-this.maxBox.min.z,i=(this.box.min.x-this.maxBox.min.x)/e*100,s=(this.box.max.x-this.maxBox.min.x)/e*100,r=(this.box.min.y-this.maxBox.min.y)/t*100,a=(this.box.max.y-this.maxBox.min.y)/t*100,l=(this.box.min.z-this.maxBox.min.z)/n*100,h=(this.box.max.z-this.maxBox.min.z)/n*100;i<0&&(i=0),s<0&&(s=0),r<0&&(r=0),a<0&&(a=0),l<0&&(l=0),h<0&&(h=0),i>100&&(i=100),s>100&&(s=100),r>100&&(r=100),a>100&&(a=100),l>100&&(l=100),h>100&&(h=100);let c={x:{min:i,max:s},y:{min:r,max:a},z:{min:l,max:h}};this.engine.events.trigger(_e.SectionMove,c)}updata_face(e){let t=this,n=[new S.Vector3(e.min.x,e.min.y,e.min.z),new S.Vector3(e.max.x,e.min.y,e.min.z),new S.Vector3(e.max.x,e.max.y,e.min.z),new S.Vector3(e.min.x,e.max.y,e.min.z)],i=[new S.Vector3(e.min.x,e.min.y,e.max.z),new S.Vector3(e.max.x,e.min.y,e.max.z),new S.Vector3(e.max.x,e.max.y,e.max.z),new S.Vector3(e.min.x,e.max.y,e.max.z)],s=[new S.Vector3(e.max.x,e.min.y,e.max.z),new S.Vector3(e.max.x,e.min.y,e.min.z),new S.Vector3(e.max.x,e.max.y,e.min.z),new S.Vector3(e.max.x,e.max.y,e.max.z)],r=[new S.Vector3(e.min.x,e.min.y,e.min.z),new S.Vector3(e.min.x,e.min.y,e.max.z),new S.Vector3(e.min.x,e.max.y,e.max.z),new S.Vector3(e.min.x,e.max.y,e.min.z)],a=[new S.Vector3(e.min.x,e.max.y,e.min.z),new S.Vector3(e.max.x,e.max.y,e.min.z),new S.Vector3(e.max.x,e.max.y,e.max.z),new S.Vector3(e.min.x,e.max.y,e.max.z)],l=[new S.Vector3(e.min.x,e.min.y,e.min.z),new S.Vector3(e.max.x,e.min.y,e.min.z),new S.Vector3(e.max.x,e.min.y,e.max.z),new S.Vector3(e.min.x,e.min.y,e.max.z)];h(n,new S.Vector3(0,0,-1),"前"),h(i,new S.Vector3(0,0,1),"后"),h(s,new S.Vector3(1,0,0),"右"),h(r,new S.Vector3(-1,0,0),"左"),h(a,new S.Vector3(0,1,0),"顶"),h(l,new S.Vector3(0,-1,0),"底");function h(c,d,m){const p=new S.BufferGeometry,f=new Float32Array([c[0].x,c[0].y,c[0].z,c[1].x,c[1].y,c[1].z,c[2].x,c[2].y,c[2].z,c[3].x,c[3].y,c[3].z]),u=[0,1,2,0,2,3];p.setAttribute("position",new S.BufferAttribute(f,3)),p.setIndex(u);let g=t.engine.scene.children.find(D=>D.type=="Group"&&D.name=="ClippingBox");g==null&&(g=new S.Group,g.name="ClippingBox",t.engine.scene.add(g));let y=t.meshs.find(D=>D.name==m);if(y==null){const D=new S.MeshBasicMaterial({color:65280,transparent:!0,opacity:0,side:S.DoubleSide});D.polygonOffset=!0,D.polygonOffsetFactor=1,D.polygonOffsetUnits=4;const T=new S.Mesh(p,D);T.normal=d,T.name=m,g.add(T),t.meshs.push(T)}else y.geometry=p;const w=new Float32Array([c[0].x,c[0].y,c[0].z,c[1].x,c[1].y,c[1].z,c[2].x,c[2].y,c[2].z,c[3].x,c[3].y,c[3].z,c[0].x,c[0].y,c[0].z]);let x=new S.LineBasicMaterial({color:255}),v=new S.BufferGeometry;v.setAttribute("position",new S.BufferAttribute(w,3));let b=t.meshs.find(D=>D.name==m+"Line");b==null&&(b=new S.Line(v,x),b.name=m+"Line",g.add(b),t.meshs.push(b)),b.geometry=v,b.material=x,m=="前"||m=="左"||m=="底"?t.engine.sectionPlane.find(D=>D.name==m).setFromNormalAndCoplanarPoint(d.clone().setLength(-1),e.min):t.engine.sectionPlane.find(D=>D.name==m).setFromNormalAndCoplanarPoint(d.clone().setLength(-1),e.max),t.engine.scene.children.filter(D=>D.type=="Mesh"&&D.url).forEach(D=>{D.material&&Array.isArray(D.material)?D.material.forEach(T=>{T.clippingPlanes=t.engine.sectionPlane}):D.material.clippingPlanes=t.engine.sectionPlane})}}}class rd{engine;isActive=!1;isDrag=!1;meshs=[];box;pickPoint;pickNormal;pickMesh;box_;plane;angleX=0;angleY=0;angleZ=0;direction=1;normal=new S.Vector3(0,0,1);distance=0;center=null;current_center=null;constructor(e){this.engine=e,this.meshs=[],this.box=null}active(){if(this.isActive==!0)return;this.isActive=!0,this.engine.scene.children.filter(t=>t.type=="Group"&&t.name=="ClippingBox").forEach(t=>{t.children.forEach(n=>{n.name.includes("face")&&(n.visible=!0)})}),this.engine.handelBehaved.init(this),this.engine.handelBehaved.active();let e=this;e.engine.scene.children.filter(t=>t.type=="Mesh"&&t.url).forEach(t=>{t.material&&Array.isArray(t.material)?t.material.forEach(n=>{n.clippingPlanes=e.engine.sectionPlane}):t.material.clippingPlanes=e.engine.sectionPlane,e.engine.clipping.clippingStencil?.addMesh(e.engine.sectionPlane.find(n=>n.name=="face"),t)}),this.init()}disActive(){this.init(),this.isActive=!1,this.engine.handelBehaved.disActive();const e=this.engine.sectionPlane.find(t=>t.name=="face");e&&(e.constant=1e5),this.engine.scene.children.filter(t=>t.type=="Group"&&t.name=="ClippingBox").forEach(t=>{t.children.forEach(n=>{n.name.includes("face")&&(n.visible=!1)})})}init(){let e=this.engine.octreeBox.getBoundingBox();this.box=e,this.updata_face(0)}disabled(){this.isActive=!1,this.engine.handelBehaved.disActive(),this.engine.interactionModule.init(),this.engine.interactionModule.active(),this.engine.scene.children.filter(e=>e.type=="Group"&&e.name=="ClippingBox").forEach(e=>{e.children.forEach(t=>{t.name.includes("face")&&(t.visible=!1)})})}recover(){this.isActive||(this.engine.handelBehaved.init(this),this.engine.handelBehaved.active(),this.engine.scene.children.filter(e=>e.type=="Group"&&e.name=="ClippingBox").forEach(e=>{e.children.forEach(t=>{t.name.includes("face")&&(t.visible=!0)})}),this.isActive=!0)}setFaceAngle(e,t,n){this.angleX=e,this.angleY=t,this.angleZ=n,this.normal=new S.Vector3(0,1,0).applyAxisAngle(new S.Vector3(1,0,0),e).applyAxisAngle(new S.Vector3(0,0,1),t).applyAxisAngle(new S.Vector3(0,1,0),n),this.normal.normalize(),this.updata_face(0)}setFaceNormal(e,t=0){this.normal=e,this.distance=t,this.updata_face(t)}reverse(){this.direction=this.direction*-1,this.updata_face(this.distance)}getFaceAngle(){return{angleX:this.angleX,angleY:this.angleY,angleZ:this.angleZ,direction:this.direction}}updata_face(e){let t=this,n=t.engine.scene.children.find(P=>P.type=="Group"&&P.name=="ClippingBox");n==null&&(n=new S.Group,n.name="ClippingBox",t.engine.scene.add(n));let i=new S.Vector3(1,0,0),s=new S.Vector3(0,1,0),r=new S.Vector3(0,0,1),a,l,h=this.normal.clone().normalize(),c=Math.abs(h.dot(i)),d=Math.abs(h.dot(s)),m=Math.abs(h.dot(r));c<=d&&c<=m?a=i:d<=c&&d<=m?a=s:a=r,a=a.clone().sub(h.clone().multiplyScalar(a.dot(h))).normalize(),l=new S.Vector3().crossVectors(h,a).normalize();let p=null;this.center==null?(p=new S.Vector3((this.box.min.x+this.box.max.x)/2,(this.box.min.y+this.box.max.y)/2,(this.box.min.z+this.box.max.z)/2),this.center=p.clone()):p=this.center.clone();let f=this.box.max.x-this.box.min.x,u=this.box.max.y-this.box.min.y,g=this.box.max.z-this.box.min.z,y=Math.max(Math.abs(a.x)*f,Math.abs(a.y)*u,Math.abs(a.z)*g),w=Math.max(Math.abs(l.x)*f,Math.abs(l.y)*u,Math.abs(l.z)*g),x=p.clone().add(a.clone().multiplyScalar(-y/2)).add(l.clone().multiplyScalar(-w/2)),v=p.clone().add(a.clone().multiplyScalar(y/2)).add(l.clone().multiplyScalar(-w/2)),b=p.clone().add(a.clone().multiplyScalar(y/2)).add(l.clone().multiplyScalar(w/2)),D=p.clone().add(a.clone().multiplyScalar(-y/2)).add(l.clone().multiplyScalar(w/2));x.add(h.clone().multiplyScalar(e)),v.add(h.clone().multiplyScalar(e)),b.add(h.clone().multiplyScalar(e)),D.add(h.clone().multiplyScalar(e)),this.current_center=p.clone().add(h.clone().multiplyScalar(e)),k([x,v,b,D],h,"face");function k(P,I,z){const C=new S.BufferGeometry,E=new Float32Array([P[0].x,P[0].y,P[0].z,P[1].x,P[1].y,P[1].z,P[2].x,P[2].y,P[2].z,P[3].x,P[3].y,P[3].z]),M=[0,1,2,0,2,3];C.setAttribute("position",new S.BufferAttribute(E,3)),C.setIndex(M);let B=t.meshs.find($=>$.name==z);if(B==null){const $=new S.MeshBasicMaterial({color:65280,transparent:!0,opacity:.02,side:S.DoubleSide});$.polygonOffset=!0,$.polygonOffsetFactor=1,$.polygonOffsetUnits=4;const F=new S.Mesh(C,$);F.normal=I,F.name=z,n.add(F),t.meshs.push(F)}else B.geometry=C;const V=new Float32Array([P[0].x,P[0].y,P[0].z,P[1].x,P[1].y,P[1].z,P[2].x,P[2].y,P[2].z,P[3].x,P[3].y,P[3].z,P[0].x,P[0].y,P[0].z]);let U=new S.LineBasicMaterial({color:255}),H=new S.BufferGeometry;H.setAttribute("position",new S.BufferAttribute(V,3));let G=t.meshs.find($=>$.name==z+"Line");G==null&&(G=new S.Line(H,U),G.name=z+"Line",n.add(G),t.meshs.push(G)),G.geometry=H,G.material=U,t.engine.sectionPlane.find($=>$.name==z).setFromNormalAndCoplanarPoint(I.clone().setLength(t.direction),P[0])}}handleMouseDown(e){this.isDrag=!0;const t=e.raycaster.intersectObjects(this.meshs,!1);if(t!=null&&t.length>0)if(this.pickPoint=t[0].point,this.pickNormal=t[0].face.normal,this.engine.controls.enabled=!1,this.pickMesh=t[0].object,this.box_={min:this.box.min.clone(),max:this.box.max.clone()},this.center=this.current_center.clone(),this.pickNormal.y==0){const n=new S.Plane;n.setFromNormalAndCoplanarPoint(new S.Vector3(0,1,0),this.pickPoint),this.plane=n}else{let n=new S.Vector3(this.engine.camera.position.x,this.pickPoint.y,this.engine.camera.position.z);const i=new S.Plane;i.setFromNormalAndCoplanarPoint(n.clone().sub(this.pickPoint.clone()).setLength(1),this.pickPoint),this.plane=i}}handleMouseUp(e){this.isDrag=!1,this.pickPoint=null,this.pickNormal=null,this.pickMesh=null,this.engine.controls.enabled=!0}handleMouseMove(e){this.meshs.forEach(n=>{n.material.opacity=0});const t=e.raycaster.intersectObjects(this.meshs,!1);if(t!=null&&t.length>0&&(t[0].object.material.opacity=.05),this.pickPoint!=null){const n=new S.Vector3;if(e.raycaster.ray.intersectPlane(this.plane,n)){let i=n.clone().sub(this.pickPoint.clone()).dot(this.pickNormal.clone());this.distance=i,this.updata_face(this.distance)}}}}class od{engine;callback_;constructor(e){this.engine=e}init(){this.engine.handelBehaved.init(this,{showCatch:!0}),this.engine.handelBehaved.active()}catch_face(e){this.callback_=e}handleMouseMove(e){}handleMouseClick(e){let t=e.catch.normal;this.engine.handelBehaved.disActive(),this.callback_({dir:t,position:e.catch.point})}}class ad{engine;sectionBox;sectionFace;clippingStencil;currentClippingMode="";constructor(e){this.engine=e;let t=new S.Plane(new S.Vector3(0,0,1),1e5);t.name="前";let n=new S.Plane(new S.Vector3(0,0,1),1e5);n.name="左";let i=new S.Plane(new S.Vector3(0,0,1),1e5);i.name="后";let s=new S.Plane(new S.Vector3(0,0,1),1e5);s.name="右";let r=new S.Plane(new S.Vector3(0,0,1),1e5);r.name="顶";let a=new S.Plane(new S.Vector3(0,0,1),1e5);a.name="底";let l=new S.Plane(new S.Vector3(0,0,1),1e5);l.name="face",this.engine.sectionPlane=[t,n,i,s,r,a,l]}init(){this.sectionBox=new sd(this.engine),this.sectionFace=new rd(this.engine)}scaleBox(){let e=this.engine.octreeBox.getBoundingBox();this.sectionBox.setBox(e)}clippingModel(e){let t=[];e.forEach(s=>{let r=this.engine.models.find(a=>a.url===s.url);s.ids.forEach(a=>{r.nodesMap.get(a).infos.forEach(l=>{t.push(l.box)})})}),this.active("box");let n=i(t);this.sectionBox.setBox(n);function i(s){let r=new S.Vector3(1e8,1e9,1e10),a=new S.Vector3(-1e8,-1e9,-1e10);return s.forEach(l=>{l.min.x<r.x&&(r.x=l.min.x),l.min.y<r.y&&(r.y=l.min.y),l.min.z<r.z&&(r.z=l.min.z),l.max.x>a.x&&(a.x=l.max.x),l.max.y>a.y&&(a.y=l.max.y),l.max.z>a.z&&(a.z=l.max.z)}),new S.Box3(r,a)}}updateClippingValue(e){let t=this.sectionBox.maxBox,n=t.min.x+(t.max.x-t.min.x)*e.x.min*.01,i=t.min.y+(t.max.y-t.min.y)*e.y.min*.01,s=t.min.z+(t.max.z-t.min.z)*e.z.min*.01,r=t.min.x+(t.max.x-t.min.x)*e.x.max*.01,a=t.min.y+(t.max.y-t.min.y)*e.y.max*.01,l=t.min.z+(t.max.z-t.min.z)*e.z.max*.01;this.sectionBox.setboxXyz({minX:n,minY:i,minZ:s,maxX:r,maxY:a,maxZ:l})}active(e){if(this.sectionFace.disActive(),this.sectionBox.disActive(),this.currentClippingMode=e,e=="x")this.sectionFace.init(),this.sectionFace.active(),this.sectionFace.setFaceAngle(Math.PI/2,0,0);else if(e=="y")this.sectionFace.init(),this.sectionFace.active(),this.sectionFace.setFaceAngle(0,Math.PI/2,0);else if(e=="z")this.sectionFace.init(),this.sectionFace.active(),this.sectionFace.setFaceAngle(0,0,Math.PI/2);else if(e=="box")this.sectionBox.init(),this.sectionBox.active();else if(e=="face"){let t=new od(this.engine);t.init(),t.catch_face(n=>{this.sectionFace.init(),this.sectionFace.active();let i=this.engine.octreeBox.getBoundingBox(),s=n.position.clone().sub(i.min.clone().add(i.max.clone()).setLength(.5)),r=new S.Vector3(n.dir.x,n.dir.y,n.dir.z),a=s.dot(r);this.sectionFace.setFaceNormal(n.dir,a)})}}disabled(){this.currentClippingMode=="box"?this.sectionBox.disabled():this.sectionFace.disabled()}recover(){this.currentClippingMode=="box"?this.sectionBox.recover():this.sectionFace.recover()}reverse(){this.sectionFace.reverse()}disActive(){this.sectionFace.disActive(),this.sectionBox.disActive(),this.currentClippingMode=""}}class ld{engine;constructor(e){this.engine=e}getLevelTreeData(){let e=[];return this.engine.engineStatus.models.forEach(t=>{e.push({children:t.info.modelTree.modelTreeLevel,name:t.info.baseInfo.name,url:t.url})}),e}getTypeTreeData(){let e=[];return this.engine.engineStatus.models.forEach(t=>{e.push({children:t.info.modelTree.modelTreeType,name:t.info.baseInfo.name,url:t.url})}),e}getMajorTreeData(){let e=[];return this.engine.engineStatus.models.forEach(t=>{e.push({children:t.info.modelTree.modelTreeMajor,name:t.info.baseInfo.name,url:t.url})}),e}}class cd{engine;constructor(e){this.engine=e}getEngineInfo(){let e=0,t=0,n=0;return!this.engine||!this.engine.scene?{totalVertices:0,totalTriangles:0,meshCount:0}:(this.engine.scene.traverse(i=>{if(i instanceof S.Mesh){const s=i.geometry;if(s&&s.attributes){const r=s.attributes.position;if(r){const a=r.count;e+=a;let l=0;s.index?l=s.index.count/3:l=a/3,t+=l}}}}),this.engine.engineStatus.models.forEach(i=>{n=n+i.info.modelEdge.length}),{totalVertices:Math.floor(e),totalTriangles:Math.floor(t),meshCount:n})}}class hd{engine;constructor(e){this.engine=e}init(){}getModelProperties(e,t,n){let i=this.engine.engineStatus.models.find(r=>r.url===e);i.properties==null&&Dr(e+"/property",r=>{let a=JSON.parse(r);i.properties=a,setTimeout(()=>{s(a,t,n)},100)}),s(i.properties,t,n);function s(r,a,l){let h=[],c=r.models[a.toString()||""],d=c.map(m=>m[0]);d=d.filter((m,p)=>d.indexOf(m)===p),d.forEach(m=>{let p={name:r.categorys[m],children:[]};h.push(p),c.filter(f=>f[0]===m).forEach(f=>{p.children.push({name:r.names[f[1]],value:r.values[f[2]]})})}),l?.({properties:h,materials:h})}}}class ud{engine;constructor(e){this.engine=e}getModelTypes(){let e=[];return this.engine.engineStatus.models.forEach(t=>{t.info.modelMapper.forEach(i=>{e.push(i.typeName)})}),e=e.filter((t,n,i)=>i.indexOf(t)===n),e}getModelMajors(){let e=[];return this.engine.engineStatus.models.forEach(t=>{t.info.modelMapper.forEach(i=>{e.push(i.majorName)})}),e=e.filter((t,n,i)=>i.indexOf(t)===n),e}getModelLevels(){let e=[];return this.engine.engineStatus.models.forEach(t=>{t.info.modelMapper.forEach(i=>{e.push(i.levelName)})}),e=e.filter((t,n,i)=>i.indexOf(t)===n),e}getModelMappers(e){}getModelMapper(e,t){let n=this.engine.engineStatus.models.find(r=>r.url==e);return n?n.info.modelMapper.find(r=>r.id==t):null}getModelsWithLevelType(e,t,n=null){let i=[];return this.engine.engineStatus.models.forEach(s=>{let r={url:s.url,ids:[]};i.push(r),s.info.modelMapper.filter(l=>l.levelName===e&&l.typeName===t).forEach(l=>{r.ids.push(Number(l.id))})}),n&&n(i),i}getModelsWithType(e,t=null){let n=[];return this.engine.engineStatus.models.forEach(i=>{let s={url:i.url,ids:[]};n.push(s),i.info.modelMapper.filter(a=>a.typeName===e).forEach(a=>{s.ids.push(Number(a.id))})}),t&&t(n),n}getModelsWithLevel(e,t){let n=[];return this.engine.engineStatus.models.forEach(i=>{let s={url:i.url,ids:[]};n.push(s),i.info.modelMapper.filter(a=>a.levelName===e).forEach(a=>{s.ids.push(Number(a.id))})}),t&&t(n),n}getModelsWithMajor(e,t){let n=[];return this.engine.engineStatus.models.forEach(i=>{let s={url:i.url,ids:[]};n.push(s),i.info.modelMapper.filter(a=>a.majorName===e).forEach(a=>{s.ids.push(Number(a.id))})}),t&&t(n),n}}class dd{engine;isActive=!1;groupEdge;material;modelEdgeLoaded=!1;indexes=new Map;constructor(e){this.engine=e,this.groupEdge=this.engine.scene.getObjectByName("groupEdge"),this.material=new S.LineBasicMaterial({color:"#000000",depthTest:!0,transparent:!0,opacity:.3}),this.material.clippingPlanes=this.engine.sectionPlane}active(){this.isActive=!0,this.groupEdge.visible=!0,this.engine.scene.traverse(e=>{e.isMesh&&e.material&&(Array.isArray(e.material)?e.material:[e.material]).forEach(n=>{n.polygonOffset=!0,n.polygonOffsetFactor=1,n.polygonOffsetUnits=4})}),this.show()}disActive(){this.isActive=!1,this.groupEdge.visible=!1,this.engine.scene.traverse(e=>{e.isMesh&&e.material&&(Array.isArray(e.material)?e.material:[e.material]).forEach(n=>{n.polygonOffset=!1})})}loadModelEdge(){this.modelEdgeLoaded||(this.engine.engineStatus.models.forEach(e=>{if(!this.groupEdge.children.find(n=>n.url==e.url)){let n=e.info,i=[],s=new Map;n.modelEdge.forEach(r=>{let a=i.length;for(let l=0;l<r.points.length;l++)r.points[l].length==2&&(i.push(r.points[l][0].X),i.push(r.points[l][0].Z),i.push(-r.points[l][0].Y),i.push(r.points[l][1].X),i.push(r.points[l][1].Z),i.push(-r.points[l][1].Y));s.set(Number(r.id),[a,i.length,r.points])}),this.indexes.set(e.url,s)}}),this.modelEdgeLoaded=!0)}show(){this.modelEdgeLoaded||this.loadModelEdge(),this.indexes.forEach((e,t)=>{let n=[];e.forEach((r,a)=>{r[2].forEach((l,h)=>{l.length==2&&(n.push(l[0].X),n.push(l[0].Z),n.push(-l[0].Y),n.push(l[1].X),n.push(l[1].Z),n.push(-l[1].Y))})});let i=new S.BufferGeometry;i.setAttribute("position",new S.Float32BufferAttribute(n,3));let s=new S.LineSegments(i,this.material);s.url=t,this.groupEdge.add(s)})}getModelEdge(e,t){let n=this.indexes.get(e);if(n){let i=n.get(t);if(i)return i.slice()}return null}hideModelEdge(e,t){let n=this.indexes.get(e);if(n){let i=n.get(t);if(i){let[s,r,a]=i,l=this.groupEdge.children.find(h=>h.url==e);if(l){let h=l.geometry.attributes.position.array;for(let c=s;c<r;c++)h[c]=NaN;l.geometry.attributes.position.needsUpdate=!0}}}}showModelEdge(e,t){let n=this.indexes.get(e);if(n){let i=n.get(t);if(i){let[s,r,a]=i,l=this.groupEdge.children.find(h=>h.url==e);if(l){let h=l.geometry.attributes.position.array,c=0;for(let d=s;d<r;d+=3){const m=Math.floor(c/6),p=c%6>=3;if(a[m]&&a[m].length===2){const f=p?a[m][1]:a[m][0];h[d]=f.X,h[d+1]=f.Z,h[d+2]=-f.Y}c+=3}l.geometry.attributes.position.needsUpdate=!0}}}}}class fd{config;constructor(e){this.config={temperature:.7,maxTokens:2e4,timeout:3e5,...e}}async chat(e){const t=new AbortController,n=setTimeout(()=>t.abort(),this.config.timeout);try{const i=await fetch(`${this.config.baseURL}/chat/completions`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.config.apiKey}`},body:JSON.stringify({model:this.config.model,messages:e,temperature:this.config.temperature,max_tokens:this.config.maxTokens,stream:!1}),signal:t.signal});if(clearTimeout(n),!i.ok){const r=await i.json().catch(()=>({}));throw new Error(`API请求失败 (${i.status}): ${r.error?.message||r.message||i.statusText}`)}return(await i.json()).choices?.[0]?.message?.content||""}catch(i){throw clearTimeout(n),i.name==="AbortError"?new Error("请求超时,请重试"):i.message.includes("Failed to fetch")?new Error(`网络请求失败,请检查:
|
|
972
972
|
1. 网络连接
|
|
973
973
|
2. API地址是否正确
|
|
974
974
|
3. 是否有CORS限制`):i}}async chatStream(e,t){const n=new AbortController,i=setTimeout(()=>n.abort(),this.config.timeout);try{const s=await fetch(`${this.config.baseURL}/chat/completions`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.config.apiKey}`},body:JSON.stringify({model:this.config.model,messages:e,temperature:this.config.temperature,max_tokens:this.config.maxTokens,stream:!0}),signal:n.signal});if(clearTimeout(i),!s.ok){const h=await s.json().catch(()=>({}));throw new Error(`API请求失败 (${s.status}): ${h.error?.message||h.message||s.statusText}`)}const r=s.body?.getReader();if(!r)throw new Error("无法读取响应流");const a=new TextDecoder;let l="";for(;;){const{done:h,value:c}=await r.read();if(h){t("",!0);break}l+=a.decode(c,{stream:!0});const d=l.split(`
|
|
@@ -1096,7 +1096,7 @@ void main() {
|
|
|
1096
1096
|
|
|
1097
1097
|
gl_FragColor = vec4(color, uOpacity);
|
|
1098
1098
|
}
|
|
1099
|
-
`;class Cd{options;deviceType;animationId=null;isRenderingPaused=!1;controlsEnabledBeforePause=!0;animate;onWindowResize;_fpsFrameCount=0;_fpsLastCheck=0;_fpsLastSwitch=0;_lowFpsCount=0;_highFpsCount=0;_fpsCheckInterval=100;_fpsSwitchCooldown=100;_fpsThreshold=30;_fpsUpgradeThreshold=60;_lowFpsRequired=3;_highFpsRequired=.1;isMouseDown=!1;isWheeling=!1;scene;camera;renderer;sceneModule;cameraModule;deviceModule;renderModule;controlModule;composerModule;loaderModule;engineStatus;events;lightModule;interactionModule;modelToolModule;worldToScreen;handelBehaved;octreeBox;controls;stats;catchSvg;engineModelModule;viewCube;rangeScale;setting;measure;clipping;modelTree;engineInfo;modelProperties;modelMapperBatch;modelEdge;ai;pathRoaming;hoverHighLight;minMap;grid;level;text;hdr;ground;models=[];reactBoundingClientRect={left:0,top:0};version="2.1.2";versionEl=null;container;constructor(e){if(this.options=e,this.container=document.getElementById(e.containerId),!this.container)throw new Error(`Container ${e.containerId} not found`);this.engineModelModule=new Wc(this),this.engineModelModule.init(),this.ai=new pd(this),this.deviceModule=new Go(this),this.deviceType=this.deviceModule.getDeviceType(),this.cameraModule=new jo(this),this.sceneModule=new Vo(this),this.scene=this.sceneModule.scene,this.renderModule=new Wo(this),this.renderer=this.renderModule.createRenderer(),this.camera=this.cameraModule.orthographicCamera,this.scene.camera=this.camera,this.controlModule=new ra(this),this.controlModule.switchDefaultMode(),this.controls=this.controlModule.orbitControls,this.composerModule=new wa(this),this.composerModule.init(),this.events=new Nc,this.engineStatus=new zc(this),this.engineStatus.init(),this.loaderModule=new Oc(this),this.lightModule=new Rc(this),this.lightModule.init(),this.viewCube=new th(this),this.viewCube.init(),this.options.showViewCube==!1&&this.viewCube.hide(),this.octreeBox=nh(this),this.rangeScale=new ih(this),this.rangeScale.init(),this.clipping=new ad(this),this.clipping.init(),this.setting=new sh(this),this.setting.init(),this.engineModelModule.init(),this.handelBehaved=Ci(this),this.modelMapperBatch=new ud(this),this.measure=new fh(this),this.modelToolModule=new Uc(this),this.modelProperties=new hd(this),this.interactionModule=new Fc(this),this.interactionModule.init(),this.interactionModule.active(),this.hoverHighLight=new qn(this),this.modelEdge=new dd(this),this.modelTree=new ld(this),this.engineInfo=new cd(this),this.pathRoaming=new md(this),this.pathRoaming.init(),this.minMap=new gd(this),this.grid=new wd(this),this.level=new vd(this),this.text=new bd(this),this.hdr=new _d(this),this.ground=new Md(this),this.ground.init(),this.worldToScreen=new ze(this.camera,this.renderer,this.scene),this.options.showStats&&(this.stats=new Kc,this.stats.showPanel(0),this.stats.dom.style.position="absolute",this.stats.dom.style.top="0px",this.stats.dom.style.left="0px",this.stats.dom.style.zIndex="1000",this.container.appendChild(this.stats.dom));let t=document.createElement("div");t.className="versionText",this.versionEl=t,this.updateVersionDisplay(),this.container.appendChild(t);let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.style.position="absolute",n.style.zIndex="1000",n.style.left="0px",n.style.top="0px",n.style.pointerEvents="none",this.container.appendChild(n),this.catchSvg=n,this.onWindowResize=()=>{this.handleWindowResize()},window.addEventListener("resize",this.onWindowResize);let i=this;this.controls.addEventListener("start",()=>{i.events.trigger(ut.EngineBusy)}),this.controls.addEventListener("end",()=>{i.events.trigger(ut.EngineFree)}),this.controls.addEventListener("change",()=>{}),this.animate=()=>{if(!this.isRenderingPaused)this.animationId=requestAnimationFrame(this.animate);else{this.animationId=null;return}this.stats&&this.stats.begin(),this.composerModule&&this.composerModule.composer.render(),this.viewCube&&this.viewCube.cubeTool.RenderScene(),this.measure.update(),this.ground.update(),this.hoverHighLight.update(),this.controlModule.update(),this.minMap.update(),this.grid.update(),this.level.update(),this.text&&this.text.update(),this.stats&&this.stats.end(),this._fpsFrameCount++;const s=performance.now();if(s-this._fpsLastCheck>=this._fpsCheckInterval){const r=s-this._fpsLastCheck,a=this._fpsFrameCount/r*1e3;this._fpsFrameCount=0,this._fpsLastCheck=s,a<this._fpsThreshold?(this._lowFpsCount++,this._highFpsCount=0,this._lowFpsCount>=this._lowFpsRequired&&s-this._fpsLastSwitch>this._fpsSwitchCooldown&&(this._adaptiveRenderingDowngrade(),this._fpsLastSwitch=s,this._lowFpsCount=0)):a>this._fpsUpgradeThreshold?(this._highFpsCount++,this._lowFpsCount=0):(this._lowFpsCount=0,this._highFpsCount=0)}if(this.scene){let r=this.scene?.dirLight;r&&this.camera&&this.updateLightPosition(this.camera,r)}},this.animate()}updateVersionDisplay(){if(!this.versionEl)return;const e={simple:"simple",balance:"balance",advanced:"advanced"},t=this.engineModelModule?.getCurrentMode()??"",n=e[t]??t;this.versionEl.innerHTML=`v${this.version} | ${n}`}updateLightPosition(e,t){const n=new S.Vector3;e.getWorldDirection(n);const i=100,s=new S.Vector3().copy(n).multiplyScalar(-i),r=new S.Vector3(0,1,0),a=new S.Vector3().crossVectors(n,r).normalize();s.addScaledVector(r,i*.5),s.addScaledVector(a,i*.3),t.position.copy(e.position).add(s);const l=new S.Vector3().copy(e.position).add(n.multiplyScalar(20));t.target.position.copy(l),t.target.updateMatrixWorld()}_adaptiveRenderingDowngrade(){const e=["simple","balance","advanced"],t=this.engineModelModule.getCurrentMode(),n=e.indexOf(t);if(n>0){const i=e[n-1];console.log(`[AdaptiveRendering] FPS低于${this._fpsThreshold},自动降级: ${t} → ${i}`),this.engineModelModule.autoSwitch(i)}}_adaptiveRenderingUpgrade(){const e=["simple","balance","advanced"],t=this.engineModelModule.getCurrentMode(),n=e.indexOf(t);if(n<e.length-1){const i=e[n+1];console.log(`[AdaptiveRendering] FPS高于${this._fpsUpgradeThreshold},自动升级: ${t} → ${i}`),this.engineModelModule.autoSwitch(i)}}pauseRendering(){if(this.isRenderingPaused){console.warn("[BimEngine] Rendering is already paused");return}this.isRenderingPaused=!0,this.controls&&(this.controlsEnabledBeforePause=this.controls.enabled,this.controls.enabled=!1)}resumeRendering(){if(!this.isRenderingPaused){console.warn("[BimEngine] Rendering is not paused");return}this.isRenderingPaused=!1,this.controls&&(this.controls.enabled=this.controlsEnabledBeforePause),this.animationId===null&&this.animate()}isRenderingPausedState(){return this.isRenderingPaused}handleWindowResize(e,t){if(!this.container||!this.renderer||!this.camera)return;if(e===void 0||t===void 0){const i=this.deviceModule.getContainerSize();e=e??i.width,t=t??i.height}if(!e||!t)return;this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(e,t);const n=e/t;if(this.camera===this.cameraModule.perspectiveCamera)this.cameraModule.perspectiveCamera.aspect=n,this.cameraModule.perspectiveCamera.updateProjectionMatrix(),this.camera=this.cameraModule.perspectiveCamera;else if(this.camera===this.cameraModule.orthographicCamera){const i=this.cameraModule.orthographicCamera,s=50,r=this.container.clientWidth/this.container.clientHeight;i.left=s*r/-2,i.right=s*r/2,i.top=s/2,i.bottom=s/-2,i.updateProjectionMatrix()}if(this.catchSvg){const i=this.container.clientWidth,s=this.container.clientHeight;this.catchSvg.setAttribute("viewBox",`0 0 ${i} ${s}`)}this.events&&this.events.trigger(ut.ViewportResize,{width:e,height:t})}dispose(){console.log("[BimEngine] Starting engine disposal..."),this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null),this.isRenderingPaused=!0,this.onWindowResize&&window.removeEventListener("resize",this.onWindowResize);try{this.measure&&(this.measure.disActive(),this.measure.clearAll(),this.measure.annotationContainer&&this.measure.annotationContainer.remove()),this.hdr&&this.hdr.dispose(),this.minMap&&this.minMap.dispose(),this.text&&this.text.dispose(),this.clipping&&this.clipping.disActive(),this.interactionModule&&this.interactionModule.disActive(),this.viewCube&&this.viewCube.cubeTool&&typeof this.viewCube.cubeTool.dispose=="function"&&this.viewCube.cubeTool.dispose()}catch(e){console.warn("[BimEngine] Error disposing managers:",e)}try{this.controlModule&&(this.controlModule.originDiv&&this.controlModule.originDiv.remove(),this.controlModule.orbitControls&&typeof this.controlModule.orbitControls.dispose=="function"&&this.controlModule.orbitControls.dispose(),this.controlModule.firstPersonControls&&typeof this.controlModule.firstPersonControls.dispose=="function"&&this.controlModule.firstPersonControls.dispose())}catch(e){console.warn("[BimEngine] Error disposing controls:",e)}this.scene&&this.clearScene(this.scene);try{this.composerModule&&this.composerModule.composer&&(this.composerModule.composer.passes&&this.composerModule.composer.passes.forEach(e=>{e.dispose&&e.dispose()}),this.composerModule.composer.renderTarget1&&this.composerModule.composer.renderTarget1.dispose(),this.composerModule.composer.renderTarget2&&this.composerModule.composer.renderTarget2.dispose())}catch(e){console.warn("[BimEngine] Error disposing composer:",e)}try{this.renderModule&&this.renderModule.disposeRenderer(),this.renderer&&(this.renderer.domElement&&this.renderer.domElement.parentElement&&this.renderer.domElement.parentElement.removeChild(this.renderer.domElement),this.renderer.dispose(),this.renderer.forceContextLoss())}catch(e){console.warn("[BimEngine] Error disposing renderer:",e)}try{this.stats&&this.stats.dom&&this.stats.dom.parentElement&&this.stats.dom.parentElement.removeChild(this.stats.dom),this.catchSvg&&this.catchSvg.parentElement&&this.catchSvg.parentElement.removeChild(this.catchSvg)}catch(e){console.warn("[BimEngine] Error disposing DOM elements:",e)}try{this.events&&this.events.listeners&&this.events.listeners.clear()}catch(e){console.warn("[BimEngine] Error clearing event listeners:",e)}this.scene=null,this.camera=null,this.renderer=null,this.controls=null,this.models=[],this.container=null,console.log("[BimEngine] Engine disposal completed")}clearScene(e){if(!e)return;[...e.children].forEach(n=>{this.clearScene(n)}),e.parent&&e.parent.remove(e),e instanceof S.Mesh&&(e.geometry&&e.geometry.dispose(),e.material&&(Array.isArray(e.material)?e.material.forEach(n=>this.disposeMaterial(n)):this.disposeMaterial(e.material))),e instanceof S.Line&&(e.geometry&&e.geometry.dispose(),e.material&&this.disposeMaterial(e.material)),e instanceof S.Points&&(e.geometry&&e.geometry.dispose(),e.material&&this.disposeMaterial(e.material)),e instanceof S.InstancedMesh&&(e.geometry&&e.geometry.dispose(),e.material&&(Array.isArray(e.material)?e.material.forEach(n=>this.disposeMaterial(n)):this.disposeMaterial(e.material)),e.instanceMatrix&&(e.instanceMatrix=null),e.instanceColor&&(e.instanceColor=null)),e instanceof S.Sprite&&e.material&&this.disposeMaterial(e.material)}disposeMaterial(e){if(!e)return;["map","lightMap","bumpMap","normalMap","specularMap","envMap","alphaMap","aoMap","displacementMap","emissiveMap","gradientMap","metalnessMap","roughnessMap","clearcoatMap","clearcoatNormalMap","clearcoatRoughnessMap","transmissionMap","thicknessMap","sheenColorMap","sheenRoughnessMap","specularIntensityMap","specularColorMap","iridescenceMap","iridescenceThicknessMap"].forEach(n=>{const i=e[n];i&&i instanceof S.Texture&&i.dispose()}),e.dispose()}}function Td(o){return new Cd(o)}const Pd=Object.freeze(Object.defineProperty({__proto__:null,default:`# BIM引擎AI助手 - 需求分析与步骤规划专家\r
|
|
1099
|
+
`;class Cd{options;deviceType;animationId=null;isRenderingPaused=!1;controlsEnabledBeforePause=!0;animate;onWindowResize;_fpsFrameCount=0;_fpsLastCheck=0;_fpsLastSwitch=0;_lowFpsCount=0;_highFpsCount=0;_fpsCheckInterval=100;_fpsSwitchCooldown=100;_fpsThreshold=30;_fpsUpgradeThreshold=60;_lowFpsRequired=3;_highFpsRequired=.1;isMouseDown=!1;isWheeling=!1;scene;camera;renderer;sceneModule;cameraModule;deviceModule;renderModule;controlModule;composerModule;loaderModule;engineStatus;events;lightModule;interactionModule;modelToolModule;worldToScreen;handelBehaved;octreeBox;controls;stats;catchSvg;engineModelModule;viewCube;rangeScale;setting;measure;clipping;modelTree;engineInfo;modelProperties;modelMapperBatch;modelEdge;ai;pathRoaming;hoverHighLight;minMap;grid;level;text;hdr;ground;models=[];reactBoundingClientRect={left:0,top:0};version="2.1.3";versionEl=null;container;constructor(e){if(this.options=e,this.container=document.getElementById(e.containerId),!this.container)throw new Error(`Container ${e.containerId} not found`);this.engineModelModule=new Wc(this),this.engineModelModule.init(),this.ai=new pd(this),this.deviceModule=new Go(this),this.deviceType=this.deviceModule.getDeviceType(),this.cameraModule=new jo(this),this.sceneModule=new Vo(this),this.scene=this.sceneModule.scene,this.renderModule=new Wo(this),this.renderer=this.renderModule.createRenderer(),this.camera=this.cameraModule.orthographicCamera,this.scene.camera=this.camera,this.controlModule=new ra(this),this.controlModule.switchDefaultMode(),this.controls=this.controlModule.orbitControls,this.composerModule=new wa(this),this.composerModule.init(),this.events=new Nc,this.engineStatus=new zc(this),this.engineStatus.init(),this.loaderModule=new Oc(this),this.lightModule=new Rc(this),this.lightModule.init(),this.viewCube=new th(this),this.viewCube.init(),this.options.showViewCube==!1&&this.viewCube.hide(),this.octreeBox=nh(this),this.rangeScale=new ih(this),this.rangeScale.init(),this.clipping=new ad(this),this.clipping.init(),this.setting=new sh(this),this.setting.init(),this.engineModelModule.init(),this.handelBehaved=Ci(this),this.modelMapperBatch=new ud(this),this.measure=new fh(this),this.modelToolModule=new Uc(this),this.modelProperties=new hd(this),this.interactionModule=new Fc(this),this.interactionModule.init(),this.interactionModule.active(),this.hoverHighLight=new qn(this),this.modelEdge=new dd(this),this.modelTree=new ld(this),this.engineInfo=new cd(this),this.pathRoaming=new md(this),this.pathRoaming.init(),this.minMap=new gd(this),this.grid=new wd(this),this.level=new vd(this),this.text=new bd(this),this.hdr=new _d(this),this.ground=new Md(this),this.ground.init(),this.worldToScreen=new ze(this.camera,this.renderer,this.scene),this.options.showStats&&(this.stats=new Kc,this.stats.showPanel(0),this.stats.dom.style.position="absolute",this.stats.dom.style.top="0px",this.stats.dom.style.left="0px",this.stats.dom.style.zIndex="1000",this.container.appendChild(this.stats.dom));let t=document.createElement("div");t.className="versionText",this.versionEl=t,this.updateVersionDisplay(),this.container.appendChild(t);let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.style.position="absolute",n.style.zIndex="1000",n.style.left="0px",n.style.top="0px",n.style.pointerEvents="none",this.container.appendChild(n),this.catchSvg=n,this.onWindowResize=()=>{this.handleWindowResize()},window.addEventListener("resize",this.onWindowResize);let i=this;this.controls.addEventListener("start",()=>{i.events.trigger(ut.EngineBusy)}),this.controls.addEventListener("end",()=>{i.events.trigger(ut.EngineFree)}),this.controls.addEventListener("change",()=>{}),this.animate=()=>{if(!this.isRenderingPaused)this.animationId=requestAnimationFrame(this.animate);else{this.animationId=null;return}this.stats&&this.stats.begin(),this.composerModule&&this.composerModule.composer.render(),this.viewCube&&this.viewCube.cubeTool.RenderScene(),this.measure.update(),this.ground.update(),this.hoverHighLight.update(),this.controlModule.update(),this.minMap.update(),this.grid.update(),this.level.update(),this.text&&this.text.update(),this.stats&&this.stats.end(),this._fpsFrameCount++;const s=performance.now();if(s-this._fpsLastCheck>=this._fpsCheckInterval){const r=s-this._fpsLastCheck,a=this._fpsFrameCount/r*1e3;this._fpsFrameCount=0,this._fpsLastCheck=s,a<this._fpsThreshold?(this._lowFpsCount++,this._highFpsCount=0,this._lowFpsCount>=this._lowFpsRequired&&s-this._fpsLastSwitch>this._fpsSwitchCooldown&&(this._adaptiveRenderingDowngrade(),this._fpsLastSwitch=s,this._lowFpsCount=0)):a>this._fpsUpgradeThreshold?(this._highFpsCount++,this._lowFpsCount=0):(this._lowFpsCount=0,this._highFpsCount=0)}if(this.scene){let r=this.scene?.dirLight;r&&this.camera&&this.updateLightPosition(this.camera,r)}},this.animate()}updateVersionDisplay(){if(!this.versionEl)return;const e={simple:"simple",balance:"balance",advanced:"advanced"},t=this.engineModelModule?.getCurrentMode()??"",n=e[t]??t;this.versionEl.innerHTML=`v${this.version} | ${n}`}updateLightPosition(e,t){const n=new S.Vector3;e.getWorldDirection(n);const i=100,s=new S.Vector3().copy(n).multiplyScalar(-i),r=new S.Vector3(0,1,0),a=new S.Vector3().crossVectors(n,r).normalize();s.addScaledVector(r,i*.5),s.addScaledVector(a,i*.3),t.position.copy(e.position).add(s);const l=new S.Vector3().copy(e.position).add(n.multiplyScalar(20));t.target.position.copy(l),t.target.updateMatrixWorld()}_adaptiveRenderingDowngrade(){const e=["simple","balance","advanced"],t=this.engineModelModule.getCurrentMode(),n=e.indexOf(t);if(n>0){const i=e[n-1];console.log(`[AdaptiveRendering] FPS低于${this._fpsThreshold},自动降级: ${t} → ${i}`),this.engineModelModule.autoSwitch(i)}}_adaptiveRenderingUpgrade(){const e=["simple","balance","advanced"],t=this.engineModelModule.getCurrentMode(),n=e.indexOf(t);if(n<e.length-1){const i=e[n+1];console.log(`[AdaptiveRendering] FPS高于${this._fpsUpgradeThreshold},自动升级: ${t} → ${i}`),this.engineModelModule.autoSwitch(i)}}pauseRendering(){if(this.isRenderingPaused){console.warn("[BimEngine] Rendering is already paused");return}this.isRenderingPaused=!0,this.controls&&(this.controlsEnabledBeforePause=this.controls.enabled,this.controls.enabled=!1)}resumeRendering(){if(!this.isRenderingPaused){console.warn("[BimEngine] Rendering is not paused");return}this.isRenderingPaused=!1,this.controls&&(this.controls.enabled=this.controlsEnabledBeforePause),this.animationId===null&&this.animate()}isRenderingPausedState(){return this.isRenderingPaused}handleWindowResize(e,t){if(!this.container||!this.renderer||!this.camera)return;if(e===void 0||t===void 0){const i=this.deviceModule.getContainerSize();e=e??i.width,t=t??i.height}if(!e||!t)return;this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(e,t);const n=e/t;if(this.camera===this.cameraModule.perspectiveCamera)this.cameraModule.perspectiveCamera.aspect=n,this.cameraModule.perspectiveCamera.updateProjectionMatrix(),this.camera=this.cameraModule.perspectiveCamera;else if(this.camera===this.cameraModule.orthographicCamera){const i=this.cameraModule.orthographicCamera,s=50,r=this.container.clientWidth/this.container.clientHeight;i.left=s*r/-2,i.right=s*r/2,i.top=s/2,i.bottom=s/-2,i.updateProjectionMatrix()}if(this.catchSvg){const i=this.container.clientWidth,s=this.container.clientHeight;this.catchSvg.setAttribute("viewBox",`0 0 ${i} ${s}`)}this.events&&this.events.trigger(ut.ViewportResize,{width:e,height:t})}dispose(){console.log("[BimEngine] Starting engine disposal..."),this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null),this.isRenderingPaused=!0,this.onWindowResize&&window.removeEventListener("resize",this.onWindowResize);try{this.measure&&(this.measure.disActive(),this.measure.clearAll(),this.measure.annotationContainer&&this.measure.annotationContainer.remove()),this.hdr&&this.hdr.dispose(),this.minMap&&this.minMap.dispose(),this.text&&this.text.dispose(),this.clipping&&this.clipping.disActive(),this.interactionModule&&this.interactionModule.disActive(),this.viewCube&&this.viewCube.cubeTool&&typeof this.viewCube.cubeTool.dispose=="function"&&this.viewCube.cubeTool.dispose()}catch(e){console.warn("[BimEngine] Error disposing managers:",e)}try{this.controlModule&&(this.controlModule.originDiv&&this.controlModule.originDiv.remove(),this.controlModule.orbitControls&&typeof this.controlModule.orbitControls.dispose=="function"&&this.controlModule.orbitControls.dispose(),this.controlModule.firstPersonControls&&typeof this.controlModule.firstPersonControls.dispose=="function"&&this.controlModule.firstPersonControls.dispose())}catch(e){console.warn("[BimEngine] Error disposing controls:",e)}this.scene&&this.clearScene(this.scene);try{this.composerModule&&this.composerModule.composer&&(this.composerModule.composer.passes&&this.composerModule.composer.passes.forEach(e=>{e.dispose&&e.dispose()}),this.composerModule.composer.renderTarget1&&this.composerModule.composer.renderTarget1.dispose(),this.composerModule.composer.renderTarget2&&this.composerModule.composer.renderTarget2.dispose())}catch(e){console.warn("[BimEngine] Error disposing composer:",e)}try{this.renderModule&&this.renderModule.disposeRenderer(),this.renderer&&(this.renderer.domElement&&this.renderer.domElement.parentElement&&this.renderer.domElement.parentElement.removeChild(this.renderer.domElement),this.renderer.dispose(),this.renderer.forceContextLoss())}catch(e){console.warn("[BimEngine] Error disposing renderer:",e)}try{this.stats&&this.stats.dom&&this.stats.dom.parentElement&&this.stats.dom.parentElement.removeChild(this.stats.dom),this.catchSvg&&this.catchSvg.parentElement&&this.catchSvg.parentElement.removeChild(this.catchSvg)}catch(e){console.warn("[BimEngine] Error disposing DOM elements:",e)}try{this.events&&this.events.listeners&&this.events.listeners.clear()}catch(e){console.warn("[BimEngine] Error clearing event listeners:",e)}this.scene=null,this.camera=null,this.renderer=null,this.controls=null,this.models=[],this.container=null,console.log("[BimEngine] Engine disposal completed")}clearScene(e){if(!e)return;[...e.children].forEach(n=>{this.clearScene(n)}),e.parent&&e.parent.remove(e),e instanceof S.Mesh&&(e.geometry&&e.geometry.dispose(),e.material&&(Array.isArray(e.material)?e.material.forEach(n=>this.disposeMaterial(n)):this.disposeMaterial(e.material))),e instanceof S.Line&&(e.geometry&&e.geometry.dispose(),e.material&&this.disposeMaterial(e.material)),e instanceof S.Points&&(e.geometry&&e.geometry.dispose(),e.material&&this.disposeMaterial(e.material)),e instanceof S.InstancedMesh&&(e.geometry&&e.geometry.dispose(),e.material&&(Array.isArray(e.material)?e.material.forEach(n=>this.disposeMaterial(n)):this.disposeMaterial(e.material)),e.instanceMatrix&&(e.instanceMatrix=null),e.instanceColor&&(e.instanceColor=null)),e instanceof S.Sprite&&e.material&&this.disposeMaterial(e.material)}disposeMaterial(e){if(!e)return;["map","lightMap","bumpMap","normalMap","specularMap","envMap","alphaMap","aoMap","displacementMap","emissiveMap","gradientMap","metalnessMap","roughnessMap","clearcoatMap","clearcoatNormalMap","clearcoatRoughnessMap","transmissionMap","thicknessMap","sheenColorMap","sheenRoughnessMap","specularIntensityMap","specularColorMap","iridescenceMap","iridescenceThicknessMap"].forEach(n=>{const i=e[n];i&&i instanceof S.Texture&&i.dispose()}),e.dispose()}}function Td(o){return new Cd(o)}const Pd=Object.freeze(Object.defineProperty({__proto__:null,default:`# BIM引擎AI助手 - 需求分析与步骤规划专家\r
|
|
1100
1100
|
\r
|
|
1101
1101
|
## 角色定位\r
|
|
1102
1102
|
\r
|