Class Mesh

Class representing a mesh. A mesh is a binding point between geometry and a program.

Hierarchy (view full)

Constructors

Properties

afterRenderCallbacks: ((props: BaseMeshOptions) => void)[]

Any callbacks to run after render

beforeRenderCallbacks: ((props: BaseMeshOptions) => void)[]

Any callbacks to run before render

children: Obj[]

The children of this object

frustumCulled: boolean

Whether to apply frustum culling to this object

true
geometry: Geometry

The geometry to render.

The WTCGL rendering context.

id: number

The unique ID of the Geometry.

matrix: Mat4

A matrix representing the translation, rotation and scale of this object.

matrixAutoUpdate: boolean

Whether to automatically calculate the object matrix each time updateWorldMatrix is called. Convenient, but potentially costly.

mode: number

The mode to use to draw this mesh. Can be one of:

  • gl.POINTS: Draws a single dot for each vertex
  • gl.LINE_STRIP: Draws a straight line between the vertices
  • gl.LINE_LOOP: As above, but loops back.
  • gl.LINES: Draws many lines between each vertex pair
  • gl.TRIANGLE_STRIP: Draws a series of triangles between each vertice trio
  • gl.TRIANGLE_FAN: Draws a series of triangles between each vertice trio, treating the first vertex as the origin of each triangle
  • gl.TRIANGLES: Draws a triangle for a group of three vertices
modelViewMatrix: Mat4

The world matrix projected by the camera's view matrix

normalMatrix: Mat3

The model-view normal matrix

parent?: null | Obj

The parent of this object.

position: Vec3

Object position

program: Program

The program that is rendering this object

quaternion: Quat

Object rotation, expressed as a quaternion

renderOrder: number = 0

Apply a specific render order, overriding calculated z-depth

0
rotation: Vec3

Object rotation, expressed as a 3D Euler rotation

scale: Vec3

Object scale

up: Vec3

The up unit vector

visible: boolean

Whether this objec is visible or not. This will stop the renderer from trying to render this object

worldMatrix: Mat4

The world matrix represents the function of all ancestor matrices and the matrix of this object

worldMatrixNeedsUpdate: boolean = false

A boolean indicating whether the world matrix requires updating.

zDepth: number = 0

The z-depth of the object, calculated at render time.

0

Methods

  • Add an after render callback.

    Parameters

    • f: MeshCallback

      The function to call before render. Expected shape ({ mesh: this, camera })=>void.

    Returns Mesh

  • Add a before render callback.

    Parameters

    • f: MeshCallback

      The function to call before render. Expected shape ({ mesh: this, camera })=>void.

    Returns Mesh

  • Adds a child object to this and indicates whether to notify the child

    Parameters

    • child: Obj

      The object to add as a child of this one

    • notifyChild: boolean = true

      Whether to set the parent of the indicated child to this

    Returns void

  • Drw the mesh. If a camera is supplied to the draw call, its various matrices will be added to the program uniforms

    Parameters

    • camera: {
          camera: Camera;
      }

      The camera to use to supply transformation matrices

    Returns void

  • Makes the object look at a particular target, useful for cameras

    Parameters

    • target: Vec3

      The point to look at

    • invert: boolean = false

      Look away from, if true

    Returns void

  • Remove an after render callback.

    Parameters

    • f: MeshCallback

      The function to call before render. Expected shape ({ mesh: this, camera })=>void.

    Returns void

  • Remove a before render callback.

    Parameters

    • f: MeshCallback

      The function to call before render. Expected shape ({ mesh: this, camera })=>void.

    Returns void

  • Remove a child from this object.

    Parameters

    • child: Obj

      The child to remove

    • notifyChild: boolean = true

      Whether to notify the child of the removal

    Returns void

  • Sets the parent of this object and indicates whether to set a child relationship on the parent.

    Parameters

    • parent: null | Obj

      The parent object to use

    • notifyParent: boolean = true

      Whether to set the full parent-child relationsjip

    Returns void

  • Traverses the object tree and runs a given function against the object. If true is returned, the traversal is stopped. This is useful for testing things like visibility etc.

    Parameters

    • callback: ((node: Obj) => null | boolean)

      The function to call, it should return true or null based on some condition

        • (node): null | boolean
        • Parameters

          Returns null | boolean

    Returns void

  • Update the fill world matrix of this object basically used for recursively looping down the hierarchy when a change in the RTS matrix is changed on this.

    Parameters

    • Optionalforce: boolean

      Even is this is not set to world matrix update, force it. Used when looping down past the first iteration.

    Returns void

  • UpdateRotation should be called whenever a change to the quaternion variable is made. This will update the rotation in response to the change in the quaternion. For example:

    const Box = new Mesh(gl, { geometry: BoxGeo, program });
    Box.quaternion = Quat.fromAxisAngle(new Vec3(1,0,0), Math.PI*-.25);
    Box.updateQuaternion();
    console.log(Box.rotation) // {_x: 0.7853981633974483, _y: 0, _z: 0}

    Returns void

  • UpdateRotation should be called whenever a change to the rotation variable is made. This will update the quaternion in response to the change in the rotation. For example:

    const Box = new Mesh(gl, { geometry: BoxGeo, program });
    Box.rotation.x = Math.PI*.25;
    Box.updateRotation();
    console.log(Box.quaternion) // {_x: 0.3826834323650898, _y: 0, _z: 0, _w: 0.9238795325112867}

    Returns void