API Docs for:
Show:

LS.Components.Transform Class

Module: LS

Constructor

LS.Components.Transform

(
  • object
)

Parameters:

  • object Object

    to configure from

Methods

applyTransform

()

Apply a transform to this transform

applyTransformMatrix

(
  • matrix
  • center
  • is_global
)

Applies the transformation using a matrix

Parameters:

  • matrix Mat4

    with the transform

  • center Vec3

    different pivot [optional] if omited 0,0,0 will be used

  • is_global Bool

    (optional) tells if the transformation should be applied in global space or local space

configure

(
  • object
)

Configure from a serialized object

Parameters:

  • object Object

    with the serialized info

copyFrom

(
  • src
)

Copy the transform from another Transform

Parameters:

  • src Transform

fromMatrix

(
  • matrix
  • is_global
)

Configure the transform from a local Matrix (do not tested carefully)

Parameters:

  • matrix Mat4

    the matrix in array format

  • is_global Bool

    tells if the matrix is in global space [optional]

getAncestors

() Array

Returns an array with all the ancestors

Returns:

Array:

getFront

() Vec3

returns the [0,0,-1] vector in global space

Returns:

Vec3:

getGlobalMatrix

(
  • out
  • fast
)
Mat4

Returns a copy of the global matrix of this transform (it updates the matrix automatically)

Parameters:

  • out Mat4

    optional

  • fast Boolean

    this flags skips recomputing parents matrices

Returns:

Mat4:

the matrix in array format

getGlobalMatrix

() Mat4

Returns a copy of the global matrix of this transform (it updates the matrix automatically)

Returns:

Mat4:

the matrix in array format

getGlobalPosition

(
  • out
)
Vec3

Returns a copy of the global position

Parameters:

  • out Vec3

    [optional] where to store the result, otherwise one vec3 is created and returned

Returns:

Vec3:

the position

getGlobalRotation

() Quat

Returns a quaternion with all parents rotations

Returns:

Quat:

Quaternion

getGlobalRotationMatrix

() Mat4

Returns the global rotation in quaternion array (a copy)

Returns:

Mat4:

the rotation

getGlobalRotationMatrix

() Mat4

Returns a Matrix with all parents rotations

Returns:

Mat4:

Matrix rotation

getGlobalScale

(
  • out
)
Vec3

Returns a copy of the global scale (this is not correct, there is no global_scale factor, because due to rotations the axis could change)

Parameters:

  • out Vec3

    [optional] where to store the result, otherwise one vec3 is created and returned

Returns:

Vec3:

the scale

getGlobalTranslationMatrix

() Mat4

Returns the local matrix of this transform without the rotation or scale

Returns:

Mat4:

the matrix in array format

getGlobalTranslationRotationMatrix

() Mat4

Returns the local matrix of this transform without the scale

Returns:

Mat4:

the matrix in array format

getLocalMatrixRef

() Mat4

Returns the original local matrix of this transform (it updates the matrix automatically)

Returns:

Mat4:

the matrix in array format

getMatrix

(
  • out
)
Mat4

Returns a copy of the local matrix of this transform (it updates the matrix automatically)

Parameters:

  • out Mat4

    [optional] where to store the result, otherwise one mat4 is created and returned

Returns:

Mat4:

the matrix

getNormalMatrix

() Mat4

Returns the matrix for the normals in the shader

Returns:

Mat4:

the matrix in array format

getPosition

(
  • out
)
Vec3

Returns a copy of the local position

Parameters:

  • out Vec3

    [optional] where to store the result, otherwise one vec3 is created and returned

Returns:

Vec3:

the position

getRight

() Vec3

returns the [1,0,0] vector in global space

Returns:

Vec3:

getRotation

(
  • out
)
Quat

Returns the global rotation in quaternion array (a copy)

Parameters:

  • out Quat

    [optional] where to store the result, otherwise one quat is created and returned

Returns:

Quat:

the rotation

getRotation

(
  • out
)
Quat

Returns the rotation in quaternion array (a copy)

Parameters:

  • out Quat

    [optional] where to store the result, otherwise one quat is created and returned

Returns:

Quat:

the rotation

getScale

(
  • out
)
Vec3

Returns the scale (its a copy)

Parameters:

  • out Vec3

    [optional] where to store the result, otherwise one vec3 is created and returned

Returns:

Vec3:

the scale

getTop

() Vec3

returns the [0,1,0] vector in global space

Returns:

Vec3:

globalToLocal

(
  • point
  • destination
)

convert from global coordinates to local coordinates

Parameters:

  • point Vec3
  • destination Vec3

    (optional)

identity

()

Reset this transform

interpolate

(
  • a
  • b
  • factor
  • the
)

