animation

package
v0.23.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Synchronized

func Synchronized[T Node](node T) T

Synchronized is a helper function that configures a node to be synchronized and returns it. This is useful during node tree construction.

Types

type AddNode

type AddNode struct {
	// contains filtered or unexported fields
}

AddNode returns the sum of two animations.

func NewAddNode

func NewAddNode(primary, overlay Node) *AddNode

NewAddNode creates a new node that returns the sum of two animations.

func (*AddNode) Advance

func (n *AddNode) Advance(seconds, synchronizationRate float64)

Advance moves the animation forward by the specified delta seconds.

The synchronizationRate determines the amount of scaling on the seconds that should be applied in order to be correctly synchronized with sibling and parent nodes in case of synchronization.

func (*AddNode) BoneDeltaTransform

func (n *AddNode) BoneDeltaTransform(bone string, delta float64) NodeTransform

BoneDeltaTransform returns the transformation that the bone will experience throughout the next delta interval. This is used for root motion.

func (*AddNode) BoneTransform

func (n *AddNode) BoneTransform(bone string) NodeTransform

BoneTransform returns the transformation of the specified bone. Keep in mind that this is after a fixed interval update has been applied. If this is called from within a dynamic update handler, the BoneTransformInterpolation method should be used instead.

func (*AddNode) Fraction

func (n *AddNode) Fraction() float64

Fraction returns the amount of animation that has elapsed. In case of looping, the value will wrap around.

The returned value is in the range [0.0..1.0).

func (*AddNode) IsSynchronized

func (n *AddNode) IsSynchronized() bool

IsSynchronized returns whether the node should be synchronized.

func (*AddNode) Rate

func (n *AddNode) Rate() float64

Rate returns the fraction of the animation length that advances each second.

func (*AddNode) SetFraction

func (n *AddNode) SetFraction(fraction float64)

SetFraction relocates the animation to the specified fractional position.

NOTE: This resets the animation and accumulated delta is lost.

func (*AddNode) SetSynchronized

func (n *AddNode) SetSynchronized(synchronized bool)

SetSynchronized configures whether the node should be synchronized.

func (*AddNode) Synchronize

func (n *AddNode) Synchronize()

Synchronize is called each frame to allow a node to synchronized its children (depending on their setting).

This will be called (and should be called on children) regardless if the current or any child node is synchronized or not.

type Blend1DEntry

type Blend1DEntry struct {
	Coord float64
	Node  Node
}

Blend1DEntry specifies an animation to be used by a Blend1DSource.

func NewBlend1DEntry

func NewBlend1DEntry(coord float64, node Node) Blend1DEntry

NewBlend1DEntry creates a new Blend1DEntry.

type Blend1DNode

type Blend1DNode struct {
	// contains filtered or unexported fields
}

Blend1DNode is an animation source that blends between the two closest animations positioned on a 1D line.

NOTE: All animations are considered to loop and are synchronized.

func NewBlend1DNode

func NewBlend1DNode(entries ...Blend1DEntry) *Blend1DNode

NewBlend1DNode creates an animation node that can blend between multiple animations placed on a 1D line.

func (*Blend1DNode) Advance

func (n *Blend1DNode) Advance(seconds, synchronizationRate float64)

Advance moves the animation forward by the specified delta seconds.

The synchronizationRate determines the amount of scaling on the seconds that should be applied in order to be correctly synchronized with sibling and parent nodes in case of synchronization.

func (*Blend1DNode) BlendCoord

func (n *Blend1DNode) BlendCoord() float64

BlendCoord returns the blending coord.

func (*Blend1DNode) BoneDeltaTransform

func (n *Blend1DNode) BoneDeltaTransform(bone string, delta float64) NodeTransform

BoneDeltaTransform returns the transformation that the bone will experience throughout the next delta interval. This is used for root motion.

func (*Blend1DNode) BoneTransform

func (n *Blend1DNode) BoneTransform(bone string) NodeTransform

BoneTransform returns the transformation of the specified bone. Keep in mind that this is after a fixed interval update has been applied. If this is called from within a dynamic update handler, the BoneTransformInterpolation method should be used instead.

func (*Blend1DNode) Fraction

func (n *Blend1DNode) Fraction() float64

Fraction returns the amount of animation that has elapsed. In case of looping, the value will wrap around.

The returned value is in the range [0.0..1.0).

func (*Blend1DNode) IsSynchronized

func (n *Blend1DNode) IsSynchronized() bool

IsSynchronized returns whether the node should be synchronized.

func (*Blend1DNode) Rate

func (n *Blend1DNode) Rate() float64

Rate returns the fraction of the animation length that advances each second.

func (*Blend1DNode) SetBlendCoord

func (n *Blend1DNode) SetBlendCoord(blendCoord float64)

SetBlendCoord changes the blending coord.

func (*Blend1DNode) SetFraction

func (n *Blend1DNode) SetFraction(fraction float64)

SetFraction relocates the animation to the specified fractional position.

NOTE: This resets the animation and accumulated delta is lost.

func (*Blend1DNode) SetSynchronized

func (n *Blend1DNode) SetSynchronized(synchronized bool)

SetSynchronized configures whether the node should be synchronized.

func (*Blend1DNode) Synchronize

func (n *Blend1DNode) Synchronize()

Synchronize is called each frame to allow a node to synchronized its children (depending on their setting).

This will be called (and should be called on children) regardless if the current or any child node is synchronized or not.

type BlendPairNode

type BlendPairNode struct {
	// contains filtered or unexported fields
}

BlendPairNode represents an animation node that blends two child animation nodes. The blending factor is determined by the factor field of the node.

func NewBlendPairNode

func NewBlendPairNode(first, second Node) *BlendPairNode

NewBlendPairNode creates a new animation blending node that blends between a pair of sub-nodes.

func (*BlendPairNode) Advance

func (n *BlendPairNode) Advance(seconds, synchronizationRate float64)

Advance moves the animation forward by the specified delta seconds.

The synchronizationRate determines the amount of scaling on the seconds that should be applied in order to be correctly synchronized with sibling and parent nodes in case of synchronization.

func (*BlendPairNode) BlendFactor

func (n *BlendPairNode) BlendFactor() float64

BlendFactor returns the blending factor of the node. A value of 0.0 means that the first blend node is used, a value of 1.0 means that the second blend node is used. The value is clamped to the range [0.0, 1.0].

func (*BlendPairNode) BoneDeltaTransform

func (n *BlendPairNode) BoneDeltaTransform(bone string, delta float64) NodeTransform

BoneDeltaTransform returns the transformation that the bone will experience throughout the next delta interval. This is used for root motion.

func (*BlendPairNode) BoneTransform

func (n *BlendPairNode) BoneTransform(bone string) NodeTransform

BoneTransform returns the transformation of the specified bone. Keep in mind that this is after a fixed interval update has been applied. If this is called from within a dynamic update handler, the BoneTransformInterpolation method should be used instead.

func (*BlendPairNode) Fraction

func (n *BlendPairNode) Fraction() float64

Fraction returns the amount of animation that has elapsed. In case of looping, the value will wrap around.

The returned value is in the range [0.0..1.0).

func (*BlendPairNode) IsSynchronized

func (n *BlendPairNode) IsSynchronized() bool

IsSynchronized returns whether the node should be synchronized.

func (*BlendPairNode) Rate

func (n *BlendPairNode) Rate() float64

Rate returns the fraction of the animation length that advances each second.

func (*BlendPairNode) SetBlendFactor

func (n *BlendPairNode) SetBlendFactor(factor float64) *BlendPairNode

SetBlendFactor sets the blending factor of the node. The value is clamped to the range [0.0, 1.0].

func (*BlendPairNode) SetFraction

func (n *BlendPairNode) SetFraction(fraction float64)

SetFraction relocates the animation to the specified fractional position.

NOTE: This resets the animation and accumulated delta is lost.

func (*BlendPairNode) SetSynchronized

func (n *BlendPairNode) SetSynchronized(synchronized bool)

SetSynchronized configures whether the node should be synchronized.

func (*BlendPairNode) Synchronize

func (n *BlendPairNode) Synchronize()

Synchronize is called each frame to allow a node to synchronized its children (depending on their setting).

This will be called (and should be called on children) regardless if the current or any child node is synchronized or not.

type DiffNode

type DiffNode struct {
	// contains filtered or unexported fields
}

DiffNode returns the difference between two animations.

func NewDiffNode

func NewDiffNode(primary, overlay Node) *DiffNode

NewDiffNode creates a node that returns the difference between two nodes.

func (*DiffNode) Advance

func (n *DiffNode) Advance(seconds, synchronizationRate float64)

Advance moves the animation forward by the specified delta seconds.

The synchronizationRate determines the amount of scaling on the seconds that should be applied in order to be correctly synchronized with sibling and parent nodes in case of synchronization.

func (*DiffNode) BoneDeltaTransform

func (n *DiffNode) BoneDeltaTransform(bone string, delta float64) NodeTransform

BoneDeltaTransform returns the transformation that the bone will experience throughout the next delta interval. This is used for root motion.

func (*DiffNode) BoneTransform

func (n *DiffNode) BoneTransform(bone string) NodeTransform

BoneTransform returns the transformation of the specified bone. Keep in mind that this is after a fixed interval update has been applied. If this is called from within a dynamic update handler, the BoneTransformInterpolation method should be used instead.

func (*DiffNode) Fraction

func (n *DiffNode) Fraction() float64

Fraction returns the amount of animation that has elapsed. In case of looping, the value will wrap around.

The returned value is in the range [0.0..1.0).

func (*DiffNode) IsSynchronized

func (n *DiffNode) IsSynchronized() bool

IsSynchronized returns whether the node should be synchronized.

func (*DiffNode) Rate

func (n *DiffNode) Rate() float64

Rate returns the fraction of the animation length that advances each second.

func (*DiffNode) SetFraction

func (n *DiffNode) SetFraction(fraction float64)

SetFraction relocates the animation to the specified fractional position.

NOTE: This resets the animation and accumulated delta is lost.

func (*DiffNode) SetSynchronized

func (n *DiffNode) SetSynchronized(synchronized bool)

SetSynchronized configures whether the node should be synchronized.

func (*DiffNode) Synchronize

func (n *DiffNode) Synchronize()

Synchronize is called each frame to allow a node to synchronized its children (depending on their setting).

This will be called (and should be called on children) regardless if the current or any child node is synchronized or not.

type GraphNode

type GraphNode[T comparable] struct {
	// contains filtered or unexported fields
}

GraphNode represents an animation node that is comprised of a graph of animation states and transitions between them.

func NewGraphNode

func NewGraphNode[T comparable]() *GraphNode[T]

NewGraphNode creates a new transition graph animation node.

func (*GraphNode[T]) AddState

func (n *GraphNode[T]) AddState(state T, animation Node)

AddState registers a new animation state.

func (*GraphNode[T]) AddTransition

func (n *GraphNode[T]) AddTransition(from, to T, transition GraphNodeTransition)

AddTransition registers a new state transition.

func (*GraphNode[T]) Advance

func (n *GraphNode[T]) Advance(seconds, synchronizationRate float64)

Advance moves the animation forward by the specified delta seconds.

The synchronizationRate determines the amount of scaling on the seconds that should be applied in order to be correctly synchronized with sibling and parent nodes in case of synchronization.

func (*GraphNode[T]) BoneDeltaTransform

func (n *GraphNode[T]) BoneDeltaTransform(bone string, delta float64) NodeTransform

BoneDeltaTransform returns the transformation that the bone will experience throughout the next delta interval. This is used for root motion.

func (*GraphNode[T]) BoneTransform

func (n *GraphNode[T]) BoneTransform(bone string) NodeTransform

BoneTransform returns the transformation of the specified bone. Keep in mind that this is after a fixed interval update has been applied. If this is called from within a dynamic update handler, the BoneTransformInterpolation method should be used instead.

func (*GraphNode[T]) Fraction

func (n *GraphNode[T]) Fraction() float64

Fraction returns the amount of animation that has elapsed. In case of looping, the value will wrap around.

The returned value is in the range [0.0..1.0).

func (*GraphNode[T]) IsSynchronized

func (n *GraphNode[T]) IsSynchronized() bool

IsSynchronized returns whether the node should be synchronized.

func (*GraphNode[T]) IsTransitioned

func (n *GraphNode[T]) IsTransitioned() bool

IsTransitioned returns whether the graph has transitioned to a stable state.

func (*GraphNode[T]) JumpToState

func (n *GraphNode[T]) JumpToState(state T)

JumpToState jumps to a specific state and cancels any transitions.

func (*GraphNode[T]) Rate

func (n *GraphNode[T]) Rate() float64

Rate returns the fraction of the animation length that advances each second (fraction per second).

func (*GraphNode[T]) SetFraction

func (n *GraphNode[T]) SetFraction(fraction float64)

SetFraction relocates the animation to the specified fractional position.

NOTE: This resets the animation and accumulated delta is lost.

func (*GraphNode[T]) SetSynchronized

func (n *GraphNode[T]) SetSynchronized(synchronized bool)

SetSynchronized configures whether the node should be synchronized.

func (*GraphNode[T]) SourceState

func (n *GraphNode[T]) SourceState() T

SourceState returns the current source state of the graph.

func (*GraphNode[T]) Synchronize

func (n *GraphNode[T]) Synchronize()

Synchronize is called each frame to allow a node to synchronized its children (depending on their setting).

This will be called (and should be called on children) regardless if the current or any child node is synchronized or not.

func (*GraphNode[T]) TargetState

func (n *GraphNode[T]) TargetState() T

TargetState returns the current target state of the graph.

func (*GraphNode[T]) TransitionFraction

func (n *GraphNode[T]) TransitionFraction() float64

TransitionFraction returns the amount (fraction) of transition that has occurred so far. Returns 1.0 if not in transition.

func (*GraphNode[T]) TransitionTo

func (n *GraphNode[T]) TransitionTo(to T)

TransitionTo triggers a new transition. Calling this while there is an ongoing transition has undefined behavior.

type GraphNodeTransition

type GraphNodeTransition struct {
	// FadeInFraction determines the amount of time (in fraction of the total
	// animation) that it takes to fade into the transition animation (if there
	// is one).
	FadeInFraction float64

	// FadeOutFraction determines the amount of time (in fraction of the total
	// animation) that it takes to fade out of the transition animation (if there
	// is one).
	FadeOutFraction float64

	// Duration optionally specifies a custom duration for the transition in
	// case that a transition animation is not specified.
	//
	// Defaults to 1.0 (one second).
	Duration opt.T[float64]

	// Animation optionally specifies an animation to be blended on top of the
	// blending from the start state to the end state. If this is not specified
	// then Duration is used to determine the length of the transition.
	Animation opt.T[Node]
}

GraphNodeTransition represents a transition in a GraphNode.

type Keyframe

type Keyframe[T any] struct {
	Timestamp float64
	Value     T
}

Keyframe represents a single keyframe in an animation.

type KeyframeList

type KeyframeList[T any] []Keyframe[T]

KeyframeList is a list of keyframes.

func (KeyframeList[T]) Keyframe

func (l KeyframeList[T]) Keyframe(timestamp float64) (Keyframe[T], Keyframe[T], float64)

Keyframe returns the keyframes that are closest to the specified timestamp and the interpolation factor between them.

type KeyframeSet

type KeyframeSet struct {
	TranslationKeyframes KeyframeList[dprec.Vec3]
	RotationKeyframes    KeyframeList[dprec.Quat]
	ScaleKeyframes       KeyframeList[dprec.Vec3]
}

KeyframeSet represents a set of keyframes for an animation, including translations, rotations, and scales.

func (KeyframeSet) Rotation

func (s KeyframeSet) Rotation(timestamp float64) dprec.Quat

Rotation returns the rotation at the specified timestamp by interpolating between the two closest keyframes using spherical linear interpolation.

func (KeyframeSet) Scale

func (s KeyframeSet) Scale(timestamp float64) dprec.Vec3

Scale returns the scale at the specified timestamp by interpolating between the two closest keyframes.

func (KeyframeSet) Translation

func (s KeyframeSet) Translation(timestamp float64) dprec.Vec3

Translation returns the translation at the specified timestamp by interpolating between the two closest keyframes.

type ManualPoseNode

type ManualPoseNode struct {
	// contains filtered or unexported fields
}

