Implements the event-driven model of Blend4Web.
- Sensor
- Sensor is a programming entity intended for detecting events occurred in the scene. Some sensors may carry a payload. For example the ray-tracing sensor (Ray Sensor) provides the relative length of the intersection ray.
- Sensor Manifold (or simply manifold)
- Sensors should be present in one or multiple collections - so called sensor manifolds. A manifold is a logic container associated with a scene object. It generates a response (pulse) to a defined set of sensor events by executing a callback function.
In order to use the input-output sensors, register the corresponding event listeners by using register_* methods.
Summary
Members
- CT_CHANGE
- CT_CONTINUOUS
- CT_LEVEL
- CT_POSITIVE
- CT_SHOT
- CT_TRIGGER
- default_AND_logic_fun
- default_OR_logic_fun
- KEY_1
- KEY_2
- KEY_3
- KEY_4
- KEY_5
- KEY_6
- KEY_7
- KEY_8
- KEY_9
- KEY_A
- KEY_ALT
- KEY_B
- KEY_BACK_SLASH
- KEY_BACKSPACE
- KEY_C
- KEY_CAPSLOCK
- KEY_COMMA
- KEY_CTRL
- KEY_D
- KEY_DASH
- KEY_DEC_POINT
- KEY_DOWN
- KEY_E
- KEY_ENTER
- KEY_EQUAL_SIGN
- KEY_ESC
- KEY_F
- KEY_FORWARD_SLASH
- KEY_G
- KEY_GRAVE_ACCENT
- KEY_H
- KEY_I
- KEY_J
- KEY_K
- KEY_L
- KEY_LEFT
- KEY_LEFT_SQ_BRACKET
- KEY_M
- KEY_N
- KEY_NUM0
- KEY_NUM1
- KEY_NUM2
- KEY_NUM3
- KEY_NUM4
- KEY_NUM5
- KEY_NUM6
- KEY_NUM7
- KEY_NUM8
- KEY_NUM9
- KEY_NUM9
- KEY_NUM9
- KEY_NUM9
- KEY_NUM9
- KEY_O
- KEY_P
- KEY_PAUSE
- KEY_PERIOD
- KEY_Q
- KEY_R
- KEY_RIGHT
- KEY_RIGHT_SQ_BRACKET
- KEY_S
- KEY_SEMI_COLON
- KEY_SHIFT
- KEY_SINGLE_QUOTE
- KEY_SPACE
- KEY_T
- KEY_TAB
- KEY_U
- KEY_UP
- KEY_V
- KEY_W
- KEY_X
- KEY_Y
- KEY_Z
- PL_MULTITOUCH_MOVE_PAN
- PL_MULTITOUCH_MOVE_ROTATE
- PL_MULTITOUCH_MOVE_ZOOM
- PL_SINGLE_TOUCH_MOVE
Methods
- check_sensor_manifold(objnullable, id) → {boolean}
- check_sensor_manifolds(objnullable) → {boolean}
- create_callback_sensor(callback, valueopt) → {Sensor}
- create_collision_impulse_sensor(obj) → {Sensor}
- create_collision_sensor(obj_src, collision_idopt, nullable, calc_pos_normopt) → {Sensor}
- create_custom_sensor(value) → {Sensor}
- create_elapsed_sensor() → {Sensor}
- create_gamepad_axis_sensor(axis, numberopt) → {Sensor}
- create_gamepad_btn_sensor(ind, numberopt) → {Sensor}
- create_gamepad_orientation_sensor(numberopt) → {Sensor}
- create_gamepad_position_sensor(numberopt) → {Sensor}
- create_gyro_angles_sensor() → {Sensor}
- create_gyro_delta_sensor() → {Sensor}
- create_gyro_quat_sensor() → {Sensor}
- create_hmd_position_sensor() → {Sensor}
- create_hmd_quat_sensor() → {Sensor}
- create_kb_sensor_manifold(objnullable, id, type, key, callback, callback_paramopt)
- create_keyboard_sensor(key, elementopt) → {Sensor}
- create_motion_sensor(obj, thresholdopt, rotation_thresholdopt) → {Sensor}
- create_mouse_click_sensor(elementopt) → {Sensor}
- create_mouse_move_sensor(axisopt, elementopt) → {Sensor}
- create_mouse_wheel_sensor(elementopt) → {Sensor}
- create_plock_mouse_sensor(elementopt) → {Sensor}
- create_plock_sensor(elementopt) → {Sensor}
- create_ray_sensor(obj_srcnullable, from, to, collision_idopt, nullable, is_binary_valueopt, calc_pos_normopt, ign_src_rotopt) → {Sensor}
- create_selection_sensor(obj, enable_toggle_switchopt) → {Sensor}
- create_sensor_manifold(objnullable, id, type, sensors, logic_funnullable, callback, callback_paramopt)
- create_timeline_sensor() → {Sensor}
- create_timer_sensor(period, do_repeatopt) → {Sensor}
- create_touch_click_sensor(elementopt) → {Sensor}
- create_touch_move_sensor(axisopt, elementopt) → {Sensor}
- create_touch_rotate_sensor(elementopt) → {Sensor}
- create_touch_zoom_sensor(elementopt) → {Sensor}
- create_vertical_velocity_sensor(obj, thresholdopt) → {Sensor}
- get_custom_sensor(sensor) → {number}
- get_sensor_payload(objnullable, manifold_id, num) → {*}
- get_sensor_value(objnullable, manifold_id, num) → {number}
- remove_sensor_manifold(objnullable, idopt)
- reset()
- reset_timer_sensor(obj, manifold_id, num, period)
- set_custom_sensor(sensor, value)
- set_plock_smooth_factor(value)
Type Definitions
- CollisionPayload(coll_objnullable, coll_posnullable, coll_normnullable, coll_distnullable)
- ManifoldCallback(objnullable, id, pulse, paramopt)
- ManifoldLogicFunction(s) → {number}
- RayPayload(hit_fract, obj_hitnullable, hit_time, hit_pos, hit_norm)
- SensorCallback()
Detailed Description
Members
CT_CHANGE
Manifold control type: change.
Such manifold executes the callback each time the value
of any sensor is changed. The logic function is ignored.
- Source:
CT_CONTINUOUS
Manifold control type: continuous.
Such manifold executes the callback with a positive pulse (+1) each frame
when the result of evaluation of its logic function is non-zero.
It executes a callback with a negative pulse (-1) once the logic function
evaluates to zero.
- Source:
CT_LEVEL
Manifold control type: level.
Such manifold executes the callback each time the result of
evaluation of its logic function is changed.
- Source:
CT_POSITIVE
Manifold control type: positive.
Such manifold executes the callback each frame when the result of
evaluation of its logic function is positive.
- Source:
CT_SHOT
Manifold control type: shot.
Such manifold executes the callback once the result of evaluation of its
logic function becomes a non-zero value.
- Source:
CT_TRIGGER
Manifold control type: trigger.
Such manifold executes the callback with a single positive pulse (+1) once the result of
evaluation of its logic function is non-zero.
It executes a callback with a single negative pulse (-1) once the logic function
evaluates to zero.
- Source:
default_AND_logic_fun
Default logic AND function for sensor manifold
- Source:
default_OR_logic_fun
Default logic OR function for sensor manifold
- Source:
KEY_1
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_2
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_3
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_4
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_5
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_6
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_7
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_8
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_9
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_A
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_ALT
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_B
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_BACK_SLASH
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_BACKSPACE
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_C
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_CAPSLOCK
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_COMMA
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_CTRL
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_D
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_DASH
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_DEC_POINT
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
Can only be used when NUM LOCK is turned on.
- Source:
KEY_DOWN
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_E
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_ENTER
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_EQUAL_SIGN
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_ESC
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_F
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_FORWARD_SLASH
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_G
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_GRAVE_ACCENT
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_H
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_I
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_J
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_K
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_L
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_LEFT
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_LEFT_SQ_BRACKET
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_M
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_N
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_NUM0
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_NUM1
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_NUM2
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_NUM3
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_NUM4
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_NUM5
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_NUM6
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_NUM7
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_NUM8
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_NUM9
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_NUM9
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_NUM9
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_NUM9
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_NUM9
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_O
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_P
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_PAUSE
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_PERIOD
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_Q
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_R
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_RIGHT
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_RIGHT_SQ_BRACKET
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_S
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_SEMI_COLON
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_SHIFT
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_SINGLE_QUOTE
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_SPACE
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_T
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_TAB
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_U
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_UP
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_V
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_W
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_X
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_Y
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
KEY_Z
Keyboard sensor parameter. Corresponds to keyCode property of KeyboardEvent.
- Source:
PL_MULTITOUCH_MOVE_PAN
Payload value of a touch movement sensor. Returned by get_sensor_payload()
for multi-finger pan gestures.
- Source:
PL_MULTITOUCH_MOVE_ROTATE
Payload value of a touch movement sensor. Returned by get_sensor_payload()
for multi-finger rotate gestures.
- Source:
PL_MULTITOUCH_MOVE_ZOOM
Payload value of a touch movement sensor. Returned by get_sensor_payload()
for multi-finger zoom gestures.
- Source:
PL_SINGLE_TOUCH_MOVE
Payload value of a touch movement sensor. Returned by get_sensor_payload()
for single-finger pan gestures.
- Source:
Methods
check_sensor_manifold(objnullable, id) → {boolean}
Check whether the object has the manifold attached.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
obj |
Object3D |
<nullable> |
Object 3D, or null to denote the global object |
id |
string | Manifold ID |
Returns:
Result of the check
- Type
- boolean
- Source:
check_sensor_manifolds(objnullable) → {boolean}
Check whether the object has any manifolds attached.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
obj |
Object3D |
<nullable> |
Object 3D, or null to denote the global object |
Returns:
Result of the check
- Type
- boolean
- Source:
create_callback_sensor(callback, valueopt) → {Sensor}
Create a callback sensor.
The given callback is executed every frame and its return value is copied into the sensor value.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
callback |
SensorCallback | A callback which modifies sensor value. | ||
value |
number |
<optional> |
0 | Initial sensor value. |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_collision_impulse_sensor(obj) → {Sensor}
create_collision_sensor(obj_src, collision_idopt, nullable, calc_pos_normopt) → {Sensor}
Create a collision sensor.
Detects collisions between the object and the entities (objects or physics
materials) with the specified collision ID. If the collision ID is not
specified, the sensor will detect collisions with any entities.
This sensor carries the following payload.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
obj_src |
Object3D | Collision object. | ||
collision_id |
string |
<optional> <nullable> |
"ANY" | Collision ID, "ANY" for any collision ID |
calc_pos_norm |
boolean |
<optional> |
false | Should the sensor return the collision position/normal/distance or not. |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_custom_sensor(value) → {Sensor}
Create a custom sensor.
A custom sensor can be controlled manually by using the get_custom_sensor()
and set_custom_sensor() methods.
Parameters:
Name | Type | Description |
---|---|---|
value |
number | Initial custom sensor value |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_elapsed_sensor() → {Sensor}
Create an elapsed sensor.
The sensor's value is the time elapsed from the previous frame.
Returns:
Sensor object
- Type
- Sensor
- Source:
create_gamepad_axis_sensor(axis, numberopt) → {Sensor}
Create a gamepad an axis sensor.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
axis |
number | Axis number | |
number |
number |
<optional> |
Connected gamepad number |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_gamepad_btn_sensor(ind, numberopt) → {Sensor}
Create a gamepad button sensor.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
ind |
number | Button number | |
number |
number |
<optional> |
Connected gamepad number |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_gamepad_orientation_sensor(numberopt) → {Sensor}
Create a gamepad orientation sensor.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
number |
number |
<optional> |
Connected gamepad number |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_gamepad_position_sensor(numberopt) → {Sensor}
Create a gamepad position sensor.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
number |
number |
<optional> |
Connected gamepad number |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_gyro_angles_sensor() → {Sensor}
Create a gyroscope angle sensor.
The sensor's payload stores the Euler angles of orientation (in radians)
of a mobile device.
Returns:
Sensor object
- Type
- Sensor
- Source:
create_gyro_delta_sensor() → {Sensor}
Create a gyroscope delta sensor.
The sensor's payload stores the differences (in radians) between Euler angles
of the current orientation and the previous orientation of a mobile device.
Returns:
Sensor object
- Type
- Sensor
- Source:
create_gyro_quat_sensor() → {Sensor}
Create a gyroscope quaternion sensor.
The sensor's payload stores the quaternion of orientation
of a mobile device.
Returns:
Sensor object
- Type
- Sensor
- Source:
create_hmd_position_sensor() → {Sensor}
Create a HMD position sensor.
The sensor's payload stores the vector of HMD position.
Returns:
Sensor object
- Type
- Sensor
- Source:
create_hmd_quat_sensor() → {Sensor}
Create a HMD quaternion sensor.
The sensor's payload stores the quaternion of orientation of a HMD.
Returns:
Sensor object
- Type
- Sensor
- Source:
create_kb_sensor_manifold(objnullable, id, type, key, callback, callback_paramopt)
Convenience function: creates a manifold coupled with a single keyboard
sensor. Can be used to quickly create a single-key functionality.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
obj |
Object3D |
<nullable> |
Object 3D to attach the manifold to, or null to denote the global object |
id |
string | New manifold ID | |
type |
number | Manifold control type (CT_SHOT, CT_TRIGGER etc) | |
key |
number | Sensor key KEY_* | |
callback |
ManifoldCallback | Manifold's callback | |
callback_param |
* |
<optional> |
Parameter to pass to the manifold's callback (e.g. some state) |
- Source:
create_keyboard_sensor(key, elementopt) → {Sensor}
Create a keyboard sensor.
This sensor carries the following payload values:
0 --- button wasn't pressed at the last frame, and it wasn't pressed at the current frame,
1 --- button wasn't pressed at the last frame, but it was pressed at the current frame,
2 --- button was pressed at the last frame, and it was pressed at the current frame,
3 --- button was pressed at the last frame, and it wasn't pressed at the current frame.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
key |
number | Sensor key KEY_* | ||
element |
HTMLElement |
<optional> |
Canvas container element | HTML element |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_motion_sensor(obj, thresholdopt, rotation_thresholdopt) → {Sensor}
Create a motion sensor.
The sensor's value is 1 if the object is in motion.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
obj |
Object3D | Object 3D | ||
threshold |
number |
<optional> |
0.1 | Translation velocity threshold, units (meters) per second |
rotation_threshold |
number |
<optional> |
0.1 | Rotation velocity threshold, radians per second |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_mouse_click_sensor(elementopt) → {Sensor}
Create a mouse click sensor.
The sensor's payload is an object
with useful properties like coordinates, and index of button
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
element |
HTMLElement |
<optional> |
Canvas container element | HTML element |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_mouse_move_sensor(axisopt, elementopt) → {Sensor}
Create a mouse movement sensor.
The sensor's value is a number of pixels, the sensor's payload is an object
with useful properties like coordinates
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
axis |
string |
<optional> |
"XY" | Coordinate(s) to track: "X", "Y", "XY" |
element |
HTMLElement |
<optional> |
HTML element. The canvas container will be use by default. |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_mouse_wheel_sensor(elementopt) → {Sensor}
Create a mouse wheel sensor.
The sensor's value is 1 for a single wheel notch scrolled away from the user.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
element |
HTMLElement |
<optional> |
Canvas container element | HTML element |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_plock_mouse_sensor(elementopt) → {Sensor}
Create a mouse move pointerlock sensor.
The sensor's value is a number of pixels, the sensor's payload is an object
with useful properties like coordinates
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
element |
HTMLElement |
<optional> |
Canvas container element | HTML element |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_plock_sensor(elementopt) → {Sensor}
Create a mouse pointerlock sensor.
The sensor's value is a pointerlock state
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
element |
HTMLElement |
<optional> |
Canvas container element | HTML element |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_ray_sensor(obj_srcnullable, from, to, collision_idopt, nullable, is_binary_valueopt, calc_pos_normopt, ign_src_rotopt) → {Sensor}
Create a ray sensor.
The sensor casts a ray between the from and to positions.
These positions are specified relatively to the object's origin
(ign_src_rot = true), in the world space (obj_src = null) or in the local
space (ign_src_rot = false).
Checks intersection of this ray with the specified collision ID. If the
collision ID is not specified, the sensor will detect collisions with any
entities.
This sensor carries the following payload.
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 |
<optional> <nullable> |
"ANY" | Collision ID, "ANY" for any collision ID |
is_binary_value |
boolean |
<optional> |
false | Calculate the value of the sensor as a binary (hit/non-hit) instead of hit fraction. |
calc_pos_norm |
boolean |
<optional> |
false | Calculate hit position/normal (accessed from payload object). |
ign_src_rot |
boolean |
<optional> |
false | Ignore any rotation of the source object during ray casting. |
Returns:
Sensor object.
- Type
- Sensor
- Source:
create_selection_sensor(obj, enable_toggle_switchopt) → {Sensor}
Create a selection sensor for the object.
The sensor's value becomes 1 when the object is selected by the user.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
obj |
Object3D | Object 3D | ||
enable_toggle_switch |
boolean |
<optional> |
false | If true, reset the sensor (set it to 0) only when another object is selected. If false, reset the sensor when the mouse button/touch is released. |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_sensor_manifold(objnullable, id, type, sensors, logic_funnullable, callback, callback_paramopt)
Create a sensor manifold.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
obj |
Object3D |
<nullable> |
Object 3D to attach the manifold to, or null to denote the global object. |
id |
string | New manifold ID. | |
type |
number | Manifold control type (CT_SHOT, CT_TRIGGER etc). | |
sensors |
Array.<Sensor> | Array of sensors. | |
logic_fun |
ManifoldLogicFunction |
<nullable> |
Manifold's logic function, if null use default_AND_logic_fun function. |
callback |
ManifoldCallback | Manifold's callback. | |
callback_param |
* |
<optional> |
Parameter to pass to the manifold's callback (e.g. some state). |
- Source:
create_timeline_sensor() → {Sensor}
Create a timeline sensor.
The sensor's value is the value of the global engine timeline.
Returns:
Sensor object
- Type
- Sensor
- Source:
create_timer_sensor(period, do_repeatopt) → {Sensor}
Create a timer sensor.
The sensor's value becomes 1 for the frame which comes next after the
period of time has elapsed. After that, its value becomes 0 again.
The timer's precision depends on FPS, so it is not effective for measuring
short intervals.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
period |
number | Timer period, in seconds | ||
do_repeat |
boolean |
<optional> |
false | Re-start the timer upon expiration |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_touch_click_sensor(elementopt) → {Sensor}
Create a touch click sensor.
The sensor's value is 1 for a touched touchscreen. The sensor's payload is an object
with useful properties like coordinates
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
element |
HTMLElement |
<optional> |
Canvas container element | HTML element |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_touch_move_sensor(axisopt, elementopt) → {Sensor}
Create a touch movement sensor.
The sensor's value is a number of pixels, the sensor's payload is an object
with useful properties like coordinates
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
axis |
string |
<optional> |
"XY" | Coordinate(s) to track: "X", "Y" or "XY" |
element |
HTMLElement |
<optional> |
HTML element. The canvas container will be use by default. |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_touch_rotate_sensor(elementopt) → {Sensor}
Create a touch rotate sensor.
The sensor's value is the angle (in radians) from -PI to PI.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
element |
HTMLElement |
<optional> |
Canvas container element | HTML element |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_touch_zoom_sensor(elementopt) → {Sensor}
Create a touch zoom sensor.
The sensor's value is the distance difference in pixels.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
element |
HTMLElement |
<optional> |
Canvas container element | HTML element |
Returns:
Sensor object
- Type
- Sensor
- Source:
create_vertical_velocity_sensor(obj, thresholdopt) → {Sensor}
Create a velocity sensor.
The sensor's value is 1 if abs() of the object's vertical velocity exceeds
the threshold.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
obj |
Object3D | Object 3D | ||
threshold |
number |
<optional> |
1.0 | Vertical velocity threshold, units (meters) per second |
Returns:
Sensor object
- Type
- Sensor
- Source:
get_custom_sensor(sensor) → {number}
Get the value of the custom sensor.
Parameters:
Name | Type | Description |
---|---|---|
sensor |
Sensor | Sensor object |
Returns:
Sensor value
- Type
- number
- Source:
get_sensor_payload(objnullable, manifold_id, num) → {*}
Return the payload data of the sensor from the object's manifold. The sensor
is identified by its index in the manifold's array of sensors.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
obj |
Object3D |
<nullable> |
Object 3D, or null to denote the global object |
manifold_id |
string | Object's manifold ID | |
num |
number | Sensor index in manifold's array |
Returns:
Sensor payload
- Type
- *
- Source:
get_sensor_value(objnullable, manifold_id, num) → {number}
Return the value of the sensor from the object's manifold. The sensor is
identified by its index in the manifold's array of sensors.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
obj |
Object3D |
<nullable> |
Object 3D, or null to denote the global object |
manifold_id |
string | Object's manifold ID | |
num |
number | Sensor index in manifold's array |
Returns:
Sensor value
- Type
- number
- Source:
remove_sensor_manifold(objnullable, idopt)
Remove the sensor manifold registered for the object.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
obj |
Object3D |
<nullable> |
Object 3D to delete the manifold from, or null to denote the global object | |
id |
string |
<optional> |
null | ID of the sensor manifold, or null to delete all manifolds |
- Source:
reset()
Reset controls for all the objects.
Calling this method is discouraged, use remove_sensor_manifold() instead.
- Source:
reset_timer_sensor(obj, manifold_id, num, period)
Reset the timer sensor and set a new period value.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object3D | Object 3D |
manifold_id |
string | Object's manifold ID |
num |
number | Sensor's number in the manifold |
period |
number | A new period value for the sensor |
- Source:
set_custom_sensor(sensor, value)
Set the value of the custom sensor.
Parameters:
Name | Type | Description |
---|---|---|
sensor |
Sensor | Sensor object |
value |
number | New sensor value |
- Source:
set_plock_smooth_factor(value)
Set smooth factor for mouse pointerlock sensor.
Parameters:
Name | Type | Description |
---|---|---|
value |
number | Set |
- Source:
Type Definitions
CollisionPayload(coll_objnullable, coll_posnullable, coll_normnullable, coll_distnullable)
Collision sensor payload.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
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:
ManifoldCallback(objnullable, id, pulse, paramopt)
Manifold's callback. It is executed when the manifold generates a pulse.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
obj |
Object3D |
<nullable> |
Object 3D, or null to denote the global object |
id |
string | Manifold ID | |
pulse |
number | Additional callback condition for CT_TRIGGER or CT_CONTINUOUS manifolds: +1 or -1 | |
param |
* |
<optional> |
Callback parameter. The user-defined parameter which is passed to create_sensor_manifold(). Can be used, for example, as a storage object to communicate between different manifolds. |
- Source:
ManifoldLogicFunction(s) → {number}
Manifold's logic function. Specifies a logic expression which consists of
sensor values. This logic expression will be evaluated every frame. As a
result, the manifold changes its internal state and fires the callback.
Parameters:
Name | Type | Description |
---|---|---|
s |
Array | Numeric array with sensor values. |
Returns:
Result of evaluation of the logic expression
- Type
- number
- Source:
RayPayload(hit_fract, obj_hitnullable, hit_time, hit_pos, hit_norm)
Ray sensor payload.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
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> |
The hit object. |
hit_time |
number | Time the hit happened. | |
hit_pos |
Vec3 | Hit position in world space. | |
hit_norm |
Vec3 | Hit normal in world space. |
- Source:
SensorCallback()
Special callback for callback-sensor. It's executed every frame and
its return value is copied into the sensor value. Should return a numeric value.
- Source: