Colliders and Materials#

A collider gives an object a shape that other objects can hit. A material sets how that shape behaves when it touches something: how much it grips and how much it bounces.

Two cups made from the same U-shaped mesh stand on the ground, and a ball drops into each. On the left, the approximation is convexHull: one collision shape, drawn dashed, covers the cup's opening, so the ball stops on top. On the right, the approximation is convexDecomposition: three dashed hulls, two walls and a base, keep the hollow, so the ball falls in.

Making an Object Solid#

Apply PhysicsCollisionAPI to a shape prim, such as a Cube or a Mesh. On or below a rigid body, the collider moves with the body. Anywhere else, it is static, like the ground. Rigid Bodies compares the kinds.

Simple Shapes#

The prim types Cube, Sphere, Capsule, Cylinder, and Cone collide with exactly their own shape. Only a Cube can be stretched unevenly: for a box, scale a Cube. A Plane is an infinite flat ground, and it cannot be part of a dynamic body. Simple shapes are the cheapest and most stable choice, so use them when they fit.

Meshes#

A Mesh collider has an approximation: the shape that ovphysx builds from its triangles. To choose it, apply PhysicsMeshCollisionAPI to the mesh and set physics:approximation:

physics:approximation

Shape

Use It For

convexHull

One convex hull: the tightest shape without dents that wraps the mesh.

Moving objects without hollows, such as a rock.

convexDecomposition

Several convex hulls that together follow the mesh.

Moving objects with hollows, such as a cup.

none, the default

The triangles themselves.

Static and kinematic objects only, such as a room. On a dynamic body, ovphysx uses a convex hull instead.

sdf

A signed distance field: a grid that stores how far each point is from the surface.

Detailed moving objects that touch closely.

boundingCube, boundingSphere

A box or a sphere around the mesh.

Rough shapes that cost little.

Turning Collisions Off#

These settings make objects pass through each other:

To Stop

Use

One collider from colliding at all

physics:collisionEnabled = false on the collider.

Two particular objects from colliding with each other

PhysicsFilteredPairsAPI on one of them, with the relationship physics:filteredPairs naming the other.

Materials#

A physics material is a Material prim with PhysicsMaterialAPI. It holds these values:

Attribute

Meaning

physics:staticFriction

How hard it is to start sliding.

physics:dynamicFriction

How strongly friction slows an object that already slides.

physics:restitution

How much an object bounces: 0 does not bounce, and 1 bounces back as fast as it hit.

physics:density

Mass per volume, such as kg/m³. Rigid Bodies shows when ovphysx uses it.

To give a collider a material, apply MaterialBindingAPI to it and point the relationship material:binding:physics at the material. A binding on a body prim applies to every collider below it. A collider without a material uses the default one: both frictions 0.5 and no bounce.

Set every value you need: a friction or restitution that the material leaves out is 0.

When two colliders touch, PhysX averages the values of their two materials, unless a material sets another combine mode with PhysxMaterialAPI, as the program in Three Bouncing Balls does.

Three Bouncing Balls#

The following program, colliders_and_materials_bounce.py, drops three balls whose materials differ only in restitution:

The imports and the scene, in USD
import ovstage
from ovphysx.population import physics_population_descs
from ovphysx import PhysX
from ovphysx.samples.python_samples.schema_support import physx_schema_paths
from ovphysx.types import SimObjectType

