Simplicial-complex-like geometry builder backed by typed arrays.
npm install geom-builderSimplicial-complex-like geometry builder backed by typed arrays.

``bash`
npm install geom-builder
`js
import createGeomBuilder from "geom-builder";
const builder = createGeomBuilder({ vertexColors: 4, cells: 3 });
builder.addPosition([0, 0, 0]);
builder.addPosition([1, 0, 0]);
builder.addPosition([1, 1, 0]);
builder.addVertexColor([1, 0, 0, 1]);
builder.addVertexColor([0, 1, 0, 1]);
builder.addVertexColor([0, 0, 1, 1]);
builder.addCell([0, 1, 0]);
// or builder.addCell(0, 1, 0)
//builder.count = 3 //vertex count
//builder.indexCount = 3 //indices count
//builder.positions = Float32Array(0, 0, 0, 1, 0, 0, 1, 1, 0, ..,)
//builder.colors = Float32Array(1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, ...)
//builder.cells = Uint16Array(0, 1, 2, ...)
`
Parameters
- opts
- size: Int (default: 32) - preallocated vertex buffer sizeInt
- positions: (default: 3) - positions attributeInt
- normals: - enable normals attributeInt
- uvs: - enable uvs attributeInt
- vertexColors: - enable vertexColors attributeInt
- cells: - enable cells (indices)Int
- attributeNames: - enable an arbitrary attribute
_Note: positions attribute is always enabled and defaults to size 3_
_Note: attribute names should be plural_
Returns
geometryBuilder: { positions: Float32Array, vertexColors: Float32Array, cells: Uint32Array }: each attribute can be enabled by passing an integer e.g.: createGeomBuilder({ positions: 3, vertexColors: 4, cells: 2 }).
Every time we add vertex position, color, etc., the internal buffer size is checked and expanded by doubling its capacity as necessary. Therefore builder.count should be used to determine how many vertices to draw instead of builder.positions.length as not all allocated vertices have to be used. Similarly for meshes with cells builder.cellsIndex should be used instead of builder.cells.length.
All enabled attributes can be accessed by builder.attributeName e.g. builder.vertexColors.
All data methods accept structs or individual components e.g. builder.addPosition(v) or builder.addPosition(v[0], v[1], v[2]).
Reset all the counters to prepare arrays for reuse. Nothing is deallocated.
- pos: vec3 - position to add
_Note: adding a vertex position will increment builder.count counter indicating number of vertices added so far_
- normal: vec3 - normal to add
_Note: you need to enable normals in constructor_
- uv: vec2 - uv texture coord to add
_Note: you need to enable uvs in constructor_
- vertexColor: vec4 - vertexColor to add
_Note: you need to enable vertexColors in constructor_
- cell: number | vec2 | vec3 - cell (face) with vertex indices to add
_Note: you need to enable cells in constructor_
- attributeValue: number | array` - any attribute to add
_Note: you need to enable attributeNames (plural) in constructor to get builder.addAttributeName (singular)_
MIT, see LICENSE.md for details.