gltf-builder
Create 3D models using JS.
gltf-builder provides a means to programatically construct 3D assets in the glTF file format. It aims to make procedural generation easier by letting you build up a model piece-by-piece without having to worry about the structure of the glTF file format itself.
Installation
npm install gltf-builder
Getting started
The gltf-builder package contains builders for various glTF components used to construct a 3D asset. Each component allows for all of its properties to be set in a chaining style syntax, and can be then composed together to make the final product.
const {
Asset,
Scene,
Mesh,
Node,
Primitive,
buildVec3Accessor
} = require('gltf-builder');
const triangleAsset = new Asset().addScene(
new Scene().addNode(
new Node().mesh(
new Mesh().addPrimitive(
new Primitive().position(
buildVec3Accessor([[0, 0, 0], [1, 0, 0], [0, 1, 0]])
)
)
)
)
);
const gltf = triangleAsset.build();
const fs = require('fs');
fs.writeFileSync('triangle.gltf', JSON.stringify(gltf), 'utf8');
The created model can be viewed online using gltf-viewer or added
to a scene using a framework like A-Frame.
Docs