Module: util

Containts various utility methods for math, searching etc.
Source:

Summary

Members

Methods

Type Definitions

Detailed Description

Members

AXIS_MX

Negative x-axis vector.
Type:
Source:

AXIS_MY

Negative y-axis vector.
Type:
Source:

AXIS_MZ

Negative z-axis vector.
Type:
Source:

AXIS_X

X-axis vector.
Type:
Source:

AXIS_Y

Y-axis vector.
Type:
Source:

AXIS_Z

Z-axis vector.
Type:
Source:

gen_tbn_quats

Generate flat array of TBN quaternions
Source:

is_ie11

Check if Internet Explorer 11 is using.
Source:

XYX

Rotation sequence: XYX.
Type:
  • RotationSequence
Source:

XYZ

Rotation sequence: XYZ.
Type:
  • RotationSequence
Source:

XZX

Rotation sequence: XZX.
Type:
  • RotationSequence
Source:

XZY

Rotation sequence: XZY.
Type:
  • RotationSequence
Source:

YXY

Rotation sequence: YXY.
Type:
  • RotationSequence
Source:

YXZ

Rotation sequence: YXZ.
Type:
  • RotationSequence
Source:

YZX

Rotation sequence: YZX.
Type:
  • RotationSequence
Source:

YZY

Rotation sequence: YZY.
Type:
  • RotationSequence
Source:

ZXY

Rotation sequence: ZXY.
Type:
  • RotationSequence
Source:

ZXZ

Rotation sequence: ZXZ.
Type:
  • RotationSequence
Source:

ZYX

Rotation sequence: ZYX.
Type:
  • RotationSequence
Source:

ZYZ

Rotation sequence: ZYZ.
Type:
  • RotationSequence
Source:

Methods

angle_wrap_0_2pi(angle) → {Number}

Convert radian angle into range [0, 2PI)
Parameters:
Name Type Description
angle Number Angle in radians
Returns:
Converted angle
Type
Number
Source:

angle_wrap_periodic(angle, from, to) → {Number}

Convert radian angle into custom range [from, to)
Parameters:
Name Type Description
angle Number Angle in radians
from Number Value from in radians
to Number Value to in radians
Returns:
Converted angle
Type
Number
Source:

assert(Boolean)

Abort the program if assertion is false.
Parameters:
Name Type Description
Boolean Boolean expression result
Source:

cam_quat_to_mesh_quat(cam_quat, destopt) → {Quat}

Transform a camera quaternion to a mesh quaternion.
Parameters:
Name Type Attributes Description
cam_quat Quat Camera quaternion.
dest Quat <optional>
Destination quaternion.
Returns:
Destination quaternion.
Type
Quat
Source:

clamp(value, min, max) → {Number}

Clamp the number.
Parameters:
Name Type Description
value Number Input value
min Number Lower bound
max Number Upper bound
Returns:
Clamped value
Type
Number
Source:

correct_cam_quat_up(quat, up_only)

Correct the camera quaternion rotation.
Parameters:
Name Type Description
quat Quat Quaternion to correct
up_only Boolean Disable upside-down camera view
Source:

deg_to_rad(degrees) → {Number}

Convert degrees to radians.
Parameters:
Name Type Description
degrees Number Angle in degrees.
Returns:
Angle in radians.
Type
Number
Source:

dir_to_quat(dir, ident, destopt) → {Quat}

Convert directional vector to quaternion.
Parameters:
Name Type Attributes Description
dir Vec3 Directional vector.
ident Vec3 Identity vector
dest Quat <optional>
Destination quaternion
Returns:
Destination quaternion
Type
Quat
Source:

euler_to_quat(euler, quat) → {Quat}

Convert euler angles in the ZYX intrinsic system to quaternion.
Parameters:
Name Type Description
euler Euler Euler angles. The angles order: an angle of the rotation around the x axis, an angle of the rotation around the y axis, an angle of the rotation around the z axis.
quat Quat Destination quaternion vector.
Returns:
Quaternion vector.
Type
Quat
Source:

f32(param) → {Float32Array}

Create a new Float32Array.
Parameters:
Name Type Description
param Number | Array | TypedArray Constructor param
Returns:
New Float32Array.
Type
Float32Array
Source:

ground_project_quat(quat, dest) → {Quat}

Project camera quaternion rotation on a horizontal plane.
Parameters:
Name Type Description
quat Quat Source quaternion.
dest Quat Destination quaternion.
Returns:
Destination quaternion.
Type
Quat
Source:

is_armature(obj) → {Boolean}

Check if object is of type ARMATURE
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Check result
Type
Boolean
Deprecated:
Source:

is_mesh(obj) → {Boolean}

Check if object is of type MESH
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Check result
Type
Boolean
Deprecated:
Source:

is_vector(o, dimensionopt) → {Boolean}

Check if object is a vector.
Parameters:
Name Type Attributes Default Description
o Object Object
dimension Number <optional>
0 Dimension, allow any if not specified
Returns:
Check result
Type
Boolean
Source:

