@selvajs/visualization 1.0.0-beta.0 → 1.0.0-beta.2
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/README.md +11 -10
- package/dist/gpu-dispose-Dkj-BKt4.js +2 -0
- package/dist/gpu-dispose-Dkj-BKt4.js.map +1 -0
- package/dist/gpu-dispose-DrN-ryj5.cjs +2 -0
- package/dist/gpu-dispose-DrN-ryj5.cjs.map +1 -0
- package/dist/index.cjs +0 -1
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -1
- package/dist/parse.cjs +3 -3
- package/dist/parse.cjs.map +1 -1
- package/dist/parse.d.cts +135 -142
- package/dist/parse.d.ts +135 -142
- package/dist/parse.js +3 -3
- package/dist/parse.js.map +1 -1
- package/dist/render.cjs +8 -10
- package/dist/render.cjs.map +1 -1
- package/dist/render.d.cts +335 -333
- package/dist/render.d.ts +335 -333
- package/dist/render.js +8 -10
- package/dist/render.js.map +1 -1
- package/dist/rolldown-runtime-BocRIvOZ.cjs +1 -0
- package/dist/scene.cjs +1 -1
- package/dist/scene.cjs.map +1 -1
- package/dist/scene.d.cts +95 -95
- package/dist/scene.d.ts +95 -95
- package/dist/scene.js +1 -1
- package/dist/scene.js.map +1 -1
- package/dist/types-Di80Y609.d.cts +34 -0
- package/dist/types-Di80Y609.d.ts +34 -0
- package/package.json +14 -10
- package/dist/chunk-5XGN7UAV.js +0 -2
- package/dist/chunk-5XGN7UAV.js.map +0 -1
- package/dist/chunk-AQJPVUH3.cjs +0 -2
- package/dist/chunk-AQJPVUH3.cjs.map +0 -1
- package/dist/chunk-BYLIBOAU.cjs +0 -2
- package/dist/chunk-BYLIBOAU.cjs.map +0 -1
- package/dist/chunk-EXAI6IC5.js +0 -2
- package/dist/chunk-EXAI6IC5.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types-CdF9R3qA.d.cts +0 -41
- package/dist/types-CdF9R3qA.d.ts +0 -41
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ layering enforced by the import graph rather than merely documented.
|
|
|
45
45
|
Only what a consumer genuinely needs is exported. In particular:
|
|
46
46
|
|
|
47
47
|
- **`initThree` owns the render toolkit.** It builds the camera controller, grid, gizmo, measure
|
|
48
|
-
tool, render pipeline and near-
|
|
48
|
+
tool, render pipeline and the camera's near-clip fitting, and returns the live instances on
|
|
49
49
|
[`ThreeViewer`](./src/render/scene-setup/viewer.ts). Configure them through
|
|
50
50
|
`ThreeInitializerOptions`, reach them through the viewer (`viewer.grid`, `viewer.measureTool`,
|
|
51
51
|
`viewer.applyEdges`, …). The factories themselves are internal — their handle _types_ are exported
|
|
@@ -53,7 +53,7 @@ Only what a consumer genuinely needs is exported. In particular:
|
|
|
53
53
|
- **`createSceneOutliner` composes the scene layer.** Content filtering, layer grouping, visibility
|
|
54
54
|
and selection state are reachable via `outliner.visibility` / `.selection` / `.layerGroups()`.
|
|
55
55
|
- **The SLVA binary wire format is private.** Magics, version gates, flag bits and the low-level
|
|
56
|
-
binary parser are implementation details of `
|
|
56
|
+
binary parser are implementation details of `parseBinaryMeshBatch*` and change without a major bump.
|
|
57
57
|
|
|
58
58
|
When adding a feature, resist re-exporting a symbol just because it exists — a published surface is
|
|
59
59
|
a compatibility promise.
|
|
@@ -72,8 +72,8 @@ jsdom has no WebGL.
|
|
|
72
72
|
pnpm example # http://localhost:5173
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
Three demos: **Viewer — Full API** (every `initThree` control), **
|
|
76
|
-
`.
|
|
75
|
+
Three demos: **Viewer — Full API** (every `initThree` control), **Mesh File — Selva Pipeline** (loads a
|
|
76
|
+
`.slvm` mesh file through the same parse + `updateScene` calls `Viewer.svelte` makes), and **Display Items**
|
|
77
77
|
(a GH compute response through `getThreeMeshesFromComputeResponse`).
|
|
78
78
|
|
|
79
79
|
They live here rather than in `@selvajs/compute` because that package must not depend on `three`.
|
|
@@ -83,17 +83,18 @@ covered by `pnpm type-check`, so a rename that breaks a demo fails the build ins
|
|
|
83
83
|
|
|
84
84
|
## Dependencies
|
|
85
85
|
|
|
86
|
-
This package depends on **nothing from Selva** — only `
|
|
86
|
+
This package depends on **nothing from Selva** — only `fflate`, and `three` as a peer
|
|
87
|
+
dependency. It owns its
|
|
87
88
|
own errors ([`shared/errors.ts`](./src/shared/errors.ts)), logging
|
|
88
89
|
([`shared/logger.ts`](./src/shared/logger.ts)) and base64 decoding
|
|
89
90
|
([`shared/encoding.ts`](./src/shared/encoding.ts)) rather than importing them from
|
|
90
91
|
`@selvajs/compute`, so mesh conversion and the viewer work for a consumer with neither Selva nor
|
|
91
92
|
Rhino.Compute.
|
|
92
93
|
|
|
93
|
-
The Grasshopper response
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
The Grasshopper response shape `getThreeMeshesFromComputeResponse` accepts is declared in
|
|
95
|
+
[`parse/webdisplay/response-envelope.ts`](./src/parse/webdisplay/response-envelope.ts) as **only the
|
|
96
|
+
fields the parser reads**, not as a named import. Compute's `GrasshopperComputeResponse` has more
|
|
97
|
+
fields and still satisfies it, so neither package has to depend on the other.
|
|
97
98
|
|
|
98
99
|
### Unified logging
|
|
99
100
|
|
|
@@ -102,7 +103,7 @@ The package logs nothing by default. To route its output into a host's logger
|
|
|
102
103
|
|
|
103
104
|
```ts
|
|
104
105
|
import { setLogger } from '@selvajs/visualization/render';
|
|
105
|
-
import { getLogger } from '@selvajs/compute';
|
|
106
|
+
import { getLogger } from '@selvajs/compute/core';
|
|
106
107
|
|
|
107
108
|
setLogger(getLogger());
|
|
108
109
|
```
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import*as e from"three";const t={VALIDATION_ERROR:`VALIDATION_ERROR`,INVALID_STATE:`INVALID_STATE`,ENVIRONMENT_ERROR:`ENVIRONMENT_ERROR`,INVALID_CONFIG:`INVALID_CONFIG`,ENCODING_ERROR:`ENCODING_ERROR`,UNKNOWN_ERROR:`UNKNOWN_ERROR`};var n=class extends Error{code;context;originalError;constructor(e,n=t.UNKNOWN_ERROR,r){super(e),this.name=`VisualizationError`,this.code=n,this.context=r?.context,this.originalError=r?.originalError,r?.originalError&&(this.cause=r.originalError)}},r=class{debug(){}info(){}warn(){}error(){}},i=class{debug(e,...t){console.debug(e,...t)}info(e,...t){console.info(e,...t)}warn(e,...t){console.warn(e,...t)}error(e,...t){console.error(e,...t)}};let a=new r;function o(){return a}function s(e){if(e===null){a=new r;return}let i=[`debug`,`info`,`warn`,`error`].filter(t=>typeof e[t]!=`function`);if(i.length>0)throw new n(`Logger is missing required method(s): ${i.join(`, `)}. A logger must implement debug, info, warn and error.`,t.INVALID_CONFIG,{context:{missingMethods:i}});a=e}function c(){s(new i)}function l(t){if(!t||typeof t!=`string`)return o().warn(`Invalid color input: ${t}, using white`),new e.Color(16777215);let n=t.trim();if(/^#?[0-9A-Fa-f]{6}$/.test(n))try{let t=n.startsWith(`#`)?n:`#${n}`;return new e.Color(t)}catch{return o().warn(`Invalid hex color: ${t}, using white`),new e.Color(16777215)}if(n.includes(`,`)){let t=n.split(`,`).map(e=>parseInt(e.trim(),10));if(t.length===3&&t.every(e=>!isNaN(e)&&e>=0&&e<=255))return new e.Color(t[0]/255,t[1]/255,t[2]/255)}let r=n.toLowerCase();return r in e.Color.NAMES?new e.Color(e.Color.NAMES[r]):(o().warn(`Invalid color string: ${t}, using white`),new e.Color(16777215))}function u(e,t,n=`z`){e.forEach(e=>{e.position[n]-=t})}function d(t){let n=new e.Box3;return t.length===0||t.forEach(t=>{t.updateMatrixWorld(!0);let r=new e.Box3().setFromObject(t);n.union(r)}),n}const f=new Set;function p(e){return e?!f.has(e):!1}const m=new Set;let h=1;function g(e){let t=Math.max(1,e);if(t!==h){h=t;for(let e of m)e(t)}}function _(e){return m.add(e),e(h),()=>m.delete(e)}function v(t){if(p(t)){for(let n of Object.values(t))n instanceof e.Texture&&n.dispose();t.dispose()}}function y(e){e&&(Array.isArray(e)?e.forEach(v):v(e))}function b(e,t={}){let{materials:n=!0}=t;e.traverse(e=>{let t=e;!t.geometry&&!t.material||(t.geometry&&t.geometry?.dispose(),n&&y(t.material))})}export{d as a,o as c,n as d,u as i,s as l,_ as n,l as o,g as r,c as s,b as t,t as u};
|
|
2
|
+
//# sourceMappingURL=gpu-dispose-Dkj-BKt4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gpu-dispose-Dkj-BKt4.js","names":[],"sources":["../src/shared/errors.ts","../src/shared/logger.ts","../src/shared/geometry.ts","../src/shared/gpu-ownership.ts","../src/shared/gpu-capabilities.ts","../src/shared/gpu-dispose.ts"],"sourcesContent":["/**\n * Errors for the visualization package. Replaces `@selvajs/compute`'s `RhinoComputeError`, which\n * mis-named failures on paths (e.g. the plugin WebSocket) that never touch Rhino.Compute. `code`\n * values match compute's so existing catch-sites keep working.\n */\n\nexport const ErrorCodes = {\n\t/** Structural check failed: bad magic bytes, out-of-window index, malformed metadata. */\n\tVALIDATION_ERROR: 'VALIDATION_ERROR',\n\tINVALID_STATE: 'INVALID_STATE',\n\t/** No `DecompressionStream`, no WebGL context, etc. */\n\tENVIRONMENT_ERROR: 'ENVIRONMENT_ERROR',\n\tINVALID_CONFIG: 'INVALID_CONFIG',\n\t/** Base64 input could not be decoded. */\n\tENCODING_ERROR: 'ENCODING_ERROR',\n\tUNKNOWN_ERROR: 'UNKNOWN_ERROR'\n} as const;\n\nexport type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];\n\nexport class VisualizationError extends Error {\n\tpublic readonly code: ErrorCode;\n\tpublic readonly context?: Record<string, unknown>;\n\tpublic readonly originalError?: Error;\n\n\tconstructor(\n\t\tmessage: string,\n\t\tcode: ErrorCode = ErrorCodes.UNKNOWN_ERROR,\n\t\toptions?: { context?: Record<string, unknown>; originalError?: Error }\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'VisualizationError';\n\t\tthis.code = code;\n\t\tthis.context = options?.context;\n\t\tthis.originalError = options?.originalError;\n\t\tif (options?.originalError) {\n\t\t\t(this as { cause?: unknown }).cause = options.originalError;\n\t\t}\n\t}\n}\n","/**\n * Logging facility for the visualization package. Deliberately local rather than imported from\n * `@selvajs/compute` (logging isn't a compute concern). Mirrors compute's logger shape so a host\n * wanting one sink for both can call `setLogger(computeLogger.getLogger())`.\n */\n\nimport { VisualizationError, ErrorCodes } from './errors.js';\n\nexport interface Logger {\n\tdebug(message: string, ...args: unknown[]): void;\n\tinfo(message: string, ...args: unknown[]): void;\n\twarn(message: string, ...args: unknown[]): void;\n\terror(message: string, ...args: unknown[]): void;\n}\n\nclass NoOpLogger implements Logger {\n\tdebug(): void {}\n\tinfo(): void {}\n\twarn(): void {}\n\terror(): void {}\n}\n\nclass ConsoleLogger implements Logger {\n\tdebug(message: string, ...args: unknown[]): void {\n\t\t// eslint-disable-next-line no-console -- this class exists to be the console sink\n\t\tconsole.debug(message, ...args);\n\t}\n\n\tinfo(message: string, ...args: unknown[]): void {\n\t\tconsole.info(message, ...args);\n\t}\n\n\twarn(message: string, ...args: unknown[]): void {\n\t\tconsole.warn(message, ...args);\n\t}\n\n\terror(message: string, ...args: unknown[]): void {\n\t\tconsole.error(message, ...args);\n\t}\n}\n\n// Defaults to no-op: a library that writes to the console uninvited is a nuisance in a host with\n// its own logging. Opt in with setLogger or enableDebugLogging.\nlet internalLogger: Logger = new NoOpLogger();\n\n// Call per-use rather than caching — the sink is settable at any time.\nexport function getLogger(): Logger {\n\treturn internalLogger;\n}\n\n// Validates logger shape up front: failing here beats a confusing \"getLogger().debug is not a\n// function\" at some later, unrelated call site.\nexport function setLogger(logger: Logger | Console | null): void {\n\tif (logger === null) {\n\t\tinternalLogger = new NoOpLogger();\n\t\treturn;\n\t}\n\n\tconst missing = (['debug', 'info', 'warn', 'error'] as const).filter(\n\t\t(method) => typeof (logger as unknown as Record<string, unknown>)[method] !== 'function'\n\t);\n\tif (missing.length > 0) {\n\t\tthrow new VisualizationError(\n\t\t\t`Logger is missing required method(s): ${missing.join(', ')}. A logger must implement debug, info, warn and error.`,\n\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t{ context: { missingMethods: missing } }\n\t\t);\n\t}\n\n\tinternalLogger = logger as Logger;\n}\n\nexport function enableDebugLogging(): void {\n\tsetLogger(new ConsoleLogger());\n}\n","import * as THREE from 'three';\n\nimport { getLogger } from './logger.js';\n\n// parse/ needs these and must never import upward from render/, so they live in shared/ instead\n// of render's three-helpers.\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\tif (/^#?[0-9A-Fa-f]{6}$/.test(trimmed)) {\n\t\ttry {\n\t\t\tconst hex = trimmed.startsWith('#') ? trimmed : `#${trimmed}`;\n\t\t\treturn new THREE.Color(hex);\n\t\t} catch {\n\t\t\tgetLogger().warn(`Invalid hex color: ${colorString}, using white`);\n\t\t\treturn new THREE.Color(0xffffff);\n\t\t}\n\t}\n\n\tif (trimmed.includes(',')) {\n\t\tconst rgb = trimmed.split(',').map((c) => parseInt(c.trim(), 10));\n\t\tif (rgb.length === 3 && rgb.every((n) => !isNaN(n) && n >= 0 && n <= 255)) {\n\t\t\treturn new THREE.Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255);\n\t\t}\n\t}\n\n\t// `new THREE.Color(name)` never throws on unknown names (it logs its own warning and leaves the\n\t// color white), so validate against three's CSS name table instead.\n\tconst named = trimmed.toLowerCase();\n\tif (named in THREE.Color.NAMES) {\n\t\treturn new THREE.Color(THREE.Color.NAMES[named as keyof typeof THREE.Color.NAMES]);\n\t}\n\n\tgetLogger().warn(`Invalid color string: ${colorString}, using white`);\n\treturn new THREE.Color(0xffffff);\n}\n\n/** Defaults to `z` (Rhino's up axis); pass an explicit axis when the scene uses a different `sceneUp`. */\nexport function applyOffset(\n\tmeshes: THREE.Object3D[],\n\toffset: number,\n\taxis: 'x' | 'y' | 'z' = 'z'\n): void {\n\tmeshes.forEach((mesh) => {\n\t\tmesh.position[axis] -= offset;\n\t});\n}\n\nexport function computeCombinedBoundingBox(meshes: THREE.Object3D[]): THREE.Box3 {\n\tconst combinedBoundingBox = new THREE.Box3();\n\tif (meshes.length === 0) return combinedBoundingBox;\n\tmeshes.forEach((mesh) => {\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","import type * as THREE from 'three';\n\n// ============================================================================\n// GPU resource ownership — the single rule every disposal path obeys\n// ============================================================================\n\n/**\n * A GPU resource has exactly one owner: a **module singleton** (nobody ever frees it) or the\n * **scene** (freed on teardown). Every disposal path asks {@link canDisposeMaterial} and disposes\n * only if true. Geometries and textures are always scene-owned, so they have no claim to check.\n */\n\n// Module-scope singletons from `render/three-materials.ts`, shared across meshes and solves —\n// disposing one would free textures still in use and force a recompile. Held here (not imported\n// there) to avoid an import cycle.\nconst protectedMaterials = new Set<THREE.Material>();\n\n/** Register materials as never-disposable. Called once by `render/three-materials.ts`. */\nexport function protectMaterials(materials: Iterable<THREE.Material>): void {\n\tfor (const material of materials) protectedMaterials.add(material);\n}\n\n/** True when `material` is scene-owned (not one of the protected singletons). */\nexport function canDisposeMaterial(material: THREE.Material | undefined): boolean {\n\tif (!material) return false;\n\treturn !protectedMaterials.has(material);\n}\n","// ============================================================================\n// GPU capabilities — published by the renderer, read by whoever needs them\n// ============================================================================\n\n// Lets a renderer publish GPU capabilities (max anisotropy) without `render/` and `parse/` importing\n// each other: the renderer publishes on init, interested parties subscribe.\n\ntype AnisotropyObserver = (value: number) => void;\n\nconst observers = new Set<AnisotropyObserver>();\n\n// Module load order between layers isn't guaranteed, so a subscriber arriving after init still\n// needs the current value rather than waiting for a second renderer to publish.\nlet maxAnisotropy = 1;\n\nexport function publishMaxAnisotropy(value: number): void {\n\tconst next = Math.max(1, value);\n\tif (next === maxAnisotropy) return;\n\tmaxAnisotropy = next;\n\tfor (const observe of observers) observe(next);\n}\n\n/** Fires immediately with the current value (1 until a renderer has reported), then on every change. */\nexport function observeMaxAnisotropy(observe: AnisotropyObserver): () => void {\n\tobservers.add(observe);\n\tobserve(maxAnisotropy);\n\treturn () => observers.delete(observe);\n}\n","import * as THREE from 'three';\n\nimport { canDisposeMaterial } from './gpu-ownership.js';\n\n// ============================================================================\n// The disposal walkers — every teardown path in the package goes through these\n// ============================================================================\n\n/** Frees a material and its textures, respecting ownership (`./gpu-ownership.ts`). */\nexport function disposeMaterial(material: THREE.Material): void {\n\tif (!canDisposeMaterial(material)) return;\n\n\tfor (const value of Object.values(material)) {\n\t\tif (value instanceof THREE.Texture) {\n\t\t\tvalue.dispose();\n\t\t}\n\t}\n\tmaterial.dispose();\n}\n\nfunction disposeMaterials(material: THREE.Material | THREE.Material[] | undefined): void {\n\tif (!material) return;\n\tif (Array.isArray(material)) material.forEach(disposeMaterial);\n\telse disposeMaterial(material);\n}\n\nexport interface DisposeOptions {\n\t/** Free materials and their textures too. Default true; the solve memo passes false. */\n\tmaterials?: boolean;\n\t/** Called for each geometry before disposal, so a subsystem can free derived resources keyed on it (e.g. edge caches). */\n\tonGeometry?: (geometry: THREE.BufferGeometry) => void;\n}\n\n/**\n * Frees the GPU resources of an object subtree, respecting ownership. **The only traversal that\n * should dispose scene content** — a second disposing `traverse` risks missing an ownership guard.\n */\nexport function disposeObjectTree(root: THREE.Object3D, options: DisposeOptions = {}): void {\n\tconst { materials = true } = options;\n\n\troot.traverse((object) => {\n\t\tconst renderable = object as Partial<THREE.Mesh> & THREE.Object3D;\n\t\tif (!renderable.geometry && !renderable.material) return;\n\n\t\tif (renderable.geometry) {\n\t\t\trenderable.geometry?.dispose();\n\t\t}\n\n\t\tif (materials) disposeMaterials(renderable.material);\n\t});\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./rolldown-runtime-BocRIvOZ.cjs");let t=require("three");t=e.t(t,1);const n={VALIDATION_ERROR:`VALIDATION_ERROR`,INVALID_STATE:`INVALID_STATE`,ENVIRONMENT_ERROR:`ENVIRONMENT_ERROR`,INVALID_CONFIG:`INVALID_CONFIG`,ENCODING_ERROR:`ENCODING_ERROR`,UNKNOWN_ERROR:`UNKNOWN_ERROR`};var r=class extends Error{code;context;originalError;constructor(e,t=n.UNKNOWN_ERROR,r){super(e),this.name=`VisualizationError`,this.code=t,this.context=r?.context,this.originalError=r?.originalError,r?.originalError&&(this.cause=r.originalError)}},i=class{debug(){}info(){}warn(){}error(){}},a=class{debug(e,...t){console.debug(e,...t)}info(e,...t){console.info(e,...t)}warn(e,...t){console.warn(e,...t)}error(e,...t){console.error(e,...t)}};let o=new i;function s(){return o}function c(e){if(e===null){o=new i;return}let t=[`debug`,`info`,`warn`,`error`].filter(t=>typeof e[t]!=`function`);if(t.length>0)throw new r(`Logger is missing required method(s): ${t.join(`, `)}. A logger must implement debug, info, warn and error.`,n.INVALID_CONFIG,{context:{missingMethods:t}});o=e}function l(){c(new a)}function u(e){if(!e||typeof e!=`string`)return s().warn(`Invalid color input: ${e}, using white`),new t.Color(16777215);let n=e.trim();if(/^#?[0-9A-Fa-f]{6}$/.test(n))try{let e=n.startsWith(`#`)?n:`#${n}`;return new t.Color(e)}catch{return s().warn(`Invalid hex color: ${e}, using white`),new t.Color(16777215)}if(n.includes(`,`)){let e=n.split(`,`).map(e=>parseInt(e.trim(),10));if(e.length===3&&e.every(e=>!isNaN(e)&&e>=0&&e<=255))return new t.Color(e[0]/255,e[1]/255,e[2]/255)}let r=n.toLowerCase();return r in t.Color.NAMES?new t.Color(t.Color.NAMES[r]):(s().warn(`Invalid color string: ${e}, using white`),new t.Color(16777215))}function d(e,t,n=`z`){e.forEach(e=>{e.position[n]-=t})}function f(e){let n=new t.Box3;return e.length===0||e.forEach(e=>{e.updateMatrixWorld(!0);let r=new t.Box3().setFromObject(e);n.union(r)}),n}const p=new Set;function m(e){return e?!p.has(e):!1}const h=new Set;let g=1;function _(e){let t=Math.max(1,e);if(t!==g){g=t;for(let e of h)e(t)}}function v(e){return h.add(e),e(g),()=>h.delete(e)}function y(e){if(m(e)){for(let n of Object.values(e))n instanceof t.Texture&&n.dispose();e.dispose()}}function b(e){e&&(Array.isArray(e)?e.forEach(y):y(e))}function x(e,t={}){let{materials:n=!0}=t;e.traverse(e=>{let t=e;!t.geometry&&!t.material||(t.geometry&&t.geometry?.dispose(),n&&b(t.material))})}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return n}});
|
|
2
|
+
//# sourceMappingURL=gpu-dispose-DrN-ryj5.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gpu-dispose-DrN-ryj5.cjs","names":["THREE","THREE"],"sources":["../src/shared/errors.ts","../src/shared/logger.ts","../src/shared/geometry.ts","../src/shared/gpu-ownership.ts","../src/shared/gpu-capabilities.ts","../src/shared/gpu-dispose.ts"],"sourcesContent":["/**\n * Errors for the visualization package. Replaces `@selvajs/compute`'s `RhinoComputeError`, which\n * mis-named failures on paths (e.g. the plugin WebSocket) that never touch Rhino.Compute. `code`\n * values match compute's so existing catch-sites keep working.\n */\n\nexport const ErrorCodes = {\n\t/** Structural check failed: bad magic bytes, out-of-window index, malformed metadata. */\n\tVALIDATION_ERROR: 'VALIDATION_ERROR',\n\tINVALID_STATE: 'INVALID_STATE',\n\t/** No `DecompressionStream`, no WebGL context, etc. */\n\tENVIRONMENT_ERROR: 'ENVIRONMENT_ERROR',\n\tINVALID_CONFIG: 'INVALID_CONFIG',\n\t/** Base64 input could not be decoded. */\n\tENCODING_ERROR: 'ENCODING_ERROR',\n\tUNKNOWN_ERROR: 'UNKNOWN_ERROR'\n} as const;\n\nexport type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];\n\nexport class VisualizationError extends Error {\n\tpublic readonly code: ErrorCode;\n\tpublic readonly context?: Record<string, unknown>;\n\tpublic readonly originalError?: Error;\n\n\tconstructor(\n\t\tmessage: string,\n\t\tcode: ErrorCode = ErrorCodes.UNKNOWN_ERROR,\n\t\toptions?: { context?: Record<string, unknown>; originalError?: Error }\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'VisualizationError';\n\t\tthis.code = code;\n\t\tthis.context = options?.context;\n\t\tthis.originalError = options?.originalError;\n\t\tif (options?.originalError) {\n\t\t\t(this as { cause?: unknown }).cause = options.originalError;\n\t\t}\n\t}\n}\n","/**\n * Logging facility for the visualization package. Deliberately local rather than imported from\n * `@selvajs/compute` (logging isn't a compute concern). Mirrors compute's logger shape so a host\n * wanting one sink for both can call `setLogger(computeLogger.getLogger())`.\n */\n\nimport { VisualizationError, ErrorCodes } from './errors.js';\n\nexport interface Logger {\n\tdebug(message: string, ...args: unknown[]): void;\n\tinfo(message: string, ...args: unknown[]): void;\n\twarn(message: string, ...args: unknown[]): void;\n\terror(message: string, ...args: unknown[]): void;\n}\n\nclass NoOpLogger implements Logger {\n\tdebug(): void {}\n\tinfo(): void {}\n\twarn(): void {}\n\terror(): void {}\n}\n\nclass ConsoleLogger implements Logger {\n\tdebug(message: string, ...args: unknown[]): void {\n\t\t// eslint-disable-next-line no-console -- this class exists to be the console sink\n\t\tconsole.debug(message, ...args);\n\t}\n\n\tinfo(message: string, ...args: unknown[]): void {\n\t\tconsole.info(message, ...args);\n\t}\n\n\twarn(message: string, ...args: unknown[]): void {\n\t\tconsole.warn(message, ...args);\n\t}\n\n\terror(message: string, ...args: unknown[]): void {\n\t\tconsole.error(message, ...args);\n\t}\n}\n\n// Defaults to no-op: a library that writes to the console uninvited is a nuisance in a host with\n// its own logging. Opt in with setLogger or enableDebugLogging.\nlet internalLogger: Logger = new NoOpLogger();\n\n// Call per-use rather than caching — the sink is settable at any time.\nexport function getLogger(): Logger {\n\treturn internalLogger;\n}\n\n// Validates logger shape up front: failing here beats a confusing \"getLogger().debug is not a\n// function\" at some later, unrelated call site.\nexport function setLogger(logger: Logger | Console | null): void {\n\tif (logger === null) {\n\t\tinternalLogger = new NoOpLogger();\n\t\treturn;\n\t}\n\n\tconst missing = (['debug', 'info', 'warn', 'error'] as const).filter(\n\t\t(method) => typeof (logger as unknown as Record<string, unknown>)[method] !== 'function'\n\t);\n\tif (missing.length > 0) {\n\t\tthrow new VisualizationError(\n\t\t\t`Logger is missing required method(s): ${missing.join(', ')}. A logger must implement debug, info, warn and error.`,\n\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t{ context: { missingMethods: missing } }\n\t\t);\n\t}\n\n\tinternalLogger = logger as Logger;\n}\n\nexport function enableDebugLogging(): void {\n\tsetLogger(new ConsoleLogger());\n}\n","import * as THREE from 'three';\n\nimport { getLogger } from './logger.js';\n\n// parse/ needs these and must never import upward from render/, so they live in shared/ instead\n// of render's three-helpers.\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\tif (/^#?[0-9A-Fa-f]{6}$/.test(trimmed)) {\n\t\ttry {\n\t\t\tconst hex = trimmed.startsWith('#') ? trimmed : `#${trimmed}`;\n\t\t\treturn new THREE.Color(hex);\n\t\t} catch {\n\t\t\tgetLogger().warn(`Invalid hex color: ${colorString}, using white`);\n\t\t\treturn new THREE.Color(0xffffff);\n\t\t}\n\t}\n\n\tif (trimmed.includes(',')) {\n\t\tconst rgb = trimmed.split(',').map((c) => parseInt(c.trim(), 10));\n\t\tif (rgb.length === 3 && rgb.every((n) => !isNaN(n) && n >= 0 && n <= 255)) {\n\t\t\treturn new THREE.Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255);\n\t\t}\n\t}\n\n\t// `new THREE.Color(name)` never throws on unknown names (it logs its own warning and leaves the\n\t// color white), so validate against three's CSS name table instead.\n\tconst named = trimmed.toLowerCase();\n\tif (named in THREE.Color.NAMES) {\n\t\treturn new THREE.Color(THREE.Color.NAMES[named as keyof typeof THREE.Color.NAMES]);\n\t}\n\n\tgetLogger().warn(`Invalid color string: ${colorString}, using white`);\n\treturn new THREE.Color(0xffffff);\n}\n\n/** Defaults to `z` (Rhino's up axis); pass an explicit axis when the scene uses a different `sceneUp`. */\nexport function applyOffset(\n\tmeshes: THREE.Object3D[],\n\toffset: number,\n\taxis: 'x' | 'y' | 'z' = 'z'\n): void {\n\tmeshes.forEach((mesh) => {\n\t\tmesh.position[axis] -= offset;\n\t});\n}\n\nexport function computeCombinedBoundingBox(meshes: THREE.Object3D[]): THREE.Box3 {\n\tconst combinedBoundingBox = new THREE.Box3();\n\tif (meshes.length === 0) return combinedBoundingBox;\n\tmeshes.forEach((mesh) => {\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","import type * as THREE from 'three';\n\n// ============================================================================\n// GPU resource ownership — the single rule every disposal path obeys\n// ============================================================================\n\n/**\n * A GPU resource has exactly one owner: a **module singleton** (nobody ever frees it) or the\n * **scene** (freed on teardown). Every disposal path asks {@link canDisposeMaterial} and disposes\n * only if true. Geometries and textures are always scene-owned, so they have no claim to check.\n */\n\n// Module-scope singletons from `render/three-materials.ts`, shared across meshes and solves —\n// disposing one would free textures still in use and force a recompile. Held here (not imported\n// there) to avoid an import cycle.\nconst protectedMaterials = new Set<THREE.Material>();\n\n/** Register materials as never-disposable. Called once by `render/three-materials.ts`. */\nexport function protectMaterials(materials: Iterable<THREE.Material>): void {\n\tfor (const material of materials) protectedMaterials.add(material);\n}\n\n/** True when `material` is scene-owned (not one of the protected singletons). */\nexport function canDisposeMaterial(material: THREE.Material | undefined): boolean {\n\tif (!material) return false;\n\treturn !protectedMaterials.has(material);\n}\n","// ============================================================================\n// GPU capabilities — published by the renderer, read by whoever needs them\n// ============================================================================\n\n// Lets a renderer publish GPU capabilities (max anisotropy) without `render/` and `parse/` importing\n// each other: the renderer publishes on init, interested parties subscribe.\n\ntype AnisotropyObserver = (value: number) => void;\n\nconst observers = new Set<AnisotropyObserver>();\n\n// Module load order between layers isn't guaranteed, so a subscriber arriving after init still\n// needs the current value rather than waiting for a second renderer to publish.\nlet maxAnisotropy = 1;\n\nexport function publishMaxAnisotropy(value: number): void {\n\tconst next = Math.max(1, value);\n\tif (next === maxAnisotropy) return;\n\tmaxAnisotropy = next;\n\tfor (const observe of observers) observe(next);\n}\n\n/** Fires immediately with the current value (1 until a renderer has reported), then on every change. */\nexport function observeMaxAnisotropy(observe: AnisotropyObserver): () => void {\n\tobservers.add(observe);\n\tobserve(maxAnisotropy);\n\treturn () => observers.delete(observe);\n}\n","import * as THREE from 'three';\n\nimport { canDisposeMaterial } from './gpu-ownership.js';\n\n// ============================================================================\n// The disposal walkers — every teardown path in the package goes through these\n// ============================================================================\n\n/** Frees a material and its textures, respecting ownership (`./gpu-ownership.ts`). */\nexport function disposeMaterial(material: THREE.Material): void {\n\tif (!canDisposeMaterial(material)) return;\n\n\tfor (const value of Object.values(material)) {\n\t\tif (value instanceof THREE.Texture) {\n\t\t\tvalue.dispose();\n\t\t}\n\t}\n\tmaterial.dispose();\n}\n\nfunction disposeMaterials(material: THREE.Material | THREE.Material[] | undefined): void {\n\tif (!material) return;\n\tif (Array.isArray(material)) material.forEach(disposeMaterial);\n\telse disposeMaterial(material);\n}\n\nexport interface DisposeOptions {\n\t/** Free materials and their textures too. Default true; the solve memo passes false. */\n\tmaterials?: boolean;\n\t/** Called for each geometry before disposal, so a subsystem can free derived resources keyed on it (e.g. edge caches). */\n\tonGeometry?: (geometry: THREE.BufferGeometry) => void;\n}\n\n/**\n * Frees the GPU resources of an object subtree, respecting ownership. **The only traversal that\n * should dispose scene content** — a second disposing `traverse` risks missing an ownership guard.\n */\nexport function disposeObjectTree(root: THREE.Object3D, options: DisposeOptions = {}): void {\n\tconst { materials = true } = options;\n\n\troot.traverse((object) => {\n\t\tconst renderable = object as Partial<THREE.Mesh> & THREE.Object3D;\n\t\tif (!renderable.geometry && !renderable.material) return;\n\n\t\tif (renderable.geometry) {\n\t\t\trenderable.geometry?.dispose();\n\t\t}\n\n\t\tif (materials) disposeMaterials(renderable.material);\n\t});\n}\n"],"mappings":"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"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { }
|
|
1
|
+
export {}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { }
|
|
1
|
+
export {}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{};
|
package/dist/parse.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkAQJPVUH3cjs = require('./chunk-AQJPVUH3.cjs');require('./chunk-BYLIBOAU.cjs');function bt(e){return e.map(t=>{let r=t.clone(!0),n=[];t.traverse(a=>n.push(a));let o=0;return r.traverse(a=>{let s=n[o++],u=a;if(!s.geometry)return;let i=s.geometry.clone();i.userData={...i.userData},delete i.userData[_chunkAQJPVUH3cjs.n],u.geometry=i}),r})}function Et(e){e.forEach(t=>_chunkAQJPVUH3cjs.v.call(void 0, t,{materials:!1}))}var xt={clone:bt,release:Et};var _three = require('three'); var de = _interopRequireWildcard(_three); var _e = _interopRequireWildcard(_three); var P = _interopRequireWildcard(_three); var V = _interopRequireWildcard(_three); var z = _interopRequireWildcard(_three); var ce = _interopRequireWildcard(_three); var O = _interopRequireWildcard(_three);var _Line2js = require('three/addons/lines/Line2.js');var _LineGeometryjs = require('three/addons/lines/LineGeometry.js');var _LineMaterialjs = require('three/addons/lines/LineMaterial.js');var At="#ffffff";function te(e,t){let r=_nullishCoalesce(t, () => (1));return{color:new _e.Color(_nullishCoalesce(e, () => (At))),transparent:r<1,opacity:r}}var Fe=12,Rt=4e-4,vt=12,St=.05,Ct=2;function Pe(e,t){if(!t)return _chunkAQJPVUH3cjs.c.call(void 0, ).warn("No rhino3dm instance provided; skipping curve display item."),null;let r=Bt(e.json,t);if(!r)return null;let n;try{n=It(r)}catch(l){return _chunkAQJPVUH3cjs.c.call(void 0, ).warn("Failed to tessellate curve display item; skipping.",l),null}finally{Y(r)}if(n.length<2)return null;let o=[];for(let l of n)o.push(l.x,l.y,l.z);let a=new _LineGeometryjs.LineGeometry;a.setPositions(o);let s=te(e.color,e.opacity),u=new (0, _LineMaterialjs.LineMaterial)({color:s.color}),i=u;i.linewidth=_nullishCoalesce(e.width, () => (Ct)),i.transparent=s.transparent,i.opacity=s.opacity;let f=new (0, _Line2js.Line2)(a,u);return f.computeLineDistances(),f.name=e.name,f.userData={source:"compute",id:e.id,layer:e.layer,kind:"curve",metadata:e.metadata},f}function Y(e){_optionalChain([e, 'optionalAccess', _2 => _2.delete, 'optionalCall', _3 => _3()])}function Bt(e,t){try{let r=JSON.parse(e),n=t.CommonObject.decode(r);return n&&typeof n.pointAt=="function"?n:(Y(n),_chunkAQJPVUH3cjs.c.call(void 0, ).warn("Decoded display-item JSON is not a curve; skipping."),null)}catch(r){return _chunkAQJPVUH3cjs.c.call(void 0, ).warn("Failed to decode curve display item JSON:",r),null}}function It(e){let t=Dt(e);return t||Ot(e)}function Dt(e){if(!e.isPolyline())return null;let t=e.tryGetPolyline(),r=Array.isArray(t)?t[1]:t;if(!r||typeof r.count!="number"||r.count<2)return Y(r),null;let n=[];for(let o=0;o<r.count;o++){let a=r.get(o);n.push(new de.Vector3(a[0],a[1],a[2]))}return Y(r),n}function Ot(e){let t=e.domain,r=t[0],o=t[1]-r,a=l=>{let y=e.pointAt(l);return new de.Vector3(y[0],y[1],y[2])},s=Ut(e),u=r,i=a(r),f=[i];for(let l=0;l<Fe;l++){let y=r+o*(l+1)/Fe,b=a(y);me(u,i,y,b,a,s,vt,f),f.push(b),u=y,i=b}return f}function me(e,t,r,n,o,a,s,u){if(s<=0)return;let i=(e+r)/2,f=o(i),l=Lt(f,t,n),y=Ht(t,f,n);l<=a&&y<=St||(me(e,t,i,f,o,a,s-1,u),u.push(f),me(i,f,r,n,o,a,s-1,u))}function Ut(e){let t=e.getBoundingBox(),r=t.min,n=t.max;Y(t);let o=Math.hypot(n[0]-r[0],n[1]-r[1],n[2]-r[2]);return Math.max(o*Rt,1e-6)}function Ht(e,t,r){let n=t.x-e.x,o=t.y-e.y,a=t.z-e.z,s=r.x-t.x,u=r.y-t.y,i=r.z-t.z,f=Math.sqrt(n*n+o*o+a*a),l=Math.sqrt(s*s+u*u+i*i);if(f===0||l===0)return 0;let y=n*s+o*u+a*i,b=Math.max(-1,Math.min(1,y/(f*l)));return Math.acos(b)}function Lt(e,t,r){let n=r.x-t.x,o=r.y-t.y,a=r.z-t.z,s=n*n+o*o+a*a;if(s===0)return e.distanceTo(t);let u=e.x-t.x,i=e.y-t.y,f=e.z-t.z,l=Math.max(0,Math.min(1,(u*n+i*o+f*a)/s)),y=u-n*l,b=i-o*l,w=f-a*l;return Math.sqrt(y*y+b*b+w*w)}function Ve(e){let{position:t}=e;if(!t||typeof t.X!="number"||!Number.isFinite(t.X)||typeof t.Y!="number"||!Number.isFinite(t.Y)||typeof t.Z!="number"||!Number.isFinite(t.Z))return _chunkAQJPVUH3cjs.c.call(void 0, ).warn(`Skipping point display item with missing or non-finite position (id: ${String(e.id)}).`),null;let r=new P.BufferGeometry;r.setAttribute("position",new P.Float32BufferAttribute([t.X,t.Y,t.Z],3));let n=new P.PointsMaterial({...te(e.color,e.opacity),size:6,sizeAttenuation:!1}),o=new P.Points(r,n);return o.name=e.name,o.userData={source:"compute",id:e.id,layer:e.layer,kind:"point",metadata:e.metadata},o}function pe(e,t={}){if(!e||e.length===0)return[];let{rhino:r}=t,n=[];for(let o of e)switch(o.kind){case"curve":{let a=Pe(o,r);a&&n.push(a);break}case"point":{let a=Ve(o);a&&n.push(a);break}default:{let s=o;_chunkAQJPVUH3cjs.c.call(void 0, ).warn(`Skipping unknown display item kind: ${String(s.kind)}`);break}}return n}var ke=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;var _fflate = require('fflate');function Ge(e){return typeof e=="string"?_chunkAQJPVUH3cjs.f.call(void 0, e):e instanceof Uint8Array?e:new Uint8Array(e)}function Ne(e){if(e.byteLength<8)return e;let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getUint32(0,!0)!==1515605075)return e;let r=t.getUint32(4,!0),n=e.subarray(8),o=Math.max(n.byteLength*1032+1024,1<<20);if(r>o)throw I("SLVZ header declares an implausible uncompressed length",{uncompressedLen:r,deflatedBytes:n.byteLength,maxPlausibleLen:o});let a;try{a=_fflate.inflateSync.call(void 0, n,{out:new Uint8Array(r+1)})}catch(s){throw I(`Failed to inflate SLVZ blob: ${s instanceof Error?s.message:String(s)}`,{uncompressedLen:r,deflatedBytes:n.byteLength})}if(a.byteLength!==r)throw I("SLVZ payload inflated to a different size than the header declares.",{declaredLen:r,actualLen:a.byteLength,deflatedBytes:n.byteLength});return a}function je(e){if(typeof TextDecoder<"u")return new TextDecoder("utf-8").decode(e);if(typeof globalThis.Buffer<"u")return globalThis.Buffer.from(e).toString("utf-8");throw new (0, _chunkAQJPVUH3cjs.b)("No UTF-8 decoder available in this environment.",_chunkAQJPVUH3cjs.a.INVALID_STATE)}function $e(e,t,r){if(r===0)return new Int16Array(0);if(t%2===0)return new Int16Array(e,t,r);let n=new Uint8Array(r*2);return n.set(new Uint8Array(e,t,r*2)),new Int16Array(n.buffer)}function re(e,t,r){if(r===0)return new Float32Array(0);if(t%4===0)return new Float32Array(e,t,r);let n=new Uint8Array(r*4);return n.set(new Uint8Array(e,t,r*4)),new Float32Array(n.buffer)}function W(e,t,r){if(r===0)return new Uint16Array(0);if(t%2===0)return new Uint16Array(e,t,r);let n=new Uint8Array(r*2);return n.set(new Uint8Array(e,t,r*2)),new Uint16Array(n.buffer)}function ze(e,t,r){if(r===0)return new Uint32Array(0);if(t%4===0)return new Uint32Array(e,t,r);let n=new Uint8Array(r*4);return n.set(new Uint8Array(e,t,r*4)),new Uint32Array(n.buffer)}function Ye(e,t){if(e.length!==0&&!(e instanceof Uint16Array&&t>65535)){for(let r=0;r<e.length;r++)if(e[r]>=t)throw I("Index out of range of vertexCount.",{indexPosition:r,indexValue:e[r],vertexCount:t})}}function L(e){return e>>>1^-(e&1)}function We(e){let t=new Int16Array(e.length),r=0,n=0,o=0;for(let a=0;a<e.length;a+=3)r=r+L(e[a])<<16>>16,n=n+L(e[a+1])<<16>>16,o=o+L(e[a+2])<<16>>16,t[a]=r,t[a+1]=n,t[a+2]=o;return t}function Je(e){let t=new Uint16Array(e.length),r=0;for(let n=0;n<e.length;n++)r=r+L(e[n])&65535,t[n]=r;return t}function Xe(e){let t=new Uint32Array(e.length),r=0;for(let n=0;n<e.length;n++)r=r+L(e[n])>>>0,t[n]=r;return t}function I(e,t){return new (0, _chunkAQJPVUH3cjs.b)(e,_chunkAQJPVUH3cjs.a.VALIDATION_ERROR,{context:t})}var Ke=36;function qe(e,t,r,n,o){if(r+Ke>e.byteLength)throw I("Insufficient data to read UV chunk header.",{expectedBytes:Ke,availableBytes:e.byteLength-r,offset:r});let a=t.getUint32(r,!0);r+=4;let s=t.getFloat64(r,!0);r+=8;let u=t.getFloat64(r,!0);r+=8;let i=t.getFloat64(r,!0);r+=8;let f=t.getFloat64(r,!0);r+=8;let l=n*2,y=a===1,b=l*(y?4:2);if(r+b>e.byteLength)throw I("Insufficient data to read UV chunk.",{expectedBytes:b,availableBytes:e.byteLength-r,offset:r,uvFormat:a,vertexCount:n});let w=e.byteOffset+r,v;if(y)v=re(e.buffer,w,l).slice();else{let C=W(e.buffer,w,l);v=new Float32Array(l);let c=0,d=0;for(let p=0;p<l;p+=2)o?(c=c+L(C[p])&65535,d=d+L(C[p+1])&65535):(c=C[p],d=C[p+1]),v[p]=s+c*i,v[p+1]=u+d*f}return{uvs:v,offset:r+b}}function Ze(e,t,r,n){let o=r*3;if(t+o>e.byteLength)throw I("Insufficient data to read vertex-color chunk.",{expectedBytes:o,availableBytes:e.byteLength-t,offset:t,vertexCount:r});let a=e.subarray(t,t+o);if(!n)return a.slice();let s=new Uint8Array(o),u=0,i=0,f=0;for(let l=0;l<o;l+=3)u=u+L(a[l])&255,i=i+L(a[l+1])&255,f=f+L(a[l+2])&255,s[l]=u,s[l+1]=i,s[l+2]=f;return s}function he(e){let t=ge(e),r;t.isFloat32?r=t.vertexData:t.deltaEncoded?r=We(t.vertexData):r=t.vertexData;let n=t.indexData;return t.deltaEncoded&&(n=n instanceof Uint16Array?Je(n):Xe(n)),Ye(n,t.vertexCount),{metadata:t.metadata,flags:t.flags,vertices:r,indices:n,origin:t.origin,scale:t.scale,uvs:t.uvs,colors:t.colors}}function ge(e){if(!ke)throw new (0, _chunkAQJPVUH3cjs.b)("SLVA parsing requires a little-endian host: the zero-copy geometry readers view the wire bytes in host byte order.",_chunkAQJPVUH3cjs.a.ENVIRONMENT_ERROR);let t=Ne(Ge(e)),r=new DataView(t.buffer,t.byteOffset,t.byteLength);if(t.byteLength<12)throw I("Blob too small to contain SLVA header.",{expectedBytes:12,availableBytes:t.byteLength});let n=0,o=r.getUint32(n,!0);if(n+=4,o!==1096174675)throw I(`Invalid SLVA magic: 0x${o.toString(16)}`,{expectedMagic:`0x${1096174675 .toString(16)}`,actualMagic:`0x${o.toString(16)}`});let a=r.getUint32(n,!0);if(n+=4,a<1||a>3)throw I(`Unsupported SLVA version: ${a}`,{minSupportedVersion:1,maxSupportedVersion:3,actualVersion:a});let s=r.getUint32(n,!0);if(n+=4,n+s>t.byteLength)throw I("Insufficient data to read metadata JSON.",{expectedBytes:s,availableBytes:t.byteLength-n,offset:n});let u=t.subarray(n,n+s);n+=s;let i;try{i=JSON.parse(je(u))}catch(U){throw I(`Failed to parse metadata JSON: ${U instanceof Error?U.message:String(U)}`,{metadataLen:s})}if(n+56>t.byteLength)throw I("Insufficient data to read geometry header.",{expectedBytes:56,availableBytes:t.byteLength-n,offset:n});let f=r.getUint32(n,!0);n+=4;let l=r.getFloat64(n,!0);n+=8;let y=r.getFloat64(n,!0);n+=8;let b=r.getFloat64(n,!0);n+=8;let w=r.getFloat64(n,!0);n+=8;let v=r.getFloat64(n,!0);n+=8;let C=r.getFloat64(n,!0);n+=8;let c=r.getUint32(n,!0);n+=4;let d=(f&1)!==0,p=(f&4)!==0,m=c*3,S=m*(d?4:2);if(n+S>t.byteLength)throw I("Insufficient data to read vertices.",{expectedBytes:S,availableBytes:t.byteLength-n,offset:n,useFloat32:d,vertexCount:c});let T=t.byteOffset+n,g;if(d?g=re(t.buffer,T,m):p?g=W(t.buffer,T,m):g=$e(t.buffer,T,m),n+=S,n+4>t.byteLength)throw I("Insufficient data to read index count.",{expectedBytes:4,availableBytes:t.byteLength-n,offset:n});let x=r.getUint32(n,!0);n+=4;let R=(f&2)!==0,M=x*(R?2:4);if(n+M>t.byteLength)throw I("Insufficient data to read indices.",{expectedBytes:M,availableBytes:t.byteLength-n,offset:n,indexCount:x,useUint16Indices:R});let B=R?W(t.buffer,t.byteOffset+n,x):ze(t.buffer,t.byteOffset+n,x);n+=M;let D=null;if((f&8)!==0){let U=qe(t,r,n,c,p);D=U.uvs,n=U.offset}let H=null;return(f&16)!==0&&(H=Ze(t,n,c,p)),{metadata:i,flags:f,vertexData:g,indexData:B,isFloat32:d,deltaEncoded:p,vertexCount:c,origin:[l,y,b],scale:[w,v,C],uvs:D,colors:H}}var ot=256*1024*1024,ne=1024,_=new Map,oe=0;function at(e,t){let r=2166136261,n=o=>{r^=o,r=Math.imul(r,16777619)};for(let o=0;o<t.length;o++)n(t.charCodeAt(o));for(let o of e){if(!o){n(57005);continue}let a=o.byteLength;if(n(a),(o.byteOffset&3)===0&&(a&3)===0){let s=new Uint32Array(o.buffer,o.byteOffset,a>>2),u=Math.min(ne,s.length);for(let i=0;i<u;i++)n(s[i]);for(let i=Math.max(u,s.length-ne);i<s.length;i++)n(s[i])}else{let s=new Uint8Array(o.buffer,o.byteOffset,a),u=Math.min(ne*4,s.length);for(let i=0;i<u;i++)n(s[i]);for(let i=Math.max(u,s.length-ne*4);i<s.length;i++)n(s[i])}}return`${(r>>>0).toString(36)}:${e.length}`}function Gt(e){let t=_nullishCoalesce(_optionalChain([e, 'access', _4 => _4.index, 'optionalAccess', _5 => _5.array, 'access', _6 => _6.byteLength]), () => (0));for(let r of Object.values(e.attributes))t+=r.array.byteLength;return t}function J(e){let t=_.get(e);if(t)return _.delete(e),_.set(e,t),t.geometry}function X(e,t){let r=Gt(t);if(!(r>ot)&&!_.has(e))for(t.userData[_chunkAQJPVUH3cjs.n]=!0,_.set(e,{geometry:t,bytes:r}),oe+=r;oe>ot&&_.size>1;){let n=_.keys().next().value,o=_.get(n);_.delete(n),oe-=o.bytes,delete o.geometry.userData[_chunkAQJPVUH3cjs.n],o.geometry.dispose()}}_chunkAQJPVUH3cjs.q.call(void 0, ()=>Nt());function Nt(){for(let e of _.values())delete e.geometry.userData[_chunkAQJPVUH3cjs.n],e.geometry.dispose();_.clear(),oe=0}function jt(e){let{isFloat32:t,deltaEncoded:r,origin:n,scale:o,uvs:a,colors:s,jobs:u}=e,i=c=>c>>>1^-(c&1),f;if(t)f=e.vertexData;else{let c;if(r){let g=e.vertexData;c=new Int16Array(g.length);let x=0,R=0,E=0;for(let M=0;M<g.length;M+=3)x=x+i(g[M])<<16>>16,R=R+i(g[M+1])<<16>>16,E=E+i(g[M+2])<<16>>16,c[M]=x,c[M+1]=R,c[M+2]=E}else c=e.vertexData;f=new Float32Array(c.length);let d=n[0],p=n[1],m=n[2],h=o[0],S=o[1],T=o[2];for(let g=0;g<c.length;g+=3)f[g]=d+(c[g]+32767)*h,f[g+1]=p+(c[g+1]+32767)*S,f[g+2]=m+(c[g+2]+32767)*T}let l;if(r){let c=e.indexData;if(c instanceof Uint16Array){let d=new Uint16Array(c.length),p=0;for(let m=0;m<c.length;m++)p=p+i(c[m])&65535,d[m]=p;l=d}else{let d=new Uint32Array(c.length),p=0;for(let m=0;m<c.length;m++)p=p+i(c[m])>>>0,d[m]=p;l=d}}else l=e.indexData;let y=f.length/3;for(let c=0;c<l.length;c++)if(l[c]>=y)throw new Error(`Index ${l[c]} out of range of vertexCount ${y}`);let b=1024,w=(c,d)=>{let p=2166136261,m=h=>{p^=h,p=Math.imul(p,16777619)};for(let h=0;h<d.length;h++)m(d.charCodeAt(h));for(let h of c){if(!h){m(57005);continue}let S=h.byteLength;if(m(S),(h.byteOffset&3)===0&&(S&3)===0){let T=new Uint32Array(h.buffer,h.byteOffset,S>>2),g=Math.min(b,T.length);for(let x=0;x<g;x++)m(T[x]);for(let x=Math.max(g,T.length-b);x<T.length;x++)m(T[x])}else{let T=new Uint8Array(h.buffer,h.byteOffset,S),g=Math.min(b*4,T.length);for(let x=0;x<g;x++)m(T[x]);for(let x=Math.max(g,T.length-b*4);x<T.length;x++)m(T[x])}}return`${(p>>>0).toString(36)}:${c.length}`},v=(c,d)=>{let p=[],m=c;for(let h of d){m+=`|${h.vertexStart},${h.vertexCount},${h.indexStart},${h.indexCount}`;let S=h.vertexStart*3,T=S+h.vertexCount*3;p.push(f.subarray(S,T)),p.push(l.subarray(h.indexStart,h.indexStart+h.indexCount)),p.push(a?a.subarray(h.vertexStart*2,(h.vertexStart+h.vertexCount)*2):null),p.push(s?s.subarray(S,T):null)}return w(p,m)},C=[];for(let c of u){let d=0,p=0;for(let E of c.windows)d+=E.vertexCount,p+=E.indexCount;let m=new Float32Array(d*3),h=new Uint32Array(p),S=a?new Float32Array(d*2):null,T=s?new Uint8Array(d*3):null,g=0,x=0;for(let E of c.windows){let M=E.vertexStart*3;m.set(f.subarray(M,M+E.vertexCount*3),g*3),S&&a&&S.set(a.subarray(E.vertexStart*2,(E.vertexStart+E.vertexCount)*2),g*2),T&&s&&T.set(s.subarray(M,M+E.vertexCount*3),g*3);let B=E.vertexStart,D=E.vertexStart+E.vertexCount,H=g-E.vertexStart;for(let U=0;U<E.indexCount;U++){let k=l[E.indexStart+U];if(k<B||k>=D)throw new Error(`Index ${k} outside vertex window [${B}, ${D})`);h[x+U]=k+H}g+=E.vertexCount,x+=E.indexCount}let R=new Float32Array(d*3);for(let E=0;E<h.length;E+=3){let M=h[E]*3,B=h[E+1]*3,D=h[E+2]*3,H=m[D]-m[B],U=m[D+1]-m[B+1],k=m[D+2]-m[B+2],ve=m[M]-m[B],Se=m[M+1]-m[B+1],Ce=m[M+2]-m[B+2],le=U*Ce-k*Se,ue=k*ve-H*Ce,fe=H*Se-U*ve;R[M]+=le,R[M+1]+=ue,R[M+2]+=fe,R[B]+=le,R[B+1]+=ue,R[B+2]+=fe,R[D]+=le,R[D+1]+=ue,R[D+2]+=fe}for(let E=0;E<R.length;E+=3){let M=R[E],B=R[E+1],D=R[E+2],H=Math.sqrt(M*M+B*B+D*D)||1;R[E]=M/H,R[E+1]=B/H,R[E+2]=D/H}C.push({key:v(c.kind,c.windows),positions:m,normals:R,indices:h,uvs:S,colors:T})}return C}function st(){return[`const assemble = ${jt.toString()};`,"self.onmessage = (event) => {"," const { id, input } = event.data;"," try {"," const geometries = assemble(input);"," const transfer = [];"," for (const g of geometries) {"," transfer.push(g.positions.buffer, g.normals.buffer, g.indices.buffer);"," if (g.uvs) transfer.push(g.uvs.buffer);"," if (g.colors) transfer.push(g.colors.buffer);"," }"," self.postMessage({ id, geometries }, transfer);"," } catch (error) {"," self.postMessage({ id, error: String((error && error.message) || error) });"," }","};"].join(`
|
|
2
|
-
`)}
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-BocRIvOZ.cjs"),t=require("./gpu-dispose-DrN-ryj5.cjs");let n=require("three");n=e.t(n,1);let r=require("three/addons/lines/Line2.js"),i=require("three/addons/lines/LineGeometry.js"),a=require("three/addons/lines/LineMaterial.js"),o=require("fflate");function s(){let e=globalThis.Buffer;return typeof e==`function`?e:void 0}function c(e){let n=e.replace(/[\t\n\f\r ]/g,``);if(n.length%4==0&&(n=n.replace(/={1,2}$/,``)),n.length%4==1||!/^[A-Za-z0-9+/]*$/.test(n))throw new t.d(`Invalid base64 input.`,t.u.ENCODING_ERROR,{context:{inputLength:e.length}});let r=s();if(r)return new Uint8Array(r.from(n,`base64`));if(typeof globalThis.atob==`function`){let e=globalThis.atob(n),t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&255;return t}throw new t.d(`Base64 decoding not supported in this environment.`,t.u.INVALID_STATE,{context:{environmentInfo:`atob or Buffer not available`}})}function l(e){return e.map(e=>{let t=e.clone(!0),n=[];e.traverse(e=>n.push(e));let r=0;return t.traverse(e=>{let t=n[r++],i=e;t.geometry&&(i.geometry=t.geometry.clone())}),t})}function u(e){e.forEach(e=>t.t(e,{materials:!1}))}const d={clone:l,release:u};function f(e,t){let r=t??1;return{color:new n.Color(e??`#ffffff`),transparent:r<1,opacity:r}}function p(e){let t=m(e);if(!t)return null;let n=new i.LineGeometry;n.setPositions(t);let o=f(e.color,e.opacity),s=new a.LineMaterial({color:o.color}),c=s;c.linewidth=e.width??2,c.transparent=o.transparent,c.opacity=o.opacity;let l=new r.Line2(n,s);return l.computeLineDistances(),l.name=e.name,l.userData={source:`compute`,id:e.id,layer:e.layer,kind:`curve`,metadata:e.metadata},l}function m(e){if(!e.points)throw new t.d(`Curve display item '${e.id}' has no tessellated points. It was produced by an outdated Display component — upgrade it in Grasshopper (Solution → Upgrade obsolete components) and re-save the definition.`,t.u.INVALID_CONFIG,{context:{itemId:e.id,kind:e.kind}});return e.points.length>=6?e.points:null}function h(e){let{position:r}=e;if(!r||typeof r.X!=`number`||!Number.isFinite(r.X)||typeof r.Y!=`number`||!Number.isFinite(r.Y)||typeof r.Z!=`number`||!Number.isFinite(r.Z))return t.c().warn(`Skipping point display item with missing or non-finite position (id: ${String(e.id)}).`),null;let i=new n.BufferGeometry;i.setAttribute(`position`,new n.Float32BufferAttribute([r.X,r.Y,r.Z],3));let a=new n.PointsMaterial({...f(e.color,e.opacity),size:6,sizeAttenuation:!1}),o=new n.Points(i,a);return o.name=e.name,o.userData={source:`compute`,id:e.id,layer:e.layer,kind:`point`,metadata:e.metadata},o}function g(e){if(!e||e.length===0)return[];let n=[];for(let r of e)switch(r.kind){case`curve`:{let e=p(r);e&&n.push(e);break}case`point`:{let e=h(r);e&&n.push(e);break}default:{let e=r;t.c().warn(`Skipping unknown display item kind: ${String(e.kind)}`);break}}return n}const _=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;function v(e){return typeof e==`string`?c(e):e instanceof Uint8Array?e:new Uint8Array(e)}function y(e){if(e.byteLength<8)return e;let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getUint32(0,!0)!==1515605075)return e;let n=t.getUint32(4,!0),r=e.subarray(8),i=Math.max(r.byteLength*1032+1024,1<<20);if(n>i)throw k(`SLVZ header declares an implausible uncompressed length`,{uncompressedLen:n,deflatedBytes:r.byteLength,maxPlausibleLen:i});let a;try{a=(0,o.inflateSync)(r,{out:new Uint8Array(n+1)})}catch(e){throw k(`Failed to inflate SLVZ blob: ${e instanceof Error?e.message:String(e)}`,{uncompressedLen:n,deflatedBytes:r.byteLength})}if(a.byteLength!==n)throw k(`SLVZ payload inflated to a different size than the header declares.`,{declaredLen:n,actualLen:a.byteLength,deflatedBytes:r.byteLength});return a}function b(e){if(typeof TextDecoder<`u`)return new TextDecoder(`utf-8`).decode(e);if(globalThis.Buffer!==void 0)return globalThis.Buffer.from(e).toString(`utf-8`);throw new t.d(`No UTF-8 decoder available in this environment.`,t.u.INVALID_STATE)}function x(e,t,n){if(n===0)return new Int16Array;if(t%2==0)return new Int16Array(e,t,n);let r=new Uint8Array(n*2);return r.set(new Uint8Array(e,t,n*2)),new Int16Array(r.buffer)}function S(e,t,n){if(n===0)return new Float32Array;if(t%4==0)return new Float32Array(e,t,n);let r=new Uint8Array(n*4);return r.set(new Uint8Array(e,t,n*4)),new Float32Array(r.buffer)}function C(e,t,n){if(n===0)return new Uint16Array;if(t%2==0)return new Uint16Array(e,t,n);let r=new Uint8Array(n*2);return r.set(new Uint8Array(e,t,n*2)),new Uint16Array(r.buffer)}function ee(e,t,n){if(n===0)return new Uint32Array;if(t%4==0)return new Uint32Array(e,t,n);let r=new Uint8Array(n*4);return r.set(new Uint8Array(e,t,n*4)),new Uint32Array(r.buffer)}function w(e,t){if(e.length!==0&&!(e instanceof Uint16Array&&t>65535)){for(let n=0;n<e.length;n++)if(e[n]>=t)throw k(`Index out of range of vertexCount.`,{indexPosition:n,indexValue:e[n],vertexCount:t})}}function T(e){return e>>>1^-(e&1)}function E(e){let t=new Int16Array(e.length),n=0,r=0,i=0;for(let a=0;a<e.length;a+=3)n=n+T(e[a])<<16>>16,r=r+T(e[a+1])<<16>>16,i=i+T(e[a+2])<<16>>16,t[a]=n,t[a+1]=r,t[a+2]=i;return t}function D(e){let t=new Uint16Array(e.length),n=0;for(let r=0;r<e.length;r++)n=n+T(e[r])&65535,t[r]=n;return t}function O(e){let t=new Uint32Array(e.length),n=0;for(let r=0;r<e.length;r++)n=n+T(e[r])>>>0,t[r]=n;return t}function k(e,n){return new t.d(e,t.u.VALIDATION_ERROR,{context:n})}function te(e,t,n,r,i){if(n+36>e.byteLength)throw k(`Insufficient data to read UV chunk header.`,{expectedBytes:36,availableBytes:e.byteLength-n,offset:n});let a=t.getUint32(n,!0);n+=4;let o=t.getFloat64(n,!0);n+=8;let s=t.getFloat64(n,!0);n+=8;let c=t.getFloat64(n,!0);n+=8;let l=t.getFloat64(n,!0);n+=8;let u=r*2,d=a===1,f=u*(d?4:2);if(n+f>e.byteLength)throw k(`Insufficient data to read UV chunk.`,{expectedBytes:f,availableBytes:e.byteLength-n,offset:n,uvFormat:a,vertexCount:r});let p=e.byteOffset+n,m;if(d)m=S(e.buffer,p,u).slice();else{let t=C(e.buffer,p,u);m=new Float32Array(u);let n=0,r=0;for(let e=0;e<u;e+=2)i?(n=n+T(t[e])&65535,r=r+T(t[e+1])&65535):(n=t[e],r=t[e+1]),m[e]=o+n*c,m[e+1]=s+r*l}return{uvs:m,offset:n+f}}function ne(e,t,n,r){let i=n*3;if(t+i>e.byteLength)throw k(`Insufficient data to read vertex-color chunk.`,{expectedBytes:i,availableBytes:e.byteLength-t,offset:t,vertexCount:n});let a=e.subarray(t,t+i);if(!r)return a.slice();let o=new Uint8Array(i),s=0,c=0,l=0;for(let e=0;e<i;e+=3)s=s+T(a[e])&255,c=c+T(a[e+1])&255,l=l+T(a[e+2])&255,o[e]=s,o[e+1]=c,o[e+2]=l;return o}function A(e){let t=j(e),n;n=t.isFloat32?t.vertexData:t.deltaEncoded?E(t.vertexData):t.vertexData;let r=t.indexData;return t.deltaEncoded&&(r=r instanceof Uint16Array?D(r):O(r)),w(r,t.vertexCount),{metadata:t.metadata,flags:t.flags,vertices:n,indices:r,origin:t.origin,scale:t.scale,uvs:t.uvs,colors:t.colors}}function j(e){if(!_)throw new t.d(`SLVA parsing requires a little-endian host: the zero-copy geometry readers view the wire bytes in host byte order.`,t.u.ENVIRONMENT_ERROR);let n=y(v(e)),r=new DataView(n.buffer,n.byteOffset,n.byteLength);if(n.byteLength<12)throw k(`Blob too small to contain SLVA header.`,{expectedBytes:12,availableBytes:n.byteLength});let i=0,a=r.getUint32(i,!0);if(i+=4,a!==1096174675)throw k(`Invalid SLVA magic: 0x${a.toString(16)}`,{expectedMagic:`0x41564c53`,actualMagic:`0x${a.toString(16)}`});let o=r.getUint32(i,!0);if(i+=4,o<1||o>3)throw k(`Unsupported SLVA version: ${o}`,{minSupportedVersion:1,maxSupportedVersion:3,actualVersion:o});let s=r.getUint32(i,!0);if(i+=4,i+s>n.byteLength)throw k(`Insufficient data to read metadata JSON.`,{expectedBytes:s,availableBytes:n.byteLength-i,offset:i});let c=n.subarray(i,i+s);i+=s;let l;try{l=JSON.parse(b(c))}catch(e){throw k(`Failed to parse metadata JSON: ${e instanceof Error?e.message:String(e)}`,{metadataLen:s})}if(i+56>n.byteLength)throw k(`Insufficient data to read geometry header.`,{expectedBytes:56,availableBytes:n.byteLength-i,offset:i});let u=r.getUint32(i,!0);i+=4;let d=r.getFloat64(i,!0);i+=8;let f=r.getFloat64(i,!0);i+=8;let p=r.getFloat64(i,!0);i+=8;let m=r.getFloat64(i,!0);i+=8;let h=r.getFloat64(i,!0);i+=8;let g=r.getFloat64(i,!0);i+=8;let w=r.getUint32(i,!0);i+=4;let T=!!(u&1),E=!!(u&4),D=w*3,O=D*(T?4:2);if(i+O>n.byteLength)throw k(`Insufficient data to read vertices.`,{expectedBytes:O,availableBytes:n.byteLength-i,offset:i,useFloat32:T,vertexCount:w});let A=n.byteOffset+i,j;if(j=T?S(n.buffer,A,D):E?C(n.buffer,A,D):x(n.buffer,A,D),i+=O,i+4>n.byteLength)throw k(`Insufficient data to read index count.`,{expectedBytes:4,availableBytes:n.byteLength-i,offset:i});let M=r.getUint32(i,!0);i+=4;let N=!!(u&2),P=M*(N?2:4);if(i+P>n.byteLength)throw k(`Insufficient data to read indices.`,{expectedBytes:P,availableBytes:n.byteLength-i,offset:i,indexCount:M,useUint16Indices:N});let F=N?C(n.buffer,n.byteOffset+i,M):ee(n.buffer,n.byteOffset+i,M);i+=P;let I=null;if(u&8){let e=te(n,r,i,w,E);I=e.uvs,i=e.offset}let L=null;return u&16&&(L=ne(n,i,w,E)),{metadata:l,flags:u,vertexData:j,indexData:F,isFloat32:T,deltaEncoded:E,vertexCount:w,origin:[d,f,p],scale:[m,h,g],uvs:I,colors:L}}function M(e){let{isFloat32:t,deltaEncoded:n,origin:r,scale:i,uvs:a,colors:o,jobs:s}=e,c=e=>e>>>1^-(e&1),l;if(t)l=e.vertexData;else{let t;if(n){let n=e.vertexData;t=new Int16Array(n.length);let r=0,i=0,a=0;for(let e=0;e<n.length;e+=3)r=r+c(n[e])<<16>>16,i=i+c(n[e+1])<<16>>16,a=a+c(n[e+2])<<16>>16,t[e]=r,t[e+1]=i,t[e+2]=a}else t=e.vertexData;l=new Float32Array(t.length);let a=r[0],o=r[1],s=r[2],u=i[0],d=i[1],f=i[2];for(let e=0;e<t.length;e+=3)l[e]=a+(t[e]+32767)*u,l[e+1]=o+(t[e+1]+32767)*d,l[e+2]=s+(t[e+2]+32767)*f}let u;if(n){let t=e.indexData;if(t instanceof Uint16Array){let e=new Uint16Array(t.length),n=0;for(let r=0;r<t.length;r++)n=n+c(t[r])&65535,e[r]=n;u=e}else{let e=new Uint32Array(t.length),n=0;for(let r=0;r<t.length;r++)n=n+c(t[r])>>>0,e[r]=n;u=e}}else u=e.indexData;let d=l.length/3;for(let e=0;e<u.length;e++)if(u[e]>=d)throw Error(`Index ${u[e]} out of range of vertexCount ${d}`);let f=[];for(let e of s){let t=0,n=0;for(let r of e.windows)t+=r.vertexCount,n+=r.indexCount;let r=new Float32Array(t*3),i=new Uint32Array(n),s=a?new Float32Array(t*2):null,c=o?new Uint8Array(t*3):null,d=0,p=0;for(let t of e.windows){let e=t.vertexStart*3;r.set(l.subarray(e,e+t.vertexCount*3),d*3),s&&a&&s.set(a.subarray(t.vertexStart*2,(t.vertexStart+t.vertexCount)*2),d*2),c&&o&&c.set(o.subarray(e,e+t.vertexCount*3),d*3);let n=t.vertexStart,f=t.vertexStart+t.vertexCount,m=d-t.vertexStart;for(let e=0;e<t.indexCount;e++){let r=u[t.indexStart+e];if(r<n||r>=f)throw Error(`Index ${r} outside vertex window [${n}, ${f})`);i[p+e]=r+m}d+=t.vertexCount,p+=t.indexCount}let m=new Float32Array(t*3);for(let e=0;e<i.length;e+=3){let t=i[e]*3,n=i[e+1]*3,a=i[e+2]*3,o=r[a]-r[n],s=r[a+1]-r[n+1],c=r[a+2]-r[n+2],l=r[t]-r[n],u=r[t+1]-r[n+1],d=r[t+2]-r[n+2],f=s*d-c*u,p=c*l-o*d,h=o*u-s*l;m[t]+=f,m[t+1]+=p,m[t+2]+=h,m[n]+=f,m[n+1]+=p,m[n+2]+=h,m[a]+=f,m[a+1]+=p,m[a+2]+=h}for(let e=0;e<m.length;e+=3){let t=m[e],n=m[e+1],r=m[e+2],i=Math.sqrt(t*t+n*n+r*r)||1;m[e]=t/i,m[e+1]=n/i,m[e+2]=r/i}f.push({positions:r,normals:m,indices:i,uvs:s,colors:c})}return f}function N(){return[`const assemble = ${M.toString()};`,`self.onmessage = (event) => {`,` const { id, input } = event.data;`,` try {`,` const geometries = assemble(input);`,` const transfer = [];`,` for (const g of geometries) {`,` transfer.push(g.positions.buffer, g.normals.buffer, g.indices.buffer);`,` if (g.uvs) transfer.push(g.uvs.buffer);`,` if (g.colors) transfer.push(g.colors.buffer);`,` }`,` self.postMessage({ id, geometries }, transfer);`,` } catch (error) {`,` self.postMessage({ id, error: String((error && error.message) || error) });`,` }`,`};`].join(`
|
|
2
|
+
`)}let P;const F=new Map;let I=1;function L(){if(P!==void 0)return P;if(typeof Worker>`u`||typeof Blob>`u`||typeof URL>`u`||typeof URL.createObjectURL!=`function`)return P=null,null;try{let e=URL.createObjectURL(new Blob([N()],{type:`text/javascript`})),t=new Worker(e);t.onmessage=e=>{let{id:t,geometries:n,error:r}=e.data,i=F.get(t);i&&(F.delete(t),n?i.resolve(n):i.reject(Error(r??`mesh assembly failed in worker`)))},t.onerror=()=>{for(let e of F.values())e.reject(Error(`mesh assembly worker crashed`));F.clear(),t.terminate(),P=null},P=t}catch{P=null}return P}function re(e,t,n){return new Promise((r,i)=>{let a=I++;F.set(a,{resolve:r,reject:i}),e.postMessage({id:a,input:t},n)})}let R=1;function z(e){R=Math.max(1,e)}t.n(z);function ie(e,r){typeof document>`u`||new n.TextureLoader().load(r,t=>{t.colorSpace=n.SRGBColorSpace,t.anisotropy=R,e.map=t,e.needsUpdate=!0},void 0,e=>{t.c().warn(`Failed to load material texture ${r}:`,e)})}function B(e,r){let i=t.o(e.color),a=r?.vertexColors??!1,o=r?.appearance,s=new n.MeshPhysicalMaterial({color:i,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,vertexColors:a,side:o?.cullBackfaces?n.FrontSide:n.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.5,polygonOffsetUnits:.5,depthWrite:!0,depthTest:!0});return o?.envMapIntensity!=null&&(s.envMapIntensity=o.envMapIntensity),e.metalness>.5&&(s.clearcoat=.5,s.clearcoatRoughness=.3),a&&ae(s),e.map&&ie(s,e.map),s}function ae(e){e.onBeforeCompile=e=>{e.vertexShader=e.vertexShader.replace(`#include <color_vertex>`,`#include <color_vertex>
|
|
3
3
|
#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )
|
|
4
4
|
vColor.rgb = mix(
|
|
5
5
|
vColor.rgb / 12.92,
|
|
6
6
|
pow( ( vColor.rgb + 0.055 ) / 1.055, vec3( 2.4 ) ),
|
|
7
7
|
step( vec3( 0.04045 ), vColor.rgb )
|
|
8
8
|
);
|
|
9
|
-
#endif`)}}function Z(e,t){return new (0, _chunkAQJPVUH3cjs.b)(e,_chunkAQJPVUH3cjs.a.VALIDATION_ERROR,{context:t})}function Ee(e,t,r,n){for(let o of e){if(!Number.isInteger(o.materialId)||o.materialId<0||o.materialId>=t)throw Z("Group materialId out of range of the materials array.",{materialId:o.materialId,materialCount:t});for(let a of o.meshes){let s={vertexStart:a.vertexStart,vertexCount:a.vertexCount,indexStart:a.indexStart,indexCount:a.indexCount};for(let[u,i]of Object.entries(s))if(!Number.isInteger(i)||i<0)throw Z(`Mesh metadata field "${u}" must be a non-negative integer.`,{meshName:a.name,field:u,value:i});if(a.vertexStart+a.vertexCount>r)throw Z("Mesh vertex window exceeds the batch vertex buffer.",{meshName:a.name,vertexStart:a.vertexStart,vertexCount:a.vertexCount,totalVertexCount:r});if(a.indexStart+a.indexCount>n)throw Z("Mesh index window exceeds the batch index buffer.",{meshName:a.name,indexStart:a.indexStart,indexCount:a.indexCount,totalIndexCount:n})}}}function xe(e,t){return Z("Index references a vertex outside its mesh's vertex window.",{meshName:t.name,indexValue:e,vertexStart:t.vertexStart,vertexCount:t.vertexCount})}function Ae(e,t,r,n,o,a){let s=[],u=e;for(let i of t){u+=`|${i.vertexStart},${i.vertexCount},${i.indexStart},${i.indexCount}`;let f=i.vertexStart*3,l=f+i.vertexCount*3;s.push(r.subarray(f,l)),s.push(n.subarray(i.indexStart,i.indexStart+i.indexCount)),s.push(o?o.subarray(i.vertexStart*2,(i.vertexStart+i.vertexCount)*2):null),s.push(a?a.subarray(f,l):null)}return at(s,u)}function mt(e,t,r){let n=new Float32Array(e.length),o=t[0],a=t[1],s=t[2],u=r[0],i=r[1],f=r[2];for(let l=0;l<e.length;l+=3)n[l]=o+(e[l]+32767)*u,n[l+1]=a+(e[l+1]+32767)*i,n[l+2]=s+(e[l+2]+32767)*f;return n}function dt(e,t,r,n,o=null,a=null){let s=Ae("merged",e.meshes,t,r,o,a),u=J(s);if(!u){let i=0,f=0;for(let c of e.meshes)i+=c.vertexCount,f+=c.indexCount;let l=new Float32Array(i*3),y=new Uint32Array(f),b=o?new Float32Array(i*2):null,w=a?new Uint8Array(i*3):null,v=0,C=0;for(let c of e.meshes){let d=c.vertexStart*3,p=c.vertexCount*3;if(l.set(t.subarray(d,d+p),v*3),b&&o){let g=c.vertexStart*2;b.set(o.subarray(g,g+c.vertexCount*2),v*2)}w&&a&&w.set(a.subarray(d,d+p),v*3);let m=r.subarray(c.indexStart,c.indexStart+c.indexCount),h=v-c.vertexStart,S=c.vertexStart,T=c.vertexStart+c.vertexCount;for(let g=0;g<m.length;g++){let x=m[g];if(x<S||x>=T)throw xe(x,c);y[C+g]=x+h}v+=c.vertexCount,C+=c.indexCount}u=new O.BufferGeometry,u.setAttribute("position",new O.BufferAttribute(l,3)),u.setIndex(new O.BufferAttribute(y,1)),b&&u.setAttribute("uv",new O.BufferAttribute(b,2)),w&&u.setAttribute("color",new O.BufferAttribute(w,3,!0)),u.computeVertexNormals(),X(s,u)}return Me(u,e,n)}function Me(e,t,r){let n=new O.Mesh(e,r[t.materialId]),o=t.meshes[0],a=t.meshes.map(s=>s.name).filter(s=>s&&s.length>0);return n.name=a.length>0?a[0]:`merged_material_${t.materialId}`,n.castShadow=!0,n.receiveShadow=!0,n.userData={source:"compute",name:n.name,layer:_nullishCoalesce(_optionalChain([o, 'optionalAccess', _11 => _11.layer]), () => ("")),originalIndex:_nullishCoalesce(_optionalChain([o, 'optionalAccess', _12 => _12.originalIndex]), () => (0)),metadata:_nullishCoalesce(_optionalChain([o, 'optionalAccess', _13 => _13.metadata]), () => ({})),mergedFrom:t.meshes.slice(1).map(s=>({name:s.name,layer:s.layer,originalIndex:s.originalIndex}))},n}function pt(e,t,r,n,o=null,a=null){let s=[];for(let u of e.meshes){let i=u.vertexStart*3,f=u.vertexCount*3,l=Ae("single",[u],t,r,o,a),y=J(l);if(!y){let b=t.slice(i,i+f),w=r.subarray(u.indexStart,u.indexStart+u.indexCount),v=new Uint32Array(w.length),C=u.vertexStart,c=u.vertexStart+u.vertexCount;for(let d=0;d<w.length;d++){let p=w[d];if(p<C||p>=c)throw xe(p,u);v[d]=p-C}if(y=new O.BufferGeometry,y.setAttribute("position",new O.BufferAttribute(b,3)),y.setIndex(new O.BufferAttribute(v,1)),o){let d=u.vertexStart*2,p=o.slice(d,d+u.vertexCount*2);y.setAttribute("uv",new O.BufferAttribute(p,2))}if(a){let d=a.slice(i,i+f);y.setAttribute("color",new O.BufferAttribute(d,3,!0))}y.computeVertexNormals(),X(l,y)}s.push(we(y,u,e,n))}return s}function we(e,t,r,n){let o=new O.Mesh(e,n[r.materialId]);return o.name=t.name,o.userData={source:"compute",name:t.name,layer:_nullishCoalesce(t.layer, () => ("")),originalIndex:t.originalIndex,metadata:_nullishCoalesce(t.metadata, () => ({}))},o.castShadow=!0,o.receiveShadow=!0,o}async function Te(e,t,r){let{mergeByMaterial:n=!0,debug:o=!1,material:a}=_nullishCoalesce(t, () => ({})),{parseTime:s=0,perfStart:u=o?performance.now():0}=_nullishCoalesce(r, () => ({}));if(!e.compressedData)return[];let i=await ht(e.compressedData,{mergeByMaterial:n,debug:o,material:a,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}});if(i)return i;let f=performance.now(),l=he(e.compressedData),y=performance.now()-f,b=o?nr(e.compressedData):0;return yt(l,{mergeByMaterial:n,debug:o,material:a,parseTime:s,decodeTime:y,perfStart:u,blobBytes:b,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}})}async function rr(e,t){let{mergeByMaterial:r=!0,debug:n=!1,material:o}=_nullishCoalesce(t, () => ({})),a=n?performance.now():0,s=await ht(e,{mergeByMaterial:r,debug:n,material:o});if(s)return s;let u=performance.now(),i=he(e),f=performance.now()-u,l=e.byteLength;return yt(i,{mergeByMaterial:r,debug:n,material:o,parseTime:0,decodeTime:f,perfStart:a,blobBytes:l})}function yt(e,t){let{mergeByMaterial:r,debug:n,material:o,parseTime:a,decodeTime:s,perfStart:u,blobBytes:i,fallback:f}=t,l=_nullishCoalesce(_nullishCoalesce(e.metadata.materials, () => (_optionalChain([f, 'optionalAccess', _14 => _14.materials]))), () => ([])),y=_nullishCoalesce(_nullishCoalesce(e.metadata.groups, () => (_optionalChain([f, 'optionalAccess', _15 => _15.groups]))), () => ([])),b=_nullishCoalesce(_optionalChain([f, 'optionalAccess', _16 => _16.sourceComponentId]), () => (e.metadata.sourceComponentId)),w=(e.flags&1)!==0;Ee(y,l.length,e.vertices.length/3,e.indices.length);let v=w?e.vertices:mt(e.vertices,e.origin,e.scale);if(n){let m=e.vertices.byteLength+e.indices.byteLength;_chunkAQJPVUH3cjs.c.call(void 0, ).debug("Mesh Batch Stats:"),_chunkAQJPVUH3cjs.c.call(void 0, ).debug(` Materials: ${l.length} | Groups: ${y.length}`),_chunkAQJPVUH3cjs.c.call(void 0, ).debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),_chunkAQJPVUH3cjs.c.call(void 0, ).debug(` Format: ${w?"float32":"int16 quantized"}`),_chunkAQJPVUH3cjs.c.call(void 0, ).debug(` Blob: ${(i/1024/1024).toFixed(2)} MB | Geometry on wire: ${(m/1024/1024).toFixed(2)} MB`)}let C=performance.now(),c=l.map(m=>be(m,{vertexColors:e.colors!=null,appearance:o})),d=[];for(let m of y)if(r&&m.meshes.length>1){let h=dt(m,v,e.indices,c,e.uvs,e.colors);h.userData.sourceComponentId=_nullishCoalesce(b, () => (null)),d.push(h)}else{let h=pt(m,v,e.indices,c,e.uvs,e.colors);for(let S of h)S.userData.sourceComponentId=_nullishCoalesce(b, () => (null));d.push(...h)}let p=performance.now()-C;if(n){let m=performance.now()-u;_chunkAQJPVUH3cjs.c.call(void 0, ).debug("Performance:"),a>0&&_chunkAQJPVUH3cjs.c.call(void 0, ).debug(` Parse JSON: ${a.toFixed(2)}ms`),_chunkAQJPVUH3cjs.c.call(void 0, ).debug(` Decode binary: ${s.toFixed(2)}ms`),_chunkAQJPVUH3cjs.c.call(void 0, ).debug(` Create Meshes: ${p.toFixed(2)}ms`),_chunkAQJPVUH3cjs.c.call(void 0, ).debug(` Total: ${m.toFixed(2)}ms`)}return Promise.resolve(d)}async function ht(e,t){if(typeof Worker>"u")return null;let r=ge(e);if(r.indexData.length/3<it)return null;let n=ct();if(!n)return null;let o=_nullishCoalesce(_nullishCoalesce(r.metadata.materials, () => (_optionalChain([t, 'access', _17 => _17.fallback, 'optionalAccess', _18 => _18.materials]))), () => ([])),a=_nullishCoalesce(_nullishCoalesce(r.metadata.groups, () => (_optionalChain([t, 'access', _19 => _19.fallback, 'optionalAccess', _20 => _20.groups]))), () => ([])),s=_nullishCoalesce(_optionalChain([t, 'access', _21 => _21.fallback, 'optionalAccess', _22 => _22.sourceComponentId]), () => (r.metadata.sourceComponentId));Ee(a,o.length,r.vertexCount,r.indexData.length);let u=c=>({vertexStart:c.vertexStart,vertexCount:c.vertexCount,indexStart:c.indexStart,indexCount:c.indexCount}),i=[],f=[];for(let c of a)if(t.mergeByMaterial&&c.meshes.length>1)i.push({kind:"merged",windows:c.meshes.map(u)}),f.push({kind:"merged",group:c});else for(let d of c.meshes)i.push({kind:"single",windows:[u(d)]}),f.push({kind:"single",group:c,meshMeta:d});let l=r.vertexData.slice(),y=r.indexData.slice(),b=[l.buffer,y.buffer];r.uvs&&b.push(r.uvs.buffer),r.colors&&b.push(r.colors.buffer);let w;try{w=await lt(n,{vertexData:l,isFloat32:r.isFloat32,deltaEncoded:r.deltaEncoded,origin:r.origin,scale:r.scale,indexData:y,uvs:r.uvs,colors:r.colors,jobs:i},b)}catch(c){return _chunkAQJPVUH3cjs.c.call(void 0, ).warn("Mesh assembly worker failed; falling back to main-thread parse.",c),null}if(w.length!==i.length)return null;let v=o.map(c=>be(c,{vertexColors:r.colors!=null,appearance:t.material})),C=[];for(let c=0;c<w.length;c++){let d=w[c],p=f[c],m=J(d.key);m||(m=new V.BufferGeometry,m.setAttribute("position",new V.BufferAttribute(d.positions,3)),m.setAttribute("normal",new V.BufferAttribute(d.normals,3)),m.setIndex(new V.BufferAttribute(d.indices,1)),d.uvs&&m.setAttribute("uv",new V.BufferAttribute(d.uvs,2)),d.colors&&m.setAttribute("color",new V.BufferAttribute(d.colors,3,!0)),X(d.key,m));let h=p.kind==="merged"?Me(m,p.group,v):we(m,p.meshMeta,p.group,v);h.userData.sourceComponentId=_nullishCoalesce(s, () => (null)),C.push(h)}return t.debug&&_chunkAQJPVUH3cjs.c.call(void 0, ).debug(`Mesh batch assembled off-thread: ${C.length} meshes, ${r.indexData.length/3} triangles`),C}function nr(e){return Math.floor(e.length*3/4)}var Re={Angstroms:1e-10,Nanometers:1e-9,Microns:1e-6,Millimeters:.001,Centimeters:.01,Decimeters:.1,Meters:1,Dekameters:10,Hectometers:100,Kilometers:1e3,Megameters:1e6,Gigameters:1e9,Microinches:254e-10,Mils:254e-7,Inches:.0254,Feet:.3048,Yards:.9144,Miles:1609.344,NauticalMiles:1852},or="Display",ar="DisplayBatch";function sr(e){let t=e.split(".");return t.includes(or)||t.includes(ar)}var gt=new Set;async function ir(e,t){let r=performance.now(),n=[],{allowScaling:o=!0,allowAutoPosition:a=!1,groundAxis:s="z",rhino:u,debug:i=!1,parsing:f={}}=_nullishCoalesce(t, () => ({}));try{let l=o?cr(e.modelunits):1;return await lr(e,n,l,f,u,i),a&&dr(n,s),n}catch(l){throw pr(l,n),l}finally{i&&hr(r)}}function cr(e){let t=Re[e];return t!==void 0?t:(gt.has(e)||(gt.add(e),_chunkAQJPVUH3cjs.c.call(void 0, ).warn(`Unknown Rhino model unit "${e}" \u2014 geometry will not be scaled (factor 1). Known units: ${Object.keys(Re).join(", ")}.`)),1)}async function lr(e,t,r,n,o,a){for(let s of e.values){let u=s.InnerTree;for(let i in u){let f=u[i];f&&await ur(f,t,r,n,o,a)}}}async function ur(e,t,r,n,o,a){for(let s of e){if(!sr(s.type))continue;let u={mergeByMaterial:!0,debug:!1,...n},i=fr(s.data);if(!i){_chunkAQJPVUH3cjs.c.call(void 0, ).error("Error parsing display batch envelope: invalid JSON");continue}let f=await Te(i,u),l=pe(i.items,{rhino:o}),y=[...f,...l];if(r!==1)for(let b of y)b.scale.set(r,r,r);t.push(...y),a&&_chunkAQJPVUH3cjs.c.call(void 0, ).debug(`Extracted ${f.length} meshes and ${l.length} items from batch`)}}function fr(e){return typeof e=="string"?mr(e):e}function mr(e){try{return JSON.parse(e)}catch (e3){return}}function dr(e,t){if(e.length===0)return;let r=_chunkAQJPVUH3cjs.m.call(void 0, e);_chunkAQJPVUH3cjs.l.call(void 0, e,r.min[t],t)}function pr(e,t){_chunkAQJPVUH3cjs.c.call(void 0, ).error("An unexpected error occurred:",e),yr(t)}function yr(e){for(let t of e){let r=t;r.geometry&&r.geometry.dispose(),r.material&&(Array.isArray(r.material)?r.material.forEach(n=>n.dispose()):r.material.dispose())}}function hr(e){let t=performance.now()-e;_chunkAQJPVUH3cjs.c.call(void 0, ).info("Time to process meshes:",`${t.toFixed(2)}ms`)}function gr(){_chunkAQJPVUH3cjs.r.call(void 0, )}exports.SCALE_FACTORS = Re; exports.getThreeMeshesFromComputeResponse = ir; exports.meshPolicy = xt; exports.parseDisplayItems = pe; exports.parseMeshBatchBlob = rr; exports.parseMeshBatchObject = Te; exports.releaseParseCaches = gr; exports.setTextureAnisotropy = ut;
|
|
9
|
+
#endif`)}}function V(e,n){return new t.d(e,t.u.VALIDATION_ERROR,{context:n})}function H(e,t,n,r){for(let i of e){if(!Number.isInteger(i.materialId)||i.materialId<0||i.materialId>=t)throw V(`Group materialId out of range of the materials array.`,{materialId:i.materialId,materialCount:t});for(let e of i.meshes){let t={vertexStart:e.vertexStart,vertexCount:e.vertexCount,indexStart:e.indexStart,indexCount:e.indexCount};for(let[n,r]of Object.entries(t))if(!Number.isInteger(r)||r<0)throw V(`Mesh metadata field "${n}" must be a non-negative integer.`,{meshName:e.name,field:n,value:r});if(e.vertexStart+e.vertexCount>n)throw V(`Mesh vertex window exceeds the batch vertex buffer.`,{meshName:e.name,vertexStart:e.vertexStart,vertexCount:e.vertexCount,totalVertexCount:n});if(e.indexStart+e.indexCount>r)throw V(`Mesh index window exceeds the batch index buffer.`,{meshName:e.name,indexStart:e.indexStart,indexCount:e.indexCount,totalIndexCount:r})}}}function U(e,t){return V(`Index references a vertex outside its mesh's vertex window.`,{meshName:t.name,indexValue:e,vertexStart:t.vertexStart,vertexCount:t.vertexCount})}function oe(e,t,n){let r=new Float32Array(e.length),i=t[0],a=t[1],o=t[2],s=n[0],c=n[1],l=n[2];for(let t=0;t<e.length;t+=3)r[t]=i+(e[t]+32767)*s,r[t+1]=a+(e[t+1]+32767)*c,r[t+2]=o+(e[t+2]+32767)*l;return r}function W(e,t,r,i,a=null,o=null){let s=0,c=0;for(let t of e.meshes)s+=t.vertexCount,c+=t.indexCount;let l=new Float32Array(s*3),u=new Uint32Array(c),d=a?new Float32Array(s*2):null,f=o?new Uint8Array(s*3):null,p=0,m=0;for(let n of e.meshes){let e=n.vertexStart*3,i=n.vertexCount*3;if(l.set(t.subarray(e,e+i),p*3),d&&a){let e=n.vertexStart*2;d.set(a.subarray(e,e+n.vertexCount*2),p*2)}f&&o&&f.set(o.subarray(e,e+i),p*3);let s=r.subarray(n.indexStart,n.indexStart+n.indexCount),c=p-n.vertexStart,h=n.vertexStart,g=n.vertexStart+n.vertexCount;for(let e=0;e<s.length;e++){let t=s[e];if(t<h||t>=g)throw U(t,n);u[m+e]=t+c}p+=n.vertexCount,m+=n.indexCount}let h=new n.BufferGeometry;return h.setAttribute(`position`,new n.BufferAttribute(l,3)),h.setIndex(new n.BufferAttribute(u,1)),d&&h.setAttribute(`uv`,new n.BufferAttribute(d,2)),f&&h.setAttribute(`color`,new n.BufferAttribute(f,3,!0)),h.computeVertexNormals(),G(h,e,i)}function G(e,t,r){let i=new n.Mesh(e,r[t.materialId]),a=t.meshes[0],o=t.meshes.map(e=>e.name).filter(e=>e&&e.length>0);return i.name=o.length>0?o[0]:`merged_material_${t.materialId}`,i.castShadow=!0,i.receiveShadow=!0,i.userData={source:`compute`,name:i.name,layer:a?.layer??``,originalIndex:a?.originalIndex??0,metadata:a?.metadata??{},mergedFrom:t.meshes.slice(1).map(e=>({name:e.name,layer:e.layer,originalIndex:e.originalIndex}))},i}function K(e,t,r,i,a=null,o=null){let s=[];for(let c of e.meshes){let l=c.vertexStart*3,u=c.vertexCount*3,d=t.slice(l,l+u),f=r.subarray(c.indexStart,c.indexStart+c.indexCount),p=new Uint32Array(f.length),m=c.vertexStart,h=c.vertexStart+c.vertexCount;for(let e=0;e<f.length;e++){let t=f[e];if(t<m||t>=h)throw U(t,c);p[e]=t-m}let g=new n.BufferGeometry;if(g.setAttribute(`position`,new n.BufferAttribute(d,3)),g.setIndex(new n.BufferAttribute(p,1)),a){let e=c.vertexStart*2,t=a.slice(e,e+c.vertexCount*2);g.setAttribute(`uv`,new n.BufferAttribute(t,2))}if(o){let e=o.slice(l,l+u);g.setAttribute(`color`,new n.BufferAttribute(e,3,!0))}g.computeVertexNormals(),s.push(q(g,c,e,i))}return s}function q(e,t,r,i){let a=new n.Mesh(e,i[r.materialId]);return a.name=t.name,a.userData={source:`compute`,name:t.name,layer:t.layer??``,originalIndex:t.originalIndex,metadata:t.metadata??{}},a.castShadow=!0,a.receiveShadow=!0,a}async function J(e,t,n){let{mergeByMaterial:r=!0,debug:i=!1,material:a}=t??{},{parseTime:o=0,perfStart:s=i?performance.now():0}=n??{};if(!e.compressedData)return[];let c=await X(e.compressedData,{mergeByMaterial:r,debug:i,material:a,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}});if(c)return c;let l=performance.now();return Y(A(e.compressedData),{mergeByMaterial:r,debug:i,material:a,parseTime:o,decodeTime:performance.now()-l,perfStart:s,blobBytes:i?ce(e.compressedData):0,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}})}async function se(e,t){let{mergeByMaterial:n=!0,debug:r=!1,material:i}=t??{},a=r?performance.now():0,o=await X(e,{mergeByMaterial:n,debug:r,material:i});if(o)return o;let s=performance.now(),c=A(e),l=performance.now()-s,u=e.byteLength;return Y(c,{mergeByMaterial:n,debug:r,material:i,parseTime:0,decodeTime:l,perfStart:a,blobBytes:u})}function Y(e,n){let{mergeByMaterial:r,debug:i,material:a,parseTime:o,decodeTime:s,perfStart:c,blobBytes:l,fallback:u}=n,d=e.metadata.materials??u?.materials??[],f=e.metadata.groups??u?.groups??[],p=u?.sourceComponentId??e.metadata.sourceComponentId,m=!!(e.flags&1);H(f,d.length,e.vertices.length/3,e.indices.length);let h=m?e.vertices:oe(e.vertices,e.origin,e.scale);if(i){let n=e.vertices.byteLength+e.indices.byteLength;t.c().debug(`Mesh Batch Stats:`),t.c().debug(` Materials: ${d.length} | Groups: ${f.length}`),t.c().debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),t.c().debug(` Format: ${m?`float32`:`int16 quantized`}`),t.c().debug(` Blob: ${(l/1024/1024).toFixed(2)} MB | Geometry on wire: ${(n/1024/1024).toFixed(2)} MB`)}let g=performance.now(),_=d.map(t=>B(t,{vertexColors:e.colors!=null,appearance:a})),v=[];for(let t of f)if(r&&t.meshes.length>1){let n=W(t,h,e.indices,_,e.uvs,e.colors);n.userData.sourceComponentId=p??null,v.push(n)}else{let n=K(t,h,e.indices,_,e.uvs,e.colors);for(let e of n)e.userData.sourceComponentId=p??null;v.push(...n)}let y=performance.now()-g;if(i){let e=performance.now()-c;t.c().debug(`Performance:`),o>0&&t.c().debug(` Parse JSON: ${o.toFixed(2)}ms`),t.c().debug(` Decode binary: ${s.toFixed(2)}ms`),t.c().debug(` Create Meshes: ${y.toFixed(2)}ms`),t.c().debug(` Total: ${e.toFixed(2)}ms`)}return Promise.resolve(v)}async function X(e,r){if(typeof Worker>`u`)return null;let i=j(e);if(i.indexData.length/3<5e4)return null;let a=L();if(!a)return null;let o=i.metadata.materials??r.fallback?.materials??[],s=i.metadata.groups??r.fallback?.groups??[],c=r.fallback?.sourceComponentId??i.metadata.sourceComponentId;H(s,o.length,i.vertexCount,i.indexData.length);let l=e=>({vertexStart:e.vertexStart,vertexCount:e.vertexCount,indexStart:e.indexStart,indexCount:e.indexCount}),u=[],d=[];for(let e of s)if(r.mergeByMaterial&&e.meshes.length>1)u.push({kind:`merged`,windows:e.meshes.map(l)}),d.push({kind:`merged`,group:e});else for(let t of e.meshes)u.push({kind:`single`,windows:[l(t)]}),d.push({kind:`single`,group:e,meshMeta:t});let f=i.vertexData.slice(),p=i.indexData.slice(),m=[f.buffer,p.buffer];i.uvs&&m.push(i.uvs.buffer),i.colors&&m.push(i.colors.buffer);let h;try{h=await re(a,{vertexData:f,isFloat32:i.isFloat32,deltaEncoded:i.deltaEncoded,origin:i.origin,scale:i.scale,indexData:p,uvs:i.uvs,colors:i.colors,jobs:u},m)}catch(e){return t.c().warn(`Mesh assembly worker failed; falling back to main-thread parse.`,e),null}if(h.length!==u.length)return null;let g=o.map(e=>B(e,{vertexColors:i.colors!=null,appearance:r.material})),_=[];for(let e=0;e<h.length;e++){let t=h[e],r=d[e],i=new n.BufferGeometry;i.setAttribute(`position`,new n.BufferAttribute(t.positions,3)),i.setAttribute(`normal`,new n.BufferAttribute(t.normals,3)),i.setIndex(new n.BufferAttribute(t.indices,1)),t.uvs&&i.setAttribute(`uv`,new n.BufferAttribute(t.uvs,2)),t.colors&&i.setAttribute(`color`,new n.BufferAttribute(t.colors,3,!0));let a=r.kind===`merged`?G(i,r.group,g):q(i,r.meshMeta,r.group,g);a.userData.sourceComponentId=c??null,_.push(a)}return r.debug&&t.c().debug(`Mesh batch assembled off-thread: ${_.length} meshes, ${i.indexData.length/3} triangles`),_}function ce(e){return Math.floor(e.length*3/4)}const Z={Angstroms:1e-10,Nanometers:1e-9,Microns:1e-6,Millimeters:.001,Centimeters:.01,Decimeters:.1,Meters:1,Dekameters:10,Hectometers:100,Kilometers:1e3,Megameters:1e6,Gigameters:1e9,Microinches:2.54e-8,Mils:254e-7,Inches:.0254,Feet:.3048,Yards:.9144,Miles:1609.344,NauticalMiles:1852};function le(e){let t=e.split(`.`);return t.includes(`Display`)||t.includes(`DisplayBatch`)}const Q=new Set;async function ue(e,t){let n=performance.now(),r=[],{allowScaling:i=!0,allowAutoPosition:a=!1,groundAxis:o=`z`,debug:s=!1,parsing:c={}}=t??{};try{return await fe(e,r,i?de(e.modelunits):1,c,s),a&&he(r,o),r}catch(e){throw ge(e,r),e}finally{s&&ve(n)}}function de(e){let n=Z[e];return n===void 0?(Q.has(e)||(Q.add(e),t.c().warn(`Unknown Rhino model unit "${e}" — geometry will not be scaled (factor 1). Known units: ${Object.keys(Z).join(`, `)}.`)),1):n}async function fe(e,t,n,r,i){for(let a of e.values){let e=a.InnerTree;for(let a in e){let o=e[a];o&&await pe(o,t,n,r,i)}}}async function pe(e,n,r,i,a){for(let o of e){if(!le(o.type))continue;let e={mergeByMaterial:!0,debug:!1,...i},s=me(o.data);if(!s){t.c().error(`Error parsing display batch envelope: invalid JSON`);continue}let c=await J(s,e),l=g(s.items),u=[...c,...l];if(r!==1)for(let e of u)e.scale.set(r,r,r);n.push(...u),a&&t.c().debug(`Extracted ${c.length} meshes and ${l.length} items from batch`)}}function me(e){return typeof e==`string`?$(e):e}function $(e){try{return JSON.parse(e)}catch{return}}function he(e,n){if(e.length===0)return;let r=t.a(e);t.i(e,r.min[n],n)}function ge(e,n){t.c().error(`An unexpected error occurred:`,e),_e(n)}function _e(e){for(let t of e){let e=t;e.geometry&&e.geometry.dispose(),e.material&&(Array.isArray(e.material)?e.material.forEach(e=>e.dispose()):e.material.dispose())}}function ve(e){let n=performance.now()-e;t.c().info(`Time to process meshes:`,`${n.toFixed(2)}ms`)}exports.SCALE_FACTORS=Z,exports.getThreeMeshesFromComputeResponse=ue,exports.meshPolicy=d,exports.parseDisplayItems=g,exports.parseMeshBatchBlob=se,exports.parseMeshBatchObject=J,exports.setTextureAnisotropy=z;
|
|
10
10
|
//# sourceMappingURL=parse.cjs.map
|