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_idopt, nullable, 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 <optional>
<nullable>
"ANY" Collision ID, "ANY" 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_srcopt, nullable, from, to, collision_idopt, nullable, callback, autoremoveopt) → {Number}

Append a new async ray test.
Parameters:
Name Type Attributes Default Description
obj_src Object3D <optional>
<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 <optional>
<nullable>
"ANY" Collision ID, "ANY" 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_srcopt, nullable, from, to, collision_idopt, nullable, 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 <optional>
<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 <optional>
<nullable>
"ANY" Collision ID, "ANY" 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 Callision 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 containting 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 horizontal plane
v_angle Number Angle 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_idopt, nullable, callback)

Remove the collision test from the given object.
Parameters:
Name Type Attributes Default Description
obj Object3D Object 3D.
collision_id String <optional>
<nullable>
"ANY" Collision ID, "ANY" 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_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 horizontal plane
angle_v Number Angle 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 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 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 occured (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: