Lens Scripting API
    Preparing search index...

    A 3D spring simulation class for smooth, physically-based animations of vectors.

    Index

    Constructors

    • Creates a 3D spring animator.

      Parameters

      • k: number

        Spring constant (stiffness).

      • damp: number

        Damping coefficient.

      • mass: number

        Mass applied to each axis.

      Returns SpringAnimate

    Accessors

    • get damp(): number

      Gets the damping constant (resistance).

      Returns number

    • set damp(value: number): void

      Sets the damping constant. Higher values increase resistance and reduce oscillation.

      Parameters

      • value: number

        The damping coefficient.

      Returns void

    • get k(): number

      Gets the spring constant (stiffness).

      Returns number

    • set k(value: number): void

      Sets the spring constant (stiffness).

      Parameters

      • value: number

        The spring constant k.

      Returns void

    • get mass(): number

      Gets the mass of the object.

      Returns number

    • set mass(value: number): void

      Sets the mass. Higher mass slows acceleration and increases inertia.

      Parameters

      • value: number

        The mass value.

      Returns void

    • get onSettled(): () => void

      Gets the onSettled callback.

      Returns () => void

    • set onSettled(callback: () => void): void

      Sets a callback that fires once all three axes of the spring have settled.

      Parameters

      • callback: () => void

      Returns void

    • get velocity(): vec3

      Returns vec3

      in favor of using velocityX, velocityY, and velocityZ. Returns the spring's velocity vector across x, y, and z axes.

    • set velocity(newVelocity: vec3): void

      Sets the spring's velocity vector across x, y, and z axes.

      Parameters

      • newVelocity: vec3

        The velocity to apply to each axis.

      Returns void

    • get velocityX(): number

      Gets the x-component of the spring's velocity.

      Returns number

    • get velocityY(): number

      Gets the y-component of the spring's velocity.

      Returns number

    • get velocityZ(): number

      Gets the z-component of the spring's velocity.

      Returns number

    Methods

    • Convenience factory for a bouncy spring with noticeable overshoot.

      Parameters

      • duration: number = DEFAULT_DURATION_BOUNCY

        Total perceptual duration in seconds (default: 0.5).

      Returns SpringAnimate

      A SpringAnimate configured for bouncy motion.

    • Evaluates the new position of the object based on the spring dynamics.

      Parameters

      • currentValue: vec3

        The current position of the object.

      • targetValue: vec3

        The target position of the object.

      • Optionalout: vec3

        The optional vector to store the updated position in.

      Returns vec3

      The updated position of the object.

    • Checks if the spring has effectively come to rest at the target value.

      Parameters

      • currentValue: vec3

        The current simulated value.

      • targetValue: vec3

        The value the spring is moving towards.

      • positionThreshold: number = 0.1

        How close the value needs to be to the target.

      • velocityThreshold: number = 0.1

        How low the velocity needs to be.

      Returns boolean

      True if the spring is settled, false otherwise.

    • Resets the spring's velocity and time accumulator to zero.

      Returns void

    • Retunes the internal springs to match a desired duration and bounce. Preserves current velocities by default to maintain continuity.

      Parameters

      • duration: number

        Perceptual duration in seconds.

      • bounce: number = BOUNCE_SMOOTH

        Bounce factor in [0,1], default 0 (smooth/critically-damped).

      • preserveVelocity: boolean = true

        If false, zeroes velocities.

      Returns void

    • Retunes to the bouncy profile.

      Parameters

      • duration: number

        Perceptual duration in seconds.

      • preserveVelocity: boolean = true

        If false, zeroes velocities.

      Returns void

    • Retunes to the smooth profile.

      Parameters

      • duration: number

        Perceptual duration in seconds.

      • preserveVelocity: boolean = true

        If false, zeroes velocities.

      Returns void

    • Retunes to the snappy profile.

      Parameters

      • duration: number

        Perceptual duration in seconds.

      • preserveVelocity: boolean = true

        If false, zeroes velocities.

      Returns void

    • Convenience factory for a smooth, critically-damped spring with no bounce.

      Parameters

      • duration: number = DEFAULT_DURATION

        Total perceptual duration in seconds (default: 0.3).

      Returns SpringAnimate

      A SpringAnimate configured for smooth motion.

    • Convenience factory for a snappy spring with slight bounce.

      Parameters

      • duration: number = DEFAULT_DURATION

        Total perceptual duration in seconds (default: 0.3).

      Returns SpringAnimate

      A SpringAnimate configured for snappy motion.

    • Creates a new spring animation with the given duration and bounce.

      Parameters

      • duration: number

        The perceptual duration of the animation in seconds.

      • bounce: number

        How much bounce the spring should have. 0 is no bounce, 1 is infinite bounce.

      Returns SpringAnimate

      A new spring animation object.