Mesh

Mesh

Flexible geometry class to draw things with webgl. Different meshes can even share MeshAttribute objects
provided that the vertexCount matches.

Constructor

new Mesh(attributes)

Source:
Example
// creating a 2D triangle mesh with position and uv attributes.
let position = new MeshAttribute(
     "position", // name
     new Float32Array([-1.0,-1.0, 0.0,1.0, 1.0,-1.0]), // data
     2, // size per vertex (2D vector in this case)
     'FLOAT', // data type
     false // is data normalized in glsl
);
let uv = new MeshAttribute(
     "uv",
     new Uint8Array([0,0, 128,255, 255,0]),
     2,
     'UNSIGNED_BYTE',
     true
);
let mesh = new Mesh([position, uv]);
mesh.draw(gl, program); // program must have uniforms set before drawing!
Parameters:
Name Type Description
attributes Array.<MeshAttribute> attributes for this mesh. must contain an attribute named: 'position'.

Members

attributes :Array.<MeshAttribute>

Source:
Mesh Attributes
Type:

drawMode :String

Source:
Default Value:
  • 'TRIANGLES'
See:
Drawing mode of the mesh
Type:
  • String

(readonly) vertexCount :Number

Source:
Vertex count for this mesh. This is calculated from an attribute named "position"
which MUST be present in the attributes array.
Type:
  • Number

Methods

draw(gl, program)

Source:
Binds all attributes and draws the mesh.
Parameters:
Name Type Description
gl WebGLRenderingContext
program ShaderProgram

getAttribute(name) → {MeshAttribute}

Source:
Returns a mesh attribute by name
Parameters:
Name Type Description
name String
Returns:
attribute
Type
MeshAttribute

loadOBJ(url)

Source:
Loads Mesh attributes from .obj file. The obje must be triangulated and both uv and normal data must be present.
Parameters:
Name Type Description
url String path to the .obj file.