Skip to content

dpisani/gltf-builder

Repository files navigation

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]])
        )
      )
    )
  )
);

// Calling .build on the asset produces the final product as an object
const gltf = triangleAsset.build();

// Saving to a file
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

About

Build 3D models using Javascript

Resources

License

Stars

Watchers

Forks

Packages

No packages published