GL.Mesh Class
Item Index
Methods
- addBuffer
- addBuffers
- clone
- clone
- computeGroupsBoundingBoxes
- computeIndices
- computeNormals
- computeTangents
- computeTextureCoordinates
- computeWireframe
- createIndexBuffer
- createVertexBuffer
- encode
- explodeIndices
- flipNormals
- freeData
- generateMetadata
- getBoundingBox
- getBuffer
- getIndexBuffer
- getMemory
- getScreenQuad
- getVertexBuffer
- getVertexNumber
- Mesh.circle
- Mesh.computeBoundingBox
- Mesh.cone
- Mesh.cube
- Mesh.cube
- Mesh.cylinder
- Mesh.fromOBJ
- Mesh.grid
- Mesh.icosahedron
- Mesh.load
- Mesh.mergeMeshes
- Mesh.parseOBJ
- Mesh.plane
- Mesh.plane2D
- Mesh.point
- Mesh.sphere
- parse
- removeIndexBuffer
- removeVertexBuffer
- setBoundingBox
- simplify
- toObject
- updateBoundingBox
- updateVertexBuffer
- upload
Methods
addBuffer
-
name
-
buffer
Adds buffer to mesh
Parameters:
-
name
String -
buffer
Buffer
addBuffers
-
vertexBuffers
-
indexBuffers
-
stream_type
Adds vertex and indices buffers to a mesh
Parameters:
-
vertexBuffers
Objectobject with all the vertex streams
-
indexBuffers
Objectobject with all the indices streams
-
stream_type
Enumdefault gl.STATIC_DRAW (other: gl.DYNAMIC_DRAW, gl.STREAM_DRAW )
clone
()
Creates a clone of the mesh, but the data-arrays are shared between both meshes (useful for sharing a mesh between contexts)
clone
()
Creates a clone of the mesh, the datarrays are cloned too
computeGroupsBoundingBoxes
()
Update bounding information for every group submesh
computeIndices
()
Compute indices for a mesh where vertices are shared
computeNormals
-
stream_type
Creates a stream with the normals
Parameters:
-
stream_type
Enumdefault gl.STATIC_DRAW (other: gl.DYNAMIC_DRAW, gl.STREAM_DRAW)
computeTangents
()
Creates a new stream with the tangents
computeTextureCoordinates
()
Creates texture coordinates using a triplanar aproximation
computeWireframe
()
Creates a new index stream with wireframe
createIndexBuffer
-
name
-
data
-
stream_type
Creates a new empty index buffer and attachs it to this mesh
Parameters:
-
name
String -
data
Typed array -
stream_type
Enumgl.STATIC_DRAW, gl.DYNAMIC_DRAW, gl.STREAM_DRAW
createVertexBuffer
-
name
-
attribute
-
spacing
-
buffer_data
-
stream_type
Creates a new empty buffer and attachs it to this mesh
Parameters:
-
name
String"vertices","normals"...
-
attribute
Stringname of the stream in the shader "a_vertex","a_normal",... [optional, if omitted is used the common_buffers]
-
spacing
Numbercomponents per vertex [optional, if ommited is used the common_buffers, if not found then uses 3 ]
-
buffer_data
ArrayBufferViewthe data in typed array format [optional, if ommited it created an empty array of getNumVertices() * spacing]
-
stream_type
Enum[optional, default = gl.STATIC_DRAW (other: gl.DYNAMIC_DRAW, gl.STREAM_DRAW ) ]
encode
-
format
It returns the mesh data encoded in the format specified Only obj supported now
Parameters:
-
format
Stringto encode the data to (p.e. "obj")
Returns:
String with the info
explodeIndices
()
Breaks the indices
flipNormals
-
stream_type
Multiplies every normal by -1 and uploads it
Parameters:
-
stream_type
Enumdefault gl.STATIC_DRAW (other: gl.DYNAMIC_DRAW, gl.STREAM_DRAW)
freeData
()
Remove all local memory from the streams (leaving it only in the VRAM) to save RAM
generateMetadata
()
Computes some data about the mesh
getBoundingBox
()
BBox
returns the bounding box, if it is not computed, then computes it
Returns:
bounding box
getBuffer
-
name
Returns a vertex buffer
Parameters:
-
name
Stringof vertex buffer
Returns:
the buffer
getIndexBuffer
-
name
Returns a index buffer
Parameters:
-
name
Stringof index buffer
Returns:
the buffer
getMemory
()
Number
Returns the amount of memory used by this mesh in bytes (sum of all buffers)
Returns:
bytes
getScreenQuad
()
GL.Mesh
Returns a shared mesh containing a quad to be used when rendering to the screen Reusing the same quad helps not filling the memory
Returns:
the screen quad
getVertexBuffer
-
name
Returns a vertex buffer
Parameters:
-
name
Stringof vertex buffer
Returns:
the buffer
getVertexNumber
-
vertices
Computes the number of vertices
Parameters:
-
vertices
Typed Arrayarray containing all the vertices
Mesh.circle
-
options
Returns a circle mesh
Parameters:
-
options
Objectvalid options: size,radius, xz = in xz plane, otherwise xy plane
Mesh.computeBoundingBox
-
vertices
-
bb
-
mask
Computes bounding information
Parameters:
-
vertices
Typed Arrayarray containing all the vertices
-
bb
BBoxwhere to store the bounding box
-
mask
Array[optional] to specify which vertices must be considered when creating the bbox, used to create BBox of a submesh
Mesh.cone
-
options
Returns a cone mesh
Parameters:
-
options
Objectvalid options: radius, height, subdivisions
Mesh.cube
-
options
Returns a cube mesh of a given size
Parameters:
-
options
Objectvalid options: size, sizex, sizey, sizez
Mesh.cube
-
options
Returns a cube mesh
Parameters:
-
options
Objectvalid options: size
Mesh.cylinder
-
options
Returns a cube mesh
Parameters:
-
options
Objectvalid options: radius, height, subdivisions
Mesh.fromOBJ
-
meshes
Returns am empty mesh and loads a mesh and parses it using the Mesh.parsers, by default only OBJ is supported
Parameters:
-
meshes
Arrayarray containing all the meshes
Mesh.grid
-
options
Returns a grid mesh (must be rendered using gl.LINES)
Parameters:
-
options
Objectvalid options: size, lines
Mesh.icosahedron
-
options
Returns a icosahedron mesh (useful to create spheres by subdivision)
Parameters:
-
options
Objectvalid options: radius, subdivisions (max: 6)
Mesh.load
-
buffers
-
options
-
output_mesh
-
gl
Static method for the class Mesh to create a mesh from a list of common streams
Parameters:
-
buffers
Objectobject will all the buffers
-
options
Object[optional]
-
output_mesh
Mesh[optional] mesh to store the mesh, otherwise is created
-
gl
WebGLContext[optional] if omitted, the global.gl is used
Mesh.mergeMeshes
-
meshes
-
options
Returns a mesh with all the meshes merged (you can apply transforms individually to every buffer)
Parameters:
-
meshes
Arrayarray containing object like { mesh:, matrix:, texture_matrix: }
-
options
Object{ only_data: to get the mesh data without uploading it }
Returns:
the mesh in GL.Mesh format or Object format (if options.only_data is true)
Mesh.parseOBJ
-
data
-
options
Parses a OBJ string and returns an object with the info ready to be passed to GL.Mesh.load
Parameters:
-
data
Stringall the OBJ info to be parsed
-
options
Object
Returns:
mesh information (vertices, coords, normals, indices)
Mesh.plane
-
options
Returns a planar mesh (you can choose how many subdivisions)
Parameters:
-
options
Objectvalid options: detail, detailX, detailY, size, width, heigth, xz (horizontal plane)
Mesh.plane2D
()
Returns a 2D Mesh (be careful, stream is vertices2D, used for 2D engines )
Mesh.point
-
options
Returns a point mesh
Parameters:
-
options
Objectno options
Mesh.sphere
-
options
Returns a sphere mesh
Parameters:
-
options
Objectvalid options: radius, lat, long, subdivisions, hemi
parse
-
data
-
format
given some data an information about the format, it search for a parser in Mesh.parsers and tries to extract the mesh information Only obj supported now
Parameters:
-
data
could be string or ArrayBuffer
-
format
Stringparser file format name (p.e. "obj")
Returns:
depending on the parser
removeIndexBuffer
-
name
-
free
Removes an index buffer from the mesh
Parameters:
-
name
String"vertices","normals"...
-
free
Booleanif you want to remove the data from the GPU
removeVertexBuffer
-
name
-
free
Removes a vertex buffer from the mesh
Parameters:
-
name
String"vertices","normals"...
-
free
Booleanif you want to remove the data from the GPU
setBoundingBox
-
center
-
half_size
forces a bounding box to be set
Parameters:
-
center
Vec3center of the bounding box
-
half_size
Vec3vector from the center to positive corner
simplify
()
Mesh
returns a low poly version of the mesh that takes much less memory (but breaks tiling of uvs and smoothing groups)
Returns:
simplified mesh
toObject
()
Creates an object with the info of the mesh (useful to transfer to workers)
updateBoundingBox
()
Update bounding information of this mesh
updateVertexBuffer
-
name
-
attribute
-
spacing
-
data
-
stream_type
Updates a vertex buffer
Parameters:
-
name
Stringthe name of the buffer
-
attribute
Stringthe name of the attribute in the shader
-
spacing
Numbernumber of numbers per component (3 per vertex, 2 per uvs...), default 3
-
data
the array with all the data
-
stream_type
Enumdefault gl.STATIC_DRAW (other: gl.DYNAMIC_DRAW, gl.STREAM_DRAW
upload
-
buffer_type
Uploads data inside buffers to VRAM.
Parameters:
-
buffer_type
Numbergl.STATIC_DRAW, gl.DYNAMIC_DRAW, gl.STREAM_DRAW