OculusTouch

May 7, 2024 ยท View on GitHub

from tdw.add_ons.oculus_touch import OculusTouch

Add a VR rig to the scene that uses Oculus Touch controllers.

Make all non-kinematic objects graspable by the rig.

Per communicate() call, this add-on updates the positions of the VR rig, its hands, and its head, as well as which objects it is grasping and the controller button presses.

Class Variables

VariableTypeDescriptionValue
AVATAR_IDstrIf an avatar is attached to the VR rig, this is the ID of the VR rig's avatar."vr"

Fields

  • vr_node_ids Object IDs of the VR nodes (the body and hands).

  • rig The Transform data of the root rig object. If output_data == False, this is never updated.

  • left_hand The Transform data of the left hand. If output_data == False, this is never updated.

  • right_hand The Transform data of the right hand. If output_data == False, this is never updated.

  • head The Transform data of the head. If output_data == False, this is never updated.

  • held_left A numpy of object IDs held by the left hand.

  • held_right A numpy of object IDs held by the right hand.

  • commands These commands will be appended to the commands of the next communicate() call.

  • initialized If True, this module has been initialized.

  • rig The Transform data of the root rig object. If output_data == False, this is never updated.

  • left_hand The Transform data of the left hand. If output_data == False, this is never updated.

  • right_hand The Transform data of the right hand. If output_data == False, this is never updated.

  • head The Transform data of the head. If output_data == False, this is never updated.

  • held_left A numpy of object IDs held by the left hand.

  • held_right A numpy of object IDs held by the right hand.

  • commands These commands will be appended to the commands of the next communicate() call.

  • initialized If True, this module has been initialized.


Functions

__init__

OculusTouch()

OculusTouch(human_hands=True, set_graspable=True, output_data=True, position=None, rotation=0, attach_avatar=False, avatar_camera_width=512, headset_aspect_ratio=0.9, headset_resolution_scale=1.0, non_graspable=None, discrete_collision_detection_mode=True)

ParameterTypeDefaultDescription
human_handsboolTrueIf True, visualize the hands as human hands. If False, visualize the hands as robot hands.
set_graspableboolTrueIf True, set all non-kinematic objects and composite sub-objects as graspable by the VR rig.
output_databoolTrueIf True, send VRRig output data per-frame.
positionDict[str, float]NoneThe initial position of the VR rig. If None, defaults to {"x": 0, "y": 0, "z": 0}
rotationfloat0The initial rotation of the VR rig in degrees.
attach_avatarboolFalseIf True, attach an avatar to the VR rig's head. Do this only if you intend to enable image capture. The avatar's ID is "vr".
avatar_camera_widthint512The width of the avatar's camera in pixels. This is not the same as the VR headset's screen resolution! This only affects the avatar that is created if attach_avatar is True. Generally, you will want this to lower than the headset's actual pixel width, otherwise the framerate will be too slow.
headset_aspect_ratiofloat0.9The width / height aspect ratio of the VR headset. This is only relevant if attach_avatar is True because it is used to set the height of the output images. The default value is the correct value for all VR devices.
headset_resolution_scalefloat1.0The headset resolution scale controls the actual size of eye textures as a multiplier of the device's default resolution. A value greater than 1 improves image quality but at a slight performance cost. Range: 0.5 to 1.75
non_graspableList[int]NoneA list of IDs of non-graspable objects. By default, all non-kinematic objects are graspable and all kinematic objects are non-graspable. Set this to make non-kinematic objects non-graspable.
discrete_collision_detection_modeboolTrueIf True, the VR rig's hands and all graspable objects in the scene will be set to the "discrete" collision detection mode, which seems to reduce physics glitches in VR. If False, the VR rig's hands and all graspable objects will be set to the "continuous_dynamic" collision detection mode (the default in TDW).

get_initialization_commands

self.get_initialization_commands()

This function gets called exactly once per add-on. To re-initialize, set self.initialized = False.

Returns: A list of commands that will initialize this add-on.

on_send

self.on_send(resp)

This is called after commands are sent to the build and a response is received.

Use this function to send commands to the build on the next frame, given the resp response. Any commands in the self.commands list will be sent on the next frame.

ParameterTypeDefaultDescription
respList[bytes]The response from the build.

set_position

self.set_position(position)

Set the position of the VR rig.

ParameterTypeDefaultDescription
positionDict[str, float]The new position.

rotate_by

self.rotate_by(angle)

Rotate the VR rig by an angle.

ParameterTypeDefaultDescription
anglefloatThe angle in degrees.

reset

self.reset()

self.reset(non_graspable=None, position=None, rotation=0)

Reset the VR rig. Call this whenever a scene is reset.

ParameterTypeDefaultDescription
non_graspableList[int]NoneA list of IDs of non-graspable objects. By default, all non-kinematic objects are graspable and all kinematic objects are non-graspable. Set this to make non-kinematic objects non-graspable.
positionDict[str, float]NoneThe initial position of the VR rig. If None, defaults to {"x": 0, "y": 0, "z": 0}
rotationfloat0The initial rotation of the VR rig in degrees.

show_loading_screen

self.show_loading_screen(show)

Show or hide the VR loading screen. To use this correctly, call this function followed by c.communicate(commands).

ParameterTypeDefaultDescription
showboolIf True, show the loading screen. If False, hide the loading screen.

before_send

self.before_send(commands)

This is called within Controller.communicate(commands) before sending commands to the build. By default, this function doesn't do anything.

ParameterTypeDefaultDescription
commandsList[dict]The commands that are about to be sent to the build.

get_early_initialization_commands

self.get_early_initialization_commands()

This function gets called exactly once per add-on. To re-initialize, set self.initialized = False.

These commands are added to the list being sent on communicate() before any other commands, including those added by the user and by other add-ons.

Usually, you shouldn't override this function. It is useful for a small number of add-ons, such as loading screens, which should initialize before anything else.

Returns: A list of commands that will initialize this add-on.

listen_to_axis

self.listen_to_axis(is_left, function)

Listen for controller axis events.

ParameterTypeDefaultDescription
is_leftboolIf True, this is the left controller. If False, this is the right controller.
functionCallable[[np.ndarray]The function to invoke when the button is pressed. This function must a single argument (a numpy array of shape (2), representing (x, y) coordinates) and return None.

listen_to_button

self.listen_to_button(button, is_left, function)

Listen for Oculus Touch controller button presses.

ParameterTypeDefaultDescription
buttonOculusTouchButtonThe Oculus Touch controller button.
is_leftboolIf True, this is the left controller. If False, this is the right controller.
functionCallable[[]The function to invoke when the button is pressed. This function must have no arguments and return None.