gokul/cm4-media-carrier
A tscircuit package created by gokul.
- Version
- 0.1.0
- License
- unset
- Stars
- 0
tools/render-board.mjs
import fs from "node:fs/promises"
import path from "node:path"
import {convertCircuitJsonTo3dGlb,getDefaultCameraForCircuitJson,applyCameraPreset} from "circuit-json-to-3d-png"
import {renderGLTFToPNGFromGLB} from "poppygl"
const circuitPath = process.argv[2]
const outputPath = process.argv[3]
const circuitJson = JSON.parse(await fs.readFile(circuitPath,"utf8"))
const glb = await convertCircuitJsonTo3dGlb(circuitJson,{modelPathBaseDir:path.resolve(process.argv[4] ?? "../smart-tv-board"),boardTextureResolution:1600})
await fs.writeFile(`${outputPath}.glb`,glb)
const defaultCamera = await getDefaultCameraForCircuitJson(circuitJson)
for(const preset of ["top-right","left-sideview","top-down"]){
const camera = applyCameraPreset(preset,defaultCamera)
const png = await renderGLTFToPNGFromGLB(glb,{...camera,width:1600,height:1200,supersampling:1,realistic:false})
await fs.writeFile(`${outputPath}-${preset}.png`,png)
}
console.log("Rendered board model and three inspection views",outputPath)