API Docs for:
Show:

GL.Mesh Class

Methods

addBuffer

(
  • name
  • buffer
)

Defined in ../src/mesh.js:340

Adds buffer to mesh

Parameters:

  • name String
  • buffer Buffer

addBuffers

(
  • vertexBuffers
  • indexBuffers
  • stream_type
)

Defined in ../src/mesh.js:359

Adds vertex and indices buffers to a mesh

Parameters:

  • vertexBuffers Object

    object with all the vertex streams

  • indexBuffers Object

    object with all the indices streams

  • stream_type Enum

    default gl.STATIC_DRAW (other: gl.DYNAMIC_DRAW, gl.STREAM_DRAW )

clone

()

Defined in ../src/mesh.js:716

Creates a clone of the mesh, but the data-arrays are shared between both meshes (useful for sharing a mesh between contexts)

clone

()

Defined in ../src/mesh.js:692

Creates a clone of the mesh, the datarrays are cloned too

computeGroupsBoundingBoxes

()

Defined in ../src/mesh.js:1526

Update bounding information for every group submesh

computeIndices

()

Defined in ../src/mesh.js:967

Compute indices for a mesh where vertices are shared

computeNormals

(
  • stream_type
)

Defined in ../src/mesh.js:1126

Creates a stream with the normals

Parameters:

  • stream_type Enum

    default gl.STATIC_DRAW (other: gl.DYNAMIC_DRAW, gl.STREAM_DRAW)

computeTangents

()

Defined in ../src/mesh.js:1212

Creates a new stream with the tangents

computeTextureCoordinates

()

Defined in ../src/mesh.js:1317

Creates texture coordinates using a triplanar aproximation

computeWireframe

()

Defined in ../src/mesh.js:883

Creates a new index stream with wireframe

createIndexBuffer

(
  • name
  • data
  • stream_type
)

Defined in ../src/mesh.js:554

Creates a new empty index buffer and attachs it to this mesh

Parameters:

  • name String
  • data Typed array
  • stream_type Enum

    gl.STATIC_DRAW, gl.DYNAMIC_DRAW, gl.STREAM_DRAW

createVertexBuffer

(
  • name
  • attribute
  • spacing
  • buffer_data
  • stream_type
)

Defined in ../src/mesh.js:453

Creates a new empty buffer and attachs it to this mesh

Parameters:

  • name String

    "vertices","normals"...

  • attribute String

    name of the stream in the shader "a_vertex","a_normal",... [optional, if omitted is used the common_buffers]

  • spacing Number

    components per vertex [optional, if ommited is used the common_buffers, if not found then uses 3 ]

  • buffer_data ArrayBufferView

    the 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
)
?

Defined in ../src/mesh.js:1945

It returns the mesh data encoded in the format specified Only obj supported now

Parameters:

  • format String

    to encode the data to (p.e. "obj")

Returns:

?:

String with the info

explodeIndices

()

Defined in ../src/mesh.js:1063

Breaks the indices

flipNormals

(
  • stream_type
)

Defined in ../src/mesh.js:934

Multiplies every normal by -1 and uploads it

Parameters:

  • stream_type Enum

    default gl.STATIC_DRAW (other: gl.DYNAMIC_DRAW, gl.STREAM_DRAW)

freeData

()

Defined in ../src/mesh.js:1584

Remove all local memory from the streams (leaving it only in the VRAM) to save RAM

generateMetadata

()

Defined in ../src/mesh.js:811

Computes some data about the mesh

getBoundingBox

() BBox

Defined in ../src/mesh.js:1499

returns the bounding box, if it is not computed, then computes it

Returns:

BBox:

bounding box

getBuffer

(
  • name
)
Buffer

Defined in ../src/mesh.js:582

Returns a vertex buffer

Parameters:

  • name String

    of vertex buffer

Returns:

Buffer:

the buffer

getIndexBuffer

(
  • name
)
Buffer

Defined in ../src/mesh.js:593

Returns a index buffer

Parameters:

  • name String

    of index buffer

Returns:

Buffer:

the buffer

getMemory

() Number

Defined in ../src/mesh.js:1646

Returns the amount of memory used by this mesh in bytes (sum of all buffers)

Returns:

Number:

bytes

getScreenQuad

() GL.Mesh

Defined in ../src/mesh.js:1961

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:

GL.Mesh:

the screen quad

getVertexBuffer

(
  • name
)
Buffer

Defined in ../src/mesh.js:542

Returns a vertex buffer

Parameters:

  • name String

    of vertex buffer

Returns:

Buffer:

the buffer

getVertexNumber

(
  • vertices
)

Defined in ../src/mesh.js:1430

Computes the number of vertices

Parameters:

  • vertices Typed Array

    array containing all the vertices

Mesh.circle

(
  • options
)

Returns a circle mesh

Parameters:

  • options Object

    valid options: size,radius, xz = in xz plane, otherwise xy plane

Mesh.computeBoundingBox

(
  • vertices
  • bb
  • mask
)

Defined in ../src/mesh.js:1442

Computes bounding information

Parameters:

  • vertices Typed Array

    array containing all the vertices

  • bb BBox

    where 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 Object

    valid options: radius, height, subdivisions

Mesh.cube

(
  • options
)

Returns a cube mesh of a given size

Parameters:

  • options Object

    valid options: size, sizex, sizey, sizez

Mesh.cube

(
  • options
)

Returns a cube mesh

Parameters:

  • options Object

    valid options: size

Mesh.cylinder

(
  • options
)

Returns a cube mesh

Parameters:

  • options Object

    valid options: radius, height, subdivisions

Mesh.fromOBJ

(
  • meshes
)

Defined in ../src/mesh.js:1899

Returns am empty mesh and loads a mesh and parses it using the Mesh.parsers, by default only OBJ is supported

Parameters:

  • meshes Array

    array containing all the meshes

Mesh.grid

(
  • options
)

Returns a grid mesh (must be rendered using gl.LINES)

Parameters:

  • options Object

    valid options: size, lines

Mesh.icosahedron

(
  • options
)

Returns a icosahedron mesh (useful to create spheres by subdivision)

Parameters:

  • options Object

    valid options: radius, subdivisions (max: 6)

Mesh.load

(
  • buffers
  • options
  • output_mesh
  • gl
)

Defined in ../src/mesh.js:1715

Static method for the class Mesh to create a mesh from a list of common streams

Parameters:

  • buffers Object

    object 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
)
GL.Mesh | Object

Defined in ../src/mesh.js:1732

Returns a mesh with all the meshes merged (you can apply transforms individually to every buffer)

Parameters:

  • meshes Array

    array containing object like { mesh:, matrix:, texture_matrix: }

  • options Object

    { only_data: to get the mesh data without uploading it }

Returns:

GL.Mesh | Object:

the mesh in GL.Mesh format or Object format (if options.only_data is true)

Mesh.parseOBJ

(
  • data
  • options
)
Object

Defined in ../src/parsers.js:2

Parses a OBJ string and returns an object with the info ready to be passed to GL.Mesh.load

Parameters:

  • data String

    all the OBJ info to be parsed

  • options Object

Returns:

Object:

mesh information (vertices, coords, normals, indices)

Mesh.plane

(
  • options
)

Returns a planar mesh (you can choose how many subdivisions)

Parameters:

  • options Object

    valid 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 Object

    no options

Mesh.sphere

(
  • options
)

Returns a sphere mesh

Parameters:

  • options Object

    valid options: radius, lat, long, subdivisions, hemi

parse

(
  • data
  • format
)
?

Defined in ../src/mesh.js:1928

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 String

    parser file format name (p.e. "obj")

Returns:

?:

depending on the parser

removeIndexBuffer

(
  • name
  • free
)

Defined in ../src/mesh.js:604

Removes an index buffer from the mesh

Parameters:

  • name String

    "vertices","normals"...

  • free Boolean

    if you want to remove the data from the GPU

removeVertexBuffer

(
  • name
  • free
)

Defined in ../src/mesh.js:527

Removes a vertex buffer from the mesh

Parameters:

  • name String

    "vertices","normals"...

  • free Boolean

    if you want to remove the data from the GPU

setBoundingBox

(
  • center
  • half_size
)

Defined in ../src/mesh.js:1573

forces a bounding box to be set

Parameters:

  • center Vec3

    center of the bounding box

  • half_size Vec3

    vector from the center to positive corner

simplify

() Mesh

Defined in ../src/mesh.js:1663

returns a low poly version of the mesh that takes much less memory (but breaks tiling of uvs and smoothing groups)

Returns:

Mesh:

simplified mesh

toObject

()

Defined in ../src/mesh.js:727

Creates an object with the info of the mesh (useful to transfer to workers)

updateBoundingBox

()

Defined in ../src/mesh.js:1513

Update bounding information of this mesh

updateVertexBuffer

(
  • name
  • attribute
  • spacing
  • data
  • stream_type
)

Defined in ../src/mesh.js:500

Updates a vertex buffer

Parameters:

  • name String

    the name of the buffer

  • attribute String

    the name of the attribute in the shader

  • spacing Number

    number of numbers per component (3 per vertex, 2 per uvs...), default 3

  • data

    the array with all the data

  • stream_type Enum

    default gl.STATIC_DRAW (other: gl.DYNAMIC_DRAW, gl.STREAM_DRAW

upload

(
  • buffer_type
)

Defined in ../src/mesh.js:620

Uploads data inside buffers to VRAM.

Parameters:

  • buffer_type Number

    gl.STATIC_DRAW, gl.DYNAMIC_DRAW, gl.STREAM_DRAW