Class Obj

Class representing an object. This provides basic transformations for sub-objects and shouldn't be instanciated directly.

Hierarchy (view full)

Constructors

Properties

children: Obj[]

The children of this object

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.

parent?: null | Obj

The parent of this object.

position: Vec3

Object position

quaternion: Quat

Object rotation, expressed as a quaternion

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.

Methods

  • 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

  • Decomposes the object matrix into the various components necessary to populate this object.

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

  • Updates the object matrix based on the rotation, translation and scale , then runs an update.

    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