Transform

Transform

This is main class to represent an object with given mesh that can be placed into a "world".

Constructor

new Transform(mesh, program)

Source:
Parameters:
Name Type Description
mesh Mesh mesh to be assigned to this transform.
program ShaderProgram shader program to be used while drawing the mesh.

Members

(readonly) children :Array.<Transform>

Source:
children Transforms of this. Use Transform#addChild instead of changing this directly.
Type:

(readonly) id :Number

Source:
a random number assigned at creation.
Type:
  • Number

localPos :Vec3

Source:
Translation in localSpace. set Transform#matrixNeedsUpdate true after modifying manually!
Type:

localRot :Quat

Source:
Rotation in localSpace. set Transform#matrixNeedsUpdate true after modifying manually!
Type:

localScale :Vec3

Source:
Scale in localSpace. set Transform#matrixNeedsUpdate true after modifying manually!
Type:

localToWorld :Mat4

Source:
transformation from localSpace to world space. This is used as model matrix in glsl. Calculated from Transform#localPos,Transform#localRot,Transform#localScale and Transform#parent matrix. if Transform#matrixNeedsUpdate is true, it will be recalculated at next Transform#update call.
Type:

matrixNeedsUpdate :Boolean

Source:
if true, Transform#localToWorld is recalculated at next Transform#update call. This avoids recalculation of matrices after every additional transformation.
Type:
  • Boolean

mesh :Mesh

Source:
mesh linked to this transformation.
Type:

(readonly) parent :Transform

Source:
parent transformation of this. It will affect the Transform#localToWorld matrix. use Transform#setparent instead of changing this directly.
Type:

program :ShaderProgram

Source:
shader program which is used when drawing Transform#mesh
Type:

uniforms :Object.<String, Uniform>

Source:
optional uniforms for this transform. they will override the uniforms in Transform#program
Type:

visible :Boolean

Source:
controls wether this object is rendered or not.
Type:
  • Boolean

worldToLocal :Mat4

Source:
transformation from world space to local space. This is just Transform#localToWorld inverted.
Type:

Methods

addChild(child)

Source:
pushes the transform to this.children. Does nothing when given transform is already a child.
Parameters:
Name Type Description
child Transform new child.

draw(gl, viewMatrix)

Source:
main method to draw this.mesh. binds the shaderprogram and assigns uniforms to it.
Parameters:
Name Type Description
gl WebglRenderingContext gl context
viewMatrix Camera camera that is used to get view and projection

onBeforeDraw(gl)

Source:
an overridable method to be called before drawing.
Parameters:
Name Type Description
gl WebglRenderingContext gl context

setParent(parent)

Source:
sets the parent for this transformation object. This affects the localToWorld and worldToLocal matrices.
Parameters:
Name Type Description
parent Transform new parent.

update()

Source:
this should be called from your mainloop implementation before rendering a frame.

updateMatrix()

Source:
updates localToWorld and worldToLocal matrices. it Is called from Transform#update if Transform#matrixNeedsUpdate is true. Also recursively updates the bounds of this and the parent chain.