Module: transform

Object transformations API. With some exceptions specified below, make sure that the objects are dynamic.

Summary

Methods

Detailed Description

Methods

distance(obj1, obj2) → {number}

Get distance between the two objects.
Parameters:
Name Type Description
obj1 Object3D The first object.
obj2 Object3D The second object.
Returns:
Distance
Type
number
Source:

empty_reset_transform(obj)

Reset EMPTY's transform to allow child objects behave in the absolute (world) space.
Parameters:
Name Type Description
obj Object3D Object 3D
Source:

get_matrix(obj, destopt) → {Mat4}

Return the object's transformation matrix. It's better to use TSR form.
Parameters:
Name Type Attributes Description
obj Object3D Object 3D
dest Mat4 <optional>
Destination matrix.
Returns:
Destination matrix.
Type
Mat4
Source:

get_matrix_rel(obj, destopt) → {Mat4}

Return the object's transformation matrix (in the coordinate space of its parent). It's better to use TSR form.
Parameters:
Name Type Attributes Description
obj Object3D Object 3D
dest Mat4 <optional>
Destination matrix.
Returns:
Destination matrix.
Type
Mat4
Source:

get_object_bounding_box(obj) → {BoundingBox}

Get object bounding box.
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Bounding box
Type
BoundingBox
Source:

get_object_center(obj, calc_bs_center, destopt) → {Vec3}

Get the object center in the world space. Works for dynamic and static objects.
Parameters:
Name Type Attributes Description
obj Object3D Object 3D
calc_bs_center boolean Use the object's bounding sphere to calculate center, otherwise use the bounding box.
dest Vec3 <optional>
Destination vector
Returns:
Destination vector
Type
Vec3
Source:

get_object_size(obj) → {number}

Get object size (maximum radius, calculated from bounding box).
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Object size
Type
number
Source:

get_rotation(obj, opt_destopt) → {Quat}

Get the object's rotation quaternion.
Parameters:
Name Type Attributes Description
obj Object3D Object 3D
opt_dest Quat <optional>
Destination vector
Returns:
Destination vector
Type
Quat
Source:
Example
var m_scenes = require("scenes");
var m_trans = require("transform");
var m_quat  = require("quat");
// precache quaternion
var _quat_tmp = m_quat.create();
// ...
var cube = m_scenes.get_object_by_name("Cube");
var rot_quat = m_trans.get_rotation(cube, _quat_tmp);

get_rotation_euler(obj, destopt) → {Euler}

Get Euler rotation of object in the ZYX intrinsic system (in the coordinate space of its parent). Using euler angles is discouraged, use quaternion instead.
Parameters:
Name Type Attributes Default Description
obj Object3D Object 3D
dest Euler <optional>
new Float32Array(3) Destination vector
Returns:
Vector with Euler angles
Type
Euler
Source:

get_rotation_euler(obj, destopt) → {Euler}

Get Euler rotation of object in the ZYX intrinsic system. Using euler angles is discouraged, use quaternion instead.
Parameters:
Name Type Attributes Default Description
obj Object3D Object 3D
dest Euler <optional>
new Float32Array(3) Destination vector
Returns:
Vector with Euler angles
Type
Euler
Source:

get_rotation_rel(obj, opt_destopt) → {Quat}

Get the object's rotation quaternion (in the coordinate space of its parent).
Parameters:
Name Type Attributes Description
obj Object3D Object 3D
opt_dest Quat <optional>
Destination vector
Returns:
Destination vector
Type
Quat
Source:

get_scale(obj) → {number}

Get the object scale.
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
scale
Type
number
Source:

get_scale_rel(obj) → {number}

Get the object scale (in the coordinate space of its parent).
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
scale
Type
number
Source:

get_translation(obj, destopt) → {Vec3}

Get the object's translation vector.
Parameters:
Name Type Attributes Description
obj Object3D Object 3D
dest Vec3 <optional>
Destination vector
Returns:
Destination vector
Type
Vec3
Source:
Example
var m_scenes = require("scenes");
var m_trans = require("transform");
var m_vec3 = require("vec3");
// precache 3D vector
var _vec3_tmp = m_vec3.create();
// ...
var cube = m_scenes.get_object_by_name("Cube");
var translation = m_trans.get_translation(cube, _vec3_tmp);

get_translation_rel(obj, destopt) → {Vec3}

Get the object's translation vector (in the coordinate space of its parent).
Parameters:
Name Type Attributes Description
obj Object3D Object 3D
dest Vec3 <optional>
Destination vector
Returns:
Destination vector
Type
Vec3
Source:

get_tsr(obj, destopt) → {TSR}

Return an object's transformation in TSR form.
Parameters:
Name Type Attributes Description
obj Object3D Object 3D
dest TSR <optional>
Destination vector.
Returns:
Destination vector.
Type
TSR
Source:

get_tsr_rel(obj, destopt) → {TSR}

Return the object transformation in TSR form. (in the coordinate space of its parent).
Parameters:
Name Type Attributes Description
obj Object3D Object 3D
dest TSR <optional>
Destination vector.
Returns:
Destination vector.
Type
TSR
Source:

move_local(obj, dx, dy, dz)

Perform incremental object translation in the local space.
Parameters:
Name Type Description
obj Object3D Object 3D
dx number Translation offset along X axis
dy number Translation offset along Y axis
dz number Translation offset along Z axis
Source:

rotate_x_local(obj, angle)

