@selvajs/visualization 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -75
- package/dist/parse.cjs +3 -3
- package/dist/parse.cjs.map +1 -1
- package/dist/parse.d.cts +15 -17
- package/dist/parse.d.ts +15 -17
- package/dist/parse.js +3 -3
- package/dist/parse.js.map +1 -1
- package/dist/render.cjs +4 -4
- package/dist/render.cjs.map +1 -1
- package/dist/render.d.cts +66 -7
- package/dist/render.d.ts +66 -7
- package/dist/render.js +4 -4
- package/dist/render.js.map +1 -1
- package/dist/scene.cjs +1 -1
- package/dist/scene.cjs.map +1 -1
- package/dist/scene.d.cts +74 -9
- package/dist/scene.d.ts +74 -9
- package/dist/scene.js +1 -1
- package/dist/scene.js.map +1 -1
- package/dist/types-C0V-dIU-.d.cts +83 -0
- package/dist/types-C0V-dIU-.d.ts +83 -0
- package/package.json +6 -6
- package/dist/types-Di80Y609.d.cts +0 -34
- package/dist/types-Di80Y609.d.ts +0 -34
package/dist/parse.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as MaterialAppearanceOptions } from "./types-C0V-dIU-.cjs";
|
|
2
2
|
import * as THREE from "three";
|
|
3
3
|
//#region src/parse/mesh-policy.d.ts
|
|
4
4
|
/** Structurally, not nominally, typed as `@selvajs/solve/client`'s `MeshPolicy<THREE.Object3D>` — avoids a dependency on solve. */
|
|
@@ -11,28 +11,28 @@ declare const meshPolicy: {
|
|
|
11
11
|
/**
|
|
12
12
|
* Declared structurally rather than imported from `@selvajs/compute` — this package converts
|
|
13
13
|
* meshes, it doesn't need a Rhino.Compute client dependency to describe the shape a caller hands
|
|
14
|
-
* it.
|
|
15
|
-
*
|
|
14
|
+
* it. Callers can pass their own `GrasshopperComputeResponse` shape here; the compute package's
|
|
15
|
+
* response type is a superset and stays assignable to this local contract.
|
|
16
16
|
*/
|
|
17
17
|
interface DisplayDataItem {
|
|
18
18
|
/** Namespaced wire type token, e.g. `Selva.GH.Features.Display.Services.DisplayBatch`. */
|
|
19
19
|
type: string;
|
|
20
20
|
data: string;
|
|
21
21
|
}
|
|
22
|
-
interface
|
|
22
|
+
interface GrasshopperResponseValue {
|
|
23
23
|
InnerTree: {
|
|
24
24
|
[branchPath: string]: DisplayDataItem[];
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
interface
|
|
28
|
-
values:
|
|
27
|
+
interface GrasshopperComputeResponse {
|
|
28
|
+
values: GrasshopperResponseValue[];
|
|
29
29
|
/** Rhino `UnitSystem` name driving unit scaling (see `SCALE_FACTORS`); unrecognized/absent scales 1. */
|
|
30
30
|
modelunits: string;
|
|
31
31
|
}
|
|
32
32
|
//#endregion
|
|
33
33
|
//#region src/parse/display-items/types.d.ts
|
|
34
34
|
interface DisplayIdentity {
|
|
35
|
-
/**
|
|
35
|
+
/** The item's identity — the writer-minted opaque id, same contract as mesh ids. Distinct from `name` so renaming doesn't change identity. */
|
|
36
36
|
id: string;
|
|
37
37
|
name: string;
|
|
38
38
|
layer: string;
|
|
@@ -93,12 +93,13 @@ interface SerializableMaterial {
|
|
|
93
93
|
* vertex components are 2 bytes (int16 quantized) or 4 bytes (`FLAG_FLOAT32`).
|
|
94
94
|
*/
|
|
95
95
|
interface MeshMetadata {
|
|
96
|
+
/** The object's identity: an opaque writer-minted string, stable across solves and unique
|
|
97
|
+
* across batches. The viewer keys hidden/selection state on it; never parsed. Absent for
|
|
98
|
+
* foreign writers that mint none. */
|
|
99
|
+
id?: string;
|
|
96
100
|
name: string;
|
|
97
101
|
/** Layer path for grouping in the scene manager, e.g. 'Structure/Walls'. */
|
|
98
102
|
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
103
|
vertexCount: number;
|
|
103
104
|
/** 3 per triangle. */
|
|
104
105
|
indexCount: number;
|
|
@@ -126,9 +127,6 @@ interface DisplayBatch {
|
|
|
126
127
|
materials: SerializableMaterial[];
|
|
127
128
|
groups: MaterialGroup[];
|
|
128
129
|
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
130
|
/** Non-mesh display items — see {@link DisplayItem}. Parsed by the separate `display-items`
|
|
133
131
|
* path, not the SLVA mesh parser. Omitted when there are none. */
|
|
134
132
|
items?: DisplayItem[];
|
|
@@ -177,7 +175,7 @@ declare const SCALE_FACTORS: Record<string, number>;
|
|
|
177
175
|
*
|
|
178
176
|
* @throws Rethrows unexpected errors after attempting to dispose any created meshes.
|
|
179
177
|
*/
|
|
180
|
-
declare function
|
|
178
|
+
declare function getThreeObjectsFromComputeResponse(data: GrasshopperComputeResponse, options?: MeshExtractionOptions): Promise<THREE.Object3D[]>;
|
|
181
179
|
//#endregion
|
|
182
180
|
//#region src/parse/webdisplay/batch-parser.d.ts
|
|
183
181
|
interface ParseTelemetry {
|
|
@@ -199,8 +197,8 @@ telemetry?: ParseTelemetry): Promise<THREE.Mesh[]>;
|
|
|
199
197
|
* Parses a raw binary mesh batch blob (SLVA wire format) and creates Three.js meshes.
|
|
200
198
|
*
|
|
201
199
|
* Use this entry point when the blob arrives as a binary WebSocket frame rather than inside a JSON
|
|
202
|
-
* envelope — the blob is self-describing, with materials, groups, and
|
|
203
|
-
* from
|
|
200
|
+
* envelope — the blob is self-describing, with materials, groups, and per-object ids coming
|
|
201
|
+
* from the container's table.
|
|
204
202
|
*
|
|
205
203
|
* @throws {VisualizationError} On a corrupt/truncated/unsupported mesh blob or malformed group metadata.
|
|
206
204
|
*/
|
|
@@ -224,5 +222,5 @@ declare function setTextureAnisotropy(value: number): void;
|
|
|
224
222
|
*/
|
|
225
223
|
declare function parseDisplayItems(items: DisplayItem[] | undefined): THREE.Object3D[];
|
|
226
224
|
//#endregion
|
|
227
|
-
export { type DisplayBatch, type
|
|
225
|
+
export { type DisplayBatch, type DisplayCurve, type DisplayIdentity, type DisplayItem, type DisplayItemBase, type DisplayPoint, type DisplayPosition, type MaterialGroup, type MeshBatchParsingOptions, type MeshExtractionOptions, type MeshMetadata, SCALE_FACTORS, type SerializableMaterial, getThreeObjectsFromComputeResponse, meshPolicy, parseDisplayItems, parseMeshBatchBlob, parseMeshBatchObject, setTextureAnisotropy };
|
|
228
226
|
//# sourceMappingURL=parse.d.cts.map
|
package/dist/parse.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as MaterialAppearanceOptions } from "./types-C0V-dIU-.js";
|
|
2
2
|
import * as THREE from "three";
|
|
3
3
|
//#region src/parse/mesh-policy.d.ts
|
|
4
4
|
/** Structurally, not nominally, typed as `@selvajs/solve/client`'s `MeshPolicy<THREE.Object3D>` — avoids a dependency on solve. */
|
|
@@ -11,28 +11,28 @@ declare const meshPolicy: {
|
|
|
11
11
|
/**
|
|
12
12
|
* Declared structurally rather than imported from `@selvajs/compute` — this package converts
|
|
13
13
|
* meshes, it doesn't need a Rhino.Compute client dependency to describe the shape a caller hands
|
|
14
|
-
* it.
|
|
15
|
-
*
|
|
14
|
+
* it. Callers can pass their own `GrasshopperComputeResponse` shape here; the compute package's
|
|
15
|
+
* response type is a superset and stays assignable to this local contract.
|
|
16
16
|
*/
|
|
17
17
|
interface DisplayDataItem {
|
|
18
18
|
/** Namespaced wire type token, e.g. `Selva.GH.Features.Display.Services.DisplayBatch`. */
|
|
19
19
|
type: string;
|
|
20
20
|
data: string;
|
|
21
21
|
}
|
|
22
|
-
interface
|
|
22
|
+
interface GrasshopperResponseValue {
|
|
23
23
|
InnerTree: {
|
|
24
24
|
[branchPath: string]: DisplayDataItem[];
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
interface
|
|
28
|
-
values:
|
|
27
|
+
interface GrasshopperComputeResponse {
|
|
28
|
+
values: GrasshopperResponseValue[];
|
|
29
29
|
/** Rhino `UnitSystem` name driving unit scaling (see `SCALE_FACTORS`); unrecognized/absent scales 1. */
|
|
30
30
|
modelunits: string;
|
|
31
31
|
}
|
|
32
32
|
//#endregion
|
|
33
33
|
//#region src/parse/display-items/types.d.ts
|
|
34
34
|
interface DisplayIdentity {
|
|
35
|
-
/**
|
|
35
|
+
/** The item's identity — the writer-minted opaque id, same contract as mesh ids. Distinct from `name` so renaming doesn't change identity. */
|
|
36
36
|
id: string;
|
|
37
37
|
name: string;
|
|
38
38
|
layer: string;
|
|
@@ -93,12 +93,13 @@ interface SerializableMaterial {
|
|
|
93
93
|
* vertex components are 2 bytes (int16 quantized) or 4 bytes (`FLAG_FLOAT32`).
|
|
94
94
|
*/
|
|
95
95
|
interface MeshMetadata {
|
|
96
|
+
/** The object's identity: an opaque writer-minted string, stable across solves and unique
|
|
97
|
+
* across batches. The viewer keys hidden/selection state on it; never parsed. Absent for
|
|
98
|
+
* foreign writers that mint none. */
|
|
99
|
+
id?: string;
|
|
96
100
|
name: string;
|
|
97
101
|
/** Layer path for grouping in the scene manager, e.g. 'Structure/Walls'. */
|
|
98
102
|
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
103
|
vertexCount: number;
|
|
103
104
|
/** 3 per triangle. */
|
|
104
105
|
indexCount: number;
|
|
@@ -126,9 +127,6 @@ interface DisplayBatch {
|
|
|
126
127
|
materials: SerializableMaterial[];
|
|
127
128
|
groups: MaterialGroup[];
|
|
128
129
|
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
130
|
/** Non-mesh display items — see {@link DisplayItem}. Parsed by the separate `display-items`
|
|
133
131
|
* path, not the SLVA mesh parser. Omitted when there are none. */
|
|
134
132
|
items?: DisplayItem[];
|
|
@@ -177,7 +175,7 @@ declare const SCALE_FACTORS: Record<string, number>;
|
|
|
177
175
|
*
|
|
178
176
|
* @throws Rethrows unexpected errors after attempting to dispose any created meshes.
|
|
179
177
|
*/
|
|
180
|
-
declare function
|
|
178
|
+
declare function getThreeObjectsFromComputeResponse(data: GrasshopperComputeResponse, options?: MeshExtractionOptions): Promise<THREE.Object3D[]>;
|
|
181
179
|
//#endregion
|
|
182
180
|
//#region src/parse/webdisplay/batch-parser.d.ts
|
|
183
181
|
interface ParseTelemetry {
|
|
@@ -199,8 +197,8 @@ telemetry?: ParseTelemetry): Promise<THREE.Mesh[]>;
|
|
|
199
197
|
* Parses a raw binary mesh batch blob (SLVA wire format) and creates Three.js meshes.
|
|
200
198
|
*
|
|
201
199
|
* Use this entry point when the blob arrives as a binary WebSocket frame rather than inside a JSON
|
|
202
|
-
* envelope — the blob is self-describing, with materials, groups, and
|
|
203
|
-
* from
|
|
200
|
+
* envelope — the blob is self-describing, with materials, groups, and per-object ids coming
|
|
201
|
+
* from the container's table.
|
|
204
202
|
*
|
|
205
203
|
* @throws {VisualizationError} On a corrupt/truncated/unsupported mesh blob or malformed group metadata.
|
|
206
204
|
*/
|
|
@@ -224,5 +222,5 @@ declare function setTextureAnisotropy(value: number): void;
|
|
|
224
222
|
*/
|
|
225
223
|
declare function parseDisplayItems(items: DisplayItem[] | undefined): THREE.Object3D[];
|
|
226
224
|
//#endregion
|
|
227
|
-
export { type DisplayBatch, type
|
|
225
|
+
export { type DisplayBatch, type DisplayCurve, type DisplayIdentity, type DisplayItem, type DisplayItemBase, type DisplayPoint, type DisplayPosition, type MaterialGroup, type MeshBatchParsingOptions, type MeshExtractionOptions, type MeshMetadata, SCALE_FACTORS, type SerializableMaterial, getThreeObjectsFromComputeResponse, meshPolicy, parseDisplayItems, parseMeshBatchBlob, parseMeshBatchObject, setTextureAnisotropy };
|
|
228
226
|
//# sourceMappingURL=parse.d.ts.map
|
package/dist/parse.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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
|
|
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 ee=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;function te(e){return typeof e==`string`?m(e):e instanceof Uint8Array?e:new Uint8Array(e)}function C(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 P(`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 P(`Failed to inflate SLVZ blob: ${e instanceof Error?e.message:String(e)}`,{uncompressedLen:n,deflatedBytes:r.byteLength})}if(a.byteLength!==n)throw P(`SLVZ payload inflated to a different size than the header declares.`,{declaredLen:n,actualLen:a.byteLength,deflatedBytes:r.byteLength});return a}function w(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 ne(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 re(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 ie(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 E(e,t){if(e.length!==0&&!(e instanceof Uint16Array&&t>65535)){for(let n=0;n<e.length;n++)if(e[n]>=t)throw P(`Index out of range of vertexCount.`,{indexPosition:n,indexValue:e[n],vertexCount:t})}}function D(e){return e>>>1^-(e&1)}function O(e){let t=new Int16Array(e.length),n=0,r=0,i=0;for(let a=0;a<e.length;a+=3)n=n+D(e[a])<<16>>16,r=r+D(e[a+1])<<16>>16,i=i+D(e[a+2])<<16>>16,t[a]=n,t[a+1]=r,t[a+2]=i;return t}function k(e,t){let n=new Int16Array(t*3),r=t,i=0,a=0,o=0;for(let t=0;t<r;t++)i=i+D(e[t]|e[r*3+t]<<8)<<16>>16,a=a+D(e[r+t]|e[r*4+t]<<8)<<16>>16,o=o+D(e[r*2+t]|e[r*5+t]<<8)<<16>>16,n[t*3]=i,n[t*3+1]=a,n[t*3+2]=o;return n}function A(e,t){let n=new Uint16Array(t),r=0;for(let i=0;i<t;i++)r=r+D(e[i]|e[t+i]<<8)&65535,n[i]=r;return n}function j(e,t){let n=new Uint32Array(t),r=0;for(let i=0;i<t;i++){let a=(e[i]|e[t+i]<<8|e[t*2+i]<<16|e[t*3+i]<<24)>>>0;r=r+D(a)>>>0,n[i]=r}return n}function M(e){let t=new Uint16Array(e.length),n=0;for(let r=0;r<e.length;r++)n=n+D(e[r])&65535,t[r]=n;return t}function N(e){let t=new Uint32Array(e.length),n=0;for(let r=0;r<e.length;r++)n=n+D(e[r])>>>0,t[r]=n;return t}function P(e,t){return new n(e,s.VALIDATION_ERROR,{context:t})}function ae(e,t,n,r,i,a=!1){if(n+36>e.byteLength)throw P(`Insufficient data to read UV chunk header.`,{expectedBytes:36,availableBytes:e.byteLength-n,offset:n});let o=t.getUint32(n,!0);n+=4;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=t.getFloat64(n,!0);n+=8;let d=r*2,f=o===1,p=d*(f?4:2);if(n+p>e.byteLength)throw P(`Insufficient data to read UV chunk.`,{expectedBytes:p,availableBytes:e.byteLength-n,offset:n,uvFormat:o,vertexCount:r});let m=e.byteOffset+n,h;if(f)h=re(e.buffer,m,d).slice();else if(a){let t=e.subarray(n,n+p),i=r;h=new Float32Array(d);let a=0,o=0;for(let e=0;e<i;e++)a=a+D(t[e]|t[i*2+e]<<8)&65535,o=o+D(t[i+e]|t[i*3+e]<<8)&65535,h[e*2]=s+a*l,h[e*2+1]=c+o*u}else{let t=T(e.buffer,m,d);h=new Float32Array(d);let n=0,r=0;for(let e=0;e<d;e+=2)i?(n=n+D(t[e])&65535,r=r+D(t[e+1])&65535):(n=t[e],r=t[e+1]),h[e]=s+n*l,h[e+1]=c+r*u}return{uvs:h,offset:n+p}}function oe(e,t,n,r){let i=n*3;if(t+i>e.byteLength)throw P(`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+D(a[e])&255,c=c+D(a[e+1])&255,l=l+D(a[e+2])&255,o[e]=s,o[e+1]=c,o[e+2]=l;return o}function se(e){return e.byteLength>=4&&new DataView(e.buffer,e.byteOffset,4).getUint32(0,!0)===1297501267}function ce(e){let t=F(e),n=null,r=null,i=null,a=[];for(let{type:e,payload:o}of t)switch(e){case 1297040711:n=o;break;case 1279410516:r=C(o);break;case 1280590157:i=w(o);break;case 1381516628:a.push(o)}if(n===null)throw P(`SLVM container has no GEOM chunk.`,{chunkCount:t.length});if(r===null)throw P(`SLVM container has no TABL chunk.`,{chunkCount:t.length});let{groups:o}=le(r),s=ue(i,a);return{geometryBlob:n,metadata:{materials:s,groups:o}}}function F(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.byteLength<12||t.getUint32(0,!0)!==1297501267)throw P(`Not an SLVM container (bad magic).`,{byteLength:e.byteLength});let n=t.getUint32(4,!0);if(n!==3)throw P(`Unsupported SLVM version: ${n}`,{expectedVersion:3});let r=t.getUint32(8,!0),i=[],a=12;for(let n=0;n<r;n++){if(a+8>e.byteLength)throw P(`Truncated SLVM chunk header.`,{offset:a,chunkIndex:n});let r=t.getUint32(a,!0),o=t.getUint32(a+4,!0);if(a+=8,a+o>e.byteLength)throw P(`Truncated SLVM chunk payload.`,{offset:a,chunkIndex:n,byteLen:o});i.push({type:r,payload:e.subarray(a,a+o)}),a+=o+(4-o%4)%4}return i}function I(e){let t=0,n=0;for(;;){if(e.pos>=e.bytes.byteLength||n>28)throw P(`Malformed varint in SLVM table.`,{pos:e.pos});let r=e.bytes[e.pos++];if(t|=(r&127)<<n,!(r&128))return t>>>0;n+=7}}function L(e,t,n){let r=e.bytes[e.pos++],i=Array(t);switch(r){case 0:i.fill(``);break;case 1:for(let e=0;e<t;e++)i[e]=String(e+1);break;case 2:for(let r=0;r<t;r++)i[r]=n[I(e)]??``;break;default:throw P(`Unknown SLVM string column mode: ${r}`,{pos:e.pos})}return i}function le(e){let t={bytes:e,pos:0},n=I(t),r=I(t),i=I(t),a=n+r+i,o=I(t),s=Array(o);for(let n=0;n<o;n++){let r=I(t);s[n]=w(e.subarray(t.pos,t.pos+r)),t.pos+=r}let c=Array(n),l=Array(n);for(let e=0;e<n;e++)c[e]=I(t),l[e]=I(t);for(let e=0;e<r;e++)I(t);let u=I(t),d=[];for(let e=0;e<u;e++)d.push({materialId:I(t),meshCount:I(t)});let f=L(t,a,s),p=L(t,a,s),m=Array(a),h=I(t);for(let e=0;e<h;e++){let e=s[I(t)]??``,n=I(t),r=Array(n),i=0;for(let e=0;e<n;e++)i+=I(t),r[e]=i;for(let i=0;i<n;i++){let n=s[I(t)]??``,a=r[i];(m[a]??={})[e]=n}}let g=d.length>0||n===0?d:[{materialId:0,meshCount:n}],_=[],v=0,y=0,b=0;for(let e of g){let t=[];for(let r=0;r<e.meshCount&&v<n;r++,v++){let e=m[v],n=e?.id;e!==void 0&&delete e.id,t.push({id:n,name:f[v],layer:p[v],vertexCount:c[v],indexCount:l[v]*3,vertexStart:y,indexStart:b,metadata:e??{}}),y+=c[v],b+=l[v]*3}_.push({materialId:e.materialId,meshes:t})}return{groups:_}}function ue(e,t){if(e===null)return[];let n;try{n=JSON.parse(e).materials??[]}catch(t){throw P(`Failed to parse SLVM materials JSON: ${t instanceof Error?t.message:String(t)}`,{byteLength:e.length})}for(let e of n)if(e.map?.startsWith(`slvm:tex:`)){let n=t[Number(e.map.slice(9))];n!==void 0&&(e.map=de(n))}return n}function de(e){let t={bytes:e,pos:0},n=I(t),r=w(e.subarray(t.pos,t.pos+n)),i=e.subarray(t.pos+n),a=``,o=32768;for(let e=0;e<i.byteLength;e+=o)a+=String.fromCharCode(...i.subarray(e,e+o));return`data:${r};base64,${btoa(a)}`}function R(e){let t=z(e),n;n=t.isFloat32?t.vertexData:t.planarByteSplit?k(t.vertexData,t.vertexCount):t.deltaEncoded?O(t.vertexData):t.vertexData;let r;if(t.planarByteSplit){let e=t.indexData;r=t.uint16Indices?A(e,e.length/2):j(e,e.length/4)}else r=t.deltaEncoded?t.indexData instanceof Uint16Array?M(t.indexData):N(t.indexData):t.indexData;return E(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 z(e){if(!ee)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(e);if(se(t)){let e=ce(t),n=z(e.geometryBlob);return n.metadata=e.metadata,n}let r=C(t),i=new DataView(r.buffer,r.byteOffset,r.byteLength);if(r.byteLength<12)throw P(`Blob too small to contain SLVA header.`,{expectedBytes:12,availableBytes:r.byteLength});let a=0,o=i.getUint32(a,!0);if(a+=4,o!==1096174675)throw P(`Invalid SLVA magic: 0x${o.toString(16)}`,{expectedMagic:`0x41564c53`,actualMagic:`0x${o.toString(16)}`});let c=i.getUint32(a,!0);if(a+=4,c<1||c>4)throw P(`Unsupported SLVA version: ${c}`,{minSupportedVersion:1,maxSupportedVersion:4,actualVersion:c});let l=i.getUint32(a,!0);if(a+=4,a+l>r.byteLength)throw P(`Insufficient data to read metadata JSON.`,{expectedBytes:l,availableBytes:r.byteLength-a,offset:a});let u=r.subarray(a,a+l);a+=l;let d;try{d=l===0?{}:JSON.parse(w(u))}catch(e){throw P(`Failed to parse metadata JSON: ${e instanceof Error?e.message:String(e)}`,{metadataLen:l})}if(a+56>r.byteLength)throw P(`Insufficient data to read geometry header.`,{expectedBytes:56,availableBytes:r.byteLength-a,offset:a});let f=i.getUint32(a,!0);a+=4;let p=i.getFloat64(a,!0);a+=8;let m=i.getFloat64(a,!0);a+=8;let h=i.getFloat64(a,!0);a+=8;let g=i.getFloat64(a,!0);a+=8;let _=i.getFloat64(a,!0);a+=8;let v=i.getFloat64(a,!0);a+=8;let y=i.getUint32(a,!0);a+=4;let b=!!(f&1),x=!!(f&4),S=!!(f&32),E=y*3,D=E*(b?4:2);if(a+D>r.byteLength)throw P(`Insufficient data to read vertices.`,{expectedBytes:D,availableBytes:r.byteLength-a,offset:a,useFloat32:b,vertexCount:y});let O=r.byteOffset+a,k;if(k=b?re(r.buffer,O,E):S?r.subarray(a,a+D):x?T(r.buffer,O,E):ne(r.buffer,O,E),a+=D,a+4>r.byteLength)throw P(`Insufficient data to read index count.`,{expectedBytes:4,availableBytes:r.byteLength-a,offset:a});let A=i.getUint32(a,!0);a+=4;let j=!!(f&2),M=A*(j?2:4);if(a+M>r.byteLength)throw P(`Insufficient data to read indices.`,{expectedBytes:M,availableBytes:r.byteLength-a,offset:a,indexCount:A,useUint16Indices:j});let N=S?r.subarray(a,a+M):j?T(r.buffer,r.byteOffset+a,A):ie(r.buffer,r.byteOffset+a,A);a+=M;let F=null;if(f&8){let e=ae(r,i,a,y,x,S);F=e.uvs,a=e.offset}let I=null;return f&16&&(I=oe(r,a,y,x)),{metadata:d,flags:f,vertexData:k,indexData:N,isFloat32:b,deltaEncoded:x,planarByteSplit:S,uint16Indices:j,vertexCount:y,origin:[p,m,h],scale:[g,_,v],uvs:F,colors:I}}function fe(e){let{isFloat32:t,deltaEncoded:n,planarByteSplit:r,uint16Indices:i,origin:a,scale:o,uvs:s,colors:c,jobs:l}=e,u=e=>e>>>1^-(e&1),d;if(t)d=e.vertexData;else{let t;if(r){let n=e.vertexData,r=n.length/6;t=new Int16Array(r*3);let i=0,a=0,o=0;for(let e=0;e<r;e++)i=i+u(n[e]|n[r*3+e]<<8)<<16>>16,a=a+u(n[r+e]|n[r*4+e]<<8)<<16>>16,o=o+u(n[r*2+e]|n[r*5+e]<<8)<<16>>16,t[e*3]=i,t[e*3+1]=a,t[e*3+2]=o}else 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+u(n[e])<<16>>16,i=i+u(n[e+1])<<16>>16,a=a+u(n[e+2])<<16>>16,t[e]=r,t[e+1]=i,t[e+2]=a}else t=e.vertexData;d=new Float32Array(t.length);let i=a[0],s=a[1],c=a[2],l=o[0],f=o[1],p=o[2];for(let e=0;e<t.length;e+=3)d[e]=i+(t[e]+32767)*l,d[e+1]=s+(t[e+1]+32767)*f,d[e+2]=c+(t[e+2]+32767)*p}let f;if(r){let t=e.indexData;if(i){let e=t.length/2,n=new Uint16Array(e),r=0;for(let i=0;i<e;i++)r=r+u(t[i]|t[e+i]<<8)&65535,n[i]=r;f=n}else{let e=t.length/4,n=new Uint32Array(e),r=0;for(let i=0;i<e;i++){let a=(t[i]|t[e+i]<<8|t[e*2+i]<<16|t[e*3+i]<<24)>>>0;r=r+u(a)>>>0,n[i]=r}f=n}}else 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+u(t[r])&65535,e[r]=n;f=e}else{let e=new Uint32Array(t.length),n=0;for(let r=0;r<t.length;r++)n=n+u(t[r])>>>0,e[r]=n;f=e}}else f=e.indexData;let p=d.length/3;for(let e=0;e<f.length;e++)if(f[e]>=p)throw Error(`Index ${f[e]} out of range of vertexCount ${p}`);let m=[];for(let e of l){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),a=s?new Float32Array(t*2):null,o=c?new Uint8Array(t*3):null,l=0,u=0;for(let t of e.windows){let e=t.vertexStart*3;r.set(d.subarray(e,e+t.vertexCount*3),l*3),a&&s&&a.set(s.subarray(t.vertexStart*2,(t.vertexStart+t.vertexCount)*2),l*2),o&&c&&o.set(c.subarray(e,e+t.vertexCount*3),l*3);let n=t.vertexStart,p=t.vertexStart+t.vertexCount,m=l-t.vertexStart;for(let e=0;e<t.indexCount;e++){let r=f[t.indexStart+e];if(r<n||r>=p)throw Error(`Index ${r} outside vertex window [${n}, ${p})`);i[u+e]=r+m}l+=t.vertexCount,u+=t.indexCount}let p=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,m=c*l-o*d,h=o*u-s*l;p[t]+=f,p[t+1]+=m,p[t+2]+=h,p[n]+=f,p[n+1]+=m,p[n+2]+=h,p[a]+=f,p[a+1]+=m,p[a+2]+=h}for(let e=0;e<p.length;e+=3){let t=p[e],n=p[e+1],r=p[e+2],i=Math.sqrt(t*t+n*n+r*r)||1;p[e]=t/i,p[e+1]=n/i,p[e+2]=r/i}m.push({positions:r,normals:p,indices:i,uvs:a,colors:o})}return m}function pe(){return[`const assemble = ${fe.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 B;const V=new Map;let me=1;function he(){if(B!==void 0)return B;if(typeof Worker>`u`||typeof Blob>`u`||typeof URL>`u`||typeof URL.createObjectURL!=`function`)return B=null,null;try{let e=URL.createObjectURL(new Blob([pe()],{type:`text/javascript`})),t=new Worker(e);t.onmessage=e=>{let{id:t,geometries:n,error:r}=e.data,i=V.get(t);i&&(V.delete(t),n?i.resolve(n):i.reject(Error(r??`mesh assembly failed in worker`)))},t.onerror=()=>{for(let e of V.values())e.reject(Error(`mesh assembly worker crashed`));V.clear(),t.terminate(),B=null},B=t}catch{B=null}return B}function ge(e,t,n){return new Promise((r,i)=>{let a=me++;V.set(a,{resolve:r,reject:i}),e.postMessage({id:a,input:t},n)})}let H=1;function U(e){H=Math.max(1,e)}i(U);function _e(e,n){typeof document>`u`||new c.TextureLoader().load(n,t=>{t.colorSpace=c.SRGBColorSpace,t.anisotropy=H,e.map=t,e.needsUpdate=!0},void 0,e=>{t().warn(`Failed to load material texture ${n}:`,e)})}function W(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&&ve(o),e.map&&_e(o,e.map),o}function ve(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 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,mergedIndices:t.meshes.map(e=>e.originalIndex).sort((e,t)=>e-t),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);p&&(n.userData.sourceComponentId=p),v.push(n)}else{let n=fe(t,h,e.indices,_,e.uvs,e.colors);if(p)for(let e of n)e.userData.sourceComponentId=p;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);s&&(i.userData.sourceComponentId=s),_.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};
|
|
9
|
+
#endif`)}}function G(e,t){return new n(e,s.VALIDATION_ERROR,{context:t})}function K(e,t,n,r){for(let i of e){if(!Number.isInteger(i.materialId)||i.materialId<0||i.materialId>=t)throw G(`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 G(`Mesh metadata field "${n}" must be a non-negative integer.`,{meshName:e.name,field:n,value:r});if(e.vertexStart+e.vertexCount>n)throw G(`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 G(`Mesh index window exceeds the batch index buffer.`,{meshName:e.name,indexStart:e.indexStart,indexCount:e.indexCount,totalIndexCount:r})}}}function q(e,t){return G(`Index references a vertex outside its mesh's vertex window.`,{meshName:t.name,indexValue:e,vertexStart:t.vertexStart,vertexCount:t.vertexCount})}function ye(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 J(e){let t=new Map;for(let n of e.meshes){let e=n.layer??``,r=t.get(e);r||(r=[],t.set(e,r)),r.push(n)}return[...t.values()].map(t=>({materialId:e.materialId,meshes:t}))}function be(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 q(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(),Y(h,e,r)}function xe(e){let t=[],n=0;for(let r of e.meshes)t.push({trackingKey:r.id,name:r.name,layer:r.layer,metadata:r.metadata??{},indexStart:n,indexCount:r.indexCount}),n+=r.indexCount;return t}function Y(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??``,metadata:i?.metadata??{},members:xe(t)},r}function Se(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 q(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(X(g,s,e,r))}return o}function X(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??``,trackingKey:t.id,metadata:t.metadata??{}},i.castShadow=!0,i.receiveShadow=!0,i}async function Z(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 Ee(e.compressedData,{mergeByMaterial:r,debug:i,material:a,fallback:{materials:e.materials,groups:e.groups}});if(c)return c;let l=performance.now();return Te(R(e.compressedData),{mergeByMaterial:r,debug:i,material:a,parseTime:o,decodeTime:performance.now()-l,perfStart:s,blobBytes:i?De(e.compressedData):0,fallback:{materials:e.materials,groups:e.groups}})}async function Ce(e,t){let{mergeByMaterial:n=!0,debug:r=!1,material:i}=t??{},a=r?performance.now():0,o=await Ee(e,{mergeByMaterial:n,debug:r,material:i});if(o)return o;let s=performance.now(),c=R(e),l=performance.now()-s,u=e.byteLength;return Te(c,{mergeByMaterial:n,debug:r,material:i,parseTime:0,decodeTime:l,perfStart:a,blobBytes:u})}let Q=!1;function we(e,n){if(e||Q)return;let r=0;for(let e of n)r+=e.meshes.length;r<1e3||(Q=!0,t().warn(`Parsing ${r} meshes with mergeByMaterial: false — each becomes its own THREE object, and render cost scales with object count. Drop the option to merge by material (the default); per-object identity survives it via userData.members.`))}function Te(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=!!(e.flags&1);K(f,d.length,e.vertices.length/3,e.indices.length);let m=p?e.vertices:ye(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: ${p?`float32`:`int16 quantized`}`),t().debug(` Blob: ${(l/1024/1024).toFixed(2)} MB | Geometry on wire: ${(n/1024/1024).toFixed(2)} MB`)}we(r,f);let h=performance.now(),g=d.map(t=>W(t,{vertexColors:e.colors!=null,appearance:a})),_=[],v=r?f.flatMap(J):f;for(let t of v)if(r&&t.meshes.length>1){let n=be(t,m,e.indices,g,e.uvs,e.colors);_.push(n)}else{let n=Se(t,m,e.indices,g,e.uvs,e.colors);_.push(...n)}let y=performance.now()-h;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(_)}async function Ee(e,n){if(typeof Worker>`u`)return null;let r=z(e),i=r.planarByteSplit?r.indexData.length/(r.uint16Indices?2:4):r.indexData.length;if(i/3<5e4)return null;let a=he();if(!a)return null;let o=r.metadata.materials??n.fallback?.materials??[],s=r.metadata.groups??n.fallback?.groups??[];K(s,o.length,r.vertexCount,i);let l=e=>({vertexStart:e.vertexStart,vertexCount:e.vertexCount,indexStart:e.indexStart,indexCount:e.indexCount}),u=[],d=[],f=n.mergeByMaterial?s.flatMap(J):s;for(let e of f)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 p=r.vertexData.slice(),m=r.indexData.slice(),h=[p.buffer,m.buffer];r.uvs&&h.push(r.uvs.buffer),r.colors&&h.push(r.colors.buffer);let g;try{g=await ge(a,{vertexData:p,isFloat32:r.isFloat32,deltaEncoded:r.deltaEncoded,planarByteSplit:r.planarByteSplit,uint16Indices:r.uint16Indices,origin:r.origin,scale:r.scale,indexData:m,uvs:r.uvs,colors:r.colors,jobs:u},h)}catch(e){return t().warn(`Mesh assembly worker failed; falling back to main-thread parse.`,e),null}if(g.length!==u.length)return null;let _=o.map(e=>W(e,{vertexColors:r.colors!=null,appearance:n.material})),v=[];for(let e=0;e<g.length;e++){let t=g[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`?Y(r,n.group,_):X(r,n.meshMeta,n.group,_);v.push(i)}return n.debug&&t().debug(`Mesh batch assembled off-thread: ${v.length} meshes, ${i/3} triangles`),v}function De(e){return Math.floor(e.length*3/4)}const $={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 Oe(e){let t=e.split(`.`);return t.includes(`Display`)||t.includes(`DisplayBatch`)}const ke=new Set;async function Ae(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 Me(e,r,i?je(e.modelunits):1,c,s),a&&Ie(r,o),r}catch(e){throw Le(e,r),e}finally{s&&ze(n)}}function je(e){let n=$[e];return n===void 0?(ke.has(e)||(ke.add(e),t().warn(`Unknown Rhino model unit "${e}" — geometry will not be scaled (factor 1). Known units: ${Object.keys($).join(`, `)}.`)),1):n}async function Me(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 Ne(o,t,n,r,i)}}}async function Ne(e,n,r,i,a){for(let o of e){if(!Oe(o.type))continue;let e={debug:!1,...i,mergeByMaterial:i.mergeByMaterial??!0},s=Pe(o.data);if(!s){t().error(`Error parsing display batch envelope: invalid JSON`);continue}let c=await Z(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 Pe(e){return typeof e==`string`?Fe(e):e}function Fe(e){try{return JSON.parse(e)}catch{return}}function Ie(t,n){if(t.length===0)return;let i=e(t);r(t,i.min[n],n)}function Le(e,n){t().error(`An unexpected error occurred:`,e),Re(n)}function Re(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 ze(e){let n=performance.now()-e;t().info(`Time to process meshes:`,`${n.toFixed(2)}ms`)}export{$ as SCALE_FACTORS,Ae as getThreeObjectsFromComputeResponse,_ as meshPolicy,S as parseDisplayItems,Ce as parseMeshBatchBlob,Z as parseMeshBatchObject,U as setTextureAnisotropy};
|
|
10
10
|
//# sourceMappingURL=parse.js.map
|