@selvajs/compute 2.0.0-beta.5 → 2.1.0-beta.0

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.
Files changed (40) hide show
  1. package/dist/{chunk-YNVXBKBY.cjs → chunk-6GCGLBJM.cjs} +2 -2
  2. package/dist/chunk-6GCGLBJM.cjs.map +1 -0
  3. package/dist/chunk-KAULD2XQ.cjs +2 -0
  4. package/dist/chunk-KAULD2XQ.cjs.map +1 -0
  5. package/dist/chunk-MA6YB3YZ.cjs.map +1 -1
  6. package/dist/{chunk-UQ3QRF72.js → chunk-QUD7W5K3.js} +2 -2
  7. package/dist/chunk-SP73WPYA.js +2 -0
  8. package/dist/chunk-SP73WPYA.js.map +1 -0
  9. package/dist/core.cjs.map +1 -1
  10. package/dist/grasshopper.cjs +1 -1
  11. package/dist/grasshopper.cjs.map +1 -1
  12. package/dist/grasshopper.d.cts +4 -3
  13. package/dist/grasshopper.d.ts +4 -3
  14. package/dist/grasshopper.js +1 -1
  15. package/dist/index.cjs +1 -1
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +2 -1
  18. package/dist/index.d.ts +2 -1
  19. package/dist/index.js +1 -1
  20. package/dist/{types-XCUrJGby.d.ts → types-B6KrSthC.d.ts} +89 -3
  21. package/dist/{types-CJ092lxB.d.cts → types-DgepKOuU.d.cts} +89 -3
  22. package/dist/visualization-5D5Y547Q.cjs +2 -0
  23. package/dist/visualization-5D5Y547Q.cjs.map +1 -0
  24. package/dist/visualization-JF4W754M.js +2 -0
  25. package/dist/visualization.cjs +1 -1
  26. package/dist/visualization.cjs.map +1 -1
  27. package/dist/visualization.d.cts +22 -7
  28. package/dist/visualization.d.ts +22 -7
  29. package/dist/visualization.js +1 -1
  30. package/package.json +133 -130
  31. package/dist/chunk-JFLD2UCY.cjs +0 -2
  32. package/dist/chunk-JFLD2UCY.cjs.map +0 -1
  33. package/dist/chunk-MKW2KTPT.js +0 -2
  34. package/dist/chunk-MKW2KTPT.js.map +0 -1
  35. package/dist/chunk-YNVXBKBY.cjs.map +0 -1
  36. package/dist/visualization-GU7JIB4V.cjs +0 -2
  37. package/dist/visualization-GU7JIB4V.cjs.map +0 -1
  38. package/dist/visualization-WIUVT2FZ.js +0 -2
  39. /package/dist/{chunk-UQ3QRF72.js.map → chunk-QUD7W5K3.js.map} +0 -0
  40. /package/dist/{visualization-WIUVT2FZ.js.map → visualization-JF4W754M.js.map} +0 -0
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkMA6YB3YZcjs = require('./chunk-MA6YB3YZ.cjs');var _three = require('three'); var i = _interopRequireWildcard(_three); var w = _interopRequireWildcard(_three); var b = _interopRequireWildcard(_three); var M = _interopRequireWildcard(_three);var _OrbitControlsjs = require('three/addons/controls/OrbitControls.js');var _HDRLoaderjs = require('three/addons/loaders/HDRLoader.js');var V=new i.Vector3(0,0,1),P=(e,r,n,t)=>{switch(e){case"mm":return r;case"cm":return n;default:return t}},Ze= exports.a =function(e,r){let n=oe(r||{}),t=ae(n),o=de(n,e),s=me(e,n),a=he(o,e,n);ce(t,n),le(t,n),_optionalChain([n, 'access', _2 => _2.floor, 'optionalAccess', _3 => _3.enabled])&&ue(t,n);let u=n.events.enableEventHandlers!==!1?fe(e,t,o,a,n):{dispose:()=>{},fitToView:()=>{},clearSelection:()=>{}},c=e.parentElement,h=()=>c?{width:c.clientWidth,height:c.clientHeight}:{width:window.innerWidth,height:window.innerHeight},{animate:m,dispose:l}=ie(s,t,o,a,h,n.events.onFrame);m();let E=_optionalChain([n, 'access', _4 => _4.environment, 'optionalAccess', _5 => _5.sceneUp])||V;return t.up.set(E.x,E.y,E.z),{scene:t,camera:o,controls:a,renderer:s,dispose:()=>{l(),u.dispose(),a.dispose(),s.dispose(),t.traverse(d=>{d instanceof i.Mesh&&(_optionalChain([d, 'access', _6 => _6.geometry, 'optionalAccess', _7 => _7.dispose, 'call', _8 => _8()]),Array.isArray(d.material)?d.material.forEach(H=>H.dispose()):_optionalChain([d, 'access', _9 => _9.material, 'optionalAccess', _10 => _10.dispose, 'call', _11 => _11()]))})},fitToView:u.fitToView,clearSelection:u.clearSelection}};function oe(e){let r=e.sceneScale||"m",t={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:_optionalChain([e, 'access', _12 => _12.camera, 'optionalAccess', _13 => _13.position])||new i.Vector3(-t.cameraDistance,t.cameraDistance,t.cameraDistance),fov:_optionalChain([e, 'access', _14 => _14.camera, 'optionalAccess', _15 => _15.fov])||20,near:_optionalChain([e, 'access', _16 => _16.camera, 'optionalAccess', _17 => _17.near])||t.near,far:_optionalChain([e, 'access', _18 => _18.camera, 'optionalAccess', _19 => _19.far])||t.far,target:_optionalChain([e, 'access', _20 => _20.camera, 'optionalAccess', _21 => _21.target])||new i.Vector3(0,0,0)},lighting:{enableSunlight:_nullishCoalesce(_optionalChain([e, 'access', _22 => _22.lighting, 'optionalAccess', _23 => _23.enableSunlight]), () => (!0)),sunlightIntensity:_optionalChain([e, 'access', _24 => _24.lighting, 'optionalAccess', _25 => _25.sunlightIntensity])||1,sunlightPosition:_optionalChain([e, 'access', _26 => _26.lighting, 'optionalAccess', _27 => _27.sunlightPosition])||new i.Vector3(t.lightDistance,t.lightHeight,t.lightDistance),ambientLightColor:_optionalChain([e, 'access', _28 => _28.lighting, 'optionalAccess', _29 => _29.ambientLightColor])||new i.Color(4210752),ambientLightIntensity:_optionalChain([e, 'access', _30 => _30.lighting, 'optionalAccess', _31 => _31.ambientLightIntensity])||1,sunlightColor:_optionalChain([e, 'access', _32 => _32.lighting, 'optionalAccess', _33 => _33.sunlightColor])||16777215},environment:{hdrPath:_optionalChain([e, 'access', _34 => _34.environment, 'optionalAccess', _35 => _35.hdrPath])||"/baseHDR.hdr",backgroundColor:_optionalChain([e, 'access', _36 => _36.environment, 'optionalAccess', _37 => _37.backgroundColor])||new i.Color(15790320),enableEnvironmentLighting:_nullishCoalesce(_optionalChain([e, 'access', _38 => _38.environment, 'optionalAccess', _39 => _39.enableEnvironmentLighting]), () => (!0)),sceneUp:_optionalChain([e, 'access', _40 => _40.environment, 'optionalAccess', _41 => _41.sceneUp])||V,showEnvironment:_nullishCoalesce(_optionalChain([e, 'access', _42 => _42.environment, 'optionalAccess', _43 => _43.showEnvironment]), () => (!1))},floor:{enabled:_nullishCoalesce(_optionalChain([e, 'access', _44 => _44.floor, 'optionalAccess', _45 => _45.enabled]), () => (!1)),size:_optionalChain([e, 'access', _46 => _46.floor, 'optionalAccess', _47 => _47.size])||t.floorSize,color:_optionalChain([e, 'access', _48 => _48.floor, 'optionalAccess', _49 => _49.color])||new i.Color(8421504),roughness:_optionalChain([e, 'access', _50 => _50.floor, 'optionalAccess', _51 => _51.roughness])||.7,metalness:_optionalChain([e, 'access', _52 => _52.floor, 'optionalAccess', _53 => _53.metalness])||0,receiveShadow:_nullishCoalesce(_optionalChain([e, 'access', _54 => _54.floor, 'optionalAccess', _55 => _55.receiveShadow]), () => (!0))},render:{enableShadows:_nullishCoalesce(_optionalChain([e, 'access', _56 => _56.render, 'optionalAccess', _57 => _57.enableShadows]), () => (!0)),shadowMapSize:_optionalChain([e, 'access', _58 => _58.render, 'optionalAccess', _59 => _59.shadowMapSize])||2048,antialias:_nullishCoalesce(_optionalChain([e, 'access', _60 => _60.render, 'optionalAccess', _61 => _61.antialias]), () => (!0)),pixelRatio:_optionalChain([e, 'access', _62 => _62.render, 'optionalAccess', _63 => _63.pixelRatio])||Math.min(window.devicePixelRatio,2),toneMapping:_optionalChain([e, 'access', _64 => _64.render, 'optionalAccess', _65 => _65.toneMapping])||i.NeutralToneMapping,toneMappingExposure:_optionalChain([e, 'access', _66 => _66.render, 'optionalAccess', _67 => _67.toneMappingExposure])||1,preserveDrawingBuffer:_nullishCoalesce(_optionalChain([e, 'access', _68 => _68.render, 'optionalAccess', _69 => _69.preserveDrawingBuffer]), () => (!1))},controls:{enableDamping:_nullishCoalesce(_optionalChain([e, 'access', _70 => _70.controls, 'optionalAccess', _71 => _71.enableDamping]), () => (!1)),dampingFactor:_optionalChain([e, 'access', _72 => _72.controls, 'optionalAccess', _73 => _73.dampingFactor])||.05,autoRotate:_nullishCoalesce(_optionalChain([e, 'access', _74 => _74.controls, 'optionalAccess', _75 => _75.autoRotate]), () => (!1)),autoRotateSpeed:_optionalChain([e, 'access', _76 => _76.controls, 'optionalAccess', _77 => _77.autoRotateSpeed])||.5,enableZoom:_nullishCoalesce(_optionalChain([e, 'access', _78 => _78.controls, 'optionalAccess', _79 => _79.enableZoom]), () => (!0)),enablePan:_nullishCoalesce(_optionalChain([e, 'access', _80 => _80.controls, 'optionalAccess', _81 => _81.enablePan]), () => (!0)),minDistance:_optionalChain([e, 'access', _82 => _82.controls, 'optionalAccess', _83 => _83.minDistance])||t.minDistance,maxDistance:_optionalChain([e, 'access', _84 => _84.controls, 'optionalAccess', _85 => _85.maxDistance])||1/0},events:{onBackgroundClicked:_optionalChain([e, 'access', _86 => _86.events, 'optionalAccess', _87 => _87.onBackgroundClicked]),onObjectSelected:_optionalChain([e, 'access', _88 => _88.events, 'optionalAccess', _89 => _89.onObjectSelected]),onMeshMetadataClicked:_optionalChain([e, 'access', _90 => _90.events, 'optionalAccess', _91 => _91.onMeshMetadataClicked]),onMeshDoubleClicked:_optionalChain([e, 'access', _92 => _92.events, 'optionalAccess', _93 => _93.onMeshDoubleClicked]),selectionColor:_optionalChain([e, 'access', _94 => _94.events, 'optionalAccess', _95 => _95.selectionColor])||"#ff0000",enableEventHandlers:_nullishCoalesce(_optionalChain([e, 'access', _96 => _96.events, 'optionalAccess', _97 => _97.enableEventHandlers]), () => (!0)),enableKeyboardControls:_nullishCoalesce(_optionalChain([e, 'access', _98 => _98.events, 'optionalAccess', _99 => _99.enableKeyboardControls]), () => (!0)),enableClickToFocus:_nullishCoalesce(_optionalChain([e, 'access', _100 => _100.events, 'optionalAccess', _101 => _101.enableClickToFocus]), () => (!0)),enableDoubleClickZoom:_nullishCoalesce(_optionalChain([e, 'access', _102 => _102.events, 'optionalAccess', _103 => _103.enableDoubleClickZoom]), () => (!0)),onReady:_optionalChain([e, 'access', _104 => _104.events, 'optionalAccess', _105 => _105.onReady]),onFrame:_optionalChain([e, 'access', _106 => _106.events, 'optionalAccess', _107 => _107.onFrame])}}}function ae(e){let r=new i.Scene,n=typeof e.environment.backgroundColor=="string"?new i.Color(e.environment.backgroundColor):e.environment.backgroundColor;return r.background=n||null,r}function se(e,r,n,t,o=200){let s=e.position.clone(),a=r.target.clone(),u=performance.now(),c=m=>1-Math.pow(1-m,3),h=()=>{let m=performance.now()-u,l=c(Math.min(m/o,1));e.position.lerpVectors(s,n,l),r.target.lerpVectors(a,t,l),r.update(),l<1&&requestAnimationFrame(h)};requestAnimationFrame(h)}function ie(e,r,n,t,o,s){let a=null,u=performance.now(),c=()=>{let{width:l,height:E}=o();if(l===0||E===0)return;let g=Math.min(window.devicePixelRatio,2),d=Math.round(l*g),H=Math.round(E*g);(e.domElement.width!==d||e.domElement.height!==H)&&(e.setPixelRatio(g),e.setSize(l,E,!1),n.aspect=l/E,n.updateProjectionMatrix())},h=function(){a=requestAnimationFrame(h);let l=performance.now(),E=(l-u)/1e3;u=l,c(),(t.enableDamping||t.autoRotate)&&t.update(),_optionalChain([s, 'optionalCall', _108 => _108(E)]),e.render(r,n)};return{animate:h,dispose:()=>{a!==null&&(cancelAnimationFrame(a),a=null)}}}function ce(e,r){r.environment.enableEnvironmentLighting?new (0, _HDRLoaderjs.HDRLoader)().load(r.environment.hdrPath||"/baseHDR.hdr",function(n){n.mapping=i.EquirectangularReflectionMapping,e.environment=n,r.environment.showEnvironment&&(e.background=n),_optionalChain([r, 'access', _109 => _109.events, 'access', _110 => _110.onReady, 'optionalCall', _111 => _111()])},void 0,function(n){_chunkMA6YB3YZcjs.e.call(void 0, ).warn("HDR texture could not be loaded, falling back to basic lighting:",n),_optionalChain([r, 'access', _112 => _112.events, 'access', _113 => _113.onReady, 'optionalCall', _114 => _114()])}):_optionalChain([r, 'access', _115 => _115.events, 'access', _116 => _116.onReady, 'optionalCall', _117 => _117()])}function le(e,r){let n=new i.AmbientLight(r.lighting.ambientLightColor,r.lighting.ambientLightIntensity);if(e.add(n),r.lighting.enableSunlight){let t=new i.DirectionalLight(_nullishCoalesce(r.lighting.sunlightColor, () => (16777215)),r.lighting.sunlightIntensity),o=r.lighting.sunlightPosition;if(o&&t.position.set(o.x,o.y,o.z),r.render.enableShadows){t.castShadow=!0;let s=P(r.sceneScale,.1,10,100);t.shadow.camera.left=-s,t.shadow.camera.right=s,t.shadow.camera.top=s,t.shadow.camera.bottom=-s;let a=P(r.sceneScale,.001,.1,.5),u=P(r.sceneScale,1,100,500);t.shadow.camera.near=a,t.shadow.camera.far=u,t.shadow.mapSize.width=r.render.shadowMapSize||2048,t.shadow.mapSize.height=r.render.shadowMapSize||2048,t.shadow.bias=-1e-4,t.shadow.normalBias=.02}e.add(t)}}function ue(e,r){let n=r.floor.size,t=new i.PlaneGeometry(n,n),o=typeof r.floor.color=="string"?new i.Color(r.floor.color):r.floor.color,s=new i.MeshStandardMaterial({color:o,roughness:r.floor.roughness,metalness:r.floor.metalness,side:i.DoubleSide}),a=new i.Mesh(t,s);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 de(e,r){let n=r.parentElement,t=n?n.clientWidth:window.innerWidth,o=n?n.clientHeight:window.innerHeight,s=new i.PerspectiveCamera(e.camera.fov,t/o,e.camera.near,e.camera.far),a=e.camera.position;return a&&s.position.set(a.x,a.y,a.z),s}function me(e,r){let n=new i.WebGLRenderer({antialias:r.render.antialias,canvas:e,alpha:!0,powerPreference:"high-performance",preserveDrawingBuffer:r.render.preserveDrawingBuffer,logarithmicDepthBuffer:!0}),t=e.parentElement,o=t?t.clientWidth:window.innerWidth,s=t?t.clientHeight:window.innerHeight;return t&&(e.style.width="100%",e.style.height="100%",e.style.display="block"),n.setSize(o,s,!1),n.setPixelRatio(r.render.pixelRatio||Math.min(window.devicePixelRatio,2)),r.render.enableShadows&&(n.shadowMap.enabled=!0,n.shadowMap.type=i.VSMShadowMap),n.toneMapping=r.render.toneMapping,n.toneMappingExposure=r.render.toneMappingExposure||1,n.outputColorSpace=i.SRGBColorSpace,n.sortObjects=!0,n}function fe(e,r,n,t,o){let s=new Set,a=new Map,u=new i.Raycaster,c=new i.Vector2,h=new i.Vector2,m=f=>{let p=f;for(;p;){if(!p.visible)return!1;p=p.parent}return!0},l=()=>{let f=new i.Box3;if(r.traverse(A=>{A.visible&&A.userData.id!=="floor"&&A instanceof i.Mesh&&f.expandByObject(A)}),f.isEmpty()){_chunkMA6YB3YZcjs.e.call(void 0, ).warn("No objects to fit to view");return}let p=f.getCenter(new i.Vector3),T=f.getSize(new i.Vector3),v=Math.max(T.x,T.y,T.z),R=n.fov*(Math.PI/180),S=v/(2*Math.tan(R/2));S*=1.5;let O=n.position.clone().sub(t.target).normalize();n.position.copy(p.clone().add(O.multiplyScalar(S))),t.target.copy(p),t.update()},E=typeof o.events.selectionColor=="string"?new i.Color(o.events.selectionColor):o.events.selectionColor instanceof i.Color?o.events.selectionColor:new i.Color("#ff0000"),g=()=>{s.forEach(f=>{f instanceof i.Mesh&&a.has(f)&&(f.material=a.get(f),a.delete(f))}),s.clear()},d=f=>{h.set(f.clientX,f.clientY)},H=f=>{let p=new i.Vector2(f.clientX,f.clientY);if(h.distanceTo(p)>5)return;let T=e.getBoundingClientRect();c.x=(f.clientX-T.left)/T.width*2-1,c.y=-((f.clientY-T.top)/T.height)*2+1,u.setFromCamera(c,n);let v=u.intersectObjects(r.children,!0).filter(R=>m(R.object));if(v.length>0){let R=v[0].object;if(!s.has(R)){if(g(),s.add(R),R instanceof i.Mesh&&R.material instanceof i.Material){a.set(R,R.material);let S=R.material.clone();S.emissive=E.clone(),R.material=S}_optionalChain([o, 'access', _118 => _118.events, 'optionalAccess', _119 => _119.onObjectSelected, 'optionalCall', _120 => _120(R)]),R instanceof i.Mesh&&Object.keys(R.userData).length>0&&_optionalChain([o, 'access', _121 => _121.events, 'optionalAccess', _122 => _122.onMeshMetadataClicked, 'optionalCall', _123 => _123(R.userData)])}}else g(),_optionalChain([o, 'access', _124 => _124.events, 'optionalAccess', _125 => _125.onBackgroundClicked, 'optionalCall', _126 => _126({x:c.x,y:c.y})])},L=f=>{let p=e.getBoundingClientRect();c.x=(f.clientX-p.left)/p.width*2-1,c.y=-((f.clientY-p.top)/p.height)*2+1,u.setFromCamera(c,n);let T=u.intersectObjects(r.children,!0).filter(ee=>m(ee.object));if(T.length===0)return;let v=T[0].object;if(_optionalChain([o, 'access', _127 => _127.events, 'optionalAccess', _128 => _128.onMeshDoubleClicked, 'optionalCall', _129 => _129(v)]),!_optionalChain([o, 'access', _130 => _130.events, 'optionalAccess', _131 => _131.enableDoubleClickZoom]))return;let R=new i.Box3().setFromObject(v);if(R.isEmpty())return;let S=R.getCenter(new i.Vector3),O=R.getSize(new i.Vector3),A=Math.max(O.x,O.y,O.z),K=n.fov*(Math.PI/180),X=A/(2*Math.tan(K/2))*1.5,J=n.position.clone().sub(t.target).normalize(),Q=S.clone().add(J.multiplyScalar(X));se(n,t,Q,S)},x=f=>{if(_optionalChain([o, 'access', _132 => _132.events, 'optionalAccess', _133 => _133.enableKeyboardControls]))switch(f.key.toLowerCase()){case"f":f.preventDefault(),l();break;case"escape":f.preventDefault(),g();break;case" ":f.preventDefault(),l();break}};return _optionalChain([o, 'access', _134 => _134.events, 'optionalAccess', _135 => _135.enableClickToFocus])&&(e.addEventListener("mousedown",d),e.addEventListener("click",H),e.addEventListener("dblclick",L)),_optionalChain([o, 'access', _136 => _136.events, 'optionalAccess', _137 => _137.enableKeyboardControls])&&(e.setAttribute("tabindex","0"),e.addEventListener("keydown",x)),{dispose:()=>{e.removeEventListener("mousedown",d),e.removeEventListener("click",H),e.removeEventListener("dblclick",L),e.removeEventListener("keydown",x),g()},fitToView:l,clearSelection:g}}function he(e,r,n){let t=new (0, _OrbitControlsjs.OrbitControls)(e,r),o=n.camera.target;return o&&t.target.set(o.x,o.y,o.z),t.enableDamping=n.controls.enableDamping||!1,t.dampingFactor=n.controls.dampingFactor||.05,t.autoRotate=n.controls.autoRotate||!1,t.autoRotateSpeed=n.controls.autoRotateSpeed||.5,t.enableZoom=_nullishCoalesce(n.controls.enableZoom, () => (!0)),t.enablePan=_nullishCoalesce(n.controls.enablePan, () => (!0)),t.minDistance=n.controls.minDistance||.001,t.maxDistance=n.controls.maxDistance||1/0,t.screenSpacePanning=!1,t.maxPolarAngle=Math.PI,t.update(),t}var B={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 Xe(e,r,n,t,o){if(Ee(e),r.length===0)return;r.forEach(m=>{e.add(m)});let s=z(r),a=s.getCenter(new w.Vector3),u=s.getSize(new w.Vector3),c=Math.max(u.x,u.y,u.z);if(c/Math.min(u.x||1,u.y||1,u.z||1)>B.SCALE_RATIO_THRESHOLD||c>B.HUGE_THRESHOLD?(n.near=c*B.NEAR_PLANE_FACTOR.TINY,n.far=c*B.FAR_PLANE_FACTOR.HUGE):c>B.LARGE_THRESHOLD?(n.near=c*B.NEAR_PLANE_FACTOR.SMALL,n.far=c*B.FAR_PLANE_FACTOR.LARGE):(n.near=Math.max(.01,c*B.NEAR_PLANE_FACTOR.NORMAL),n.far=Math.max(2e3,c*B.FAR_PLANE_FACTOR.NORMAL)),n.updateProjectionMatrix(),o)t.minDistance=n.near*2,t.maxDistance=n.far*.9;else{let m=c*B.INITIAL_DISTANCE_MULTIPLIER;n.position.set(a.x+m*.8,a.y+m,a.z+m*1.2),t.target.copy(a),t.minDistance=n.near*2,t.maxDistance=n.far*.9,t.update()}}function N(e){if(!e||typeof e!="string")return _chunkMA6YB3YZcjs.e.call(void 0, ).warn(`Invalid color input: ${e}, using white`),new w.Color(16777215);let r=e.trim();if(/^#?[0-9A-Fa-f]{6}$/.test(r))try{let n=r.startsWith("#")?r:`#${r}`;return new w.Color(n)}catch (e2){return _chunkMA6YB3YZcjs.e.call(void 0, ).warn(`Invalid hex color: ${e}, using white`),new w.Color(16777215)}if(r.includes(",")){let n=r.split(",").map(t=>parseInt(t.trim(),10));if(n.length===3&&n.every(t=>!isNaN(t)&&t>=0&&t<=255))return new w.Color(n[0]/255,n[1]/255,n[2]/255)}try{return new w.Color(r.toLowerCase())}catch (e3){return _chunkMA6YB3YZcjs.e.call(void 0, ).warn(`Invalid color string: ${e}, using white`),new w.Color(16777215)}}function G(e,r){e.forEach(n=>{n.position.y-=r})}function z(e){let r=new w.Box3;return e.length===0||e.forEach(n=>{n.updateMatrixWorld(!0);let t=new w.Box3().setFromObject(n);r.union(t)}),r}function Ee(e){[...e.children].forEach(n=>{n.userData.id!=="floor"&&(n.traverse(t=>{if(!(t instanceof w.Mesh))return;_optionalChain([t, 'access', _138 => _138.geometry, 'optionalAccess', _139 => _139.dispose, 'call', _140 => _140()]),(Array.isArray(t.material)?t.material:[t.material]).forEach(s=>{for(let a of Object.values(s))a instanceof w.Texture&&a.dispose();s.dispose()})}),n.removeFromParent())})}var Me={};_chunkMA6YB3YZcjs.a.call(void 0, Me,{CONCRETE_MATERIAL:()=>ye,EMISSIVE_MATERIAL:()=>pe,GLASS_MATERIAL:()=>Re,METAL_MATERIAL:()=>ge,PLASTIC_MATERIAL:()=>be,RUBBER_MATERIAL:()=>Te,WOOD_MATERIAL:()=>we});var pe=new b.MeshPhysicalMaterial({color:0,emissive:new b.Color(16777215),emissiveIntensity:5,metalness:0,roughness:.2,clearcoat:.3,clearcoatRoughness:.2,depthWrite:!0,depthTest:!0,transparent:!1,alphaTest:0,polygonOffset:!0,side:b.FrontSide,dithering:!0}),ge=new b.MeshPhysicalMaterial({color:new b.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:b.FrontSide,dithering:!0}),ye=new b.MeshPhysicalMaterial({color:new b.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:b.FrontSide,dithering:!0}),be=new b.MeshPhysicalMaterial({color:new b.Color(16777215),metalness:0,roughness:.3,envMapIntensity:.5,clearcoat:.5,clearcoatRoughness:.1,reflectivity:.5,ior:1.4,transmission:0,transparent:!1,depthWrite:!0,side:b.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Re=new b.MeshPhysicalMaterial({color:new b.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:b.DoubleSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Te=new b.MeshPhysicalMaterial({color:new b.Color(1710618),metalness:0,roughness:.9,envMapIntensity:.2,clearcoat:.1,clearcoatRoughness:.8,reflectivity:.2,ior:1.3,transmission:0,depthWrite:!0,side:b.FrontSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),we=new b.MeshPhysicalMaterial({color:new b.Color(8934707),metalness:0,roughness:.7,envMapIntensity:.3,clearcoat:.3,clearcoatRoughness:.4,reflectivity:.3,ior:1.3,transmission:0,depthWrite:!0,side:b.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});var $=1096174675,W= exports.h =1,k= exports.i =1,Y=12,j=56;function _(e){let r=He(e),n=new DataView(r.buffer,r.byteOffset,r.byteLength);if(r.byteLength<Y)throw I("Blob too small to contain SLVA header.",{expectedBytes:Y,availableBytes:r.byteLength});let t=0,o=n.getUint32(t,!0);if(t+=4,o!==$)throw I(`Invalid SLVA magic: 0x${o.toString(16)}`,{expectedMagic:`0x${$.toString(16)}`,actualMagic:`0x${o.toString(16)}`});let s=n.getUint32(t,!0);if(t+=4,s!==W)throw I(`Unsupported SLVA version: ${s}`,{expectedVersion:W,actualVersion:s});let a=n.getUint32(t,!0);if(t+=4,t+a>r.byteLength)throw I("Insufficient data to read metadata JSON.",{expectedBytes:a,availableBytes:r.byteLength-t,offset:t});let u=r.subarray(t,t+a);t+=a;let c;try{c=JSON.parse(xe(u))}catch(A){throw I(`Failed to parse metadata JSON: ${A instanceof Error?A.message:String(A)}`,{metadataLen:a})}if(t+j>r.byteLength)throw I("Insufficient data to read geometry header.",{expectedBytes:j,availableBytes:r.byteLength-t,offset:t});let h=n.getUint32(t,!0);t+=4;let m=n.getFloat64(t,!0);t+=8;let l=n.getFloat64(t,!0);t+=8;let E=n.getFloat64(t,!0);t+=8;let g=n.getFloat64(t,!0);t+=8;let d=n.getFloat64(t,!0);t+=8;let H=n.getFloat64(t,!0);t+=8;let L=n.getUint32(t,!0);t+=4;let x=(h&k)!==0,C=L*3,p=C*(x?4:2);if(t+p>r.byteLength)throw I("Insufficient data to read vertices.",{expectedBytes:p,availableBytes:r.byteLength-t,offset:t,useFloat32:x,vertexCount:L});let T=r.byteOffset+t,v=x?ve(r.buffer,T,C):Ce(r.buffer,T,C);if(t+=p,t+4>r.byteLength)throw I("Insufficient data to read index count.",{expectedBytes:4,availableBytes:r.byteLength-t,offset:t});let R=n.getUint32(t,!0);t+=4;let S=R*4;if(t+S>r.byteLength)throw I("Insufficient data to read indices.",{expectedBytes:S,availableBytes:r.byteLength-t,offset:t,indexCount:R});let O=Se(r.buffer,r.byteOffset+t,R);return{metadata:c,flags:h,vertices:v,indices:O,origin:[m,l,E],scale:[g,d,H]}}function He(e){return typeof e=="string"?_chunkMA6YB3YZcjs.o.call(void 0, e):e instanceof Uint8Array?e:new Uint8Array(e)}function xe(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 (0, _chunkMA6YB3YZcjs.d)("No UTF-8 decoder available in this environment.",_chunkMA6YB3YZcjs.c.INVALID_STATE)}function Ce(e,r,n){if(n===0)return new Int16Array(0);if(r%2===0)return new Int16Array(e,r,n);let t=new Uint8Array(n*2);return t.set(new Uint8Array(e,r,n*2)),new Int16Array(t.buffer)}function ve(e,r,n){if(n===0)return new Float32Array(0);if(r%4===0)return new Float32Array(e,r,n);let t=new Uint8Array(n*4);return t.set(new Uint8Array(e,r,n*4)),new Float32Array(t.buffer)}function Se(e,r,n){if(n===0)return new Uint32Array(0);if(r%4===0)return new Uint32Array(e,r,n);let t=new Uint8Array(n*4);return t.set(new Uint8Array(e,r,n*4)),new Uint32Array(t.buffer)}function I(e,r){return new (0, _chunkMA6YB3YZcjs.d)(e,_chunkMA6YB3YZcjs.c.VALIDATION_ERROR,{context:r})}async function Z(e,r){let{debug:n=!1}=_nullishCoalesce(r, () => ({})),t=n?performance.now():0;try{let o=performance.now(),s=JSON.parse(e),a=performance.now()-o;return await Ae(s,r,{parseTime:a,perfStart:t})}catch(o){return _chunkMA6YB3YZcjs.e.call(void 0, ).error("Error parsing mesh batch:",o),[]}}async function Ae(e,r,n){let{mergeByMaterial:t=!0,applyTransforms:o=!0,scaleFactor:s=1,debug:a=!1}=_nullishCoalesce(r, () => ({})),{parseTime:u=0,perfStart:c=a?performance.now():0}=_nullishCoalesce(n, () => ({}));try{let h=performance.now(),m=_(e.compressedData),l=performance.now()-h,E=a?Fe(e.compressedData):0;return q(m,{mergeByMaterial:t,applyTransforms:o,scaleFactor:s,debug:a,parseTime:u,decodeTime:l,perfStart:c,blobBytes:E,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}})}catch(h){return _chunkMA6YB3YZcjs.e.call(void 0, ).error("Error parsing mesh batch object:",h),[]}}async function at(e,r){let{mergeByMaterial:n=!0,applyTransforms:t=!0,scaleFactor:o=1,debug:s=!1}=_nullishCoalesce(r, () => ({})),a=s?performance.now():0;try{let u=performance.now(),c=_(e),h=performance.now()-u,m=e.byteLength;return q(c,{mergeByMaterial:n,applyTransforms:t,scaleFactor:o,debug:s,parseTime:0,decodeTime:h,perfStart:a,blobBytes:m})}catch(u){return _chunkMA6YB3YZcjs.e.call(void 0, ).error("Error parsing mesh batch blob:",u),[]}}function q(e,r){let{mergeByMaterial:n,applyTransforms:t,scaleFactor:o,debug:s,parseTime:a,decodeTime:u,perfStart:c,blobBytes:h,fallback:m}=r,l=_nullishCoalesce(_nullishCoalesce(e.metadata.materials, () => (_optionalChain([m, 'optionalAccess', _141 => _141.materials]))), () => ([])),E=_nullishCoalesce(_nullishCoalesce(e.metadata.groups, () => (_optionalChain([m, 'optionalAccess', _142 => _142.groups]))), () => ([])),g=_nullishCoalesce(e.metadata.sourceComponentId, () => (_optionalChain([m, 'optionalAccess', _143 => _143.sourceComponentId]))),d=(e.flags&k)!==0,H=d?Le(e.vertices,t):Be(e.vertices,e.origin,e.scale,t);if(s){let p=e.vertices.byteLength+e.indices.byteLength;_chunkMA6YB3YZcjs.e.call(void 0, ).debug("Mesh Batch Stats:"),_chunkMA6YB3YZcjs.e.call(void 0, ).debug(` Materials: ${l.length} | Groups: ${E.length}`),_chunkMA6YB3YZcjs.e.call(void 0, ).debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),_chunkMA6YB3YZcjs.e.call(void 0, ).debug(` Format: ${d?"float32":"int16 quantized"}`),_chunkMA6YB3YZcjs.e.call(void 0, ).debug(` Blob: ${(h/1024/1024).toFixed(2)} MB | Geometry on wire: ${(p/1024/1024).toFixed(2)} MB`)}let L=performance.now(),x=l.map(Ie),C=[];for(let p of E)if(n&&p.meshes.length>1){let T=Oe(p,H,e.indices,x);T.userData.sourceComponentId=_nullishCoalesce(g, () => (null)),C.push(T)}else{let T=De(p,H,e.indices,x);for(let v of T)v.userData.sourceComponentId=_nullishCoalesce(g, () => (null));C.push(...T)}if(o!==1)for(let p of C)p.scale.set(o,o,o);let f=performance.now()-L;if(s){let p=performance.now()-c;_chunkMA6YB3YZcjs.e.call(void 0, ).debug("Performance:"),a>0&&_chunkMA6YB3YZcjs.e.call(void 0, ).debug(` Parse JSON: ${a.toFixed(2)}ms`),_chunkMA6YB3YZcjs.e.call(void 0, ).debug(` Decode binary: ${u.toFixed(2)}ms`),_chunkMA6YB3YZcjs.e.call(void 0, ).debug(` Create Meshes: ${f.toFixed(2)}ms`),_chunkMA6YB3YZcjs.e.call(void 0, ).debug(` Total: ${p.toFixed(2)}ms`)}return Promise.resolve(C)}function Be(e,r,n,t){let o=new Float32Array(e.length),s=r[0],a=r[1],u=r[2],c=n[0],h=n[1],m=n[2];if(t)for(let l=0;l<e.length;l+=3){let E=s+(e[l]+32767)*c,g=a+(e[l+1]+32767)*h,d=u+(e[l+2]+32767)*m;o[l]=E,o[l+1]=d,o[l+2]=-g}else for(let l=0;l<e.length;l+=3)o[l]=s+(e[l]+32767)*c,o[l+1]=a+(e[l+1]+32767)*h,o[l+2]=u+(e[l+2]+32767)*m;return o}function Le(e,r){if(!r)return e;let n=new Float32Array(e.length);for(let t=0;t<e.length;t+=3){let o=e[t],s=e[t+1],a=e[t+2];n[t]=o,n[t+1]=a,n[t+2]=-s}return n}function Ie(e){let r=N(e.color);return new M.MeshPhysicalMaterial({color:r,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,side:M.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.5,polygonOffsetUnits:.5,depthWrite:!0,depthTest:!0})}function Oe(e,r,n,t){let o=0,s=0;for(let d of e.meshes)o+=d.vertexCount,s+=d.indexCount;let a=new Float32Array(o*3),u=new Uint32Array(s),c=0,h=0;for(let d of e.meshes){let H=d.vertexStart*3,L=d.vertexCount*3;a.set(r.subarray(H,H+L),c*3);let x=n.subarray(d.indexStart,d.indexStart+d.indexCount),C=c-d.vertexStart;if(C===0)u.set(x,h);else for(let f=0;f<x.length;f++)u[h+f]=x[f]+C;c+=d.vertexCount,h+=d.indexCount}let m=new M.BufferGeometry;m.setAttribute("position",new M.BufferAttribute(a,3)),m.setIndex(new M.BufferAttribute(u,1)),m.computeVertexNormals();let l=new M.Mesh(m,t[e.materialId]),E=e.meshes[0],g=e.meshes.map(d=>d.name).filter(d=>d&&d.length>0);return l.name=g.length>0?g[0]:`merged_material_${e.materialId}`,l.castShadow=!0,l.receiveShadow=!0,l.userData={name:l.name,layer:_nullishCoalesce(_optionalChain([E, 'optionalAccess', _144 => _144.layer]), () => ("")),originalIndex:_nullishCoalesce(_optionalChain([E, 'optionalAccess', _145 => _145.originalIndex]), () => (0)),metadata:_nullishCoalesce(_optionalChain([E, 'optionalAccess', _146 => _146.metadata]), () => ({})),mergedFrom:e.meshes.slice(1).map(d=>({name:d.name,layer:d.layer,originalIndex:d.originalIndex}))},l}function De(e,r,n,t){let o=[];for(let s of e.meshes){let a=s.vertexStart*3,u=s.vertexCount*3,c=r.slice(a,a+u),h=n.subarray(s.indexStart,s.indexStart+s.indexCount),m=new Uint32Array(h.length),l=s.vertexStart;for(let d=0;d<h.length;d++)m[d]=h[d]-l;let E=new M.BufferGeometry;E.setAttribute("position",new M.BufferAttribute(c,3)),E.setIndex(new M.BufferAttribute(m,1)),E.computeVertexNormals();let g=new M.Mesh(E,t[e.materialId]);g.name=s.name,g.userData={name:s.name,layer:_nullishCoalesce(s.layer, () => ("")),originalIndex:s.originalIndex,metadata:_nullishCoalesce(s.metadata, () => ({}))},g.castShadow=!0,g.receiveShadow=!0,o.push(g)}return o}function Fe(e){return Math.floor(e.length*3/4)}var Pe={Millimeters:1/1e3,Centimeters:1/100,Meters:1,Inches:1/39.37,Feet:1/3.28084},ze="Display";async function ut(e,r){let n=performance.now(),t=[],{allowScaling:o=!0,allowAutoPosition:s=!0,debug:a=!1,parsing:u={}}=_nullishCoalesce(r, () => ({}));try{let c=o?ke(e.modelunits):1;return await _e(e,t,c,u,a),s&&Ve(t),t}catch(c){throw Ne(c,t),c}finally{a&&$e(n)}}function ke(e){return _nullishCoalesce(Pe[e], () => (1))}async function _e(e,r,n,t,o){for(let s of e.values){let a=s.InnerTree;for(let u in a){let c=a[u];c&&await Ue(c,r,n,t,o)}}}async function Ue(e,r,n,t,o){for(let s of e)if(s.type.includes(ze)){let a={mergeByMaterial:!0,applyTransforms:!0,debug:!1,...t},u=await Z(s.data,a);if(n!==1)for(let c of u)c.scale.set(n,n,n);r.push(...u),o&&_chunkMA6YB3YZcjs.e.call(void 0, ).debug(`Extracted ${u.length} meshes from batch`)}}function Ve(e){if(e.length===0)return;let n=z(e).min.y;G(e,n)}function Ne(e,r){_chunkMA6YB3YZcjs.e.call(void 0, ).error("An unexpected error occurred:",e),Ge(r)}function Ge(e){for(let r of e)r.geometry&&r.geometry.dispose(),r.material&&(Array.isArray(r.material)?r.material.forEach(n=>n.dispose()):r.material.dispose())}function $e(e){let r=performance.now()-e;_chunkMA6YB3YZcjs.e.call(void 0, ).info("Time to process meshes:",`${r.toFixed(2)}ms`)}exports.a = Ze; exports.b = Xe; exports.c = N; exports.d = G; exports.e = z; exports.f = Me; exports.g = $; exports.h = W; exports.i = k; exports.j = _; exports.k = Z; exports.l = Ae; exports.m = at; exports.n = Pe; exports.o = ut;
2
- //# sourceMappingURL=chunk-JFLD2UCY.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-JFLD2UCY.cjs","../src/features/visualization/threejs/three-initializer.ts","../src/features/visualization/threejs/three-helpers.ts"],"names":["defaultUp","getScaleValue","scale","mmVal","cmVal","mVal","initThree","canvas","options","config","applyDefaults","scene","createScene","camera","createCamera","renderer","setupRenderer","controls","setupControls","setupEnvironment","setupLighting","addFloor","eventHandlers","setupEventHandlers","parent","getCanvasSize","animate","disposeAnimation","createAnimationLoop","sceneUp","object","material","defaults","bgColor","animateCameraTo","toPosition","toTarget","durationMs","fromPosition","fromTarget","startTime","easeOut","t","tick","elapsed","onFrame","animationId","lastTime","checkResize","width","height","pixelRatio","newW","newH","now","delta","HDRLoader","envMap","error","getLogger","ambientLight","sunlight","pos","shadowSize","shadowNear","shadowFar","floorSize","floorGeometry","floorColor","floorMaterial","floor","selectedObjects","originalMaterials","raycaster","mouse","mouseDownPosition","isFullyVisible","current","fitToView","box","center","size","maxDim","fov","distance","direction","selectionColorObj","clearSelection","obj","handleMouseDown","event","handleCanvasClick","currentMousePosition","rect","intersects","i","clickedObject","clonedMaterial","handleDoubleClick","target","targetPosition","handleKeydown","OrbitControls","CAMERA_CONFIG","updateScene","meshes","initialPositionSet","clearScene","mesh","unionBoundingBox","computeCombinedBoundingBox","parseColor","colorString","trimmed","hex"],"mappings":"AAAA,2/BAAqE,kMCA9C,yEACO,gEACJ,IAKpBA,CAAAA,CAAY,IAAU,CAAA,CAAA,OAAA,CAAQ,CAAA,CAAG,CAAA,CAAG,CAAC,CAAA,CAGrCC,CAAAA,CAAgB,CAACC,CAAAA,CAAeC,CAAAA,CAAeC,CAAAA,CAAeC,CAAAA,CAAAA,EAAyB,CAC5F,MAAA,CAAQH,CAAAA,CAAO,CACd,IAAK,IAAA,CACJ,OAAOC,CAAAA,CACR,IAAK,IAAA,CACJ,OAAOC,CAAAA,CACR,OAAA,CACC,OAAOC,CACT,CACD,CAAA,CAKaC,EAAAA,aAAY,QAAA,CACxBC,CAAAA,CACAC,CAAAA,CASC,CACD,IAAMC,CAAAA,CAASC,EAAAA,CAAcF,CAAAA,EAAW,CAAC,CAAC,CAAA,CAEpCG,CAAAA,CAAQC,EAAAA,CAAYH,CAAM,CAAA,CAC1BI,CAAAA,CAASC,EAAAA,CAAaL,CAAAA,CAAQF,CAAM,CAAA,CACpCQ,CAAAA,CAAWC,EAAAA,CAAcT,CAAAA,CAAQE,CAAM,CAAA,CACvCQ,CAAAA,CAAWC,EAAAA,CAAcL,CAAAA,CAAQN,CAAAA,CAAQE,CAAM,CAAA,CAErDU,EAAAA,CAAiBR,CAAAA,CAAOF,CAAM,CAAA,CAC9BW,EAAAA,CAAcT,CAAAA,CAAOF,CAAM,CAAA,iBAEvBA,CAAAA,qBAAO,KAAA,6BAAO,SAAA,EACjBY,EAAAA,CAASV,CAAAA,CAAOF,CAAM,CAAA,CAGvB,IAAMa,CAAAA,CACLb,CAAAA,CAAO,MAAA,CAAO,mBAAA,GAAwB,CAAA,CAAA,CACnCc,EAAAA,CAAmBhB,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AAA,CAAA,IAZZ,CACxB,IAAMuE,CAAAA,CAAWF,CAAAA,CAASqB,CAAAA,CAAc,2BAAA,CAExC1F,CAAAA,CAAO,QAAA,CAAS,GAAA,CAAImE,CAAAA,CAAO,CAAA,CAAII,CAAAA,CAAW,EAAA,CAAKJ,CAAAA,CAAO,CAAA,CAAII,CAAAA,CAAUJ,CAAAA,CAAO,CAAA,CAAII,CAAAA,CAAW,GAAG,CAAA,CAC7FnE,CAAAA,CAAS,MAAA,CAAO,IAAA,CAAK+D,CAAM,CAAA,CAC3B/D,CAAAA,CAAS,WAAA,CAAcJ,CAAAA,CAAO,IAAA,CAAO,CAAA,CACrCI,CAAAA,CAAS,WAAA,CAAcJ,CAAAA,CAAO,GAAA,CAAM,EAAA,CAEpCI,CAAAA,CAAS,MAAA,CAAO,CACjB,CAKD,CAeO,SAAS8F,CAAAA,CAAWC,CAAAA,CAAkC,CAC5D,EAAA,CAAI,CAACA,CAAAA,EAAe,OAAOA,CAAAA,EAAgB,QAAA,CAC1C,OAAArD,iCAAAA,CAAU,CAAE,IAAA,CAAK,CAAA,qBAAA,EAAwBqD,CAAW,CAAA,aAAA,CAAe,CAAA,CAC5D,IAAU,CAAA,CAAA,KAAA,CAAM,QAAQ,CAAA,CAGhC,IAAMC,CAAAA,CAAUD,CAAAA,CAAY,IAAA,CAAK,CAAA,CAGjC,EAAA,CAAI,oBAAA,CAAqB,IAAA,CAAKC,CAAO,CAAA,CACpC,GAAI,CACH,IAAMC,CAAAA,CAAMD,CAAAA,CAAQ,UAAA,CAAW,GAAG,CAAA,CAAIA,CAAAA,CAAU,CAAA,CAAA,EAAIA,CAAO,CAAA,CAAA","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-JFLD2UCY.cjs","sourcesContent":[null,"import * as THREE from 'three';\nimport { OrbitControls } from 'three/addons/controls/OrbitControls.js';\nimport { HDRLoader } from 'three/addons/loaders/HDRLoader.js';\n\nimport { getLogger } from '@/core';\nimport { ThreeInitializerOptions } from '../types';\n\nconst defaultUp = new THREE.Vector3(0, 0, 1);\n\n// Returns scale-specific values for mm, cm, and m scales\nconst getScaleValue = (scale: string, mmVal: number, cmVal: number, mVal: number): number => {\n\tswitch (scale) {\n\t\tcase 'mm':\n\t\t\treturn mmVal;\n\t\tcase 'cm':\n\t\t\treturn cmVal;\n\t\tdefault:\n\t\t\treturn mVal;\n\t}\n};\n\n/**\n * Initializes a Three.js environment with scene, camera, renderer, and event handling.\n */\nexport const initThree = function (\n\tcanvas: HTMLCanvasElement,\n\toptions?: ThreeInitializerOptions\n): {\n\tscene: THREE.Scene;\n\tcamera: THREE.PerspectiveCamera;\n\tcontrols: OrbitControls;\n\trenderer: THREE.WebGLRenderer;\n\tdispose: () => void;\n\tfitToView: () => void;\n\tclearSelection: () => void;\n} {\n\tconst config = applyDefaults(options || {});\n\n\tconst scene = createScene(config);\n\tconst camera = createCamera(config, canvas);\n\tconst renderer = setupRenderer(canvas, config);\n\tconst controls = setupControls(camera, canvas, config);\n\n\tsetupEnvironment(scene, config);\n\tsetupLighting(scene, config);\n\n\tif (config.floor?.enabled) {\n\t\taddFloor(scene, config);\n\t}\n\n\tconst eventHandlers =\n\t\tconfig.events.enableEventHandlers !== false\n\t\t\t? setupEventHandlers(canvas, scene, camera, controls, config)\n\t\t\t: { dispose: () => {}, fitToView: () => {}, clearSelection: () => {} };\n\n\tconst parent = canvas.parentElement;\n\tconst getCanvasSize = () =>\n\t\tparent\n\t\t\t? { width: parent.clientWidth, height: parent.clientHeight }\n\t\t\t: { width: window.innerWidth, height: window.innerHeight };\n\n\t// Resize checked every frame so buffer resize and render happen in the same frame,\n\t// preventing visible blank frames on resize\n\tconst { animate, dispose: disposeAnimation } = createAnimationLoop(\n\t\trenderer,\n\t\tscene,\n\t\tcamera,\n\t\tcontrols,\n\t\tgetCanvasSize,\n\t\tconfig.events.onFrame\n\t);\n\tanimate();\n\n\tconst sceneUp = config.environment?.sceneUp || defaultUp;\n\tscene.up.set(sceneUp.x, sceneUp.y, sceneUp.z);\n\n\tconst dispose = () => {\n\t\tdisposeAnimation();\n\t\teventHandlers.dispose();\n\t\tcontrols.dispose();\n\t\trenderer.dispose();\n\n\t\tscene.traverse((object) => {\n\t\t\tif (object instanceof THREE.Mesh) {\n\t\t\t\tobject.geometry?.dispose();\n\t\t\t\tif (Array.isArray(object.material)) {\n\t\t\t\t\tobject.material.forEach((material) => material.dispose());\n\t\t\t\t} else {\n\t\t\t\t\tobject.material?.dispose();\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t};\n\n\treturn {\n\t\tscene,\n\t\tcamera,\n\t\tcontrols,\n\t\trenderer,\n\t\tdispose,\n\t\tfitToView: eventHandlers.fitToView,\n\t\tclearSelection: eventHandlers.clearSelection\n\t};\n};\n\nfunction applyDefaults(options: ThreeInitializerOptions): Required<ThreeInitializerOptions> {\n\tconst scale = options.sceneScale || 'm';\n\n\t// All Rhino geometry is normalized to METERS (1 unit = 1 meter), sceneScale just changes the viewing perspective\n\tconst scaleDefaults = {\n\t\tmm: {\n\t\t\tcameraDistance: 20,\n\t\t\tnear: 0.1,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 100,\n\t\t\tlightDistance: 10,\n\t\t\tlightHeight: 20,\n\t\t\tminDistance: 0.1,\n\t\t\tshadowSize: 100,\n\t\t\tscaleFactor: 1000\n\t\t},\n\t\tcm: {\n\t\t\tcameraDistance: 20,\n\t\t\tnear: 0.1,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 100,\n\t\t\tlightDistance: 25,\n\t\t\tlightHeight: 50,\n\t\t\tminDistance: 0.1,\n\t\t\tshadowSize: 100,\n\t\t\tscaleFactor: 100\n\t\t},\n\t\tm: {\n\t\t\tcameraDistance: 10,\n\t\t\tnear: 0.01,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 50,\n\t\t\tlightDistance: 25,\n\t\t\tlightHeight: 50,\n\t\t\tminDistance: 0.001,\n\t\t\tshadowSize: 100,\n\t\t\tscaleFactor: 1\n\t\t},\n\t\tinches: {\n\t\t\tcameraDistance: 15,\n\t\t\tnear: 0.1,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 80,\n\t\t\tlightDistance: 20,\n\t\t\tlightHeight: 40,\n\t\t\tminDistance: 0.1,\n\t\t\tshadowSize: 80,\n\t\t\tscaleFactor: 39.37\n\t\t},\n\t\tfeet: {\n\t\t\tcameraDistance: 8,\n\t\t\tnear: 0.1,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 40,\n\t\t\tlightDistance: 15,\n\t\t\tlightHeight: 30,\n\t\t\tminDistance: 0.1,\n\t\t\tshadowSize: 60,\n\t\t\tscaleFactor: 3.28084\n\t\t}\n\t};\n\n\tconst defaults = scaleDefaults[scale];\n\n\treturn {\n\t\tsceneScale: scale,\n\t\tcamera: {\n\t\t\tposition:\n\t\t\t\toptions.camera?.position ||\n\t\t\t\tnew THREE.Vector3(\n\t\t\t\t\t-defaults.cameraDistance,\n\t\t\t\t\tdefaults.cameraDistance,\n\t\t\t\t\tdefaults.cameraDistance\n\t\t\t\t),\n\t\t\tfov: options.camera?.fov || 20,\n\t\t\tnear: options.camera?.near || defaults.near,\n\t\t\tfar: options.camera?.far || defaults.far,\n\t\t\ttarget: options.camera?.target || new THREE.Vector3(0, 0, 0)\n\t\t},\n\t\tlighting: {\n\t\t\tenableSunlight: options.lighting?.enableSunlight ?? true,\n\t\t\tsunlightIntensity: options.lighting?.sunlightIntensity || 1,\n\t\t\tsunlightPosition:\n\t\t\t\toptions.lighting?.sunlightPosition ||\n\t\t\t\tnew THREE.Vector3(defaults.lightDistance, defaults.lightHeight, defaults.lightDistance),\n\t\t\tambientLightColor: options.lighting?.ambientLightColor || new THREE.Color(0x404040),\n\t\t\tambientLightIntensity: options.lighting?.ambientLightIntensity || 1,\n\t\t\tsunlightColor: options.lighting?.sunlightColor || 0xffffff // Default to white sunlight\n\t\t},\n\t\tenvironment: {\n\t\t\thdrPath: options.environment?.hdrPath || '/baseHDR.hdr',\n\t\t\tbackgroundColor: options.environment?.backgroundColor || new THREE.Color(0xf0f0f0),\n\t\t\tenableEnvironmentLighting: options.environment?.enableEnvironmentLighting ?? true,\n\t\t\tsceneUp: options.environment?.sceneUp || defaultUp,\n\t\t\tshowEnvironment: options.environment?.showEnvironment ?? false\n\t\t},\n\t\tfloor: {\n\t\t\tenabled: options.floor?.enabled ?? false,\n\t\t\tsize: options.floor?.size || defaults.floorSize,\n\t\t\tcolor: options.floor?.color || new THREE.Color(0x808080),\n\t\t\troughness: options.floor?.roughness || 0.7,\n\t\t\tmetalness: options.floor?.metalness || 0.0,\n\t\t\treceiveShadow: options.floor?.receiveShadow ?? true\n\t\t},\n\t\trender: {\n\t\t\tenableShadows: options.render?.enableShadows ?? true,\n\t\t\tshadowMapSize: options.render?.shadowMapSize || 2048,\n\t\t\tantialias: options.render?.antialias ?? true,\n\t\t\tpixelRatio: options.render?.pixelRatio || Math.min(window.devicePixelRatio, 2),\n\t\t\ttoneMapping: options.render?.toneMapping || THREE.NeutralToneMapping,\n\t\t\ttoneMappingExposure: options.render?.toneMappingExposure || 1,\n\t\t\tpreserveDrawingBuffer: options.render?.preserveDrawingBuffer ?? false\n\t\t},\n\t\tcontrols: {\n\t\t\tenableDamping: options.controls?.enableDamping ?? false,\n\t\t\tdampingFactor: options.controls?.dampingFactor || 0.05,\n\t\t\tautoRotate: options.controls?.autoRotate ?? false,\n\t\t\tautoRotateSpeed: options.controls?.autoRotateSpeed || 0.5,\n\t\t\tenableZoom: options.controls?.enableZoom ?? true,\n\t\t\tenablePan: options.controls?.enablePan ?? true,\n\t\t\tminDistance: options.controls?.minDistance || defaults.minDistance,\n\t\t\tmaxDistance: options.controls?.maxDistance || Infinity\n\t\t},\n\t\tevents: {\n\t\t\tonBackgroundClicked: options.events?.onBackgroundClicked,\n\t\t\tonObjectSelected: options.events?.onObjectSelected,\n\t\t\tonMeshMetadataClicked: options.events?.onMeshMetadataClicked,\n\t\t\tonMeshDoubleClicked: options.events?.onMeshDoubleClicked,\n\t\t\tselectionColor: options.events?.selectionColor || '#ff0000', // Default to red\n\t\t\tenableEventHandlers: options.events?.enableEventHandlers ?? true,\n\t\t\tenableKeyboardControls: options.events?.enableKeyboardControls ?? true,\n\t\t\tenableClickToFocus: options.events?.enableClickToFocus ?? true,\n\t\t\tenableDoubleClickZoom: options.events?.enableDoubleClickZoom ?? true,\n\t\t\tonReady: options.events?.onReady,\n\t\t\tonFrame: options.events?.onFrame\n\t\t}\n\t};\n}\n\nfunction createScene(config: Required<ThreeInitializerOptions>): THREE.Scene {\n\tconst scene = new THREE.Scene();\n\n\tconst bgColor =\n\t\ttypeof config.environment.backgroundColor === 'string'\n\t\t\t? new THREE.Color(config.environment.backgroundColor)\n\t\t\t: config.environment.backgroundColor;\n\tscene.background = bgColor || null;\n\n\treturn scene;\n}\n\nfunction animateCameraTo(\n\tcamera: THREE.PerspectiveCamera,\n\tcontrols: OrbitControls,\n\ttoPosition: THREE.Vector3,\n\ttoTarget: THREE.Vector3,\n\tdurationMs = 200\n): void {\n\tconst fromPosition = camera.position.clone();\n\tconst fromTarget = controls.target.clone();\n\tconst startTime = performance.now();\n\n\tconst easeOut = (t: number) => 1 - Math.pow(1 - t, 3);\n\n\tconst tick = () => {\n\t\tconst elapsed = performance.now() - startTime;\n\t\tconst t = easeOut(Math.min(elapsed / durationMs, 1));\n\n\t\tcamera.position.lerpVectors(fromPosition, toPosition, t);\n\t\tcontrols.target.lerpVectors(fromTarget, toTarget, t);\n\t\tcontrols.update();\n\n\t\tif (t < 1) requestAnimationFrame(tick);\n\t};\n\n\trequestAnimationFrame(tick);\n}\n\n// Resize applied before render so buffer clear and draw happen in the same frame,\n// preventing visible blank frames when the canvas is resized\nfunction createAnimationLoop(\n\trenderer: THREE.WebGLRenderer,\n\tscene: THREE.Scene,\n\tcamera: THREE.PerspectiveCamera,\n\tcontrols: OrbitControls,\n\tgetCanvasSize: () => { width: number; height: number },\n\tonFrame?: (delta: number) => void\n): { animate: () => void; dispose: () => void } {\n\tlet animationId: number | null = null;\n\tlet lastTime = performance.now();\n\n\tconst checkResize = () => {\n\t\tconst { width, height } = getCanvasSize();\n\t\tif (width === 0 || height === 0) return;\n\n\t\tconst pixelRatio = Math.min(window.devicePixelRatio, 2);\n\t\tconst newW = Math.round(width * pixelRatio);\n\t\tconst newH = Math.round(height * pixelRatio);\n\n\t\tif (renderer.domElement.width !== newW || renderer.domElement.height !== newH) {\n\t\t\trenderer.setPixelRatio(pixelRatio);\n\t\t\trenderer.setSize(width, height, false);\n\t\t\tcamera.aspect = width / height;\n\t\t\tcamera.updateProjectionMatrix();\n\t\t}\n\t};\n\n\tconst animate = function () {\n\t\tanimationId = requestAnimationFrame(animate);\n\n\t\tconst now = performance.now();\n\t\tconst delta = (now - lastTime) / 1000;\n\t\tlastTime = now;\n\n\t\tcheckResize();\n\n\t\tif (controls.enableDamping || controls.autoRotate) {\n\t\t\tcontrols.update();\n\t\t}\n\n\t\tonFrame?.(delta);\n\n\t\trenderer.render(scene, camera);\n\t};\n\n\tconst dispose = () => {\n\t\tif (animationId !== null) {\n\t\t\tcancelAnimationFrame(animationId);\n\t\t\tanimationId = null;\n\t\t}\n\t};\n\n\treturn { animate, dispose };\n}\n\nfunction setupEnvironment(scene: THREE.Scene, config: Required<ThreeInitializerOptions>) {\n\tif (config.environment.enableEnvironmentLighting) {\n\t\tnew HDRLoader().load(\n\t\t\tconfig.environment.hdrPath || '/baseHDR.hdr',\n\t\t\tfunction (envMap) {\n\t\t\t\tenvMap.mapping = THREE.EquirectangularReflectionMapping;\n\t\t\t\tscene.environment = envMap;\n\t\t\t\tif (config.environment.showEnvironment) {\n\t\t\t\t\tscene.background = envMap;\n\t\t\t\t}\n\t\t\t\tconfig.events.onReady?.();\n\t\t\t},\n\t\t\tundefined,\n\t\t\tfunction (error) {\n\t\t\t\tgetLogger().warn('HDR texture could not be loaded, falling back to basic lighting:', error);\n\t\t\t\tconfig.events.onReady?.();\n\t\t\t}\n\t\t);\n\t} else {\n\t\tconfig.events.onReady?.();\n\t}\n}\n\nfunction setupLighting(scene: THREE.Scene, config: Required<ThreeInitializerOptions>) {\n\tconst ambientLight = new THREE.AmbientLight(\n\t\tconfig.lighting.ambientLightColor,\n\t\tconfig.lighting.ambientLightIntensity\n\t);\n\tscene.add(ambientLight);\n\n\tif (config.lighting.enableSunlight) {\n\t\tconst sunlight = new THREE.DirectionalLight(\n\t\t\tconfig.lighting.sunlightColor ?? 0xffffff,\n\t\t\tconfig.lighting.sunlightIntensity\n\t\t);\n\t\tconst pos = config.lighting.sunlightPosition;\n\t\tif (pos) {\n\t\t\tsunlight.position.set(pos.x, pos.y, pos.z);\n\t\t}\n\n\t\tif (config.render.enableShadows) {\n\t\t\tsunlight.castShadow = true;\n\t\t\tconst shadowSize = getScaleValue(config.sceneScale, 0.1, 10, 100);\n\n\t\t\tsunlight.shadow.camera.left = -shadowSize;\n\t\t\tsunlight.shadow.camera.right = shadowSize;\n\t\t\tsunlight.shadow.camera.top = shadowSize;\n\t\t\tsunlight.shadow.camera.bottom = -shadowSize;\n\n\t\t\tconst shadowNear = getScaleValue(config.sceneScale, 0.001, 0.1, 0.5);\n\t\t\tconst shadowFar = getScaleValue(config.sceneScale, 1, 100, 500);\n\n\t\t\tsunlight.shadow.camera.near = shadowNear;\n\t\t\tsunlight.shadow.camera.far = shadowFar;\n\n\t\t\tsunlight.shadow.mapSize.width = config.render.shadowMapSize || 2048;\n\t\t\tsunlight.shadow.mapSize.height = config.render.shadowMapSize || 2048;\n\n\t\t\tsunlight.shadow.bias = -0.0001;\n\t\t\tsunlight.shadow.normalBias = 0.02;\n\t\t}\n\n\t\tscene.add(sunlight);\n\t}\n}\n\nfunction addFloor(scene: THREE.Scene, config: Required<ThreeInitializerOptions>) {\n\tconst floorSize = config.floor.size;\n\tconst floorGeometry = new THREE.PlaneGeometry(floorSize, floorSize);\n\n\tconst floorColor =\n\t\ttypeof config.floor.color === 'string'\n\t\t\t? new THREE.Color(config.floor.color)\n\t\t\t: config.floor.color;\n\n\tconst floorMaterial = new THREE.MeshStandardMaterial({\n\t\tcolor: floorColor,\n\t\troughness: config.floor.roughness,\n\t\tmetalness: config.floor.metalness,\n\t\tside: THREE.DoubleSide\n\t});\n\n\tconst floor = new THREE.Mesh(floorGeometry, floorMaterial);\n\tfloor.userData.id = 'floor';\n\tfloor.name = 'floor';\n\tfloor.rotation.x = -Math.PI / 2;\n\tfloor.position.y = 0;\n\n\tif (config.floor.receiveShadow && config.render.enableShadows) {\n\t\tfloor.receiveShadow = true;\n\t}\n\n\tscene.add(floor);\n}\n\nfunction createCamera(\n\tconfig: Required<ThreeInitializerOptions>,\n\tcanvas: HTMLCanvasElement\n): THREE.PerspectiveCamera {\n\tconst parent = canvas.parentElement;\n\tconst width = parent ? parent.clientWidth : window.innerWidth;\n\tconst height = parent ? parent.clientHeight : window.innerHeight;\n\n\tconst camera = new THREE.PerspectiveCamera(\n\t\tconfig.camera.fov,\n\t\twidth / height,\n\t\tconfig.camera.near,\n\t\tconfig.camera.far\n\t);\n\n\tconst pos = config.camera.position;\n\tif (pos) {\n\t\tcamera.position.set(pos.x, pos.y, pos.z);\n\t}\n\n\treturn camera;\n}\n\n// Logarithmic depth buffer improves depth precision for mixed scales (mm to km)\nfunction setupRenderer(\n\tcanvas: HTMLCanvasElement,\n\tconfig: Required<ThreeInitializerOptions>\n): THREE.WebGLRenderer {\n\tconst renderer = new THREE.WebGLRenderer({\n\t\tantialias: config.render.antialias,\n\t\tcanvas,\n\t\talpha: true,\n\t\tpowerPreference: 'high-performance',\n\t\tpreserveDrawingBuffer: config.render.preserveDrawingBuffer,\n\t\tlogarithmicDepthBuffer: true\n\t});\n\n\tconst parent = canvas.parentElement;\n\tconst width = parent ? parent.clientWidth : window.innerWidth;\n\tconst height = parent ? parent.clientHeight : window.innerHeight;\n\n\tif (parent) {\n\t\tcanvas.style.width = '100%';\n\t\tcanvas.style.height = '100%';\n\t\tcanvas.style.display = 'block';\n\t}\n\n\trenderer.setSize(width, height, false);\n\trenderer.setPixelRatio(config.render.pixelRatio || Math.min(window.devicePixelRatio, 2));\n\n\tif (config.render.enableShadows) {\n\t\trenderer.shadowMap.enabled = true;\n\t\trenderer.shadowMap.type = THREE.VSMShadowMap;\n\t}\n\n\trenderer.toneMapping = config.render.toneMapping!;\n\trenderer.toneMappingExposure = config.render.toneMappingExposure || 1.0;\n\trenderer.outputColorSpace = THREE.SRGBColorSpace;\n\n\trenderer.sortObjects = true;\n\n\treturn renderer;\n}\n\nfunction setupEventHandlers(\n\tcanvas: HTMLCanvasElement,\n\tscene: THREE.Scene,\n\tcamera: THREE.PerspectiveCamera,\n\tcontrols: OrbitControls,\n\tconfig: Required<ThreeInitializerOptions>\n): {\n\tdispose: () => void;\n\tfitToView: () => void;\n\tclearSelection: () => void;\n} {\n\tconst selectedObjects = new Set<THREE.Object3D>();\n\tconst originalMaterials = new Map<THREE.Object3D, THREE.Material | THREE.Material[]>();\n\tconst raycaster = new THREE.Raycaster();\n\tconst mouse = new THREE.Vector2();\n\tconst mouseDownPosition = new THREE.Vector2();\n\n\t// An object is hittable only if every ancestor is also visible. Three.js's\n\t// recursive intersect doesn't enforce that — it can hit a visible Mesh inside\n\t// a hidden Group.\n\tconst isFullyVisible = (object: THREE.Object3D): boolean => {\n\t\tlet current: THREE.Object3D | null = object;\n\t\twhile (current) {\n\t\t\tif (!current.visible) return false;\n\t\t\tcurrent = current.parent;\n\t\t}\n\t\treturn true;\n\t};\n\n\tconst fitToView = () => {\n\t\tconst box = new THREE.Box3();\n\n\t\tscene.traverse((object) => {\n\t\t\tif (object.visible && object.userData.id !== 'floor' && object instanceof THREE.Mesh) {\n\t\t\t\tbox.expandByObject(object);\n\t\t\t}\n\t\t});\n\n\t\tif (box.isEmpty()) {\n\t\t\tgetLogger().warn('No objects to fit to view');\n\t\t\treturn;\n\t\t}\n\n\t\tconst center = box.getCenter(new THREE.Vector3());\n\t\tconst size = box.getSize(new THREE.Vector3());\n\n\t\tconst maxDim = Math.max(size.x, size.y, size.z);\n\t\tconst fov = camera.fov * (Math.PI / 180);\n\t\tlet distance = maxDim / (2 * Math.tan(fov / 2));\n\n\t\tdistance *= 1.5;\n\n\t\tconst direction = camera.position.clone().sub(controls.target).normalize();\n\t\tcamera.position.copy(center.clone().add(direction.multiplyScalar(distance)));\n\n\t\tcontrols.target.copy(center);\n\t\tcontrols.update();\n\t};\n\n\tconst selectionColorObj =\n\t\ttypeof config.events.selectionColor === 'string'\n\t\t\t? new THREE.Color(config.events.selectionColor)\n\t\t\t: config.events.selectionColor instanceof THREE.Color\n\t\t\t\t? config.events.selectionColor\n\t\t\t\t: new THREE.Color('#ff0000');\n\n\tconst clearSelection = () => {\n\t\tselectedObjects.forEach((obj) => {\n\t\t\tif (obj instanceof THREE.Mesh && originalMaterials.has(obj)) {\n\t\t\t\tobj.material = originalMaterials.get(obj)!;\n\t\t\t\toriginalMaterials.delete(obj);\n\t\t\t}\n\t\t});\n\t\tselectedObjects.clear();\n\t};\n\n\tconst handleMouseDown = (event: MouseEvent) => {\n\t\tmouseDownPosition.set(event.clientX, event.clientY);\n\t};\n\n\tconst handleCanvasClick = (event: MouseEvent) => {\n\t\t// Ignore if mouse has moved (drag)\n\t\tconst currentMousePosition = new THREE.Vector2(event.clientX, event.clientY);\n\t\tif (mouseDownPosition.distanceTo(currentMousePosition) > 5) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst rect = canvas.getBoundingClientRect();\n\t\tmouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;\n\t\tmouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;\n\n\t\traycaster.setFromCamera(mouse, camera);\n\t\tconst intersects = raycaster\n\t\t\t.intersectObjects(scene.children, true)\n\t\t\t.filter((i) => isFullyVisible(i.object));\n\n\t\tif (intersects.length > 0) {\n\t\t\tconst clickedObject = intersects[0].object;\n\n\t\t\tif (!selectedObjects.has(clickedObject)) {\n\t\t\t\tclearSelection();\n\t\t\t\tselectedObjects.add(clickedObject);\n\n\t\t\t\t// Clone material so we don't affect other meshes\n\t\t\t\tif (\n\t\t\t\t\tclickedObject instanceof THREE.Mesh &&\n\t\t\t\t\tclickedObject.material instanceof THREE.Material\n\t\t\t\t) {\n\t\t\t\t\toriginalMaterials.set(clickedObject, clickedObject.material);\n\n\t\t\t\t\tconst clonedMaterial = clickedObject.material.clone();\n\t\t\t\t\t(clonedMaterial as any).emissive = selectionColorObj.clone();\n\t\t\t\t\tclickedObject.material = clonedMaterial;\n\t\t\t\t}\n\n\t\t\t\tconfig.events?.onObjectSelected?.(clickedObject);\n\n\t\t\t\tif (clickedObject instanceof THREE.Mesh && Object.keys(clickedObject.userData).length > 0) {\n\t\t\t\t\tconfig.events?.onMeshMetadataClicked?.(clickedObject.userData);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tclearSelection();\n\t\t\tconfig.events?.onBackgroundClicked?.({ x: mouse.x, y: mouse.y });\n\t\t}\n\t};\n\n\tconst handleDoubleClick = (event: MouseEvent) => {\n\t\tconst rect = canvas.getBoundingClientRect();\n\t\tmouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;\n\t\tmouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;\n\n\t\traycaster.setFromCamera(mouse, camera);\n\t\tconst intersects = raycaster\n\t\t\t.intersectObjects(scene.children, true)\n\t\t\t.filter((i) => isFullyVisible(i.object));\n\n\t\tif (intersects.length === 0) return;\n\n\t\tconst target = intersects[0].object;\n\t\tconfig.events?.onMeshDoubleClicked?.(target);\n\n\t\tif (!config.events?.enableDoubleClickZoom) return;\n\n\t\tconst box = new THREE.Box3().setFromObject(target);\n\t\tif (box.isEmpty()) return;\n\n\t\tconst center = box.getCenter(new THREE.Vector3());\n\t\tconst size = box.getSize(new THREE.Vector3());\n\t\tconst maxDim = Math.max(size.x, size.y, size.z);\n\t\tconst fov = camera.fov * (Math.PI / 180);\n\t\tconst distance = (maxDim / (2 * Math.tan(fov / 2))) * 1.5;\n\n\t\tconst direction = camera.position.clone().sub(controls.target).normalize();\n\t\tconst targetPosition = center.clone().add(direction.multiplyScalar(distance));\n\n\t\tanimateCameraTo(camera, controls, targetPosition, center);\n\t};\n\n\tconst handleKeydown = (event: KeyboardEvent) => {\n\t\tif (!config.events?.enableKeyboardControls) return;\n\n\t\tswitch (event.key.toLowerCase()) {\n\t\t\tcase 'f':\n\t\t\t\tevent.preventDefault();\n\t\t\t\tfitToView();\n\t\t\t\tbreak;\n\t\t\tcase 'escape':\n\t\t\t\tevent.preventDefault();\n\t\t\t\tclearSelection();\n\t\t\t\tbreak;\n\t\t\tcase ' ':\n\t\t\t\tevent.preventDefault();\n\t\t\t\tfitToView();\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\tif (config.events?.enableClickToFocus) {\n\t\tcanvas.addEventListener('mousedown', handleMouseDown);\n\t\tcanvas.addEventListener('click', handleCanvasClick);\n\t\tcanvas.addEventListener('dblclick', handleDoubleClick);\n\t}\n\n\tif (config.events?.enableKeyboardControls) {\n\t\tcanvas.setAttribute('tabindex', '0');\n\t\tcanvas.addEventListener('keydown', handleKeydown);\n\t}\n\n\tconst dispose = () => {\n\t\tcanvas.removeEventListener('mousedown', handleMouseDown);\n\t\tcanvas.removeEventListener('click', handleCanvasClick);\n\t\tcanvas.removeEventListener('dblclick', handleDoubleClick);\n\t\tcanvas.removeEventListener('keydown', handleKeydown);\n\t\tclearSelection();\n\t};\n\n\treturn { dispose, fitToView, clearSelection };\n}\n\nfunction setupControls(\n\tcamera: THREE.PerspectiveCamera,\n\tcanvas: HTMLCanvasElement,\n\tconfig: Required<ThreeInitializerOptions>\n): OrbitControls {\n\tconst controls = new OrbitControls(camera, canvas);\n\n\tconst target = config.camera.target;\n\tif (target) {\n\t\tcontrols.target.set(target.x, target.y, target.z);\n\t}\n\n\tcontrols.enableDamping = config.controls.enableDamping || false;\n\tcontrols.dampingFactor = config.controls.dampingFactor || 0.05;\n\n\tcontrols.autoRotate = config.controls.autoRotate || false;\n\tcontrols.autoRotateSpeed = config.controls.autoRotateSpeed || 0.5;\n\n\tcontrols.enableZoom = config.controls.enableZoom ?? true;\n\tcontrols.enablePan = config.controls.enablePan ?? true;\n\tcontrols.minDistance = config.controls.minDistance || 0.001;\n\tcontrols.maxDistance = config.controls.maxDistance || Infinity;\n\n\tcontrols.screenSpacePanning = false;\n\tcontrols.maxPolarAngle = Math.PI;\n\n\tcontrols.update();\n\treturn controls;\n}\n","import * as THREE from 'three';\nimport { OrbitControls } from 'three/addons/controls/OrbitControls.js';\nimport { getLogger } from '@/core';\n\n// Camera configuration constants\nconst CAMERA_CONFIG = {\n\tHUGE_THRESHOLD: 10000,\n\tLARGE_THRESHOLD: 1000,\n\tSCALE_RATIO_THRESHOLD: 100,\n\tNEAR_PLANE_FACTOR: {\n\t\tTINY: 0.0001,\n\t\tSMALL: 0.001,\n\t\tNORMAL: 0.01\n\t},\n\tFAR_PLANE_FACTOR: {\n\t\tHUGE: 100,\n\t\tLARGE: 50,\n\t\tNORMAL: 20\n\t},\n\tINITIAL_DISTANCE_MULTIPLIER: 4\n};\n\n/**\n * Updates the scene with the given meshes and camera settings.\n * If initialPositionSet is false, it positions the camera and sets the controls target based on the bounding boxes of the meshes.\n * @param scene - The THREE.Scene object to update.\n * @param meshes - An array of THREE.Mesh objects to add to the scene.\n * @param camera - The THREE.PerspectiveCamera object to position.\n * @param controls - The OrbitControls object to update.\n * @param initialPositionSet - A boolean indicating whether the initial position of the camera and controls have been set.\n */\nexport function updateScene(\n\tscene: THREE.Scene,\n\tmeshes: THREE.Mesh[],\n\tcamera: THREE.PerspectiveCamera,\n\tcontrols: OrbitControls,\n\tinitialPositionSet: boolean\n) {\n\tclearScene(scene);\n\n\tif (meshes.length === 0) return;\n\n\t// Add new meshes to scene\n\tmeshes.forEach((mesh) => {\n\t\tscene.add(mesh);\n\t});\n\n\t// Calculate bounds of the new content\n\tconst unionBoundingBox = computeCombinedBoundingBox(meshes);\n\n\t// Get the center of the union bounding box\n\tconst center = unionBoundingBox.getCenter(new THREE.Vector3());\n\tconst size = unionBoundingBox.getSize(new THREE.Vector3());\n\n\t// Calculate a distance that is slightly larger than the largest dimension of the union bounding box\n\tconst maxDim = Math.max(size.x, size.y, size.z);\n\n\t// Always update camera frustum to ensure geometry is visible\n\t// This prevents clipping when geometry size changes significantly\n\tconst scaleRatio = maxDim / Math.min(size.x || 1, size.y || 1, size.z || 1);\n\n\tif (scaleRatio > CAMERA_CONFIG.SCALE_RATIO_THRESHOLD || maxDim > CAMERA_CONFIG.HUGE_THRESHOLD) {\n\t\t// Large scale range detected - use logarithmic depth buffer approach\n\t\tcamera.near = maxDim * CAMERA_CONFIG.NEAR_PLANE_FACTOR.TINY;\n\t\tcamera.far = maxDim * CAMERA_CONFIG.FAR_PLANE_FACTOR.HUGE;\n\t} else if (maxDim > CAMERA_CONFIG.LARGE_THRESHOLD) {\n\t\t// Large scene\n\t\tcamera.near = maxDim * CAMERA_CONFIG.NEAR_PLANE_FACTOR.SMALL;\n\t\tcamera.far = maxDim * CAMERA_CONFIG.FAR_PLANE_FACTOR.LARGE;\n\t} else {\n\t\t// Normal scene\n\t\tcamera.near = Math.max(0.01, maxDim * CAMERA_CONFIG.NEAR_PLANE_FACTOR.NORMAL);\n\t\tcamera.far = Math.max(2000, maxDim * CAMERA_CONFIG.FAR_PLANE_FACTOR.NORMAL);\n\t}\n\n\tcamera.updateProjectionMatrix();\n\n\t// Only reposition camera and controls on first frame\n\tif (!initialPositionSet) {\n\t\tconst distance = maxDim * CAMERA_CONFIG.INITIAL_DISTANCE_MULTIPLIER;\n\n\t\tcamera.position.set(center.x + distance * 0.8, center.y + distance, center.z + distance * 1.2);\n\t\tcontrols.target.copy(center);\n\t\tcontrols.minDistance = camera.near * 2;\n\t\tcontrols.maxDistance = camera.far * 0.9;\n\n\t\tcontrols.update();\n\t} else {\n\t\t// Update control constraints to match new frustum\n\t\tcontrols.minDistance = camera.near * 2;\n\t\tcontrols.maxDistance = camera.far * 0.9;\n\t}\n}\n\n// =========================\n// Helper functions\n// =========================\n\n/**\n * Parses a color string in multiple formats to a THREE.Color object.\n * Supported formats:\n * - Hex: \"#C7A5A5\", \"C7A5A5\"\n * - RGB: \"199, 165, 165\"\n * - CSS named colors: \"red\", \"blue\", etc.\n * @param colorString - The color string to parse.\n * @returns A THREE.Color object.\n */\nexport function parseColor(colorString: string): THREE.Color {\n\tif (!colorString || typeof colorString !== 'string') {\n\t\tgetLogger().warn(`Invalid color input: ${colorString}, using white`);\n\t\treturn new THREE.Color(0xffffff);\n\t}\n\n\tconst trimmed = colorString.trim();\n\n\t// Try hex format (#C7A5A5 or C7A5A5) — require exactly 6 hex chars\n\tif (/^#?[0-9A-Fa-f]{6}$/.test(trimmed)) {\n\t\ttry {\n\t\t\tconst hex = trimmed.startsWith('#') ? trimmed : `#${trimmed}`;\n\t\t\treturn new THREE.Color(hex);\n\t\t} catch {\n\t\t\tgetLogger().warn(`Invalid hex color: ${colorString}, using white`);\n\t\t\treturn new THREE.Color(0xffffff);\n\t\t}\n\t}\n\n\t// Try RGB format (R, G, B)\n\tif (trimmed.includes(',')) {\n\t\tconst rgb = trimmed.split(',').map((c) => parseInt(c.trim(), 10));\n\t\tif (rgb.length === 3 && rgb.every((n) => !isNaN(n) && n >= 0 && n <= 255)) {\n\t\t\treturn new THREE.Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255);\n\t\t}\n\t}\n\n\t// Try CSS named color\n\ttry {\n\t\treturn new THREE.Color(trimmed.toLowerCase());\n\t} catch {\n\t\tgetLogger().warn(`Invalid color string: ${colorString}, using white`);\n\t\treturn new THREE.Color(0xffffff);\n\t}\n}\n\nexport function applyOffset(meshes: THREE.Mesh[], offsetY: number): void {\n\tmeshes.forEach((mesh) => {\n\t\tmesh.position.y -= offsetY;\n\t});\n}\n\n/**\n * Computes the combined world-axis-aligned bounding box of a set of meshes.\n * Correctly accounts for mesh transformations (rotation, position, scale).\n */\nexport function computeCombinedBoundingBox(meshes: THREE.Mesh[]): THREE.Box3 {\n\tconst combinedBoundingBox = new THREE.Box3();\n\tif (meshes.length === 0) return combinedBoundingBox;\n\tmeshes.forEach((mesh) => {\n\t\t// Ensure the world matrix is up to date before calculating the box\n\t\tmesh.updateMatrixWorld(true);\n\t\tconst bbox = new THREE.Box3().setFromObject(mesh);\n\t\tcombinedBoundingBox.union(bbox);\n\t});\n\treturn combinedBoundingBox;\n}\n\n/**\n * Clears the given THREE.Scene by removing all non-floor top-level children and\n * recursively disposing of their geometry and materials.\n *\n * Removes at the top level rather than traversing for meshes, so parent Groups\n * don't accumulate as ghost nodes after their mesh children are disposed.\n */\nfunction clearScene(scene: THREE.Scene): void {\n\t// Snapshot children — we mutate the array via removeFromParent during iteration\n\tconst topLevel = [...scene.children];\n\n\ttopLevel.forEach((object) => {\n\t\tif (object.userData.id === 'floor') return;\n\n\t\t// Recursively dispose all meshes in this subtree\n\t\tobject.traverse((child) => {\n\t\t\tif (!(child instanceof THREE.Mesh)) return;\n\n\t\t\tchild.geometry?.dispose();\n\n\t\t\tconst materials = Array.isArray(child.material) ? child.material : [child.material];\n\t\t\tmaterials.forEach((material) => {\n\t\t\t\t// Walk only own enumerable properties — `for...in` on a Three.js material\n\t\t\t\t// also iterates the prototype chain, which is needlessly expensive.\n\t\t\t\tfor (const value of Object.values(material)) {\n\t\t\t\t\tif (value instanceof THREE.Texture) {\n\t\t\t\t\t\tvalue.dispose();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmaterial.dispose();\n\t\t\t});\n\t\t});\n\n\t\tobject.removeFromParent();\n\t});\n}\n"]}
@@ -1,2 +0,0 @@
1
- import{a as te,c as D,d as F,e as y,o as U}from"./chunk-GTTKNF4G.js";import*as i from"three";import{OrbitControls as ne}from"three/addons/controls/OrbitControls.js";import{HDRLoader as re}from"three/addons/loaders/HDRLoader.js";var V=new i.Vector3(0,0,1),P=(e,r,n,t)=>{switch(e){case"mm":return r;case"cm":return n;default:return t}},Ze=function(e,r){let n=oe(r||{}),t=ae(n),o=de(n,e),s=me(e,n),a=he(o,e,n);ce(t,n),le(t,n),n.floor?.enabled&&ue(t,n);let u=n.events.enableEventHandlers!==!1?fe(e,t,o,a,n):{dispose:()=>{},fitToView:()=>{},clearSelection:()=>{}},c=e.parentElement,h=()=>c?{width:c.clientWidth,height:c.clientHeight}:{width:window.innerWidth,height:window.innerHeight},{animate:m,dispose:l}=ie(s,t,o,a,h,n.events.onFrame);m();let E=n.environment?.sceneUp||V;return t.up.set(E.x,E.y,E.z),{scene:t,camera:o,controls:a,renderer:s,dispose:()=>{l(),u.dispose(),a.dispose(),s.dispose(),t.traverse(d=>{d instanceof i.Mesh&&(d.geometry?.dispose(),Array.isArray(d.material)?d.material.forEach(H=>H.dispose()):d.material?.dispose())})},fitToView:u.fitToView,clearSelection:u.clearSelection}};function oe(e){let r=e.sceneScale||"m",t={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 i.Vector3(-t.cameraDistance,t.cameraDistance,t.cameraDistance),fov:e.camera?.fov||20,near:e.camera?.near||t.near,far:e.camera?.far||t.far,target:e.camera?.target||new i.Vector3(0,0,0)},lighting:{enableSunlight:e.lighting?.enableSunlight??!0,sunlightIntensity:e.lighting?.sunlightIntensity||1,sunlightPosition:e.lighting?.sunlightPosition||new i.Vector3(t.lightDistance,t.lightHeight,t.lightDistance),ambientLightColor:e.lighting?.ambientLightColor||new i.Color(4210752),ambientLightIntensity:e.lighting?.ambientLightIntensity||1,sunlightColor:e.lighting?.sunlightColor||16777215},environment:{hdrPath:e.environment?.hdrPath||"/baseHDR.hdr",backgroundColor:e.environment?.backgroundColor||new i.Color(15790320),enableEnvironmentLighting:e.environment?.enableEnvironmentLighting??!0,sceneUp:e.environment?.sceneUp||V,showEnvironment:e.environment?.showEnvironment??!1},floor:{enabled:e.floor?.enabled??!1,size:e.floor?.size||t.floorSize,color:e.floor?.color||new i.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||i.NeutralToneMapping,toneMappingExposure:e.render?.toneMappingExposure||1,preserveDrawingBuffer:e.render?.preserveDrawingBuffer??!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||t.minDistance,maxDistance:e.controls?.maxDistance||1/0},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 ae(e){let r=new i.Scene,n=typeof e.environment.backgroundColor=="string"?new i.Color(e.environment.backgroundColor):e.environment.backgroundColor;return r.background=n||null,r}function se(e,r,n,t,o=200){let s=e.position.clone(),a=r.target.clone(),u=performance.now(),c=m=>1-Math.pow(1-m,3),h=()=>{let m=performance.now()-u,l=c(Math.min(m/o,1));e.position.lerpVectors(s,n,l),r.target.lerpVectors(a,t,l),r.update(),l<1&&requestAnimationFrame(h)};requestAnimationFrame(h)}function ie(e,r,n,t,o,s){let a=null,u=performance.now(),c=()=>{let{width:l,height:E}=o();if(l===0||E===0)return;let g=Math.min(window.devicePixelRatio,2),d=Math.round(l*g),H=Math.round(E*g);(e.domElement.width!==d||e.domElement.height!==H)&&(e.setPixelRatio(g),e.setSize(l,E,!1),n.aspect=l/E,n.updateProjectionMatrix())},h=function(){a=requestAnimationFrame(h);let l=performance.now(),E=(l-u)/1e3;u=l,c(),(t.enableDamping||t.autoRotate)&&t.update(),s?.(E),e.render(r,n)};return{animate:h,dispose:()=>{a!==null&&(cancelAnimationFrame(a),a=null)}}}function ce(e,r){r.environment.enableEnvironmentLighting?new re().load(r.environment.hdrPath||"/baseHDR.hdr",function(n){n.mapping=i.EquirectangularReflectionMapping,e.environment=n,r.environment.showEnvironment&&(e.background=n),r.events.onReady?.()},void 0,function(n){y().warn("HDR texture could not be loaded, falling back to basic lighting:",n),r.events.onReady?.()}):r.events.onReady?.()}function le(e,r){let n=new i.AmbientLight(r.lighting.ambientLightColor,r.lighting.ambientLightIntensity);if(e.add(n),r.lighting.enableSunlight){let t=new i.DirectionalLight(r.lighting.sunlightColor??16777215,r.lighting.sunlightIntensity),o=r.lighting.sunlightPosition;if(o&&t.position.set(o.x,o.y,o.z),r.render.enableShadows){t.castShadow=!0;let s=P(r.sceneScale,.1,10,100);t.shadow.camera.left=-s,t.shadow.camera.right=s,t.shadow.camera.top=s,t.shadow.camera.bottom=-s;let a=P(r.sceneScale,.001,.1,.5),u=P(r.sceneScale,1,100,500);t.shadow.camera.near=a,t.shadow.camera.far=u,t.shadow.mapSize.width=r.render.shadowMapSize||2048,t.shadow.mapSize.height=r.render.shadowMapSize||2048,t.shadow.bias=-1e-4,t.shadow.normalBias=.02}e.add(t)}}function ue(e,r){let n=r.floor.size,t=new i.PlaneGeometry(n,n),o=typeof r.floor.color=="string"?new i.Color(r.floor.color):r.floor.color,s=new i.MeshStandardMaterial({color:o,roughness:r.floor.roughness,metalness:r.floor.metalness,side:i.DoubleSide}),a=new i.Mesh(t,s);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 de(e,r){let n=r.parentElement,t=n?n.clientWidth:window.innerWidth,o=n?n.clientHeight:window.innerHeight,s=new i.PerspectiveCamera(e.camera.fov,t/o,e.camera.near,e.camera.far),a=e.camera.position;return a&&s.position.set(a.x,a.y,a.z),s}function me(e,r){let n=new i.WebGLRenderer({antialias:r.render.antialias,canvas:e,alpha:!0,powerPreference:"high-performance",preserveDrawingBuffer:r.render.preserveDrawingBuffer,logarithmicDepthBuffer:!0}),t=e.parentElement,o=t?t.clientWidth:window.innerWidth,s=t?t.clientHeight:window.innerHeight;return t&&(e.style.width="100%",e.style.height="100%",e.style.display="block"),n.setSize(o,s,!1),n.setPixelRatio(r.render.pixelRatio||Math.min(window.devicePixelRatio,2)),r.render.enableShadows&&(n.shadowMap.enabled=!0,n.shadowMap.type=i.VSMShadowMap),n.toneMapping=r.render.toneMapping,n.toneMappingExposure=r.render.toneMappingExposure||1,n.outputColorSpace=i.SRGBColorSpace,n.sortObjects=!0,n}function fe(e,r,n,t,o){let s=new Set,a=new Map,u=new i.Raycaster,c=new i.Vector2,h=new i.Vector2,m=f=>{let p=f;for(;p;){if(!p.visible)return!1;p=p.parent}return!0},l=()=>{let f=new i.Box3;if(r.traverse(A=>{A.visible&&A.userData.id!=="floor"&&A instanceof i.Mesh&&f.expandByObject(A)}),f.isEmpty()){y().warn("No objects to fit to view");return}let p=f.getCenter(new i.Vector3),T=f.getSize(new i.Vector3),v=Math.max(T.x,T.y,T.z),R=n.fov*(Math.PI/180),S=v/(2*Math.tan(R/2));S*=1.5;let O=n.position.clone().sub(t.target).normalize();n.position.copy(p.clone().add(O.multiplyScalar(S))),t.target.copy(p),t.update()},E=typeof o.events.selectionColor=="string"?new i.Color(o.events.selectionColor):o.events.selectionColor instanceof i.Color?o.events.selectionColor:new i.Color("#ff0000"),g=()=>{s.forEach(f=>{f instanceof i.Mesh&&a.has(f)&&(f.material=a.get(f),a.delete(f))}),s.clear()},d=f=>{h.set(f.clientX,f.clientY)},H=f=>{let p=new i.Vector2(f.clientX,f.clientY);if(h.distanceTo(p)>5)return;let T=e.getBoundingClientRect();c.x=(f.clientX-T.left)/T.width*2-1,c.y=-((f.clientY-T.top)/T.height)*2+1,u.setFromCamera(c,n);let v=u.intersectObjects(r.children,!0).filter(R=>m(R.object));if(v.length>0){let R=v[0].object;if(!s.has(R)){if(g(),s.add(R),R instanceof i.Mesh&&R.material instanceof i.Material){a.set(R,R.material);let S=R.material.clone();S.emissive=E.clone(),R.material=S}o.events?.onObjectSelected?.(R),R instanceof i.Mesh&&Object.keys(R.userData).length>0&&o.events?.onMeshMetadataClicked?.(R.userData)}}else g(),o.events?.onBackgroundClicked?.({x:c.x,y:c.y})},L=f=>{let p=e.getBoundingClientRect();c.x=(f.clientX-p.left)/p.width*2-1,c.y=-((f.clientY-p.top)/p.height)*2+1,u.setFromCamera(c,n);let T=u.intersectObjects(r.children,!0).filter(ee=>m(ee.object));if(T.length===0)return;let v=T[0].object;if(o.events?.onMeshDoubleClicked?.(v),!o.events?.enableDoubleClickZoom)return;let R=new i.Box3().setFromObject(v);if(R.isEmpty())return;let S=R.getCenter(new i.Vector3),O=R.getSize(new i.Vector3),A=Math.max(O.x,O.y,O.z),K=n.fov*(Math.PI/180),X=A/(2*Math.tan(K/2))*1.5,J=n.position.clone().sub(t.target).normalize(),Q=S.clone().add(J.multiplyScalar(X));se(n,t,Q,S)},x=f=>{if(o.events?.enableKeyboardControls)switch(f.key.toLowerCase()){case"f":f.preventDefault(),l();break;case"escape":f.preventDefault(),g();break;case" ":f.preventDefault(),l();break}};return o.events?.enableClickToFocus&&(e.addEventListener("mousedown",d),e.addEventListener("click",H),e.addEventListener("dblclick",L)),o.events?.enableKeyboardControls&&(e.setAttribute("tabindex","0"),e.addEventListener("keydown",x)),{dispose:()=>{e.removeEventListener("mousedown",d),e.removeEventListener("click",H),e.removeEventListener("dblclick",L),e.removeEventListener("keydown",x),g()},fitToView:l,clearSelection:g}}function he(e,r,n){let t=new ne(e,r),o=n.camera.target;return o&&t.target.set(o.x,o.y,o.z),t.enableDamping=n.controls.enableDamping||!1,t.dampingFactor=n.controls.dampingFactor||.05,t.autoRotate=n.controls.autoRotate||!1,t.autoRotateSpeed=n.controls.autoRotateSpeed||.5,t.enableZoom=n.controls.enableZoom??!0,t.enablePan=n.controls.enablePan??!0,t.minDistance=n.controls.minDistance||.001,t.maxDistance=n.controls.maxDistance||1/0,t.screenSpacePanning=!1,t.maxPolarAngle=Math.PI,t.update(),t}import*as w from"three";var B={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 Xe(e,r,n,t,o){if(Ee(e),r.length===0)return;r.forEach(m=>{e.add(m)});let s=z(r),a=s.getCenter(new w.Vector3),u=s.getSize(new w.Vector3),c=Math.max(u.x,u.y,u.z);if(c/Math.min(u.x||1,u.y||1,u.z||1)>B.SCALE_RATIO_THRESHOLD||c>B.HUGE_THRESHOLD?(n.near=c*B.NEAR_PLANE_FACTOR.TINY,n.far=c*B.FAR_PLANE_FACTOR.HUGE):c>B.LARGE_THRESHOLD?(n.near=c*B.NEAR_PLANE_FACTOR.SMALL,n.far=c*B.FAR_PLANE_FACTOR.LARGE):(n.near=Math.max(.01,c*B.NEAR_PLANE_FACTOR.NORMAL),n.far=Math.max(2e3,c*B.FAR_PLANE_FACTOR.NORMAL)),n.updateProjectionMatrix(),o)t.minDistance=n.near*2,t.maxDistance=n.far*.9;else{let m=c*B.INITIAL_DISTANCE_MULTIPLIER;n.position.set(a.x+m*.8,a.y+m,a.z+m*1.2),t.target.copy(a),t.minDistance=n.near*2,t.maxDistance=n.far*.9,t.update()}}function N(e){if(!e||typeof e!="string")return y().warn(`Invalid color input: ${e}, using white`),new w.Color(16777215);let r=e.trim();if(/^#?[0-9A-Fa-f]{6}$/.test(r))try{let n=r.startsWith("#")?r:`#${r}`;return new w.Color(n)}catch{return y().warn(`Invalid hex color: ${e}, using white`),new w.Color(16777215)}if(r.includes(",")){let n=r.split(",").map(t=>parseInt(t.trim(),10));if(n.length===3&&n.every(t=>!isNaN(t)&&t>=0&&t<=255))return new w.Color(n[0]/255,n[1]/255,n[2]/255)}try{return new w.Color(r.toLowerCase())}catch{return y().warn(`Invalid color string: ${e}, using white`),new w.Color(16777215)}}function G(e,r){e.forEach(n=>{n.position.y-=r})}function z(e){let r=new w.Box3;return e.length===0||e.forEach(n=>{n.updateMatrixWorld(!0);let t=new w.Box3().setFromObject(n);r.union(t)}),r}function Ee(e){[...e.children].forEach(n=>{n.userData.id!=="floor"&&(n.traverse(t=>{if(!(t instanceof w.Mesh))return;t.geometry?.dispose(),(Array.isArray(t.material)?t.material:[t.material]).forEach(s=>{for(let a of Object.values(s))a instanceof w.Texture&&a.dispose();s.dispose()})}),n.removeFromParent())})}var Me={};te(Me,{CONCRETE_MATERIAL:()=>ye,EMISSIVE_MATERIAL:()=>pe,GLASS_MATERIAL:()=>Re,METAL_MATERIAL:()=>ge,PLASTIC_MATERIAL:()=>be,RUBBER_MATERIAL:()=>Te,WOOD_MATERIAL:()=>we});import*as b from"three";var pe=new b.MeshPhysicalMaterial({color:0,emissive:new b.Color(16777215),emissiveIntensity:5,metalness:0,roughness:.2,clearcoat:.3,clearcoatRoughness:.2,depthWrite:!0,depthTest:!0,transparent:!1,alphaTest:0,polygonOffset:!0,side:b.FrontSide,dithering:!0}),ge=new b.MeshPhysicalMaterial({color:new b.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:b.FrontSide,dithering:!0}),ye=new b.MeshPhysicalMaterial({color:new b.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:b.FrontSide,dithering:!0}),be=new b.MeshPhysicalMaterial({color:new b.Color(16777215),metalness:0,roughness:.3,envMapIntensity:.5,clearcoat:.5,clearcoatRoughness:.1,reflectivity:.5,ior:1.4,transmission:0,transparent:!1,depthWrite:!0,side:b.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Re=new b.MeshPhysicalMaterial({color:new b.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:b.DoubleSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Te=new b.MeshPhysicalMaterial({color:new b.Color(1710618),metalness:0,roughness:.9,envMapIntensity:.2,clearcoat:.1,clearcoatRoughness:.8,reflectivity:.2,ior:1.3,transmission:0,depthWrite:!0,side:b.FrontSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),we=new b.MeshPhysicalMaterial({color:new b.Color(8934707),metalness:0,roughness:.7,envMapIntensity:.3,clearcoat:.3,clearcoatRoughness:.4,reflectivity:.3,ior:1.3,transmission:0,depthWrite:!0,side:b.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});var $=1096174675,W=1,k=1,Y=12,j=56;function _(e){let r=He(e),n=new DataView(r.buffer,r.byteOffset,r.byteLength);if(r.byteLength<Y)throw I("Blob too small to contain SLVA header.",{expectedBytes:Y,availableBytes:r.byteLength});let t=0,o=n.getUint32(t,!0);if(t+=4,o!==$)throw I(`Invalid SLVA magic: 0x${o.toString(16)}`,{expectedMagic:`0x${$.toString(16)}`,actualMagic:`0x${o.toString(16)}`});let s=n.getUint32(t,!0);if(t+=4,s!==W)throw I(`Unsupported SLVA version: ${s}`,{expectedVersion:W,actualVersion:s});let a=n.getUint32(t,!0);if(t+=4,t+a>r.byteLength)throw I("Insufficient data to read metadata JSON.",{expectedBytes:a,availableBytes:r.byteLength-t,offset:t});let u=r.subarray(t,t+a);t+=a;let c;try{c=JSON.parse(xe(u))}catch(A){throw I(`Failed to parse metadata JSON: ${A instanceof Error?A.message:String(A)}`,{metadataLen:a})}if(t+j>r.byteLength)throw I("Insufficient data to read geometry header.",{expectedBytes:j,availableBytes:r.byteLength-t,offset:t});let h=n.getUint32(t,!0);t+=4;let m=n.getFloat64(t,!0);t+=8;let l=n.getFloat64(t,!0);t+=8;let E=n.getFloat64(t,!0);t+=8;let g=n.getFloat64(t,!0);t+=8;let d=n.getFloat64(t,!0);t+=8;let H=n.getFloat64(t,!0);t+=8;let L=n.getUint32(t,!0);t+=4;let x=(h&k)!==0,C=L*3,p=C*(x?4:2);if(t+p>r.byteLength)throw I("Insufficient data to read vertices.",{expectedBytes:p,availableBytes:r.byteLength-t,offset:t,useFloat32:x,vertexCount:L});let T=r.byteOffset+t,v=x?ve(r.buffer,T,C):Ce(r.buffer,T,C);if(t+=p,t+4>r.byteLength)throw I("Insufficient data to read index count.",{expectedBytes:4,availableBytes:r.byteLength-t,offset:t});let R=n.getUint32(t,!0);t+=4;let S=R*4;if(t+S>r.byteLength)throw I("Insufficient data to read indices.",{expectedBytes:S,availableBytes:r.byteLength-t,offset:t,indexCount:R});let O=Se(r.buffer,r.byteOffset+t,R);return{metadata:c,flags:h,vertices:v,indices:O,origin:[m,l,E],scale:[g,d,H]}}function He(e){return typeof e=="string"?U(e):e instanceof Uint8Array?e:new Uint8Array(e)}function xe(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 F("No UTF-8 decoder available in this environment.",D.INVALID_STATE)}function Ce(e,r,n){if(n===0)return new Int16Array(0);if(r%2===0)return new Int16Array(e,r,n);let t=new Uint8Array(n*2);return t.set(new Uint8Array(e,r,n*2)),new Int16Array(t.buffer)}function ve(e,r,n){if(n===0)return new Float32Array(0);if(r%4===0)return new Float32Array(e,r,n);let t=new Uint8Array(n*4);return t.set(new Uint8Array(e,r,n*4)),new Float32Array(t.buffer)}function Se(e,r,n){if(n===0)return new Uint32Array(0);if(r%4===0)return new Uint32Array(e,r,n);let t=new Uint8Array(n*4);return t.set(new Uint8Array(e,r,n*4)),new Uint32Array(t.buffer)}function I(e,r){return new F(e,D.VALIDATION_ERROR,{context:r})}import*as M from"three";async function Z(e,r){let{debug:n=!1}=r??{},t=n?performance.now():0;try{let o=performance.now(),s=JSON.parse(e),a=performance.now()-o;return await Ae(s,r,{parseTime:a,perfStart:t})}catch(o){return y().error("Error parsing mesh batch:",o),[]}}async function Ae(e,r,n){let{mergeByMaterial:t=!0,applyTransforms:o=!0,scaleFactor:s=1,debug:a=!1}=r??{},{parseTime:u=0,perfStart:c=a?performance.now():0}=n??{};try{let h=performance.now(),m=_(e.compressedData),l=performance.now()-h,E=a?Fe(e.compressedData):0;return q(m,{mergeByMaterial:t,applyTransforms:o,scaleFactor:s,debug:a,parseTime:u,decodeTime:l,perfStart:c,blobBytes:E,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}})}catch(h){return y().error("Error parsing mesh batch object:",h),[]}}async function at(e,r){let{mergeByMaterial:n=!0,applyTransforms:t=!0,scaleFactor:o=1,debug:s=!1}=r??{},a=s?performance.now():0;try{let u=performance.now(),c=_(e),h=performance.now()-u,m=e.byteLength;return q(c,{mergeByMaterial:n,applyTransforms:t,scaleFactor:o,debug:s,parseTime:0,decodeTime:h,perfStart:a,blobBytes:m})}catch(u){return y().error("Error parsing mesh batch blob:",u),[]}}function q(e,r){let{mergeByMaterial:n,applyTransforms:t,scaleFactor:o,debug:s,parseTime:a,decodeTime:u,perfStart:c,blobBytes:h,fallback:m}=r,l=e.metadata.materials??m?.materials??[],E=e.metadata.groups??m?.groups??[],g=e.metadata.sourceComponentId??m?.sourceComponentId,d=(e.flags&k)!==0,H=d?Le(e.vertices,t):Be(e.vertices,e.origin,e.scale,t);if(s){let p=e.vertices.byteLength+e.indices.byteLength;y().debug("Mesh Batch Stats:"),y().debug(` Materials: ${l.length} | Groups: ${E.length}`),y().debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),y().debug(` Format: ${d?"float32":"int16 quantized"}`),y().debug(` Blob: ${(h/1024/1024).toFixed(2)} MB | Geometry on wire: ${(p/1024/1024).toFixed(2)} MB`)}let L=performance.now(),x=l.map(Ie),C=[];for(let p of E)if(n&&p.meshes.length>1){let T=Oe(p,H,e.indices,x);T.userData.sourceComponentId=g??null,C.push(T)}else{let T=De(p,H,e.indices,x);for(let v of T)v.userData.sourceComponentId=g??null;C.push(...T)}if(o!==1)for(let p of C)p.scale.set(o,o,o);let f=performance.now()-L;if(s){let p=performance.now()-c;y().debug("Performance:"),a>0&&y().debug(` Parse JSON: ${a.toFixed(2)}ms`),y().debug(` Decode binary: ${u.toFixed(2)}ms`),y().debug(` Create Meshes: ${f.toFixed(2)}ms`),y().debug(` Total: ${p.toFixed(2)}ms`)}return Promise.resolve(C)}function Be(e,r,n,t){let o=new Float32Array(e.length),s=r[0],a=r[1],u=r[2],c=n[0],h=n[1],m=n[2];if(t)for(let l=0;l<e.length;l+=3){let E=s+(e[l]+32767)*c,g=a+(e[l+1]+32767)*h,d=u+(e[l+2]+32767)*m;o[l]=E,o[l+1]=d,o[l+2]=-g}else for(let l=0;l<e.length;l+=3)o[l]=s+(e[l]+32767)*c,o[l+1]=a+(e[l+1]+32767)*h,o[l+2]=u+(e[l+2]+32767)*m;return o}function Le(e,r){if(!r)return e;let n=new Float32Array(e.length);for(let t=0;t<e.length;t+=3){let o=e[t],s=e[t+1],a=e[t+2];n[t]=o,n[t+1]=a,n[t+2]=-s}return n}function Ie(e){let r=N(e.color);return new M.MeshPhysicalMaterial({color:r,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,side:M.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.5,polygonOffsetUnits:.5,depthWrite:!0,depthTest:!0})}function Oe(e,r,n,t){let o=0,s=0;for(let d of e.meshes)o+=d.vertexCount,s+=d.indexCount;let a=new Float32Array(o*3),u=new Uint32Array(s),c=0,h=0;for(let d of e.meshes){let H=d.vertexStart*3,L=d.vertexCount*3;a.set(r.subarray(H,H+L),c*3);let x=n.subarray(d.indexStart,d.indexStart+d.indexCount),C=c-d.vertexStart;if(C===0)u.set(x,h);else for(let f=0;f<x.length;f++)u[h+f]=x[f]+C;c+=d.vertexCount,h+=d.indexCount}let m=new M.BufferGeometry;m.setAttribute("position",new M.BufferAttribute(a,3)),m.setIndex(new M.BufferAttribute(u,1)),m.computeVertexNormals();let l=new M.Mesh(m,t[e.materialId]),E=e.meshes[0],g=e.meshes.map(d=>d.name).filter(d=>d&&d.length>0);return l.name=g.length>0?g[0]:`merged_material_${e.materialId}`,l.castShadow=!0,l.receiveShadow=!0,l.userData={name:l.name,layer:E?.layer??"",originalIndex:E?.originalIndex??0,metadata:E?.metadata??{},mergedFrom:e.meshes.slice(1).map(d=>({name:d.name,layer:d.layer,originalIndex:d.originalIndex}))},l}function De(e,r,n,t){let o=[];for(let s of e.meshes){let a=s.vertexStart*3,u=s.vertexCount*3,c=r.slice(a,a+u),h=n.subarray(s.indexStart,s.indexStart+s.indexCount),m=new Uint32Array(h.length),l=s.vertexStart;for(let d=0;d<h.length;d++)m[d]=h[d]-l;let E=new M.BufferGeometry;E.setAttribute("position",new M.BufferAttribute(c,3)),E.setIndex(new M.BufferAttribute(m,1)),E.computeVertexNormals();let g=new M.Mesh(E,t[e.materialId]);g.name=s.name,g.userData={name:s.name,layer:s.layer??"",originalIndex:s.originalIndex,metadata:s.metadata??{}},g.castShadow=!0,g.receiveShadow=!0,o.push(g)}return o}function Fe(e){return Math.floor(e.length*3/4)}var Pe={Millimeters:1/1e3,Centimeters:1/100,Meters:1,Inches:1/39.37,Feet:1/3.28084},ze="Display";async function ut(e,r){let n=performance.now(),t=[],{allowScaling:o=!0,allowAutoPosition:s=!0,debug:a=!1,parsing:u={}}=r??{};try{let c=o?ke(e.modelunits):1;return await _e(e,t,c,u,a),s&&Ve(t),t}catch(c){throw Ne(c,t),c}finally{a&&$e(n)}}function ke(e){return Pe[e]??1}async function _e(e,r,n,t,o){for(let s of e.values){let a=s.InnerTree;for(let u in a){let c=a[u];c&&await Ue(c,r,n,t,o)}}}async function Ue(e,r,n,t,o){for(let s of e)if(s.type.includes(ze)){let a={mergeByMaterial:!0,applyTransforms:!0,debug:!1,...t},u=await Z(s.data,a);if(n!==1)for(let c of u)c.scale.set(n,n,n);r.push(...u),o&&y().debug(`Extracted ${u.length} meshes from batch`)}}function Ve(e){if(e.length===0)return;let n=z(e).min.y;G(e,n)}function Ne(e,r){y().error("An unexpected error occurred:",e),Ge(r)}function Ge(e){for(let r of e)r.geometry&&r.geometry.dispose(),r.material&&(Array.isArray(r.material)?r.material.forEach(n=>n.dispose()):r.material.dispose())}function $e(e){let r=performance.now()-e;y().info("Time to process meshes:",`${r.toFixed(2)}ms`)}export{Ze as a,Xe as b,N as c,G as d,z as e,Me as f,$ as g,W as h,k as i,_ as j,Z as k,Ae as l,at as m,Pe as n,ut as o};
2
- //# sourceMappingURL=chunk-MKW2KTPT.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/features/visualization/threejs/three-initializer.ts","../src/features/visualization/threejs/three-helpers.ts","../src/features/visualization/threejs/three-materials.ts","../src/features/visualization/webdisplay/binary-parser.ts","../src/features/visualization/webdisplay/batch-parser.ts","../src/features/visualization/webdisplay/webdisplay-parser.ts"],"sourcesContent":["import * as THREE from 'three';\nimport { OrbitControls } from 'three/addons/controls/OrbitControls.js';\nimport { HDRLoader } from 'three/addons/loaders/HDRLoader.js';\n\nimport { getLogger } from '@/core';\nimport { ThreeInitializerOptions } from '../types';\n\nconst defaultUp = new THREE.Vector3(0, 0, 1);\n\n// Returns scale-specific values for mm, cm, and m scales\nconst getScaleValue = (scale: string, mmVal: number, cmVal: number, mVal: number): number => {\n\tswitch (scale) {\n\t\tcase 'mm':\n\t\t\treturn mmVal;\n\t\tcase 'cm':\n\t\t\treturn cmVal;\n\t\tdefault:\n\t\t\treturn mVal;\n\t}\n};\n\n/**\n * Initializes a Three.js environment with scene, camera, renderer, and event handling.\n */\nexport const initThree = function (\n\tcanvas: HTMLCanvasElement,\n\toptions?: ThreeInitializerOptions\n): {\n\tscene: THREE.Scene;\n\tcamera: THREE.PerspectiveCamera;\n\tcontrols: OrbitControls;\n\trenderer: THREE.WebGLRenderer;\n\tdispose: () => void;\n\tfitToView: () => void;\n\tclearSelection: () => void;\n} {\n\tconst config = applyDefaults(options || {});\n\n\tconst scene = createScene(config);\n\tconst camera = createCamera(config, canvas);\n\tconst renderer = setupRenderer(canvas, config);\n\tconst controls = setupControls(camera, canvas, config);\n\n\tsetupEnvironment(scene, config);\n\tsetupLighting(scene, config);\n\n\tif (config.floor?.enabled) {\n\t\taddFloor(scene, config);\n\t}\n\n\tconst eventHandlers =\n\t\tconfig.events.enableEventHandlers !== false\n\t\t\t? setupEventHandlers(canvas, scene, camera, controls, config)\n\t\t\t: { dispose: () => {}, fitToView: () => {}, clearSelection: () => {} };\n\n\tconst parent = canvas.parentElement;\n\tconst getCanvasSize = () =>\n\t\tparent\n\t\t\t? { width: parent.clientWidth, height: parent.clientHeight }\n\t\t\t: { width: window.innerWidth, height: window.innerHeight };\n\n\t// Resize checked every frame so buffer resize and render happen in the same frame,\n\t// preventing visible blank frames on resize\n\tconst { animate, dispose: disposeAnimation } = createAnimationLoop(\n\t\trenderer,\n\t\tscene,\n\t\tcamera,\n\t\tcontrols,\n\t\tgetCanvasSize,\n\t\tconfig.events.onFrame\n\t);\n\tanimate();\n\n\tconst sceneUp = config.environment?.sceneUp || defaultUp;\n\tscene.up.set(sceneUp.x, sceneUp.y, sceneUp.z);\n\n\tconst dispose = () => {\n\t\tdisposeAnimation();\n\t\teventHandlers.dispose();\n\t\tcontrols.dispose();\n\t\trenderer.dispose();\n\n\t\tscene.traverse((object) => {\n\t\t\tif (object instanceof THREE.Mesh) {\n\t\t\t\tobject.geometry?.dispose();\n\t\t\t\tif (Array.isArray(object.material)) {\n\t\t\t\t\tobject.material.forEach((material) => material.dispose());\n\t\t\t\t} else {\n\t\t\t\t\tobject.material?.dispose();\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t};\n\n\treturn {\n\t\tscene,\n\t\tcamera,\n\t\tcontrols,\n\t\trenderer,\n\t\tdispose,\n\t\tfitToView: eventHandlers.fitToView,\n\t\tclearSelection: eventHandlers.clearSelection\n\t};\n};\n\nfunction applyDefaults(options: ThreeInitializerOptions): Required<ThreeInitializerOptions> {\n\tconst scale = options.sceneScale || 'm';\n\n\t// All Rhino geometry is normalized to METERS (1 unit = 1 meter), sceneScale just changes the viewing perspective\n\tconst scaleDefaults = {\n\t\tmm: {\n\t\t\tcameraDistance: 20,\n\t\t\tnear: 0.1,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 100,\n\t\t\tlightDistance: 10,\n\t\t\tlightHeight: 20,\n\t\t\tminDistance: 0.1,\n\t\t\tshadowSize: 100,\n\t\t\tscaleFactor: 1000\n\t\t},\n\t\tcm: {\n\t\t\tcameraDistance: 20,\n\t\t\tnear: 0.1,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 100,\n\t\t\tlightDistance: 25,\n\t\t\tlightHeight: 50,\n\t\t\tminDistance: 0.1,\n\t\t\tshadowSize: 100,\n\t\t\tscaleFactor: 100\n\t\t},\n\t\tm: {\n\t\t\tcameraDistance: 10,\n\t\t\tnear: 0.01,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 50,\n\t\t\tlightDistance: 25,\n\t\t\tlightHeight: 50,\n\t\t\tminDistance: 0.001,\n\t\t\tshadowSize: 100,\n\t\t\tscaleFactor: 1\n\t\t},\n\t\tinches: {\n\t\t\tcameraDistance: 15,\n\t\t\tnear: 0.1,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 80,\n\t\t\tlightDistance: 20,\n\t\t\tlightHeight: 40,\n\t\t\tminDistance: 0.1,\n\t\t\tshadowSize: 80,\n\t\t\tscaleFactor: 39.37\n\t\t},\n\t\tfeet: {\n\t\t\tcameraDistance: 8,\n\t\t\tnear: 0.1,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 40,\n\t\t\tlightDistance: 15,\n\t\t\tlightHeight: 30,\n\t\t\tminDistance: 0.1,\n\t\t\tshadowSize: 60,\n\t\t\tscaleFactor: 3.28084\n\t\t}\n\t};\n\n\tconst defaults = scaleDefaults[scale];\n\n\treturn {\n\t\tsceneScale: scale,\n\t\tcamera: {\n\t\t\tposition:\n\t\t\t\toptions.camera?.position ||\n\t\t\t\tnew THREE.Vector3(\n\t\t\t\t\t-defaults.cameraDistance,\n\t\t\t\t\tdefaults.cameraDistance,\n\t\t\t\t\tdefaults.cameraDistance\n\t\t\t\t),\n\t\t\tfov: options.camera?.fov || 20,\n\t\t\tnear: options.camera?.near || defaults.near,\n\t\t\tfar: options.camera?.far || defaults.far,\n\t\t\ttarget: options.camera?.target || new THREE.Vector3(0, 0, 0)\n\t\t},\n\t\tlighting: {\n\t\t\tenableSunlight: options.lighting?.enableSunlight ?? true,\n\t\t\tsunlightIntensity: options.lighting?.sunlightIntensity || 1,\n\t\t\tsunlightPosition:\n\t\t\t\toptions.lighting?.sunlightPosition ||\n\t\t\t\tnew THREE.Vector3(defaults.lightDistance, defaults.lightHeight, defaults.lightDistance),\n\t\t\tambientLightColor: options.lighting?.ambientLightColor || new THREE.Color(0x404040),\n\t\t\tambientLightIntensity: options.lighting?.ambientLightIntensity || 1,\n\t\t\tsunlightColor: options.lighting?.sunlightColor || 0xffffff // Default to white sunlight\n\t\t},\n\t\tenvironment: {\n\t\t\thdrPath: options.environment?.hdrPath || '/baseHDR.hdr',\n\t\t\tbackgroundColor: options.environment?.backgroundColor || new THREE.Color(0xf0f0f0),\n\t\t\tenableEnvironmentLighting: options.environment?.enableEnvironmentLighting ?? true,\n\t\t\tsceneUp: options.environment?.sceneUp || defaultUp,\n\t\t\tshowEnvironment: options.environment?.showEnvironment ?? false\n\t\t},\n\t\tfloor: {\n\t\t\tenabled: options.floor?.enabled ?? false,\n\t\t\tsize: options.floor?.size || defaults.floorSize,\n\t\t\tcolor: options.floor?.color || new THREE.Color(0x808080),\n\t\t\troughness: options.floor?.roughness || 0.7,\n\t\t\tmetalness: options.floor?.metalness || 0.0,\n\t\t\treceiveShadow: options.floor?.receiveShadow ?? true\n\t\t},\n\t\trender: {\n\t\t\tenableShadows: options.render?.enableShadows ?? true,\n\t\t\tshadowMapSize: options.render?.shadowMapSize || 2048,\n\t\t\tantialias: options.render?.antialias ?? true,\n\t\t\tpixelRatio: options.render?.pixelRatio || Math.min(window.devicePixelRatio, 2),\n\t\t\ttoneMapping: options.render?.toneMapping || THREE.NeutralToneMapping,\n\t\t\ttoneMappingExposure: options.render?.toneMappingExposure || 1,\n\t\t\tpreserveDrawingBuffer: options.render?.preserveDrawingBuffer ?? false\n\t\t},\n\t\tcontrols: {\n\t\t\tenableDamping: options.controls?.enableDamping ?? false,\n\t\t\tdampingFactor: options.controls?.dampingFactor || 0.05,\n\t\t\tautoRotate: options.controls?.autoRotate ?? false,\n\t\t\tautoRotateSpeed: options.controls?.autoRotateSpeed || 0.5,\n\t\t\tenableZoom: options.controls?.enableZoom ?? true,\n\t\t\tenablePan: options.controls?.enablePan ?? true,\n\t\t\tminDistance: options.controls?.minDistance || defaults.minDistance,\n\t\t\tmaxDistance: options.controls?.maxDistance || Infinity\n\t\t},\n\t\tevents: {\n\t\t\tonBackgroundClicked: options.events?.onBackgroundClicked,\n\t\t\tonObjectSelected: options.events?.onObjectSelected,\n\t\t\tonMeshMetadataClicked: options.events?.onMeshMetadataClicked,\n\t\t\tonMeshDoubleClicked: options.events?.onMeshDoubleClicked,\n\t\t\tselectionColor: options.events?.selectionColor || '#ff0000', // Default to red\n\t\t\tenableEventHandlers: options.events?.enableEventHandlers ?? true,\n\t\t\tenableKeyboardControls: options.events?.enableKeyboardControls ?? true,\n\t\t\tenableClickToFocus: options.events?.enableClickToFocus ?? true,\n\t\t\tenableDoubleClickZoom: options.events?.enableDoubleClickZoom ?? true,\n\t\t\tonReady: options.events?.onReady,\n\t\t\tonFrame: options.events?.onFrame\n\t\t}\n\t};\n}\n\nfunction createScene(config: Required<ThreeInitializerOptions>): THREE.Scene {\n\tconst scene = new THREE.Scene();\n\n\tconst bgColor =\n\t\ttypeof config.environment.backgroundColor === 'string'\n\t\t\t? new THREE.Color(config.environment.backgroundColor)\n\t\t\t: config.environment.backgroundColor;\n\tscene.background = bgColor || null;\n\n\treturn scene;\n}\n\nfunction animateCameraTo(\n\tcamera: THREE.PerspectiveCamera,\n\tcontrols: OrbitControls,\n\ttoPosition: THREE.Vector3,\n\ttoTarget: THREE.Vector3,\n\tdurationMs = 200\n): void {\n\tconst fromPosition = camera.position.clone();\n\tconst fromTarget = controls.target.clone();\n\tconst startTime = performance.now();\n\n\tconst easeOut = (t: number) => 1 - Math.pow(1 - t, 3);\n\n\tconst tick = () => {\n\t\tconst elapsed = performance.now() - startTime;\n\t\tconst t = easeOut(Math.min(elapsed / durationMs, 1));\n\n\t\tcamera.position.lerpVectors(fromPosition, toPosition, t);\n\t\tcontrols.target.lerpVectors(fromTarget, toTarget, t);\n\t\tcontrols.update();\n\n\t\tif (t < 1) requestAnimationFrame(tick);\n\t};\n\n\trequestAnimationFrame(tick);\n}\n\n// Resize applied before render so buffer clear and draw happen in the same frame,\n// preventing visible blank frames when the canvas is resized\nfunction createAnimationLoop(\n\trenderer: THREE.WebGLRenderer,\n\tscene: THREE.Scene,\n\tcamera: THREE.PerspectiveCamera,\n\tcontrols: OrbitControls,\n\tgetCanvasSize: () => { width: number; height: number },\n\tonFrame?: (delta: number) => void\n): { animate: () => void; dispose: () => void } {\n\tlet animationId: number | null = null;\n\tlet lastTime = performance.now();\n\n\tconst checkResize = () => {\n\t\tconst { width, height } = getCanvasSize();\n\t\tif (width === 0 || height === 0) return;\n\n\t\tconst pixelRatio = Math.min(window.devicePixelRatio, 2);\n\t\tconst newW = Math.round(width * pixelRatio);\n\t\tconst newH = Math.round(height * pixelRatio);\n\n\t\tif (renderer.domElement.width !== newW || renderer.domElement.height !== newH) {\n\t\t\trenderer.setPixelRatio(pixelRatio);\n\t\t\trenderer.setSize(width, height, false);\n\t\t\tcamera.aspect = width / height;\n\t\t\tcamera.updateProjectionMatrix();\n\t\t}\n\t};\n\n\tconst animate = function () {\n\t\tanimationId = requestAnimationFrame(animate);\n\n\t\tconst now = performance.now();\n\t\tconst delta = (now - lastTime) / 1000;\n\t\tlastTime = now;\n\n\t\tcheckResize();\n\n\t\tif (controls.enableDamping || controls.autoRotate) {\n\t\t\tcontrols.update();\n\t\t}\n\n\t\tonFrame?.(delta);\n\n\t\trenderer.render(scene, camera);\n\t};\n\n\tconst dispose = () => {\n\t\tif (animationId !== null) {\n\t\t\tcancelAnimationFrame(animationId);\n\t\t\tanimationId = null;\n\t\t}\n\t};\n\n\treturn { animate, dispose };\n}\n\nfunction setupEnvironment(scene: THREE.Scene, config: Required<ThreeInitializerOptions>) {\n\tif (config.environment.enableEnvironmentLighting) {\n\t\tnew HDRLoader().load(\n\t\t\tconfig.environment.hdrPath || '/baseHDR.hdr',\n\t\t\tfunction (envMap) {\n\t\t\t\tenvMap.mapping = THREE.EquirectangularReflectionMapping;\n\t\t\t\tscene.environment = envMap;\n\t\t\t\tif (config.environment.showEnvironment) {\n\t\t\t\t\tscene.background = envMap;\n\t\t\t\t}\n\t\t\t\tconfig.events.onReady?.();\n\t\t\t},\n\t\t\tundefined,\n\t\t\tfunction (error) {\n\t\t\t\tgetLogger().warn('HDR texture could not be loaded, falling back to basic lighting:', error);\n\t\t\t\tconfig.events.onReady?.();\n\t\t\t}\n\t\t);\n\t} else {\n\t\tconfig.events.onReady?.();\n\t}\n}\n\nfunction setupLighting(scene: THREE.Scene, config: Required<ThreeInitializerOptions>) {\n\tconst ambientLight = new THREE.AmbientLight(\n\t\tconfig.lighting.ambientLightColor,\n\t\tconfig.lighting.ambientLightIntensity\n\t);\n\tscene.add(ambientLight);\n\n\tif (config.lighting.enableSunlight) {\n\t\tconst sunlight = new THREE.DirectionalLight(\n\t\t\tconfig.lighting.sunlightColor ?? 0xffffff,\n\t\t\tconfig.lighting.sunlightIntensity\n\t\t);\n\t\tconst pos = config.lighting.sunlightPosition;\n\t\tif (pos) {\n\t\t\tsunlight.position.set(pos.x, pos.y, pos.z);\n\t\t}\n\n\t\tif (config.render.enableShadows) {\n\t\t\tsunlight.castShadow = true;\n\t\t\tconst shadowSize = getScaleValue(config.sceneScale, 0.1, 10, 100);\n\n\t\t\tsunlight.shadow.camera.left = -shadowSize;\n\t\t\tsunlight.shadow.camera.right = shadowSize;\n\t\t\tsunlight.shadow.camera.top = shadowSize;\n\t\t\tsunlight.shadow.camera.bottom = -shadowSize;\n\n\t\t\tconst shadowNear = getScaleValue(config.sceneScale, 0.001, 0.1, 0.5);\n\t\t\tconst shadowFar = getScaleValue(config.sceneScale, 1, 100, 500);\n\n\t\t\tsunlight.shadow.camera.near = shadowNear;\n\t\t\tsunlight.shadow.camera.far = shadowFar;\n\n\t\t\tsunlight.shadow.mapSize.width = config.render.shadowMapSize || 2048;\n\t\t\tsunlight.shadow.mapSize.height = config.render.shadowMapSize || 2048;\n\n\t\t\tsunlight.shadow.bias = -0.0001;\n\t\t\tsunlight.shadow.normalBias = 0.02;\n\t\t}\n\n\t\tscene.add(sunlight);\n\t}\n}\n\nfunction addFloor(scene: THREE.Scene, config: Required<ThreeInitializerOptions>) {\n\tconst floorSize = config.floor.size;\n\tconst floorGeometry = new THREE.PlaneGeometry(floorSize, floorSize);\n\n\tconst floorColor =\n\t\ttypeof config.floor.color === 'string'\n\t\t\t? new THREE.Color(config.floor.color)\n\t\t\t: config.floor.color;\n\n\tconst floorMaterial = new THREE.MeshStandardMaterial({\n\t\tcolor: floorColor,\n\t\troughness: config.floor.roughness,\n\t\tmetalness: config.floor.metalness,\n\t\tside: THREE.DoubleSide\n\t});\n\n\tconst floor = new THREE.Mesh(floorGeometry, floorMaterial);\n\tfloor.userData.id = 'floor';\n\tfloor.name = 'floor';\n\tfloor.rotation.x = -Math.PI / 2;\n\tfloor.position.y = 0;\n\n\tif (config.floor.receiveShadow && config.render.enableShadows) {\n\t\tfloor.receiveShadow = true;\n\t}\n\n\tscene.add(floor);\n}\n\nfunction createCamera(\n\tconfig: Required<ThreeInitializerOptions>,\n\tcanvas: HTMLCanvasElement\n): THREE.PerspectiveCamera {\n\tconst parent = canvas.parentElement;\n\tconst width = parent ? parent.clientWidth : window.innerWidth;\n\tconst height = parent ? parent.clientHeight : window.innerHeight;\n\n\tconst camera = new THREE.PerspectiveCamera(\n\t\tconfig.camera.fov,\n\t\twidth / height,\n\t\tconfig.camera.near,\n\t\tconfig.camera.far\n\t);\n\n\tconst pos = config.camera.position;\n\tif (pos) {\n\t\tcamera.position.set(pos.x, pos.y, pos.z);\n\t}\n\n\treturn camera;\n}\n\n// Logarithmic depth buffer improves depth precision for mixed scales (mm to km)\nfunction setupRenderer(\n\tcanvas: HTMLCanvasElement,\n\tconfig: Required<ThreeInitializerOptions>\n): THREE.WebGLRenderer {\n\tconst renderer = new THREE.WebGLRenderer({\n\t\tantialias: config.render.antialias,\n\t\tcanvas,\n\t\talpha: true,\n\t\tpowerPreference: 'high-performance',\n\t\tpreserveDrawingBuffer: config.render.preserveDrawingBuffer,\n\t\tlogarithmicDepthBuffer: true\n\t});\n\n\tconst parent = canvas.parentElement;\n\tconst width = parent ? parent.clientWidth : window.innerWidth;\n\tconst height = parent ? parent.clientHeight : window.innerHeight;\n\n\tif (parent) {\n\t\tcanvas.style.width = '100%';\n\t\tcanvas.style.height = '100%';\n\t\tcanvas.style.display = 'block';\n\t}\n\n\trenderer.setSize(width, height, false);\n\trenderer.setPixelRatio(config.render.pixelRatio || Math.min(window.devicePixelRatio, 2));\n\n\tif (config.render.enableShadows) {\n\t\trenderer.shadowMap.enabled = true;\n\t\trenderer.shadowMap.type = THREE.VSMShadowMap;\n\t}\n\n\trenderer.toneMapping = config.render.toneMapping!;\n\trenderer.toneMappingExposure = config.render.toneMappingExposure || 1.0;\n\trenderer.outputColorSpace = THREE.SRGBColorSpace;\n\n\trenderer.sortObjects = true;\n\n\treturn renderer;\n}\n\nfunction setupEventHandlers(\n\tcanvas: HTMLCanvasElement,\n\tscene: THREE.Scene,\n\tcamera: THREE.PerspectiveCamera,\n\tcontrols: OrbitControls,\n\tconfig: Required<ThreeInitializerOptions>\n): {\n\tdispose: () => void;\n\tfitToView: () => void;\n\tclearSelection: () => void;\n} {\n\tconst selectedObjects = new Set<THREE.Object3D>();\n\tconst originalMaterials = new Map<THREE.Object3D, THREE.Material | THREE.Material[]>();\n\tconst raycaster = new THREE.Raycaster();\n\tconst mouse = new THREE.Vector2();\n\tconst mouseDownPosition = new THREE.Vector2();\n\n\t// An object is hittable only if every ancestor is also visible. Three.js's\n\t// recursive intersect doesn't enforce that — it can hit a visible Mesh inside\n\t// a hidden Group.\n\tconst isFullyVisible = (object: THREE.Object3D): boolean => {\n\t\tlet current: THREE.Object3D | null = object;\n\t\twhile (current) {\n\t\t\tif (!current.visible) return false;\n\t\t\tcurrent = current.parent;\n\t\t}\n\t\treturn true;\n\t};\n\n\tconst fitToView = () => {\n\t\tconst box = new THREE.Box3();\n\n\t\tscene.traverse((object) => {\n\t\t\tif (object.visible && object.userData.id !== 'floor' && object instanceof THREE.Mesh) {\n\t\t\t\tbox.expandByObject(object);\n\t\t\t}\n\t\t});\n\n\t\tif (box.isEmpty()) {\n\t\t\tgetLogger().warn('No objects to fit to view');\n\t\t\treturn;\n\t\t}\n\n\t\tconst center = box.getCenter(new THREE.Vector3());\n\t\tconst size = box.getSize(new THREE.Vector3());\n\n\t\tconst maxDim = Math.max(size.x, size.y, size.z);\n\t\tconst fov = camera.fov * (Math.PI / 180);\n\t\tlet distance = maxDim / (2 * Math.tan(fov / 2));\n\n\t\tdistance *= 1.5;\n\n\t\tconst direction = camera.position.clone().sub(controls.target).normalize();\n\t\tcamera.position.copy(center.clone().add(direction.multiplyScalar(distance)));\n\n\t\tcontrols.target.copy(center);\n\t\tcontrols.update();\n\t};\n\n\tconst selectionColorObj =\n\t\ttypeof config.events.selectionColor === 'string'\n\t\t\t? new THREE.Color(config.events.selectionColor)\n\t\t\t: config.events.selectionColor instanceof THREE.Color\n\t\t\t\t? config.events.selectionColor\n\t\t\t\t: new THREE.Color('#ff0000');\n\n\tconst clearSelection = () => {\n\t\tselectedObjects.forEach((obj) => {\n\t\t\tif (obj instanceof THREE.Mesh && originalMaterials.has(obj)) {\n\t\t\t\tobj.material = originalMaterials.get(obj)!;\n\t\t\t\toriginalMaterials.delete(obj);\n\t\t\t}\n\t\t});\n\t\tselectedObjects.clear();\n\t};\n\n\tconst handleMouseDown = (event: MouseEvent) => {\n\t\tmouseDownPosition.set(event.clientX, event.clientY);\n\t};\n\n\tconst handleCanvasClick = (event: MouseEvent) => {\n\t\t// Ignore if mouse has moved (drag)\n\t\tconst currentMousePosition = new THREE.Vector2(event.clientX, event.clientY);\n\t\tif (mouseDownPosition.distanceTo(currentMousePosition) > 5) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst rect = canvas.getBoundingClientRect();\n\t\tmouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;\n\t\tmouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;\n\n\t\traycaster.setFromCamera(mouse, camera);\n\t\tconst intersects = raycaster\n\t\t\t.intersectObjects(scene.children, true)\n\t\t\t.filter((i) => isFullyVisible(i.object));\n\n\t\tif (intersects.length > 0) {\n\t\t\tconst clickedObject = intersects[0].object;\n\n\t\t\tif (!selectedObjects.has(clickedObject)) {\n\t\t\t\tclearSelection();\n\t\t\t\tselectedObjects.add(clickedObject);\n\n\t\t\t\t// Clone material so we don't affect other meshes\n\t\t\t\tif (\n\t\t\t\t\tclickedObject instanceof THREE.Mesh &&\n\t\t\t\t\tclickedObject.material instanceof THREE.Material\n\t\t\t\t) {\n\t\t\t\t\toriginalMaterials.set(clickedObject, clickedObject.material);\n\n\t\t\t\t\tconst clonedMaterial = clickedObject.material.clone();\n\t\t\t\t\t(clonedMaterial as any).emissive = selectionColorObj.clone();\n\t\t\t\t\tclickedObject.material = clonedMaterial;\n\t\t\t\t}\n\n\t\t\t\tconfig.events?.onObjectSelected?.(clickedObject);\n\n\t\t\t\tif (clickedObject instanceof THREE.Mesh && Object.keys(clickedObject.userData).length > 0) {\n\t\t\t\t\tconfig.events?.onMeshMetadataClicked?.(clickedObject.userData);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tclearSelection();\n\t\t\tconfig.events?.onBackgroundClicked?.({ x: mouse.x, y: mouse.y });\n\t\t}\n\t};\n\n\tconst handleDoubleClick = (event: MouseEvent) => {\n\t\tconst rect = canvas.getBoundingClientRect();\n\t\tmouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;\n\t\tmouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;\n\n\t\traycaster.setFromCamera(mouse, camera);\n\t\tconst intersects = raycaster\n\t\t\t.intersectObjects(scene.children, true)\n\t\t\t.filter((i) => isFullyVisible(i.object));\n\n\t\tif (intersects.length === 0) return;\n\n\t\tconst target = intersects[0].object;\n\t\tconfig.events?.onMeshDoubleClicked?.(target);\n\n\t\tif (!config.events?.enableDoubleClickZoom) return;\n\n\t\tconst box = new THREE.Box3().setFromObject(target);\n\t\tif (box.isEmpty()) return;\n\n\t\tconst center = box.getCenter(new THREE.Vector3());\n\t\tconst size = box.getSize(new THREE.Vector3());\n\t\tconst maxDim = Math.max(size.x, size.y, size.z);\n\t\tconst fov = camera.fov * (Math.PI / 180);\n\t\tconst distance = (maxDim / (2 * Math.tan(fov / 2))) * 1.5;\n\n\t\tconst direction = camera.position.clone().sub(controls.target).normalize();\n\t\tconst targetPosition = center.clone().add(direction.multiplyScalar(distance));\n\n\t\tanimateCameraTo(camera, controls, targetPosition, center);\n\t};\n\n\tconst handleKeydown = (event: KeyboardEvent) => {\n\t\tif (!config.events?.enableKeyboardControls) return;\n\n\t\tswitch (event.key.toLowerCase()) {\n\t\t\tcase 'f':\n\t\t\t\tevent.preventDefault();\n\t\t\t\tfitToView();\n\t\t\t\tbreak;\n\t\t\tcase 'escape':\n\t\t\t\tevent.preventDefault();\n\t\t\t\tclearSelection();\n\t\t\t\tbreak;\n\t\t\tcase ' ':\n\t\t\t\tevent.preventDefault();\n\t\t\t\tfitToView();\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\tif (config.events?.enableClickToFocus) {\n\t\tcanvas.addEventListener('mousedown', handleMouseDown);\n\t\tcanvas.addEventListener('click', handleCanvasClick);\n\t\tcanvas.addEventListener('dblclick', handleDoubleClick);\n\t}\n\n\tif (config.events?.enableKeyboardControls) {\n\t\tcanvas.setAttribute('tabindex', '0');\n\t\tcanvas.addEventListener('keydown', handleKeydown);\n\t}\n\n\tconst dispose = () => {\n\t\tcanvas.removeEventListener('mousedown', handleMouseDown);\n\t\tcanvas.removeEventListener('click', handleCanvasClick);\n\t\tcanvas.removeEventListener('dblclick', handleDoubleClick);\n\t\tcanvas.removeEventListener('keydown', handleKeydown);\n\t\tclearSelection();\n\t};\n\n\treturn { dispose, fitToView, clearSelection };\n}\n\nfunction setupControls(\n\tcamera: THREE.PerspectiveCamera,\n\tcanvas: HTMLCanvasElement,\n\tconfig: Required<ThreeInitializerOptions>\n): OrbitControls {\n\tconst controls = new OrbitControls(camera, canvas);\n\n\tconst target = config.camera.target;\n\tif (target) {\n\t\tcontrols.target.set(target.x, target.y, target.z);\n\t}\n\n\tcontrols.enableDamping = config.controls.enableDamping || false;\n\tcontrols.dampingFactor = config.controls.dampingFactor || 0.05;\n\n\tcontrols.autoRotate = config.controls.autoRotate || false;\n\tcontrols.autoRotateSpeed = config.controls.autoRotateSpeed || 0.5;\n\n\tcontrols.enableZoom = config.controls.enableZoom ?? true;\n\tcontrols.enablePan = config.controls.enablePan ?? true;\n\tcontrols.minDistance = config.controls.minDistance || 0.001;\n\tcontrols.maxDistance = config.controls.maxDistance || Infinity;\n\n\tcontrols.screenSpacePanning = false;\n\tcontrols.maxPolarAngle = Math.PI;\n\n\tcontrols.update();\n\treturn controls;\n}\n","import * as THREE from 'three';\nimport { OrbitControls } from 'three/addons/controls/OrbitControls.js';\nimport { getLogger } from '@/core';\n\n// Camera configuration constants\nconst CAMERA_CONFIG = {\n\tHUGE_THRESHOLD: 10000,\n\tLARGE_THRESHOLD: 1000,\n\tSCALE_RATIO_THRESHOLD: 100,\n\tNEAR_PLANE_FACTOR: {\n\t\tTINY: 0.0001,\n\t\tSMALL: 0.001,\n\t\tNORMAL: 0.01\n\t},\n\tFAR_PLANE_FACTOR: {\n\t\tHUGE: 100,\n\t\tLARGE: 50,\n\t\tNORMAL: 20\n\t},\n\tINITIAL_DISTANCE_MULTIPLIER: 4\n};\n\n/**\n * Updates the scene with the given meshes and camera settings.\n * If initialPositionSet is false, it positions the camera and sets the controls target based on the bounding boxes of the meshes.\n * @param scene - The THREE.Scene object to update.\n * @param meshes - An array of THREE.Mesh objects to add to the scene.\n * @param camera - The THREE.PerspectiveCamera object to position.\n * @param controls - The OrbitControls object to update.\n * @param initialPositionSet - A boolean indicating whether the initial position of the camera and controls have been set.\n */\nexport function updateScene(\n\tscene: THREE.Scene,\n\tmeshes: THREE.Mesh[],\n\tcamera: THREE.PerspectiveCamera,\n\tcontrols: OrbitControls,\n\tinitialPositionSet: boolean\n) {\n\tclearScene(scene);\n\n\tif (meshes.length === 0) return;\n\n\t// Add new meshes to scene\n\tmeshes.forEach((mesh) => {\n\t\tscene.add(mesh);\n\t});\n\n\t// Calculate bounds of the new content\n\tconst unionBoundingBox = computeCombinedBoundingBox(meshes);\n\n\t// Get the center of the union bounding box\n\tconst center = unionBoundingBox.getCenter(new THREE.Vector3());\n\tconst size = unionBoundingBox.getSize(new THREE.Vector3());\n\n\t// Calculate a distance that is slightly larger than the largest dimension of the union bounding box\n\tconst maxDim = Math.max(size.x, size.y, size.z);\n\n\t// Always update camera frustum to ensure geometry is visible\n\t// This prevents clipping when geometry size changes significantly\n\tconst scaleRatio = maxDim / Math.min(size.x || 1, size.y || 1, size.z || 1);\n\n\tif (scaleRatio > CAMERA_CONFIG.SCALE_RATIO_THRESHOLD || maxDim > CAMERA_CONFIG.HUGE_THRESHOLD) {\n\t\t// Large scale range detected - use logarithmic depth buffer approach\n\t\tcamera.near = maxDim * CAMERA_CONFIG.NEAR_PLANE_FACTOR.TINY;\n\t\tcamera.far = maxDim * CAMERA_CONFIG.FAR_PLANE_FACTOR.HUGE;\n\t} else if (maxDim > CAMERA_CONFIG.LARGE_THRESHOLD) {\n\t\t// Large scene\n\t\tcamera.near = maxDim * CAMERA_CONFIG.NEAR_PLANE_FACTOR.SMALL;\n\t\tcamera.far = maxDim * CAMERA_CONFIG.FAR_PLANE_FACTOR.LARGE;\n\t} else {\n\t\t// Normal scene\n\t\tcamera.near = Math.max(0.01, maxDim * CAMERA_CONFIG.NEAR_PLANE_FACTOR.NORMAL);\n\t\tcamera.far = Math.max(2000, maxDim * CAMERA_CONFIG.FAR_PLANE_FACTOR.NORMAL);\n\t}\n\n\tcamera.updateProjectionMatrix();\n\n\t// Only reposition camera and controls on first frame\n\tif (!initialPositionSet) {\n\t\tconst distance = maxDim * CAMERA_CONFIG.INITIAL_DISTANCE_MULTIPLIER;\n\n\t\tcamera.position.set(center.x + distance * 0.8, center.y + distance, center.z + distance * 1.2);\n\t\tcontrols.target.copy(center);\n\t\tcontrols.minDistance = camera.near * 2;\n\t\tcontrols.maxDistance = camera.far * 0.9;\n\n\t\tcontrols.update();\n\t} else {\n\t\t// Update control constraints to match new frustum\n\t\tcontrols.minDistance = camera.near * 2;\n\t\tcontrols.maxDistance = camera.far * 0.9;\n\t}\n}\n\n// =========================\n// Helper functions\n// =========================\n\n/**\n * Parses a color string in multiple formats to a THREE.Color object.\n * Supported formats:\n * - Hex: \"#C7A5A5\", \"C7A5A5\"\n * - RGB: \"199, 165, 165\"\n * - CSS named colors: \"red\", \"blue\", etc.\n * @param colorString - The color string to parse.\n * @returns A THREE.Color object.\n */\nexport function parseColor(colorString: string): THREE.Color {\n\tif (!colorString || typeof colorString !== 'string') {\n\t\tgetLogger().warn(`Invalid color input: ${colorString}, using white`);\n\t\treturn new THREE.Color(0xffffff);\n\t}\n\n\tconst trimmed = colorString.trim();\n\n\t// Try hex format (#C7A5A5 or C7A5A5) — require exactly 6 hex chars\n\tif (/^#?[0-9A-Fa-f]{6}$/.test(trimmed)) {\n\t\ttry {\n\t\t\tconst hex = trimmed.startsWith('#') ? trimmed : `#${trimmed}`;\n\t\t\treturn new THREE.Color(hex);\n\t\t} catch {\n\t\t\tgetLogger().warn(`Invalid hex color: ${colorString}, using white`);\n\t\t\treturn new THREE.Color(0xffffff);\n\t\t}\n\t}\n\n\t// Try RGB format (R, G, B)\n\tif (trimmed.includes(',')) {\n\t\tconst rgb = trimmed.split(',').map((c) => parseInt(c.trim(), 10));\n\t\tif (rgb.length === 3 && rgb.every((n) => !isNaN(n) && n >= 0 && n <= 255)) {\n\t\t\treturn new THREE.Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255);\n\t\t}\n\t}\n\n\t// Try CSS named color\n\ttry {\n\t\treturn new THREE.Color(trimmed.toLowerCase());\n\t} catch {\n\t\tgetLogger().warn(`Invalid color string: ${colorString}, using white`);\n\t\treturn new THREE.Color(0xffffff);\n\t}\n}\n\nexport function applyOffset(meshes: THREE.Mesh[], offsetY: number): void {\n\tmeshes.forEach((mesh) => {\n\t\tmesh.position.y -= offsetY;\n\t});\n}\n\n/**\n * Computes the combined world-axis-aligned bounding box of a set of meshes.\n * Correctly accounts for mesh transformations (rotation, position, scale).\n */\nexport function computeCombinedBoundingBox(meshes: THREE.Mesh[]): THREE.Box3 {\n\tconst combinedBoundingBox = new THREE.Box3();\n\tif (meshes.length === 0) return combinedBoundingBox;\n\tmeshes.forEach((mesh) => {\n\t\t// Ensure the world matrix is up to date before calculating the box\n\t\tmesh.updateMatrixWorld(true);\n\t\tconst bbox = new THREE.Box3().setFromObject(mesh);\n\t\tcombinedBoundingBox.union(bbox);\n\t});\n\treturn combinedBoundingBox;\n}\n\n/**\n * Clears the given THREE.Scene by removing all non-floor top-level children and\n * recursively disposing of their geometry and materials.\n *\n * Removes at the top level rather than traversing for meshes, so parent Groups\n * don't accumulate as ghost nodes after their mesh children are disposed.\n */\nfunction clearScene(scene: THREE.Scene): void {\n\t// Snapshot children — we mutate the array via removeFromParent during iteration\n\tconst topLevel = [...scene.children];\n\n\ttopLevel.forEach((object) => {\n\t\tif (object.userData.id === 'floor') return;\n\n\t\t// Recursively dispose all meshes in this subtree\n\t\tobject.traverse((child) => {\n\t\t\tif (!(child instanceof THREE.Mesh)) return;\n\n\t\t\tchild.geometry?.dispose();\n\n\t\t\tconst materials = Array.isArray(child.material) ? child.material : [child.material];\n\t\t\tmaterials.forEach((material) => {\n\t\t\t\t// Walk only own enumerable properties — `for...in` on a Three.js material\n\t\t\t\t// also iterates the prototype chain, which is needlessly expensive.\n\t\t\t\tfor (const value of Object.values(material)) {\n\t\t\t\t\tif (value instanceof THREE.Texture) {\n\t\t\t\t\t\tvalue.dispose();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmaterial.dispose();\n\t\t\t});\n\t\t});\n\n\t\tobject.removeFromParent();\n\t});\n}\n","import * as THREE from 'three';\n\nexport const EMISSIVE_MATERIAL = new THREE.MeshPhysicalMaterial({\n\tcolor: 0x000000,\n\temissive: new THREE.Color(0xffffff),\n\temissiveIntensity: 5,\n\tmetalness: 0.0,\n\troughness: 0.2,\n\tclearcoat: 0.3,\n\tclearcoatRoughness: 0.2,\n\tdepthWrite: true,\n\tdepthTest: true,\n\ttransparent: false,\n\talphaTest: 0.0,\n\tpolygonOffset: true,\n\tside: THREE.FrontSide,\n\tdithering: true\n});\n\nexport const METAL_MATERIAL = new THREE.MeshPhysicalMaterial({\n\tcolor: new THREE.Color(0x000000),\n\tmetalness: 0.9,\n\troughness: 0.3,\n\tenvMapIntensity: 1.2,\n\tclearcoat: 0.3,\n\tclearcoatRoughness: 0.2,\n\treflectivity: 1,\n\tior: 2.5,\n\tthickness: 1,\n\tdepthWrite: true,\n\ttransparent: false,\n\talphaTest: 0.0,\n\tdepthTest: true,\n\tpolygonOffset: true,\n\tside: THREE.FrontSide,\n\tdithering: true\n});\n\nexport const CONCRETE_MATERIAL = new THREE.MeshPhysicalMaterial({\n\tcolor: new THREE.Color(0xcccccc),\n\tmetalness: 0.0,\n\troughness: 0.92,\n\tenvMapIntensity: 0.15,\n\tclearcoat: 0.05,\n\tclearcoatRoughness: 0.9,\n\treflectivity: 0.15,\n\ttransmission: 0.0,\n\tior: 1.45,\n\tthickness: 0.0,\n\tdepthWrite: true,\n\ttransparent: false,\n\talphaTest: 0.5,\n\tdepthTest: true,\n\tpolygonOffset: true,\n\tside: THREE.FrontSide,\n\tdithering: true\n});\n\nexport const PLASTIC_MATERIAL = new THREE.MeshPhysicalMaterial({\n\tcolor: new THREE.Color(0xffffff), // Default white plastic\n\tmetalness: 0.0,\n\troughness: 0.3,\n\tenvMapIntensity: 0.5,\n\tclearcoat: 0.5,\n\tclearcoatRoughness: 0.1,\n\treflectivity: 0.5,\n\tior: 1.4,\n\ttransmission: 0.0,\n\ttransparent: false,\n\tdepthWrite: true,\n\tside: THREE.FrontSide,\n\tdithering: true,\n\tpolygonOffset: true,\n\tpolygonOffsetFactor: 1,\n\tpolygonOffsetUnits: 1\n});\n\nexport const GLASS_MATERIAL = new THREE.MeshPhysicalMaterial({\n\tcolor: new THREE.Color(0xffffff),\n\tmetalness: 0.0,\n\troughness: 0.0,\n\ttransmission: 0.95,\n\ttransparent: true,\n\topacity: 0.3,\n\tenvMapIntensity: 1.0,\n\tclearcoat: 1.0,\n\tclearcoatRoughness: 0.0,\n\tior: 1.52,\n\treflectivity: 0.9,\n\tthickness: 1.0,\n\tside: THREE.DoubleSide,\n\tpolygonOffset: true,\n\tpolygonOffsetFactor: 1,\n\tpolygonOffsetUnits: 1\n});\n\nexport const RUBBER_MATERIAL = new THREE.MeshPhysicalMaterial({\n\tcolor: new THREE.Color(0x1a1a1a),\n\tmetalness: 0.0,\n\troughness: 0.9,\n\tenvMapIntensity: 0.2,\n\tclearcoat: 0.1,\n\tclearcoatRoughness: 0.8,\n\treflectivity: 0.2,\n\tior: 1.3,\n\ttransmission: 0.0,\n\tdepthWrite: true,\n\tside: THREE.FrontSide,\n\tpolygonOffset: true,\n\tpolygonOffsetFactor: 1,\n\tpolygonOffsetUnits: 1\n});\n\nexport const WOOD_MATERIAL = new THREE.MeshPhysicalMaterial({\n\tcolor: new THREE.Color(0x885533),\n\tmetalness: 0.0,\n\troughness: 0.7,\n\tenvMapIntensity: 0.3,\n\tclearcoat: 0.3,\n\tclearcoatRoughness: 0.4,\n\treflectivity: 0.3,\n\tior: 1.3,\n\ttransmission: 0.0,\n\tdepthWrite: true,\n\tside: THREE.FrontSide,\n\tdithering: true,\n\tpolygonOffset: true,\n\tpolygonOffsetFactor: 1,\n\tpolygonOffsetUnits: 1\n});\n","import { decodeBase64ToBinary } from '@/core/utils/encoding';\nimport { RhinoComputeError, ErrorCodes } from '@/core/errors';\n\nimport type { MaterialGroup, SerializableMaterial } from './types';\n\n// ============================================================================\n// WIRE FORMAT CONSTANTS\n// ============================================================================\n\n/** \"SLVA\" little-endian. */\nexport const BINARY_MESH_MAGIC = 0x41564c53;\n/** Bumped on any wire-layout change. */\nexport const BINARY_MESH_VERSION = 1;\n/** Bit 0 of the geometry flags word: 0 = int16 quantized, 1 = float32 raw. */\nexport const FLAG_FLOAT32 = 0x1;\n\nconst HEADER_PREAMBLE_BYTES = 4 /* magic */ + 4 /* version */ + 4; /* metadataLen */\nconst GEOMETRY_HEADER_BYTES =\n\t4 /* flags */ + 24 /* origin (3 x f64) */ + 24 /* scale (3 x f64) */ + 4; /* vertexCount */\n\n// ============================================================================\n// PARSED TYPES\n// ============================================================================\n\n/**\n * Metadata JSON embedded inside the binary blob.\n *\n * This is the same shape as a `MeshBatch` minus the `compressedData` field (the blob is opaque to\n * its own metadata header). Kept separate from the public `MeshBatch` type because the blob's\n * metadata never carries `compressedData` itself — it would be circular.\n */\nexport interface BinaryMeshMetadata {\n\tmaterials: SerializableMaterial[];\n\tgroups: MaterialGroup[];\n\tsourceComponentId?: string;\n}\n\n/**\n * Result of parsing a binary mesh blob.\n *\n * `vertices` and `indices` are typed-array views over the original `ArrayBuffer` — zero copies.\n * The consumer is responsible for not mutating the underlying buffer if it cares about safety,\n * or for calling `.slice()` to detach.\n */\nexport interface ParsedBinaryMeshBatch {\n\tmetadata: BinaryMeshMetadata;\n\tflags: number;\n\tvertices: Int16Array | Float32Array;\n\tindices: Uint32Array;\n\torigin: [number, number, number];\n\tscale: [number, number, number];\n}\n\n// ============================================================================\n// PARSER\n// ============================================================================\n\n/**\n * Parses a binary mesh batch blob in the SLVA wire format.\n *\n * The blob layout is:\n * ```\n * [4] magic = \"SLVA\" (0x53 0x4C 0x56 0x41)\n * [4] version = uint32 (currently 1)\n * [4] metadataLen = uint32 byte length of UTF-8 metadata JSON\n * [N] metadata = UTF-8 JSON (materials, groups, sourceComponentId, ...)\n * [4] flags = uint32 (bit 0: 0 = int16 quantized, 1 = float32 raw)\n * [24] origin = 3 x float64\n * [24] scale = 3 x float64 (step per int16 unit; identity for float32)\n * [4] vertexCount = uint32 number of vertices (positions = vertexCount * 3 components)\n * [V] vertices = int16[vertexCount*3] OR float32[vertexCount*3]\n * [4] indexCount = uint32 number of indices\n * [I] indices = uint32[indexCount]\n * ```\n *\n * For int16 vertices: world position = `origin + (q + 32767) * scale`. This matches Three.js\n * `BufferAttribute(arr, 3, true)` (`normalized: true`) semantics when the per-mesh transform\n * encodes `origin + scale`.\n *\n * For float32: `origin = (0, 0, 0)`, `scale = (1, 1, 1)`, vertices are raw world positions.\n *\n * @param input - The blob, as either an `ArrayBuffer`/`Uint8Array` (binary transport) or a\n * base64-encoded string (today's JSON-envelope transport).\n * @returns Decoded metadata plus typed-array views into the geometry payload.\n * @throws {RhinoComputeError} On invalid magic, unknown version, or truncated input.\n */\nexport function parseBinaryMeshBatch(\n\tinput: ArrayBuffer | Uint8Array | string\n): ParsedBinaryMeshBatch {\n\tconst bytes = toUint8Array(input);\n\tconst view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n\n\tif (bytes.byteLength < HEADER_PREAMBLE_BYTES) {\n\t\tthrow fail('Blob too small to contain SLVA header.', {\n\t\t\texpectedBytes: HEADER_PREAMBLE_BYTES,\n\t\t\tavailableBytes: bytes.byteLength\n\t\t});\n\t}\n\n\tlet offset = 0;\n\n\tconst magic = view.getUint32(offset, true);\n\toffset += 4;\n\tif (magic !== BINARY_MESH_MAGIC) {\n\t\tthrow fail(`Invalid SLVA magic: 0x${magic.toString(16)}`, {\n\t\t\texpectedMagic: `0x${BINARY_MESH_MAGIC.toString(16)}`,\n\t\t\tactualMagic: `0x${magic.toString(16)}`\n\t\t});\n\t}\n\n\tconst version = view.getUint32(offset, true);\n\toffset += 4;\n\tif (version !== BINARY_MESH_VERSION) {\n\t\tthrow fail(`Unsupported SLVA version: ${version}`, {\n\t\t\texpectedVersion: BINARY_MESH_VERSION,\n\t\t\tactualVersion: version\n\t\t});\n\t}\n\n\tconst metadataLen = view.getUint32(offset, true);\n\toffset += 4;\n\tif (offset + metadataLen > bytes.byteLength) {\n\t\tthrow fail('Insufficient data to read metadata JSON.', {\n\t\t\texpectedBytes: metadataLen,\n\t\t\tavailableBytes: bytes.byteLength - offset,\n\t\t\toffset\n\t\t});\n\t}\n\n\tconst metadataBytes = bytes.subarray(offset, offset + metadataLen);\n\toffset += metadataLen;\n\n\tlet metadata: BinaryMeshMetadata;\n\ttry {\n\t\tmetadata = JSON.parse(decodeUtf8(metadataBytes)) as BinaryMeshMetadata;\n\t} catch (error) {\n\t\tthrow fail(\n\t\t\t`Failed to parse metadata JSON: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t{ metadataLen }\n\t\t);\n\t}\n\n\tif (offset + GEOMETRY_HEADER_BYTES > bytes.byteLength) {\n\t\tthrow fail('Insufficient data to read geometry header.', {\n\t\t\texpectedBytes: GEOMETRY_HEADER_BYTES,\n\t\t\tavailableBytes: bytes.byteLength - offset,\n\t\t\toffset\n\t\t});\n\t}\n\n\tconst flags = view.getUint32(offset, true);\n\toffset += 4;\n\n\tconst originX = view.getFloat64(offset, true);\n\toffset += 8;\n\tconst originY = view.getFloat64(offset, true);\n\toffset += 8;\n\tconst originZ = view.getFloat64(offset, true);\n\toffset += 8;\n\n\tconst scaleX = view.getFloat64(offset, true);\n\toffset += 8;\n\tconst scaleY = view.getFloat64(offset, true);\n\toffset += 8;\n\tconst scaleZ = view.getFloat64(offset, true);\n\toffset += 8;\n\n\tconst vertexCount = view.getUint32(offset, true);\n\toffset += 4;\n\n\tconst useFloat32 = (flags & FLAG_FLOAT32) !== 0;\n\tconst componentCount = vertexCount * 3;\n\tconst bytesPerComponent = useFloat32 ? 4 : 2;\n\tconst verticesByteLength = componentCount * bytesPerComponent;\n\n\tif (offset + verticesByteLength > bytes.byteLength) {\n\t\tthrow fail('Insufficient data to read vertices.', {\n\t\t\texpectedBytes: verticesByteLength,\n\t\t\tavailableBytes: bytes.byteLength - offset,\n\t\t\toffset,\n\t\t\tuseFloat32,\n\t\t\tvertexCount\n\t\t});\n\t}\n\n\t// Typed-array views require alignment to the element size. The header lays out the geometry\n\t// block such that the vertex byte offset is always 4-aligned (preamble 12 + metadataLen + 4 +\n\t// 48 + 4). float32 needs 4-byte alignment (satisfied), int16 needs 2-byte alignment\n\t// (satisfied). We can take a zero-copy view as long as `bytes.byteOffset + offset` agrees with\n\t// that alignment in the underlying buffer — a wrapper Uint8Array could violate it. Fall back\n\t// to a fresh copy if so.\n\tconst absoluteOffset = bytes.byteOffset + offset;\n\tconst verticesView = useFloat32\n\t\t? readFloat32Vertices(bytes.buffer, absoluteOffset, componentCount)\n\t\t: readInt16Vertices(bytes.buffer, absoluteOffset, componentCount);\n\toffset += verticesByteLength;\n\n\tif (offset + 4 > bytes.byteLength) {\n\t\tthrow fail('Insufficient data to read index count.', {\n\t\t\texpectedBytes: 4,\n\t\t\tavailableBytes: bytes.byteLength - offset,\n\t\t\toffset\n\t\t});\n\t}\n\tconst indexCount = view.getUint32(offset, true);\n\toffset += 4;\n\n\tconst indicesByteLength = indexCount * 4;\n\tif (offset + indicesByteLength > bytes.byteLength) {\n\t\tthrow fail('Insufficient data to read indices.', {\n\t\t\texpectedBytes: indicesByteLength,\n\t\t\tavailableBytes: bytes.byteLength - offset,\n\t\t\toffset,\n\t\t\tindexCount\n\t\t});\n\t}\n\n\tconst indicesView = readUint32Indices(bytes.buffer, bytes.byteOffset + offset, indexCount);\n\n\treturn {\n\t\tmetadata,\n\t\tflags,\n\t\tvertices: verticesView,\n\t\tindices: indicesView,\n\t\torigin: [originX, originY, originZ],\n\t\tscale: [scaleX, scaleY, scaleZ]\n\t};\n}\n\n// ============================================================================\n// HELPERS\n// ============================================================================\n\nfunction toUint8Array(input: ArrayBuffer | Uint8Array | string): Uint8Array {\n\tif (typeof input === 'string') {\n\t\treturn decodeBase64ToBinary(input);\n\t}\n\tif (input instanceof Uint8Array) {\n\t\treturn input;\n\t}\n\treturn new Uint8Array(input);\n}\n\nfunction decodeUtf8(bytes: Uint8Array): string {\n\tif (typeof TextDecoder !== 'undefined') {\n\t\treturn new TextDecoder('utf-8').decode(bytes);\n\t}\n\t// Node fallback (Buffer is utf-8 by default).\n\tif (\n\t\ttypeof (globalThis as { Buffer?: { from(b: Uint8Array): { toString(enc: string): string } } })\n\t\t\t.Buffer !== 'undefined'\n\t) {\n\t\treturn (\n\t\t\tglobalThis as { Buffer: { from(b: Uint8Array): { toString(enc: string): string } } }\n\t\t).Buffer.from(bytes).toString('utf-8');\n\t}\n\tthrow new RhinoComputeError(\n\t\t'No UTF-8 decoder available in this environment.',\n\t\tErrorCodes.INVALID_STATE\n\t);\n}\n\nfunction readInt16Vertices(buffer: ArrayBufferLike, byteOffset: number, count: number): Int16Array {\n\tif (count === 0) return new Int16Array(0);\n\tif (byteOffset % 2 === 0) {\n\t\treturn new Int16Array(buffer, byteOffset, count);\n\t}\n\t// Misaligned (rare — would require a wrapper Uint8Array with odd byteOffset).\n\tconst copy = new Uint8Array(count * 2);\n\tcopy.set(new Uint8Array(buffer, byteOffset, count * 2));\n\treturn new Int16Array(copy.buffer);\n}\n\nfunction readFloat32Vertices(\n\tbuffer: ArrayBufferLike,\n\tbyteOffset: number,\n\tcount: number\n): Float32Array {\n\tif (count === 0) return new Float32Array(0);\n\tif (byteOffset % 4 === 0) {\n\t\treturn new Float32Array(buffer, byteOffset, count);\n\t}\n\tconst copy = new Uint8Array(count * 4);\n\tcopy.set(new Uint8Array(buffer, byteOffset, count * 4));\n\treturn new Float32Array(copy.buffer);\n}\n\nfunction readUint32Indices(\n\tbuffer: ArrayBufferLike,\n\tbyteOffset: number,\n\tcount: number\n): Uint32Array {\n\tif (count === 0) return new Uint32Array(0);\n\tif (byteOffset % 4 === 0) {\n\t\treturn new Uint32Array(buffer, byteOffset, count);\n\t}\n\tconst copy = new Uint8Array(count * 4);\n\tcopy.set(new Uint8Array(buffer, byteOffset, count * 4));\n\treturn new Uint32Array(copy.buffer);\n}\n\nfunction fail(message: string, context: Record<string, unknown>): RhinoComputeError {\n\treturn new RhinoComputeError(message, ErrorCodes.VALIDATION_ERROR, { context });\n}\n","import * as THREE from 'three';\n\nimport { parseColor } from '../threejs/three-helpers';\nimport { getLogger } from '@/core';\n\nimport { FLAG_FLOAT32, parseBinaryMeshBatch } from './binary-parser';\n\nimport type { ParsedBinaryMeshBatch } from './binary-parser';\nimport type {\n\tMeshBatch,\n\tMaterialGroup,\n\tMeshBatchParsingOptions,\n\tSerializableMaterial\n} from './types';\n\n/**\n * Internal-only telemetry threaded from an outer entry point (e.g. the JSON\n * `parseMeshBatch` measuring its own `JSON.parse` cost) into the shared build\n * step. Never part of any public options surface — callers don't supply timings.\n */\ninterface ParseTelemetry {\n\tparseTime?: number;\n\tperfStart?: number;\n}\n\n/**\n * Parses a batched mesh JSON and creates Three.js meshes.\n *\n * The geometry payload is the binary \"SLVA\" blob produced by the C# `BinaryGeometryWriter`,\n * base64-encoded into the outer JSON envelope. We `JSON.parse` the small envelope, then hand the\n * blob to `parseBinaryMeshBatch` which decodes the geometry without ever turning it into a string.\n *\n * @param batchJson - JSON string containing the batched mesh data\n * @param options - Rendering options\n * @returns Promise resolving to array of Three.js mesh objects\n */\nexport async function parseMeshBatch(\n\tbatchJson: string,\n\toptions?: MeshBatchParsingOptions\n): Promise<THREE.Mesh[]> {\n\tconst { debug = false } = options ?? {};\n\n\tconst perfStart = debug ? performance.now() : 0;\n\n\ttry {\n\t\tconst parseStart = performance.now();\n\t\tconst batch: MeshBatch = JSON.parse(batchJson);\n\t\tconst parseTime = performance.now() - parseStart;\n\n\t\treturn await parseMeshBatchObject(batch, options, { parseTime, perfStart });\n\t} catch (error) {\n\t\tgetLogger().error('Error parsing mesh batch:', error);\n\t\treturn [];\n\t}\n}\n\n/**\n * Parses a MeshBatch object and creates Three.js meshes.\n *\n * The path is synchronous internally — `parseBinaryMeshBatch` does no IO, just typed-array views\n * over the blob. The function stays `async` so callers don't have to change shape if we move\n * parsing into a worker later.\n *\n * @param batch - MeshBatch object\n * @param options - Rendering options\n * @returns Promise resolving to array of Three.js mesh objects\n */\nexport async function parseMeshBatchObject(\n\tbatch: MeshBatch,\n\toptions?: MeshBatchParsingOptions & {\n\t\t/** Scale factor to apply to meshes (e.g., for unit conversion) */\n\t\tscaleFactor?: number;\n\t},\n\t/** @internal Timings threaded from an outer entry point; not a caller option. */\n\ttelemetry?: ParseTelemetry\n): Promise<THREE.Mesh[]> {\n\tconst {\n\t\tmergeByMaterial = true,\n\t\tapplyTransforms = true,\n\t\tscaleFactor = 1,\n\t\tdebug = false\n\t} = options ?? {};\n\tconst { parseTime = 0, perfStart = debug ? performance.now() : 0 } = telemetry ?? {};\n\n\ttry {\n\t\tconst decodeStart = performance.now();\n\t\tconst parsed = parseBinaryMeshBatch(batch.compressedData);\n\t\tconst decodeTime = performance.now() - decodeStart;\n\n\t\tconst blobBytes = debug ? approximateBase64DecodedBytes(batch.compressedData) : 0;\n\n\t\treturn buildMeshesFromParsed(parsed, {\n\t\t\tmergeByMaterial,\n\t\t\tapplyTransforms,\n\t\t\tscaleFactor,\n\t\t\tdebug,\n\t\t\tparseTime,\n\t\t\tdecodeTime,\n\t\t\tperfStart,\n\t\t\tblobBytes,\n\t\t\tfallback: {\n\t\t\t\tmaterials: batch.materials,\n\t\t\t\tgroups: batch.groups,\n\t\t\t\tsourceComponentId: batch.sourceComponentId\n\t\t\t}\n\t\t});\n\t} catch (error) {\n\t\tgetLogger().error('Error parsing mesh batch object:', error);\n\t\treturn [];\n\t}\n}\n\n/**\n * Parses a raw binary mesh batch blob (SLVA wire format) and creates Three.js meshes.\n *\n * Use this entry point when the blob arrives as a binary WebSocket frame (Phase 1b transport):\n * the JSON envelope no longer carries `displayData`, so there's nothing to `JSON.parse`. The blob\n * is self-describing — materials, groups, and `sourceComponentId` come from its embedded metadata\n * header.\n *\n * @param blob - Raw blob bytes from a binary WebSocket frame.\n * @param options - Rendering options.\n * @returns Promise resolving to array of Three.js mesh objects.\n */\nexport async function parseMeshBatchBlob(\n\tblob: ArrayBuffer | Uint8Array,\n\toptions?: MeshBatchParsingOptions & {\n\t\t/** Scale factor to apply to meshes (e.g., for unit conversion) */\n\t\tscaleFactor?: number;\n\t}\n): Promise<THREE.Mesh[]> {\n\tconst {\n\t\tmergeByMaterial = true,\n\t\tapplyTransforms = true,\n\t\tscaleFactor = 1,\n\t\tdebug = false\n\t} = options ?? {};\n\n\tconst perfStart = debug ? performance.now() : 0;\n\n\ttry {\n\t\tconst decodeStart = performance.now();\n\t\tconst parsed = parseBinaryMeshBatch(blob);\n\t\tconst decodeTime = performance.now() - decodeStart;\n\n\t\tconst blobBytes = blob.byteLength;\n\n\t\treturn buildMeshesFromParsed(parsed, {\n\t\t\tmergeByMaterial,\n\t\t\tapplyTransforms,\n\t\t\tscaleFactor,\n\t\t\tdebug,\n\t\t\tparseTime: 0,\n\t\t\tdecodeTime,\n\t\t\tperfStart,\n\t\t\tblobBytes\n\t\t});\n\t} catch (error) {\n\t\tgetLogger().error('Error parsing mesh batch blob:', error);\n\t\treturn [];\n\t}\n}\n\ninterface BuildOptions {\n\tmergeByMaterial: boolean;\n\tapplyTransforms: boolean;\n\tscaleFactor: number;\n\tdebug: boolean;\n\tparseTime: number;\n\tdecodeTime: number;\n\tperfStart: number;\n\tblobBytes: number;\n\t/** Outer-envelope fallback when the blob's metadata is missing fields (defensive). */\n\tfallback?: {\n\t\tmaterials?: SerializableMaterial[];\n\t\tgroups?: MaterialGroup[];\n\t\tsourceComponentId?: string;\n\t};\n}\n\nfunction buildMeshesFromParsed(\n\tparsed: ParsedBinaryMeshBatch,\n\topts: BuildOptions\n): Promise<THREE.Mesh[]> {\n\tconst {\n\t\tmergeByMaterial,\n\t\tapplyTransforms,\n\t\tscaleFactor,\n\t\tdebug,\n\t\tparseTime,\n\t\tdecodeTime,\n\t\tperfStart,\n\t\tblobBytes,\n\t\tfallback\n\t} = opts;\n\n\tconst materialsSrc = parsed.metadata.materials ?? fallback?.materials ?? [];\n\tconst groups = parsed.metadata.groups ?? fallback?.groups ?? [];\n\tconst sourceComponentId = parsed.metadata.sourceComponentId ?? fallback?.sourceComponentId;\n\n\tconst isFloat32 = (parsed.flags & FLAG_FLOAT32) !== 0;\n\n\t// Dequantize once up-front into a single Float32Array. Downstream code (per-group merging,\n\t// computeVertexNormals, ground-offset, scaleFactor) all expect world-unit floats, and a single\n\t// linear pass over the int16 buffer is far cheaper than the legacy gunzip + base64 path. The\n\t// Z-up -> Y-up rotation, when requested, is folded into the same pass.\n\tconst worldVertices = isFloat32\n\t\t? maybeRotateFloat32Vertices(parsed.vertices as Float32Array, applyTransforms)\n\t\t: dequantizeInt16(parsed.vertices as Int16Array, parsed.origin, parsed.scale, applyTransforms);\n\n\tif (debug) {\n\t\tconst wireBytes = parsed.vertices.byteLength + parsed.indices.byteLength;\n\t\tgetLogger().debug('Mesh Batch Stats:');\n\t\tgetLogger().debug(` Materials: ${materialsSrc.length} | Groups: ${groups.length}`);\n\t\tgetLogger().debug(\n\t\t\t` Vertices: ${parsed.vertices.length / 3} | Indices: ${parsed.indices.length}`\n\t\t);\n\t\tgetLogger().debug(` Format: ${isFloat32 ? 'float32' : 'int16 quantized'}`);\n\t\tgetLogger().debug(\n\t\t\t` Blob: ${(blobBytes / 1024 / 1024).toFixed(2)} MB | Geometry on wire: ${(wireBytes / 1024 / 1024).toFixed(2)} MB`\n\t\t);\n\t}\n\n\tconst meshCreateStart = performance.now();\n\tconst materials = materialsSrc.map(createMaterial);\n\n\tconst meshes: THREE.Mesh[] = [];\n\n\tfor (const group of groups) {\n\t\tif (mergeByMaterial && group.meshes.length > 1) {\n\t\t\tconst mergedMesh = createMergedMesh(group, worldVertices, parsed.indices, materials);\n\t\t\tmergedMesh.userData.sourceComponentId = sourceComponentId ?? null;\n\t\t\tmeshes.push(mergedMesh);\n\t\t} else {\n\t\t\tconst individualMeshes = createIndividualMeshes(\n\t\t\t\tgroup,\n\t\t\t\tworldVertices,\n\t\t\t\tparsed.indices,\n\t\t\t\tmaterials\n\t\t\t);\n\t\t\tfor (const mesh of individualMeshes) {\n\t\t\t\tmesh.userData.sourceComponentId = sourceComponentId ?? null;\n\t\t\t}\n\t\t\tmeshes.push(...individualMeshes);\n\t\t}\n\t}\n\n\tif (scaleFactor !== 1) {\n\t\tfor (const mesh of meshes) {\n\t\t\tmesh.scale.set(scaleFactor, scaleFactor, scaleFactor);\n\t\t}\n\t}\n\n\tconst meshCreateTime = performance.now() - meshCreateStart;\n\n\tif (debug) {\n\t\tconst totalTime = performance.now() - perfStart;\n\t\tgetLogger().debug('Performance:');\n\t\tif (parseTime > 0) getLogger().debug(` Parse JSON: ${parseTime.toFixed(2)}ms`);\n\t\tgetLogger().debug(` Decode binary: ${decodeTime.toFixed(2)}ms`);\n\t\tgetLogger().debug(` Create Meshes: ${meshCreateTime.toFixed(2)}ms`);\n\t\tgetLogger().debug(` Total: ${totalTime.toFixed(2)}ms`);\n\t}\n\n\treturn Promise.resolve(meshes);\n}\n\n// ============================================================================\n// DEQUANTIZATION\n// ============================================================================\n\n/**\n * Reconstructs world-unit float32 positions from int16 quantized values.\n *\n * Mirrors the encoder formula: `world = origin + (q + 32767) * scale`. When\n * `applyCoordinateTransform=true` we fold the Rhino Z-up -> Three Y-up shuffle into the same pass\n * (`(x, y, z) -> (x, z, -y)`), saving a second walk over the buffer.\n */\nfunction dequantizeInt16(\n\tq: Int16Array,\n\torigin: [number, number, number],\n\tscale: [number, number, number],\n\tapplyCoordinateTransform: boolean\n): Float32Array {\n\tconst out = new Float32Array(q.length);\n\tconst ox = origin[0];\n\tconst oy = origin[1];\n\tconst oz = origin[2];\n\tconst sx = scale[0];\n\tconst sy = scale[1];\n\tconst sz = scale[2];\n\n\tif (applyCoordinateTransform) {\n\t\t// Rotate -90 deg around X: (x, y, z) -> (x, z, -y)\n\t\tfor (let i = 0; i < q.length; i += 3) {\n\t\t\tconst wx = ox + (q[i]! + 32767) * sx;\n\t\t\tconst wy = oy + (q[i + 1]! + 32767) * sy;\n\t\t\tconst wz = oz + (q[i + 2]! + 32767) * sz;\n\t\t\tout[i] = wx;\n\t\t\tout[i + 1] = wz;\n\t\t\tout[i + 2] = -wy;\n\t\t}\n\t} else {\n\t\tfor (let i = 0; i < q.length; i += 3) {\n\t\t\tout[i] = ox + (q[i]! + 32767) * sx;\n\t\t\tout[i + 1] = oy + (q[i + 1]! + 32767) * sy;\n\t\t\tout[i + 2] = oz + (q[i + 2]! + 32767) * sz;\n\t\t}\n\t}\n\n\treturn out;\n}\n\n/**\n * For float32 batches: when no transform is needed we can pass through the parser's view; the\n * caller doesn't mutate it. When the rotation is needed we have to allocate.\n */\nfunction maybeRotateFloat32Vertices(\n\tvertices: Float32Array,\n\tapplyCoordinateTransform: boolean\n): Float32Array {\n\tif (!applyCoordinateTransform) return vertices;\n\n\tconst out = new Float32Array(vertices.length);\n\tfor (let i = 0; i < vertices.length; i += 3) {\n\t\tconst x = vertices[i]!;\n\t\tconst y = vertices[i + 1]!;\n\t\tconst z = vertices[i + 2]!;\n\t\tout[i] = x;\n\t\tout[i + 1] = z;\n\t\tout[i + 2] = -y;\n\t}\n\treturn out;\n}\n\n// ============================================================================\n// MATERIAL CONSTRUCTION\n// ============================================================================\n\nfunction createMaterial(matData: SerializableMaterial): THREE.MeshPhysicalMaterial {\n\tconst color = parseColor(matData.color);\n\n\treturn new THREE.MeshPhysicalMaterial({\n\t\tcolor,\n\t\tmetalness: matData.metalness,\n\t\troughness: matData.roughness,\n\t\topacity: matData.opacity,\n\t\ttransparent: matData.transparent,\n\t\tside: THREE.DoubleSide,\n\t\t// Reduced polygon offset to minimize artifacts\n\t\t// Only use minimal offset to prevent z-fighting on coplanar faces\n\t\tpolygonOffset: true,\n\t\tpolygonOffsetFactor: 0.5,\n\t\tpolygonOffsetUnits: 0.5,\n\t\t// Improve depth rendering\n\t\tdepthWrite: true,\n\t\tdepthTest: true\n\t});\n}\n\n// ============================================================================\n// MESH CONSTRUCTION\n// ============================================================================\n\n/**\n * Creates a merged mesh from multiple meshes sharing the same material.\n *\n * Indices in the parser output already reference offsets into the combined vertex array (the C#\n * pipeline rebases per-mesh local indices into combined-array indices when assembling the batch).\n * For merged meshes we copy the relevant slices into a fresh contiguous buffer and shift indices\n * to match the new layout.\n */\nfunction createMergedMesh(\n\tgroup: MaterialGroup,\n\tallVertices: Float32Array,\n\tallIndices: Uint32Array,\n\tmaterials: THREE.Material[]\n): THREE.Mesh {\n\tlet totalVertexCount = 0;\n\tlet totalIndexCount = 0;\n\tfor (const meshMeta of group.meshes) {\n\t\ttotalVertexCount += meshMeta.vertexCount;\n\t\ttotalIndexCount += meshMeta.indexCount;\n\t}\n\n\tconst mergedVertices = new Float32Array(totalVertexCount * 3);\n\tconst mergedIndices = new Uint32Array(totalIndexCount);\n\n\tlet vertexWriteCursor = 0;\n\tlet indexWriteCursor = 0;\n\n\tfor (const meshMeta of group.meshes) {\n\t\tconst componentStart = meshMeta.vertexStart * 3;\n\t\tconst componentLen = meshMeta.vertexCount * 3;\n\t\tmergedVertices.set(\n\t\t\tallVertices.subarray(componentStart, componentStart + componentLen),\n\t\t\tvertexWriteCursor * 3\n\t\t);\n\n\t\tconst indicesSlice = allIndices.subarray(\n\t\t\tmeshMeta.indexStart,\n\t\t\tmeshMeta.indexStart + meshMeta.indexCount\n\t\t);\n\t\tconst indexShift = vertexWriteCursor - meshMeta.vertexStart;\n\t\tif (indexShift === 0) {\n\t\t\tmergedIndices.set(indicesSlice, indexWriteCursor);\n\t\t} else {\n\t\t\tfor (let i = 0; i < indicesSlice.length; i++) {\n\t\t\t\tmergedIndices[indexWriteCursor + i] = indicesSlice[i]! + indexShift;\n\t\t\t}\n\t\t}\n\n\t\tvertexWriteCursor += meshMeta.vertexCount;\n\t\tindexWriteCursor += meshMeta.indexCount;\n\t}\n\n\tconst geometry = new THREE.BufferGeometry();\n\tgeometry.setAttribute('position', new THREE.BufferAttribute(mergedVertices, 3));\n\tgeometry.setIndex(new THREE.BufferAttribute(mergedIndices, 1));\n\tgeometry.computeVertexNormals();\n\n\tconst threeMesh = new THREE.Mesh(geometry, materials[group.materialId]);\n\tconst firstMesh = group.meshes[0];\n\tconst meshNames = group.meshes.map((m) => m.name).filter((name) => name && name.length > 0);\n\tthreeMesh.name = meshNames.length > 0 ? meshNames[0]! : `merged_material_${group.materialId}`;\n\tthreeMesh.castShadow = true;\n\tthreeMesh.receiveShadow = true;\n\n\tthreeMesh.userData = {\n\t\tname: threeMesh.name,\n\t\tlayer: firstMesh?.layer ?? '',\n\t\toriginalIndex: firstMesh?.originalIndex ?? 0,\n\t\tmetadata: firstMesh?.metadata ?? {},\n\t\tmergedFrom: group.meshes.slice(1).map((m) => ({\n\t\t\tname: m.name,\n\t\t\tlayer: m.layer,\n\t\t\toriginalIndex: m.originalIndex\n\t\t}))\n\t};\n\n\treturn threeMesh;\n}\n\n/**\n * Creates individual meshes from a material group. Each mesh's indices are rebased so they\n * address its own local vertex slice starting from 0.\n */\nfunction createIndividualMeshes(\n\tgroup: MaterialGroup,\n\tallVertices: Float32Array,\n\tallIndices: Uint32Array,\n\tmaterials: THREE.Material[]\n): THREE.Mesh[] {\n\tconst meshes: THREE.Mesh[] = [];\n\n\tfor (const meshMeta of group.meshes) {\n\t\tconst componentStart = meshMeta.vertexStart * 3;\n\t\tconst componentLen = meshMeta.vertexCount * 3;\n\n\t\t// `subarray` returns a view; copy via `slice` so the BufferAttribute owns its memory and\n\t\t// downstream code (dispose/reuse) can't surprise us by sharing the parser's buffer.\n\t\tconst vertices = allVertices.slice(componentStart, componentStart + componentLen);\n\n\t\tconst indicesSlice = allIndices.subarray(\n\t\t\tmeshMeta.indexStart,\n\t\t\tmeshMeta.indexStart + meshMeta.indexCount\n\t\t);\n\t\tconst rebasedIndices = new Uint32Array(indicesSlice.length);\n\t\tconst baseIndex = meshMeta.vertexStart;\n\t\tfor (let i = 0; i < indicesSlice.length; i++) {\n\t\t\trebasedIndices[i] = indicesSlice[i]! - baseIndex;\n\t\t}\n\n\t\tconst geometry = new THREE.BufferGeometry();\n\t\tgeometry.setAttribute('position', new THREE.BufferAttribute(vertices, 3));\n\t\tgeometry.setIndex(new THREE.BufferAttribute(rebasedIndices, 1));\n\t\tgeometry.computeVertexNormals();\n\n\t\tconst mesh = new THREE.Mesh(geometry, materials[group.materialId]);\n\t\tmesh.name = meshMeta.name;\n\t\tmesh.userData = {\n\t\t\tname: meshMeta.name,\n\t\t\tlayer: meshMeta.layer ?? '',\n\t\t\toriginalIndex: meshMeta.originalIndex,\n\t\t\tmetadata: meshMeta.metadata ?? {}\n\t\t};\n\t\tmesh.castShadow = true;\n\t\tmesh.receiveShadow = true;\n\n\t\tmeshes.push(mesh);\n\t}\n\n\treturn meshes;\n}\n\n// ============================================================================\n// DEBUG HELPERS\n// ============================================================================\n\nfunction approximateBase64DecodedBytes(base64: string): number {\n\treturn Math.floor((base64.length * 3) / 4);\n}\n","import * as THREE from 'three';\n\nimport { applyOffset, computeCombinedBoundingBox } from '../threejs/three-helpers.js';\nimport { getLogger } from '@/core';\n\nimport { parseMeshBatch } from './batch-parser';\n\nimport type { DataItem, GrasshopperComputeResponse } from '@/features/grasshopper/types';\nimport type { MeshExtractionOptions, MeshBatchParsingOptions } from './types';\n\n// Constants\nexport const SCALE_FACTORS: Record<string, number> = {\n\tMillimeters: 1 / 1000,\n\tCentimeters: 1 / 100,\n\tMeters: 1,\n\tInches: 1 / 39.37,\n\tFeet: 1 / 3.28084\n};\n\nconst DISPLAY_COMPONENT_TYPE = 'Display';\n\n/**\n * Extracts and processes display meshes from a ComputePointerResponse using the Grasshopper WebDisplay component.\n *\n * This is the primary entry point for extracting mesh geometry from Grasshopper compute responses.\n * It handles all aspects of mesh processing: decompression, coordinate transformation, scaling, and positioning.\n *\n * **Note:** Mesh decompression happens asynchronously in a Web Worker to prevent UI blocking.\n *\n * @param data - The ComputePointerResponse containing Grasshopper output trees.\n * @param options - Configuration for mesh extraction and parsing behavior. All options are optional with sensible defaults.\n * @returns Promise resolving to array of THREE.Mesh objects (may be empty).\n * @throws Rethrows unexpected errors after attempting to dispose any created meshes.\n *\n * @remarks\n * - Only works with the WebDisplay component of GHHeadless.\n * - Requires changes to Rhino.Compute (see https://github.com/TheVessen/compute.rhino3d).\n * - Provides a performant way to display mesh data in Three.js.\n * - Decompression is performed in a Web Worker for non-blocking UI updates.\n * - Supports mesh metadata (names, user data) if provided in the compute response.\n *\n * @internal Internal helper: high-level extraction remains public via visualization module, but this\n * function is considered internal implementation detail for mesh extraction.\n *\n * @example\n * ```ts\n * // Simple usage with defaults (all processing enabled)\n * const meshes = await getThreeMeshesFromComputeResponse(response);\n *\n * // With debugging enabled\n * const meshes = await getThreeMeshesFromComputeResponse(response, { debug: true });\n *\n * // With advanced options\n * const meshes = await getThreeMeshesFromComputeResponse(response, {\n * debug: true,\n * allowScaling: true,\n * allowAutoPosition: false,\n * parsing: {\n * mergeByMaterial: false,\n * applyTransforms: true,\n * debug: true,\n * },\n * });\n * ```\n */\nexport async function getThreeMeshesFromComputeResponse(\n\tdata: GrasshopperComputeResponse,\n\toptions?: MeshExtractionOptions\n): Promise<THREE.Mesh[]> {\n\tconst startTime = performance.now();\n\tconst meshes: THREE.Mesh[] = [];\n\n\tconst {\n\t\tallowScaling = true,\n\t\tallowAutoPosition = true,\n\t\tdebug = false,\n\t\tparsing: parsingOptions = {}\n\t} = options ?? {};\n\n\ttry {\n\t\tconst scaleFactor = allowScaling ? getScaleFactor(data.modelunits) : 1;\n\t\tawait extractMeshesFromData(data, meshes, scaleFactor, parsingOptions, debug);\n\n\t\tif (allowAutoPosition) {\n\t\t\tapplyGroundOffset(meshes);\n\t\t}\n\n\t\treturn meshes;\n\t} catch (error) {\n\t\thandleError(error, meshes);\n\t\tthrow error;\n\t} finally {\n\t\tif (debug) {\n\t\t\tlogProcessingTime(startTime);\n\t\t}\n\t}\n}\n\n/**\n * Gets the scale factor for the given unit type.\n */\nfunction getScaleFactor(modelUnits: string): number {\n\treturn SCALE_FACTORS[modelUnits] ?? 1;\n}\n\n/**\n * Extracts meshes from compute response data.\n */\nasync function extractMeshesFromData(\n\tdata: GrasshopperComputeResponse,\n\tmeshes: THREE.Mesh[],\n\tscaleFactor: number,\n\tparsingOptions: MeshBatchParsingOptions,\n\tdebug: boolean\n): Promise<void> {\n\tfor (const value of data.values) {\n\t\tconst innerTree = value.InnerTree as { [key: string]: DataItem[] };\n\n\t\tfor (const path in innerTree) {\n\t\t\tconst branch = innerTree[path];\n\t\t\tif (!branch) continue;\n\n\t\t\tawait processDataBranch(branch, meshes, scaleFactor, parsingOptions, debug);\n\t\t}\n\t}\n}\n\n/**\n * Processes a single data branch to extract MeshBatch display meshes.\n */\nasync function processDataBranch(\n\tbranch: DataItem[],\n\tmeshes: THREE.Mesh[],\n\tscaleFactor: number,\n\tparsingOptions: MeshBatchParsingOptions,\n\tdebug: boolean\n): Promise<void> {\n\tfor (const item of branch) {\n\t\tif (item.type.includes(DISPLAY_COMPONENT_TYPE)) {\n\t\t\tconst mergedParsingOptions = {\n\t\t\t\tmergeByMaterial: true,\n\t\t\t\tapplyTransforms: true,\n\t\t\t\tdebug: false,\n\t\t\t\t...parsingOptions\n\t\t\t};\n\n\t\t\tconst batchMeshes = await parseMeshBatch(item.data, mergedParsingOptions);\n\n\t\t\tif (scaleFactor !== 1) {\n\t\t\t\tfor (const mesh of batchMeshes) {\n\t\t\t\t\tmesh.scale.set(scaleFactor, scaleFactor, scaleFactor);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tmeshes.push(...batchMeshes);\n\n\t\t\tif (debug) {\n\t\t\t\tgetLogger().debug(`Extracted ${batchMeshes.length} meshes from batch`);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Applies vertical offset to position meshes on the Z=0 plane.\n */\nfunction applyGroundOffset(meshes: THREE.Mesh[]): void {\n\tif (meshes.length === 0) return;\n\n\tconst combinedBoundingBox = computeCombinedBoundingBox(meshes);\n\tconst offsetY = combinedBoundingBox.min.y;\n\tapplyOffset(meshes, offsetY);\n}\n\n/**\n * Handles errors by disposing created meshes and logging.\n */\nfunction handleError(error: unknown, meshes: THREE.Mesh[]): void {\n\tgetLogger().error('An unexpected error occurred:', error);\n\tdisposeMeshes(meshes);\n}\n\n/**\n * Disposes of all meshes and their associated resources.\n */\nfunction disposeMeshes(meshes: THREE.Mesh[]): void {\n\tfor (const mesh of meshes) {\n\t\tif (mesh.geometry) {\n\t\t\tmesh.geometry.dispose();\n\t\t}\n\n\t\tif (mesh.material) {\n\t\t\tif (Array.isArray(mesh.material)) {\n\t\t\t\tmesh.material.forEach((material) => material.dispose());\n\t\t\t} else {\n\t\t\t\tmesh.material.dispose();\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Logs the processing time for mesh extraction.\n */\nfunction logProcessingTime(startTime: number): void {\n\tconst elapsed = performance.now() - startTime;\n\tgetLogger().info('Time to process meshes:', `${elapsed.toFixed(2)}ms`);\n}\n"],"mappings":"qEAAA,UAAYA,MAAW,QACvB,OAAS,iBAAAC,OAAqB,yCAC9B,OAAS,aAAAC,OAAiB,oCAK1B,IAAMC,EAAY,IAAU,UAAQ,EAAG,EAAG,CAAC,EAGrCC,EAAgB,CAACC,EAAeC,EAAeC,EAAeC,IAAyB,CAC5F,OAAQH,EAAO,CACd,IAAK,KACJ,OAAOC,EACR,IAAK,KACJ,OAAOC,EACR,QACC,OAAOC,CACT,CACD,EAKaC,GAAY,SACxBC,EACAC,EASC,CACD,IAAMC,EAASC,GAAcF,GAAW,CAAC,CAAC,EAEpCG,EAAQC,GAAYH,CAAM,EAC1BI,EAASC,GAAaL,EAAQF,CAAM,EACpCQ,EAAWC,GAAcT,EAAQE,CAAM,EACvCQ,EAAWC,GAAcL,EAAQN,EAAQE,CAAM,EAErDU,GAAiBR,EAAOF,CAAM,EAC9BW,GAAcT,EAAOF,CAAM,EAEvBA,EAAO,OAAO,SACjBY,GAASV,EAAOF,CAAM,EAGvB,IAAMa,EACLb,EAAO,OAAO,sBAAwB,GACnCc,GAAmBhB,EAAQI,EAAOE,EAAQI,EAAUR,CAAM,EAC1D,CAAE,QAAS,IAAM,CAAC,EAAG,UAAW,IAAM,CAAC,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CAAC,IAAI,CACtE","names":["THREE","OrbitControls","HDRLoader","defaultUp","getScaleValue","scale","mmVal","cmVal","mVal","initThree","canvas","options","config","applyDefaults","scene","createScene","camera","createCamera","renderer","setupRenderer","controls","setupControls","setupEnvironment","setupLighting","addFloor","eventHandlers","setupEventHandlers","parent","getCanvasSize","animate","disposeAnimation","createAnimationLoop","sceneUp","object","material","defaults","bgColor","animateCameraTo","toPosition","toTarget","durationMs","fromPosition","fromTarget","startTime","easeOut","t","tick","elapsed","onFrame","animationId","lastTime","checkResize","width","height","pixelRatio","newW","newH","now","delta","HDRLoader","envMap","error","getLogger","ambientLight","sunlight","pos","shadowSize","shadowNear","shadowFar","floorSize","floorGeometry","floorColor","floorMaterial","floor","selectedObjects","originalMaterials","raycaster","mouse","mouseDownPosition","isFullyVisible","current","fitToView","box","center","size","maxDim","fov","distance","direction","selectionColorObj","clearSelection","obj","handleMouseDown","event","handleCanvasClick","currentMousePosition","rect","intersects","i","clickedObject","clonedMaterial","handleDoubleClick","target","targetPosition","handleKeydown","OrbitControls","THREE","CAMERA_CONFIG","updateScene","scene","meshes","camera","controls","initialPositionSet","clearScene","mesh","unionBoundingBox","computeCombinedBoundingBox","center","size","maxDim","distance","parseColor","colorString","getLogger","trimmed","hex","rgb","c","n","applyOffset","offsetY","combinedBoundingBox","bbox","object","child","material","value","three_materials_exports","__export","CONCRETE_MATERIAL","EMISSIVE_MATERIAL","GLASS_MATERIAL","METAL_MATERIAL","PLASTIC_MATERIAL","RUBBER_MATERIAL","WOOD_MATERIAL","THREE","BINARY_MESH_MAGIC","BINARY_MESH_VERSION","FLAG_FLOAT32","HEADER_PREAMBLE_BYTES","GEOMETRY_HEADER_BYTES","parseBinaryMeshBatch","input","bytes","toUint8Array","view","fail","offset","magic","version","metadataLen","metadataBytes","metadata","decodeUtf8","error","flags","originX","originY","originZ","scaleX","scaleY","scaleZ","vertexCount","useFloat32","componentCount","verticesByteLength","absoluteOffset","verticesView","readFloat32Vertices","readInt16Vertices","indexCount","indicesByteLength","indicesView","readUint32Indices","decodeBase64ToBinary","RhinoComputeError","ErrorCodes","buffer","byteOffset","count","copy","message","context","THREE","parseMeshBatch","batchJson","options","debug","perfStart","parseStart","batch","parseTime","parseMeshBatchObject","error","getLogger","telemetry","mergeByMaterial","applyTransforms","scaleFactor","decodeStart","parsed","parseBinaryMeshBatch","decodeTime","blobBytes","approximateBase64DecodedBytes","buildMeshesFromParsed","parseMeshBatchBlob","blob","opts","fallback","materialsSrc","groups","sourceComponentId","isFloat32","FLAG_FLOAT32","worldVertices","maybeRotateFloat32Vertices","dequantizeInt16","wireBytes","meshCreateStart","materials","createMaterial","meshes","group","mergedMesh","createMergedMesh","individualMeshes","createIndividualMeshes","mesh","meshCreateTime","totalTime","q","origin","scale","applyCoordinateTransform","out","ox","oy","oz","sx","sy","sz","i","wx","wy","wz","vertices","x","y","z","matData","color","parseColor","allVertices","allIndices","totalVertexCount","totalIndexCount","meshMeta","mergedVertices","mergedIndices","vertexWriteCursor","indexWriteCursor","componentStart","componentLen","indicesSlice","indexShift","geometry","threeMesh","firstMesh","meshNames","m","name","rebasedIndices","baseIndex","base64","SCALE_FACTORS","DISPLAY_COMPONENT_TYPE","getThreeMeshesFromComputeResponse","data","options","startTime","meshes","allowScaling","allowAutoPosition","debug","parsingOptions","scaleFactor","getScaleFactor","extractMeshesFromData","applyGroundOffset","error","handleError","logProcessingTime","modelUnits","value","innerTree","path","branch","processDataBranch","item","mergedParsingOptions","batchMeshes","parseMeshBatch","mesh","getLogger","offsetY","computeCombinedBoundingBox","applyOffset","disposeMeshes","material","elapsed"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-YNVXBKBY.cjs","../src/core/utils/read-field.ts","../src/core/utils/warnings.ts","../src/features/grasshopper/solve.ts"],"names":["readField","obj","name","record","lower","key","hasField","warnIfClientSide","functionName","suppress","getLogger","DEFINITION_LOAD_FAILED","isDefinitionLoadMiss","error","RhinoComputeError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EAAAA,CAAqBC,CAAAA,CAAyB,CACtD,OAAOA,EAAAA,WAAiBC,mBAAAA,EAAqBD,CAAAA,CAAM,OAAA,CAAQ,QAAA,CAASF,EAAsB,CAC3F,CAeO,SAASI,CAAAA,CAAsBC,CAAAA,CAAsCC,CAAAA,CAAuB,CAClG,EAAA,CAAI,CAACA,CAAAA,CAAO,MAAA,CAEZ,IAAMC,CAAAA,CAASlB,CAAAA,CAAqBgB,CAAAA,CAAU,QAAQ,CAAA,CACtD,EAAA,CAAI,CAAC,KAAA,CAAM,OAAA,CAAQE,CAAM,CAAA,EAAKA,CAAAA,CAAO,MAAA,GAAW,CAAA,CAAG,MAAA,CAEnD,IAAMC,CAAAA,CAAkB,CAAC,CAAA,CACzB,GAAA,CAAA,IAAWC,EAAAA,GAASF,CAAAA,CAAQ,CAC3B,IAAMG,CAAAA,CAAYrB,CAAAA,CAAmCoB,CAAAA,CAAO,WAAW,CAAA,CAAA,CAEnE,CAACC,CAAAA,EAAa,MAAA,CAAO,IAAA,CAAKA,CAAS,CAAA,CAAE,MAAA,GAAW,CAAA,CAAA,EACnDF,CAAAA,CAAM,IAAA,kBAAKnB,CAAAA,CAAkBoB,CAAAA,CAAO,WAAW,CAAA,SAAK,aAAW,CAEjE,CAEA,EAAA,CAAID,CAAAA,CAAM,MAAA,GAAW,CAAA,CAAG,MAAA,CAExB,IAAMG,CAAAA,CAAQH,CAAAA,CAAM,MAAA,GAAWD,CAAAA,CAAO,MAAA,CAAS,KAAA,CAAQ,CAAA,EAAA","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-YNVXBKBY.cjs","sourcesContent":[null,"/**\n * Case-insensitive single-key reader for wire payloads.\n *\n * The Rhino Compute family serializes the same logical field with different\n * casing depending on the server branch:\n *\n * - mcneel 8.x / 9.x: the IO schema is PascalCase (`ParamType`, `Default`,\n * `InnerTree`, …) because those C# classes carry no `[JsonProperty]`.\n * - VektorNode Compute8: the IO schema is camelCase (`paramType`, `default`,\n * …) because the fork added `[JsonProperty(\"camelCase\")]`, BUT the nested\n * `default` DataTree wrapper stays PascalCase (`ParamName` / `InnerTree`)\n * since `Resthopper.IO.DataTree` is an external type the fork can't attribute.\n *\n * So a single response can mix casings, and which casing a given field uses\n * depends on the server branch. Rather than deep-camelCasing the whole payload\n * (the old `camelcaseKeys` approach — which corrupted user-authored value-list\n * label keys and item `data` JSON), read the specific fields we care about\n * case-insensitively and leave everything else verbatim.\n *\n * Prefers an exact-case match when present, then falls back to the first\n * case-insensitive match. Returns `undefined` when no key matches.\n *\n * @param obj - The source object (any non-object input yields `undefined`).\n * @param name - The logical field name, in any casing.\n */\nexport function readField<T = unknown>(obj: unknown, name: string): T | undefined {\n\tif (!obj || typeof obj !== 'object') return undefined;\n\n\tconst record = obj as Record<string, unknown>;\n\tif (name in record) return record[name] as T;\n\n\tconst lower = name.toLowerCase();\n\tfor (const key of Object.keys(record)) {\n\t\tif (key.toLowerCase() === lower) return record[key] as T;\n\t}\n\treturn undefined;\n}\n\n/**\n * True when `obj` has a key matching `name` (case-insensitively). Distinguishes\n * \"field present but value is null/undefined\" from \"field absent\" — needed where\n * presence itself carries meaning (e.g. an `innerTree` that exists but is empty).\n */\nexport function hasField(obj: unknown, name: string): boolean {\n\tif (!obj || typeof obj !== 'object') return false;\n\tconst record = obj as Record<string, unknown>;\n\tif (name in record) return true;\n\tconst lower = name.toLowerCase();\n\treturn Object.keys(record).some((key) => key.toLowerCase() === lower);\n}\n","import { getLogger } from './logger';\n\nexport function warnIfClientSide(functionName: string, suppress?: boolean): void {\n\tif (suppress) {\n\t\treturn;\n\t}\n\n\tif (typeof window !== 'undefined') {\n\t\tgetLogger().warn(\n\t\t\t`Warning: ${functionName} is running on the client side. For better performance and security, consider running this on the server side.`\n\t\t);\n\t}\n}\n","import { fetchRhinoCompute, RhinoComputeError } from '@/core';\nimport { base64ByteArray, encodeStringToBase64, isBase64 } from '@/core/utils/encoding';\nimport { getLogger } from '@/core/utils/logger';\nimport { readField } from '@/core/utils/read-field';\nimport { warnIfClientSide } from '@/core/utils/warnings';\n\nimport {\n\tGrasshopperRequestSchema,\n\tGrasshopperComputeConfig,\n\tGrasshopperComputeResponse,\n\tDataTree\n} from './types';\n\n/**\n * The exact message the server throws when it can neither resolve a `pointer`\n * nor a base64 `algo` to a definition (ResthopperEndpoints.cs). This is the\n * signal that a cache-key pointer missed the server's definition cache (GC'd, or\n * a different child in the pool), so the caller should retry with the full\n * definition. Matched as a substring because the server wraps it with a category\n * prefix in its exception handler.\n */\nconst DEFINITION_LOAD_FAILED = 'Unable to load grasshopper definition';\n\n/** Does this error look like a server-side definition-load miss? */\nfunction isDefinitionLoadMiss(error: unknown): boolean {\n\treturn error instanceof RhinoComputeError && error.message.includes(DEFINITION_LOAD_FAILED);\n}\n\n/**\n * Debug aid: a solve can return successfully yet hand back outputs whose\n * `InnerTree` is empty (`{}`), meaning that parameter produced nothing — often a\n * sign the definition didn't actually compute (wrong/missing inputs, a guarded\n * branch). The names tell you exactly which output was empty so you can trace it\n * back to the responsible branch.\n *\n * Only logs when `debug` is set: an empty output can be legitimate, so this is a\n * diagnostic, never a hard failure. Reads `ParamName` / `InnerTree`\n * case-insensitively to stay robust across server-branch casing.\n *\n * @internal Exported for testing.\n */\nexport function warnOnEmptyInnerTrees(response: GrasshopperComputeResponse, debug?: boolean): void {\n\tif (!debug) return;\n\n\tconst values = readField<unknown[]>(response, 'values');\n\tif (!Array.isArray(values) || values.length === 0) return;\n\n\tconst empty: string[] = [];\n\tfor (const param of values) {\n\t\tconst innerTree = readField<Record<string, unknown>>(param, 'innerTree');\n\t\t// Treat a missing or empty innerTree as \"produced nothing\".\n\t\tif (!innerTree || Object.keys(innerTree).length === 0) {\n\t\t\tempty.push(readField<string>(param, 'paramName') ?? '<unnamed>');\n\t\t}\n\t}\n\n\tif (empty.length === 0) return;\n\n\tconst scope = empty.length === values.length ? 'all' : `${empty.length}/${values.length}`;\n\tgetLogger().warn(\n\t\t`Solve returned empty output(s) (${scope}): ${empty.join(', ')}. ` +\n\t\t\t`These parameters produced no data — check the definition's inputs and the branch feeding each.`\n\t);\n}\n\n/**\n * Result of a solve that also reports the definition's server-side cache key.\n *\n * `cacheKey` is the `md5_…` identifier the server assigned to the (base64)\n * definition — stable for identical content. A caller that holds it can solve\n * the same definition again by reference (`pointer: cacheKey`) instead of\n * re-uploading the full base64, which matters a lot for large (multi-MB)\n * definitions on a live UI. `null` when the server didn't return one (e.g. a\n * URL-pointer solve).\n */\nexport interface SolveWithCacheKey {\n\tresponse: GrasshopperComputeResponse;\n\tcacheKey: string | null;\n}\n\n/**\n * Runs a Rhino Compute job using the provided tree prototypes and Grasshopper definition.\n *\n * @public Use this for direct compute control. For high-level API, use `GrasshopperClient.solve()`.\n *\n * @param dataTree - An array of `DataTree` objects representing the input data for the compute job.\n * @param definition - The Grasshopper definition, which can be:\n * - A URL string (e.g., 'https://example.com/definition.gh')\n * - A base64-encoded string of the .gh file\n * - A plain string (will be base64-encoded)\n * - A Uint8Array of the .gh file (will be base64-encoded)\n * @param config - Compute configuration (server URL, API key, etc. along with optional timeout, units, etc.)\n * @returns An object containing the compute result and extracted file data.\n *\n * @example\n * // Using a URL\n * await solveGrasshopperDefinition(trees, 'https://example.com/definition.gh', config);\n *\n * // Using a base64 string\n * await solveGrasshopperDefinition(trees, 'UEsDBBQAAAAIAL...', config);\n *\n * // Using binary data\n * const fileData = new Uint8Array([...]);\n * await solveGrasshopperDefinition(trees, fileData, config);\n */\nexport async function solveGrasshopperDefinition(\n\tdataTree: DataTree[],\n\tdefinition: string | Uint8Array,\n\tconfig: GrasshopperComputeConfig\n): Promise<GrasshopperComputeResponse> {\n\tif (config.debug) {\n\t\twarnIfClientSide(\n\t\t\t'solveGrasshopperDefinition',\n\t\t\tconfig.suppressBrowserWarning ?? config.suppressClientSideWarning\n\t\t);\n\t}\n\n\tconst { response } = await runSolve(prepareGrasshopperArgs(definition, dataTree), config);\n\treturn response;\n}\n\n/**\n * Solve while reporting the server's definition cache key.\n *\n * Behaves like {@link solveGrasshopperDefinition} but returns the `cacheKey` the\n * server assigned, so a caller (e.g. the scheduler) can later solve the same\n * definition by reference instead of re-uploading it. The cache key is only\n * meaningful for base64/binary definitions; a URL-pointer solve returns the URL.\n *\n * @internal\n */\nexport async function solveGrasshopperDefinitionWithCacheKey(\n\tdataTree: DataTree[],\n\tdefinition: string | Uint8Array,\n\tconfig: GrasshopperComputeConfig\n): Promise<SolveWithCacheKey> {\n\tif (config.debug) {\n\t\twarnIfClientSide(\n\t\t\t'solveGrasshopperDefinitionWithCacheKey',\n\t\t\tconfig.suppressBrowserWarning ?? config.suppressClientSideWarning\n\t\t);\n\t}\n\n\treturn runSolve(prepareGrasshopperArgs(definition, dataTree), config);\n}\n\n/**\n * Solve a definition by its server-side cache key (`pointer: cacheKey`),\n * skipping the (potentially multi-MB) base64 upload. If the key has been evicted\n * from the server's definition cache — `DEFINITION_LOAD_FAILED` — transparently\n * retry once with the full `definition` and report the fresh cache key so the\n * caller can update its mapping.\n *\n * @returns The solve result plus the (possibly refreshed) cache key, and whether\n * the fast path missed (so callers can record the new key / track hit rate).\n * @internal\n */\nexport async function solveByCacheKey(\n\tdataTree: DataTree[],\n\tcacheKey: string,\n\tdefinition: string | Uint8Array,\n\tconfig: GrasshopperComputeConfig\n): Promise<SolveWithCacheKey & { missed: boolean }> {\n\tif (config.debug) {\n\t\twarnIfClientSide(\n\t\t\t'solveByCacheKey',\n\t\t\tconfig.suppressBrowserWarning ?? config.suppressClientSideWarning\n\t\t);\n\t}\n\n\tconst pointerArgs: GrasshopperRequestSchema = { algo: null, pointer: cacheKey, values: dataTree };\n\n\ttry {\n\t\tconst fast = await runSolve(pointerArgs, config);\n\t\treturn { ...fast, missed: false };\n\t} catch (error) {\n\t\tif (!isDefinitionLoadMiss(error)) throw error;\n\t\t// Cache miss — fall back to the full upload and capture the fresh key.\n\t\tconst full = await runSolve(prepareGrasshopperArgs(definition, dataTree), config);\n\t\treturn { ...full, missed: true };\n\t}\n}\n\n/**\n * Shared solve body: apply optional settings, POST, and split the server's\n * `pointer` (its cache key) off the response. Stripping via shallow copy rather\n * than `delete` keeps any already-observed response object unmutated.\n */\nasync function runSolve(\n\targs: GrasshopperRequestSchema,\n\tconfig: GrasshopperComputeConfig\n): Promise<SolveWithCacheKey> {\n\tapplyOptionalComputeSettings(args, config);\n\n\tconst result = await fetchRhinoCompute<GrasshopperComputeResponse>('grasshopper', args, config);\n\n\tif ('pointer' in result) {\n\t\tconst { pointer, ...rest } = result as GrasshopperComputeResponse & { pointer?: unknown };\n\t\tconst response = rest as GrasshopperComputeResponse;\n\t\twarnOnEmptyInnerTrees(response, config.debug);\n\t\treturn {\n\t\t\tresponse,\n\t\t\tcacheKey: typeof pointer === 'string' ? pointer : null\n\t\t};\n\t}\n\n\twarnOnEmptyInnerTrees(result, config.debug);\n\treturn { response: result, cacheKey: null };\n}\n\n// ============================================================================\n// Grasshopper Arguments\n// ============================================================================\n\n/**\n * Prepares Grasshopper arguments from a definition and data tree.\n * Automatically detects the definition format and converts it appropriately.\n *\n * @param definition - Can be a URL, base64 string, plain string, or Uint8Array\n * @param dataTree - Array of DataTree objects for compute inputs\n * @internal\n */\nexport function prepareGrasshopperArgs(\n\tdefinition: string | Uint8Array,\n\tdataTree: DataTree[]\n): GrasshopperRequestSchema {\n\tconst args: GrasshopperRequestSchema = {\n\t\talgo: null,\n\t\tpointer: null,\n\t\tvalues: dataTree\n\t};\n\n\tif (definition instanceof Uint8Array) {\n\t\t// Binary data → convert to base64\n\t\targs.algo = base64ByteArray(definition);\n\t} else if (/^https?:\\/\\//i.test(definition)) {\n\t\t// URL → use as pointer reference\n\t\targs.pointer = definition;\n\t} else if (isBase64(definition)) {\n\t\t// Already base64 → use as-is\n\t\targs.algo = definition;\n\t} else {\n\t\t// Plain string → encode to base64\n\t\targs.algo = encodeStringToBase64(definition);\n\t}\n\n\treturn args;\n}\n\n/**\n * @internal\n */\nexport function applyOptionalComputeSettings(\n\targlist: GrasshopperRequestSchema,\n\toptions: GrasshopperComputeConfig\n): void {\n\tif (options.cachesolve != null) arglist.cachesolve = options.cachesolve;\n\tif (options.modelunits != null) arglist.modelunits = options.modelunits;\n\tif (options.angletolerance != null) arglist.angletolerance = options.angletolerance;\n\tif (options.absolutetolerance != null) arglist.absolutetolerance = options.absolutetolerance;\n\tif (options.dataversion != null) arglist.dataversion = options.dataversion;\n}\n"]}
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkJFLD2UCYcjs = require('./chunk-JFLD2UCY.cjs');require('./chunk-MA6YB3YZ.cjs');exports.BINARY_MESH_MAGIC = _chunkJFLD2UCYcjs.g; exports.BINARY_MESH_VERSION = _chunkJFLD2UCYcjs.h; exports.FLAG_FLOAT32 = _chunkJFLD2UCYcjs.i; exports.Materials = _chunkJFLD2UCYcjs.f; exports.SCALE_FACTORS = _chunkJFLD2UCYcjs.n; exports.applyOffset = _chunkJFLD2UCYcjs.d; exports.computeCombinedBoundingBox = _chunkJFLD2UCYcjs.e; exports.getThreeMeshesFromComputeResponse = _chunkJFLD2UCYcjs.o; exports.initThree = _chunkJFLD2UCYcjs.a; exports.parseBinaryMeshBatch = _chunkJFLD2UCYcjs.j; exports.parseColor = _chunkJFLD2UCYcjs.c; exports.parseMeshBatch = _chunkJFLD2UCYcjs.k; exports.parseMeshBatchBlob = _chunkJFLD2UCYcjs.m; exports.parseMeshBatchObject = _chunkJFLD2UCYcjs.l; exports.updateScene = _chunkJFLD2UCYcjs.b;
2
- //# sourceMappingURL=visualization-GU7JIB4V.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/visualization-GU7JIB4V.cjs"],"names":[],"mappings":"AAAA,iIAAqI,gCAA6B,itBAAoV","file":"/home/runner/work/selva-compute/selva-compute/dist/visualization-GU7JIB4V.cjs"}
@@ -1,2 +0,0 @@
1
- import{a as e,b as r,c as o,d as t,e as a,f as s,g as i,h as p,i as n,j as h,k as M,l as f,m,n as B,o as C}from"./chunk-MKW2KTPT.js";import"./chunk-GTTKNF4G.js";export{i as BINARY_MESH_MAGIC,p as BINARY_MESH_VERSION,n as FLAG_FLOAT32,s as Materials,B as SCALE_FACTORS,t as applyOffset,a as computeCombinedBoundingBox,C as getThreeMeshesFromComputeResponse,e as initThree,h as parseBinaryMeshBatch,o as parseColor,M as parseMeshBatch,m as parseMeshBatchBlob,f as parseMeshBatchObject,r as updateScene};
2
- //# sourceMappingURL=visualization-WIUVT2FZ.js.map