@selvajs/visualization 1.6.0-beta.1 → 1.6.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/parse.d.cts CHANGED
@@ -1,13 +1,10 @@
1
- import { a as MaterialAppearanceOptions } from "./types-DjPelPRM.cjs";
1
+ import { a as MaterialAppearanceOptions } from "./types-P5PyfYYE.cjs";
2
2
  import * as THREE from "three";
3
- //#region src/parse/mesh-policy.d.ts
4
3
  /** Structurally, not nominally, typed as `@selvajs/solve/client`'s `MeshPolicy<THREE.Object3D>` — avoids a dependency on solve. */
5
4
  export declare const meshPolicy: {
6
5
  clone(meshes: THREE.Object3D[]): THREE.Object3D[];
7
6
  release(meshes: THREE.Object3D[]): void;
8
7
  };
9
- //#endregion
10
- //#region src/parse/webdisplay/response-envelope.d.ts
11
8
  /**
12
9
  * Declared structurally rather than imported from `@selvajs/compute` — this package converts
13
10
  * meshes, it doesn't need a Rhino.Compute client dependency to describe the shape a caller hands
@@ -29,8 +26,6 @@ interface GrasshopperComputeResponse {
29
26
  /** Rhino `UnitSystem` name driving unit scaling (see `SCALE_FACTORS`); unrecognized/absent scales 1. */
30
27
  modelunits: string;
31
28
  }
