Package Jitter

jit.phys.world

Collision detection and rigid body dynamics

Description

The jit.phys.world object encapsulates a physics simulation context to perform collision detection and rigid body dynamics on its child objects. Other physics objects in the same patch as a jit.phys.world object are automatically added to the world. Multiple contexts can be managed by explicitly setting the name attribute of the jit.phys.world object and the worldname attribute of the child physics objects. Dynamics can be disabled, allowing the world to be used solely for collision detections. A 2D simulation is achieved with the remove_plane attribute.

Discussion

The physics engine maintains an internal timer for simulation steps that decouples the physics step frequency from the rendering frame rate. The fixedtimestep attribute controls the physics engine frequency, and the maxsubsteps attribute clamps the number of steps allowed between updates. The default frequency of 60 and maxsubsteps of 1 requires a FPS of 60. If the FPS is 30, maxsubsteps should be increased (allowing for more than 1 simulation step each update). If the simulation is behaving incorrectly (rigid body penetration, erratic movement, etc), try increasing the simulation frequency and sub-steps.

Attributes

automatic[int]

Enables and disables automatic mode where update messages are received from that target jit.gl.render object (default = 1).

collision_mode[symbol]

Specifies the format of the collisions dictionary (default = simple) Possible values:

'simple' ( Report contact point positions and normals average )
'complete' ( All contact point position and normals reported )

collisions[int]

Enables and disables collision reporting out the second (dumpout) outlet.

drawto[symbol]

Assign to the named drawing context, allowing for updates to be received automatically.

dynamics[int]

Enables and disables rigid-body dynamics.

enable[int]

Enable the physics simulation for all objects in this physics context (default = 1).

fixed_delta[float]

Fixed Delta Time

fixedtimestep[int]

Fixed time step value (Hz) of physics simulation (default = 60). Increasing this value increases the resolution of the simulation.

gravity[3 floats]

A 3D vector describes the force of gravity applied to all objects in the world (default = 0, -9.8, 0).

maxsubsteps[int]

Maximum number of internal simulation steps between updates (default = 1). Increase this number if FPS is low in order to prevent the simulation from losing time.

name[symbol]

Specifies the name of the instance (default = UID).

numcollisions[int]
read-only

Specifies the number of collision points in the world.

numthreads[int]

Sets the number of collison dispatcher threads (default = 1). Increasing the number of threads may improve performance, especially for physics scenes with distinct and separate groups of colliding objects.

raytest_mode[symbol]

Specifies how raytest messages return object hits for the raytest and screenraytest messages (default = closest) Possible values:

'closest' ( Return only the object closest to the camera )
'all' ( Return all intersecting objects )

remove_plane[int]

Remove plane to enable 2D simulation (default = none). Possible values:

0 = 'none'
1 = 'x' ( Constrain simulation to Y and Z planes )
2 = 'y' ( Constrain simulation to X and Z planes )
3 = 'z' ( Constrain simulation to X and Y planes )

split_impulse[int]

Enables and disables split impulse dynamics (default = 1). When enabled, split impulse will allow the dynamics solver to apply positional corrections when deep collision penetrations occur.

targetname[symbol]

Specifies the name of a jit.gl.render object to receive update messages from.

worldbox[int]

Enables and disables the world bounds. (default = 1)

worldbox_scale[3 floats]

Changes the size and shape of the world bounds (default = 5, 5, 5).

Common Box Attributes

Below is a list of attributes shared by all objects. If you want to change one of these attributes for an object based on the object box, you need to place the word sendbox in front of the attribute name, or use the object's Inspector.

annotation[symbol]

Sets the text that will be displayed in the Clue window when the user moves the mouse over the object.

background[int]: 0

Adds or removes the object from the patcher's background layer. background 1 adds the object to the background layer, background 0 removes it. Objects in the background layer are shown behind all objects in the default foreground layer.

color[4 floats]

Sets the color for the object box outline.

fontface[int]

Sets the type style used by the object. The options are:

plain
bold
italic
bold italic Possible values:

0 = 'regular'
1 = 'bold'
2 = 'italic'
3 = 'bold italic'

fontname[symbol]

Sets the object's font.

fontsize[float]

Sets the object's font size (in points). Possible values:

'8'
'9'
'10'
'11'
'12'
'13'
'14'
'16'
'18'
'20'
'24'
'30'
'36'
'48'
'64'
'72'

hidden[int]: 0

Toggles whether an object is hidden when the patcher is locked.

hint[symbol]

Sets the text that will be displayed in as a pop-up hint when the user moves the mouse over the object in a locked patcher.

ignoreclick[int]: 0

Toggles whether an object ignores mouse clicks in a locked patcher.

jspainterfile[symbol]

JS Painter File

patching_rect[4 floats]: 0. 0. 100. 0.

Sets the position and size of the object in the patcher window.

position[2 floats]
write-only

Sets the object's x and y position in both patching and presentation modes (if the object belongs to its patcher's presentation), leaving its size unchanged.

presentation[int]: 0

Sets whether an object belongs to the patcher's presentation.

presentation_rect[4 floats]: 0. 0. 0. 0.

Sets the x and y position and width and height of the object in the patcher's presentation, leaving its patching position unchanged.

rect[4 floats]
write-only

Sets the x and y position and width and height of the object in both patching and presentation modes (if the object belongs to its patcher's presentation).

size[2 floats]
write-only

Sets the object's width and height in both patching and presentation modes (if the object belongs to its patcher's presentation), leaving its position unchanged.

textcolor[4 floats]

Sets the color for the object's text in RGBA format.

textjustification[int]

Sets the justification for the object's text. Possible values:

0 = 'left'
1 = 'center'
2 = 'right'

varname[symbol]

Sets the patcher's scripting name, which can be used to address the object by name in pattr, scripting messages to thispatcher, and the js object.

Messages

bang

Causes the world to perform a single step of the physics simulation, test and report collisions, and update all child objects.

raytest

Perform ray-testing on the rigid bodies using the passed in ray endpoints, and report colliding objects out the right-hand (dumpout) outlet of the object, followed by the relative intersection position and world-space intersection. See raytest_mode for more info.

Arguments:
  • x-from [float]
  • y-from [float]
  • z-from [float]
  • x-to [float]
  • y-to [float]
  • z-to [float]

reset

Reset the simulation including dynamic and kinematic rigid bodies.

screenraytest

Perform ray-testing on the rigid bodies using the passed in screen coords. The ray start point is taken by converting the screen coords to world-space, and the end point is generated by casting a ray from the camera position, through the start point to the camera far clip plane. The colliding objects name is reported out the right-hand (dumpout) outlet of the object, followed by the relative intersection position and world-space intersection. See raytest_mode for more info.

Arguments:
  • screen-x [float]
  • screen-y [float]

See Also

Name Description
jit.phys.body A rigid body and collision shape
jit.phys.multiple Uses matrices to simulate multiple rigid bodies
jit.phys.ghost A collision sensor and forcefield
jit.phys.picker Constraint picking in a physics world
jit.gl.physdraw A physics opengl debug drawer