@selvajs/visualization 1.0.0-beta.4 → 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.js CHANGED
@@ -6,5 +6,5 @@ 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-dispos
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 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};
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,mergedIndices:t.meshes.map(e=>e.originalIndex).sort((e,t)=>e-t),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);p&&(n.userData.sourceComponentId=p),v.push(n)}else{let n=fe(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().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);s&&(i.userData.sourceComponentId=s),_.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