@selvajs/visualization 1.6.0-beta.5 → 1.6.0-beta.6
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.cjs +2 -2
- package/dist/parse.cjs.map +1 -1
- package/dist/parse.d.cts +2 -0
- package/dist/parse.d.ts +2 -0
- package/dist/parse.js +8 -8
- package/dist/parse.js.map +1 -1
- package/dist/render.cjs +2 -2
- package/dist/render.cjs.map +1 -1
- package/dist/render.d.cts +4 -4
- package/dist/render.d.ts +4 -4
- package/dist/render.js +4 -4
- package/dist/render.js.map +1 -1
- package/package.json +1 -1
package/dist/parse.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./gpu-ownership-ilj3JEdn.cjs"),t=require("./gpu-dispose-Cestx__L.cjs");let n=require("three");n=e.s(n,1);let r=require("three/addons/lines/Line2.js"),i=require("three/addons/lines/LineGeometry.js"),a=require("three/addons/lines/LineMaterial.js"),o=require("fflate");function s(){let e=globalThis.Buffer;return typeof e==`function`?e:void 0}function c(e){let 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 l(e){let n=c(e),r=n===null?null:u(n);if(r===null)throw new t.g(`Invalid base64 input.`,t.h.ENCODING_ERROR,{context:{inputLength:e.length}});return r}function u(e){let n=s();if(n){if(n.byteLength(e,`utf8`)!==e.length||e.includes(`-`)||e.includes(`_`))return null;let t=n.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.g(`Base64 decoding not supported in this environment.`,t.h.INVALID_STATE,{context:{environmentInfo:`atob or Buffer not available`}})}function d(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 f(e){e.forEach(e=>t.t(e,{materials:!1}))}const p={clone:d,release:f};function m(e,t){let r=t??1;return{color:new n.Color(e??`#ffffff`),transparent:r<1,opacity:r}}function h(e){let t=g(e);if(!t)return null;let n=new i.LineGeometry;n.setPositions(t);let o=m(e.color,e.opacity),s=new a.LineMaterial({color:o.color}),c=s;c.linewidth=e.width??2,c.transparent=o.transparent,c.opacity=o.opacity;let l=new r.Line2(n,s);return l.computeLineDistances(),l.name=e.name,l.userData={source:`compute`,id:e.id,layer:e.layer,kind:`curve`,metadata:e.metadata},l}function g(e){if(!e.points)throw new t.g(`Curve display item '${e.id}' has no tessellated points. It was produced by an outdated Display component — upgrade it in Grasshopper (Solution → Upgrade obsolete components) and re-save the definition.`,t.h.INVALID_CONFIG,{context:{itemId:e.id,kind:e.kind}});return e.points.length>=6?e.points:null}function _(e){let{position:r}=e;if(!r||typeof r.X!=`number`||!Number.isFinite(r.X)||typeof r.Y!=`number`||!Number.isFinite(r.Y)||typeof r.Z!=`number`||!Number.isFinite(r.Z))return t.p().warn(`Skipping point display item with missing or non-finite position (id: ${String(e.id)}).`),null;let i=new n.BufferGeometry;i.setAttribute(`position`,new n.Float32BufferAttribute([r.X,r.Y,r.Z],3));let a=new n.PointsMaterial({...m(e.color,e.opacity),size:6,sizeAttenuation:!1}),o=new n.Points(i,a);return o.name=e.name,o.userData={source:`compute`,id:e.id,layer:e.layer,kind:`point`,metadata:e.metadata},o}function v(e){if(!e||e.length===0)return[];let n=[];for(let r of e)switch(r.kind){case`curve`:{let e=h(r);e&&n.push(e);break}case`point`:{let e=_(r);e&&n.push(e);break}default:{let e=r;t.p().warn(`Skipping unknown display item kind: ${String(e.kind)}`);break}}return n}const y=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;function b(e){return typeof e==`string`?l(e):e instanceof Uint8Array?e:new Uint8Array(e)}function x(e){return e.byteLength>=8&&new DataView(e.buffer,e.byteOffset,8).getUint32(0,!0)===1515605075}function S(e){return x(e)?new DataView(e.buffer,e.byteOffset,8).getUint32(4,!0):0}function C(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(4,!0),n=e.subarray(8),r=Math.max(n.byteLength*1032+1024,1<<20);if(t>r)throw z(`SLVZ header declares an implausible uncompressed length`,{uncompressedLen:t,deflatedBytes:n.byteLength,maxPlausibleLen:r});return{deflated:n,uncompressedLen:t}}function w(e,t){return z(`Failed to inflate SLVZ blob: ${e instanceof Error?e.message:String(e)}`,{uncompressedLen:t.uncompressedLen,deflatedBytes:t.deflated.byteLength})}function T(e,t){if(e.byteLength!==t.uncompressedLen)throw z(`SLVZ payload inflated to a different size than the header declares.`,{declaredLen:t.uncompressedLen,actualLen:e.byteLength,deflatedBytes:t.deflated.byteLength});return e}function E(e){if(!x(e))return e;let t=C(e),n;try{n=(0,o.inflateSync)(t.deflated,{out:new Uint8Array(t.uncompressedLen+1)})}catch(e){throw w(e,t)}return T(n,t)}function D(e){return new Promise((t,n)=>{let r=C(e);try{(0,o.inflate)(r.deflated,{size:r.uncompressedLen+1},(e,i)=>{if(e)n(w(e,r));else try{t(T(i,r))}catch(e){n(e)}})}catch(e){n(w(e,r))}})}function O(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.g(`No UTF-8 decoder available in this environment.`,t.h.INVALID_STATE)}function k(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 A(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 j(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 M(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 N(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 P(e){return e>>>1^-(e&1)}function F(e){let t=new Int16Array(e.length),n=0,r=0,i=0;for(let a=0;a<e.length;a+=3)n=n+P(e[a])<<16>>16,r=r+P(e[a+1])<<16>>16,i=i+P(e[a+2])<<16>>16,t[a]=n,t[a+1]=r,t[a+2]=i;return t}function I(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+P(e[t]|e[r*3+t]<<8)<<16>>16,a=a+P(e[r+t]|e[r*4+t]<<8)<<16>>16,o=o+P(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 ee(e,t){let n=new Uint16Array(t),r=0;for(let i=0;i<t;i++)r=r+P(e[i]|e[t+i]<<8)&65535,n[i]=r;return n}function L(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+P(a)>>>0,n[i]=r}return n}function R(e){let t=new Uint16Array(e.length),n=0;for(let r=0;r<e.length;r++)n=n+P(e[r])&65535,t[r]=n;return t}function te(e){let t=new Uint32Array(e.length),n=0;for(let r=0;r<e.length;r++)n=n+P(e[r])>>>0,t[r]=n;return t}function z(e,n){return new t.g(e,t.h.VALIDATION_ERROR,{context:n})}function ne(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=A(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+P(t[e]|t[i*2+e]<<8)&65535,o=o+P(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=j(e.buffer,m,d);h=new Float32Array(d);let n=0,r=0;for(let e=0;e<d;e+=2)i?(n=n+P(t[e])&65535,r=r+P(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 re(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+P(a[e])&255,c=c+P(a[e+1])&255,l=l+P(a[e+2])&255,o[e]=s,o[e+1]=c,o[e+2]=l;return o}function ie(e){return e.byteLength>=4&&new DataView(e.buffer,e.byteOffset,4).getUint32(0,!0)===1297501267}function ae(e){let t=oe(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=E(o);break;case 1280590157:i=O(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}=ce(r),s=le(i,a);return{geometryBlob:n,metadata:{materials:s,groups:o}}}function oe(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 se(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 ce(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]=O(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=se(t,a,s),p=se(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 le(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 ue){let r=e[n];if(r?.startsWith(`slvm:tex:`)){let i=t[Number(r.slice(9))];i!==void 0&&(e[n]=de(i))}}return n}const ue=[`map`,`roughnessMap`,`normalMap`];function de(e){let t={bytes:e,pos:0},n=B(t),r=O(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 fe(e){let t;t=e.isFloat32?e.vertexData:e.planarByteSplit?I(e.vertexData,e.vertexCount):e.deltaEncoded?F(e.vertexData):e.vertexData;let n;if(e.planarByteSplit){let t=e.indexData;n=e.uint16Indices?ee(t,t.length/2):L(t,t.length/4)}else n=e.deltaEncoded?e.indexData instanceof Uint16Array?R(e.indexData):te(e.indexData):e.indexData;return N(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 V(e){if(!y)throw new t.g(`SLVA parsing requires a little-endian host: the zero-copy geometry readers view the wire bytes in host byte order.`,t.h.ENVIRONMENT_ERROR);let n=b(e);if(ie(n)){let e=ae(n),t=V(e.geometryBlob);return t.metadata=e.metadata,t}let r=E(n),i=new DataView(r.buffer,r.byteOffset,r.byteLength);if(r.byteLength<12)throw z(`Blob too small to contain SLVA header.`,{expectedBytes:12,availableBytes:r.byteLength});let a=0,o=i.getUint32(a,!0);if(a+=4,o!==1096174675)throw z(`Invalid SLVA magic: 0x${o.toString(16)}`,{expectedMagic:`0x41564c53`,actualMagic:`0x${o.toString(16)}`});let s=i.getUint32(a,!0);if(a+=4,s<1||s>4)throw z(`Unsupported SLVA version: ${s}`,{minSupportedVersion:1,maxSupportedVersion:4,actualVersion:s});let c=i.getUint32(a,!0);if(a+=4,a+c>r.byteLength)throw z(`Insufficient data to read metadata JSON.`,{expectedBytes:c,availableBytes:r.byteLength-a,offset:a});let l=r.subarray(a,a+c);a+=c;let u;try{u=c===0?{}:JSON.parse(O(l))}catch(e){throw z(`Failed to parse metadata JSON: ${e instanceof Error?e.message:String(e)}`,{metadataLen:c})}if(a+56>r.byteLength)throw z(`Insufficient data to read geometry header.`,{expectedBytes:56,availableBytes:r.byteLength-a,offset:a});let d=i.getUint32(a,!0);a+=4;let f=i.getFloat64(a,!0);a+=8;let p=i.getFloat64(a,!0);a+=8;let m=i.getFloat64(a,!0);a+=8;let h=i.getFloat64(a,!0);a+=8;let g=i.getFloat64(a,!0);a+=8;let _=i.getFloat64(a,!0);a+=8;let v=i.getUint32(a,!0);a+=4;let x=!!(d&1),S=!!(d&4),C=!!(d&32),w=v*3,T=w*(x?4:2);if(a+T>r.byteLength)throw z(`Insufficient data to read vertices.`,{expectedBytes:T,availableBytes:r.byteLength-a,offset:a,useFloat32:x,vertexCount:v});let D=r.byteOffset+a,N;if(N=x?A(r.buffer,D,w):C?r.subarray(a,a+T):S?j(r.buffer,D,w):k(r.buffer,D,w),a+=T,a+4>r.byteLength)throw z(`Insufficient data to read index count.`,{expectedBytes:4,availableBytes:r.byteLength-a,offset:a});let P=i.getUint32(a,!0);a+=4;let F=!!(d&2),I=P*(F?2:4);if(a+I>r.byteLength)throw z(`Insufficient data to read indices.`,{expectedBytes:I,availableBytes:r.byteLength-a,offset:a,indexCount:P,useUint16Indices:F});let ee=C?r.subarray(a,a+I):F?j(r.buffer,r.byteOffset+a,P):M(r.buffer,r.byteOffset+a,P);a+=I;let L=null;if(d&8){let e=ne(r,i,a,v,S,C);L=e.uvs,a=e.offset}let R=null;return d&16&&(R=re(r,a,v,S)),{metadata:u,flags:d,vertexData:N,indexData:ee,isFloat32:x,deltaEncoded:S,planarByteSplit:C,uint16Indices:F,vertexCount:v,origin:[f,p,m],scale:[h,g,_],uvs:L,colors:R}}function pe(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=/* @__PURE__ */ new Int32Array,c=/* @__PURE__ */ new Int32Array,l=/* @__PURE__ */ new Int32Array,u=/* @__PURE__ */ new Int32Array,d=/* @__PURE__ */ new Int32Array,f=/* @__PURE__ */ new Int32Array,p=/* @__PURE__ */ new Int32Array,m=/* @__PURE__ */ new Int32Array,h=/* @__PURE__ */ new Int32Array,g=(e,t)=>e.length>=t?e:new Int32Array(t),_=(n,i,_)=>{if(_<12||_%3!=0)return!1;let v=2*n+1,y=v+1,b=0,x=0;for(let n=0;n<_;n++){let r=t[i+n];a[r]!==v&&(a[r]=v,x++,b=Math.max(b,Math.abs(e[r*3]),Math.abs(e[r*3+1]),Math.abs(e[r*3+2])))}if(!(b>0)||!Number.isFinite(b))return!1;let S=1/(2*2**(Math.floor(Math.log2(b))-23)),C=r(x),w=C-1;s=g(s,C),s.fill(-1,0,C),c=g(c,C),l=g(l,C),u=g(u,C);let T=(e,t,n)=>{let r=Math.imul(e,2654435761)^Math.imul(t,2246822519)^Math.imul(n,3266489917);for(r=(r^r>>>15)&w;s[r]!==-1&&(c[r]!==e||l[r]!==t||u[r]!==n);)r=r+1&w;return r},E=(e,t)=>{let n=e-t;return n>.25?t+1:n<-.25?t-1:t};d=g(d,_),f=g(f,x);let D=0;for(let n=0;n<_;n++){let r=t[i+n];if(a[r]===y){d[n]=o[r];continue}let p=e[r*3]*S,m=e[r*3+1]*S,h=e[r*3+2]*S,g=Math.round(p),_=Math.round(m),v=Math.round(h),b=E(p,g),x=E(m,_),C=E(h,v),w=-1,O=-1;for(let e=0;e<8&&w===-1;e++){if(e&1&&b===g||e&2&&x===_||e&4&&C===v)continue;let t=T(e&1?b:g,e&2?x:_,e&4?C:v);e===0&&(O=t),s[t]!==-1&&(w=s[t])}if(w===-1){let e=O;w=D++,s[e]=w,c[e]=g,l[e]=_,u[e]=v,f[w]=r}a[r]=y,o[r]=w,d[n]=w}p=g(p,D+1),p.fill(0,0,D+1);let O=0;for(let e=0;e<_;e+=3){let t=d[e],n=d[e+1],r=d[e+2];t!==n&&n!==r&&r!==t&&(p[t+1]+=1,p[n+1]+=1,p[r+1]+=1,O++)}if(O<4)return!1;for(let e=0;e<D;e++)p[e+1]+=p[e];m=g(m,p[D]),h=g(h,D),h.set(p.subarray(0,D));for(let e=0;e<_;e+=3){let t=d[e],n=d[e+1],r=d[e+2];t!==n&&n!==r&&r!==t&&(m[h[t]]=n,h[t]+=1,m[h[n]]=r,h[n]+=1,m[h[r]]=t,h[r]+=1)}for(let e=0;e<D;e++){let t=p[e],n=p[e+1];for(let r=t;r<n;r++){let n=m[r];for(let e=t;e<r;e++)if(m[e]===n)return!1;let i=!1;for(let t=p[n],r=p[n+1];t<r&&!i;t++)i=m[t]===e;if(!i)return!1}}let k=f[d[0]]*3,A=e[k],j=e[k+1],M=e[k+2],N=0;for(let t=0;t<_;t+=3){let n=f[d[t]]*3,r=f[d[t+1]]*3,i=f[d[t+2]]*3,a=e[n]-A,o=e[n+1]-j,s=e[n+2]-M,c=e[r]-A,l=e[r+1]-j,u=e[r+2]-M,p=e[i]-A,m=e[i+1]-j,h=e[i+2]-M;N+=a*(l*h-u*m)+o*(u*p-c*h)+s*(c*m-l*p)}return N>0},v=0;for(let e=0;e<n.length;e++){let t=n[e];if(!_(e,v,t))return!1;v+=t}return!0}function me(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=16;for(;l<a*2;)l*=2;let u=l-1,d=new Int32Array(l).fill(-1),f=new Uint32Array(a),p=!1;for(let e=0;e<a;e++){let t=c(i,e*3),n=c(i,e*3+1),a=c(i,e*3+2),o=Math.imul(t,2654435761)^Math.imul(n,2246822519)^Math.imul(a,3266489917);for(o=(o^o>>>15)&u;;){let l=d[o];if(l===-1){d[o]=e,f[e]=e;break}if(c(i,l*3)===t&&c(i,l*3+1)===n&&c(i,l*3+2)===a&&(!r||r[l*3]===r[e*3]&&r[l*3+1]===r[e*3+1]&&r[l*3+2]===r[e*3+2])&&(!s||s[l*2]===s[e*2]&&s[l*2+1]===s[e*2+1])){f[e]=l,p=!0;break}o=o+1&u}}if(p)for(let e=0;e<o;e++)t[e]=f[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<s;e++){let n=l[e],r=c[e*3]*n,i=c[e*3+1]*n,o=c[e*3+2]*n;for(let n=e*3;n<e*3+3;n++){let e=t[n],s=m[n];s!==0&&(e=a+_[e]+s-1,t[n]=e),C[e*3]+=r,C[e*3+1]+=i,C[e*3+2]+=o}}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 he(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,P=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]+=P}}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 H(e,t){let n=pe(e.positions,e.indices,t),r=me(e.positions,e.indices,e.uvs,e.colors),i=r.uvs?he(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 = ${pe.toString()};`,`const splitCreases = ${me.toString()};`,`const grainTangents = ${he.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(`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./gpu-ownership-ilj3JEdn.cjs"),t=require("./gpu-dispose-Cestx__L.cjs");let n=require("three");n=e.s(n,1);let r=require("three/addons/lines/Line2.js"),i=require("three/addons/lines/LineGeometry.js"),a=require("three/addons/lines/LineMaterial.js"),o=require("fflate");function s(){let e=globalThis.Buffer;return typeof e==`function`?e:void 0}function c(e){let 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 l(e){let n=c(e),r=n===null?null:u(n);if(r===null)throw new t.g(`Invalid base64 input.`,t.h.ENCODING_ERROR,{context:{inputLength:e.length}});return r}function u(e){let n=s();if(n){if(n.byteLength(e,`utf8`)!==e.length||e.includes(`-`)||e.includes(`_`))return null;let t=n.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.g(`Base64 decoding not supported in this environment.`,t.h.INVALID_STATE,{context:{environmentInfo:`atob or Buffer not available`}})}function d(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 f(e){e.forEach(e=>t.t(e,{materials:!1}))}const p={clone:d,release:f};function m(e,t){let r=t??1;return{color:new n.Color(e??`#ffffff`),transparent:r<1,opacity:r}}function h(e){let t=g(e);if(!t)return null;let n=new i.LineGeometry;n.setPositions(t);let o=m(e.color,e.opacity),s=new a.LineMaterial({color:o.color}),c=s;c.linewidth=e.width??2,c.transparent=o.transparent,c.opacity=o.opacity;let l=new r.Line2(n,s);return l.computeLineDistances(),l.name=e.name,l.userData={source:`compute`,id:e.id,layer:e.layer,kind:`curve`,metadata:e.metadata},l}function g(e){if(!e.points)throw new t.g(`Curve display item '${e.id}' has no tessellated points. It was produced by an outdated Display component — upgrade it in Grasshopper (Solution → Upgrade obsolete components) and re-save the definition.`,t.h.INVALID_CONFIG,{context:{itemId:e.id,kind:e.kind}});return e.points.length>=6?e.points:null}function _(e){let{position:r}=e;if(!r||typeof r.X!=`number`||!Number.isFinite(r.X)||typeof r.Y!=`number`||!Number.isFinite(r.Y)||typeof r.Z!=`number`||!Number.isFinite(r.Z))return t.p().warn(`Skipping point display item with missing or non-finite position (id: ${String(e.id)}).`),null;let i=new n.BufferGeometry;i.setAttribute(`position`,new n.Float32BufferAttribute([r.X,r.Y,r.Z],3));let a=new n.PointsMaterial({...m(e.color,e.opacity),size:6,sizeAttenuation:!1}),o=new n.Points(i,a);return o.name=e.name,o.userData={source:`compute`,id:e.id,layer:e.layer,kind:`point`,metadata:e.metadata},o}function v(e){if(!e||e.length===0)return[];let n=[];for(let r of e)switch(r.kind){case`curve`:{let e=h(r);e&&n.push(e);break}case`point`:{let e=_(r);e&&n.push(e);break}default:{let e=r;t.p().warn(`Skipping unknown display item kind: ${String(e.kind)}`);break}}return n}const y=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;function b(e){return typeof e==`string`?l(e):e instanceof Uint8Array?e:new Uint8Array(e)}function x(e){return e.byteLength>=8&&new DataView(e.buffer,e.byteOffset,8).getUint32(0,!0)===1515605075}function S(e){return x(e)?new DataView(e.buffer,e.byteOffset,8).getUint32(4,!0):0}function C(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(4,!0),n=e.subarray(8),r=Math.max(n.byteLength*1032+1024,1<<20);if(t>r)throw z(`SLVZ header declares an implausible uncompressed length`,{uncompressedLen:t,deflatedBytes:n.byteLength,maxPlausibleLen:r});return{deflated:n,uncompressedLen:t}}function w(e,t){return z(`Failed to inflate SLVZ blob: ${e instanceof Error?e.message:String(e)}`,{uncompressedLen:t.uncompressedLen,deflatedBytes:t.deflated.byteLength})}function T(e,t){if(e.byteLength!==t.uncompressedLen)throw z(`SLVZ payload inflated to a different size than the header declares.`,{declaredLen:t.uncompressedLen,actualLen:e.byteLength,deflatedBytes:t.deflated.byteLength});return e}function E(e){if(!x(e))return e;let t=C(e),n;try{n=(0,o.inflateSync)(t.deflated,{out:new Uint8Array(t.uncompressedLen+1)})}catch(e){throw w(e,t)}return T(n,t)}function D(e){return new Promise((t,n)=>{let r=C(e);try{(0,o.inflate)(r.deflated,{size:r.uncompressedLen+1},(e,i)=>{if(e)n(w(e,r));else try{t(T(i,r))}catch(e){n(e)}})}catch(e){n(w(e,r))}})}function O(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.g(`No UTF-8 decoder available in this environment.`,t.h.INVALID_STATE)}function k(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 A(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 j(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 M(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 N(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 P(e){return e>>>1^-(e&1)}function F(e){let t=new Int16Array(e.length),n=0,r=0,i=0;for(let a=0;a<e.length;a+=3)n=n+P(e[a])<<16>>16,r=r+P(e[a+1])<<16>>16,i=i+P(e[a+2])<<16>>16,t[a]=n,t[a+1]=r,t[a+2]=i;return t}function I(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+P(e[t]|e[r*3+t]<<8)<<16>>16,a=a+P(e[r+t]|e[r*4+t]<<8)<<16>>16,o=o+P(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 ee(e,t){let n=new Uint16Array(t),r=0;for(let i=0;i<t;i++)r=r+P(e[i]|e[t+i]<<8)&65535,n[i]=r;return n}function L(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+P(a)>>>0,n[i]=r}return n}function R(e){let t=new Uint16Array(e.length),n=0;for(let r=0;r<e.length;r++)n=n+P(e[r])&65535,t[r]=n;return t}function te(e){let t=new Uint32Array(e.length),n=0;for(let r=0;r<e.length;r++)n=n+P(e[r])>>>0,t[r]=n;return t}function z(e,n){return new t.g(e,t.h.VALIDATION_ERROR,{context:n})}function ne(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=A(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+P(t[e]|t[i*2+e]<<8)&65535,o=o+P(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=j(e.buffer,m,d);h=new Float32Array(d);let n=0,r=0;for(let e=0;e<d;e+=2)i?(n=n+P(t[e])&65535,r=r+P(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 re(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+P(a[e])&255,c=c+P(a[e+1])&255,l=l+P(a[e+2])&255,o[e]=s,o[e+1]=c,o[e+2]=l;return o}function ie(e){return e.byteLength>=4&&new DataView(e.buffer,e.byteOffset,4).getUint32(0,!0)===1297501267}function ae(e){let t=oe(e),n=null,r=null,i=null,a=null,o=[];for(let{type:e,payload:s}of t)switch(e){case 1297040711:n=s;break;case 1279410516:r=E(s);break;case 1280590157:i=O(s);break;case 1381516628:o.push(s);break;case 1146309699:a=E(s)}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:s}=ce(r,a),c=le(i,o);return{geometryBlob:n,metadata:{materials:c,groups:s}}}function oe(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 se(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 ce(e,t){let n={bytes:e,pos:0},r=B(n),i=B(n),a=B(n),o=r+i+a,s=B(n),c=Array(s);for(let t=0;t<s;t++){let r=B(n);c[t]=O(e.subarray(n.pos,n.pos+r)),n.pos+=r}let l=Array(r),u=Array(r);for(let e=0;e<r;e++)l[e]=B(n),u[e]=B(n);for(let e=0;e<i;e++)B(n);let d=B(n),f=[];for(let e=0;e<d;e++)f.push({materialId:B(n),meshCount:B(n)});let p=se(n,o,c),m=se(n,o,c),h=Array(o),g=B(n);for(let e=0;e<g;e++){let e=c[B(n)]??``,t=B(n),r=Array(t),i=0;for(let e=0;e<t;e++)i+=B(n),r[e]=i;for(let i=0;i<t;i++){let t=c[B(n)]??``,a=r[i];(h[a]??={})[e]=t}}let _=f.length>0||r===0?f:[{materialId:0,meshCount:r}],v=[],y=0,b=0,x=0;for(let e of _){let n=[];for(let i=0;i<e.meshCount&&y<r;i++,y++){let e=h[y],r=e?.id;e!==void 0&&delete e.id;let i={id:r,name:p[y],layer:m[y],vertexCount:l[y],indexCount:u[y]*3,vertexStart:b,indexStart:x,metadata:e??{}},a=t?.[y];(a===1||a===2)&&(i.closed=a===2),n.push(i),b+=l[y],x+=u[y]*3}v.push({materialId:e.materialId,meshes:n})}return{groups:v}}function le(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 ue){let r=e[n];if(r?.startsWith(`slvm:tex:`)){let i=t[Number(r.slice(9))];i!==void 0&&(e[n]=de(i))}}return n}const ue=[`map`,`roughnessMap`,`normalMap`];function de(e){let t={bytes:e,pos:0},n=B(t),r=O(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 fe(e){let t;t=e.isFloat32?e.vertexData:e.planarByteSplit?I(e.vertexData,e.vertexCount):e.deltaEncoded?F(e.vertexData):e.vertexData;let n;if(e.planarByteSplit){let t=e.indexData;n=e.uint16Indices?ee(t,t.length/2):L(t,t.length/4)}else n=e.deltaEncoded?e.indexData instanceof Uint16Array?R(e.indexData):te(e.indexData):e.indexData;return N(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 V(e){if(!y)throw new t.g(`SLVA parsing requires a little-endian host: the zero-copy geometry readers view the wire bytes in host byte order.`,t.h.ENVIRONMENT_ERROR);let n=b(e);if(ie(n)){let e=ae(n),t=V(e.geometryBlob);return t.metadata=e.metadata,t}let r=E(n),i=new DataView(r.buffer,r.byteOffset,r.byteLength);if(r.byteLength<12)throw z(`Blob too small to contain SLVA header.`,{expectedBytes:12,availableBytes:r.byteLength});let a=0,o=i.getUint32(a,!0);if(a+=4,o!==1096174675)throw z(`Invalid SLVA magic: 0x${o.toString(16)}`,{expectedMagic:`0x41564c53`,actualMagic:`0x${o.toString(16)}`});let s=i.getUint32(a,!0);if(a+=4,s<1||s>4)throw z(`Unsupported SLVA version: ${s}`,{minSupportedVersion:1,maxSupportedVersion:4,actualVersion:s});let c=i.getUint32(a,!0);if(a+=4,a+c>r.byteLength)throw z(`Insufficient data to read metadata JSON.`,{expectedBytes:c,availableBytes:r.byteLength-a,offset:a});let l=r.subarray(a,a+c);a+=c;let u;try{u=c===0?{}:JSON.parse(O(l))}catch(e){throw z(`Failed to parse metadata JSON: ${e instanceof Error?e.message:String(e)}`,{metadataLen:c})}if(a+56>r.byteLength)throw z(`Insufficient data to read geometry header.`,{expectedBytes:56,availableBytes:r.byteLength-a,offset:a});let d=i.getUint32(a,!0);a+=4;let f=i.getFloat64(a,!0);a+=8;let p=i.getFloat64(a,!0);a+=8;let m=i.getFloat64(a,!0);a+=8;let h=i.getFloat64(a,!0);a+=8;let g=i.getFloat64(a,!0);a+=8;let _=i.getFloat64(a,!0);a+=8;let v=i.getUint32(a,!0);a+=4;let x=!!(d&1),S=!!(d&4),C=!!(d&32),w=v*3,T=w*(x?4:2);if(a+T>r.byteLength)throw z(`Insufficient data to read vertices.`,{expectedBytes:T,availableBytes:r.byteLength-a,offset:a,useFloat32:x,vertexCount:v});let D=r.byteOffset+a,N;if(N=x?A(r.buffer,D,w):C?r.subarray(a,a+T):S?j(r.buffer,D,w):k(r.buffer,D,w),a+=T,a+4>r.byteLength)throw z(`Insufficient data to read index count.`,{expectedBytes:4,availableBytes:r.byteLength-a,offset:a});let P=i.getUint32(a,!0);a+=4;let F=!!(d&2),I=P*(F?2:4);if(a+I>r.byteLength)throw z(`Insufficient data to read indices.`,{expectedBytes:I,availableBytes:r.byteLength-a,offset:a,indexCount:P,useUint16Indices:F});let ee=C?r.subarray(a,a+I):F?j(r.buffer,r.byteOffset+a,P):M(r.buffer,r.byteOffset+a,P);a+=I;let L=null;if(d&8){let e=ne(r,i,a,v,S,C);L=e.uvs,a=e.offset}let R=null;return d&16&&(R=re(r,a,v,S)),{metadata:u,flags:d,vertexData:N,indexData:ee,isFloat32:x,deltaEncoded:S,planarByteSplit:C,uint16Indices:F,vertexCount:v,origin:[f,p,m],scale:[h,g,_],uvs:L,colors:R}}function pe(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=/* @__PURE__ */ new Int32Array,c=/* @__PURE__ */ new Int32Array,l=/* @__PURE__ */ new Int32Array,u=/* @__PURE__ */ new Int32Array,d=/* @__PURE__ */ new Int32Array,f=/* @__PURE__ */ new Int32Array,p=/* @__PURE__ */ new Int32Array,m=/* @__PURE__ */ new Int32Array,h=/* @__PURE__ */ new Int32Array,g=(e,t)=>e.length>=t?e:new Int32Array(t),_=(n,i,_)=>{if(_<12||_%3!=0)return!1;let v=2*n+1,y=v+1,b=0,x=0;for(let n=0;n<_;n++){let r=t[i+n];a[r]!==v&&(a[r]=v,x++,b=Math.max(b,Math.abs(e[r*3]),Math.abs(e[r*3+1]),Math.abs(e[r*3+2])))}if(!(b>0)||!Number.isFinite(b))return!1;let S=1/(2*2**(Math.floor(Math.log2(b))-23)),C=r(x),w=C-1;s=g(s,C),s.fill(-1,0,C),c=g(c,C),l=g(l,C),u=g(u,C);let T=(e,t,n)=>{let r=Math.imul(e,2654435761)^Math.imul(t,2246822519)^Math.imul(n,3266489917);for(r=(r^r>>>15)&w;s[r]!==-1&&(c[r]!==e||l[r]!==t||u[r]!==n);)r=r+1&w;return r},E=(e,t)=>{let n=e-t;return n>.25?t+1:n<-.25?t-1:t};d=g(d,_),f=g(f,x);let D=0;for(let n=0;n<_;n++){let r=t[i+n];if(a[r]===y){d[n]=o[r];continue}let p=e[r*3]*S,m=e[r*3+1]*S,h=e[r*3+2]*S,g=Math.round(p),_=Math.round(m),v=Math.round(h),b=E(p,g),x=E(m,_),C=E(h,v),w=-1,O=-1;for(let e=0;e<8&&w===-1;e++){if(e&1&&b===g||e&2&&x===_||e&4&&C===v)continue;let t=T(e&1?b:g,e&2?x:_,e&4?C:v);e===0&&(O=t),s[t]!==-1&&(w=s[t])}if(w===-1){let e=O;w=D++,s[e]=w,c[e]=g,l[e]=_,u[e]=v,f[w]=r}a[r]=y,o[r]=w,d[n]=w}p=g(p,D+1),p.fill(0,0,D+1);let O=0;for(let e=0;e<_;e+=3){let t=d[e],n=d[e+1],r=d[e+2];t!==n&&n!==r&&r!==t&&(p[t+1]+=1,p[n+1]+=1,p[r+1]+=1,O++)}if(O<4)return!1;for(let e=0;e<D;e++)p[e+1]+=p[e];m=g(m,p[D]),h=g(h,D),h.set(p.subarray(0,D));for(let e=0;e<_;e+=3){let t=d[e],n=d[e+1],r=d[e+2];t!==n&&n!==r&&r!==t&&(m[h[t]]=n,h[t]+=1,m[h[n]]=r,h[n]+=1,m[h[r]]=t,h[r]+=1)}for(let e=0;e<D;e++){let t=p[e],n=p[e+1];for(let r=t;r<n;r++){let n=m[r];for(let e=t;e<r;e++)if(m[e]===n)return!1;let i=!1;for(let t=p[n],r=p[n+1];t<r&&!i;t++)i=m[t]===e;if(!i)return!1}}let k=f[d[0]]*3,A=e[k],j=e[k+1],M=e[k+2],N=0;for(let t=0;t<_;t+=3){let n=f[d[t]]*3,r=f[d[t+1]]*3,i=f[d[t+2]]*3,a=e[n]-A,o=e[n+1]-j,s=e[n+2]-M,c=e[r]-A,l=e[r+1]-j,u=e[r+2]-M,p=e[i]-A,m=e[i+1]-j,h=e[i+2]-M;N+=a*(l*h-u*m)+o*(u*p-c*h)+s*(c*m-l*p)}return N>0},v=0;for(let e=0;e<n.length;e++){let t=n[e];if(!_(e,v,t))return!1;v+=t}return!0}function me(e,t,n,r){let i=Math.cos(30*Math.PI/180),a=e.length/3,o=t.length,s=o/3,c=/* @__PURE__ */ new Uint32Array;{let i=new Uint32Array(e.buffer,e.byteOffset,e.length),s=n?new Uint32Array(n.buffer,n.byteOffset,n.length):null,l=(e,t)=>e[t]===2147483648?0:e[t],u=16;for(;u<a*2;)u*=2;let d=u-1,f=new Int32Array(u).fill(-1),p=new Uint32Array(a),m=!1;for(let e=0;e<a;e++){let t=l(i,e*3),n=l(i,e*3+1),a=l(i,e*3+2),o=Math.imul(t,2654435761)^Math.imul(n,2246822519)^Math.imul(a,3266489917);for(o=(o^o>>>15)&d;;){let c=f[o];if(c===-1){f[o]=e,p[e]=e;break}if(l(i,c*3)===t&&l(i,c*3+1)===n&&l(i,c*3+2)===a&&(!r||r[c*3]===r[e*3]&&r[c*3+1]===r[e*3+1]&&r[c*3+2]===r[e*3+2])&&(!s||s[c*2]===s[e*2]&&s[c*2+1]===s[e*2+1])){p[e]=c,m=!0;break}o=o+1&d}}if(m){for(let e=0;e<o;e++)t[e]=p[t[e]];let e=0;for(let t=0;t<a;t++)p[t]!==t&&e++;c=new Uint32Array(e);for(let e=0,t=0;e<a;e++)p[e]!==e&&(c[t++]=e)}}let l=new Float32Array(s*3),u=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],c=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-c*f,h=c*d-o*p,g=o*f-s*d,_=Math.sqrt(m*m+h*h+g*g);_!==0&&(l[n*3]=m/_,l[n*3+1]=h/_,l[n*3+2]=g/_,u[n]=_)}let d=new Uint32Array(a+1);for(let e=0;e<o;e++)d[t[e]+1]+=1;for(let e=0;e<a;e++)d[e+1]+=d[e];let f=new Uint32Array(o),p=d.slice(0,a);for(let e=0;e<o;e++){let n=t[e];f[p[n]]=e,p[n]+=1}let m=0;for(let e=0;e<a;e++)m=Math.max(m,d[e+1]-d[e]);let h=new Uint32Array(o),g=new Uint32Array(a),_=new Float32Array(Math.max(1,m)*3);for(let e=0;e<a;e++){let t=0;for(let n=d[e];n<d[e+1];n++){let e=f[n],r=Math.floor(e/3)*3,a=l[r],o=l[r+1],s=l[r+2],c=-1;if(a===0&&o===0&&s===0)c=0;else for(let e=0;e<t;e++)if(_[e*3]*a+_[e*3+1]*o+_[e*3+2]*s>=i){c=e;break}c===-1&&(c=t,_[t*3]=a,_[t*3+1]=o,_[t*3+2]=s,t++),h[e]=c}g[e]=Math.max(1,t)}let v=new Uint32Array(a+1);for(let e=0;e<a;e++)v[e+1]=v[e]+g[e]-1;let y=v[a],b=a+Math.max(0,y-c.length),x=new Uint32Array(y);for(let e=0;e<y;e++)x[e]=e<c.length?c[e]:a+e-c.length;let S=e,C=n,w=r;if(y>0){S=new Float32Array(b*3),S.set(e),C=n?new Float32Array(b*2):null,C&&n&&C.set(n),w=r?new Uint8Array(b*3):null,w&&r&&w.set(r);for(let t=0;t<a;t++)for(let i=1;i<g[t];i++){let a=x[v[t]+i-1];S[a*3]=e[t*3],S[a*3+1]=e[t*3+1],S[a*3+2]=e[t*3+2],C&&n&&(C[a*2]=n[t*2],C[a*2+1]=n[t*2+1]),w&&r&&(w[a*3]=r[t*3],w[a*3+1]=r[t*3+1],w[a*3+2]=r[t*3+2])}}let T=new Float32Array(b*3);for(let e=0;e<s;e++){let n=u[e],r=l[e*3]*n,i=l[e*3+1]*n,a=l[e*3+2]*n;for(let n=e*3;n<e*3+3;n++){let e=t[n],o=h[n];o!==0&&(e=x[v[e]+o-1],t[n]=e),T[e*3]+=r,T[e*3+1]+=i,T[e*3+2]+=a}}for(let e=0;e<T.length;e+=3){let t=T[e],n=T[e+1],r=T[e+2],i=Math.sqrt(t*t+n*n+r*r)||1;T[e]=t/i,T[e+1]=n/i,T[e+2]=r/i}return{positions:S,normals:T,indices:t,uvs:C,colors:w}}function he(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,P=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]+=P}}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 H(e,t){let n=t.every(e=>typeof e.closed==`boolean`)?t.length>0&&t.every(e=>e.closed):pe(e.positions,e.indices,t.map(e=>e.indexCount)),r=me(e.positions,e.indices,e.uvs,e.colors),i=r.uvs?he(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 = ${pe.toString()};`,`const splitCreases = ${me.toString()};`,`const grainTangents = ${he.toString()};`,`self.onmessage = (event) => {`,` const { id, input } = event.data;`,` try {`,` const geometries = assemble(input).map((g, i) => {`,` const windows = input.jobs[i].windows;`,` const known = windows.every((w) => typeof w.closed === 'boolean');`,` const closed = known`,` ? windows.length > 0 && windows.every((w) => w.closed)`,` : isClosedSolid(g.positions, g.indices, windows.map((w) => w.indexCount));`,` 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
2
|
`)}let U;const W=/* @__PURE__ */ new Map;let ve=1;function ye(){if(U!==void 0)return U;if(typeof Worker>`u`||typeof Blob>`u`||typeof URL>`u`||typeof URL.createObjectURL!=`function`)return U=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=W.get(t);i&&(W.delete(t),n?i.resolve(n):i.reject(Error(r??`mesh assembly failed in worker`)))},t.onerror=()=>{for(let e of W.values())e.reject(/* @__PURE__ */ Error(`mesh assembly worker crashed`));W.clear(),t.terminate(),U=null},U=t}catch{U=null}return U}function be(e,t,n){return new Promise((r,i)=>{let a=ve++;W.set(a,{resolve:r,reject:i}),e.postMessage({id:a,input:t},n)})}let xe=1;function Se(e){xe=Math.max(1,e)}t.n(Se);function G(e,r,i,a){typeof document<`u`&&new n.TextureLoader().load(r,t=>{if(t.colorSpace=i===`map`?n.SRGBColorSpace:n.NoColorSpace,t.anisotropy=xe,a){let e=t.image,r=e?.width&&e.height?e.height/e.width:1;t.wrapS=n.RepeatWrapping,t.wrapT=n.RepeatWrapping,t.repeat.set(1/a,1/(a*r))}e[i]=t,e.needsUpdate=!0},void 0,e=>{t.p().warn(`Failed to load material ${i} ${r}:`,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,K=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, ${K(e.pitch)}, vec2( ${K(e.length[0])}, ${K(e.length[1])} ), ${K(e.depth)}, ${K(t*31+3)} )`).join(` + `)||`0.0`,i=n.bands.map(e=>`selvaBand( vUv, footprint, vec2( ${K(e.length)}, ${K(e.width)} ), ${K(e.depth)} )`).join(` + `)||`0.0`;return{key:`finish:${e}:${K(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 ) {
|
|
@@ -64,5 +64,5 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
|
|
|
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 q(e,n){return new t.g(e,t.h.VALIDATION_ERROR,{context:n})}function J(e,t,n,r){for(let i of e){if(!Number.isInteger(i.materialId)||i.materialId<0||i.materialId>=t)throw q(`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 q(`Mesh metadata field "${n}" must be a non-negative integer.`,{meshName:e.name,field:n,value:r});if(e.vertexStart+e.vertexCount>n)throw q(`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 q(`Mesh index window exceeds the batch index buffer.`,{meshName:e.name,indexStart:e.indexStart,indexCount:e.indexCount,totalIndexCount:r})}}}function je(e,t){return q(`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=/* @__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 Pe(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=t.get(n.materialId);e?e.push(...n.meshes):t.set(n.materialId,[...n.meshes])}return[...t].flatMap(([e,t])=>Ne({materialId:e,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 je(t,r);l[p+e]=t+m}f+=r.vertexCount,p+=r.indexCount}let m=H({positions:c,indices:l,uvs:u,colors:d},e.meshes.map(e=>e.indexCount));return Le(Y(m),e,r(e.materialId,m.closed))}function Y(e){let t=new n.BufferGeometry;return t.setAttribute(`position`,new n.BufferAttribute(e.positions,3)),t.setAttribute(`normal`,new n.BufferAttribute(e.normals,3)),t.setIndex(new n.BufferAttribute(e.indices,1)),e.uvs&&t.setAttribute(`uv`,new n.BufferAttribute(e.uvs,2)),e.tangents&&t.setAttribute(`tangent`,new n.BufferAttribute(e.tangents,4)),e.colors&&t.setAttribute(`color`,new n.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,r){let i=new n.Mesh(e,r),a=t.meshes[0],o=t.meshes.map(e=>e.name).filter(e=>e&&e.length>0);return i.name=o.length>0?o[0]:`merged_material_${t.materialId}`,i.castShadow=!0,i.receiveShadow=!0,i.userData={source:`compute`,name:i.name,layer:a?.layer??``,metadata:a?.metadata??{},members:Ie(t)},i}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 je(t,s);f[e]=t-p}let h=s.vertexStart*2,g=H({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(Y(g),s,r(e.materialId,g.closed)))}return o}function ze(e,t,r){let i=new n.Mesh(e,r);return i.name=t.name,i.userData={source:`compute`,name:t.name,layer:t.layer??``,trackingKey:t.id,metadata:t.metadata??{}},i.castShadow=!0,i.receiveShadow=!0,i}const Be=268435456,X=/* @__PURE__ */ new Map;let Z=0;function Ve(e,t){let n=Ge(t),r=Ke(e,n),i=X.get(r);return!i||!qe(i.jobShape,n)||!Je(i.geometryBytes,e)?null:(X.delete(r),X.set(r,i),i)}function He(e){let{geometries:t,...n}=e;return{...n,buffers:t.map(Y),closed:t.map(e=>e.closed)}}function Ue(t,n,r){let i=He(r),a=t.byteLength;for(let e of r.geometries)a+=e.positions.byteLength+e.normals.byteLength+e.indices.byteLength,a+=(e.uvs?.byteLength??0)+(e.colors?.byteLength??0)+(e.tangents?.byteLength??0);if(a>Be)return i;let o=Ge(n),s=Ke(t,o),c=X.get(s);c&&(X.delete(s),Q(c)),i.buffers.forEach(e.a),X.set(s,{...i,geometryBytes:t.slice(),jobShape:o,bytes:a}),Z+=a;for(let[e,t]of X){if(Z<=Be)break;X.delete(e),Q(t)}return i}function We(){X.forEach(Q),X.clear()}function Q(t){Z-=t.bytes;for(let n of t.buffers)e.o(n),n.dispose()}function Ge(e){let t=0;for(let n of e)t+=2+4*n.windows.length;let n=new Int32Array(t),r=0;for(let t of e){n[r++]=+(t.kind===`merged`),n[r++]=t.windows.length;for(let e of t.windows)n[r++]=e.vertexStart,n[r++]=e.vertexCount,n[r++]=e.indexStart,n[r++]=e.indexCount}return n}function Ke(e,t){let n=e.length,r=Math.max(1,Math.floor(n/1024)),i=2166136261;for(let t=0;t<n;t+=r)i=Math.imul(i^e[t],16777619);let a=2166136261;for(let e=0;e<t.length;e++)a=Math.imul(a^t[e],16777619);return`${n}:${i>>>0}:${t.length}:${a>>>0}`}function qe(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Je(e,t){if(e.length!==t.length)return!1;let n=0;if(e.byteOffset%4==0&&t.byteOffset%4==0){let r=e.length>>>2,i=new Uint32Array(e.buffer,e.byteOffset,r),a=new Uint32Array(t.buffer,t.byteOffset,r);for(;n<r;n++)if(i[n]!==a[n])return!1;n=r<<2}for(;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}async function Ye(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={mergeByMaterial:r,debug:i,material:a,fallback:{materials:e.materials,groups:e.groups}},u=await et(e.compressedData,l);return u.meshes?u.meshes:await it(u,l)||$e(fe(u.raw),{mergeByMaterial:r,debug:i,material:a,parseTime:o,decodeTime:performance.now()-c,perfStart:s,blobBytes:i?ct(e.compressedData):0,fallback:{materials:e.materials,groups:e.groups}})}async function Xe(e,t){let{mergeByMaterial:n=!0,debug:r=!1,material:i}=t??{},a=r?performance.now():0,o=performance.now(),s={mergeByMaterial:n,debug:r,material:i},c=await et(e,s);if(c.meshes)return c.meshes;let l=await it(c,s);if(l)return l;let u=fe(c.raw),d=performance.now()-o,f=e.byteLength;return $e(u,{mergeByMaterial:n,debug:r,material:i,parseTime:0,decodeTime:d,perfStart:a,blobBytes:f})}let Ze=!1;function Qe(e,n){if(e||Ze)return;let r=0;for(let e of n)r+=e.meshes.length;r<1e3||(Ze=!0,t.p().warn(`Parsing ${r} meshes with mergeByMaterial: false — each becomes its own THREE object, and render cost scales with object count. Drop the option to merge by material (the default); per-object identity survives it via userData.members.`))}function $e(e,n){let{mergeByMaterial:r,debug:i,material:a,parseTime:o,decodeTime:s,perfStart:c,blobBytes:l,fallback:u}=n,d=e.metadata.materials??u?.materials??[],f=e.metadata.groups??u?.groups??[],p=!!(e.flags&1);J(f,d.length,e.vertices.length/3,e.indices.length);let m=p?e.vertices:Me(e.vertices,e.origin,e.scale);if(i){let n=e.vertices.byteLength+e.indices.byteLength;t.p().debug(`Mesh Batch Stats:`),t.p().debug(` Materials: ${d.length} | Groups: ${f.length}`),t.p().debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),t.p().debug(` Format: ${p?`float32`:`int16 quantized`}`),t.p().debug(` Blob: ${(l/1024/1024).toFixed(2)} MB | Geometry on wire: ${(n/1024/1024).toFixed(2)} MB`)}Qe(r,f);let h=performance.now(),g=De(d,{vertexColors:e.colors!=null,hasUvs:e.uvs!=null,appearance:a}),_=[],v=r?Pe(f):f;for(let t of v)if(r&&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(i){let e=performance.now()-c;t.p().debug(`Performance:`),o>0&&t.p().debug(` Parse JSON: ${o.toFixed(2)}ms`),t.p().debug(` Decode binary: ${s.toFixed(2)}ms`),t.p().debug(` Create Meshes: ${y.toFixed(2)}ms`),t.p().debug(` Total: ${e.toFixed(2)}ms`)}return Promise.resolve(_)}async function et(e,t){let n=b(e);if(!ie(n))return{raw:V(n),geometryBytes:null,source:n,reparse:()=>V(n)};let r=ae(n),i=nt(r,t);if(i)return{meshes:i};let a=r.geometryBlob,o=()=>{let e=V(a);return e.metadata=r.metadata,e},s=await tt(r),c=s?V(s):o();return c.metadata=r.metadata,{raw:c,geometryBytes:a,source:a,reparse:o}}async function tt(e){if(S(e.geometryBlob)<4194304||!ye())return null;try{return await D(e.geometryBlob)}catch{return null}}function nt(e,t){let n=e.metadata.materials??t.fallback?.materials??[],r=e.metadata.groups??t.fallback?.groups??[],{jobs:i,jobRefs:a}=rt(r,t.mergeByMaterial),o=Ve(e.geometryBlob,i);return o?(J(r,n.length,o.vertexCount,o.indexCount),st(o,a,n,t.material)):null}function rt(e,t){let n=e=>({vertexStart:e.vertexStart,vertexCount:e.vertexCount,indexStart:e.indexStart,indexCount:e.indexCount}),r=[],i=[],a=t?Pe(e):e;for(let e of a)if(t&&e.meshes.length>1)r.push({kind:`merged`,windows:e.meshes.map(n)}),i.push({kind:`merged`,group:e});else for(let t of e.meshes)r.push({kind:`single`,windows:[n(t)]}),i.push({kind:`single`,group:e,meshMeta:t});return{jobs:r,jobRefs:i}}async function it(e,n){let{raw:r,geometryBytes:i}=e,a=r.planarByteSplit?r.indexData.length/(r.uint16Indices?2:4):r.indexData.length;if(a/3<5e4)return null;let o=r.metadata.materials??n.fallback?.materials??[],s=r.metadata.groups??n.fallback?.groups??[];J(s,o.length,r.vertexCount,a);let{jobs:c,jobRefs:l}=rt(s,n.mergeByMaterial),u=await ot(r,c,e.source);if(!u)return at(r,e.source)&&(e.raw=e.reparse()),null;let d={geometries:u,hasUvs:r.uvs!=null,hasColors:r.colors!=null,vertexCount:r.vertexCount,indexCount:a},f=i?Ue(i,c,d):He(d);return n.debug&&t.p().debug(`Mesh batch assembled: ${u.length} geometries, ${a/3} triangles`),st(f,l,o,n.material)}function at(e,t){return e.vertexData.buffer!==t.buffer&&e.indexData.buffer!==t.buffer}async function ot(e,n,r){let i=ye(),a={vertexData:e.vertexData,isFloat32:e.isFloat32,deltaEncoded:e.deltaEncoded,planarByteSplit:e.planarByteSplit,uint16Indices:e.uint16Indices,origin:e.origin,scale:e.scale,indexData:e.indexData,uvs:e.uvs,colors:e.colors,jobs:n};if(!i)return ge(a).map((e,t)=>H(e,n[t].windows.map(e=>e.indexCount)));at(e,r)||(a.vertexData=e.vertexData.slice(),a.indexData=e.indexData.slice(),a.uvs=e.uvs?.slice()??null,a.colors=e.colors?.slice()??null);let o=/* @__PURE__ */ new Set([a.vertexData.buffer,a.indexData.buffer]);a.uvs&&o.add(a.uvs.buffer),a.colors&&o.add(a.colors.buffer);try{let e=await be(i,a,[...o]);return e.length===n.length?e:null}catch(e){return t.p().warn(`Mesh assembly worker failed; falling back to main-thread parse.`,e),null}}function st(e,t,n,r){let i=De(n,{vertexColors:e.hasColors,hasUvs:e.hasUvs,appearance:r}),a=[];for(let n=0;n<e.buffers.length;n++){let r=e.buffers[n],o=t[n],s=i(o.group.materialId,e.closed[n]),c=o.kind===`merged`?Le(r,o.group,s):ze(r,o.meshMeta,s);a.push(c)}return a}function ct(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 lt(e){let t=e.split(`.`);return t.includes(`Display`)||t.includes(`DisplayBatch`)}const ut=/* @__PURE__ */ new Set;async function dt(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 pt(e,r,i?ft(e.modelunits):1,c,s),a&&_t(r,o),r}catch(e){throw vt(e,r),e}finally{s&&bt(n)}}function ft(e){let n=$[e];return n===void 0?(ut.has(e)||(ut.add(e),t.p().warn(`Unknown Rhino model unit "${e}" — geometry will not be scaled (factor 1). Known units: ${Object.keys($).join(`, `)}.`)),1):n}async function pt(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 mt(o,t,n,r,i)}}}async function mt(e,n,r,i,a){for(let o of e){if(!lt(o.type))continue;let e={debug:!1,...i,mergeByMaterial:i.mergeByMaterial??!0},s=ht(o.data);if(!s){t.p().error(`Error parsing display batch envelope: invalid JSON`);continue}let c=await Ye(s,e),l=v(s.items),u=[...c,...l];if(r!==1)for(let e of u)e.scale.set(r,r,r);n.push(...u),a&&t.p().debug(`Extracted ${c.length} meshes and ${l.length} items from batch`)}}function ht(e){return typeof e==`string`?gt(e):e}function gt(e){try{return JSON.parse(e)}catch{return}}function _t(e,n){if(e.length===0)return;let r=t.a(e);t.i(e,r.min[n],n)}function vt(e,n){t.p().error(`An unexpected error occurred:`,e),yt(n)}function yt(e){for(let n of e)t.t(n)}function bt(e){let n=performance.now()-e;t.p().info(`Time to process meshes:`,`${n.toFixed(2)}ms`)}exports.SCALE_FACTORS=$,exports.clearGeometryCache=We,exports.getThreeObjectsFromComputeResponse=dt,exports.meshPolicy=p,exports.parseDisplayItems=v,exports.parseMeshBatchBlob=Xe,exports.parseMeshBatchObject=Ye,exports.setTextureAnisotropy=Se;
|
|
67
|
+
#endif`)})}function q(e,n){return new t.g(e,t.h.VALIDATION_ERROR,{context:n})}function J(e,t,n,r){for(let i of e){if(!Number.isInteger(i.materialId)||i.materialId<0||i.materialId>=t)throw q(`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 q(`Mesh metadata field "${n}" must be a non-negative integer.`,{meshName:e.name,field:n,value:r});if(e.vertexStart+e.vertexCount>n)throw q(`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 q(`Mesh index window exceeds the batch index buffer.`,{meshName:e.name,indexStart:e.indexStart,indexCount:e.indexCount,totalIndexCount:r})}}}function je(e,t){return q(`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=/* @__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 Pe(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=t.get(n.materialId);if(e)for(let t of n.meshes)e.push(t);else t.set(n.materialId,n.meshes.slice())}return[...t].flatMap(([e,t])=>Ne({materialId:e,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 je(t,r);l[p+e]=t+m}f+=r.vertexCount,p+=r.indexCount}let m=H({positions:c,indices:l,uvs:u,colors:d},e.meshes);return Le(Y(m),e,r(e.materialId,m.closed))}function Y(e){let t=new n.BufferGeometry;return t.setAttribute(`position`,new n.BufferAttribute(e.positions,3)),t.setAttribute(`normal`,new n.BufferAttribute(e.normals,3)),t.setIndex(new n.BufferAttribute(e.indices,1)),e.uvs&&t.setAttribute(`uv`,new n.BufferAttribute(e.uvs,2)),e.tangents&&t.setAttribute(`tangent`,new n.BufferAttribute(e.tangents,4)),e.colors&&t.setAttribute(`color`,new n.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,r){let i=new n.Mesh(e,r),a=t.meshes[0],o=t.meshes.map(e=>e.name).filter(e=>e&&e.length>0);return i.name=o.length>0?o[0]:`merged_material_${t.materialId}`,i.castShadow=!0,i.receiveShadow=!0,i.userData={source:`compute`,name:i.name,layer:a?.layer??``,metadata:a?.metadata??{},members:Ie(t)},i}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 je(t,s);f[e]=t-p}let h=s.vertexStart*2,g=H({positions:u,indices:f,uvs:i?i.slice(h,h+s.vertexCount*2):null,colors:a?a.slice(c,c+l):null},[s]);o.push(ze(Y(g),s,r(e.materialId,g.closed)))}return o}function ze(e,t,r){let i=new n.Mesh(e,r);return i.name=t.name,i.userData={source:`compute`,name:t.name,layer:t.layer??``,trackingKey:t.id,metadata:t.metadata??{}},i.castShadow=!0,i.receiveShadow=!0,i}const Be=268435456,X=/* @__PURE__ */ new Map;let Z=0;function Ve(e,t){let n=Ge(t),r=Ke(e,n),i=X.get(r);return!i||!qe(i.jobShape,n)||!Je(i.geometryBytes,e)?null:(X.delete(r),X.set(r,i),i)}function He(e){let{geometries:t,...n}=e;return{...n,buffers:t.map(Y),closed:t.map(e=>e.closed)}}function Ue(t,n,r){let i=He(r),a=t.byteLength;for(let e of r.geometries)a+=e.positions.byteLength+e.normals.byteLength+e.indices.byteLength,a+=(e.uvs?.byteLength??0)+(e.colors?.byteLength??0)+(e.tangents?.byteLength??0);if(a>Be)return i;let o=Ge(n),s=Ke(t,o),c=X.get(s);c&&(X.delete(s),Q(c)),i.buffers.forEach(e.a),X.set(s,{...i,geometryBytes:t.slice(),jobShape:o,bytes:a}),Z+=a;for(let[e,t]of X){if(Z<=Be)break;X.delete(e),Q(t)}return i}function We(){X.forEach(Q),X.clear()}function Q(t){Z-=t.bytes;for(let n of t.buffers)e.o(n),n.dispose()}function Ge(e){let t=0;for(let n of e)t+=2+4*n.windows.length;let n=new Int32Array(t),r=0;for(let t of e){n[r++]=+(t.kind===`merged`),n[r++]=t.windows.length;for(let e of t.windows)n[r++]=e.vertexStart,n[r++]=e.vertexCount,n[r++]=e.indexStart,n[r++]=e.indexCount}return n}function Ke(e,t){let n=e.length,r=Math.max(1,Math.floor(n/1024)),i=2166136261;for(let t=0;t<n;t+=r)i=Math.imul(i^e[t],16777619);let a=2166136261;for(let e=0;e<t.length;e++)a=Math.imul(a^t[e],16777619);return`${n}:${i>>>0}:${t.length}:${a>>>0}`}function qe(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Je(e,t){if(e.length!==t.length)return!1;let n=0;if(e.byteOffset%4==0&&t.byteOffset%4==0){let r=e.length>>>2,i=new Uint32Array(e.buffer,e.byteOffset,r),a=new Uint32Array(t.buffer,t.byteOffset,r);for(;n<r;n++)if(i[n]!==a[n])return!1;n=r<<2}for(;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}async function Ye(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={mergeByMaterial:r,debug:i,material:a,fallback:{materials:e.materials,groups:e.groups}},u=await et(e.compressedData,l);return u.meshes?u.meshes:await it(u,l)||$e(fe(u.raw),{mergeByMaterial:r,debug:i,material:a,parseTime:o,decodeTime:performance.now()-c,perfStart:s,blobBytes:i?ct(e.compressedData):0,fallback:{materials:e.materials,groups:e.groups}})}async function Xe(e,t){let{mergeByMaterial:n=!0,debug:r=!1,material:i}=t??{},a=r?performance.now():0,o=performance.now(),s={mergeByMaterial:n,debug:r,material:i},c=await et(e,s);if(c.meshes)return c.meshes;let l=await it(c,s);if(l)return l;let u=fe(c.raw),d=performance.now()-o,f=e.byteLength;return $e(u,{mergeByMaterial:n,debug:r,material:i,parseTime:0,decodeTime:d,perfStart:a,blobBytes:f})}let Ze=!1;function Qe(e,n){if(e||Ze)return;let r=0;for(let e of n)r+=e.meshes.length;r<1e3||(Ze=!0,t.p().warn(`Parsing ${r} meshes with mergeByMaterial: false — each becomes its own THREE object, and render cost scales with object count. Drop the option to merge by material (the default); per-object identity survives it via userData.members.`))}function $e(e,n){let{mergeByMaterial:r,debug:i,material:a,parseTime:o,decodeTime:s,perfStart:c,blobBytes:l,fallback:u}=n,d=e.metadata.materials??u?.materials??[],f=e.metadata.groups??u?.groups??[],p=!!(e.flags&1);J(f,d.length,e.vertices.length/3,e.indices.length);let m=p?e.vertices:Me(e.vertices,e.origin,e.scale);if(i){let n=e.vertices.byteLength+e.indices.byteLength;t.p().debug(`Mesh Batch Stats:`),t.p().debug(` Materials: ${d.length} | Groups: ${f.length}`),t.p().debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),t.p().debug(` Format: ${p?`float32`:`int16 quantized`}`),t.p().debug(` Blob: ${(l/1024/1024).toFixed(2)} MB | Geometry on wire: ${(n/1024/1024).toFixed(2)} MB`)}Qe(r,f);let h=performance.now(),g=De(d,{vertexColors:e.colors!=null,hasUvs:e.uvs!=null,appearance:a}),_=[],v=r?Pe(f):f;for(let t of v)if(r&&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);for(let e of n)_.push(e)}let y=performance.now()-h;if(i){let e=performance.now()-c;t.p().debug(`Performance:`),o>0&&t.p().debug(` Parse JSON: ${o.toFixed(2)}ms`),t.p().debug(` Decode binary: ${s.toFixed(2)}ms`),t.p().debug(` Create Meshes: ${y.toFixed(2)}ms`),t.p().debug(` Total: ${e.toFixed(2)}ms`)}return Promise.resolve(_)}async function et(e,t){let n=b(e);if(!ie(n))return{raw:V(n),geometryBytes:null,source:n,reparse:()=>V(n)};let r=ae(n),i=nt(r,t);if(i)return{meshes:i};let a=r.geometryBlob,o=()=>{let e=V(a);return e.metadata=r.metadata,e},s=await tt(r),c=s?V(s):o();return c.metadata=r.metadata,{raw:c,geometryBytes:a,source:a,reparse:o}}async function tt(e){if(S(e.geometryBlob)<4194304||!ye())return null;try{return await D(e.geometryBlob)}catch{return null}}function nt(e,t){let n=e.metadata.materials??t.fallback?.materials??[],r=e.metadata.groups??t.fallback?.groups??[],{jobs:i,jobRefs:a}=rt(r,t.mergeByMaterial),o=Ve(e.geometryBlob,i);return o?(J(r,n.length,o.vertexCount,o.indexCount),st(o,a,n,t.material)):null}function rt(e,t){let n=e=>({vertexStart:e.vertexStart,vertexCount:e.vertexCount,indexStart:e.indexStart,indexCount:e.indexCount,closed:e.closed}),r=[],i=[],a=t?Pe(e):e;for(let e of a)if(t&&e.meshes.length>1)r.push({kind:`merged`,windows:e.meshes.map(n)}),i.push({kind:`merged`,group:e});else for(let t of e.meshes)r.push({kind:`single`,windows:[n(t)]}),i.push({kind:`single`,group:e,meshMeta:t});return{jobs:r,jobRefs:i}}async function it(e,n){let{raw:r,geometryBytes:i}=e,a=r.planarByteSplit?r.indexData.length/(r.uint16Indices?2:4):r.indexData.length;if(a/3<5e4)return null;let o=r.metadata.materials??n.fallback?.materials??[],s=r.metadata.groups??n.fallback?.groups??[];J(s,o.length,r.vertexCount,a);let{jobs:c,jobRefs:l}=rt(s,n.mergeByMaterial),u=await ot(r,c,e.source);if(!u)return at(r,e.source)&&(e.raw=e.reparse()),null;let d={geometries:u,hasUvs:r.uvs!=null,hasColors:r.colors!=null,vertexCount:r.vertexCount,indexCount:a},f=i?Ue(i,c,d):He(d);return n.debug&&t.p().debug(`Mesh batch assembled: ${u.length} geometries, ${a/3} triangles`),st(f,l,o,n.material)}function at(e,t){return e.vertexData.buffer!==t.buffer&&e.indexData.buffer!==t.buffer}async function ot(e,n,r){let i=ye(),a={vertexData:e.vertexData,isFloat32:e.isFloat32,deltaEncoded:e.deltaEncoded,planarByteSplit:e.planarByteSplit,uint16Indices:e.uint16Indices,origin:e.origin,scale:e.scale,indexData:e.indexData,uvs:e.uvs,colors:e.colors,jobs:n};if(!i)return ge(a).map((e,t)=>H(e,n[t].windows));at(e,r)||(a.vertexData=e.vertexData.slice(),a.indexData=e.indexData.slice(),a.uvs=e.uvs?.slice()??null,a.colors=e.colors?.slice()??null);let o=/* @__PURE__ */ new Set([a.vertexData.buffer,a.indexData.buffer]);a.uvs&&o.add(a.uvs.buffer),a.colors&&o.add(a.colors.buffer);try{let e=await be(i,a,[...o]);return e.length===n.length?e:null}catch(e){return t.p().warn(`Mesh assembly worker failed; falling back to main-thread parse.`,e),null}}function st(e,t,n,r){let i=De(n,{vertexColors:e.hasColors,hasUvs:e.hasUvs,appearance:r}),a=[];for(let n=0;n<e.buffers.length;n++){let r=e.buffers[n],o=t[n],s=i(o.group.materialId,e.closed[n]),c=o.kind===`merged`?Le(r,o.group,s):ze(r,o.meshMeta,s);a.push(c)}return a}function ct(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 lt(e){let t=e.split(`.`);return t.includes(`Display`)||t.includes(`DisplayBatch`)}const ut=/* @__PURE__ */ new Set;async function dt(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 pt(e,r,i?ft(e.modelunits):1,c,s),a&&_t(r,o),r}catch(e){throw vt(e,r),e}finally{s&&bt(n)}}function ft(e){let n=$[e];return n===void 0?(ut.has(e)||(ut.add(e),t.p().warn(`Unknown Rhino model unit "${e}" — geometry will not be scaled (factor 1). Known units: ${Object.keys($).join(`, `)}.`)),1):n}async function pt(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 mt(o,t,n,r,i)}}}async function mt(e,n,r,i,a){for(let o of e){if(!lt(o.type))continue;let e={debug:!1,...i,mergeByMaterial:i.mergeByMaterial??!0},s=ht(o.data);if(!s){t.p().error(`Error parsing display batch envelope: invalid JSON`);continue}let c=await Ye(s,e),l=v(s.items),u=[...c,...l];if(r!==1)for(let e of u)e.scale.set(r,r,r);for(let e of u)n.push(e);a&&t.p().debug(`Extracted ${c.length} meshes and ${l.length} items from batch`)}}function ht(e){return typeof e==`string`?gt(e):e}function gt(e){try{return JSON.parse(e)}catch{return}}function _t(e,n){if(e.length===0)return;let r=t.a(e);t.i(e,r.min[n],n)}function vt(e,n){t.p().error(`An unexpected error occurred:`,e),yt(n)}function yt(e){for(let n of e)t.t(n)}function bt(e){let n=performance.now()-e;t.p().info(`Time to process meshes:`,`${n.toFixed(2)}ms`)}exports.SCALE_FACTORS=$,exports.clearGeometryCache=We,exports.getThreeObjectsFromComputeResponse=dt,exports.meshPolicy=p,exports.parseDisplayItems=v,exports.parseMeshBatchBlob=Xe,exports.parseMeshBatchObject=Ye,exports.setTextureAnisotropy=Se;
|
|
68
68
|
//# sourceMappingURL=parse.cjs.map
|