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:
-
nameString -
bufferBuffer
addBuffers
-
vertexBuffers -
indexBuffers -
stream_type
Adds vertex and indices buffers to a mesh
Parameters:
-
vertexBuffersObjectobject with all the vertex streams
-
indexBuffersObjectobject with all the indices streams
-
stream_typeEnumdefault 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_typeEnumdefault 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:
-
nameString -
dataTyped array -
stream_typeEnumgl.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:
-
nameString"vertices","normals"...
-
attributeStringname of the stream in the shader "a_vertex","a_normal",... [optional, if omitted is used the common_buffers]
-
spacingNumbercomponents per vertex [optional, if ommited is used the common_buffers, if not found then uses 3 ]
-
buffer_dataArrayBufferViewthe data in typed array format [optional, if ommited it created an empty array of getNumVertices() * spacing]
-
stream_typeEnum[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:
-
formatStringto 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_typeEnumdefault 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:
-
nameStringof vertex buffer
Returns:
the buffer
getIndexBuffer
-
name
Returns a index buffer
Parameters:
-
nameStringof 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:
-
nameStringof vertex buffer
Returns:
the buffer
getVertexNumber
-
vertices
Computes the number of vertices
Parameters:
-
verticesTyped Arrayarray containing all the vertices
Mesh.circle
-
options
Returns a circle mesh
Parameters:
-
optionsObjectvalid options: size,radius, xz = in xz plane, otherwise xy plane
Mesh.computeBoundingBox
-
vertices -
bb -
mask
Computes bounding information
Parameters:
-
verticesTyped Arrayarray containing all the vertices
-
bbBBoxwhere to store the bounding box
-
maskArray[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:
-
optionsObjectvalid options: radius, height, subdivisions
Mesh.cube
-
options
Returns a cube mesh of a given size
Parameters:
-
optionsObjectvalid options: size, sizex, sizey, sizez
Mesh.cube
-
options
Returns a cube mesh
Parameters:
-
optionsObjectvalid options: size
Mesh.cylinder
-
options
Returns a cube mesh
Parameters:
-
optionsObjectvalid 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:
-
meshesArrayarray containing all the meshes
Mesh.grid
-
options
Returns a grid mesh (must be rendered using gl.LINES)
Parameters:
-
optionsObjectvalid options: size, lines
Mesh.icosahedron
-
options
Returns a icosahedron mesh (useful to create spheres by subdivision)
Parameters:
-
optionsObjectvalid 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:
-
buffersObjectobject will all the buffers
-
optionsObject[optional]
-
output_meshMesh[optional] mesh to store the mesh, otherwise is created
-
glWebGLContext[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:
-
meshesArrayarray containing object like { mesh:, matrix:, texture_matrix: }
-
optionsObject{ 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:
-
dataStringall the OBJ info to be parsed
-
optionsObject
Returns:
mesh information (vertices, coords, normals, indices)
Mesh.plane
-
options
Returns a planar mesh (you can choose how many subdivisions)
Parameters:
-
optionsObjectvalid 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:
-
optionsObjectno options
Mesh.sphere
-
options
Returns a sphere mesh
Parameters:
-
optionsObjectvalid 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:
-
datacould be string or ArrayBuffer
-
formatStringparser file format name (p.e. "obj")
Returns:
depending on the parser
removeIndexBuffer
-
name -
free
Removes an index buffer from the mesh
Parameters:
-
nameString"vertices","normals"...
-
freeBooleanif you want to remove the data from the GPU
removeVertexBuffer
-
name -
free
Removes a vertex buffer from the mesh
Parameters:
-
nameString"vertices","normals"...
-
freeBooleanif you want to remove the data from the GPU
setBoundingBox
-
center -
half_size
forces a bounding box to be set
Parameters:
-
centerVec3center of the bounding box
-
half_sizeVec3vector 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:
-
nameStringthe name of the buffer
-
attributeStringthe name of the attribute in the shader
-
spacingNumbernumber of numbers per component (3 per vertex, 2 per uvs...), default 3
-
datathe array with all the data
-
stream_typeEnumdefault gl.STATIC_DRAW (other: gl.DYNAMIC_DRAW, gl.STREAM_DRAW
upload
-
buffer_type
Uploads data inside buffers to VRAM.
Parameters:
-
buffer_typeNumbergl.STATIC_DRAW, gl.DYNAMIC_DRAW, gl.STREAM_DRAW
