Created
February 27, 2022 21:59
-
-
Save donmccurdy/07f89a045446d943d06c3162d67ed8ac to your computer and use it in GitHub Desktop.
Create a basic GLB with a single mesh.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Accessor, Document, Primitive, NodeIO } from '@gltf-transform/core'; | |
const document = new Document(); | |
const prim = document.createPrimitive(); | |
const buffer = document.createBuffer(); | |
const material = document.createMaterial() | |
.setBaseColorFactor([1.0, 0.0, 0.0, 1.0]) | |
.setMetallicFactor(0.0) | |
.setRoughnessFactor(1.0); | |
prim.setMode(Primitive.Mode.TRIANGLES) | |
.setMaterial(material) | |
.setAttribute( | |
'POSITION', | |
document | |
.createAccessor() | |
.setArray(new Float32Array([0, 0, 0])) | |
.setType(Accessor.Type.VEC3) | |
.setBuffer(buffer) | |
) | |
.setAttribute( | |
'COLOR_0', | |
document | |
.createAccessor() | |
.setArray(new Uint8Array([128, 128, 128])) | |
.setType(Accessor.Type.VEC3) | |
.setBuffer(buffer) | |
); | |
const mesh = document.createMesh().addPrimitive(prim); | |
const node = document.createNode().setMesh(mesh); | |
const scene = document.createScene().addChild(node); | |
const io = new NodeIO(); | |
await io.write('path/to/output.glb', document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment