Basic module for drawing a simplicial complex. This code can be used to get something on the screen quickly. It is useful for debugging and prototyping, though in a real 3d engine you would probably want to write your own shaders and vertex formats.
var shell =var camera = shellvar mat4 = mat4var bunny =var createSimplicialComplex =var meshshellshell
npm instal gl-simplicial-complex
var createSimplicialComplex =
var mesh = createSimplicialComplex(gl, params)
Creates a simplicial complex that can be drawn directly in a WebGL context.
gl- is a handle to a WebGL context
paramsis an object that has the following properties:
cells(Required) An indexed list of vertices, edges and/or faces.
positions(Required) An array of positions for the mesh, encoded as arrays
vertexColorsA list of per vertex color attributes encoded as length 3 rgb arrays
cellColorsA list of per cell color attributes
meshColorA constant color for the entire mesh
vertexNormalsAn array of per vertex normals
cellNormalsAn array of per cell normals
useFacetNormalsA flag which if set to
cellNormalsto be computed
pointSizesAn array of point sizes
pointSizeA single point size float
Returns A renderable mesh object
Draws the mesh to the current buffer using a Phong material.
paramsis an object that has the following properties
modelThe model matrix for the object
viewThe view matrix for the camera
projectionThe projection matrix for the display
Updates the contents of the simplicial complex in place.
paramsis a list of parameters which are in the same format as
Draws the mesh for the purposes of point picking and selection.
Using the output from gl-select finds the point on the mesh closest to the given pick data.
Returns An object with the following properties:
positionsthe position of the picked point on the mesh
cellIdthe index of the closest cell
cellthe cell of the closest point
indexthe index of the closest vertex
Destroys the mesh object and releases all resources assigned to it.
(c) 2013 Mikola Lysenko. MIT License