ManualPoseNode is an animation node that represents a static pose that is manually configured.

func NewManualPoseNode

func NewManualPoseNode(transforms map[string]NodeTransform) *ManualPoseNode

NewManualPoseNode creates a static animation pose with pre-configured bone transformations.

func (*ManualPoseNode) Advance

func (n *ManualPoseNode) Advance(seconds, synchronizationRate float64)

Advance moves the animation forward by the specified delta seconds.

The synchronizationRate determines the amount of scaling on the seconds that should be applied in order to be correctly synchronized with sibling and parent nodes in case of synchronization.

func (*ManualPoseNode) BoneDeltaTransform

func (n *ManualPoseNode) BoneDeltaTransform(bone string, delta float64) NodeTransform

BoneDeltaTransform returns the transformation that the bone will experience throughout the next delta interval. This is used for root motion.

func (*ManualPoseNode) BoneTransform

func (n *ManualPoseNode) BoneTransform(bone string) NodeTransform

BoneTransform returns the transformation of the specified bone. Keep in mind that this is after a fixed interval update has been applied. If this is called from within a dynamic update handler, the BoneTransformInterpolation method should be used instead.

func (*ManualPoseNode) Fraction

func (n *ManualPoseNode) Fraction() float64

Fraction returns the amount of animation that has elapsed. In case of looping, the value will wrap around.

The returned value is in the range [0.0..1.0).

func (*ManualPoseNode) IsSynchronized

func (n *ManualPoseNode) IsSynchronized() bool

IsSynchronized returns whether the node should be synchronized.

func (*ManualPoseNode) Rate

func (n *ManualPoseNode) Rate() float64

Rate returns the fraction of the animation length that advances each second (fraction per second).

func (*ManualPoseNode) Reset

func (n *ManualPoseNode) Reset()

Reset clears any update delta information, so that new interpolations can be tracked.

func (*ManualPoseNode) SetFraction

func (n *ManualPoseNode) SetFraction(fraction float64)

SetFraction relocates the animation to the specified fractional position.

NOTE: This resets the animation and accumulated delta is lost.

func (*ManualPoseNode) SetSynchronized

func (n *ManualPoseNode) SetSynchronized(synchronized bool)

SetSynchronized configures whether the node should be synchronized.

func (*ManualPoseNode) Synchronize

func (n *ManualPoseNode) Synchronize()

Synchronize is called each frame to allow a node to synchronized its children (depending on their setting).

This will be called (and should be called on children) regardless if the current or any child node is synchronized or not.

type MaskNode

type MaskNode struct {
	// contains filtered or unexported fields
}

MaskNode is an animation source that picks specific bones from another animation source.

func NewMaskNode

func NewMaskNode(delegate Node, selection filter.Func[string]) *MaskNode

NewMaskNode creates a new animation node that picks specific bones from the specified node.

func (*MaskNode) Advance

func (n *MaskNode) Advance(seconds, synchronizationRate float64)

Advance moves the animation forward by the specified delta seconds.

The synchronizationRate determines the amount of scaling on the seconds that should be applied in order to be correctly synchronized with sibling and parent nodes in case of synchronization.

func (*MaskNode) BoneDeltaTransform

func (n *MaskNode) BoneDeltaTransform(bone string, delta float64) NodeTransform

BoneDeltaTransform returns the transformation that the bone will experience throughout the next delta interval. This is used for root motion.

func (*MaskNode) BoneTransform

func (n *MaskNode) BoneTransform(bone string) NodeTransform

BoneTransform returns the transformation of the specified bone. Keep in mind that this is after a fixed interval update has been applied. If this is called from within a dynamic update handler, the BoneTransformInterpolation method should be used instead.

func (*MaskNode) Fraction

func (n *MaskNode) Fraction() float64

Fraction returns the amount of animation that has elapsed. In case of looping, the value will wrap around.

The returned value is in the range [0.0..1.0).

func (*MaskNode) IsSynchronized

func (n *MaskNode) IsSynchronized() bool

IsSynchronized returns whether the node should be synchronized.

func (*MaskNode) Rate

func (n *MaskNode) Rate() float64

Rate returns the fraction of the animation length that advances each second.

func (*MaskNode) SetFraction

func (n *MaskNode) SetFraction(fraction float64)

SetFraction relocates the animation to the specified fractional position.

NOTE: This resets the animation and accumulated delta is lost.

func (*MaskNode) SetSynchronized

func (n *MaskNode) SetSynchronized(synchronized bool)

SetSynchronized configures whether the node should be synchronized.

func (*MaskNode) Synchronize

func (n *MaskNode) Synchronize()

Synchronize is called each frame to allow a node to synchronized its children (depending on their setting).

This will be called (and should be called on children) regardless if the current or any child node is synchronized or not.

type Node