This method is static (call it from Transform.interpolate) interpolate the transform between two transforms and stores the result in another Transform

Parameters:

  • a Transform
  • b Transform
  • factor Number

    from 0 to 1

  • the Transform

    destination

localToGlobal

(
  • point
  • destination
)

convert from local coordinates to global coordinates If no destination is specified a new vector is created

Parameters:

  • point Vec3
  • destination Vec3

    (optional)

localVectorToGlobal

(
  • vector
  • destination
)

Applies the transformation to a vector (rotate but not translate)

Parameters:

  • vector Vec3
  • destination Vec3

    (optional)

lookAt

(
  • position
  • target
  • up
  • in_world
)

Orients the transform to look from one position to another

Parameters:

  • position Vec3
  • target Vec3
  • up Vec3
  • in_world Boolean

    tells if the values are in world coordinates (otherwise asume its in local coordinates)

orbit

(
  • angle_in_deg
  • axis
  • center
)

Orbits around a point

Parameters:

  • angle_in_deg Number
  • axis Vec3
  • center Vec3

    in local coordinates

resetPosition

()

Sets the position to 0,0,0

resetRotation

()

Sets the rotation to identity

resetScale

()

Sets the scale to 1,1,1

rotate

(
  • angle_in_deg
  • axis
)

rotate object in local space (axis is in local space)

Parameters:

  • angle_in_deg Number
  • axis Vec3

rotateGlobal

(
  • angle_in_deg
  • axis
)

rotate object in global space (axis is in global space)

Parameters:

  • angle_in_deg Number
  • axis Vec3

rotateQuat

(
  • quaternion
)

rotate object in local space using a quat

Parameters:

  • quaternion Quat

rotateQuatGlobal

(
  • quaternion
)

rotate object in global space using a quat

Parameters:

  • quaternion Quat

rotateX

(
  • angle_in_rad
)

rotate object in local space in local X axis

Parameters:

  • angle_in_rad Number

rotateY

(
  • angle_in_rad
)

rotate object in local space in local Y axis

Parameters:

  • angle_in_rad Number

rotateZ

(
  • angle_in_rad
)

rotate object in local space in local Z axis

Parameters:

  • angle_in_rad Number

scale

(
  • x
  • y
  • z
)

scale the object

Parameters:

  • x Number
  • y Number
  • z Number

serialize

() Object

Serialize the object

Returns:

Object:

object with the serialized info

setPosition

(
  • x
  • y
  • z
)

sets the position

Parameters:

  • x Number
  • y Number
  • z Number

setRotation

(
  • rotation
)

sets the rotation from a quaternion or from an angle(rad) and axis

Parameters:

  • rotation Quat

    in quaterion format or angle

setRotationFromEuler

(
  • src,
)

Configure the transform rotation from a vec3 Euler angles (heading,attitude,bank)

Parameters:

  • src, Mat4

    the matrix in array format

setScale

(
  • x
  • y
  • z
)

sets the scale

Parameters:

  • x Number
  • y Number
  • z Number

transformPoint

(
  • point
  • destination
)

Multiplies a point by the local matrix (not global) If no destination is specified a new vector is created

Parameters:

  • point Vec3
  • destination Vec3

    (optional)

transformPointGlobal

(
  • point
  • destination
)

same as localToGlobal

Parameters:

  • point Vec3
  • destination Vec3

    (optional)

transformVector

(
  • vector
  • destination
)

Applies the transformation to a vector (rotate but not translate)

Parameters:

  • vector Vec3
  • destination Vec3

    (optional)

translate

(
  • x
  • y
  • z
)

translates object in local coordinates (using the rotation and the scale)

Parameters:

  • x Number
  • y Number
  • z Number

translateGlobal

(
  • x
  • y
  • z
)

translates object in local coordinates (adds to the position)

Parameters:

  • x Number
  • y Number
  • z Number

updateGlobalMatrix

(
  • fast
)

updates the global matrix using the parents transformation

Parameters:

  • fast Bool

    it doesnt recompute parent matrices, just uses the stored one, is faster but could create errors if the parent doesnt have its global matrix update

updateMatrix

()

update the local Matrix to match the position,scale and rotation

Properties

matrix

Mat4

The local matrix transform relative to its parent in mat4 format

matrix

Mat4

The local matrix transform relative to its parent in mat4 format

matrix

Mat4

The local matrix transform relative to its parent in mat4 format

mustUpdate

Boolean

Force object to update matrices

position

Vec3

The position relative to its parent in vec3 format

position

Vec3

The position relative to its parent in vec3 format

rotation

Quat

The orientation relative to its parent in quaternion format

scaling

Vec3

The scaling relative to its parent in vec3 format (default is [1,1,1])

Events

changed

Fired when the node has changed its transform