@selvajs/compute 2.1.0-beta.2 → 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.
- package/dist/chunk-45AYUHMT.js +55 -0
- package/dist/chunk-45AYUHMT.js.map +1 -0
- package/dist/chunk-6YCTAJ6N.cjs +55 -0
- package/dist/chunk-6YCTAJ6N.cjs.map +1 -0
- package/dist/{chunk-ZLBFTV7M.cjs → chunk-KU7ND4EV.cjs} +2 -2
- package/dist/{chunk-ZLBFTV7M.cjs.map → chunk-KU7ND4EV.cjs.map} +1 -1
- package/dist/{chunk-QAS2VM6Q.js → chunk-YUMCH6ZU.js} +2 -2
- package/dist/grasshopper.cjs +1 -1
- package/dist/grasshopper.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{visualization-QMK4VTCF.js → visualization-JZLL7SOB.js} +2 -2
- package/dist/visualization-U76H2KBD.cjs +2 -0
- package/dist/{visualization-YWPVPKCI.cjs.map → visualization-U76H2KBD.cjs.map} +1 -1
- package/dist/visualization.cjs +1 -1
- package/dist/visualization.cjs.map +1 -1
- package/dist/visualization.d.cts +232 -14
- package/dist/visualization.d.ts +232 -14
- package/dist/visualization.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-7RLHTZZQ.cjs +0 -54
- package/dist/chunk-7RLHTZZQ.cjs.map +0 -1
- package/dist/chunk-PGOKADJC.js +0 -54
- package/dist/chunk-PGOKADJC.js.map +0 -1
- package/dist/visualization-YWPVPKCI.cjs +0 -2
- /package/dist/{chunk-QAS2VM6Q.js.map → chunk-YUMCH6ZU.js.map} +0 -0
- /package/dist/{visualization-QMK4VTCF.js.map → visualization-JZLL7SOB.js.map} +0 -0
package/dist/chunk-PGOKADJC.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import{a as we,c as W,d as $,e as w,o as K}from"./chunk-XFYFC2DH.js";import*as P from"three";var F={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 dn(e,r,t,n,i){if(He(e),r.length===0)return;r.forEach(d=>{e.add(d)});let o=_(r),a=o.getCenter(new P.Vector3),c=o.getSize(new P.Vector3),s=Math.max(c.x,c.y,c.z);if(s/Math.min(c.x||1,c.y||1,c.z||1)>F.SCALE_RATIO_THRESHOLD||s>F.HUGE_THRESHOLD?(t.near=s*F.NEAR_PLANE_FACTOR.TINY,t.far=s*F.FAR_PLANE_FACTOR.HUGE):s>F.LARGE_THRESHOLD?(t.near=s*F.NEAR_PLANE_FACTOR.SMALL,t.far=s*F.FAR_PLANE_FACTOR.LARGE):(t.near=Math.max(.01,s*F.NEAR_PLANE_FACTOR.NORMAL),t.far=Math.max(2e3,s*F.FAR_PLANE_FACTOR.NORMAL)),t.updateProjectionMatrix(),i)n.minDistance=t.near*2,n.maxDistance=t.far*.9;else{let d=s*F.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 Q(e){if(!e||typeof e!="string")return w().warn(`Invalid color input: ${e}, using white`),new P.Color(16777215);let r=e.trim();if(/^#?[0-9A-Fa-f]{6}$/.test(r))try{let t=r.startsWith("#")?r:`#${r}`;return new P.Color(t)}catch{return w().warn(`Invalid hex color: ${e}, using white`),new P.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 P.Color(t[0]/255,t[1]/255,t[2]/255)}try{return new P.Color(r.toLowerCase())}catch{return w().warn(`Invalid color string: ${e}, using white`),new P.Color(16777215)}}function ee(e,r){e.forEach(t=>{t.position.y-=r})}function _(e){let r=new P.Box3;return e.length===0||e.forEach(t=>{t.updateMatrixWorld(!0);let n=new P.Box3().setFromObject(t);r.union(n)}),r}function He(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(c=>{for(let s of Object.values(c))s instanceof P.Texture&&s.dispose();c.dispose()})}),t.removeFromParent())})}import*as B from"three";var Ce={top:new B.Vector3(0,1,0),bottom:new B.Vector3(0,-1,0),front:new B.Vector3(0,0,1),back:new B.Vector3(0,0,-1),right:new B.Vector3(1,0,0),left:new B.Vector3(-1,0,0),iso:new B.Vector3(.8,1,1.2).normalize()};function te(e){let{scene:r,perspective:t,controls:n,onActiveCameraChange:i}=e,o=new B.OrthographicCamera(-1,1,1,-1,t.near,t.far);o.up.copy(t.up);let a="perspective",c=t.aspect,s=()=>a==="perspective"?t:o,l=()=>{let v=t.position.distanceTo(n.target)*Math.tan(t.fov*Math.PI/360),S=v*c;o.left=-S,o.right=S,o.top=v,o.bottom=-v,o.near=t.near,o.far=t.far,o.updateProjectionMatrix()},d=m=>{m!==a&&(m==="orthographic"?(o.position.copy(t.position),o.up.copy(t.up),o.lookAt(n.target),l()):t.position.copy(o.position),a=m,n.object=s(),n.update(),i(s()))};return{getActiveCamera:s,getProjection:()=>a,setProjection:d,toggleProjection:()=>(d(a==="perspective"?"orthographic":"perspective"),a),setView:(m,v=!0)=>{let S=xe(r),T=S.isEmpty()?n.target.clone():S.getCenter(new B.Vector3),b=S.isEmpty()?new B.Vector3(1,1,1):S.getSize(new B.Vector3),H=Math.max(b.x,b.y,b.z)||1,h=t.fov*(Math.PI/180),g=H/(2*Math.tan(h/2))*1.5,R=Ce[m],M=T.clone().add(R.clone().multiplyScalar(g)),y=s();v?Ae(y,n,M,T,()=>{a==="orthographic"&&l()}):(y.position.copy(M),n.target.copy(T),a==="orthographic"&&l(),n.update())},setRotateEnabled:m=>{n.enableRotate=m},isRotateEnabled:()=>n.enableRotate,updateAspect:(m,v)=>{c=v===0?c:m/v,a==="orthographic"&&l()}}}var ve=new Set(["grid","floor","label-layer","measure"]);function Me(e){let r=e;for(;r;){if(typeof r.userData.id=="string"&&ve.has(r.userData.id))return!0;r=r.parent}return!1}function xe(e){let r=[];return e.traverse(t=>{let n=t;t.visible&&!Me(t)&&n.geometry&&r.push(t)}),_(r)}var Se=e=>1-Math.pow(1-e,3);function Ae(e,r,t,n,i,o=250){let a=e.position.clone(),c=r.target.clone(),s=performance.now(),l=()=>{let d=Se(Math.min((performance.now()-s)/o,1));e.position.lerpVectors(a,t,d),r.target.lerpVectors(c,n,d),i(),r.update(),d<1&&requestAnimationFrame(l)};requestAnimationFrame(l)}import*as D from"three";var De=`
|
|
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
|
-
`,Le=`
|
|
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 ne(e={}){let{cellSize:r=1,majorEvery:t=10,cellColor:n=8947848,majorColor:i=4473924,fadeDistance:o=100,plane:a="y"}=e,c=a==="y"?new D.Vector2(0,2):a==="z"?new D.Vector2(0,1):new D.Vector2(1,2),s=o*2.5,l=new D.PlaneGeometry(s,s);a==="y"?l.rotateX(-Math.PI/2):a==="x"&&l.rotateY(Math.PI/2);let d=new D.ShaderMaterial({vertexShader:De,fragmentShader:Le,transparent:!0,depthWrite:!1,side:D.DoubleSide,uniforms:{uAxes:{value:c},uCell:{value:r},uMajor:{value:t},uCellColor:{value:new D.Color(n)},uMajorColor:{value:new D.Color(i)},uCenter:{value:new D.Vector3},uFade:{value:o}}}),u=new D.Mesh(l,d);u.name="grid",u.userData.id="grid",u.renderOrder=-1;let p=new D.Vector3;return{object:u,update:E=>{a==="y"?(u.position.set(E.x,0,E.z),p.set(E.x,0,E.z)):a==="z"?(u.position.set(E.x,E.y,0),p.set(E.x,E.y,0)):(u.position.set(0,E.y,E.z),p.set(0,E.y,E.z)),d.uniforms.uCenter.value.copy(p)},setVisible:E=>{u.visible=E},dispose:()=>{l.dispose(),d.dispose()}}}import{ViewHelper as Oe}from"three/addons/helpers/ViewHelper.js";function re(e){let{camera:r,domElement:t,controls:n,controller:i}=e,o=new Oe(r,t);o.setLabels("X","Y","Z");let a=!0;return{render:s=>{if(!a)return;let l=s.autoClear;s.autoClear=!1,o.render(s),s.autoClear=l},update:s=>{o.animating&&o.update(s)},handleClick:s=>!a||(o.center.copy(n.target),!o.handleClick(s))?!1:(i.getProjection()==="orthographic"&&i.setProjection("perspective"),!0),get isAnimating(){return o.animating},setVisible:s=>{a=s},isVisible:()=>a,dispose:()=>o.dispose()}}import*as j from"three";import{LineSegmentsGeometry as Pe}from"three/addons/lines/LineSegmentsGeometry.js";import{LineSegments2 as oe}from"three/addons/lines/LineSegments2.js";import{LineMaterial as Ie}from"three/addons/lines/LineMaterial.js";var N="edge-overlay",Be=2236962,Ve=1.5,Fe=30;function ae(e,r={}){let t=new j.Color(r.color??Be),n=r.width??Ve,i=r.thresholdAngle??Fe,o=[];return e.traverse(a=>{if(!(a instanceof j.Mesh)||a.userData.id==="floor"||a.userData.id==="grid"||a.userData.kind===N||a.children.some(s=>s.userData?.kind===N)||!a.geometry)return;let c=ze(a.geometry,t,n,i);a.add(c),o.push(c)}),o}function ze(e,r,t,n){let i=new j.EdgesGeometry(e,n),o=new Pe;o.setPositions(Array.from(i.attributes.position.array)),i.dispose();let a=new Ie({color:r});a.linewidth=t,a.polygonOffset=!0,a.polygonOffsetFactor=-1,a.polygonOffsetUnits=-1;let c=new oe(o,a);return c.userData.kind=N,c.raycast=()=>{},c}function ke(e){return e.userData?.kind===N}function Rn(e){let r=[];e.traverse(t=>{t instanceof oe&&ke(t)&&r.push(t)});for(let t of r)t.geometry.dispose(),t.material.dispose(),t.removeFromParent();return r.length}import{EffectComposer as je}from"three/addons/postprocessing/EffectComposer.js";import{RenderPass as _e}from"three/addons/postprocessing/RenderPass.js";import{GTAOPass as Ge}from"three/addons/postprocessing/GTAOPass.js";import{OutputPass as Ne}from"three/addons/postprocessing/OutputPass.js";function ie(e,r,t,n,i,o){let a=new je(e),c=new _e(r,t);a.addPass(c);let s=new Ge(r,t,n,i);s.blendIntensity=o.aoIntensity??1,s.updateGtaoMaterial({screenSpaceRadius:!0}),a.addPass(s);let l=new Ne;return a.addPass(l),e.toneMapping=o.toneMapping,e.toneMappingExposure=o.toneMappingExposure,a.setSize(n,i),{render:d=>a.render(d),setSize:(d,u,p)=>{a.setPixelRatio(p),a.setSize(d,u),s.setSize(d,u)},setCamera:d=>{c.camera=d,s.camera=d},dispose:()=>a.dispose()}}import*as se from"three";import{CSS2DRenderer as Ue,CSS2DObject as We}from"three/addons/renderers/CSS2DRenderer.js";function le(e,r){let t=new Ue,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 se.Group;o.name="label-layer",o.userData.id="label-layer",r.add(o);let a=new Set;return{addLabel:(s,l,d)=>{let u=document.createElement("div");u.textContent=s,d&&(u.className=d),u.style.pointerEvents="none";let p=new We(u);return p.position.copy(l),o.add(p),a.add(p),{object:p,setPosition:E=>p.position.copy(E),setText:E=>{u.textContent=E},remove:()=>{p.removeFromParent(),u.remove(),a.delete(p)}}},render:(s,l)=>t.render(s,l),setSize:(s,l)=>t.setSize(s,l),dispose:()=>{a.forEach(s=>{s.removeFromParent(),s.element.remove()}),a.clear(),o.removeFromParent(),n.remove()}}}import*as A from"three";import{Line2 as $e}from"three/addons/lines/Line2.js";import{LineGeometry as Ye}from"three/addons/lines/LineGeometry.js";import{LineMaterial as Xe}from"three/addons/lines/LineMaterial.js";var qe=12,Ze=16763904,Je=e=>`${e.toPrecision(3)} m`;function Ke(e,r,t,n){let i=e.point.clone(),o=e.object;if(!(o instanceof A.Mesh)||e.face==null||!o.geometry)return i;let a=o.geometry.attributes.position;if(!a)return i;let c=u=>{let p=u.clone().project(r);return new A.Vector2((p.x+1)/2*t.width,(1-p.y)/2*t.height)},s=c(i),l=i,d=n;for(let u of[e.face.a,e.face.b,e.face.c]){let E=new A.Vector3().fromBufferAttribute(a,u).applyMatrix4(o.matrixWorld),m=c(E).distanceTo(s);m<d&&(d=m,l=E)}return l}function ce(e){let{canvas:r,scene:t,getActiveCamera:n,labelLayer:i,options:o={}}=e,a=o.snapPixels??qe,c=new A.Color(o.color??Ze),s=o.format??Je,l=new A.Raycaster,d=new A.Vector2,u=!1,p=[],E=[],m=null,v=null,S=new A.PointsMaterial({color:c,size:8,sizeAttenuation:!1,depthTest:!1}),T=g=>{let R=new A.BufferGeometry;R.setAttribute("position",new A.Float32BufferAttribute([g.x,g.y,g.z],3));let M=new A.Points(R,S);return M.renderOrder=999,M.userData.id="measure",M.raycast=()=>{},t.add(M),M},b=()=>{p.length=0,E.forEach(g=>{g.geometry.dispose(),g.removeFromParent()}),E.length=0,m&&(m.geometry.dispose(),m.material.dispose(),m.removeFromParent(),m=null),v?.remove(),v=null},H=()=>{if(p.length!==2)return;let[g,R]=p,M=new Ye;M.setPositions([g.x,g.y,g.z,R.x,R.y,R.z]);let y=new Xe({color:c});y.linewidth=2,y.depthTest=!1,m=new $e(M,y),m.renderOrder=998,m.userData.id="measure",m.raycast=()=>{},t.add(m);let L=g.clone().add(R).multiplyScalar(.5);v=i.addLabel(s(g.distanceTo(R)),L,o.labelClassName)};return{setEnabled:g=>{u=g,g||b()},isEnabled:()=>u,handleClick:g=>{if(!u)return!1;p.length===2&&b();let R=r.getBoundingClientRect();d.x=(g.clientX-R.left)/R.width*2-1,d.y=-((g.clientY-R.top)/R.height)*2+1;let M=n();l.setFromCamera(d,M);let y=l.intersectObjects(t.children,!0).filter(C=>C.object.userData.id!=="measure"&&C.object.userData.id!=="grid");if(y.length===0)return!0;let L=Ke(y[0],M,{width:R.width,height:R.height},a);return p.push(L),E.push(T(L)),p.length===2&&H(),!0},clear:b,dispose:()=>{b(),S.dispose()}}}import*as f from"three";import{OrbitControls as Qe}from"three/addons/controls/OrbitControls.js";import{HDRLoader as et}from"three/addons/loaders/HDRLoader.js";var de=new f.Vector3(0,0,1),Y=(e,r,t,n)=>{switch(e){case"mm":return r;case"cm":return t;default:return n}},Nn=function(e,r){let t=tt(r||{}),n=ot(t),i=dt(t,e),o=ut(e,t),a=pt(i,e,t),c=te({scene:n,perspective:i,controls:a,onActiveCameraChange:()=>{}}),s=()=>c.getActiveCamera();st(n,t),lt(n,t),t.floor?.enabled&&ct(n,t);let l=t.grid.enabled?ne({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;l&&n.add(l.object);let d=t.gizmo.enabled?re({camera:i,domElement:e,controls:a,controller:c}):null,u=e.parentElement??e,p=t.measure.enabled?le(u,n):null,E=t.measure.enabled&&p?ce({canvas:e,scene:n,getActiveCamera:s,labelLayer:p,options:{snapPixels:t.measure.snapPixels,color:t.measure.color,labelClassName:t.measure.labelClassName,format:t.measure.format}}):null,m=t.events.enableEventHandlers!==!1?mt(e,n,s,i,a,t):{dispose:()=>{},fitToView:()=>{},clearSelection:()=>{}},v=C=>{if(E?.handleClick(C)){C.stopImmediatePropagation();return}d?.handleClick(C)&&C.stopImmediatePropagation()};(d||E)&&e.addEventListener("click",v,{capture:!0});let S=C=>{ae(C,{color:t.edges.color,width:t.edges.width,thresholdAngle:t.edges.thresholdAngle})},T=e.parentElement,b=()=>T?{width:T.clientWidth,height:T.clientHeight}:{width:window.innerWidth,height:window.innerHeight},H=null,h=()=>{let{width:C,height:O}=b(),k=Math.min(window.devicePixelRatio,2),G=ie(o,n,s(),Math.max(1,C),Math.max(1,O),{toneMapping:t.render.toneMapping??f.NeutralToneMapping,toneMappingExposure:t.render.toneMappingExposure??1,aoIntensity:t.render.aoIntensity});return G.setSize(Math.max(1,C),Math.max(1,O),k),G},g=C=>{C&&!H?H=h():!C&&H&&(H.dispose(),H=null)};t.render.ambientOcclusion&&(H=h());let{animate:R,dispose:M}=it(o,n,i,s,c,a,b,t.events.onFrame,l,d,()=>H,p);R();let y=t.environment?.sceneUp||de;return n.up.set(y.x,y.y,y.z),{scene:n,camera:i,controls:a,renderer:o,cameraController:c,grid:l,gizmo:d,measureTool:E,applyEdges:S,setAmbientOcclusion:g,dispose:()=>{M(),m.dispose(),(d||E)&&e.removeEventListener("click",v,{capture:!0}),E?.dispose(),p?.dispose(),d?.dispose(),l?.dispose(),H?.dispose(),a.dispose(),o.dispose(),n.traverse(C=>{let O=C;!O.geometry&&!O.material||(O.geometry?.dispose(),Array.isArray(O.material)?O.material.forEach(k=>k.dispose()):O.material?.dispose())})},fitToView:m.fitToView,clearSelection:m.clearSelection}};function tt(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 f.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 f.Vector3(0,0,0)},lighting:{enableSunlight:e.lighting?.enableSunlight??!0,sunlightIntensity:e.lighting?.sunlightIntensity||1,sunlightPosition:e.lighting?.sunlightPosition||new f.Vector3(n.lightDistance,n.lightHeight,n.lightDistance),ambientLightColor:e.lighting?.ambientLightColor||new f.Color(4210752),ambientLightIntensity:e.lighting?.ambientLightIntensity||1,sunlightColor:e.lighting?.sunlightColor||16777215},environment:{hdrPath:e.environment?.hdrPath||"/baseHDR.hdr",backgroundColor:e.environment?.backgroundColor||new f.Color(15790320),enableEnvironmentLighting:e.environment?.enableEnvironmentLighting??!0,sceneUp:e.environment?.sceneUp||de,showEnvironment:e.environment?.showEnvironment??!1},floor:{enabled:e.floor?.enabled??!1,size:e.floor?.size||n.floorSize,color:e.floor?.color||new f.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||f.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??"y"},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 nt=new Set(["grid","floor","label-layer","measure"]);function rt(e){let r=e;for(;r;){if(typeof r.userData.id=="string"&&nt.has(r.userData.id))return!0;r=r.parent}return!1}function ot(e){let r=new f.Scene,t=typeof e.environment.backgroundColor=="string"?new f.Color(e.environment.backgroundColor):e.environment.backgroundColor;return r.background=t||null,r}function at(e,r,t,n,i=200){let o=e.position.clone(),a=r.target.clone(),c=performance.now(),s=d=>1-Math.pow(1-d,3),l=()=>{let d=performance.now()-c,u=s(Math.min(d/i,1));e.position.lerpVectors(o,t,u),r.target.lerpVectors(a,n,u),r.update(),u<1&&requestAnimationFrame(l)};requestAnimationFrame(l)}function it(e,r,t,n,i,o,a,c,s,l,d,u){let p=null,E=performance.now(),m=()=>{let{width:T,height:b}=a();if(T===0||b===0)return;let H=Math.min(window.devicePixelRatio,2),h=Math.round(T*H),g=Math.round(b*H);(e.domElement.width!==h||e.domElement.height!==g)&&(e.setPixelRatio(H),e.setSize(T,b,!1),t.aspect=T/b,t.updateProjectionMatrix(),i.updateAspect(T,b),d?.()?.setSize(T,b,H),u?.setSize(T,b))},v=function(){p=requestAnimationFrame(v);let T=performance.now(),b=(T-E)/1e3;E=T,m(),(o.enableDamping||o.autoRotate)&&o.update(),s&&s.update(n().position),l&&l.update(b),c?.(b);let H=n(),h=d?.();h?(h.setCamera(H),h.render(b)):e.render(r,H),u&&u.render(r,H),l&&l.render(e)};return{animate:v,dispose:()=>{p!==null&&(cancelAnimationFrame(p),p=null)}}}function st(e,r){r.environment.enableEnvironmentLighting?new et().load(r.environment.hdrPath||"/baseHDR.hdr",function(t){if(!t?.image){w().warn("HDR loaded without image data; skipping environment map."),r.events.onReady?.();return}t.mapping=f.EquirectangularReflectionMapping,e.environment=t,r.environment.showEnvironment&&(e.background=t),r.events.onReady?.()},void 0,function(t){w().warn("HDR texture could not be loaded, falling back to basic lighting:",t),r.events.onReady?.()}):r.events.onReady?.()}function lt(e,r){let t=new f.AmbientLight(r.lighting.ambientLightColor,r.lighting.ambientLightIntensity);if(e.add(t),r.lighting.enableSunlight){let n=new f.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=Y(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=Y(r.sceneScale,.001,.1,.5),c=Y(r.sceneScale,1,100,500);n.shadow.camera.near=a,n.shadow.camera.far=c,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 ct(e,r){let t=r.floor.size,n=new f.PlaneGeometry(t,t),i=typeof r.floor.color=="string"?new f.Color(r.floor.color):r.floor.color,o=new f.MeshStandardMaterial({color:i,roughness:r.floor.roughness,metalness:r.floor.metalness,side:f.DoubleSide}),a=new f.Mesh(n,o);a.userData.id="floor",a.name="floor",a.rotation.x=-Math.PI/2,a.position.y=0,r.floor.receiveShadow&&r.render.enableShadows&&(a.receiveShadow=!0),e.add(a)}function dt(e,r){let t=r.parentElement,n=t?t.clientWidth:window.innerWidth,i=t?t.clientHeight:window.innerHeight,o=new f.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 ut(e,r){let t=new f.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=f.VSMShadowMap),t.toneMapping=r.render.toneMapping,t.toneMappingExposure=r.render.toneMappingExposure||1,t.outputColorSpace=f.SRGBColorSpace,t.sortObjects=!0,t}function mt(e,r,t,n,i,o){let a=new Set,c=new Map,s=new f.Raycaster,l=new f.Vector2,d=new f.Vector2,u=h=>{let g=h;for(;g;){if(!g.visible)return!1;g=g.parent}return!0},p=()=>{let h=new f.Box3;if(r.traverse(O=>{let k=O;O.visible&&!rt(O)&&k.geometry&&h.expandByObject(O)}),h.isEmpty()){w().warn("No objects to fit to view");return}let g=h.getCenter(new f.Vector3),R=h.getSize(new f.Vector3),M=Math.max(R.x,R.y,R.z),y=n.fov*(Math.PI/180),L=M/(2*Math.tan(y/2));L*=1.5;let C=n.position.clone().sub(i.target);C.lengthSq()<1e-12&&C.set(.8,1,1.2),C.normalize(),n.position.copy(g.clone().add(C.multiplyScalar(L))),i.target.copy(g),i.update()},E=typeof o.events.selectionColor=="string"?new f.Color(o.events.selectionColor):o.events.selectionColor instanceof f.Color?o.events.selectionColor:new f.Color("#ff0000"),m=()=>{a.forEach(h=>{h instanceof f.Mesh&&c.has(h)&&(h.material=c.get(h),c.delete(h))}),a.clear()},v=h=>{d.set(h.clientX,h.clientY)},S=h=>{let g=new f.Vector2(h.clientX,h.clientY);if(d.distanceTo(g)>5)return;let R=e.getBoundingClientRect();l.x=(h.clientX-R.left)/R.width*2-1,l.y=-((h.clientY-R.top)/R.height)*2+1,s.setFromCamera(l,t());let M=s.intersectObjects(r.children,!0).filter(y=>u(y.object));if(M.length>0){let y=M[0].object;if(!a.has(y)){if(m(),a.add(y),y instanceof f.Mesh&&y.material instanceof f.Material){c.set(y,y.material);let L=y.material.clone();L.emissive=E.clone(),y.material=L}o.events?.onObjectSelected?.(y),y instanceof f.Mesh&&Object.keys(y.userData).length>0&&o.events?.onMeshMetadataClicked?.(y.userData)}}else m(),o.events?.onBackgroundClicked?.({x:l.x,y:l.y})},T=h=>{let g=e.getBoundingClientRect();l.x=(h.clientX-g.left)/g.width*2-1,l.y=-((h.clientY-g.top)/g.height)*2+1,s.setFromCamera(l,t());let R=s.intersectObjects(r.children,!0).filter(Te=>u(Te.object));if(R.length===0)return;let M=R[0].object;if(o.events?.onMeshDoubleClicked?.(M),!o.events?.enableDoubleClickZoom)return;let y=new f.Box3().setFromObject(M);if(y.isEmpty())return;let L=y.getCenter(new f.Vector3),C=y.getSize(new f.Vector3),O=Math.max(C.x,C.y,C.z),k=n.fov*(Math.PI/180),G=O/(2*Math.tan(k/2))*1.5,ye=n.position.clone().sub(i.target).normalize(),Re=L.clone().add(ye.multiplyScalar(G));at(n,i,Re,L)},b=h=>{if(o.events?.enableKeyboardControls)switch(h.key.toLowerCase()){case"f":h.preventDefault(),p();break;case"escape":h.preventDefault(),m();break;case" ":h.preventDefault(),p();break}};return o.events?.enableClickToFocus&&(e.addEventListener("mousedown",v),e.addEventListener("click",S),e.addEventListener("dblclick",T)),o.events?.enableKeyboardControls&&(e.setAttribute("tabindex","0"),e.addEventListener("keydown",b)),{dispose:()=>{e.removeEventListener("mousedown",v),e.removeEventListener("click",S),e.removeEventListener("dblclick",T),e.removeEventListener("keydown",b),m()},fitToView:p,clearSelection:m}}function pt(e,r,t){let n=new Qe(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 Tt={};we(Tt,{CONCRETE_MATERIAL:()=>ht,EMISSIVE_MATERIAL:()=>ft,GLASS_MATERIAL:()=>bt,METAL_MATERIAL:()=>Et,PLASTIC_MATERIAL:()=>gt,RUBBER_MATERIAL:()=>yt,WOOD_MATERIAL:()=>Rt});import*as x from"three";var ft=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}),Et=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}),gt=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}),bt=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}),yt=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}),Rt=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 V from"three";import{Line2 as wt}from"three/addons/lines/Line2.js";import{LineGeometry as Ht}from"three/addons/lines/LineGeometry.js";import{LineMaterial as Ct}from"three/addons/lines/LineMaterial.js";function U(e,r,t,n=!0){return n?{x:e,y:t,z:-r}:{x:e,y:r,z:t}}var vt="#ffffff",X=12,Mt=4e-4,xt=12,St=.05;function ue(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=Dt(o,t,n);a&&i.push(a);break}case"point":{i.push(Lt(o,n));break}default:{let a=o;w().warn(`Skipping unknown display item kind: ${String(a.kind)}`);break}}return i}var At=2;function Dt(e,r,t){if(!r)return w().warn("No rhino3dm instance provided; skipping curve display item."),null;let n=Ot(e.json,r);if(!n)return null;let i=Pt(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 Ht;a.setPositions(o);let c=me(e.color,e.opacity),s=new Ct({color:c.color}),l=s;l.linewidth=e.width??At,l.transparent=c.transparent,l.opacity=c.opacity;let d=new wt(a,s);return d.computeLineDistances(),d.name=e.name,d.userData={id:e.id,layer:e.layer,kind:"curve",metadata:e.metadata},d}function Lt(e,r){let{x:t,y:n,z:i}=U(e.position.X,e.position.Y,e.position.Z,r),o=new V.BufferGeometry;o.setAttribute("position",new V.Float32BufferAttribute([t,n,i],3));let a=new V.PointsMaterial({...me(e.color,e.opacity),size:6,sizeAttenuation:!1}),c=new V.Points(o,a);return c.name=e.name,c.userData={id:e.id,layer:e.layer,kind:"point",metadata:e.metadata},c}function Ot(e,r){try{let t=JSON.parse(e),n=r.CommonObject.decode(t);return n&&typeof n.pointAt=="function"?n:(w().warn("Decoded display-item JSON is not a curve; skipping."),null)}catch(t){return w().warn("Failed to decode curve display item JSON:",t),null}}function Pt(e,r){let t=It(e,r);return t||Bt(e,r)}function It(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:c,y:s,z:l}=U(a[0],a[1],a[2],r);i.push(new V.Vector3(c,s,l))}return i}function Bt(e,r){let t=e.domain,n=t[0],o=t[1]-n,a=l=>{let d=e.pointAt(l),{x:u,y:p,z:E}=U(d[0],d[1],d[2],r);return new V.Vector3(u,p,E)},c=Vt(e),s=[a(n)];for(let l=0;l<X;l++){let d=n+o*l/X,u=n+o*(l+1)/X;q(d,a(d),u,a(u),a,c,xt,s),s.push(a(u))}return s}function q(e,r,t,n,i,o,a,c){if(a<=0)return;let s=(e+t)/2,l=i(s),d=zt(l,r,n),u=Ft(r,l,n);d<=o&&u<=St||(q(e,r,s,l,i,o,a-1,c),c.push(l),q(s,l,t,n,i,o,a-1,c))}function Vt(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*Mt,1e-6)}function Ft(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 c=Math.max(-1,Math.min(1,n.dot(i)/(o*a)));return Math.acos(c)}function zt(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 me(e,r){let t=r??1;return{color:new V.Color(e??vt),transparent:t<1,opacity:t}}var pe=1096174675,fe=1,Z=1,Ee=12,he=56;function J(e){let r=kt(e),t=new DataView(r.buffer,r.byteOffset,r.byteLength);if(r.byteLength<Ee)throw z("Blob too small to contain SLVA header.",{expectedBytes:Ee,availableBytes:r.byteLength});let n=0,i=t.getUint32(n,!0);if(n+=4,i!==pe)throw z(`Invalid SLVA magic: 0x${i.toString(16)}`,{expectedMagic:`0x${pe.toString(16)}`,actualMagic:`0x${i.toString(16)}`});let o=t.getUint32(n,!0);if(n+=4,o!==fe)throw z(`Unsupported SLVA version: ${o}`,{expectedVersion:fe,actualVersion:o});let a=t.getUint32(n,!0);if(n+=4,n+a>r.byteLength)throw z("Insufficient data to read metadata JSON.",{expectedBytes:a,availableBytes:r.byteLength-n,offset:n});let c=r.subarray(n,n+a);n+=a;let s;try{s=JSON.parse(jt(c))}catch(C){throw z(`Failed to parse metadata JSON: ${C instanceof Error?C.message:String(C)}`,{metadataLen:a})}if(n+he>r.byteLength)throw z("Insufficient data to read geometry header.",{expectedBytes:he,availableBytes:r.byteLength-n,offset:n});let l=t.getUint32(n,!0);n+=4;let d=t.getFloat64(n,!0);n+=8;let u=t.getFloat64(n,!0);n+=8;let p=t.getFloat64(n,!0);n+=8;let E=t.getFloat64(n,!0);n+=8;let m=t.getFloat64(n,!0);n+=8;let v=t.getFloat64(n,!0);n+=8;let S=t.getUint32(n,!0);n+=4;let T=(l&Z)!==0,b=S*3,h=b*(T?4:2);if(n+h>r.byteLength)throw z("Insufficient data to read vertices.",{expectedBytes:h,availableBytes:r.byteLength-n,offset:n,useFloat32:T,vertexCount:S});let g=r.byteOffset+n,R=T?Gt(r.buffer,g,b):_t(r.buffer,g,b);if(n+=h,n+4>r.byteLength)throw z("Insufficient data to read index count.",{expectedBytes:4,availableBytes:r.byteLength-n,offset:n});let M=t.getUint32(n,!0);n+=4;let y=M*4;if(n+y>r.byteLength)throw z("Insufficient data to read indices.",{expectedBytes:y,availableBytes:r.byteLength-n,offset:n,indexCount:M});let L=Nt(r.buffer,r.byteOffset+n,M);return{metadata:s,flags:l,vertices:R,indices:L,origin:[d,u,p],scale:[E,m,v]}}function kt(e){return typeof e=="string"?K(e):e instanceof Uint8Array?e:new Uint8Array(e)}function jt(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 $("No UTF-8 decoder available in this environment.",W.INVALID_STATE)}function _t(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 Gt(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 Nt(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 z(e,r){return new $(e,W.VALIDATION_ERROR,{context:r})}import*as I from"three";async function ge(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 Ut(o,r,{parseTime:a,perfStart:n})}catch(i){return w().error("Error parsing mesh batch:",i),[]}}async function Ut(e,r,t){let{mergeByMaterial:n=!0,applyTransforms:i=!0,scaleFactor:o=1,debug:a=!1}=r??{},{parseTime:c=0,perfStart:s=a?performance.now():0}=t??{};try{let l=performance.now(),d=J(e.compressedData),u=performance.now()-l,p=a?Zt(e.compressedData):0;return be(d,{mergeByMaterial:n,applyTransforms:i,scaleFactor:o,debug:a,parseTime:c,decodeTime:u,perfStart:s,blobBytes:p,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}})}catch(l){return w().error("Error parsing mesh batch object:",l),[]}}async function or(e,r){let{mergeByMaterial:t=!0,applyTransforms:n=!0,scaleFactor:i=1,debug:o=!1}=r??{},a=o?performance.now():0;try{let c=performance.now(),s=J(e),l=performance.now()-c,d=e.byteLength;return be(s,{mergeByMaterial:t,applyTransforms:n,scaleFactor:i,debug:o,parseTime:0,decodeTime:l,perfStart:a,blobBytes:d})}catch(c){return w().error("Error parsing mesh batch blob:",c),[]}}function be(e,r){let{mergeByMaterial:t,applyTransforms:n,scaleFactor:i,debug:o,parseTime:a,decodeTime:c,perfStart:s,blobBytes:l,fallback:d}=r,u=e.metadata.materials??d?.materials??[],p=e.metadata.groups??d?.groups??[],E=e.metadata.sourceComponentId??d?.sourceComponentId,m=(e.flags&Z)!==0,v=m?$t(e.vertices,n):Wt(e.vertices,e.origin,e.scale,n);if(o){let h=e.vertices.byteLength+e.indices.byteLength;w().debug("Mesh Batch Stats:"),w().debug(` Materials: ${u.length} | Groups: ${p.length}`),w().debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),w().debug(` Format: ${m?"float32":"int16 quantized"}`),w().debug(` Blob: ${(l/1024/1024).toFixed(2)} MB | Geometry on wire: ${(h/1024/1024).toFixed(2)} MB`)}let S=performance.now(),T=u.map(Yt),b=[];for(let h of p)if(t&&h.meshes.length>1){let g=Xt(h,v,e.indices,T);g.userData.sourceComponentId=E??null,b.push(g)}else{let g=qt(h,v,e.indices,T);for(let R of g)R.userData.sourceComponentId=E??null;b.push(...g)}if(i!==1)for(let h of b)h.scale.set(i,i,i);let H=performance.now()-S;if(o){let h=performance.now()-s;w().debug("Performance:"),a>0&&w().debug(` Parse JSON: ${a.toFixed(2)}ms`),w().debug(` Decode binary: ${c.toFixed(2)}ms`),w().debug(` Create Meshes: ${H.toFixed(2)}ms`),w().debug(` Total: ${h.toFixed(2)}ms`)}return Promise.resolve(b)}function Wt(e,r,t,n){let i=new Float32Array(e.length),o=r[0],a=r[1],c=r[2],s=t[0],l=t[1],d=t[2];if(n)for(let u=0;u<e.length;u+=3){let p=o+(e[u]+32767)*s,E=a+(e[u+1]+32767)*l,m=c+(e[u+2]+32767)*d;i[u]=p,i[u+1]=m,i[u+2]=-E}else for(let u=0;u<e.length;u+=3)i[u]=o+(e[u]+32767)*s,i[u+1]=a+(e[u+1]+32767)*l,i[u+2]=c+(e[u+2]+32767)*d;return i}function $t(e,r){if(!r)return e;let t=new Float32Array(e.length);for(let n=0;n<e.length;n+=3){let i=e[n],o=e[n+1],a=e[n+2];t[n]=i,t[n+1]=a,t[n+2]=-o}return t}function Yt(e){let r=Q(e.color);return new I.MeshPhysicalMaterial({color:r,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,side:I.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.5,polygonOffsetUnits:.5,depthWrite:!0,depthTest:!0})}function Xt(e,r,t,n){let i=0,o=0;for(let m of e.meshes)i+=m.vertexCount,o+=m.indexCount;let a=new Float32Array(i*3),c=new Uint32Array(o),s=0,l=0;for(let m of e.meshes){let v=m.vertexStart*3,S=m.vertexCount*3;a.set(r.subarray(v,v+S),s*3);let T=t.subarray(m.indexStart,m.indexStart+m.indexCount),b=s-m.vertexStart;if(b===0)c.set(T,l);else for(let H=0;H<T.length;H++)c[l+H]=T[H]+b;s+=m.vertexCount,l+=m.indexCount}let d=new I.BufferGeometry;d.setAttribute("position",new I.BufferAttribute(a,3)),d.setIndex(new I.BufferAttribute(c,1)),d.computeVertexNormals();let u=new I.Mesh(d,n[e.materialId]),p=e.meshes[0],E=e.meshes.map(m=>m.name).filter(m=>m&&m.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:p?.layer??"",originalIndex:p?.originalIndex??0,metadata:p?.metadata??{},mergedFrom:e.meshes.slice(1).map(m=>({name:m.name,layer:m.layer,originalIndex:m.originalIndex}))},u}function qt(e,r,t,n){let i=[];for(let o of e.meshes){let a=o.vertexStart*3,c=o.vertexCount*3,s=r.slice(a,a+c),l=t.subarray(o.indexStart,o.indexStart+o.indexCount),d=new Uint32Array(l.length),u=o.vertexStart;for(let m=0;m<l.length;m++)d[m]=l[m]-u;let p=new I.BufferGeometry;p.setAttribute("position",new I.BufferAttribute(s,3)),p.setIndex(new I.BufferAttribute(d,1)),p.computeVertexNormals();let E=new I.Mesh(p,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 Zt(e){return Math.floor(e.length*3/4)}var Jt={Millimeters:1/1e3,Centimeters:1/100,Meters:1,Inches:1/39.37,Feet:1/3.28084},Kt="Display";async function dr(e,r){let t=performance.now(),n=[],{allowScaling:i=!0,allowAutoPosition:o=!0,rhino:a,debug:c=!1,parsing:s={}}=r??{};try{let l=i?Qt(e.modelunits):1;return await en(e,n,l,s,a,c),o&&on(n),n}catch(l){throw an(l,n),l}finally{c&&ln(t)}}function Qt(e){return Jt[e]??1}async function en(e,r,t,n,i,o){for(let a of e.values){let c=a.InnerTree;for(let s in c){let l=c[s];l&&await tn(l,r,t,n,i,o)}}}async function tn(e,r,t,n,i,o){for(let a of e){if(!a.type.includes(Kt))continue;let c={mergeByMaterial:!0,applyTransforms:!0,debug:!1,...n},s=await ge(a.data,c),l=ue(nn(a.data),{rhino:i,applyTransforms:c.applyTransforms}),d=[...s,...l];if(t!==1)for(let u of d)u.scale.set(t,t,t);r.push(...d),o&&w().debug(`Extracted ${s.length} meshes and ${l.length} items from batch`)}}function nn(e){return(typeof e=="string"?rn(e):e)?.items}function rn(e){try{return JSON.parse(e)}catch{return}}function on(e){if(e.length===0)return;let t=_(e).min.y;ee(e,t)}function an(e,r){w().error("An unexpected error occurred:",e),sn(r)}function sn(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 ln(e){let r=performance.now()-e;w().info("Time to process meshes:",`${r.toFixed(2)}ms`)}export{dn as a,Q as b,ee as c,_ as d,te as e,ne as f,re as g,N as h,ae as i,ke as j,Rn as k,ie as l,le as m,Ke as n,ce as o,Nn as p,Tt as q,ue as r,pe as s,fe as t,Z as u,J as v,ge as w,Ut as x,or as y,Jt as z,dr as A};
|
|
54
|
-
//# sourceMappingURL=chunk-PGOKADJC.js.map
|