Skip to content

Commit

Permalink
Sample curves eagerly (#41)
Browse files Browse the repository at this point in the history
Since the start, I have been using lazy/delayed sampling for the
animation graph. This means that the pose data passed around the graph
was in the form of curve segments (`ValueFrame` types), and we sample
them only when needed. While this allowed a couple of cool things (e.g.
extremely flexible animation chaining), the complexity introduced in
many parts of the codebase was getting out of hand.

The industry standard way of doing this is to sample animations as early
as possible, and only worked with pose values throughout the graph. This
PR switches to that approach.

This is part of an effort to clean up technical debt from the codebase,
and make development faster and more approachable.

### Breaking changes

There are changes in how chaining and looping works that required a new
parameter being introduced. Chain and loop nodes now have a
`interpolation_period` f32 parameter that determines how long should be
spent blending back to the starting pose (for looping) or blending to
the second animation (for chaining). You should manually edit graphs
files to change the Loop and Chain nodes to a struct (change `Loop` to
`Loop()` and `Chain` to `Chain()`), and when opening the editor the
nodes should be loaded with default values. See the updated examples for
how for how to do similar tasks in the new system.

### Follow-up work
- Update space conversion nodes
  • Loading branch information
mbrea-c committed Mar 17, 2024
1 parent c77bfc5 commit 97c4302
Show file tree
Hide file tree
Showing 40 changed files with 1,123 additions and 2,682 deletions.
6 changes: 3 additions & 3 deletions assets/animation_graphs/fox.animgraph.ron
Expand Up @@ -10,7 +10,7 @@
),
(
name: "Loop Walk",
node: Loop,
node: Loop(),
),
(
name: "Run Clip",
Expand All @@ -26,7 +26,7 @@
),
(
name: "Loop Run",
node: Loop,
node: Loop(),
),
],
edges_inverted: {
Expand Down Expand Up @@ -63,4 +63,4 @@
input_position: (-381.0, 260.0),
output_position: (269.0, 173.0),
),
)
)
130 changes: 68 additions & 62 deletions assets/animation_graphs/human.animgraph.ron
@@ -1,37 +1,50 @@
(
nodes: [
(
name: "Run Clip 2",
node: Clip("animations/human_run.anim.ron", Some(1.0)),
name: "Blend",
node: Blend,
),
(
name: "Walk Chain",
node: Chain,
name: "Walk Clip",
node: Clip("animations/human_walk.anim.ron", None),
),
(
name: "Run Flip LR",
node: FlipLR(
config: (
name_mapper: Pattern((
key_1: "L",
key_2: "R",
pattern_before: "^.*",
pattern_after: "$",
)),
),
name: "Run Chain",
node: Chain(
interpolation_period: 0.5,
),
),
(
name: "Run Chain",
node: Chain,
name: "Walk Clip 2",
node: Clip("animations/human_walk.anim.ron", None),
),
(
name: "Rotate",
node: Rotation(Compose, Character, Linear, 1, 1.0),
),
(
name: "Walk Chain",
node: Chain(
interpolation_period: 0.5,
),
),
(
name: "Run Clip",
node: Clip("animations/human_run.anim.ron", Some(1.0)),
node: Clip("animations/human_run.anim.ron", None),
),
(
name: "Blend",
node: Blend,
name: "Make Rotation",
node: RotationArc,
),
(
name: "Loop",
node: Loop(
interpolation_period: 0.5,
),
),
(
name: "Run Clip 2",
node: Clip("animations/human_run.anim.ron", None),
),
(
name: "Walk Flip LR",
Expand All @@ -46,10 +59,6 @@
),
),
),
(
name: "Loop",
node: Loop,
),
(
name: "Speed",
node: Speed,
Expand All @@ -59,45 +68,42 @@
node: Graph("animation_graphs/velocity_to_params.animgraph.ron"),
),
(
name: "Make Rotation",
node: RotationArc,
),
(
name: "Walk Clip 2",
node: Clip("animations/human_walk.anim.ron", Some(1.0)),
),
(
name: "Rotate",
node: Rotation(Compose, Character, Linear, 1, 1.0),
),
(
name: "Walk Clip",
node: Clip("animations/human_walk.anim.ron", Some(1.0)),
name: "Run Flip LR",
node: FlipLR(
config: (
name_mapper: Pattern((
key_1: "L",
key_2: "R",
pattern_before: "^.*",
pattern_after: "$",
)),
),
),
),
],
edges_inverted: {
NodeParameter("Make Rotation", "Vec3 In 1"): InputParameter("Z"),
NodeParameter("Blend", "Factor"): NodeParameter("Param graph", "blend_fac"),
NodePose("Loop", "Pose In"): NodePose("Blend"),
NodePose("Rotate", "Pose In"): NodePose("Speed"),
NodePose("Walk Flip LR", "Pose In"): NodePose("Walk Clip 2"),
NodePose("Run Chain", "Pose In 2"): NodePose("Run Flip LR"),
NodeParameter("Make Rotation", "Vec3 In 1"): InputParameter("Z"),
NodePose("Speed", "Pose In"): NodePose("Loop"),
NodeParameter("Param graph", "Target Speed"): InputParameter("Target Speed"),
NodePose("Blend", "Pose In 1"): NodePose("Walk Chain"),
NodePose("Blend", "Pose In 2"): NodePose("Run Chain"),
NodePose("Run Flip LR", "Pose In"): NodePose("Run Clip 2"),
NodePose("Run Chain", "Pose In 2"): NodePose("Run Flip LR"),
NodeParameter("Make Rotation", "Vec3 In 2"): InputParameter("Target Direction"),
NodePose("Run Chain", "Pose In 1"): NodePose("Run Clip"),
NodePose("Blend", "Pose In 1"): NodePose("Walk Chain"),
NodePose("Walk Chain", "Pose In 2"): NodePose("Walk Flip LR"),
OutputPose: NodePose("Rotate"),
NodeParameter("Speed", "Speed"): NodeParameter("Param graph", "speed_fac"),
NodePose("Walk Chain", "Pose In 1"): NodePose("Walk Clip"),
NodePose("Walk Flip LR", "Pose In"): NodePose("Walk Clip 2"),
NodeParameter("Rotate", "Rotation"): NodeParameter("Make Rotation", "Quat Out"),
OutputPose: NodePose("Rotate"),
NodeParameter("Blend", "Factor"): NodeParameter("Param graph", "blend_fac"),
NodePose("Run Chain", "Pose In 1"): NodePose("Run Clip"),
NodeParameter("Param graph", "Target Speed"): InputParameter("Target Speed"),
NodeParameter("Rotate", "Bone Mask"): InputParameter("Rotation Mask"),
NodePose("Walk Chain", "Pose In 2"): NodePose("Walk Flip LR"),
NodePose("Walk Chain", "Pose In 1"): NodePose("Walk Clip"),
NodePose("Rotate", "Pose In"): NodePose("Speed"),
NodePose("Run Flip LR", "Pose In"): NodePose("Run Clip 2"),
},
default_parameters: {
"Target Speed": F32(1.5),
"Target Speed": F32(3.0),
"Target Direction": Vec3((0.0, 0.0, -1.0)),
"Rotation Mask": EntityPath([
"metarig",
Expand All @@ -110,22 +116,22 @@
output_pose: Some(BoneSpace),
extra: (
node_positions: {
"Walk Clip": (-84.0, -288.0),
"Run Flip LR": (-77.0, -21.0),
"Blend": (238.0, -142.0),
"Walk Flip LR": (-82.0, -204.0),
"Run Clip 2": (-216.0, -10.0),
"Blend": (124.0, -240.0),
"Walk Clip": (-215.0, -365.0),
"Run Chain": (-78.0, -62.0),
"Walk Clip 2": (-351.0, -251.0),
"Rotate": (692.0, -97.0),
"Run Chain": (60.0, -70.0),
"Run Clip": (-81.0, -102.0),
"Speed": (540.0, -99.0),
"Walk Chain": (-74.0, -303.0),
"Run Clip": (-284.0, -109.0),
"Make Rotation": (502.0, 69.0),
"Loop": (384.0, -92.0),
"Run Clip 2": (-441.0, -16.0),
"Walk Flip LR": (-214.0, -247.0),
"Speed": (612.0, -238.0),
"Param graph": (135.0, 190.0),
"Make Rotation": (502.0, 69.0),
"Walk Clip 2": (-220.0, -210.0),
"Walk Chain": (61.0, -248.0),
"Run Flip LR": (-271.0, -18.0),
},
input_position: (-242.0, 134.0),
output_position: (860.0, -42.0),
output_position: (840.0, -45.0),
),
)

0 comments on commit 97c4302

Please sign in to comment.