ldr 0.6.0 → 0.7.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 +11 -2
- package/dist/cli.js +55 -17
- package/dist/index.d.ts +3 -1
- package/dist/index.js +456 -24
- package/dist/instructions.d.ts +80 -0
- package/dist/load-worker.gen.d.ts +1 -1
- package/dist/model.d.ts +23 -1
- package/dist/node/index.js +473 -33
- package/dist/parts-cdn.d.ts +2 -0
- package/dist/render.d.ts +1 -1
- package/dist/scene.d.ts +3 -2
- package/dist/spec.d.ts +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type M } from "./spec.js";
|
|
2
|
+
/** Unit vector from the target towards the camera, LDraw space (-Y up, the model's front faces -Z). */
|
|
3
|
+
export type Vec3 = [number, number, number];
|
|
4
|
+
export interface StepCameraView {
|
|
5
|
+
dir: Vec3;
|
|
6
|
+
/** Point to look at and radius of the sphere to fit in view, LDraw space. */
|
|
7
|
+
target: Vec3;
|
|
8
|
+
radius: number;
|
|
9
|
+
/** Visibility (0..1) from `dir` of the least visible new part, and the mean over new parts. */
|
|
10
|
+
minVis: number;
|
|
11
|
+
meanVis: number;
|
|
12
|
+
/** The view looks up at the model from below (the new parts were added underneath). */
|
|
13
|
+
below: boolean;
|
|
14
|
+
/** Set when the step builds a sub-assembly (every new part inside one submodel copy; needs `flatten(doc, { callouts: true })`):
|
|
15
|
+
* that copy's placement id. Show it on its own, as a booklet callout: `obj.setStep(step, isolateMask(insts, view.isolate))`. */
|
|
16
|
+
isolate?: number;
|
|
17
|
+
/** With `isolate`: the copy's placement matrix (LDraw 12 numbers). `dir`, `target` and `radius` are then in the copy's own frame:
|
|
18
|
+
* show it the way it is built, upright on the table, by drawing the model through inverse(`frame`) for this step. */
|
|
19
|
+
frame?: number[];
|
|
20
|
+
}
|
|
21
|
+
export interface StepCameraOptions {
|
|
22
|
+
/** Default view, degrees. Default 45 / 30. */
|
|
23
|
+
azimuth?: number;
|
|
24
|
+
elevation?: number;
|
|
25
|
+
/** New parts must be at least this visible on average to keep the previous view. Default 0.5. */
|
|
26
|
+
minVis?: number;
|
|
27
|
+
/** Below this, views from underneath are considered. Default 0.35. */
|
|
28
|
+
reorient?: number;
|
|
29
|
+
/** Visibility cost per degree of camera turn. Default 0.002. */
|
|
30
|
+
turnCost?: number;
|
|
31
|
+
/** Per-step override (e.g. from `0 ROTSTEP`): a direction to use as is. */
|
|
32
|
+
fixed?: (step: number) => Vec3 | null;
|
|
33
|
+
}
|
|
34
|
+
export declare const MIN_VIS = 0.5, REORIENT = 0.35;
|
|
35
|
+
export declare function viewDir(azimuthDeg: number, elevationDeg: number): Vec3;
|
|
36
|
+
interface Inst {
|
|
37
|
+
part: string;
|
|
38
|
+
m: M | number[];
|
|
39
|
+
sub?: number;
|
|
40
|
+
subPath?: number[];
|
|
41
|
+
subMats?: (M | number[])[];
|
|
42
|
+
}
|
|
43
|
+
/** Per-instance mask of a sub-assembly copy and everything nested in it (for `setStep(step, mask)`). */
|
|
44
|
+
export declare function isolateMask(insts: Inst[], sub: number): Uint8Array;
|
|
45
|
+
/** World AABBs (LDraw space) of the instances whose part has a `bbox` in the pack header; null for the others. */
|
|
46
|
+
export declare function instanceBoxes(insts: Inst[], parts: Record<string, {
|
|
47
|
+
bbox?: number[];
|
|
48
|
+
} | undefined>): (Float64Array | null)[];
|
|
49
|
+
/** Uniform grid of boxes for "does a ray from p along d hit any box except `self`?" queries. Boxes are added incrementally. */
|
|
50
|
+
declare class BoxGrid {
|
|
51
|
+
cells: Map<number, number[]>;
|
|
52
|
+
boxes: (Float64Array | null)[];
|
|
53
|
+
cell: number;
|
|
54
|
+
stamp: Int32Array;
|
|
55
|
+
q: number;
|
|
56
|
+
lo: number[];
|
|
57
|
+
hi: number[];
|
|
58
|
+
constructor(boxes: (Float64Array | null)[], cell: number);
|
|
59
|
+
private key;
|
|
60
|
+
add(id: number): void;
|
|
61
|
+
/** Is p inside an added box other than `self`? (a face sample pressed against a neighbour is never visible from anywhere) */
|
|
62
|
+
inside(p: number[], self: number): boolean;
|
|
63
|
+
/** Ray p + t d (t > 0) against the added boxes (shrunk by `eps`), skipping `self`. Walks grid cells (Amanatides & Woo). */
|
|
64
|
+
hits(p: number[], d: Vec3, self: number, eps?: number): boolean;
|
|
65
|
+
}
|
|
66
|
+
/** Visible fraction (projected-area weighted) of box `id` from direction `d`, with the boxes in `grid` as occluders; -1 when no face
|
|
67
|
+
* sample can be judged (a part inside a hollow part's box, which a bounding box can't see into). */
|
|
68
|
+
export declare function boxVisibility(grid: BoxGrid, id: number, d: Vec3, n?: number): number;
|
|
69
|
+
/**
|
|
70
|
+
* Plan the camera for build steps, in order (each view depends on the previous one). `stepOf[k]` is instance k's global step
|
|
71
|
+
* (`sequenceSteps` / `createLdrObject` order). Returns `view(step)`, computing and caching steps up to `step` on first use, so a
|
|
72
|
+
* viewer pays only for the steps it shows.
|
|
73
|
+
*/
|
|
74
|
+
export declare function planStepViews(insts: Inst[], parts: Record<string, {
|
|
75
|
+
bbox?: number[];
|
|
76
|
+
} | undefined>, stepOf: ArrayLike<number>, nSteps: number, o?: StepCameraOptions): {
|
|
77
|
+
stepCount: number;
|
|
78
|
+
view(step: number): StepCameraView;
|
|
79
|
+
};
|
|
80
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "var ut=ArrayBuffer,j=Uint8Array,ge=Uint16Array,ft=Int16Array;var be=Int32Array,Ae=function(e,t,n){if(j.prototype.slice)return j.prototype.slice.call(e,t,n);if(t==null||t<0)t=0;if(n==null||n>e.length)n=e.length;var r=new j(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(j.prototype.fill)return j.prototype.fill.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;for(;n<r;++n)e[n]=t;return e},pt=function(e,t,n,r){if(j.prototype.copyWithin)return j.prototype.copyWithin.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;while(n<r)e[t++]=e[n++]};var mt=[\"invalid zstd data\",\"window size too large (>2046MB)\",\"invalid block type\",\"FSE accuracy too high\",\"match distance too far back\",\"unexpected EOF\"],V=function(e,t,n){var r=Error(t||mt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,V);if(!n)throw r;return r},Ne=function(e,t,n){var r=0,o=0;for(;r<n;++r)o|=e[t++]<<(r<<3);return o},ht=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},gt=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],o=r>>5&1,s=r>>2&1,i=r&3,c=r>>6;if(r&8)V(0);var a=6-o,l=i==3?4:i,f=Ne(e,a,l);a+=l;var g=c?1<<c:o,p=Ne(e,a,g)+(c==1&&256),y=p;if(!o){var C=1<<10+(e[5]>>3);y=C+(C>>3)*(e[5]&7)}if(y>2145386496)V(1);var u=new j((t==1?p||y:t?0:y)+12);return u[0]=1,u[4]=4,u[8]=8,{b:a+g,y:0,l:0,d:f,w:t&&t!=1?t:u.subarray(12),e:y,o:new be(u.buffer,0,3),u:p,c:s,m:Math.min(131072,y)}}else if((n>>4|e[3]<<20)==25481893)return ht(e,4)+8;V(0)},re=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,o=(e[t]&15)+5;if(o>n)V(3);var s=1<<o,i=s,c=-1,a=-1,l=-1,f=s,g=new ut(512+(s<<2)),p=new ft(g,0,256),y=new ge(g,0,256),C=new ge(g,512,s),u=512+(s<<1),m=new j(g,u,s),P=new j(g,u+s);while(c<255&&i>0){var b=re(i+1),d=r>>3,S=(1<<b+1)-1,k=(e[d]|e[d+1]<<8|e[d+2]<<16)>>(r&7)&S,w=(1<<b)-1,E=S-i-1,M=k&w;if(M<E)r+=b,k=M;else if(r+=b+1,k>w)k-=E;if(p[++c]=--k,k==-1)i+=k,m[--f]=c;else i-=k;if(!k)do{var x=r>>3;a=(e[x]|e[x+1]<<8)>>(r&7)&3,r+=2,c+=a}while(a==3)}if(c>255||i)V(0);var A=0,L=(s>>1)+(s>>3)+3,D=s-1;for(var F=0;F<=c;++F){var v=p[F];if(v<1){y[F]=-v;continue}for(l=0;l<v;++l){m[A]=F;do A=A+L&D;while(A>=f)}}if(A)V(0);for(l=0;l<s;++l){var h=y[m[l]]++,T=P[l]=o-re(h);C[l]=(h<<T)-s}return[r+7>>3,{b:o,s:m,n:P,t:C}]},bt=function(e,t){var n=0,r=-1,o=new j(292),s=e[t],i=o.subarray(0,256),c=o.subarray(256,268),a=new ge(o.buffer,268);if(s<128){var l=ue(e,t+1,6),f=l[0],g=l[1];t+=s;var p=f<<3,y=e[t];if(!y)V(0);var C=0,u=0,m=g.b,P=m,b=(++t<<3)-8+re(y);for(;;){if(b-=m,b<p)break;var d=b>>3;if(C+=(e[d]|e[d+1]<<8)>>(b&7)&(1<<m)-1,i[++r]=g.s[C],b-=P,b<p)break;d=b>>3,u+=(e[d]|e[d+1]<<8)>>(b&7)&(1<<P)-1,i[++r]=g.s[u],m=g.n[C],C=g.t[C],P=g.n[u],u=g.t[u]}if(++r>255)V(0)}else{r=s-127;for(;n<r;n+=2){var S=e[++t];i[n]=S>>4,i[n+1]=S&15}++t}var k=0;for(n=0;n<r;++n){var w=i[n];if(w>11)V(0);k+=w&&1<<w-1}var E=re(k)+1,M=1<<E,x=M-k;if(x&x-1)V(0);i[r++]=re(x)+1;for(n=0;n<r;++n){var w=i[n];++c[i[n]=w&&E+1-w]}var A=new j(M<<1),L=A.subarray(0,M),D=A.subarray(M);a[E]=0;for(n=E;n>0;--n){var F=a[n];ce(D,n,F,a[n-1]=F+c[n]*(1<<E-n))}if(a[0]!=M)V(0);for(n=0;n<r;++n){var v=i[n];if(v){var h=a[v];ce(L,n,h,a[v]=h+(1<<E-v))}}return[t,{n:D,b:E,s:L}]},dt=ue(new j([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],yt=ue(new j([33,20,196,24,99,140,33,132,16,66,8,33,132,16,66,8,33,68,68,68,68,68,68,68,68,36,9]),0,6)[1],xt=ue(new j([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],$e=function(e,t){var n=e.length,r=new be(n);for(var o=0;o<n;++o)r[o]=t,t+=1<<e[o];return r},Me=new j(new be([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),wt=$e(Me,0),Se=new j(new be([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),vt=$e(Se,3),le=function(e,t,n){var r=e.length,o=t.length,s=e[r-1],i=(1<<n.b)-1,c=-n.b;if(!s)V(0);var a=0,l=n.b,f=(r<<3)-8+re(s)-l,g=-1;for(;f>c&&g<o;){var p=f>>3,y=(e[p]|e[p+1]<<8|e[p+2]<<16)>>(f&7);a=(a<<l|y)&i,t[++g]=n.s[a],f-=l=n.n[a]}if(f!=c||g+1!=o)V(0)},At=function(e,t,n){var r=6,o=t.length,s=o+3>>2,i=s<<1,c=s+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,s),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(s,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,c),n),le(e.subarray(r),t.subarray(c),n)},Mt=function(e,t,n){var r,o=t.b,s=e[o],i=s>>1&3;t.l=s&1;var c=s>>3|e[o+1]<<5|e[o+2]<<13,a=(o+=3)+c;if(i==1){if(o>=e.length)return;if(t.b=o+1,n)return ce(n,e[o],t.y,t.y+=c),n;return ce(new j(c),e[o])}if(a>e.length)return;if(i==0){if(t.b=a,n)return n.set(e.subarray(o,a),t.y),t.y+=c,n;return Ae(e,o,a)}if(i==2){var l=e[o],f=l&3,g=l>>2&3,p=l>>4,y=0,C=0;if(f<2)if(g&1)p|=e[++o]<<4|(g&2&&e[++o]<<12);else p=l>>3;else if(C=g,g<2)p|=(e[++o]&63)<<4,y=e[o]>>6|e[++o]<<2;else if(g==2)p|=e[++o]<<4|(e[++o]&3)<<12,y=e[o]>>2|e[++o]<<6;else p|=e[++o]<<4|(e[++o]&63)<<12,y=e[o]>>6|e[++o]<<2|e[++o]<<10;++o;var u=n?n.subarray(t.y,t.y+t.m):new j(t.m),m=u.length-p;if(f==0)u.set(e.subarray(o,o+=p),m);else if(f==1)ce(u,e[o++],m);else{var P=t.h;if(f==2){var b=bt(e,o);y+=o-(o=b[0]),t.h=P=b[1]}else if(!P)V(0);(C?At:le)(e.subarray(o,o+=y),u.subarray(m),P)}var d=e[o++];if(d){if(d==255)d=(e[o++]|e[o++]<<8)+32512;else if(d>127)d=d-128<<8|e[o++];var S=e[o++];if(S&3)V(0);var k=[yt,xt,dt];for(var w=2;w>-1;--w){var E=S>>(w<<1)+2&3;if(E==1){var M=new j([0,0,e[o++]]);k[w]={s:M.subarray(2,3),n:M.subarray(0,1),t:new ge(M.buffer,0,1),b:0}}else if(E==2)r=ue(e,o,9-(w&1)),o=r[0],k[w]=r[1];else if(E==3){if(!t.t)V(0);k[w]=t.t[w]}}var x=t.t=k,A=x[0],L=x[1],D=x[2],F=e[a-1];if(!F)V(0);var v=(a<<3)-8+re(F)-D.b,h=v>>3,T=0,R=(e[h]|e[h+1]<<8)>>(v&7)&(1<<D.b)-1;h=(v-=L.b)>>3;var I=(e[h]|e[h+1]<<8)>>(v&7)&(1<<L.b)-1;h=(v-=A.b)>>3;var U=(e[h]|e[h+1]<<8)>>(v&7)&(1<<A.b)-1;for(++d;--d;){var O=D.s[R],K=D.n[R],H=A.s[U],z=A.n[U],B=L.s[I],N=L.n[I];h=(v-=B)>>3;var G=1<<B,X=G+((e[h]|e[h+1]<<8|e[h+2]<<16|e[h+3]<<24)>>>(v&7)&G-1);h=(v-=Se[H])>>3;var Y=vt[H]+((e[h]|e[h+1]<<8|e[h+2]<<16)>>(v&7)&(1<<Se[H])-1);h=(v-=Me[O])>>3;var W=wt[O]+((e[h]|e[h+1]<<8|e[h+2]<<16)>>(v&7)&(1<<Me[O])-1);if(h=(v-=K)>>3,R=D.t[R]+((e[h]|e[h+1]<<8)>>(v&7)&(1<<K)-1),h=(v-=z)>>3,U=A.t[U]+((e[h]|e[h+1]<<8)>>(v&7)&(1<<z)-1),h=(v-=N)>>3,I=L.t[I]+((e[h]|e[h+1]<<8)>>(v&7)&(1<<N)-1),X>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=X-=3;else{var _=X-(W!=0);if(_){if(X=_==3?t.o[0]-1:t.o[_],_>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=X}else X=t.o[0]}for(var w=0;w<W;++w)u[T+w]=u[m+w];T+=W,m+=W;var Z=T-X;if(Z<0){var J=-Z,ee=t.e+Z;if(J>Y)J=Y;for(var w=0;w<J;++w)u[T+w]=t.w[ee+w];T+=J,Y-=J,Z=0}for(var w=0;w<Y;++w)u[T+w]=u[Z+w];T+=Y}if(T!=m)while(m<u.length)u[T++]=u[m++];else T=u.length;if(n)t.y+=T;else u=Ae(u,0,T)}else if(n){if(t.y+=p,m)for(var w=0;w<p;++w)u[w]=u[m+w]}else if(m)u=Ae(u,m);return t.b=a,u}V(2)},St=function(e,t){if(e.length==1)return e[0];var n=new j(t);for(var r=0,o=0;r<e.length;++r){var s=e[r];n.set(s,o),o+=s.length}return n};function je(e,t){var n=[],r=+!t,o=0,s=0;for(;e.length;){var i=gt(e,r||t);if(typeof i==\"object\"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),s+=i.u}else n.push(t),i.e=0;for(;!i.l;){var c=Mt(e,i,t);if(!c)V(5);if(t)i.e=i.y;else n.push(c),s+=c.length,pt(i.w,0,c.length),i.w.set(c,i.w.length-c.length)}o=i.b+i.c*4}else o=i;e=e.subarray(o)}return St(n,s)}function de(e){let t=new DataView(e).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,t))),r=4+t;return{header:n,arr:(s)=>s&&(s[2]===\"f32\"?new Float32Array(e,r+s[0],s[1]):s[2]===\"u16\"?new Uint16Array(e,r+s[0],s[1]):s[2]===\"u8\"?new Uint8Array(e,r+s[0],s[1]):new Uint32Array(e,r+s[0],s[1])),bytes:e.byteLength,buffer:e}}var q=(e)=>e.trim().toLowerCase().replace(/\\\\/g,\"/\").replace(/\\/+/g,\"/\");function Ce(e){if(/^0x/i.test(e))return parseInt(e,16);return+e}var Ve=/^~?\\s*moved\\s+to\\s+(.+)$/i,Ct=new Set([\"FILE\",\"NOFILE\",\"!DATA\",\"!:\",\"STEP\",\"BFC\",\"ROTSTEP\",\"BUFEXCHG\",\"!TEXMAP\"]),Je=new Set([\"part\",\"subpart\",\"primitive\",\"8_primitive\",\"48_primitive\",\"shortcut\",\"helper\"]),Pt=new Set([\"model\",\"submodel\",\"configuration\"]),Et=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function He(e){let t=Et.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,\"\");return Je.has(n)||Pt.has(n)?n:void 0}function Tt(e){let t=[],n=0;while(n<e.length){while(e[n]===\" \"||e[n]===\"\\t\")n++;if(n>=e.length)break;if(e[n]==='\"'){let r=\"\";n++;while(n<e.length&&e[n]!=='\"'){if(e[n]===\"\\\\\"&&n+1<e.length)n++;r+=e[n++]}n++,t.push(r)}else{let r=n;while(r<e.length&&e[r]!==\" \"&&e[r]!==\"\\t\")r++;t.push(e.slice(n,r)),n=r}}return t}function Lt(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),o=r===\"PLANAR\"?9:r===\"CYLINDRICAL\"?10:r===\"SPHERICAL\"?11:0;if(!o)return null;let s=n[2].trim().split(/\\s+/);if(s.length<o+1)return null;let i=s.slice(0,o).map(Number);if(!i.every(Number.isFinite))return null;let c=n[2].trim();for(let g=0;g<o;g++)c=c.replace(/^\\S+\\s*/,\"\");let a=Tt(c);if(!a.length)return null;let l={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(o>=10)l.a=i[9];if(o===11)l.b=i[10];let f=a.findIndex((g,p)=>p>0&&g.toUpperCase()===\"GLOSSMAP\");if(f>0&&a[f+1])l.glossmap=a[f+1];if(t)l.next=!0;return l}var It=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,\"\"),n=t+\"=\".repeat((4-t.length%4)%4),r=atob(n),o=new Uint8Array(r.length);for(let s=0;s<r.length;s++)o[s]=r.charCodeAt(s);return o};function kt(e){let t=e.length,n=1,r=(l)=>l===32||l===9,o=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let l=n;while(n<t&&!r(e.charCodeAt(n)))n++;return l<n?e.slice(l,n):null},s=o();if(s===null)return null;let i=Array(12);for(let l=0;l<12;l++){let f=o();if(f===null)return null;i[l]=+f}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let c=e.slice(n),a=/[ \\t]{2,}|\\t/.test(c)?c.split(/\\s+/).join(\" \"):c;return{t:1,color:Ce(s),m:i,file:q(a)}}function Ge(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Ce(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:q(e.slice(14).join(\" \"))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function Ze(e,t=\"main.ldr\",n={}){let r=!!n.geometryText,o=new Map,s=null,i=\"\",c,a=null,l=[],f=null,g=()=>{if(!a)return;let b=It(a.chunks.join(\"\")),d=b[0]===137&&b[1]===80&&b[2]===78&&b[3]===71;(c??=new Map).set(q(a.name),{name:a.name,bytes:b,...d?{mime:\"image/png\"}:{}}),a=null},p=!0,y=(b)=>{if(g(),s={name:q(b),cmds:[]},o.set(s.name,s),!i)i=s.name;l=[],f=null,p=!0},C=!1,u=!1,m=()=>{if(u)return;u=!0,o.clear(),s=null,i=\"\"},P=(b,d)=>{if(f){b.tex=f,f=null;return}let S=l[l.length-1];if(!S)return;if(S.fallback){if(!d)b.fallback=!0}else b.tex=S.map};for(let b of e.split(`\n`)){let d=b.trim();if(!d)continue;if(r&&d.charCodeAt(0)>=50&&d.charCodeAt(0)<=53&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)){if(a||C)continue;if(!s)y(t);let E=d.slice(2).trimStart(),M=E.search(/\\s/),x={t:d.charCodeAt(0)-48,color:Ce(M<0?E:E.slice(0,M)),p:[],src:d};P(x,!1),s.cmds.push(x),p=!1;continue}if(d.charCodeAt(0)===48&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)){let E=2;while(d.charCodeAt(E)===32||d.charCodeAt(E)===9)E++;let M=E;while(M<d.length&&d.charCodeAt(M)!==32&&d.charCodeAt(M)!==9)M++;let x=d.slice(E,M);if(!Ct.has(x)){if(C||a)continue;if(!s)y(t);let A=d.slice(E),L={t:0,text:A};if(x.charCodeAt(0)===33)L.meta=x;if(f=null,p&&!s.org){let F=He(A);if(F)s.org=F}let D=A.match(Ve);if(D&&!s.movedTo){let F=D[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(F))F+=\".dat\";s.movedTo=q(F)}s.cmds.push(L);continue}}if(d.charCodeAt(0)===49&&(d.charCodeAt(1)===32||d.charCodeAt(1)===9)&&!a&&!C){let E=kt(d);if(E){if(!s)y(t);P(E,!1),s.cmds.push(E),p=!1;continue}}let S=d.split(/\\s+/);if(+S[0]===0){let E=d.slice(1).trim();if(S[1]===\"FILE\"){m(),C=!1,y(E.slice(5));continue}if(S[1]===\"NOFILE\"){g(),s=null,C=!0;continue}if(S[1]===\"!DATA\"){m(),g(),s=null,C=!1,a={name:E.slice(5).trim(),chunks:[]};continue}if(C)continue;if(a){if(S[1]===\"!:\")a.chunks.push(S.slice(2).join(\"\"));continue}if(!s)y(t);let M={t:0,text:E};if(S[1]===\"STEP\")M.step=!0,l=[],f=null;else if(S[1]===\"BFC\")M.bfc=S.slice(2).join(\" \");else if(S[1]===\"ROTSTEP\")if(M.meta=\"ROTSTEP\",M.step=!0,l=[],f=null,(S[2]??\"\").toUpperCase()===\"END\")M.rotstep={x:0,y:0,z:0,mode:\"END\"};else{let A=(S[5]??\"REL\").toUpperCase();M.rotstep={x:+S[2]||0,y:+S[3]||0,z:+S[4]||0,mode:[\"REL\",\"ABS\",\"ADD\"].includes(A)?A:\"REL\"}}else if(S[1]===\"BUFEXCHG\"){M.meta=\"BUFEXCHG\";let A=(S[2]??\"\").toUpperCase();M.bufexchg={op:A===\"RETRIEVE\"?\"RETRIEVE\":\"STORE\",buf:S[3]??\"A\"}}else if(S[1]?.startsWith(\"!\"))M.meta=S[1];if(p&&!s.org){let A=He(E);if(A)s.org=A}if(S[1]===\"!TEXMAP\"){let A=(S[2]??\"\").toUpperCase();if(f=null,A===\"START\"||A===\"NEXT\"){let L=Lt(E.replace(/^!TEXMAP\\s+\\S+/i,\"\"),A===\"NEXT\");if(M.texmap={op:A,...L?{map:L}:{}},L)if((s.texmaps??=[]).push(L),A===\"START\")l.push({map:L,fallback:!1});else f=L}else if(A===\"FALLBACK\"){M.texmap={op:A};let L=l[l.length-1];if(L)L.fallback=!0}else if(A===\"END\")M.texmap={op:A},l.pop()}else if(S[1]===\"!:\"){f=null;let A=Ge(S.slice(2));if(A)P(A,!0),M.geom=A}else f=null;let x=E.match(Ve);if(x&&!s.movedTo){let A=x[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(A))A+=\".dat\";s.movedTo=q(A)}s.cmds.push(M);continue}if(a||C)continue;if(!s)y(t);let w=Ge(S);if(!w)continue;P(w,!1),s.cmds.push(w),p=!1}return g(),c?{main:i,files:o,data:c}:{main:i,files:o}}var Kt=Math.PI/180;function qe(e,t){let n=(r)=>[t[3]*r[0]+t[4]*r[1]+t[5]*r[2]+t[0],t[6]*r[0]+t[7]*r[1]+t[8]*r[2]+t[1],t[9]*r[0]+t[10]*r[1]+t[11]*r[2]+t[2]];return{...e,p1:n(e.p1),p2:n(e.p2),p3:n(e.p3)}}function Qe(e,t){let[n,r,o,s,i,c,a,l,f,g,p,y]=e,[C,u,m,P,b,d,S,k,w,E,M,x]=t;return[s*C+i*u+c*m+n,a*C+l*u+f*m+r,g*C+p*u+y*m+o,s*P+i*S+c*E,s*b+i*k+c*M,s*d+i*w+c*x,a*P+l*S+f*E,a*b+l*k+f*M,a*d+l*w+f*x,g*P+p*S+y*E,g*b+p*k+y*M,g*d+p*w+y*x]}var Pe=[0,0,0,1,0,0,0,1,0,0,0,1];var Xe=new WeakMap,Ft=/^(s|8|48)\\//;function Ee(e,t){let n=e.files.get(q(t));if(!n)return\"part\";let r=Xe.get(n);if(r)return r;if(n.org)r=Je.has(n.org)?\"part\":\"model\";else if(n.name===e.main)r=\"model\";else r=n.cmds.some((o)=>o.t>=2||o.t===0&&!!o.geom||o.t===1&&Ft.test(o.file))?\"part\":\"model\";return Xe.set(n,r),r}var We=new WeakMap;function et(e){let t=We.get(e);if(t)return t;t=[];let n=0;for(let r of e.cmds){if(r.t===0&&r.step){n++;continue}if((r.t>=2||r.t===0&&r.geom&&r.geom.t>=2)&&t[t.length-1]!==n)t.push(n)}return We.set(e,t),t}var _e=(e)=>e>16777215?\"0x\"+e.toString(16).toUpperCase():String(e),Rt=(e)=>e.t===0?\"0 \"+e.text:e.t===1?`1 ${_e(e.color)} ${e.m.join(\" \")} ${e.file}`:e.src?e.src:`${e.t} ${_e(e.color)} ${e.p.join(\" \")}`,Te=(e,t)=>`${q(e)}#${t}`;function Ut(e,t){let n=[],r=0,o=(s)=>!!s&&s.t===0&&s.texmap?.op===\"NEXT\";for(let s of e.cmds){if(s.t===0){if(s.step){r++;continue}if(s.bfc!==void 0){n.push(s);continue}if(r!==t)continue;if(s.texmap)n.push(s);else if(s.geom){if(s.geom.t>=2)n.push(s);else if(o(n[n.length-1]))n.pop()}continue}if(r!==t)continue;if(s.t===1){if(o(n[n.length-1]))n.pop();continue}n.push(s)}return{name:Te(e.name,t),cmds:n}}function tt(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...Ut(e,t).cmds.map(Rt)].join(`\n`)+`\n`}function Dt(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,\"0\")}function nt(e){let[t,n,r,o,s,i,c,a,l,f,g,p]=e,y=a*p-l*g,C=-(c*p-l*f),u=c*g-a*f,m=o*y+s*C+i*u;if(!Number.isFinite(m)||Math.abs(m)<0.000000000001)return null;let P=1/m,b=[y*P,-(s*p-i*g)*P,(s*l-i*a)*P,C*P,(o*p-i*f)*P,-(o*l-i*c)*P,u*P,-(o*g-s*f)*P,(o*a-s*c)*P];return[-(b[0]*t+b[1]*n+b[2]*r),-(b[3]*t+b[4]*n+b[5]*r),-(b[6]*t+b[7]*n+b[8]*r),...b]}var Ot=(e)=>String(+e.toFixed(6)||0),Ke=(e)=>'\"'+e.replace(/\\\\/g,\"\\\\\\\\\").replace(/\"/g,\"\\\\\\\"\")+'\"';function rt(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!==\"PLANAR\"?[t.a??360]:[],...t.method===\"SPHERICAL\"?[t.b??180]:[]].map(Ot).join(\" \"),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${Ke(t.texture)}${t.glossmap?\" GLOSSMAP \"+Ke(t.glossmap):\"\"}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${q(e)}\n0 !TEXMAP END\n`;return{name:`${q(e)}#tex-${Dt(r)}`,source:r}}var zt=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let o=0;o<3;o++)n[r*3+o]=e[r*3]*t[o]+e[r*3+1]*t[3+o]+e[r*3+2]*t[6+o];return n};function Bt(e,t,n){let r=Math.PI/180,o=Math.sin(e*r),s=Math.cos(e*r),i=Math.sin(t*r),c=Math.cos(t*r),a=Math.sin(n*r),l=Math.cos(n*r);return[c*l,-c*a,i,s*a+o*i*l,s*l-o*i*a,-o*c,o*a-s*i*l,o*l+s*i*a,s*c]}var Ye=new WeakMap;function ot(e){let t=Ye.get(e);if(t)return t;let n=[],r=null;for(let o of e.cmds){if(o.t!==0||!o.step)continue;let s=o.rotstep;if(s)if(s.mode===\"END\")r=null;else{let i=Bt(s.x,s.y,s.z);r=s.mode===\"ABS\"?{abs:!0,m:i,rotstep:s}:s.mode===\"ADD\"&&r?{abs:r.abs,m:zt(r.m,i),rotstep:s}:{abs:!1,m:i,rotstep:s}}n.push(r)}return n.push(r),Ye.set(e,n),n}function Nt(e,t={}){let n=[],r=t.maxDepth??64,o=t.looseGeometry!==!1,s=!!t.textures,i=new Map,c=(l,f)=>{let g=l.name+\"#\"+f,p=i.get(g);if(!p){let y;p=Object.assign(()=>y??=tt(l,f),{file:l,step:f}),i.set(g,p)}return p},a=(l,f,g,p,y,C,u,m)=>{let P=l.files.get(f);if(!P||u>r)return;let b=0,d=ot(P),S=o?et(P):[],k=0,w=(M,x,A,L,D,F,v)=>{let h={part:M,color:x,m:A,step:L[0],steps:L,localStep:D,path:y};if(F)h.embedded=!0;if(v){let R=rt(M,v);h.texPart=R.name,h.texSource=R.source}let T=d[D];if(T)h.view=T;return n.push(h),h},E=(M)=>{while(k<S.length&&S[k]<=M){let x=S[k++];w(Te(P.name,x),p,g,[...C,x],x,!1,null).source=c(P,x)}};for(let M of P.cmds){if(M.t===0&&M.step){b++;continue}let x=M;if(x.t>=2||x.t===0&&x.geom&&x.geom.t>=2){E(b);continue}if(x.t===0)if(s&&x.geom?.t===1)x=x.geom;else continue;if(x.t!==1)continue;if(s&&x.fallback)continue;let A=x.color===16?p:x.color,L=Qe(g,x.m),D=[...C,b],F=s?x.tex??m:null,v=F?nt(x.m):null,h=F&&v?qe(F,v):null;if(l.files.has(x.file)){if(Ee(l,x.file)===\"model\"){a(l,x.file,L,A,y+\"/\"+x.file,D,u+1,h);continue}w(x.file,A,L,D,b,!0,h);continue}let T=t.resolveModel?.(x.file);if(T){a(T,T.main,L,A,y+\"/\"+x.file,D,u+1,h);continue}w(x.file,A,L,D,b,!1,h)}E(1/0)};if(Ee(e,e.main)===\"part\"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Pe],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return a(e,e.main,Pe,16,e.main,[],0,null),n}function st(e,t=\"main.ldr\",n){return Nt(Ze(e,t,{geometryText:!0}),n)}var it=(e,t=0)=>Math.abs(e[t+7]-1)<0.001&&Math.abs(e[t+4])<0.001&&Math.abs(e[t+10])<0.001,at=new WeakMap;function Le(e,t){let n=at.get(e);if(!n)at.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let o=e.parts[t];if(!o)return n.set(t,null),null;let s=o.studs.length,i=new Float64Array(s*12),c=[],a=[];o.studs.forEach((p,y)=>{c.push(p[0]),a.push(p[1]);for(let C=0;C<12;C++)i[y*12+C]=p[2+C]});let l=null,f=0,g=0;if(o.mask){f=o.mask[0],g=o.mask[1];let p=o.mask[2];l=new Uint8Array(p.length);for(let y=0;y<p.length;y++)l[y]=p.charCodeAt(y)===49?1:0}return n.set(t,r={nStuds:s,studM:i,kind:c,color:a,mask:l,nx:f,nz:g}),r}var ie=1073741824;class Ie{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),o=this.used,s=this.a,i=this.b,c=this.c;for(;;){if(!o[r])return-1;if(s[r]===e&&i[r]===t&&c[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let o=this.slot(e,t,n),s=this.used,i=this.a,c=this.b,a=this.c;for(;;){if(!s[o])return s[o]=1,i[o]=e,c[o]=t,a[o]=n,this.vals[o]=r,this.size++,-1;if(i[o]===e&&c[o]===t&&a[o]===n){let l=this.vals[o];return this.vals[o]=r,l}o=o+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:o}=this,s=o.length*2;this.a=new Int32Array(s),this.b=new Int32Array(s),this.c=new Int32Array(s),this.vals=new Int32Array(s),this.used=new Uint8Array(s),this.mask=s-1,this.size=0;for(let i=0;i<o.length;i++)if(o[i])this.put(e[i],t[i],n[i],r[i])}}var ye=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function $t(e,t,n){let o=[],s=[],i=[],c=[],a=[],l=[],f=[],g=[],p=new Ie(e.length*2),y=[],C=[];for(let v=0;v<e.length;v++){let h=e[v],T=h.m,R=t.parts[h.part];if(!R||!R.mask||!it(T))continue;let I=R.bbox,U=1/0,O=-1/0,K=1/0,H=-1/0;for(let N=0;N<2;N++)for(let G=0;G<2;G++){let X=N?I[3]:I[0],Y=G?I[5]:I[2],W=T[0]+T[3]*X+T[5]*Y,_=T[2]+T[9]*X+T[11]*Y;if(W<U)U=W;if(W>O)O=W;if(_<K)K=_;if(_>H)H=_}let z=a.length;o.push(U),s.push(O),i.push(K),c.push(H),a.push(v),l.push(Le(t,h.part)),f.push(I[0]),g.push(I[2]);let B=Math.round((T[1]+I[4])*2);for(let N=Math.floor(U/40);N<=Math.floor(O/40);N++)for(let G=Math.floor(K/40);G<=Math.floor(H/40);G++){if(!ye(B,N,G))continue;let X=C.length;C.push(z),y.push(p.put(B,N,G,X))}}let u=[0,5,-5,5,-5],m=[0,5,5,-5,-5],P=NaN,b=NaN,d=NaN,S=-1,k=(v,h,T,R)=>{let I=Math.round(h*2),U=Math.floor(v/40),O=Math.floor(T/40);if(!ye(I,U,O))return fe;let K=fe;if(I!==P||U!==b||O!==d)P=I,b=U,d=O,S=p.get(I,U,O);for(let H=S;H>=0;H=y[H]){let z=C[H];if(a[z]===R||!(v-6>=o[z]-0.5&&v+6<=s[z]+0.5&&T-6>=i[z]-0.5&&T+6<=c[z]+0.5))continue;let B=e[a[z]].m,N=l[z],G=f[z],X=g[z],Y=v-B[0],W=h-B[1],_=T-B[2],Z=B[3]*Y+B[6]*W+B[9]*_,J=B[5]*Y+B[8]*W+B[11]*_,{nx:ee,nz:oe,mask:ae}=N,se=!0;for(let Q=0;Q<5;Q++){let te=Math.floor((Z+u[Q]-G)/20),ne=Math.floor((J+m[Q]-X)/20);if(te<0||ne<0||te>=ee||ne>=oe||ae[te*oe+ne]!==1){se=!1;break}}if(se){if(!n)return 0;let Q=n[a[z]];if(Q<K)K=Q}}return K},w=0;for(let v of e){let h=Le(t,v.part);if(h)w+=h.nStuds}let E=new Uint8Array(w),M=new Uint8Array(w),x=new Ie(w),A=0,L=n?new Int32Array(w).fill(fe):void 0;for(let v=0,h=0;v<e.length;v++){let T=e[v],R=Le(t,T.part);if(!R)continue;let I=T.m,U=R.studM,O=I[0],K=I[1],H=I[2],z=I[3],B=I[4],N=I[5],G=I[6],X=I[7],Y=I[8],W=I[9],_=I[10],Z=I[11];for(let J=0;J<R.nStuds;J++,h++){let ee=J*12,oe=U[ee+4],ae=U[ee+7],se=U[ee+10];if(!(Math.abs(G*oe+X*ae+Y*se-1)<0.001&&Math.abs(z*oe+B*ae+N*se)<0.001&&Math.abs(W*oe+_*ae+Z*se)<0.001))continue;M[h]=1;let Q=U[ee],te=U[ee+1],ne=U[ee+2],Re=O+z*Q+B*te+N*ne,Ue=K+G*Q+X*te+Y*ne,De=H+W*Q+_*te+Z*ne,Oe=k(Re,Ue,De,v);if(Oe!==fe){if(E[h]=1,A++,L)L[h]=Oe}let pe=Math.round(Re),me=Math.round(Ue),he=Math.round(De);if(!ye(pe,me,he))continue;if(!n){x.put(pe,me,he,1);continue}let ze=n[v],Be=x.get(pe,me,he);if(Be<0||ze<Be)x.put(pe,me,he,ze)}}let D=new Uint8Array(e.length),F=n?new Int32Array(e.length).fill(fe):void 0;for(let v=0;v<e.length;v++){let h=e[v],T=t.parts[h.part];if(!T||!T.under||!it(h.m))continue;let R=T.bbox,I=Math.round((R[3]-R[0])/20),U=Math.round((R[5]-R[2])/20);if(!I||!U||I*U>4096)continue;let O=h.m,K=!0,H=0;for(let z=0;z<I&&K;z++)for(let B=0;B<U;B++){let N=R[0]+10+20*z,G=R[2]+10+20*B,X=O[0]+O[3]*N+O[5]*G,Y=O[2]+O[9]*N+O[11]*G,W=Math.round(X),_=Math.round(O[1]+R[4]),Z=Math.round(Y),J=ye(W,_,Z)?x.get(W,_,Z):-1;if(J<0){K=!1;break}if(J>H)H=J}if(K){if(D[v]=1,F)F[v]=H}}return{nStuds:w,studHidden:E,studUp:M,underHidden:D,studsHidden:A,studHideStep:L,underHideStep:F}}function jt(e,t,n){let r=(a)=>n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,o=e.map((a)=>({part:r(a),color:String(a.color),m:a.m,steps:a.steps})),s=o.map((a)=>a.steps.map((l)=>String(l).padStart(6,\"0\")).join(\".\")),i=[...new Set(s)].sort(),c=new Map(i.map((a,l)=>[a,l]));return{all:o,stepOf:s.map((a)=>c.get(a)),nSteps:i.length}}function xe(e,t,n=!0){let r=jt(e,t,n);return $t(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Fe=\"https://ldr-demo.vercel.app/cdn/v1/\",ke=new Map,we=new Map;function lt(e=Fe,t=fetch){let n=ke.get(e);if(!n)n=t(e+\"parts.json\").then((r)=>{if(!r.ok)throw Error(`ldr: parts CDN index ${r.status} (${e}parts.json)`);return r.json()}),n.catch(()=>ke.delete(e)),ke.set(e,n);return n}var Vt=(e)=>Array.isArray(e)&&e.length===3&&typeof e[0]===\"number\"&&typeof e[1]===\"number\"&&(e[2]===\"f32\"||e[2]===\"u16\"||e[2]===\"u8\"||e[2]===\"u32\"),ve=(e,t)=>Vt(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>ve(n,t)):e&&typeof e===\"object\"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,ve(r,t)])):e;function Ht(e,t={}){let n=[],r=0,o={},s={};for(let p of e){let y=p.buffer;if(!y)throw Error(\"ldr: mergePacks needs packs from decodePack/loadPack\");let C=new DataView(y).getUint32(0,!0),u=new Uint8Array(y,4+C),m=r;n.push(u),r+=u.byteLength;let P=(4-r%4)%4;if(P)n.push(new Uint8Array(P)),r+=P;for(let[b,d]of Object.entries(p.header.parts??{}))if(!(b in o))o[b]=ve(d,m);for(let[b,d]of Object.entries(p.header.studKinds??{}))if(!(b in s))s[b]=ve(d,m)}let i=e[0]?.header??{version:1,weld:!0},c=new TextEncoder().encode(JSON.stringify({...i,parts:o,studKinds:s,...t})),a=(4-(4+c.length)%4)%4,l=4+c.length+a,f=new Uint8Array(l+r);new DataView(f.buffer).setUint32(0,c.length+a,!0),f.set(c,4),f.fill(32,4+c.length,l);let g=l;for(let p of n)f.set(p,g),g+=p.byteLength;return de(f.buffer)}async function Gt(e,t={}){let n=t.cdn??Fe,r=t.fetch??fetch,o=t.gap??16384,s=await lt(n,r),i=[...new Set([...e].map(q))],c=[],a=[];for(let u of i){if(we.has(n+u))continue;let m=s.parts[u];if(m)a.push({name:u,off:m[0],len:m[1],file:m[2]??0});else c.push(u)}a.sort((u,m)=>u.file-m.file||u.off-m.off);let l=[];for(let u of a){let m=l[l.length-1];if(m&&m.file===u.file&&u.off-m.end<=o)m.end=Math.max(m.end,u.off+u.len),m.items.push(u);else l.push({file:u.file,start:u.off,end:u.off+u.len,items:[u]})}let f=0,g=0,p=async()=>{while(g<l.length){let u=l[g++],m=await r(new URL(s.archives[u.file],n).href,{headers:{Range:`bytes=${u.start}-${u.end-1}`}});if(!m.ok)throw Error(`ldr: parts CDN ${m.status}`);let P=new Uint8Array(await m.arrayBuffer());if(m.status===200)P=P.subarray(u.start,u.end);f+=P.byteLength;for(let b of u.items){let d=je(P.subarray(b.off-u.start,b.off-u.start+b.len)),S=d.buffer.slice(d.byteOffset,d.byteOffset+d.byteLength);we.set(n+b.name,de(S))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,l.length)},p));let y=i.filter((u)=>we.has(n+u)).map((u)=>we.get(n+u));return{pack:y.length?Ht(y,{colors:s.colors}):de(Xt(s.colors)),missing:c,requests:l.length,bytes:f}}function Xt(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}async function ct(e,t={}){let n=performance.now(),r=t.fetch??fetch,o=lt(t.cdn??Fe,r);o.catch(()=>{});let s=t.text?e:await r(e).then((m)=>{if(!m.ok)throw Error(`ldr: ${m.status} fetching ${e}`);return m.text()}),i=performance.now(),c=t.name??(t.text?\"main.ldr\":decodeURIComponent(e.split(/[?#]/)[0].split(\"/\").pop()||\"main.ldr\")),a=st(s,c,{looseGeometry:!1}),l=performance.now();t.onParsed?.(a),await o;let{pack:f,missing:g,requests:p,bytes:y}=await Gt(a.filter((m)=>!m.embedded).map((m)=>m.part),t),C=performance.now(),u=t.cull?xe(a,f.header,t.textures!==!1):void 0;return{insts:a,pack:f,missing:g,requests:p,bytes:y,cull:u,timings:{fetchModel:i-n,parse:l-i,parts:C-l,...u?{cull:performance.now()-C}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let o=await ct(n,{...r,cull:!1,onParsed:(f)=>self.postMessage({id:t,insts:f})}),s=o.pack.buffer;if(self.postMessage({id:t,buffer:s,missing:o.missing,requests:o.requests,bytes:o.bytes,timings:o.timings},[s]),!r.cull)return;let i=performance.now(),c=xe(o.insts,o.pack.header,r.textures!==!1),a=performance.now()-i,l=[];for(let f of[c.studHidden,c.studUp,c.underHidden,c.studHideStep,c.underHideStep])if(f)l.push(f.buffer);self.postMessage({id:t,cull:c,ms:a},l)}catch(o){self.postMessage({id:t,phase:\"error\",error:String(o?.message??o)})}};\n";
|
|
1
|
+
declare const _default: "var mt=ArrayBuffer,_=Uint8Array,ge=Uint16Array,ht=Int16Array;var be=Int32Array,Se=function(e,t,n){if(_.prototype.slice)return _.prototype.slice.call(e,t,n);if(t==null||t<0)t=0;if(n==null||n>e.length)n=e.length;var r=new _(n-t);return r.set(e.subarray(t,n)),r},ce=function(e,t,n,r){if(_.prototype.fill)return _.prototype.fill.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;for(;n<r;++n)e[n]=t;return e},gt=function(e,t,n,r){if(_.prototype.copyWithin)return _.prototype.copyWithin.call(e,t,n,r);if(n==null||n<0)n=0;if(r==null||r>e.length)r=e.length;while(n<r)e[t++]=e[n++]};var bt=[\"invalid zstd data\",\"window size too large (>2046MB)\",\"invalid block type\",\"FSE accuracy too high\",\"match distance too far back\",\"unexpected EOF\"],K=function(e,t,n){var r=Error(t||bt[e]);if(r.code=e,Error.captureStackTrace)Error.captureStackTrace(r,K);if(!n)throw r;return r},Ne=function(e,t,n){var r=0,o=0;for(;r<n;++r)o|=e[t++]<<(r<<3);return o},yt=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},dt=function(e,t){var n=e[0]|e[1]<<8|e[2]<<16;if(n==3126568&&e[3]==253){var r=e[4],o=r>>5&1,s=r>>2&1,i=r&3,c=r>>6;if(r&8)K(0);var a=6-o,l=i==3?4:i,f=Ne(e,a,l);a+=l;var p=c?1<<c:o,m=Ne(e,a,p)+(c==1&&256),b=m;if(!o){var A=1<<10+(e[5]>>3);b=A+(A>>3)*(e[5]&7)}if(b>2145386496)K(1);var u=new _((t==1?m||b:t?0:b)+12);return u[0]=1,u[4]=4,u[8]=8,{b:a+p,y:0,l:0,d:f,w:t&&t!=1?t:u.subarray(12),e:b,o:new be(u.buffer,0,3),u:m,c:s,m:Math.min(131072,b)}}else if((n>>4|e[3]<<20)==25481893)return yt(e,4)+8;K(0)},re=function(e){var t=0;for(;1<<t<=e;++t);return t-1},ue=function(e,t,n){var r=(t<<3)+4,o=(e[t]&15)+5;if(o>n)K(3);var s=1<<o,i=s,c=-1,a=-1,l=-1,f=s,p=new mt(512+(s<<2)),m=new ht(p,0,256),b=new ge(p,0,256),A=new ge(p,512,s),u=512+(s<<1),h=new _(p,u,s),E=new _(p,u+s);while(c<255&&i>0){var y=re(i+1),g=r>>3,C=(1<<y+1)-1,B=(e[g]|e[g+1]<<8|e[g+2]<<16)>>(r&7)&C,d=(1<<y)-1,M=C-i-1,P=B&d;if(P<M)r+=y,B=P;else if(r+=y+1,B>d)B-=M;if(m[++c]=--B,B==-1)i+=B,h[--f]=c;else i-=B;if(!B)do{var F=r>>3;a=(e[F]|e[F+1]<<8)>>(r&7)&3,r+=2,c+=a}while(a==3)}if(c>255||i)K(0);var S=0,U=(s>>1)+(s>>3)+3,W=s-1;for(var H=0;H<=c;++H){var v=m[H];if(v<1){b[H]=-v;continue}for(l=0;l<v;++l){h[S]=H;do S=S+U&W;while(S>=f)}}if(S)K(0);for(l=0;l<s;++l){var w=b[h[l]]++,L=E[l]=o-re(w);A[l]=(w<<L)-s}return[r+7>>3,{b:o,s:h,n:E,t:A}]},xt=function(e,t){var n=0,r=-1,o=new _(292),s=e[t],i=o.subarray(0,256),c=o.subarray(256,268),a=new ge(o.buffer,268);if(s<128){var l=ue(e,t+1,6),f=l[0],p=l[1];t+=s;var m=f<<3,b=e[t];if(!b)K(0);var A=0,u=0,h=p.b,E=h,y=(++t<<3)-8+re(b);for(;;){if(y-=h,y<m)break;var g=y>>3;if(A+=(e[g]|e[g+1]<<8)>>(y&7)&(1<<h)-1,i[++r]=p.s[A],y-=E,y<m)break;g=y>>3,u+=(e[g]|e[g+1]<<8)>>(y&7)&(1<<E)-1,i[++r]=p.s[u],h=p.n[A],A=p.t[A],E=p.n[u],u=p.t[u]}if(++r>255)K(0)}else{r=s-127;for(;n<r;n+=2){var C=e[++t];i[n]=C>>4,i[n+1]=C&15}++t}var B=0;for(n=0;n<r;++n){var d=i[n];if(d>11)K(0);B+=d&&1<<d-1}var M=re(B)+1,P=1<<M,F=P-B;if(F&F-1)K(0);i[r++]=re(F)+1;for(n=0;n<r;++n){var d=i[n];++c[i[n]=d&&M+1-d]}var S=new _(P<<1),U=S.subarray(0,P),W=S.subarray(P);a[M]=0;for(n=M;n>0;--n){var H=a[n];ce(W,n,H,a[n-1]=H+c[n]*(1<<M-n))}if(a[0]!=P)K(0);for(n=0;n<r;++n){var v=i[n];if(v){var w=a[v];ce(U,n,w,a[v]=w+(1<<M-v))}}return[t,{n:W,b:M,s:U}]},wt=ue(new _([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],vt=ue(new _([33,20,196,24,99,140,33,132,16,66,8,33,132,16,66,8,33,68,68,68,68,68,68,68,68,36,9]),0,6)[1],At=ue(new _([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],$e=function(e,t){var n=e.length,r=new be(n);for(var o=0;o<n;++o)r[o]=t,t+=1<<e[o];return r},Ce=new _(new be([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),Mt=$e(Ce,0),Pe=new _(new be([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),St=$e(Pe,3),le=function(e,t,n){var r=e.length,o=t.length,s=e[r-1],i=(1<<n.b)-1,c=-n.b;if(!s)K(0);var a=0,l=n.b,f=(r<<3)-8+re(s)-l,p=-1;for(;f>c&&p<o;){var m=f>>3,b=(e[m]|e[m+1]<<8|e[m+2]<<16)>>(f&7);a=(a<<l|b)&i,t[++p]=n.s[a],f-=l=n.n[a]}if(f!=c||p+1!=o)K(0)},Ct=function(e,t,n){var r=6,o=t.length,s=o+3>>2,i=s<<1,c=s+i;le(e.subarray(r,r+=e[0]|e[1]<<8),t.subarray(0,s),n),le(e.subarray(r,r+=e[2]|e[3]<<8),t.subarray(s,i),n),le(e.subarray(r,r+=e[4]|e[5]<<8),t.subarray(i,c),n),le(e.subarray(r),t.subarray(c),n)},Pt=function(e,t,n){var r,o=t.b,s=e[o],i=s>>1&3;t.l=s&1;var c=s>>3|e[o+1]<<5|e[o+2]<<13,a=(o+=3)+c;if(i==1){if(o>=e.length)return;if(t.b=o+1,n)return ce(n,e[o],t.y,t.y+=c),n;return ce(new _(c),e[o])}if(a>e.length)return;if(i==0){if(t.b=a,n)return n.set(e.subarray(o,a),t.y),t.y+=c,n;return Se(e,o,a)}if(i==2){var l=e[o],f=l&3,p=l>>2&3,m=l>>4,b=0,A=0;if(f<2)if(p&1)m|=e[++o]<<4|(p&2&&e[++o]<<12);else m=l>>3;else if(A=p,p<2)m|=(e[++o]&63)<<4,b=e[o]>>6|e[++o]<<2;else if(p==2)m|=e[++o]<<4|(e[++o]&3)<<12,b=e[o]>>2|e[++o]<<6;else m|=e[++o]<<4|(e[++o]&63)<<12,b=e[o]>>6|e[++o]<<2|e[++o]<<10;++o;var u=n?n.subarray(t.y,t.y+t.m):new _(t.m),h=u.length-m;if(f==0)u.set(e.subarray(o,o+=m),h);else if(f==1)ce(u,e[o++],h);else{var E=t.h;if(f==2){var y=xt(e,o);b+=o-(o=y[0]),t.h=E=y[1]}else if(!E)K(0);(A?Ct:le)(e.subarray(o,o+=b),u.subarray(h),E)}var g=e[o++];if(g){if(g==255)g=(e[o++]|e[o++]<<8)+32512;else if(g>127)g=g-128<<8|e[o++];var C=e[o++];if(C&3)K(0);var B=[vt,At,wt];for(var d=2;d>-1;--d){var M=C>>(d<<1)+2&3;if(M==1){var P=new _([0,0,e[o++]]);B[d]={s:P.subarray(2,3),n:P.subarray(0,1),t:new ge(P.buffer,0,1),b:0}}else if(M==2)r=ue(e,o,9-(d&1)),o=r[0],B[d]=r[1];else if(M==3){if(!t.t)K(0);B[d]=t.t[d]}}var F=t.t=B,S=F[0],U=F[1],W=F[2],H=e[a-1];if(!H)K(0);var v=(a<<3)-8+re(H)-W.b,w=v>>3,L=0,V=(e[w]|e[w+1]<<8)>>(v&7)&(1<<W.b)-1;w=(v-=U.b)>>3;var I=(e[w]|e[w+1]<<8)>>(v&7)&(1<<U.b)-1;w=(v-=S.b)>>3;var N=(e[w]|e[w+1]<<8)>>(v&7)&(1<<S.b)-1;for(++g;--g;){var T=W.s[V],x=W.n[V],z=S.s[N],R=S.n[N],D=U.s[I],O=U.n[I];w=(v-=D)>>3;var j=1<<D,k=j+((e[w]|e[w+1]<<8|e[w+2]<<16|e[w+3]<<24)>>>(v&7)&j-1);w=(v-=Pe[z])>>3;var G=St[z]+((e[w]|e[w+1]<<8|e[w+2]<<16)>>(v&7)&(1<<Pe[z])-1);w=(v-=Ce[T])>>3;var X=Mt[T]+((e[w]|e[w+1]<<8|e[w+2]<<16)>>(v&7)&(1<<Ce[T])-1);if(w=(v-=x)>>3,V=W.t[V]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<x)-1),w=(v-=R)>>3,N=S.t[N]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<R)-1),w=(v-=O)>>3,I=U.t[I]+((e[w]|e[w+1]<<8)>>(v&7)&(1<<O)-1),k>3)t.o[2]=t.o[1],t.o[1]=t.o[0],t.o[0]=k-=3;else{var Y=k-(X!=0);if(Y){if(k=Y==3?t.o[0]-1:t.o[Y],Y>1)t.o[2]=t.o[1];t.o[1]=t.o[0],t.o[0]=k}else k=t.o[0]}for(var d=0;d<X;++d)u[L+d]=u[h+d];L+=X,h+=X;var Z=L-k;if(Z<0){var J=-Z,ee=t.e+Z;if(J>G)J=G;for(var d=0;d<J;++d)u[L+d]=t.w[ee+d];L+=J,G-=J,Z=0}for(var d=0;d<G;++d)u[L+d]=u[Z+d];L+=G}if(L!=h)while(h<u.length)u[L++]=u[h++];else L=u.length;if(n)t.y+=L;else u=Se(u,0,L)}else if(n){if(t.y+=m,h)for(var d=0;d<m;++d)u[d]=u[h+d]}else if(h)u=Se(u,h);return t.b=a,u}K(2)},Et=function(e,t){if(e.length==1)return e[0];var n=new _(t);for(var r=0,o=0;r<e.length;++r){var s=e[r];n.set(s,o),o+=s.length}return n};function je(e,t){var n=[],r=+!t,o=0,s=0;for(;e.length;){var i=dt(e,r||t);if(typeof i==\"object\"){if(r){if(t=null,i.w.length==i.u)n.push(t=i.w),s+=i.u}else n.push(t),i.e=0;for(;!i.l;){var c=Pt(e,i,t);if(!c)K(5);if(t)i.e=i.y;else n.push(c),s+=c.length,gt(i.w,0,c.length),i.w.set(c,i.w.length-c.length)}o=i.b+i.c*4}else o=i;e=e.subarray(o)}return Et(n,s)}function ye(e){let t=new DataView(e).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(e,4,t))),r=4+t;return{header:n,arr:(s)=>s&&(s[2]===\"f32\"?new Float32Array(e,r+s[0],s[1]):s[2]===\"u16\"?new Uint16Array(e,r+s[0],s[1]):s[2]===\"u8\"?new Uint8Array(e,r+s[0],s[1]):new Uint32Array(e,r+s[0],s[1])),bytes:e.byteLength,buffer:e}}var q=(e)=>e.trim().toLowerCase().replace(/\\\\/g,\"/\").replace(/\\/+/g,\"/\");function Ee(e){if(/^0x/i.test(e))return parseInt(e,16);return+e}var Ve=/^~?\\s*moved\\s+to\\s+(.+)$/i,Tt=new Set([\"FILE\",\"NOFILE\",\"!DATA\",\"!:\",\"STEP\",\"BFC\",\"ROTSTEP\",\"BUFEXCHG\",\"!TEXMAP\"]),Je=new Set([\"part\",\"subpart\",\"primitive\",\"8_primitive\",\"48_primitive\",\"shortcut\",\"helper\"]),Lt=new Set([\"model\",\"submodel\",\"configuration\"]),It=/^(?:!?LDRAW_ORG|Unofficial|Official\\s+LCAD)\\s+(\\S+)/i;function He(e){let t=It.exec(e);if(!t)return;let n=t[1].toLowerCase().replace(/^unofficial_/,\"\");return Je.has(n)||Lt.has(n)?n:void 0}function kt(e){let t=[],n=0;while(n<e.length){while(e[n]===\" \"||e[n]===\"\\t\")n++;if(n>=e.length)break;if(e[n]==='\"'){let r=\"\";n++;while(n<e.length&&e[n]!=='\"'){if(e[n]===\"\\\\\"&&n+1<e.length)n++;r+=e[n++]}n++,t.push(r)}else{let r=n;while(r<e.length&&e[r]!==\" \"&&e[r]!==\"\\t\")r++;t.push(e.slice(n,r)),n=r}}return t}function Rt(e,t=!1){let n=/^\\s*(\\S+)\\s+(.*)$/.exec(e);if(!n)return null;let r=n[1].toUpperCase(),o=r===\"PLANAR\"?9:r===\"CYLINDRICAL\"?10:r===\"SPHERICAL\"?11:0;if(!o)return null;let s=n[2].trim().split(/\\s+/);if(s.length<o+1)return null;let i=s.slice(0,o).map(Number);if(!i.every(Number.isFinite))return null;let c=n[2].trim();for(let p=0;p<o;p++)c=c.replace(/^\\S+\\s*/,\"\");let a=kt(c);if(!a.length)return null;let l={method:r,p1:i.slice(0,3),p2:i.slice(3,6),p3:i.slice(6,9),texture:a[0]};if(o>=10)l.a=i[9];if(o===11)l.b=i[10];let f=a.findIndex((p,m)=>m>0&&p.toUpperCase()===\"GLOSSMAP\");if(f>0&&a[f+1])l.glossmap=a[f+1];if(t)l.next=!0;return l}var Dt=(e)=>{let t=e.replace(/[^A-Za-z0-9+/]/g,\"\"),n=t+\"=\".repeat((4-t.length%4)%4),r=atob(n),o=new Uint8Array(r.length);for(let s=0;s<r.length;s++)o[s]=r.charCodeAt(s);return o};function Ft(e){let t=e.length,n=1,r=(l)=>l===32||l===9,o=()=>{while(n<t&&r(e.charCodeAt(n)))n++;let l=n;while(n<t&&!r(e.charCodeAt(n)))n++;return l<n?e.slice(l,n):null},s=o();if(s===null)return null;let i=Array(12);for(let l=0;l<12;l++){let f=o();if(f===null)return null;i[l]=+f}while(n<t&&r(e.charCodeAt(n)))n++;if(n>=t)return null;let c=e.slice(n),a=/[ \\t]{2,}|\\t/.test(c)?c.split(/\\s+/).join(\" \"):c;return{t:1,color:Ee(s),m:i,file:q(a)}}function Ge(e){let t=+e[0];if(!(t>=1&&t<=5)||e.length<2)return null;let n=Ee(e[1]),r=e.slice(2).map(Number);if(t===1)return{t:1,color:n,m:r.slice(0,12),file:q(e.slice(14).join(\" \"))};if(t===2)return{t:2,color:n,p:r.slice(0,6)};if(t===3)return{t:3,color:n,p:r.slice(0,9)};if(t===4)return{t:4,color:n,p:r.slice(0,12)};return{t:5,color:n,p:r.slice(0,12)}}function Ze(e,t=\"main.ldr\",n={}){let r=!!n.geometryText,o=new Map,s=null,i=\"\",c,a=null,l=[],f=null,p=()=>{if(!a)return;let y=Dt(a.chunks.join(\"\")),g=y[0]===137&&y[1]===80&&y[2]===78&&y[3]===71;(c??=new Map).set(q(a.name),{name:a.name,bytes:y,...g?{mime:\"image/png\"}:{}}),a=null},m=!0,b=(y)=>{if(p(),s={name:q(y),cmds:[]},o.set(s.name,s),!i)i=s.name;l=[],f=null,m=!0},A=!1,u=!1,h=()=>{if(u)return;u=!0,o.clear(),s=null,i=\"\"},E=(y,g)=>{if(f){y.tex=f,f=null;return}let C=l[l.length-1];if(!C)return;if(C.fallback){if(!g)y.fallback=!0}else y.tex=C.map};for(let y of e.split(`\n`)){let g=y.trim();if(!g)continue;if(r&&g.charCodeAt(0)>=50&&g.charCodeAt(0)<=53&&(g.charCodeAt(1)===32||g.charCodeAt(1)===9)){if(a||A)continue;if(!s)b(t);let M=g.slice(2).trimStart(),P=M.search(/\\s/),F={t:g.charCodeAt(0)-48,color:Ee(P<0?M:M.slice(0,P)),p:[],src:g};E(F,!1),s.cmds.push(F),m=!1;continue}if(g.charCodeAt(0)===48&&(g.charCodeAt(1)===32||g.charCodeAt(1)===9)){let M=2;while(g.charCodeAt(M)===32||g.charCodeAt(M)===9)M++;let P=M;while(P<g.length&&g.charCodeAt(P)!==32&&g.charCodeAt(P)!==9)P++;let F=g.slice(M,P);if(!Tt.has(F)){if(A||a)continue;if(!s)b(t);let S=g.slice(M),U={t:0,text:S};if(F.charCodeAt(0)===33)U.meta=F;if(f=null,m&&!s.org){let H=He(S);if(H)s.org=H}let W=S.match(Ve);if(W&&!s.movedTo){let H=W[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(H))H+=\".dat\";s.movedTo=q(H)}s.cmds.push(U);continue}}if(g.charCodeAt(0)===49&&(g.charCodeAt(1)===32||g.charCodeAt(1)===9)&&!a&&!A){let M=Ft(g);if(M){if(!s)b(t);E(M,!1),s.cmds.push(M),m=!1;continue}}let C=g.split(/\\s+/);if(+C[0]===0){let M=g.slice(1).trim();if(C[1]===\"FILE\"){h(),A=!1,b(M.slice(5));continue}if(C[1]===\"NOFILE\"){p(),s=null,A=!0;continue}if(C[1]===\"!DATA\"){h(),p(),s=null,A=!1,a={name:M.slice(5).trim(),chunks:[]};continue}if(A)continue;if(a){if(C[1]===\"!:\")a.chunks.push(C.slice(2).join(\"\"));continue}if(!s)b(t);let P={t:0,text:M};if(C[1]===\"STEP\")P.step=!0,l=[],f=null;else if(C[1]===\"BFC\")P.bfc=C.slice(2).join(\" \");else if(C[1]===\"ROTSTEP\")if(P.meta=\"ROTSTEP\",P.step=!0,l=[],f=null,(C[2]??\"\").toUpperCase()===\"END\")P.rotstep={x:0,y:0,z:0,mode:\"END\"};else{let S=(C[5]??\"REL\").toUpperCase();P.rotstep={x:+C[2]||0,y:+C[3]||0,z:+C[4]||0,mode:[\"REL\",\"ABS\",\"ADD\"].includes(S)?S:\"REL\"}}else if(C[1]===\"BUFEXCHG\"){P.meta=\"BUFEXCHG\";let S=(C[2]??\"\").toUpperCase();P.bufexchg={op:S===\"RETRIEVE\"?\"RETRIEVE\":\"STORE\",buf:C[3]??\"A\"}}else if(C[1]?.startsWith(\"!\"))P.meta=C[1];if(m&&!s.org){let S=He(M);if(S)s.org=S}if(C[1]===\"!TEXMAP\"){let S=(C[2]??\"\").toUpperCase();if(f=null,S===\"START\"||S===\"NEXT\"){let U=Rt(M.replace(/^!TEXMAP\\s+\\S+/i,\"\"),S===\"NEXT\");if(P.texmap={op:S,...U?{map:U}:{}},U)if((s.texmaps??=[]).push(U),S===\"START\")l.push({map:U,fallback:!1});else f=U}else if(S===\"FALLBACK\"){P.texmap={op:S};let U=l[l.length-1];if(U)U.fallback=!0}else if(S===\"END\")P.texmap={op:S},l.pop()}else if(C[1]===\"!:\"){f=null;let S=Ge(C.slice(2));if(S)E(S,!0),P.geom=S}else f=null;let F=M.match(Ve);if(F&&!s.movedTo){let S=F[1].trim().replace(/\\\\/g,\"/\");if(!/\\.(dat|ldr|mpd)$/i.test(S))S+=\".dat\";s.movedTo=q(S)}s.cmds.push(P);continue}if(a||A)continue;if(!s)b(t);let d=Ge(C);if(!d)continue;E(d,!1),s.cmds.push(d),m=!1}return p(),c?{main:i,files:o,data:c}:{main:i,files:o}}var Zt=Math.PI/180;function qe(e,t){let n=(r)=>[t[3]*r[0]+t[4]*r[1]+t[5]*r[2]+t[0],t[6]*r[0]+t[7]*r[1]+t[8]*r[2]+t[1],t[9]*r[0]+t[10]*r[1]+t[11]*r[2]+t[2]];return{...e,p1:n(e.p1),p2:n(e.p2),p3:n(e.p3)}}function Qe(e,t){let[n,r,o,s,i,c,a,l,f,p,m,b]=e,[A,u,h,E,y,g,C,B,d,M,P,F]=t;return[s*A+i*u+c*h+n,a*A+l*u+f*h+r,p*A+m*u+b*h+o,s*E+i*C+c*M,s*y+i*B+c*P,s*g+i*d+c*F,a*E+l*C+f*M,a*y+l*B+f*P,a*g+l*d+f*F,p*E+m*C+b*M,p*y+m*B+b*P,p*g+m*d+b*F]}var Te=[0,0,0,1,0,0,0,1,0,0,0,1];var Xe=new WeakMap,Ut=/^(s|8|48)\\//;function Le(e,t){let n=e.files.get(q(t));if(!n)return\"part\";let r=Xe.get(n);if(r)return r;if(n.org)r=Je.has(n.org)?\"part\":\"model\";else if(n.name===e.main)r=\"model\";else r=n.cmds.some((o)=>o.t>=2||o.t===0&&!!o.geom||o.t===1&&Ut.test(o.file))?\"part\":\"model\";return Xe.set(n,r),r}var _e=new WeakMap;function et(e){let t=_e.get(e);if(t)return t;t=[];let n=0;for(let r of e.cmds){if(r.t===0&&r.step){n++;continue}if((r.t>=2||r.t===0&&r.geom&&r.geom.t>=2)&&t[t.length-1]!==n)t.push(n)}return _e.set(e,t),t}var Ke=(e)=>e>16777215?\"0x\"+e.toString(16).toUpperCase():String(e),Ot=(e)=>e.t===0?\"0 \"+e.text:e.t===1?`1 ${Ke(e.color)} ${e.m.join(\" \")} ${e.file}`:e.src?e.src:`${e.t} ${Ke(e.color)} ${e.p.join(\" \")}`,Ie=(e,t)=>`${q(e)}#${t}`;function zt(e,t){let n=[],r=0,o=(s)=>!!s&&s.t===0&&s.texmap?.op===\"NEXT\";for(let s of e.cmds){if(s.t===0){if(s.step){r++;continue}if(s.bfc!==void 0){n.push(s);continue}if(r!==t)continue;if(s.texmap)n.push(s);else if(s.geom){if(s.geom.t>=2)n.push(s);else if(o(n[n.length-1]))n.pop()}continue}if(r!==t)continue;if(s.t===1){if(o(n[n.length-1]))n.pop();continue}n.push(s)}return{name:Ie(e.name,t),cmds:n}}function tt(e,t){return[`0 ldr: own geometry of ${e.name}, step ${t}`,...zt(e,t).cmds.map(Ot)].join(`\n`)+`\n`}function Bt(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,\"0\")}function nt(e){let[t,n,r,o,s,i,c,a,l,f,p,m]=e,b=a*m-l*p,A=-(c*m-l*f),u=c*p-a*f,h=o*b+s*A+i*u;if(!Number.isFinite(h)||Math.abs(h)<0.000000000001)return null;let E=1/h,y=[b*E,-(s*m-i*p)*E,(s*l-i*a)*E,A*E,(o*m-i*f)*E,-(o*l-i*c)*E,u*E,-(o*p-s*f)*E,(o*a-s*c)*E];return[-(y[0]*t+y[1]*n+y[2]*r),-(y[3]*t+y[4]*n+y[5]*r),-(y[6]*t+y[7]*n+y[8]*r),...y]}var Nt=(e)=>String(+e.toFixed(6)||0),We=(e)=>'\"'+e.replace(/\\\\/g,\"\\\\\\\\\").replace(/\"/g,\"\\\\\\\"\")+'\"';function rt(e,t){let n=[...t.p1,...t.p2,...t.p3,...t.method!==\"PLANAR\"?[t.a??360]:[],...t.method===\"SPHERICAL\"?[t.b??180]:[]].map(Nt).join(\" \"),r=`0 ldr: ${e} with a model-level !TEXMAP\n0 BFC CERTIFY CCW\n0 !TEXMAP START ${t.method} ${n} ${We(t.texture)}${t.glossmap?\" GLOSSMAP \"+We(t.glossmap):\"\"}\n1 16 0 0 0 1 0 0 0 1 0 0 0 1 ${q(e)}\n0 !TEXMAP END\n`;return{name:`${q(e)}#tex-${Bt(r)}`,source:r}}var $t=(e,t)=>{let n=[,,,,,,,,,];for(let r=0;r<3;r++)for(let o=0;o<3;o++)n[r*3+o]=e[r*3]*t[o]+e[r*3+1]*t[3+o]+e[r*3+2]*t[6+o];return n};function jt(e,t,n){let r=Math.PI/180,o=Math.sin(e*r),s=Math.cos(e*r),i=Math.sin(t*r),c=Math.cos(t*r),a=Math.sin(n*r),l=Math.cos(n*r);return[c*l,-c*a,i,s*a+o*i*l,s*l-o*i*a,-o*c,o*a-s*i*l,o*l+s*i*a,s*c]}var Ye=new WeakMap;function ot(e){let t=Ye.get(e);if(t)return t;let n=[],r=null;for(let o of e.cmds){if(o.t!==0||!o.step)continue;let s=o.rotstep;if(s)if(s.mode===\"END\")r=null;else{let i=jt(s.x,s.y,s.z);r=s.mode===\"ABS\"?{abs:!0,m:i,rotstep:s}:s.mode===\"ADD\"&&r?{abs:r.abs,m:$t(r.m,i),rotstep:s}:{abs:!1,m:i,rotstep:s}}n.push(r)}return n.push(r),Ye.set(e,n),n}var st=999999,it=(e)=>e.map((t)=>String(t).padStart(6,\"0\")).join(\".\")+\"~\";function Vt(e,t={}){let n=[],r=t.maxDepth??64,o=t.looseGeometry!==!1,s=!!t.textures,i=!!t.callouts,c=new Map,a=0,l=(p,m)=>{let b=p.name+\"#\"+m,A=c.get(b);if(!A){let u;A=Object.assign(()=>u??=tt(p,m),{file:p,step:m}),c.set(b,A)}return A},f=(p,m,b,A,u,h,E,y,g=null,C=[],B=[])=>{let d=p.files.get(m);if(!d||E>r)return;let M=0,P=E>0?++a:0,F=i&&P?[...C,P]:C,S=i&&P?[...B,b]:B,U=i&&!g?new Map:null,W=-1,H=0,v=(T,x,z,R,D,O)=>{if(W!==M)W=M,H=0;let j=U?.get(M+\"|\"+x);if(j)return j.n++,f(T,T===p?x:T.main,z,R,u+\"/\"+x,[...D,st],E+1,O,[...D,st],F,S);let k=[...D,H++],G=n.length;f(T,T===p?x:T.main,z,R,u+\"/\"+x,k,E+1,O,g,F,S),U?.set(M+\"|\"+x,{n:1,from:G,to:n.length})},w=ot(d),L=o?et(d):[],V=0,I=(T,x,z,R,D,O,j)=>{if(g)R=g;let k={part:T,color:x,m:z,step:R[0],steps:R,localStep:D,path:u};if(P){if(k.sub=P,i)k.subPath=F,k.subMats=S}if(O)k.embedded=!0;if(j){let X=rt(T,j);k.texPart=X.name,k.texSource=X.source}let G=w[D];if(G)k.view=G;return n.push(k),k},N=(T)=>{while(V<L.length&&L[V]<=T){let x=L[V++];I(Ie(d.name,x),A,b,[...h,x],x,!1,null).source=l(d,x)}};for(let T of d.cmds){if(T.t===0&&T.step){M++;continue}let x=T;if(x.t>=2||x.t===0&&x.geom&&x.geom.t>=2){N(M);continue}if(x.t===0)if(s&&x.geom?.t===1)x=x.geom;else continue;if(x.t!==1)continue;if(s&&x.fallback)continue;let z=x.color===16?A:x.color,R=Qe(b,x.m),D=[...h,M],O=s?x.tex??y:null,j=O?nt(x.m):null,k=O&&j?qe(O,j):null;if(p.files.has(x.file)){if(Le(p,x.file)===\"model\"){v(p,x.file,R,z,D,k);continue}I(x.file,z,R,D,M,!0,k);continue}let G=t.resolveModel?.(x.file);if(G){v(G,x.file,R,z,D,k);continue}I(x.file,z,R,D,M,!1,k)}if(N(1/0),U){for(let T of U.values())if(T.n>1)for(let x=T.from;x<T.to;x++)n[x].mult??=T.n}};if(Le(e,e.main)===\"part\"){if(e.files.get(e.main))n.push({part:e.main,color:16,m:[...Te],step:0,steps:[0],localStep:0,path:e.main,embedded:!0});return n}return f(e,e.main,Te,16,e.main,[],0,null),n}function at(e,t=\"main.ldr\",n){return Vt(Ze(e,t,{geometryText:!0}),n)}var lt=(e,t=0)=>Math.abs(e[t+7]-1)<0.001&&Math.abs(e[t+4])<0.001&&Math.abs(e[t+10])<0.001,ct=new WeakMap;function ke(e,t){let n=ct.get(e);if(!n)ct.set(e,n=new Map);let r=n.get(t);if(r!==void 0)return r;let o=e.parts[t];if(!o)return n.set(t,null),null;let s=o.studs.length,i=new Float64Array(s*12),c=[],a=[];o.studs.forEach((m,b)=>{c.push(m[0]),a.push(m[1]);for(let A=0;A<12;A++)i[b*12+A]=m[2+A]});let l=null,f=0,p=0;if(o.mask){f=o.mask[0],p=o.mask[1];let m=o.mask[2];l=new Uint8Array(m.length);for(let b=0;b<m.length;b++)l[b]=m.charCodeAt(b)===49?1:0}return n.set(t,r={nStuds:s,studM:i,kind:c,color:a,mask:l,nx:f,nz:p}),r}var ie=1073741824;class Re{a;b;c;vals;used;mask;size=0;constructor(e=1024){let t=1024;while(t<e*2)t*=2;this.a=new Int32Array(t),this.b=new Int32Array(t),this.c=new Int32Array(t),this.vals=new Int32Array(t),this.used=new Uint8Array(t),this.mask=t-1}slot(e,t,n){let r=Math.imul(e,2654435761)^Math.imul(t,2246822507)^Math.imul(n,3266489909);return r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,r&this.mask}get(e,t,n){let r=this.slot(e,t,n),o=this.used,s=this.a,i=this.b,c=this.c;for(;;){if(!o[r])return-1;if(s[r]===e&&i[r]===t&&c[r]===n)return this.vals[r];r=r+1&this.mask}}put(e,t,n,r){if((this.size+1)*2>this.used.length)this.grow();let o=this.slot(e,t,n),s=this.used,i=this.a,c=this.b,a=this.c;for(;;){if(!s[o])return s[o]=1,i[o]=e,c[o]=t,a[o]=n,this.vals[o]=r,this.size++,-1;if(i[o]===e&&c[o]===t&&a[o]===n){let l=this.vals[o];return this.vals[o]=r,l}o=o+1&this.mask}}grow(){let{a:e,b:t,c:n,vals:r,used:o}=this,s=o.length*2;this.a=new Int32Array(s),this.b=new Int32Array(s),this.c=new Int32Array(s),this.vals=new Int32Array(s),this.used=new Uint8Array(s),this.mask=s-1,this.size=0;for(let i=0;i<o.length;i++)if(o[i])this.put(e[i],t[i],n[i],r[i])}}var de=(e,t,n)=>e>-ie&&e<ie&&t>-ie&&t<ie&&n>-ie&&n<ie,fe=2147483647;function Ht(e,t,n){let o=[],s=[],i=[],c=[],a=[],l=[],f=[],p=[],m=new Re(e.length*2),b=[],A=[];for(let v=0;v<e.length;v++){let w=e[v],L=w.m,V=t.parts[w.part];if(!V||!V.mask||!lt(L))continue;let I=V.bbox,N=1/0,T=-1/0,x=1/0,z=-1/0;for(let O=0;O<2;O++)for(let j=0;j<2;j++){let k=O?I[3]:I[0],G=j?I[5]:I[2],X=L[0]+L[3]*k+L[5]*G,Y=L[2]+L[9]*k+L[11]*G;if(X<N)N=X;if(X>T)T=X;if(Y<x)x=Y;if(Y>z)z=Y}let R=a.length;o.push(N),s.push(T),i.push(x),c.push(z),a.push(v),l.push(ke(t,w.part)),f.push(I[0]),p.push(I[2]);let D=Math.round((L[1]+I[4])*2);for(let O=Math.floor(N/40);O<=Math.floor(T/40);O++)for(let j=Math.floor(x/40);j<=Math.floor(z/40);j++){if(!de(D,O,j))continue;let k=A.length;A.push(R),b.push(m.put(D,O,j,k))}}let u=[0,5,-5,5,-5],h=[0,5,5,-5,-5],E=NaN,y=NaN,g=NaN,C=-1,B=(v,w,L,V)=>{let I=Math.round(w*2),N=Math.floor(v/40),T=Math.floor(L/40);if(!de(I,N,T))return fe;let x=fe;if(I!==E||N!==y||T!==g)E=I,y=N,g=T,C=m.get(I,N,T);for(let z=C;z>=0;z=b[z]){let R=A[z];if(a[R]===V||!(v-6>=o[R]-0.5&&v+6<=s[R]+0.5&&L-6>=i[R]-0.5&&L+6<=c[R]+0.5))continue;let D=e[a[R]].m,O=l[R],j=f[R],k=p[R],G=v-D[0],X=w-D[1],Y=L-D[2],Z=D[3]*G+D[6]*X+D[9]*Y,J=D[5]*G+D[8]*X+D[11]*Y,{nx:ee,nz:oe,mask:ae}=O,se=!0;for(let Q=0;Q<5;Q++){let te=Math.floor((Z+u[Q]-j)/20),ne=Math.floor((J+h[Q]-k)/20);if(te<0||ne<0||te>=ee||ne>=oe||ae[te*oe+ne]!==1){se=!1;break}}if(se){if(!n)return 0;let Q=n[a[R]];if(Q<x)x=Q}}return x},d=0;for(let v of e){let w=ke(t,v.part);if(w)d+=w.nStuds}let M=new Uint8Array(d),P=new Uint8Array(d),F=new Re(d),S=0,U=n?new Int32Array(d).fill(fe):void 0;for(let v=0,w=0;v<e.length;v++){let L=e[v],V=ke(t,L.part);if(!V)continue;let I=L.m,N=V.studM,T=I[0],x=I[1],z=I[2],R=I[3],D=I[4],O=I[5],j=I[6],k=I[7],G=I[8],X=I[9],Y=I[10],Z=I[11];for(let J=0;J<V.nStuds;J++,w++){let ee=J*12,oe=N[ee+4],ae=N[ee+7],se=N[ee+10];if(!(Math.abs(j*oe+k*ae+G*se-1)<0.001&&Math.abs(R*oe+D*ae+O*se)<0.001&&Math.abs(X*oe+Y*ae+Z*se)<0.001))continue;P[w]=1;let Q=N[ee],te=N[ee+1],ne=N[ee+2],De=T+R*Q+D*te+O*ne,Fe=x+j*Q+k*te+G*ne,Ue=z+X*Q+Y*te+Z*ne,Oe=B(De,Fe,Ue,v);if(Oe!==fe){if(M[w]=1,S++,U)U[w]=Oe}let pe=Math.round(De),me=Math.round(Fe),he=Math.round(Ue);if(!de(pe,me,he))continue;if(!n){F.put(pe,me,he,1);continue}let ze=n[v],Be=F.get(pe,me,he);if(Be<0||ze<Be)F.put(pe,me,he,ze)}}let W=new Uint8Array(e.length),H=n?new Int32Array(e.length).fill(fe):void 0;for(let v=0;v<e.length;v++){let w=e[v],L=t.parts[w.part];if(!L||!L.under||!lt(w.m))continue;let V=L.bbox,I=Math.round((V[3]-V[0])/20),N=Math.round((V[5]-V[2])/20);if(!I||!N||I*N>4096)continue;let T=w.m,x=!0,z=0;for(let R=0;R<I&&x;R++)for(let D=0;D<N;D++){let O=V[0]+10+20*R,j=V[2]+10+20*D,k=T[0]+T[3]*O+T[5]*j,G=T[2]+T[9]*O+T[11]*j,X=Math.round(k),Y=Math.round(T[1]+V[4]),Z=Math.round(G),J=de(X,Y,Z)?F.get(X,Y,Z):-1;if(J<0){x=!1;break}if(J>z)z=J}if(x){if(W[v]=1,H)H[v]=z}}return{nStuds:d,studHidden:M,studUp:P,underHidden:W,studsHidden:S,studHideStep:U,underHideStep:H}}function Gt(e,t,n){let r=(a)=>n&&a.texPart&&t.parts[a.texPart]?a.texPart:a.part,o=e.map((a)=>({part:r(a),color:String(a.color),m:a.m,steps:a.steps})),s=o.map((a)=>it(a.steps)),i=[...new Set(s)].sort(),c=new Map(i.map((a,l)=>[a,l]));return{all:o,stepOf:s.map((a)=>c.get(a)),nSteps:i.length}}function xe(e,t,n=!0){let r=Gt(e,t,n);return Ht(r.all,t,r.nSteps>1?r.stepOf:void 0)}var Me=\"https://ldr-demo.vercel.app/cdn/v1/\",ve=new Map,we=new Map;function ft(e=Me,t=fetch){let n=ve.get(e);if(!n)n=t(e+\"parts.json\").then((r)=>{if(!r.ok)throw Error(`ldr: parts CDN index ${r.status} (${e}parts.json)`);return r.json()}),n.catch(()=>ve.delete(e)),ve.set(e,n);return n}var Xt=(e)=>Array.isArray(e)&&e.length===3&&typeof e[0]===\"number\"&&typeof e[1]===\"number\"&&(e[2]===\"f32\"||e[2]===\"u16\"||e[2]===\"u8\"||e[2]===\"u32\"),Ae=(e,t)=>Xt(e)?[e[0]+t,e[1],e[2]]:Array.isArray(e)?e.map((n)=>Ae(n,t)):e&&typeof e===\"object\"?Object.fromEntries(Object.entries(e).map(([n,r])=>[n,Ae(r,t)])):e;function _t(e,t={}){let n=[],r=0,o={},s={};for(let m of e){let b=m.buffer;if(!b)throw Error(\"ldr: mergePacks needs packs from decodePack/loadPack\");let A=new DataView(b).getUint32(0,!0),u=new Uint8Array(b,4+A),h=r;n.push(u),r+=u.byteLength;let E=(4-r%4)%4;if(E)n.push(new Uint8Array(E)),r+=E;for(let[y,g]of Object.entries(m.header.parts??{}))if(!(y in o))o[y]=Ae(g,h);for(let[y,g]of Object.entries(m.header.studKinds??{}))if(!(y in s))s[y]=Ae(g,h)}let i=e[0]?.header??{version:1,weld:!0},c=new TextEncoder().encode(JSON.stringify({...i,parts:o,studKinds:s,...t})),a=(4-(4+c.length)%4)%4,l=4+c.length+a,f=new Uint8Array(l+r);new DataView(f.buffer).setUint32(0,c.length+a,!0),f.set(c,4),f.fill(32,4+c.length,l);let p=l;for(let m of n)f.set(m,p),p+=m.byteLength;return ye(f.buffer)}async function Kt(e,t={}){e=[...e];try{return await ut(e,t)}catch(n){let r=t.cdn??Me,o=t.fetch??fetch;ve.delete(r);let s=(i,c)=>o(i,{...c,cache:\"reload\"});try{return await ut(e,{...t,fetch:s})}catch{throw n}}}async function ut(e,t){let n=t.cdn??Me,r=t.fetch??fetch,o=t.gap??16384,s=await ft(n,r),i=[...new Set([...e].map(q))],c=[],a=[];for(let u of i){if(we.has(n+u))continue;let h=s.parts[u];if(h)a.push({name:u,off:h[0],len:h[1],file:h[2]??0});else c.push(u)}a.sort((u,h)=>u.file-h.file||u.off-h.off);let l=[];for(let u of a){let h=l[l.length-1];if(h&&h.file===u.file&&u.off-h.end<=o)h.end=Math.max(h.end,u.off+u.len),h.items.push(u);else l.push({file:u.file,start:u.off,end:u.off+u.len,items:[u]})}let f=0,p=0,m=async()=>{while(p<l.length){let u=l[p++],h=await r(new URL(s.archives[u.file],n).href,{headers:{Range:`bytes=${u.start}-${u.end-1}`}});if(!h.ok)throw Error(`ldr: parts CDN ${h.status}`);let E=new Uint8Array(await h.arrayBuffer());if(h.status===200)E=E.subarray(u.start,u.end);f+=E.byteLength;for(let y of u.items){let g=je(E.subarray(y.off-u.start,y.off-u.start+y.len)),C=g.buffer.slice(g.byteOffset,g.byteOffset+g.byteLength);we.set(n+y.name,ye(C))}}};await Promise.all(Array.from({length:Math.min(t.concurrency??24,l.length)},m));let b=i.filter((u)=>we.has(n+u)).map((u)=>we.get(n+u));return{pack:b.length?_t(b,{colors:s.colors}):ye(Wt(s.colors)),missing:c,requests:l.length,bytes:f}}function Wt(e){let t=new TextEncoder().encode(JSON.stringify({version:1,weld:!0,parts:{},studKinds:{},colors:e})),n=(4-(4+t.length)%4)%4,r=new Uint8Array(4+t.length+n).fill(32);return new DataView(r.buffer).setUint32(0,t.length+n,!0),r.set(t,4),r.buffer}async function pt(e,t={}){let n=performance.now(),r=t.fetch??fetch,o=ft(t.cdn??Me,r);o.catch(()=>{});let s=t.text?e:await r(e).then((h)=>{if(!h.ok)throw Error(`ldr: ${h.status} fetching ${e}`);return h.text()}),i=performance.now(),c=t.name??(t.text?\"main.ldr\":decodeURIComponent(e.split(/[?#]/)[0].split(\"/\").pop()||\"main.ldr\")),a=at(s,c,{looseGeometry:!1,callouts:t.callouts}),l=performance.now();t.onParsed?.(a),await o;let{pack:f,missing:p,requests:m,bytes:b}=await Kt(a.filter((h)=>!h.embedded).map((h)=>h.part),t),A=performance.now(),u=t.cull?xe(a,f.header,t.textures!==!1):void 0;return{insts:a,pack:f,missing:p,requests:m,bytes:b,cull:u,timings:{fetchModel:i-n,parse:l-i,parts:A-l,...u?{cull:performance.now()-A}:{}}}}self.onmessage=async(e)=>{let{id:t,source:n,opts:r}=e.data;try{let o=await pt(n,{...r,cull:!1,onParsed:(f)=>self.postMessage({id:t,insts:f})}),s=o.pack.buffer;if(self.postMessage({id:t,buffer:s,missing:o.missing,requests:o.requests,bytes:o.bytes,timings:o.timings},[s]),!r.cull)return;let i=performance.now(),c=xe(o.insts,o.pack.header,r.textures!==!1),a=performance.now()-i,l=[];for(let f of[c.studHidden,c.studUp,c.underHidden,c.studHideStep,c.underHideStep])if(f)l.push(f.buffer);self.postMessage({id:t,cull:c,ms:a},l)}catch(o){self.postMessage({id:t,phase:\"error\",error:String(o?.message??o)})}};\n";
|
|
2
2
|
export default _default;
|
package/dist/model.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ export interface PartInstance {
|
|
|
6
6
|
m: M;
|
|
7
7
|
/** Build step of the top-level model this instance appears in (0-based). */
|
|
8
8
|
step: number;
|
|
9
|
-
/** Step path through nested submodels
|
|
9
|
+
/** Step path through nested submodels: per level the step, then (for a submodel) which submodel placement of that step it is,
|
|
10
|
+
* e.g. [3, 1, 2] = top step 3, its second submodel placement (0-based 1), that submodel's step 2. Sequenced by `stepKey`. */
|
|
10
11
|
steps: number[];
|
|
11
12
|
/** Step within the file that places this instance (the last entry of `steps`). */
|
|
12
13
|
localStep: number;
|
|
@@ -26,6 +27,16 @@ export interface PartInstance {
|
|
|
26
27
|
texSource?: string;
|
|
27
28
|
/** View rotation of this instance's step from `0 ROTSTEP` (absent = default view). See `fileStepViews`. */
|
|
28
29
|
view?: StepView;
|
|
30
|
+
/** Only with `flatten(doc, { callouts: true })`: this instance belongs to the copy of a submodel that is built step by step
|
|
31
|
+
* while `mult - 1` more copies placed in the same step appear finished afterwards (an instruction booklet's "x4" callout). */
|
|
32
|
+
mult?: number;
|
|
33
|
+
/** Id of the submodel placement (sub-assembly copy) this instance came from, innermost; absent for the main model's own parts. */
|
|
34
|
+
sub?: number;
|
|
35
|
+
/** Only with `callouts: true`: the submodel placement ids from the outermost to the innermost (`sub`), for isolating a sub-assembly. */
|
|
36
|
+
subPath?: number[];
|
|
37
|
+
/** Only with `callouts: true`: the world matrix of each placement in `subPath` (shared arrays), to show a sub-assembly in its
|
|
38
|
+
* own frame, the way it is built (see `planStepViews`' `frame`). */
|
|
39
|
+
subMats?: M[];
|
|
29
40
|
}
|
|
30
41
|
export interface FlattenOptions {
|
|
31
42
|
/** Resolve an external reference that is not a submodel of this document (e.g. a model file you loaded separately). Return null to treat it as a part. */
|
|
@@ -37,7 +48,18 @@ export interface FlattenOptions {
|
|
|
37
48
|
/** TEXMAP-aware view of the model: references wrapped by a model-level `!TEXMAP` get `texPart`, `0 !:` type-1 lines are
|
|
38
49
|
* included and `!TEXMAP FALLBACK` references are skipped. Use with packs built with `textures: true`. Default false. */
|
|
39
50
|
textures?: boolean;
|
|
51
|
+
/** Instruction-booklet sequencing: when one step places the same submodel N > 1 times, only the first copy keeps its own steps
|
|
52
|
+
* (its instances get `mult = N`); the other copies get the step path `[..., step, CALLOUT_END]`, so they appear together,
|
|
53
|
+
* finished, once the first copy is built. Default false (every copy is built step by step at the same time). */
|
|
54
|
+
callouts?: boolean;
|
|
40
55
|
}
|
|
56
|
+
/** Last sub-step of a step: where `callouts` puts the finished extra copies of a multiplied submodel. */
|
|
57
|
+
export declare const CALLOUT_END = 999999;
|
|
58
|
+
/**
|
|
59
|
+
* Sort key of a step path. Submodels placed in one step are built one after another (not interleaved step by step), and before the
|
|
60
|
+
* step's own parts, which attach them: like a booklet, where callouts are built first and then added in the step that places them.
|
|
61
|
+
*/
|
|
62
|
+
export declare const stepKey: (steps: number[]) => string;
|
|
41
63
|
/**
|
|
42
64
|
* Flatten a parsed LDraw document into part instances. Model files (`0 FILE` blocks in an MPD that `fileKind` calls models) are
|
|
43
65
|
* expanded; MPD-embedded parts and library references become instances. A model file's own geometry becomes synthetic parts.
|