Perform incremental rotation around X axis in the local space.
Parameters:
Name Type Description
obj Object3D Object 3D
angle number Angle in radians
Source:

rotate_y_local(obj, angle)

Perform incremental rotation around Y axis in the local space.
Parameters:
Name Type Description
obj Object3D Object 3D
angle number Angle in radians
Source:

rotate_z_local(obj, angle)

Perform incremental rotation around Z axis in the local space.
Parameters:
Name Type Description
obj Object3D Object 3D
angle number Angle in radians
Source:

set_matrix(obj, mat)

Set the object's transformation matrix. It's better to use TSR form.
Parameters:
Name Type Description
obj Object3D Object 3D
mat Mat4 Matrix
Source:

set_matrix_rel(obj, mat)

Set the object's transformation matrix (in the coordinate space of its parent). It's better to use TSR form.
Parameters:
Name Type Description
obj Object3D Object 3D
mat Mat4 Matrix
Source:

set_rotation(obj, x, y, z, w)

Set the object's rotation quaternion.
Parameters:
Name Type Description
obj Object3D Object 3D
x number X part of quaternion
y number Y part of quaternion
z number Z part of quaternion
w number W part of quaternion
Source:

set_rotation_euler(obj, x, y, z)

Set euler rotation in the ZYX intrinsic system. Using euler angles is discouraged, use quaternion instead.
Parameters:
Name Type Description
obj Object3D Object 3D
x number Angle X in radians
y number Angle Y in radians
z number Angle Z in radians
Source:

set_rotation_euler_rel(obj, x, y, z)

Set euler rotation in the ZYX intrinsic system (in the coordinate space of its parent). Using euler angles is discouraged, use quaternion instead.
Parameters:
Name Type Description
obj Object3D Object 3D
x number Angle X in radians
y number Angle Y in radians
z number Angle Z in radians
Source:

set_rotation_euler_rel_v(obj, euler)

Set euler rotation in vector form relatively to its parent (in the coordinate space of its parent). Using euler angles is discouraged, use quaternion instead.
Parameters:
Name Type Description
obj Object3D Object 3D
euler Euler Vector with euler angles
Source:

set_rotation_euler_v(obj, euler)

Set euler rotation in vector form. Using euler angles is discouraged, use quaternion instead.
Parameters:
Name Type Description
obj Object3D Object 3D
euler Euler Vector with euler angles
Source:

set_rotation_rel(obj, x, y, z, w)

Set the object's rotation quaternion (in the coordinate space of its parent).
Parameters:
Name Type Description
obj Object3D Object 3D
x number X part of quaternion
y number Y part of quaternion
z number Z part of quaternion
w number W part of quaternion
Source:

set_rotation_rel_v(obj, quat)

Set the object's rotation in vector form (in the coordinate space of its parent).
Parameters:
Name Type Description
obj Object3D Object 3D
quat Quat Quaternion vector
Source:

set_rotation_rel_v(obj, quat) → {Quat}

Get the object's rotation in vector form (in the coordinate space of its parent).
Parameters:
Name Type Description
obj Object3D Object 3D
quat Quat Quaternion vector
Returns:
Destination vector
Type
Quat
Source:
Example
var m_scenes = require("scenes");
var m_trans = require("transform");
var m_quat  = require("quat");
// precache quaternion
var _quat_tmp = m_quat.create();
// ...
var cube = m_scenes.get_object_by_name("Cube");
var rot_quat = m_trans.get_rotation_rel_v(cube, _quat_tmp);

set_rotation_v(obj, quat)

Set the object's rotation in vector form.
Parameters:
Name Type Description
obj Object3D Object 3D
quat Quat Quaternion vector
Source:

set_scale(obj, scale)

Set the object scale.
Parameters:
Name Type Description
obj Object3D Object 3D
scale number Object scale
Source:

set_scale_rel(obj, scale)

Set the object's scale (in the coordinate space of its parent).
Parameters:
Name Type Description
obj Object3D Object 3D
scale number Object scale
Source:

set_translation(obj, x, y, z)

Set the object translation.
Parameters:
Name Type Description
obj Object3D Object 3D
x number X coord
y number Y coord
z number Z coord
Source:

set_translation_obj_rel(obj, x, y, z, obj_ref)

Set the object translation relatively to another object.
Parameters:
Name Type Description
obj Object3D Transformed object
x number X coord
y number Y coord
z number Z coord
obj_ref Object3D Reference object
Source:

set_translation_rel(obj, x, y, z)

Set the object translation (in the coordinate space of its parent).
Parameters:
Name Type Description
obj Object3D Object 3D
x number X coord
y number Y coord
z number Z coord
Source:

set_translation_rel_v(obj, trans)

Set the object translation in vector form (in the coordinate space of its parent).
Parameters:
Name Type Description
obj Object3D Object 3D
trans Vec3 Translation vector
Source:

set_translation_v(obj, trans)

Set the object translation (vector form).
Parameters:
Name Type Description
obj Object3D Object 3D
trans Vec3 Translation vector
Source:

set_tsr(obj, tsr)

Set the object's TSR vector.
Parameters:
Name Type Description
obj Object3D Object 3D
tsr TSR vector
Source:

set_tsr_rel(obj, tsr)

Set the object's TSR vector (in the coordinate space of its parent).
Parameters:
Name Type Description
obj Object3D Object 3D
tsr TSR vector
Source: