API Docs for:
Show:

GL.Mesh Class

Methods

addBuffer

(
  • name
  • buffer
)

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

Adds buffer to mesh

Parameters:

  • name String
  • buffer Buffer

addBuffers

(
  • vertexBuffers
  • indexBuffers
  • stream_type
)

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

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:639

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:615

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

computeIndices

()

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

Compute indices for a mesh where vertices are shared

computeNormals

(
  • stream_type
)

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

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:1082

Creates a new stream with the tangents

computeTextureCoordinates

()

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

Creates texture coordinates using a triplanar aproximation

computeWireframe

()

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

Creates a new index stream with wireframe

createIndexBuffer

(
  • name
  • data
  • stream_type
)

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

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:403

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:1715

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:937

Breaks the indices

flipNormals

(
  • stream_type
)

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

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:1366

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

generateMetadata

()

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

Computes some data about the mesh

getBoundingBox

() BBox

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

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

Returns:

BBox:

bounding box

getBuffer

(
  • name
)
Buffer

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

Returns a vertex buffer

Parameters:

  • name String

    of vertex buffer

Returns:

Buffer:

the buffer

getIndexBuffer

(
  • name
)
Buffer

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

Returns a index buffer

Parameters:

  • name String

    of index buffer

Returns:

Buffer:

the buffer

getMemory

() Number

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

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:1731

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:465

Returns a vertex buffer

Parameters:

  • name String

    of vertex buffer

Returns:

Buffer:

the buffer

getVertexNumber

(
  • vertices
)

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

Computes bounding information

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.computeBounding

(
  • vertices
)

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

Computes bounding information

Parameters:

  • vertices Typed Array

    array containing all the vertices

Mesh.cube

(
  • options
)

Returns a cube mesh

Parameters:

  • options Object

    valid options: size

Mesh.cube

(
  • options
)

Returns a cube mesh of a given size

Parameters:

  • options Object

    valid options: size, sizex, sizey, sizez

Mesh.cylinder

(
  • options
)

Returns a cube mesh

Parameters:

  • options Object

    valid options: radius, height, subdivisions

Mesh.fromOBJ

(
  • meshes
)

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

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:1495

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:1512

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:1698

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:527

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:450

Removes a vertex buffer from the mesh

Parameters:

  • name String

    "vertices","normals"...

  • free Boolean

    if you want to remove the data from the GPU

setBounding

(
  • center
  • half_size
)

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

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:1443

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:650

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

updateBounding

()

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

Update bounding information of this mesh

upload

(
  • buffer_type
)

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

Uploads data inside buffers to VRAM.

Parameters:

  • buffer_type Number

    gl.STATIC_DRAW, gl.DYNAMIC_DRAW, gl.STREAM_DRAW