Draws a simplicial complex in WebGL
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 = require"gl-now"var camera = require"game-shell-orbit-camera"shellvar mat4 = require"gl-matrix"mat4var bunny = require"bunny"var createSimplicialComplex = require"gl-simplicial-complex"var meshshellon"gl-init"var gl = shellglglenableglDEPTH_TESTbunnyMesh = createSimplicialComplexgl bunnyshellon"gl-render"bunnyMeshdrawview: cameraviewprojection: mat4perspectivemat4createMathPI/4.0shellwidth/shellheight0.11000.0
npm instal gl-simplicial-complex
var createSimplicialComplex = require"gl-simplicial-complex"
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