@selvajs/visualization 1.0.0 → 1.0.1

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 CHANGED
@@ -6,5 +6,5 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
6
6
  pow( ( vColor.rgb + 0.055 ) / 1.055, vec3( 2.4 ) ),
7
7
  step( vec3( 0.04045 ), vColor.rgb )
8
8
  );
9
- #endif`)}}function V(e,n){return new t.d(e,t.u.VALIDATION_ERROR,{context:n})}function H(e,t,n,r){for(let i of e){if(!Number.isInteger(i.materialId)||i.materialId<0||i.materialId>=t)throw V(`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 V(`Mesh metadata field "${n}" must be a non-negative integer.`,{meshName:e.name,field:n,value:r});if(e.vertexStart+e.vertexCount>n)throw V(`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 V(`Mesh index window exceeds the batch index buffer.`,{meshName:e.name,indexStart:e.indexStart,indexCount:e.indexCount,totalIndexCount:r})}}}function U(e,t){return V(`Index references a vertex outside its mesh's vertex window.`,{meshName:t.name,indexValue:e,vertexStart:t.vertexStart,vertexCount:t.vertexCount})}function oe(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 W(e,t,r,i,a=null,o=null){let s=0,c=0;for(let t of e.meshes)s+=t.vertexCount,c+=t.indexCount;let l=new Float32Array(s*3),u=new Uint32Array(c),d=a?new Float32Array(s*2):null,f=o?new Uint8Array(s*3):null,p=0,m=0;for(let n of e.meshes){let e=n.vertexStart*3,i=n.vertexCount*3;if(l.set(t.subarray(e,e+i),p*3),d&&a){let e=n.vertexStart*2;d.set(a.subarray(e,e+n.vertexCount*2),p*2)}f&&o&&f.set(o.subarray(e,e+i),p*3);let s=r.subarray(n.indexStart,n.indexStart+n.indexCount),c=p-n.vertexStart,h=n.vertexStart,g=n.vertexStart+n.vertexCount;for(let e=0;e<s.length;e++){let t=s[e];if(t<h||t>=g)throw U(t,n);u[m+e]=t+c}p+=n.vertexCount,m+=n.indexCount}let h=new n.BufferGeometry;return h.setAttribute(`position`,new n.BufferAttribute(l,3)),h.setIndex(new n.BufferAttribute(u,1)),d&&h.setAttribute(`uv`,new n.BufferAttribute(d,2)),f&&h.setAttribute(`color`,new n.BufferAttribute(f,3,!0)),h.computeVertexNormals(),G(h,e,i)}function G(e,t,r){let i=new n.Mesh(e,r[t.materialId]),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??``,originalIndex:a?.originalIndex??0,metadata:a?.metadata??{},mergedFrom:t.meshes.slice(1).map(e=>({name:e.name,layer:e.layer,originalIndex:e.originalIndex}))},i}function K(e,t,r,i,a=null,o=null){let s=[];for(let c of e.meshes){let l=c.vertexStart*3,u=c.vertexCount*3,d=t.slice(l,l+u),f=r.subarray(c.indexStart,c.indexStart+c.indexCount),p=new Uint32Array(f.length),m=c.vertexStart,h=c.vertexStart+c.vertexCount;for(let e=0;e<f.length;e++){let t=f[e];if(t<m||t>=h)throw U(t,c);p[e]=t-m}let g=new n.BufferGeometry;if(g.setAttribute(`position`,new n.BufferAttribute(d,3)),g.setIndex(new n.BufferAttribute(p,1)),a){let e=c.vertexStart*2,t=a.slice(e,e+c.vertexCount*2);g.setAttribute(`uv`,new n.BufferAttribute(t,2))}if(o){let e=o.slice(l,l+u);g.setAttribute(`color`,new n.BufferAttribute(e,3,!0))}g.computeVertexNormals(),s.push(q(g,c,e,i))}return s}function q(e,t,r,i){let a=new n.Mesh(e,i[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 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(A(e.compressedData),{mergeByMaterial:r,debug:i,material:a,parseTime:o,decodeTime:performance.now()-l,perfStart:s,blobBytes:i?ce(e.compressedData):0,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}})}async function se(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=A(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);H(f,d.length,e.vertices.length/3,e.indices.length);let h=m?e.vertices:oe(e.vertices,e.origin,e.scale);if(i){let n=e.vertices.byteLength+e.indices.byteLength;t.c().debug(`Mesh Batch Stats:`),t.c().debug(` Materials: ${d.length} | Groups: ${f.length}`),t.c().debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),t.c().debug(` Format: ${m?`float32`:`int16 quantized`}`),t.c().debug(` Blob: ${(l/1024/1024).toFixed(2)} MB | Geometry on wire: ${(n/1024/1024).toFixed(2)} MB`)}let g=performance.now(),_=d.map(t=>B(t,{vertexColors:e.colors!=null,appearance:a})),v=[];for(let t of f)if(r&&t.meshes.length>1){let n=W(t,h,e.indices,_,e.uvs,e.colors);n.userData.sourceComponentId=p??null,v.push(n)}else{let n=K(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.c().debug(`Performance:`),o>0&&t.c().debug(` Parse JSON: ${o.toFixed(2)}ms`),t.c().debug(` Decode binary: ${s.toFixed(2)}ms`),t.c().debug(` Create Meshes: ${y.toFixed(2)}ms`),t.c().debug(` Total: ${e.toFixed(2)}ms`)}return Promise.resolve(v)}async function X(e,r){if(typeof Worker>`u`)return null;let i=j(e);if(i.indexData.length/3<5e4)return null;let a=L();if(!a)return null;let o=i.metadata.materials??r.fallback?.materials??[],s=i.metadata.groups??r.fallback?.groups??[],c=r.fallback?.sourceComponentId??i.metadata.sourceComponentId;H(s,o.length,i.vertexCount,i.indexData.length);let l=e=>({vertexStart:e.vertexStart,vertexCount:e.vertexCount,indexStart:e.indexStart,indexCount:e.indexCount}),u=[],d=[];for(let e of s)if(r.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=i.vertexData.slice(),p=i.indexData.slice(),m=[f.buffer,p.buffer];i.uvs&&m.push(i.uvs.buffer),i.colors&&m.push(i.colors.buffer);let h;try{h=await re(a,{vertexData:f,isFloat32:i.isFloat32,deltaEncoded:i.deltaEncoded,origin:i.origin,scale:i.scale,indexData:p,uvs:i.uvs,colors:i.colors,jobs:u},m)}catch(e){return t.c().warn(`Mesh assembly worker failed; falling back to main-thread parse.`,e),null}if(h.length!==u.length)return null;let g=o.map(e=>B(e,{vertexColors:i.colors!=null,appearance:r.material})),_=[];for(let e=0;e<h.length;e++){let t=h[e],r=d[e],i=new n.BufferGeometry;i.setAttribute(`position`,new n.BufferAttribute(t.positions,3)),i.setAttribute(`normal`,new n.BufferAttribute(t.normals,3)),i.setIndex(new n.BufferAttribute(t.indices,1)),t.uvs&&i.setAttribute(`uv`,new n.BufferAttribute(t.uvs,2)),t.colors&&i.setAttribute(`color`,new n.BufferAttribute(t.colors,3,!0));let a=r.kind===`merged`?G(i,r.group,g):q(i,r.meshMeta,r.group,g);a.userData.sourceComponentId=c??null,_.push(a)}return r.debug&&t.c().debug(`Mesh batch assembled off-thread: ${_.length} meshes, ${i.indexData.length/3} triangles`),_}function ce(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 le(e){let t=e.split(`.`);return t.includes(`Display`)||t.includes(`DisplayBatch`)}const Q=new Set;async function ue(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 fe(e,r,i?de(e.modelunits):1,c,s),a&&he(r,o),r}catch(e){throw ge(e,r),e}finally{s&&ve(n)}}function de(e){let n=Z[e];return n===void 0?(Q.has(e)||(Q.add(e),t.c().warn(`Unknown Rhino model unit "${e}" — geometry will not be scaled (factor 1). Known units: ${Object.keys(Z).join(`, `)}.`)),1):n}async function fe(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 pe(o,t,n,r,i)}}}async function pe(e,n,r,i,a){for(let o of e){if(!le(o.type))continue;let e={mergeByMaterial:!0,debug:!1,...i},s=me(o.data);if(!s){t.c().error(`Error parsing display batch envelope: invalid JSON`);continue}let c=await J(s,e),l=g(s.items),u=[...c,...l];if(r!==1)for(let e of u)e.scale.set(r,r,r);n.push(...u),a&&t.c().debug(`Extracted ${c.length} meshes and ${l.length} items from batch`)}}function me(e){return typeof e==`string`?$(e):e}function $(e){try{return JSON.parse(e)}catch{return}}function he(e,n){if(e.length===0)return;let r=t.a(e);t.i(e,r.min[n],n)}function ge(e,n){t.c().error(`An unexpected error occurred:`,e),_e(n)}function _e(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 ve(e){let n=performance.now()-e;t.c().info(`Time to process meshes:`,`${n.toFixed(2)}ms`)}exports.SCALE_FACTORS=Z,exports.getThreeMeshesFromComputeResponse=ue,exports.meshPolicy=d,exports.parseDisplayItems=g,exports.parseMeshBatchBlob=se,exports.parseMeshBatchObject=J,exports.setTextureAnisotropy=z;
9
+ #endif`)}}function V(e,n){return new t.d(e,t.u.VALIDATION_ERROR,{context:n})}function H(e,t,n,r){for(let i of e){if(!Number.isInteger(i.materialId)||i.materialId<0||i.materialId>=t)throw V(`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 V(`Mesh metadata field "${n}" must be a non-negative integer.`,{meshName:e.name,field:n,value:r});if(e.vertexStart+e.vertexCount>n)throw V(`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 V(`Mesh index window exceeds the batch index buffer.`,{meshName:e.name,indexStart:e.indexStart,indexCount:e.indexCount,totalIndexCount:r})}}}function U(e,t){return V(`Index references a vertex outside its mesh's vertex window.`,{meshName:t.name,indexValue:e,vertexStart:t.vertexStart,vertexCount:t.vertexCount})}function oe(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 W(e,t,r,i,a=null,o=null){let s=0,c=0;for(let t of e.meshes)s+=t.vertexCount,c+=t.indexCount;let l=new Float32Array(s*3),u=new Uint32Array(c),d=a?new Float32Array(s*2):null,f=o?new Uint8Array(s*3):null,p=0,m=0;for(let n of e.meshes){let e=n.vertexStart*3,i=n.vertexCount*3;if(l.set(t.subarray(e,e+i),p*3),d&&a){let e=n.vertexStart*2;d.set(a.subarray(e,e+n.vertexCount*2),p*2)}f&&o&&f.set(o.subarray(e,e+i),p*3);let s=r.subarray(n.indexStart,n.indexStart+n.indexCount),c=p-n.vertexStart,h=n.vertexStart,g=n.vertexStart+n.vertexCount;for(let e=0;e<s.length;e++){let t=s[e];if(t<h||t>=g)throw U(t,n);u[m+e]=t+c}p+=n.vertexCount,m+=n.indexCount}let h=new n.BufferGeometry;return h.setAttribute(`position`,new n.BufferAttribute(l,3)),h.setIndex(new n.BufferAttribute(u,1)),d&&h.setAttribute(`uv`,new n.BufferAttribute(d,2)),f&&h.setAttribute(`color`,new n.BufferAttribute(f,3,!0)),h.computeVertexNormals(),G(h,e,i)}function G(e,t,r){let i=new n.Mesh(e,r[t.materialId]),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??``,originalIndex:a?.originalIndex??0,mergedIndices:t.meshes.map(e=>e.originalIndex).sort((e,t)=>e-t),metadata:a?.metadata??{},mergedFrom:t.meshes.slice(1).map(e=>({name:e.name,layer:e.layer,originalIndex:e.originalIndex}))},i}function K(e,t,r,i,a=null,o=null){let s=[];for(let c of e.meshes){let l=c.vertexStart*3,u=c.vertexCount*3,d=t.slice(l,l+u),f=r.subarray(c.indexStart,c.indexStart+c.indexCount),p=new Uint32Array(f.length),m=c.vertexStart,h=c.vertexStart+c.vertexCount;for(let e=0;e<f.length;e++){let t=f[e];if(t<m||t>=h)throw U(t,c);p[e]=t-m}let g=new n.BufferGeometry;if(g.setAttribute(`position`,new n.BufferAttribute(d,3)),g.setIndex(new n.BufferAttribute(p,1)),a){let e=c.vertexStart*2,t=a.slice(e,e+c.vertexCount*2);g.setAttribute(`uv`,new n.BufferAttribute(t,2))}if(o){let e=o.slice(l,l+u);g.setAttribute(`color`,new n.BufferAttribute(e,3,!0))}g.computeVertexNormals(),s.push(q(g,c,e,i))}return s}function q(e,t,r,i){let a=new n.Mesh(e,i[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 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(A(e.compressedData),{mergeByMaterial:r,debug:i,material:a,parseTime:o,decodeTime:performance.now()-l,perfStart:s,blobBytes:i?ce(e.compressedData):0,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}})}async function se(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=A(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);H(f,d.length,e.vertices.length/3,e.indices.length);let h=m?e.vertices:oe(e.vertices,e.origin,e.scale);if(i){let n=e.vertices.byteLength+e.indices.byteLength;t.c().debug(`Mesh Batch Stats:`),t.c().debug(` Materials: ${d.length} | Groups: ${f.length}`),t.c().debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),t.c().debug(` Format: ${m?`float32`:`int16 quantized`}`),t.c().debug(` Blob: ${(l/1024/1024).toFixed(2)} MB | Geometry on wire: ${(n/1024/1024).toFixed(2)} MB`)}let g=performance.now(),_=d.map(t=>B(t,{vertexColors:e.colors!=null,appearance:a})),v=[];for(let t of f)if(r&&t.meshes.length>1){let n=W(t,h,e.indices,_,e.uvs,e.colors);p&&(n.userData.sourceComponentId=p),v.push(n)}else{let n=K(t,h,e.indices,_,e.uvs,e.colors);if(p)for(let e of n)e.userData.sourceComponentId=p;v.push(...n)}let y=performance.now()-g;if(i){let e=performance.now()-c;t.c().debug(`Performance:`),o>0&&t.c().debug(` Parse JSON: ${o.toFixed(2)}ms`),t.c().debug(` Decode binary: ${s.toFixed(2)}ms`),t.c().debug(` Create Meshes: ${y.toFixed(2)}ms`),t.c().debug(` Total: ${e.toFixed(2)}ms`)}return Promise.resolve(v)}async function X(e,r){if(typeof Worker>`u`)return null;let i=j(e);if(i.indexData.length/3<5e4)return null;let a=L();if(!a)return null;let o=i.metadata.materials??r.fallback?.materials??[],s=i.metadata.groups??r.fallback?.groups??[],c=r.fallback?.sourceComponentId??i.metadata.sourceComponentId;H(s,o.length,i.vertexCount,i.indexData.length);let l=e=>({vertexStart:e.vertexStart,vertexCount:e.vertexCount,indexStart:e.indexStart,indexCount:e.indexCount}),u=[],d=[];for(let e of s)if(r.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=i.vertexData.slice(),p=i.indexData.slice(),m=[f.buffer,p.buffer];i.uvs&&m.push(i.uvs.buffer),i.colors&&m.push(i.colors.buffer);let h;try{h=await re(a,{vertexData:f,isFloat32:i.isFloat32,deltaEncoded:i.deltaEncoded,origin:i.origin,scale:i.scale,indexData:p,uvs:i.uvs,colors:i.colors,jobs:u},m)}catch(e){return t.c().warn(`Mesh assembly worker failed; falling back to main-thread parse.`,e),null}if(h.length!==u.length)return null;let g=o.map(e=>B(e,{vertexColors:i.colors!=null,appearance:r.material})),_=[];for(let e=0;e<h.length;e++){let t=h[e],r=d[e],i=new n.BufferGeometry;i.setAttribute(`position`,new n.BufferAttribute(t.positions,3)),i.setAttribute(`normal`,new n.BufferAttribute(t.normals,3)),i.setIndex(new n.BufferAttribute(t.indices,1)),t.uvs&&i.setAttribute(`uv`,new n.BufferAttribute(t.uvs,2)),t.colors&&i.setAttribute(`color`,new n.BufferAttribute(t.colors,3,!0));let a=r.kind===`merged`?G(i,r.group,g):q(i,r.meshMeta,r.group,g);c&&(a.userData.sourceComponentId=c),_.push(a)}return r.debug&&t.c().debug(`Mesh batch assembled off-thread: ${_.length} meshes, ${i.indexData.length/3} triangles`),_}function ce(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 le(e){let t=e.split(`.`);return t.includes(`Display`)||t.includes(`DisplayBatch`)}const Q=new Set;async function ue(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 fe(e,r,i?de(e.modelunits):1,c,s),a&&he(r,o),r}catch(e){throw ge(e,r),e}finally{s&&ve(n)}}function de(e){let n=Z[e];return n===void 0?(Q.has(e)||(Q.add(e),t.c().warn(`Unknown Rhino model unit "${e}" — geometry will not be scaled (factor 1). Known units: ${Object.keys(Z).join(`, `)}.`)),1):n}async function fe(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 pe(o,t,n,r,i)}}}async function pe(e,n,r,i,a){for(let o of e){if(!le(o.type))continue;let e={mergeByMaterial:!0,debug:!1,...i},s=me(o.data);if(!s){t.c().error(`Error parsing display batch envelope: invalid JSON`);continue}let c=await J(s,e),l=g(s.items),u=[...c,...l];if(r!==1)for(let e of u)e.scale.set(r,r,r);n.push(...u),a&&t.c().debug(`Extracted ${c.length} meshes and ${l.length} items from batch`)}}function me(e){return typeof e==`string`?$(e):e}function $(e){try{return JSON.parse(e)}catch{return}}function he(e,n){if(e.length===0)return;let r=t.a(e);t.i(e,r.min[n],n)}function ge(e,n){t.c().error(`An unexpected error occurred:`,e),_e(n)}function _e(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 ve(e){let n=performance.now()-e;t.c().info(`Time to process meshes:`,`${n.toFixed(2)}ms`)}exports.SCALE_FACTORS=Z,exports.getThreeMeshesFromComputeResponse=ue,exports.meshPolicy=d,exports.parseDisplayItems=g,exports.parseMeshBatchBlob=se,exports.parseMeshBatchObject=J,exports.setTextureAnisotropy=z;
10
10
  //# sourceMappingURL=parse.cjs.map