@selvajs/compute 1.5.1 → 1.5.2-beta.1

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 (61) hide show
  1. package/README.md +12 -8
  2. package/dist/chunk-2D74PNQU.cjs +2 -0
  3. package/dist/chunk-2D74PNQU.cjs.map +1 -0
  4. package/dist/chunk-5465MDT4.cjs +2 -0
  5. package/dist/chunk-5465MDT4.cjs.map +1 -0
  6. package/dist/chunk-DADFXYBV.js +2 -0
  7. package/dist/chunk-DADFXYBV.js.map +1 -0
  8. package/dist/chunk-MZGKJZVP.cjs +2 -0
  9. package/dist/chunk-MZGKJZVP.cjs.map +1 -0
  10. package/dist/chunk-RHULSS7S.js +3 -0
  11. package/dist/chunk-RHULSS7S.js.map +1 -0
  12. package/dist/chunk-VWOEUM7C.cjs +3 -0
  13. package/dist/chunk-VWOEUM7C.cjs.map +1 -0
  14. package/dist/chunk-XIBQV4XW.js +2 -0
  15. package/dist/chunk-XIBQV4XW.js.map +1 -0
  16. package/dist/chunk-XLHA5YPH.js +2 -0
  17. package/dist/chunk-XLHA5YPH.js.map +1 -0
  18. package/dist/core.cjs +1 -1
  19. package/dist/core.d.cts +3 -21
  20. package/dist/core.d.ts +3 -21
  21. package/dist/core.js +1 -1
  22. package/dist/errors-CiA83qw2.d.cts +510 -0
  23. package/dist/errors-CiA83qw2.d.ts +510 -0
  24. package/dist/grasshopper.cjs +1 -1
  25. package/dist/grasshopper.d.cts +75 -142
  26. package/dist/grasshopper.d.ts +75 -142
  27. package/dist/grasshopper.js +1 -1
  28. package/dist/index.cjs +1 -1
  29. package/dist/index.d.cts +3 -5
  30. package/dist/index.d.ts +3 -5
  31. package/dist/index.js +1 -1
  32. package/dist/visualization-3HFOMXUY.cjs +2 -0
  33. package/dist/visualization-3HFOMXUY.cjs.map +1 -0
  34. package/dist/visualization-XXHESVUI.js +2 -0
  35. package/dist/visualization-XXHESVUI.js.map +1 -0
  36. package/dist/visualization.cjs +1 -1
  37. package/dist/visualization.cjs.map +1 -1
  38. package/dist/visualization.d.cts +1 -76
  39. package/dist/visualization.d.ts +1 -76
  40. package/dist/visualization.js +1 -1
  41. package/dist/visualization.js.map +1 -1
  42. package/package.json +1 -1
  43. package/LICENSE.md +0 -21
  44. package/dist/base-dtik4Dlu.d.cts +0 -138
  45. package/dist/base-dtik4Dlu.d.ts +0 -138
  46. package/dist/chunk-FRSLCR7G.cjs +0 -2
  47. package/dist/chunk-FRSLCR7G.cjs.map +0 -1
  48. package/dist/chunk-IJZNCO5X.cjs +0 -3
  49. package/dist/chunk-IJZNCO5X.cjs.map +0 -1
  50. package/dist/chunk-LNIUUPA5.cjs +0 -2
  51. package/dist/chunk-LNIUUPA5.cjs.map +0 -1
  52. package/dist/chunk-PZ4HZLFJ.js +0 -2
  53. package/dist/chunk-PZ4HZLFJ.js.map +0 -1
  54. package/dist/chunk-VK2TSW7S.js +0 -3
  55. package/dist/chunk-VK2TSW7S.js.map +0 -1
  56. package/dist/chunk-WXQGTKU6.js +0 -2
  57. package/dist/chunk-WXQGTKU6.js.map +0 -1
  58. package/dist/schemas-Ct7lU-IH.d.cts +0 -247
  59. package/dist/schemas-Ct7lU-IH.d.ts +0 -247
  60. package/dist/types-B24K2LG4.d.cts +0 -85
  61. package/dist/types-B24K2LG4.d.ts +0 -85
@@ -1,8 +1,5 @@
1
1
  import * as THREE from 'three';
2
2
  import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
3
- import { d as GrasshopperComputeResponse } from './schemas-Ct7lU-IH.js';
4
- import { M as MeshExtractionOptions, a as MeshBatch } from './types-B24K2LG4.js';
5
- export { D as DecompressedMeshData, b as MaterialGroup, c as MeshBatchParsingOptions, d as MeshMetadata, S as SerializableMaterial } from './types-B24K2LG4.js';
6
3
 
7
4
  type CameraConfig = {
8
5
  position?: THREE.Vector3;
@@ -130,76 +127,4 @@ declare namespace threeMaterials {
130
127
  export { threeMaterials_CONCRETE_MATERIAL as CONCRETE_MATERIAL, threeMaterials_EMISSIVE_MATERIAL as EMISSIVE_MATERIAL, threeMaterials_GLASS_MATERIAL as GLASS_MATERIAL, threeMaterials_METAL_MATERIAL as METAL_MATERIAL, threeMaterials_PLASTIC_MATERIAL as PLASTIC_MATERIAL, threeMaterials_RUBBER_MATERIAL as RUBBER_MATERIAL, threeMaterials_WOOD_MATERIAL as WOOD_MATERIAL };
131
128
  }
132
129
 
133
- declare const SCALE_FACTORS: Record<string, number>;
134
- /**
135
- * Extracts and processes display meshes from a ComputePointerResponse using the Grasshopper WebDisplay component.
136
- *
137
- * This is the primary entry point for extracting mesh geometry from Grasshopper compute responses.
138
- * It handles all aspects of mesh processing: decompression, coordinate transformation, scaling, and positioning.
139
- *
140
- * **Note:** Mesh decompression happens asynchronously in a Web Worker to prevent UI blocking.
141
- *
142
- * @param data - The ComputePointerResponse containing Grasshopper output trees.
143
- * @param options - Configuration for mesh extraction and parsing behavior. All options are optional with sensible defaults.
144
- * @returns Promise resolving to array of THREE.Mesh objects (may be empty).
145
- * @throws Rethrows unexpected errors after attempting to dispose any created meshes.
146
- *
147
- * @remarks
148
- * - Only works with the WebDisplay component of GHHeadless.
149
- * - Requires changes to Rhino.Compute (see https://github.com/TheVessen/compute.rhino3d).
150
- * - Provides a performant way to display mesh data in Three.js.
151
- * - Decompression is performed in a Web Worker for non-blocking UI updates.
152
- * - Supports mesh metadata (names, user data) if provided in the compute response.
153
- *
154
- * @internal Internal helper: high-level extraction remains public via visualization module, but this
155
- * function is considered internal implementation detail for mesh extraction.
156
- *
157
- * @example
158
- * ```ts
159
- * // Simple usage with defaults (all processing enabled)
160
- * const meshes = await getThreeMeshesFromComputeResponse(response);
161
- *
162
- * // With debugging enabled
163
- * const meshes = await getThreeMeshesFromComputeResponse(response, { debug: true });
164
- *
165
- * // With advanced options
166
- * const meshes = await getThreeMeshesFromComputeResponse(response, {
167
- * debug: true,
168
- * allowScaling: true,
169
- * allowAutoPosition: false,
170
- * parsing: {
171
- * mergeByMaterial: false,
172
- * applyTransforms: true,
173
- * debug: true,
174
- * },
175
- * });
176
- * ```
177
- */
178
- declare function getThreeMeshesFromComputeResponse(data: GrasshopperComputeResponse, options?: MeshExtractionOptions): Promise<THREE.Mesh[]>;
179
-
180
- /**
181
- * Parses a MeshBatch object and creates Three.js meshes.
182
- * This is useful when you already have a deserialized MeshBatch object.
183
- *
184
- * @internal Low-level mesh parsing — keep internal to `@selvajs/compute`.
185
- *
186
- * @param batch - MeshBatch object
187
- * @param options - Rendering options
188
- * @returns Promise resolving to array of Three.js mesh objects
189
- */
190
- declare function parseMeshBatchObject(batch: MeshBatch, options?: {
191
- /** Merge meshes with same material into single geometry*/
192
- mergeByMaterial?: boolean;
193
- /** Apply coordinate system transformations */
194
- applyTransforms?: boolean;
195
- /** Scale factor to apply to meshes (e.g., for unit conversion) */
196
- scaleFactor?: number;
197
- /** Enable performance monitoring */
198
- debug?: boolean;
199
- /** Parse time (optional, for debugging) */
200
- parseTime?: number;
201
- /** Performance start time (optional, for debugging) */
202
- perfStart?: number;
203
- }): Promise<THREE.Mesh[]>;
204
-
205
- export { type CameraConfig, type ControlsConfig, type EnvironmentConfig, type EventConfig, type FloorConfig, type LightingConfig, threeMaterials as Materials, MeshBatch, MeshExtractionOptions, type RenderConfig, SCALE_FACTORS, type ThreeInitializerOptions, getThreeMeshesFromComputeResponse, initThree, parseMeshBatchObject, updateScene };
130
+ export { type CameraConfig, type ControlsConfig, type EnvironmentConfig, type EventConfig, type FloorConfig, type LightingConfig, threeMaterials as Materials, type RenderConfig, type ThreeInitializerOptions, initThree, updateScene };
@@ -1,2 +1,2 @@
1
- import{c as G}from"./chunk-PZ4HZLFJ.js";import{a as te,c as O,d as H,e as p}from"./chunk-VK2TSW7S.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 W=new i.Vector3(0,0,1),P=(e,r,t,n)=>{switch(e){case"mm":return r;case"cm":return t;default:return n}},$=function(e,r){let t=oe(r||{}),n=ae(t),o=de(t,e),s=he(e,t),a=ue(o,e,t);ce(n,t),le(n,t),t.floor?.enabled&&fe(n,t);let l=t.events.enableEventHandlers!==!1?me(e,n,o,a,t):{dispose:()=>{},fitToView:()=>{},clearSelection:()=>{}},c=e.parentElement,g=()=>c?{width:c.clientWidth,height:c.clientHeight}:{width:window.innerWidth,height:window.innerHeight},{animate:u,dispose:d}=ie(s,n,o,a,g,t.events.onFrame);u();let m=t.environment?.sceneUp||W;return n.up.set(m.x,m.y,m.z),{scene:n,camera:o,controls:a,renderer:s,dispose:()=>{d(),l.dispose(),a.dispose(),s.dispose(),n.traverse(h=>{h instanceof i.Mesh&&(h.geometry?.dispose(),Array.isArray(h.material)?h.material.forEach(x=>x.dispose()):h.material?.dispose())})},fitToView:l.fitToView,clearSelection:l.clearSelection}};function oe(e){let r=e.sceneScale||"m",n={mm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:10,lightHeight:20,minDistance:.1,shadowSize:100,scaleFactor:1e3},cm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:25,lightHeight:50,minDistance:.1,shadowSize:100,scaleFactor:100},m:{cameraDistance:10,near:.01,far:2e3,floorSize:50,lightDistance:25,lightHeight:50,minDistance:.001,shadowSize:100,scaleFactor:1},inches:{cameraDistance:15,near:.1,far:2e3,floorSize:80,lightDistance:20,lightHeight:40,minDistance:.1,shadowSize:80,scaleFactor:39.37},feet:{cameraDistance:8,near:.1,far:2e3,floorSize:40,lightDistance:15,lightHeight:30,minDistance:.1,shadowSize:60,scaleFactor:3.28084}}[r];return{sceneScale:r,camera:{position:e.camera?.position||new i.Vector3(-n.cameraDistance,n.cameraDistance,n.cameraDistance),fov:e.camera?.fov||20,near:e.camera?.near||n.near,far:e.camera?.far||n.far,target:e.camera?.target||new i.Vector3(0,0,0)},lighting:{enableSunlight:e.lighting?.enableSunlight??!0,sunlightIntensity:e.lighting?.sunlightIntensity||1,sunlightPosition:e.lighting?.sunlightPosition||new i.Vector3(n.lightDistance,n.lightHeight,n.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||W,showEnvironment:e.environment?.showEnvironment??!1},floor:{enabled:e.floor?.enabled??!1,size:e.floor?.size||n.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||n.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,t=typeof e.environment.backgroundColor=="string"?new i.Color(e.environment.backgroundColor):e.environment.backgroundColor;return r.background=t||null,r}function se(e,r,t,n,o=200){let s=e.position.clone(),a=r.target.clone(),l=performance.now(),c=u=>1-Math.pow(1-u,3),g=()=>{let u=performance.now()-l,d=c(Math.min(u/o,1));e.position.lerpVectors(s,t,d),r.target.lerpVectors(a,n,d),r.update(),d<1&&requestAnimationFrame(g)};requestAnimationFrame(g)}function ie(e,r,t,n,o,s){let a=null,l=performance.now(),c=()=>{let{width:d,height:m}=o();if(d===0||m===0)return;let w=Math.min(window.devicePixelRatio,2),h=Math.round(d*w),x=Math.round(m*w);(e.domElement.width!==h||e.domElement.height!==x)&&(e.setPixelRatio(w),e.setSize(d,m,!1),t.aspect=d/m,t.updateProjectionMatrix())},g=function(){a=requestAnimationFrame(g);let d=performance.now(),m=(d-l)/1e3;l=d,c(),(n.enableDamping||n.autoRotate)&&n.update(),s?.(m),e.render(r,t)};return{animate:g,dispose:()=>{a!==null&&(cancelAnimationFrame(a),a=null)}}}function ce(e,r){r.environment.enableEnvironmentLighting?new re().load(r.environment.hdrPath||"/baseHDR.hdr",function(t){t.mapping=i.EquirectangularReflectionMapping,e.environment=t,r.environment.showEnvironment&&(e.background=t),r.events.onReady?.()},void 0,function(t){p().warn("HDR texture could not be loaded, falling back to basic lighting:",t),r.events.onReady?.()}):r.events.onReady?.()}function le(e,r){let t=new i.AmbientLight(r.lighting.ambientLightColor,r.lighting.ambientLightIntensity);if(e.add(t),r.lighting.enableSunlight){let n=new i.DirectionalLight(r.lighting.sunlightColor??16777215,r.lighting.sunlightIntensity),o=r.lighting.sunlightPosition;if(o&&n.position.set(o.x,o.y,o.z),r.render.enableShadows){n.castShadow=!0;let s=P(r.sceneScale,.1,10,100);n.shadow.camera.left=-s,n.shadow.camera.right=s,n.shadow.camera.top=s,n.shadow.camera.bottom=-s;let a=P(r.sceneScale,.001,.1,.5),l=P(r.sceneScale,1,100,500);n.shadow.camera.near=a,n.shadow.camera.far=l,n.shadow.mapSize.width=r.render.shadowMapSize||2048,n.shadow.mapSize.height=r.render.shadowMapSize||2048,n.shadow.bias=-1e-4,n.shadow.normalBias=.02}e.add(n)}}function fe(e,r){let t=r.floor.size,n=new i.PlaneGeometry(t,t),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(n,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 t=r.parentElement,n=t?t.clientWidth:window.innerWidth,o=t?t.clientHeight:window.innerHeight,s=new i.PerspectiveCamera(e.camera.fov,n/o,e.camera.near,e.camera.far),a=e.camera.position;return a&&s.position.set(a.x,a.y,a.z),s}function he(e,r){let t=new i.WebGLRenderer({antialias:r.render.antialias,canvas:e,alpha:!0,powerPreference:"high-performance",preserveDrawingBuffer:r.render.preserveDrawingBuffer,logarithmicDepthBuffer:!0}),n=e.parentElement,o=n?n.clientWidth:window.innerWidth,s=n?n.clientHeight:window.innerHeight;return n&&(e.style.width="100%",e.style.height="100%",e.style.display="block"),t.setSize(o,s,!1),t.setPixelRatio(r.render.pixelRatio||Math.min(window.devicePixelRatio,2)),r.render.enableShadows&&(t.shadowMap.enabled=!0,t.shadowMap.type=i.VSMShadowMap),t.toneMapping=r.render.toneMapping,t.toneMappingExposure=r.render.toneMappingExposure||1,t.outputColorSpace=i.SRGBColorSpace,t.sortObjects=!0,t}function me(e,r,t,n,o){let s=new Set,a=new Map,l=new i.Raycaster,c=new i.Vector2,g=new i.Vector2,u=f=>{let R=f;for(;R;){if(!R.visible)return!1;R=R.parent}return!0},d=()=>{let f=new i.Box3;if(r.traverse(D=>{D.visible&&D.userData.id!=="floor"&&D instanceof i.Mesh&&f.expandByObject(D)}),f.isEmpty()){p().warn("No objects to fit to view");return}let R=f.getCenter(new i.Vector3),M=f.getSize(new i.Vector3),A=Math.max(M.x,M.y,M.z),T=t.fov*(Math.PI/180),v=A/(2*Math.tan(T/2));v*=1.5;let B=t.position.clone().sub(n.target).normalize();t.position.copy(R.clone().add(B.multiplyScalar(v))),n.target.copy(R),n.update()},m=typeof o.events.selectionColor=="string"?new i.Color(o.events.selectionColor):o.events.selectionColor instanceof i.Color?o.events.selectionColor:new i.Color("#ff0000"),w=()=>{s.forEach(f=>{f instanceof i.Mesh&&a.has(f)&&(f.material=a.get(f),a.delete(f))}),s.clear()},h=f=>{g.set(f.clientX,f.clientY)},x=f=>{let R=new i.Vector2(f.clientX,f.clientY);if(g.distanceTo(R)>5)return;let M=e.getBoundingClientRect();c.x=(f.clientX-M.left)/M.width*2-1,c.y=-((f.clientY-M.top)/M.height)*2+1,l.setFromCamera(c,t);let A=l.intersectObjects(r.children,!0).filter(T=>u(T.object));if(A.length>0){let T=A[0].object;if(!s.has(T)){if(w(),s.add(T),T instanceof i.Mesh&&T.material instanceof i.Material){a.set(T,T.material);let v=T.material.clone();v.emissive=m.clone(),T.material=v}o.events?.onObjectSelected?.(T),T instanceof i.Mesh&&Object.keys(T.userData).length>0&&o.events?.onMeshMetadataClicked?.(T.userData)}}else w(),o.events?.onBackgroundClicked?.({x:c.x,y:c.y})},I=f=>{let R=e.getBoundingClientRect();c.x=(f.clientX-R.left)/R.width*2-1,c.y=-((f.clientY-R.top)/R.height)*2+1,l.setFromCamera(c,t);let M=l.intersectObjects(r.children,!0).filter(ee=>u(ee.object));if(M.length===0)return;let A=M[0].object;if(o.events?.onMeshDoubleClicked?.(A),!o.events?.enableDoubleClickZoom)return;let T=new i.Box3().setFromObject(A);if(T.isEmpty())return;let v=T.getCenter(new i.Vector3),B=T.getSize(new i.Vector3),D=Math.max(B.x,B.y,B.z),K=t.fov*(Math.PI/180),X=D/(2*Math.tan(K/2))*1.5,J=t.position.clone().sub(n.target).normalize(),Q=v.clone().add(J.multiplyScalar(X));se(t,n,Q,v)},L=f=>{if(o.events?.enableKeyboardControls)switch(f.key.toLowerCase()){case"f":f.preventDefault(),d();break;case"escape":f.preventDefault(),w();break;case" ":f.preventDefault(),d();break}};return o.events?.enableClickToFocus&&(e.addEventListener("mousedown",h),e.addEventListener("click",x),e.addEventListener("dblclick",I)),o.events?.enableKeyboardControls&&(e.setAttribute("tabindex","0"),e.addEventListener("keydown",L)),{dispose:()=>{e.removeEventListener("mousedown",h),e.removeEventListener("click",x),e.removeEventListener("dblclick",I),e.removeEventListener("keydown",L),w()},fitToView:d,clearSelection:w}}function ue(e,r,t){let n=new ne(e,r),o=t.camera.target;return o&&n.target.set(o.x,o.y,o.z),n.enableDamping=t.controls.enableDamping||!1,n.dampingFactor=t.controls.dampingFactor||.05,n.autoRotate=t.controls.autoRotate||!1,n.autoRotateSpeed=t.controls.autoRotateSpeed||.5,n.enableZoom=t.controls.enableZoom??!0,n.enablePan=t.controls.enablePan??!0,n.minDistance=t.controls.minDistance||.001,n.maxDistance=t.controls.maxDistance||1/0,n.screenSpacePanning=!1,n.maxPolarAngle=Math.PI,n.update(),n}import*as y from"three";var C={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 j(e,r,t,n,o){if(Ee(e),r.length===0)return;r.forEach(u=>{e.add(u)});let s=F(r),a=s.getCenter(new y.Vector3),l=s.getSize(new y.Vector3),c=Math.max(l.x,l.y,l.z);if(c/Math.min(l.x||1,l.y||1,l.z||1)>C.SCALE_RATIO_THRESHOLD||c>C.HUGE_THRESHOLD?(t.near=c*C.NEAR_PLANE_FACTOR.TINY,t.far=c*C.FAR_PLANE_FACTOR.HUGE):c>C.LARGE_THRESHOLD?(t.near=c*C.NEAR_PLANE_FACTOR.SMALL,t.far=c*C.FAR_PLANE_FACTOR.LARGE):(t.near=Math.max(.01,c*C.NEAR_PLANE_FACTOR.NORMAL),t.far=Math.max(2e3,c*C.FAR_PLANE_FACTOR.NORMAL)),t.updateProjectionMatrix(),o)n.minDistance=t.near*2,n.maxDistance=t.far*.9;else{let u=c*C.INITIAL_DISTANCE_MULTIPLIER;t.position.set(a.x+u*.8,a.y+u,a.z+u*1.2),n.target.copy(a),n.minDistance=t.near*2,n.maxDistance=t.far*.9,n.update()}}function z(e){if(!e||typeof e!="string")return p().warn(`Invalid color input: ${e}, using white`),new y.Color(16777215);let r=e.trim();if(r.startsWith("#")||/^[0-9A-Fa-f]{6}$/.test(r))try{let t=r.startsWith("#")?r:`#${r}`;return new y.Color(t)}catch{return p().warn(`Invalid hex color: ${e}, using white`),new y.Color(16777215)}if(r.includes(",")){let t=r.split(",").map(n=>parseInt(n.trim(),10));if(t.length===3&&t.every(n=>!isNaN(n)&&n>=0&&n<=255))return new y.Color(t[0]/255,t[1]/255,t[2]/255)}try{return new y.Color(r.toLowerCase())}catch{return p().warn(`Invalid color string: ${e}, using white`),new y.Color(16777215)}}function _(e,r){e.forEach(t=>{t.position.y-=r})}function F(e){let r=new y.Box3;return e.length===0||e.forEach(t=>{t.updateMatrixWorld(!0);let n=new y.Box3().setFromObject(t);r.union(n)}),r}function Ee(e){[...e.children].forEach(t=>{t.userData.id!=="floor"&&(t.traverse(n=>{if(!(n instanceof y.Mesh))return;n.geometry?.dispose(),(Array.isArray(n.material)?n.material:[n.material]).forEach(s=>{for(let a of Object.values(s))a instanceof y.Texture&&a.dispose();s.dispose()})}),t.removeFromParent())})}var V={};te(V,{CONCRETE_MATERIAL:()=>Re,EMISSIVE_MATERIAL:()=>pe,GLASS_MATERIAL:()=>ye,METAL_MATERIAL:()=>ge,PLASTIC_MATERIAL:()=>Te,RUBBER_MATERIAL:()=>we,WOOD_MATERIAL:()=>be});import*as E from"three";var pe=new E.MeshPhysicalMaterial({color:0,emissive:new E.Color(16777215),emissiveIntensity:5,metalness:0,roughness:.2,clearcoat:.3,clearcoatRoughness:.2,depthWrite:!0,depthTest:!0,transparent:!1,alphaTest:0,polygonOffset:!0,side:E.FrontSide,dithering:!0}),ge=new E.MeshPhysicalMaterial({color:new E.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:E.FrontSide,dithering:!0}),Re=new E.MeshPhysicalMaterial({color:new E.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:E.FrontSide,dithering:!0}),Te=new E.MeshPhysicalMaterial({color:new E.Color(16777215),metalness:0,roughness:.3,envMapIntensity:.5,clearcoat:.5,clearcoatRoughness:.1,reflectivity:.5,ior:1.4,transmission:0,transparent:!1,depthWrite:!0,side:E.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),ye=new E.MeshPhysicalMaterial({color:new E.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:E.DoubleSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),we=new E.MeshPhysicalMaterial({color:new E.Color(1710618),metalness:0,roughness:.9,envMapIntensity:.2,clearcoat:.1,clearcoatRoughness:.8,reflectivity:.2,ior:1.3,transmission:0,depthWrite:!0,side:E.FrontSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),be=new E.MeshPhysicalMaterial({color:new E.Color(8934707),metalness:0,roughness:.7,envMapIntensity:.3,clearcoat:.3,clearcoatRoughness:.4,reflectivity:.3,ior:1.3,transmission:0,depthWrite:!0,side:E.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});import*as b from"three";import*as q from"fflate";async function Y(e){return new Promise((r,t)=>{try{let n=()=>{try{let o=G(e),s=q.gunzipSync(o),a=Me(s);r(a)}catch(o){t(new H(o instanceof H?o.message:`Failed to decompress batched data: ${o instanceof Error?o.message:String(o)}`,o instanceof H?o.code:O.VALIDATION_ERROR,{context:{base64StringLength:e.length},originalError:o instanceof Error?o:new Error(String(o))}))}};"requestIdleCallback"in globalThis?globalThis.requestIdleCallback(n,{timeout:5e3}):setTimeout(n,0)}catch(n){t(new H(`Failed to schedule decompression: ${n instanceof Error?n.message:String(n)}`,O.VALIDATION_ERROR,{originalError:n instanceof Error?n:new Error(String(n))}))}})}function Me(e){let r=new DataView(e.buffer,e.byteOffset,e.byteLength),t=0;if(t+4>r.byteLength)throw new H("Insufficient data to read the number of vertex floats.",O.VALIDATION_ERROR,{context:{expectedBytes:4,availableBytes:r.byteLength,offset:t}});let n=r.getUint32(t,!0);if(t+=4,n%3!==0)throw new H("Invalid number of vertex floats; should be divisible by 3.",O.VALIDATION_ERROR,{context:{numVertexFloats:n,remainder:n%3,totalBytes:r.byteLength}});let o=n*Float32Array.BYTES_PER_ELEMENT;if(t+o>r.byteLength)throw new H("Insufficient data to read vertices.",O.VALIDATION_ERROR,{context:{expectedBytes:o,availableBytes:r.byteLength-t,offset:t}});let s=new Float32Array(e.buffer.slice(e.byteOffset+t,e.byteOffset+t+o));if(t+=o,t+4>r.byteLength)throw new H("Insufficient data to read the number of face indices.",O.VALIDATION_ERROR,{context:{expectedBytes:4,availableBytes:r.byteLength-t,offset:t}});let a=r.getUint32(t,!0);t+=4;let l=a*Uint32Array.BYTES_PER_ELEMENT;if(t+l>r.byteLength)throw new H("Insufficient data to read face indices.",O.VALIDATION_ERROR,{context:{expectedBytes:l,availableBytes:r.byteLength-t,offset:t}});let c=new Uint32Array(e.buffer.slice(e.byteOffset+t,e.byteOffset+t+l));return{vertices:s,faces:c}}async function N(e,r){let{mergeByMaterial:t=!0,applyTransforms:n=!0,debug:o=!1}=r??{},s=o?performance.now():0,a=0;try{let l=performance.now(),c=JSON.parse(e);return a=performance.now()-l,await k(c,{mergeByMaterial:t,applyTransforms:n,debug:o,parseTime:a,perfStart:s})}catch(l){return p().error("Error parsing mesh batch:",l),[]}}async function k(e,r){let{mergeByMaterial:t=!0,applyTransforms:n=!0,scaleFactor:o=1,debug:s=!1,parseTime:a=0,perfStart:l=s?performance.now():0}=r??{},c=0,g=0;try{let u=performance.now(),{vertices:d,faces:m}=await Y(e.compressedData);c=performance.now()-u;let w=(e.compressedData.length*.75/1024/1024).toFixed(2),h=((d.byteLength+m.byteLength)/1024/1024).toFixed(2),x=((1-parseFloat(w)/parseFloat(h))*100).toFixed(1);s&&(p().debug("Mesh Batch Stats:"),p().debug(` Materials: ${e.materials.length} | Groups: ${e.groups.length}`),p().debug(` Vertices: ${(d.length/3).toLocaleString()} | Faces: ${(m.length/3).toLocaleString()}`),p().debug(` Compressed: ${w} MB | Uncompressed: ${h} MB`),p().debug(` Compression Ratio: ${x}%`)),n&&ve(d);let I=performance.now(),L=e.materials.map(xe),S=[];for(let f of e.groups)if(t&&f.meshes.length>1){let R=He(f,d,m,L);R.userData.sourceComponentId=e.sourceComponentId??null,S.push(R)}else{let R=Ce(f,d,m,L);for(let M of R)M.userData.sourceComponentId=e.sourceComponentId??null;S.push(...R)}if(o!==1)for(let f of S)f.scale.set(o,o,o);if(g=performance.now()-I,s){let f=performance.now()-l;p().debug("Performance:"),a>0&&p().debug(` Parse JSON: ${a.toFixed(2)}ms`),p().debug(` Decompress: ${c.toFixed(2)}ms`),p().debug(` Create Meshes: ${g.toFixed(2)}ms`),p().debug(` Total: ${f.toFixed(2)}ms`)}return S}catch(u){return p().error("Error parsing mesh batch object:",u),[]}}function xe(e){let r=z(e.color);return new b.MeshPhysicalMaterial({color:r,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,side:b.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.5,polygonOffsetUnits:.5,depthWrite:!0,depthTest:!0})}function He(e,r,t,n){let o=new b.BufferGeometry,s=0,a=0;for(let h of e.meshes)s+=h.vertexCount,a+=h.faceCount;let l=new Float32Array(s),c=new Uint32Array(a),g=0,u=0;for(let h of e.meshes){l.set(r.subarray(h.vertexOffset,h.vertexOffset+h.vertexCount),g);let x=t.subarray(h.faceOffset,h.faceOffset+h.faceCount),I=Math.floor(h.vertexOffset/3),S=Math.floor(g/3)-I;for(let f=0;f<x.length;f++)c[u+f]=x[f]+S;g+=h.vertexCount,u+=h.faceCount}o.setAttribute("position",new b.BufferAttribute(l,3)),o.setIndex(new b.BufferAttribute(c,1)),o.computeVertexNormals();let d=new b.Mesh(o,n[e.materialId]),m=e.meshes[0],w=e.meshes.map(h=>h.name).filter(h=>h&&h.length>0);return d.name=w.length>0?w[0]:`merged_material_${e.materialId}`,d.castShadow=!0,d.receiveShadow=!0,d.userData={name:d.name,layer:m?.layer??"",originalIndex:m?.originalIndex??0,metadata:m?.metadata??{},mergedFrom:e.meshes.slice(1).map(h=>({name:h.name,layer:h.layer,originalIndex:h.originalIndex}))},d}function Ce(e,r,t,n){let o=[];for(let s of e.meshes){let a=new b.BufferGeometry,l=r.subarray(s.vertexOffset,s.vertexOffset+s.vertexCount),c=t.subarray(s.faceOffset,s.faceOffset+s.faceCount),g=Math.floor(s.vertexOffset/3),u=new Uint32Array(c.length);for(let m=0;m<c.length;m++)u[m]=c[m]-g;a.setAttribute("position",new b.BufferAttribute(l,3)),a.setIndex(new b.BufferAttribute(u,1)),a.computeVertexNormals();let d=new b.Mesh(a,n[e.materialId]);d.name=s.name,d.userData={name:s.name,layer:s.layer??"",originalIndex:s.originalIndex,metadata:s.metadata??{}},d.castShadow=!0,d.receiveShadow=!0,o.push(d)}return o}function ve(e){let r=Math.cos(-Math.PI/2),t=Math.sin(-Math.PI/2);for(let n=0;n<e.length;n+=3){let o=e[n],s=e[n+1],a=e[n+2];e[n]=o,e[n+1]=s*r-a*t,e[n+2]=s*t+a*r}}var U={Millimeters:1/1e3,Centimeters:1/100,Meters:1,Inches:1/39.37,Feet:1/3.28084},Oe="Display";async function Z(e,r){let t=performance.now(),n=[],{allowScaling:o=!0,allowAutoPosition:s=!0,debug:a=!1,parsing:l={}}=r??{};try{let c=o?Se(e.modelunits):1;return await Ae(e,n,c,l,a),s&&Le(n),n}catch(c){throw De(c,n),c}finally{a&&Fe(t)}}function Se(e){return U[e]??1}async function Ae(e,r,t,n,o){for(let s of e.values){let a=s.InnerTree;for(let l in a){let c=a[l];c&&await Ie(c,r,t,n,o)}}}async function Ie(e,r,t,n,o){for(let s of e)if(s.type.includes(Oe)){let a={mergeByMaterial:!0,applyTransforms:!0,debug:!1,...n},l=await N(s.data,a);if(t!==1)for(let c of l)c.scale.set(t,t,t);r.push(...l),o&&p().debug(`Extracted ${l.length} meshes from batch`)}}function Le(e){if(e.length===0)return;let t=F(e).min.y;_(e,t)}function De(e,r){p().error("An unexpected error occurred:",e),Be(r)}function Be(e){for(let r of e)r.geometry&&r.geometry.dispose(),r.material&&(Array.isArray(r.material)?r.material.forEach(t=>t.dispose()):r.material.dispose())}function Fe(e){let r=performance.now()-e;p().info("Time to process meshes:",`${r.toFixed(2)}ms`)}export{V as Materials,U as SCALE_FACTORS,Z as getThreeMeshesFromComputeResponse,$ as initThree,k as parseMeshBatchObject,j as updateScene};
1
+ import{a as e,b as o,f as i}from"./chunk-DADFXYBV.js";import"./chunk-RHULSS7S.js";export{i as Materials,e as initThree,o as updateScene};
2
2
  //# sourceMappingURL=visualization.js.map
@@ -1 +1 @@
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/batch-parser.ts","../src/features/visualization/webdisplay/mesh-compression.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)\n\tif (trimmed.startsWith('#') || /^[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 * as THREE from 'three';\n\nimport { parseColor } from '../threejs/three-helpers';\nimport { getLogger } from '@/core';\n\nimport { decompressBatchedMeshData } from './mesh-compression';\n\nimport type { MeshBatch, MaterialGroup, SerializableMaterial } from './types';\n\n/**\n * Parses a batched mesh JSON and creates Three.js meshes.\n *\n * This function handles the optimized batch format where:\n * - Materials are deduplicated and stored once\n * - Meshes are grouped by material for efficient rendering\n * - All geometry data is compressed together and decompressed in a Web Worker\n *\n * @internal Low-level mesh parsing — keep internal to `@selvajs/compute`.\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?: {\n\t\t/** Merge meshes with same material into single geometry*/\n\t\tmergeByMaterial?: boolean;\n\t\t/** Apply coordinate system transformations */\n\t\tapplyTransforms?: boolean;\n\t\t/** Enable performance monitoring */\n\t\tdebug?: boolean;\n\t}\n): Promise<THREE.Mesh[]> {\n\tconst { mergeByMaterial = true, applyTransforms = true, debug = false } = options ?? {};\n\n\tconst perfStart = debug ? performance.now() : 0;\n\tlet parseTime = 0;\n\n\ttry {\n\t\tconst parseStart = performance.now();\n\t\tconst batch: MeshBatch = JSON.parse(batchJson);\n\t\tparseTime = performance.now() - parseStart;\n\n\t\treturn await parseMeshBatchObject(batch, {\n\t\t\tmergeByMaterial,\n\t\t\tapplyTransforms,\n\t\t\tdebug,\n\t\t\tparseTime,\n\t\t\tperfStart\n\t\t});\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 * This is useful when you already have a deserialized MeshBatch object.\n *\n * @internal Low-level mesh parsing — keep internal to `@selvajs/compute`.\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?: {\n\t\t/** Merge meshes with same material into single geometry*/\n\t\tmergeByMaterial?: boolean;\n\t\t/** Apply coordinate system transformations */\n\t\tapplyTransforms?: boolean;\n\t\t/** Scale factor to apply to meshes (e.g., for unit conversion) */\n\t\tscaleFactor?: number;\n\t\t/** Enable performance monitoring */\n\t\tdebug?: boolean;\n\t\t/** Parse time (optional, for debugging) */\n\t\tparseTime?: number;\n\t\t/** Performance start time (optional, for debugging) */\n\t\tperfStart?: 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\tparseTime = 0,\n\t\tperfStart = debug ? performance.now() : 0\n\t} = options ?? {};\n\n\tlet decompressTime = 0,\n\t\tmeshCreateTime = 0;\n\n\ttry {\n\t\tconst decompressStart = performance.now();\n\t\tconst { vertices, faces } = await decompressBatchedMeshData(batch.compressedData);\n\t\tdecompressTime = performance.now() - decompressStart;\n\n\t\tconst compressedSizeMB = ((batch.compressedData.length * 0.75) / 1024 / 1024).toFixed(2); // Base64 overhead\n\t\tconst uncompressedSizeMB = ((vertices.byteLength + faces.byteLength) / 1024 / 1024).toFixed(2);\n\t\tconst compressionRatio = (\n\t\t\t(1 - parseFloat(compressedSizeMB) / parseFloat(uncompressedSizeMB)) *\n\t\t\t100\n\t\t).toFixed(1);\n\n\t\tif (debug) {\n\t\t\tgetLogger().debug('Mesh Batch Stats:');\n\t\t\tgetLogger().debug(` Materials: ${batch.materials.length} | Groups: ${batch.groups.length}`);\n\t\t\tgetLogger().debug(\n\t\t\t\t` Vertices: ${(vertices.length / 3).toLocaleString()} | Faces: ${(faces.length / 3).toLocaleString()}`\n\t\t\t);\n\t\t\tgetLogger().debug(\n\t\t\t\t` Compressed: ${compressedSizeMB} MB | Uncompressed: ${uncompressedSizeMB} MB`\n\t\t\t);\n\t\t\tgetLogger().debug(` Compression Ratio: ${compressionRatio}%`);\n\t\t}\n\n\t\tif (applyTransforms) {\n\t\t\tapplyCoordinateTransform(vertices);\n\t\t}\n\n\t\tconst meshCreateStart = performance.now();\n\t\tconst materials = batch.materials.map(createMaterial);\n\n\t\tconst meshes: THREE.Mesh[] = [];\n\n\t\tfor (const group of batch.groups) {\n\t\t\tif (mergeByMaterial && group.meshes.length > 1) {\n\t\t\t\tconst mergedMesh = createMergedMesh(group, vertices, faces, materials);\n\t\t\t\tmergedMesh.userData.sourceComponentId = batch.sourceComponentId ?? null;\n\t\t\t\tmeshes.push(mergedMesh);\n\t\t\t} else {\n\t\t\t\tconst individualMeshes = createIndividualMeshes(group, vertices, faces, materials);\n\t\t\t\tfor (const mesh of individualMeshes) {\n\t\t\t\t\tmesh.userData.sourceComponentId = batch.sourceComponentId ?? null;\n\t\t\t\t}\n\t\t\t\tmeshes.push(...individualMeshes);\n\t\t\t}\n\t\t}\n\n\t\t// Apply scaling if needed\n\t\tif (scaleFactor !== 1) {\n\t\t\tfor (const mesh of meshes) {\n\t\t\t\tmesh.scale.set(scaleFactor, scaleFactor, scaleFactor);\n\t\t\t}\n\t\t}\n\n\t\tmeshCreateTime = performance.now() - meshCreateStart;\n\n\t\tif (debug) {\n\t\t\tconst totalTime = performance.now() - perfStart;\n\t\t\tgetLogger().debug('Performance:');\n\t\t\tif (parseTime > 0) getLogger().debug(` Parse JSON: ${parseTime.toFixed(2)}ms`);\n\t\t\tgetLogger().debug(` Decompress: ${decompressTime.toFixed(2)}ms`);\n\t\t\tgetLogger().debug(` Create Meshes: ${meshCreateTime.toFixed(2)}ms`);\n\t\t\tgetLogger().debug(` Total: ${totalTime.toFixed(2)}ms`);\n\t\t}\n\n\t\treturn meshes;\n\t} catch (error) {\n\t\tgetLogger().error('Error parsing mesh batch object:', error);\n\t\treturn [];\n\t}\n}\n\n/**\n * Creates a Three.js material from serializable material data.\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 * Creates a merged mesh from multiple meshes sharing the same material.\n * This is optimal for rendering many small meshes.\n * Optimized to minimize memory allocations and copies.\n */\nfunction createMergedMesh(\n\tgroup: MaterialGroup,\n\tallVertices: Float32Array,\n\tallFaces: Uint32Array,\n\tmaterials: THREE.Material[]\n): THREE.Mesh {\n\tconst geometry = new THREE.BufferGeometry();\n\n\tlet totalVertexFloats = 0;\n\tlet totalFaceIndices = 0;\n\n\tfor (const mesh of group.meshes) {\n\t\ttotalVertexFloats += mesh.vertexCount;\n\t\ttotalFaceIndices += mesh.faceCount;\n\t}\n\n\tconst mergedVertices = new Float32Array(totalVertexFloats);\n\tconst mergedIndices = new Uint32Array(totalFaceIndices);\n\n\tlet vertexWriteOffset = 0;\n\tlet indexWriteOffset = 0;\n\n\tfor (const mesh of group.meshes) {\n\t\tmergedVertices.set(\n\t\t\tallVertices.subarray(mesh.vertexOffset, mesh.vertexOffset + mesh.vertexCount),\n\t\t\tvertexWriteOffset\n\t\t);\n\n\t\tconst faceSlice = allFaces.subarray(mesh.faceOffset, mesh.faceOffset + mesh.faceCount);\n\n\t\t// Face indices are already rebased in the C# batching process\n\t\t// We need to adjust them based on where we're copying the vertices to in the merged array\n\t\tconst originalBaseVertexIndex = Math.floor(mesh.vertexOffset / 3);\n\t\tconst newBaseVertexIndex = Math.floor(vertexWriteOffset / 3);\n\t\tconst indexOffset = newBaseVertexIndex - originalBaseVertexIndex;\n\n\t\tfor (let i = 0; i < faceSlice.length; i++) {\n\t\t\tmergedIndices[indexWriteOffset + i] = faceSlice[i] + indexOffset;\n\t\t}\n\n\t\tvertexWriteOffset += mesh.vertexCount;\n\t\tindexWriteOffset += mesh.faceCount;\n\t}\n\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\t// Use the first mesh's name for the merged mesh\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\t// Structured userData — merged meshes carry data from the first mesh in the group\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\t// Remaining meshes in the merged group, for reference\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.\n * This allows independent control of each mesh.\n */\nfunction createIndividualMeshes(\n\tgroup: MaterialGroup,\n\tallVertices: Float32Array,\n\tallFaces: Uint32Array,\n\tmaterials: THREE.Material[]\n): THREE.Mesh[] {\n\tconst meshes: THREE.Mesh[] = [];\n\n\tfor (const meshMeta of group.meshes) {\n\t\tconst geometry = new THREE.BufferGeometry();\n\n\t\tconst vertices = allVertices.subarray(\n\t\t\tmeshMeta.vertexOffset,\n\t\t\tmeshMeta.vertexOffset + meshMeta.vertexCount\n\t\t);\n\n\t\tconst faces = allFaces.subarray(meshMeta.faceOffset, meshMeta.faceOffset + meshMeta.faceCount);\n\n\t\t// Faces are already rebased in C# batching, but we need to rebase them for this\n\t\t// individual mesh since we're using a subarray of vertices starting at 0\n\t\tconst baseIndex = Math.floor(meshMeta.vertexOffset / 3);\n\t\tconst rebasedFaces = new Uint32Array(faces.length);\n\t\tfor (let i = 0; i < faces.length; i++) {\n\t\t\trebasedFaces[i] = faces[i] - baseIndex;\n\t\t}\n\n\t\tgeometry.setAttribute('position', new THREE.BufferAttribute(vertices, 3));\n\t\tgeometry.setIndex(new THREE.BufferAttribute(rebasedFaces, 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 * Applies Rhino to Three.js coordinate system transformation.\n * Rhino uses Z-up, Three.js uses Y-up.\n */\nfunction applyCoordinateTransform(vertices: Float32Array): void {\n\tconst cos = Math.cos(-Math.PI / 2);\n\tconst sin = Math.sin(-Math.PI / 2);\n\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\n\t\tvertices[i] = x;\n\t\tvertices[i + 1] = y * cos - z * sin;\n\t\tvertices[i + 2] = y * sin + z * cos;\n\t}\n}\n","import * as fflate from 'fflate';\n\nimport { decodeBase64ToBinary } from '@/core/utils/encoding';\nimport { RhinoComputeError, ErrorCodes } from '@/core/errors';\n\nimport type { DecompressedMeshData } from './types';\n\ninterface MeshData {\n\tverticesArray: Float32Array;\n\tfaceIndicesArray: Uint32Array;\n}\n\n/**\n * Decompresses a base64-encoded string using GZip.\n *\n * @internal Low-level decompression helper — keep internal to `@selvajs/compute`.\n * @param base64String - The base64-encoded string to decompress.\n * @returns The decompressed MeshData.\n * @throws {RhinoComputeError} If decompression fails or data is invalid.\n */\nexport function decompressMeshData(base64String: string): MeshData {\n\ttry {\n\t\tconst bytes = decodeBase64ToBinary(base64String);\n\t\tconst decompressedData = fflate.gunzipSync(bytes);\n\t\treturn parseMeshBinaryData(decompressedData);\n\t} catch (error) {\n\t\tthrow new RhinoComputeError(\n\t\t\terror instanceof RhinoComputeError\n\t\t\t\t? error.message\n\t\t\t\t: `Failed to decompress data: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\terror instanceof RhinoComputeError ? error.code : ErrorCodes.VALIDATION_ERROR,\n\t\t\t{\n\t\t\t\tcontext: { base64StringLength: base64String.length },\n\t\t\t\toriginalError: error instanceof Error ? error : new Error(String(error))\n\t\t\t}\n\t\t);\n\t}\n}\n\n/**\n * Decompresses batched mesh data asynchronously using requestIdleCallback for non-blocking decompression.\n *\n * @internal Low-level decompression helper — keep internal to `@selvajs/compute`.\n * @param base64String - The base64-encoded compressed data.\n * @returns Promise resolving to decompressed vertices and faces arrays.\n * @throws {RhinoComputeError} If decompression fails or data is invalid.\n */\nexport async function decompressBatchedMeshData(\n\tbase64String: string\n): Promise<DecompressedMeshData> {\n\treturn new Promise((resolve, reject) => {\n\t\ttry {\n\t\t\t// Use requestIdleCallback for non-blocking decompression if available\n\t\t\tconst decompressFn = () => {\n\t\t\t\ttry {\n\t\t\t\t\tconst bytes = decodeBase64ToBinary(base64String);\n\t\t\t\t\tconst decompressedData = fflate.gunzipSync(bytes);\n\t\t\t\t\tconst result = parseBatchedMeshBinaryData(decompressedData);\n\t\t\t\t\tresolve(result);\n\t\t\t\t} catch (error) {\n\t\t\t\t\treject(\n\t\t\t\t\t\tnew RhinoComputeError(\n\t\t\t\t\t\t\terror instanceof RhinoComputeError\n\t\t\t\t\t\t\t\t? error.message\n\t\t\t\t\t\t\t\t: `Failed to decompress batched data: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t\t\terror instanceof RhinoComputeError ? error.code : ErrorCodes.VALIDATION_ERROR,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcontext: { base64StringLength: base64String.length },\n\t\t\t\t\t\t\t\toriginalError: error instanceof Error ? error : new Error(String(error))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tif ('requestIdleCallback' in globalThis) {\n\t\t\t\t(globalThis as any).requestIdleCallback(decompressFn, { timeout: 5000 });\n\t\t\t} else {\n\t\t\t\t// Fallback: use setTimeout with 0 delay to yield to other tasks\n\t\t\t\tsetTimeout(decompressFn, 0);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\treject(\n\t\t\t\tnew RhinoComputeError(\n\t\t\t\t\t`Failed to schedule decompression: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t\t\t{ originalError: error instanceof Error ? error : new Error(String(error)) }\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t});\n}\n\n/**\n * Parses batched binary mesh data (all vertices and faces together).\n * @param binaryMeshData - The binary mesh data to parse.\n * @returns The parsed mesh data with vertices and faces.\n * @throws {RhinoComputeError} If data is invalid or insufficient.\n */\nfunction parseBatchedMeshBinaryData(binaryMeshData: Uint8Array): DecompressedMeshData {\n\tconst dataView = new DataView(\n\t\tbinaryMeshData.buffer,\n\t\tbinaryMeshData.byteOffset,\n\t\tbinaryMeshData.byteLength\n\t);\n\tlet offset = 0;\n\n\t// Read vertex data\n\tif (offset + 4 > dataView.byteLength) {\n\t\tthrow new RhinoComputeError(\n\t\t\t'Insufficient data to read the number of vertex floats.',\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{ context: { expectedBytes: 4, availableBytes: dataView.byteLength, offset } }\n\t\t);\n\t}\n\tconst numVertexFloats = dataView.getUint32(offset, true);\n\toffset += 4;\n\n\tif (numVertexFloats % 3 !== 0) {\n\t\tthrow new RhinoComputeError(\n\t\t\t'Invalid number of vertex floats; should be divisible by 3.',\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{\n\t\t\t\tcontext: {\n\t\t\t\t\tnumVertexFloats,\n\t\t\t\t\tremainder: numVertexFloats % 3,\n\t\t\t\t\ttotalBytes: dataView.byteLength\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\tconst verticesByteLength = numVertexFloats * Float32Array.BYTES_PER_ELEMENT;\n\tif (offset + verticesByteLength > dataView.byteLength) {\n\t\tthrow new RhinoComputeError(\n\t\t\t'Insufficient data to read vertices.',\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{\n\t\t\t\tcontext: {\n\t\t\t\t\texpectedBytes: verticesByteLength,\n\t\t\t\t\tavailableBytes: dataView.byteLength - offset,\n\t\t\t\t\toffset\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\t// slice() detaches the views from the gunzip buffer so downstream in-place\n\t// mutations (coordinate transform) don't write back into shared memory.\n\tconst vertices = new Float32Array(\n\t\tbinaryMeshData.buffer.slice(\n\t\t\tbinaryMeshData.byteOffset + offset,\n\t\t\tbinaryMeshData.byteOffset + offset + verticesByteLength\n\t\t)\n\t);\n\toffset += verticesByteLength;\n\n\tif (offset + 4 > dataView.byteLength) {\n\t\tthrow new RhinoComputeError(\n\t\t\t'Insufficient data to read the number of face indices.',\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{ context: { expectedBytes: 4, availableBytes: dataView.byteLength - offset, offset } }\n\t\t);\n\t}\n\tconst numIndices = dataView.getUint32(offset, true);\n\toffset += 4;\n\n\tconst indicesByteLength = numIndices * Uint32Array.BYTES_PER_ELEMENT;\n\tif (offset + indicesByteLength > dataView.byteLength) {\n\t\tthrow new RhinoComputeError(\n\t\t\t'Insufficient data to read face indices.',\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{\n\t\t\t\tcontext: {\n\t\t\t\t\texpectedBytes: indicesByteLength,\n\t\t\t\t\tavailableBytes: dataView.byteLength - offset,\n\t\t\t\t\toffset\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\tconst faces = new Uint32Array(\n\t\tbinaryMeshData.buffer.slice(\n\t\t\tbinaryMeshData.byteOffset + offset,\n\t\t\tbinaryMeshData.byteOffset + offset + indicesByteLength\n\t\t)\n\t);\n\n\treturn {\n\t\tvertices,\n\t\tfaces\n\t};\n}\n\n/**\n * Parses binary data and returns mesh data.\n * @param binaryMeshData - The binary mesh data to parse.\n * @returns The parsed mesh data.\n * @throws {RhinoComputeError} If data is invalid or insufficient.\n */\nfunction parseMeshBinaryData(binaryMeshData: Uint8Array): MeshData {\n\tconst dataView = new DataView(\n\t\tbinaryMeshData.buffer,\n\t\tbinaryMeshData.byteOffset,\n\t\tbinaryMeshData.byteLength\n\t);\n\tlet offset = 0;\n\n\tif (offset + 4 > dataView.byteLength) {\n\t\tthrow new RhinoComputeError(\n\t\t\t'Insufficient data to read the number of vertex floats.',\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{ context: { expectedBytes: 4, availableBytes: dataView.byteLength, offset } }\n\t\t);\n\t}\n\tconst numVertexFloats = dataView.getUint32(offset, true);\n\toffset += 4;\n\n\tif (numVertexFloats % 3 !== 0) {\n\t\tthrow new RhinoComputeError(\n\t\t\t'Invalid number of vertex floats; should be divisible by 3.',\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{ context: { numVertexFloats, remainder: numVertexFloats % 3 } }\n\t\t);\n\t}\n\n\tconst verticesByteLength = numVertexFloats * Float32Array.BYTES_PER_ELEMENT;\n\tif (offset + verticesByteLength > dataView.byteLength) {\n\t\tthrow new RhinoComputeError(\n\t\t\t'Insufficient data to read vertices.',\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{\n\t\t\t\tcontext: {\n\t\t\t\t\texpectedBytes: verticesByteLength,\n\t\t\t\t\tavailableBytes: dataView.byteLength - offset,\n\t\t\t\t\toffset\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\t// slice() detaches views from the gunzip buffer so downstream consumers\n\t// cannot accidentally mutate shared memory.\n\tconst vertices = new Float32Array(\n\t\tbinaryMeshData.buffer.slice(\n\t\t\tbinaryMeshData.byteOffset + offset,\n\t\t\tbinaryMeshData.byteOffset + offset + verticesByteLength\n\t\t)\n\t);\n\toffset += verticesByteLength;\n\n\tif (offset + 4 > dataView.byteLength) {\n\t\tthrow new RhinoComputeError(\n\t\t\t'Insufficient data to read the number of face indices.',\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{ context: { expectedBytes: 4, availableBytes: dataView.byteLength - offset, offset } }\n\t\t);\n\t}\n\tconst numIndices = dataView.getUint32(offset, true);\n\toffset += 4;\n\n\tconst indicesByteLength = numIndices * Uint32Array.BYTES_PER_ELEMENT;\n\tif (offset + indicesByteLength > dataView.byteLength) {\n\t\tthrow new RhinoComputeError(\n\t\t\t'Insufficient data to read face indices.',\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{\n\t\t\t\tcontext: {\n\t\t\t\t\texpectedBytes: indicesByteLength,\n\t\t\t\t\tavailableBytes: dataView.byteLength - offset,\n\t\t\t\t\toffset\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\tconst faceIndices = new Uint32Array(\n\t\tbinaryMeshData.buffer.slice(\n\t\t\tbinaryMeshData.byteOffset + offset,\n\t\t\tbinaryMeshData.byteOffset + offset + indicesByteLength\n\t\t)\n\t);\n\n\treturn {\n\t\tverticesArray: vertices,\n\t\tfaceIndicesArray: faceIndices\n\t};\n}\n","import * as THREE from 'three';\n\nimport { applyOffset, computeCombinedBoundingBox } from '../threejs';\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":"sGAAA,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,EAAY,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,GAA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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","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","THREE","fflate","decompressBatchedMeshData","base64String","resolve","reject","decompressFn","bytes","decodeBase64ToBinary","decompressedData","result","parseBatchedMeshBinaryData","error","RhinoComputeError","ErrorCodes","binaryMeshData","dataView","offset","numVertexFloats","verticesByteLength","vertices","numIndices","indicesByteLength","faces","parseMeshBatch","batchJson","options","mergeByMaterial","applyTransforms","debug","perfStart","parseTime","parseStart","batch","parseMeshBatchObject","error","getLogger","scaleFactor","decompressTime","meshCreateTime","decompressStart","vertices","faces","decompressBatchedMeshData","compressedSizeMB","uncompressedSizeMB","compressionRatio","applyCoordinateTransform","meshCreateStart","materials","createMaterial","meshes","group","mergedMesh","createMergedMesh","individualMeshes","createIndividualMeshes","mesh","totalTime","matData","color","parseColor","allVertices","allFaces","geometry","totalVertexFloats","totalFaceIndices","mergedVertices","mergedIndices","vertexWriteOffset","indexWriteOffset","faceSlice","originalBaseVertexIndex","indexOffset","i","threeMesh","firstMesh","meshNames","m","name","meshMeta","baseIndex","rebasedFaces","cos","sin","x","y","z","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
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@selvajs/compute",
3
- "version": "1.5.1",
3
+ "version": "1.5.2-beta.1",
4
4
  "description": "TypeScript library for Rhino Compute Server - Grasshopper and RhinoCommon",
5
5
  "author": "VektorNode",
6
6
  "license": "MIT",
package/LICENSE.md DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Selva FelixBrunold VektorNode
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,138 +0,0 @@
1
- /**
2
- * ComputeServerStats provides methods to query Rhino Compute server statistics.
3
- *
4
- * @public Use this for server health monitoring and statistics.
5
- *
6
- * @example
7
- * ```typescript
8
- * const stats = new ComputeServerStats('http://localhost:6500', 'your-api-key');
9
- *
10
- * try {
11
- * const isOnline = await stats.isServerOnline();
12
- * const children = await stats.getActiveChildren();
13
- * const version = await stats.getVersion();
14
- *
15
- * // Or get everything at once
16
- * const allStats = await stats.getServerStats();
17
- * } finally {
18
- * await stats.dispose(); // Clean up resources
19
- * }
20
- * ```
21
- */
22
- declare class ComputeServerStats {
23
- private readonly serverUrl;
24
- private readonly apiKey?;
25
- private disposed;
26
- private activeMonitors;
27
- private activeTimeouts;
28
- /**
29
- * @param serverUrl - Base URL of the Rhino Compute server with http:// or https:// scheme (e.g., 'http://localhost:6500')
30
- * @param apiKey - Optional API key for authentication
31
- */
32
- constructor(serverUrl: string, apiKey?: string);
33
- /**
34
- * Build request headers with optional API key.
35
- */
36
- private buildHeaders;
37
- /**
38
- * Check if the server is online.
39
- */
40
- isServerOnline(): Promise<boolean>;
41
- /**
42
- * Get the number of active child processes on the server.
43
- *
44
- * @returns Number of active children, or null if unavailable
45
- */
46
- getActiveChildren(): Promise<number | null>;
47
- /**
48
- * Get the server version information.
49
- *
50
- * @returns Version object with rhino, compute, and git_sha, or null if unavailable
51
- */
52
- getVersion(): Promise<{
53
- rhino: string;
54
- compute: string;
55
- git_sha: string | null;
56
- } | null>;
57
- /**
58
- * Get comprehensive server statistics.
59
- * Fetches all available server information in parallel.
60
- *
61
- * @returns Object containing server status and available stats
62
- */
63
- getServerStats(): Promise<{
64
- isOnline: boolean;
65
- version?: {
66
- rhino: string;
67
- compute: string;
68
- git_sha: string | null;
69
- };
70
- activeChildren?: number;
71
- }>;
72
- /**
73
- * Continuously monitor server stats at specified interval.
74
- *
75
- * @param callback - Function called with stats on each interval
76
- * @param intervalMs - Milliseconds between checks (default: 5000)
77
- * @returns Function to stop monitoring
78
- *
79
- * @example
80
- * ```typescript
81
- * const stopMonitoring = stats.monitor((data) => {
82
- * console.log('Server stats:', data);
83
- * }, 3000);
84
- *
85
- * // Later...
86
- * stopMonitoring();
87
- * ```
88
- */
89
- monitor(callback: (stats: Awaited<ReturnType<typeof this.getServerStats>>) => void, intervalMs?: number): () => void;
90
- /**
91
- * Disposes of all resources and stops all active monitors.
92
- * Call this when you're done using the stats instance.
93
- */
94
- dispose(): Promise<void>;
95
- /**
96
- * Ensures the instance hasn't been disposed.
97
- */
98
- private ensureNotDisposed;
99
- }
100
-
101
- /**
102
- * Simplified error for Rhino Compute operations
103
- *
104
- * @public Use this for error handling with error codes and context.
105
- */
106
- declare class RhinoComputeError extends Error {
107
- readonly code: string;
108
- readonly statusCode?: number;
109
- readonly context?: Record<string, unknown>;
110
- readonly originalError?: Error;
111
- constructor(message: string, code?: string, options?: {
112
- statusCode?: number;
113
- context?: Record<string, unknown>;
114
- originalError?: Error;
115
- });
116
- /**
117
- * Create a generic validation error with custom reason
118
- */
119
- static validation(inputName: string, reason: string, context?: Record<string, unknown>): RhinoComputeError;
120
- /**
121
- * Create an error for missing/empty values
122
- */
123
- static missingValues(inputName: string, expectedType?: string, context?: Record<string, unknown>): RhinoComputeError;
124
- /**
125
- * Create an error for invalid default value in value list
126
- */
127
- static invalidDefault(inputName: string, defaultValue: unknown, availableValues: unknown[], context?: Record<string, unknown>): RhinoComputeError;
128
- /**
129
- * Create an error for unknown parameter type
130
- */
131
- static unknownParamType(paramType: string, paramName?: string, context?: Record<string, unknown>): RhinoComputeError;
132
- /**
133
- * Create an error for invalid input structure
134
- */
135
- static invalidStructure(inputName: string, expectedStructure: string, context?: Record<string, unknown>): RhinoComputeError;
136
- }
137
-
138
- export { ComputeServerStats as C, RhinoComputeError as R };