vrPhysicsService

class vrPhysicsService

(Inherits vrBaseService)

The vrPhysicsService class.

This class provides access to the physics simulation in VRED. It allows adding, removing, and manipulating physics objects in the simulation.

This is an experimental feature and is subject to change in future releases. For now, it is only available for collision detection and not for actual physics simulations.

There are three types of physics objects that can be added to the simulation: Kinematic, Dynamic, and Static. A kinematic object is a physics object that is not affected by forces but can be controlled manually by the user. Only convex shapes are supported for kinematic objects, which means no triangle meshes can be used. A dynamic object is a physics object that is affected by forces and can interact with other objects in the simulation. It cannot be manually moved. Dynamic objects are currently not used in VRED. A static object is a physics object that is not affected by forces and can’t be moved manually or by other objects or the user. The only valid configuration for a static object is the triangle mesh configuration.

Some notes on using this service:

At this moment, only convex shapes are really supported. So the best case is to use convex hulls. Triangle meshes are only partly supported. They can be used for static objects but not for moving objects. That means they must not be moved in any way in VRED after they have been added to the physics simulation or their collision shape will be out of sync with the actual object. PhysX is also very strict about the tessellation of the triangle meshes. If the tessellation is not good enough, they can cause problems or even errors.

For complex objects, convex decomposition can be used, which breaks down the object into multiple smaller convex shapes. The library used for that is v-hacd (https://github.com/kmammou/v-hacd). Almost all parameters of the library can be set in the vrdPhysicsConfig object to fine-tune the decomposition process.

The collision shapes of the objects are currently not visualized in VRED. They can be visualized in the NVidia PhysX Visual Debugger which can be connected to the physics simulation using the connectDebugger(host, port) function. The debugger must be started on the same machine as VRED before the connection can be established. The debugger can be downloaded from the NVidia website (https://developer.nvidia.com/nvidia-physx-visual-debugger).

Please also note that there is currently no detection if a child node of a registered node is moved or removed. If there are structural changes in the scene graph for a registered node, the node should be removed and then re-added to the physics simulation. It is not possible to add a node to the physics simulation for which a parent node is already registered. This is detected and results in an error when trying to add the node.

Functions

vrPhysicsService.addKinematicObject(node, config)

Adds a kinematic object to the physics simulation.

A kinematic object is a physics object that is not affected by forces but can interact with other objects in the simulation and can be moved manually (manipulator, script, etc.). Valid configurations are vrdPhysicsHullConfig and vrdPhysicsConvexConfig.

Parameters:
Returns:

True if the object was added successfully, False otherwise.

Return type:

bool

vrPhysicsService.addStaticObject(node, config)

Adds a static object to the physics simulation.

A static object is a physics object that is not affected by forces and can’t be moved manually or by other objects. The only valid configuration for a static object is the triangle mesh configuration, see vrdPhysicsTrianglesConfig.

Parameters:
Returns:

True if the object was added successfully, False otherwise.

Return type:

bool

vrPhysicsService.clearCollisionData(node)

Clears the collision data for a node.

This function clears the persistent collision data for a node. The stored collision shapes of the node and all its children are removed. and will no longer be saved to the VPB file. This only affects the data that is stored with ‘vrPhysicsService.storeCollisionData(node)’. The collision shapes itself are not removed from the physics simulation, for that you need to use vrPhysicsService.removeObject(node).

Parameters:node (vrdNode) – The node to clear the collision data from.
Returns:True if the collision data could be cleared successfully, False otherwise.
Return type:bool
vrPhysicsService.clearFilters()

Clears all node filters from the physics simulation.

This function clears all node filters from the physics simulation. All nodes will be able to collide with each other after this function is called.

vrPhysicsService.connectDebugger(host='127.0.0.1', port=5425)

Connects the physics debugger.

This function connects the NVidia PhysX Visual Debugger to the physics simulation. The debugger must have been started before this function is called.

Parameters:
  • host (string) – The host address of the debugger (default: 127.0.0.1)
  • port (integer) – The port of the debugger (default: 5425)
vrPhysicsService.deregisterNodeFilter(node)

Deregisters a node filter from the physics simulation.

This function deregisters a node filter from the physics simulation. The node will be able to collide with other nodes after this function is called.

Parameters:node (vrdNode) – The node to deregister.
vrPhysicsService.deregisterNodePairFilter(node1, node2)

Deregisters a node pair filter from the physics simulation.

This function deregisters a node pair filter from the physics simulation. The nodes will be able to collide with each other after this function is called.

Parameters:
  • node1 (vrdNode) – The first node in the pair.
  • node2 (vrdNode) – The second node in the pair.
vrPhysicsService.disconnectDebugger()

Disconnects the physics debugger.

This function disconnects the NVidia PhysX Visual Debugger from the physics simulation.

vrPhysicsService.getKinematicObjects()

Gets all kinematic objects in the physics simulation.

Returns:List of all kinematic objects in the simulation.
Return type:List[vrdNode]
vrPhysicsService.getStaticObjects()

Gets all static objects in the physics simulation.

Returns:List of all static objects in the simulation.
Return type:List[vrdNode]
vrPhysicsService.hasCollisionData(node)

Checks if collision data is available for a node.

This function checks if collision data is available for a node. Collision data is available if the node has collision shapes stored in an attachment by using vrPhysicsService.storeCollisionData(node).

Parameters:node (vrdNode) – The node to check.
Returns:True if collision data is available, False otherwise.
Return type:bool
vrPhysicsService.hasPhysicsObject(node)

Checks if a node is registered in the physics simulation.

Parameters:node (vrdNode) – The node to check.
Returns:True if the node is registered, False otherwise.
Return type:bool
vrPhysicsService.isActive()

Returns if the simulation is currently active.

Returns:The active state.
Return type:bool
vrPhysicsService.registerNodeFilter(node)

Registers a node filter for the physics simulation.

This function registers a node filter for the physics simulation. The node filter is used to specify a node that should not collide with any other node. Can be used to temporarily disable collisions for a node without removing it from the simulation.

Parameters:node (vrdNode) – The node to filter.
vrPhysicsService.registerNodePairFilter(node1, node2)

Registers a node pair filter for the physics simulation.

This function registers a node pair filter for physics simulation. The node pair filter is used to specify a pair of nodes that should not collide with each other.

Parameters:
  • node1 (vrdNode) – The first node in the pair.
  • node2 (vrdNode) – The second node in the pair.
vrPhysicsService.removeAllObjects()

Removes all objects from the physics simulation.

vrPhysicsService.removeObject(node)

Removes an object from the physics simulation.

Parameters:node (vrdNode) – The node to remove.
Returns:True if the object was removed successfully, False otherwise.
Return type:bool
vrPhysicsService.restoreCollisionData(node)

Restores the collision data for a node.

This function restores the collision data for a node. The collision data includes the collision shapes of the node and all its children. The collision data is stored in an attachment of the node and must have been stored before. Collision data is versioned and platform specific. If the underlying physics engine changes, the collision data might not be compatible anymore and will be invalidated. The same is true if the collision data was saved on a different platform (e.g. Windows vs. Linux). In that case, the collision data will be discarded at load time and the re-created from the actual geometry of the node using the same parameters that were used when the data was saved. Afterwards the VPB can be saved again for the current platform.

Parameters:node (vrdNode) – The node to restore the collision data for.
Returns:True if the collision data was restored successfully, False otherwise.
Return type:bool
vrPhysicsService.setActive(state)

Sets the active state of the simulation.

If the simulation is active, physics objects will be updated in the simulation when they are moved.

Parameters:state (bool) – False to deactivate the simulation, True to activate it.
vrPhysicsService.storeCollisionData(node)

Stores the collision data for a node.

This function stores the collision data for a node into an attachment so that it can be saved in the VPB file. The collision data includes the collision shapes of the node and all its children.

Parameters:node (vrdNode) – The node to save the collision data for.
Returns:True if the collision data was saved successfully, False otherwise.
Return type:bool

Signals

vrPhysicsService.collisionContinues(info)

Signals that a collision is continuing.

This signal is emitted when a collision between two objects is still ongoing.

Parameters:info (vrdPhysicsInfo) – The physics information related to the collision. Contains the colliding nodes and their root nodes.
vrPhysicsService.collisionStarted(info)

Signals that a collision has started.

This signal is emitted when a collision between two objects is detected.

Parameters:info (vrdPhysicsInfo) – The physics information related to the collision. Contains the colliding nodes and their root nodes.
vrPhysicsService.collisionStopped(info)

Signals that a collision has stopped.

This signal is emitted when a collision between two objects has stopped.

Parameters:info (vrdPhysicsInfo) – The physics information related to the collision. Contains the formerly colliding nodes and their root nodes.