Object transformations API.
With some exceptions specified below, make sure that the objects are dynamic.
- Source:
Summary
Methods
- distance(obj1, obj2) → {number}
- empty_reset_transform(obj)
- get_matrix(obj, destopt) → {Mat4}
- get_matrix_rel(obj, destopt) → {Mat4}
- get_object_bounding_box(obj) → {BoundingBox}
- get_object_center(obj, calc_bs_center, destopt) → {Vec3}
- get_object_size(obj) → {number}
- get_rotation(obj, opt_destopt) → {Quat}
- get_rotation_euler(obj, destopt) → {Euler}
- get_rotation_euler(obj, destopt) → {Euler}
- get_rotation_rel(obj, opt_destopt) → {Quat}
- get_scale(obj) → {number}
- get_scale_rel(obj) → {number}
- get_translation(obj, destopt) → {Vec3}
- get_translation_rel(obj, destopt) → {Vec3}
- get_tsr(obj, destopt) → {TSR}
- get_tsr_rel(obj, destopt) → {TSR}
- move_local(obj, dx, dy, dz)
- rotate_x_local(obj, angle)
- rotate_y_local(obj, angle)
- rotate_z_local(obj, angle)
- set_matrix(obj, mat)
- set_matrix_rel(obj, mat)
- set_rotation(obj, x, y, z, w)
- set_rotation_euler(obj, x, y, z)
- set_rotation_euler_rel(obj, x, y, z)
- set_rotation_euler_rel_v(obj, euler)
- set_rotation_euler_v(obj, euler)
- set_rotation_rel(obj, x, y, z, w)
- set_rotation_rel_v(obj, quat)
- set_rotation_rel_v(obj, quat) → {Quat}
- set_rotation_v(obj, quat)
- set_scale(obj, scale)
- set_scale_rel(obj, scale)
- set_translation(obj, x, y, z)
- set_translation_obj_rel(obj, x, y, z, obj_ref)
- set_translation_rel(obj, x, y, z)
- set_translation_rel_v(obj, trans)
- set_translation_v(obj, trans)
- set_tsr(obj, tsr)
- set_tsr_rel(obj, tsr)
Detailed Description
Methods
distance(obj1, obj2) → {number}
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}
get_matrix_rel(obj, destopt) → {Mat4}
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_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_tsr(obj, destopt) → {TSR}
get_tsr_rel(obj, destopt) → {TSR}
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_matrix_rel(obj, mat)
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_rotation_euler_v(obj, euler)
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_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_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_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: