@selvajs/compute 3.1.0-beta.16 → 3.1.0-beta.18

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.
@@ -1,11 +1,11 @@
1
- import{a as _n,b as re,c as Te,d as Re,e as P,j as bt}from"./chunk-Y3M7P3BW.js";var zn={};_n(zn,{CONCRETE_MATERIAL:()=>xt,EMISSIVE_MATERIAL:()=>Tt,GLASS_MATERIAL:()=>wt,METAL_MATERIAL:()=>Rt,PLASTIC_MATERIAL:()=>vt,RUBBER_MATERIAL:()=>Mt,SHARED_MATERIALS:()=>Ye,WOOD_MATERIAL:()=>Ht});import*as z from"three";var Tt=new z.MeshPhysicalMaterial({color:0,emissive:new z.Color(16777215),emissiveIntensity:5,metalness:0,roughness:.2,clearcoat:.3,clearcoatRoughness:.2,depthWrite:!0,depthTest:!0,transparent:!1,alphaTest:0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1,side:z.FrontSide,dithering:!0}),Rt=new z.MeshPhysicalMaterial({color:new z.Color(0),metalness:.9,roughness:.3,envMapIntensity:1.2,clearcoat:.3,clearcoatRoughness:.2,reflectivity:1,ior:2.5,thickness:1,depthWrite:!0,transparent:!1,alphaTest:0,depthTest:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1,side:z.FrontSide,dithering:!0}),xt=new z.MeshPhysicalMaterial({color:new z.Color(13421772),metalness:0,roughness:.92,envMapIntensity:.15,clearcoat:.05,clearcoatRoughness:.9,reflectivity:.15,transmission:0,ior:1.45,thickness:0,depthWrite:!0,transparent:!1,alphaTest:0,depthTest:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1,side:z.FrontSide,dithering:!0}),vt=new z.MeshPhysicalMaterial({color:new z.Color(16777215),metalness:0,roughness:.3,envMapIntensity:.5,clearcoat:.5,clearcoatRoughness:.1,reflectivity:.5,ior:1.4,transmission:0,transparent:!1,depthWrite:!0,side:z.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),wt=new z.MeshPhysicalMaterial({color:new z.Color(16777215),metalness:0,roughness:0,transmission:.95,transparent:!0,depthWrite:!1,envMapIntensity:1,clearcoat:1,clearcoatRoughness:0,ior:1.52,reflectivity:.9,thickness:1,side:z.DoubleSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Mt=new z.MeshPhysicalMaterial({color:new z.Color(1710618),metalness:0,roughness:.9,envMapIntensity:.2,clearcoat:.1,clearcoatRoughness:.8,reflectivity:.2,ior:1.3,transmission:0,depthWrite:!0,side:z.FrontSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Ht=new z.MeshPhysicalMaterial({color:new z.Color(8934707),metalness:0,roughness:.7,envMapIntensity:.3,clearcoat:.3,clearcoatRoughness:.4,reflectivity:.3,ior:1.3,transmission:0,depthWrite:!0,side:z.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Ye=new Set([Tt,Rt,xt,vt,wt,Mt,Ht]);import*as oe from"three";function we(e){let n=e.clone().normalize(),t=new oe.Vector3(0,0,1),r=new oe.Vector3(0,1,0),a=Math.abs(n.dot(t))>.9?r:t,o=new oe.Vector3().crossVectors(a,n).normalize(),i=new oe.Vector3().crossVectors(n,o).normalize();return{up:n,forward:i,right:o}}function Oe(e,n){let{forward:t,right:r,up:a}=we(e);return t.clone().multiplyScalar(-1).add(r.clone().multiplyScalar(-1)).add(a).normalize().multiplyScalar(n)}function Ct(e,n,t){let{forward:r,right:a,up:o}=we(e);return a.clone().multiplyScalar(n).add(r.clone().multiplyScalar(n)).add(o.clone().multiplyScalar(t))}function At(e){let n=e.clone().normalize(),t=new oe.Vector3(0,1,0);if(n.dot(t)>.9999)return new oe.Euler;if(n.dot(t)<-.9999)return new oe.Euler(Math.PI,0,0);let r=new oe.Quaternion().setFromUnitVectors(t,n);return new oe.Euler().setFromQuaternion(r)}function Xe(e){let n=Math.abs(e.x),t=Math.abs(e.y),r=Math.abs(e.z);return n>=t&&n>=r?"x":t>=r?"y":"z"}import*as $ from"three";var se={HUGE_THRESHOLD:1e4,LARGE_THRESHOLD:1e3,SCALE_RATIO_THRESHOLD:100,NEAR_PLANE_FACTOR:{TINY:1e-4,SMALL:.001,NORMAL:.01},FAR_PLANE_FACTOR:{HUGE:100,LARGE:50,NORMAL:20},INITIAL_DISTANCE_MULTIPLIER:4};function La(e,n,t,r,a){if(Wn(e),n.length===0)return;n.forEach(u=>{e.add(u)});let o=Ke(n),i=o.getCenter(new $.Vector3),l=o.getSize(new $.Vector3),s=Math.max(l.x,l.y,l.z);if(s/Math.min(l.x||1,l.y||1,l.z||1)>se.SCALE_RATIO_THRESHOLD||s>se.HUGE_THRESHOLD?(t.near=s*se.NEAR_PLANE_FACTOR.TINY,t.far=s*se.FAR_PLANE_FACTOR.HUGE):s>se.LARGE_THRESHOLD?(t.near=s*se.NEAR_PLANE_FACTOR.SMALL,t.far=s*se.FAR_PLANE_FACTOR.LARGE):(t.near=Math.max(.01,s*se.NEAR_PLANE_FACTOR.NORMAL),t.far=Math.max(2e3,s*se.FAR_PLANE_FACTOR.NORMAL)),t.updateProjectionMatrix(),!a){let u=s*se.INITIAL_DISTANCE_MULTIPLIER;t.position.copy(i).add(Oe(t.up,u)),r.target.copy(i),r.update()}}function St(e){if(!e||typeof e!="string")return P().warn(`Invalid color input: ${e}, using white`),new $.Color(16777215);let n=e.trim();if(/^#?[0-9A-Fa-f]{6}$/.test(n))try{let r=n.startsWith("#")?n:`#${n}`;return new $.Color(r)}catch{return P().warn(`Invalid hex color: ${e}, using white`),new $.Color(16777215)}if(n.includes(",")){let r=n.split(",").map(a=>parseInt(a.trim(),10));if(r.length===3&&r.every(a=>!isNaN(a)&&a>=0&&a<=255))return new $.Color(r[0]/255,r[1]/255,r[2]/255)}let t=n.toLowerCase();return t in $.Color.NAMES?new $.Color($.Color.NAMES[t]):(P().warn(`Invalid color string: ${e}, using white`),new $.Color(16777215))}function Dt(e,n,t="z"){e.forEach(r=>{r.position[t]-=n})}function Ke(e){let n=new $.Box3;return e.length===0||e.forEach(t=>{t.updateMatrixWorld(!0);let r=new $.Box3().setFromObject(t);n.union(r)}),n}var Gn=new Set(["grid","floor","label-layer","measure"]);function Nn(e){let n=e;for(;n;){if(typeof n.userData.id=="string"&&Gn.has(n.userData.id))return!0;n=n.parent}return!1}function ce(e){e.updateMatrixWorld(!0);let n=new $.Box3;return e.traverse(t=>{let r=t;t.visible&&!Nn(t)&&r.geometry&&n.expandByObject(t)}),n}var jn=new Set(["floor","grid","label-layer"]),Ie="selvaGeometryCache";function Wn(e){[...e.children].forEach(t=>{jn.has(t.userData.id)||t.userData.source!=="user"&&(t.traverse(r=>{let a=r;if(!a.geometry&&!a.material)return;a.geometry?.userData?.[Ie]||a.geometry?.dispose();let o=a.material;if(!o)return;(Array.isArray(o)?o:[o]).forEach(l=>{if(!Ye.has(l)){for(let s of Object.values(l))s instanceof $.Texture&&s.dispose();l.dispose()}})}),t.removeFromParent())})}import*as Ee from"three";function $n(e){let{up:n,forward:t,right:r}=we(e),a=t.clone().negate(),o=r.clone();return{top:n.clone(),bottom:n.clone().negate(),front:a.clone(),back:a.clone().negate(),right:o.clone(),left:o.clone().negate(),iso:a.clone().multiplyScalar(1.2).add(o.clone()).add(n.clone()).normalize()}}function Lt(e){let{scene:n,perspective:t,controls:r,onActiveCameraChange:a}=e,o=(e.up??t.up).clone().normalize(),i=$n(o),l=new Ee.OrthographicCamera(-1,1,1,-1,t.near,t.far);l.up.copy(o);let s="perspective",c=t.aspect,u=()=>s==="perspective"?t:l,d=null,p=()=>{d?.cancel(),d=null},T=()=>{let h=(s==="orthographic"?l:t).position.distanceTo(r.target)*Math.tan(t.fov*Math.PI/360),y=h*c;l.left=-y,l.right=y,l.top=h,l.bottom=-h,l.near=t.near,l.far=t.far,l.updateProjectionMatrix()},v=E=>{if(E!==s){if(p(),E==="orthographic")l.position.copy(t.position),l.up.copy(t.up),l.lookAt(r.target),l.zoom=1,T();else{let h=(l.top-l.bottom)/(2*l.zoom)/Math.tan(t.fov*Math.PI/360),y=l.position.clone().sub(r.target);y.lengthSq()<1e-12&&y.copy(o),y.normalize(),t.position.copy(r.target).add(y.multiplyScalar(h))}s=E,r.object=u(),r.update(),a(u())}},R=(E,f,h,y)=>{let C=t.fov*(Math.PI/180),M=f/(2*Math.tan(C/2))*1.5,L=qn(h,o),I=E.clone().add(L.clone().multiplyScalar(M)),k=u();s==="orthographic"&&(l.zoom=1),p(),y?d=Xn(k,r,I,E,()=>{s==="orthographic"&&T()}):(k.position.copy(I),r.target.copy(E),s==="orthographic"&&T(),r.update())},m=(E,f=!0)=>{let h=ce(n),y=h.isEmpty()?r.target.clone():h.getCenter(new Ee.Vector3),C=h.isEmpty()?new Ee.Vector3(1,1,1):h.getSize(new Ee.Vector3),M=Math.max(C.x,C.y,C.z)||1;R(y,M,E,f)};return{getActiveCamera:u,getProjection:()=>s,setProjection:v,toggleProjection:()=>(v(s==="perspective"?"orthographic":"perspective"),s),setView:(E,f=!0)=>{m(i[E],f)},setViewDirection:m,frameBounds:(E,f=!0)=>{if(E.isEmpty())return;let h=E.getCenter(new Ee.Vector3),y=E.getSize(new Ee.Vector3),C=Math.max(y.x,y.y,y.z)||1,M=u().position.clone().sub(r.target);M.lengthSq()<1e-12&&M.copy(i.iso),R(h,C,M.normalize(),f)},setRotateEnabled:E=>{r.enableRotate=E},isRotateEnabled:()=>r.enableRotate,updateAspect:(E,f)=>{c=f===0?c:E/f,s==="orthographic"&&T()},dispose:p}}function qn(e,n){let{up:t,forward:r}=we(n),a=e.clone().normalize();if(Math.abs(a.dot(t))<.9999)return e;let o=r.clone().negate(),i=.5*Math.PI/180;return a.multiplyScalar(Math.cos(i)).add(o.multiplyScalar(Math.sin(i))).normalize()}var Yn=e=>1-Math.pow(1-e,3);function Xn(e,n,t,r,a,o=250){let i=e.position.clone(),l=n.target.clone(),s=performance.now(),c=null,u=()=>{c=null;let d=Yn(Math.min((performance.now()-s)/o,1));e.position.lerpVectors(i,t,d),n.target.lerpVectors(l,r,d),a(),n.update(),d<1&&(c=requestAnimationFrame(u))};return c=requestAnimationFrame(u),{cancel:()=>{c!==null&&(cancelAnimationFrame(c),c=null)}}}import*as W from"three";function Kn(e){if(!(e>0)||!Number.isFinite(e))return 1;let n=Math.floor(Math.log10(e)),t=Math.pow(10,n),r=e/t;return(r>=5?5:r>=2?2:1)*t}var Zn=`
1
+ import{a as _n,b as re,c as Te,d as Re,e as P,j as bt}from"./chunk-Y3M7P3BW.js";var Vn={};_n(Vn,{CONCRETE_MATERIAL:()=>xt,EMISSIVE_MATERIAL:()=>Tt,GLASS_MATERIAL:()=>wt,METAL_MATERIAL:()=>Rt,PLASTIC_MATERIAL:()=>vt,RUBBER_MATERIAL:()=>Mt,SHARED_MATERIALS:()=>Ye,WOOD_MATERIAL:()=>Ht});import*as z from"three";var Tt=new z.MeshPhysicalMaterial({color:0,emissive:new z.Color(16777215),emissiveIntensity:5,metalness:0,roughness:.2,clearcoat:.3,clearcoatRoughness:.2,depthWrite:!0,depthTest:!0,transparent:!1,alphaTest:0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1,side:z.FrontSide,dithering:!0}),Rt=new z.MeshPhysicalMaterial({color:new z.Color(0),metalness:.9,roughness:.3,envMapIntensity:1.2,clearcoat:.3,clearcoatRoughness:.2,reflectivity:1,ior:2.5,thickness:1,depthWrite:!0,transparent:!1,alphaTest:0,depthTest:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1,side:z.FrontSide,dithering:!0}),xt=new z.MeshPhysicalMaterial({color:new z.Color(13421772),metalness:0,roughness:.92,envMapIntensity:.15,clearcoat:.05,clearcoatRoughness:.9,reflectivity:.15,transmission:0,ior:1.45,thickness:0,depthWrite:!0,transparent:!1,alphaTest:0,depthTest:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1,side:z.FrontSide,dithering:!0}),vt=new z.MeshPhysicalMaterial({color:new z.Color(16777215),metalness:0,roughness:.3,envMapIntensity:.5,clearcoat:.5,clearcoatRoughness:.1,reflectivity:.5,ior:1.4,transmission:0,transparent:!1,depthWrite:!0,side:z.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),wt=new z.MeshPhysicalMaterial({color:new z.Color(16777215),metalness:0,roughness:0,transmission:.95,transparent:!0,depthWrite:!1,envMapIntensity:1,clearcoat:1,clearcoatRoughness:0,ior:1.52,reflectivity:.9,thickness:1,side:z.DoubleSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Mt=new z.MeshPhysicalMaterial({color:new z.Color(1710618),metalness:0,roughness:.9,envMapIntensity:.2,clearcoat:.1,clearcoatRoughness:.8,reflectivity:.2,ior:1.3,transmission:0,depthWrite:!0,side:z.FrontSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Ht=new z.MeshPhysicalMaterial({color:new z.Color(8934707),metalness:0,roughness:.7,envMapIntensity:.3,clearcoat:.3,clearcoatRoughness:.4,reflectivity:.3,ior:1.3,transmission:0,depthWrite:!0,side:z.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Ye=new Set([Tt,Rt,xt,vt,wt,Mt,Ht]);import*as oe from"three";function we(e){let n=e.clone().normalize(),t=new oe.Vector3(0,0,1),r=new oe.Vector3(0,1,0),a=Math.abs(n.dot(t))>.9?r:t,o=new oe.Vector3().crossVectors(a,n).normalize(),i=new oe.Vector3().crossVectors(n,o).normalize();return{up:n,forward:i,right:o}}function Oe(e,n){let{forward:t,right:r,up:a}=we(e);return t.clone().multiplyScalar(-1).add(r.clone().multiplyScalar(-1)).add(a).normalize().multiplyScalar(n)}function Ct(e,n,t){let{forward:r,right:a,up:o}=we(e);return a.clone().multiplyScalar(n).add(r.clone().multiplyScalar(n)).add(o.clone().multiplyScalar(t))}function At(e){let n=e.clone().normalize(),t=new oe.Vector3(0,1,0);if(n.dot(t)>.9999)return new oe.Euler;if(n.dot(t)<-.9999)return new oe.Euler(Math.PI,0,0);let r=new oe.Quaternion().setFromUnitVectors(t,n);return new oe.Euler().setFromQuaternion(r)}function Xe(e){let n=Math.abs(e.x),t=Math.abs(e.y),r=Math.abs(e.z);return n>=t&&n>=r?"x":t>=r?"y":"z"}import*as $ from"three";var se={HUGE_THRESHOLD:1e4,LARGE_THRESHOLD:1e3,SCALE_RATIO_THRESHOLD:100,NEAR_PLANE_FACTOR:{TINY:1e-4,SMALL:.001,NORMAL:.01},FAR_PLANE_FACTOR:{HUGE:100,LARGE:50,NORMAL:20},INITIAL_DISTANCE_MULTIPLIER:4};function Ia(e,n,t,r,a){if(jn(e),n.length===0)return;n.forEach(u=>{e.add(u)});let o=Ke(n),i=o.getCenter(new $.Vector3),l=o.getSize(new $.Vector3),s=Math.max(l.x,l.y,l.z);if(s/Math.min(l.x||1,l.y||1,l.z||1)>se.SCALE_RATIO_THRESHOLD||s>se.HUGE_THRESHOLD?(t.near=s*se.NEAR_PLANE_FACTOR.TINY,t.far=s*se.FAR_PLANE_FACTOR.HUGE):s>se.LARGE_THRESHOLD?(t.near=s*se.NEAR_PLANE_FACTOR.SMALL,t.far=s*se.FAR_PLANE_FACTOR.LARGE):(t.near=Math.max(.01,s*se.NEAR_PLANE_FACTOR.NORMAL),t.far=Math.max(2e3,s*se.FAR_PLANE_FACTOR.NORMAL)),t.updateProjectionMatrix(),!a){let u=s*se.INITIAL_DISTANCE_MULTIPLIER;t.position.copy(i).add(Oe(t.up,u)),r.target.copy(i),r.update()}}function St(e){if(!e||typeof e!="string")return P().warn(`Invalid color input: ${e}, using white`),new $.Color(16777215);let n=e.trim();if(/^#?[0-9A-Fa-f]{6}$/.test(n))try{let r=n.startsWith("#")?n:`#${n}`;return new $.Color(r)}catch{return P().warn(`Invalid hex color: ${e}, using white`),new $.Color(16777215)}if(n.includes(",")){let r=n.split(",").map(a=>parseInt(a.trim(),10));if(r.length===3&&r.every(a=>!isNaN(a)&&a>=0&&a<=255))return new $.Color(r[0]/255,r[1]/255,r[2]/255)}let t=n.toLowerCase();return t in $.Color.NAMES?new $.Color($.Color.NAMES[t]):(P().warn(`Invalid color string: ${e}, using white`),new $.Color(16777215))}function Dt(e,n,t="z"){e.forEach(r=>{r.position[t]-=n})}function Ke(e){let n=new $.Box3;return e.length===0||e.forEach(t=>{t.updateMatrixWorld(!0);let r=new $.Box3().setFromObject(t);n.union(r)}),n}var zn=new Set(["grid","floor","label-layer","measure"]);function Gn(e){let n=e;for(;n;){if(typeof n.userData.id=="string"&&zn.has(n.userData.id))return!0;n=n.parent}return!1}function ce(e){e.updateMatrixWorld(!0);let n=new $.Box3;return e.traverse(t=>{let r=t;t.visible&&!Gn(t)&&r.geometry&&n.expandByObject(t)}),n}var Nn=new Set(["floor","grid","label-layer"]),Ie="selvaGeometryCache";function jn(e){[...e.children].forEach(t=>{Nn.has(t.userData.id)||t.userData.source!=="user"&&(t.traverse(r=>{let a=r;if(!a.geometry&&!a.material)return;a.geometry?.userData?.[Ie]||a.geometry?.dispose();let o=a.material;if(!o)return;(Array.isArray(o)?o:[o]).forEach(l=>{if(!Ye.has(l)){for(let s of Object.values(l))s instanceof $.Texture&&s.dispose();l.dispose()}})}),t.removeFromParent())})}import*as Ee from"three";function Wn(e){let{up:n,forward:t,right:r}=we(e),a=t.clone().negate(),o=r.clone();return{top:n.clone(),bottom:n.clone().negate(),front:a.clone(),back:a.clone().negate(),right:o.clone(),left:o.clone().negate(),iso:a.clone().multiplyScalar(1.2).add(o.clone()).add(n.clone()).normalize()}}function Lt(e){let{scene:n,perspective:t,controls:r,onActiveCameraChange:a}=e,o=(e.up??t.up).clone().normalize(),i=Wn(o),l=new Ee.OrthographicCamera(-1,1,1,-1,t.near,t.far);l.up.copy(o);let s="perspective",c=t.aspect,u=()=>s==="perspective"?t:l,d=null,p=()=>{d?.cancel(),d=null},T=()=>{let h=(s==="orthographic"?l:t).position.distanceTo(r.target)*Math.tan(t.fov*Math.PI/360),y=h*c;l.left=-y,l.right=y,l.top=h,l.bottom=-h,l.near=t.near,l.far=t.far,l.updateProjectionMatrix()},v=E=>{if(E!==s){if(p(),E==="orthographic")l.position.copy(t.position),l.up.copy(t.up),l.lookAt(r.target),l.zoom=1,T();else{let h=(l.top-l.bottom)/(2*l.zoom)/Math.tan(t.fov*Math.PI/360),y=l.position.clone().sub(r.target);y.lengthSq()<1e-12&&y.copy(o),y.normalize(),t.position.copy(r.target).add(y.multiplyScalar(h))}s=E,r.object=u(),r.update(),a(u())}},R=(E,f,h,y)=>{let C=t.fov*(Math.PI/180),M=f/(2*Math.tan(C/2))*1.5,L=$n(h,o),I=E.clone().add(L.clone().multiplyScalar(M)),k=u();s==="orthographic"&&(l.zoom=1),p(),y?d=Yn(k,r,I,E,()=>{s==="orthographic"&&T()}):(k.position.copy(I),r.target.copy(E),s==="orthographic"&&T(),r.update())},m=(E,f=!0)=>{let h=ce(n),y=h.isEmpty()?r.target.clone():h.getCenter(new Ee.Vector3),C=h.isEmpty()?new Ee.Vector3(1,1,1):h.getSize(new Ee.Vector3),M=Math.max(C.x,C.y,C.z)||1;R(y,M,E,f)};return{getActiveCamera:u,getProjection:()=>s,setProjection:v,toggleProjection:()=>(v(s==="perspective"?"orthographic":"perspective"),s),setView:(E,f=!0)=>{m(i[E],f)},setViewDirection:m,frameBounds:(E,f=!0)=>{if(E.isEmpty())return;let h=E.getCenter(new Ee.Vector3),y=E.getSize(new Ee.Vector3),C=Math.max(y.x,y.y,y.z)||1,M=u().position.clone().sub(r.target);M.lengthSq()<1e-12&&M.copy(i.iso),R(h,C,M.normalize(),f)},setRotateEnabled:E=>{r.enableRotate=E},isRotateEnabled:()=>r.enableRotate,updateAspect:(E,f)=>{c=f===0?c:E/f,s==="orthographic"&&T()},dispose:p}}function $n(e,n){let{up:t,forward:r}=we(n),a=e.clone().normalize();if(Math.abs(a.dot(t))<.9999)return e;let o=r.clone().negate(),i=.5*Math.PI/180;return a.multiplyScalar(Math.cos(i)).add(o.multiplyScalar(Math.sin(i))).normalize()}var qn=e=>1-Math.pow(1-e,3);function Yn(e,n,t,r,a,o=250){let i=e.position.clone(),l=n.target.clone(),s=performance.now(),c=null,u=()=>{c=null;let d=qn(Math.min((performance.now()-s)/o,1));e.position.lerpVectors(i,t,d),n.target.lerpVectors(l,r,d),a(),n.update(),d<1&&(c=requestAnimationFrame(u))};return c=requestAnimationFrame(u),{cancel:()=>{c!==null&&(cancelAnimationFrame(c),c=null)}}}import*as W from"three";function Xn(e){if(!(e>0)||!Number.isFinite(e))return 1;let n=Math.floor(Math.log10(e)),t=Math.pow(10,n),r=e/t;return(r>=5?5:r>=2?2:1)*t}var Kn=`
2
2
  varying vec3 vWorldPos;
3
3
  void main() {
4
4
  vec4 world = modelMatrix * vec4(position, 1.0);
5
5
  vWorldPos = world.xyz;
6
6
  gl_Position = projectionMatrix * viewMatrix * world;
7
7
  }
8
- `,Jn=`
8
+ `,Zn=`
9
9
  precision highp float;
10
10
  varying vec3 vWorldPos;
11
11
 
@@ -50,8 +50,8 @@ import{a as _n,b as re,c as Te,d as Re,e as P,j as bt}from"./chunk-Y3M7P3BW.js";
50
50
  if (alpha < 0.001) discard;
51
51
  gl_FragColor = vec4(color, alpha);
52
52
  }
53
- `;function Ot(e={}){let{cellSize:n=1,majorEvery:t=10,cellColor:r=8947848,majorColor:a=4473924,fadeDistance:o=100,plane:i="y"}=e,l=i==="y"?new W.Vector2(0,2):i==="z"?new W.Vector2(0,1):new W.Vector2(1,2),s=2.5,c=new W.PlaneGeometry(1,1);i==="y"?c.rotateX(-Math.PI/2):i==="x"&&c.rotateY(Math.PI/2);let u=new W.ShaderMaterial({vertexShader:Zn,fragmentShader:Jn,transparent:!0,depthWrite:!1,side:W.DoubleSide,uniforms:{uAxes:{value:l},uCell:{value:n},uMajor:{value:t},uCellColor:{value:new W.Color(r)},uMajorColor:{value:new W.Color(a)},uCenter:{value:new W.Vector3},uFade:{value:o}}}),d=new W.Mesh(c,u);d.name="grid",d.userData.id="grid",d.renderOrder=-1;let p=o,T=o*s,v=new W.Vector3;return{object:d,update:R=>{i==="y"?(d.position.set(R.x,0,R.z),v.set(R.x,0,R.z)):i==="z"?(d.position.set(R.x,R.y,0),v.set(R.x,R.y,0)):(d.position.set(0,R.y,R.z),v.set(0,R.y,R.z)),u.uniforms.uCenter.value.copy(v),d.scale.setScalar(T)},fitToContent:R=>{if(R.isEmpty())return;let m=R.getSize(new W.Vector3),g=(H,E)=>E===0?H.x:E===1?H.y:H.z,b=Math.max(g(m,l.x),g(m,l.y));if(!(b>0)||!Number.isFinite(b))return;let x=20;u.uniforms.uCell.value=Kn(b/x),p=b*2,u.uniforms.uFade.value=p,T=p*s},setVisible:R=>{d.visible=R},dispose:()=>{d.removeFromParent(),c.dispose(),u.dispose()}}}import*as J from"three";import{ViewHelper as Qn}from"three/addons/helpers/ViewHelper.js";function It(e){let{camera:n,domElement:t,controller:r}=e,a=new Qn(n,t);a.setLabels("X","Y","Z");let o=!0,i=128,l=new J.Raycaster,s=new J.OrthographicCamera(-2,2,2,-2,0,4);s.position.set(0,0,2),s.updateMatrixWorld();let c={posX:new J.Vector3(1,0,0),negX:new J.Vector3(-1,0,0),posY:new J.Vector3(0,1,0),negY:new J.Vector3(0,-1,0),posZ:new J.Vector3(0,0,1),negZ:new J.Vector3(0,0,-1)},u=p=>{let T=t.getBoundingClientRect(),v=T.left+t.offsetWidth-i-a.location.right,R=T.top+t.offsetHeight-i-a.location.bottom,m=new J.Vector2((p.clientX-v)/i*2-1,-((p.clientY-R)/i)*2+1);if(Math.abs(m.x)>1||Math.abs(m.y)>1)return null;a.quaternion.copy(n.quaternion).invert(),a.updateMatrixWorld(),l.setFromCamera(m,s);let g=l.intersectObjects(a.children,!1);for(let b of g){let x=b.object.userData?.type;if(typeof x=="string"&&x in c)return x}return null};return{render:p=>{if(!o)return;let T=p.autoClear;p.autoClear=!1,a.render(p),p.autoClear=T},update:()=>{},handleClick:p=>{if(!o)return!1;let T=u(p);return T?(r.getProjection()==="orthographic"&&r.setProjection("perspective"),r.setViewDirection(c[T],!1),!0):!1},isAnimating:!1,setVisible:p=>{o=p},isVisible:()=>o,dispose:()=>a.dispose()}}import*as Z from"three";import{LineSegmentsGeometry as tr}from"three/addons/lines/LineSegmentsGeometry.js";import{LineSegments2 as nt}from"three/addons/lines/LineSegments2.js";import{LineMaterial as nr}from"three/addons/lines/LineMaterial.js";function Pe(e,n,t){let o=Math.cos(Math.PI/180*t),i=e.length/3;if(i>=67108864)throw new Error(`extractEdgeSegments: ${i} vertices exceeds 2^26 limit`);let l=new Float64Array(i),s=new Float64Array(i),c=new Float64Array(i);for(let f=0;f<i;f++)l[f]=Math.round(e[3*f]*1e4),s[f]=Math.round(e[3*f+1]*1e4),c[f]=Math.round(e[3*f+2]*1e4);let u=16;for(;u<i*2;)u<<=1;let d=u-1,p=new Int32Array(u).fill(-1),T=new Int32Array(i);for(let f=0;f<i;f++){let h=(Math.imul(l[f]|0,73856093)^Math.imul(s[f]|0,19349663)^Math.imul(c[f]|0,83492791))&d;for(;;){let y=p[h];if(y===-1){p[h]=f,T[f]=f;break}if(l[y]===l[f]&&s[y]===s[f]&&c[y]===c[f]){T[f]=y;break}h=h+1&d}}let v=new Float32Array(4096),R=0,m=(f,h)=>{if(R+6>v.length){let y=new Float32Array(v.length*2);y.set(v),v=y}v[R++]=e[3*f],v[R++]=e[3*f+1],v[R++]=e[3*f+2],v[R++]=e[3*h],v[R++]=e[3*h+1],v[R++]=e[3*h+2]},g=new Map,b=[],x=[],H=[],E=(n?n.length:i)/3;for(let f=0;f<E;f++){let h=n?n[3*f]:3*f,y=n?n[3*f+1]:3*f+1,C=n?n[3*f+2]:3*f+2,M=T[h],L=T[y],I=T[C];if(M===L||L===I||I===M)continue;let k=e[3*C]-e[3*y],O=e[3*C+1]-e[3*y+1],F=e[3*C+2]-e[3*y+2],S=e[3*h]-e[3*y],D=e[3*h+1]-e[3*y+1],G=e[3*h+2]-e[3*y+2],_=O*G-F*D,q=F*S-k*G,Y=k*D-O*S,fe=_*_+q*q+Y*Y;if(fe>0){let ee=1/Math.sqrt(fe);_*=ee,q*=ee,Y*=ee}else _=0,q=0,Y=0;for(let ee=0;ee<3;ee++){let pe,j,te,ne;ee===0?(pe=h,j=y,te=M,ne=L):ee===1?(pe=y,j=C,te=L,ne=I):(pe=C,j=h,te=I,ne=M);let xe=ne*67108864+te,he=g.get(xe);if(he!==void 0&&he!==-1)_*H[3*he]+q*H[3*he+1]+Y*H[3*he+2]<=o&&m(pe,j),g.set(xe,-1);else{let ie=te*67108864+ne;if(!g.has(ie)){let ve=b.length;g.set(ie,ve),b.push(pe),x.push(j),H.push(_,q,Y)}}}}for(let f of g.values())f!==-1&&m(b[f],x[f]);return v.slice(0,R)}function Pt(){return[`const extract = ${Pe.toString()};`,"self.onmessage = (event) => {"," const { id, positions, index, thresholdAngle } = event.data;"," try {"," const segments = extract(positions, index, thresholdAngle);"," self.postMessage({ id, segments }, [segments.buffer]);"," } catch (error) {"," self.postMessage({ id, error: String((error && error.message) || error) });"," }","};"].join(`
54
- `)}var He="edge-overlay",rt="triangle-cap",rr=2236962,or=1.5,ar=44,ir=.75,sr=4e6,lr=2e6,cr=25e3,Ft=128*1024*1024,ur=80,Bt=20,dr=1,mr=2;function Ut(e,n){let t=Array.isArray(e.material)?e.material:[e.material];for(let r of t)r&&(r.polygonOffset=n,r.polygonOffsetFactor=n?dr:0,r.polygonOffsetUnits=n?mr:0)}function Je(e){let n=e.getAttribute("position");return n?(e.index?e.index.count:n.count)/3:0}function Vt(e){let n=e.getAttribute("position");if(!n||n.isInterleavedBufferAttribute||n.itemSize!==3||!(n.array instanceof Float32Array)||n.count>=67108864)return null;let t=e.index;return t&&!(t.array instanceof Uint32Array)&&!(t.array instanceof Uint16Array)?null:{positions:n.array,index:t?t.array:null}}function _t(e,n){let r=2166136261,a=s=>{r^=s,r=Math.imul(r,16777619)},o=new Uint32Array(e.positions.buffer,e.positions.byteOffset,e.positions.length),i=Math.min(4096,o.length);for(let s=0;s<i;s++)a(o[s]);for(let s=Math.max(i,o.length-4096);s<o.length;s++)a(o[s]);let l=0;if(e.index){l=e.index.length;let s=Math.min(4096,l);for(let c=0;c<s;c++)a(e.index[c]);for(let c=Math.max(s,l-4096);c<l;c++)a(e.index[c])}return`${n}:${e.positions.length}:${l}:${r>>>0}`}var ue=new Map,Fe=0;function zt(e){let n=ue.get(e);return n&&(ue.delete(e),ue.set(e,n)),n}function Gt(e,n){if(n.byteLength>Ft)return;let t=ue.get(e);for(t&&(Fe-=t.byteLength,ue.delete(e)),ue.set(e,n),Fe+=n.byteLength;Fe>Ft;){let r=ue.keys().next().value;Fe-=ue.get(r).byteLength,ue.delete(r)}}function fr(e,n){let t=new Z.EdgesGeometry(e,n),r=t.attributes.position?t.attributes.position.array:new Float32Array(0);return t.dispose(),r}function Qe(e,n){let t=Vt(e);if(!t)return fr(e,n);let r=_t(t,n),a=zt(r);if(a)return a;let o=Pe(t.positions,t.index,n);return Gt(r,o),o}var ye,Me=new Map,pr=1;function Er(){if(ye!==void 0)return ye;if(typeof Worker>"u"||typeof Blob>"u"||typeof URL>"u"||typeof URL.createObjectURL!="function")return ye=null,null;try{let e=URL.createObjectURL(new Blob([Pt()],{type:"text/javascript"})),n=new Worker(e);n.onmessage=t=>{let{id:r,segments:a,error:o}=t.data,i=Me.get(r);i&&(Me.delete(r),a?i.resolve(a):i.reject(new Error(o??"edge extraction failed in worker")))},n.onerror=()=>{for(let t of Me.values())t.reject(new Error("edge extraction worker crashed"));Me.clear(),n.terminate(),ye=null},ye=n}catch{ye=null}return ye}function hr(e,n,t){return new Promise((r,a)=>{let o=pr++;Me.set(o,{resolve:r,reject:a});let i=n.positions.slice(),l=n.index?n.index.slice():null,s=[i.buffer];l&&s.push(l.buffer),e.postMessage({id:o,positions:i,index:l,thresholdAngle:t},s)})}var Ze=new Map;function gr(e,n){let t=Vt(e);if(!t||Je(e)<cr)return Promise.resolve(Qe(e,n));let r=_t(t,n),a=zt(r);if(a)return Promise.resolve(a);let o=Ze.get(r);if(o)return o;let i=Er();if(!i)return Promise.resolve(Qe(e,n));let l=hr(i,t,n).catch(()=>Pe(t.positions,t.index,n)).then(s=>(Gt(r,s),s)).finally(()=>{Ze.delete(r)});return Ze.set(r,l),l}var Be=new WeakMap;function et(e,n){return Be.get(e)?.get(n)}function Nt(e,n,t){let r=Be.get(e);r||(r=new Map,Be.set(e,r));let a=new tr;a.setPositions(t);let o={geometry:a,refCount:0,segmentCount:t.length/6};return r.set(n,o),o}function yr(e){let n=e.userData,t=n.edgeSource&&Be.get(n.edgeSource),r=n.edgeThresholdAngle!=null?t?.get(n.edgeThresholdAngle):void 0;if(!r||r.geometry!==e.geometry){e.geometry.dispose();return}r.refCount-=1,r.refCount<=0&&(r.geometry.dispose(),t.delete(n.edgeThresholdAngle))}function jt(e){return{forcedColor:e.color!=null?new Z.Color(e.color):null,darken:Z.MathUtils.clamp(e.darken??ir,0,1),width:e.width??or,thresholdAngle:e.thresholdAngle??ar,distanceFade:e.distanceFade??!0,maxTriangles:e.maxTriangles??sr,maxSegments:e.maxSegments??lr}}function br(e,n){let r=(Array.isArray(e.material)?e.material[0]:e.material)?.color;return r?r.clone().multiplyScalar(1-n):new Z.Color(rr)}var ke=class{constructor(n){re(this,"options",n);re(this,"byKey",new Map)}for(n,t){let r=this.options.forcedColor??br(n,this.options.darken),a=r.getHex()*2+(t?1:0),o=this.byKey.get(a);return o||(o=Tr(r,this.options.width,t),this.byKey.set(a,o)),o}disposeUnused(n){let t=new Set(n.map(r=>r.material));for(let r of this.byKey.values())t.has(r)||r.dispose()}};function Tr(e,n,t){let r=new nr({color:e});return r.linewidth=n,t&&(r.transparent=!0),r}function Rr(e,n,t,r,a){n.refCount+=1;let o=new nt(n.geometry,t);return o.userData.kind=He,o.userData.edgeSource=e,o.userData.edgeThresholdAngle=r,o.raycast=()=>{},a&&wr(o),o}var kt=new Z.Vector3,xr=new Z.Vector3;function vr(e,n,t){e.geometry.boundingSphere||e.geometry.computeBoundingSphere();let r=e.geometry.boundingSphere;if(!r||r.radius<=0)return 1/0;let a=r.radius*e.matrixWorld.getMaxScaleOnAxis();if(kt.copy(r.center).applyMatrix4(e.matrixWorld),n.isPerspectiveCamera){let o=n,i=xr.setFromMatrixPosition(n.matrixWorld).distanceTo(kt);if(i<=a)return 1/0;let l=Math.tan(Z.MathUtils.degToRad(o.fov)*.5);return a/(i*l)*t}if(n.isOrthographicCamera){let o=n,i=(o.top-o.bottom)/o.zoom;return i>0?2*a/i*t:1/0}return 1/0}function wr(e){e.onBeforeRender=(n,t,r)=>{nt.prototype.onBeforeRender.call(e,n);let a=e.material,o=vr(e,r,a.resolution.y);a.opacity=Z.MathUtils.clamp((o-Bt)/(ur-Bt),0,1)}}function Mr(e){return e.userData?.kind===He}function Wt(e,n){let t=[];return e.traverse(r=>{if(r instanceof Z.Mesh&&!(r.userData.id==="floor"||r.userData.id==="grid")&&r.userData.kind!==He&&!r.children.some(a=>a.userData?.kind===He)&&r.geometry){if(Je(r.geometry)>n){r.userData.edgesSkipped=rt,console.debug(`[edges] skipping mesh over triangle cap (${Je(r.geometry)} > ${n})`);return}delete r.userData.edgesSkipped,t.push(r)}}),t}function $t(e,n,t,r){let a=r.distanceFade&&n.segmentCount<=r.maxSegments,o=Rr(e.geometry,n,t.for(e,a),r.thresholdAngle,a);return e.add(o),Ut(e,!0),o}function ja(e,n={}){let t=jt(n),r=new ke(t),a=[];for(let o of Wt(e,t.maxTriangles)){let i=et(o.geometry,t.thresholdAngle)??Nt(o.geometry,t.thresholdAngle,Qe(o.geometry,t.thresholdAngle));a.push($t(o,i,r,t))}return r.disposeUnused(a),a}var qt=new WeakMap;function tt(e){return qt.get(e)??0}function Hr(e,n){for(let t=e;t;t=t.parent)if(t===n)return!0;return!1}async function Yt(e,n={}){let t=jt(n),r=new ke(t),a=tt(e),o=[],i=Wt(e,t.maxTriangles).map(async l=>{let s=et(l.geometry,t.thresholdAngle);if(!s){let c=await gr(l.geometry,t.thresholdAngle);if(tt(e)!==a||!Hr(l,e)||l.children.some(u=>u.userData?.kind===He))return;s=et(l.geometry,t.thresholdAngle),s||(s=Nt(l.geometry,t.thresholdAngle,c))}o.push($t(l,s,r,t))});return await Promise.all(i),r.disposeUnused(o),o}function Xt(e){qt.set(e,tt(e)+1);let n=[];e.traverse(r=>{r instanceof nt&&Mr(r)&&n.push(r)});let t=new Set;for(let r of n)yr(r),t.add(r.material),r.parent instanceof Z.Mesh&&Ut(r.parent,!1),r.removeFromParent();return t.forEach(r=>r.dispose()),n.length}import*as N from"three";import{Pass as Cr,FullScreenQuad as Ar}from"three/addons/postprocessing/Pass.js";var ot={uniforms:{tDiffuse:{value:null},tNormal:{value:null},tDepth:{value:null},uResolution:{value:new N.Vector2(1,1)},uColor:{value:new N.Color(2236962)},uOpacity:{value:1},uNormalThreshold:{value:.4},uDepthThreshold:{value:.02},uThickness:{value:1},uNear:{value:.1},uFar:{value:1e3},uPerspective:{value:1}},vertexShader:`
53
+ `;function Ot(e={}){let{cellSize:n=1,majorEvery:t=10,cellColor:r=8947848,majorColor:a=4473924,fadeDistance:o=100,plane:i="y"}=e,l=i==="y"?new W.Vector2(0,2):i==="z"?new W.Vector2(0,1):new W.Vector2(1,2),s=2.5,c=new W.PlaneGeometry(1,1);i==="y"?c.rotateX(-Math.PI/2):i==="x"&&c.rotateY(Math.PI/2);let u=new W.ShaderMaterial({vertexShader:Kn,fragmentShader:Zn,transparent:!0,depthWrite:!1,side:W.DoubleSide,uniforms:{uAxes:{value:l},uCell:{value:n},uMajor:{value:t},uCellColor:{value:new W.Color(r)},uMajorColor:{value:new W.Color(a)},uCenter:{value:new W.Vector3},uFade:{value:o}}}),d=new W.Mesh(c,u);d.name="grid",d.userData.id="grid",d.renderOrder=-1;let p=o,T=o*s,v=new W.Vector3;return{object:d,update:R=>{i==="y"?(d.position.set(R.x,0,R.z),v.set(R.x,0,R.z)):i==="z"?(d.position.set(R.x,R.y,0),v.set(R.x,R.y,0)):(d.position.set(0,R.y,R.z),v.set(0,R.y,R.z)),u.uniforms.uCenter.value.copy(v),d.scale.setScalar(T)},fitToContent:R=>{if(R.isEmpty())return;let m=R.getSize(new W.Vector3),g=(H,E)=>E===0?H.x:E===1?H.y:H.z,b=Math.max(g(m,l.x),g(m,l.y));if(!(b>0)||!Number.isFinite(b))return;let x=20;u.uniforms.uCell.value=Xn(b/x),p=b*2,u.uniforms.uFade.value=p,T=p*s},setVisible:R=>{d.visible=R},dispose:()=>{d.removeFromParent(),c.dispose(),u.dispose()}}}import*as J from"three";import{ViewHelper as Jn}from"three/addons/helpers/ViewHelper.js";function It(e){let{camera:n,domElement:t,controller:r}=e,a=new Jn(n,t);a.setLabels("X","Y","Z");let o=!0,i=128,l=new J.Raycaster,s=new J.OrthographicCamera(-2,2,2,-2,0,4);s.position.set(0,0,2),s.updateMatrixWorld();let c={posX:new J.Vector3(1,0,0),negX:new J.Vector3(-1,0,0),posY:new J.Vector3(0,1,0),negY:new J.Vector3(0,-1,0),posZ:new J.Vector3(0,0,1),negZ:new J.Vector3(0,0,-1)},u=p=>{let T=t.getBoundingClientRect(),v=T.left+t.offsetWidth-i-a.location.right,R=T.top+t.offsetHeight-i-a.location.bottom,m=new J.Vector2((p.clientX-v)/i*2-1,-((p.clientY-R)/i)*2+1);if(Math.abs(m.x)>1||Math.abs(m.y)>1)return null;a.quaternion.copy(n.quaternion).invert(),a.updateMatrixWorld(),l.setFromCamera(m,s);let g=l.intersectObjects(a.children,!1);for(let b of g){let x=b.object.userData?.type;if(typeof x=="string"&&x in c)return x}return null};return{render:p=>{if(!o)return;let T=p.autoClear;p.autoClear=!1,a.render(p),p.autoClear=T},update:()=>{},handleClick:p=>{if(!o)return!1;let T=u(p);return T?(r.getProjection()==="orthographic"&&r.setProjection("perspective"),r.setViewDirection(c[T],!1),!0):!1},isAnimating:!1,setVisible:p=>{o=p},isVisible:()=>o,dispose:()=>a.dispose()}}import*as Z from"three";import{LineSegmentsGeometry as er}from"three/addons/lines/LineSegmentsGeometry.js";import{LineSegments2 as nt}from"three/addons/lines/LineSegments2.js";import{LineMaterial as tr}from"three/addons/lines/LineMaterial.js";function Pe(e,n,t){let o=Math.cos(Math.PI/180*t),i=e.length/3;if(i>=67108864)throw new Error(`extractEdgeSegments: ${i} vertices exceeds 2^26 limit`);let l=new Float64Array(i),s=new Float64Array(i),c=new Float64Array(i);for(let f=0;f<i;f++)l[f]=Math.round(e[3*f]*1e4),s[f]=Math.round(e[3*f+1]*1e4),c[f]=Math.round(e[3*f+2]*1e4);let u=16;for(;u<i*2;)u<<=1;let d=u-1,p=new Int32Array(u).fill(-1),T=new Int32Array(i);for(let f=0;f<i;f++){let h=(Math.imul(l[f]|0,73856093)^Math.imul(s[f]|0,19349663)^Math.imul(c[f]|0,83492791))&d;for(;;){let y=p[h];if(y===-1){p[h]=f,T[f]=f;break}if(l[y]===l[f]&&s[y]===s[f]&&c[y]===c[f]){T[f]=y;break}h=h+1&d}}let v=new Float32Array(4096),R=0,m=(f,h)=>{if(R+6>v.length){let y=new Float32Array(v.length*2);y.set(v),v=y}v[R++]=e[3*f],v[R++]=e[3*f+1],v[R++]=e[3*f+2],v[R++]=e[3*h],v[R++]=e[3*h+1],v[R++]=e[3*h+2]},g=new Map,b=[],x=[],H=[],E=(n?n.length:i)/3;for(let f=0;f<E;f++){let h=n?n[3*f]:3*f,y=n?n[3*f+1]:3*f+1,C=n?n[3*f+2]:3*f+2,M=T[h],L=T[y],I=T[C];if(M===L||L===I||I===M)continue;let k=e[3*C]-e[3*y],O=e[3*C+1]-e[3*y+1],F=e[3*C+2]-e[3*y+2],S=e[3*h]-e[3*y],D=e[3*h+1]-e[3*y+1],G=e[3*h+2]-e[3*y+2],V=O*G-F*D,q=F*S-k*G,Y=k*D-O*S,fe=V*V+q*q+Y*Y;if(fe>0){let ee=1/Math.sqrt(fe);V*=ee,q*=ee,Y*=ee}else V=0,q=0,Y=0;for(let ee=0;ee<3;ee++){let pe,j,te,ne;ee===0?(pe=h,j=y,te=M,ne=L):ee===1?(pe=y,j=C,te=L,ne=I):(pe=C,j=h,te=I,ne=M);let xe=ne*67108864+te,he=g.get(xe);if(he!==void 0&&he!==-1)V*H[3*he]+q*H[3*he+1]+Y*H[3*he+2]<=o&&m(pe,j),g.set(xe,-1);else{let ie=te*67108864+ne;if(!g.has(ie)){let ve=b.length;g.set(ie,ve),b.push(pe),x.push(j),H.push(V,q,Y)}}}}for(let f of g.values())f!==-1&&m(b[f],x[f]);return v.slice(0,R)}function Pt(){return[`const extract = ${Pe.toString()};`,"self.onmessage = (event) => {"," const { id, positions, index, thresholdAngle } = event.data;"," try {"," const segments = extract(positions, index, thresholdAngle);"," self.postMessage({ id, segments }, [segments.buffer]);"," } catch (error) {"," self.postMessage({ id, error: String((error && error.message) || error) });"," }","};"].join(`
54
+ `)}var He="edge-overlay",rt="triangle-cap",nr=2236962,rr=1.5,or=44,ar=.75,ir=4e6,sr=2e6,lr=25e3,Ft=128*1024*1024,cr=4,Bt=1,ur=0,dr=-1;function Je(e){let n=e.getAttribute("position");return n?(e.index?e.index.count:n.count)/3:0}function Ut(e){let n=e.getAttribute("position");if(!n||n.isInterleavedBufferAttribute||n.itemSize!==3||!(n.array instanceof Float32Array)||n.count>=67108864)return null;let t=e.index;return t&&!(t.array instanceof Uint32Array)&&!(t.array instanceof Uint16Array)?null:{positions:n.array,index:t?t.array:null}}function _t(e,n){let r=2166136261,a=s=>{r^=s,r=Math.imul(r,16777619)},o=new Uint32Array(e.positions.buffer,e.positions.byteOffset,e.positions.length),i=Math.min(4096,o.length);for(let s=0;s<i;s++)a(o[s]);for(let s=Math.max(i,o.length-4096);s<o.length;s++)a(o[s]);let l=0;if(e.index){l=e.index.length;let s=Math.min(4096,l);for(let c=0;c<s;c++)a(e.index[c]);for(let c=Math.max(s,l-4096);c<l;c++)a(e.index[c])}return`${n}:${e.positions.length}:${l}:${r>>>0}`}var ue=new Map,Fe=0;function Vt(e){let n=ue.get(e);return n&&(ue.delete(e),ue.set(e,n)),n}function zt(e,n){if(n.byteLength>Ft)return;let t=ue.get(e);for(t&&(Fe-=t.byteLength,ue.delete(e)),ue.set(e,n),Fe+=n.byteLength;Fe>Ft;){let r=ue.keys().next().value;Fe-=ue.get(r).byteLength,ue.delete(r)}}function mr(e,n){let t=new Z.EdgesGeometry(e,n),r=t.attributes.position?t.attributes.position.array:new Float32Array(0);return t.dispose(),r}function Qe(e,n){let t=Ut(e);if(!t)return mr(e,n);let r=_t(t,n),a=Vt(r);if(a)return a;let o=Pe(t.positions,t.index,n);return zt(r,o),o}var ye,Me=new Map,fr=1;function pr(){if(ye!==void 0)return ye;if(typeof Worker>"u"||typeof Blob>"u"||typeof URL>"u"||typeof URL.createObjectURL!="function")return ye=null,null;try{let e=URL.createObjectURL(new Blob([Pt()],{type:"text/javascript"})),n=new Worker(e);n.onmessage=t=>{let{id:r,segments:a,error:o}=t.data,i=Me.get(r);i&&(Me.delete(r),a?i.resolve(a):i.reject(new Error(o??"edge extraction failed in worker")))},n.onerror=()=>{for(let t of Me.values())t.reject(new Error("edge extraction worker crashed"));Me.clear(),n.terminate(),ye=null},ye=n}catch{ye=null}return ye}function Er(e,n,t){return new Promise((r,a)=>{let o=fr++;Me.set(o,{resolve:r,reject:a});let i=n.positions.slice(),l=n.index?n.index.slice():null,s=[i.buffer];l&&s.push(l.buffer),e.postMessage({id:o,positions:i,index:l,thresholdAngle:t},s)})}var Ze=new Map;function hr(e,n){let t=Ut(e);if(!t||Je(e)<lr)return Promise.resolve(Qe(e,n));let r=_t(t,n),a=Vt(r);if(a)return Promise.resolve(a);let o=Ze.get(r);if(o)return o;let i=pr();if(!i)return Promise.resolve(Qe(e,n));let l=Er(i,t,n).catch(()=>Pe(t.positions,t.index,n)).then(s=>(zt(r,s),s)).finally(()=>{Ze.delete(r)});return Ze.set(r,l),l}var gr=.15,yr=4096;function br(e){let n=Math.floor(e.length/6);if(n===0)return 1/0;let t=Math.max(1,Math.ceil(n/yr)),r=[];for(let a=0;a<n;a+=t){let o=a*6,i=Math.hypot(e[o+3]-e[o],e[o+4]-e[o+1],e[o+5]-e[o+2]);i>0&&r.push(i)}return r.length===0?1/0:(r.sort((a,o)=>a-o),r[Math.min(r.length-1,Math.floor(r.length*gr))])}var Be=new WeakMap;function et(e,n){return Be.get(e)?.get(n)}function Gt(e,n,t){let r=Be.get(e);r||(r=new Map,Be.set(e,r));let a=new er;a.setPositions(t);let o={geometry:a,refCount:0,segmentCount:t.length/6,edgeSpacing:br(t)};return r.set(n,o),o}function Tr(e){let n=e.userData,t=n.edgeSource&&Be.get(n.edgeSource),r=n.edgeThresholdAngle!=null?t?.get(n.edgeThresholdAngle):void 0;if(!r||r.geometry!==e.geometry){e.geometry.dispose();return}r.refCount-=1,r.refCount<=0&&(r.geometry.dispose(),t.delete(n.edgeThresholdAngle))}function Nt(e){return{forcedColor:e.color!=null?new Z.Color(e.color):null,darken:Z.MathUtils.clamp(e.darken??ar,0,1),width:e.width??rr,thresholdAngle:e.thresholdAngle??or,distanceFade:e.distanceFade??!0,maxTriangles:e.maxTriangles??ir,maxSegments:e.maxSegments??sr}}function Rr(e,n){let r=(Array.isArray(e.material)?e.material[0]:e.material)?.color;return r?r.clone().multiplyScalar(1-n):new Z.Color(nr)}var ke=class{constructor(n){re(this,"options",n);re(this,"byKey",new Map)}for(n,t){let r=this.options.forcedColor??Rr(n,this.options.darken),a=r.getHex()*2+(t?1:0),o=this.byKey.get(a);return o||(o=xr(r,this.options.width,t),this.byKey.set(a,o)),o}disposeUnused(n){let t=new Set(n.map(r=>r.material));for(let r of this.byKey.values())t.has(r)||r.dispose()}};function xr(e,n,t){let r=new tr({color:e});return r.linewidth=n,r.polygonOffset=!0,r.polygonOffsetFactor=ur,r.polygonOffsetUnits=dr,t&&(r.transparent=!0),r}function vr(e,n,t,r,a){n.refCount+=1;let o=new nt(n.geometry,t);return o.userData.kind=He,o.userData.edgeSource=e,o.userData.edgeThresholdAngle=r,o.raycast=()=>{},a&&Hr(o,n.edgeSpacing),o}var kt=new Z.Vector3,wr=new Z.Vector3;function Mr(e,n,t){e.geometry.boundingSphere||e.geometry.computeBoundingSphere();let r=e.geometry.boundingSphere;if(!r)return 1/0;if(n.isPerspectiveCamera){let a=n;kt.copy(r.center).applyMatrix4(e.matrixWorld);let o=wr.setFromMatrixPosition(n.matrixWorld).distanceTo(kt),i=r.radius*e.matrixWorld.getMaxScaleOnAxis();if(o<=i)return 1/0;let l=Math.tan(Z.MathUtils.degToRad(a.fov)*.5),s=2*o*l;return s>0?t/s:1/0}if(n.isOrthographicCamera){let a=n,o=(a.top-a.bottom)/a.zoom;return o>0?t/o:1/0}return 1/0}function Hr(e,n){e.onBeforeRender=(t,r,a)=>{nt.prototype.onBeforeRender.call(e,t);let o=e.material,i=Mr(e,a,o.resolution.y),l=n*i;o.opacity=Z.MathUtils.clamp((l-Bt)/(cr-Bt),0,1)}}function Cr(e){return e.userData?.kind===He}function jt(e,n){let t=[];return e.traverse(r=>{if(r instanceof Z.Mesh&&!(r.userData.id==="floor"||r.userData.id==="grid")&&r.userData.kind!==He&&!r.children.some(a=>a.userData?.kind===He)&&r.geometry){if(Je(r.geometry)>n){r.userData.edgesSkipped=rt,console.debug(`[edges] skipping mesh over triangle cap (${Je(r.geometry)} > ${n})`);return}delete r.userData.edgesSkipped,t.push(r)}}),t}function Wt(e,n,t,r){let a=r.distanceFade&&n.segmentCount<=r.maxSegments,o=vr(e.geometry,n,t.for(e,a),r.thresholdAngle,a);return e.add(o),o}function $a(e,n={}){let t=Nt(n),r=new ke(t),a=[];for(let o of jt(e,t.maxTriangles)){let i=et(o.geometry,t.thresholdAngle)??Gt(o.geometry,t.thresholdAngle,Qe(o.geometry,t.thresholdAngle));a.push(Wt(o,i,r,t))}return r.disposeUnused(a),a}var $t=new WeakMap;function tt(e){return $t.get(e)??0}function Ar(e,n){for(let t=e;t;t=t.parent)if(t===n)return!0;return!1}async function qt(e,n={}){let t=Nt(n),r=new ke(t),a=tt(e),o=[],i=jt(e,t.maxTriangles).map(async l=>{let s=et(l.geometry,t.thresholdAngle);if(!s){let c=await hr(l.geometry,t.thresholdAngle);if(tt(e)!==a||!Ar(l,e)||l.children.some(u=>u.userData?.kind===He))return;s=et(l.geometry,t.thresholdAngle),s||(s=Gt(l.geometry,t.thresholdAngle,c))}o.push(Wt(l,s,r,t))});return await Promise.all(i),r.disposeUnused(o),o}function Yt(e){$t.set(e,tt(e)+1);let n=[];e.traverse(r=>{r instanceof nt&&Cr(r)&&n.push(r)});let t=new Set;for(let r of n)Tr(r),t.add(r.material),r.removeFromParent();return t.forEach(r=>r.dispose()),n.length}import*as N from"three";import{Pass as Sr,FullScreenQuad as Dr}from"three/addons/postprocessing/Pass.js";var ot={uniforms:{tDiffuse:{value:null},tNormal:{value:null},tDepth:{value:null},uResolution:{value:new N.Vector2(1,1)},uColor:{value:new N.Color(2236962)},uOpacity:{value:1},uNormalThreshold:{value:.4},uDepthThreshold:{value:.02},uThickness:{value:1},uNear:{value:.1},uFar:{value:1e3},uPerspective:{value:1}},vertexShader:`
55
55
  varying vec2 vUv;
56
56
  void main() {
57
57
  vUv = uv;
@@ -107,14 +107,14 @@ import{a as _n,b as re,c as Te,d as Re,e as P,j as bt}from"./chunk-Y3M7P3BW.js";
107
107
  float edge = max(depthEdge, normalEdge) * uOpacity;
108
108
  gl_FragColor = vec4(mix(color.rgb, uColor, edge), color.a);
109
109
  }
110
- `},Ue=class extends Cr{constructor(t,r,a,o,i={}){super();re(this,"camera");re(this,"scene");re(this,"normalMaterial");re(this,"edgeMaterial");re(this,"fsQuad");re(this,"normalTarget",null);re(this,"width");re(this,"height");this.scene=t,this.camera=r,this.width=Math.max(1,a),this.height=Math.max(1,o),this.normalMaterial=new N.MeshNormalMaterial,this.normalMaterial.blending=N.NoBlending,this.edgeMaterial=new N.ShaderMaterial({uniforms:N.UniformsUtils.clone(ot.uniforms),vertexShader:ot.vertexShader,fragmentShader:ot.fragmentShader});let l=this.edgeMaterial.uniforms;l.uColor.value=new N.Color(i.color??2236962),l.uOpacity.value=i.opacity??1,l.uNormalThreshold.value=i.normalThreshold??.4,l.uDepthThreshold.value=i.depthThreshold??.02,l.uThickness.value=i.thickness??1,this.fsQuad=new Ar(this.edgeMaterial),this.needsSwap=!0}acquireNormalTarget(){if(!this.normalTarget){let t=new N.DepthTexture(this.width,this.height);this.normalTarget=new N.WebGLRenderTarget(this.width,this.height,{minFilter:N.NearestFilter,magFilter:N.NearestFilter,depthTexture:t})}return this.normalTarget}setSize(t,r){this.width=Math.max(1,t),this.height=Math.max(1,r),this.normalTarget?.setSize(this.width,this.height)}render(t,r,a){let o=this.acquireNormalTarget(),i=t.getRenderTarget(),l=t.autoClear,s=t.getClearColor(new N.Color),c=t.getClearAlpha(),u=this.scene.overrideMaterial;t.setRenderTarget(o),t.setClearColor(7829503,1),t.autoClear=!0,this.scene.overrideMaterial=this.normalMaterial,t.render(this.scene,this.camera),this.scene.overrideMaterial=u,t.setClearColor(s,c),t.autoClear=l;let d=this.edgeMaterial.uniforms;d.tDiffuse.value=a.texture,d.tNormal.value=o.texture,d.tDepth.value=o.depthTexture,d.uResolution.value.set(this.width,this.height);let p=this.camera;d.uPerspective.value=p.isPerspectiveCamera?1:0,d.uNear.value=this.camera.near??.1,d.uFar.value=this.camera.far??1e3,t.setRenderTarget(this.renderToScreen?null:r),this.fsQuad.render(t),t.setRenderTarget(i)}dispose(){this.normalTarget?.dispose(),this.normalMaterial.dispose(),this.edgeMaterial.dispose(),this.fsQuad.dispose()}};import{EffectComposer as Sr}from"three/addons/postprocessing/EffectComposer.js";import{RenderPass as Dr}from"three/addons/postprocessing/RenderPass.js";import{GTAOPass as Lr}from"three/addons/postprocessing/GTAOPass.js";import{SMAAPass as Or}from"three/addons/postprocessing/SMAAPass.js";import{OutputPass as Ir}from"three/addons/postprocessing/OutputPass.js";function Kt(e,n,t,r,a,o){let i=new Sr(e),l=new Dr(n,t);i.addPass(l);let s=null;(o.ambientOcclusion??!0)&&(s=new Lr(n,t,r,a),s.blendIntensity=o.aoIntensity??1,s.updateGtaoMaterial({screenSpaceRadius:!0}),i.addPass(s));let c=typeof o.edgeDetection=="object"?o.edgeDetection:{},u=new Ue(n,t,r,a,c);u.enabled=!!o.edgeDetection,i.addPass(u);let d=new Or;i.addPass(d);let p=new Ir;i.addPass(p),e.toneMapping=o.toneMapping,e.toneMappingExposure=o.toneMappingExposure;let T=o.aoPixelRatio??1;return i.setSize(r,a),{render:v=>i.render(v),setSize:(v,R,m)=>{i.setPixelRatio(Math.min(m,T)),i.setSize(v,R)},setCamera:v=>{if(l.camera=v,u.camera=v,!s)return;s.camera=v;let R=v.isPerspectiveCamera?1:0;s.gtaoMaterial.defines.PERSPECTIVE_CAMERA!==R&&(s.gtaoMaterial.defines.PERSPECTIVE_CAMERA=R,s.gtaoMaterial.needsUpdate=!0)},setEdgeDetection:v=>{u.enabled=v},edgeDetectionEnabled:()=>u.enabled,dispose:()=>{i.dispose(),s?.dispose(),u.dispose(),d.dispose(),p.dispose()}}}import*as Zt from"three";import{CSS2DRenderer as Pr,CSS2DObject as Fr}from"three/addons/renderers/CSS2DRenderer.js";function Jt(e,n){let t=new Pr,r=t.domElement;r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.overflow="hidden",r.style.pointerEvents="none",r.style.zIndex="30",getComputedStyle(e).position==="static"&&(e.style.position="relative"),e.appendChild(r);let a={width:e.clientWidth||1,height:e.clientHeight||1};t.setSize(a.width,a.height);let o=new Zt.Group;o.name="label-layer",o.userData.id="label-layer",n.add(o);let i=new Set;return{addLabel:(s,c,u)=>{let d=document.createElement("div");d.textContent=s,u?d.className=u:Object.assign(d.style,{padding:"2px 6px",borderRadius:"4px",background:"rgba(20, 20, 20, 0.78)",color:"#fff",font:"12px/1.3 system-ui, sans-serif",whiteSpace:"pre",textAlign:"center",userSelect:"none"}),d.style.pointerEvents="none";let p=new Fr(d);return p.position.copy(c),o.add(p),i.add(p),{object:p,setPosition:T=>p.position.copy(T),setText:T=>{d.textContent=T},remove:()=>{p.removeFromParent(),d.remove(),i.delete(p)}}},render:(s,c)=>t.render(s,c),setSize:(s,c)=>t.setSize(s,c),dispose:()=>{i.forEach(s=>{s.removeFromParent(),s.element.remove()}),i.clear(),o.removeFromParent(),r.remove()}}}import*as U from"three";import{Line2 as Br}from"three/addons/lines/Line2.js";import{LineGeometry as kr}from"three/addons/lines/LineGeometry.js";import{LineMaterial as Ur}from"three/addons/lines/LineMaterial.js";var Vr=12,_r=16763904,Qt=.015,en={Millimeters:{metersPerUnit:1/1e3,suffix:"mm"},Centimeters:{metersPerUnit:1/100,suffix:"cm"},Meters:{metersPerUnit:1,suffix:"m"},Inches:{metersPerUnit:1/39.37,suffix:"in"},Feet:{metersPerUnit:1/3.28084,suffix:"ft"}};function zr(e){let n=e&&en[e]||en.Meters;return t=>`${(t/n.metersPerUnit).toPrecision(3)} ${n.suffix}`}function Gr(e,n){if(e.isOrthographicCamera){let r=e;return Math.abs(r.top-r.bottom)/(r.zoom||1)*Qt}return((n?e.position.distanceTo(n):e.position.length())||1)*Qt}function Nr(e){let n=e.object;if(n instanceof U.Mesh)return e.face?[e.face.a,e.face.b,e.face.c]:null;if(n instanceof U.Points)return e.index!=null?[e.index]:null;if(n instanceof U.Line){if(e.index==null)return null;let t=n.geometry.index;return t?e.index+1>=t.count?null:[t.getX(e.index),t.getX(e.index+1)]:[e.index,e.index+1]}return null}function jr(e,n,t,r){let a=e.point.clone(),o=e.object,i=Nr(e);if(!i||!o.geometry)return a;let l=o.geometry.attributes.position;if(!l)return a;let s=p=>{let T=p.clone().project(n);return new U.Vector2((T.x+1)/2*t.width,(1-T.y)/2*t.height)},c=s(a),u=a,d=r;for(let p of i){if(p>=l.count)continue;let v=new U.Vector3().fromBufferAttribute(l,p).applyMatrix4(o.matrixWorld),R=s(v).distanceTo(c);R<d&&(d=R,u=v)}return u}function tn(e){let{canvas:n,scene:t,getActiveCamera:r,getViewTarget:a,labelLayer:o,options:i={}}=e,l=i.snapPixels??Vr,s=new U.Color(i.color??_r),c=zr(i.displayUnit),u=(S,D)=>`${c(S)}
111
- \u0394x ${c(D.x)} \u0394y ${c(D.y)} \u0394z ${c(D.z)}`,d=i.format??u,p=new U.Raycaster,T=new U.Vector2,v=!1,R=[],m=[],g=null,b=null,x=new U.PointsMaterial({color:s,size:8,sizeAttenuation:!1,depthTest:!1}),H=new U.PointsMaterial({color:s,size:11,sizeAttenuation:!1,depthTest:!1,transparent:!0,opacity:.5}),E=null,f=S=>{if(!S){E&&(E.visible=!1);return}if(!E){let D=new U.BufferGeometry;D.setAttribute("position",new U.Float32BufferAttribute([0,0,0],3)),E=new U.Points(D,H),E.renderOrder=1e3,E.userData.id="measure",E.raycast=()=>{},t.add(E)}E.position.copy(S),E.visible=!0},h=S=>{let D=new U.BufferGeometry;D.setAttribute("position",new U.Float32BufferAttribute([S.x,S.y,S.z],3));let G=new U.Points(D,x);return G.renderOrder=999,G.userData.id="measure",G.raycast=()=>{},t.add(G),G},y=()=>{R.length=0,m.forEach(S=>{S.geometry.dispose(),S.removeFromParent()}),m.length=0,g&&(g.geometry.dispose(),g.material.dispose(),g.removeFromParent(),g=null),b?.remove(),b=null},C=()=>{if(R.length!==2)return;let[S,D]=R,G=new kr;G.setPositions([S.x,S.y,S.z,D.x,D.y,D.z]);let _=new Ur({color:s});_.linewidth=2,_.depthTest=!1,g=new Br(G,_),g.renderOrder=998,g.userData.id="measure",g.raycast=()=>{},t.add(g);let q=S.clone().add(D).multiplyScalar(.5),Y=new U.Vector3(Math.abs(D.x-S.x),Math.abs(D.y-S.y),Math.abs(D.z-S.z));b=o.addLabel(d(S.distanceTo(D),Y),q,i.labelClassName)},M=S=>{let D=n.getBoundingClientRect();T.x=(S.clientX-D.left)/D.width*2-1,T.y=-((S.clientY-D.top)/D.height)*2+1;let G=r();p.setFromCamera(T,G);let _=Gr(G,a?.());p.params.Line.threshold=_,p.params.Points.threshold=_;let q=p.intersectObjects(t.children,!0).filter(Y=>Y.object.userData.id!=="measure"&&Y.object.userData.id!=="grid");return q.length===0?null:jr(q[0],G,{width:D.width,height:D.height},l)},L=null,I=0,k=()=>{I&&(cancelAnimationFrame(I),I=0),L=null};return{setEnabled:S=>{v=S,S||(k(),y(),f(null))},isEnabled:()=>v,handleClick:S=>{if(!v)return!1;R.length===2&&y();let D=M(S);return D===null||(R.push(D),m.push(h(D)),R.length===2&&C()),!0},handleMove:S=>{v&&(L=S,!I&&(I=requestAnimationFrame(()=>{I=0;let D=L;L=null,!(!v||!D)&&f(M(D))})))},clear:y,dispose:()=>{k(),y(),E&&(E.geometry.dispose(),E.removeFromParent(),E=null),x.dispose(),H.dispose()}}}import*as Ge from"three";var Wr=64,$r=256,ae=new Map,Ce=new Map,Ve=0,ze=class extends Error{constructor(n){super(`Texture load for ${n} resolved after clearTextureCache(); texture disposed.`),this.name="StaleTextureLoadError"}},_e=1;function nn(e){_e=Math.max(1,e);for(let n of ae.values())n.anisotropy!==_e&&(n.anisotropy=_e,n.needsUpdate=!0)}function rn(e,n){let t=qr(n),r=ae.get(t);if(r){ae.delete(t),ae.set(t,r),e.map=r,e.needsUpdate=!0;return}typeof document>"u"||Kr(n,t).then(a=>{e.map=a,e.needsUpdate=!0}).catch(a=>{a instanceof ze||P().warn(`Failed to load material texture ${n}:`,a)})}function ui(){Ve++;for(let e of ae.values())e.dispose();ae.clear(),Ce.clear()}function qr(e){return e.length<=$r?e:`data-uri:${Yr(e).toString(16)}:${e.length}`}function Yr(e){let n=2166136261;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619);return n>>>0}function Xr(e,n){for(ae.set(e,n);ae.size>Wr;){let t=ae.keys().next().value,r=ae.get(t);ae.delete(t),r.dispose()}}function Kr(e,n){let t=Ce.get(n);if(!t){let r=Ve;t=new Promise((a,o)=>{new Ge.TextureLoader().load(e,i=>{if(r!==Ve){i.dispose(),o(new ze(e));return}i.colorSpace=Ge.SRGBColorSpace,i.anisotropy=_e,Xr(n,i),Ce.delete(n),a(i)},void 0,i=>{r===Ve&&Ce.delete(n),o(i)})}),Ce.set(n,t)}return t}import*as w from"three";import{OrbitControls as to}from"three/addons/controls/OrbitControls.js";import{HDRLoader as no}from"three/addons/loaders/HDRLoader.js";import*as Ae from"three";var Zr=.5,Jr=.01,Qr=.05,eo=[];function on({camera:e,scene:n,groundNormals:t=()=>eo}){let r=e.near,a=e.near,o=new Ae.Vector3,i=new Ae.Vector3;return{update:()=>{e.near!==a&&(r=e.near);let s=ce(n),c=r;if(!s.isEmpty()){let u=s.getSize(i).length()*.5,d=e.position.distanceTo(s.getCenter(o))-u;for(let p of t())d=Math.min(d,Math.abs(e.position.dot(p)));c=Ae.MathUtils.clamp(d*Zr,r,e.far*Jr)}Math.abs(c-a)>a*Qr&&(e.near=c,e.updateProjectionMatrix(),a=c)}}}var de=new w.Vector3(0,0,1),ro="technical",at={studio:{toneMapping:w.ACESFilmicToneMapping,toneMappingExposure:1,envMapIntensity:1,environmentIntensity:1,hemisphereIntensity:.75,ambientIntensity:.4,cullBackfaces:!1,ambientOcclusion:!1},technical:{toneMapping:w.NeutralToneMapping,toneMappingExposure:1,envMapIntensity:.9,environmentIntensity:1,hemisphereIntensity:.35,ambientIntensity:.25,cullBackfaces:!1,ambientOcclusion:!1},showcase:{toneMapping:w.ACESFilmicToneMapping,toneMappingExposure:1.15,envMapIntensity:1.4,environmentIntensity:1.25,hemisphereIntensity:.35,ambientIntensity:.15,cullBackfaces:!1,ambientOcclusion:!1}};function oo(e){let n=at[e];return{envMapIntensity:n.envMapIntensity,cullBackfaces:n.cullBackfaces}}var Ai=function(e,n){let t=ao(n||{}),r=t.environment?.sceneUp||de,a=t.render.pixelRatio??Math.min(window.devicePixelRatio,2),o=so(t),i=fo(t,e);i.up.copy(r);let l=po(e,t,a);nn(l.capabilities.getMaxAnisotropy());let s=ho(i,e,t),c=Lt({scene:o,perspective:i,controls:s,onActiveCameraChange:()=>{},up:r}),u=()=>c.getActiveCamera(),d=!1;co(o,l,t,()=>d);let p=uo(o,t),T=p.sun,v=()=>{T&&io(T,ce(o))};t.floor?.enabled&&mo(o,t);let R=t.floor?.enabled?o.children.find(A=>A.userData.id==="floor")??null:null,m=t.grid.enabled?Ot({cellSize:t.grid.cellSize,majorEvery:t.grid.majorEvery,cellColor:t.grid.cellColor,majorColor:t.grid.majorColor,fadeDistance:t.grid.fadeDistance,plane:t.grid.plane}):null;m&&o.add(m.object);let g=()=>{m&&m.fitToContent(ce(o))},b=t.gizmo.enabled?It({camera:i,domElement:e,controller:c}):null,x=t.grid.plane??Xe(r),H=new w.Vector3(x==="x"?1:0,x==="y"?1:0,x==="z"?1:0),E=r.clone().normalize(),f=()=>{let A=[];return m?.object.visible&&A.push(H),t.floor.enabled&&R?.visible&&A.push(E),A},h=t.camera.dynamicNear?on({camera:i,scene:o,groundNormals:f}):null,y=e.parentElement??e,C=t.measure.enabled?Jt(y,o):null,M=t.measure.enabled&&C?tn({canvas:e,scene:o,getActiveCamera:u,labelLayer:C,options:{snapPixels:t.measure.snapPixels,color:t.measure.color,labelClassName:t.measure.labelClassName,displayUnit:t.measure.displayUnit,format:t.measure.format}}):null,L=t.events.enableEventHandlers!==!1?Eo(e,o,c,t):{dispose:()=>{},fitToView:()=>{},clearSelection:()=>{}},I=5,k=0,O=0,F=A=>{k=A.clientX,O=A.clientY},S=A=>Math.hypot(A.clientX-k,A.clientY-O)>I,D=A=>{if(!S(A)){if(M?.handleClick(A)){A.stopImmediatePropagation();return}b?.handleClick(A)&&A.stopImmediatePropagation()}};(b||M)&&(e.addEventListener("mousedown",F,{capture:!0}),e.addEventListener("click",D,{capture:!0}));let G=A=>M?.handleMove(A);M&&e.addEventListener("mousemove",G,{passive:!0});let _=()=>{},q=A=>{Yt(A,{color:t.edges.color,darken:t.edges.darken,width:t.edges.width,thresholdAngle:t.edges.thresholdAngle,distanceFade:t.edges.distanceFade,maxTriangles:t.edges.maxTriangles,maxSegments:t.edges.maxSegments}).then(()=>{Y(A),_()})},Y=A=>{if(t.edges.screenSpaceFallback===!1)return;let B=!1;A.traverse(K=>{K.userData?.edgesSkipped===rt&&(B=!0)}),B!==ne&&(ne=B,ie())},fe=A=>{Xt(A),ne&&(ne=!1,ie()),_()},ee=e.parentElement,pe=()=>ee?{width:ee.clientWidth,height:ee.clientHeight}:{width:window.innerWidth,height:window.innerHeight},j=null,te=!!t.render.ambientOcclusion,ne=!1,xe=!1,he=A=>{let{width:B,height:K}=pe(),ge=Kt(l,o,u(),Math.max(1,B),Math.max(1,K),{toneMapping:t.render.toneMapping??w.NeutralToneMapping,toneMappingExposure:t.render.toneMappingExposure??1,ambientOcclusion:A,aoIntensity:t.render.aoIntensity,aoPixelRatio:t.render.aoPixelRatio,edgeDetection:!1});return ge.setSize(Math.max(1,B),Math.max(1,K),a),ge},ie=()=>{if(!(te||ne)){j?.dispose(),j=null,_();return}(!j||xe!==te)&&(j?.dispose(),j=he(te),xe=te),j.setEdgeDetection(ne),_()},ve=()=>{j?.dispose(),j=null,ie()},Sn=A=>{te=A,ie()};ie();let ft=A=>{A.ambientIntensity!==void 0&&(p.ambient.intensity=A.ambientIntensity),A.hemisphereIntensity!==void 0&&!p.hemisphere&&A.hemisphereIntensity>0&&(p.hemisphere=new w.HemisphereLight(A.hemisphereSkyColor??t.lighting.hemisphereSkyColor,A.hemisphereGroundColor??t.lighting.hemisphereGroundColor,A.hemisphereIntensity),p.hemisphere.position.copy(t.environment.sceneUp??de),o.add(p.hemisphere)),p.hemisphere&&(A.hemisphereIntensity!==void 0&&(p.hemisphere.intensity=A.hemisphereIntensity),A.hemisphereSkyColor!==void 0&&p.hemisphere.color.set(A.hemisphereSkyColor),A.hemisphereGroundColor!==void 0&&p.hemisphere.groundColor.set(A.hemisphereGroundColor)),_()},pt=A=>{t.environment.environmentIntensity=A,o.environmentIntensity=A,_()},Dn=A=>{t.render.toneMappingExposure=A,l.toneMappingExposure=A,j&&ve()},Ln=A=>{t.render.aoIntensity=A,j&&ve()},On=A=>{let B=at[A];Et=A,l.toneMapping=B.toneMapping,l.toneMappingExposure=B.toneMappingExposure,t.render.toneMapping=B.toneMapping,t.render.toneMappingExposure=B.toneMappingExposure,ft({hemisphereIntensity:B.hemisphereIntensity,ambientIntensity:B.ambientIntensity}),pt(B.environmentIntensity),te=B.ambientOcclusion,j?ve():ie(),o.traverse(K=>{if(K.userData.source!=="compute")return;let ge=K,Vn=Array.isArray(ge.material)?ge.material:ge.material?[ge.material]:[];for(let yt of Vn)"envMapIntensity"in yt&&(yt.envMapIntensity=B.envMapIntensity)}),_()},Et=t.look,In=()=>oo(Et),{animate:Pn,dispose:Fn,invalidate:ht}=lo(l,o,i,u,c,s,pe,a,t.events.onFrame,m,b,()=>j,C,h,t.render.onDemand??!0);_=ht,Pn(),o.up.set(r.x,r.y,r.z),v(),g();let gt=A=>{A.traverse(B=>{let K=B;!K.geometry&&!K.material||(K.geometry?.dispose(),Array.isArray(K.material)?K.material.forEach(Ne):K.material&&Ne(K.material))})},Bn=A=>{A.userData.source="user",o.add(A)},kn=A=>{A.removeFromParent(),gt(A)},Un=()=>{o.children.filter(B=>B.userData.source==="user").forEach(B=>{B.removeFromParent(),gt(B)})};return{scene:o,camera:i,controls:s,renderer:l,cameraController:c,grid:m,gizmo:b,measureTool:M,applyEdges:q,clearEdges:fe,invalidate:ht,setAmbientOcclusion:Sn,setLook:On,setFillLights:ft,setEnvironmentIntensity:pt,setToneMappingExposure:Dn,setAoIntensity:Ln,getMaterialAppearance:In,updateShadowBounds:v,updateGridScale:g,dispose:()=>{d||(d=!0,Fn(),L.dispose(),(b||M)&&(e.removeEventListener("mousedown",F,{capture:!0}),e.removeEventListener("click",D,{capture:!0})),M&&e.removeEventListener("mousemove",G),M?.dispose(),C?.dispose(),b?.dispose(),m?.dispose(),j?.dispose(),c.dispose(),s.dispose(),l.dispose(),l.forceContextLoss(),o.traverse(A=>{let B=A;!B.geometry&&!B.material||(B.geometry?.dispose(),Array.isArray(B.material)?B.material.forEach(Ne):B.material&&Ne(B.material))}),o.environment?.dispose(),o.background instanceof w.Texture&&o.background.dispose())},fitToView:L.fitToView,clearSelection:L.clearSelection,addUserGeometry:Bn,removeUserGeometry:kn,clearUserGeometry:Un}};function ao(e){let n=e.sceneScale||"m",r={mm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:10,lightHeight:20,minDistance:.1,shadowSize:100,scaleFactor:1e3},cm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:25,lightHeight:50,minDistance:.1,shadowSize:100,scaleFactor:100},m:{cameraDistance:10,near:.01,far:2e3,floorSize:50,lightDistance:25,lightHeight:50,minDistance:.001,shadowSize:100,scaleFactor:1},inches:{cameraDistance:15,near:.1,far:2e3,floorSize:80,lightDistance:20,lightHeight:40,minDistance:.1,shadowSize:80,scaleFactor:39.37},feet:{cameraDistance:8,near:.1,far:2e3,floorSize:40,lightDistance:15,lightHeight:30,minDistance:.1,shadowSize:60,scaleFactor:3.28084}}[n],a=e.look??ro,o=at[a];return{sceneScale:n,look:a,camera:{position:e.camera?.position||Oe(e.environment?.sceneUp??de,r.cameraDistance*Math.sqrt(3)),fov:e.camera?.fov||20,near:e.camera?.near||r.near,far:e.camera?.far||r.far,target:e.camera?.target||new w.Vector3(0,0,0),dynamicNear:e.camera?.dynamicNear??!0},lighting:{enableSunlight:e.lighting?.enableSunlight??!0,sunlightIntensity:e.lighting?.sunlightIntensity??1,sunlightPosition:e.lighting?.sunlightPosition||Ct(e.environment?.sceneUp??de,r.lightDistance,r.lightHeight),ambientLightColor:e.lighting?.ambientLightColor||new w.Color(4210752),ambientLightIntensity:e.lighting?.ambientLightIntensity??o.ambientIntensity,sunlightColor:e.lighting?.sunlightColor||16777215,enableHemisphereLight:e.lighting?.enableHemisphereLight??o.hemisphereIntensity>0,hemisphereSkyColor:e.lighting?.hemisphereSkyColor??14673663,hemisphereGroundColor:e.lighting?.hemisphereGroundColor??7036754,hemisphereIntensity:e.lighting?.hemisphereIntensity??o.hemisphereIntensity},environment:{hdrPath:e.environment?.hdrPath||"/baseHDR.hdr",backgroundColor:e.environment?.backgroundColor||new w.Color(15790320),enableEnvironmentLighting:e.environment?.enableEnvironmentLighting??!0,sceneUp:e.environment?.sceneUp||de,showEnvironment:e.environment?.showEnvironment??!1,environmentIntensity:e.environment?.environmentIntensity??o.environmentIntensity},floor:{enabled:e.floor?.enabled??!1,size:e.floor?.size||r.floorSize,color:e.floor?.color||new w.Color(8421504),roughness:e.floor?.roughness??.7,metalness:e.floor?.metalness??0,receiveShadow:e.floor?.receiveShadow??!0},render:{enableShadows:e.render?.enableShadows??!0,shadowMapSize:e.render?.shadowMapSize||2048,antialias:e.render?.antialias??!0,pixelRatio:e.render?.pixelRatio||Math.min(window.devicePixelRatio,2),toneMapping:e.render?.toneMapping??o.toneMapping,toneMappingExposure:e.render?.toneMappingExposure??o.toneMappingExposure,preserveDrawingBuffer:e.render?.preserveDrawingBuffer??!1,ambientOcclusion:e.render?.ambientOcclusion??o.ambientOcclusion,aoIntensity:e.render?.aoIntensity??1,aoPixelRatio:e.render?.aoPixelRatio??1,onDemand:e.render?.onDemand??!0},controls:{enableDamping:e.controls?.enableDamping??!1,dampingFactor:e.controls?.dampingFactor||.05,autoRotate:e.controls?.autoRotate??!1,autoRotateSpeed:e.controls?.autoRotateSpeed||.5,enableZoom:e.controls?.enableZoom??!0,enablePan:e.controls?.enablePan??!0,minDistance:e.controls?.minDistance||r.minDistance,maxDistance:e.controls?.maxDistance||1/0},grid:{enabled:e.grid?.enabled??!1,cellSize:e.grid?.cellSize??1,majorEvery:e.grid?.majorEvery??10,cellColor:e.grid?.cellColor??8947848,majorColor:e.grid?.majorColor??4473924,fadeDistance:e.grid?.fadeDistance??100,plane:e.grid?.plane??Xe(e.environment?.sceneUp??de)},gizmo:{enabled:e.gizmo?.enabled??!1},edges:{enabled:e.edges?.enabled??!1,color:e.edges?.color,darken:e.edges?.darken,width:e.edges?.width??1.5,thresholdAngle:e.edges?.thresholdAngle??44,distanceFade:e.edges?.distanceFade??!0},measure:{enabled:e.measure?.enabled??!1,snapPixels:e.measure?.snapPixels,color:e.measure?.color,labelClassName:e.measure?.labelClassName,displayUnit:e.measure?.displayUnit,format:e.measure?.format},events:{onBackgroundClicked:e.events?.onBackgroundClicked,onObjectSelected:e.events?.onObjectSelected,onMeshMetadataClicked:e.events?.onMeshMetadataClicked,onMeshDoubleClicked:e.events?.onMeshDoubleClicked,selectionColor:e.events?.selectionColor||"#ff0000",enableEventHandlers:e.events?.enableEventHandlers??!0,enableKeyboardControls:e.events?.enableKeyboardControls??!0,enableClickToFocus:e.events?.enableClickToFocus??!0,enableDoubleClickZoom:e.events?.enableDoubleClickZoom??!0,onReady:e.events?.onReady,onFrame:e.events?.onFrame}}}function Ne(e){for(let n of Object.values(e))n instanceof w.Texture&&n.dispose();e.dispose()}function io(e,n){if(n.isEmpty())return;let t=n.getCenter(new w.Vector3),r=n.getSize(new w.Vector3).length()*.5*1.2,a=e.shadow.camera;a.left=-r,a.right=r,a.top=r,a.bottom=-r,e.target.position.copy(t),e.target.updateMatrixWorld();let o=e.position.distanceTo(t);a.near=Math.max(r*.01,o-r),a.far=o+r,a.updateProjectionMatrix()}function so(e){let n=new w.Scene,t=typeof e.environment.backgroundColor=="string"?new w.Color(e.environment.backgroundColor):e.environment.backgroundColor;return n.background=t||null,n}function lo(e,n,t,r,a,o,i,l,s,c,u,d,p,T,v=!0){let R=null,m=performance.now(),g=!0,b=0,x=500,H=new w.Matrix4,E=new w.Matrix4,f=null,h=()=>{g=!0},y=O=>{O.updateMatrixWorld();let F=f!==O||!H.equals(O.matrixWorld)||!E.equals(O.projectionMatrix);return F&&(f=O,H.copy(O.matrixWorld),E.copy(O.projectionMatrix)),F},C=e.domElement,M=["pointerdown","pointerup","wheel"];if(v)for(let O of M)C.addEventListener(O,h,{passive:!0});let L=()=>{let{width:O,height:F}=i();if(O===0||F===0)return;let S=Math.floor(O*l),D=Math.floor(F*l);(e.domElement.width!==S||e.domElement.height!==D)&&(e.setPixelRatio(l),e.setSize(O,F,!1),t.aspect=O/F,t.updateProjectionMatrix(),a.updateAspect(O,F),d?.()?.setSize(O,F,l),p?.setSize(O,F),h())},I=function(){R=requestAnimationFrame(I);let O=performance.now(),F=(O-m)/1e3;m=O,L(),(o.enableDamping||o.autoRotate)&&o.update(),c&&c.update(r().position),u&&u.update(F),T&&T.update(),s?.(F);let S=r();if(v){if(!(g||y(S)||O-b>=x))return;g=!1,b=O}let D=d?.();D?(D.setCamera(S),D.render(F)):e.render(n,S),p&&p.render(n,S),u&&u.render(e)};return{animate:I,dispose:()=>{if(R!==null&&(cancelAnimationFrame(R),R=null),v)for(let O of M)C.removeEventListener(O,h)},invalidate:h}}function co(e,n,t,r){t.environment.enableEnvironmentLighting?new no().load(t.environment.hdrPath||"/baseHDR.hdr",function(a){if(r()){a.dispose();return}if(!a?.image){P().warn("HDR loaded without image data; skipping environment map."),a?.dispose(),t.events.onReady?.();return}a.mapping=w.EquirectangularReflectionMapping;let o=new w.PMREMGenerator(n);o.compileEquirectangularShader();let i=o.fromEquirectangular(a).texture;o.dispose(),e.environment=i,e.environmentIntensity=t.environment.environmentIntensity??1;let l=At(t.environment.sceneUp??de);e.environmentRotation.copy(l),t.environment.showEnvironment?(e.background=a,e.backgroundRotation.copy(l)):a.dispose(),t.events.onReady?.()},void 0,function(a){r()||(P().warn("HDR texture could not be loaded, falling back to basic lighting:",a),t.events.onReady?.())}):t.events.onReady?.()}function uo(e,n){let t=new w.AmbientLight(n.lighting.ambientLightColor,n.lighting.ambientLightIntensity);e.add(t);let r=null;if(n.lighting.enableHemisphereLight){r=new w.HemisphereLight(n.lighting.hemisphereSkyColor,n.lighting.hemisphereGroundColor,n.lighting.hemisphereIntensity);let i=n.environment.sceneUp??de;r.position.copy(i),e.add(r)}if(!n.lighting.enableSunlight)return{ambient:t,hemisphere:r,sun:null};let a=new w.DirectionalLight(n.lighting.sunlightColor??16777215,n.lighting.sunlightIntensity),o=n.lighting.sunlightPosition;return o&&a.position.set(o.x,o.y,o.z),n.render.enableShadows?(a.castShadow=!0,a.shadow.mapSize.width=n.render.shadowMapSize||2048,a.shadow.mapSize.height=n.render.shadowMapSize||2048,a.shadow.bias=-1e-4,a.shadow.normalBias=.02,a.shadow.radius=4,e.add(a),e.add(a.target),{ambient:t,hemisphere:r,sun:a}):(e.add(a),{ambient:t,hemisphere:r,sun:null})}function mo(e,n){let t=n.floor.size,r=new w.PlaneGeometry(t,t),a=typeof n.floor.color=="string"?new w.Color(n.floor.color):n.floor.color,o=new w.MeshStandardMaterial({color:a,roughness:n.floor.roughness,metalness:n.floor.metalness,side:w.DoubleSide}),i=new w.Mesh(r,o);i.userData.id="floor",i.name="floor";let l=(n.environment?.sceneUp||de).clone().normalize();i.quaternion.setFromUnitVectors(new w.Vector3(0,0,1),l),i.position.set(0,0,0),n.floor.receiveShadow&&n.render.enableShadows&&(i.receiveShadow=!0),e.add(i)}function fo(e,n){let t=n.parentElement,r=t?t.clientWidth:window.innerWidth,a=t?t.clientHeight:window.innerHeight,o=new w.PerspectiveCamera(e.camera.fov,r/a,e.camera.near,e.camera.far),i=e.camera.position;return i&&o.position.set(i.x,i.y,i.z),o}function po(e,n,t){let r=new w.WebGLRenderer({antialias:n.render.antialias,canvas:e,alpha:!0,powerPreference:"high-performance",preserveDrawingBuffer:n.render.preserveDrawingBuffer,logarithmicDepthBuffer:!1}),a=e.parentElement,o=a?a.clientWidth:window.innerWidth,i=a?a.clientHeight:window.innerHeight;return a&&(e.style.width="100%",e.style.height="100%",e.style.display="block"),r.setSize(o,i,!1),r.setPixelRatio(t),n.render.enableShadows&&(r.shadowMap.enabled=!0,r.shadowMap.type=w.VSMShadowMap),r.toneMapping=n.render.toneMapping,r.toneMappingExposure=n.render.toneMappingExposure??1,r.outputColorSpace=w.SRGBColorSpace,r.sortObjects=!0,r}function Eo(e,n,t,r){let a=new Set,o=new Map,i=new w.Raycaster,l=new w.Vector2,s=new w.Vector2,c=()=>t.getActiveCamera(),u=E=>{let f=E;for(;f;){if(!f.visible)return!1;f=f.parent}return!0},d=()=>{let E=ce(n);if(E.isEmpty()){P().warn("No objects to fit to view");return}t.frameBounds(E,!1)},p=typeof r.events.selectionColor=="string"?new w.Color(r.events.selectionColor):r.events.selectionColor instanceof w.Color?r.events.selectionColor:new w.Color("#ff0000"),T=()=>{a.forEach(E=>{let f=E;if(o.has(E)){let h=o.get(E),y=f.material;y instanceof w.Material?y.dispose():Array.isArray(y)&&y.forEach(M=>M.dispose()),f.material=h,o.delete(E);let C=E;for(;C.parent;)C=C.parent;C!==n&&(h instanceof w.Material?h.dispose():h.forEach(M=>M.dispose()))}}),a.clear()},v=E=>{let f=E;if(!(f.material instanceof w.Material))return!1;o.set(E,f.material);let h=f.material.clone();return E instanceof w.Mesh&&"emissive"in h?h.emissive=p.clone():"color"in h&&(h.color=p.clone()),f.material=h,!0},R=()=>{let E=ce(n),f=E.isEmpty()?1:E.getSize(new w.Vector3).length();i.params.Points.threshold=f*.01},m=E=>{s.set(E.clientX,E.clientY)},g=E=>{let f=new w.Vector2(E.clientX,E.clientY);if(s.distanceTo(f)>5)return;let h=e.getBoundingClientRect();l.x=(E.clientX-h.left)/h.width*2-1,l.y=-((E.clientY-h.top)/h.height)*2+1,R(),i.setFromCamera(l,c());let y=i.intersectObjects(n.children,!0).filter(C=>u(C.object));if(y.length>0){let C=y[0].object;a.has(C)||(T(),a.add(C),v(C),r.events?.onObjectSelected?.(C),C instanceof w.Mesh&&Object.keys(C.userData).length>0&&r.events?.onMeshMetadataClicked?.(C.userData))}else T(),r.events?.onBackgroundClicked?.({x:l.x,y:l.y})},b=E=>{let f=e.getBoundingClientRect();l.x=(E.clientX-f.left)/f.width*2-1,l.y=-((E.clientY-f.top)/f.height)*2+1,R(),i.setFromCamera(l,c());let h=i.intersectObjects(n.children,!0).filter(M=>u(M.object));if(h.length===0)return;let y=h[0].object;if(r.events?.onMeshDoubleClicked?.(y),!r.events?.enableDoubleClickZoom)return;let C=new w.Box3().setFromObject(y);C.isEmpty()||t.frameBounds(C,!0)},x=E=>{if(r.events?.enableKeyboardControls)switch(E.key.toLowerCase()){case"f":E.preventDefault(),d();break;case"escape":E.preventDefault(),T();break;case" ":E.preventDefault(),d();break}};return r.events?.enableClickToFocus&&(e.addEventListener("mousedown",m),e.addEventListener("click",g),e.addEventListener("dblclick",b)),r.events?.enableKeyboardControls&&(e.setAttribute("tabindex","0"),e.addEventListener("keydown",x)),{dispose:()=>{e.removeEventListener("mousedown",m),e.removeEventListener("click",g),e.removeEventListener("dblclick",b),e.removeEventListener("keydown",x),T()},fitToView:d,clearSelection:T}}function ho(e,n,t){let r=new to(e,n),a=t.camera.target;return a&&r.target.set(a.x,a.y,a.z),r.enableDamping=t.controls.enableDamping||!1,r.dampingFactor=t.controls.dampingFactor||.05,r.autoRotate=t.controls.autoRotate||!1,r.autoRotateSpeed=t.controls.autoRotateSpeed||.5,r.enableZoom=t.controls.enableZoom??!0,r.enablePan=t.controls.enablePan??!0,r.minDistance=t.controls.minDistance||.001,r.maxDistance=t.controls.maxDistance||1/0,r.screenSpacePanning=!1,r.maxPolarAngle=Math.PI,r.update(),r}var Di=["technical","studio","showcase"];import*as Q from"three";import{Line2 as go}from"three/addons/lines/Line2.js";import{LineGeometry as yo}from"three/addons/lines/LineGeometry.js";import{LineMaterial as bo}from"three/addons/lines/LineMaterial.js";function je(e,n,t,r=!0){return{x:e,y:n,z:t}}var To="#ffffff",an=12,Ro=4e-4,xo=12,vo=.05;function sn(e,n={}){if(!e||e.length===0)return[];let{rhino:t,applyTransforms:r=!0}=n,a=[];for(let o of e)switch(o.kind){case"curve":{let i=Mo(o,t,r);i&&a.push(i);break}case"point":{let i=Ho(o,r);i&&a.push(i);break}default:{let l=o;P().warn(`Skipping unknown display item kind: ${String(l.kind)}`);break}}return a}var wo=2;function Mo(e,n,t){if(!n)return P().warn("No rhino3dm instance provided; skipping curve display item."),null;let r=Co(e.json,n);if(!r)return null;let a;try{a=Ao(r,t)}catch(d){return P().warn("Failed to tessellate curve display item; skipping.",d),null}finally{Se(r)}if(a.length<2)return null;let o=[];for(let d of a)o.push(d.x,d.y,d.z);let i=new yo;i.setPositions(o);let l=ln(e.color,e.opacity),s=new bo({color:l.color}),c=s;c.linewidth=e.width??wo,c.transparent=l.transparent,c.opacity=l.opacity;let u=new go(i,s);return u.computeLineDistances(),u.name=e.name,u.userData={source:"compute",id:e.id,layer:e.layer,kind:"curve",metadata:e.metadata},u}function Ho(e,n){let{position:t}=e;if(!t||typeof t.X!="number"||!Number.isFinite(t.X)||typeof t.Y!="number"||!Number.isFinite(t.Y)||typeof t.Z!="number"||!Number.isFinite(t.Z))return P().warn(`Skipping point display item with missing or non-finite position (id: ${String(e.id)}).`),null;let{x:r,y:a,z:o}=je(t.X,t.Y,t.Z,n),i=new Q.BufferGeometry;i.setAttribute("position",new Q.Float32BufferAttribute([r,a,o],3));let l=new Q.PointsMaterial({...ln(e.color,e.opacity),size:6,sizeAttenuation:!1}),s=new Q.Points(i,l);return s.name=e.name,s.userData={source:"compute",id:e.id,layer:e.layer,kind:"point",metadata:e.metadata},s}function Se(e){e?.delete?.()}function Co(e,n){try{let t=JSON.parse(e),r=n.CommonObject.decode(t);return r&&typeof r.pointAt=="function"?r:(Se(r),P().warn("Decoded display-item JSON is not a curve; skipping."),null)}catch(t){return P().warn("Failed to decode curve display item JSON:",t),null}}function Ao(e,n){let t=So(e,n);return t||Do(e,n)}function So(e,n){if(!e.isPolyline())return null;let t=e.tryGetPolyline(),r=Array.isArray(t)?t[1]:t;if(!r||typeof r.count!="number"||r.count<2)return Se(r),null;let a=[];for(let o=0;o<r.count;o++){let i=r.get(o),{x:l,y:s,z:c}=je(i[0],i[1],i[2],n);a.push(new Q.Vector3(l,s,c))}return Se(r),a}function Do(e,n){let t=e.domain,r=t[0],o=t[1]-r,i=d=>{let p=e.pointAt(d),{x:T,y:v,z:R}=je(p[0],p[1],p[2],n);return new Q.Vector3(T,v,R)},l=Lo(e),s=r,c=i(r),u=[c];for(let d=0;d<an;d++){let p=r+o*(d+1)/an,T=i(p);it(s,c,p,T,i,l,xo,u),u.push(T),s=p,c=T}return u}function it(e,n,t,r,a,o,i,l){if(i<=0)return;let s=(e+t)/2,c=a(s),u=Io(c,n,r),d=Oo(n,c,r);u<=o&&d<=vo||(it(e,n,s,c,a,o,i-1,l),l.push(c),it(s,c,t,r,a,o,i-1,l))}function Lo(e){let n=e.getBoundingBox(),t=n.min,r=n.max;Se(n);let a=Math.hypot(r[0]-t[0],r[1]-t[1],r[2]-t[2]);return Math.max(a*Ro,1e-6)}function Oo(e,n,t){let r=n.x-e.x,a=n.y-e.y,o=n.z-e.z,i=t.x-n.x,l=t.y-n.y,s=t.z-n.z,c=Math.sqrt(r*r+a*a+o*o),u=Math.sqrt(i*i+l*l+s*s);if(c===0||u===0)return 0;let d=r*i+a*l+o*s,p=Math.max(-1,Math.min(1,d/(c*u)));return Math.acos(p)}function Io(e,n,t){let r=t.x-n.x,a=t.y-n.y,o=t.z-n.z,i=r*r+a*a+o*o;if(i===0)return e.distanceTo(n);let l=e.x-n.x,s=e.y-n.y,c=e.z-n.z,u=Math.max(0,Math.min(1,(l*r+s*a+c*o)/i)),d=l-r*u,p=s-a*u,T=c-o*u;return Math.sqrt(d*d+p*p+T*T)}function ln(e,n){let t=n??1;return{color:new Q.Color(e??To),transparent:t<1,opacity:t}}import{inflateSync as Po}from"fflate";var cn=1096174675,Fo=1515605075,un=3,dn=1,lt=1,Bo=2,ko=4,Uo=8,Vo=16,Gi=0,_o=1,mn=12,fn=56,zo=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;function ct(e){let n=ut(e),t;n.isFloat32?t=n.vertexData:n.deltaEncoded?t=Ko(n.vertexData):t=n.vertexData;let r=n.indexData;return n.deltaEncoded&&(r=r instanceof Uint16Array?Zo(r):Jo(r)),Xo(r,n.vertexCount),{metadata:n.metadata,flags:n.flags,vertices:t,indices:r,origin:n.origin,scale:n.scale,uvs:n.uvs,colors:n.colors}}function ut(e){if(!zo)throw new Re("SLVA parsing requires a little-endian host: the zero-copy geometry readers view the wire bytes in host byte order.",Te.ENVIRONMENT_ERROR);let n=Wo(jo(e)),t=new DataView(n.buffer,n.byteOffset,n.byteLength);if(n.byteLength<mn)throw X("Blob too small to contain SLVA header.",{expectedBytes:mn,availableBytes:n.byteLength});let r=0,a=t.getUint32(r,!0);if(r+=4,a!==cn)throw X(`Invalid SLVA magic: 0x${a.toString(16)}`,{expectedMagic:`0x${cn.toString(16)}`,actualMagic:`0x${a.toString(16)}`});let o=t.getUint32(r,!0);if(r+=4,o<dn||o>un)throw X(`Unsupported SLVA version: ${o}`,{minSupportedVersion:dn,maxSupportedVersion:un,actualVersion:o});let i=t.getUint32(r,!0);if(r+=4,r+i>n.byteLength)throw X("Insufficient data to read metadata JSON.",{expectedBytes:i,availableBytes:n.byteLength-r,offset:r});let l=n.subarray(r,r+i);r+=i;let s;try{s=JSON.parse($o(l))}catch(F){throw X(`Failed to parse metadata JSON: ${F instanceof Error?F.message:String(F)}`,{metadataLen:i})}if(r+fn>n.byteLength)throw X("Insufficient data to read geometry header.",{expectedBytes:fn,availableBytes:n.byteLength-r,offset:r});let c=t.getUint32(r,!0);r+=4;let u=t.getFloat64(r,!0);r+=8;let d=t.getFloat64(r,!0);r+=8;let p=t.getFloat64(r,!0);r+=8;let T=t.getFloat64(r,!0);r+=8;let v=t.getFloat64(r,!0);r+=8;let R=t.getFloat64(r,!0);r+=8;let m=t.getUint32(r,!0);r+=4;let g=(c&lt)!==0,b=(c&ko)!==0,x=m*3,E=x*(g?4:2);if(r+E>n.byteLength)throw X("Insufficient data to read vertices.",{expectedBytes:E,availableBytes:n.byteLength-r,offset:r,useFloat32:g,vertexCount:m});let f=n.byteOffset+r,h;if(g?h=En(n.buffer,f,x):b?h=st(n.buffer,f,x):h=qo(n.buffer,f,x),r+=E,r+4>n.byteLength)throw X("Insufficient data to read index count.",{expectedBytes:4,availableBytes:n.byteLength-r,offset:r});let y=t.getUint32(r,!0);r+=4;let C=(c&Bo)!==0,L=y*(C?2:4);if(r+L>n.byteLength)throw X("Insufficient data to read indices.",{expectedBytes:L,availableBytes:n.byteLength-r,offset:r,indexCount:y,useUint16Indices:C});let I=C?st(n.buffer,n.byteOffset+r,y):Yo(n.buffer,n.byteOffset+r,y);r+=L;let k=null;if((c&Uo)!==0){let F=Go(n,t,r,m,b);k=F.uvs,r=F.offset}let O=null;return(c&Vo)!==0&&(O=No(n,r,m,b)),{metadata:s,flags:c,vertexData:h,indexData:I,isFloat32:g,deltaEncoded:b,vertexCount:m,origin:[u,d,p],scale:[T,v,R],uvs:k,colors:O}}var pn=36;function Go(e,n,t,r,a){if(t+pn>e.byteLength)throw X("Insufficient data to read UV chunk header.",{expectedBytes:pn,availableBytes:e.byteLength-t,offset:t});let o=n.getUint32(t,!0);t+=4;let i=n.getFloat64(t,!0);t+=8;let l=n.getFloat64(t,!0);t+=8;let s=n.getFloat64(t,!0);t+=8;let c=n.getFloat64(t,!0);t+=8;let u=r*2,d=o===_o,p=u*(d?4:2);if(t+p>e.byteLength)throw X("Insufficient data to read UV chunk.",{expectedBytes:p,availableBytes:e.byteLength-t,offset:t,uvFormat:o,vertexCount:r});let T=e.byteOffset+t,v;if(d)v=En(e.buffer,T,u).slice();else{let R=st(e.buffer,T,u);v=new Float32Array(u);let m=0,g=0;for(let b=0;b<u;b+=2)a?(m=m+le(R[b])&65535,g=g+le(R[b+1])&65535):(m=R[b],g=R[b+1]),v[b]=i+m*s,v[b+1]=l+g*c}return{uvs:v,offset:t+p}}function No(e,n,t,r){let a=t*3;if(n+a>e.byteLength)throw X("Insufficient data to read vertex-color chunk.",{expectedBytes:a,availableBytes:e.byteLength-n,offset:n,vertexCount:t});let o=e.subarray(n,n+a);if(!r)return o.slice();let i=new Uint8Array(a),l=0,s=0,c=0;for(let u=0;u<a;u+=3)l=l+le(o[u])&255,s=s+le(o[u+1])&255,c=c+le(o[u+2])&255,i[u]=l,i[u+1]=s,i[u+2]=c;return i}function jo(e){return typeof e=="string"?bt(e):e instanceof Uint8Array?e:new Uint8Array(e)}function Wo(e){if(e.byteLength<8)return e;let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint32(0,!0)!==Fo)return e;let t=n.getUint32(4,!0),r=e.subarray(8),a=Math.max(r.byteLength*1032+1024,1<<20);if(t>a)throw X("SLVZ header declares an implausible uncompressed length",{uncompressedLen:t,deflatedBytes:r.byteLength,maxPlausibleLen:a});let o;try{o=Po(r,{out:new Uint8Array(t+1)})}catch(i){throw X(`Failed to inflate SLVZ blob: ${i instanceof Error?i.message:String(i)}`,{uncompressedLen:t,deflatedBytes:r.byteLength})}if(o.byteLength!==t)throw X("SLVZ payload inflated to a different size than the header declares.",{declaredLen:t,actualLen:o.byteLength,deflatedBytes:r.byteLength});return o}function $o(e){if(typeof TextDecoder<"u")return new TextDecoder("utf-8").decode(e);if(typeof globalThis.Buffer<"u")return globalThis.Buffer.from(e).toString("utf-8");throw new Re("No UTF-8 decoder available in this environment.",Te.INVALID_STATE)}function qo(e,n,t){if(t===0)return new Int16Array(0);if(n%2===0)return new Int16Array(e,n,t);let r=new Uint8Array(t*2);return r.set(new Uint8Array(e,n,t*2)),new Int16Array(r.buffer)}function En(e,n,t){if(t===0)return new Float32Array(0);if(n%4===0)return new Float32Array(e,n,t);let r=new Uint8Array(t*4);return r.set(new Uint8Array(e,n,t*4)),new Float32Array(r.buffer)}function st(e,n,t){if(t===0)return new Uint16Array(0);if(n%2===0)return new Uint16Array(e,n,t);let r=new Uint8Array(t*2);return r.set(new Uint8Array(e,n,t*2)),new Uint16Array(r.buffer)}function Yo(e,n,t){if(t===0)return new Uint32Array(0);if(n%4===0)return new Uint32Array(e,n,t);let r=new Uint8Array(t*4);return r.set(new Uint8Array(e,n,t*4)),new Uint32Array(r.buffer)}function Xo(e,n){if(e.length!==0&&!(e instanceof Uint16Array&&n>65535)){for(let t=0;t<e.length;t++)if(e[t]>=n)throw X("Index out of range of vertexCount.",{indexPosition:t,indexValue:e[t],vertexCount:n})}}function le(e){return e>>>1^-(e&1)}function Ko(e){let n=new Int16Array(e.length),t=0,r=0,a=0;for(let o=0;o<e.length;o+=3)t=t+le(e[o])<<16>>16,r=r+le(e[o+1])<<16>>16,a=a+le(e[o+2])<<16>>16,n[o]=t,n[o+1]=r,n[o+2]=a;return n}function Zo(e){let n=new Uint16Array(e.length),t=0;for(let r=0;r<e.length;r++)t=t+le(e[r])&65535,n[r]=t;return n}function Jo(e){let n=new Uint32Array(e.length),t=0;for(let r=0;r<e.length;r++)t=t+le(e[r])>>>0,n[r]=t;return n}function X(e,n){return new Re(e,Te.VALIDATION_ERROR,{context:n})}import*as V from"three";var hn=256*1024*1024,We=1024,me=new Map,dt=0;function gn(e,n){let t=2166136261,r=a=>{t^=a,t=Math.imul(t,16777619)};for(let a=0;a<n.length;a++)r(n.charCodeAt(a));for(let a of e){if(!a){r(57005);continue}let o=a.byteLength;if(r(o),(a.byteOffset&3)===0&&(o&3)===0){let i=new Uint32Array(a.buffer,a.byteOffset,o>>2),l=Math.min(We,i.length);for(let s=0;s<l;s++)r(i[s]);for(let s=Math.max(l,i.length-We);s<i.length;s++)r(i[s])}else{let i=new Uint8Array(a.buffer,a.byteOffset,o),l=Math.min(We*4,i.length);for(let s=0;s<l;s++)r(i[s]);for(let s=Math.max(l,i.length-We*4);s<i.length;s++)r(i[s])}}return`${(t>>>0).toString(36)}:${e.length}`}function Qo(e){let n=e.index?.array.byteLength??0;for(let t of Object.values(e.attributes))n+=t.array.byteLength;return n}function $e(e){let n=me.get(e);if(n)return me.delete(e),me.set(e,n),n.geometry}function qe(e,n){let t=Qo(n);if(!(t>hn||(n.userData[Ie]=!0,me.get(e))))for(me.set(e,{geometry:n,bytes:t}),dt+=t;dt>hn&&me.size>1;){let a=me.keys().next().value,o=me.get(a);me.delete(a),dt-=o.bytes,delete o.geometry.userData[Ie],o.geometry.dispose()}}function ea(e){let{isFloat32:n,deltaEncoded:t,origin:r,scale:a,uvs:o,colors:i,jobs:l}=e,s=m=>m>>>1^-(m&1),c;if(n)c=e.vertexData;else{let m;if(t){let h=e.vertexData;m=new Int16Array(h.length);let y=0,C=0,M=0;for(let L=0;L<h.length;L+=3)y=y+s(h[L])<<16>>16,C=C+s(h[L+1])<<16>>16,M=M+s(h[L+2])<<16>>16,m[L]=y,m[L+1]=C,m[L+2]=M}else m=e.vertexData;c=new Float32Array(m.length);let g=r[0],b=r[1],x=r[2],H=a[0],E=a[1],f=a[2];for(let h=0;h<m.length;h+=3)c[h]=g+(m[h]+32767)*H,c[h+1]=b+(m[h+1]+32767)*E,c[h+2]=x+(m[h+2]+32767)*f}let u;if(t){let m=e.indexData;if(m instanceof Uint16Array){let g=new Uint16Array(m.length),b=0;for(let x=0;x<m.length;x++)b=b+s(m[x])&65535,g[x]=b;u=g}else{let g=new Uint32Array(m.length),b=0;for(let x=0;x<m.length;x++)b=b+s(m[x])>>>0,g[x]=b;u=g}}else u=e.indexData;let d=c.length/3;for(let m=0;m<u.length;m++)if(u[m]>=d)throw new Error(`Index ${u[m]} out of range of vertexCount ${d}`);let p=1024,T=(m,g)=>{let b=2166136261,x=H=>{b^=H,b=Math.imul(b,16777619)};for(let H=0;H<g.length;H++)x(g.charCodeAt(H));for(let H of m){if(!H){x(57005);continue}let E=H.byteLength;if(x(E),(H.byteOffset&3)===0&&(E&3)===0){let f=new Uint32Array(H.buffer,H.byteOffset,E>>2),h=Math.min(p,f.length);for(let y=0;y<h;y++)x(f[y]);for(let y=Math.max(h,f.length-p);y<f.length;y++)x(f[y])}else{let f=new Uint8Array(H.buffer,H.byteOffset,E),h=Math.min(p*4,f.length);for(let y=0;y<h;y++)x(f[y]);for(let y=Math.max(h,f.length-p*4);y<f.length;y++)x(f[y])}}return`${(b>>>0).toString(36)}:${m.length}`},v=(m,g)=>{let b=[],x=m;for(let H of g){x+=`|${H.vertexStart},${H.vertexCount},${H.indexStart},${H.indexCount}`;let E=H.vertexStart*3,f=E+H.vertexCount*3;b.push(c.subarray(E,f)),b.push(u.subarray(H.indexStart,H.indexStart+H.indexCount)),b.push(o?o.subarray(H.vertexStart*2,(H.vertexStart+H.vertexCount)*2):null),b.push(i?i.subarray(E,f):null)}return T(b,x)},R=[];for(let m of l){let g=0,b=0;for(let M of m.windows)g+=M.vertexCount,b+=M.indexCount;let x=new Float32Array(g*3),H=new Uint32Array(b),E=o?new Float32Array(g*2):null,f=i?new Uint8Array(g*3):null,h=0,y=0;for(let M of m.windows){let L=M.vertexStart*3;x.set(c.subarray(L,L+M.vertexCount*3),h*3),E&&o&&E.set(o.subarray(M.vertexStart*2,(M.vertexStart+M.vertexCount)*2),h*2),f&&i&&f.set(i.subarray(L,L+M.vertexCount*3),h*3);let I=M.vertexStart,k=M.vertexStart+M.vertexCount,O=h-M.vertexStart;for(let F=0;F<M.indexCount;F++){let S=u[M.indexStart+F];if(S<I||S>=k)throw new Error(`Index ${S} outside vertex window [${I}, ${k})`);H[y+F]=S+O}h+=M.vertexCount,y+=M.indexCount}let C=new Float32Array(g*3);for(let M=0;M<H.length;M+=3){let L=H[M]*3,I=H[M+1]*3,k=H[M+2]*3,O=x[k]-x[I],F=x[k+1]-x[I+1],S=x[k+2]-x[I+2],D=x[L]-x[I],G=x[L+1]-x[I+1],_=x[L+2]-x[I+2],q=F*_-S*G,Y=S*D-O*_,fe=O*G-F*D;C[L]+=q,C[L+1]+=Y,C[L+2]+=fe,C[I]+=q,C[I+1]+=Y,C[I+2]+=fe,C[k]+=q,C[k+1]+=Y,C[k+2]+=fe}for(let M=0;M<C.length;M+=3){let L=C[M],I=C[M+1],k=C[M+2],O=Math.sqrt(L*L+I*I+k*k)||1;C[M]=L/O,C[M+1]=I/O,C[M+2]=k/O}R.push({key:v(m.kind,m.windows),positions:x,normals:C,indices:H,uvs:E,colors:f})}return R}function yn(){return[`const assemble = ${ea.toString()};`,"self.onmessage = (event) => {"," const { id, input } = event.data;"," try {"," const geometries = assemble(input);"," const transfer = [];"," for (const g of geometries) {"," transfer.push(g.positions.buffer, g.normals.buffer, g.indices.buffer);"," if (g.uvs) transfer.push(g.uvs.buffer);"," if (g.colors) transfer.push(g.colors.buffer);"," }"," self.postMessage({ id, geometries }, transfer);"," } catch (error) {"," self.postMessage({ id, error: String((error && error.message) || error) });"," }","};"].join(`
112
- `)}async function es(e,n){let{debug:t=!1}=n??{},r=t?performance.now():0,a,o=performance.now();try{a=JSON.parse(e)}catch(l){return P().error("Error parsing mesh batch envelope JSON:",l),[]}let i=performance.now()-o;return await mt(a,n,{parseTime:i,perfStart:r})}async function mt(e,n,t){let{mergeByMaterial:r=!0,applyTransforms:a=!0,debug:o=!1,material:i}=n??{},{parseTime:l=0,perfStart:s=o?performance.now():0}=t??{};if(!e.compressedData)return[];let c=await vn(e.compressedData,{mergeByMaterial:r,applyTransforms:a,debug:o,material:i,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}});if(c)return c;let u=performance.now(),d=ct(e.compressedData),p=performance.now()-u,T=o?fa(e.compressedData):0;return bn(d,{mergeByMaterial:r,applyTransforms:a,debug:o,material:i,parseTime:l,decodeTime:p,perfStart:s,blobBytes:T,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}})}async function ts(e,n){let{mergeByMaterial:t=!0,applyTransforms:r=!0,debug:a=!1,material:o}=n??{},i=a?performance.now():0,l=await vn(e,{mergeByMaterial:t,applyTransforms:r,debug:a,material:o});if(l)return l;let s=performance.now(),c=ct(e),u=performance.now()-s,d=e.byteLength;return bn(c,{mergeByMaterial:t,applyTransforms:r,debug:a,material:o,parseTime:0,decodeTime:u,perfStart:i,blobBytes:d})}function bn(e,n){let{mergeByMaterial:t,applyTransforms:r,debug:a,material:o,parseTime:i,decodeTime:l,perfStart:s,blobBytes:c,fallback:u}=n,d=e.metadata.materials??u?.materials??[],p=e.metadata.groups??u?.groups??[],T=u?.sourceComponentId??e.metadata.sourceComponentId,v=(e.flags&lt)!==0;Tn(p,d.length,e.vertices.length/3,e.indices.length);let R=v?na(e.vertices,r):ta(e.vertices,e.origin,e.scale,r);if(a){let H=e.vertices.byteLength+e.indices.byteLength;P().debug("Mesh Batch Stats:"),P().debug(` Materials: ${d.length} | Groups: ${p.length}`),P().debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),P().debug(` Format: ${v?"float32":"int16 quantized"}`),P().debug(` Blob: ${(c/1024/1024).toFixed(2)} MB | Geometry on wire: ${(H/1024/1024).toFixed(2)} MB`)}let m=performance.now(),g=d.map(H=>wn(H,{vertexColors:e.colors!=null,appearance:o})),b=[];for(let H of p)if(t&&H.meshes.length>1){let E=da(H,R,e.indices,g,e.uvs,e.colors);E.userData.sourceComponentId=T??null,b.push(E)}else{let E=ma(H,R,e.indices,g,e.uvs,e.colors);for(let f of E)f.userData.sourceComponentId=T??null;b.push(...E)}let x=performance.now()-m;if(a){let H=performance.now()-s;P().debug("Performance:"),i>0&&P().debug(` Parse JSON: ${i.toFixed(2)}ms`),P().debug(` Decode binary: ${l.toFixed(2)}ms`),P().debug(` Create Meshes: ${x.toFixed(2)}ms`),P().debug(` Total: ${H.toFixed(2)}ms`)}return Promise.resolve(b)}function De(e,n){return new Re(e,Te.VALIDATION_ERROR,{context:n})}function Tn(e,n,t,r){for(let a of e){if(!Number.isInteger(a.materialId)||a.materialId<0||a.materialId>=n)throw De("Group materialId out of range of the materials array.",{materialId:a.materialId,materialCount:n});for(let o of a.meshes){let i={vertexStart:o.vertexStart,vertexCount:o.vertexCount,indexStart:o.indexStart,indexCount:o.indexCount};for(let[l,s]of Object.entries(i))if(!Number.isInteger(s)||s<0)throw De(`Mesh metadata field "${l}" must be a non-negative integer.`,{meshName:o.name,field:l,value:s});if(o.vertexStart+o.vertexCount>t)throw De("Mesh vertex window exceeds the batch vertex buffer.",{meshName:o.name,vertexStart:o.vertexStart,vertexCount:o.vertexCount,totalVertexCount:t});if(o.indexStart+o.indexCount>r)throw De("Mesh index window exceeds the batch index buffer.",{meshName:o.name,indexStart:o.indexStart,indexCount:o.indexCount,totalIndexCount:r})}}}function Rn(e,n){return De("Index references a vertex outside its mesh's vertex window.",{meshName:n.name,indexValue:e,vertexStart:n.vertexStart,vertexCount:n.vertexCount})}function xn(e,n,t,r,a,o){let i=[],l=e;for(let s of n){l+=`|${s.vertexStart},${s.vertexCount},${s.indexStart},${s.indexCount}`;let c=s.vertexStart*3,u=c+s.vertexCount*3;i.push(t.subarray(c,u)),i.push(r.subarray(s.indexStart,s.indexStart+s.indexCount)),i.push(a?a.subarray(s.vertexStart*2,(s.vertexStart+s.vertexCount)*2):null),i.push(o?o.subarray(c,u):null)}return gn(i,l)}function ta(e,n,t,r){let a=new Float32Array(e.length),o=n[0],i=n[1],l=n[2],s=t[0],c=t[1],u=t[2];for(let d=0;d<e.length;d+=3)a[d]=o+(e[d]+32767)*s,a[d+1]=i+(e[d+1]+32767)*c,a[d+2]=l+(e[d+2]+32767)*u;return a}function na(e,n){return e}var ra=5e4,be,Le=new Map,oa=1;function aa(){if(be!==void 0)return be;if(typeof Worker>"u"||typeof Blob>"u"||typeof URL>"u"||typeof URL.createObjectURL!="function")return be=null,null;try{let e=URL.createObjectURL(new Blob([yn()],{type:"text/javascript"})),n=new Worker(e);n.onmessage=t=>{let{id:r,geometries:a,error:o}=t.data,i=Le.get(r);i&&(Le.delete(r),a?i.resolve(a):i.reject(new Error(o??"mesh assembly failed in worker")))},n.onerror=()=>{for(let t of Le.values())t.reject(new Error("mesh assembly worker crashed"));Le.clear(),n.terminate(),be=null},be=n}catch{be=null}return be}function ia(e,n,t){return new Promise((r,a)=>{let o=oa++;Le.set(o,{resolve:r,reject:a}),e.postMessage({id:o,input:n},t)})}async function vn(e,n){if(typeof Worker>"u")return null;let t=ut(e);if(t.indexData.length/3<ra)return null;let r=aa();if(!r)return null;let a=t.metadata.materials??n.fallback?.materials??[],o=t.metadata.groups??n.fallback?.groups??[],i=n.fallback?.sourceComponentId??t.metadata.sourceComponentId;Tn(o,a.length,t.vertexCount,t.indexData.length);let l=m=>({vertexStart:m.vertexStart,vertexCount:m.vertexCount,indexStart:m.indexStart,indexCount:m.indexCount}),s=[],c=[];for(let m of o)if(n.mergeByMaterial&&m.meshes.length>1)s.push({kind:"merged",windows:m.meshes.map(l)}),c.push({kind:"merged",group:m});else for(let g of m.meshes)s.push({kind:"single",windows:[l(g)]}),c.push({kind:"single",group:m,meshMeta:g});let u=t.vertexData.slice(),d=t.indexData.slice(),p=[u.buffer,d.buffer];t.uvs&&p.push(t.uvs.buffer),t.colors&&p.push(t.colors.buffer);let T;try{T=await ia(r,{vertexData:u,isFloat32:t.isFloat32,deltaEncoded:t.deltaEncoded,origin:t.origin,scale:t.scale,indexData:d,uvs:t.uvs,colors:t.colors,jobs:s},p)}catch(m){return P().warn("Mesh assembly worker failed; falling back to main-thread parse.",m),null}if(T.length!==s.length)return null;let v=a.map(m=>wn(m,{vertexColors:t.colors!=null,appearance:n.material})),R=[];for(let m=0;m<T.length;m++){let g=T[m],b=c[m],x=$e(g.key);x||(x=new V.BufferGeometry,x.setAttribute("position",new V.BufferAttribute(g.positions,3)),x.setAttribute("normal",new V.BufferAttribute(g.normals,3)),x.setIndex(new V.BufferAttribute(g.indices,1)),g.uvs&&x.setAttribute("uv",new V.BufferAttribute(g.uvs,2)),g.colors&&x.setAttribute("color",new V.BufferAttribute(g.colors,3,!0)),qe(g.key,x));let H=b.kind==="merged"?Mn(x,b.group,v):Hn(x,b.meshMeta,b.group,v);H.userData.sourceComponentId=i??null,R.push(H)}return n.debug&&P().debug(`Mesh batch assembled off-thread: ${R.length} meshes, ${t.indexData.length/3} triangles`),R}var sa=.5,la=.5,ca=.3;function wn(e,n){let t=St(e.color),r=n?.vertexColors??!1,a=n?.appearance,o=new V.MeshPhysicalMaterial({color:t,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,vertexColors:r,side:a?.cullBackfaces?V.FrontSide:V.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.5,polygonOffsetUnits:.5,depthWrite:!0,depthTest:!0});return a?.envMapIntensity!=null&&(o.envMapIntensity=a.envMapIntensity),e.metalness>sa&&(o.clearcoat=la,o.clearcoatRoughness=ca),r&&ua(o),e.map&&rn(o,e.map),o}function ua(e){e.onBeforeCompile=n=>{n.vertexShader=n.vertexShader.replace("#include <color_vertex>",`#include <color_vertex>
110
+ `},Ue=class extends Sr{constructor(t,r,a,o,i={}){super();re(this,"camera");re(this,"scene");re(this,"normalMaterial");re(this,"edgeMaterial");re(this,"fsQuad");re(this,"normalTarget",null);re(this,"width");re(this,"height");this.scene=t,this.camera=r,this.width=Math.max(1,a),this.height=Math.max(1,o),this.normalMaterial=new N.MeshNormalMaterial,this.normalMaterial.blending=N.NoBlending,this.edgeMaterial=new N.ShaderMaterial({uniforms:N.UniformsUtils.clone(ot.uniforms),vertexShader:ot.vertexShader,fragmentShader:ot.fragmentShader});let l=this.edgeMaterial.uniforms;l.uColor.value=new N.Color(i.color??2236962),l.uOpacity.value=i.opacity??1,l.uNormalThreshold.value=i.normalThreshold??.4,l.uDepthThreshold.value=i.depthThreshold??.02,l.uThickness.value=i.thickness??1,this.fsQuad=new Dr(this.edgeMaterial),this.needsSwap=!0}acquireNormalTarget(){if(!this.normalTarget){let t=new N.DepthTexture(this.width,this.height);this.normalTarget=new N.WebGLRenderTarget(this.width,this.height,{minFilter:N.NearestFilter,magFilter:N.NearestFilter,depthTexture:t})}return this.normalTarget}setSize(t,r){this.width=Math.max(1,t),this.height=Math.max(1,r),this.normalTarget?.setSize(this.width,this.height)}render(t,r,a){let o=this.acquireNormalTarget(),i=t.getRenderTarget(),l=t.autoClear,s=t.getClearColor(new N.Color),c=t.getClearAlpha(),u=this.scene.overrideMaterial;t.setRenderTarget(o),t.setClearColor(7829503,1),t.autoClear=!0,this.scene.overrideMaterial=this.normalMaterial,t.render(this.scene,this.camera),this.scene.overrideMaterial=u,t.setClearColor(s,c),t.autoClear=l;let d=this.edgeMaterial.uniforms;d.tDiffuse.value=a.texture,d.tNormal.value=o.texture,d.tDepth.value=o.depthTexture,d.uResolution.value.set(this.width,this.height);let p=this.camera;d.uPerspective.value=p.isPerspectiveCamera?1:0,d.uNear.value=this.camera.near??.1,d.uFar.value=this.camera.far??1e3,t.setRenderTarget(this.renderToScreen?null:r),this.fsQuad.render(t),t.setRenderTarget(i)}dispose(){this.normalTarget?.dispose(),this.normalMaterial.dispose(),this.edgeMaterial.dispose(),this.fsQuad.dispose()}};import{EffectComposer as Lr}from"three/addons/postprocessing/EffectComposer.js";import{RenderPass as Or}from"three/addons/postprocessing/RenderPass.js";import{GTAOPass as Ir}from"three/addons/postprocessing/GTAOPass.js";import{SMAAPass as Pr}from"three/addons/postprocessing/SMAAPass.js";import{OutputPass as Fr}from"three/addons/postprocessing/OutputPass.js";function Xt(e,n,t,r,a,o){let i=new Lr(e),l=new Or(n,t);i.addPass(l);let s=null;(o.ambientOcclusion??!0)&&(s=new Ir(n,t,r,a),s.blendIntensity=o.aoIntensity??1,s.updateGtaoMaterial({screenSpaceRadius:!0}),i.addPass(s));let c=typeof o.edgeDetection=="object"?o.edgeDetection:{},u=new Ue(n,t,r,a,c);u.enabled=!!o.edgeDetection,i.addPass(u);let d=new Pr;i.addPass(d);let p=new Fr;i.addPass(p),e.toneMapping=o.toneMapping,e.toneMappingExposure=o.toneMappingExposure;let T=o.aoPixelRatio??1;return i.setSize(r,a),{render:v=>i.render(v),setSize:(v,R,m)=>{i.setPixelRatio(Math.min(m,T)),i.setSize(v,R)},setCamera:v=>{if(l.camera=v,u.camera=v,!s)return;s.camera=v;let R=v.isPerspectiveCamera?1:0;s.gtaoMaterial.defines.PERSPECTIVE_CAMERA!==R&&(s.gtaoMaterial.defines.PERSPECTIVE_CAMERA=R,s.gtaoMaterial.needsUpdate=!0)},setEdgeDetection:v=>{u.enabled=v},edgeDetectionEnabled:()=>u.enabled,dispose:()=>{i.dispose(),s?.dispose(),u.dispose(),d.dispose(),p.dispose()}}}import*as Kt from"three";import{CSS2DRenderer as Br,CSS2DObject as kr}from"three/addons/renderers/CSS2DRenderer.js";function Zt(e,n){let t=new Br,r=t.domElement;r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.overflow="hidden",r.style.pointerEvents="none",r.style.zIndex="30",getComputedStyle(e).position==="static"&&(e.style.position="relative"),e.appendChild(r);let a={width:e.clientWidth||1,height:e.clientHeight||1};t.setSize(a.width,a.height);let o=new Kt.Group;o.name="label-layer",o.userData.id="label-layer",n.add(o);let i=new Set;return{addLabel:(s,c,u)=>{let d=document.createElement("div");d.textContent=s,u?d.className=u:Object.assign(d.style,{padding:"2px 6px",borderRadius:"4px",background:"rgba(20, 20, 20, 0.78)",color:"#fff",font:"12px/1.3 system-ui, sans-serif",whiteSpace:"pre",textAlign:"center",userSelect:"none"}),d.style.pointerEvents="none";let p=new kr(d);return p.position.copy(c),o.add(p),i.add(p),{object:p,setPosition:T=>p.position.copy(T),setText:T=>{d.textContent=T},remove:()=>{p.removeFromParent(),d.remove(),i.delete(p)}}},render:(s,c)=>t.render(s,c),setSize:(s,c)=>t.setSize(s,c),dispose:()=>{i.forEach(s=>{s.removeFromParent(),s.element.remove()}),i.clear(),o.removeFromParent(),r.remove()}}}import*as U from"three";import{Line2 as Ur}from"three/addons/lines/Line2.js";import{LineGeometry as _r}from"three/addons/lines/LineGeometry.js";import{LineMaterial as Vr}from"three/addons/lines/LineMaterial.js";var zr=12,Gr=16763904,Jt=.015,Qt={Millimeters:{metersPerUnit:1/1e3,suffix:"mm"},Centimeters:{metersPerUnit:1/100,suffix:"cm"},Meters:{metersPerUnit:1,suffix:"m"},Inches:{metersPerUnit:1/39.37,suffix:"in"},Feet:{metersPerUnit:1/3.28084,suffix:"ft"}};function Nr(e){let n=e&&Qt[e]||Qt.Meters;return t=>`${(t/n.metersPerUnit).toPrecision(3)} ${n.suffix}`}function jr(e,n){if(e.isOrthographicCamera){let r=e;return Math.abs(r.top-r.bottom)/(r.zoom||1)*Jt}return((n?e.position.distanceTo(n):e.position.length())||1)*Jt}function Wr(e){let n=e.object;if(n instanceof U.Mesh)return e.face?[e.face.a,e.face.b,e.face.c]:null;if(n instanceof U.Points)return e.index!=null?[e.index]:null;if(n instanceof U.Line){if(e.index==null)return null;let t=n.geometry.index;return t?e.index+1>=t.count?null:[t.getX(e.index),t.getX(e.index+1)]:[e.index,e.index+1]}return null}function $r(e,n,t,r){let a=e.point.clone(),o=e.object,i=Wr(e);if(!i||!o.geometry)return a;let l=o.geometry.attributes.position;if(!l)return a;let s=p=>{let T=p.clone().project(n);return new U.Vector2((T.x+1)/2*t.width,(1-T.y)/2*t.height)},c=s(a),u=a,d=r;for(let p of i){if(p>=l.count)continue;let v=new U.Vector3().fromBufferAttribute(l,p).applyMatrix4(o.matrixWorld),R=s(v).distanceTo(c);R<d&&(d=R,u=v)}return u}function en(e){let{canvas:n,scene:t,getActiveCamera:r,getViewTarget:a,labelLayer:o,options:i={}}=e,l=i.snapPixels??zr,s=new U.Color(i.color??Gr),c=Nr(i.displayUnit),u=(S,D)=>`${c(S)}
111
+ \u0394x ${c(D.x)} \u0394y ${c(D.y)} \u0394z ${c(D.z)}`,d=i.format??u,p=new U.Raycaster,T=new U.Vector2,v=!1,R=[],m=[],g=null,b=null,x=new U.PointsMaterial({color:s,size:8,sizeAttenuation:!1,depthTest:!1}),H=new U.PointsMaterial({color:s,size:11,sizeAttenuation:!1,depthTest:!1,transparent:!0,opacity:.5}),E=null,f=S=>{if(!S){E&&(E.visible=!1);return}if(!E){let D=new U.BufferGeometry;D.setAttribute("position",new U.Float32BufferAttribute([0,0,0],3)),E=new U.Points(D,H),E.renderOrder=1e3,E.userData.id="measure",E.raycast=()=>{},t.add(E)}E.position.copy(S),E.visible=!0},h=S=>{let D=new U.BufferGeometry;D.setAttribute("position",new U.Float32BufferAttribute([S.x,S.y,S.z],3));let G=new U.Points(D,x);return G.renderOrder=999,G.userData.id="measure",G.raycast=()=>{},t.add(G),G},y=()=>{R.length=0,m.forEach(S=>{S.geometry.dispose(),S.removeFromParent()}),m.length=0,g&&(g.geometry.dispose(),g.material.dispose(),g.removeFromParent(),g=null),b?.remove(),b=null},C=()=>{if(R.length!==2)return;let[S,D]=R,G=new _r;G.setPositions([S.x,S.y,S.z,D.x,D.y,D.z]);let V=new Vr({color:s});V.linewidth=2,V.depthTest=!1,g=new Ur(G,V),g.renderOrder=998,g.userData.id="measure",g.raycast=()=>{},t.add(g);let q=S.clone().add(D).multiplyScalar(.5),Y=new U.Vector3(Math.abs(D.x-S.x),Math.abs(D.y-S.y),Math.abs(D.z-S.z));b=o.addLabel(d(S.distanceTo(D),Y),q,i.labelClassName)},M=S=>{let D=n.getBoundingClientRect();T.x=(S.clientX-D.left)/D.width*2-1,T.y=-((S.clientY-D.top)/D.height)*2+1;let G=r();p.setFromCamera(T,G);let V=jr(G,a?.());p.params.Line.threshold=V,p.params.Points.threshold=V;let q=p.intersectObjects(t.children,!0).filter(Y=>Y.object.userData.id!=="measure"&&Y.object.userData.id!=="grid");return q.length===0?null:$r(q[0],G,{width:D.width,height:D.height},l)},L=null,I=0,k=()=>{I&&(cancelAnimationFrame(I),I=0),L=null};return{setEnabled:S=>{v=S,S||(k(),y(),f(null))},isEnabled:()=>v,handleClick:S=>{if(!v)return!1;R.length===2&&y();let D=M(S);return D===null||(R.push(D),m.push(h(D)),R.length===2&&C()),!0},handleMove:S=>{v&&(L=S,!I&&(I=requestAnimationFrame(()=>{I=0;let D=L;L=null,!(!v||!D)&&f(M(D))})))},clear:y,dispose:()=>{k(),y(),E&&(E.geometry.dispose(),E.removeFromParent(),E=null),x.dispose(),H.dispose()}}}import*as Ge from"three";var qr=64,Yr=256,ae=new Map,Ce=new Map,_e=0,ze=class extends Error{constructor(n){super(`Texture load for ${n} resolved after clearTextureCache(); texture disposed.`),this.name="StaleTextureLoadError"}},Ve=1;function tn(e){Ve=Math.max(1,e);for(let n of ae.values())n.anisotropy!==Ve&&(n.anisotropy=Ve,n.needsUpdate=!0)}function nn(e,n){let t=Xr(n),r=ae.get(t);if(r){ae.delete(t),ae.set(t,r),e.map=r,e.needsUpdate=!0;return}typeof document>"u"||Jr(n,t).then(a=>{e.map=a,e.needsUpdate=!0}).catch(a=>{a instanceof ze||P().warn(`Failed to load material texture ${n}:`,a)})}function mi(){_e++;for(let e of ae.values())e.dispose();ae.clear(),Ce.clear()}function Xr(e){return e.length<=Yr?e:`data-uri:${Kr(e).toString(16)}:${e.length}`}function Kr(e){let n=2166136261;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619);return n>>>0}function Zr(e,n){for(ae.set(e,n);ae.size>qr;){let t=ae.keys().next().value,r=ae.get(t);ae.delete(t),r.dispose()}}function Jr(e,n){let t=Ce.get(n);if(!t){let r=_e;t=new Promise((a,o)=>{new Ge.TextureLoader().load(e,i=>{if(r!==_e){i.dispose(),o(new ze(e));return}i.colorSpace=Ge.SRGBColorSpace,i.anisotropy=Ve,Zr(n,i),Ce.delete(n),a(i)},void 0,i=>{r===_e&&Ce.delete(n),o(i)})}),Ce.set(n,t)}return t}import*as w from"three";import{OrbitControls as ro}from"three/addons/controls/OrbitControls.js";import{HDRLoader as oo}from"three/addons/loaders/HDRLoader.js";import*as Ae from"three";var Qr=.5,eo=.01,to=.05,no=[];function rn({camera:e,scene:n,groundNormals:t=()=>no}){let r=e.near,a=e.near,o=new Ae.Vector3,i=new Ae.Vector3;return{update:()=>{e.near!==a&&(r=e.near);let s=ce(n),c=r;if(!s.isEmpty()){let u=s.getSize(i).length()*.5,d=e.position.distanceTo(s.getCenter(o))-u;for(let p of t())d=Math.min(d,Math.abs(e.position.dot(p)));c=Ae.MathUtils.clamp(d*Qr,r,e.far*eo)}Math.abs(c-a)>a*to&&(e.near=c,e.updateProjectionMatrix(),a=c)}}}var de=new w.Vector3(0,0,1),ao="technical",at={studio:{toneMapping:w.ACESFilmicToneMapping,toneMappingExposure:1,envMapIntensity:1,environmentIntensity:1,hemisphereIntensity:.75,ambientIntensity:.4,cullBackfaces:!1,ambientOcclusion:!1},technical:{toneMapping:w.NeutralToneMapping,toneMappingExposure:1,envMapIntensity:.9,environmentIntensity:1,hemisphereIntensity:.35,ambientIntensity:.25,cullBackfaces:!1,ambientOcclusion:!1},showcase:{toneMapping:w.ACESFilmicToneMapping,toneMappingExposure:1.15,envMapIntensity:1.4,environmentIntensity:1.25,hemisphereIntensity:.35,ambientIntensity:.15,cullBackfaces:!1,ambientOcclusion:!1}};function io(e){let n=at[e];return{envMapIntensity:n.envMapIntensity,cullBackfaces:n.cullBackfaces}}var Di=function(e,n){let t=so(n||{}),r=t.environment?.sceneUp||de,a=t.render.pixelRatio??Math.min(window.devicePixelRatio,2),o=co(t),i=Eo(t,e);i.up.copy(r);let l=ho(e,t,a);tn(l.capabilities.getMaxAnisotropy());let s=yo(i,e,t),c=Lt({scene:o,perspective:i,controls:s,onActiveCameraChange:()=>{},up:r}),u=()=>c.getActiveCamera(),d=!1;mo(o,l,t,()=>d);let p=fo(o,t),T=p.sun,v=()=>{T&&lo(T,ce(o))};t.floor?.enabled&&po(o,t);let R=t.floor?.enabled?o.children.find(A=>A.userData.id==="floor")??null:null,m=t.grid.enabled?Ot({cellSize:t.grid.cellSize,majorEvery:t.grid.majorEvery,cellColor:t.grid.cellColor,majorColor:t.grid.majorColor,fadeDistance:t.grid.fadeDistance,plane:t.grid.plane}):null;m&&o.add(m.object);let g=()=>{m&&m.fitToContent(ce(o))},b=t.gizmo.enabled?It({camera:i,domElement:e,controller:c}):null,x=t.grid.plane??Xe(r),H=new w.Vector3(x==="x"?1:0,x==="y"?1:0,x==="z"?1:0),E=r.clone().normalize(),f=()=>{let A=[];return m?.object.visible&&A.push(H),t.floor.enabled&&R?.visible&&A.push(E),A},h=t.camera.dynamicNear?rn({camera:i,scene:o,groundNormals:f}):null,y=e.parentElement??e,C=t.measure.enabled?Zt(y,o):null,M=t.measure.enabled&&C?en({canvas:e,scene:o,getActiveCamera:u,labelLayer:C,options:{snapPixels:t.measure.snapPixels,color:t.measure.color,labelClassName:t.measure.labelClassName,displayUnit:t.measure.displayUnit,format:t.measure.format}}):null,L=t.events.enableEventHandlers!==!1?go(e,o,c,t):{dispose:()=>{},fitToView:()=>{},clearSelection:()=>{}},I=5,k=0,O=0,F=A=>{k=A.clientX,O=A.clientY},S=A=>Math.hypot(A.clientX-k,A.clientY-O)>I,D=A=>{if(!S(A)){if(M?.handleClick(A)){A.stopImmediatePropagation();return}b?.handleClick(A)&&A.stopImmediatePropagation()}};(b||M)&&(e.addEventListener("mousedown",F,{capture:!0}),e.addEventListener("click",D,{capture:!0}));let G=A=>M?.handleMove(A);M&&e.addEventListener("mousemove",G,{passive:!0});let V=()=>{},q=A=>{qt(A,{color:t.edges.color,darken:t.edges.darken,width:t.edges.width,thresholdAngle:t.edges.thresholdAngle,distanceFade:t.edges.distanceFade,maxTriangles:t.edges.maxTriangles,maxSegments:t.edges.maxSegments}).then(()=>{Y(A),V()})},Y=A=>{if(t.edges.screenSpaceFallback===!1)return;let B=!1;A.traverse(K=>{K.userData?.edgesSkipped===rt&&(B=!0)}),B!==ne&&(ne=B,ie())},fe=A=>{Yt(A),ne&&(ne=!1,ie()),V()},ee=e.parentElement,pe=()=>ee?{width:ee.clientWidth,height:ee.clientHeight}:{width:window.innerWidth,height:window.innerHeight},j=null,te=!!t.render.ambientOcclusion,ne=!1,xe=!1,he=A=>{let{width:B,height:K}=pe(),ge=Xt(l,o,u(),Math.max(1,B),Math.max(1,K),{toneMapping:t.render.toneMapping??w.NeutralToneMapping,toneMappingExposure:t.render.toneMappingExposure??1,ambientOcclusion:A,aoIntensity:t.render.aoIntensity,aoPixelRatio:t.render.aoPixelRatio,edgeDetection:!1});return ge.setSize(Math.max(1,B),Math.max(1,K),a),ge},ie=()=>{if(!(te||ne)){j?.dispose(),j=null,V();return}(!j||xe!==te)&&(j?.dispose(),j=he(te),xe=te),j.setEdgeDetection(ne),V()},ve=()=>{j?.dispose(),j=null,ie()},An=A=>{te=A,ie()};ie();let ft=A=>{A.ambientIntensity!==void 0&&(p.ambient.intensity=A.ambientIntensity),A.hemisphereIntensity!==void 0&&!p.hemisphere&&A.hemisphereIntensity>0&&(p.hemisphere=new w.HemisphereLight(A.hemisphereSkyColor??t.lighting.hemisphereSkyColor,A.hemisphereGroundColor??t.lighting.hemisphereGroundColor,A.hemisphereIntensity),p.hemisphere.position.copy(t.environment.sceneUp??de),o.add(p.hemisphere)),p.hemisphere&&(A.hemisphereIntensity!==void 0&&(p.hemisphere.intensity=A.hemisphereIntensity),A.hemisphereSkyColor!==void 0&&p.hemisphere.color.set(A.hemisphereSkyColor),A.hemisphereGroundColor!==void 0&&p.hemisphere.groundColor.set(A.hemisphereGroundColor)),V()},pt=A=>{t.environment.environmentIntensity=A,o.environmentIntensity=A,V()},Sn=A=>{t.render.toneMappingExposure=A,l.toneMappingExposure=A,j&&ve()},Dn=A=>{t.render.aoIntensity=A,j&&ve()},Ln=A=>{let B=at[A];Et=A,l.toneMapping=B.toneMapping,l.toneMappingExposure=B.toneMappingExposure,t.render.toneMapping=B.toneMapping,t.render.toneMappingExposure=B.toneMappingExposure,ft({hemisphereIntensity:B.hemisphereIntensity,ambientIntensity:B.ambientIntensity}),pt(B.environmentIntensity),te=B.ambientOcclusion,j?ve():ie(),o.traverse(K=>{if(K.userData.source!=="compute")return;let ge=K,Un=Array.isArray(ge.material)?ge.material:ge.material?[ge.material]:[];for(let yt of Un)"envMapIntensity"in yt&&(yt.envMapIntensity=B.envMapIntensity)}),V()},Et=t.look,On=()=>io(Et),{animate:In,dispose:Pn,invalidate:ht}=uo(l,o,i,u,c,s,pe,a,t.events.onFrame,m,b,()=>j,C,h,t.render.onDemand??!0);V=ht,In(),o.up.set(r.x,r.y,r.z),v(),g();let gt=A=>{A.traverse(B=>{let K=B;!K.geometry&&!K.material||(K.geometry?.dispose(),Array.isArray(K.material)?K.material.forEach(Ne):K.material&&Ne(K.material))})},Fn=A=>{A.userData.source="user",o.add(A)},Bn=A=>{A.removeFromParent(),gt(A)},kn=()=>{o.children.filter(B=>B.userData.source==="user").forEach(B=>{B.removeFromParent(),gt(B)})};return{scene:o,camera:i,controls:s,renderer:l,cameraController:c,grid:m,gizmo:b,measureTool:M,applyEdges:q,clearEdges:fe,invalidate:ht,setAmbientOcclusion:An,setLook:Ln,setFillLights:ft,setEnvironmentIntensity:pt,setToneMappingExposure:Sn,setAoIntensity:Dn,getMaterialAppearance:On,updateShadowBounds:v,updateGridScale:g,dispose:()=>{d||(d=!0,Pn(),L.dispose(),(b||M)&&(e.removeEventListener("mousedown",F,{capture:!0}),e.removeEventListener("click",D,{capture:!0})),M&&e.removeEventListener("mousemove",G),M?.dispose(),C?.dispose(),b?.dispose(),m?.dispose(),j?.dispose(),c.dispose(),s.dispose(),l.dispose(),l.forceContextLoss(),o.traverse(A=>{let B=A;!B.geometry&&!B.material||(B.geometry?.dispose(),Array.isArray(B.material)?B.material.forEach(Ne):B.material&&Ne(B.material))}),o.environment?.dispose(),o.background instanceof w.Texture&&o.background.dispose())},fitToView:L.fitToView,clearSelection:L.clearSelection,addUserGeometry:Fn,removeUserGeometry:Bn,clearUserGeometry:kn}};function so(e){let n=e.sceneScale||"m",r={mm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:10,lightHeight:20,minDistance:.1,shadowSize:100,scaleFactor:1e3},cm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:25,lightHeight:50,minDistance:.1,shadowSize:100,scaleFactor:100},m:{cameraDistance:10,near:.01,far:2e3,floorSize:50,lightDistance:25,lightHeight:50,minDistance:.001,shadowSize:100,scaleFactor:1},inches:{cameraDistance:15,near:.1,far:2e3,floorSize:80,lightDistance:20,lightHeight:40,minDistance:.1,shadowSize:80,scaleFactor:39.37},feet:{cameraDistance:8,near:.1,far:2e3,floorSize:40,lightDistance:15,lightHeight:30,minDistance:.1,shadowSize:60,scaleFactor:3.28084}}[n],a=e.look??ao,o=at[a];return{sceneScale:n,look:a,camera:{position:e.camera?.position||Oe(e.environment?.sceneUp??de,r.cameraDistance*Math.sqrt(3)),fov:e.camera?.fov||20,near:e.camera?.near||r.near,far:e.camera?.far||r.far,target:e.camera?.target||new w.Vector3(0,0,0),dynamicNear:e.camera?.dynamicNear??!0},lighting:{enableSunlight:e.lighting?.enableSunlight??!0,sunlightIntensity:e.lighting?.sunlightIntensity??1,sunlightPosition:e.lighting?.sunlightPosition||Ct(e.environment?.sceneUp??de,r.lightDistance,r.lightHeight),ambientLightColor:e.lighting?.ambientLightColor||new w.Color(4210752),ambientLightIntensity:e.lighting?.ambientLightIntensity??o.ambientIntensity,sunlightColor:e.lighting?.sunlightColor||16777215,enableHemisphereLight:e.lighting?.enableHemisphereLight??o.hemisphereIntensity>0,hemisphereSkyColor:e.lighting?.hemisphereSkyColor??14673663,hemisphereGroundColor:e.lighting?.hemisphereGroundColor??7036754,hemisphereIntensity:e.lighting?.hemisphereIntensity??o.hemisphereIntensity},environment:{hdrPath:e.environment?.hdrPath||"/baseHDR.hdr",backgroundColor:e.environment?.backgroundColor||new w.Color(15790320),enableEnvironmentLighting:e.environment?.enableEnvironmentLighting??!0,sceneUp:e.environment?.sceneUp||de,showEnvironment:e.environment?.showEnvironment??!1,environmentIntensity:e.environment?.environmentIntensity??o.environmentIntensity},floor:{enabled:e.floor?.enabled??!1,size:e.floor?.size||r.floorSize,color:e.floor?.color||new w.Color(8421504),roughness:e.floor?.roughness??.7,metalness:e.floor?.metalness??0,receiveShadow:e.floor?.receiveShadow??!0},render:{enableShadows:e.render?.enableShadows??!0,shadowMapSize:e.render?.shadowMapSize||2048,antialias:e.render?.antialias??!0,pixelRatio:e.render?.pixelRatio||Math.min(window.devicePixelRatio,2),toneMapping:e.render?.toneMapping??o.toneMapping,toneMappingExposure:e.render?.toneMappingExposure??o.toneMappingExposure,preserveDrawingBuffer:e.render?.preserveDrawingBuffer??!1,ambientOcclusion:e.render?.ambientOcclusion??o.ambientOcclusion,aoIntensity:e.render?.aoIntensity??1,aoPixelRatio:e.render?.aoPixelRatio??1,onDemand:e.render?.onDemand??!0},controls:{enableDamping:e.controls?.enableDamping??!1,dampingFactor:e.controls?.dampingFactor||.05,autoRotate:e.controls?.autoRotate??!1,autoRotateSpeed:e.controls?.autoRotateSpeed||.5,enableZoom:e.controls?.enableZoom??!0,enablePan:e.controls?.enablePan??!0,minDistance:e.controls?.minDistance||r.minDistance,maxDistance:e.controls?.maxDistance||1/0},grid:{enabled:e.grid?.enabled??!1,cellSize:e.grid?.cellSize??1,majorEvery:e.grid?.majorEvery??10,cellColor:e.grid?.cellColor??8947848,majorColor:e.grid?.majorColor??4473924,fadeDistance:e.grid?.fadeDistance??100,plane:e.grid?.plane??Xe(e.environment?.sceneUp??de)},gizmo:{enabled:e.gizmo?.enabled??!1},edges:{enabled:e.edges?.enabled??!1,color:e.edges?.color,darken:e.edges?.darken,width:e.edges?.width??1.5,thresholdAngle:e.edges?.thresholdAngle??44,distanceFade:e.edges?.distanceFade??!0},measure:{enabled:e.measure?.enabled??!1,snapPixels:e.measure?.snapPixels,color:e.measure?.color,labelClassName:e.measure?.labelClassName,displayUnit:e.measure?.displayUnit,format:e.measure?.format},events:{onBackgroundClicked:e.events?.onBackgroundClicked,onObjectSelected:e.events?.onObjectSelected,onMeshMetadataClicked:e.events?.onMeshMetadataClicked,onMeshDoubleClicked:e.events?.onMeshDoubleClicked,selectionColor:e.events?.selectionColor||"#ff0000",enableEventHandlers:e.events?.enableEventHandlers??!0,enableKeyboardControls:e.events?.enableKeyboardControls??!0,enableClickToFocus:e.events?.enableClickToFocus??!0,enableDoubleClickZoom:e.events?.enableDoubleClickZoom??!0,onReady:e.events?.onReady,onFrame:e.events?.onFrame}}}function Ne(e){for(let n of Object.values(e))n instanceof w.Texture&&n.dispose();e.dispose()}function lo(e,n){if(n.isEmpty())return;let t=n.getCenter(new w.Vector3),r=n.getSize(new w.Vector3).length()*.5*1.2,a=e.shadow.camera;a.left=-r,a.right=r,a.top=r,a.bottom=-r,e.target.position.copy(t),e.target.updateMatrixWorld();let o=e.position.distanceTo(t);a.near=Math.max(r*.01,o-r),a.far=o+r,a.updateProjectionMatrix()}function co(e){let n=new w.Scene,t=typeof e.environment.backgroundColor=="string"?new w.Color(e.environment.backgroundColor):e.environment.backgroundColor;return n.background=t||null,n}function uo(e,n,t,r,a,o,i,l,s,c,u,d,p,T,v=!0){let R=null,m=performance.now(),g=!0,b=0,x=500,H=new w.Matrix4,E=new w.Matrix4,f=null,h=()=>{g=!0},y=O=>{O.updateMatrixWorld();let F=f!==O||!H.equals(O.matrixWorld)||!E.equals(O.projectionMatrix);return F&&(f=O,H.copy(O.matrixWorld),E.copy(O.projectionMatrix)),F},C=e.domElement,M=["pointerdown","pointerup","wheel"];if(v)for(let O of M)C.addEventListener(O,h,{passive:!0});let L=()=>{let{width:O,height:F}=i();if(O===0||F===0)return;let S=Math.floor(O*l),D=Math.floor(F*l);(e.domElement.width!==S||e.domElement.height!==D)&&(e.setPixelRatio(l),e.setSize(O,F,!1),t.aspect=O/F,t.updateProjectionMatrix(),a.updateAspect(O,F),d?.()?.setSize(O,F,l),p?.setSize(O,F),h())},I=function(){R=requestAnimationFrame(I);let O=performance.now(),F=(O-m)/1e3;m=O,L(),(o.enableDamping||o.autoRotate)&&o.update(),c&&c.update(r().position),u&&u.update(F),T&&T.update(),s?.(F);let S=r();if(v){if(!(g||y(S)||O-b>=x))return;g=!1,b=O}let D=d?.();D?(D.setCamera(S),D.render(F)):e.render(n,S),p&&p.render(n,S),u&&u.render(e)};return{animate:I,dispose:()=>{if(R!==null&&(cancelAnimationFrame(R),R=null),v)for(let O of M)C.removeEventListener(O,h)},invalidate:h}}function mo(e,n,t,r){t.environment.enableEnvironmentLighting?new oo().load(t.environment.hdrPath||"/baseHDR.hdr",function(a){if(r()){a.dispose();return}if(!a?.image){P().warn("HDR loaded without image data; skipping environment map."),a?.dispose(),t.events.onReady?.();return}a.mapping=w.EquirectangularReflectionMapping;let o=new w.PMREMGenerator(n);o.compileEquirectangularShader();let i=o.fromEquirectangular(a).texture;o.dispose(),e.environment=i,e.environmentIntensity=t.environment.environmentIntensity??1;let l=At(t.environment.sceneUp??de);e.environmentRotation.copy(l),t.environment.showEnvironment?(e.background=a,e.backgroundRotation.copy(l)):a.dispose(),t.events.onReady?.()},void 0,function(a){r()||(P().warn("HDR texture could not be loaded, falling back to basic lighting:",a),t.events.onReady?.())}):t.events.onReady?.()}function fo(e,n){let t=new w.AmbientLight(n.lighting.ambientLightColor,n.lighting.ambientLightIntensity);e.add(t);let r=null;if(n.lighting.enableHemisphereLight){r=new w.HemisphereLight(n.lighting.hemisphereSkyColor,n.lighting.hemisphereGroundColor,n.lighting.hemisphereIntensity);let i=n.environment.sceneUp??de;r.position.copy(i),e.add(r)}if(!n.lighting.enableSunlight)return{ambient:t,hemisphere:r,sun:null};let a=new w.DirectionalLight(n.lighting.sunlightColor??16777215,n.lighting.sunlightIntensity),o=n.lighting.sunlightPosition;return o&&a.position.set(o.x,o.y,o.z),n.render.enableShadows?(a.castShadow=!0,a.shadow.mapSize.width=n.render.shadowMapSize||2048,a.shadow.mapSize.height=n.render.shadowMapSize||2048,a.shadow.bias=-1e-4,a.shadow.normalBias=.02,a.shadow.radius=4,e.add(a),e.add(a.target),{ambient:t,hemisphere:r,sun:a}):(e.add(a),{ambient:t,hemisphere:r,sun:null})}function po(e,n){let t=n.floor.size,r=new w.PlaneGeometry(t,t),a=typeof n.floor.color=="string"?new w.Color(n.floor.color):n.floor.color,o=new w.MeshStandardMaterial({color:a,roughness:n.floor.roughness,metalness:n.floor.metalness,side:w.DoubleSide}),i=new w.Mesh(r,o);i.userData.id="floor",i.name="floor";let l=(n.environment?.sceneUp||de).clone().normalize();i.quaternion.setFromUnitVectors(new w.Vector3(0,0,1),l),i.position.set(0,0,0),n.floor.receiveShadow&&n.render.enableShadows&&(i.receiveShadow=!0),e.add(i)}function Eo(e,n){let t=n.parentElement,r=t?t.clientWidth:window.innerWidth,a=t?t.clientHeight:window.innerHeight,o=new w.PerspectiveCamera(e.camera.fov,r/a,e.camera.near,e.camera.far),i=e.camera.position;return i&&o.position.set(i.x,i.y,i.z),o}function ho(e,n,t){let r=new w.WebGLRenderer({antialias:n.render.antialias,canvas:e,alpha:!0,powerPreference:"high-performance",preserveDrawingBuffer:n.render.preserveDrawingBuffer,logarithmicDepthBuffer:!1}),a=e.parentElement,o=a?a.clientWidth:window.innerWidth,i=a?a.clientHeight:window.innerHeight;return a&&(e.style.width="100%",e.style.height="100%",e.style.display="block"),r.setSize(o,i,!1),r.setPixelRatio(t),n.render.enableShadows&&(r.shadowMap.enabled=!0,r.shadowMap.type=w.VSMShadowMap),r.toneMapping=n.render.toneMapping,r.toneMappingExposure=n.render.toneMappingExposure??1,r.outputColorSpace=w.SRGBColorSpace,r.sortObjects=!0,r}function go(e,n,t,r){let a=new Set,o=new Map,i=new w.Raycaster,l=new w.Vector2,s=new w.Vector2,c=()=>t.getActiveCamera(),u=E=>{let f=E;for(;f;){if(!f.visible)return!1;f=f.parent}return!0},d=()=>{let E=ce(n);if(E.isEmpty()){P().warn("No objects to fit to view");return}t.frameBounds(E,!1)},p=typeof r.events.selectionColor=="string"?new w.Color(r.events.selectionColor):r.events.selectionColor instanceof w.Color?r.events.selectionColor:new w.Color("#ff0000"),T=()=>{a.forEach(E=>{let f=E;if(o.has(E)){let h=o.get(E),y=f.material;y instanceof w.Material?y.dispose():Array.isArray(y)&&y.forEach(M=>M.dispose()),f.material=h,o.delete(E);let C=E;for(;C.parent;)C=C.parent;C!==n&&(h instanceof w.Material?h.dispose():h.forEach(M=>M.dispose()))}}),a.clear()},v=E=>{let f=E;if(!(f.material instanceof w.Material))return!1;o.set(E,f.material);let h=f.material.clone();return E instanceof w.Mesh&&"emissive"in h?h.emissive=p.clone():"color"in h&&(h.color=p.clone()),f.material=h,!0},R=()=>{let E=ce(n),f=E.isEmpty()?1:E.getSize(new w.Vector3).length();i.params.Points.threshold=f*.01},m=E=>{s.set(E.clientX,E.clientY)},g=E=>{let f=new w.Vector2(E.clientX,E.clientY);if(s.distanceTo(f)>5)return;let h=e.getBoundingClientRect();l.x=(E.clientX-h.left)/h.width*2-1,l.y=-((E.clientY-h.top)/h.height)*2+1,R(),i.setFromCamera(l,c());let y=i.intersectObjects(n.children,!0).filter(C=>u(C.object));if(y.length>0){let C=y[0].object;a.has(C)||(T(),a.add(C),v(C),r.events?.onObjectSelected?.(C),C instanceof w.Mesh&&Object.keys(C.userData).length>0&&r.events?.onMeshMetadataClicked?.(C.userData))}else T(),r.events?.onBackgroundClicked?.({x:l.x,y:l.y})},b=E=>{let f=e.getBoundingClientRect();l.x=(E.clientX-f.left)/f.width*2-1,l.y=-((E.clientY-f.top)/f.height)*2+1,R(),i.setFromCamera(l,c());let h=i.intersectObjects(n.children,!0).filter(M=>u(M.object));if(h.length===0)return;let y=h[0].object;if(r.events?.onMeshDoubleClicked?.(y),!r.events?.enableDoubleClickZoom)return;let C=new w.Box3().setFromObject(y);C.isEmpty()||t.frameBounds(C,!0)},x=E=>{if(r.events?.enableKeyboardControls)switch(E.key.toLowerCase()){case"f":E.preventDefault(),d();break;case"escape":E.preventDefault(),T();break;case" ":E.preventDefault(),d();break}};return r.events?.enableClickToFocus&&(e.addEventListener("mousedown",m),e.addEventListener("click",g),e.addEventListener("dblclick",b)),r.events?.enableKeyboardControls&&(e.setAttribute("tabindex","0"),e.addEventListener("keydown",x)),{dispose:()=>{e.removeEventListener("mousedown",m),e.removeEventListener("click",g),e.removeEventListener("dblclick",b),e.removeEventListener("keydown",x),T()},fitToView:d,clearSelection:T}}function yo(e,n,t){let r=new ro(e,n),a=t.camera.target;return a&&r.target.set(a.x,a.y,a.z),r.enableDamping=t.controls.enableDamping||!1,r.dampingFactor=t.controls.dampingFactor||.05,r.autoRotate=t.controls.autoRotate||!1,r.autoRotateSpeed=t.controls.autoRotateSpeed||.5,r.enableZoom=t.controls.enableZoom??!0,r.enablePan=t.controls.enablePan??!0,r.minDistance=t.controls.minDistance||.001,r.maxDistance=t.controls.maxDistance||1/0,r.screenSpacePanning=!1,r.maxPolarAngle=Math.PI,r.update(),r}var Oi=["technical","studio","showcase"];import*as Q from"three";import{Line2 as bo}from"three/addons/lines/Line2.js";import{LineGeometry as To}from"three/addons/lines/LineGeometry.js";import{LineMaterial as Ro}from"three/addons/lines/LineMaterial.js";function je(e,n,t,r=!0){return{x:e,y:n,z:t}}var xo="#ffffff",on=12,vo=4e-4,wo=12,Mo=.05;function an(e,n={}){if(!e||e.length===0)return[];let{rhino:t,applyTransforms:r=!0}=n,a=[];for(let o of e)switch(o.kind){case"curve":{let i=Co(o,t,r);i&&a.push(i);break}case"point":{let i=Ao(o,r);i&&a.push(i);break}default:{let l=o;P().warn(`Skipping unknown display item kind: ${String(l.kind)}`);break}}return a}var Ho=2;function Co(e,n,t){if(!n)return P().warn("No rhino3dm instance provided; skipping curve display item."),null;let r=So(e.json,n);if(!r)return null;let a;try{a=Do(r,t)}catch(d){return P().warn("Failed to tessellate curve display item; skipping.",d),null}finally{Se(r)}if(a.length<2)return null;let o=[];for(let d of a)o.push(d.x,d.y,d.z);let i=new To;i.setPositions(o);let l=sn(e.color,e.opacity),s=new Ro({color:l.color}),c=s;c.linewidth=e.width??Ho,c.transparent=l.transparent,c.opacity=l.opacity;let u=new bo(i,s);return u.computeLineDistances(),u.name=e.name,u.userData={source:"compute",id:e.id,layer:e.layer,kind:"curve",metadata:e.metadata},u}function Ao(e,n){let{position:t}=e;if(!t||typeof t.X!="number"||!Number.isFinite(t.X)||typeof t.Y!="number"||!Number.isFinite(t.Y)||typeof t.Z!="number"||!Number.isFinite(t.Z))return P().warn(`Skipping point display item with missing or non-finite position (id: ${String(e.id)}).`),null;let{x:r,y:a,z:o}=je(t.X,t.Y,t.Z,n),i=new Q.BufferGeometry;i.setAttribute("position",new Q.Float32BufferAttribute([r,a,o],3));let l=new Q.PointsMaterial({...sn(e.color,e.opacity),size:6,sizeAttenuation:!1}),s=new Q.Points(i,l);return s.name=e.name,s.userData={source:"compute",id:e.id,layer:e.layer,kind:"point",metadata:e.metadata},s}function Se(e){e?.delete?.()}function So(e,n){try{let t=JSON.parse(e),r=n.CommonObject.decode(t);return r&&typeof r.pointAt=="function"?r:(Se(r),P().warn("Decoded display-item JSON is not a curve; skipping."),null)}catch(t){return P().warn("Failed to decode curve display item JSON:",t),null}}function Do(e,n){let t=Lo(e,n);return t||Oo(e,n)}function Lo(e,n){if(!e.isPolyline())return null;let t=e.tryGetPolyline(),r=Array.isArray(t)?t[1]:t;if(!r||typeof r.count!="number"||r.count<2)return Se(r),null;let a=[];for(let o=0;o<r.count;o++){let i=r.get(o),{x:l,y:s,z:c}=je(i[0],i[1],i[2],n);a.push(new Q.Vector3(l,s,c))}return Se(r),a}function Oo(e,n){let t=e.domain,r=t[0],o=t[1]-r,i=d=>{let p=e.pointAt(d),{x:T,y:v,z:R}=je(p[0],p[1],p[2],n);return new Q.Vector3(T,v,R)},l=Io(e),s=r,c=i(r),u=[c];for(let d=0;d<on;d++){let p=r+o*(d+1)/on,T=i(p);it(s,c,p,T,i,l,wo,u),u.push(T),s=p,c=T}return u}function it(e,n,t,r,a,o,i,l){if(i<=0)return;let s=(e+t)/2,c=a(s),u=Fo(c,n,r),d=Po(n,c,r);u<=o&&d<=Mo||(it(e,n,s,c,a,o,i-1,l),l.push(c),it(s,c,t,r,a,o,i-1,l))}function Io(e){let n=e.getBoundingBox(),t=n.min,r=n.max;Se(n);let a=Math.hypot(r[0]-t[0],r[1]-t[1],r[2]-t[2]);return Math.max(a*vo,1e-6)}function Po(e,n,t){let r=n.x-e.x,a=n.y-e.y,o=n.z-e.z,i=t.x-n.x,l=t.y-n.y,s=t.z-n.z,c=Math.sqrt(r*r+a*a+o*o),u=Math.sqrt(i*i+l*l+s*s);if(c===0||u===0)return 0;let d=r*i+a*l+o*s,p=Math.max(-1,Math.min(1,d/(c*u)));return Math.acos(p)}function Fo(e,n,t){let r=t.x-n.x,a=t.y-n.y,o=t.z-n.z,i=r*r+a*a+o*o;if(i===0)return e.distanceTo(n);let l=e.x-n.x,s=e.y-n.y,c=e.z-n.z,u=Math.max(0,Math.min(1,(l*r+s*a+c*o)/i)),d=l-r*u,p=s-a*u,T=c-o*u;return Math.sqrt(d*d+p*p+T*T)}function sn(e,n){let t=n??1;return{color:new Q.Color(e??xo),transparent:t<1,opacity:t}}import{inflateSync as Bo}from"fflate";var ln=1096174675,ko=1515605075,cn=3,un=1,lt=1,Uo=2,_o=4,Vo=8,zo=16,ji=0,Go=1,dn=12,mn=56,No=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;function ct(e){let n=ut(e),t;n.isFloat32?t=n.vertexData:n.deltaEncoded?t=Jo(n.vertexData):t=n.vertexData;let r=n.indexData;return n.deltaEncoded&&(r=r instanceof Uint16Array?Qo(r):ea(r)),Zo(r,n.vertexCount),{metadata:n.metadata,flags:n.flags,vertices:t,indices:r,origin:n.origin,scale:n.scale,uvs:n.uvs,colors:n.colors}}function ut(e){if(!No)throw new Re("SLVA parsing requires a little-endian host: the zero-copy geometry readers view the wire bytes in host byte order.",Te.ENVIRONMENT_ERROR);let n=qo($o(e)),t=new DataView(n.buffer,n.byteOffset,n.byteLength);if(n.byteLength<dn)throw X("Blob too small to contain SLVA header.",{expectedBytes:dn,availableBytes:n.byteLength});let r=0,a=t.getUint32(r,!0);if(r+=4,a!==ln)throw X(`Invalid SLVA magic: 0x${a.toString(16)}`,{expectedMagic:`0x${ln.toString(16)}`,actualMagic:`0x${a.toString(16)}`});let o=t.getUint32(r,!0);if(r+=4,o<un||o>cn)throw X(`Unsupported SLVA version: ${o}`,{minSupportedVersion:un,maxSupportedVersion:cn,actualVersion:o});let i=t.getUint32(r,!0);if(r+=4,r+i>n.byteLength)throw X("Insufficient data to read metadata JSON.",{expectedBytes:i,availableBytes:n.byteLength-r,offset:r});let l=n.subarray(r,r+i);r+=i;let s;try{s=JSON.parse(Yo(l))}catch(F){throw X(`Failed to parse metadata JSON: ${F instanceof Error?F.message:String(F)}`,{metadataLen:i})}if(r+mn>n.byteLength)throw X("Insufficient data to read geometry header.",{expectedBytes:mn,availableBytes:n.byteLength-r,offset:r});let c=t.getUint32(r,!0);r+=4;let u=t.getFloat64(r,!0);r+=8;let d=t.getFloat64(r,!0);r+=8;let p=t.getFloat64(r,!0);r+=8;let T=t.getFloat64(r,!0);r+=8;let v=t.getFloat64(r,!0);r+=8;let R=t.getFloat64(r,!0);r+=8;let m=t.getUint32(r,!0);r+=4;let g=(c&lt)!==0,b=(c&_o)!==0,x=m*3,E=x*(g?4:2);if(r+E>n.byteLength)throw X("Insufficient data to read vertices.",{expectedBytes:E,availableBytes:n.byteLength-r,offset:r,useFloat32:g,vertexCount:m});let f=n.byteOffset+r,h;if(g?h=pn(n.buffer,f,x):b?h=st(n.buffer,f,x):h=Xo(n.buffer,f,x),r+=E,r+4>n.byteLength)throw X("Insufficient data to read index count.",{expectedBytes:4,availableBytes:n.byteLength-r,offset:r});let y=t.getUint32(r,!0);r+=4;let C=(c&Uo)!==0,L=y*(C?2:4);if(r+L>n.byteLength)throw X("Insufficient data to read indices.",{expectedBytes:L,availableBytes:n.byteLength-r,offset:r,indexCount:y,useUint16Indices:C});let I=C?st(n.buffer,n.byteOffset+r,y):Ko(n.buffer,n.byteOffset+r,y);r+=L;let k=null;if((c&Vo)!==0){let F=jo(n,t,r,m,b);k=F.uvs,r=F.offset}let O=null;return(c&zo)!==0&&(O=Wo(n,r,m,b)),{metadata:s,flags:c,vertexData:h,indexData:I,isFloat32:g,deltaEncoded:b,vertexCount:m,origin:[u,d,p],scale:[T,v,R],uvs:k,colors:O}}var fn=36;function jo(e,n,t,r,a){if(t+fn>e.byteLength)throw X("Insufficient data to read UV chunk header.",{expectedBytes:fn,availableBytes:e.byteLength-t,offset:t});let o=n.getUint32(t,!0);t+=4;let i=n.getFloat64(t,!0);t+=8;let l=n.getFloat64(t,!0);t+=8;let s=n.getFloat64(t,!0);t+=8;let c=n.getFloat64(t,!0);t+=8;let u=r*2,d=o===Go,p=u*(d?4:2);if(t+p>e.byteLength)throw X("Insufficient data to read UV chunk.",{expectedBytes:p,availableBytes:e.byteLength-t,offset:t,uvFormat:o,vertexCount:r});let T=e.byteOffset+t,v;if(d)v=pn(e.buffer,T,u).slice();else{let R=st(e.buffer,T,u);v=new Float32Array(u);let m=0,g=0;for(let b=0;b<u;b+=2)a?(m=m+le(R[b])&65535,g=g+le(R[b+1])&65535):(m=R[b],g=R[b+1]),v[b]=i+m*s,v[b+1]=l+g*c}return{uvs:v,offset:t+p}}function Wo(e,n,t,r){let a=t*3;if(n+a>e.byteLength)throw X("Insufficient data to read vertex-color chunk.",{expectedBytes:a,availableBytes:e.byteLength-n,offset:n,vertexCount:t});let o=e.subarray(n,n+a);if(!r)return o.slice();let i=new Uint8Array(a),l=0,s=0,c=0;for(let u=0;u<a;u+=3)l=l+le(o[u])&255,s=s+le(o[u+1])&255,c=c+le(o[u+2])&255,i[u]=l,i[u+1]=s,i[u+2]=c;return i}function $o(e){return typeof e=="string"?bt(e):e instanceof Uint8Array?e:new Uint8Array(e)}function qo(e){if(e.byteLength<8)return e;let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint32(0,!0)!==ko)return e;let t=n.getUint32(4,!0),r=e.subarray(8),a=Math.max(r.byteLength*1032+1024,1<<20);if(t>a)throw X("SLVZ header declares an implausible uncompressed length",{uncompressedLen:t,deflatedBytes:r.byteLength,maxPlausibleLen:a});let o;try{o=Bo(r,{out:new Uint8Array(t+1)})}catch(i){throw X(`Failed to inflate SLVZ blob: ${i instanceof Error?i.message:String(i)}`,{uncompressedLen:t,deflatedBytes:r.byteLength})}if(o.byteLength!==t)throw X("SLVZ payload inflated to a different size than the header declares.",{declaredLen:t,actualLen:o.byteLength,deflatedBytes:r.byteLength});return o}function Yo(e){if(typeof TextDecoder<"u")return new TextDecoder("utf-8").decode(e);if(typeof globalThis.Buffer<"u")return globalThis.Buffer.from(e).toString("utf-8");throw new Re("No UTF-8 decoder available in this environment.",Te.INVALID_STATE)}function Xo(e,n,t){if(t===0)return new Int16Array(0);if(n%2===0)return new Int16Array(e,n,t);let r=new Uint8Array(t*2);return r.set(new Uint8Array(e,n,t*2)),new Int16Array(r.buffer)}function pn(e,n,t){if(t===0)return new Float32Array(0);if(n%4===0)return new Float32Array(e,n,t);let r=new Uint8Array(t*4);return r.set(new Uint8Array(e,n,t*4)),new Float32Array(r.buffer)}function st(e,n,t){if(t===0)return new Uint16Array(0);if(n%2===0)return new Uint16Array(e,n,t);let r=new Uint8Array(t*2);return r.set(new Uint8Array(e,n,t*2)),new Uint16Array(r.buffer)}function Ko(e,n,t){if(t===0)return new Uint32Array(0);if(n%4===0)return new Uint32Array(e,n,t);let r=new Uint8Array(t*4);return r.set(new Uint8Array(e,n,t*4)),new Uint32Array(r.buffer)}function Zo(e,n){if(e.length!==0&&!(e instanceof Uint16Array&&n>65535)){for(let t=0;t<e.length;t++)if(e[t]>=n)throw X("Index out of range of vertexCount.",{indexPosition:t,indexValue:e[t],vertexCount:n})}}function le(e){return e>>>1^-(e&1)}function Jo(e){let n=new Int16Array(e.length),t=0,r=0,a=0;for(let o=0;o<e.length;o+=3)t=t+le(e[o])<<16>>16,r=r+le(e[o+1])<<16>>16,a=a+le(e[o+2])<<16>>16,n[o]=t,n[o+1]=r,n[o+2]=a;return n}function Qo(e){let n=new Uint16Array(e.length),t=0;for(let r=0;r<e.length;r++)t=t+le(e[r])&65535,n[r]=t;return n}function ea(e){let n=new Uint32Array(e.length),t=0;for(let r=0;r<e.length;r++)t=t+le(e[r])>>>0,n[r]=t;return n}function X(e,n){return new Re(e,Te.VALIDATION_ERROR,{context:n})}import*as _ from"three";var En=256*1024*1024,We=1024,me=new Map,dt=0;function hn(e,n){let t=2166136261,r=a=>{t^=a,t=Math.imul(t,16777619)};for(let a=0;a<n.length;a++)r(n.charCodeAt(a));for(let a of e){if(!a){r(57005);continue}let o=a.byteLength;if(r(o),(a.byteOffset&3)===0&&(o&3)===0){let i=new Uint32Array(a.buffer,a.byteOffset,o>>2),l=Math.min(We,i.length);for(let s=0;s<l;s++)r(i[s]);for(let s=Math.max(l,i.length-We);s<i.length;s++)r(i[s])}else{let i=new Uint8Array(a.buffer,a.byteOffset,o),l=Math.min(We*4,i.length);for(let s=0;s<l;s++)r(i[s]);for(let s=Math.max(l,i.length-We*4);s<i.length;s++)r(i[s])}}return`${(t>>>0).toString(36)}:${e.length}`}function ta(e){let n=e.index?.array.byteLength??0;for(let t of Object.values(e.attributes))n+=t.array.byteLength;return n}function $e(e){let n=me.get(e);if(n)return me.delete(e),me.set(e,n),n.geometry}function qe(e,n){let t=ta(n);if(!(t>En||(n.userData[Ie]=!0,me.get(e))))for(me.set(e,{geometry:n,bytes:t}),dt+=t;dt>En&&me.size>1;){let a=me.keys().next().value,o=me.get(a);me.delete(a),dt-=o.bytes,delete o.geometry.userData[Ie],o.geometry.dispose()}}function na(e){let{isFloat32:n,deltaEncoded:t,origin:r,scale:a,uvs:o,colors:i,jobs:l}=e,s=m=>m>>>1^-(m&1),c;if(n)c=e.vertexData;else{let m;if(t){let h=e.vertexData;m=new Int16Array(h.length);let y=0,C=0,M=0;for(let L=0;L<h.length;L+=3)y=y+s(h[L])<<16>>16,C=C+s(h[L+1])<<16>>16,M=M+s(h[L+2])<<16>>16,m[L]=y,m[L+1]=C,m[L+2]=M}else m=e.vertexData;c=new Float32Array(m.length);let g=r[0],b=r[1],x=r[2],H=a[0],E=a[1],f=a[2];for(let h=0;h<m.length;h+=3)c[h]=g+(m[h]+32767)*H,c[h+1]=b+(m[h+1]+32767)*E,c[h+2]=x+(m[h+2]+32767)*f}let u;if(t){let m=e.indexData;if(m instanceof Uint16Array){let g=new Uint16Array(m.length),b=0;for(let x=0;x<m.length;x++)b=b+s(m[x])&65535,g[x]=b;u=g}else{let g=new Uint32Array(m.length),b=0;for(let x=0;x<m.length;x++)b=b+s(m[x])>>>0,g[x]=b;u=g}}else u=e.indexData;let d=c.length/3;for(let m=0;m<u.length;m++)if(u[m]>=d)throw new Error(`Index ${u[m]} out of range of vertexCount ${d}`);let p=1024,T=(m,g)=>{let b=2166136261,x=H=>{b^=H,b=Math.imul(b,16777619)};for(let H=0;H<g.length;H++)x(g.charCodeAt(H));for(let H of m){if(!H){x(57005);continue}let E=H.byteLength;if(x(E),(H.byteOffset&3)===0&&(E&3)===0){let f=new Uint32Array(H.buffer,H.byteOffset,E>>2),h=Math.min(p,f.length);for(let y=0;y<h;y++)x(f[y]);for(let y=Math.max(h,f.length-p);y<f.length;y++)x(f[y])}else{let f=new Uint8Array(H.buffer,H.byteOffset,E),h=Math.min(p*4,f.length);for(let y=0;y<h;y++)x(f[y]);for(let y=Math.max(h,f.length-p*4);y<f.length;y++)x(f[y])}}return`${(b>>>0).toString(36)}:${m.length}`},v=(m,g)=>{let b=[],x=m;for(let H of g){x+=`|${H.vertexStart},${H.vertexCount},${H.indexStart},${H.indexCount}`;let E=H.vertexStart*3,f=E+H.vertexCount*3;b.push(c.subarray(E,f)),b.push(u.subarray(H.indexStart,H.indexStart+H.indexCount)),b.push(o?o.subarray(H.vertexStart*2,(H.vertexStart+H.vertexCount)*2):null),b.push(i?i.subarray(E,f):null)}return T(b,x)},R=[];for(let m of l){let g=0,b=0;for(let M of m.windows)g+=M.vertexCount,b+=M.indexCount;let x=new Float32Array(g*3),H=new Uint32Array(b),E=o?new Float32Array(g*2):null,f=i?new Uint8Array(g*3):null,h=0,y=0;for(let M of m.windows){let L=M.vertexStart*3;x.set(c.subarray(L,L+M.vertexCount*3),h*3),E&&o&&E.set(o.subarray(M.vertexStart*2,(M.vertexStart+M.vertexCount)*2),h*2),f&&i&&f.set(i.subarray(L,L+M.vertexCount*3),h*3);let I=M.vertexStart,k=M.vertexStart+M.vertexCount,O=h-M.vertexStart;for(let F=0;F<M.indexCount;F++){let S=u[M.indexStart+F];if(S<I||S>=k)throw new Error(`Index ${S} outside vertex window [${I}, ${k})`);H[y+F]=S+O}h+=M.vertexCount,y+=M.indexCount}let C=new Float32Array(g*3);for(let M=0;M<H.length;M+=3){let L=H[M]*3,I=H[M+1]*3,k=H[M+2]*3,O=x[k]-x[I],F=x[k+1]-x[I+1],S=x[k+2]-x[I+2],D=x[L]-x[I],G=x[L+1]-x[I+1],V=x[L+2]-x[I+2],q=F*V-S*G,Y=S*D-O*V,fe=O*G-F*D;C[L]+=q,C[L+1]+=Y,C[L+2]+=fe,C[I]+=q,C[I+1]+=Y,C[I+2]+=fe,C[k]+=q,C[k+1]+=Y,C[k+2]+=fe}for(let M=0;M<C.length;M+=3){let L=C[M],I=C[M+1],k=C[M+2],O=Math.sqrt(L*L+I*I+k*k)||1;C[M]=L/O,C[M+1]=I/O,C[M+2]=k/O}R.push({key:v(m.kind,m.windows),positions:x,normals:C,indices:H,uvs:E,colors:f})}return R}function gn(){return[`const assemble = ${na.toString()};`,"self.onmessage = (event) => {"," const { id, input } = event.data;"," try {"," const geometries = assemble(input);"," const transfer = [];"," for (const g of geometries) {"," transfer.push(g.positions.buffer, g.normals.buffer, g.indices.buffer);"," if (g.uvs) transfer.push(g.uvs.buffer);"," if (g.colors) transfer.push(g.colors.buffer);"," }"," self.postMessage({ id, geometries }, transfer);"," } catch (error) {"," self.postMessage({ id, error: String((error && error.message) || error) });"," }","};"].join(`
112
+ `)}async function ns(e,n){let{debug:t=!1}=n??{},r=t?performance.now():0,a,o=performance.now();try{a=JSON.parse(e)}catch(l){return P().error("Error parsing mesh batch envelope JSON:",l),[]}let i=performance.now()-o;return await mt(a,n,{parseTime:i,perfStart:r})}async function mt(e,n,t){let{mergeByMaterial:r=!0,applyTransforms:a=!0,debug:o=!1,material:i}=n??{},{parseTime:l=0,perfStart:s=o?performance.now():0}=t??{};if(!e.compressedData)return[];let c=await xn(e.compressedData,{mergeByMaterial:r,applyTransforms:a,debug:o,material:i,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}});if(c)return c;let u=performance.now(),d=ct(e.compressedData),p=performance.now()-u,T=o?Ea(e.compressedData):0;return yn(d,{mergeByMaterial:r,applyTransforms:a,debug:o,material:i,parseTime:l,decodeTime:p,perfStart:s,blobBytes:T,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}})}async function rs(e,n){let{mergeByMaterial:t=!0,applyTransforms:r=!0,debug:a=!1,material:o}=n??{},i=a?performance.now():0,l=await xn(e,{mergeByMaterial:t,applyTransforms:r,debug:a,material:o});if(l)return l;let s=performance.now(),c=ct(e),u=performance.now()-s,d=e.byteLength;return yn(c,{mergeByMaterial:t,applyTransforms:r,debug:a,material:o,parseTime:0,decodeTime:u,perfStart:i,blobBytes:d})}function yn(e,n){let{mergeByMaterial:t,applyTransforms:r,debug:a,material:o,parseTime:i,decodeTime:l,perfStart:s,blobBytes:c,fallback:u}=n,d=e.metadata.materials??u?.materials??[],p=e.metadata.groups??u?.groups??[],T=u?.sourceComponentId??e.metadata.sourceComponentId,v=(e.flags&lt)!==0;bn(p,d.length,e.vertices.length/3,e.indices.length);let R=v?oa(e.vertices,r):ra(e.vertices,e.origin,e.scale,r);if(a){let H=e.vertices.byteLength+e.indices.byteLength;P().debug("Mesh Batch Stats:"),P().debug(` Materials: ${d.length} | Groups: ${p.length}`),P().debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),P().debug(` Format: ${v?"float32":"int16 quantized"}`),P().debug(` Blob: ${(c/1024/1024).toFixed(2)} MB | Geometry on wire: ${(H/1024/1024).toFixed(2)} MB`)}let m=performance.now(),g=d.map(H=>vn(H,{vertexColors:e.colors!=null,appearance:o})),b=[];for(let H of p)if(t&&H.meshes.length>1){let E=fa(H,R,e.indices,g,e.uvs,e.colors);E.userData.sourceComponentId=T??null,b.push(E)}else{let E=pa(H,R,e.indices,g,e.uvs,e.colors);for(let f of E)f.userData.sourceComponentId=T??null;b.push(...E)}let x=performance.now()-m;if(a){let H=performance.now()-s;P().debug("Performance:"),i>0&&P().debug(` Parse JSON: ${i.toFixed(2)}ms`),P().debug(` Decode binary: ${l.toFixed(2)}ms`),P().debug(` Create Meshes: ${x.toFixed(2)}ms`),P().debug(` Total: ${H.toFixed(2)}ms`)}return Promise.resolve(b)}function De(e,n){return new Re(e,Te.VALIDATION_ERROR,{context:n})}function bn(e,n,t,r){for(let a of e){if(!Number.isInteger(a.materialId)||a.materialId<0||a.materialId>=n)throw De("Group materialId out of range of the materials array.",{materialId:a.materialId,materialCount:n});for(let o of a.meshes){let i={vertexStart:o.vertexStart,vertexCount:o.vertexCount,indexStart:o.indexStart,indexCount:o.indexCount};for(let[l,s]of Object.entries(i))if(!Number.isInteger(s)||s<0)throw De(`Mesh metadata field "${l}" must be a non-negative integer.`,{meshName:o.name,field:l,value:s});if(o.vertexStart+o.vertexCount>t)throw De("Mesh vertex window exceeds the batch vertex buffer.",{meshName:o.name,vertexStart:o.vertexStart,vertexCount:o.vertexCount,totalVertexCount:t});if(o.indexStart+o.indexCount>r)throw De("Mesh index window exceeds the batch index buffer.",{meshName:o.name,indexStart:o.indexStart,indexCount:o.indexCount,totalIndexCount:r})}}}function Tn(e,n){return De("Index references a vertex outside its mesh's vertex window.",{meshName:n.name,indexValue:e,vertexStart:n.vertexStart,vertexCount:n.vertexCount})}function Rn(e,n,t,r,a,o){let i=[],l=e;for(let s of n){l+=`|${s.vertexStart},${s.vertexCount},${s.indexStart},${s.indexCount}`;let c=s.vertexStart*3,u=c+s.vertexCount*3;i.push(t.subarray(c,u)),i.push(r.subarray(s.indexStart,s.indexStart+s.indexCount)),i.push(a?a.subarray(s.vertexStart*2,(s.vertexStart+s.vertexCount)*2):null),i.push(o?o.subarray(c,u):null)}return hn(i,l)}function ra(e,n,t,r){let a=new Float32Array(e.length),o=n[0],i=n[1],l=n[2],s=t[0],c=t[1],u=t[2];for(let d=0;d<e.length;d+=3)a[d]=o+(e[d]+32767)*s,a[d+1]=i+(e[d+1]+32767)*c,a[d+2]=l+(e[d+2]+32767)*u;return a}function oa(e,n){return e}var aa=5e4,be,Le=new Map,ia=1;function sa(){if(be!==void 0)return be;if(typeof Worker>"u"||typeof Blob>"u"||typeof URL>"u"||typeof URL.createObjectURL!="function")return be=null,null;try{let e=URL.createObjectURL(new Blob([gn()],{type:"text/javascript"})),n=new Worker(e);n.onmessage=t=>{let{id:r,geometries:a,error:o}=t.data,i=Le.get(r);i&&(Le.delete(r),a?i.resolve(a):i.reject(new Error(o??"mesh assembly failed in worker")))},n.onerror=()=>{for(let t of Le.values())t.reject(new Error("mesh assembly worker crashed"));Le.clear(),n.terminate(),be=null},be=n}catch{be=null}return be}function la(e,n,t){return new Promise((r,a)=>{let o=ia++;Le.set(o,{resolve:r,reject:a}),e.postMessage({id:o,input:n},t)})}async function xn(e,n){if(typeof Worker>"u")return null;let t=ut(e);if(t.indexData.length/3<aa)return null;let r=sa();if(!r)return null;let a=t.metadata.materials??n.fallback?.materials??[],o=t.metadata.groups??n.fallback?.groups??[],i=n.fallback?.sourceComponentId??t.metadata.sourceComponentId;bn(o,a.length,t.vertexCount,t.indexData.length);let l=m=>({vertexStart:m.vertexStart,vertexCount:m.vertexCount,indexStart:m.indexStart,indexCount:m.indexCount}),s=[],c=[];for(let m of o)if(n.mergeByMaterial&&m.meshes.length>1)s.push({kind:"merged",windows:m.meshes.map(l)}),c.push({kind:"merged",group:m});else for(let g of m.meshes)s.push({kind:"single",windows:[l(g)]}),c.push({kind:"single",group:m,meshMeta:g});let u=t.vertexData.slice(),d=t.indexData.slice(),p=[u.buffer,d.buffer];t.uvs&&p.push(t.uvs.buffer),t.colors&&p.push(t.colors.buffer);let T;try{T=await la(r,{vertexData:u,isFloat32:t.isFloat32,deltaEncoded:t.deltaEncoded,origin:t.origin,scale:t.scale,indexData:d,uvs:t.uvs,colors:t.colors,jobs:s},p)}catch(m){return P().warn("Mesh assembly worker failed; falling back to main-thread parse.",m),null}if(T.length!==s.length)return null;let v=a.map(m=>vn(m,{vertexColors:t.colors!=null,appearance:n.material})),R=[];for(let m=0;m<T.length;m++){let g=T[m],b=c[m],x=$e(g.key);x||(x=new _.BufferGeometry,x.setAttribute("position",new _.BufferAttribute(g.positions,3)),x.setAttribute("normal",new _.BufferAttribute(g.normals,3)),x.setIndex(new _.BufferAttribute(g.indices,1)),g.uvs&&x.setAttribute("uv",new _.BufferAttribute(g.uvs,2)),g.colors&&x.setAttribute("color",new _.BufferAttribute(g.colors,3,!0)),qe(g.key,x));let H=b.kind==="merged"?wn(x,b.group,v):Mn(x,b.meshMeta,b.group,v);H.userData.sourceComponentId=i??null,R.push(H)}return n.debug&&P().debug(`Mesh batch assembled off-thread: ${R.length} meshes, ${t.indexData.length/3} triangles`),R}var ca=.5,ua=.5,da=.3;function vn(e,n){let t=St(e.color),r=n?.vertexColors??!1,a=n?.appearance,o=new _.MeshPhysicalMaterial({color:t,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,vertexColors:r,side:a?.cullBackfaces?_.FrontSide:_.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.5,polygonOffsetUnits:.5,depthWrite:!0,depthTest:!0});return a?.envMapIntensity!=null&&(o.envMapIntensity=a.envMapIntensity),e.metalness>ca&&(o.clearcoat=ua,o.clearcoatRoughness=da),r&&ma(o),e.map&&nn(o,e.map),o}function ma(e){e.onBeforeCompile=n=>{n.vertexShader=n.vertexShader.replace("#include <color_vertex>",`#include <color_vertex>
113
113
  #if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )
114
114
  vColor.rgb = mix(
115
115
  vColor.rgb / 12.92,
116
116
  pow( ( vColor.rgb + 0.055 ) / 1.055, vec3( 2.4 ) ),
117
117
  step( vec3( 0.04045 ), vColor.rgb )
118
118
  );
119
- #endif`)}}function da(e,n,t,r,a=null,o=null){let i=xn("merged",e.meshes,n,t,a,o),l=$e(i);if(!l){let s=0,c=0;for(let m of e.meshes)s+=m.vertexCount,c+=m.indexCount;let u=new Float32Array(s*3),d=new Uint32Array(c),p=a?new Float32Array(s*2):null,T=o?new Uint8Array(s*3):null,v=0,R=0;for(let m of e.meshes){let g=m.vertexStart*3,b=m.vertexCount*3;if(u.set(n.subarray(g,g+b),v*3),p&&a){let h=m.vertexStart*2;p.set(a.subarray(h,h+m.vertexCount*2),v*2)}T&&o&&T.set(o.subarray(g,g+b),v*3);let x=t.subarray(m.indexStart,m.indexStart+m.indexCount),H=v-m.vertexStart,E=m.vertexStart,f=m.vertexStart+m.vertexCount;for(let h=0;h<x.length;h++){let y=x[h];if(y<E||y>=f)throw Rn(y,m);d[R+h]=y+H}v+=m.vertexCount,R+=m.indexCount}l=new V.BufferGeometry,l.setAttribute("position",new V.BufferAttribute(u,3)),l.setIndex(new V.BufferAttribute(d,1)),p&&l.setAttribute("uv",new V.BufferAttribute(p,2)),T&&l.setAttribute("color",new V.BufferAttribute(T,3,!0)),l.computeVertexNormals(),qe(i,l)}return Mn(l,e,r)}function Mn(e,n,t){let r=new V.Mesh(e,t[n.materialId]),a=n.meshes[0],o=n.meshes.map(i=>i.name).filter(i=>i&&i.length>0);return r.name=o.length>0?o[0]:`merged_material_${n.materialId}`,r.castShadow=!0,r.receiveShadow=!0,r.userData={source:"compute",name:r.name,layer:a?.layer??"",originalIndex:a?.originalIndex??0,metadata:a?.metadata??{},mergedFrom:n.meshes.slice(1).map(i=>({name:i.name,layer:i.layer,originalIndex:i.originalIndex}))},r}function ma(e,n,t,r,a=null,o=null){let i=[];for(let l of e.meshes){let s=l.vertexStart*3,c=l.vertexCount*3,u=xn("single",[l],n,t,a,o),d=$e(u);if(!d){let p=n.slice(s,s+c),T=t.subarray(l.indexStart,l.indexStart+l.indexCount),v=new Uint32Array(T.length),R=l.vertexStart,m=l.vertexStart+l.vertexCount;for(let g=0;g<T.length;g++){let b=T[g];if(b<R||b>=m)throw Rn(b,l);v[g]=b-R}if(d=new V.BufferGeometry,d.setAttribute("position",new V.BufferAttribute(p,3)),d.setIndex(new V.BufferAttribute(v,1)),a){let g=l.vertexStart*2,b=a.slice(g,g+l.vertexCount*2);d.setAttribute("uv",new V.BufferAttribute(b,2))}if(o){let g=o.slice(s,s+c);d.setAttribute("color",new V.BufferAttribute(g,3,!0))}d.computeVertexNormals(),qe(u,d)}i.push(Hn(d,l,e,r))}return i}function Hn(e,n,t,r){let a=new V.Mesh(e,r[t.materialId]);return a.name=n.name,a.userData={source:"compute",name:n.name,layer:n.layer??"",originalIndex:n.originalIndex,metadata:n.metadata??{}},a.castShadow=!0,a.receiveShadow=!0,a}function fa(e){return Math.floor(e.length*3/4)}var Cn={Angstroms:1e-10,Nanometers:1e-9,Microns:1e-6,Millimeters:.001,Centimeters:.01,Decimeters:.1,Meters:1,Dekameters:10,Hectometers:100,Kilometers:1e3,Megameters:1e6,Gigameters:1e9,Microinches:254e-10,Mils:254e-7,Inches:.0254,Feet:.3048,Yards:.9144,Miles:1609.344,NauticalMiles:1852},pa="Display",Ea="DisplayBatch";function ha(e){let n=e.split(".");return n.includes(pa)||n.includes(Ea)}var An=new Set;async function ss(e,n){let t=performance.now(),r=[],{allowScaling:a=!0,allowAutoPosition:o=!1,groundAxis:i="z",rhino:l,debug:s=!1,parsing:c={}}=n??{};try{let u=a?ga(e.modelunits):1;return await ya(e,r,u,c,l,s),o&&xa(r,i),r}catch(u){throw va(u,r),u}finally{s&&Ma(t)}}function ga(e){let n=Cn[e];return n!==void 0?n:(An.has(e)||(An.add(e),P().warn(`Unknown Rhino model unit "${e}" \u2014 geometry will not be scaled (factor 1). Known units: ${Object.keys(Cn).join(", ")}.`)),1)}async function ya(e,n,t,r,a,o){for(let i of e.values){let l=i.InnerTree;for(let s in l){let c=l[s];c&&await ba(c,n,t,r,a,o)}}}async function ba(e,n,t,r,a,o){for(let i of e){if(!ha(i.type))continue;let l={mergeByMaterial:!0,applyTransforms:!0,debug:!1,...r},s=Ta(i.data);if(!s){P().error("Error parsing display batch envelope: invalid JSON");continue}let c=await mt(s,l),u=sn(s.items,{rhino:a,applyTransforms:l.applyTransforms}),d=[...c,...u];if(t!==1)for(let p of d)p.scale.set(t,t,t);n.push(...d),o&&P().debug(`Extracted ${c.length} meshes and ${u.length} items from batch`)}}function Ta(e){return typeof e=="string"?Ra(e):e}function Ra(e){try{return JSON.parse(e)}catch{return}}function xa(e,n){if(e.length===0)return;let t=Ke(e);Dt(e,t.min[n],n)}function va(e,n){P().error("An unexpected error occurred:",e),wa(n)}function wa(e){for(let n of e){let t=n;t.geometry&&t.geometry.dispose(),t.material&&(Array.isArray(t.material)?t.material.forEach(r=>r.dispose()):t.material.dispose())}}function Ma(e){let n=performance.now()-e;P().info("Time to process meshes:",`${n.toFixed(2)}ms`)}export{zn as a,we as b,Oe as c,Ct as d,At as e,Xe as f,La as g,St as h,Dt as i,Ke as j,Lt as k,Ot as l,It as m,He as n,rt as o,Mr as p,ja as q,Yt as r,Xt as s,Ue as t,Kt as u,Jt as v,jr as w,tn as x,Wr as y,nn as z,ui as A,oo as B,Ai as C,Di as D,sn as E,cn as F,Fo as G,un as H,dn as I,lt as J,Bo as K,ko as L,Uo as M,Vo as N,Gi as O,_o as P,ct as Q,es as R,mt as S,ts as T,Cn as U,ss as V};
120
- //# sourceMappingURL=chunk-5LBYVJZD.js.map
119
+ #endif`)}}function fa(e,n,t,r,a=null,o=null){let i=Rn("merged",e.meshes,n,t,a,o),l=$e(i);if(!l){let s=0,c=0;for(let m of e.meshes)s+=m.vertexCount,c+=m.indexCount;let u=new Float32Array(s*3),d=new Uint32Array(c),p=a?new Float32Array(s*2):null,T=o?new Uint8Array(s*3):null,v=0,R=0;for(let m of e.meshes){let g=m.vertexStart*3,b=m.vertexCount*3;if(u.set(n.subarray(g,g+b),v*3),p&&a){let h=m.vertexStart*2;p.set(a.subarray(h,h+m.vertexCount*2),v*2)}T&&o&&T.set(o.subarray(g,g+b),v*3);let x=t.subarray(m.indexStart,m.indexStart+m.indexCount),H=v-m.vertexStart,E=m.vertexStart,f=m.vertexStart+m.vertexCount;for(let h=0;h<x.length;h++){let y=x[h];if(y<E||y>=f)throw Tn(y,m);d[R+h]=y+H}v+=m.vertexCount,R+=m.indexCount}l=new _.BufferGeometry,l.setAttribute("position",new _.BufferAttribute(u,3)),l.setIndex(new _.BufferAttribute(d,1)),p&&l.setAttribute("uv",new _.BufferAttribute(p,2)),T&&l.setAttribute("color",new _.BufferAttribute(T,3,!0)),l.computeVertexNormals(),qe(i,l)}return wn(l,e,r)}function wn(e,n,t){let r=new _.Mesh(e,t[n.materialId]),a=n.meshes[0],o=n.meshes.map(i=>i.name).filter(i=>i&&i.length>0);return r.name=o.length>0?o[0]:`merged_material_${n.materialId}`,r.castShadow=!0,r.receiveShadow=!0,r.userData={source:"compute",name:r.name,layer:a?.layer??"",originalIndex:a?.originalIndex??0,metadata:a?.metadata??{},mergedFrom:n.meshes.slice(1).map(i=>({name:i.name,layer:i.layer,originalIndex:i.originalIndex}))},r}function pa(e,n,t,r,a=null,o=null){let i=[];for(let l of e.meshes){let s=l.vertexStart*3,c=l.vertexCount*3,u=Rn("single",[l],n,t,a,o),d=$e(u);if(!d){let p=n.slice(s,s+c),T=t.subarray(l.indexStart,l.indexStart+l.indexCount),v=new Uint32Array(T.length),R=l.vertexStart,m=l.vertexStart+l.vertexCount;for(let g=0;g<T.length;g++){let b=T[g];if(b<R||b>=m)throw Tn(b,l);v[g]=b-R}if(d=new _.BufferGeometry,d.setAttribute("position",new _.BufferAttribute(p,3)),d.setIndex(new _.BufferAttribute(v,1)),a){let g=l.vertexStart*2,b=a.slice(g,g+l.vertexCount*2);d.setAttribute("uv",new _.BufferAttribute(b,2))}if(o){let g=o.slice(s,s+c);d.setAttribute("color",new _.BufferAttribute(g,3,!0))}d.computeVertexNormals(),qe(u,d)}i.push(Mn(d,l,e,r))}return i}function Mn(e,n,t,r){let a=new _.Mesh(e,r[t.materialId]);return a.name=n.name,a.userData={source:"compute",name:n.name,layer:n.layer??"",originalIndex:n.originalIndex,metadata:n.metadata??{}},a.castShadow=!0,a.receiveShadow=!0,a}function Ea(e){return Math.floor(e.length*3/4)}var Hn={Angstroms:1e-10,Nanometers:1e-9,Microns:1e-6,Millimeters:.001,Centimeters:.01,Decimeters:.1,Meters:1,Dekameters:10,Hectometers:100,Kilometers:1e3,Megameters:1e6,Gigameters:1e9,Microinches:254e-10,Mils:254e-7,Inches:.0254,Feet:.3048,Yards:.9144,Miles:1609.344,NauticalMiles:1852},ha="Display",ga="DisplayBatch";function ya(e){let n=e.split(".");return n.includes(ha)||n.includes(ga)}var Cn=new Set;async function cs(e,n){let t=performance.now(),r=[],{allowScaling:a=!0,allowAutoPosition:o=!1,groundAxis:i="z",rhino:l,debug:s=!1,parsing:c={}}=n??{};try{let u=a?ba(e.modelunits):1;return await Ta(e,r,u,c,l,s),o&&wa(r,i),r}catch(u){throw Ma(u,r),u}finally{s&&Ca(t)}}function ba(e){let n=Hn[e];return n!==void 0?n:(Cn.has(e)||(Cn.add(e),P().warn(`Unknown Rhino model unit "${e}" \u2014 geometry will not be scaled (factor 1). Known units: ${Object.keys(Hn).join(", ")}.`)),1)}async function Ta(e,n,t,r,a,o){for(let i of e.values){let l=i.InnerTree;for(let s in l){let c=l[s];c&&await Ra(c,n,t,r,a,o)}}}async function Ra(e,n,t,r,a,o){for(let i of e){if(!ya(i.type))continue;let l={mergeByMaterial:!0,applyTransforms:!0,debug:!1,...r},s=xa(i.data);if(!s){P().error("Error parsing display batch envelope: invalid JSON");continue}let c=await mt(s,l),u=an(s.items,{rhino:a,applyTransforms:l.applyTransforms}),d=[...c,...u];if(t!==1)for(let p of d)p.scale.set(t,t,t);n.push(...d),o&&P().debug(`Extracted ${c.length} meshes and ${u.length} items from batch`)}}function xa(e){return typeof e=="string"?va(e):e}function va(e){try{return JSON.parse(e)}catch{return}}function wa(e,n){if(e.length===0)return;let t=Ke(e);Dt(e,t.min[n],n)}function Ma(e,n){P().error("An unexpected error occurred:",e),Ha(n)}function Ha(e){for(let n of e){let t=n;t.geometry&&t.geometry.dispose(),t.material&&(Array.isArray(t.material)?t.material.forEach(r=>r.dispose()):t.material.dispose())}}function Ca(e){let n=performance.now()-e;P().info("Time to process meshes:",`${n.toFixed(2)}ms`)}export{Vn as a,we as b,Oe as c,Ct as d,At as e,Xe as f,Ia as g,St as h,Dt as i,Ke as j,Lt as k,Ot as l,It as m,He as n,rt as o,Cr as p,$a as q,qt as r,Yt as s,Ue as t,Xt as u,Zt as v,$r as w,en as x,qr as y,tn as z,mi as A,io as B,Di as C,Oi as D,an as E,ln as F,ko as G,cn as H,un as I,lt as J,Uo as K,_o as L,Vo as M,zo as N,ji as O,Go as P,ct as Q,ns as R,mt as S,rs as T,Hn as U,cs as V};
120
+ //# sourceMappingURL=chunk-N2WCSETE.js.map