32
- //#endregion
33
- //#region src/parse/display-items/types.d.ts
34
29
  interface DisplayIdentity {
35
30
  /** The item's identity — the writer-minted opaque id, same contract as mesh ids. Distinct from `name` so renaming doesn't change identity. */
36
31
  id: string;
@@ -70,8 +65,6 @@ interface DisplayPoint extends DisplayItemBase {
70
65
  position: DisplayPosition;
71
66
  }
72
67
  type DisplayItem = DisplayCurve | DisplayPoint;
73
- //#endregion
74
- //#region src/parse/webdisplay/types.d.ts
75
68
  interface SerializableMaterial {
76
69
  color: string;
77
70
  metalness: number;
@@ -186,8 +179,6 @@ interface MeshExtractionOptions {
186
179
  groundAxis?: 'x' | 'y' | 'z';
187
180
  debug?: boolean;
188
181
  }
189
- //#endregion
190
- //#region src/parse/webdisplay/webdisplay-parser.d.ts
191
182
  /**
192
183
  * Metres per model unit, keyed by Rhino `UnitSystem` name (the `modelunits` string on the compute
193
184
  * response). Imperial factors are the exact international definitions. Units missing from this
@@ -204,8 +195,6 @@ export declare const SCALE_FACTORS: Record<string, number>;
204
195
  * @throws Rethrows unexpected errors after attempting to dispose any created meshes.
205
196
  */
206
197
  export declare function getThreeObjectsFromComputeResponse(data: GrasshopperComputeResponse, options?: MeshExtractionOptions): Promise<THREE.Object3D[]>;
207
- //#endregion
208
- //#region src/parse/webdisplay/batch-parser.d.ts
209
198
  interface ParseTelemetry {
210
199
  parseTime?: number;
211
200
  perfStart?: number;
@@ -231,16 +220,12 @@ telemetry?: ParseTelemetry): Promise<THREE.Mesh[]>;
231
220
  * @throws {VisualizationError} On a corrupt/truncated/unsupported mesh blob or malformed group metadata.
232
221
  */
233
222
  export declare function parseMeshBatchBlob(blob: ArrayBuffer | Uint8Array, options?: MeshBatchParsingOptions): Promise<THREE.Mesh[]>;
234
- //#endregion
235
- //#region src/parse/webdisplay/apply-texture.d.ts
236
223
  /**
237
224
  * Subscribed to the renderer's own report below, so no host wiring is needed; still exported for a
238
225
  * host embedding a foreign renderer that wants to set it directly. Applies to textures loaded from
239
226
  * here on — textures already decoded keep the value they were given.
240
227
  */
241
228
  export declare function setTextureAnisotropy(value: number): void;
242
- //#endregion
243
- //#region src/parse/display-items/display-items-parser.d.ts
244
229
  /**
245
230
  * Builds THREE objects for the batch's non-mesh items.
246
231
  *
@@ -249,6 +234,5 @@ export declare function setTextureAnisotropy(value: number): void;
249
234
  * unrenderable item is logged and skipped.
250
235
  */
251
236
  export declare function parseDisplayItems(items: DisplayItem[] | undefined): THREE.Object3D[];
252
- //#endregion
253
237
  export type { DisplayBatch, DisplayCurve, DisplayIdentity, DisplayItem, DisplayItemBase, DisplayPoint, DisplayPosition, MaterialGroup, MeshBatchParsingOptions, MeshExtractionOptions, MeshMetadata, SerializableMaterial };
254
238
  //# sourceMappingURL=parse.d.cts.map
package/dist/parse.d.ts CHANGED
@@ -1,13 +1,10 @@
1
- import { a as MaterialAppearanceOptions } from "./types-DjPelPRM.js";
1
+ import { a as MaterialAppearanceOptions } from "./types-P5PyfYYE.js";
2
2
  import * as THREE from "three";
3
- //#region src/parse/mesh-policy.d.ts
4
3
  /** Structurally, not nominally, typed as `@selvajs/solve/client`'s `MeshPolicy<THREE.Object3D>` — avoids a dependency on solve. */
5
4
  export declare const meshPolicy: {
6
5
  clone(meshes: THREE.Object3D[]): THREE.Object3D[];
7
6
  release(meshes: THREE.Object3D[]): void;
8
7
  };
9
- //#endregion
10
- //#region src/parse/webdisplay/response-envelope.d.ts
11
8
  /**
12
9
  * Declared structurally rather than imported from `@selvajs/compute` — this package converts
13
10
  * meshes, it doesn't need a Rhino.Compute client dependency to describe the shape a caller hands
@@ -29,8 +26,6 @@ interface GrasshopperComputeResponse {
29
26
  /** Rhino `UnitSystem` name driving unit scaling (see `SCALE_FACTORS`); unrecognized/absent scales 1. */
30
27
  modelunits: string;
31
28
  }
32
- //#endregion
33
- //#region src/parse/display-items/types.d.ts
34
29
  interface DisplayIdentity {
35
30
  /** The item's identity — the writer-minted opaque id, same contract as mesh ids. Distinct from `name` so renaming doesn't change identity. */
36
31
  id: string;
@@ -70,8 +65,6 @@ interface DisplayPoint extends DisplayItemBase {
70
65
  position: DisplayPosition;
71
66
  }
72
67
  type DisplayItem = DisplayCurve | DisplayPoint;
73
- //#endregion
74
- //#region src/parse/webdisplay/types.d.ts
75
68
  interface SerializableMaterial {
76
69
  color: string;
77
70
  metalness: number;
@@ -186,8 +179,6 @@ interface MeshExtractionOptions {
186
179
  groundAxis?: 'x' | 'y' | 'z';
187
180
  debug?: boolean;
188
181
  }
189
- //#endregion
190
- //#region src/parse/webdisplay/webdisplay-parser.d.ts
191
182
  /**
192
183
  * Metres per model unit, keyed by Rhino `UnitSystem` name (the `modelunits` string on the compute
193
184
  * response). Imperial factors are the exact international definitions. Units missing from this
@@ -204,8 +195,6 @@ export declare const SCALE_FACTORS: Record<string, number>;
204
195
  * @throws Rethrows unexpected errors after attempting to dispose any created meshes.
205
196
  */
206
197
  export declare function getThreeObjectsFromComputeResponse(data: GrasshopperComputeResponse, options?: MeshExtractionOptions): Promise<THREE.Object3D[]>;
207
- //#endregion
208
- //#region src/parse/webdisplay/batch-parser.d.ts
209
198
  interface ParseTelemetry {
210
199
  parseTime?: number;
211
200
  perfStart?: number;
@@ -231,16 +220,12 @@ telemetry?: ParseTelemetry): Promise<THREE.Mesh[]>;
231
220
  * @throws {VisualizationError} On a corrupt/truncated/unsupported mesh blob or malformed group metadata.
232
221
  */
233
222
  export declare function parseMeshBatchBlob(blob: ArrayBuffer | Uint8Array, options?: MeshBatchParsingOptions): Promise<THREE.Mesh[]>;
234
- //#endregion
235
- //#region src/parse/webdisplay/apply-texture.d.ts
236
223
  /**
237
224
  * Subscribed to the renderer's own report below, so no host wiring is needed; still exported for a
238
225
  * host embedding a foreign renderer that wants to set it directly. Applies to textures loaded from
239
226
  * here on — textures already decoded keep the value they were given.
240
227
  */
241
228
  export declare function setTextureAnisotropy(value: number): void;
242
- //#endregion
243
- //#region src/parse/display-items/display-items-parser.d.ts
244
229
  /**
245
230
  * Builds THREE objects for the batch's non-mesh items.
246
231
  *
@@ -249,6 +234,5 @@ export declare function setTextureAnisotropy(value: number): void;
249
234
  * unrenderable item is logged and skipped.
250
235
  */
251
236
  export declare function parseDisplayItems(items: DisplayItem[] | undefined): THREE.Object3D[];
252
- //#endregion
253
237
  export type { DisplayBatch, DisplayCurve, DisplayIdentity, DisplayItem, DisplayItemBase, DisplayPoint, DisplayPosition, MaterialGroup, MeshBatchParsingOptions, MeshExtractionOptions, MeshMetadata, SerializableMaterial };
254
238
  //# sourceMappingURL=parse.d.ts.map
package/dist/parse.js CHANGED
@@ -1,5 +1,5 @@
1
- import{a as e,g as t,h as n,i as r,l as i,n as a,o,p as s,t as c,u as l}from"./gpu-dispose-Dich0oW7.js";import*as u from"three";import{Line2 as d}from"three/addons/lines/Line2.js";import{LineGeometry as f}from"three/addons/lines/LineGeometry.js";import{LineMaterial as p}from"three/addons/lines/LineMaterial.js";import{inflateSync as m}from"fflate";function h(){let e=globalThis.Buffer;return typeof e==`function`?e:void 0}function g(e){let t=e.replace(/[\t\n\f\r ]/g,``);return t.length%4==0&&(t=t.replace(/={1,2}$/,``)),t.length%4==1?null:t}function _(e){let r=g(e),i=r===null?null:v(r);if(i===null)throw new t(`Invalid base64 input.`,n.ENCODING_ERROR,{context:{inputLength:e.length}});return i}function v(e){let r=h();if(r){if(r.byteLength(e,`utf8`)!==e.length||e.includes(`-`)||e.includes(`_`))return null;let t=r.from(e,`base64`);return t.length===Math.floor(e.length*3/4)?t.byteOffset===0&&t.buffer.byteLength===t.length?new Uint8Array(t.buffer,0,t.length):new Uint8Array(t):null}if(typeof globalThis.atob==`function`){let t;try{t=globalThis.atob(e)}catch{return null}let n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e)&255;return n}throw new t(`Base64 decoding not supported in this environment.`,n.INVALID_STATE,{context:{environmentInfo:`atob or Buffer not available`}})}function y(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 b(e){e.forEach(e=>c(e,{materials:!1}))}const x={clone:y,release:b};function S(e,t){let n=t??1;return{color:new u.Color(e??`#ffffff`),transparent:n<1,opacity:n}}function C(e){let t=w(e);if(!t)return null;let n=new f;n.setPositions(t);let r=S(e.color,e.opacity),i=new p({color:r.color}),a=i;a.linewidth=e.width??2,a.transparent=r.transparent,a.opacity=r.opacity;let o=new d(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 w(e){if(!e.points)throw new t(`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.`,n.INVALID_CONFIG,{context:{itemId:e.id,kind:e.kind}});return e.points.length>=6?e.points:null}function T(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 s().warn(`Skipping point display item with missing or non-finite position (id: ${String(e.id)}).`),null;let n=new u.BufferGeometry;n.setAttribute(`position`,new u.Float32BufferAttribute([t.X,t.Y,t.Z],3));let r=new u.PointsMaterial({...S(e.color,e.opacity),size:6,sizeAttenuation:!1}),i=new u.Points(n,r);return i.name=e.name,i.userData={source:`compute`,id:e.id,layer:e.layer,kind:`point`,metadata:e.metadata},i}function E(e){if(!e||e.length===0)return[];let t=[];for(let n of e)switch(n.kind){case`curve`:{let e=C(n);e&&t.push(e);break}case`point`:{let e=T(n);e&&t.push(e);break}default:{let e=n;s().warn(`Skipping unknown display item kind: ${String(e.kind)}`);break}}return t}const D=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;function O(e){return typeof e==`string`?_(e):e instanceof Uint8Array?e:new Uint8Array(e)}function k(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 z(`SLVZ header declares an implausible uncompressed length`,{uncompressedLen:n,deflatedBytes:r.byteLength,maxPlausibleLen:i});let a;try{a=m(r,{out:new Uint8Array(n+1)})}catch(e){throw z(`Failed to inflate SLVZ blob: ${e instanceof Error?e.message:String(e)}`,{uncompressedLen:n,deflatedBytes:r.byteLength})}if(a.byteLength!==n)throw z(`SLVZ payload inflated to a different size than the header declares.`,{declaredLen:n,actualLen:a.byteLength,deflatedBytes:r.byteLength});return a}function A(e){if(typeof TextDecoder<`u`)return new TextDecoder(`utf-8`).decode(e);if(globalThis.Buffer!==void 0)return globalThis.Buffer.from(e).toString(`utf-8`);throw new t(`No UTF-8 decoder available in this environment.`,n.INVALID_STATE)}function j(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 M(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 N(e,t,n){if(n===0)return new Uint16Array;if(t%2==0)return new Uint16Array(e,t,n);let r=new Uint8Array(n*2);return r.set(new Uint8Array(e,t,n*2)),new Uint16Array(r.buffer)}function ee(e,t,n){if(n===0)return new Uint32Array;if(t%4==0)return new Uint32Array(e,t,n);let r=new Uint8Array(n*4);return r.set(new Uint8Array(e,t,n*4)),new Uint32Array(r.buffer)}function P(e,t){if(e.length!==0&&!(e instanceof Uint16Array&&t>65535)){for(let n=0;n<e.length;n++)if(e[n]>=t)throw z(`Index out of range of vertexCount.`,{indexPosition:n,indexValue:e[n],vertexCount:t})}}function F(e){return e>>>1^-(e&1)}function I(e){let t=new Int16Array(e.length),n=0,r=0,i=0;for(let a=0;a<e.length;a+=3)n=n+F(e[a])<<16>>16,r=r+F(e[a+1])<<16>>16,i=i+F(e[a+2])<<16>>16,t[a]=n,t[a+1]=r,t[a+2]=i;return t}function te(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+F(e[t]|e[r*3+t]<<8)<<16>>16,a=a+F(e[r+t]|e[r*4+t]<<8)<<16>>16,o=o+F(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 L(e,t){let n=new Uint16Array(t),r=0;for(let i=0;i<t;i++)r=r+F(e[i]|e[t+i]<<8)&65535,n[i]=r;return n}function R(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+F(a)>>>0,n[i]=r}return n}function ne(e){let t=new Uint16Array(e.length),n=0;for(let r=0;r<e.length;r++)n=n+F(e[r])&65535,t[r]=n;return t}function re(e){let t=new Uint32Array(e.length),n=0;for(let r=0;r<e.length;r++)n=n+F(e[r])>>>0,t[r]=n;return t}function z(e,r){return new t(e,n.VALIDATION_ERROR,{context:r})}function ie(e,t,n,r,i,a=!1){if(n+36>e.byteLength)throw z(`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 z(`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=M(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+F(t[e]|t[i*2+e]<<8)&65535,o=o+F(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=N(e.buffer,m,d);h=new Float32Array(d);let n=0,r=0;for(let e=0;e<d;e+=2)i?(n=n+F(t[e])&65535,r=r+F(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 ae(e,t,n,r){let i=n*3;if(t+i>e.byteLength)throw z(`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+F(a[e])&255,c=c+F(a[e+1])&255,l=l+F(a[e+2])&255,o[e]=s,o[e+1]=c,o[e+2]=l;return o}function oe(e){return e.byteLength>=4&&new DataView(e.buffer,e.byteOffset,4).getUint32(0,!0)===1297501267}function se(e){let t=ce(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=k(o);break;case 1280590157:i=A(o);break;case 1381516628:a.push(o)}if(n===null)throw z(`SLVM container has no GEOM chunk.`,{chunkCount:t.length});if(r===null)throw z(`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 ce(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.byteLength<12||t.getUint32(0,!0)!==1297501267)throw z(`Not an SLVM container (bad magic).`,{byteLength:e.byteLength});let n=t.getUint32(4,!0);if(n!==3)throw z(`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 z(`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 z(`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 B(e){let t=0,n=0;for(;;){if(e.pos>=e.bytes.byteLength||n>28)throw z(`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 V(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[B(e)]??``;break;default:throw z(`Unknown SLVM string column mode: ${r}`,{pos:e.pos})}return i}function le(e){let t={bytes:e,pos:0},n=B(t),r=B(t),i=B(t),a=n+r+i,o=B(t),s=Array(o);for(let n=0;n<o;n++){let r=B(t);s[n]=A(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]=B(t),l[e]=B(t);for(let e=0;e<r;e++)B(t);let u=B(t),d=[];for(let e=0;e<u;e++)d.push({materialId:B(t),meshCount:B(t)});let f=V(t,a,s),p=V(t,a,s),m=Array(a),h=B(t);for(let e=0;e<h;e++){let e=s[B(t)]??``,n=B(t),r=Array(n),i=0;for(let e=0;e<n;e++)i+=B(t),r[e]=i;for(let i=0;i<n;i++){let n=s[B(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 z(`Failed to parse SLVM materials JSON: ${t instanceof Error?t.message:String(t)}`,{byteLength:e.length})}for(let e of n)for(let n of de){let r=e[n];if(r?.startsWith(`slvm:tex:`)){let i=t[Number(r.slice(9))];i!==void 0&&(e[n]=fe(i))}}return n}const de=[`map`,`roughnessMap`,`normalMap`];function fe(e){let t={bytes:e,pos:0},n=B(t),r=A(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 H(e){let t=U(e),n;n=t.isFloat32?t.vertexData:t.planarByteSplit?te(t.vertexData,t.vertexCount):t.deltaEncoded?I(t.vertexData):t.vertexData;let r;if(t.planarByteSplit){let e=t.indexData;r=t.uint16Indices?L(e,e.length/2):R(e,e.length/4)}else r=t.deltaEncoded?t.indexData instanceof Uint16Array?ne(t.indexData):re(t.indexData):t.indexData;return P(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 U(e){if(!D)throw new t(`SLVA parsing requires a little-endian host: the zero-copy geometry readers view the wire bytes in host byte order.`,n.ENVIRONMENT_ERROR);let r=O(e);if(oe(r)){let e=se(r),t=U(e.geometryBlob);return t.metadata=e.metadata,t}let i=k(r),a=new DataView(i.buffer,i.byteOffset,i.byteLength);if(i.byteLength<12)throw z(`Blob too small to contain SLVA header.`,{expectedBytes:12,availableBytes:i.byteLength});let o=0,s=a.getUint32(o,!0);if(o+=4,s!==1096174675)throw z(`Invalid SLVA magic: 0x${s.toString(16)}`,{expectedMagic:`0x41564c53`,actualMagic:`0x${s.toString(16)}`});let c=a.getUint32(o,!0);if(o+=4,c<1||c>4)throw z(`Unsupported SLVA version: ${c}`,{minSupportedVersion:1,maxSupportedVersion:4,actualVersion:c});let l=a.getUint32(o,!0);if(o+=4,o+l>i.byteLength)throw z(`Insufficient data to read metadata JSON.`,{expectedBytes:l,availableBytes:i.byteLength-o,offset:o});let u=i.subarray(o,o+l);o+=l;let d;try{d=l===0?{}:JSON.parse(A(u))}catch(e){throw z(`Failed to parse metadata JSON: ${e instanceof Error?e.message:String(e)}`,{metadataLen:l})}if(o+56>i.byteLength)throw z(`Insufficient data to read geometry header.`,{expectedBytes:56,availableBytes:i.byteLength-o,offset:o});let f=a.getUint32(o,!0);o+=4;let p=a.getFloat64(o,!0);o+=8;let m=a.getFloat64(o,!0);o+=8;let h=a.getFloat64(o,!0);o+=8;let g=a.getFloat64(o,!0);o+=8;let _=a.getFloat64(o,!0);o+=8;let v=a.getFloat64(o,!0);o+=8;let y=a.getUint32(o,!0);o+=4;let b=!!(f&1),x=!!(f&4),S=!!(f&32),C=y*3,w=C*(b?4:2);if(o+w>i.byteLength)throw z(`Insufficient data to read vertices.`,{expectedBytes:w,availableBytes:i.byteLength-o,offset:o,useFloat32:b,vertexCount:y});let T=i.byteOffset+o,E;if(E=b?M(i.buffer,T,C):S?i.subarray(o,o+w):x?N(i.buffer,T,C):j(i.buffer,T,C),o+=w,o+4>i.byteLength)throw z(`Insufficient data to read index count.`,{expectedBytes:4,availableBytes:i.byteLength-o,offset:o});let P=a.getUint32(o,!0);o+=4;let F=!!(f&2),I=P*(F?2:4);if(o+I>i.byteLength)throw z(`Insufficient data to read indices.`,{expectedBytes:I,availableBytes:i.byteLength-o,offset:o,indexCount:P,useUint16Indices:F});let te=S?i.subarray(o,o+I):F?N(i.buffer,i.byteOffset+o,P):ee(i.buffer,i.byteOffset+o,P);o+=I;let L=null;if(f&8){let e=ie(i,a,o,y,x,S);L=e.uvs,o=e.offset}let R=null;return f&16&&(R=ae(i,o,y,x)),{metadata:d,flags:f,vertexData:E,indexData:te,isFloat32:b,deltaEncoded:x,planarByteSplit:S,uint16Indices:F,vertexCount:y,origin:[p,m,h],scale:[g,_,v],uvs:L,colors:R}}function W(e,t,n){if(n.length===0)return!1;let r=e=>{let t=16;for(;t<e*2;)t*=2;return t},i=(n,i)=>{if(i<12||i%3!=0)return!1;let a=0;for(let r=0;r<i;r++){let i=t[n+r]*3;a=Math.max(a,Math.abs(e[i]),Math.abs(e[i+1]),Math.abs(e[i+2]))}if(!(a>0)||!Number.isFinite(a))return!1;let o=1/(2*2**(Math.floor(Math.log2(a))-23)),s=r(i),c=s-1,l=new Int32Array(s).fill(-1),u=new Int32Array(s),d=new Int32Array(s),f=new Int32Array(s),p=(e,t,n)=>{let r=Math.imul(e,2654435761)^Math.imul(t,2246822519)^Math.imul(n,3266489917);for(r=(r^r>>>15)&c;l[r]!==-1&&(u[r]!==e||d[r]!==t||f[r]!==n);)r=r+1&c;return r},m=(e,t)=>{let n=e-t;return n>.25?t+1:n<-.25?t-1:t},h=new Int32Array(i);for(let r=0;r<i;r++){let i=t[n+r],a=e[i*3]*o,s=e[i*3+1]*o,c=e[i*3+2]*o,g=Math.round(a),_=Math.round(s),v=Math.round(c),y=m(a,g),b=m(s,_),x=m(c,v),S=-1;for(let e=0;e<8&&S===-1;e++){if(e&1&&y===g||e&2&&b===_||e&4&&x===v)continue;let t=p(e&1?y:g,e&2?b:_,e&4?x:v);l[t]!==-1&&(S=l[t])}if(S===-1){let e=p(g,_,v);l[e]=i,u[e]=g,d[e]=_,f[e]=v,S=i}h[r]=S}let g=r(i),_=g-1,v=new Int32Array(g).fill(-1),y=new Int32Array(g),b=(e,t)=>{let n=(Math.imul(e,2654435761)^Math.imul(t,2246822519))&_;for(;v[n]!==-1&&(v[n]!==e||y[n]!==t);)n=n+1&_;return n},x=(e,t)=>{let n=b(e,t);return v[n]===-1&&(v[n]=e,y[n]=t,!0)},S=(e,t)=>v[b(e,t)]!==-1,C=0;for(let e=0;e<i;e+=3){let t=h[e],n=h[e+1],r=h[e+2];if(t!==n&&n!==r&&r!==t){if(!x(t,n)||!x(n,r)||!x(r,t))return!1;C++}}if(C<4)return!1;for(let e=0;e<i;e+=3){let t=h[e],n=h[e+1],r=h[e+2];if(t!==n&&n!==r&&r!==t&&(!S(n,t)||!S(r,n)||!S(t,r)))return!1}let w=h[0]*3,T=e[w],E=e[w+1],D=e[w+2],O=0;for(let t=0;t<i;t+=3){let n=h[t]*3,r=h[t+1]*3,i=h[t+2]*3,a=e[n]-T,o=e[n+1]-E,s=e[n+2]-D,c=e[r]-T,l=e[r+1]-E,u=e[r+2]-D,d=e[i]-T,f=e[i+1]-E,p=e[i+2]-D;O+=a*(l*p-u*f)+o*(u*d-c*p)+s*(c*f-l*d)}return O>0},a=0;for(let e of n){if(!i(a,e))return!1;a+=e}return!0}function G(e,t,n,r){let i=Math.cos(30*Math.PI/180),a=e.length/3,o=t.length,s=o/3;{let i=new Uint32Array(e.buffer,e.byteOffset,e.length),s=n?new Uint32Array(n.buffer,n.byteOffset,n.length):null,c=(e,t)=>e[t]===2147483648?0:e[t],l=(e,t)=>{for(let n=0;n<3;n++)if(c(i,e*3+n)!==c(i,t*3+n)||r&&r[e*3+n]!==r[t*3+n])return!1;return!s||s[e*2]===s[t*2]&&s[e*2+1]===s[t*2+1]},u=16;for(;u<a*2;)u*=2;let d=u-1,f=new Int32Array(u).fill(-1),p=new Uint32Array(a);for(let e=0;e<a;e++){let t=Math.imul(c(i,e*3),2654435761)^Math.imul(c(i,e*3+1),2246822519)^Math.imul(c(i,e*3+2),3266489917);for(t=(t^t>>>15)&d;f[t]!==-1&&!l(f[t],e);)t=t+1&d;f[t]===-1&&(f[t]=e),p[e]=f[t]}for(let e=0;e<o;e++)t[e]=p[t[e]]}let c=new Float32Array(s*3),l=new Float32Array(s);for(let n=0;n<s;n++){let r=t[n*3]*3,i=t[n*3+1]*3,a=t[n*3+2]*3,o=e[i]-e[r],s=e[i+1]-e[r+1],u=e[i+2]-e[r+2],d=e[a]-e[r],f=e[a+1]-e[r+1],p=e[a+2]-e[r+2],m=s*p-u*f,h=u*d-o*p,g=o*f-s*d,_=Math.sqrt(m*m+h*h+g*g);_!==0&&(c[n*3]=m/_,c[n*3+1]=h/_,c[n*3+2]=g/_,l[n]=_)}let u=new Uint32Array(a+1);for(let e=0;e<o;e++)u[t[e]+1]+=1;for(let e=0;e<a;e++)u[e+1]+=u[e];let d=new Uint32Array(o),f=u.slice(0,a);for(let e=0;e<o;e++){let n=t[e];d[f[n]]=e,f[n]+=1}let p=0;for(let e=0;e<a;e++)p=Math.max(p,u[e+1]-u[e]);let m=new Uint32Array(o),h=new Uint32Array(a),g=new Float32Array(Math.max(1,p)*3);for(let e=0;e<a;e++){let t=0;for(let n=u[e];n<u[e+1];n++){let e=d[n],r=Math.floor(e/3)*3,a=c[r],o=c[r+1],s=c[r+2],l=-1;if(a===0&&o===0&&s===0)l=0;else for(let e=0;e<t;e++)if(g[e*3]*a+g[e*3+1]*o+g[e*3+2]*s>=i){l=e;break}l===-1&&(l=t,g[t*3]=a,g[t*3+1]=o,g[t*3+2]=s,t++),m[e]=l}h[e]=Math.max(1,t)}let _=new Uint32Array(a+1);for(let e=0;e<a;e++)_[e+1]=_[e]+h[e]-1;let v=_[a],y=a+v,b=e,x=n,S=r;if(v>0){b=new Float32Array(y*3),b.set(e),x=n?new Float32Array(y*2):null,x&&n&&x.set(n),S=r?new Uint8Array(y*3):null,S&&r&&S.set(r);for(let t=0;t<a;t++)for(let i=1;i<h[t];i++){let o=a+_[t]+i-1;b[o*3]=e[t*3],b[o*3+1]=e[t*3+1],b[o*3+2]=e[t*3+2],x&&n&&(x[o*2]=n[t*2],x[o*2+1]=n[t*2+1]),S&&r&&(S[o*3]=r[t*3],S[o*3+1]=r[t*3+1],S[o*3+2]=r[t*3+2])}}let C=new Float32Array(y*3);for(let e=0;e<o;e++){let n=t[e],r=m[e],i=r===0?n:a+_[n]+r-1;t[e]=i;let o=Math.floor(e/3)*3,s=l[o/3];C[i*3]+=c[o]*s,C[i*3+1]+=c[o+1]*s,C[i*3+2]+=c[o+2]*s}for(let e=0;e<C.length;e+=3){let t=C[e],n=C[e+1],r=C[e+2],i=Math.sqrt(t*t+n*n+r*r)||1;C[e]=t/i,C[e+1]=n/i,C[e+2]=r/i}return{positions:b,normals:C,indices:t,uvs:x,colors:S}}function pe(e,t,n,r){let i=e.length/3,a=new Float32Array(i*3),o=new Float32Array(i*3);for(let t=0;t<n.length;t+=3){let i=n[t],s=n[t+1],c=n[t+2],l=e[s*3]-e[i*3],u=e[s*3+1]-e[i*3+1],d=e[s*3+2]-e[i*3+2],f=e[c*3]-e[i*3],p=e[c*3+1]-e[i*3+1],m=e[c*3+2]-e[i*3+2],h=u*m-d*p,g=d*f-l*m,_=l*p-u*f,v=Math.sqrt(h*h+g*g+_*_);if(v===0)continue;let y=(p*_-m*g)/v,b=(m*h-f*_)/v,x=(f*g-p*h)/v,S=(g*d-_*u)/v,C=(_*l-h*d)/v,w=(h*u-g*l)/v,T=r[s*2]-r[i*2],E=r[c*2]-r[i*2],D=r[s*2+1]-r[i*2+1],O=r[c*2+1]-r[i*2+1],k=T*y+E*S,A=T*b+E*C,j=T*x+E*w,M=D*y+O*S,N=D*b+O*C,ee=D*x+O*w;for(let e=0;e<3;e++){let r=n[t+e];a[r*3]+=k,a[r*3+1]+=A,a[r*3+2]+=j,o[r*3]+=M,o[r*3+1]+=N,o[r*3+2]+=ee}}let s=new Float32Array(i*4);for(let e=0;e<i;e++){let n=t[e*3],r=t[e*3+1],i=t[e*3+2],c=a[e*3]*n+a[e*3+1]*r+a[e*3+2]*i,l=a[e*3]-c*n,u=a[e*3+1]-c*r,d=a[e*3+2]-c*i,f=Math.sqrt(l*l+u*u+d*d);if(!(f>1e-12)){let e=+(Math.abs(n)<.9),t=1-e;l=t*i,u=-e*i,d=e*r-t*n,f=Math.sqrt(l*l+u*u+d*d)||1}l/=f,u/=f,d/=f;let p=r*d-i*u,m=i*l-n*d,h=n*u-r*l,g=p*o[e*3]+m*o[e*3+1]+h*o[e*3+2];s[e*4]=l,s[e*4+1]=u,s[e*4+2]=d,s[e*4+3]=g<0?-1:1}return s}function me(e,t){let n=W(e.positions,e.indices,t),r=G(e.positions,e.indices,e.uvs,e.colors),i=r.uvs?pe(r.positions,r.normals,r.indices,r.uvs):null;return{...r,closed:n,tangents:i}}function he(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}m.push({positions:r,indices:i,uvs:a,colors:o})}return m}function ge(){return[`const assemble = ${he.toString()};`,`const isClosedSolid = ${W.toString()};`,`const splitCreases = ${G.toString()};`,`const grainTangents = ${pe.toString()};`,`self.onmessage = (event) => {`,` const { id, input } = event.data;`,` try {`,` const geometries = assemble(input).map((g, i) => {`,` const counts = input.jobs[i].windows.map((w) => w.indexCount);`,` const closed = isClosedSolid(g.positions, g.indices, counts);`,` const c = splitCreases(g.positions, g.indices, g.uvs, g.colors);`,` const tangents = c.uvs ? grainTangents(c.positions, c.normals, c.indices, c.uvs) : null;`,` return { ...c, closed, tangents };`,` });`,` 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.tangents) transfer.push(g.tangents.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 K;const q=new Map;let _e=1;function ve(){if(K!==void 0)return K;if(typeof Worker>`u`||typeof Blob>`u`||typeof URL>`u`||typeof URL.createObjectURL!=`function`)return K=null,null;try{let e=URL.createObjectURL(new Blob([ge()],{type:`text/javascript`})),t=new Worker(e);t.onmessage=e=>{let{id:t,geometries:n,error:r}=e.data,i=q.get(t);i&&(q.delete(t),n?i.resolve(n):i.reject(Error(r??`mesh assembly failed in worker`)))},t.onerror=()=>{for(let e of q.values())e.reject(Error(`mesh assembly worker crashed`));q.clear(),t.terminate(),K=null},K=t}catch{K=null}return K}function ye(e,t,n){return new Promise((r,i)=>{let a=_e++;q.set(a,{resolve:r,reject:i}),e.postMessage({id:a,input:t},n)})}let be=1;function xe(e){be=Math.max(1,e)}a(xe);function J(e,t,n,r){typeof document>`u`||new u.TextureLoader().load(t,t=>{if(t.colorSpace=n===`map`?u.SRGBColorSpace:u.NoColorSpace,t.anisotropy=be,r){let e=t.image,n=e?.width&&e.height?e.height/e.width:1;t.wrapS=u.RepeatWrapping,t.wrapT=u.RepeatWrapping,t.repeat.set(1/r,1/(r*n))}e[n]=t,e.needsUpdate=!0},void 0,e=>{s().warn(`Failed to load material ${n} ${t}:`,e)})}const Se={brushed:{fibres:[{pitch:.04,length:[2,12],depth:.3},{pitch:.25,length:[5,40],depth:.18}],bands:[]},rolled:{fibres:[{pitch:.3,length:[80,600],depth:.07}],bands:[{width:20,length:1500,depth:.05}]}},Ce=.35,Y=e=>e.toFixed(4);function we(e,t){let n=Se[e];if(!n||!(t>0))return null;let r=n.fibres.map((e,t)=>`selvaFibres( vUv, footprint, ${Y(e.pitch)}, vec2( ${Y(e.length[0])}, ${Y(e.length[1])} ), ${Y(e.depth)}, ${Y(t*31+3)} )`).join(` + `)||`0.0`,i=n.bands.map(e=>`selvaBand( vUv, footprint, vec2( ${Y(e.length)}, ${Y(e.width)} ), ${Y(e.depth)} )`).join(` + `)||`0.0`;return{key:`finish:${e}:${Y(t)}`,patch:e=>{e.fragmentShader=e.fragmentShader.replace(`#include <common>`,`#include <common>
1
+ import{a as e,g as t,h as n,i as r,l as i,n as a,o,p as s,t as c,u as l}from"./gpu-dispose-Dr69ZlDk.js";import*as u from"three";import{Line2 as d}from"three/addons/lines/Line2.js";import{LineGeometry as f}from"three/addons/lines/LineGeometry.js";import{LineMaterial as p}from"three/addons/lines/LineMaterial.js";import{inflateSync as m}from"fflate";function h(){let e=globalThis.Buffer;return typeof e==`function`?e:void 0}function g(e){let t=e.replace(/[\t\n\f\r ]/g,``);return t.length%4==0&&(t=t.replace(/={1,2}$/,``)),t.length%4==1?null:t}function _(e){let r=g(e),i=r===null?null:v(r);if(i===null)throw new t(`Invalid base64 input.`,n.ENCODING_ERROR,{context:{inputLength:e.length}});return i}function v(e){let r=h();if(r){if(r.byteLength(e,`utf8`)!==e.length||e.includes(`-`)||e.includes(`_`))return null;let t=r.from(e,`base64`);return t.length===Math.floor(e.length*3/4)?t.byteOffset===0&&t.buffer.byteLength===t.length?new Uint8Array(t.buffer,0,t.length):new Uint8Array(t):null}if(typeof globalThis.atob==`function`){let t;try{t=globalThis.atob(e)}catch{return null}let n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e)&255;return n}throw new t(`Base64 decoding not supported in this environment.`,n.INVALID_STATE,{context:{environmentInfo:`atob or Buffer not available`}})}function y(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 b(e){e.forEach(e=>c(e,{materials:!1}))}const x={clone:y,release:b};function S(e,t){let n=t??1;return{color:new u.Color(e??`#ffffff`),transparent:n<1,opacity:n}}function C(e){let t=w(e);if(!t)return null;let n=new f;n.setPositions(t);let r=S(e.color,e.opacity),i=new p({color:r.color}),a=i;a.linewidth=e.width??2,a.transparent=r.transparent,a.opacity=r.opacity;let o=new d(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 w(e){if(!e.points)throw new t(`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.`,n.INVALID_CONFIG,{context:{itemId:e.id,kind:e.kind}});return e.points.length>=6?e.points:null}function T(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 s().warn(`Skipping point display item with missing or non-finite position (id: ${String(e.id)}).`),null;let n=new u.BufferGeometry;n.setAttribute(`position`,new u.Float32BufferAttribute([t.X,t.Y,t.Z],3));let r=new u.PointsMaterial({...S(e.color,e.opacity),size:6,sizeAttenuation:!1}),i=new u.Points(n,r);return i.name=e.name,i.userData={source:`compute`,id:e.id,layer:e.layer,kind:`point`,metadata:e.metadata},i}function E(e){if(!e||e.length===0)return[];let t=[];for(let n of e)switch(n.kind){case`curve`:{let e=C(n);e&&t.push(e);break}case`point`:{let e=T(n);e&&t.push(e);break}default:{let e=n;s().warn(`Skipping unknown display item kind: ${String(e.kind)}`);break}}return t}const D=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;function O(e){return typeof e==`string`?_(e):e instanceof Uint8Array?e:new Uint8Array(e)}function k(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 z(`SLVZ header declares an implausible uncompressed length`,{uncompressedLen:n,deflatedBytes:r.byteLength,maxPlausibleLen:i});let a;try{a=m(r,{out:new Uint8Array(n+1)})}catch(e){throw z(`Failed to inflate SLVZ blob: ${e instanceof Error?e.message:String(e)}`,{uncompressedLen:n,deflatedBytes:r.byteLength})}if(a.byteLength!==n)throw z(`SLVZ payload inflated to a different size than the header declares.`,{declaredLen:n,actualLen:a.byteLength,deflatedBytes:r.byteLength});return a}function A(e){if(typeof TextDecoder<`u`)return new TextDecoder(`utf-8`).decode(e);if(globalThis.Buffer!==void 0)return globalThis.Buffer.from(e).toString(`utf-8`);throw new t(`No UTF-8 decoder available in this environment.`,n.INVALID_STATE)}function j(e,t,n){if(n===0)return/* @__PURE__ */ 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 M(e,t,n){if(n===0)return/* @__PURE__ */ 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 N(e,t,n){if(n===0)return/* @__PURE__ */ new Uint16Array;if(t%2==0)return new Uint16Array(e,t,n);let r=new Uint8Array(n*2);return r.set(new Uint8Array(e,t,n*2)),new Uint16Array(r.buffer)}function ee(e,t,n){if(n===0)return/* @__PURE__ */ 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 P(e,t){if(e.length!==0&&!(e instanceof Uint16Array&&t>65535)){for(let n=0;n<e.length;n++)if(e[n]>=t)throw z(`Index out of range of vertexCount.`,{indexPosition:n,indexValue:e[n],vertexCount:t})}}function F(e){return e>>>1^-(e&1)}function I(e){let t=new Int16Array(e.length),n=0,r=0,i=0;for(let a=0;a<e.length;a+=3)n=n+F(e[a])<<16>>16,r=r+F(e[a+1])<<16>>16,i=i+F(e[a+2])<<16>>16,t[a]=n,t[a+1]=r,t[a+2]=i;return t}function te(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+F(e[t]|e[r*3+t]<<8)<<16>>16,a=a+F(e[r+t]|e[r*4+t]<<8)<<16>>16,o=o+F(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 L(e,t){let n=new Uint16Array(t),r=0;for(let i=0;i<t;i++)r=r+F(e[i]|e[t+i]<<8)&65535,n[i]=r;return n}function R(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+F(a)>>>0,n[i]=r}return n}function ne(e){let t=new Uint16Array(e.length),n=0;for(let r=0;r<e.length;r++)n=n+F(e[r])&65535,t[r]=n;return t}function re(e){let t=new Uint32Array(e.length),n=0;for(let r=0;r<e.length;r++)n=n+F(e[r])>>>0,t[r]=n;return t}function z(e,r){return new t(e,n.VALIDATION_ERROR,{context:r})}function ie(e,t,n,r,i,a=!1){if(n+36>e.byteLength)throw z(`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 z(`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=M(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+F(t[e]|t[i*2+e]<<8)&65535,o=o+F(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=N(e.buffer,m,d);h=new Float32Array(d);let n=0,r=0;for(let e=0;e<d;e+=2)i?(n=n+F(t[e])&65535,r=r+F(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 ae(e,t,n,r){let i=n*3;if(t+i>e.byteLength)throw z(`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+F(a[e])&255,c=c+F(a[e+1])&255,l=l+F(a[e+2])&255,o[e]=s,o[e+1]=c,o[e+2]=l;return o}function oe(e){return e.byteLength>=4&&new DataView(e.buffer,e.byteOffset,4).getUint32(0,!0)===1297501267}function se(e){let t=ce(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=k(o);break;case 1280590157:i=A(o);break;case 1381516628:a.push(o)}if(n===null)throw z(`SLVM container has no GEOM chunk.`,{chunkCount:t.length});if(r===null)throw z(`SLVM container has no TABL chunk.`,{chunkCount:t.length});let{groups:o}=ue(r),s=de(i,a);return{geometryBlob:n,metadata:{materials:s,groups:o}}}function ce(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.byteLength<12||t.getUint32(0,!0)!==1297501267)throw z(`Not an SLVM container (bad magic).`,{byteLength:e.byteLength});let n=t.getUint32(4,!0);if(n!==3)throw z(`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 z(`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 z(`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 B(e){let t=0,n=0;for(;;){if(e.pos>=e.bytes.byteLength||n>28)throw z(`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 le(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[B(e)]??``;break;default:throw z(`Unknown SLVM string column mode: ${r}`,{pos:e.pos})}return i}function ue(e){let t={bytes:e,pos:0},n=B(t),r=B(t),i=B(t),a=n+r+i,o=B(t),s=Array(o);for(let n=0;n<o;n++){let r=B(t);s[n]=A(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]=B(t),l[e]=B(t);for(let e=0;e<r;e++)B(t);let u=B(t),d=[];for(let e=0;e<u;e++)d.push({materialId:B(t),meshCount:B(t)});let f=le(t,a,s),p=le(t,a,s),m=Array(a),h=B(t);for(let e=0;e<h;e++){let e=s[B(t)]??``,n=B(t),r=Array(n),i=0;for(let e=0;e<n;e++)i+=B(t),r[e]=i;for(let i=0;i<n;i++){let n=s[B(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 de(e,t){if(e===null)return[];let n;try{n=JSON.parse(e).materials??[]}catch(t){throw z(`Failed to parse SLVM materials JSON: ${t instanceof Error?t.message:String(t)}`,{byteLength:e.length})}for(let e of n)for(let n of fe){let r=e[n];if(r?.startsWith(`slvm:tex:`)){let i=t[Number(r.slice(9))];i!==void 0&&(e[n]=pe(i))}}return n}const fe=[`map`,`roughnessMap`,`normalMap`];function pe(e){let t={bytes:e,pos:0},n=B(t),r=A(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 V(e){let t;t=e.isFloat32?e.vertexData:e.planarByteSplit?te(e.vertexData,e.vertexCount):e.deltaEncoded?I(e.vertexData):e.vertexData;let n;if(e.planarByteSplit){let t=e.indexData;n=e.uint16Indices?L(t,t.length/2):R(t,t.length/4)}else n=e.deltaEncoded?e.indexData instanceof Uint16Array?ne(e.indexData):re(e.indexData):e.indexData;return P(n,e.vertexCount),{metadata:e.metadata,flags:e.flags,vertices:t,indices:n,origin:e.origin,scale:e.scale,uvs:e.uvs,colors:e.colors}}function H(e){if(!D)throw new t(`SLVA parsing requires a little-endian host: the zero-copy geometry readers view the wire bytes in host byte order.`,n.ENVIRONMENT_ERROR);let r=O(e);if(oe(r)){let e=se(r),t=H(e.geometryBlob);return t.metadata=e.metadata,t}let i=k(r),a=new DataView(i.buffer,i.byteOffset,i.byteLength);if(i.byteLength<12)throw z(`Blob too small to contain SLVA header.`,{expectedBytes:12,availableBytes:i.byteLength});let o=0,s=a.getUint32(o,!0);if(o+=4,s!==1096174675)throw z(`Invalid SLVA magic: 0x${s.toString(16)}`,{expectedMagic:`0x41564c53`,actualMagic:`0x${s.toString(16)}`});let c=a.getUint32(o,!0);if(o+=4,c<1||c>4)throw z(`Unsupported SLVA version: ${c}`,{minSupportedVersion:1,maxSupportedVersion:4,actualVersion:c});let l=a.getUint32(o,!0);if(o+=4,o+l>i.byteLength)throw z(`Insufficient data to read metadata JSON.`,{expectedBytes:l,availableBytes:i.byteLength-o,offset:o});let u=i.subarray(o,o+l);o+=l;let d;try{d=l===0?{}:JSON.parse(A(u))}catch(e){throw z(`Failed to parse metadata JSON: ${e instanceof Error?e.message:String(e)}`,{metadataLen:l})}if(o+56>i.byteLength)throw z(`Insufficient data to read geometry header.`,{expectedBytes:56,availableBytes:i.byteLength-o,offset:o});let f=a.getUint32(o,!0);o+=4;let p=a.getFloat64(o,!0);o+=8;let m=a.getFloat64(o,!0);o+=8;let h=a.getFloat64(o,!0);o+=8;let g=a.getFloat64(o,!0);o+=8;let _=a.getFloat64(o,!0);o+=8;let v=a.getFloat64(o,!0);o+=8;let y=a.getUint32(o,!0);o+=4;let b=!!(f&1),x=!!(f&4),S=!!(f&32),C=y*3,w=C*(b?4:2);if(o+w>i.byteLength)throw z(`Insufficient data to read vertices.`,{expectedBytes:w,availableBytes:i.byteLength-o,offset:o,useFloat32:b,vertexCount:y});let T=i.byteOffset+o,E;if(E=b?M(i.buffer,T,C):S?i.subarray(o,o+w):x?N(i.buffer,T,C):j(i.buffer,T,C),o+=w,o+4>i.byteLength)throw z(`Insufficient data to read index count.`,{expectedBytes:4,availableBytes:i.byteLength-o,offset:o});let P=a.getUint32(o,!0);o+=4;let F=!!(f&2),I=P*(F?2:4);if(o+I>i.byteLength)throw z(`Insufficient data to read indices.`,{expectedBytes:I,availableBytes:i.byteLength-o,offset:o,indexCount:P,useUint16Indices:F});let te=S?i.subarray(o,o+I):F?N(i.buffer,i.byteOffset+o,P):ee(i.buffer,i.byteOffset+o,P);o+=I;let L=null;if(f&8){let e=ie(i,a,o,y,x,S);L=e.uvs,o=e.offset}let R=null;return f&16&&(R=ae(i,o,y,x)),{metadata:d,flags:f,vertexData:E,indexData:te,isFloat32:b,deltaEncoded:x,planarByteSplit:S,uint16Indices:F,vertexCount:y,origin:[p,m,h],scale:[g,_,v],uvs:L,colors:R}}function U(e,t,n){if(n.length===0)return!1;let r=e=>{let t=16;for(;t<e*2;)t*=2;return t},i=e.length/3,a=new Int32Array(i),o=new Int32Array(i),s=(n,i,s)=>{if(s<12||s%3!=0)return!1;let c=2*n+1,l=c+1,u=0,d=0;for(let n=0;n<s;n++){let r=t[i+n];a[r]!==c&&(a[r]=c,d++,u=Math.max(u,Math.abs(e[r*3]),Math.abs(e[r*3+1]),Math.abs(e[r*3+2])))}if(!(u>0)||!Number.isFinite(u))return!1;let f=1/(2*2**(Math.floor(Math.log2(u))-23)),p=r(d),m=p-1,h=new Int32Array(p).fill(-1),g=new Int32Array(p),_=new Int32Array(p),v=new Int32Array(p),y=(e,t,n)=>{let r=Math.imul(e,2654435761)^Math.imul(t,2246822519)^Math.imul(n,3266489917);for(r=(r^r>>>15)&m;h[r]!==-1&&(g[r]!==e||_[r]!==t||v[r]!==n);)r=r+1&m;return r},b=(e,t)=>{let n=e-t;return n>.25?t+1:n<-.25?t-1:t},x=new Int32Array(s),S=new Int32Array(d),C=0;for(let n=0;n<s;n++){let r=t[i+n];if(a[r]===l){x[n]=o[r];continue}let s=e[r*3]*f,c=e[r*3+1]*f,u=e[r*3+2]*f,d=Math.round(s),p=Math.round(c),m=Math.round(u),w=b(s,d),T=b(c,p),E=b(u,m),D=-1;for(let e=0;e<8&&D===-1;e++){if(e&1&&w===d||e&2&&T===p||e&4&&E===m)continue;let t=y(e&1?w:d,e&2?T:p,e&4?E:m);h[t]!==-1&&(D=h[t])}if(D===-1){let e=y(d,p,m);D=C++,h[e]=D,g[e]=d,_[e]=p,v[e]=m,S[D]=r}a[r]=l,o[r]=D,x[n]=D}let w=new Int32Array(C+1),T=0;for(let e=0;e<s;e+=3){let t=x[e],n=x[e+1],r=x[e+2];t!==n&&n!==r&&r!==t&&(w[t+1]+=1,w[n+1]+=1,w[r+1]+=1,T++)}if(T<4)return!1;for(let e=0;e<C;e++)w[e+1]+=w[e];let E=new Int32Array(w[C]),D=w.slice(0,C);for(let e=0;e<s;e+=3){let t=x[e],n=x[e+1],r=x[e+2];t!==n&&n!==r&&r!==t&&(E[D[t]]=n,D[t]+=1,E[D[n]]=r,D[n]+=1,E[D[r]]=t,D[r]+=1)}for(let e=0;e<C;e++){let t=w[e],n=w[e+1];for(let r=t;r<n;r++){let n=E[r];for(let e=t;e<r;e++)if(E[e]===n)return!1;let i=!1;for(let t=w[n],r=w[n+1];t<r&&!i;t++)i=E[t]===e;if(!i)return!1}}let O=S[x[0]]*3,k=e[O],A=e[O+1],j=e[O+2],M=0;for(let t=0;t<s;t+=3){let n=S[x[t]]*3,r=S[x[t+1]]*3,i=S[x[t+2]]*3,a=e[n]-k,o=e[n+1]-A,s=e[n+2]-j,c=e[r]-k,l=e[r+1]-A,u=e[r+2]-j,d=e[i]-k,f=e[i+1]-A,p=e[i+2]-j;M+=a*(l*p-u*f)+o*(u*d-c*p)+s*(c*f-l*d)}return M>0},c=0;for(let e=0;e<n.length;e++){let t=n[e];if(!s(e,c,t))return!1;c+=t}return!0}function W(e,t,n,r){let i=Math.cos(30*Math.PI/180),a=e.length/3,o=t.length,s=o/3;{let i=new Uint32Array(e.buffer,e.byteOffset,e.length),s=n?new Uint32Array(n.buffer,n.byteOffset,n.length):null,c=(e,t)=>e[t]===2147483648?0:e[t],l=(e,t)=>{for(let n=0;n<3;n++)if(c(i,e*3+n)!==c(i,t*3+n)||r&&r[e*3+n]!==r[t*3+n])return!1;return!s||s[e*2]===s[t*2]&&s[e*2+1]===s[t*2+1]},u=16;for(;u<a*2;)u*=2;let d=u-1,f=new Int32Array(u).fill(-1),p=new Uint32Array(a);for(let e=0;e<a;e++){let t=Math.imul(c(i,e*3),2654435761)^Math.imul(c(i,e*3+1),2246822519)^Math.imul(c(i,e*3+2),3266489917);for(t=(t^t>>>15)&d;f[t]!==-1&&!l(f[t],e);)t=t+1&d;f[t]===-1&&(f[t]=e),p[e]=f[t]}for(let e=0;e<o;e++)t[e]=p[t[e]]}let c=new Float32Array(s*3),l=new Float32Array(s);for(let n=0;n<s;n++){let r=t[n*3]*3,i=t[n*3+1]*3,a=t[n*3+2]*3,o=e[i]-e[r],s=e[i+1]-e[r+1],u=e[i+2]-e[r+2],d=e[a]-e[r],f=e[a+1]-e[r+1],p=e[a+2]-e[r+2],m=s*p-u*f,h=u*d-o*p,g=o*f-s*d,_=Math.sqrt(m*m+h*h+g*g);_!==0&&(c[n*3]=m/_,c[n*3+1]=h/_,c[n*3+2]=g/_,l[n]=_)}let u=new Uint32Array(a+1);for(let e=0;e<o;e++)u[t[e]+1]+=1;for(let e=0;e<a;e++)u[e+1]+=u[e];let d=new Uint32Array(o),f=u.slice(0,a);for(let e=0;e<o;e++){let n=t[e];d[f[n]]=e,f[n]+=1}let p=0;for(let e=0;e<a;e++)p=Math.max(p,u[e+1]-u[e]);let m=new Uint32Array(o),h=new Uint32Array(a),g=new Float32Array(Math.max(1,p)*3);for(let e=0;e<a;e++){let t=0;for(let n=u[e];n<u[e+1];n++){let e=d[n],r=Math.floor(e/3)*3,a=c[r],o=c[r+1],s=c[r+2],l=-1;if(a===0&&o===0&&s===0)l=0;else for(let e=0;e<t;e++)if(g[e*3]*a+g[e*3+1]*o+g[e*3+2]*s>=i){l=e;break}l===-1&&(l=t,g[t*3]=a,g[t*3+1]=o,g[t*3+2]=s,t++),m[e]=l}h[e]=Math.max(1,t)}let _=new Uint32Array(a+1);for(let e=0;e<a;e++)_[e+1]=_[e]+h[e]-1;let v=_[a],y=a+v,b=e,x=n,S=r;if(v>0){b=new Float32Array(y*3),b.set(e),x=n?new Float32Array(y*2):null,x&&n&&x.set(n),S=r?new Uint8Array(y*3):null,S&&r&&S.set(r);for(let t=0;t<a;t++)for(let i=1;i<h[t];i++){let o=a+_[t]+i-1;b[o*3]=e[t*3],b[o*3+1]=e[t*3+1],b[o*3+2]=e[t*3+2],x&&n&&(x[o*2]=n[t*2],x[o*2+1]=n[t*2+1]),S&&r&&(S[o*3]=r[t*3],S[o*3+1]=r[t*3+1],S[o*3+2]=r[t*3+2])}}let C=new Float32Array(y*3);for(let e=0;e<o;e++){let n=t[e],r=m[e],i=r===0?n:a+_[n]+r-1;t[e]=i;let o=Math.floor(e/3)*3,s=l[o/3];C[i*3]+=c[o]*s,C[i*3+1]+=c[o+1]*s,C[i*3+2]+=c[o+2]*s}for(let e=0;e<C.length;e+=3){let t=C[e],n=C[e+1],r=C[e+2],i=Math.sqrt(t*t+n*n+r*r)||1;C[e]=t/i,C[e+1]=n/i,C[e+2]=r/i}return{positions:b,normals:C,indices:t,uvs:x,colors:S}}function me(e,t,n,r){let i=e.length/3,a=new Float32Array(i*3),o=new Float32Array(i*3);for(let t=0;t<n.length;t+=3){let i=n[t],s=n[t+1],c=n[t+2],l=e[s*3]-e[i*3],u=e[s*3+1]-e[i*3+1],d=e[s*3+2]-e[i*3+2],f=e[c*3]-e[i*3],p=e[c*3+1]-e[i*3+1],m=e[c*3+2]-e[i*3+2],h=u*m-d*p,g=d*f-l*m,_=l*p-u*f,v=Math.sqrt(h*h+g*g+_*_);if(v===0)continue;let y=(p*_-m*g)/v,b=(m*h-f*_)/v,x=(f*g-p*h)/v,S=(g*d-_*u)/v,C=(_*l-h*d)/v,w=(h*u-g*l)/v,T=r[s*2]-r[i*2],E=r[c*2]-r[i*2],D=r[s*2+1]-r[i*2+1],O=r[c*2+1]-r[i*2+1],k=T*y+E*S,A=T*b+E*C,j=T*x+E*w,M=D*y+O*S,N=D*b+O*C,ee=D*x+O*w;for(let e=0;e<3;e++){let r=n[t+e];a[r*3]+=k,a[r*3+1]+=A,a[r*3+2]+=j,o[r*3]+=M,o[r*3+1]+=N,o[r*3+2]+=ee}}let s=new Float32Array(i*4);for(let e=0;e<i;e++){let n=t[e*3],r=t[e*3+1],i=t[e*3+2],c=a[e*3]*n+a[e*3+1]*r+a[e*3+2]*i,l=a[e*3]-c*n,u=a[e*3+1]-c*r,d=a[e*3+2]-c*i,f=Math.sqrt(l*l+u*u+d*d);if(!(f>1e-12)){let e=+(Math.abs(n)<.9),t=1-e;l=t*i,u=-e*i,d=e*r-t*n,f=Math.sqrt(l*l+u*u+d*d)||1}l/=f,u/=f,d/=f;let p=r*d-i*u,m=i*l-n*d,h=n*u-r*l,g=p*o[e*3]+m*o[e*3+1]+h*o[e*3+2];s[e*4]=l,s[e*4+1]=u,s[e*4+2]=d,s[e*4+3]=g<0?-1:1}return s}function he(e,t){let n=U(e.positions,e.indices,t),r=W(e.positions,e.indices,e.uvs,e.colors),i=r.uvs?me(r.positions,r.normals,r.indices,r.uvs):null;return{...r,closed:n,tangents:i}}function ge(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}m.push({positions:r,indices:i,uvs:a,colors:o})}return m}function _e(){return[`const assemble = ${ge.toString()};`,`const isClosedSolid = ${U.toString()};`,`const splitCreases = ${W.toString()};`,`const grainTangents = ${me.toString()};`,`self.onmessage = (event) => {`,` const { id, input } = event.data;`,` try {`,` const geometries = assemble(input).map((g, i) => {`,` const counts = input.jobs[i].windows.map((w) => w.indexCount);`,` const closed = isClosedSolid(g.positions, g.indices, counts);`,` const c = splitCreases(g.positions, g.indices, g.uvs, g.colors);`,` const tangents = c.uvs ? grainTangents(c.positions, c.normals, c.indices, c.uvs) : null;`,` return { ...c, closed, tangents };`,` });`,` 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.tangents) transfer.push(g.tangents.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 G;const K=/* @__PURE__ */ new Map;let ve=1;function ye(){if(G!==void 0)return G;if(typeof Worker>`u`||typeof Blob>`u`||typeof URL>`u`||typeof URL.createObjectURL!=`function`)return G=null,null;try{let e=URL.createObjectURL(new Blob([_e()],{type:`text/javascript`})),t=new Worker(e);t.onmessage=e=>{let{id:t,geometries:n,error:r}=e.data,i=K.get(t);i&&(K.delete(t),n?i.resolve(n):i.reject(Error(r??`mesh assembly failed in worker`)))},t.onerror=()=>{for(let e of K.values())e.reject(/* @__PURE__ */ Error(`mesh assembly worker crashed`));K.clear(),t.terminate(),G=null},G=t}catch{G=null}return G}function be(e,t,n){return new Promise((r,i)=>{let a=ve++;K.set(a,{resolve:r,reject:i}),e.postMessage({id:a,input:t},n)})}let xe=1;function Se(e){xe=Math.max(1,e)}a(Se);function q(e,t,n,r){typeof document<`u`&&new u.TextureLoader().load(t,t=>{if(t.colorSpace=n===`map`?u.SRGBColorSpace:u.NoColorSpace,t.anisotropy=xe,r){let e=t.image,n=e?.width&&e.height?e.height/e.width:1;t.wrapS=u.RepeatWrapping,t.wrapT=u.RepeatWrapping,t.repeat.set(1/r,1/(r*n))}e[n]=t,e.needsUpdate=!0},void 0,e=>{s().warn(`Failed to load material ${n} ${t}:`,e)})}const Ce={brushed:{fibres:[{pitch:.04,length:[2,12],depth:.3},{pitch:.25,length:[5,40],depth:.18}],bands:[]},rolled:{fibres:[{pitch:.3,length:[80,600],depth:.07}],bands:[{width:20,length:1500,depth:.05}]}},we=.35,J=e=>e.toFixed(4);function Te(e,t){let n=Ce[e];if(!n||!(t>0))return null;let r=n.fibres.map((e,t)=>`selvaFibres( vUv, footprint, ${J(e.pitch)}, vec2( ${J(e.length[0])}, ${J(e.length[1])} ), ${J(e.depth)}, ${J(t*31+3)} )`).join(` + `)||`0.0`,i=n.bands.map(e=>`selvaBand( vUv, footprint, vec2( ${J(e.length)}, ${J(e.width)} ), ${J(e.depth)} )`).join(` + `)||`0.0`;return{key:`finish:${e}:${J(t)}`,patch:e=>{e.fragmentShader=e.fragmentShader.replace(`#include <common>`,`#include <common>
3
3
  // Hash without sine: sin() loses precision on the large arguments mm UVs produce.
4
4
  float selvaHash( vec2 p ) {
5
5
  vec3 p3 = fract( vec3( p.xyx ) * 0.1031 );
@@ -34,9 +34,9 @@ import{a as e,g as t,h as n,i as r,l as i,n as a,o,p as s,t as c,u as l}from"./g
34
34
  float selvaFibres( vec2 uv, float footprint, float pitch, vec2 len, float depth, float seed ) {
35
35
  float level = clamp( log2( footprint / pitch ) + 0.5, 0.0, 14.0 );
36
36
  float l0 = floor( level );
37
- float a = selvaFibreRow( uv, pitch * exp2( l0 ), len, seed + 7.0 * l0 ) * exp2( -${Y(Ce)} * l0 );
37
+ float a = selvaFibreRow( uv, pitch * exp2( l0 ), len, seed + 7.0 * l0 ) * exp2( -${J(we)} * l0 );
38
38
  float b = selvaFibreRow( uv, pitch * exp2( l0 + 1.0 ), len, seed + 7.0 * l0 + 7.0 )
39
- * exp2( -${Y(Ce)} * ( l0 + 1.0 ) );
39
+ * exp2( -${J(we)} * ( l0 + 1.0 ) );
40
40
  return depth * mix( a, b, level - l0 );
41
41
  }
42
42
  float selvaBand( vec2 uv, float footprint, vec2 size, float depth ) {
@@ -44,8 +44,8 @@ import{a as e,g as t,h as n,i as r,l as i,n as a,o,p as s,t as c,u as l}from"./g
44
44
  return depth * fade * ( selvaNoise( uv / size ) * 2.0 - 1.0 );
45
45
  }`).replace(`#include <color_fragment>`,`#include <color_fragment>
46
46
  float footprint = max( fwidth( vUv.y ), 1e-6 );
47
- float selvaFibre = ( ${r} ) * ${Y(t)};
48
- float selvaStreak = selvaFibre + ( ${i} ) * ${Y(t)};
47
+ float selvaFibre = ( ${r} ) * ${J(t)};
48
+ float selvaStreak = selvaFibre + ( ${i} ) * ${J(t)};
49
49
  diffuseColor.rgb *= 1.0 + 0.5 * selvaStreak;`).replace(`#include <roughnessmap_fragment>`,`#include <roughnessmap_fragment>
50
50
  roughnessFactor = clamp( roughnessFactor * ( 1.0 + selvaStreak ), 0.0, 1.0 );`).replace(`#include <normal_fragment_maps>`,`#include <normal_fragment_maps>
51
51
  #ifdef USE_ANISOTROPY
@@ -57,12 +57,12 @@ import{a as e,g as t,h as n,i as r,l as i,n as a,o,p as s,t as c,u as l}from"./g
57
57
  vec3 selvaAcross = cross( selvaQ1, normal ) * dFdx( vUv ).y + cross( normal, selvaQ0 ) * dFdy( vUv ).y;
58
58
  selvaAcross *= inversesqrt( max( dot( selvaAcross, selvaAcross ), 1e-12 ) );
59
59
  #endif
60
- normal = normalize( normal + ${Y(.6)} * selvaFibre * selvaAcross );`)}}}function Te(e,t){return t?.appearance?.cullBackfaces?!0:(t?.closed??!1)&&!e.transparent&&e.opacity>=1}function Ee(e,t){let n=new Map;return(r,i)=>{let a=e[r],o=Te(a,{...t,closed:i}),s=`${r}:${o}`,c=n.get(s);return c||(c=De(a,{...t,closed:o}),n.set(s,c)),c}}function De(e,t){let n=o(e.color),r=t?.vertexColors??!1,a=t?.appearance,s=new u.MeshPhysicalMaterial({color:n,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,vertexColors:r,side:Te(e,t)?u.FrontSide:u.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.25,polygonOffsetUnits:0,depthWrite:!0,depthTest:!0});e.envMapIntensity==null?a?.envMapIntensity!=null&&(s.envMapIntensity=l(a.envMapIntensity,e.metalness)):(s.envMapIntensity=e.envMapIntensity,s.userData[i]=e.envMapIntensity),e.clearcoat!=null&&(s.clearcoat=e.clearcoat,s.clearcoatRoughness=e.clearcoatRoughness??0),e.anisotropy!=null&&e.anisotropy>0&&t?.hasUvs&&(s.anisotropy=e.anisotropy,s.anisotropyRotation=e.anisotropyRotation??0),e.transmission!=null&&(s.transmission=e.transmission,s.thickness=0),e.ior!=null&&(s.ior=e.ior),r&&ke(s);let c=e.finish&&t?.hasUvs?we(e.finish,e.finishStrength??1):null;c&&(s.defines={...s.defines,USE_UV:``},Oe(s,c.key,c.patch));let{mapSize:d}=e;return e.map&&J(s,e.map,`map`,d),e.roughnessMap&&J(s,e.roughnessMap,`roughnessMap`,d),e.normalMap&&J(s,e.normalMap,`normalMap`,d),s}function Oe(e,t,n){let r=e.onBeforeCompile,i=e.customProgramCacheKey.bind(e);e.onBeforeCompile=(t,i)=>{r.call(e,t,i),n(t)},e.customProgramCacheKey=()=>`${i()}|${t}`}function ke(e){Oe(e,`srgb-vertex-colors`,e=>{e.vertexShader=e.vertexShader.replace(`#include <color_vertex>`,`#include <color_vertex>
60
+ normal = normalize( normal + ${J(.6)} * selvaFibre * selvaAcross );`)}}}function Ee(e,t){return t?.appearance?.cullBackfaces?!0:(t?.closed??!1)&&!e.transparent&&e.opacity>=1}function De(e,t){let n=/* @__PURE__ */ new Map;return(r,i)=>{let a=e[r],o=Ee(a,{...t,closed:i}),s=`${r}:${o}`,c=n.get(s);return c||(c=Oe(a,{...t,closed:o}),n.set(s,c)),c}}function Oe(e,t){let n=o(e.color),r=t?.vertexColors??!1,a=t?.appearance,s=new u.MeshPhysicalMaterial({color:n,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,vertexColors:r,side:Ee(e,t)?u.FrontSide:u.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.25,polygonOffsetUnits:0,depthWrite:!0,depthTest:!0});e.envMapIntensity==null?a?.envMapIntensity!=null&&(s.envMapIntensity=l(a.envMapIntensity,e.metalness)):(s.envMapIntensity=e.envMapIntensity,s.userData[i]=e.envMapIntensity),e.clearcoat!=null&&(s.clearcoat=e.clearcoat,s.clearcoatRoughness=e.clearcoatRoughness??0),e.anisotropy!=null&&e.anisotropy>0&&t?.hasUvs&&(s.anisotropy=e.anisotropy,s.anisotropyRotation=e.anisotropyRotation??0),e.transmission!=null&&(s.transmission=e.transmission,s.thickness=0),e.ior!=null&&(s.ior=e.ior),r&&Ae(s);let c=e.finish&&t?.hasUvs?Te(e.finish,e.finishStrength??1):null;c&&(s.defines={...s.defines,USE_UV:``},ke(s,c.key,c.patch));let{mapSize:d}=e;return e.map&&q(s,e.map,`map`,d),e.roughnessMap&&q(s,e.roughnessMap,`roughnessMap`,d),e.normalMap&&q(s,e.normalMap,`normalMap`,d),s}function ke(e,t,n){let r=e.onBeforeCompile,i=e.customProgramCacheKey.bind(e);e.onBeforeCompile=(t,i)=>{r.call(e,t,i),n(t)},e.customProgramCacheKey=()=>`${i()}|${t}`}function Ae(e){ke(e,`srgb-vertex-colors`,e=>{e.vertexShader=e.vertexShader.replace(`#include <color_vertex>`,`#include <color_vertex>
61
61
  #if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )
62
62
  vColor.rgb = mix(
63
63
  vColor.rgb / 12.92,
64
64
  pow( ( vColor.rgb + 0.055 ) / 1.055, vec3( 2.4 ) ),
65
65
  step( vec3( 0.04045 ), vColor.rgb )
66
66
  );
67
- #endif`)})}function X(e,r){return new t(e,n.VALIDATION_ERROR,{context:r})}function Ae(e,t,n,r){for(let i of e){if(!Number.isInteger(i.materialId)||i.materialId<0||i.materialId>=t)throw X(`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 X(`Mesh metadata field "${n}" must be a non-negative integer.`,{meshName:e.name,field:n,value:r});if(e.vertexStart+e.vertexCount>n)throw X(`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 X(`Mesh index window exceeds the batch index buffer.`,{meshName:e.name,indexStart:e.indexStart,indexCount:e.indexCount,totalIndexCount:r})}}}function je(e,t){return X(`Index references a vertex outside its mesh's vertex window.`,{meshName:t.name,indexValue:e,vertexStart:t.vertexStart,vertexCount:t.vertexCount})}function Me(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 Ne(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 Pe(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 c=new Float32Array(o*3),l=new Uint32Array(s),u=i?new Float32Array(o*2):null,d=a?new Uint8Array(o*3):null,f=0,p=0;for(let r of e.meshes){let e=r.vertexStart*3,o=r.vertexCount*3;if(c.set(t.subarray(e,e+o),f*3),u&&i){let e=r.vertexStart*2;u.set(i.subarray(e,e+r.vertexCount*2),f*2)}d&&a&&d.set(a.subarray(e,e+o),f*3);let s=n.subarray(r.indexStart,r.indexStart+r.indexCount),m=f-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 je(t,r);l[p+e]=t+m}f+=r.vertexCount,p+=r.indexCount}let m=me({positions:c,indices:l,uvs:u,colors:d},e.meshes.map(e=>e.indexCount));return Ie(Z(m),e,r(e.materialId,m.closed))}function Z(e){let t=new u.BufferGeometry;return t.setAttribute(`position`,new u.BufferAttribute(e.positions,3)),t.setAttribute(`normal`,new u.BufferAttribute(e.normals,3)),t.setIndex(new u.BufferAttribute(e.indices,1)),e.uvs&&t.setAttribute(`uv`,new u.BufferAttribute(e.uvs,2)),e.tangents&&t.setAttribute(`tangent`,new u.BufferAttribute(e.tangents,4)),e.colors&&t.setAttribute(`color`,new u.BufferAttribute(e.colors,3,!0)),t}function Fe(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 Ie(e,t,n){let r=new u.Mesh(e,n),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:Fe(t)},r}function Le(e,t,n,r,i=null,a=null){let o=[];for(let s of e.meshes){let c=s.vertexStart*3,l=s.vertexCount*3,u=t.slice(c,c+l),d=n.subarray(s.indexStart,s.indexStart+s.indexCount),f=new Uint32Array(d.length),p=s.vertexStart,m=s.vertexStart+s.vertexCount;for(let e=0;e<d.length;e++){let t=d[e];if(t<p||t>=m)throw je(t,s);f[e]=t-p}let h=s.vertexStart*2,g=me({positions:u,indices:f,uvs:i?i.slice(h,h+s.vertexCount*2):null,colors:a?a.slice(c,c+l):null},[f.length]);o.push(Re(Z(g),s,r(e.materialId,g.closed)))}return o}function Re(e,t,n){let r=new u.Mesh(e,n);return r.name=t.name,r.userData={source:`compute`,name:t.name,layer:t.layer??``,trackingKey:t.id,metadata:t.metadata??{}},r.castShadow=!0,r.receiveShadow=!0,r}async function ze(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 Ue(e.compressedData,{mergeByMaterial:r,debug:i,material:a,fallback:{materials:e.materials,groups:e.groups}});if(c)return c;let l=performance.now();return Q(H(e.compressedData),{mergeByMaterial:r,debug:i,material:a,parseTime:o,decodeTime:performance.now()-l,perfStart:s,blobBytes:i?We(e.compressedData):0,fallback:{materials:e.materials,groups:e.groups}})}async function Be(e,t){let{mergeByMaterial:n=!0,debug:r=!1,material:i}=t??{},a=r?performance.now():0,o=await Ue(e,{mergeByMaterial:n,debug:r,material:i});if(o)return o;let s=performance.now(),c=H(e),l=performance.now()-s,u=e.byteLength;return Q(c,{mergeByMaterial:n,debug:r,material:i,parseTime:0,decodeTime:l,perfStart:a,blobBytes:u})}let Ve=!1;function He(e,t){if(e||Ve)return;let n=0;for(let e of t)n+=e.meshes.length;n<1e3||(Ve=!0,s().warn(`Parsing ${n} 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 Q(e,t){let{mergeByMaterial:n,debug:r,material:i,parseTime:a,decodeTime:o,perfStart:c,blobBytes:l,fallback:u}=t,d=e.metadata.materials??u?.materials??[],f=e.metadata.groups??u?.groups??[],p=!!(e.flags&1);Ae(f,d.length,e.vertices.length/3,e.indices.length);let m=p?e.vertices:Me(e.vertices,e.origin,e.scale);if(r){let t=e.vertices.byteLength+e.indices.byteLength;s().debug(`Mesh Batch Stats:`),s().debug(` Materials: ${d.length} | Groups: ${f.length}`),s().debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),s().debug(` Format: ${p?`float32`:`int16 quantized`}`),s().debug(` Blob: ${(l/1024/1024).toFixed(2)} MB | Geometry on wire: ${(t/1024/1024).toFixed(2)} MB`)}He(n,f);let h=performance.now(),g=Ee(d,{vertexColors:e.colors!=null,hasUvs:e.uvs!=null,appearance:i}),_=[],v=n?f.flatMap(Ne):f;for(let t of v)if(n&&t.meshes.length>1){let n=Pe(t,m,e.indices,g,e.uvs,e.colors);_.push(n)}else{let n=Le(t,m,e.indices,g,e.uvs,e.colors);_.push(...n)}let y=performance.now()-h;if(r){let e=performance.now()-c;s().debug(`Performance:`),a>0&&s().debug(` Parse JSON: ${a.toFixed(2)}ms`),s().debug(` Decode binary: ${o.toFixed(2)}ms`),s().debug(` Create Meshes: ${y.toFixed(2)}ms`),s().debug(` Total: ${e.toFixed(2)}ms`)}return Promise.resolve(_)}async function Ue(e,t){if(typeof Worker>`u`)return null;let n=U(e),r=n.planarByteSplit?n.indexData.length/(n.uint16Indices?2:4):n.indexData.length;if(r/3<5e4)return null;let i=ve();if(!i)return null;let a=n.metadata.materials??t.fallback?.materials??[],o=n.metadata.groups??t.fallback?.groups??[];Ae(o,a.length,n.vertexCount,r);let c=e=>({vertexStart:e.vertexStart,vertexCount:e.vertexCount,indexStart:e.indexStart,indexCount:e.indexCount}),l=[],u=[],d=t.mergeByMaterial?o.flatMap(Ne):o;for(let e of d)if(t.mergeByMaterial&&e.meshes.length>1)l.push({kind:`merged`,windows:e.meshes.map(c)}),u.push({kind:`merged`,group:e});else for(let t of e.meshes)l.push({kind:`single`,windows:[c(t)]}),u.push({kind:`single`,group:e,meshMeta:t});let f=n.vertexData.slice(),p=n.indexData.slice(),m=[f.buffer,p.buffer];n.uvs&&m.push(n.uvs.buffer),n.colors&&m.push(n.colors.buffer);let h;try{h=await ye(i,{vertexData:f,isFloat32:n.isFloat32,deltaEncoded:n.deltaEncoded,planarByteSplit:n.planarByteSplit,uint16Indices:n.uint16Indices,origin:n.origin,scale:n.scale,indexData:p,uvs:n.uvs,colors:n.colors,jobs:l},m)}catch(e){return s().warn(`Mesh assembly worker failed; falling back to main-thread parse.`,e),null}if(h.length!==l.length)return null;let g=Ee(a,{vertexColors:n.colors!=null,hasUvs:n.uvs!=null,appearance:t.material}),_=[];for(let e=0;e<h.length;e++){let t=h[e],n=u[e],r=Z(t),i=g(n.group.materialId,t.closed),a=n.kind===`merged`?Ie(r,n.group,i):Re(r,n.meshMeta,i);_.push(a)}return t.debug&&s().debug(`Mesh batch assembled off-thread: ${_.length} meshes, ${r/3} triangles`),_}function We(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 Ge(e){let t=e.split(`.`);return t.includes(`Display`)||t.includes(`DisplayBatch`)}const Ke=new Set;async function qe(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 Ye(e,r,i?Je(e.modelunits):1,c,s),a&&$e(r,o),r}catch(e){throw et(e,r),e}finally{s&&nt(n)}}function Je(e){let t=$[e];return t===void 0?(Ke.has(e)||(Ke.add(e),s().warn(`Unknown Rhino model unit "${e}" — geometry will not be scaled (factor 1). Known units: ${Object.keys($).join(`, `)}.`)),1):t}async function Ye(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 Xe(o,t,n,r,i)}}}async function Xe(e,t,n,r,i){for(let a of e){if(!Ge(a.type))continue;let e={debug:!1,...r,mergeByMaterial:r.mergeByMaterial??!0},o=Ze(a.data);if(!o){s().error(`Error parsing display batch envelope: invalid JSON`);continue}let c=await ze(o,e),l=E(o.items),u=[...c,...l];if(n!==1)for(let e of u)e.scale.set(n,n,n);t.push(...u),i&&s().debug(`Extracted ${c.length} meshes and ${l.length} items from batch`)}}function Ze(e){return typeof e==`string`?Qe(e):e}function Qe(e){try{return JSON.parse(e)}catch{return}}function $e(t,n){if(t.length===0)return;let i=e(t);r(t,i.min[n],n)}function et(e,t){s().error(`An unexpected error occurred:`,e),tt(t)}function tt(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 nt(e){let t=performance.now()-e;s().info(`Time to process meshes:`,`${t.toFixed(2)}ms`)}export{$ as SCALE_FACTORS,qe as getThreeObjectsFromComputeResponse,x as meshPolicy,E as parseDisplayItems,Be as parseMeshBatchBlob,ze as parseMeshBatchObject,xe as setTextureAnisotropy};
67
+ #endif`)})}function Y(e,r){return new t(e,n.VALIDATION_ERROR,{context:r})}function je(e,t,n,r){for(let i of e){if(!Number.isInteger(i.materialId)||i.materialId<0||i.materialId>=t)throw Y(`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 Y(`Mesh metadata field "${n}" must be a non-negative integer.`,{meshName:e.name,field:n,value:r});if(e.vertexStart+e.vertexCount>n)throw Y(`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 Y(`Mesh index window exceeds the batch index buffer.`,{meshName:e.name,indexStart:e.indexStart,indexCount:e.indexCount,totalIndexCount:r})}}}function Me(e,t){return Y(`Index references a vertex outside its mesh's vertex window.`,{meshName:t.name,indexValue:e,vertexStart:t.vertexStart,vertexCount:t.vertexCount})}function Ne(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 Pe(e){let t=/* @__PURE__ */ 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 Fe(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 c=new Float32Array(o*3),l=new Uint32Array(s),u=i?new Float32Array(o*2):null,d=a?new Uint8Array(o*3):null,f=0,p=0;for(let r of e.meshes){let e=r.vertexStart*3,o=r.vertexCount*3;if(c.set(t.subarray(e,e+o),f*3),u&&i){let e=r.vertexStart*2;u.set(i.subarray(e,e+r.vertexCount*2),f*2)}d&&a&&d.set(a.subarray(e,e+o),f*3);let s=n.subarray(r.indexStart,r.indexStart+r.indexCount),m=f-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 Me(t,r);l[p+e]=t+m}f+=r.vertexCount,p+=r.indexCount}let m=he({positions:c,indices:l,uvs:u,colors:d},e.meshes.map(e=>e.indexCount));return Le(X(m),e,r(e.materialId,m.closed))}function X(e){let t=new u.BufferGeometry;return t.setAttribute(`position`,new u.BufferAttribute(e.positions,3)),t.setAttribute(`normal`,new u.BufferAttribute(e.normals,3)),t.setIndex(new u.BufferAttribute(e.indices,1)),e.uvs&&t.setAttribute(`uv`,new u.BufferAttribute(e.uvs,2)),e.tangents&&t.setAttribute(`tangent`,new u.BufferAttribute(e.tangents,4)),e.colors&&t.setAttribute(`color`,new u.BufferAttribute(e.colors,3,!0)),t}function Ie(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 Le(e,t,n){let r=new u.Mesh(e,n),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:Ie(t)},r}function Re(e,t,n,r,i=null,a=null){let o=[];for(let s of e.meshes){let c=s.vertexStart*3,l=s.vertexCount*3,u=t.slice(c,c+l),d=n.subarray(s.indexStart,s.indexStart+s.indexCount),f=new Uint32Array(d.length),p=s.vertexStart,m=s.vertexStart+s.vertexCount;for(let e=0;e<d.length;e++){let t=d[e];if(t<p||t>=m)throw Me(t,s);f[e]=t-p}let h=s.vertexStart*2,g=he({positions:u,indices:f,uvs:i?i.slice(h,h+s.vertexCount*2):null,colors:a?a.slice(c,c+l):null},[f.length]);o.push(ze(X(g),s,r(e.materialId,g.closed)))}return o}function ze(e,t,n){let r=new u.Mesh(e,n);return r.name=t.name,r.userData={source:`compute`,name:t.name,layer:t.layer??``,trackingKey:t.id,metadata:t.metadata??{}},r.castShadow=!0,r.receiveShadow=!0,r}async function Be(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=performance.now(),l=H(e.compressedData);return await We(l,{mergeByMaterial:r,debug:i,material:a,fallback:{materials:e.materials,groups:e.groups}})||Z(V(l),{mergeByMaterial:r,debug:i,material:a,parseTime:o,decodeTime:performance.now()-c,perfStart:s,blobBytes:i?Ge(e.compressedData):0,fallback:{materials:e.materials,groups:e.groups}})}async function Ve(e,t){let{mergeByMaterial:n=!0,debug:r=!1,material:i}=t??{},a=r?performance.now():0,o=performance.now(),s=H(e),c=await We(s,{mergeByMaterial:n,debug:r,material:i});if(c)return c;let l=V(s),u=performance.now()-o,d=e.byteLength;return Z(l,{mergeByMaterial:n,debug:r,material:i,parseTime:0,decodeTime:u,perfStart:a,blobBytes:d})}let He=!1;function Ue(e,t){if(e||He)return;let n=0;for(let e of t)n+=e.meshes.length;n<1e3||(He=!0,s().warn(`Parsing ${n} 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 Z(e,t){let{mergeByMaterial:n,debug:r,material:i,parseTime:a,decodeTime:o,perfStart:c,blobBytes:l,fallback:u}=t,d=e.metadata.materials??u?.materials??[],f=e.metadata.groups??u?.groups??[],p=!!(e.flags&1);je(f,d.length,e.vertices.length/3,e.indices.length);let m=p?e.vertices:Ne(e.vertices,e.origin,e.scale);if(r){let t=e.vertices.byteLength+e.indices.byteLength;s().debug(`Mesh Batch Stats:`),s().debug(` Materials: ${d.length} | Groups: ${f.length}`),s().debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),s().debug(` Format: ${p?`float32`:`int16 quantized`}`),s().debug(` Blob: ${(l/1024/1024).toFixed(2)} MB | Geometry on wire: ${(t/1024/1024).toFixed(2)} MB`)}Ue(n,f);let h=performance.now(),g=De(d,{vertexColors:e.colors!=null,hasUvs:e.uvs!=null,appearance:i}),_=[],v=n?f.flatMap(Pe):f;for(let t of v)if(n&&t.meshes.length>1){let n=Fe(t,m,e.indices,g,e.uvs,e.colors);_.push(n)}else{let n=Re(t,m,e.indices,g,e.uvs,e.colors);_.push(...n)}let y=performance.now()-h;if(r){let e=performance.now()-c;s().debug(`Performance:`),a>0&&s().debug(` Parse JSON: ${a.toFixed(2)}ms`),s().debug(` Decode binary: ${o.toFixed(2)}ms`),s().debug(` Create Meshes: ${y.toFixed(2)}ms`),s().debug(` Total: ${e.toFixed(2)}ms`)}return Promise.resolve(_)}async function We(e,t){if(typeof Worker>`u`)return null;let n=e.planarByteSplit?e.indexData.length/(e.uint16Indices?2:4):e.indexData.length;if(n/3<5e4)return null;let r=ye();if(!r)return null;let i=e.metadata.materials??t.fallback?.materials??[],a=e.metadata.groups??t.fallback?.groups??[];je(a,i.length,e.vertexCount,n);let o=e=>({vertexStart:e.vertexStart,vertexCount:e.vertexCount,indexStart:e.indexStart,indexCount:e.indexCount}),c=[],l=[],u=t.mergeByMaterial?a.flatMap(Pe):a;for(let e of u)if(t.mergeByMaterial&&e.meshes.length>1)c.push({kind:`merged`,windows:e.meshes.map(o)}),l.push({kind:`merged`,group:e});else for(let t of e.meshes)c.push({kind:`single`,windows:[o(t)]}),l.push({kind:`single`,group:e,meshMeta:t});let d=e.vertexData.slice(),f=e.indexData.slice(),p=e.uvs?.slice()??null,m=e.colors?.slice()??null,h=[d.buffer,f.buffer];p&&h.push(p.buffer),m&&h.push(m.buffer);let g;try{g=await be(r,{vertexData:d,isFloat32:e.isFloat32,deltaEncoded:e.deltaEncoded,planarByteSplit:e.planarByteSplit,uint16Indices:e.uint16Indices,origin:e.origin,scale:e.scale,indexData:f,uvs:p,colors:m,jobs:c},h)}catch(e){return s().warn(`Mesh assembly worker failed; falling back to main-thread parse.`,e),null}if(g.length!==c.length)return null;let _=De(i,{vertexColors:e.colors!=null,hasUvs:e.uvs!=null,appearance:t.material}),v=[];for(let e=0;e<g.length;e++){let t=g[e],n=l[e],r=X(t),i=_(n.group.materialId,t.closed),a=n.kind===`merged`?Le(r,n.group,i):ze(r,n.meshMeta,i);v.push(a)}return t.debug&&s().debug(`Mesh batch assembled off-thread: ${v.length} meshes, ${n/3} triangles`),v}function Ge(e){return Math.floor(e.length*3/4)}const Q={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 Ke(e){let t=e.split(`.`);return t.includes(`Display`)||t.includes(`DisplayBatch`)}const $=/* @__PURE__ */ new Set;async function qe(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 Ye(e,r,i?Je(e.modelunits):1,c,s),a&&$e(r,o),r}catch(e){throw et(e,r),e}finally{s&&nt(n)}}function Je(e){let t=Q[e];return t===void 0?($.has(e)||($.add(e),s().warn(`Unknown Rhino model unit "${e}" — geometry will not be scaled (factor 1). Known units: ${Object.keys(Q).join(`, `)}.`)),1):t}async function Ye(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 Xe(o,t,n,r,i)}}}async function Xe(e,t,n,r,i){for(let a of e){if(!Ke(a.type))continue;let e={debug:!1,...r,mergeByMaterial:r.mergeByMaterial??!0},o=Ze(a.data);if(!o){s().error(`Error parsing display batch envelope: invalid JSON`);continue}let c=await Be(o,e),l=E(o.items),u=[...c,...l];if(n!==1)for(let e of u)e.scale.set(n,n,n);t.push(...u),i&&s().debug(`Extracted ${c.length} meshes and ${l.length} items from batch`)}}function Ze(e){return typeof e==`string`?Qe(e):e}function Qe(e){try{return JSON.parse(e)}catch{return}}function $e(t,n){if(t.length===0)return;let i=e(t);r(t,i.min[n],n)}function et(e,t){s().error(`An unexpected error occurred:`,e),tt(t)}function tt(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 nt(e){let t=performance.now()-e;s().info(`Time to process meshes:`,`${t.toFixed(2)}ms`)}export{Q as SCALE_FACTORS,qe as getThreeObjectsFromComputeResponse,x as meshPolicy,E as parseDisplayItems,Ve as parseMeshBatchBlob,Be as parseMeshBatchObject,Se as setTextureAnisotropy};
68
68
  //# sourceMappingURL=parse.js.map