# Three balls with a radius of 0.1 m. Each ball's lowest point starts 1 m
# above the ground. Each ball has its own material; only the restitution
# differs.
SCENE = """#usda 1.0
(
    metersPerUnit = 1
    kilogramsPerUnit = 1
    upAxis = "Z"
)

def Xform "World"
{
    def PhysicsScene "PhysicsScene" {}

    def Plane "Ground" (
        prepend apiSchemas = ["PhysicsCollisionAPI"]
    )
    {
        uniform token axis = "Z"
    }

    def Material "Clay" (
        prepend apiSchemas = ["PhysicsMaterialAPI", "PhysxMaterialAPI"]
    )
    {
        float physics:restitution = 0.0
        uniform token physxMaterial:restitutionCombineMode = "max"
    }

    def Material "Rubber" (
        prepend apiSchemas = ["PhysicsMaterialAPI", "PhysxMaterialAPI"]
    )
    {
        float physics:restitution = 0.5
        uniform token physxMaterial:restitutionCombineMode = "max"
    }

    def Material "Superball" (
        prepend apiSchemas = ["PhysicsMaterialAPI", "PhysxMaterialAPI"]
    )
    {
        float physics:restitution = 0.9
        uniform token physxMaterial:restitutionCombineMode = "max"
    }

    def Sphere "ClayBall" (
        prepend apiSchemas = ["PhysicsRigidBodyAPI", "PhysicsCollisionAPI",
                              "MaterialBindingAPI"]
    )
    {
        double radius = 0.1
        double3 xformOp:translate = (-0.5, 0, 1.1)
        uniform token[] xformOpOrder = ["xformOp:translate"]
        rel material:binding:physics = </World/Clay>
    }

    def Sphere "RubberBall" (
        prepend apiSchemas = ["PhysicsRigidBodyAPI", "PhysicsCollisionAPI",
                              "MaterialBindingAPI"]
    )
    {
        double radius = 0.1
        double3 xformOp:translate = (0, 0, 1.1)
        uniform token[] xformOpOrder = ["xformOp:translate"]
        rel material:binding:physics = </World/Rubber>
    }

    def Sphere "SuperBall" (
        prepend apiSchemas = ["PhysicsRigidBodyAPI", "PhysicsCollisionAPI",
                              "MaterialBindingAPI"]
    )
    {
        double radius = 0.1
        double3 xformOp:translate = (0.5, 0, 1.1)
        uniform token[] xformOpOrder = ["xformOp:translate"]
        rel material:binding:physics = </World/Superball>
    }
}
"""


def lowest_points(physx):
    """Return the height of each ball's lowest point, keyed by the ball's path."""
    heights = {}
    with physx.read_sync(SimObjectType.RIGID_BODY, ["position"]) as result:
        for group in result.groups:
            paths = result.dictionary.get_path_strings(group.prim_list)
            centers = group.tensors[0].numpy()[:, 2]
            for path, center in zip(paths, centers):
                heights[path] = float(center) - 0.1  # subtract the radius
    return heights


ovstage.population.register_usd_schemas([str(p) for p in physx_schema_paths()])

stage = ovstage.Stage("bouncing_balls")
ovstage.population.open_usd_from_string_with_desc(
    stage, SCENE, ordinal=1, time=ovstage.population.DEFAULT_TIME, descs=physics_population_descs(rendering=True)
)
stage.advance_write_floor(ordinal=1).wait()

physx = PhysX()
physx.wait_task(physx.attach_ovstage(stage, read_ordinal=1))

# The balls reach the ground after about 0.45 s. From 0.5 s on, keep each
# ball's highest point: the top of its first bounce.
peaks = {}
for step in range(1, 91):
    physx.step_sync(1.0 / 60.0)
    if step >= 30:
        for path, height in lowest_points(physx).items():
            peaks[path] = max(peaks.get(path, 0.0), height)

for path in sorted(peaks):
    print(f"{path} bounces back to {peaks[path]:.3f} m")

physx.wait_task(physx.detach_ovstage())
physx.destroy()
stage.destroy()

It prints how high each ball bounces back:

/World/ClayBall bounces back to 0.000 m
/World/RubberBall bounces back to 0.249 m
/World/SuperBall bounces back to 0.806 m

Three balls with a restitution of 0.0, 0.5, and 0.9 fall from 1 m onto the ground. The first does not bounce. The second bounces back to 0.249 m and the third to 0.806 m, and a faint circle marks the top of each bounce.

Notice the following:

  • A ball bounces back to about its restitution squared times the drop height: 0.5 × 0.5 × 1 m = 0.25 m, and 0.9 × 0.9 × 1 m = 0.81 m.

  • The ground has no material, so its restitution is 0. Each ball’s material sets restitutionCombineMode = "max", so every contact uses the ball’s restitution, not the average.

More Detail#