type Node interface {

	// Rate returns the fraction of the animation length that advances each
	// second (fraction per second).
	Rate() float64

	// Fraction returns the amount of animation that has elapsed. In case of
	// looping, the value will wrap around.
	//
	// The returned value is in the range [0.0..1.0).
	Fraction() float64

	// SetFraction relocates the animation to the specified fractional position.
	//
	// NOTE: This resets the animation and accumulated delta is lost.
	SetFraction(fraction float64)

	// Advance moves the animation forward by the specified delta seconds.
	//
	// The synchronizationRate determines the amount of scaling on the seconds
	// that should be applied in order to be correctly synchronized with sibling
	// and parent nodes in case of synchronization.
	Advance(seconds, synchronizationRate float64)

	// IsSynchronized returns whether the node should be synchronized.
	IsSynchronized() bool

	// SetSynchronized configures whether the node should be synchronized.
	SetSynchronized(synchronized bool)

	// Synchronize is called each frame to allow a node to synchronized its
	// children (depending on their setting).
	//
	// This will be called (and should be called on children) regardless if
	// the current or any child node is synchronized or not.
	Synchronize()

	// BoneTransform returns the transformation of the specified bone. Keep in
	// mind that this is after a fixed interval update has been applied. If
	// this is called from within a dynamic update handler, the
	// BoneTransformInterpolation method should be used instead.
	BoneTransform(bone string) NodeTransform

	// BoneDeltaTransform returns the transformation that the bone will experience
	// throughout the next delta interval. This is used for root motion.
	BoneDeltaTransform(bone string, delta float64) NodeTransform
}

Node represents an animation logic.

type NodeTransform

type NodeTransform struct {

	// Translation, if specified, indicates the translation of the node.
	Translation opt.T[dprec.Vec3]

	// Rotation, if specified, indicates the rotation of the node.
	Rotation opt.T[dprec.Quat]

	// Scale, if specified, indicates the scale of the node.
	Scale opt.T[dprec.Vec3]
}

NodeTransform represents the transformation of a node.

func AddNodeTransforms

func AddNodeTransforms(first, second NodeTransform) NodeTransform

AddNodeTransforms combines two transforms into a single one.

func BlendNodeTransforms

func BlendNodeTransforms(first, second NodeTransform, factor float64) NodeTransform

BlendNodeTransforms blends two node transformations using the specified factor. A factor of 0.0 means that the first transformation is used, a factor of 1.0 means that the second transformation is used.

func DiffNodeTransforms

func DiffNodeTransforms(first, second NodeTransform) NodeTransform

DiffNodeTransforms combines two transforms into a single one.

func FirstNodeTransform

func FirstNodeTransform(first, second NodeTransform) NodeTransform

FirstNodeTransform combines two transforms into a single one by using the first transform that has a value.

func InverseNodeTransform

func InverseNodeTransform(transform NodeTransform) NodeTransform

InverseNodeTransform returns the inverse of a node transform.

type OnceNode

type OnceNode struct {
	// contains filtered or unexported fields
}

OnceNode allows an animation to be played just once.

func NewOnceNode

func NewOnceNode(primary, overlay Node) *OnceNode

NewOnceNode creates a node that can play an animation once at a time, per user request.

func (*OnceNode) Advance

func (n *OnceNode) Advance(seconds, synchronizationRate float64)

Advance moves the animation forward by the specified delta seconds.

The synchronizationRate determines the amount of scaling on the seconds that should be applied in order to be correctly synchronized with sibling and parent nodes in case of synchronization.

func (*OnceNode) BoneDeltaTransform

func (n *OnceNode) BoneDeltaTransform(bone string, delta float64) NodeTransform

BoneDeltaTransform returns the transformation that the bone will experience throughout the next delta interval. This is used for root motion.

func (*OnceNode) BoneTransform

func (n *OnceNode) BoneTransform(bone string) NodeTransform

BoneTransform returns the transformation of the specified bone. Keep in mind that this is after a fixed interval update has been applied. If this is called from within a dynamic update handler, the BoneTransformInterpolation method should be used instead.

func (*OnceNode) FadeInFraction

func (n *OnceNode) FadeInFraction() float64

FadeInFraction returns the amount of time (in fraction of the total animation) that it takes to fade into the overlay animation.

func (*OnceNode) FadeOutFraction

func (n *OnceNode) FadeOutFraction() float64

FadeOutFraction returns the amount of time (in fraction of the total animation) that it takes to fade out of the overlay animation.

func (*OnceNode) Finished

func (n *OnceNode) Finished() bool

Finished returns whether the action has completed.

func (*OnceNode) Fraction

func (n *OnceNode) Fraction() float64

Fraction returns the amount of animation that has elapsed. In case of looping, the value will wrap around.

The returned value is in the range [0.0..1.0).

func (*OnceNode) IsSynchronized

func (n *OnceNode) IsSynchronized() bool

IsSynchronized returns whether the node should be synchronized.

func (*OnceNode) Rate

func (n *OnceNode) Rate() float64

Rate returns the fraction of the animation length that advances each second.

func (*OnceNode) SetFadeInFraction

func (n *OnceNode) SetFadeInFraction(fraction float64)

SetFadeInFraction sets the amount of time (in fraction of the total animation) that it takes to fade into the overlay animation.

func (*OnceNode) SetFadeOutFraction

func (n *OnceNode) SetFadeOutFraction(fraction float64)

SetFadeOutFraction sets the amount of time (in fraction of the total animation) that it takes to fade out of the overlay animation.

func (*OnceNode) SetFraction

func (n *OnceNode) SetFraction(fraction float64)

SetFraction relocates the animation to the specified fractional position.

NOTE: This resets the animation and accumulated delta is lost.

func (*OnceNode) SetSynchronized

func (n *OnceNode) SetSynchronized(synchronized bool)

SetSynchronized configures whether the node should be synchronized.

func (*OnceNode) Synchronize

func (n *OnceNode) Synchronize()

Synchronize is called each frame to allow a node to synchronized its children (depending on their setting).

This will be called (and should be called on children) regardless if the current or any child node is synchronized or not.

func (*OnceNode) Trigger

func (n *OnceNode) Trigger() *OnceNode

Trigger rewinds and activates the animation to be played once.

type OneOfNode

type OneOfNode[T comparable] struct {
	// contains filtered or unexported fields
}

OneOfNode is an animation node that plays one specific animation from a set of animations. The active animation can be changed at any time.

func NewOneOfNode

func NewOneOfNode[T comparable](animations map[T]Node) *OneOfNode[T]

NewOneOfNode creates an animation node that produces one specific animation from a set of animations.

func (*OneOfNode[T]) ActiveAnimation

func (n *OneOfNode[T]) ActiveAnimation() T

ActiveAnimation returns the animation key that is playing.

func (*OneOfNode[T]) Advance

func (n *OneOfNode[T]) Advance(seconds, synchronizationRate float64)

Advance moves the animation forward by the specified delta seconds.

The synchronizationRate determines the amount of scaling on the seconds that should be applied in order to be correctly synchronized with sibling and parent nodes in case of synchronization.

func (*OneOfNode[T]) BoneDeltaTransform

func (n *OneOfNode[T]) BoneDeltaTransform(bone string, delta float64) NodeTransform

BoneDeltaTransform returns the transformation that the bone will experience throughout the next delta interval. This is used for root motion.

func (*OneOfNode[T]) BoneTransform

func (n *OneOfNode[T]) BoneTransform(bone string) NodeTransform

BoneTransform returns the transformation of the specified bone. Keep in mind that this is after a fixed interval update has been applied. If this is called from within a dynamic update handler, the BoneTransformInterpolation method should be used instead.

func (*OneOfNode[T]) Fraction

func (n *OneOfNode[T]) Fraction() float64

Fraction returns the amount of animation that has elapsed. In case of looping, the value will wrap around.

The returned value is in the range [0.0..1.0).

func (*OneOfNode[T]) IsSynchronized

func (n *OneOfNode[T]) IsSynchronized() bool

IsSynchronized returns whether the node should be synchronized.

func (*OneOfNode[T]) PickAnimation

func (n *OneOfNode[T]) PickAnimation(key T, rewind bool)

PickAnimation changes to the specified animation.

The rewind flag controls whether the new animation should start from the beginning.

func (*OneOfNode[T]) Rate

func (n *OneOfNode[T]) Rate() float64

Rate returns the fraction of the animation length that advances each second.

func (*OneOfNode[T]) SetFraction

func (n *OneOfNode[T]) SetFraction(fraction float64)

SetFraction relocates the animation to the specified fractional position.

NOTE: This resets the animation and accumulated delta is lost.

func (*OneOfNode[T]) SetSynchronized

func (n *OneOfNode[T]) SetSynchronized(synchronized bool)

SetSynchronized configures whether the node should be synchronized.

func (*OneOfNode[T]) Synchronize

func (n *OneOfNode[T]) Synchronize()

Synchronize is called each frame to allow a node to synchronized its children (depending on their setting).

This will be called (and should be called on children) regardless if the current or any child node is synchronized or not.

type OverlayNode

type OverlayNode struct {
	// contains filtered or unexported fields
}

OverlayNode is an animation node that overlays one animation on top of another.

func NewOverlayNode

func NewOverlayNode(primary, overlay Node) *OverlayNode

NewOverlayNode creates an animation node that overlays one animation on top of another.

func (*OverlayNode) Advance

func (n *OverlayNode) Advance(seconds, synchronizationRate float64)

Advance moves the animation forward by the specified delta seconds.

The synchronizationRate determines the amount of scaling on the seconds that should be applied in order to be correctly synchronized with sibling and parent nodes in case of synchronization.

func (*OverlayNode) BoneDeltaTransform

func (n *OverlayNode) BoneDeltaTransform(bone string, delta float64) NodeTransform

BoneDeltaTransform returns the transformation that the bone will experience throughout the next delta interval. This is used for root motion.

func (*OverlayNode) BoneTransform

func (n *OverlayNode) BoneTransform(bone string) NodeTransform

BoneTransform returns the transformation of the specified bone. Keep in mind that this is after a fixed interval update has been applied. If this is called from within a dynamic update handler, the BoneTransformInterpolation method should be used instead.

func (*OverlayNode) Fraction

func (n *OverlayNode) Fraction() float64

Fraction returns the amount of animation that has elapsed. In case of looping, the value will wrap around.

The returned value is in the range [0.0..1.0).

func (*OverlayNode) IsSynchronized

func (n *OverlayNode) IsSynchronized() bool

IsSynchronized returns whether the node should be synchronized.

func (*OverlayNode) Rate

func (n *OverlayNode) Rate() float64

Rate returns the fraction of the animation length that advances each second (fraction per second).

func (*OverlayNode) SetFraction

func (n *OverlayNode) SetFraction(fraction float64)

SetFraction relocates the animation to the specified fractional position.

NOTE: This resets the animation and accumulated delta is lost.

func (*OverlayNode) SetSynchronized

func (n *OverlayNode) SetSynchronized(synchronized bool)

SetSynchronized configures whether the node should be synchronized.

func (*OverlayNode) Synchronize

func (n *OverlayNode) Synchronize()

Synchronize is called each frame to allow a node to synchronized its children (depending on their setting).

This will be called (and should be called on children) regardless if the current or any child node is synchronized or not.

type PlaybackNode

type PlaybackNode struct {
	// contains filtered or unexported fields
}

PlaybackNode represents an animation source that plays back an animation.

func NewPlaybackNode

func NewPlaybackNode(source Source, loop bool) *PlaybackNode

NewPlaybackNode creates a simple animation Node that plays back a given source directly.

func (*PlaybackNode) Advance

func (n *PlaybackNode) Advance(seconds, synchronizationRate float64)

Advance moves the animation forward by the specified delta seconds.

The synchronizationRate determines the amount of scaling on the seconds that should be applied in order to be correctly synchronized with sibling and parent nodes in case of synchronization.

func (*PlaybackNode) BoneDeltaTransform

func (n *PlaybackNode) BoneDeltaTransform(bone string, delta float64) NodeTransform

BoneDeltaTransform returns the transformation that the bone will experience throughout the next delta interval. This is used for root motion.

func (*PlaybackNode) BoneTransform

func (n *PlaybackNode) BoneTransform(bone string) NodeTransform

BoneTransform returns the transformation of the specified bone. Keep in mind that this is after a fixed interval update has been applied. If this is called from within a dynamic update handler, the BoneTransformInterpolation method should be used instead.

func (*PlaybackNode) Fraction

func (n *PlaybackNode) Fraction() float64

Fraction returns the amount of animation that has elapsed. In case of looping, the value will wrap around.

The returned value is in the range [0.0..1.0).

func (*PlaybackNode) IsSynchronized

func (n *PlaybackNode) IsSynchronized() bool

IsSynchronized returns whether the node should be synchronized.

func (*PlaybackNode) Rate

func (n *PlaybackNode) Rate() float64

Rate returns the fraction of the animation length that advances each second.

func (*PlaybackNode) SetFraction

func (n *PlaybackNode) SetFraction(fraction float64)

SetFraction relocates the animation to the specified fractional position.

NOTE: This resets the animation and accumulated delta is lost.

func (*PlaybackNode) SetSynchronized

func (n *PlaybackNode) SetSynchronized(synchronized bool)

SetSynchronized configures whether the node should be synchronized.

func (*PlaybackNode) Source

func (n *PlaybackNode) Source() Source

Source returns the underlying animation source.

func (*PlaybackNode) Synchronize

func (n *PlaybackNode) Synchronize()

Synchronize is called each frame to allow a node to synchronized its children (depending on their setting).

This will be called (and should be called on children) regardless if the current or any child node is synchronized or not.

type Player

type Player struct {
	// contains filtered or unexported fields
}

func NewPlayer

func NewPlayer(root Node) *Player

func (*Player) BoneTransform

func (p *Player) BoneTransform(name string) NodeTransform

func (*Player) Update

func (p *Player) Update(elapsedTime time.Duration)

type PoseNode

type PoseNode struct {
	// contains filtered or unexported fields
}

PoseNode represents an animation node that produces a single static bone pose.

func NewPoseNode

func NewPoseNode(source Source, timestamp float64) *PoseNode

NewPoseNode creates an animation node that produces a single static bone pose.

func (*PoseNode) Advance

func (n *PoseNode) Advance(seconds, synchronizationRate float64)

Advance moves the animation forward by the specified delta seconds.

The synchronizationRate determines the amount of scaling on the seconds that should be applied in order to be correctly synchronized with sibling and parent nodes in case of synchronization.

func (*PoseNode) BoneDeltaTransform

func (n *PoseNode) BoneDeltaTransform(bone string, delta float64) NodeTransform

BoneDeltaTransform returns the transformation that the bone will experience throughout the next delta interval. This is used for root motion.

func (*PoseNode) BoneTransform

func (n *PoseNode) BoneTransform(bone string) NodeTransform

BoneTransform returns the transformation of the specified bone. Keep in mind that this is after a fixed interval update has been applied. If this is called from within a dynamic update handler, the BoneTransformInterpolation method should be used instead.

func (*PoseNode) Fraction

func (n *PoseNode) Fraction() float64

Fraction returns the amount of animation that has elapsed. In case of looping, the value will wrap around.

The returned value is in the range [0.0..1.0).

func (*PoseNode) IsSynchronized

func (n *PoseNode) IsSynchronized() bool

IsSynchronized returns whether the node should be synchronized.

func (*PoseNode) Rate

func (n *PoseNode) Rate() float64

Rate returns the fraction of the animation length that advances each second (fraction per second).

func (*PoseNode) Reset

func (n *PoseNode) Reset()

Reset clears any update delta information, so that new interpolations can be tracked.

func (*PoseNode) SetFraction

func (n *PoseNode) SetFraction(fraction float64)

SetFraction relocates the animation to the specified fractional position.

NOTE: This resets the animation and accumulated delta is lost.

func (*PoseNode) SetSynchronized

func (n *PoseNode) SetSynchronized(synchronized bool)

SetSynchronized configures whether the node should be synchronized.

func (*PoseNode) Synchronize

func (n *PoseNode) Synchronize()

Synchronize is called each frame to allow a node to synchronized its children (depending on their setting).

This will be called (and should be called on children) regardless if the current or any child node is synchronized or not.

type Recording

type Recording struct {
	// contains filtered or unexported fields
}

Recording represents a pre-stored set of keyframmes that can be played back.

func NewRecording

func NewRecording() *Recording

NewRecording creates a new empty recording.

func (*Recording) Binding

func (r *Recording) Binding(name string) (KeyframeSet, bool)

Binding returns the keyframes for the node with the specified name.

func (*Recording) BoneTransformAt

func (r *Recording) BoneTransformAt(bone string, timestamp float64) NodeTransform

BoneTransformAt returns the transformation for the specified bone at the specified animation timestamp.

func (*Recording) BoneTransformDelta

func (r *Recording) BoneTransformDelta(bone string, fromTimestamp, toTimestamp float64) NodeTransform

BoneTransformDelta returns the transformation that occurred for the specified bone between the from and to animation timestamps .

