docs.unity3d.com
    Show / Hide Table of Contents

    Class GraphicalSmoothingUtility

    Utility functions for smoothing the motion of rigid bodies' graphical representations when physics steps at a lower frequency than rendering.

    Inheritance
    Object
    GraphicalSmoothingUtility
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.Physics.GraphicsIntegration
    Syntax
    public static class GraphicalSmoothingUtility

    Methods

    BuildLocalToWorld(Int32, RigidTransform, Single, Boolean, NativeArray<PostTransformMatrix>)

    Construct a LocalToWorld matrix for a rigid body's graphical representation.

    Declaration
    public static LocalToWorld BuildLocalToWorld(int i, RigidTransform transform, float uniformScale, bool hasPostTransformMatrix, NativeArray<PostTransformMatrix> postTransformMatrices)
    Parameters
    Type Name Description
    Int32 i

    The index of the rigid body in the chunk.
    Used to look up the body's PostTransformMatrix component in the provided postTransformMatrices array, if any (see hasPostTransformMatrix parameter).

    RigidTransform transform

    The body's world space transform.

    Single uniformScale

    The body's uniform scale.

    Boolean hasPostTransformMatrix

    true if the rigid body has a PostTransformMatrix component; otherwise, false.

    NativeArray<PostTransformMatrix> postTransformMatrices

    The array of post transform matrices in the chunk.

    Returns
    Type Description
    LocalToWorld

    A LocalToWorld matrix to use in place of those produced by default.

    Extrapolate(in RigidTransform, in PhysicsVelocity, in PhysicsMass, Single)

    Compute a simple extrapolated transform for the graphical representation of a rigid body using its currentTransform and currentVelocity. Because bodies' motion may change the next time physics steps (e.g., as the result of a collision), using this method can mis-predict their future locations, causing them to appear to snap into place the next time physics steps. It generally results in a solid contact and kick from collisions, albeit with some interpenetration, as well as slight jitter on small, smooth velocity changes (e.g., the top of a parabolic arc).

    Simulation:                Graphical Extrapolation:
    
                  O (t=2)                     O (t=2)
    (t=0) O      /               (t=0) O     o
           \    /                       o   o
            \  O (t=1)                   o O (t=1)
    _________\/_________       ___________o________
                                           o
    Declaration
    public static RigidTransform Extrapolate(in RigidTransform currentTransform, in PhysicsVelocity currentVelocity, in PhysicsMass mass, float timeAhead)
    Parameters
    Type Name Description
    RigidTransform currentTransform

    The transform of the rigid body after physics has stepped (i.e., the value of its LocalTransform components).

    PhysicsVelocity currentVelocity

    The velocity of the rigid body after physics has stepped (i.e., the value of its PhysicsVelocity component).

    PhysicsMass mass

    The body's PhysicsMass component.

    Single timeAhead

    A value indicating how many seconds the current elapsed time for graphics is ahead of the elapsed time when physics last stepped.

    Returns
    Type Description
    RigidTransform

    An extrapolated transform for a rigid body's graphical representation, suitable for constructing its LocalToWorld matrix before rendering. See also BuildLocalToWorld(Int32, RigidTransform, Single, Boolean, NativeArray<PostTransformMatrix>).

    Interpolate(in RigidTransform, in RigidTransform, Single)

    Compute a simple interpolated transform for the graphical representation of a rigid body between previousTransform and currentTransform. Because bodies' motion is often deflected during a physics step when there is a contact event, using this method can make bodies appear to change direction before a collision is actually visible.

    Simulation:                Graphical Interpolation:
    
                  O (t=2)                     O (t=2)
    (t=0) O      /               (t=0) O     o
           \    /                        o  o
            \  O (t=1)                     O (t=1)
    _________\/_________       ____________________

    (Note that for cartoons, an animator would use squash and stretch to force a body to make contact even if it is technically not hitting on a specific frame.) See InterpolateUsingVelocity(in RigidTransform, in PhysicsVelocity, in PhysicsVelocity, in PhysicsMass, Single, Single) for an alternative approach.

    Declaration
    public static RigidTransform Interpolate(in RigidTransform previousTransform, in RigidTransform currentTransform, float normalizedTimeAhead)
    Parameters
    Type Name Description
    RigidTransform previousTransform

    The transform of the rigid body before physics stepped.

    RigidTransform currentTransform

    The transform of the rigid body after physics has stepped (i.e., the value of its LocalTransform components).

    Single normalizedTimeAhead

    A value in the range [0, 1] indicating how many seconds the current elapsed time for graphics is ahead of the elapsed time when physics last stepped, as a proportion of the fixed timestep used by physics.

    Returns
    Type Description
    RigidTransform

    An interpolated transform for a rigid body's graphical representation, suitable for constructing its LocalToWorld matrix before rendering. See also BuildLocalToWorld(Int32, RigidTransform, Single, Boolean, NativeArray<PostTransformMatrix>).

    InterpolateUsingVelocity(in RigidTransform, in PhysicsVelocity, in PhysicsVelocity, in PhysicsMass, Single, Single)

    Compute an interpolated transform for the graphical representation of a rigid body between its previous transform and current transform, integrating forward using an interpolated velocity value. This method tries to achieve a compromise between the visual artifacts of Interpolate(in RigidTransform, in RigidTransform, Single) and Extrapolate(in RigidTransform, in PhysicsVelocity, in PhysicsMass, Single). While integrating forward using previousVelocity alone would exhibit behavior similar to Extrapolate(in RigidTransform, in PhysicsVelocity, in PhysicsMass, Single), doing so in conjunction with previousTransform results in smoother motion for small velocity changes. Collisions can still appear premature when physics has a low tick rate, however, as when using Interpolate(in RigidTransform, in RigidTransform, Single).

    Declaration
    public static RigidTransform InterpolateUsingVelocity(in RigidTransform previousTransform, in PhysicsVelocity previousVelocity, in PhysicsVelocity currentVelocity, in PhysicsMass mass, float timeAhead, float normalizedTimeAhead)
    Parameters
    Type Name Description
    RigidTransform previousTransform

    The transform of the rigid body before physics stepped.

    PhysicsVelocity previousVelocity

    The velocity of the rigid body before physics stepped.

    PhysicsVelocity currentVelocity

    The velocity of the rigid body after physics has stepped (i.e., the value of its PhysicsVelocity component).

    PhysicsMass mass

    The body's PhysicsMass component.

    Single timeAhead

    A value indicating how many seconds the current elapsed time for graphics is ahead of the elapsed time when physics last stepped.

    Single normalizedTimeAhead

    A value in the range [0, 1] indicating how many seconds the current elapsed time for graphics is ahead of the elapsed time when physics last stepped, as a proportion of the fixed timestep used by physics.

    Returns
    Type Description
    RigidTransform

    An interpolated transform for a rigid body's graphical representation, suitable for constructing its LocalToWorld matrix before rendering. See also BuildLocalToWorld(Int32, RigidTransform, Single, Boolean, NativeArray<PostTransformMatrix>).

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023