keyfind(key, value, array) → {Array.<Object>}

Search for object in array.
Parameters:
Name Type Description
key String Key
value * Value
array Array.<Object> Array of objects.
Returns:
Array of found objects.
Type
Array.<Object>
Source:

keysearch(key, value, array) → (nullable) {Object}

Search for object in array.
Parameters:
Name Type Description
key String Key.
value * Value.
array Array Array of objects.
Returns:
First found object or null.
Type
Object
Source:

lerp(t, from, to) → {Number}

Linear interpolation function.
Parameters:
Name Type Description
t Number Input value.
from Number Start interpolation value.
to Number End interpolation value.
Returns:
Result value.
Type
Number
Source:

line_plane_intersect(pn, p_dist, lp, l_dir, dest) → (nullable) {Vec3}

Calculate intersection point of a line and a plane.
Parameters:
Name Type Description
pn Vec3 Plane normal.
p_dist Number Plane signed distance from the origin.
lp Vec3 Point belonging to the line.
l_dir Vec3 Line direction.
dest Vec3 Destination vector.
Returns:
Intersection point or null if the line is parallel to the plane.
Type
Vec3
Deprecated:
Source:
See:
  • Lengyel E. - Mathematics for 3D Game Programming and Computer Graphics, Third Edition. Chapter 5.2.1 Intersection of a Line and a Plane

matrix_to_quat(matrix) → {Quat}

Extract rotation from the 4x4 matrix to quaternion vector.
Parameters:
Name Type Description
matrix Mat4 4x4 matrix
Returns:
Quaternion
Type
Quat
Source:

ordered_angles_to_quat(angles, order, quat) → {Quat}

Convert Euler angles in the ordered intrinsic system to quaternion.
Parameters:
Name Type Description
angles Euler Ordered Euler angles. Euler angles have the same order as the intrinsic rotation sequence.
order RotationSequence Intrinsic rotation sequence.
quat Quat Destination quaternion vector.
Returns:
Quaternion vector.
Type
Quat
Source:

quat_project(quat, quat_ident_dir, plane, plane_ident_dir, destopt) → {Quat}

Perform quaternion projection.
Parameters:
Name Type Attributes Default Description
quat Quat Quaternion to project.
quat_ident_dir Vec3 Direction corresponding to the identity quaternion.
plane Vec3 Plane direction (normal).
plane_ident_dir Vec3 Direction corresponding to the identity quaternion in a plane.
dest Quat <optional>
quat.create() Destination quaternion.
Returns:
Destination quaternion.
Type
Quat
Source:

quat_to_dir(quat, ident, destopt) → {Vec3}

Convert quaternion rotation to a directional vector.
Parameters:
Name Type Attributes Description
quat Quat Rotation quaternion
ident Vec3 Identity vector
dest Vec3 <optional>
Destination vector
Returns:
Destination vector.
Type
Vec3
Source:

quat_to_euler(quat, euler) → {Euler}

Convert quaternion rotation to euler rotation.
Parameters:
Name Type Description
quat Quat Quaternion vector
euler Euler Destination euler vector
Returns:
Euler vector
Type
Euler
Source:

quat_to_ordered_angles(quat, order, euler) → {Euler}

Convert quaternion to Euler angles in the ordered intrinsic system.
Parameters:
Name Type Description
quat Quat Quaternion vector.
order RotationSequence Intrinsic rotation sequence.
euler Euler Destination Euler angles vector. Euler angles have the same order as the intrinsic rotation sequence.
Returns:
Euler angles vector.
Type
Euler
Source:

rad_to_deg(radians) → {Number}

Convert radians to degrees.
Parameters:
Name Type Description
radians Number Angle in radians.
Returns:
Angle in degrees.
Type
Number
Source:

sign(value) → {Number}

Get sign of the number.
Parameters:
Name Type Description
value Number Input value
Returns:
-1,0,1 for negative, zero or positive number accordingly
Type
Number
Source:

smooth(curr, last, delta, pariod) → {Number}

Perform exponential smoothing.
Parameters:
Name Type Description
curr Number Current value.
last Number Last smoothed value.
delta Number Time delta.
pariod Number Mean lifetime for avaraging.
Returns:
Smoothed value
Type
Number
Source:

smooth_step(t, min, max) → {Number}

Smooth step function.
Parameters:
Name Type Description
t Number Input value.
min Number Min clamping value.
max Number Max clamping value.
Returns:
Result value.
Type
Number
Source:

smooth_v(curr, last, delta, pariod, destopt) → {Float32Array}

Perform exponential smoothing (vector form).
Parameters:
Name Type Attributes Description
curr Float32Array Current value.
last Float32Array Last smoothed value.
delta Float32Array Time delta.
pariod Float32Array Mean lifetime for avaraging.
dest Float32Array <optional>
Smoothed value
Returns:
Smoothed value
Type
Float32Array
Source:

Type Definitions

RotationSequence

Rotation sequence enum.
Type:
  • Number
Source: