selva-compute 1.1.4 → 1.2.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-3ECK2JAS.js → chunk-3MVIRDAI.js} +1 -1
- package/dist/{chunk-GIV3ZLXR.cjs → chunk-YBPIKW2A.cjs} +1 -1
- package/dist/{chunk-GIV3ZLXR.cjs.map → chunk-YBPIKW2A.cjs.map} +1 -1
- package/dist/grasshopper.cjs +1 -1
- package/dist/grasshopper.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/visualization.cjs +1 -1
- package/dist/visualization.cjs.map +1 -1
- package/dist/visualization.d.cts +4 -0
- package/dist/visualization.d.ts +4 -0
- package/dist/visualization.js +1 -1
- package/dist/visualization.js.map +1 -1
- package/package.json +1 -1
- /package/dist/{chunk-3ECK2JAS.js.map → chunk-3MVIRDAI.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/visualization.cjs","../src/features/visualization/threejs/three-initializer.ts","../src/features/visualization/threejs/three-helpers.ts"],"names":["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","child","bgColor","animationId","parent","rafId","resizeObserver","getSize","applyResize","width","height","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","handleKeydown","OrbitControls","target","CAMERA_CONFIG","updateScene","mesh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jC,EAAA,CAAIC,CAAAA,CAAQ,UAAA,CAAW,GAAG,CAAA,EAAK,kBAAA,CAAmB,IAAA,CAAKA,CAAO,CAAA,CAC7D,GAAI,CACH,IAAMC,CAAAA,CAAMD,CAAAA,CAAQ,UAAA,CAAW,GAAG,CAAA,CAAIA,CAAAA,CAAU,CAAA,CAAA,EAAIA,CAAO,CAAA,CAAA","file":"/home/runner/work/selva-compute/selva-compute/dist/visualization.cjs","sourcesContent":[null,"import * as THREE from 'three';\nimport { OrbitControls } from 'three/addons/controls/OrbitControls.js';\nimport { HDRLoader } from 'three/addons/loaders/HDRLoader.js';\n\nimport { getLogger } from '@/core';\nimport { ThreeInitializerOptions } from '../types';\n\nconst defaultUp = new THREE.Vector3(0, 0, 1);\n\n/**\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);\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\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}\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// Clear existing children except floor\n\tscene.children.forEach((child) => {\n\t\tif (child.userData.id !== 'floor') {\n\t\t\tscene.remove(child);\n\t\t}\n\t});\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 * 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 is enabled\n\t\tif (controls.enableDamping) {\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 (renderer.domElement.width !== width || renderer.domElement.height !== height) {\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 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\t// Add basic ambient light as fallback\n\t\t\t\tconst ambientLight = new THREE.AmbientLight(0x404040, 0.4);\n\t\t\t\tscene.add(ambientLight);\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(config: Required<ThreeInitializerOptions>): THREE.PerspectiveCamera {\n\t// Get proper aspect ratio from canvas parent or window\n\tconst canvas = document.querySelector('canvas');\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, false);\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 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}\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('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"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/visualization.cjs","../src/features/visualization/threejs/three-initializer.ts","../src/features/visualization/threejs/three-helpers.ts"],"names":["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","CAMERA_CONFIG","updateScene","meshes","initialPositionSet","clearScene","mesh","unionBoundingBox","computeCombinedBoundingBox","parseColor","colorString","trimmed","hex"],"mappings":"AAAA,2/BAAwC,wDAAqE,kMCAtF,yEACO,gEACJ,IAKpBA,CAAAA,CAAY,IAAU,CAAA,CAAA,OAAA,CAAQ,CAAA,CAAG,CAAA,CAAG,CAAC,CAAA,CAS9BC,CAAAA,qBAAY,QAAA,CACxBC,CAAAA,CACAC,CAAAA,CAUC,CACD,IAAMC,CAAAA,CAASC,EAAAA,CAAcF,CAAAA,EAAW,CAAC,CAAC,CAAA,CAGpCG,CAAAA,CAAQC,EAAAA,CAAYH,CAAM,CAAA,CAC1BI,CAAAA,CAASC,EAAAA,CAAaL,CAAAA,CAAQF,CAAM,CAAA,CACpCQ,CAAAA,CAAWC,EAAAA,CAAcT,CAAAA,CAAQE,CAAM,CAAA,CACvCQ,CAAAA,CAAWC,EAAAA,CAAcL,CAAAA,CAAQN,CAAAA,CAAQE,CAAM,CAAA,CAGrDU,EAAAA,CAAiBR,CAAAA,CAAOF,CAAM,CAAA,CAC9BW,EAAAA,CAAcT,CAAAA,CAAOF,CAAM,CAAA,iBAGvBA,CAAAA,qBAAO,KAAA,6BAAO,SAAA,EACjBY,EAAAA,CAASV,CAAAA,CAAOF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AAA,CAGhC,IAAMC,CAAAA,CAAUD,CAAAA,CAAY,IAAA,CAAK,CAAA,CAGjC,EAAA,CAAIC,CAAAA,CAAQ,UAAA,CAAW,GAAG,CAAA,EAAK,kBAAA,CAAmB,IAAA,CAAKA,CAAO,CAAA,CAC7D,GAAI,CACH,IAAMC,CAAAA,CAAMD,CAAAA,CAAQ,UAAA,CAAW,GAAG,CAAA,CAAIA,CAAAA,CAAU,CAAA,CAAA,EAAIA,CAAO,CAAA,CAAA","file":"/home/runner/work/selva-compute/selva-compute/dist/visualization.cjs","sourcesContent":[null,"import * as THREE from 'three';\nimport { OrbitControls } from 'three/addons/controls/OrbitControls.js';\nimport { HDRLoader } from 'three/addons/loaders/HDRLoader.js';\n\nimport { getLogger } from '@/core';\nimport { ThreeInitializerOptions } from '../types';\n\nconst defaultUp = new THREE.Vector3(0, 0, 1);\n\n/**\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"]}
|
package/dist/visualization.d.cts
CHANGED
|
@@ -71,12 +71,16 @@ type EventConfig = {
|
|
|
71
71
|
onObjectSelected?: (object: THREE.Object3D) => void;
|
|
72
72
|
/** Called when a mesh with metadata is clicked. Receives the mesh's metadata object. */
|
|
73
73
|
onMeshMetadataClicked?: (metadata: Record<string, string>) => void;
|
|
74
|
+
/** Called when a mesh is double-clicked. Receives the mesh object. */
|
|
75
|
+
onMeshDoubleClicked?: (object: THREE.Object3D) => void;
|
|
74
76
|
/** Color to use for highlighting selected meshes. Defaults to red (#ff0000). */
|
|
75
77
|
selectionColor?: THREE.Color | string;
|
|
76
78
|
/** Enable all event handlers (click/selection/metadata). Defaults to true. */
|
|
77
79
|
enableEventHandlers?: boolean;
|
|
78
80
|
enableKeyboardControls?: boolean;
|
|
79
81
|
enableClickToFocus?: boolean;
|
|
82
|
+
/** Zoom into a mesh on double-click. Defaults to true. */
|
|
83
|
+
enableDoubleClickZoom?: boolean;
|
|
80
84
|
};
|
|
81
85
|
|
|
82
86
|
/**
|
package/dist/visualization.d.ts
CHANGED
|
@@ -71,12 +71,16 @@ type EventConfig = {
|
|
|
71
71
|
onObjectSelected?: (object: THREE.Object3D) => void;
|
|
72
72
|
/** Called when a mesh with metadata is clicked. Receives the mesh's metadata object. */
|
|
73
73
|
onMeshMetadataClicked?: (metadata: Record<string, string>) => void;
|
|
74
|
+
/** Called when a mesh is double-clicked. Receives the mesh object. */
|
|
75
|
+
onMeshDoubleClicked?: (object: THREE.Object3D) => void;
|
|
74
76
|
/** Color to use for highlighting selected meshes. Defaults to red (#ff0000). */
|
|
75
77
|
selectionColor?: THREE.Color | string;
|
|
76
78
|
/** Enable all event handlers (click/selection/metadata). Defaults to true. */
|
|
77
79
|
enableEventHandlers?: boolean;
|
|
78
80
|
enableKeyboardControls?: boolean;
|
|
79
81
|
enableClickToFocus?: boolean;
|
|
82
|
+
/** Zoom into a mesh on double-click. Defaults to true. */
|
|
83
|
+
enableDoubleClickZoom?: boolean;
|
|
80
84
|
};
|
|
81
85
|
|
|
82
86
|
/**
|
package/dist/visualization.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as N}from"./chunk-WD3ENUAA.js";import{a as Y,d as C,e as M,h as j,i as u}from"./chunk-MK3M76VN.js";import*as i from"three";import{OrbitControls as K}from"three/addons/controls/OrbitControls.js";import{HDRLoader as Z}from"three/addons/loaders/HDRLoader.js";var V=new i.Vector3(0,0,1),k=function(e,r){let t=X(r||{}),n=J(t),o=oe(t),a=ae(e,t),s=ie(o,e,t);te(n,t),ne(n,t),t.floor?.enabled&&re(n,t);let l=t.events.enableEventHandlers!==!1?se(e,n,o,s,t):{dispose:()=>{},fitToView:()=>{},clearSelection:()=>{}},{resize:c,dispose:T}=ee(e,a,o),{animate:m,dispose:h}=Q(a,n,o,s);m();let p=t.environment?.sceneUp||V;return n.up.set(p.x,p.y,p.z),{scene:n,camera:o,controls:s,renderer:a,dispose:()=>{h(),T(),l.dispose(),s.dispose(),a.dispose(),n.traverse(f=>{f instanceof i.Mesh&&(f.geometry?.dispose(),Array.isArray(f.material)?f.material.forEach(v=>v.dispose()):f.material?.dispose())})},resize:c,fitToView:l.fitToView,clearSelection:l.clearSelection}};function X(e){let r=e.sceneScale||"m",n={mm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:10,lightHeight:20,minDistance:.1,shadowSize:100,scaleFactor:1e3},cm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:25,lightHeight:50,minDistance:.1,shadowSize:100,scaleFactor:100},m:{cameraDistance:10,near:.01,far:2e3,floorSize:50,lightDistance:25,lightHeight:50,minDistance:.001,shadowSize:100,scaleFactor:1},inches:{cameraDistance:15,near:.1,far:2e3,floorSize:80,lightDistance:20,lightHeight:40,minDistance:.1,shadowSize:80,scaleFactor:39.37},feet:{cameraDistance:8,near:.1,far:2e3,floorSize:40,lightDistance:15,lightHeight:30,minDistance:.1,shadowSize:60,scaleFactor:3.28084}}[r];return{sceneScale:r,camera:{position:e.camera?.position||new i.Vector3(-n.cameraDistance,n.cameraDistance,n.cameraDistance),fov:e.camera?.fov||20,near:e.camera?.near||n.near,far:e.camera?.far||n.far,target:e.camera?.target||new i.Vector3(0,0,0)},lighting:{enableSunlight:e.lighting?.enableSunlight??!0,sunlightIntensity:e.lighting?.sunlightIntensity||1,sunlightPosition:e.lighting?.sunlightPosition||new i.Vector3(n.lightDistance,n.lightHeight,n.lightDistance),ambientLightColor:e.lighting?.ambientLightColor||new i.Color(4210752),ambientLightIntensity:e.lighting?.ambientLightIntensity||1,sunlightColor:e.lighting?.sunlightColor||16777215},environment:{hdrPath:e.environment?.hdrPath||"/baseHDR.hdr",backgroundColor:e.environment?.backgroundColor||new i.Color(15790320),enableEnvironmentLighting:e.environment?.enableEnvironmentLighting??!0,sceneUp:e.environment?.sceneUp||V,showEnvironment:e.environment?.showEnvironment??!1},floor:{enabled:e.floor?.enabled??!1,size:e.floor?.size||n.floorSize,color:e.floor?.color||new i.Color(8421504),roughness:e.floor?.roughness||.7,metalness:e.floor?.metalness||0,receiveShadow:e.floor?.receiveShadow??!0},render:{enableShadows:e.render?.enableShadows??!0,shadowMapSize:e.render?.shadowMapSize||2048,antialias:e.render?.antialias??!0,pixelRatio:e.render?.pixelRatio||Math.min(window.devicePixelRatio,2),toneMapping:e.render?.toneMapping||i.NeutralToneMapping,toneMappingExposure:e.render?.toneMappingExposure||1,preserveDrawingBuffer:e.render?.preserveDrawingBuffer??!1},controls:{enableDamping:e.controls?.enableDamping??!1,dampingFactor:e.controls?.dampingFactor||.05,autoRotate:e.controls?.autoRotate??!1,autoRotateSpeed:e.controls?.autoRotateSpeed||.5,enableZoom:e.controls?.enableZoom??!0,enablePan:e.controls?.enablePan??!0,minDistance:e.controls?.minDistance||n.minDistance,maxDistance:e.controls?.maxDistance||1/0},events:{onBackgroundClicked:e.events?.onBackgroundClicked,onObjectSelected:e.events?.onObjectSelected,onMeshMetadataClicked:e.events?.onMeshMetadataClicked,selectionColor:e.events?.selectionColor||"#ff0000",enableEventHandlers:e.events?.enableEventHandlers??!0,enableKeyboardControls:e.events?.enableKeyboardControls??!0,enableClickToFocus:e.events?.enableClickToFocus??!0}}}function J(e){let r=new i.Scene;r.children.forEach(n=>{n.userData.id!=="floor"&&r.remove(n)});let t=typeof e.environment.backgroundColor=="string"?new i.Color(e.environment.backgroundColor):e.environment.backgroundColor;return r.background=t||null,r}function Q(e,r,t,n){let o=null,a=function(){o=requestAnimationFrame(a),n.enableDamping&&n.update(),e.render(r,t)};return{animate:a,dispose:()=>{o!==null&&(cancelAnimationFrame(o),o=null)}}}function ee(e,r,t){let n=e.parentElement,o=null,a=null,s=()=>n?{width:n.clientWidth,height:n.clientHeight}:{width:window.innerWidth,height:window.innerHeight},l=()=>{let{width:m,height:h}=s();(r.domElement.width!==m||r.domElement.height!==h)&&(r.setSize(m,h,!1),t.aspect=m/h,t.updateProjectionMatrix())},c=()=>{o!==null&&cancelAnimationFrame(o),o=requestAnimationFrame(()=>{o=requestAnimationFrame(()=>{o=null,l()})})};return typeof ResizeObserver<"u"?(a=new ResizeObserver(c),n?a.observe(n):a.observe(e)):window.addEventListener("resize",c),{resize:c,dispose:()=>{o!==null&&(cancelAnimationFrame(o),o=null),a?a.disconnect():window.removeEventListener("resize",c)}}}function te(e,r){r.environment.enableEnvironmentLighting&&new Z().load(r.environment.hdrPath||"/baseHDR.hdr",function(t){t.mapping=i.EquirectangularReflectionMapping,e.environment=t,r.environment.showEnvironment&&(e.background=t)},void 0,function(t){u().warn("HDR texture could not be loaded, falling back to basic lighting:",t);let n=new i.AmbientLight(4210752,.4);e.add(n)})}function ne(e,r){let t=new i.AmbientLight(r.lighting.ambientLightColor,r.lighting.ambientLightIntensity);if(e.add(t),r.lighting.enableSunlight){let n=new i.DirectionalLight(r.lighting.sunlightColor??16777215,r.lighting.sunlightIntensity),o=r.lighting.sunlightPosition;if(o&&n.position.set(o.x,o.y,o.z),r.render.enableShadows){n.castShadow=!0;let a=r.sceneScale==="mm"?.1:r.sceneScale==="cm"?10:100;n.shadow.camera.left=-a,n.shadow.camera.right=a,n.shadow.camera.top=a,n.shadow.camera.bottom=-a;let s=r.sceneScale==="mm"?.001:r.sceneScale==="cm"?.1:.5,l=r.sceneScale==="mm"?1:r.sceneScale==="cm"?100:500;n.shadow.camera.near=s,n.shadow.camera.far=l,n.shadow.mapSize.width=r.render.shadowMapSize||2048,n.shadow.mapSize.height=r.render.shadowMapSize||2048,n.shadow.bias=-1e-4,n.shadow.normalBias=.02}e.add(n)}}function re(e,r){let t=r.floor.size,n=new i.PlaneGeometry(t,t),o=typeof r.floor.color=="string"?new i.Color(r.floor.color):r.floor.color,a=new i.MeshStandardMaterial({color:o,roughness:r.floor.roughness,metalness:r.floor.metalness,side:i.DoubleSide}),s=new i.Mesh(n,a);s.userData.id="floor",s.name="floor",s.rotation.x=-Math.PI/2,s.position.y=0,r.floor.receiveShadow&&r.render.enableShadows&&(s.receiveShadow=!0),e.add(s)}function oe(e){let t=document.querySelector("canvas")?.parentElement,n=t?t.clientWidth:window.innerWidth,o=t?t.clientHeight:window.innerHeight,a=new i.PerspectiveCamera(e.camera.fov,n/o,e.camera.near,e.camera.far),s=e.camera.position;return s&&a.position.set(s.x,s.y,s.z),a}function ae(e,r){let t=new i.WebGLRenderer({antialias:r.render.antialias,canvas:e,alpha:!0,powerPreference:"high-performance",preserveDrawingBuffer:r.render.preserveDrawingBuffer,logarithmicDepthBuffer:!0}),n=e.parentElement,o=n?n.clientWidth:window.innerWidth,a=n?n.clientHeight:window.innerHeight;return n&&(e.style.width="100%",e.style.height="100%",e.style.display="block"),t.setSize(o,a,!1),t.setPixelRatio(r.render.pixelRatio||Math.min(window.devicePixelRatio,2)),r.render.enableShadows&&(t.shadowMap.enabled=!0,t.shadowMap.type=i.VSMShadowMap),t.toneMapping=r.render.toneMapping||i.ACESFilmicToneMapping,t.toneMappingExposure=r.render.toneMappingExposure||1,t.outputColorSpace=i.SRGBColorSpace,t.sortObjects=!0,t}function se(e,r,t,n,o){let a=new Set,s=new Map,l=new i.Raycaster,c=new i.Vector2,T=new i.Vector2,m=()=>{let d=new i.Box3;if(r.traverse(L=>{L.visible&&L.userData.id!=="floor"&&L instanceof i.Mesh&&d.expandByObject(L)}),d.isEmpty()){u().warn("No objects to fit to view");return}let b=d.getCenter(new i.Vector3),g=d.getSize(new i.Vector3),O=Math.max(g.x,g.y,g.z),y=t.fov*(Math.PI/180),S=O/(2*Math.tan(y/2));S*=1.5;let q=t.position.clone().sub(n.target).normalize();t.position.copy(b.clone().add(q.multiplyScalar(S))),n.target.copy(b),n.update()},h=typeof o.events.selectionColor=="string"?new i.Color(o.events.selectionColor):o.events.selectionColor instanceof i.Color?o.events.selectionColor:new i.Color("#ff0000"),p=()=>{a.forEach(d=>{d instanceof i.Mesh&&s.has(d)&&(d.material=s.get(d),s.delete(d))}),a.clear()},x=d=>{T.set(d.clientX,d.clientY)},f=d=>{let b=new i.Vector2(d.clientX,d.clientY);if(T.distanceTo(b)>5)return;let g=e.getBoundingClientRect();c.x=(d.clientX-g.left)/g.width*2-1,c.y=-((d.clientY-g.top)/g.height)*2+1,l.setFromCamera(c,t);let O=l.intersectObjects(r.children,!0);if(O.length>0){let y=O[0].object;if(!a.has(y)){if(p(),a.add(y),y instanceof i.Mesh&&y.material instanceof i.Material){s.set(y,y.material);let S=y.material.clone();S.emissive=h.clone(),y.material=S}o.events?.onObjectSelected?.(y),y instanceof i.Mesh&&Object.keys(y.userData).length>0&&o.events?.onMeshMetadataClicked?.(y.userData)}}else p(),o.events?.onBackgroundClicked?.({x:c.x,y:c.y})},v=d=>{if(o.events?.enableKeyboardControls)switch(d.key.toLowerCase()){case"f":d.preventDefault(),m();break;case"escape":d.preventDefault(),p();break;case" ":d.preventDefault(),m();break}};return o.events?.enableClickToFocus&&(e.addEventListener("mousedown",x),e.addEventListener("click",f)),o.events?.enableKeyboardControls&&(e.setAttribute("tabindex","0"),e.addEventListener("keydown",v)),{dispose:()=>{e.removeEventListener("mousedown",x),e.removeEventListener("click",f),e.removeEventListener("keydown",v),p()},fitToView:m,clearSelection:p}}function ie(e,r,t){let n=new K(e,r),o=t.camera.target;return o&&n.target.set(o.x,o.y,o.z),n.enableDamping=t.controls.enableDamping||!1,n.dampingFactor=t.controls.dampingFactor||.05,n.autoRotate=t.controls.autoRotate||!1,n.autoRotateSpeed=t.controls.autoRotateSpeed||.5,n.enableZoom=t.controls.enableZoom||!0,n.enablePan=t.controls.enablePan||!0,n.minDistance=t.controls.minDistance||.001,n.maxDistance=t.controls.maxDistance||1/0,n.screenSpacePanning=!1,n.maxPolarAngle=Math.PI,n.update(),n}import*as R from"three";var H={HUGE_THRESHOLD:1e4,LARGE_THRESHOLD:1e3,SCALE_RATIO_THRESHOLD:100,NEAR_PLANE_FACTOR:{TINY:1e-4,SMALL:.001,NORMAL:.01},FAR_PLANE_FACTOR:{HUGE:100,LARGE:50,NORMAL:20},InitialDistanceMultiplier:4};function G(e,r,t,n,o){if(ce(e),r.length===0)return;r.forEach(m=>{e.add(m)});let a=D(r),s=a.getCenter(new R.Vector3),l=a.getSize(new R.Vector3),c=Math.max(l.x,l.y,l.z);if(c/Math.min(l.x||1,l.y||1,l.z||1)>H.SCALE_RATIO_THRESHOLD||c>H.HUGE_THRESHOLD?(t.near=c*H.NEAR_PLANE_FACTOR.TINY,t.far=c*H.FAR_PLANE_FACTOR.HUGE):c>H.LARGE_THRESHOLD?(t.near=c*H.NEAR_PLANE_FACTOR.SMALL,t.far=c*H.FAR_PLANE_FACTOR.LARGE):(t.near=Math.max(.01,c*H.NEAR_PLANE_FACTOR.NORMAL),t.far=Math.max(2e3,c*H.FAR_PLANE_FACTOR.NORMAL)),t.updateProjectionMatrix(),o)n.minDistance=t.near*2,n.maxDistance=t.far*.9;else{let m=c*H.InitialDistanceMultiplier;t.position.set(s.x+m*.8,s.y+m,s.z+m*1.2),n.target.copy(s),n.minDistance=t.near*2,n.maxDistance=t.far*.9,n.update()}}function I(e){if(!e||typeof e!="string")return u().warn(`Invalid color input: ${e}, using white`),new R.Color(16777215);let r=e.trim();if(r.startsWith("#")||/^[0-9A-Fa-f]{6}$/.test(r))try{let t=r.startsWith("#")?r:`#${r}`;return new R.Color(t)}catch{return u().warn(`Invalid hex color: ${e}, using white`),new R.Color(16777215)}if(r.includes(",")){let t=r.split(",").map(n=>parseInt(n.trim(),10));if(t.length===3&&t.every(n=>!isNaN(n)&&n>=0&&n<=255))return new R.Color(t[0]/255,t[1]/255,t[2]/255)}try{return new R.Color(r.toLowerCase())}catch{return u().warn(`Invalid color string: ${e}, using white`),new R.Color(16777215)}}function B(e,r){e.forEach(t=>{t.position.y-=r,t.updateMatrix()})}function D(e){let r=new R.Box3;return e.forEach(t=>{t.updateMatrixWorld(!0);let n=new R.Box3().setFromObject(t);r.union(n)}),r}function ce(e){let r=[];e.traverse(t=>{t instanceof R.Mesh&&t.userData.id!=="floor"&&r.push(t)}),r.forEach(t=>{t instanceof R.Mesh&&(t.geometry?.dispose(),(Array.isArray(t.material)?t.material:[t.material]).forEach(o=>{for(let a in o){let s=o[a];s&&s instanceof R.Texture&&s.dispose()}o.dispose()})),t.removeFromParent()})}var F={};Y(F,{CONCRETE_MATERIAL:()=>de,EMISSIVE_MATERIAL:()=>le,GLASS_MATERIAL:()=>me,METAL_MATERIAL:()=>fe,PLASTIC_MATERIAL:()=>he,RUBBER_MATERIAL:()=>Ee,WOOD_MATERIAL:()=>ue});import*as E from"three";var le=new E.MeshPhysicalMaterial({color:0,emissive:new E.Color(16777215),emissiveIntensity:5,metalness:0,roughness:.2,clearcoat:.3,clearcoatRoughness:.2,depthWrite:!0,depthTest:!0,transparent:!1,alphaTest:0,polygonOffset:!0,side:E.FrontSide,dithering:!0}),fe=new E.MeshPhysicalMaterial({color:new E.Color(0),metalness:.9,roughness:.3,envMapIntensity:1.2,clearcoat:.3,clearcoatRoughness:.2,reflectivity:1,ior:2.5,thickness:1,depthWrite:!0,transparent:!1,alphaTest:0,depthTest:!0,polygonOffset:!0,side:E.FrontSide,dithering:!0}),de=new E.MeshPhysicalMaterial({color:new E.Color(13421772),metalness:0,roughness:.92,envMapIntensity:.15,clearcoat:.05,clearcoatRoughness:.9,reflectivity:.15,transmission:0,ior:1.45,thickness:0,depthWrite:!0,transparent:!1,alphaTest:.5,depthTest:!0,polygonOffset:!0,side:E.FrontSide,dithering:!0}),he=new E.MeshPhysicalMaterial({color:new E.Color(16777215),metalness:0,roughness:.3,envMapIntensity:.5,clearcoat:.5,clearcoatRoughness:.1,reflectivity:.5,ior:1.4,transmission:0,transparent:!1,depthWrite:!0,side:E.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),me=new E.MeshPhysicalMaterial({color:new E.Color(16777215),metalness:0,roughness:0,transmission:.95,transparent:!0,opacity:.3,envMapIntensity:1,clearcoat:1,clearcoatRoughness:0,ior:1.52,reflectivity:.9,thickness:1,side:E.DoubleSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Ee=new E.MeshPhysicalMaterial({color:new E.Color(1710618),metalness:0,roughness:.9,envMapIntensity:.2,clearcoat:.1,clearcoatRoughness:.8,reflectivity:.2,ior:1.3,transmission:0,depthWrite:!0,side:E.FrontSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),ue=new E.MeshPhysicalMaterial({color:new E.Color(8934707),metalness:0,roughness:.7,envMapIntensity:.3,clearcoat:.3,clearcoatRoughness:.4,reflectivity:.3,ior:1.3,transmission:0,depthWrite:!0,side:E.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});import*as w from"three";import*as U from"fflate";j();async function W(e){return new Promise((r,t)=>{try{let n=()=>{try{let o=N(e),a=U.gunzipSync(o),s=pe(a);r(s)}catch(o){t(new M(o instanceof M?o.message:`Failed to decompress batched data: ${o instanceof Error?o.message:String(o)}`,o instanceof M?o.code:C.VALIDATION_ERROR,{context:{base64StringLength:e.length},originalError:o instanceof Error?o:new Error(String(o))}))}};"requestIdleCallback"in globalThis?globalThis.requestIdleCallback(n,{timeout:5e3}):setTimeout(n,0)}catch(n){t(new M(`Failed to schedule decompression: ${n instanceof Error?n.message:String(n)}`,C.VALIDATION_ERROR,{originalError:n instanceof Error?n:new Error(String(n))}))}})}function pe(e){let r=new DataView(e.buffer,e.byteOffset,e.byteLength),t=0;if(t+4>r.byteLength)throw new M("Insufficient data to read the number of vertex floats.",C.VALIDATION_ERROR,{context:{expectedBytes:4,availableBytes:r.byteLength,offset:t}});let n=r.getUint32(t,!0);if(t+=4,n%3!==0)throw new M("Invalid number of vertex floats; should be divisible by 3.",C.VALIDATION_ERROR,{context:{numVertexFloats:n,remainder:n%3,totalBytes:r.byteLength}});let o=n*Float32Array.BYTES_PER_ELEMENT;if(t+o>r.byteLength)throw new M("Insufficient data to read vertices.",C.VALIDATION_ERROR,{context:{expectedBytes:o,availableBytes:r.byteLength-t,offset:t}});let a=new Float32Array(e.buffer,e.byteOffset+t,n);if(t+=o,t+4>r.byteLength)throw new M("Insufficient data to read the number of face indices.",C.VALIDATION_ERROR,{context:{expectedBytes:4,availableBytes:r.byteLength-t,offset:t}});let s=r.getUint32(t,!0);t+=4;let l=s*Uint32Array.BYTES_PER_ELEMENT;if(t+l>r.byteLength)throw new M("Insufficient data to read face indices.",C.VALIDATION_ERROR,{context:{expectedBytes:l,availableBytes:r.byteLength-t,offset:t}});let c=new Uint32Array(e.buffer,e.byteOffset+t,s);return{vertices:a,faces:c}}async function z(e,r){let{mergeByMaterial:t=!0,applyTransforms:n=!0,debug:o=!1}=r??{},a=o?performance.now():0,s=0;try{let l=performance.now(),c=JSON.parse(e);return s=performance.now()-l,await P(c,{mergeByMaterial:t,applyTransforms:n,debug:o,parseTime:s,perfStart:a})}catch(l){return u().error("Error parsing mesh batch:",l),[]}}async function P(e,r){let{mergeByMaterial:t=!0,applyTransforms:n=!0,scaleFactor:o=1,debug:a=!1,parseTime:s=0,perfStart:l=a?performance.now():0}=r??{},c=0,T=0;try{let m=performance.now(),{vertices:h,faces:p}=await W(e.compressedData);c=performance.now()-m;let x=(e.compressedData.length*.75/1024/1024).toFixed(2),f=((h.byteLength+p.byteLength)/1024/1024).toFixed(2),v=((1-parseFloat(x)/parseFloat(f))*100).toFixed(1);a&&(u().debug("Mesh Batch Stats:"),u().debug(` Materials: ${e.materials.length} | Groups: ${e.groups.length}`),u().debug(` Vertices: ${(h.length/3).toLocaleString()} | Faces: ${(p.length/3).toLocaleString()}`),u().debug(` Compressed: ${x} MB | Uncompressed: ${f} MB`),u().debug(` Compression Ratio: ${v}%`)),n&&we(h);let A=performance.now(),d=e.materials.map(ge),b=[];for(let g of e.groups)if(t&&g.meshes.length>1){let O=Re(g,h,p,d);b.push(O)}else{let O=Te(g,h,p,d);b.push(...O)}if(o!==1)for(let g of b)g.scale.set(o,o,o);if(T=performance.now()-A,a){let g=performance.now()-l;u().debug("Performance:"),s>0&&u().debug(` Parse JSON: ${s.toFixed(2)}ms`),u().debug(` Decompress: ${c.toFixed(2)}ms`),u().debug(` Create Meshes: ${T.toFixed(2)}ms`),u().debug(` Total: ${g.toFixed(2)}ms`)}return b}catch(m){return u().error("Error parsing mesh batch object:",m),[]}}function ge(e){let r=I(e.color);return new w.MeshPhysicalMaterial({color:r,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,side:w.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.5,polygonOffsetUnits:.5,depthWrite:!0,depthTest:!0})}function Re(e,r,t,n){let o=new w.BufferGeometry,a=0,s=0;for(let f of e.meshes)a+=f.vertexCount,s+=f.faceCount;let l=new Float32Array(a),c=new Uint32Array(s),T=0,m=0;for(let f of e.meshes){l.set(r.subarray(f.vertexOffset,f.vertexOffset+f.vertexCount),T);let v=t.subarray(f.faceOffset,f.faceOffset+f.faceCount),A=Math.floor(f.vertexOffset/3),b=Math.floor(T/3)-A;for(let g=0;g<v.length;g++)c[m+g]=v[g]+b;T+=f.vertexCount,m+=f.faceCount}o.setAttribute("position",new w.BufferAttribute(l,3)),o.setIndex(new w.BufferAttribute(c,1)),o.computeVertexNormals();let h=new w.Mesh(o,n[e.materialId]),p=e.meshes.map(f=>f.name).filter(f=>f&&f.length>0);h.name=p.length>0?p[0]:`merged_material_${e.materialId}`,h.castShadow=!0,h.receiveShadow=!0;let x=e.meshes.map(f=>f.metadata).filter(f=>f);return x.length>0&&(h.userData.mergedMetadata=x),h}function Te(e,r,t,n){let o=[];for(let a of e.meshes){let s=new w.BufferGeometry,l=r.subarray(a.vertexOffset,a.vertexOffset+a.vertexCount),c=t.subarray(a.faceOffset,a.faceOffset+a.faceCount),T=Math.floor(a.vertexOffset/3),m=new Uint32Array(c.length);for(let p=0;p<c.length;p++)m[p]=c[p]-T;s.setAttribute("position",new w.BufferAttribute(l,3)),s.setIndex(new w.BufferAttribute(m,1)),s.computeVertexNormals();let h=new w.Mesh(s,n[e.materialId]);h.name=a.name,a.metadata&&(h.userData={...h.userData,...a.metadata}),h.castShadow=!0,h.receiveShadow=!0,o.push(h)}return o}function we(e){let r=Math.cos(-Math.PI/2),t=Math.sin(-Math.PI/2);for(let n=0;n<e.length;n+=3){let o=e[n],a=e[n+1],s=e[n+2];e[n]=o,e[n+1]=a*r-s*t,e[n+2]=a*t+s*r}}var _={Millimeters:1/1e3,Centimeters:1/100,Meters:1,Inches:1/39.37,Feet:1/3.28084},ye="Display";async function $(e,r){let t=performance.now(),n=[],{allowScaling:o=!0,allowAutoPosition:a=!0,debug:s=!1,parsing:l={}}=r??{};try{let c=o?be(e.modelunits):1;return await Me(e,n,c,l,s),a&&xe(n),n}catch(c){throw ve(c,n),c}finally{s&&Ce(t)}}function be(e){return _[e]??1}async function Me(e,r,t,n,o){for(let a of e.values){let s=a.InnerTree;for(let l in s){let c=s[l];c&&await He(c,r,t,n,o)}}}async function He(e,r,t,n,o){for(let a of e)if(a.type.includes(ye)){let s={mergeByMaterial:!0,applyTransforms:!0,debug:!1,...n},l=await z(a.data,s);if(t!==1)for(let c of l)c.scale.set(t,t,t);r.push(...l),o&&u().debug(`Extracted ${l.length} meshes from batch`)}}function xe(e){if(e.length===0)return;let t=D(e).min.y;B(e,t)}function ve(e,r){u().error("An unexpected error occurred:",e),Oe(r)}function Oe(e){for(let r of e)r.geometry&&r.geometry.dispose(),r.material&&(Array.isArray(r.material)?r.material.forEach(t=>t.dispose()):r.material.dispose())}function Ce(e){let r=performance.now()-e;u().info("Time to process meshes:",`${r.toFixed(2)}ms`)}export{F as Materials,_ as SCALE_FACTORS,$ as getThreeMeshesFromComputeResponse,k as initThree,P as parseMeshBatchObject,G as updateScene};
|
|
1
|
+
import{c as N}from"./chunk-WD3ENUAA.js";import{a as J,d as S,e as x,h as Q,i as p}from"./chunk-MK3M76VN.js";import*as i from"three";import{OrbitControls as ee}from"three/addons/controls/OrbitControls.js";import{HDRLoader as te}from"three/addons/loaders/HDRLoader.js";var G=new i.Vector3(0,0,1),U=function(e,r){let t=ne(r||{}),n=re(t),o=fe(t,e),s=de(e,t),a=me(o,e,t);ie(n,t),ce(n,t),t.floor?.enabled&&le(n,t);let l=t.events.enableEventHandlers!==!1?he(e,n,o,a,t):{dispose:()=>{},fitToView:()=>{},clearSelection:()=>{}},{resize:c,dispose:R}=ae(e,s,o),{animate:m,dispose:h}=se(s,n,o,a);m();let E=t.environment?.sceneUp||G;return n.up.set(E.x,E.y,E.z),{scene:n,camera:o,controls:a,renderer:s,dispose:()=>{h(),R(),l.dispose(),a.dispose(),s.dispose(),n.traverse(f=>{f instanceof i.Mesh&&(f.geometry?.dispose(),Array.isArray(f.material)?f.material.forEach(H=>H.dispose()):f.material?.dispose())})},resize:c,fitToView:l.fitToView,clearSelection:l.clearSelection}};function ne(e){let r=e.sceneScale||"m",n={mm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:10,lightHeight:20,minDistance:.1,shadowSize:100,scaleFactor:1e3},cm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:25,lightHeight:50,minDistance:.1,shadowSize:100,scaleFactor:100},m:{cameraDistance:10,near:.01,far:2e3,floorSize:50,lightDistance:25,lightHeight:50,minDistance:.001,shadowSize:100,scaleFactor:1},inches:{cameraDistance:15,near:.1,far:2e3,floorSize:80,lightDistance:20,lightHeight:40,minDistance:.1,shadowSize:80,scaleFactor:39.37},feet:{cameraDistance:8,near:.1,far:2e3,floorSize:40,lightDistance:15,lightHeight:30,minDistance:.1,shadowSize:60,scaleFactor:3.28084}}[r];return{sceneScale:r,camera:{position:e.camera?.position||new i.Vector3(-n.cameraDistance,n.cameraDistance,n.cameraDistance),fov:e.camera?.fov||20,near:e.camera?.near||n.near,far:e.camera?.far||n.far,target:e.camera?.target||new i.Vector3(0,0,0)},lighting:{enableSunlight:e.lighting?.enableSunlight??!0,sunlightIntensity:e.lighting?.sunlightIntensity||1,sunlightPosition:e.lighting?.sunlightPosition||new i.Vector3(n.lightDistance,n.lightHeight,n.lightDistance),ambientLightColor:e.lighting?.ambientLightColor||new i.Color(4210752),ambientLightIntensity:e.lighting?.ambientLightIntensity||1,sunlightColor:e.lighting?.sunlightColor||16777215},environment:{hdrPath:e.environment?.hdrPath||"/baseHDR.hdr",backgroundColor:e.environment?.backgroundColor||new i.Color(15790320),enableEnvironmentLighting:e.environment?.enableEnvironmentLighting??!0,sceneUp:e.environment?.sceneUp||G,showEnvironment:e.environment?.showEnvironment??!1},floor:{enabled:e.floor?.enabled??!1,size:e.floor?.size||n.floorSize,color:e.floor?.color||new i.Color(8421504),roughness:e.floor?.roughness||.7,metalness:e.floor?.metalness||0,receiveShadow:e.floor?.receiveShadow??!0},render:{enableShadows:e.render?.enableShadows??!0,shadowMapSize:e.render?.shadowMapSize||2048,antialias:e.render?.antialias??!0,pixelRatio:e.render?.pixelRatio||Math.min(window.devicePixelRatio,2),toneMapping:e.render?.toneMapping||i.NeutralToneMapping,toneMappingExposure:e.render?.toneMappingExposure||1,preserveDrawingBuffer:e.render?.preserveDrawingBuffer??!1},controls:{enableDamping:e.controls?.enableDamping??!1,dampingFactor:e.controls?.dampingFactor||.05,autoRotate:e.controls?.autoRotate??!1,autoRotateSpeed:e.controls?.autoRotateSpeed||.5,enableZoom:e.controls?.enableZoom??!0,enablePan:e.controls?.enablePan??!0,minDistance:e.controls?.minDistance||n.minDistance,maxDistance:e.controls?.maxDistance||1/0},events:{onBackgroundClicked:e.events?.onBackgroundClicked,onObjectSelected:e.events?.onObjectSelected,onMeshMetadataClicked:e.events?.onMeshMetadataClicked,onMeshDoubleClicked:e.events?.onMeshDoubleClicked,selectionColor:e.events?.selectionColor||"#ff0000",enableEventHandlers:e.events?.enableEventHandlers??!0,enableKeyboardControls:e.events?.enableKeyboardControls??!0,enableClickToFocus:e.events?.enableClickToFocus??!0,enableDoubleClickZoom:e.events?.enableDoubleClickZoom??!0}}}function re(e){let r=new i.Scene,t=typeof e.environment.backgroundColor=="string"?new i.Color(e.environment.backgroundColor):e.environment.backgroundColor;return r.background=t||null,r}function oe(e,r,t,n,o=200){let s=e.position.clone(),a=r.target.clone(),l=performance.now(),c=m=>1-Math.pow(1-m,3),R=()=>{let m=performance.now()-l,h=c(Math.min(m/o,1));e.position.lerpVectors(s,t,h),r.target.lerpVectors(a,n,h),r.update(),h<1&&requestAnimationFrame(R)};requestAnimationFrame(R)}function se(e,r,t,n){let o=null,s=function(){o=requestAnimationFrame(s),(n.enableDamping||n.autoRotate)&&n.update(),e.render(r,t)};return{animate:s,dispose:()=>{o!==null&&(cancelAnimationFrame(o),o=null)}}}function ae(e,r,t){let n=e.parentElement,o=null,s=null,a=()=>n?{width:n.clientWidth,height:n.clientHeight}:{width:window.innerWidth,height:window.innerHeight},l=()=>{let{width:m,height:h}=a();if(m===0||h===0)return;let E=Math.min(window.devicePixelRatio,2),M=Math.round(r.domElement.clientWidth*E),f=Math.round(r.domElement.clientHeight*E),H=Math.round(m*E),C=Math.round(h*E);(M!==H||f!==C)&&(r.setPixelRatio(E),r.setSize(m,h,!0),t.aspect=m/h,t.updateProjectionMatrix())},c=()=>{o!==null&&cancelAnimationFrame(o),o=requestAnimationFrame(()=>{o=requestAnimationFrame(()=>{o=null,l()})})};return typeof ResizeObserver<"u"?(s=new ResizeObserver(c),n?s.observe(n):s.observe(e)):window.addEventListener("resize",c),{resize:c,dispose:()=>{o!==null&&(cancelAnimationFrame(o),o=null),s?s.disconnect():window.removeEventListener("resize",c)}}}function ie(e,r){r.environment.enableEnvironmentLighting&&new te().load(r.environment.hdrPath||"/baseHDR.hdr",function(t){t.mapping=i.EquirectangularReflectionMapping,e.environment=t,r.environment.showEnvironment&&(e.background=t)},void 0,function(t){p().warn("HDR texture could not be loaded, falling back to basic lighting:",t)})}function ce(e,r){let t=new i.AmbientLight(r.lighting.ambientLightColor,r.lighting.ambientLightIntensity);if(e.add(t),r.lighting.enableSunlight){let n=new i.DirectionalLight(r.lighting.sunlightColor??16777215,r.lighting.sunlightIntensity),o=r.lighting.sunlightPosition;if(o&&n.position.set(o.x,o.y,o.z),r.render.enableShadows){n.castShadow=!0;let s=r.sceneScale==="mm"?.1:r.sceneScale==="cm"?10:100;n.shadow.camera.left=-s,n.shadow.camera.right=s,n.shadow.camera.top=s,n.shadow.camera.bottom=-s;let a=r.sceneScale==="mm"?.001:r.sceneScale==="cm"?.1:.5,l=r.sceneScale==="mm"?1:r.sceneScale==="cm"?100:500;n.shadow.camera.near=a,n.shadow.camera.far=l,n.shadow.mapSize.width=r.render.shadowMapSize||2048,n.shadow.mapSize.height=r.render.shadowMapSize||2048,n.shadow.bias=-1e-4,n.shadow.normalBias=.02}e.add(n)}}function le(e,r){let t=r.floor.size,n=new i.PlaneGeometry(t,t),o=typeof r.floor.color=="string"?new i.Color(r.floor.color):r.floor.color,s=new i.MeshStandardMaterial({color:o,roughness:r.floor.roughness,metalness:r.floor.metalness,side:i.DoubleSide}),a=new i.Mesh(n,s);a.userData.id="floor",a.name="floor",a.rotation.x=-Math.PI/2,a.position.y=0,r.floor.receiveShadow&&r.render.enableShadows&&(a.receiveShadow=!0),e.add(a)}function fe(e,r){let t=r.parentElement,n=t?t.clientWidth:window.innerWidth,o=t?t.clientHeight:window.innerHeight,s=new i.PerspectiveCamera(e.camera.fov,n/o,e.camera.near,e.camera.far),a=e.camera.position;return a&&s.position.set(a.x,a.y,a.z),s}function de(e,r){let t=new i.WebGLRenderer({antialias:r.render.antialias,canvas:e,alpha:!0,powerPreference:"high-performance",preserveDrawingBuffer:r.render.preserveDrawingBuffer,logarithmicDepthBuffer:!0}),n=e.parentElement,o=n?n.clientWidth:window.innerWidth,s=n?n.clientHeight:window.innerHeight;return n&&(e.style.width="100%",e.style.height="100%",e.style.display="block"),t.setSize(o,s,!0),t.setPixelRatio(r.render.pixelRatio||Math.min(window.devicePixelRatio,2)),r.render.enableShadows&&(t.shadowMap.enabled=!0,t.shadowMap.type=i.VSMShadowMap),t.toneMapping=r.render.toneMapping||i.ACESFilmicToneMapping,t.toneMappingExposure=r.render.toneMappingExposure||1,t.outputColorSpace=i.SRGBColorSpace,t.sortObjects=!0,t}function he(e,r,t,n,o){let s=new Set,a=new Map,l=new i.Raycaster,c=new i.Vector2,R=new i.Vector2,m=()=>{let d=new i.Box3;if(r.traverse(D=>{D.visible&&D.userData.id!=="floor"&&D instanceof i.Mesh&&d.expandByObject(D)}),d.isEmpty()){p().warn("No objects to fit to view");return}let g=d.getCenter(new i.Vector3),y=d.getSize(new i.Vector3),A=Math.max(y.x,y.y,y.z),T=t.fov*(Math.PI/180),O=A/(2*Math.tan(T/2));O*=1.5;let L=t.position.clone().sub(n.target).normalize();t.position.copy(g.clone().add(L.multiplyScalar(O))),n.target.copy(g),n.update()},h=typeof o.events.selectionColor=="string"?new i.Color(o.events.selectionColor):o.events.selectionColor instanceof i.Color?o.events.selectionColor:new i.Color("#ff0000"),E=()=>{s.forEach(d=>{d instanceof i.Mesh&&a.has(d)&&(d.material=a.get(d),a.delete(d))}),s.clear()},M=d=>{R.set(d.clientX,d.clientY)},f=d=>{let g=new i.Vector2(d.clientX,d.clientY);if(R.distanceTo(g)>5)return;let y=e.getBoundingClientRect();c.x=(d.clientX-y.left)/y.width*2-1,c.y=-((d.clientY-y.top)/y.height)*2+1,l.setFromCamera(c,t);let A=l.intersectObjects(r.children,!0);if(A.length>0){let T=A[0].object;if(!s.has(T)){if(E(),s.add(T),T instanceof i.Mesh&&T.material instanceof i.Material){a.set(T,T.material);let O=T.material.clone();O.emissive=h.clone(),T.material=O}o.events?.onObjectSelected?.(T),T instanceof i.Mesh&&Object.keys(T.userData).length>0&&o.events?.onMeshMetadataClicked?.(T.userData)}}else E(),o.events?.onBackgroundClicked?.({x:c.x,y:c.y})},H=d=>{let g=e.getBoundingClientRect();c.x=(d.clientX-g.left)/g.width*2-1,c.y=-((d.clientY-g.top)/g.height)*2+1,l.setFromCamera(c,t);let y=l.intersectObjects(r.children,!0);if(y.length===0)return;let A=y[0].object;if(o.events?.onMeshDoubleClicked?.(A),!o.events?.enableDoubleClickZoom)return;let T=new i.Box3().setFromObject(A);if(T.isEmpty())return;let O=T.getCenter(new i.Vector3),L=T.getSize(new i.Vector3),D=Math.max(L.x,L.y,L.z),j=t.fov*(Math.PI/180),Z=D/(2*Math.tan(j/2))*1.5,K=t.position.clone().sub(n.target).normalize(),X=O.clone().add(K.multiplyScalar(Z));oe(t,n,X,O)},C=d=>{if(o.events?.enableKeyboardControls)switch(d.key.toLowerCase()){case"f":d.preventDefault(),m();break;case"escape":d.preventDefault(),E();break;case" ":d.preventDefault(),m();break}};return o.events?.enableClickToFocus&&(e.addEventListener("mousedown",M),e.addEventListener("click",f),e.addEventListener("dblclick",H)),o.events?.enableKeyboardControls&&(e.setAttribute("tabindex","0"),e.addEventListener("keydown",C)),{dispose:()=>{e.removeEventListener("mousedown",M),e.removeEventListener("click",f),e.removeEventListener("dblclick",H),e.removeEventListener("keydown",C),E()},fitToView:m,clearSelection:E}}function me(e,r,t){let n=new ee(e,r),o=t.camera.target;return o&&n.target.set(o.x,o.y,o.z),n.enableDamping=t.controls.enableDamping||!1,n.dampingFactor=t.controls.dampingFactor||.05,n.autoRotate=t.controls.autoRotate||!1,n.autoRotateSpeed=t.controls.autoRotateSpeed||.5,n.enableZoom=t.controls.enableZoom??!0,n.enablePan=t.controls.enablePan??!0,n.minDistance=t.controls.minDistance||.001,n.maxDistance=t.controls.maxDistance||1/0,n.screenSpacePanning=!1,n.maxPolarAngle=Math.PI,n.update(),n}import*as w from"three";var v={HUGE_THRESHOLD:1e4,LARGE_THRESHOLD:1e3,SCALE_RATIO_THRESHOLD:100,NEAR_PLANE_FACTOR:{TINY:1e-4,SMALL:.001,NORMAL:.01},FAR_PLANE_FACTOR:{HUGE:100,LARGE:50,NORMAL:20},InitialDistanceMultiplier:4};function W(e,r,t,n,o){if(Ee(e),r.length===0)return;r.forEach(m=>{e.add(m)});let s=B(r),a=s.getCenter(new w.Vector3),l=s.getSize(new w.Vector3),c=Math.max(l.x,l.y,l.z);if(c/Math.min(l.x||1,l.y||1,l.z||1)>v.SCALE_RATIO_THRESHOLD||c>v.HUGE_THRESHOLD?(t.near=c*v.NEAR_PLANE_FACTOR.TINY,t.far=c*v.FAR_PLANE_FACTOR.HUGE):c>v.LARGE_THRESHOLD?(t.near=c*v.NEAR_PLANE_FACTOR.SMALL,t.far=c*v.FAR_PLANE_FACTOR.LARGE):(t.near=Math.max(.01,c*v.NEAR_PLANE_FACTOR.NORMAL),t.far=Math.max(2e3,c*v.FAR_PLANE_FACTOR.NORMAL)),t.updateProjectionMatrix(),o)n.minDistance=t.near*2,n.maxDistance=t.far*.9;else{let m=c*v.InitialDistanceMultiplier;t.position.set(a.x+m*.8,a.y+m,a.z+m*1.2),n.target.copy(a),n.minDistance=t.near*2,n.maxDistance=t.far*.9,n.update()}}function F(e){if(!e||typeof e!="string")return p().warn(`Invalid color input: ${e}, using white`),new w.Color(16777215);let r=e.trim();if(r.startsWith("#")||/^[0-9A-Fa-f]{6}$/.test(r))try{let t=r.startsWith("#")?r:`#${r}`;return new w.Color(t)}catch{return p().warn(`Invalid hex color: ${e}, using white`),new w.Color(16777215)}if(r.includes(",")){let t=r.split(",").map(n=>parseInt(n.trim(),10));if(t.length===3&&t.every(n=>!isNaN(n)&&n>=0&&n<=255))return new w.Color(t[0]/255,t[1]/255,t[2]/255)}try{return new w.Color(r.toLowerCase())}catch{return p().warn(`Invalid color string: ${e}, using white`),new w.Color(16777215)}}function P(e,r){e.forEach(t=>{t.position.y-=r,t.updateMatrix()})}function B(e){let r=new w.Box3;return e.forEach(t=>{t.updateMatrixWorld(!0);let n=new w.Box3().setFromObject(t);r.union(n)}),r}function Ee(e){let r=[];e.traverse(t=>{t instanceof w.Mesh&&t.userData.id!=="floor"&&r.push(t)}),r.forEach(t=>{t instanceof w.Mesh&&(t.geometry?.dispose(),(Array.isArray(t.material)?t.material:[t.material]).forEach(o=>{for(let s in o){let a=o[s];a&&a instanceof w.Texture&&a.dispose()}o.dispose()})),t.removeFromParent()})}var z={};J(z,{CONCRETE_MATERIAL:()=>ge,EMISSIVE_MATERIAL:()=>ue,GLASS_MATERIAL:()=>Te,METAL_MATERIAL:()=>pe,PLASTIC_MATERIAL:()=>Re,RUBBER_MATERIAL:()=>we,WOOD_MATERIAL:()=>ye});import*as u from"three";var ue=new u.MeshPhysicalMaterial({color:0,emissive:new u.Color(16777215),emissiveIntensity:5,metalness:0,roughness:.2,clearcoat:.3,clearcoatRoughness:.2,depthWrite:!0,depthTest:!0,transparent:!1,alphaTest:0,polygonOffset:!0,side:u.FrontSide,dithering:!0}),pe=new u.MeshPhysicalMaterial({color:new u.Color(0),metalness:.9,roughness:.3,envMapIntensity:1.2,clearcoat:.3,clearcoatRoughness:.2,reflectivity:1,ior:2.5,thickness:1,depthWrite:!0,transparent:!1,alphaTest:0,depthTest:!0,polygonOffset:!0,side:u.FrontSide,dithering:!0}),ge=new u.MeshPhysicalMaterial({color:new u.Color(13421772),metalness:0,roughness:.92,envMapIntensity:.15,clearcoat:.05,clearcoatRoughness:.9,reflectivity:.15,transmission:0,ior:1.45,thickness:0,depthWrite:!0,transparent:!1,alphaTest:.5,depthTest:!0,polygonOffset:!0,side:u.FrontSide,dithering:!0}),Re=new u.MeshPhysicalMaterial({color:new u.Color(16777215),metalness:0,roughness:.3,envMapIntensity:.5,clearcoat:.5,clearcoatRoughness:.1,reflectivity:.5,ior:1.4,transmission:0,transparent:!1,depthWrite:!0,side:u.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Te=new u.MeshPhysicalMaterial({color:new u.Color(16777215),metalness:0,roughness:0,transmission:.95,transparent:!0,opacity:.3,envMapIntensity:1,clearcoat:1,clearcoatRoughness:0,ior:1.52,reflectivity:.9,thickness:1,side:u.DoubleSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),we=new u.MeshPhysicalMaterial({color:new u.Color(1710618),metalness:0,roughness:.9,envMapIntensity:.2,clearcoat:.1,clearcoatRoughness:.8,reflectivity:.2,ior:1.3,transmission:0,depthWrite:!0,side:u.FrontSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),ye=new u.MeshPhysicalMaterial({color:new u.Color(8934707),metalness:0,roughness:.7,envMapIntensity:.3,clearcoat:.3,clearcoatRoughness:.4,reflectivity:.3,ior:1.3,transmission:0,depthWrite:!0,side:u.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});import*as b from"three";import*as $ from"fflate";Q();async function q(e){return new Promise((r,t)=>{try{let n=()=>{try{let o=N(e),s=$.gunzipSync(o),a=be(s);r(a)}catch(o){t(new x(o instanceof x?o.message:`Failed to decompress batched data: ${o instanceof Error?o.message:String(o)}`,o instanceof x?o.code:S.VALIDATION_ERROR,{context:{base64StringLength:e.length},originalError:o instanceof Error?o:new Error(String(o))}))}};"requestIdleCallback"in globalThis?globalThis.requestIdleCallback(n,{timeout:5e3}):setTimeout(n,0)}catch(n){t(new x(`Failed to schedule decompression: ${n instanceof Error?n.message:String(n)}`,S.VALIDATION_ERROR,{originalError:n instanceof Error?n:new Error(String(n))}))}})}function be(e){let r=new DataView(e.buffer,e.byteOffset,e.byteLength),t=0;if(t+4>r.byteLength)throw new x("Insufficient data to read the number of vertex floats.",S.VALIDATION_ERROR,{context:{expectedBytes:4,availableBytes:r.byteLength,offset:t}});let n=r.getUint32(t,!0);if(t+=4,n%3!==0)throw new x("Invalid number of vertex floats; should be divisible by 3.",S.VALIDATION_ERROR,{context:{numVertexFloats:n,remainder:n%3,totalBytes:r.byteLength}});let o=n*Float32Array.BYTES_PER_ELEMENT;if(t+o>r.byteLength)throw new x("Insufficient data to read vertices.",S.VALIDATION_ERROR,{context:{expectedBytes:o,availableBytes:r.byteLength-t,offset:t}});let s=new Float32Array(e.buffer,e.byteOffset+t,n);if(t+=o,t+4>r.byteLength)throw new x("Insufficient data to read the number of face indices.",S.VALIDATION_ERROR,{context:{expectedBytes:4,availableBytes:r.byteLength-t,offset:t}});let a=r.getUint32(t,!0);t+=4;let l=a*Uint32Array.BYTES_PER_ELEMENT;if(t+l>r.byteLength)throw new x("Insufficient data to read face indices.",S.VALIDATION_ERROR,{context:{expectedBytes:l,availableBytes:r.byteLength-t,offset:t}});let c=new Uint32Array(e.buffer,e.byteOffset+t,a);return{vertices:s,faces:c}}async function _(e,r){let{mergeByMaterial:t=!0,applyTransforms:n=!0,debug:o=!1}=r??{},s=o?performance.now():0,a=0;try{let l=performance.now(),c=JSON.parse(e);return a=performance.now()-l,await V(c,{mergeByMaterial:t,applyTransforms:n,debug:o,parseTime:a,perfStart:s})}catch(l){return p().error("Error parsing mesh batch:",l),[]}}async function V(e,r){let{mergeByMaterial:t=!0,applyTransforms:n=!0,scaleFactor:o=1,debug:s=!1,parseTime:a=0,perfStart:l=s?performance.now():0}=r??{},c=0,R=0;try{let m=performance.now(),{vertices:h,faces:E}=await q(e.compressedData);c=performance.now()-m;let M=(e.compressedData.length*.75/1024/1024).toFixed(2),f=((h.byteLength+E.byteLength)/1024/1024).toFixed(2),H=((1-parseFloat(M)/parseFloat(f))*100).toFixed(1);s&&(p().debug("Mesh Batch Stats:"),p().debug(` Materials: ${e.materials.length} | Groups: ${e.groups.length}`),p().debug(` Vertices: ${(h.length/3).toLocaleString()} | Faces: ${(E.length/3).toLocaleString()}`),p().debug(` Compressed: ${M} MB | Uncompressed: ${f} MB`),p().debug(` Compression Ratio: ${H}%`)),n&&ve(h);let C=performance.now(),I=e.materials.map(Me),d=[];for(let g of e.groups)if(t&&g.meshes.length>1){let y=He(g,h,E,I);d.push(y)}else{let y=xe(g,h,E,I);d.push(...y)}if(o!==1)for(let g of d)g.scale.set(o,o,o);if(R=performance.now()-C,s){let g=performance.now()-l;p().debug("Performance:"),a>0&&p().debug(` Parse JSON: ${a.toFixed(2)}ms`),p().debug(` Decompress: ${c.toFixed(2)}ms`),p().debug(` Create Meshes: ${R.toFixed(2)}ms`),p().debug(` Total: ${g.toFixed(2)}ms`)}return d}catch(m){return p().error("Error parsing mesh batch object:",m),[]}}function Me(e){let r=F(e.color);return new b.MeshPhysicalMaterial({color:r,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,side:b.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.5,polygonOffsetUnits:.5,depthWrite:!0,depthTest:!0})}function He(e,r,t,n){let o=new b.BufferGeometry,s=0,a=0;for(let f of e.meshes)s+=f.vertexCount,a+=f.faceCount;let l=new Float32Array(s),c=new Uint32Array(a),R=0,m=0;for(let f of e.meshes){l.set(r.subarray(f.vertexOffset,f.vertexOffset+f.vertexCount),R);let H=t.subarray(f.faceOffset,f.faceOffset+f.faceCount),C=Math.floor(f.vertexOffset/3),d=Math.floor(R/3)-C;for(let g=0;g<H.length;g++)c[m+g]=H[g]+d;R+=f.vertexCount,m+=f.faceCount}o.setAttribute("position",new b.BufferAttribute(l,3)),o.setIndex(new b.BufferAttribute(c,1)),o.computeVertexNormals();let h=new b.Mesh(o,n[e.materialId]),E=e.meshes.map(f=>f.name).filter(f=>f&&f.length>0);h.name=E.length>0?E[0]:`merged_material_${e.materialId}`,h.castShadow=!0,h.receiveShadow=!0;let M=e.meshes.map(f=>f.metadata).filter(f=>f);return M.length>0&&(h.userData.mergedMetadata=M),h}function xe(e,r,t,n){let o=[];for(let s of e.meshes){let a=new b.BufferGeometry,l=r.subarray(s.vertexOffset,s.vertexOffset+s.vertexCount),c=t.subarray(s.faceOffset,s.faceOffset+s.faceCount),R=Math.floor(s.vertexOffset/3),m=new Uint32Array(c.length);for(let E=0;E<c.length;E++)m[E]=c[E]-R;a.setAttribute("position",new b.BufferAttribute(l,3)),a.setIndex(new b.BufferAttribute(m,1)),a.computeVertexNormals();let h=new b.Mesh(a,n[e.materialId]);h.name=s.name,s.metadata&&(h.userData={...h.userData,...s.metadata}),h.castShadow=!0,h.receiveShadow=!0,o.push(h)}return o}function ve(e){let r=Math.cos(-Math.PI/2),t=Math.sin(-Math.PI/2);for(let n=0;n<e.length;n+=3){let o=e[n],s=e[n+1],a=e[n+2];e[n]=o,e[n+1]=s*r-a*t,e[n+2]=s*t+a*r}}var k={Millimeters:1/1e3,Centimeters:1/100,Meters:1,Inches:1/39.37,Feet:1/3.28084},Ce="Display";async function Y(e,r){let t=performance.now(),n=[],{allowScaling:o=!0,allowAutoPosition:s=!0,debug:a=!1,parsing:l={}}=r??{};try{let c=o?Oe(e.modelunits):1;return await Se(e,n,c,l,a),s&&De(n),n}catch(c){throw Le(c,n),c}finally{a&&Be(t)}}function Oe(e){return k[e]??1}async function Se(e,r,t,n,o){for(let s of e.values){let a=s.InnerTree;for(let l in a){let c=a[l];c&&await Ae(c,r,t,n,o)}}}async function Ae(e,r,t,n,o){for(let s of e)if(s.type.includes(Ce)){let a={mergeByMaterial:!0,applyTransforms:!0,debug:!1,...n},l=await _(s.data,a);if(t!==1)for(let c of l)c.scale.set(t,t,t);r.push(...l),o&&p().debug(`Extracted ${l.length} meshes from batch`)}}function De(e){if(e.length===0)return;let t=B(e).min.y;P(e,t)}function Le(e,r){p().error("An unexpected error occurred:",e),Ie(r)}function Ie(e){for(let r of e)r.geometry&&r.geometry.dispose(),r.material&&(Array.isArray(r.material)?r.material.forEach(t=>t.dispose()):r.material.dispose())}function Be(e){let r=performance.now()-e;p().info("Time to process meshes:",`${r.toFixed(2)}ms`)}export{z as Materials,k as SCALE_FACTORS,Y as getThreeMeshesFromComputeResponse,U as initThree,V as parseMeshBatchObject,W as updateScene};
|
|
2
2
|
//# sourceMappingURL=visualization.js.map
|