@selvajs/compute 2.1.0-beta.3 → 2.1.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,55 @@
1
+ import{a as Se,c as Q,d as ee,e as v,o as se}from"./chunk-XFYFC2DH.js";import*as B from"three";var N={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 gn(e,r,t,n,i){if(Ae(e),r.length===0)return;r.forEach(d=>{e.add(d)});let o=Y(r),a=o.getCenter(new B.Vector3),s=o.getSize(new B.Vector3),l=Math.max(s.x,s.y,s.z);if(l/Math.min(s.x||1,s.y||1,s.z||1)>N.SCALE_RATIO_THRESHOLD||l>N.HUGE_THRESHOLD?(t.near=l*N.NEAR_PLANE_FACTOR.TINY,t.far=l*N.FAR_PLANE_FACTOR.HUGE):l>N.LARGE_THRESHOLD?(t.near=l*N.NEAR_PLANE_FACTOR.SMALL,t.far=l*N.FAR_PLANE_FACTOR.LARGE):(t.near=Math.max(.01,l*N.NEAR_PLANE_FACTOR.NORMAL),t.far=Math.max(2e3,l*N.FAR_PLANE_FACTOR.NORMAL)),t.updateProjectionMatrix(),i)n.minDistance=t.near*2,n.maxDistance=t.far*.9;else{let d=l*N.INITIAL_DISTANCE_MULTIPLIER;t.position.set(a.x+d*.8,a.y+d,a.z+d*1.2),n.target.copy(a),n.minDistance=t.near*2,n.maxDistance=t.far*.9,n.update()}}function le(e){if(!e||typeof e!="string")return v().warn(`Invalid color input: ${e}, using white`),new B.Color(16777215);let r=e.trim();if(/^#?[0-9A-Fa-f]{6}$/.test(r))try{let t=r.startsWith("#")?r:`#${r}`;return new B.Color(t)}catch{return v().warn(`Invalid hex color: ${e}, using white`),new B.Color(16777215)}if(r.includes(",")){let t=r.split(",").map(n=>parseInt(n.trim(),10));if(t.length===3&&t.every(n=>!isNaN(n)&&n>=0&&n<=255))return new B.Color(t[0]/255,t[1]/255,t[2]/255)}try{return new B.Color(r.toLowerCase())}catch{return v().warn(`Invalid color string: ${e}, using white`),new B.Color(16777215)}}function ce(e,r){e.forEach(t=>{t.position.y-=r})}function Y(e){let r=new B.Box3;return e.length===0||e.forEach(t=>{t.updateMatrixWorld(!0);let n=new B.Box3().setFromObject(t);r.union(n)}),r}function Ae(e){[...e.children].forEach(t=>{t.userData.id!=="floor"&&(t.traverse(n=>{let i=n;if(!i.geometry&&!i.material)return;i.geometry?.dispose();let o=i.material;if(!o)return;(Array.isArray(o)?o:[o]).forEach(s=>{for(let l of Object.values(s))l instanceof B.Texture&&l.dispose();s.dispose()})}),t.removeFromParent())})}import*as F from"three";function De(e){let r=e.clone().normalize(),t=new F.Vector3(0,0,1),n=new F.Vector3(0,1,0),i=Math.abs(r.dot(t))>.9?n:t,o=new F.Vector3().crossVectors(r,i).normalize(),a=new F.Vector3().crossVectors(o,r).normalize();return{top:r.clone(),bottom:r.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(r.clone()).normalize()}}function de(e){let{scene:r,perspective:t,controls:n,onActiveCameraChange:i}=e,o=(e.up??t.up).clone().normalize(),a=De(o),s=new F.OrthographicCamera(-1,1,1,-1,t.near,t.far);s.up.copy(o);let l="perspective",c=t.aspect,d=()=>l==="perspective"?t:s,u=()=>{let g=t.position.distanceTo(n.target)*Math.tan(t.fov*Math.PI/360),R=g*c;s.left=-R,s.right=R,s.top=g,s.bottom=-g,s.near=t.near,s.far=t.far,s.updateProjectionMatrix()},m=y=>{y!==l&&(y==="orthographic"?(s.position.copy(t.position),s.up.copy(t.up),s.lookAt(n.target),u()):t.position.copy(s.position),l=y,n.object=d(),n.update(),i(d()))},E=(y,g=!0)=>{let R=Oe(r),M=R.isEmpty()?n.target.clone():R.getCenter(new F.Vector3),D=R.isEmpty()?new F.Vector3(1,1,1):R.getSize(new F.Vector3),b=Math.max(D.x,D.y,D.z)||1,w=t.fov*(Math.PI/180),H=b/(2*Math.tan(w/2))*1.5,L=Ie(y,o),f=M.clone().add(L.clone().multiplyScalar(H)),T=d();g?Be(T,n,f,M,()=>{l==="orthographic"&&u()}):(T.position.copy(f),n.target.copy(M),l==="orthographic"&&u(),n.update())};return{getActiveCamera:d,getProjection:()=>l,setProjection:m,toggleProjection:()=>(m(l==="perspective"?"orthographic":"perspective"),l),setView:(y,g=!0)=>{E(a[y],g)},setViewDirection:E,setRotateEnabled:y=>{n.enableRotate=y},isRotateEnabled:()=>n.enableRotate,updateAspect:(y,g)=>{c=g===0?c:y/g,l==="orthographic"&&u()}}}var Le=new Set(["grid","floor","label-layer","measure"]);function Pe(e){let r=e;for(;r;){if(typeof r.userData.id=="string"&&Le.has(r.userData.id))return!0;r=r.parent}return!1}function Oe(e){let r=[];return e.traverse(t=>{let n=t;t.visible&&!Pe(t)&&n.geometry&&r.push(t)}),Y(r)}function Ie(e,r){let t=r.clone().normalize(),n=e.clone().normalize();if(Math.abs(n.dot(t))<.9999)return e;let i=Math.abs(t.dot(new F.Vector3(0,0,1)))>.9?new F.Vector3(0,1,0):new F.Vector3(0,0,1),o=new F.Vector3().crossVectors(t,i).normalize(),a=.5*Math.PI/180;return n.multiplyScalar(Math.cos(a)).add(o.multiplyScalar(Math.sin(a))).normalize()}var Ve=e=>1-Math.pow(1-e,3);function Be(e,r,t,n,i,o=250){let a=e.position.clone(),s=r.target.clone(),l=performance.now(),c=()=>{let d=Ve(Math.min((performance.now()-l)/o,1));e.position.lerpVectors(a,t,d),r.target.lerpVectors(s,n,d),i(),r.update(),d<1&&requestAnimationFrame(c)};requestAnimationFrame(c)}import*as I from"three";var ze=`
2
+ varying vec3 vWorldPos;
3
+ void main() {
4
+ vec4 world = modelMatrix * vec4(position, 1.0);
5
+ vWorldPos = world.xyz;
6
+ gl_Position = projectionMatrix * viewMatrix * world;
7
+ }
8
+ `,Fe=`
9
+ precision highp float;
10
+ varying vec3 vWorldPos;
11
+
12
+ uniform vec2 uAxes; // indices (0=x,1=y,2=z) of the two in-plane world axes
13
+ uniform float uCell;
14
+ uniform float uMajor;
15
+ uniform vec3 uCellColor;
16
+ uniform vec3 uMajorColor;
17
+ uniform vec3 uCenter; // fade center (camera position), projected onto plane
18
+ uniform float uFade;
19
+
20
+ // Antialiased grid line intensity for a given spacing, using screen-space derivatives so lines
21
+ // stay ~1px regardless of zoom (the standard "pristine grid" technique).
22
+ float gridLine(vec2 coord, float spacing) {
23
+ vec2 c = coord / spacing;
24
+ vec2 d = fwidth(c);
25
+ vec2 g = abs(fract(c - 0.5) - 0.5) / max(d, 1e-6);
26
+ float line = min(g.x, g.y);
27
+ return 1.0 - clamp(line, 0.0, 1.0);
28
+ }
29
+
30
+ // Index a vec3 by a float axis id (0/1/2) without dynamic indexing (WebGL1-safe).
31
+ float axis(vec3 v, float i) {
32
+ return i < 0.5 ? v.x : (i < 1.5 ? v.y : v.z);
33
+ }
34
+
35
+ void main() {
36
+ // Pick the two in-plane world coordinates.
37
+ vec2 coord = vec2(axis(vWorldPos, uAxes.x), axis(vWorldPos, uAxes.y));
38
+
39
+ float minor = gridLine(coord, uCell);
40
+ float major = gridLine(coord, uCell * uMajor);
41
+
42
+ vec3 color = mix(uCellColor, uMajorColor, major);
43
+ float alpha = max(minor, major);
44
+
45
+ // Radial fade from the camera-projected center.
46
+ float dist = distance(vWorldPos, uCenter);
47
+ float fade = 1.0 - clamp(dist / uFade, 0.0, 1.0);
48
+ alpha *= fade * fade;
49
+
50
+ if (alpha < 0.001) discard;
51
+ gl_FragColor = vec4(color, alpha);
52
+ }
53
+ `;function ue(e={}){let{cellSize:r=1,majorEvery:t=10,cellColor:n=8947848,majorColor:i=4473924,fadeDistance:o=100,plane:a="y"}=e,s=a==="y"?new I.Vector2(0,2):a==="z"?new I.Vector2(0,1):new I.Vector2(1,2),l=o*2.5,c=new I.PlaneGeometry(l,l);a==="y"?c.rotateX(-Math.PI/2):a==="x"&&c.rotateY(Math.PI/2);let d=new I.ShaderMaterial({vertexShader:ze,fragmentShader:Fe,transparent:!0,depthWrite:!1,side:I.DoubleSide,uniforms:{uAxes:{value:s},uCell:{value:r},uMajor:{value:t},uCellColor:{value:new I.Color(n)},uMajorColor:{value:new I.Color(i)},uCenter:{value:new I.Vector3},uFade:{value:o}}}),u=new I.Mesh(c,d);u.name="grid",u.userData.id="grid",u.renderOrder=-1;let m=new I.Vector3;return{object:u,update:E=>{a==="y"?(u.position.set(E.x,0,E.z),m.set(E.x,0,E.z)):a==="z"?(u.position.set(E.x,E.y,0),m.set(E.x,E.y,0)):(u.position.set(0,E.y,E.z),m.set(0,E.y,E.z)),d.uniforms.uCenter.value.copy(m)},setVisible:E=>{u.visible=E},dispose:()=>{c.dispose(),d.dispose()}}}import*as k from"three";import{ViewHelper as ke}from"three/addons/helpers/ViewHelper.js";function me(e){let{camera:r,domElement:t,controller:n}=e,i=new ke(r,t);i.setLabels("X","Y","Z");let o=!0,a=128,s=new k.Raycaster,l=new k.OrthographicCamera(-2,2,2,-2,0,4);l.position.set(0,0,2);let c={posX:new k.Vector3(1,0,0),negX:new k.Vector3(-1,0,0),posY:new k.Vector3(0,1,0),negY:new k.Vector3(0,-1,0),posZ:new k.Vector3(0,0,1),negZ:new k.Vector3(0,0,-1)},d=m=>{let E=t.getBoundingClientRect(),p=E.left+t.offsetWidth-a-i.location.right,A=E.top+t.offsetHeight-a-i.location.bottom,O=new k.Vector2((m.clientX-p)/a*2-1,-((m.clientY-A)/a)*2+1);if(Math.abs(O.x)>1||Math.abs(O.y)>1)return null;i.quaternion.copy(r.quaternion).invert(),i.updateMatrixWorld(),s.setFromCamera(O,l);let y=s.intersectObjects(i.children,!1);for(let g of y){let R=g.object.userData?.type;if(typeof R=="string"&&R in c)return R}return null};return{render:m=>{if(!o)return;let E=m.autoClear;m.autoClear=!1,i.render(m),m.autoClear=E},update:m=>{i.animating&&i.update(m)},handleClick:m=>{if(!o)return!1;let E=d(m);return E?(n.getProjection()==="orthographic"&&n.setProjection("perspective"),n.setViewDirection(c[E],!1),!0):!1},get isAnimating(){return i.animating},setVisible:m=>{o=m},isVisible:()=>o,dispose:()=>i.dispose()}}import*as W from"three";import{LineSegmentsGeometry as je}from"three/addons/lines/LineSegmentsGeometry.js";import{LineSegments2 as pe}from"three/addons/lines/LineSegments2.js";import{LineMaterial as _e}from"three/addons/lines/LineMaterial.js";var q="edge-overlay",Ge=2236962,Ne=1.5,Ue=30;function Ee(e,r={}){let t=new W.Color(r.color??Ge),n=r.width??Ne,i=r.thresholdAngle??Ue,o=[];return e.traverse(a=>{if(!(a instanceof W.Mesh)||a.userData.id==="floor"||a.userData.id==="grid"||a.userData.kind===q||a.children.some(l=>l.userData?.kind===q)||!a.geometry)return;let s=We(a.geometry,t,n,i);a.add(s),o.push(s)}),o}function We(e,r,t,n){let i=new W.EdgesGeometry(e,n),o=new je;o.setPositions(Array.from(i.attributes.position.array)),i.dispose();let a=new _e({color:r});a.linewidth=t,a.polygonOffset=!0,a.polygonOffsetFactor=-1,a.polygonOffsetUnits=-1;let s=new pe(o,a);return s.userData.kind=q,s.raycast=()=>{},s}function $e(e){return e.userData?.kind===q}function xn(e){let r=[];e.traverse(t=>{t instanceof pe&&$e(t)&&r.push(t)});for(let t of r)t.geometry.dispose(),t.material.dispose(),t.removeFromParent();return r.length}import{EffectComposer as Ye}from"three/addons/postprocessing/EffectComposer.js";import{RenderPass as Xe}from"three/addons/postprocessing/RenderPass.js";import{GTAOPass as qe}from"three/addons/postprocessing/GTAOPass.js";import{OutputPass as Ze}from"three/addons/postprocessing/OutputPass.js";function fe(e,r,t,n,i,o){let a=new Ye(e),s=new Xe(r,t);a.addPass(s);let l=new qe(r,t,n,i);l.blendIntensity=o.aoIntensity??1,l.updateGtaoMaterial({screenSpaceRadius:!0}),a.addPass(l);let c=new Ze;return a.addPass(c),e.toneMapping=o.toneMapping,e.toneMappingExposure=o.toneMappingExposure,a.setSize(n,i),{render:d=>a.render(d),setSize:(d,u,m)=>{a.setPixelRatio(m),a.setSize(d,u),l.setSize(d,u)},setCamera:d=>{s.camera=d,l.camera=d},dispose:()=>a.dispose()}}import*as he from"three";import{CSS2DRenderer as Je,CSS2DObject as Ke}from"three/addons/renderers/CSS2DRenderer.js";function ge(e,r){let t=new Je,n=t.domElement;n.style.position="absolute",n.style.top="0",n.style.left="0",n.style.width="100%",n.style.height="100%",n.style.overflow="hidden",n.style.pointerEvents="none",getComputedStyle(e).position==="static"&&(e.style.position="relative"),e.appendChild(n);let i={width:e.clientWidth||1,height:e.clientHeight||1};t.setSize(i.width,i.height);let o=new he.Group;o.name="label-layer",o.userData.id="label-layer",r.add(o);let a=new Set;return{addLabel:(l,c,d)=>{let u=document.createElement("div");u.textContent=l,d?u.className=d:Object.assign(u.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"}),u.style.pointerEvents="none";let m=new Ke(u);return m.position.copy(c),o.add(m),a.add(m),{object:m,setPosition:E=>m.position.copy(E),setText:E=>{u.textContent=E},remove:()=>{m.removeFromParent(),u.remove(),a.delete(m)}}},render:(l,c)=>t.render(l,c),setSize:(l,c)=>t.setSize(l,c),dispose:()=>{a.forEach(l=>{l.removeFromParent(),l.element.remove()}),a.clear(),o.removeFromParent(),n.remove()}}}import*as S from"three";import{Line2 as Qe}from"three/addons/lines/Line2.js";import{LineGeometry as et}from"three/addons/lines/LineGeometry.js";import{LineMaterial as tt}from"three/addons/lines/LineMaterial.js";var nt=12,rt=16763904,Z=e=>`${e.toPrecision(3)} m`,ot=(e,r)=>`${Z(e)}
54
+ \u0394x ${Z(r.x)} \u0394y ${Z(r.y)} \u0394z ${Z(r.z)}`;function at(e,r,t,n){let i=e.point.clone(),o=e.object;if(!(o instanceof S.Mesh)||e.face==null||!o.geometry)return i;let a=o.geometry.attributes.position;if(!a)return i;let s=u=>{let m=u.clone().project(r);return new S.Vector2((m.x+1)/2*t.width,(1-m.y)/2*t.height)},l=s(i),c=i,d=n;for(let u of[e.face.a,e.face.b,e.face.c]){let E=new S.Vector3().fromBufferAttribute(a,u).applyMatrix4(o.matrixWorld),p=s(E).distanceTo(l);p<d&&(d=p,c=E)}return c}function be(e){let{canvas:r,scene:t,getActiveCamera:n,labelLayer:i,options:o={}}=e,a=o.snapPixels??nt,s=new S.Color(o.color??rt),l=o.format??ot,c=new S.Raycaster,d=new S.Vector2,u=!1,m=[],E=[],p=null,A=null,O=new S.PointsMaterial({color:s,size:8,sizeAttenuation:!1,depthTest:!1}),y=new S.PointsMaterial({color:s,size:11,sizeAttenuation:!1,depthTest:!1,transparent:!0,opacity:.5}),g=null,R=f=>{if(!f){g&&(g.visible=!1);return}if(!g){let T=new S.BufferGeometry;T.setAttribute("position",new S.Float32BufferAttribute([0,0,0],3)),g=new S.Points(T,y),g.renderOrder=1e3,g.userData.id="measure",g.raycast=()=>{},t.add(g)}g.position.copy(f),g.visible=!0},M=f=>{let T=new S.BufferGeometry;T.setAttribute("position",new S.Float32BufferAttribute([f.x,f.y,f.z],3));let P=new S.Points(T,O);return P.renderOrder=999,P.userData.id="measure",P.raycast=()=>{},t.add(P),P},D=()=>{m.length=0,E.forEach(f=>{f.geometry.dispose(),f.removeFromParent()}),E.length=0,p&&(p.geometry.dispose(),p.material.dispose(),p.removeFromParent(),p=null),A?.remove(),A=null},b=()=>{if(m.length!==2)return;let[f,T]=m,P=new et;P.setPositions([f.x,f.y,f.z,T.x,T.y,T.z]);let V=new tt({color:s});V.linewidth=2,V.depthTest=!1,p=new Qe(P,V),p.renderOrder=998,p.userData.id="measure",p.raycast=()=>{},t.add(p);let G=f.clone().add(T).multiplyScalar(.5),X=new S.Vector3(Math.abs(T.x-f.x),Math.abs(T.y-f.y),Math.abs(T.z-f.z));A=i.addLabel(l(f.distanceTo(T),X),G,o.labelClassName)},w=f=>{let T=r.getBoundingClientRect();d.x=(f.clientX-T.left)/T.width*2-1,d.y=-((f.clientY-T.top)/T.height)*2+1;let P=n();c.setFromCamera(d,P);let V=c.intersectObjects(t.children,!0).filter(G=>G.object.userData.id!=="measure"&&G.object.userData.id!=="grid");return V.length===0?null:at(V[0],P,{width:T.width,height:T.height},a)};return{setEnabled:f=>{u=f,f||(D(),R(null))},isEnabled:()=>u,handleClick:f=>{if(!u)return!1;m.length===2&&D();let T=w(f);return T===null||(m.push(T),E.push(M(T)),m.length===2&&b()),!0},handleMove:f=>{u&&R(w(f))},clear:D,dispose:()=>{D(),g&&(g.geometry.dispose(),g.removeFromParent(),g=null),O.dispose(),y.dispose()}}}import*as h from"three";import{OrbitControls as it}from"three/addons/controls/OrbitControls.js";import{HDRLoader as st}from"three/addons/loaders/HDRLoader.js";var J=new h.Vector3(0,0,1);function lt(e){let r=Math.abs(e.x),t=Math.abs(e.y),n=Math.abs(e.z);return n>=r&&n>=t?"z":t>=r&&t>=n?"y":"x"}var te=(e,r,t,n)=>{switch(e){case"mm":return r;case"cm":return t;default:return n}},Zn=function(e,r){let t=ct(r||{}),n=t.environment?.sceneUp||J,i=ut(t),o=gt(t,e);o.up.copy(n);let a=bt(e,t),s=Rt(o,e,t),l=de({scene:i,perspective:o,controls:s,onActiveCameraChange:()=>{},up:n}),c=()=>l.getActiveCamera();Et(i,t),ft(i,t),t.floor?.enabled&&ht(i,t);let d=t.grid.enabled?ue({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;d&&i.add(d.object);let u=t.gizmo.enabled?me({camera:o,domElement:e,controller:l}):null,m=e.parentElement??e,E=t.measure.enabled?ge(m,i):null,p=t.measure.enabled&&E?be({canvas:e,scene:i,getActiveCamera:c,labelLayer:E,options:{snapPixels:t.measure.snapPixels,color:t.measure.color,labelClassName:t.measure.labelClassName,format:t.measure.format}}):null,A=t.events.enableEventHandlers!==!1?yt(e,i,c,o,s,t):{dispose:()=>{},fitToView:()=>{},clearSelection:()=>{}},O=5,y=0,g=0,R=C=>{y=C.clientX,g=C.clientY},M=C=>Math.hypot(C.clientX-y,C.clientY-g)>O,D=C=>{if(!M(C)){if(p?.handleClick(C)){C.stopImmediatePropagation();return}u?.handleClick(C)&&C.stopImmediatePropagation()}};(u||p)&&(e.addEventListener("mousedown",R,{capture:!0}),e.addEventListener("click",D,{capture:!0}));let b=C=>p?.handleMove(C);p&&e.addEventListener("mousemove",b,{passive:!0});let w=C=>{Ee(C,{color:t.edges.color,width:t.edges.width,thresholdAngle:t.edges.thresholdAngle})},H=e.parentElement,L=()=>H?{width:H.clientWidth,height:H.clientHeight}:{width:window.innerWidth,height:window.innerHeight},f=null,T=()=>{let{width:C,height:_}=L(),$=Math.min(window.devicePixelRatio,2),ie=fe(a,i,c(),Math.max(1,C),Math.max(1,_),{toneMapping:t.render.toneMapping??h.NeutralToneMapping,toneMappingExposure:t.render.toneMappingExposure??1,aoIntensity:t.render.aoIntensity});return ie.setSize(Math.max(1,C),Math.max(1,_),$),ie},P=C=>{C&&!f?f=T():!C&&f&&(f.dispose(),f=null)};t.render.ambientOcclusion&&(f=T());let{animate:V,dispose:G}=pt(a,i,o,c,l,s,L,t.events.onFrame,d,u,()=>f,E);return V(),i.up.set(n.x,n.y,n.z),{scene:i,camera:o,controls:s,renderer:a,cameraController:l,grid:d,gizmo:u,measureTool:p,applyEdges:w,setAmbientOcclusion:P,dispose:()=>{G(),A.dispose(),(u||p)&&(e.removeEventListener("mousedown",R,{capture:!0}),e.removeEventListener("click",D,{capture:!0})),p&&e.removeEventListener("mousemove",b),p?.dispose(),E?.dispose(),u?.dispose(),d?.dispose(),f?.dispose(),s.dispose(),a.dispose(),i.traverse(C=>{let _=C;!_.geometry&&!_.material||(_.geometry?.dispose(),Array.isArray(_.material)?_.material.forEach($=>$.dispose()):_.material?.dispose())})},fitToView:A.fitToView,clearSelection:A.clearSelection}};function ct(e){let r=e.sceneScale||"m",n={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}}[r];return{sceneScale:r,camera:{position:e.camera?.position||new h.Vector3(-n.cameraDistance,-n.cameraDistance,n.cameraDistance),fov:e.camera?.fov||20,near:e.camera?.near||n.near,far:e.camera?.far||n.far,target:e.camera?.target||new h.Vector3(0,0,0)},lighting:{enableSunlight:e.lighting?.enableSunlight??!0,sunlightIntensity:e.lighting?.sunlightIntensity||1,sunlightPosition:e.lighting?.sunlightPosition||new h.Vector3(n.lightDistance,n.lightDistance,n.lightHeight),ambientLightColor:e.lighting?.ambientLightColor||new h.Color(4210752),ambientLightIntensity:e.lighting?.ambientLightIntensity||1,sunlightColor:e.lighting?.sunlightColor||16777215},environment:{hdrPath:e.environment?.hdrPath||"/baseHDR.hdr",backgroundColor:e.environment?.backgroundColor||new h.Color(15790320),enableEnvironmentLighting:e.environment?.enableEnvironmentLighting??!0,sceneUp:e.environment?.sceneUp||J,showEnvironment:e.environment?.showEnvironment??!1},floor:{enabled:e.floor?.enabled??!1,size:e.floor?.size||n.floorSize,color:e.floor?.color||new h.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||h.NeutralToneMapping,toneMappingExposure:e.render?.toneMappingExposure||1,preserveDrawingBuffer:e.render?.preserveDrawingBuffer??!1,ambientOcclusion:e.render?.ambientOcclusion??!1,aoIntensity:e.render?.aoIntensity??1},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||n.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??lt(e.environment?.sceneUp??J)},gizmo:{enabled:e.gizmo?.enabled??!1},edges:{enabled:e.edges?.enabled??!1,color:e.edges?.color??2236962,width:e.edges?.width??1.5,thresholdAngle:e.edges?.thresholdAngle??30},measure:{enabled:e.measure?.enabled??!1,snapPixels:e.measure?.snapPixels,color:e.measure?.color,labelClassName:e.measure?.labelClassName,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}}}var dt=new Set(["grid","floor","label-layer","measure"]);function ye(e){let r=e;for(;r;){if(typeof r.userData.id=="string"&&dt.has(r.userData.id))return!0;r=r.parent}return!1}function ut(e){let r=new h.Scene,t=typeof e.environment.backgroundColor=="string"?new h.Color(e.environment.backgroundColor):e.environment.backgroundColor;return r.background=t||null,r}function mt(e,r,t,n,i=200){let o=e.position.clone(),a=r.target.clone(),s=performance.now(),l=d=>1-Math.pow(1-d,3),c=()=>{let d=performance.now()-s,u=l(Math.min(d/i,1));e.position.lerpVectors(o,t,u),r.target.lerpVectors(a,n,u),r.update(),u<1&&requestAnimationFrame(c)};requestAnimationFrame(c)}function pt(e,r,t,n,i,o,a,s,l,c,d,u){let m=null,E=performance.now(),p=()=>{let{width:y,height:g}=a();if(y===0||g===0)return;let R=Math.min(window.devicePixelRatio,2),M=Math.round(y*R),D=Math.round(g*R);(e.domElement.width!==M||e.domElement.height!==D)&&(e.setPixelRatio(R),e.setSize(y,g,!1),t.aspect=y/g,t.updateProjectionMatrix(),i.updateAspect(y,g),d?.()?.setSize(y,g,R),u?.setSize(y,g))},A=function(){m=requestAnimationFrame(A);let y=performance.now(),g=(y-E)/1e3;E=y,p(),(o.enableDamping||o.autoRotate)&&o.update(),l&&l.update(n().position),c&&c.update(g),s?.(g);let R=n(),M=d?.();M?(M.setCamera(R),M.render(g)):e.render(r,R),u&&u.render(r,R),c&&c.render(e)};return{animate:A,dispose:()=>{m!==null&&(cancelAnimationFrame(m),m=null)}}}function Et(e,r){r.environment.enableEnvironmentLighting?new st().load(r.environment.hdrPath||"/baseHDR.hdr",function(t){if(!t?.image){v().warn("HDR loaded without image data; skipping environment map."),r.events.onReady?.();return}t.mapping=h.EquirectangularReflectionMapping,e.environment=t,r.environment.showEnvironment&&(e.background=t),r.events.onReady?.()},void 0,function(t){v().warn("HDR texture could not be loaded, falling back to basic lighting:",t),r.events.onReady?.()}):r.events.onReady?.()}function ft(e,r){let t=new h.AmbientLight(r.lighting.ambientLightColor,r.lighting.ambientLightIntensity);if(e.add(t),r.lighting.enableSunlight){let n=new h.DirectionalLight(r.lighting.sunlightColor??16777215,r.lighting.sunlightIntensity),i=r.lighting.sunlightPosition;if(i&&n.position.set(i.x,i.y,i.z),r.render.enableShadows){n.castShadow=!0;let o=te(r.sceneScale,.1,10,100);n.shadow.camera.left=-o,n.shadow.camera.right=o,n.shadow.camera.top=o,n.shadow.camera.bottom=-o;let a=te(r.sceneScale,.001,.1,.5),s=te(r.sceneScale,1,100,500);n.shadow.camera.near=a,n.shadow.camera.far=s,n.shadow.mapSize.width=r.render.shadowMapSize||2048,n.shadow.mapSize.height=r.render.shadowMapSize||2048,n.shadow.bias=-1e-4,n.shadow.normalBias=.02}e.add(n)}}function ht(e,r){let t=r.floor.size,n=new h.PlaneGeometry(t,t),i=typeof r.floor.color=="string"?new h.Color(r.floor.color):r.floor.color,o=new h.MeshStandardMaterial({color:i,roughness:r.floor.roughness,metalness:r.floor.metalness,side:h.DoubleSide}),a=new h.Mesh(n,o);a.userData.id="floor",a.name="floor";let s=(r.environment?.sceneUp||J).clone().normalize();a.quaternion.setFromUnitVectors(new h.Vector3(0,0,1),s),a.position.set(0,0,0),r.floor.receiveShadow&&r.render.enableShadows&&(a.receiveShadow=!0),e.add(a)}function gt(e,r){let t=r.parentElement,n=t?t.clientWidth:window.innerWidth,i=t?t.clientHeight:window.innerHeight,o=new h.PerspectiveCamera(e.camera.fov,n/i,e.camera.near,e.camera.far),a=e.camera.position;return a&&o.position.set(a.x,a.y,a.z),o}function bt(e,r){let t=new h.WebGLRenderer({antialias:r.render.antialias,canvas:e,alpha:!0,powerPreference:"high-performance",preserveDrawingBuffer:r.render.preserveDrawingBuffer,logarithmicDepthBuffer:!0}),n=e.parentElement,i=n?n.clientWidth:window.innerWidth,o=n?n.clientHeight:window.innerHeight;return n&&(e.style.width="100%",e.style.height="100%",e.style.display="block"),t.setSize(i,o,!1),t.setPixelRatio(r.render.pixelRatio||Math.min(window.devicePixelRatio,2)),r.render.enableShadows&&(t.shadowMap.enabled=!0,t.shadowMap.type=h.VSMShadowMap),t.toneMapping=r.render.toneMapping,t.toneMappingExposure=r.render.toneMappingExposure||1,t.outputColorSpace=h.SRGBColorSpace,t.sortObjects=!0,t}function yt(e,r,t,n,i,o){let a=new Set,s=new Map,l=new h.Raycaster,c=new h.Vector2,d=new h.Vector2,u=b=>{let w=b;for(;w;){if(!w.visible)return!1;w=w.parent}return!0},m=()=>{let b=new h.Box3;if(r.traverse(V=>{let G=V;V.visible&&!ye(V)&&G.geometry&&b.expandByObject(V)}),b.isEmpty()){v().warn("No objects to fit to view");return}let w=b.getCenter(new h.Vector3),H=b.getSize(new h.Vector3),L=Math.max(H.x,H.y,H.z),f=n.fov*(Math.PI/180),T=L/(2*Math.tan(f/2));T*=1.5;let P=n.position.clone().sub(i.target);P.lengthSq()<1e-12&&P.set(.8,1,1.2),P.normalize(),n.position.copy(w.clone().add(P.multiplyScalar(T))),i.target.copy(w),i.update()},E=typeof o.events.selectionColor=="string"?new h.Color(o.events.selectionColor):o.events.selectionColor instanceof h.Color?o.events.selectionColor:new h.Color("#ff0000"),p=()=>{a.forEach(b=>{let w=b;if(s.has(b)){let H=s.get(b),L=w.material;L instanceof h.Material?L.dispose():Array.isArray(L)&&L.forEach(f=>f.dispose()),w.material=H,s.delete(b)}}),a.clear()},A=b=>{let w=b;if(!(w.material instanceof h.Material))return!1;s.set(b,w.material);let H=w.material.clone();return b instanceof h.Mesh&&"emissive"in H?H.emissive=E.clone():"color"in H&&(H.color=E.clone()),w.material=H,!0},O=()=>{let b=new h.Box3;r.traverse(H=>{let L=H;H.visible&&!ye(H)&&L.geometry&&b.expandByObject(H)});let w=b.isEmpty()?1:b.getSize(new h.Vector3).length();l.params.Points.threshold=w*.01},y=b=>{d.set(b.clientX,b.clientY)},g=b=>{let w=new h.Vector2(b.clientX,b.clientY);if(d.distanceTo(w)>5)return;let H=e.getBoundingClientRect();c.x=(b.clientX-H.left)/H.width*2-1,c.y=-((b.clientY-H.top)/H.height)*2+1,O(),l.setFromCamera(c,t());let L=l.intersectObjects(r.children,!0).filter(f=>u(f.object));if(L.length>0){let f=L[0].object;a.has(f)||(p(),a.add(f),A(f),o.events?.onObjectSelected?.(f),f instanceof h.Mesh&&Object.keys(f.userData).length>0&&o.events?.onMeshMetadataClicked?.(f.userData))}else p(),o.events?.onBackgroundClicked?.({x:c.x,y:c.y})},R=b=>{let w=e.getBoundingClientRect();c.x=(b.clientX-w.left)/w.width*2-1,c.y=-((b.clientY-w.top)/w.height)*2+1,O(),l.setFromCamera(c,t());let H=l.intersectObjects(r.children,!0).filter($=>u($.object));if(H.length===0)return;let L=H[0].object;if(o.events?.onMeshDoubleClicked?.(L),!o.events?.enableDoubleClickZoom)return;let f=new h.Box3().setFromObject(L);if(f.isEmpty())return;let T=f.getCenter(new h.Vector3),P=f.getSize(new h.Vector3),V=Math.max(P.x,P.y,P.z),G=n.fov*(Math.PI/180),X=V/(2*Math.tan(G/2))*1.5,C=n.position.clone().sub(i.target).normalize(),_=T.clone().add(C.multiplyScalar(X));mt(n,i,_,T)},M=b=>{if(o.events?.enableKeyboardControls)switch(b.key.toLowerCase()){case"f":b.preventDefault(),m();break;case"escape":b.preventDefault(),p();break;case" ":b.preventDefault(),m();break}};return o.events?.enableClickToFocus&&(e.addEventListener("mousedown",y),e.addEventListener("click",g),e.addEventListener("dblclick",R)),o.events?.enableKeyboardControls&&(e.setAttribute("tabindex","0"),e.addEventListener("keydown",M)),{dispose:()=>{e.removeEventListener("mousedown",y),e.removeEventListener("click",g),e.removeEventListener("dblclick",R),e.removeEventListener("keydown",M),p()},fitToView:m,clearSelection:p}}function Rt(e,r,t){let n=new it(e,r),i=t.camera.target;return i&&n.target.set(i.x,i.y,i.z),n.enableDamping=t.controls.enableDamping||!1,n.dampingFactor=t.controls.dampingFactor||.05,n.autoRotate=t.controls.autoRotate||!1,n.autoRotateSpeed=t.controls.autoRotateSpeed||.5,n.enableZoom=t.controls.enableZoom??!0,n.enablePan=t.controls.enablePan??!0,n.minDistance=t.controls.minDistance||.001,n.maxDistance=t.controls.maxDistance||1/0,n.screenSpacePanning=!1,n.maxPolarAngle=Math.PI,n.update(),n}var St={};Se(St,{CONCRETE_MATERIAL:()=>Ht,EMISSIVE_MATERIAL:()=>Tt,GLASS_MATERIAL:()=>Mt,METAL_MATERIAL:()=>wt,PLASTIC_MATERIAL:()=>vt,RUBBER_MATERIAL:()=>Ct,WOOD_MATERIAL:()=>xt});import*as x from"three";var Tt=new x.MeshPhysicalMaterial({color:0,emissive:new x.Color(16777215),emissiveIntensity:5,metalness:0,roughness:.2,clearcoat:.3,clearcoatRoughness:.2,depthWrite:!0,depthTest:!0,transparent:!1,alphaTest:0,polygonOffset:!0,side:x.FrontSide,dithering:!0}),wt=new x.MeshPhysicalMaterial({color:new x.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,side:x.FrontSide,dithering:!0}),Ht=new x.MeshPhysicalMaterial({color:new x.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:.5,depthTest:!0,polygonOffset:!0,side:x.FrontSide,dithering:!0}),vt=new x.MeshPhysicalMaterial({color:new x.Color(16777215),metalness:0,roughness:.3,envMapIntensity:.5,clearcoat:.5,clearcoatRoughness:.1,reflectivity:.5,ior:1.4,transmission:0,transparent:!1,depthWrite:!0,side:x.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Mt=new x.MeshPhysicalMaterial({color:new x.Color(16777215),metalness:0,roughness:0,transmission:.95,transparent:!0,opacity:.3,envMapIntensity:1,clearcoat:1,clearcoatRoughness:0,ior:1.52,reflectivity:.9,thickness:1,side:x.DoubleSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Ct=new x.MeshPhysicalMaterial({color:new x.Color(1710618),metalness:0,roughness:.9,envMapIntensity:.2,clearcoat:.1,clearcoatRoughness:.8,reflectivity:.2,ior:1.3,transmission:0,depthWrite:!0,side:x.FrontSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),xt=new x.MeshPhysicalMaterial({color:new x.Color(8934707),metalness:0,roughness:.7,envMapIntensity:.3,clearcoat:.3,clearcoatRoughness:.4,reflectivity:.3,ior:1.3,transmission:0,depthWrite:!0,side:x.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});import*as j from"three";import{Line2 as At}from"three/addons/lines/Line2.js";import{LineGeometry as Dt}from"three/addons/lines/LineGeometry.js";import{LineMaterial as Lt}from"three/addons/lines/LineMaterial.js";function K(e,r,t,n=!0){return{x:e,y:r,z:t}}var Pt="#ffffff",ne=12,Ot=4e-4,It=12,Vt=.05;function Re(e,r={}){if(!e||e.length===0)return[];let{rhino:t,applyTransforms:n=!0}=r,i=[];for(let o of e)switch(o.kind){case"curve":{let a=zt(o,t,n);a&&i.push(a);break}case"point":{i.push(Ft(o,n));break}default:{let a=o;v().warn(`Skipping unknown display item kind: ${String(a.kind)}`);break}}return i}var Bt=2;function zt(e,r,t){if(!r)return v().warn("No rhino3dm instance provided; skipping curve display item."),null;let n=kt(e.json,r);if(!n)return null;let i=jt(n,t);if(i.length<2)return null;let o=[];for(let u of i)o.push(u.x,u.y,u.z);let a=new Dt;a.setPositions(o);let s=Te(e.color,e.opacity),l=new Lt({color:s.color}),c=l;c.linewidth=e.width??Bt,c.transparent=s.transparent,c.opacity=s.opacity;let d=new At(a,l);return d.computeLineDistances(),d.name=e.name,d.userData={id:e.id,layer:e.layer,kind:"curve",metadata:e.metadata},d}function Ft(e,r){let{x:t,y:n,z:i}=K(e.position.X,e.position.Y,e.position.Z,r),o=new j.BufferGeometry;o.setAttribute("position",new j.Float32BufferAttribute([t,n,i],3));let a=new j.PointsMaterial({...Te(e.color,e.opacity),size:6,sizeAttenuation:!1}),s=new j.Points(o,a);return s.name=e.name,s.userData={id:e.id,layer:e.layer,kind:"point",metadata:e.metadata},s}function kt(e,r){try{let t=JSON.parse(e),n=r.CommonObject.decode(t);return n&&typeof n.pointAt=="function"?n:(v().warn("Decoded display-item JSON is not a curve; skipping."),null)}catch(t){return v().warn("Failed to decode curve display item JSON:",t),null}}function jt(e,r){let t=_t(e,r);return t||Gt(e,r)}function _t(e,r){if(!e.isPolyline())return null;let t=e.tryGetPolyline(),n=Array.isArray(t)?t[1]:t;if(!n||typeof n.count!="number"||n.count<2)return null;let i=[];for(let o=0;o<n.count;o++){let a=n.get(o),{x:s,y:l,z:c}=K(a[0],a[1],a[2],r);i.push(new j.Vector3(s,l,c))}return i}function Gt(e,r){let t=e.domain,n=t[0],o=t[1]-n,a=c=>{let d=e.pointAt(c),{x:u,y:m,z:E}=K(d[0],d[1],d[2],r);return new j.Vector3(u,m,E)},s=Nt(e),l=[a(n)];for(let c=0;c<ne;c++){let d=n+o*c/ne,u=n+o*(c+1)/ne;re(d,a(d),u,a(u),a,s,It,l),l.push(a(u))}return l}function re(e,r,t,n,i,o,a,s){if(a<=0)return;let l=(e+t)/2,c=i(l),d=Wt(c,r,n),u=Ut(r,c,n);d<=o&&u<=Vt||(re(e,r,l,c,i,o,a-1,s),s.push(c),re(l,c,t,n,i,o,a-1,s))}function Nt(e){let r=e.getBoundingBox(),t=r.min,n=r.max,i=Math.hypot(n[0]-t[0],n[1]-t[1],n[2]-t[2]);return Math.max(i*Ot,1e-6)}function Ut(e,r,t){let n=r.clone().sub(e),i=t.clone().sub(r),o=n.length(),a=i.length();if(o===0||a===0)return 0;let s=Math.max(-1,Math.min(1,n.dot(i)/(o*a)));return Math.acos(s)}function Wt(e,r,t){let n=t.clone().sub(r),i=n.lengthSq();if(i===0)return e.distanceTo(r);let o=Math.max(0,Math.min(1,e.clone().sub(r).dot(n)/i)),a=r.clone().addScaledVector(n,o);return e.distanceTo(a)}function Te(e,r){let t=r??1;return{color:new j.Color(e??Pt),transparent:t<1,opacity:t}}var we=1096174675,He=1,oe=1,ve=12,Me=56;function ae(e){let r=$t(e),t=new DataView(r.buffer,r.byteOffset,r.byteLength);if(r.byteLength<ve)throw U("Blob too small to contain SLVA header.",{expectedBytes:ve,availableBytes:r.byteLength});let n=0,i=t.getUint32(n,!0);if(n+=4,i!==we)throw U(`Invalid SLVA magic: 0x${i.toString(16)}`,{expectedMagic:`0x${we.toString(16)}`,actualMagic:`0x${i.toString(16)}`});let o=t.getUint32(n,!0);if(n+=4,o!==He)throw U(`Unsupported SLVA version: ${o}`,{expectedVersion:He,actualVersion:o});let a=t.getUint32(n,!0);if(n+=4,n+a>r.byteLength)throw U("Insufficient data to read metadata JSON.",{expectedBytes:a,availableBytes:r.byteLength-n,offset:n});let s=r.subarray(n,n+a);n+=a;let l;try{l=JSON.parse(Yt(s))}catch(f){throw U(`Failed to parse metadata JSON: ${f instanceof Error?f.message:String(f)}`,{metadataLen:a})}if(n+Me>r.byteLength)throw U("Insufficient data to read geometry header.",{expectedBytes:Me,availableBytes:r.byteLength-n,offset:n});let c=t.getUint32(n,!0);n+=4;let d=t.getFloat64(n,!0);n+=8;let u=t.getFloat64(n,!0);n+=8;let m=t.getFloat64(n,!0);n+=8;let E=t.getFloat64(n,!0);n+=8;let p=t.getFloat64(n,!0);n+=8;let A=t.getFloat64(n,!0);n+=8;let O=t.getUint32(n,!0);n+=4;let y=(c&oe)!==0,g=O*3,M=g*(y?4:2);if(n+M>r.byteLength)throw U("Insufficient data to read vertices.",{expectedBytes:M,availableBytes:r.byteLength-n,offset:n,useFloat32:y,vertexCount:O});let D=r.byteOffset+n,b=y?qt(r.buffer,D,g):Xt(r.buffer,D,g);if(n+=M,n+4>r.byteLength)throw U("Insufficient data to read index count.",{expectedBytes:4,availableBytes:r.byteLength-n,offset:n});let w=t.getUint32(n,!0);n+=4;let H=w*4;if(n+H>r.byteLength)throw U("Insufficient data to read indices.",{expectedBytes:H,availableBytes:r.byteLength-n,offset:n,indexCount:w});let L=Zt(r.buffer,r.byteOffset+n,w);return{metadata:l,flags:c,vertices:b,indices:L,origin:[d,u,m],scale:[E,p,A]}}function $t(e){return typeof e=="string"?se(e):e instanceof Uint8Array?e:new Uint8Array(e)}function Yt(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 ee("No UTF-8 decoder available in this environment.",Q.INVALID_STATE)}function Xt(e,r,t){if(t===0)return new Int16Array(0);if(r%2===0)return new Int16Array(e,r,t);let n=new Uint8Array(t*2);return n.set(new Uint8Array(e,r,t*2)),new Int16Array(n.buffer)}function qt(e,r,t){if(t===0)return new Float32Array(0);if(r%4===0)return new Float32Array(e,r,t);let n=new Uint8Array(t*4);return n.set(new Uint8Array(e,r,t*4)),new Float32Array(n.buffer)}function Zt(e,r,t){if(t===0)return new Uint32Array(0);if(r%4===0)return new Uint32Array(e,r,t);let n=new Uint8Array(t*4);return n.set(new Uint8Array(e,r,t*4)),new Uint32Array(n.buffer)}function U(e,r){return new ee(e,Q.VALIDATION_ERROR,{context:r})}import*as z from"three";async function Ce(e,r){let{debug:t=!1}=r??{},n=t?performance.now():0;try{let i=performance.now(),o=JSON.parse(e),a=performance.now()-i;return await Jt(o,r,{parseTime:a,perfStart:n})}catch(i){return v().error("Error parsing mesh batch:",i),[]}}async function Jt(e,r,t){let{mergeByMaterial:n=!0,applyTransforms:i=!0,scaleFactor:o=1,debug:a=!1}=r??{},{parseTime:s=0,perfStart:l=a?performance.now():0}=t??{};try{let c=performance.now(),d=ae(e.compressedData),u=performance.now()-c,m=a?rn(e.compressedData):0;return xe(d,{mergeByMaterial:n,applyTransforms:i,scaleFactor:o,debug:a,parseTime:s,decodeTime:u,perfStart:l,blobBytes:m,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}})}catch(c){return v().error("Error parsing mesh batch object:",c),[]}}async function ur(e,r){let{mergeByMaterial:t=!0,applyTransforms:n=!0,scaleFactor:i=1,debug:o=!1}=r??{},a=o?performance.now():0;try{let s=performance.now(),l=ae(e),c=performance.now()-s,d=e.byteLength;return xe(l,{mergeByMaterial:t,applyTransforms:n,scaleFactor:i,debug:o,parseTime:0,decodeTime:c,perfStart:a,blobBytes:d})}catch(s){return v().error("Error parsing mesh batch blob:",s),[]}}function xe(e,r){let{mergeByMaterial:t,applyTransforms:n,scaleFactor:i,debug:o,parseTime:a,decodeTime:s,perfStart:l,blobBytes:c,fallback:d}=r,u=e.metadata.materials??d?.materials??[],m=e.metadata.groups??d?.groups??[],E=e.metadata.sourceComponentId??d?.sourceComponentId,p=(e.flags&oe)!==0,A=p?Qt(e.vertices,n):Kt(e.vertices,e.origin,e.scale,n);if(o){let M=e.vertices.byteLength+e.indices.byteLength;v().debug("Mesh Batch Stats:"),v().debug(` Materials: ${u.length} | Groups: ${m.length}`),v().debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),v().debug(` Format: ${p?"float32":"int16 quantized"}`),v().debug(` Blob: ${(c/1024/1024).toFixed(2)} MB | Geometry on wire: ${(M/1024/1024).toFixed(2)} MB`)}let O=performance.now(),y=u.map(en),g=[];for(let M of m)if(t&&M.meshes.length>1){let D=tn(M,A,e.indices,y);D.userData.sourceComponentId=E??null,g.push(D)}else{let D=nn(M,A,e.indices,y);for(let b of D)b.userData.sourceComponentId=E??null;g.push(...D)}if(i!==1)for(let M of g)M.scale.set(i,i,i);let R=performance.now()-O;if(o){let M=performance.now()-l;v().debug("Performance:"),a>0&&v().debug(` Parse JSON: ${a.toFixed(2)}ms`),v().debug(` Decode binary: ${s.toFixed(2)}ms`),v().debug(` Create Meshes: ${R.toFixed(2)}ms`),v().debug(` Total: ${M.toFixed(2)}ms`)}return Promise.resolve(g)}function Kt(e,r,t,n){let i=new Float32Array(e.length),o=r[0],a=r[1],s=r[2],l=t[0],c=t[1],d=t[2];for(let u=0;u<e.length;u+=3)i[u]=o+(e[u]+32767)*l,i[u+1]=a+(e[u+1]+32767)*c,i[u+2]=s+(e[u+2]+32767)*d;return i}function Qt(e,r){return e}function en(e){let r=le(e.color);return new z.MeshPhysicalMaterial({color:r,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,side:z.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.5,polygonOffsetUnits:.5,depthWrite:!0,depthTest:!0})}function tn(e,r,t,n){let i=0,o=0;for(let p of e.meshes)i+=p.vertexCount,o+=p.indexCount;let a=new Float32Array(i*3),s=new Uint32Array(o),l=0,c=0;for(let p of e.meshes){let A=p.vertexStart*3,O=p.vertexCount*3;a.set(r.subarray(A,A+O),l*3);let y=t.subarray(p.indexStart,p.indexStart+p.indexCount),g=l-p.vertexStart;if(g===0)s.set(y,c);else for(let R=0;R<y.length;R++)s[c+R]=y[R]+g;l+=p.vertexCount,c+=p.indexCount}let d=new z.BufferGeometry;d.setAttribute("position",new z.BufferAttribute(a,3)),d.setIndex(new z.BufferAttribute(s,1)),d.computeVertexNormals();let u=new z.Mesh(d,n[e.materialId]),m=e.meshes[0],E=e.meshes.map(p=>p.name).filter(p=>p&&p.length>0);return u.name=E.length>0?E[0]:`merged_material_${e.materialId}`,u.castShadow=!0,u.receiveShadow=!0,u.userData={name:u.name,layer:m?.layer??"",originalIndex:m?.originalIndex??0,metadata:m?.metadata??{},mergedFrom:e.meshes.slice(1).map(p=>({name:p.name,layer:p.layer,originalIndex:p.originalIndex}))},u}function nn(e,r,t,n){let i=[];for(let o of e.meshes){let a=o.vertexStart*3,s=o.vertexCount*3,l=r.slice(a,a+s),c=t.subarray(o.indexStart,o.indexStart+o.indexCount),d=new Uint32Array(c.length),u=o.vertexStart;for(let p=0;p<c.length;p++)d[p]=c[p]-u;let m=new z.BufferGeometry;m.setAttribute("position",new z.BufferAttribute(l,3)),m.setIndex(new z.BufferAttribute(d,1)),m.computeVertexNormals();let E=new z.Mesh(m,n[e.materialId]);E.name=o.name,E.userData={name:o.name,layer:o.layer??"",originalIndex:o.originalIndex,metadata:o.metadata??{}},E.castShadow=!0,E.receiveShadow=!0,i.push(E)}return i}function rn(e){return Math.floor(e.length*3/4)}var on={Millimeters:1/1e3,Centimeters:1/100,Meters:1,Inches:1/39.37,Feet:1/3.28084},an="Display";async function gr(e,r){let t=performance.now(),n=[],{allowScaling:i=!0,allowAutoPosition:o=!0,rhino:a,debug:s=!1,parsing:l={}}=r??{};try{let c=i?sn(e.modelunits):1;return await ln(e,n,c,l,a,s),o&&mn(n),n}catch(c){throw pn(c,n),c}finally{s&&fn(t)}}function sn(e){return on[e]??1}async function ln(e,r,t,n,i,o){for(let a of e.values){let s=a.InnerTree;for(let l in s){let c=s[l];c&&await cn(c,r,t,n,i,o)}}}async function cn(e,r,t,n,i,o){for(let a of e){if(!a.type.includes(an))continue;let s={mergeByMaterial:!0,applyTransforms:!0,debug:!1,...n},l=await Ce(a.data,s),c=Re(dn(a.data),{rhino:i,applyTransforms:s.applyTransforms}),d=[...l,...c];if(t!==1)for(let u of d)u.scale.set(t,t,t);r.push(...d),o&&v().debug(`Extracted ${l.length} meshes and ${c.length} items from batch`)}}function dn(e){return(typeof e=="string"?un(e):e)?.items}function un(e){try{return JSON.parse(e)}catch{return}}function mn(e){if(e.length===0)return;let t=Y(e).min.y;ce(e,t)}function pn(e,r){v().error("An unexpected error occurred:",e),En(r)}function En(e){for(let r of e){let t=r;t.geometry&&t.geometry.dispose(),t.material&&(Array.isArray(t.material)?t.material.forEach(n=>n.dispose()):t.material.dispose())}}function fn(e){let r=performance.now()-e;v().info("Time to process meshes:",`${r.toFixed(2)}ms`)}export{gn as a,le as b,ce as c,Y as d,de as e,ue as f,me as g,q as h,Ee as i,$e as j,xn as k,fe as l,ge as m,at as n,be as o,Zn as p,St as q,Re as r,we as s,He as t,oe as u,ae as v,Ce as w,Jt as x,ur as y,on as z,gr as A};
55
+ //# sourceMappingURL=chunk-45AYUHMT.js.map