This is mostly used for root motion.

func (*Recording) BoundNodesIter

func (r *Recording) BoundNodesIter() iter.Seq[string]

BoundNodesIter returns an iterator over the names of all nodes that have keyframes in this recording.

func (*Recording) EndTime

func (r *Recording) EndTime() float64

EndTime returns the time (in seconds) at which the recording ends.

func (*Recording) Length

func (r *Recording) Length() float64

Length returns the length of the recording in seconds.

func (*Recording) Name

func (r *Recording) Name() string

Name returns the name of the recording.

func (*Recording) Playback

func (r *Recording) Playback(loop bool) *PlaybackNode

Playback creates a new animtion node that plays back the animation.

func (*Recording) Pose

func (r *Recording) Pose(timestamp float64) *PoseNode

Pose returns a new animation node that represents a fixed pose from the recording.

func (*Recording) RemoveBinding

func (r *Recording) RemoveBinding(name string) *Recording

RemoveBinding removes the binding for the node with the specified name.

func (*Recording) SetBinding

func (r *Recording) SetBinding(name string, keyframes KeyframeSet) *Recording

SetBinding sets the keyframes for the node with the specified name.

func (*Recording) SetEndTime

func (r *Recording) SetEndTime(endTime float64) *Recording

SetEndTime sets the time (in seconds) at which the recording ends.

func (*Recording) SetName

func (r *Recording) SetName(name string) *Recording

SetName sets the name of the recording.

func (*Recording) SetStartTime

func (r *Recording) SetStartTime(startTime float64) *Recording

SetStartTime sets the time (in seconds) at which the recording starts.

func (*Recording) StartTime

func (r *Recording) StartTime() float64

StartTime returns the time (in seconds) at which the recording starts.

type RootMotion

type RootMotion struct {
	// contains filtered or unexported fields
}

RootMotion allows for the extraction of relative animation transformations from a root bone in order to move a character.

func NewRootMotion

func NewRootMotion(node Node, bone string) *RootMotion

NewRootMotion creates a new RootMotion instance that is controlled by the specified root bone.

func (*RootMotion) DeltaTransform

func (m *RootMotion) DeltaTransform(delta float64) dprec.Mat4

DeltaTransform returns the transformation that occurred during the last animation tick for the root bone.

type Source

type Source interface {

	// Length returns the length of the animation in seconds.
	Length() float64

	// BoneTransformDelta returns the transformation that occurred for the
	// specified bone between the from and to animation timestamps .
	//
	// This is mostly used for root motion.
	BoneTransformDelta(bone string, fromTimestamp, toTimestamp float64) NodeTransform

	// BoneTransformAt returns the transformation for the specified bone
	// at the specified animation timestamp.
	BoneTransformAt(bone string, timestamp float64) NodeTransform
}

Source represents a source of animation data.

type TempoNode

type TempoNode struct {
	// contains filtered or unexported fields
}

TempoNode is a decorator for an animation source that allows adjusting the playback speed.

func NewTempoNode

func NewTempoNode(delegate Node) *TempoNode

NewTempoNode creates a new animation node that can adjust the speed of the underlying animation.

func WithSpeed

func WithSpeed(node Node, speed float64) *TempoNode

WithSpeed creates a new node that adjusts the speed of the underlying node.

func (*TempoNode) Advance

func (n *TempoNode) Advance(seconds, synchronizationRate float64)

Advance moves the animation forward by the specified delta seconds.

The synchronizationRate determines the amount of scaling on the seconds that should be applied in order to be correctly synchronized with sibling and parent nodes in case of synchronization.

func (*TempoNode) BoneDeltaTransform

func (n *TempoNode) BoneDeltaTransform(bone string, delta float64) NodeTransform

BoneDeltaTransform returns the transformation that the bone will experience throughout the next delta interval. This is used for root motion.

func (*TempoNode) BoneTransform

func (n *TempoNode) BoneTransform(bone string) NodeTransform

BoneTransform returns the transformation of the specified bone. Keep in mind that this is after a fixed interval update has been applied. If this is called from within a dynamic update handler, the BoneTransformInterpolation method should be used instead.

func (*TempoNode) Fraction

func (n *TempoNode) Fraction() float64

Fraction returns the amount of animation that has elapsed. In case of looping, the value will wrap around.

The returned value is in the range [0.0..1.0).

func (*TempoNode) IsSynchronized

func (n *TempoNode) IsSynchronized() bool

IsSynchronized returns whether the node should be synchronized.

func (*TempoNode) Rate

func (n *TempoNode) Rate() float64

Rate returns the fraction of the animation length that advances each second.

func (*TempoNode) SetFraction

func (n *TempoNode) SetFraction(fraction float64)

SetFraction relocates the animation to the specified fractional position.

NOTE: This resets the animation and accumulated delta is lost.

func (*TempoNode) SetSpeed

func (n *TempoNode) SetSpeed(speed float64) *TempoNode

SetSpeed sets the playback speed of the animation.

func (*TempoNode) SetSynchronized

func (n *TempoNode) SetSynchronized(synchronized bool)

SetSynchronized configures whether the node should be synchronized.

func (*TempoNode) Speed

func (n *TempoNode) Speed() float64

Speed returns the current playback speed of the animation. A value of 1.0 means that the animation is played at normal speed.

func (*TempoNode) Synchronize

func (n *TempoNode) Synchronize()

Synchronize is called each frame to allow a node to synchronized its children (depending on their setting).

This will be called (and should be called on children) regardless if the current or any child node is synchronized or not.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL