main
John Lauer
Update Board31 digital twin with verified fan state rendering
7359da9
// Canonical viewer screenshot review only: no user desktop/browser window opened.
const {default:puppeteer}=await import(process.env.PUPPETEER_MODULE || '/home/adom/project/adom-video-brand/node_modules/puppeteer-core/lib/esm/puppeteer/puppeteer-core.js');
import fs from 'node:fs';
const browser=await puppeteer.launch({executablePath:process.env.CHROME || '/home/adom/.cache/ms-playwright/chromium-1243/chrome-linux64/chrome',headless:true,args:['--no-sandbox','--use-angle=swiftshader','--enable-unsafe-swiftshader']});
try {
const page=await browser.newPage();await page.setViewport({width:1600,height:1100,deviceScaleFactor:1});const errors=[];page.on('pageerror',e=>errors.push(e.message));
for(const model of (process.env.REVIEW_MODEL?[process.env.REVIEW_MODEL]:['board','assembly'])){
await page.goto(process.argv[2]+'/mechanical/board31-review/review.html?model='+model,{waitUntil:'networkidle0',timeout:90000});
await page.waitForFunction(()=>window.review!==undefined,{timeout:90000});
const status=await page.evaluate(()=>({ready:window.review.ready,error:window.review.error,methods:window.review.viewer?Object.keys(window.review.viewer):[]}));
if(!status.ready)throw Error(JSON.stringify(status));
await new Promise(r=>setTimeout(r,1500));
await page.screenshot({path:'mechanical/board31-review/'+model+'-canonical.png'});
if(model==='board'){
await page.evaluate(()=>{const c=review.viewer.getCamera();const V=c.target.constructor;c.setTarget(new V(.025,.015,.0028));c.radius=.040;});
await new Promise(r=>setTimeout(r,500));await page.screenshot({path:'mechanical/board31-review/board-pad-detail.png'});
} else {
const motion=await page.evaluate(async()=>{
const {bindFanMotion}=await import('/control-panel/twin/controller.mjs');const scene=review.viewer.getScene();
const manifest=await fetch('assembly-states.json').then(r=>r.json());const adapter=bindFanMotion(scene,manifest);
const rotor=[...scene.transformNodes,...scene.meshes].find(n=>n.name==='Fan.Rotor');
const housing=[...scene.transformNodes,...scene.meshes].find(n=>n.name==='Fan.Housing');
const q=()=>rotor.rotationQuaternion.asArray();const h=()=>Array.from(housing.computeWorldMatrix(true).asArray());
const delay=ms=>new Promise(r=>setTimeout(r,ms));
const frames=async count=>{for(let i=0;i<count;i++)await new Promise((resolve,reject)=>{const timer=setTimeout(()=>{scene.onAfterRenderObservable.remove(observer);reject(Error('No rendered frame within10s'));},10000);const observer=scene.onAfterRenderObservable.addOnce(()=>{clearTimeout(timer);resolve();});});};
const off=adapter.apply({state:'off',speed:0,source:'simulated',timeScale:.002});const stopped0=q();await frames(3);const stopped1=q();
const housing0=h();const on=adapter.apply({state:'on',speed:6000,source:'simulated',timeScale:.002});await frames(5);const rotating=q();const housing1=h();
const unknown=adapter.apply({state:'on',speed:6000,source:'simulated',valid:false,timeScale:.002});const paused0=q();await frames(3);const paused1=q();adapter.dispose();
const same=(a,b)=>a.every((v,i)=>Math.abs(v-b[i])<1e-6);
return {off,on,unknown,diagnostics:{animationsEnabled:scene.animationsEnabled,engineFps:scene.getEngine().getFps(),stopped0,stopped1,rotating,groups:scene.animationGroups.map(g=>({name:g.name,from:g.from,to:g.to,keys:g.targetedAnimations.map(t=>t.animation.getKeys().map(k=>({frame:k.frame,value:k.value.asArray?.()})))}))},offPoseStable:same(stopped0,stopped1),rotorMoved:!same(stopped1,rotating),housingUnchanged:same(housing0,housing1),unknownPauses:same(paused0,paused1),source:'Synthetic renderer test; no measured RPM or hardware control'};
});
fs.writeFileSync('mechanical/board31-review/fan-runtime-check.json',JSON.stringify(motion,null,2)+'\n');
if(!motion.offPoseStable||!motion.rotorMoved||!motion.housingUnchanged||!motion.unknownPauses)throw Error('fan scene behavior failed: '+JSON.stringify(motion));
await page.evaluate(()=>{const c=review.viewer.getCamera();c.alpha+=Math.PI/2;c.beta=Math.PI/2.8;});
await new Promise(r=>setTimeout(r,500));await page.screenshot({path:'mechanical/board31-review/assembly-side.png'});
}
fs.writeFileSync('mechanical/board31-review/'+model+'-canonical-review.json',JSON.stringify({...status,errors,visualAcceptance:'pending image inspection',source:'Canonical Adom Babylon viewer in local headless Chromium; not native desktop footage'},null,2)+'\n');
console.log(model,JSON.stringify(status));
}
} finally {await browser.close();}