Physics & Constraints

These puzzles are used to simulate physics behavior and restrict the movement of objects. As backend, Verge3D uses the open source physics engine Bullet (aka ammo.js).

Getting Started With Physics

Before you can use these Puzzles, you must add the physics module to your application. You can do this at the app creation stage using the corresponding option in the App Manager.

Alternatively, you can add the physics module to an existing app. To do this, copy the file ammo.js from the verge3d/build folder to your app folder, and add the line

<script src="ammo.js"></script>

to your application .html file just above the v3d.js script statement.

General Recommendations

Physics Puzzles

"create physics world"

Initializes the physics engine using the specified gravity and frame-per-second parameters. The default gravity value of 9.8 corresponds to Earth surface conditions. Zero value means no gravity as in space. The higher fps value the better simulation quality at the expense of performance.

Under the hood, this puzzle also enables collision detection and automatic synchronization with graphics.

"create physics body"

Creates a physics body from a specified object, of Dynamic, Kinematic or Static type. Assigns the collision shape: Box, Sphere or Mesh. Sets the mass for the body (valid for Dynamic bodies only). Also works for a list of objects, a group (or a list of groups) or with the all objects puzzle.

Physics body types:

"remove physics body"

Removes physics from a specified object by destroying the physics body associated with it. Also works for a list of objects, a group (or a list of groups) or with the all objects puzzle.

"physics body params"

Sets parameters for the physics body associated with a specified object. Also works for a list of objects, a group (or a list of groups) or with the all objects puzzle.

Parameters:

When two bodies collide, friction and restitution parameters of both of them are taken into consideration.

"apply vector"

Applies Force, Gravity, Linear Velocity, Angular Velocity, Impulse, Torque, Torque Impulse or Position to the physics body associated with a specified object, in a specified direction in world space. Also works for a list of objects, a group (or a list of groups) or with the all objects puzzle.

Parameters:

"snap body"

Moves a physics body associated with a specified object, and the object itself, to the position of another object by copying its transform data. Also copies rotation. Does not work with lists, groups or the "all objects" puzzle.

Works similar to apply vector / Position puzzle.

"detect collisions" and "collision info"

Detects if there is a collision at the moment of a specified body with another body (or any body from a list or a group). If there is a collision, the puzzles in the "if touching do" slot are triggered, otherwise - in the "if not touching do".

The "detect collisions" puzzle triggers either of its callback slots every rendering frame.

The collision info puzzle outputs a dictionary with the following fields:

Constraints Puzzles

If an object is not parented to another object, the constraints will work in world space. Otherwise they will work in the parent object's space - you can select the parent object in 3ds Max or Blender to show up the coordinate axes.

"limit transform"

Creates a constraint to limit object position, rotation or scale along a selected axis. Constraint id should be unique, otherwise an existing constraint with the same id will be replaced. The min and max slots specify the range between which the movement is allowed.

"copy transform"

Creates a constraint to copy object position, rotation or scale from another object. Constraint id should be unique, otherwise an existing constraint with the same id will be replaced.

"remove / mute / unmute constraint"

Removes, mutes or unmutes a constraint assigned to a specified object. Other constraints assigned to this object (if any) will remain intact.