Module: physics

Physics module. Provides API to uranium.js physics engine.

Summary

Members

Methods

Type Definitions

Detailed Description

Members

CM_CLIMB

The character's type of movement is "climb".
Type:
Source:

CM_FLY

The character's type of movement is "fly".
Type:
Source:

CM_RUN

The character's type of movement is "run".
Type:
Source:

CM_WALK

The character's type of movement is "walk".
Type:
Source:

Methods

append_collision_test(obj_src, collision_idnullable, callback, calc_pos_normopt)

Append a new async collision test to the given object.
Parameters:
Name Type Attributes Default Description
obj_src Object3D Object 3D
collision_id string <nullable>
Collision ID, pass "ANY" or null for any collision ID.
callback CollisionCallback Collision callback
calc_pos_norm boolean <optional>
false Pass collision point/normal/distance in callback
Source:

append_ray_test(obj_srcnullable, from, to, collision_idnullable, callback, autoremoveopt) → {number}

Append a new async ray test.
Parameters:
Name Type Attributes Default Description
obj_src Object3D <nullable>
Source object, pass a non-null value to perform ray casting in object space, e.g. from/to vectors specified in object space.
from Vec3 From vector
to Vec3 To vector
collision_id string <nullable>
Collision ID, pass "ANY" or null for any collision ID.
callback RayTestCallback Ray Test callback
autoremove boolean <optional>
false Automatically remove test after ray casting.
Returns:
Ray Test ID
Type
number
Source:

append_ray_test_ext(obj_srcnullable, from, to, collision_idnullable, callback, autoremoveopt, calc_all_hitsopt, calc_pos_normopt, ign_src_rotopt) → {number}

Append a new async ray test (extended version).
Parameters:
Name Type Attributes Default Description
obj_src Object3D <nullable>
Source object, pass a non-null value to perform ray casting in object space, e.g. from/to vectors specified in object space
from Vec3 From vector
to Vec3 To vector
collision_id string <nullable>
Collision ID, pass "ANY" or null for any collision ID.
callback RayTestCallback | RayTestCallbackPosNorm Ray Test callback
autoremove boolean <optional>
false Automatically remove test after ray casting.
calc_all_hits boolean <optional>
false Test for all possible objects along the ray or just for closest object
calc_pos_norm boolean <optional>
false Calculate and return hit point's position/normal in callback
ign_src_rot boolean <optional>
false Ignore rotation of source object
Returns:
Ray Test ID
Type
number
Source:

apply_collision_impulse_test(obj, callback)

Apply a new async collision impulse test to the given object.
Parameters:
Name Type Description
obj Object3D Object 3D
callback CollisionImpulseCallback Collision impulse test callback.
Source:

apply_constraint(pivot_type, obj_a, trans_a, quat_a, obj_b, trans_b, quat_b, limits, stiffnessopt, dampingopt)

Apply physics constraint.
Parameters:
Name Type Attributes Default Description
pivot_type string Pivot type
obj_a Object3D Object 3D A
trans_a Vec3 Translation of pivot frame relative to A
quat_a Quat Rotation of pivot frame relative to A
obj_b Object3D Object 3D B
trans_b Vec3 Translation of pivot frame relative to B
quat_b Quat Rotation of pivot frame relative to B
limits ConstraintLimits Object containing constraint limits
stiffness Float32Array <optional>
null 6-dimensional vector with constraint stiffness
damping Float32Array <optional>
null 6-dimensional vector with constraint damping
Source:

apply_force(obj, fx_local, fy_local, fz_local)

Apply a constant force to the object (in the local space). Pass zero values to remove applied force.
Parameters:
Name Type Description
obj Object3D Object 3D
fx_local number Fx force in the local space
fy_local number Fy force in the local space
fz_local number Fz force in the local space
Source:

apply_force_world(obj, fx_world, fy_world, fz_world)

Apply a constant force to the object (in the world space). Pass zero values to remove applied force.
Parameters:
Name Type Description
obj Object3D Object 3D
fx_world number Fx force in the world space
fy_world number Fy force in the world space
fz_world number Fz force in the world space
Source:

apply_torque(obj, tx_local, ty_local, tz_local)

Apply constant torque to the object (in the local space). Pass zero values to remove applied torque.
Parameters:
Name Type Description
obj Object3D Object 3D
tx_local number Tx torque
ty_local number Ty torque
tz_local number Tz torque
Source:

apply_velocity(obj, vx_local, vy_local, vz_local)

Apply velocity to the object (in the local space)
Parameters:
Name Type Description
obj Object3D Object 3D
vx_local number Vx local space velocity
vy_local number Vy local space velocity
vz_local number Vz local space velocity
Source:

apply_velocity_world(obj, vx, vy, vz)

Apply velocity to the object (in the world space)
Parameters:
Name Type Description
obj Object3D Object 3D
vx number Vx world space velocity
vy number Vy world space velocity
vz number Vz world space velocity
Source:

change_ray_test_from_to(id, from, to)

Change from/to vectors for the given ray test.
Parameters:
Name Type Description
id number Ray Test ID
from Vec3 New from vector
to Vec3 New to vector
Source:

character_jump(obj)

Make the character jump
Parameters:
Name Type Description
obj Object3D Object 3D
Source:

character_rotation_inc(obj, h_angle, v_angle)

Increment the character rotation
Parameters:
Name Type Description
obj Object3D Object 3D
h_angle number Angle (in radians) in horizontal plane
v_angle number Angle (in radians) in vertical plane
Source:

clear_collision_impulse_test(obj)

Remove the collision impulse test from the given object.
Parameters:
Name Type Description
obj Object3D Object 3D
Source:

disable_simulation(obj)

Disable physics simulation.
Parameters:
Name Type Description
obj Object3D Object 3D
Source:

enable_simulation(obj)

Enable physics simulation.
Parameters:
Name Type Description
obj Object3D Object 3D
Source:

get_vehicle_brake(obj) → {number}

Get the vehicle's brake force.
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Brake value
Type
number
Source:

get_vehicle_name(obj) → (nullable) {string}

Get the vehicle name.
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Vehicle name.
Type
string
Source:

get_vehicle_speed(obj) → {number}

Get the vehicle speed in km/h.
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Vehicle speed
Type
number
Source:

get_vehicle_steering(obj) → {number}

Get the vehicle's steering value.
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Steering value
Type
number
Source:

get_vehicle_throttle(obj) → (nullable) {number}

Get the vehicle's throttle value.
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Throttle value.
Type
number
Source:

has_dynamic_physics(obj) → {boolean}

Check if the object has dynamic simulated physics
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Check result
Type
boolean
Source:

has_physics(obj) → {boolean}

Check if the object has any physics
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Check result
Type
boolean
Source:

has_simulated_physics(obj) → {boolean}

Check if the object has any simulated physics
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Check result
Type
boolean
Source:

is_character(obj) → {boolean}

Check if the given object is a character.
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Check result
Type
boolean
Source:

is_vehicle_chassis(obj) → {boolean}

Check if the given object is a vehicle chassis.
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Checking result.
Type
boolean
Source:

is_vehicle_hull(obj) → {boolean}

Check if the given object is a vehicle hull.
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Checking result.
Type
boolean
Source:

navmesh_find_path(navmesh_obj, start_pos, dest_pos, optionsopt) → (nullable) {PathInformation}

Find path between start_pos and dest_pos, return flat array containing positions of path.
Parameters:
Name Type Attributes Default Description
navmesh_obj Object3D Navigation mesh object
start_pos Vec3 Start position
dest_pos Vec3 Target position
options NavmeshPathOptions <optional>
{} Configurable options of navmesh path
Returns:
Path information or null if path does not exist
Type
PathInformation
Source:
Example
var m_phys = require("physics");
var m_scenes = require("scenes");

var start_point = new Float32Array([5, 2, -7]);
var end_point = new Float32Array([-2, 0, 3]);
var navmesh_obj = m_scenes.get_object_by_name("navmesh");

var island_id = m_phys.navmesh_get_island(navmesh_obj, start_point);
var path = m_phys.navmesh_find_path(navmesh_obj, start_point, end_point, { island: island_id });

navmesh_get_island(navmesh_obj, position, distance_to_closestnullable) → {number}

