selva-compute 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-5H6EJVX3.cjs → chunk-7AD5GVQO.cjs} +1 -1
- package/dist/{chunk-5H6EJVX3.cjs.map → chunk-7AD5GVQO.cjs.map} +1 -1
- package/dist/{chunk-V3TFZJFZ.js → chunk-WYX224LA.js} +1 -1
- package/dist/grasshopper.cjs +1 -1
- package/dist/grasshopper.d.cts +1 -1
- package/dist/grasshopper.d.ts +1 -1
- package/dist/grasshopper.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{types-BARMhgxW.d.cts → types-B24K2LG4.d.cts} +9 -1
- package/dist/{types-BARMhgxW.d.ts → types-B24K2LG4.d.ts} +9 -1
- package/dist/visualization.cjs +1 -1
- package/dist/visualization.cjs.map +1 -1
- package/dist/visualization.d.cts +7 -8
- package/dist/visualization.d.ts +7 -8
- package/dist/visualization.js +1 -1
- package/dist/visualization.js.map +1 -1
- package/package.json +3 -1
- /package/dist/{chunk-V3TFZJFZ.js.map → chunk-WYX224LA.js.map} +0 -0
|
@@ -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/**\n * Initializes a comprehensive Three.js environment with enhanced render quality and flexible configuration.\n *\n * @param canvas - The HTML canvas element to render the scene on.\n * @param options - Configuration options for the Three.js environment.\n * @returns An object containing the scene, camera, controls, renderer, and utility methods.\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\tresize: () => void;\n\tfitToView: () => void;\n\tclearSelection: () => void;\n} {\n\tconst config = applyDefaults(options || {});\n\n\t// Initialize core components\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\t// Setup environment and lighting\n\tsetupEnvironment(scene, config);\n\tsetupLighting(scene, config);\n\n\t// Add floor if enabled\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\t// Handle resizing\n\tconst { resize, dispose: disposeResize } = setupResponsiveResize(canvas, renderer, camera);\n\n\t// Animation loop\n\tconst { animate, dispose: disposeAnimation } = createAnimationLoop(\n\t\trenderer,\n\t\tscene,\n\t\tcamera,\n\t\tcontrols\n\t);\n\tanimate();\n\n\t// Set scene up vector\n\tconst sceneUp = config.environment?.sceneUp || defaultUp;\n\tscene.up.set(sceneUp.x, sceneUp.y, sceneUp.z);\n\n\t// Comprehensive disposal\n\tconst dispose = () => {\n\t\tdisposeAnimation(); // Stop animation loop\n\t\tdisposeResize(); // Remove resize listeners\n\t\teventHandlers.dispose(); // Remove click/keyboard listeners\n\t\tcontrols.dispose(); // Dispose controls\n\t\trenderer.dispose(); // Dispose renderer\n\n\t\t// Dispose geometries and materials\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\tresize,\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// Define sensible defaults for each scale\n\t// Note: 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\t// Geometry scaled UP by 1000x (mm to m conversion for better precision)\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\t// Geometry scaled UP by 100x (cm to m conversion)\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\t// Natural Three.js scale (1 unit = 1 meter)\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\t// Geometry scaled UP by ~39.37x (inches to m conversion)\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\t// Geometry scaled UP by ~3.28x (feet to m conversion)\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}\n\t};\n}\n\n/**\n * Creates and configures the scene.\n */\nfunction createScene(config: Required<ThreeInitializerOptions>): THREE.Scene {\n\tconst scene = new THREE.Scene();\n\n\t// Set background color\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\n/**\n * Smoothly animates the camera to a new position and target using an ease-out curve.\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\t// Ease-out cubic\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/**\n * Creates an optimized animation loop with proper disposal.\n */\nfunction createAnimationLoop(\n\trenderer: THREE.WebGLRenderer,\n\tscene: THREE.Scene,\n\tcamera: THREE.PerspectiveCamera,\n\tcontrols: OrbitControls\n): { animate: () => void; dispose: () => void } {\n\tlet animationId: number | null = null;\n\n\tconst animate = function () {\n\t\tanimationId = requestAnimationFrame(animate);\n\n\t\t// Update controls if damping or auto-rotate is enabled\n\t\tif (controls.enableDamping || controls.autoRotate) {\n\t\t\tcontrols.update();\n\t\t}\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\n/**\n * Sets up responsive resizing with double-rAF for accurate post-layout measurements.\n * Observes the parent container when present. When the canvas has no parent (fullscreen /\n * position:fixed), observes the canvas directly so mobile fullscreen transitions are caught\n * reliably. Observing both simultaneously is intentionally avoided: setSize() mutates the\n * canvas dimensions and would cause redundant observer callbacks on every resize.\n */\nfunction setupResponsiveResize(\n\tcanvas: HTMLCanvasElement,\n\trenderer: THREE.WebGLRenderer,\n\tcamera: THREE.PerspectiveCamera\n): { resize: () => void; dispose: () => void } {\n\tconst parent = canvas.parentElement;\n\tlet rafId: number | null = null;\n\tlet resizeObserver: ResizeObserver | null = null;\n\n\tconst getSize = () =>\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\tconst applyResize = () => {\n\t\tconst { width, height } = getSize();\n\t\tif (width === 0 || height === 0) return;\n\n\t\tconst pixelRatio = Math.min(window.devicePixelRatio, 2);\n\t\tconst currentW = Math.round(renderer.domElement.clientWidth * pixelRatio);\n\t\tconst currentH = Math.round(renderer.domElement.clientHeight * pixelRatio);\n\t\tconst newW = Math.round(width * pixelRatio);\n\t\tconst newH = Math.round(height * pixelRatio);\n\n\t\tif (currentW !== newW || currentH !== newH) {\n\t\t\trenderer.setPixelRatio(pixelRatio);\n\t\t\trenderer.setSize(width, height, true);\n\t\t\tcamera.aspect = width / height;\n\t\t\tcamera.updateProjectionMatrix();\n\t\t}\n\t};\n\n\tconst handleResize = () => {\n\t\t// Cancel any pending rAF\n\t\tif (rafId !== null) cancelAnimationFrame(rafId);\n\n\t\t// Double rAF: first frame lets the browser finish layout,\n\t\t// second frame guarantees clientWidth/Height are stable and accurate.\n\t\t// This fixes mobile fullscreen transitions where setTimeout(fn, 16)\n\t\t// fires before the new layout is fully committed.\n\t\trafId = requestAnimationFrame(() => {\n\t\t\trafId = requestAnimationFrame(() => {\n\t\t\t\trafId = null;\n\t\t\t\tapplyResize();\n\t\t\t});\n\t\t});\n\t};\n\n\tif (typeof ResizeObserver !== 'undefined') {\n\t\tresizeObserver = new ResizeObserver(handleResize);\n\t\tif (parent) {\n\t\t\t// Normal case: observe parent container; setSize() changes canvas attrs but\n\t\t\t// the parent is not affected, so no feedback loop.\n\t\t\tresizeObserver.observe(parent);\n\t\t} else {\n\t\t\t// Fullscreen / position:fixed case: observe canvas directly.\n\t\t\t// The guard in applyResize (domElement.width !== width) prevents\n\t\t\t// infinite loops caused by setSize() mutating the canvas dimensions.\n\t\t\tresizeObserver.observe(canvas);\n\t\t}\n\t} else {\n\t\t// Fallback for older browsers\n\t\twindow.addEventListener('resize', handleResize);\n\t}\n\n\tconst dispose = () => {\n\t\tif (rafId !== null) {\n\t\t\tcancelAnimationFrame(rafId);\n\t\t\trafId = null;\n\t\t}\n\t\tif (resizeObserver) {\n\t\t\tresizeObserver.disconnect();\n\t\t} else {\n\t\t\twindow.removeEventListener('resize', handleResize);\n\t\t}\n\t};\n\n\treturn { resize: handleResize, dispose };\n}\n\n/**\n * Sets up environment lighting and HDR.\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},\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}\n\t\t);\n\t}\n}\n\nfunction setupLighting(scene: THREE.Scene, config: Required<ThreeInitializerOptions>) {\n\t// Add ambient light\n\tconst ambientLight = new THREE.AmbientLight(\n\t\tconfig.lighting.ambientLightColor,\n\t\tconfig.lighting.ambientLightIntensity\n\t);\n\tscene.add(ambientLight);\n\n\t// Add directional light (sunlight)\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 = config.sceneScale === 'mm' ? 0.1 : config.sceneScale === 'cm' ? 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 =\n\t\t\t\tconfig.sceneScale === 'mm' ? 0.001 : config.sceneScale === 'cm' ? 0.1 : 0.5;\n\n\t\t\tconst shadowFar = config.sceneScale === 'mm' ? 1 : config.sceneScale === 'cm' ? 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\t// Improved shadow quality\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\n/**\n * Adds a floor to the scene with scale-aware sizing.\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\n/**\n * Creates and configures the camera with proper aspect ratio.\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/**\n * Sets up enhanced WebGL renderer with improved quality settings.\n */\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\t// Enable logarithmic depth buffer for extreme scale ranges\n\t\t// This dramatically improves depth precision for mixed scales (mm to km)\n\t\tlogarithmicDepthBuffer: true\n\t});\n\n\t// Get proper dimensions - parent container or window\n\tconst parent = canvas.parentElement;\n\tconst width = parent ? parent.clientWidth : window.innerWidth;\n\tconst height = parent ? parent.clientHeight : window.innerHeight;\n\n\t// Set canvas style to fill parent if it exists\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, true);\n\trenderer.setPixelRatio(config.render.pixelRatio || Math.min(window.devicePixelRatio, 2));\n\n\t// Enhanced shadow settings\n\tif (config.render.enableShadows) {\n\t\trenderer.shadowMap.enabled = true;\n\t\t// Use VSM for better quality with extreme scales\n\t\trenderer.shadowMap.type = THREE.VSMShadowMap;\n\t}\n\n\t// Improved tone mapping and color management\n\trenderer.toneMapping = config.render.toneMapping || THREE.ACESFilmicToneMapping;\n\trenderer.toneMappingExposure = config.render.toneMappingExposure || 1.0;\n\trenderer.outputColorSpace = THREE.SRGBColorSpace;\n\n\t// Additional quality settings for depth rendering\n\trenderer.sortObjects = true; // Ensure proper render order\n\n\treturn renderer;\n}\n\n// Add event handler setup function\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// Fit scene to view\n\tconst fitToView = () => {\n\t\tconst box = new THREE.Box3();\n\n\t\t// Calculate bounding box of all visible objects (excluding floor)\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\t// Calculate distance needed to fit the object\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\t// Add some padding\n\t\tdistance *= 1.5;\n\n\t\t// Position camera\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\t// Update controls target\n\t\tcontrols.target.copy(center);\n\t\tcontrols.update();\n\t};\n\n\t// Parse selection color\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\t// Clear selection\n\tconst clearSelection = () => {\n\t\tselectedObjects.forEach((obj) => {\n\t\t\t// Restore original material\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\t// Handle canvas clicks\n\tconst handleCanvasClick = (event: MouseEvent) => {\n\t\t// Ignore if mouse has moved significantly (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\t// Calculate mouse position in normalized device coordinates\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\t// Raycast to find intersected objects\n\t\traycaster.setFromCamera(mouse, camera);\n\t\tconst intersects = raycaster.intersectObjects(scene.children, true);\n\n\t\tif (intersects.length > 0) {\n\t\t\tconst clickedObject = intersects[0].object;\n\n\t\t\t// Handle object selection\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 and apply selection color only to this mesh\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\t// Store original material\n\t\t\t\t\toriginalMaterials.set(clickedObject, clickedObject.material);\n\n\t\t\t\t\t// Clone the material so we don't affect other meshes\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\t// Call metadata callback if the mesh has metadata\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\t// Background clicked\n\t\t\tclearSelection();\n\t\t\tconfig.events?.onBackgroundClicked?.({ x: mouse.x, y: mouse.y });\n\t\t}\n\t};\n\n\t// Handle double-click to zoom into mesh\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.intersectObjects(scene.children, true);\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\t// Handle keyboard events\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\t// Add event listeners\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\t// Make canvas focusable\n\t\tcanvas.setAttribute('tabindex', '0');\n\t\t// Only listen for keydown when canvas has focus\n\t\tcanvas.addEventListener('keydown', handleKeydown);\n\t}\n\n\t// Disposal function\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\n/**\n * Sets up enhanced orbit controls with scale-aware distances.\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\t// Set target\n\tconst target = config.camera.target;\n\tif (target) {\n\t\tcontrols.target.set(target.x, target.y, target.z);\n\t}\n\n\t// Configure damping\n\tcontrols.enableDamping = config.controls.enableDamping || false;\n\tcontrols.dampingFactor = config.controls.dampingFactor || 0.05;\n\n\t// Configure auto rotation\n\tcontrols.autoRotate = config.controls.autoRotate || false;\n\tcontrols.autoRotateSpeed = config.controls.autoRotateSpeed || 0.5;\n\n\t// Configure interaction limits\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\t// Smooth controls\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\tInitialDistanceMultiplier: 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.InitialDistanceMultiplier;\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\t// THREE.Color constructor accepts r, g, b in range [0, 1]\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\t// Ensure world matrix is pending update if needed\n\t\tmesh.updateMatrix();\n\t});\n}\n\n/**\n * Computes the combined AI 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\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 * Updates shadow camera bounds to match scene geometry.\n * This prevents shadow artifacts and ensures proper shadow coverage.\n * @param scene - The scene containing geometry.\n * @param directionalLight - The light to update.\n * @param optionalBounds - Optional pre-calculated bounds to avoid scene traversal.\n */\nexport function updateShadowCameraBounds(\n\tscene: THREE.Scene,\n\tdirectionalLight: THREE.DirectionalLight,\n\toptionalBounds?: THREE.Box3\n): void {\n\tlet bbox = optionalBounds;\n\n\tif (!bbox) {\n\t\tbbox = new THREE.Box3();\n\t\tscene.traverse((object) => {\n\t\t\tif (object instanceof THREE.Mesh && object.userData.id !== 'floor') {\n\t\t\t\t// Use setFromObject to ensure world transforms are respected\n\t\t\t\tconst objBbox = new THREE.Box3().setFromObject(object);\n\t\t\t\tbbox!.union(objBbox);\n\t\t\t}\n\t\t});\n\t}\n\n\tif (!bbox || bbox.isEmpty()) return;\n\n\tconst size = bbox.getSize(new THREE.Vector3());\n\tconst center = bbox.getCenter(new THREE.Vector3());\n\tconst maxDim = Math.max(size.x, size.y, size.z);\n\n\t// Position light relative to scene center\n\tconst lightDistance = maxDim * 2;\n\tdirectionalLight.position.set(\n\t\tcenter.x + lightDistance * 0.5,\n\t\tcenter.y + lightDistance,\n\t\tcenter.z + lightDistance * 0.5\n\t);\n\tdirectionalLight.target.position.copy(center);\n\n\t// Adjust shadow camera bounds to scene size with padding\n\tconst padding = maxDim * 0.2;\n\tdirectionalLight.shadow.camera.left = -maxDim / 2 - padding;\n\tdirectionalLight.shadow.camera.right = maxDim / 2 + padding;\n\tdirectionalLight.shadow.camera.top = maxDim / 2 + padding;\n\tdirectionalLight.shadow.camera.bottom = -maxDim / 2 - padding;\n\tdirectionalLight.shadow.camera.near = 0.1;\n\tdirectionalLight.shadow.camera.far = lightDistance * 3;\n\n\t// Improve shadow quality for extreme scales\n\tif (maxDim > CAMERA_CONFIG.LARGE_THRESHOLD) {\n\t\tdirectionalLight.shadow.bias = -0.001;\n\t\tdirectionalLight.shadow.normalBias = 0.05;\n\t} else {\n\t\tdirectionalLight.shadow.bias = -0.0001;\n\t\tdirectionalLight.shadow.normalBias = 0.02;\n\t}\n\n\tdirectionalLight.shadow.camera.updateProjectionMatrix();\n}\n\n/**\n * Clears the given THREE.Scene by removing all meshes and disposing of associated resources.\n * @param scene - The THREE.Scene to clear.\n */\nfunction clearScene(scene: THREE.Scene): void {\n\tconst objectsToRemove: THREE.Object3D[] = [];\n\n\t// Collect all meshes except the floor\n\tscene.traverse((child: THREE.Object3D) => {\n\t\tif (child instanceof THREE.Mesh && child.userData.id !== 'floor') {\n\t\t\tobjectsToRemove.push(child);\n\t\t}\n\t});\n\n\t// Remove and dispose of each object\n\tobjectsToRemove.forEach((object: THREE.Object3D) => {\n\t\tif (object instanceof THREE.Mesh) {\n\t\t\tobject.geometry?.dispose();\n\n\t\t\tconst materials = Array.isArray(object.material) ? object.material : [object.material];\n\t\t\tmaterials.forEach((material) => {\n\t\t\t\t// Dispose textures first\n\t\t\t\tfor (const key in material) {\n\t\t\t\t\tconst value = material[key as keyof THREE.Material];\n\t\t\t\t\tif (value && 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 `selva-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 `selva-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\tmeshes.push(mergedMesh);\n\t\t\t} else {\n\t\t\t\tconst individualMeshes = createIndividualMeshes(group, vertices, faces, materials);\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, or combine names if multiple meshes\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\tconst allMetadata = group.meshes.map((m) => m.metadata).filter((m) => m);\n\tif (allMetadata.length > 0) {\n\t\tthreeMesh.userData.mergedMetadata = allMetadata;\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\tif (meshMeta.metadata) {\n\t\t\tmesh.userData = { ...mesh.userData, ...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 `selva-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 `selva-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\tconst vertices = new Float32Array(\n\t\tbinaryMeshData.buffer,\n\t\tbinaryMeshData.byteOffset + offset,\n\t\tnumVertexFloats\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,\n\t\tbinaryMeshData.byteOffset + offset,\n\t\tnumIndices\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\tconst vertices = new Float32Array(\n\t\tbinaryMeshData.buffer,\n\t\tbinaryMeshData.byteOffset + offset,\n\t\tnumVertexFloats\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,\n\t\tbinaryMeshData.byteOffset + offset,\n\t\tnumIndices\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":"4GAAA,UAAYA,MAAW,QACvB,OAAS,iBAAAC,OAAqB,yCAC9B,OAAS,aAAAC,OAAiB,oCAK1B,IAAMC,EAAY,IAAU,UAAQ,EAAG,EAAG,CAAC,EAS9BC,EAAY,SACxBC,EACAC,EAUC,CACD,IAAMC,EAASC,GAAcF,GAAW,CAAC,CAAC,EAGpCG,EAAQC,GAAYH,CAAM,EAC1BI,EAASC,GAAaL,EAAQF,CAAM,EACpCQ,EAAWC,GAAcT,EAAQE,CAAM,EACvCQ,EAAWC,GAAcL,EAAQN,EAAQE,CAAM,EAGrDU,GAAiBR,EAAOF,CAAM,EAC9BW,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GAAkBD,EAAQhB,EAAQK,EAAaD,EAAgBD,CAAK,CAC3E,CACD,CACD,CAKA,eAAec,GACdD,EACAhB,EACAK,EACAD,EACAD,EACgB,CAChB,QAAWe,KAAQF,EAClB,GAAIE,EAAK,KAAK,SAASvB,EAAsB,EAAG,CAC/C,IAAMwB,EAAuB,CAC5B,gBAAiB,GACjB,gBAAiB,GACjB,MAAO,GACP,GAAGf,CACJ,EAEMgB,EAAc,MAAMC,EAAeH,EAAK,KAAMC,CAAoB,EAExE,GAAId,IAAgB,EACnB,QAAWiB,KAAQF,EAClBE,EAAK,MAAM,IAAIjB,EAAaA,EAAaA,CAAW,EAItDL,EAAO,KAAK,GAAGoB,CAAW,EAEtBjB,GACHoB,EAAU,EAAE,MAAM,aAAaH,EAAY,MAAM,oBAAoB,CAEvE,CAEF,CAKA,SAASZ,GAAkBR,EAA4B,CACtD,GAAIA,EAAO,SAAW,EAAG,OAGzB,IAAMwB,EADsBC,EAA2BzB,CAAM,EACzB,IAAI,EACxC0B,EAAY1B,EAAQwB,CAAO,CAC5B,CAKA,SAASd,GAAYD,EAAgBT,EAA4B,CAChEuB,EAAU,EAAE,MAAM,gCAAiCd,CAAK,EACxDkB,GAAc3B,CAAM,CACrB,CAKA,SAAS2B,GAAc3B,EAA4B,CAClD,QAAWsB,KAAQtB,EACdsB,EAAK,UACRA,EAAK,SAAS,QAAQ,EAGnBA,EAAK,WACJ,MAAM,QAAQA,EAAK,QAAQ,EAC9BA,EAAK,SAAS,QAASM,GAAaA,EAAS,QAAQ,CAAC,EAEtDN,EAAK,SAAS,QAAQ,EAI1B,CAKA,SAASX,GAAkBZ,EAAyB,CACnD,IAAM8B,EAAU,YAAY,IAAI,EAAI9B,EACpCwB,EAAU,EAAE,KAAK,0BAA2B,GAAGM,EAAQ,QAAQ,CAAC,CAAC,IAAI,CACtE","names":["THREE","OrbitControls","HDRLoader","defaultUp","initThree","canvas","options","config","applyDefaults","scene","createScene","camera","createCamera","renderer","setupRenderer","controls","setupControls","setupEnvironment","setupLighting","addFloor","eventHandlers","setupEventHandlers","resize","disposeResize","setupResponsiveResize","animate","disposeAnimation","createAnimationLoop","sceneUp","object","material","scale","defaults","bgColor","animateCameraTo","toPosition","toTarget","durationMs","fromPosition","fromTarget","startTime","easeOut","t","tick","elapsed","animationId","parent","rafId","resizeObserver","getSize","applyResize","width","height","pixelRatio","currentW","currentH","newW","newH","handleResize","HDRLoader","envMap","error","getLogger","ambientLight","sunlight","pos","shadowSize","shadowNear","shadowFar","floorSize","floorGeometry","floorColor","floorMaterial","floor","selectedObjects","originalMaterials","raycaster","mouse","mouseDownPosition","fitToView","box","center","size","maxDim","fov","distance","direction","selectionColorObj","clearSelection","obj","handleMouseDown","event","handleCanvasClick","currentMousePosition","rect","intersects","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","clearScene","scene","objectsToRemove","child","object","material","key","value","three_materials_exports","__export","CONCRETE_MATERIAL","EMISSIVE_MATERIAL","GLASS_MATERIAL","METAL_MATERIAL","PLASTIC_MATERIAL","RUBBER_MATERIAL","WOOD_MATERIAL","THREE","THREE","fflate","init_errors","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","meshNames","m","name","allMetadata","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":["../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\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.intersectObjects(scene.children, true);\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.intersectObjects(scene.children, true);\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\tfor (const key in material) {\n\t\t\t\t\tconst value = material[key as keyof THREE.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 `selva-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 `selva-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 `selva-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 `selva-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\tconst vertices = new Float32Array(\n\t\tbinaryMeshData.buffer,\n\t\tbinaryMeshData.byteOffset + offset,\n\t\tnumVertexFloats\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,\n\t\tbinaryMeshData.byteOffset + offset,\n\t\tnumIndices\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\tconst vertices = new Float32Array(\n\t\tbinaryMeshData.buffer,\n\t\tbinaryMeshData.byteOffset + offset,\n\t\tnumVertexFloats\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,\n\t\tbinaryMeshData.byteOffset + offset,\n\t\tnumIndices\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":"6GAAA,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,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,KAAQF,EAClB,GAAIE,EAAK,KAAK,SAASvB,EAAsB,EAAG,CAC/C,IAAMwB,EAAuB,CAC5B,gBAAiB,GACjB,gBAAiB,GACjB,MAAO,GACP,GAAGf,CACJ,EAEMgB,EAAc,MAAMC,EAAeH,EAAK,KAAMC,CAAoB,EAExE,GAAId,IAAgB,EACnB,QAAWiB,KAAQF,EAClBE,EAAK,MAAM,IAAIjB,EAAaA,EAAaA,CAAW,EAItDL,EAAO,KAAK,GAAGoB,CAAW,EAEtBjB,GACHoB,EAAU,EAAE,MAAM,aAAaH,EAAY,MAAM,oBAAoB,CAEvE,CAEF,CAKA,SAASZ,GAAkBR,EAA4B,CACtD,GAAIA,EAAO,SAAW,EAAG,OAGzB,IAAMwB,EADsBC,EAA2BzB,CAAM,EACzB,IAAI,EACxC0B,EAAY1B,EAAQwB,CAAO,CAC5B,CAKA,SAASd,GAAYD,EAAgBT,EAA4B,CAChEuB,EAAU,EAAE,MAAM,gCAAiCd,CAAK,EACxDkB,GAAc3B,CAAM,CACrB,CAKA,SAAS2B,GAAc3B,EAA4B,CAClD,QAAWsB,KAAQtB,EACdsB,EAAK,UACRA,EAAK,SAAS,QAAQ,EAGnBA,EAAK,WACJ,MAAM,QAAQA,EAAK,QAAQ,EAC9BA,EAAK,SAAS,QAASM,GAAaA,EAAS,QAAQ,CAAC,EAEtDN,EAAK,SAAS,QAAQ,EAI1B,CAKA,SAASX,GAAkBZ,EAAyB,CACnD,IAAM8B,EAAU,YAAY,IAAI,EAAI9B,EACpCwB,EAAU,EAAE,KAAK,0BAA2B,GAAGM,EAAQ,QAAQ,CAAC,CAAC,IAAI,CACtE","names":["THREE","OrbitControls","HDRLoader","defaultUp","getScaleValue","scale","mmVal","cmVal","mVal","initThree","canvas","options","config","applyDefaults","scene","createScene","camera","createCamera","renderer","setupRenderer","controls","setupControls","setupEnvironment","setupLighting","addFloor","eventHandlers","setupEventHandlers","parent","getCanvasSize","animate","disposeAnimation","createAnimationLoop","sceneUp","object","material","defaults","bgColor","animateCameraTo","toPosition","toTarget","durationMs","fromPosition","fromTarget","startTime","easeOut","t","tick","elapsed","onFrame","animationId","lastTime","checkResize","width","height","pixelRatio","newW","newH","now","delta","HDRLoader","envMap","error","getLogger","ambientLight","sunlight","pos","shadowSize","shadowNear","shadowFar","floorSize","floorGeometry","floorColor","floorMaterial","floor","selectedObjects","originalMaterials","raycaster","mouse","mouseDownPosition","fitToView","box","center","size","maxDim","fov","distance","direction","selectionColorObj","clearSelection","obj","handleMouseDown","event","handleCanvasClick","currentMousePosition","rect","intersects","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","key","value","three_materials_exports","__export","CONCRETE_MATERIAL","EMISSIVE_MATERIAL","GLASS_MATERIAL","METAL_MATERIAL","PLASTIC_MATERIAL","RUBBER_MATERIAL","WOOD_MATERIAL","THREE","THREE","fflate","init_errors","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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "selva-compute",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "TypeScript library for Rhino Compute Server - Grasshopper and RhinoCommon",
|
|
5
5
|
"author": "VektorNode",
|
|
6
6
|
"license": "MIT",
|
|
@@ -99,11 +99,13 @@
|
|
|
99
99
|
"typedoc-plugin-missing-exports": "^4.1.2",
|
|
100
100
|
"typescript": "^5.9.3",
|
|
101
101
|
"typescript-eslint": "^8.56.1",
|
|
102
|
+
"vite": "^8.0.8",
|
|
102
103
|
"vitest": "^3.2.4"
|
|
103
104
|
},
|
|
104
105
|
"scripts": {
|
|
105
106
|
"build": " pnpm type-check && pnpm clean && tsup",
|
|
106
107
|
"dev": "tsup --watch",
|
|
108
|
+
"example": "vite --config vite.config.ts",
|
|
107
109
|
"clean": "node --input-type=module -e \"import fs from 'fs'; fs.rmSync('dist', { recursive: true, force: true })\"",
|
|
108
110
|
"lint": "eslint .",
|
|
109
111
|
"lint:fix": "eslint . --fix",
|
|
File without changes
|