master
John Lauer export-wiki guide: rewrite for the current publish path (README.html, not an auto-rendered asset), add the three tscirc… ed21612 2mo ago
import fs from "fs"
const f = process.argv[2]
const b = fs.readFileSync(f)
const g = JSON.parse(b.slice(20, 20 + b.readUInt32LE(12)).toString("utf8"))
const mat = n => { if (n.matrix) return n.matrix.slice()
  const t=n.translation||[0,0,0], r=n.rotation||[0,0,0,1], s=n.scale||[1,1,1], [x,y,z,w]=r
  return [(1-2*(y*y+z*z))*s[0],(2*(x*y+z*w))*s[0],(2*(x*z-y*w))*s[0],0,
          (2*(x*y-z*w))*s[1],(1-2*(x*x+z*z))*s[1],(2*(y*z+x*w))*s[1],0,
          (2*(x*z+y*w))*s[2],(2*(y*z-x*w))*s[2],(1-2*(x*x+y*y))*s[2],0,t[0],t[1],t[2],1] }
const mul=(a,b)=>{const o=new Array(16);for(let c=0;c<4;c++)for(let r=0;r<4;r++){let v=0;for(let k=0;k<4;k++)v+=a[k*4+r]*b[c*4+k];o[c*4+r]=v}return o}
const xf=(m,p)=>[m[0]*p[0]+m[4]*p[1]+m[8]*p[2]+m[12],m[1]*p[0]+m[5]*p[1]+m[9]*p[2]+m[13],m[2]*p[0]+m[6]*p[1]+m[10]*p[2]+m[14]]
const I=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]
function bbox(i,parent,acc){const n=g.nodes[i],m=mul(parent,mat(n))
  if(n.mesh!=null)for(const p of g.meshes[n.mesh].primitives){const a=g.accessors[p.attributes.POSITION];if(!a.min)continue
    for(let k2=0;k2<8;k2++){const c=[(k2&1)?a.max[0]:a.min[0],(k2&2)?a.max[1]:a.min[1],(k2&4)?a.max[2]:a.min[2]],w=xf(m,c)
      for(let k=0;k<3;k++){acc.min[k]=Math.min(acc.min[k],w[k]);acc.max[k]=Math.max(acc.max[k],w[k])}}}
  for(const c of n.children||[])bbox(c,m,acc)}
const get=nm=>{const i=g.nodes.findIndex(n=>n.name===nm);if(i<0)return null
  const acc={min:[1e9,1e9,1e9],max:[-1e9,-1e9,-1e9]};bbox(i,I,acc);return acc}
const j1=get("J1"), bd=get("Box0")
const leds=g.nodes.filter(n=>/^D\d+$/.test(n.name||"")).length
const tex=(g.images||[]).length
console.log(`${f.split("/").pop()}`)
console.log(`  nodes ${g.nodes.length} | LED nodes ${leds} | images(textures) ${tex}`)
console.log(`  board ${(bd.max[0]-bd.min[0]).toFixed(1)} x ${(bd.max[2]-bd.min[2]).toFixed(1)} mm`)
console.log(`  J1 pcb x ${(-j1.max[0]).toFixed(2)} .. ${(-j1.min[0]).toFixed(2)}  (east edge ${bd.max[0].toFixed(2)})`)