@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/dist/parse.d.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Structural, not nominal: satisfies `@selvajs/solve/client`'s `MeshPolicy<THREE.Object3D>`
|
|
7
|
-
* without this package depending on solve.
|
|
8
|
-
*/
|
|
1
|
+
import { i as MaterialAppearanceOptions } from "./types-Di80Y609.js";
|
|
2
|
+
import * as THREE from "three";
|
|
3
|
+
//#region src/parse/mesh-policy.d.ts
|
|
4
|
+
/** Structurally, not nominally, typed as `@selvajs/solve/client`'s `MeshPolicy<THREE.Object3D>` — avoids a dependency on solve. */
|
|
9
5
|
declare const meshPolicy: {
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
clone(meshes: THREE.Object3D[]): THREE.Object3D[];
|
|
7
|
+
release(meshes: THREE.Object3D[]): void;
|
|
12
8
|
};
|
|
13
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/parse/webdisplay/response-envelope.d.ts
|
|
14
11
|
/**
|
|
15
12
|
* Declared structurally rather than imported from `@selvajs/compute` — this package converts
|
|
16
13
|
* meshes, it doesn't need a Rhino.Compute client dependency to describe the shape a caller hands
|
|
@@ -18,68 +15,75 @@ declare const meshPolicy: {
|
|
|
18
15
|
* this, so {@link getThreeMeshesFromComputeResponse} keeps accepting one unchanged.
|
|
19
16
|
*/
|
|
20
17
|
interface DisplayDataItem {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
/** Namespaced wire type token, e.g. `Selva.GH.Features.Display.Services.DisplayBatch`. */
|
|
19
|
+
type: string;
|
|
20
|
+
data: string;
|
|
24
21
|
}
|
|
25
22
|
interface DisplayResponseValue {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
InnerTree: {
|
|
24
|
+
[branchPath: string]: DisplayDataItem[];
|
|
25
|
+
};
|
|
29
26
|
}
|
|
30
27
|
interface DisplayComputeResponse {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
values: DisplayResponseValue[];
|
|
29
|
+
/** Rhino `UnitSystem` name driving unit scaling (see `SCALE_FACTORS`); unrecognized/absent scales 1. */
|
|
30
|
+
modelunits: string;
|
|
34
31
|
}
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/parse/display-items/types.d.ts
|
|
37
34
|
interface DisplayIdentity {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
metadata?: Record<string, string>;
|
|
35
|
+
/** Stable pick key: `${sourceComponentId}:${originalIndex}`. Distinct from `name` so renaming doesn't change identity. */
|
|
36
|
+
id: string;
|
|
37
|
+
name: string;
|
|
38
|
+
layer: string;
|
|
39
|
+
/** Arbitrary key-value pairs from the GH Metadata input. */
|
|
40
|
+
metadata?: Record<string, string>;
|
|
45
41
|
}
|
|
46
42
|
interface DisplayItemBase extends DisplayIdentity {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
/** Hex/rgb/named color string, parsed by `parseColor`. Falls back to a viewer default. */
|
|
44
|
+
color?: string;
|
|
45
|
+
/** 0-1; omitted means fully opaque. */
|
|
46
|
+
opacity?: number;
|
|
51
47
|
}
|
|
52
48
|
/** Rhino's Z-up frame and `{X,Y,Z}` casing. */
|
|
53
49
|
interface DisplayPosition {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
X: number;
|
|
51
|
+
Y: number;
|
|
52
|
+
Z: number;
|
|
57
53
|
}
|
|
58
|
-
/**
|
|
54
|
+
/** Rendered as a fat `Line2` straight from `points` — nothing decodes geometry in the browser. */
|
|
59
55
|
interface DisplayCurve extends DisplayItemBase {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
kind: 'curve';
|
|
57
|
+
/**
|
|
58
|
+
* Backend-tessellated polyline, flat `[x,y,z, …]` in Rhino's Z-up frame.
|
|
59
|
+
*
|
|
60
|
+
* Typed as required even though the plugin still sends a legacy `json` field alongside it: a
|
|
61
|
+
* payload without `points` came from a Display component too old to render, and parsing throws
|
|
62
|
+
* rather than treating it as a shape this package supports.
|
|
63
|
+
*/
|
|
64
|
+
points: number[];
|
|
65
|
+
/** Screen-space CSS px, constant regardless of zoom. Omitted uses the viewer default. */
|
|
66
|
+
width?: number;
|
|
64
67
|
}
|
|
65
68
|
interface DisplayPoint extends DisplayItemBase {
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
kind: 'point';
|
|
70
|
+
position: DisplayPosition;
|
|
68
71
|
}
|
|
69
72
|
type DisplayItem = DisplayCurve | DisplayPoint;
|
|
70
|
-
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/parse/webdisplay/types.d.ts
|
|
71
75
|
interface SerializableMaterial {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
color: string;
|
|
77
|
+
metalness: number;
|
|
78
|
+
roughness: number;
|
|
79
|
+
opacity: number;
|
|
80
|
+
transparent: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Optional color-map texture reference: http(s) URL, data URI, or plugin asset URL
|
|
83
|
+
* (`http://localhost:{port}/assets/{hash}`). Omitted entirely (not just empty) when untextured.
|
|
84
|
+
* When set, the mesh blob also carries per-vertex UVs (FLAG_HAS_UVS) for meshes using it.
|
|
85
|
+
*/
|
|
86
|
+
map?: string;
|
|
83
87
|
}
|
|
84
88
|
/**
|
|
85
89
|
* `vertexStart`/`vertexCount` and `indexStart`/`indexCount` are in **element units** of the
|
|
@@ -89,24 +93,23 @@ interface SerializableMaterial {
|
|
|
89
93
|
* vertex components are 2 bytes (int16 quantized) or 4 bytes (`FLAG_FLOAT32`).
|
|
90
94
|
*/
|
|
91
95
|
interface MeshMetadata {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
96
|
+
name: string;
|
|
97
|
+
/** Layer path for grouping in the scene manager, e.g. 'Structure/Walls'. */
|
|
98
|
+
layer: string;
|
|
99
|
+
/** Index in the GH input tree before material grouping; combined with sourceComponentId
|
|
100
|
+
* uniquely identifies the GH source geometry. */
|
|
101
|
+
originalIndex: number;
|
|
102
|
+
vertexCount: number;
|
|
103
|
+
/** 3 per triangle. */
|
|
104
|
+
indexCount: number;
|
|
105
|
+
vertexStart: number;
|
|
106
|
+
indexStart: number;
|
|
107
|
+
/** Arbitrary key-value pairs from the GH Metadata input. */
|
|
108
|
+
metadata?: Record<string, string>;
|
|
105
109
|
}
|
|
106
110
|
interface MaterialGroup {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
meshes: MeshMetadata[];
|
|
111
|
+
materialId: number;
|
|
112
|
+
meshes: MeshMetadata[];
|
|
110
113
|
}
|
|
111
114
|
/**
|
|
112
115
|
* One Display component's payload, ready for Three.js rendering.
|
|
@@ -120,59 +123,54 @@ interface MaterialGroup {
|
|
|
120
123
|
* blob (`items`), not inside it.
|
|
121
124
|
*/
|
|
122
125
|
interface DisplayBatch {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
126
|
+
materials: SerializableMaterial[];
|
|
127
|
+
groups: MaterialGroup[];
|
|
128
|
+
compressedData: string;
|
|
129
|
+
/** InstanceGuid of the WebDisplay GH component that produced this batch; combined with
|
|
130
|
+
* MeshMetadata.originalIndex to backtrack any mesh to its GH source. */
|
|
131
|
+
sourceComponentId?: string;
|
|
132
|
+
/** Non-mesh display items — see {@link DisplayItem}. Parsed by the separate `display-items`
|
|
133
|
+
* path, not the SLVA mesh parser. Omitted when there are none. */
|
|
134
|
+
items?: DisplayItem[];
|
|
132
135
|
}
|
|
133
136
|
interface MeshBatchParsingOptions {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
137
|
+
/** Merge meshes sharing a material into a single geometry. Defaults to true. */
|
|
138
|
+
mergeByMaterial?: boolean;
|
|
139
|
+
debug?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Appearance dials applied to every material built from this batch — set once at parse time
|
|
142
|
+
* (materials are rebuilt per solve). Runtime restyling of an already-built scene lives in the
|
|
143
|
+
* viewer's `setLook`.
|
|
144
|
+
*/
|
|
145
|
+
material?: MaterialAppearanceOptions;
|
|
143
146
|
}
|
|
144
|
-
|
|
145
147
|
interface MeshExtractionOptions {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
148
|
+
parsing?: MeshBatchParsingOptions;
|
|
149
|
+
/** Scale geometry to model units. Defaults to true. */
|
|
150
|
+
allowScaling?: boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Drop geometry so its lowest point sits on the ground plane. **Defaults to `false`** — content
|
|
153
|
+
* renders at its true Rhino coordinates, matching the Grasshopper definition. Setting `true`
|
|
154
|
+
* shifts objects, so anything read back out of the scene (bounds, measured/picked positions) no
|
|
155
|
+
* longer corresponds to Rhino coordinates.
|
|
156
|
+
*/
|
|
157
|
+
allowAutoPosition?: boolean;
|
|
158
|
+
/** Up axis for `allowAutoPosition` grounding. Defaults to `'z'` (Rhino's frame) — only set this
|
|
159
|
+
* if the viewer is configured with a non-default `sceneUp`. */
|
|
160
|
+
groundAxis?: 'x' | 'y' | 'z';
|
|
161
|
+
debug?: boolean;
|
|
162
|
+
}
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/parse/webdisplay/webdisplay-parser.d.ts
|
|
165
165
|
/**
|
|
166
166
|
* Metres per model unit, keyed by Rhino `UnitSystem` name (the `modelunits` string on the compute
|
|
167
|
-
* response). Imperial factors are the exact international definitions
|
|
168
|
-
*
|
|
169
|
-
* — see {@link getScaleFactor}.
|
|
167
|
+
* response). Imperial factors are the exact international definitions. Units missing from this
|
|
168
|
+
* table scale by 1 and log a one-time warning — see {@link getScaleFactor}.
|
|
170
169
|
*/
|
|
171
170
|
declare const SCALE_FACTORS: Record<string, number>;
|
|
172
171
|
/**
|
|
173
172
|
* Extracts display meshes and items from a Grasshopper WebDisplay compute response: decompresses,
|
|
174
|
-
* scales to meters, and optionally grounds them. Requires the VektorNode Rhino.Compute fork
|
|
175
|
-
* root CLAUDE.md).
|
|
173
|
+
* scales to meters, and optionally grounds them. Requires the VektorNode Rhino.Compute fork.
|
|
176
174
|
*
|
|
177
175
|
* Synchronous internally (large batches block the UI for their duration); `async` only so the
|
|
178
176
|
* shape can stay stable if parsing moves off-thread later.
|
|
@@ -180,56 +178,51 @@ declare const SCALE_FACTORS: Record<string, number>;
|
|
|
180
178
|
* @throws Rethrows unexpected errors after attempting to dispose any created meshes.
|
|
181
179
|
*/
|
|
182
180
|
declare function getThreeMeshesFromComputeResponse(data: DisplayComputeResponse, options?: MeshExtractionOptions): Promise<THREE.Object3D[]>;
|
|
183
|
-
|
|
184
|
-
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/parse/webdisplay/batch-parser.d.ts
|
|
185
183
|
interface ParseTelemetry {
|
|
186
|
-
|
|
187
|
-
|
|
184
|
+
parseTime?: number;
|
|
185
|
+
perfStart?: number;
|
|
188
186
|
}
|
|
189
187
|
/**
|
|
190
188
|
* Parses a DisplayBatch object and creates Three.js meshes from its mesh blob.
|
|
191
189
|
*
|
|
192
190
|
* Synchronous internally — `parseBinaryMeshBatch` does no IO, just typed-array views over the
|
|
193
|
-
* blob. Stays `async` so callers don't
|
|
191
|
+
* blob. Stays `async` so callers don't need to change shape if parsing moves into a worker later.
|
|
194
192
|
*
|
|
195
193
|
* @throws {VisualizationError} On a corrupt/truncated/unsupported mesh blob or malformed group metadata.
|
|
196
194
|
*/
|
|
197
|
-
declare function parseMeshBatchObject(batch: DisplayBatch, options?: MeshBatchParsingOptions,
|
|
198
|
-
/** @internal Timings threaded from an outer entry point
|
|
195
|
+
declare function parseMeshBatchObject(batch: DisplayBatch, options?: MeshBatchParsingOptions,
|
|
196
|
+
/** @internal Timings threaded from an outer entry point — not a caller option. */
|
|
199
197
|
telemetry?: ParseTelemetry): Promise<THREE.Mesh[]>;
|
|
200
198
|
/**
|
|
201
199
|
* Parses a raw binary mesh batch blob (SLVA wire format) and creates Three.js meshes.
|
|
202
200
|
*
|
|
203
201
|
* Use this entry point when the blob arrives as a binary WebSocket frame rather than inside a JSON
|
|
204
|
-
* envelope
|
|
205
|
-
* embedded metadata header.
|
|
202
|
+
* envelope — the blob is self-describing, with materials, groups, and `sourceComponentId` coming
|
|
203
|
+
* from its embedded metadata header.
|
|
206
204
|
*
|
|
207
205
|
* @throws {VisualizationError} On a corrupt/truncated/unsupported mesh blob or malformed group metadata.
|
|
208
206
|
*/
|
|
209
207
|
declare function parseMeshBatchBlob(blob: ArrayBuffer | Uint8Array, options?: MeshBatchParsingOptions): Promise<THREE.Mesh[]>;
|
|
210
|
-
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region src/parse/webdisplay/apply-texture.d.ts
|
|
211
210
|
/**
|
|
212
211
|
* Subscribed to the renderer's own report below, so no host wiring is needed; still exported for a
|
|
213
|
-
* host embedding a foreign renderer that wants to set it directly.
|
|
212
|
+
* host embedding a foreign renderer that wants to set it directly. Applies to textures loaded from
|
|
213
|
+
* here on — textures already decoded keep the value they were given.
|
|
214
214
|
*/
|
|
215
215
|
declare function setTextureAnisotropy(value: number): void;
|
|
216
|
-
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/parse/display-items/display-items-parser.d.ts
|
|
217
218
|
/**
|
|
218
|
-
*
|
|
219
|
+
* Builds THREE objects for the batch's non-mesh items.
|
|
219
220
|
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
* module-level state.
|
|
224
|
-
*
|
|
225
|
-
* Safe to call repeatedly and with a viewer running — the caches simply repopulate on the next solve.
|
|
221
|
+
* @throws VisualizationError when a curve predates backend tessellation, so a stale definition
|
|
222
|
+
* surfaces as an actionable error instead of a scene quietly missing its curves. Every other
|
|
223
|
+
* unrenderable item is logged and skipped.
|
|
226
224
|
*/
|
|
227
|
-
declare function
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
rhino?: RhinoModule;
|
|
232
|
-
}
|
|
233
|
-
declare function parseDisplayItems(items: DisplayItem[] | undefined, options?: DisplayItemParseOptions): THREE.Object3D[];
|
|
234
|
-
|
|
235
|
-
export { type DisplayBatch, type DisplayComputeResponse, type DisplayCurve, type DisplayDataItem, type DisplayIdentity, type DisplayItem, type DisplayItemBase, type DisplayItemParseOptions, type DisplayPoint, type DisplayPosition, type DisplayResponseValue, type MaterialGroup, type MeshBatchParsingOptions, type MeshExtractionOptions, type MeshMetadata, SCALE_FACTORS, type SerializableMaterial, getThreeMeshesFromComputeResponse, meshPolicy, parseDisplayItems, parseMeshBatchBlob, parseMeshBatchObject, releaseParseCaches, setTextureAnisotropy };
|
|
225
|
+
declare function parseDisplayItems(items: DisplayItem[] | undefined): THREE.Object3D[];
|
|
226
|
+
//#endregion
|
|
227
|
+
export { type DisplayBatch, type DisplayComputeResponse, type DisplayCurve, type DisplayDataItem, type DisplayIdentity, type DisplayItem, type DisplayItemBase, type DisplayPoint, type DisplayPosition, type DisplayResponseValue, type MaterialGroup, type MeshBatchParsingOptions, type MeshExtractionOptions, type MeshMetadata, SCALE_FACTORS, type SerializableMaterial, getThreeMeshesFromComputeResponse, meshPolicy, parseDisplayItems, parseMeshBatchBlob, parseMeshBatchObject, setTextureAnisotropy };
|
|
228
|
+
//# sourceMappingURL=parse.d.ts.map
|
package/dist/parse.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import{a as G,b as N,c as A,f as Be,k as Ie,l as De,m as Oe,n as $,o as Q,q as ee,r as Ue,u as He,v as Le}from"./chunk-EXAI6IC5.js";import"./chunk-5XGN7UAV.js";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[$],u.geometry=i}),r})}function Et(e){e.forEach(t=>Le(t,{materials:!1}))}var xt={clone:bt,release:Et};import*as de from"three";import{Line2 as Mt}from"three/addons/lines/Line2.js";import{LineGeometry as wt}from"three/addons/lines/LineGeometry.js";import{LineMaterial as Tt}from"three/addons/lines/LineMaterial.js";import*as _e from"three";var At="#ffffff";function te(e,t){let r=t??1;return{color:new _e.Color(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 A().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 A().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 wt;a.setPositions(o);let s=te(e.color,e.opacity),u=new Tt({color:s.color}),i=u;i.linewidth=e.width??Ct,i.transparent=s.transparent,i.opacity=s.opacity;let f=new Mt(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){e?.delete?.()}function Bt(e,t){try{let r=JSON.parse(e),n=t.CommonObject.decode(r);return n&&typeof n.pointAt=="function"?n:(Y(n),A().warn("Decoded display-item JSON is not a curve; skipping."),null)}catch(r){return A().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)}import*as P from"three";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 A().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;A().warn(`Skipping unknown display item kind: ${String(s.kind)}`);break}}return n}import*as V from"three";var ke=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;import{inflateSync as _t}from"fflate";function Ge(e){return typeof e=="string"?Be(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=_t(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 N("No UTF-8 decoder available in this environment.",G.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 N(e,G.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 N("SLVA parsing requires a little-endian host: the zero-copy geometry readers view the wire bytes in host byte order.",G.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=e.index?.array.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[$]=!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[$],o.geometry.dispose()}}ee(()=>Nt());function Nt(){for(let e of _.values())delete e.geometry.userData[$],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
|
+
import{a as e,c as t,d as n,i as r,n as i,o as a,t as o,u as s}from"./gpu-dispose-Dkj-BKt4.js";import*as c from"three";import{Line2 as l}from"three/addons/lines/Line2.js";import{LineGeometry as u}from"three/addons/lines/LineGeometry.js";import{LineMaterial as d}from"three/addons/lines/LineMaterial.js";import{inflateSync as f}from"fflate";function p(){let e=globalThis.Buffer;return typeof e==`function`?e:void 0}function m(e){let t=e.replace(/[\t\n\f\r ]/g,``);if(t.length%4==0&&(t=t.replace(/={1,2}$/,``)),t.length%4==1||!/^[A-Za-z0-9+/]*$/.test(t))throw new n(`Invalid base64 input.`,s.ENCODING_ERROR,{context:{inputLength:e.length}});let r=p();if(r)return new Uint8Array(r.from(t,`base64`));if(typeof globalThis.atob==`function`){let e=globalThis.atob(t),n=new Uint8Array(e.length);for(let t=0;t<e.length;t++)n[t]=e.charCodeAt(t)&255;return n}throw new n(`Base64 decoding not supported in this environment.`,s.INVALID_STATE,{context:{environmentInfo:`atob or Buffer not available`}})}function h(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 g(e){e.forEach(e=>o(e,{materials:!1}))}const _={clone:h,release:g};function v(e,t){let n=t??1;return{color:new c.Color(e??`#ffffff`),transparent:n<1,opacity:n}}function y(e){let t=b(e);if(!t)return null;let n=new u;n.setPositions(t);let r=v(e.color,e.opacity),i=new d({color:r.color}),a=i;a.linewidth=e.width??2,a.transparent=r.transparent,a.opacity=r.opacity;let o=new l(n,i);return o.computeLineDistances(),o.name=e.name,o.userData={source:`compute`,id:e.id,layer:e.layer,kind:`curve`,metadata:e.metadata},o}function b(e){if(!e.points)throw new n(`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.`,s.INVALID_CONFIG,{context:{itemId:e.id,kind:e.kind}});return e.points.length>=6?e.points:null}function x(e){let{position:n}=e;if(!n||typeof n.X!=`number`||!Number.isFinite(n.X)||typeof n.Y!=`number`||!Number.isFinite(n.Y)||typeof n.Z!=`number`||!Number.isFinite(n.Z))return t().warn(`Skipping point display item with missing or non-finite position (id: ${String(e.id)}).`),null;let r=new c.BufferGeometry;r.setAttribute(`position`,new c.Float32BufferAttribute([n.X,n.Y,n.Z],3));let i=new c.PointsMaterial({...v(e.color,e.opacity),size:6,sizeAttenuation:!1}),a=new c.Points(r,i);return a.name=e.name,a.userData={source:`compute`,id:e.id,layer:e.layer,kind:`point`,metadata:e.metadata},a}function S(e){if(!e||e.length===0)return[];let n=[];for(let r of e)switch(r.kind){case`curve`:{let e=y(r);e&&n.push(e);break}case`point`:{let e=x(r);e&&n.push(e);break}default:{let e=r;t().warn(`Skipping unknown display item kind: ${String(e.kind)}`);break}}return n}const C=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;function ee(e){return typeof e==`string`?m(e):e instanceof Uint8Array?e:new Uint8Array(e)}function te(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 M(`SLVZ header declares an implausible uncompressed length`,{uncompressedLen:n,deflatedBytes:r.byteLength,maxPlausibleLen:i});let a;try{a=f(r,{out:new Uint8Array(n+1)})}catch(e){throw M(`Failed to inflate SLVZ blob: ${e instanceof Error?e.message:String(e)}`,{uncompressedLen:n,deflatedBytes:r.byteLength})}if(a.byteLength!==n)throw M(`SLVZ payload inflated to a different size than the header declares.`,{declaredLen:n,actualLen:a.byteLength,deflatedBytes:r.byteLength});return a}function ne(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 n(`No UTF-8 decoder available in this environment.`,s.INVALID_STATE)}function re(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 w(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 T(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 E(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 D(e,t){if(e.length!==0&&!(e instanceof Uint16Array&&t>65535)){for(let n=0;n<e.length;n++)if(e[n]>=t)throw M(`Index out of range of vertexCount.`,{indexPosition:n,indexValue:e[n],vertexCount:t})}}function O(e){return e>>>1^-(e&1)}function k(e){let t=new Int16Array(e.length),n=0,r=0,i=0;for(let a=0;a<e.length;a+=3)n=n+O(e[a])<<16>>16,r=r+O(e[a+1])<<16>>16,i=i+O(e[a+2])<<16>>16,t[a]=n,t[a+1]=r,t[a+2]=i;return t}function A(e){let t=new Uint16Array(e.length),n=0;for(let r=0;r<e.length;r++)n=n+O(e[r])&65535,t[r]=n;return t}function j(e){let t=new Uint32Array(e.length),n=0;for(let r=0;r<e.length;r++)n=n+O(e[r])>>>0,t[r]=n;return t}function M(e,t){return new n(e,s.VALIDATION_ERROR,{context:t})}function ie(e,t,n,r,i){if(n+36>e.byteLength)throw M(`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 M(`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=w(e.buffer,p,u).slice();else{let t=T(e.buffer,p,u);m=new Float32Array(u);let n=0,r=0;for(let e=0;e<u;e+=2)i?(n=n+O(t[e])&65535,r=r+O(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 ae(e,t,n,r){let i=n*3;if(t+i>e.byteLength)throw M(`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+O(a[e])&255,c=c+O(a[e+1])&255,l=l+O(a[e+2])&255,o[e]=s,o[e+1]=c,o[e+2]=l;return o}function N(e){let t=P(e),n;n=t.isFloat32?t.vertexData:t.deltaEncoded?k(t.vertexData):t.vertexData;let r=t.indexData;return t.deltaEncoded&&(r=r instanceof Uint16Array?A(r):j(r)),D(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 P(e){if(!C)throw new n(`SLVA parsing requires a little-endian host: the zero-copy geometry readers view the wire bytes in host byte order.`,s.ENVIRONMENT_ERROR);let t=te(ee(e)),r=new DataView(t.buffer,t.byteOffset,t.byteLength);if(t.byteLength<12)throw M(`Blob too small to contain SLVA header.`,{expectedBytes:12,availableBytes:t.byteLength});let i=0,a=r.getUint32(i,!0);if(i+=4,a!==1096174675)throw M(`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 M(`Unsupported SLVA version: ${o}`,{minSupportedVersion:1,maxSupportedVersion:3,actualVersion:o});let c=r.getUint32(i,!0);if(i+=4,i+c>t.byteLength)throw M(`Insufficient data to read metadata JSON.`,{expectedBytes:c,availableBytes:t.byteLength-i,offset:i});let l=t.subarray(i,i+c);i+=c;let u;try{u=JSON.parse(ne(l))}catch(e){throw M(`Failed to parse metadata JSON: ${e instanceof Error?e.message:String(e)}`,{metadataLen:c})}if(i+56>t.byteLength)throw M(`Insufficient data to read geometry header.`,{expectedBytes:56,availableBytes:t.byteLength-i,offset:i});let d=r.getUint32(i,!0);i+=4;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 _=r.getFloat64(i,!0);i+=8;let v=r.getUint32(i,!0);i+=4;let y=!!(d&1),b=!!(d&4),x=v*3,S=x*(y?4:2);if(i+S>t.byteLength)throw M(`Insufficient data to read vertices.`,{expectedBytes:S,availableBytes:t.byteLength-i,offset:i,useFloat32:y,vertexCount:v});let D=t.byteOffset+i,O;if(O=y?w(t.buffer,D,x):b?T(t.buffer,D,x):re(t.buffer,D,x),i+=S,i+4>t.byteLength)throw M(`Insufficient data to read index count.`,{expectedBytes:4,availableBytes:t.byteLength-i,offset:i});let k=r.getUint32(i,!0);i+=4;let A=!!(d&2),j=k*(A?2:4);if(i+j>t.byteLength)throw M(`Insufficient data to read indices.`,{expectedBytes:j,availableBytes:t.byteLength-i,offset:i,indexCount:k,useUint16Indices:A});let N=A?T(t.buffer,t.byteOffset+i,k):E(t.buffer,t.byteOffset+i,k);i+=j;let P=null;if(d&8){let e=ie(t,r,i,v,b);P=e.uvs,i=e.offset}let F=null;return d&16&&(F=ae(t,i,v,b)),{metadata:u,flags:d,vertexData:O,indexData:N,isFloat32:y,deltaEncoded:b,vertexCount:v,origin:[f,p,m],scale:[h,g,_],uvs:P,colors:F}}function F(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 I(){return[`const assemble = ${F.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 L;const R=new Map;let oe=1;function se(){if(L!==void 0)return L;if(typeof Worker>`u`||typeof Blob>`u`||typeof URL>`u`||typeof URL.createObjectURL!=`function`)return L=null,null;try{let e=URL.createObjectURL(new Blob([I()],{type:`text/javascript`})),t=new Worker(e);t.onmessage=e=>{let{id:t,geometries:n,error:r}=e.data,i=R.get(t);i&&(R.delete(t),n?i.resolve(n):i.reject(Error(r??`mesh assembly failed in worker`)))},t.onerror=()=>{for(let e of R.values())e.reject(Error(`mesh assembly worker crashed`));R.clear(),t.terminate(),L=null},L=t}catch{L=null}return L}function ce(e,t,n){return new Promise((r,i)=>{let a=oe++;R.set(a,{resolve:r,reject:i}),e.postMessage({id:a,input:t},n)})}let z=1;function B(e){z=Math.max(1,e)}i(B);function le(e,n){typeof document>`u`||new c.TextureLoader().load(n,t=>{t.colorSpace=c.SRGBColorSpace,t.anisotropy=z,e.map=t,e.needsUpdate=!0},void 0,e=>{t().warn(`Failed to load material texture ${n}:`,e)})}function V(e,t){let n=a(e.color),r=t?.vertexColors??!1,i=t?.appearance,o=new c.MeshPhysicalMaterial({color:n,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,vertexColors:r,side:i?.cullBackfaces?c.FrontSide:c.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.5,polygonOffsetUnits:.5,depthWrite:!0,depthTest:!0});return i?.envMapIntensity!=null&&(o.envMapIntensity=i.envMapIntensity),e.metalness>.5&&(o.clearcoat=.5,o.clearcoatRoughness=.3),r&&H(o),e.map&&le(o,e.map),o}function H(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`)}}import*as O from"three";function Z(e,t){return new N(e,G.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:o?.layer??"",originalIndex:o?.originalIndex??0,metadata:o?.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:t.layer??"",originalIndex:t.originalIndex,metadata:t.metadata??{}},o.castShadow=!0,o.receiveShadow=!0,o}async function Te(e,t,r){let{mergeByMaterial:n=!0,debug:o=!1,material:a}=t??{},{parseTime:s=0,perfStart:u=o?performance.now():0}=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}=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=e.metadata.materials??f?.materials??[],y=e.metadata.groups??f?.groups??[],b=f?.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;A().debug("Mesh Batch Stats:"),A().debug(` Materials: ${l.length} | Groups: ${y.length}`),A().debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),A().debug(` Format: ${w?"float32":"int16 quantized"}`),A().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=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=b??null;d.push(...h)}let p=performance.now()-C;if(n){let m=performance.now()-u;A().debug("Performance:"),a>0&&A().debug(` Parse JSON: ${a.toFixed(2)}ms`),A().debug(` Decode binary: ${s.toFixed(2)}ms`),A().debug(` Create Meshes: ${p.toFixed(2)}ms`),A().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=r.metadata.materials??t.fallback?.materials??[],a=r.metadata.groups??t.fallback?.groups??[],s=t.fallback?.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 A().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=s??null,C.push(h)}return t.debug&&A().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={}}=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),A().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){A().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&&A().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{return}}function dr(e,t){if(e.length===0)return;let r=Oe(e);De(e,r.min[t],t)}function pr(e,t){A().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;A().info("Time to process meshes:",`${t.toFixed(2)}ms`)}function gr(){Ue()}export{Re as SCALE_FACTORS,ir as getThreeMeshesFromComputeResponse,xt as meshPolicy,pe as parseDisplayItems,rr as parseMeshBatchBlob,Te as parseMeshBatchObject,gr as releaseParseCaches,ut as setTextureAnisotropy};
|
|
9
|
+
#endif`)}}function U(e,t){return new n(e,s.VALIDATION_ERROR,{context:t})}function W(e,t,n,r){for(let i of e){if(!Number.isInteger(i.materialId)||i.materialId<0||i.materialId>=t)throw U(`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 U(`Mesh metadata field "${n}" must be a non-negative integer.`,{meshName:e.name,field:n,value:r});if(e.vertexStart+e.vertexCount>n)throw U(`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 U(`Mesh index window exceeds the batch index buffer.`,{meshName:e.name,indexStart:e.indexStart,indexCount:e.indexCount,totalIndexCount:r})}}}function G(e,t){return U(`Index references a vertex outside its mesh's vertex window.`,{meshName:t.name,indexValue:e,vertexStart:t.vertexStart,vertexCount:t.vertexCount})}function ue(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 de(e,t,n,r,i=null,a=null){let o=0,s=0;for(let t of e.meshes)o+=t.vertexCount,s+=t.indexCount;let l=new Float32Array(o*3),u=new Uint32Array(s),d=i?new Float32Array(o*2):null,f=a?new Uint8Array(o*3):null,p=0,m=0;for(let r of e.meshes){let e=r.vertexStart*3,o=r.vertexCount*3;if(l.set(t.subarray(e,e+o),p*3),d&&i){let e=r.vertexStart*2;d.set(i.subarray(e,e+r.vertexCount*2),p*2)}f&&a&&f.set(a.subarray(e,e+o),p*3);let s=n.subarray(r.indexStart,r.indexStart+r.indexCount),c=p-r.vertexStart,h=r.vertexStart,g=r.vertexStart+r.vertexCount;for(let e=0;e<s.length;e++){let t=s[e];if(t<h||t>=g)throw G(t,r);u[m+e]=t+c}p+=r.vertexCount,m+=r.indexCount}let h=new c.BufferGeometry;return h.setAttribute(`position`,new c.BufferAttribute(l,3)),h.setIndex(new c.BufferAttribute(u,1)),d&&h.setAttribute(`uv`,new c.BufferAttribute(d,2)),f&&h.setAttribute(`color`,new c.BufferAttribute(f,3,!0)),h.computeVertexNormals(),K(h,e,r)}function K(e,t,n){let r=new c.Mesh(e,n[t.materialId]),i=t.meshes[0],a=t.meshes.map(e=>e.name).filter(e=>e&&e.length>0);return r.name=a.length>0?a[0]:`merged_material_${t.materialId}`,r.castShadow=!0,r.receiveShadow=!0,r.userData={source:`compute`,name:r.name,layer:i?.layer??``,originalIndex:i?.originalIndex??0,metadata:i?.metadata??{},mergedFrom:t.meshes.slice(1).map(e=>({name:e.name,layer:e.layer,originalIndex:e.originalIndex}))},r}function fe(e,t,n,r,i=null,a=null){let o=[];for(let s of e.meshes){let l=s.vertexStart*3,u=s.vertexCount*3,d=t.slice(l,l+u),f=n.subarray(s.indexStart,s.indexStart+s.indexCount),p=new Uint32Array(f.length),m=s.vertexStart,h=s.vertexStart+s.vertexCount;for(let e=0;e<f.length;e++){let t=f[e];if(t<m||t>=h)throw G(t,s);p[e]=t-m}let g=new c.BufferGeometry;if(g.setAttribute(`position`,new c.BufferAttribute(d,3)),g.setIndex(new c.BufferAttribute(p,1)),i){let e=s.vertexStart*2,t=i.slice(e,e+s.vertexCount*2);g.setAttribute(`uv`,new c.BufferAttribute(t,2))}if(a){let e=a.slice(l,l+u);g.setAttribute(`color`,new c.BufferAttribute(e,3,!0))}g.computeVertexNormals(),o.push(q(g,s,e,r))}return o}function q(e,t,n,r){let i=new c.Mesh(e,r[n.materialId]);return i.name=t.name,i.userData={source:`compute`,name:t.name,layer:t.layer??``,originalIndex:t.originalIndex,metadata:t.metadata??{}},i.castShadow=!0,i.receiveShadow=!0,i}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(N(e.compressedData),{mergeByMaterial:r,debug:i,material:a,parseTime:o,decodeTime:performance.now()-l,perfStart:s,blobBytes:i?me(e.compressedData):0,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}})}async function pe(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=N(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);W(f,d.length,e.vertices.length/3,e.indices.length);let h=m?e.vertices:ue(e.vertices,e.origin,e.scale);if(i){let n=e.vertices.byteLength+e.indices.byteLength;t().debug(`Mesh Batch Stats:`),t().debug(` Materials: ${d.length} | Groups: ${f.length}`),t().debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),t().debug(` Format: ${m?`float32`:`int16 quantized`}`),t().debug(` Blob: ${(l/1024/1024).toFixed(2)} MB | Geometry on wire: ${(n/1024/1024).toFixed(2)} MB`)}let g=performance.now(),_=d.map(t=>V(t,{vertexColors:e.colors!=null,appearance:a})),v=[];for(let t of f)if(r&&t.meshes.length>1){let n=de(t,h,e.indices,_,e.uvs,e.colors);n.userData.sourceComponentId=p??null,v.push(n)}else{let n=fe(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().debug(`Performance:`),o>0&&t().debug(` Parse JSON: ${o.toFixed(2)}ms`),t().debug(` Decode binary: ${s.toFixed(2)}ms`),t().debug(` Create Meshes: ${y.toFixed(2)}ms`),t().debug(` Total: ${e.toFixed(2)}ms`)}return Promise.resolve(v)}async function X(e,n){if(typeof Worker>`u`)return null;let r=P(e);if(r.indexData.length/3<5e4)return null;let i=se();if(!i)return null;let a=r.metadata.materials??n.fallback?.materials??[],o=r.metadata.groups??n.fallback?.groups??[],s=n.fallback?.sourceComponentId??r.metadata.sourceComponentId;W(o,a.length,r.vertexCount,r.indexData.length);let l=e=>({vertexStart:e.vertexStart,vertexCount:e.vertexCount,indexStart:e.indexStart,indexCount:e.indexCount}),u=[],d=[];for(let e of o)if(n.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=r.vertexData.slice(),p=r.indexData.slice(),m=[f.buffer,p.buffer];r.uvs&&m.push(r.uvs.buffer),r.colors&&m.push(r.colors.buffer);let h;try{h=await ce(i,{vertexData:f,isFloat32:r.isFloat32,deltaEncoded:r.deltaEncoded,origin:r.origin,scale:r.scale,indexData:p,uvs:r.uvs,colors:r.colors,jobs:u},m)}catch(e){return t().warn(`Mesh assembly worker failed; falling back to main-thread parse.`,e),null}if(h.length!==u.length)return null;let g=a.map(e=>V(e,{vertexColors:r.colors!=null,appearance:n.material})),_=[];for(let e=0;e<h.length;e++){let t=h[e],n=d[e],r=new c.BufferGeometry;r.setAttribute(`position`,new c.BufferAttribute(t.positions,3)),r.setAttribute(`normal`,new c.BufferAttribute(t.normals,3)),r.setIndex(new c.BufferAttribute(t.indices,1)),t.uvs&&r.setAttribute(`uv`,new c.BufferAttribute(t.uvs,2)),t.colors&&r.setAttribute(`color`,new c.BufferAttribute(t.colors,3,!0));let i=n.kind===`merged`?K(r,n.group,g):q(r,n.meshMeta,n.group,g);i.userData.sourceComponentId=s??null,_.push(i)}return n.debug&&t().debug(`Mesh batch assembled off-thread: ${_.length} meshes, ${r.indexData.length/3} triangles`),_}function me(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 he(e){let t=e.split(`.`);return t.includes(`Display`)||t.includes(`DisplayBatch`)}const Q=new Set;async function ge(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 ve(e,r,i?_e(e.modelunits):1,c,s),a&&xe(r,o),r}catch(e){throw Se(e,r),e}finally{s&&we(n)}}function _e(e){let n=Z[e];return n===void 0?(Q.has(e)||(Q.add(e),t().warn(`Unknown Rhino model unit "${e}" — geometry will not be scaled (factor 1). Known units: ${Object.keys(Z).join(`, `)}.`)),1):n}async function ve(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 ye(o,t,n,r,i)}}}async function ye(e,n,r,i,a){for(let o of e){if(!he(o.type))continue;let e={mergeByMaterial:!0,debug:!1,...i},s=$(o.data);if(!s){t().error(`Error parsing display batch envelope: invalid JSON`);continue}let c=await J(s,e),l=S(s.items),u=[...c,...l];if(r!==1)for(let e of u)e.scale.set(r,r,r);n.push(...u),a&&t().debug(`Extracted ${c.length} meshes and ${l.length} items from batch`)}}function $(e){return typeof e==`string`?be(e):e}function be(e){try{return JSON.parse(e)}catch{return}}function xe(t,n){if(t.length===0)return;let i=e(t);r(t,i.min[n],n)}function Se(e,n){t().error(`An unexpected error occurred:`,e),Ce(n)}function Ce(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 we(e){let n=performance.now()-e;t().info(`Time to process meshes:`,`${n.toFixed(2)}ms`)}export{Z as SCALE_FACTORS,ge as getThreeMeshesFromComputeResponse,_ as meshPolicy,S as parseDisplayItems,pe as parseMeshBatchBlob,J as parseMeshBatchObject,B as setTextureAnisotropy};
|
|
10
10
|
//# sourceMappingURL=parse.js.map
|