Rigid Bodies

ProtoTwin can simulate rigid bodies, which are idealized bodies that do not deform. Rigid bodies may be dynamic or kinematic. It is important to understand the difference between these for knowing when each type should be used.

Types

Dynamic

Dynamic rigid bodies are bodies that have a finite mass and inertia tensor. They can be influenced by forces such as gravity and respond to collisions with other rigid bodies. Dynamic rigid bodies are typically used for parts that move through a machine, or for parts that are moved by joints or driven by motors.

Kinematic

Kinematic rigid bodies are bodies that have infinite mass. They are not influenced by forces and can only be moved by setting their velocity or position. They can influence dynamic rigid bodies through collisions, but are not themselves influenced by collisions. Kinematic rigid bodies are typically used for parts of a machine that can be assumed to be physically fixed or grounded, such as conveyors.

Attached

Attached rigid bodies specify that the entity should have no rigid body, but that its collider should be attached to the rigid body of the nearest ancestor entity in the hierarchy. This can be used to create compound/composite collision geometry, such as a table consisting of a table top and four legs.

Mass and Inertia

The mass for the rigid body can be specified directly in the inspector. The inertia tensor is calculated automatically from the collision geometry attached to the rigid body. Interactions (constraints) involving rigid bodies with high mass ratios require many iterations to converge. It is recommended that you reduce mass ratios where possible, and increase the number of solver iterations to improve stability when necessary.

Damping

Linear and angular damping can be used to approximate air resistance and joint friction. The value of the coefficients specify 1 / t, where t represents the time over which the body should lose half its velocity.

Axis Locks

Translation and rotation for a rigid body can be restricted in and about one or more of the global axes respectively. This can be used to restrict motion to a 2D plane, or to disable rotation entirely.

Velocity

Dynamic and kinematic rigid bodies have a linear and angular velocity. You can query these velocities at any time using a custom scripted component. There are also linear velocity sensor and angular velocity sensor components, which provide signal outputs for reading the velocity values from PLCs and/or Python clients.

import { Component, type Entity, type Handle, PhysicsComponent } from "prototwin";

export class VelocitySensor extends Component {
    public physics: Handle<PhysicsComponent> = this.handle(PhysicsComponent);

    constructor(entity: Entity) {
        super(entity);
    }

    public override postUpdate(dt: number) {
        // Use postUpdate() to get the velocities after the physics timestep has been completed.
        const component = this.physics.value;
        if (component !== null) {
            const linear = component.linearVelocity;
            const angular = component.angularVelocity;
        }
    }
}

Force / Torque

A force/torque can be applied to dynamic rigid bodies using a custom scripted component. You can apply these at the center-of-mass or at an aribtrary position.

import { Component, type Entity, type Handle, PhysicsComponent, Vec3, ForceSpace } from "prototwin";

export class ApplyForce extends Component {
    public physics: Handle<PhysicsComponent> = this.handle(PhysicsComponent);

    constructor(entity: Entity) {
        super(entity);
    }

    public override update(dt: number) {
        // Use update() to apply forces in the current physics timestep.
        const component = this.physics.value;
        if (component !== null) {
            component.applyForce(new Vec3(10, 0, 0), ForceSpace.World);
            component.applyTorque(new Vec3(0, 0, 2), ForceSpace.Local);
        }
    }
}

Hierarchy

ProtoTwin supports hierarchies of rigid bodies, which generally isn’t reliably supported by other industrial simulation software. If a child entity has a rigid body then any movement of the parent due to physics doesn’t affect the child. This can be useful if your CAD is organized into a hiararchy, such as boxes stacked on a pallet.