World Class
The physics world
Constructor
World
()
Item Index
Methods
- add deprecated
- addConstraint
- addContactMaterial
- addEventListener
- addMaterial
- clearForces
- collisionMatrixTick
- dispatchEvent
- getContactMaterial
- hasEventListener
- numObjects deprecated
- raycastAll
- raycastAny
- raycastClosest
- rayTest deprecated
- remove deprecated
- removeBody
- removeConstraint
- removeEventListener
- step
- step
Methods
addEventListener
-
type
-
listener
Add an event listener
Parameters:
-
type
String -
listener
Function
Returns:
The self object, for chainability.
clearForces
()
Sets all body forces in the world to zero.
collisionMatrixTick
()
Store old collision state info
dispatchEvent
-
event
Emit an event.
Parameters:
-
event
Object-
type
String
-
Returns:
The self object, for chainability.
getContactMaterial
-
m1
-
m2
Get the contact material between materials m1 and m2
Returns:
The contact material if it was found.
hasEventListener
-
type
-
listener
Check if an event listener is added
Parameters:
-
type
String -
listener
Function
Returns:
numObjects
()
Number
deprecated
Get number of objects in the world.
Returns:
raycastAll
-
from
-
to
-
options
-
callback
Ray cast against all bodies. The provided callback will be executed for each hit with a RaycastResult as single argument.
Parameters:
Returns:
True if any body was hit.
raycastAny
-
from
-
to
-
options
-
result
Ray cast, and stop at the first result. Note that the order is random - but the method is fast.
Parameters:
-
from
Vec3 -
to
Vec3 -
options
Object-
[collisionFilterMask=-1]
Number optional -
[collisionFilterGroup=-1]
Number optional -
[skipBackfaces=false]
Boolean optional -
[checkCollisionResponse=true]
Boolean optional
-
-
result
RaycastResult
Returns:
True if any body was hit.
raycastClosest
-
from
-
to
-
options
-
result
Ray cast, and return information of the closest hit.
Parameters:
-
from
Vec3 -
to
Vec3 -
options
Object-
[collisionFilterMask=-1]
Number optional -
[collisionFilterGroup=-1]
Number optional -
[skipBackfaces=false]
Boolean optional -
[checkCollisionResponse=true]
Boolean optional
-
-
result
RaycastResult
Returns:
True if any body was hit.
rayTest
-
from
-
to
-
result
Raycast test
Parameters:
-
from
Vec3 -
to
Vec3 -
result
Function | RaycastResult
removeEventListener
-
type
-
listener
Remove an event listener
Parameters:
-
type
String -
listener
Function
Returns:
The self object, for chainability.
step
-
dt
-
[timeSinceLastCalled]
-
[maxSubSteps=10]
Step the physics world forward in time.
There are two modes. The simple mode is fixed timestepping without interpolation. In this case you only use the first argument. The second case uses interpolation. In that you also provide the time since the function was last used, as well as the maximum fixed timesteps to take.
Parameters:
-
dt
NumberThe fixed time step size to use.
-
[timeSinceLastCalled]
Number optionalThe time elapsed since the function was last called.
-
[maxSubSteps=10]
Number optionalMaximum number of fixed steps to take per function call.
Example:
// fixed timestepping without interpolation
world.step(1/60);
step
-
dt
Step the simulation
Parameters:
-
dt
Number
Properties
allowSleep
Boolean
Makes bodies go to sleep when they've been inactive
bodies
Array
constraints
Array
contactmaterials
Array
contactMaterialTable
TupleDictionary
Used to look up a ContactMaterial given two instances of Material.
contacts
Array
All the current contacts (instances of ContactEquation) in the world.
defaultContactMaterial
ContactMaterial
This contact material is used if no suitable contactmaterial is found for a contact.
doProfiling
Boolean
dt
Number
Currently / last used timestep. Is set to -1 if not available. This value is updated before each internal step, which means that it is "fresh" inside event callbacks.
materials
Array
All added materials
profile
Object
quatNormalizeFast
Boolean
Set to true to use fast quaternion normalization. It is often enough accurate to use. If bodies tend to explode, set to false.
quatNormalizeSkip
Number
How often to normalize quaternions. Set to 0 for every step, 1 for every second etc.. A larger value increases performance. If bodies tend to explode, set to a smaller value (zero to be sure nothing can go wrong).
stepnumber
Number
Number of timesteps taken since start
subsystems
Array
time
Number
The wall-clock time since simulation start