audit-user-sample-glb-quality.mjs 2.0 KB

123456789
  1. import {readFileSync,writeFileSync} from 'node:fs'
  2. import {resolve,join} from 'node:path'
  3. import {unpackInstanceBuffers} from './instance-buffer-codec.mjs'
  4. const root=resolve('tools/city-massing/city/cad-bim'),sources=[{label:'positive-urban-sample',dir:'lod-batch-urban8000b-roofed2',ids:['cad-16575','cad-16576']},{label:'positive-urban-tail',dir:'lod-batch-urban-tail-roofed2',ids:['cad-16503']},{label:'negative-rural-whitelist',dir:'lod-batch-rural1',ids:['cad-25612','cad-25968','cad-25957']},{label:'negative-rural-slab',dir:'lod-batch-rural3',ids:['cad-25467']}]
  5. function stat(file){const d=unpackInstanceBuffers(readFileSync(file)),j=d.json;let tri=0,verts=0,prims=0;for(const m of j.meshes||[])for(const p of m.primitives||[]){prims++;verts+=j.accessors[p.attributes.POSITION]?.count||0;tri+=p.indices!==undefined?(j.accessors[p.indices]?.count||0)/3:0}return{file,bytes:d.bin.length,nodes:j.nodes?.length||0,meshes:j.meshes?.length||0,triangles:tri,vertices:verts,primitives:prims,materials:(j.materials||[]).map(m=>m.name),textures:j.textures?.length||0,images:j.images?.length||0,extensionsUsed:j.extensionsUsed||[]}}
  6. const rows=[]
  7. for(const s of sources){const manifest=JSON.parse(readFileSync(join(root,s.dir,'manifest.json')));for(const id of s.ids){const cell=manifest.cells.find(c=>c.buildingIds.includes(id));if(!cell)throw Error(`${s.label} missing ${id}`);const file=join(root,s.dir,cell.lod0.uri);rows.push({id,label:s.label,cell:cell.id,cellCount:cell.count,cellBuildingIds:cell.buildingIds,stats:stat(file)})}}
  8. const report={generatedAt:'2026-10-14',rows,attribution:'cell-level GLB statistics; merged cells cannot attribute triangles/textures to one building',modelChanged:false}
  9. writeFileSync('.scratch/cockpit-shell-panel-layout/verify/artifacts/t35/user-samples/glb-quality-baseline.json',JSON.stringify(report,null,2));console.log(JSON.stringify({passed:true,rows:rows.map(r=>({id:r.id,label:r.label,cell:r.cell,cellCount:r.cellCount,triangles:r.stats.triangles,materials:r.stats.materials.length,textures:r.stats.textures,images:r.stats.images})),modelChanged:false}))