gokul/cm4-media-carrier
A tscircuit package created by gokul.
- Version
- 0.1.0
- License
- unset
- Stars
- 0
tools/led-model.mjs
import { Document, NodeIO } from "@gltf-transform/core"
// Mechanical envelope only, from the Kingbright APT1608 drawing.
const document = new Document()
const buffer = document.createBuffer()
const scene = document.createScene()
const faces = [[0,3,2,1],[4,5,6,7],[0,1,5,4],[1,2,6,5],[2,3,7,6],[3,0,4,7]]
const normals = [[0,0,-1],[0,0,1],[0,-1,0],[1,0,0],[0,1,0],[-1,0,0]]
function box({ name, min, max, color }) {
const vertices = [[min[0],min[1],min[2]],[max[0],min[1],min[2]],[max[0],max[1],min[2]],[min[0],max[1],min[2]],
[min[0],min[1],max[2]],[max[0],min[1],max[2]],[max[0],max[1],max[2]],[min[0],max[1],max[2]]]
const positions = faces.flatMap(face => face.flatMap(index => vertices[index]))
const normalVectors = faces.flatMap((face,index) => face.flatMap(() => normals[index]))
const indices = faces.flatMap((_,index) => [0,1,2,0,2,3].map(vertex => 4 * index + vertex))
const position = document.createAccessor().setType("VEC3").setArray(new Float32Array(positions)).setBuffer(buffer)
const normal = document.createAccessor().setType("VEC3").setArray(new Float32Array(normalVectors)).setBuffer(buffer)
const triangles = document.createAccessor().setType("SCALAR").setArray(new Uint16Array(indices)).setBuffer(buffer)
const material = document.createMaterial(name).setBaseColorFactor(color).setRoughnessFactor(0.6)
const primitive = document.createPrimitive().setAttribute("POSITION",position).setAttribute("NORMAL",normal).setIndices(triangles).setMaterial(material)
scene.addChild(document.createNode(name).setMesh(document.createMesh(name).addPrimitive(primitive)))
}
box({name:"substrate",min:[-.8,-.4,0],max:[.8,.4,.25],color:[.9,.87,.7,1]})
box({name:"lens-envelope",min:[-.6,-.4,.25],max:[.6,.4,.75],color:[.87,.86,.64,1]})
box({name:"anode",min:[-.8,-.4,0],max:[-.5,.4,.26],color:[.8,.61,.14,1]})
box({name:"cathode-pin-1",min:[.5,-.4,0],max:[.8,.4,.26],color:[.8,.61,.14,1]})
await new NodeIO().write("../smart-tv-board/models/led.glb",document)