geom = createGeometry(gl)
Creates a new geometry attached to the WebGL canvas context
geom.attr(name, values[, opt])
Define or update an attribute value, for example using a simplicial complex:
var createGeometry =var bunny =var geom =
The following vertex formats are supported and will be normalized:
Arrays of arrays, e.g.
[[0, 0, 0], [1, 0, 0], [1, 1, 0]].
Flat arrays, e.g.
[0, 0, 0, 1, 0, 0, 1, 1, 0].
Typed arrays, preferably a
simplicial complexes, i.e. an object with a
positionsarray and a
cellsarray. The former is a list of unique vertices in the mesh (if you've used three.js, think
THREE.Vector3), and the latter is an index mapping these vertices to faces (
THREE.Face3) in the mesh. It looks something like this:
You can specify
opt.size for the vertex size, defaults to 3.
You can update attribute values by calling
attr again with the same
By default the entire contents of the associated
gl-bufferare replaced by
data; the buffer will be resized accordingly.
Alternatively, you can pass
datainto the current buffer at a specific offset (in bytes). In this case, the buffer cannot be resized.
Pass a simplicial complex's
cells property here in any of the above formats
to use it as your index when drawing the geometry. For example:
var createGeometry =var bunny =bunnynormals = normalsvar geom =
You can specify
opt.size for the cell size, defaults to 3.
geom.draw(mode, start, stop)
Draws the geometry to the screen using the currently bound shader.
Optionally, you can pass in the drawing mode, which should be one of the following:
The default value is
gl.TRIANGLES. You're also able to pass in a
stop range for the points you want to render, just the same as you would
Unbinds the underlying VAO. This must be done when you're finished drawing, unless you're binding to another gl-geometry or gl-vao instance.
Disposes the underlying element and array buffers, as well as the VAO.
- ArrayBuffer and Typed Arrays
- The WebGL Context
MIT. See LICENSE.md for details.