1.0.6 • Published 7 months ago

@chongma/gltf-builder v1.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

Gltf builder

The spec file GltfBuilder.spec.ts contains examples of usage.

Writing points

Use a points builder to build the points structure. Then build it using the GltfBuilder

const gltfBuilder = new GltfBuilder()
const verticesCount = vertices.length
const pointsBuilder = new PointsBuilder(verticesCount, scale)
pointsBuilder.addVertices(vertices)
pointsBuilder.buildGltf(gltfBuilder)
const gltf = gltfBuilder.build()
console.log(JSON.stringify(gltf))

Writing lines

Use a line builder to build the line structure. Then build it using the GltfBuilder

const gltfBuilder = new GltfBuilder()
const verticesCount = vertices.length
const indexesCount = vertices.length
const lineBuilder = new LinesBuilder(verticesCount, indexesCount, scale, LineType.LINE_STRIP)
vertices.forEach(vertex => {
    const index = lineBuilder.addVertex(vertex)
    lineBuilder.addIndex(index)
})
lineBuilder.buildGltf(gltfBuilder)
const gltf = gltfBuilder.build()
console.log(JSON.stringify(gltf))

Writing triangles

Writing Gltf to file

The Gltf can be written to file by stringifying the JSON object

const gltfBuilder = new GltfBuilder()
// add contents
const gltf = gltfBuilder.build()
fs.writeFileSync(path, JSON.stringify(gltf));
1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago