Module: util

Contains various utility methods for math, searching etc.

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:

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
Deprecated
  • Do not use it anymore
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, quatopt) → {Quat}

Convert euler angles in the ZYX intrinsic system to quaternion.
Parameters:
Name Type Attributes 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 <optional>
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:

gen_tbn_quats(normals, tangentsopt) → {Float32Array}

Generate flat array of TBN quaternions
Parameters:
Name Type Attributes Description
normals Float32Array Flat array of normals.
tangents Float32Array <optional>
Flat array of tangents.
Returns:
Flat array of quaternions.
Type
Float32Array
Deprecated
  • Do not use it anymore
Source:

ground_project_cam_quat(quat, destopt) → {Quat}

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

is_ie11() → {boolean}

Check if Internet Explorer 11 is using.
Returns:
Check result.
Type
boolean
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:

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, quatopt) → {Quat}

Convert Euler angles in the ordered intrinsic system to quaternion.
Parameters:
Name Type Attributes Description
angles Euler Ordered Euler angles. Euler angles have the same order as the intrinsic rotation sequence.
order RotationSequence Intrinsic rotation sequence.
quat Quat <optional>
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, euleropt) → {Euler}

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

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

Convert quaternion to Euler angles in the ordered intrinsic system.
Parameters:
Name Type Attributes Description
quat Quat Quaternion vector.
order RotationSequence Intrinsic rotation sequence.
angles Euler <optional>
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, period) → {number}

Perform exponential smoothing.
Parameters:
Name Type Description
curr number Current value.
last number Last smoothed value.
delta number Time delta.
period number Mean lifetime for averaging.
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, period, 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.
period Float32Array Mean lifetime for averaging.
dest Float32Array <optional>
Smoothed value
Returns:
Smoothed value
Type
Float32Array
Source:

trunc(value) → {number}

Returns the integer part of the given number.
Parameters:
Name Type Description
value number Original value.
Returns:
Truncated value.
Type
number
Source:

Type Definitions

RotationSequence

Rotation sequence enum.
Type:
  • number
Source: