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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +7 -7
  2. package/dist/gpu-dispose-Dkj-BKt4.js +2 -0
  3. package/dist/gpu-dispose-Dkj-BKt4.js.map +1 -0
  4. package/dist/gpu-dispose-DrN-ryj5.cjs +2 -0
  5. package/dist/gpu-dispose-DrN-ryj5.cjs.map +1 -0
  6. package/dist/index.cjs +0 -1
  7. package/dist/index.d.cts +1 -2
  8. package/dist/index.d.ts +1 -2
  9. package/dist/index.js +1 -1
  10. package/dist/parse.cjs +3 -3
  11. package/dist/parse.cjs.map +1 -1
  12. package/dist/parse.d.cts +117 -110
  13. package/dist/parse.d.ts +117 -110
  14. package/dist/parse.js +3 -3
  15. package/dist/parse.js.map +1 -1
  16. package/dist/render.cjs +5 -6
  17. package/dist/render.cjs.map +1 -1
  18. package/dist/render.d.cts +441 -312
  19. package/dist/render.d.ts +441 -312
  20. package/dist/render.js +5 -6
  21. package/dist/render.js.map +1 -1
  22. package/dist/rolldown-runtime-BocRIvOZ.cjs +1 -0
  23. package/dist/scene.cjs +1 -1
  24. package/dist/scene.cjs.map +1 -1
  25. package/dist/scene.d.cts +94 -89
  26. package/dist/scene.d.ts +94 -89
  27. package/dist/scene.js +1 -1
  28. package/dist/scene.js.map +1 -1
  29. package/dist/types-Di80Y609.d.cts +34 -0
  30. package/dist/types-Di80Y609.d.ts +34 -0
  31. package/package.json +13 -8
  32. package/dist/chunk-5XGN7UAV.js +0 -2
  33. package/dist/chunk-5XGN7UAV.js.map +0 -1
  34. package/dist/chunk-AZ4GBXXL.cjs +0 -2
  35. package/dist/chunk-AZ4GBXXL.cjs.map +0 -1
  36. package/dist/chunk-BYLIBOAU.cjs +0 -2
  37. package/dist/chunk-BYLIBOAU.cjs.map +0 -1
  38. package/dist/chunk-KRA5RVHM.js +0 -2
  39. package/dist/chunk-KRA5RVHM.js.map +0 -1
  40. package/dist/index.cjs.map +0 -1
  41. package/dist/index.js.map +0 -1
  42. package/dist/types-DCuos3gI.d.cts +0 -33
  43. package/dist/types-DCuos3gI.d.ts +0 -33
package/dist/parse.js CHANGED
@@ -1,10 +1,10 @@
1
- import{a as F,b as _,c as v,f as ce,k as ue,l as fe,m as me,o as de,p as pe}from"./chunk-KRA5RVHM.js";import"./chunk-5XGN7UAV.js";function Xe(e){return e.map(t=>{let r=t.clone(!0),n=[];t.traverse(o=>n.push(o));let a=0;return r.traverse(o=>{let i=n[a++],c=o;i.geometry&&(c.geometry=i.geometry.clone())}),r})}function Ze(e){e.forEach(t=>pe(t,{materials:!1}))}var qe={clone:Xe,release:Ze};import{Line2 as Qe}from"three/addons/lines/Line2.js";import{LineGeometry as et}from"three/addons/lines/LineGeometry.js";import{LineMaterial as tt}from"three/addons/lines/LineMaterial.js";import*as ye from"three";var Ke="#ffffff";function z(e,t){let r=t??1;return{color:new ye.Color(e??Ke),transparent:r<1,opacity:r}}var rt=2,nt=6;function he(e){let t=ot(e);if(!t)return null;let r=new et;r.setPositions(t);let n=z(e.color,e.opacity),a=new tt({color:n.color}),o=a;o.linewidth=e.width??rt,o.transparent=n.transparent,o.opacity=n.opacity;let i=new Qe(r,a);return i.computeLineDistances(),i.name=e.name,i.userData={source:"compute",id:e.id,layer:e.layer,kind:"curve",metadata:e.metadata},i}function ot(e){if(!e.points)throw new _(`Curve display item '${e.id}' has no tessellated points. It was produced by an outdated Display component \u2014 upgrade it in Grasshopper (Solution \u2192 Upgrade obsolete components) and re-save the definition.`,F.INVALID_CONFIG,{context:{itemId:e.id,kind:e.kind}});return e.points.length>=nt?e.points:null}import*as H from"three";function be(e){let{position:t}=e;if(!t||typeof t.X!="number"||!Number.isFinite(t.X)||typeof t.Y!="number"||!Number.isFinite(t.Y)||typeof t.Z!="number"||!Number.isFinite(t.Z))return v().warn(`Skipping point display item with missing or non-finite position (id: ${String(e.id)}).`),null;let r=new H.BufferGeometry;r.setAttribute("position",new H.Float32BufferAttribute([t.X,t.Y,t.Z],3));let n=new H.PointsMaterial({...z(e.color,e.opacity),size:6,sizeAttenuation:!1}),a=new H.Points(r,n);return a.name=e.name,a.userData={source:"compute",id:e.id,layer:e.layer,kind:"point",metadata:e.metadata},a}function q(e){if(!e||e.length===0)return[];let t=[];for(let r of e)switch(r.kind){case"curve":{let n=he(r);n&&t.push(n);break}case"point":{let n=be(r);n&&t.push(n);break}default:{let a=r;v().warn(`Skipping unknown display item kind: ${String(a.kind)}`);break}}return t}import*as P from"three";var ge=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;import{inflateSync as at}from"fflate";function Ae(e){return typeof e=="string"?ce(e):e instanceof Uint8Array?e:new Uint8Array(e)}function xe(e){if(e.byteLength<8)return e;let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getUint32(0,!0)!==1515605075)return e;let r=t.getUint32(4,!0),n=e.subarray(8),a=Math.max(n.byteLength*1032+1024,1<<20);if(r>a)throw T("SLVZ header declares an implausible uncompressed length",{uncompressedLen:r,deflatedBytes:n.byteLength,maxPlausibleLen:a});let o;try{o=at(n,{out:new Uint8Array(r+1)})}catch(i){throw T(`Failed to inflate SLVZ blob: ${i instanceof Error?i.message:String(i)}`,{uncompressedLen:r,deflatedBytes:n.byteLength})}if(o.byteLength!==r)throw T("SLVZ payload inflated to a different size than the header declares.",{declaredLen:r,actualLen:o.byteLength,deflatedBytes:n.byteLength});return o}function Ee(e){if(typeof TextDecoder<"u")return new TextDecoder("utf-8").decode(e);if(typeof globalThis.Buffer<"u")return globalThis.Buffer.from(e).toString("utf-8");throw new _("No UTF-8 decoder available in this environment.",F.INVALID_STATE)}function we(e,t,r){if(r===0)return new Int16Array(0);if(t%2===0)return new Int16Array(e,t,r);let n=new Uint8Array(r*2);return n.set(new Uint8Array(e,t,r*2)),new Int16Array(n.buffer)}function W(e,t,r){if(r===0)return new Float32Array(0);if(t%4===0)return new Float32Array(e,t,r);let n=new Uint8Array(r*4);return n.set(new Uint8Array(e,t,r*4)),new Float32Array(n.buffer)}function V(e,t,r){if(r===0)return new Uint16Array(0);if(t%2===0)return new Uint16Array(e,t,r);let n=new Uint8Array(r*2);return n.set(new Uint8Array(e,t,r*2)),new Uint16Array(n.buffer)}function Me(e,t,r){if(r===0)return new Uint32Array(0);if(t%4===0)return new Uint32Array(e,t,r);let n=new Uint8Array(r*4);return n.set(new Uint8Array(e,t,r*4)),new Uint32Array(n.buffer)}function ve(e,t){if(e.length!==0&&!(e instanceof Uint16Array&&t>65535)){for(let r=0;r<e.length;r++)if(e[r]>=t)throw T("Index out of range of vertexCount.",{indexPosition:r,indexValue:e[r],vertexCount:t})}}function C(e){return e>>>1^-(e&1)}function Se(e){let t=new Int16Array(e.length),r=0,n=0,a=0;for(let o=0;o<e.length;o+=3)r=r+C(e[o])<<16>>16,n=n+C(e[o+1])<<16>>16,a=a+C(e[o+2])<<16>>16,t[o]=r,t[o+1]=n,t[o+2]=a;return t}function Te(e){let t=new Uint16Array(e.length),r=0;for(let n=0;n<e.length;n++)r=r+C(e[n])&65535,t[n]=r;return t}function Re(e){let t=new Uint32Array(e.length),r=0;for(let n=0;n<e.length;n++)r=r+C(e[n])>>>0,t[n]=r;return t}function T(e,t){return new _(e,F.VALIDATION_ERROR,{context:t})}var Be=36;function Ie(e,t,r,n,a){if(r+Be>e.byteLength)throw T("Insufficient data to read UV chunk header.",{expectedBytes:Be,availableBytes:e.byteLength-r,offset:r});let o=t.getUint32(r,!0);r+=4;let i=t.getFloat64(r,!0);r+=8;let c=t.getFloat64(r,!0);r+=8;let f=t.getFloat64(r,!0);r+=8;let m=t.getFloat64(r,!0);r+=8;let l=n*2,w=o===1,M=l*(w?4:2);if(r+M>e.byteLength)throw T("Insufficient data to read UV chunk.",{expectedBytes:M,availableBytes:e.byteLength-r,offset:r,uvFormat:o,vertexCount:n});let d=e.byteOffset+r,h;if(w)h=W(e.buffer,d,l).slice();else{let u=V(e.buffer,d,l);h=new Float32Array(l);let s=0,y=0;for(let x=0;x<l;x+=2)a?(s=s+C(u[x])&65535,y=y+C(u[x+1])&65535):(s=u[x],y=u[x+1]),h[x]=i+s*f,h[x+1]=c+y*m}return{uvs:h,offset:r+M}}function De(e,t,r,n){let a=r*3;if(t+a>e.byteLength)throw T("Insufficient data to read vertex-color chunk.",{expectedBytes:a,availableBytes:e.byteLength-t,offset:t,vertexCount:r});let o=e.subarray(t,t+a);if(!n)return o.slice();let i=new Uint8Array(a),c=0,f=0,m=0;for(let l=0;l<a;l+=3)c=c+C(o[l])&255,f=f+C(o[l+1])&255,m=m+C(o[l+2])&255,i[l]=c,i[l+1]=f,i[l+2]=m;return i}function Q(e){let t=ee(e),r;t.isFloat32?r=t.vertexData:t.deltaEncoded?r=Se(t.vertexData):r=t.vertexData;let n=t.indexData;return t.deltaEncoded&&(n=n instanceof Uint16Array?Te(n):Re(n)),ve(n,t.vertexCount),{metadata:t.metadata,flags:t.flags,vertices:r,indices:n,origin:t.origin,scale:t.scale,uvs:t.uvs,colors:t.colors}}function ee(e){if(!ge)throw new _("SLVA parsing requires a little-endian host: the zero-copy geometry readers view the wire bytes in host byte order.",F.ENVIRONMENT_ERROR);let t=xe(Ae(e)),r=new DataView(t.buffer,t.byteOffset,t.byteLength);if(t.byteLength<12)throw T("Blob too small to contain SLVA header.",{expectedBytes:12,availableBytes:t.byteLength});let n=0,a=r.getUint32(n,!0);if(n+=4,a!==1096174675)throw T(`Invalid SLVA magic: 0x${a.toString(16)}`,{expectedMagic:`0x${1096174675 .toString(16)}`,actualMagic:`0x${a.toString(16)}`});let o=r.getUint32(n,!0);if(n+=4,o<1||o>3)throw T(`Unsupported SLVA version: ${o}`,{minSupportedVersion:1,maxSupportedVersion:3,actualVersion:o});let i=r.getUint32(n,!0);if(n+=4,n+i>t.byteLength)throw T("Insufficient data to read metadata JSON.",{expectedBytes:i,availableBytes:t.byteLength-n,offset:n});let c=t.subarray(n,n+i);n+=i;let f;try{f=JSON.parse(Ee(c))}catch(L){throw T(`Failed to parse metadata JSON: ${L instanceof Error?L.message:String(L)}`,{metadataLen:i})}if(n+56>t.byteLength)throw T("Insufficient data to read geometry header.",{expectedBytes:56,availableBytes:t.byteLength-n,offset:n});let m=r.getUint32(n,!0);n+=4;let l=r.getFloat64(n,!0);n+=8;let w=r.getFloat64(n,!0);n+=8;let M=r.getFloat64(n,!0);n+=8;let d=r.getFloat64(n,!0);n+=8;let h=r.getFloat64(n,!0);n+=8;let u=r.getFloat64(n,!0);n+=8;let s=r.getUint32(n,!0);n+=4;let y=(m&1)!==0,x=(m&4)!==0,A=s*3,B=A*(y?4:2);if(n+B>t.byteLength)throw T("Insufficient data to read vertices.",{expectedBytes:B,availableBytes:t.byteLength-n,offset:n,useFloat32:y,vertexCount:s});let b=t.byteOffset+n,p;if(y?p=W(t.buffer,b,A):x?p=V(t.buffer,b,A):p=we(t.buffer,b,A),n+=B,n+4>t.byteLength)throw T("Insufficient data to read index count.",{expectedBytes:4,availableBytes:t.byteLength-n,offset:n});let E=r.getUint32(n,!0);n+=4;let S=(m&2)!==0,D=E*(S?2:4);if(n+D>t.byteLength)throw T("Insufficient data to read indices.",{expectedBytes:D,availableBytes:t.byteLength-n,offset:n,indexCount:E,useUint16Indices:S});let O=S?V(t.buffer,t.byteOffset+n,E):Me(t.buffer,t.byteOffset+n,E);n+=D;let U=null;if((m&8)!==0){let L=Ie(t,r,n,s,x);U=L.uvs,n=L.offset}let G=null;return(m&16)!==0&&(G=De(t,n,s,x)),{metadata:f,flags:m,vertexData:p,indexData:O,isFloat32:y,deltaEncoded:x,vertexCount:s,origin:[l,w,M],scale:[d,h,u],uvs:U,colors:G}}function ut(e){let{isFloat32:t,deltaEncoded:r,origin:n,scale:a,uvs:o,colors:i,jobs:c}=e,f=d=>d>>>1^-(d&1),m;if(t)m=e.vertexData;else{let d;if(r){let g=e.vertexData;d=new Int16Array(g.length);let B=0,b=0,p=0;for(let E=0;E<g.length;E+=3)B=B+f(g[E])<<16>>16,b=b+f(g[E+1])<<16>>16,p=p+f(g[E+2])<<16>>16,d[E]=B,d[E+1]=b,d[E+2]=p}else d=e.vertexData;m=new Float32Array(d.length);let h=n[0],u=n[1],s=n[2],y=a[0],x=a[1],A=a[2];for(let g=0;g<d.length;g+=3)m[g]=h+(d[g]+32767)*y,m[g+1]=u+(d[g+1]+32767)*x,m[g+2]=s+(d[g+2]+32767)*A}let l;if(r){let d=e.indexData;if(d instanceof Uint16Array){let h=new Uint16Array(d.length),u=0;for(let s=0;s<d.length;s++)u=u+f(d[s])&65535,h[s]=u;l=h}else{let h=new Uint32Array(d.length),u=0;for(let s=0;s<d.length;s++)u=u+f(d[s])>>>0,h[s]=u;l=h}}else l=e.indexData;let w=m.length/3;for(let d=0;d<l.length;d++)if(l[d]>=w)throw new Error(`Index ${l[d]} out of range of vertexCount ${w}`);let M=[];for(let d of c){let h=0,u=0;for(let p of d.windows)h+=p.vertexCount,u+=p.indexCount;let s=new Float32Array(h*3),y=new Uint32Array(u),x=o?new Float32Array(h*2):null,A=i?new Uint8Array(h*3):null,g=0,B=0;for(let p of d.windows){let E=p.vertexStart*3;s.set(m.subarray(E,E+p.vertexCount*3),g*3),x&&o&&x.set(o.subarray(p.vertexStart*2,(p.vertexStart+p.vertexCount)*2),g*2),A&&i&&A.set(i.subarray(E,E+p.vertexCount*3),g*3);let S=p.vertexStart,I=p.vertexStart+p.vertexCount,D=g-p.vertexStart;for(let O=0;O<p.indexCount;O++){let U=l[p.indexStart+O];if(U<S||U>=I)throw new Error(`Index ${U} outside vertex window [${S}, ${I})`);y[B+O]=U+D}g+=p.vertexCount,B+=p.indexCount}let b=new Float32Array(h*3);for(let p=0;p<y.length;p+=3){let E=y[p]*3,S=y[p+1]*3,I=y[p+2]*3,D=s[I]-s[S],O=s[I+1]-s[S+1],U=s[I+2]-s[S+2],G=s[E]-s[S],L=s[E+1]-s[S+1],le=s[E+2]-s[S+2],J=O*le-U*L,X=U*G-D*le,Z=D*L-O*G;b[E]+=J,b[E+1]+=X,b[E+2]+=Z,b[S]+=J,b[S+1]+=X,b[S+2]+=Z,b[I]+=J,b[I+1]+=X,b[I+2]+=Z}for(let p=0;p<b.length;p+=3){let E=b[p],S=b[p+1],I=b[p+2],D=Math.sqrt(E*E+S*S+I*I)||1;b[p]=E/D,b[p+1]=S/D,b[p+2]=I/D}M.push({positions:s,normals:b,indices:y,uvs:x,colors:A})}return M}function _e(){return[`const assemble = ${ut.toString()};`,"self.onmessage = (event) => {"," const { id, input } = event.data;"," try {"," const geometries = assemble(input);"," const transfer = [];"," for (const g of geometries) {"," transfer.push(g.positions.buffer, g.normals.buffer, g.indices.buffer);"," if (g.uvs) transfer.push(g.uvs.buffer);"," if (g.colors) transfer.push(g.colors.buffer);"," }"," self.postMessage({ id, geometries }, transfer);"," } catch (error) {"," self.postMessage({ id, error: String((error && error.message) || error) });"," }","};"].join(`
2
- `)}var He=5e4,k,j=new Map,ft=1;function Pe(){if(k!==void 0)return k;if(typeof Worker>"u"||typeof Blob>"u"||typeof URL>"u"||typeof URL.createObjectURL!="function")return k=null,null;try{let e=URL.createObjectURL(new Blob([_e()],{type:"text/javascript"})),t=new Worker(e);t.onmessage=r=>{let{id:n,geometries:a,error:o}=r.data,i=j.get(n);i&&(j.delete(n),a?i.resolve(a):i.reject(new Error(o??"mesh assembly failed in worker")))},t.onerror=()=>{for(let r of j.values())r.reject(new Error("mesh assembly worker crashed"));j.clear(),t.terminate(),k=null},k=t}catch{k=null}return k}function ke(e,t,r){return new Promise((n,a)=>{let o=ft++;j.set(o,{resolve:n,reject:a}),e.postMessage({id:o,input:t},r)})}import*as N from"three";import*as Y from"three";var Ne=1;function Ge(e){Ne=Math.max(1,e)}de(Ge);function Ve(e,t){typeof document>"u"||new Y.TextureLoader().load(t,r=>{r.colorSpace=Y.SRGBColorSpace,r.anisotropy=Ne,e.map=r,e.needsUpdate=!0},void 0,r=>{v().warn(`Failed to load material texture ${t}:`,r)})}var mt=.5,dt=.5,pt=.3;function te(e,t){let r=ue(e.color),n=t?.vertexColors??!1,a=t?.appearance,o=new N.MeshPhysicalMaterial({color:r,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,vertexColors:n,side:a?.cullBackfaces?N.FrontSide:N.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.5,polygonOffsetUnits:.5,depthWrite:!0,depthTest:!0});return a?.envMapIntensity!=null&&(o.envMapIntensity=a.envMapIntensity),e.metalness>mt&&(o.clearcoat=dt,o.clearcoatRoughness=pt),n&&yt(o),e.map&&Ve(o,e.map),o}function yt(e){e.onBeforeCompile=t=>{t.vertexShader=t.vertexShader.replace("#include <color_vertex>",`#include <color_vertex>
1
+ import{a as e,c as t,d as n,i as r,n as i,o as a,t as o,u as s}from"./gpu-dispose-Dkj-BKt4.js";import*as c from"three";import{Line2 as l}from"three/addons/lines/Line2.js";import{LineGeometry as u}from"three/addons/lines/LineGeometry.js";import{LineMaterial as d}from"three/addons/lines/LineMaterial.js";import{inflateSync as f}from"fflate";function p(){let e=globalThis.Buffer;return typeof e==`function`?e:void 0}function m(e){let t=e.replace(/[\t\n\f\r ]/g,``);if(t.length%4==0&&(t=t.replace(/={1,2}$/,``)),t.length%4==1||!/^[A-Za-z0-9+/]*$/.test(t))throw new n(`Invalid base64 input.`,s.ENCODING_ERROR,{context:{inputLength:e.length}});let r=p();if(r)return new Uint8Array(r.from(t,`base64`));if(typeof globalThis.atob==`function`){let e=globalThis.atob(t),n=new Uint8Array(e.length);for(let t=0;t<e.length;t++)n[t]=e.charCodeAt(t)&255;return n}throw new n(`Base64 decoding not supported in this environment.`,s.INVALID_STATE,{context:{environmentInfo:`atob or Buffer not available`}})}function h(e){return e.map(e=>{let t=e.clone(!0),n=[];e.traverse(e=>n.push(e));let r=0;return t.traverse(e=>{let t=n[r++],i=e;t.geometry&&(i.geometry=t.geometry.clone())}),t})}function g(e){e.forEach(e=>o(e,{materials:!1}))}const _={clone:h,release:g};function v(e,t){let n=t??1;return{color:new c.Color(e??`#ffffff`),transparent:n<1,opacity:n}}function y(e){let t=b(e);if(!t)return null;let n=new u;n.setPositions(t);let r=v(e.color,e.opacity),i=new d({color:r.color}),a=i;a.linewidth=e.width??2,a.transparent=r.transparent,a.opacity=r.opacity;let o=new l(n,i);return o.computeLineDistances(),o.name=e.name,o.userData={source:`compute`,id:e.id,layer:e.layer,kind:`curve`,metadata:e.metadata},o}function b(e){if(!e.points)throw new n(`Curve display item '${e.id}' has no tessellated points. It was produced by an outdated Display component — upgrade it in Grasshopper (Solution → Upgrade obsolete components) and re-save the definition.`,s.INVALID_CONFIG,{context:{itemId:e.id,kind:e.kind}});return e.points.length>=6?e.points:null}function x(e){let{position:n}=e;if(!n||typeof n.X!=`number`||!Number.isFinite(n.X)||typeof n.Y!=`number`||!Number.isFinite(n.Y)||typeof n.Z!=`number`||!Number.isFinite(n.Z))return t().warn(`Skipping point display item with missing or non-finite position (id: ${String(e.id)}).`),null;let r=new c.BufferGeometry;r.setAttribute(`position`,new c.Float32BufferAttribute([n.X,n.Y,n.Z],3));let i=new c.PointsMaterial({...v(e.color,e.opacity),size:6,sizeAttenuation:!1}),a=new c.Points(r,i);return a.name=e.name,a.userData={source:`compute`,id:e.id,layer:e.layer,kind:`point`,metadata:e.metadata},a}function S(e){if(!e||e.length===0)return[];let n=[];for(let r of e)switch(r.kind){case`curve`:{let e=y(r);e&&n.push(e);break}case`point`:{let e=x(r);e&&n.push(e);break}default:{let e=r;t().warn(`Skipping unknown display item kind: ${String(e.kind)}`);break}}return n}const C=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;function ee(e){return typeof e==`string`?m(e):e instanceof Uint8Array?e:new Uint8Array(e)}function te(e){if(e.byteLength<8)return e;let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getUint32(0,!0)!==1515605075)return e;let n=t.getUint32(4,!0),r=e.subarray(8),i=Math.max(r.byteLength*1032+1024,1<<20);if(n>i)throw M(`SLVZ header declares an implausible uncompressed length`,{uncompressedLen:n,deflatedBytes:r.byteLength,maxPlausibleLen:i});let a;try{a=f(r,{out:new Uint8Array(n+1)})}catch(e){throw M(`Failed to inflate SLVZ blob: ${e instanceof Error?e.message:String(e)}`,{uncompressedLen:n,deflatedBytes:r.byteLength})}if(a.byteLength!==n)throw M(`SLVZ payload inflated to a different size than the header declares.`,{declaredLen:n,actualLen:a.byteLength,deflatedBytes:r.byteLength});return a}function ne(e){if(typeof TextDecoder<`u`)return new TextDecoder(`utf-8`).decode(e);if(globalThis.Buffer!==void 0)return globalThis.Buffer.from(e).toString(`utf-8`);throw new n(`No UTF-8 decoder available in this environment.`,s.INVALID_STATE)}function re(e,t,n){if(n===0)return new Int16Array;if(t%2==0)return new Int16Array(e,t,n);let r=new Uint8Array(n*2);return r.set(new Uint8Array(e,t,n*2)),new Int16Array(r.buffer)}function w(e,t,n){if(n===0)return new Float32Array;if(t%4==0)return new Float32Array(e,t,n);let r=new Uint8Array(n*4);return r.set(new Uint8Array(e,t,n*4)),new Float32Array(r.buffer)}function T(e,t,n){if(n===0)return new Uint16Array;if(t%2==0)return new Uint16Array(e,t,n);let r=new Uint8Array(n*2);return r.set(new Uint8Array(e,t,n*2)),new Uint16Array(r.buffer)}function E(e,t,n){if(n===0)return new Uint32Array;if(t%4==0)return new Uint32Array(e,t,n);let r=new Uint8Array(n*4);return r.set(new Uint8Array(e,t,n*4)),new Uint32Array(r.buffer)}function D(e,t){if(e.length!==0&&!(e instanceof Uint16Array&&t>65535)){for(let n=0;n<e.length;n++)if(e[n]>=t)throw M(`Index out of range of vertexCount.`,{indexPosition:n,indexValue:e[n],vertexCount:t})}}function O(e){return e>>>1^-(e&1)}function k(e){let t=new Int16Array(e.length),n=0,r=0,i=0;for(let a=0;a<e.length;a+=3)n=n+O(e[a])<<16>>16,r=r+O(e[a+1])<<16>>16,i=i+O(e[a+2])<<16>>16,t[a]=n,t[a+1]=r,t[a+2]=i;return t}function A(e){let t=new Uint16Array(e.length),n=0;for(let r=0;r<e.length;r++)n=n+O(e[r])&65535,t[r]=n;return t}function j(e){let t=new Uint32Array(e.length),n=0;for(let r=0;r<e.length;r++)n=n+O(e[r])>>>0,t[r]=n;return t}function M(e,t){return new n(e,s.VALIDATION_ERROR,{context:t})}function ie(e,t,n,r,i){if(n+36>e.byteLength)throw M(`Insufficient data to read UV chunk header.`,{expectedBytes:36,availableBytes:e.byteLength-n,offset:n});let a=t.getUint32(n,!0);n+=4;let o=t.getFloat64(n,!0);n+=8;let s=t.getFloat64(n,!0);n+=8;let c=t.getFloat64(n,!0);n+=8;let l=t.getFloat64(n,!0);n+=8;let u=r*2,d=a===1,f=u*(d?4:2);if(n+f>e.byteLength)throw M(`Insufficient data to read UV chunk.`,{expectedBytes:f,availableBytes:e.byteLength-n,offset:n,uvFormat:a,vertexCount:r});let p=e.byteOffset+n,m;if(d)m=w(e.buffer,p,u).slice();else{let t=T(e.buffer,p,u);m=new Float32Array(u);let n=0,r=0;for(let e=0;e<u;e+=2)i?(n=n+O(t[e])&65535,r=r+O(t[e+1])&65535):(n=t[e],r=t[e+1]),m[e]=o+n*c,m[e+1]=s+r*l}return{uvs:m,offset:n+f}}function ae(e,t,n,r){let i=n*3;if(t+i>e.byteLength)throw M(`Insufficient data to read vertex-color chunk.`,{expectedBytes:i,availableBytes:e.byteLength-t,offset:t,vertexCount:n});let a=e.subarray(t,t+i);if(!r)return a.slice();let o=new Uint8Array(i),s=0,c=0,l=0;for(let e=0;e<i;e+=3)s=s+O(a[e])&255,c=c+O(a[e+1])&255,l=l+O(a[e+2])&255,o[e]=s,o[e+1]=c,o[e+2]=l;return o}function N(e){let t=P(e),n;n=t.isFloat32?t.vertexData:t.deltaEncoded?k(t.vertexData):t.vertexData;let r=t.indexData;return t.deltaEncoded&&(r=r instanceof Uint16Array?A(r):j(r)),D(r,t.vertexCount),{metadata:t.metadata,flags:t.flags,vertices:n,indices:r,origin:t.origin,scale:t.scale,uvs:t.uvs,colors:t.colors}}function P(e){if(!C)throw new n(`SLVA parsing requires a little-endian host: the zero-copy geometry readers view the wire bytes in host byte order.`,s.ENVIRONMENT_ERROR);let t=te(ee(e)),r=new DataView(t.buffer,t.byteOffset,t.byteLength);if(t.byteLength<12)throw M(`Blob too small to contain SLVA header.`,{expectedBytes:12,availableBytes:t.byteLength});let i=0,a=r.getUint32(i,!0);if(i+=4,a!==1096174675)throw M(`Invalid SLVA magic: 0x${a.toString(16)}`,{expectedMagic:`0x41564c53`,actualMagic:`0x${a.toString(16)}`});let o=r.getUint32(i,!0);if(i+=4,o<1||o>3)throw M(`Unsupported SLVA version: ${o}`,{minSupportedVersion:1,maxSupportedVersion:3,actualVersion:o});let c=r.getUint32(i,!0);if(i+=4,i+c>t.byteLength)throw M(`Insufficient data to read metadata JSON.`,{expectedBytes:c,availableBytes:t.byteLength-i,offset:i});let l=t.subarray(i,i+c);i+=c;let u;try{u=JSON.parse(ne(l))}catch(e){throw M(`Failed to parse metadata JSON: ${e instanceof Error?e.message:String(e)}`,{metadataLen:c})}if(i+56>t.byteLength)throw M(`Insufficient data to read geometry header.`,{expectedBytes:56,availableBytes:t.byteLength-i,offset:i});let d=r.getUint32(i,!0);i+=4;let f=r.getFloat64(i,!0);i+=8;let p=r.getFloat64(i,!0);i+=8;let m=r.getFloat64(i,!0);i+=8;let h=r.getFloat64(i,!0);i+=8;let g=r.getFloat64(i,!0);i+=8;let _=r.getFloat64(i,!0);i+=8;let v=r.getUint32(i,!0);i+=4;let y=!!(d&1),b=!!(d&4),x=v*3,S=x*(y?4:2);if(i+S>t.byteLength)throw M(`Insufficient data to read vertices.`,{expectedBytes:S,availableBytes:t.byteLength-i,offset:i,useFloat32:y,vertexCount:v});let D=t.byteOffset+i,O;if(O=y?w(t.buffer,D,x):b?T(t.buffer,D,x):re(t.buffer,D,x),i+=S,i+4>t.byteLength)throw M(`Insufficient data to read index count.`,{expectedBytes:4,availableBytes:t.byteLength-i,offset:i});let k=r.getUint32(i,!0);i+=4;let A=!!(d&2),j=k*(A?2:4);if(i+j>t.byteLength)throw M(`Insufficient data to read indices.`,{expectedBytes:j,availableBytes:t.byteLength-i,offset:i,indexCount:k,useUint16Indices:A});let N=A?T(t.buffer,t.byteOffset+i,k):E(t.buffer,t.byteOffset+i,k);i+=j;let P=null;if(d&8){let e=ie(t,r,i,v,b);P=e.uvs,i=e.offset}let F=null;return d&16&&(F=ae(t,i,v,b)),{metadata:u,flags:d,vertexData:O,indexData:N,isFloat32:y,deltaEncoded:b,vertexCount:v,origin:[f,p,m],scale:[h,g,_],uvs:P,colors:F}}function F(e){let{isFloat32:t,deltaEncoded:n,origin:r,scale:i,uvs:a,colors:o,jobs:s}=e,c=e=>e>>>1^-(e&1),l;if(t)l=e.vertexData;else{let t;if(n){let n=e.vertexData;t=new Int16Array(n.length);let r=0,i=0,a=0;for(let e=0;e<n.length;e+=3)r=r+c(n[e])<<16>>16,i=i+c(n[e+1])<<16>>16,a=a+c(n[e+2])<<16>>16,t[e]=r,t[e+1]=i,t[e+2]=a}else t=e.vertexData;l=new Float32Array(t.length);let a=r[0],o=r[1],s=r[2],u=i[0],d=i[1],f=i[2];for(let e=0;e<t.length;e+=3)l[e]=a+(t[e]+32767)*u,l[e+1]=o+(t[e+1]+32767)*d,l[e+2]=s+(t[e+2]+32767)*f}let u;if(n){let t=e.indexData;if(t instanceof Uint16Array){let e=new Uint16Array(t.length),n=0;for(let r=0;r<t.length;r++)n=n+c(t[r])&65535,e[r]=n;u=e}else{let e=new Uint32Array(t.length),n=0;for(let r=0;r<t.length;r++)n=n+c(t[r])>>>0,e[r]=n;u=e}}else u=e.indexData;let d=l.length/3;for(let e=0;e<u.length;e++)if(u[e]>=d)throw Error(`Index ${u[e]} out of range of vertexCount ${d}`);let f=[];for(let e of s){let t=0,n=0;for(let r of e.windows)t+=r.vertexCount,n+=r.indexCount;let r=new Float32Array(t*3),i=new Uint32Array(n),s=a?new Float32Array(t*2):null,c=o?new Uint8Array(t*3):null,d=0,p=0;for(let t of e.windows){let e=t.vertexStart*3;r.set(l.subarray(e,e+t.vertexCount*3),d*3),s&&a&&s.set(a.subarray(t.vertexStart*2,(t.vertexStart+t.vertexCount)*2),d*2),c&&o&&c.set(o.subarray(e,e+t.vertexCount*3),d*3);let n=t.vertexStart,f=t.vertexStart+t.vertexCount,m=d-t.vertexStart;for(let e=0;e<t.indexCount;e++){let r=u[t.indexStart+e];if(r<n||r>=f)throw Error(`Index ${r} outside vertex window [${n}, ${f})`);i[p+e]=r+m}d+=t.vertexCount,p+=t.indexCount}let m=new Float32Array(t*3);for(let e=0;e<i.length;e+=3){let t=i[e]*3,n=i[e+1]*3,a=i[e+2]*3,o=r[a]-r[n],s=r[a+1]-r[n+1],c=r[a+2]-r[n+2],l=r[t]-r[n],u=r[t+1]-r[n+1],d=r[t+2]-r[n+2],f=s*d-c*u,p=c*l-o*d,h=o*u-s*l;m[t]+=f,m[t+1]+=p,m[t+2]+=h,m[n]+=f,m[n+1]+=p,m[n+2]+=h,m[a]+=f,m[a+1]+=p,m[a+2]+=h}for(let e=0;e<m.length;e+=3){let t=m[e],n=m[e+1],r=m[e+2],i=Math.sqrt(t*t+n*n+r*r)||1;m[e]=t/i,m[e+1]=n/i,m[e+2]=r/i}f.push({positions:r,normals:m,indices:i,uvs:s,colors:c})}return f}function I(){return[`const assemble = ${F.toString()};`,`self.onmessage = (event) => {`,` const { id, input } = event.data;`,` try {`,` const geometries = assemble(input);`,` const transfer = [];`,` for (const g of geometries) {`,` transfer.push(g.positions.buffer, g.normals.buffer, g.indices.buffer);`,` if (g.uvs) transfer.push(g.uvs.buffer);`,` if (g.colors) transfer.push(g.colors.buffer);`,` }`,` self.postMessage({ id, geometries }, transfer);`,` } catch (error) {`,` self.postMessage({ id, error: String((error && error.message) || error) });`,` }`,`};`].join(`
2
+ `)}let L;const R=new Map;let oe=1;function se(){if(L!==void 0)return L;if(typeof Worker>`u`||typeof Blob>`u`||typeof URL>`u`||typeof URL.createObjectURL!=`function`)return L=null,null;try{let e=URL.createObjectURL(new Blob([I()],{type:`text/javascript`})),t=new Worker(e);t.onmessage=e=>{let{id:t,geometries:n,error:r}=e.data,i=R.get(t);i&&(R.delete(t),n?i.resolve(n):i.reject(Error(r??`mesh assembly failed in worker`)))},t.onerror=()=>{for(let e of R.values())e.reject(Error(`mesh assembly worker crashed`));R.clear(),t.terminate(),L=null},L=t}catch{L=null}return L}function ce(e,t,n){return new Promise((r,i)=>{let a=oe++;R.set(a,{resolve:r,reject:i}),e.postMessage({id:a,input:t},n)})}let z=1;function B(e){z=Math.max(1,e)}i(B);function le(e,n){typeof document>`u`||new c.TextureLoader().load(n,t=>{t.colorSpace=c.SRGBColorSpace,t.anisotropy=z,e.map=t,e.needsUpdate=!0},void 0,e=>{t().warn(`Failed to load material texture ${n}:`,e)})}function V(e,t){let n=a(e.color),r=t?.vertexColors??!1,i=t?.appearance,o=new c.MeshPhysicalMaterial({color:n,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,vertexColors:r,side:i?.cullBackfaces?c.FrontSide:c.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.5,polygonOffsetUnits:.5,depthWrite:!0,depthTest:!0});return i?.envMapIntensity!=null&&(o.envMapIntensity=i.envMapIntensity),e.metalness>.5&&(o.clearcoat=.5,o.clearcoatRoughness=.3),r&&H(o),e.map&&le(o,e.map),o}function H(e){e.onBeforeCompile=e=>{e.vertexShader=e.vertexShader.replace(`#include <color_vertex>`,`#include <color_vertex>
3
3
  #if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )
4
4
  vColor.rgb = mix(
5
5
  vColor.rgb / 12.92,
6
6
  pow( ( vColor.rgb + 0.055 ) / 1.055, vec3( 2.4 ) ),
7
7
  step( vec3( 0.04045 ), vColor.rgb )
8
8
  );
9
- #endif`)}}import*as R from"three";function $(e,t){return new _(e,F.VALIDATION_ERROR,{context:t})}function re(e,t,r,n){for(let a of e){if(!Number.isInteger(a.materialId)||a.materialId<0||a.materialId>=t)throw $("Group materialId out of range of the materials array.",{materialId:a.materialId,materialCount:t});for(let o of a.meshes){let i={vertexStart:o.vertexStart,vertexCount:o.vertexCount,indexStart:o.indexStart,indexCount:o.indexCount};for(let[c,f]of Object.entries(i))if(!Number.isInteger(f)||f<0)throw $(`Mesh metadata field "${c}" must be a non-negative integer.`,{meshName:o.name,field:c,value:f});if(o.vertexStart+o.vertexCount>r)throw $("Mesh vertex window exceeds the batch vertex buffer.",{meshName:o.name,vertexStart:o.vertexStart,vertexCount:o.vertexCount,totalVertexCount:r});if(o.indexStart+o.indexCount>n)throw $("Mesh index window exceeds the batch index buffer.",{meshName:o.name,indexStart:o.indexStart,indexCount:o.indexCount,totalIndexCount:n})}}}function ne(e,t){return $("Index references a vertex outside its mesh's vertex window.",{meshName:t.name,indexValue:e,vertexStart:t.vertexStart,vertexCount:t.vertexCount})}function je(e,t,r){let n=new Float32Array(e.length),a=t[0],o=t[1],i=t[2],c=r[0],f=r[1],m=r[2];for(let l=0;l<e.length;l+=3)n[l]=a+(e[l]+32767)*c,n[l+1]=o+(e[l+1]+32767)*f,n[l+2]=i+(e[l+2]+32767)*m;return n}function $e(e,t,r,n,a=null,o=null){let i=0,c=0;for(let u of e.meshes)i+=u.vertexCount,c+=u.indexCount;let f=new Float32Array(i*3),m=new Uint32Array(c),l=a?new Float32Array(i*2):null,w=o?new Uint8Array(i*3):null,M=0,d=0;for(let u of e.meshes){let s=u.vertexStart*3,y=u.vertexCount*3;if(f.set(t.subarray(s,s+y),M*3),l&&a){let b=u.vertexStart*2;l.set(a.subarray(b,b+u.vertexCount*2),M*2)}w&&o&&w.set(o.subarray(s,s+y),M*3);let x=r.subarray(u.indexStart,u.indexStart+u.indexCount),A=M-u.vertexStart,g=u.vertexStart,B=u.vertexStart+u.vertexCount;for(let b=0;b<x.length;b++){let p=x[b];if(p<g||p>=B)throw ne(p,u);m[d+b]=p+A}M+=u.vertexCount,d+=u.indexCount}let h=new R.BufferGeometry;return h.setAttribute("position",new R.BufferAttribute(f,3)),h.setIndex(new R.BufferAttribute(m,1)),l&&h.setAttribute("uv",new R.BufferAttribute(l,2)),w&&h.setAttribute("color",new R.BufferAttribute(w,3,!0)),h.computeVertexNormals(),oe(h,e,n)}function oe(e,t,r){let n=new R.Mesh(e,r[t.materialId]),a=t.meshes[0],o=t.meshes.map(i=>i.name).filter(i=>i&&i.length>0);return n.name=o.length>0?o[0]:`merged_material_${t.materialId}`,n.castShadow=!0,n.receiveShadow=!0,n.userData={source:"compute",name:n.name,layer:a?.layer??"",originalIndex:a?.originalIndex??0,metadata:a?.metadata??{},mergedFrom:t.meshes.slice(1).map(i=>({name:i.name,layer:i.layer,originalIndex:i.originalIndex}))},n}function ze(e,t,r,n,a=null,o=null){let i=[];for(let c of e.meshes){let f=c.vertexStart*3,m=c.vertexCount*3,l=t.slice(f,f+m),w=r.subarray(c.indexStart,c.indexStart+c.indexCount),M=new Uint32Array(w.length),d=c.vertexStart,h=c.vertexStart+c.vertexCount;for(let s=0;s<w.length;s++){let y=w[s];if(y<d||y>=h)throw ne(y,c);M[s]=y-d}let u=new R.BufferGeometry;if(u.setAttribute("position",new R.BufferAttribute(l,3)),u.setIndex(new R.BufferAttribute(M,1)),a){let s=c.vertexStart*2,y=a.slice(s,s+c.vertexCount*2);u.setAttribute("uv",new R.BufferAttribute(y,2))}if(o){let s=o.slice(f,f+m);u.setAttribute("color",new R.BufferAttribute(s,3,!0))}u.computeVertexNormals(),i.push(ae(u,c,e,n))}return i}function ae(e,t,r,n){let a=new R.Mesh(e,n[r.materialId]);return a.name=t.name,a.userData={source:"compute",name:t.name,layer:t.layer??"",originalIndex:t.originalIndex,metadata:t.metadata??{}},a.castShadow=!0,a.receiveShadow=!0,a}async function se(e,t,r){let{mergeByMaterial:n=!0,debug:a=!1,material:o}=t??{},{parseTime:i=0,perfStart:c=a?performance.now():0}=r??{};if(!e.compressedData)return[];let f=await Ye(e.compressedData,{mergeByMaterial:n,debug:a,material:o,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}});if(f)return f;let m=performance.now(),l=Q(e.compressedData),w=performance.now()-m,M=a?bt(e.compressedData):0;return We(l,{mergeByMaterial:n,debug:a,material:o,parseTime:i,decodeTime:w,perfStart:c,blobBytes:M,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}})}async function ht(e,t){let{mergeByMaterial:r=!0,debug:n=!1,material:a}=t??{},o=n?performance.now():0,i=await Ye(e,{mergeByMaterial:r,debug:n,material:a});if(i)return i;let c=performance.now(),f=Q(e),m=performance.now()-c,l=e.byteLength;return We(f,{mergeByMaterial:r,debug:n,material:a,parseTime:0,decodeTime:m,perfStart:o,blobBytes:l})}function We(e,t){let{mergeByMaterial:r,debug:n,material:a,parseTime:o,decodeTime:i,perfStart:c,blobBytes:f,fallback:m}=t,l=e.metadata.materials??m?.materials??[],w=e.metadata.groups??m?.groups??[],M=m?.sourceComponentId??e.metadata.sourceComponentId,d=(e.flags&1)!==0;re(w,l.length,e.vertices.length/3,e.indices.length);let h=d?e.vertices:je(e.vertices,e.origin,e.scale);if(n){let A=e.vertices.byteLength+e.indices.byteLength;v().debug("Mesh Batch Stats:"),v().debug(` Materials: ${l.length} | Groups: ${w.length}`),v().debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),v().debug(` Format: ${d?"float32":"int16 quantized"}`),v().debug(` Blob: ${(f/1024/1024).toFixed(2)} MB | Geometry on wire: ${(A/1024/1024).toFixed(2)} MB`)}let u=performance.now(),s=l.map(A=>te(A,{vertexColors:e.colors!=null,appearance:a})),y=[];for(let A of w)if(r&&A.meshes.length>1){let g=$e(A,h,e.indices,s,e.uvs,e.colors);g.userData.sourceComponentId=M??null,y.push(g)}else{let g=ze(A,h,e.indices,s,e.uvs,e.colors);for(let B of g)B.userData.sourceComponentId=M??null;y.push(...g)}let x=performance.now()-u;if(n){let A=performance.now()-c;v().debug("Performance:"),o>0&&v().debug(` Parse JSON: ${o.toFixed(2)}ms`),v().debug(` Decode binary: ${i.toFixed(2)}ms`),v().debug(` Create Meshes: ${x.toFixed(2)}ms`),v().debug(` Total: ${A.toFixed(2)}ms`)}return Promise.resolve(y)}async function Ye(e,t){if(typeof Worker>"u")return null;let r=ee(e);if(r.indexData.length/3<He)return null;let n=Pe();if(!n)return null;let a=r.metadata.materials??t.fallback?.materials??[],o=r.metadata.groups??t.fallback?.groups??[],i=t.fallback?.sourceComponentId??r.metadata.sourceComponentId;re(o,a.length,r.vertexCount,r.indexData.length);let c=s=>({vertexStart:s.vertexStart,vertexCount:s.vertexCount,indexStart:s.indexStart,indexCount:s.indexCount}),f=[],m=[];for(let s of o)if(t.mergeByMaterial&&s.meshes.length>1)f.push({kind:"merged",windows:s.meshes.map(c)}),m.push({kind:"merged",group:s});else for(let y of s.meshes)f.push({kind:"single",windows:[c(y)]}),m.push({kind:"single",group:s,meshMeta:y});let l=r.vertexData.slice(),w=r.indexData.slice(),M=[l.buffer,w.buffer];r.uvs&&M.push(r.uvs.buffer),r.colors&&M.push(r.colors.buffer);let d;try{d=await ke(n,{vertexData:l,isFloat32:r.isFloat32,deltaEncoded:r.deltaEncoded,origin:r.origin,scale:r.scale,indexData:w,uvs:r.uvs,colors:r.colors,jobs:f},M)}catch(s){return v().warn("Mesh assembly worker failed; falling back to main-thread parse.",s),null}if(d.length!==f.length)return null;let h=a.map(s=>te(s,{vertexColors:r.colors!=null,appearance:t.material})),u=[];for(let s=0;s<d.length;s++){let y=d[s],x=m[s],A=new P.BufferGeometry;A.setAttribute("position",new P.BufferAttribute(y.positions,3)),A.setAttribute("normal",new P.BufferAttribute(y.normals,3)),A.setIndex(new P.BufferAttribute(y.indices,1)),y.uvs&&A.setAttribute("uv",new P.BufferAttribute(y.uvs,2)),y.colors&&A.setAttribute("color",new P.BufferAttribute(y.colors,3,!0));let g=x.kind==="merged"?oe(A,x.group,h):ae(A,x.meshMeta,x.group,h);g.userData.sourceComponentId=i??null,u.push(g)}return t.debug&&v().debug(`Mesh batch assembled off-thread: ${u.length} meshes, ${r.indexData.length/3} triangles`),u}function bt(e){return Math.floor(e.length*3/4)}var ie={Angstroms:1e-10,Nanometers:1e-9,Microns:1e-6,Millimeters:.001,Centimeters:.01,Decimeters:.1,Meters:1,Dekameters:10,Hectometers:100,Kilometers:1e3,Megameters:1e6,Gigameters:1e9,Microinches:254e-10,Mils:254e-7,Inches:.0254,Feet:.3048,Yards:.9144,Miles:1609.344,NauticalMiles:1852},gt="Display",At="DisplayBatch";function xt(e){let t=e.split(".");return t.includes(gt)||t.includes(At)}var Je=new Set;async function Et(e,t){let r=performance.now(),n=[],{allowScaling:a=!0,allowAutoPosition:o=!1,groundAxis:i="z",debug:c=!1,parsing:f={}}=t??{};try{let m=a?wt(e.modelunits):1;return await Mt(e,n,m,f,c),o&&Rt(n,i),n}catch(m){throw Bt(m,n),m}finally{c&&Dt(r)}}function wt(e){let t=ie[e];return t!==void 0?t:(Je.has(e)||(Je.add(e),v().warn(`Unknown Rhino model unit "${e}" \u2014 geometry will not be scaled (factor 1). Known units: ${Object.keys(ie).join(", ")}.`)),1)}async function Mt(e,t,r,n,a){for(let o of e.values){let i=o.InnerTree;for(let c in i){let f=i[c];f&&await vt(f,t,r,n,a)}}}async function vt(e,t,r,n,a){for(let o of e){if(!xt(o.type))continue;let i={mergeByMaterial:!0,debug:!1,...n},c=St(o.data);if(!c){v().error("Error parsing display batch envelope: invalid JSON");continue}let f=await se(c,i),m=q(c.items),l=[...f,...m];if(r!==1)for(let w of l)w.scale.set(r,r,r);t.push(...l),a&&v().debug(`Extracted ${f.length} meshes and ${m.length} items from batch`)}}function St(e){return typeof e=="string"?Tt(e):e}function Tt(e){try{return JSON.parse(e)}catch{return}}function Rt(e,t){if(e.length===0)return;let r=me(e);fe(e,r.min[t],t)}function Bt(e,t){v().error("An unexpected error occurred:",e),It(t)}function It(e){for(let t of e){let r=t;r.geometry&&r.geometry.dispose(),r.material&&(Array.isArray(r.material)?r.material.forEach(n=>n.dispose()):r.material.dispose())}}function Dt(e){let t=performance.now()-e;v().info("Time to process meshes:",`${t.toFixed(2)}ms`)}export{ie as SCALE_FACTORS,Et as getThreeMeshesFromComputeResponse,qe as meshPolicy,q as parseDisplayItems,ht as parseMeshBatchBlob,se as parseMeshBatchObject,Ge as setTextureAnisotropy};
9
+ #endif`)}}function U(e,t){return new n(e,s.VALIDATION_ERROR,{context:t})}function W(e,t,n,r){for(let i of e){if(!Number.isInteger(i.materialId)||i.materialId<0||i.materialId>=t)throw U(`Group materialId out of range of the materials array.`,{materialId:i.materialId,materialCount:t});for(let e of i.meshes){let t={vertexStart:e.vertexStart,vertexCount:e.vertexCount,indexStart:e.indexStart,indexCount:e.indexCount};for(let[n,r]of Object.entries(t))if(!Number.isInteger(r)||r<0)throw U(`Mesh metadata field "${n}" must be a non-negative integer.`,{meshName:e.name,field:n,value:r});if(e.vertexStart+e.vertexCount>n)throw U(`Mesh vertex window exceeds the batch vertex buffer.`,{meshName:e.name,vertexStart:e.vertexStart,vertexCount:e.vertexCount,totalVertexCount:n});if(e.indexStart+e.indexCount>r)throw U(`Mesh index window exceeds the batch index buffer.`,{meshName:e.name,indexStart:e.indexStart,indexCount:e.indexCount,totalIndexCount:r})}}}function G(e,t){return U(`Index references a vertex outside its mesh's vertex window.`,{meshName:t.name,indexValue:e,vertexStart:t.vertexStart,vertexCount:t.vertexCount})}function ue(e,t,n){let r=new Float32Array(e.length),i=t[0],a=t[1],o=t[2],s=n[0],c=n[1],l=n[2];for(let t=0;t<e.length;t+=3)r[t]=i+(e[t]+32767)*s,r[t+1]=a+(e[t+1]+32767)*c,r[t+2]=o+(e[t+2]+32767)*l;return r}function de(e,t,n,r,i=null,a=null){let o=0,s=0;for(let t of e.meshes)o+=t.vertexCount,s+=t.indexCount;let l=new Float32Array(o*3),u=new Uint32Array(s),d=i?new Float32Array(o*2):null,f=a?new Uint8Array(o*3):null,p=0,m=0;for(let r of e.meshes){let e=r.vertexStart*3,o=r.vertexCount*3;if(l.set(t.subarray(e,e+o),p*3),d&&i){let e=r.vertexStart*2;d.set(i.subarray(e,e+r.vertexCount*2),p*2)}f&&a&&f.set(a.subarray(e,e+o),p*3);let s=n.subarray(r.indexStart,r.indexStart+r.indexCount),c=p-r.vertexStart,h=r.vertexStart,g=r.vertexStart+r.vertexCount;for(let e=0;e<s.length;e++){let t=s[e];if(t<h||t>=g)throw G(t,r);u[m+e]=t+c}p+=r.vertexCount,m+=r.indexCount}let h=new c.BufferGeometry;return h.setAttribute(`position`,new c.BufferAttribute(l,3)),h.setIndex(new c.BufferAttribute(u,1)),d&&h.setAttribute(`uv`,new c.BufferAttribute(d,2)),f&&h.setAttribute(`color`,new c.BufferAttribute(f,3,!0)),h.computeVertexNormals(),K(h,e,r)}function K(e,t,n){let r=new c.Mesh(e,n[t.materialId]),i=t.meshes[0],a=t.meshes.map(e=>e.name).filter(e=>e&&e.length>0);return r.name=a.length>0?a[0]:`merged_material_${t.materialId}`,r.castShadow=!0,r.receiveShadow=!0,r.userData={source:`compute`,name:r.name,layer:i?.layer??``,originalIndex:i?.originalIndex??0,metadata:i?.metadata??{},mergedFrom:t.meshes.slice(1).map(e=>({name:e.name,layer:e.layer,originalIndex:e.originalIndex}))},r}function fe(e,t,n,r,i=null,a=null){let o=[];for(let s of e.meshes){let l=s.vertexStart*3,u=s.vertexCount*3,d=t.slice(l,l+u),f=n.subarray(s.indexStart,s.indexStart+s.indexCount),p=new Uint32Array(f.length),m=s.vertexStart,h=s.vertexStart+s.vertexCount;for(let e=0;e<f.length;e++){let t=f[e];if(t<m||t>=h)throw G(t,s);p[e]=t-m}let g=new c.BufferGeometry;if(g.setAttribute(`position`,new c.BufferAttribute(d,3)),g.setIndex(new c.BufferAttribute(p,1)),i){let e=s.vertexStart*2,t=i.slice(e,e+s.vertexCount*2);g.setAttribute(`uv`,new c.BufferAttribute(t,2))}if(a){let e=a.slice(l,l+u);g.setAttribute(`color`,new c.BufferAttribute(e,3,!0))}g.computeVertexNormals(),o.push(q(g,s,e,r))}return o}function q(e,t,n,r){let i=new c.Mesh(e,r[n.materialId]);return i.name=t.name,i.userData={source:`compute`,name:t.name,layer:t.layer??``,originalIndex:t.originalIndex,metadata:t.metadata??{}},i.castShadow=!0,i.receiveShadow=!0,i}async function J(e,t,n){let{mergeByMaterial:r=!0,debug:i=!1,material:a}=t??{},{parseTime:o=0,perfStart:s=i?performance.now():0}=n??{};if(!e.compressedData)return[];let c=await X(e.compressedData,{mergeByMaterial:r,debug:i,material:a,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}});if(c)return c;let l=performance.now();return Y(N(e.compressedData),{mergeByMaterial:r,debug:i,material:a,parseTime:o,decodeTime:performance.now()-l,perfStart:s,blobBytes:i?me(e.compressedData):0,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}})}async function pe(e,t){let{mergeByMaterial:n=!0,debug:r=!1,material:i}=t??{},a=r?performance.now():0,o=await X(e,{mergeByMaterial:n,debug:r,material:i});if(o)return o;let s=performance.now(),c=N(e),l=performance.now()-s,u=e.byteLength;return Y(c,{mergeByMaterial:n,debug:r,material:i,parseTime:0,decodeTime:l,perfStart:a,blobBytes:u})}function Y(e,n){let{mergeByMaterial:r,debug:i,material:a,parseTime:o,decodeTime:s,perfStart:c,blobBytes:l,fallback:u}=n,d=e.metadata.materials??u?.materials??[],f=e.metadata.groups??u?.groups??[],p=u?.sourceComponentId??e.metadata.sourceComponentId,m=!!(e.flags&1);W(f,d.length,e.vertices.length/3,e.indices.length);let h=m?e.vertices:ue(e.vertices,e.origin,e.scale);if(i){let n=e.vertices.byteLength+e.indices.byteLength;t().debug(`Mesh Batch Stats:`),t().debug(` Materials: ${d.length} | Groups: ${f.length}`),t().debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),t().debug(` Format: ${m?`float32`:`int16 quantized`}`),t().debug(` Blob: ${(l/1024/1024).toFixed(2)} MB | Geometry on wire: ${(n/1024/1024).toFixed(2)} MB`)}let g=performance.now(),_=d.map(t=>V(t,{vertexColors:e.colors!=null,appearance:a})),v=[];for(let t of f)if(r&&t.meshes.length>1){let n=de(t,h,e.indices,_,e.uvs,e.colors);n.userData.sourceComponentId=p??null,v.push(n)}else{let n=fe(t,h,e.indices,_,e.uvs,e.colors);for(let e of n)e.userData.sourceComponentId=p??null;v.push(...n)}let y=performance.now()-g;if(i){let e=performance.now()-c;t().debug(`Performance:`),o>0&&t().debug(` Parse JSON: ${o.toFixed(2)}ms`),t().debug(` Decode binary: ${s.toFixed(2)}ms`),t().debug(` Create Meshes: ${y.toFixed(2)}ms`),t().debug(` Total: ${e.toFixed(2)}ms`)}return Promise.resolve(v)}async function X(e,n){if(typeof Worker>`u`)return null;let r=P(e);if(r.indexData.length/3<5e4)return null;let i=se();if(!i)return null;let a=r.metadata.materials??n.fallback?.materials??[],o=r.metadata.groups??n.fallback?.groups??[],s=n.fallback?.sourceComponentId??r.metadata.sourceComponentId;W(o,a.length,r.vertexCount,r.indexData.length);let l=e=>({vertexStart:e.vertexStart,vertexCount:e.vertexCount,indexStart:e.indexStart,indexCount:e.indexCount}),u=[],d=[];for(let e of o)if(n.mergeByMaterial&&e.meshes.length>1)u.push({kind:`merged`,windows:e.meshes.map(l)}),d.push({kind:`merged`,group:e});else for(let t of e.meshes)u.push({kind:`single`,windows:[l(t)]}),d.push({kind:`single`,group:e,meshMeta:t});let f=r.vertexData.slice(),p=r.indexData.slice(),m=[f.buffer,p.buffer];r.uvs&&m.push(r.uvs.buffer),r.colors&&m.push(r.colors.buffer);let h;try{h=await ce(i,{vertexData:f,isFloat32:r.isFloat32,deltaEncoded:r.deltaEncoded,origin:r.origin,scale:r.scale,indexData:p,uvs:r.uvs,colors:r.colors,jobs:u},m)}catch(e){return t().warn(`Mesh assembly worker failed; falling back to main-thread parse.`,e),null}if(h.length!==u.length)return null;let g=a.map(e=>V(e,{vertexColors:r.colors!=null,appearance:n.material})),_=[];for(let e=0;e<h.length;e++){let t=h[e],n=d[e],r=new c.BufferGeometry;r.setAttribute(`position`,new c.BufferAttribute(t.positions,3)),r.setAttribute(`normal`,new c.BufferAttribute(t.normals,3)),r.setIndex(new c.BufferAttribute(t.indices,1)),t.uvs&&r.setAttribute(`uv`,new c.BufferAttribute(t.uvs,2)),t.colors&&r.setAttribute(`color`,new c.BufferAttribute(t.colors,3,!0));let i=n.kind===`merged`?K(r,n.group,g):q(r,n.meshMeta,n.group,g);i.userData.sourceComponentId=s??null,_.push(i)}return n.debug&&t().debug(`Mesh batch assembled off-thread: ${_.length} meshes, ${r.indexData.length/3} triangles`),_}function me(e){return Math.floor(e.length*3/4)}const Z={Angstroms:1e-10,Nanometers:1e-9,Microns:1e-6,Millimeters:.001,Centimeters:.01,Decimeters:.1,Meters:1,Dekameters:10,Hectometers:100,Kilometers:1e3,Megameters:1e6,Gigameters:1e9,Microinches:2.54e-8,Mils:254e-7,Inches:.0254,Feet:.3048,Yards:.9144,Miles:1609.344,NauticalMiles:1852};function he(e){let t=e.split(`.`);return t.includes(`Display`)||t.includes(`DisplayBatch`)}const Q=new Set;async function ge(e,t){let n=performance.now(),r=[],{allowScaling:i=!0,allowAutoPosition:a=!1,groundAxis:o=`z`,debug:s=!1,parsing:c={}}=t??{};try{return await ve(e,r,i?_e(e.modelunits):1,c,s),a&&xe(r,o),r}catch(e){throw Se(e,r),e}finally{s&&we(n)}}function _e(e){let n=Z[e];return n===void 0?(Q.has(e)||(Q.add(e),t().warn(`Unknown Rhino model unit "${e}" geometry will not be scaled (factor 1). Known units: ${Object.keys(Z).join(`, `)}.`)),1):n}async function ve(e,t,n,r,i){for(let a of e.values){let e=a.InnerTree;for(let a in e){let o=e[a];o&&await ye(o,t,n,r,i)}}}async function ye(e,n,r,i,a){for(let o of e){if(!he(o.type))continue;let e={mergeByMaterial:!0,debug:!1,...i},s=$(o.data);if(!s){t().error(`Error parsing display batch envelope: invalid JSON`);continue}let c=await J(s,e),l=S(s.items),u=[...c,...l];if(r!==1)for(let e of u)e.scale.set(r,r,r);n.push(...u),a&&t().debug(`Extracted ${c.length} meshes and ${l.length} items from batch`)}}function $(e){return typeof e==`string`?be(e):e}function be(e){try{return JSON.parse(e)}catch{return}}function xe(t,n){if(t.length===0)return;let i=e(t);r(t,i.min[n],n)}function Se(e,n){t().error(`An unexpected error occurred:`,e),Ce(n)}function Ce(e){for(let t of e){let e=t;e.geometry&&e.geometry.dispose(),e.material&&(Array.isArray(e.material)?e.material.forEach(e=>e.dispose()):e.material.dispose())}}function we(e){let n=performance.now()-e;t().info(`Time to process meshes:`,`${n.toFixed(2)}ms`)}export{Z as SCALE_FACTORS,ge as getThreeMeshesFromComputeResponse,_ as meshPolicy,S as parseDisplayItems,pe as parseMeshBatchBlob,J as parseMeshBatchObject,B as setTextureAnisotropy};
10
10
  //# sourceMappingURL=parse.js.map