ProtoTwin API
    Preparing search index...

    Class PhysicsComponent

    A core component that provides an entity with 3D physics.

    Hierarchy (View Summary)

    Index

    Properties

    entity: Entity

    The entity to which the component is attached.

    Accessors

    • get angularDamping(): number

      The angular damping for the rigid body.

      Returns number

    • set angularDamping(value: number): void

      Parameters

      • value: number

      Returns void

    • get angularVelocity(): Vec3

      The angular velocity for the rigid body.

      Returns Vec3

    • set angularVelocity(value: Vec3): void

      Parameters

      Returns void

    • get attached(): boolean

      Whether the component is attached to its entity.

      Returns boolean

    • get axisLocks(): AxisLock

      The motion restrictions for the dynamic rigid body.

      Returns AxisLock

    • set axisLocks(value: AxisLock): void

      Parameters

      Returns void

    • get body(): Body

      The rigid body type.

      Returns Body

    • set body(value: Body): void

      Parameters

      Returns void

    • get contactOffset(): number

      The contact offset.

      Returns number

      Colliders whose distance is less than the sum of their contact offsets will generate contact points, helping to prevent instability/jitter. When the default value of -1 is used, an appropriate contact offset is automatically determined based on the dimensions of the graphics mesh.

    • set contactOffset(value: number): void

      Parameters

      • value: number

      Returns void

    • get initialized(): boolean

      Whether the component has been initialized.

      Returns boolean

    • get io(): null | IO

      The IO signals provided by the component.

      Returns null | IO

    • get joints(): null | readonly Joint[]

      The collection of joints.

      Returns null | readonly Joint[]

    • get linearDamping(): number

      The linear damping for the rigid body.

      Returns number

    • set linearDamping(value: number): void

      Parameters

      • value: number

      Returns void

    • get linearVelocity(): Vec3

      The linear velocity for the rigid body.

      Returns Vec3

    • set linearVelocity(value: Vec3): void

      Parameters

      Returns void

    • get mass(): number

      The mass for the rigid body.

      Returns number

      Avoid large mass ratios where possible to prevent instability.

    • set mass(value: number): void

      Parameters

      • value: number

      Returns void

    • get massDistribution(): null | MassDistribution

      The mass distribution (center of mass and inertia tensor) for the rigid body in the local-space of the entity.

      Returns null | MassDistribution

      When set to null (default), the mass distribution is automatically determined from the collision geometry and mass, assuming uniform density. You can use MassDistribution.fromPhysics to get the actual mass distribution when this is the case. It may sometimes be beneficial to increase the inertia tensor in order improve stability. The InertiaTensor.scaleUniform function can be used for this purpose.

    • set massDistribution(value: null | MassDistribution): void

      Parameters

      Returns void

    • get name(): string

      The component name.

      Returns string

    • set name(value: string): void

      Parameters

      • value: string

      Returns void

    • get restOffset(): number

      The rest offset.

      Returns number

      Two colliders will come to rest at a distance equal to the sum of their rest offsets. A small positive rest offset can help colliders to slide over each other more easily, preventing snagging on irregularities in the collision geometry. Must be less than the contact offset.

    • set restOffset(value: number): void

      Parameters

      • value: number

      Returns void

    • get world(): World

      The virtual world to which the owning entity belongs.

      Returns World

    Methods

    • Added function called immediately after the component is attached to an entity.

      Returns void

    • Adds a fixed joint.

      Parameters

      • Optionalbase: Entity

        The base entity, to which the other end of the joint is attached.

      Returns Joint

      The joint.

    • Adds a joint.

      Parameters

      • constraint: Constraint

        The constraint type.

      • axis: IVec3

        The local axis for the constraint.

      • anchor: IVec3

        The local position for the constraint.

      • Optionalbase: Entity

        The base entity, to which the other end of the joint is attached.

      Returns Joint

      The joint.

    • Adds a path joint.

      Parameters

      • anchor: IVec3

        The local anchor.

      • Optionalbase: Entity

        The base entity, to which the other end of the joint is attached.

      Returns Joint

      The joint.

    • Adds a prismatic joint.

      Parameters

      • axis: IVec3

        The local axis, which defines the direction in which the entity is allowed to move.

      • Optionalbase: Entity

        The base entity, to which the other end of the joint is attached.

      Returns Joint

      The joint.

    • Adds a revolute joint.

      Parameters

      • axis: IVec3

        The local axis, which defines the plane in which the entity is allowed to move.

      • anchor: IVec3

        The local anchor, which defines the point about which the entity is allowed to rotate.

      • Optionalbase: Entity

        The base entity, to which the other end of the joint is attached.

      Returns Joint

      The joint.

    • Adds a spherical joint.

      Parameters

      • anchor: IVec3

        The local anchor, which defines the point about which the entity is allowed to rotate.

      • Optionalbase: Entity

        The base entity, to which the other end of the joint is attached.

      Returns Joint

      The joint.

    • Applies a force to the rigid body's center-of-mass.

      Parameters

      • force: IVec3

        The force to be applied.

      • space: ForceSpace = ForceSpace.Local

        The (optional) coordinate system for the force vector.

      Returns void

      If the coordinate space is not provided then the force is assumed to be in the entity's local-space.

    • Applies a force to the rigid body acting at the specified point.

      Parameters

      • force: IVec3

        The force to be applied.

      • point: IVec3

        The point at which the force is applied.

      • space: ForceSpace = ForceSpace.Local

        The (optional) coordinate system for the force and point.

      Returns void

      If the coordinate space is not provided then the force and point are assumed to be in the entity's local-space.

    • Applies a torque to the rigid body's center-of-mass.

      Parameters

      • torque: IVec3

        The torque vector.

      • space: ForceSpace = ForceSpace.Local

        The (optional) coordinate system for the torque vector.

      Returns void

      If the coordinate space is not provided then the torque is assumed to be in the entity's local-space.

    • Creates a handle (weak reference) to a trackable object.

      Type Parameters

      Parameters

      • type: TrackableType<T>

        The type of object that is to be referenced.

      • value: null | T = null

        The object that is initially referenced by the handle.

      Returns Handle<T>

      A handle to a trackable object.

      Handles created through this function are automatically cleared when the component is detached/removed.

    • Asynchronous initialization function called immediately before simulating when the model is initialized.

      Returns Promise<void>

    • Post-update function called after physics has been updated.

      Parameters

      • dt: number

        The timestep (seconds).

      Returns void

    • Asynchronous post-update function called after physics has been updated.

      Parameters

      • dt: number

        The timestep (seconds).

      Returns Promise<void>

    • Removes the specified joint.

      Parameters

      Returns boolean

      True if the joint was removed, false otherwise.

    • Immediately triggers asynchronous initialization if the component hasn't already been initialized.

      Returns Promise<void>

      This can be used in cases where one component references another in its asynchronous initialize function, but it is required that the referenced component has already been asynchronously initialized.

    • Immediately triggers initialization if the component hasn't already been initialized.

      Returns void

      This can be used in cases where one component references another in its initialize function, but it is required that the referenced component has already been initialized.

    • Subscribes to a subscribable object.

      Subscriptions created through this function are automatically unsubscribed when the component is detached/removed.

      Type Parameters

      • T

      Parameters

      • object: Subscribable<T>

        The subscribable object for which to subscribe.

      • subscriber: Subscriber<T>

        The callback function that is triggered when the object's value is updated.

      Returns void

    • Unsubscribes from a subscribable object.

      Type Parameters

      • T

      Parameters

      • object: Subscribable<T>

        The object from which to unsubscribe.

      • subscriber: Subscriber<T>

        The callback function for the subscription.

      Returns boolean

      True if the subscription was canceled, false otherwise.

    • Update function called every timestep when simulating.

      Parameters

      • dt: number

        The timestep (seconds).

      Returns void

    • Asynchronous update function called every timestep when simulating.

      Parameters

      • dt: number

        The timestep (seconds).

      Returns Promise<void>