Get the id of a closest navmesh island(group)
Parameters:
Name Type Attributes Description
navmesh_obj Object3D Navigation mesh object
position Vec3 Path start position
distance_to_closest NavmeshDistanceCallback <nullable>
Callback for distance calculation to determine the closest node. If null then the default function will be used. It calculates the distance from a point to a triangle in the 3D space.
Returns:
island ID
Type
number
Source:
Example
var m_phys = require("physics");
var m_scenes = require("scenes");

var start_point = new Float32Array([5, 2, -7]);
var end_point = new Float32Array([-2, 0, 3]);
var navmesh_obj = m_scenes.get_object_by_name("navmesh");

var island_id = m_phys.navmesh_get_island(navmesh_obj, start_point);
var path = m_phys.navmesh_find_path(navmesh_obj, start_point, end_point, { island: island_id });

pull_to_constraint_pivot(obj_a, trans_a, quat_a, obj_b, trans_b, quat_b)

Pull object A to constraint pivot with object B.
Parameters:
Name Type Description
obj_a Object3D Object 3D A
trans_a Vec3 Translation of pivot frame relative to A
quat_a Quat Rotation of pivot frame relative to A
obj_b Object3D Object 3D B
trans_b Vec3 Translation of pivot frame relative to B
quat_b Quat Rotation of pivot frame relative to B
Source:

remove_collision_test(obj, collision_idnullable, callback)

Remove the collision test from the given object.
Parameters:
Name Type Attributes Description
obj Object3D Object 3D.
collision_id string <nullable>
Collision ID, pass "ANY" or null for any collision ID.
callback CollisionCallback Collision callback.
Source:

remove_constraint(obj_a)

Remove physics constraint. constraint identified by object A from apply_constraint function
Parameters:
Name Type Description
obj_a Object3D Object A.
Source:

remove_ray_test(id)

Remove ray test.
Parameters:
Name Type Description
id number Ray Test ID
Source:

set_angular_velocity(obj, av_x, av_y, av_z)

Set object's angular velocity.
Parameters:
Name Type Description
obj Object3D Object 3D
av_x number X projection of angular velocity in the local space
av_y number Y projection of angular velocity in the local space
av_z number Z projection of angular velocity in the local space
Source:
Example
var m_physics = require("physics");

var obj = m_scenes.get_object_by_name("Cube");
m_physics.set_angular_velocity(obj, 0.0, 0.0, 0.5);

set_character_fly_velocity(obj, velocity)

Set the character's fly speed.
Parameters:
Name Type Description
obj Object3D Object 3D
velocity number Flying velocity
Source:

set_character_move_dir(obj, forw, side)

Move the character in the corresponding direction.
Parameters:
Name Type Description
obj Object3D Object 3D
forw number Apply forward speed
side number Apply side speed
Source:

set_character_move_type(obj, type)

Set the character moving type.
Parameters:
Name Type Description
obj Object3D Object 3D
type CharacterMoveType Character moving type (one of CM_*).
Source:

set_character_rotation(obj, angle_h, angle_v)

Set the character rotation in horizontal and vertical planes
Parameters:
Name Type Description
obj Object3D Object 3D
angle_h number Angle (in radians) in horizontal plane
angle_v number Angle (in radians) in vertical plane
Source:

set_character_rotation_h(obj, angle)

Set the character horizontal rotation
Parameters:
Name Type Description
obj Object3D Object 3D
angle number Angle (in radians) in horizontal plane
Source:

set_character_rotation_v(obj, angle)

Set the character vertical rotation
Parameters:
Name Type Description
obj Object3D Object 3D
angle number Angle (in radians) in vertical plane
Source:

set_character_run_velocity(obj, velocity)

Set the character's run speed.
Parameters:
Name Type Description
obj Object3D Object 3D
velocity number Running velocity
Source:

set_character_walk_velocity(obj, velocity)

Set the character's walk speed.
Parameters:
Name Type Description
obj Object3D Object 3D
velocity number Walking velocity
Source:

set_gravity(obj, gravity)

Set the object's gravity.
Parameters:
Name Type Description
obj Object3D Object 3D
gravity number Positive object gravity
Source:

set_transform(obj, trans, quat)

Set the object's transform (for static/kinematic objects)
Parameters:
Name Type Description
obj Object3D Object 3D
trans Vec3 Translation vector
quat Quat Rotation quaternion
Source:

sync_transform(obj)

Sync the object's transform (for static/kinematic objects)
Parameters:
Name Type Description
obj Object3D Object 3D
Source:

vehicle_brake(obj, brake_force)

Stop the vehicle by applying the brake force.
Parameters:
Name Type Description
obj Object3D Object 3D
brake_force number Brake force (0..1)
Source:

vehicle_brake_inc(obj, brake_force_inc)

Increment the brake force
Parameters:
Name Type Description
obj Object3D Object 3D
brake_force_inc number Brake force increment (-1..1)
Source:

vehicle_steer(obj, steering_value)

Change vehicle steering.
Parameters:
Name Type Description
obj Object3D Object 3D
steering_value number Steering value (-1..1)
Source:

vehicle_steer_inc(obj, steering_value_inc, dir)

Increment vehicle steering.
Parameters:
Name Type Description
obj Object3D Object 3D
steering_value_inc number Steering value increment (0..1)
dir number Steering direction -1,0,1
Source:

vehicle_throttle(obj, engine_force)

Apply throttle to vehicle.
Parameters:
Name Type Description
obj Object3D Object 3D
engine_force number Engine force (-1..1)
Source:

vehicle_throttle_inc(obj, engine_force_inc, dir)

Increment vehicle throttle.
Parameters:
Name Type Description
obj Object3D Object 3D
engine_force_inc number Engine force increment (0..1)
dir number Throttling direction -1,0,1
Source:

Type Definitions

CharacterMoveType

Character's type of movement enum. One of CM_*.
Type:
  • number
Source:

CollisionCallback(result, coll_objnullable, coll_posnullable, coll_normnullable, coll_distnullable)

Collision result callback.
Parameters:
Name Type Attributes Description
result boolean Collision result flag.
coll_obj Object3D <nullable>
The target collision object, i.e the object the source object collides with (null for no collision or when this object is represented by collision material).
coll_pos Vec3 <nullable>
Position of collision point.
coll_norm Vec3 <nullable>
Normal of collision point.
coll_dist number <nullable>
Distance between collision points of colliding objects.
Source:

CollisionImpulseCallback(impulse)

Collision impulse result callback.
Parameters:
Name Type Description
impulse number Impulse applied on collision point.
Source:

NavmeshDistanceCallback(position, centroid, vertex_ids, vertices, current_max_distance)

Navmesh distance callback. Used to determine start and end polygon of navmesh
Parameters:
Name Type Description
position Vec3 Position to which we must calculate a distance
centroid Vec3 Center of current polygon
vertex_ids Uint32Array Indices of polygon vertices
vertices Array Vertex array
current_max_distance number Current maximum distance
Source:

NavmeshPathOptions

Configurable options of navmesh path.
Type:
  • Object
Properties:
Name Type Attributes Default Description
island number <optional>
0 ID; see physics.navmesh_get_island
allowed_distance number <optional>
Number.MAX_VALUE Distance limit from start/target position to navmesh
do_not_pull_string boolean <optional>
false Returns centroids path instead of pulled string
return_normals boolean <optional>
false Return path normals in PathInformation.
distance_to_closest NavmeshDistanceCallback <optional>
Callback for distance calculation to determine closest node
distance_to_farthest NavmeshDistanceCallback <optional>
Callback for distance calculation to determine farthest node
Source:

PathInformation

Navmesh path information.
Type:
  • Object
Properties:
Name Type Attributes Description
positions Float32Array Positions of path points - plane array of Vec3-type positions
normals Float32Array <nullable>
Normals of path points - plane array of Vec3-type normals
Source:

RayTestCallback(id, hit_fract, obj_hitnullable, hit_time)

Ray test callback.
Parameters:
Name Type Attributes Description
id number Ray Test ID
hit_fract number Fraction of ray length where hit has occurred (0-1) or -1 if there is no hit anymore
obj_hit Object3D <nullable>
Hit Object 3D
hit_time number Time the hit happened.
Source: