-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement more arithmetic nodes (#60)
Adds: - `DecomposeVec3` - `LerpVec3` - `SlerpQuat` - `FromEuler` - `IntoEuler` - `MulQuat` - `InvertQuat` One issue that's present is `FromEuler` and `IntoEuler` store a `glam::EulerRot` to store which euler rotation mode to use for conversions. This is treated as an opaque value by `bevy_reflect`, so egui can't give you a dropdown box to select which variant you want. Tracking PR: bevyengine/bevy#15349. The default rot mode is YXZ, which is what most people will want.
- Loading branch information
Showing
14 changed files
with
464 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
mod bool; | ||
mod event_queue; | ||
mod f32; | ||
mod quat; | ||
mod vec3; | ||
|
||
pub use bool::*; | ||
pub use event_queue::*; | ||
pub use f32::*; | ||
pub use quat::*; | ||
pub use vec3::*; |
50 changes: 50 additions & 0 deletions
50
crates/bevy_animation_graph/src/nodes/arithmetic/quat/from_euler.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crate::core::animation_graph::PinMap; | ||
use crate::core::animation_node::{AnimationNode, AnimationNodeType, NodeLike}; | ||
use crate::core::errors::GraphError; | ||
use crate::core::prelude::DataSpec; | ||
use crate::prelude::{PassContext, SpecContext}; | ||
use crate::utils::unwrap::UnwrapVal; | ||
use bevy::prelude::*; | ||
|
||
#[derive(Reflect, Clone, Debug, Default)] | ||
#[reflect(Default)] | ||
pub struct FromEulerNode { | ||
pub mode: EulerRot, | ||
} | ||
|
||
impl FromEulerNode { | ||
pub const INPUT: &'static str = "euler"; | ||
pub const OUTPUT: &'static str = "quat"; | ||
|
||
pub fn new(mode: EulerRot) -> Self { | ||
Self { mode } | ||
} | ||
|
||
pub fn wrapped(self, name: impl Into<String>) -> AnimationNode { | ||
AnimationNode::new_from_nodetype(name.into(), AnimationNodeType::FromEuler(self)) | ||
} | ||
} | ||
|
||
impl NodeLike for FromEulerNode { | ||
fn update(&self, mut ctx: PassContext) -> Result<(), GraphError> { | ||
let Vec3 { x, y, z } = ctx.data_back(Self::INPUT)?.val(); | ||
|
||
let output = Quat::from_euler(self.mode, x, y, z); | ||
|
||
ctx.set_data_fwd(Self::OUTPUT, output); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn data_input_spec(&self, _: SpecContext) -> PinMap<DataSpec> { | ||
[(Self::INPUT.into(), DataSpec::Vec3)].into() | ||
} | ||
|
||
fn data_output_spec(&self, _: SpecContext) -> PinMap<DataSpec> { | ||
[(Self::OUTPUT.into(), DataSpec::Quat)].into() | ||
} | ||
|
||
fn display_name(&self) -> String { | ||
"Quat from Euler".into() | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
crates/bevy_animation_graph/src/nodes/arithmetic/quat/into_euler.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use crate::core::animation_graph::PinMap; | ||
use crate::core::animation_node::{AnimationNode, AnimationNodeType, NodeLike}; | ||
use crate::core::errors::GraphError; | ||
use crate::core::prelude::DataSpec; | ||
use crate::prelude::{PassContext, SpecContext}; | ||
use crate::utils::unwrap::UnwrapVal; | ||
use bevy::prelude::*; | ||
|
||
#[derive(Reflect, Clone, Debug, Default)] | ||
#[reflect(Default)] | ||
pub struct IntoEulerNode { | ||
pub mode: EulerRot, | ||
} | ||
|
||
impl IntoEulerNode { | ||
pub const INPUT: &'static str = "quat"; | ||
pub const OUTPUT: &'static str = "euler"; | ||
|
||
pub fn new(mode: EulerRot) -> Self { | ||
Self { mode } | ||
} | ||
|
||
pub fn wrapped(self, name: impl Into<String>) -> AnimationNode { | ||
AnimationNode::new_from_nodetype(name.into(), AnimationNodeType::IntoEuler(self)) | ||
} | ||
} | ||
|
||
impl NodeLike for IntoEulerNode { | ||
fn update(&self, mut ctx: PassContext) -> Result<(), GraphError> { | ||
let quat: Quat = ctx.data_back(Self::INPUT)?.val(); | ||
|
||
let (x, y, z) = quat.to_euler(self.mode); | ||
let output = Vec3::new(x, y, z); | ||
|
||
ctx.set_data_fwd(Self::OUTPUT, output); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn data_input_spec(&self, _: SpecContext) -> PinMap<DataSpec> { | ||
[(Self::INPUT.into(), DataSpec::Quat)].into() | ||
} | ||
|
||
fn data_output_spec(&self, _: SpecContext) -> PinMap<DataSpec> { | ||
[(Self::OUTPUT.into(), DataSpec::Vec3)].into() | ||
} | ||
|
||
fn display_name(&self) -> String { | ||
"Quat into Euler".into() | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
crates/bevy_animation_graph/src/nodes/arithmetic/quat/inverse.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::core::animation_graph::PinMap; | ||
use crate::core::animation_node::{AnimationNode, AnimationNodeType, NodeLike}; | ||
use crate::core::errors::GraphError; | ||
use crate::core::prelude::DataSpec; | ||
use crate::prelude::{PassContext, SpecContext}; | ||
use crate::utils::unwrap::UnwrapVal; | ||
use bevy::prelude::*; | ||
|
||
#[derive(Reflect, Clone, Debug, Default)] | ||
#[reflect(Default)] | ||
pub struct InvertQuatNode {} | ||
|
||
impl InvertQuatNode { | ||
pub const INPUT: &'static str = "quat"; | ||
pub const OUTPUT: &'static str = "inverse"; | ||
|
||
pub fn new() -> Self { | ||
Self {} | ||
} | ||
|
||
pub fn wrapped(self, name: impl Into<String>) -> AnimationNode { | ||
AnimationNode::new_from_nodetype(name.into(), AnimationNodeType::InvertQuat(self)) | ||
} | ||
} | ||
|
||
impl NodeLike for InvertQuatNode { | ||
fn update(&self, mut ctx: PassContext) -> Result<(), GraphError> { | ||
let input: Quat = ctx.data_back(Self::INPUT)?.val(); | ||
let output: Quat = input.inverse(); | ||
|
||
ctx.set_data_fwd(Self::OUTPUT, output); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn data_input_spec(&self, _: SpecContext) -> PinMap<DataSpec> { | ||
[(Self::INPUT.into(), DataSpec::Quat)].into() | ||
} | ||
|
||
fn data_output_spec(&self, _: SpecContext) -> PinMap<DataSpec> { | ||
[(Self::OUTPUT.into(), DataSpec::Quat)].into() | ||
} | ||
|
||
fn display_name(&self) -> String { | ||
"Invert Quat".into() | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
crates/bevy_animation_graph/src/nodes/arithmetic/quat/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
mod from_euler; | ||
mod into_euler; | ||
mod inverse; | ||
mod mul; | ||
mod slerp; | ||
|
||
pub use from_euler::*; | ||
pub use into_euler::*; | ||
pub use inverse::*; | ||
pub use mul::*; | ||
pub use slerp::*; |
54 changes: 54 additions & 0 deletions
54
crates/bevy_animation_graph/src/nodes/arithmetic/quat/mul.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use crate::core::animation_graph::PinMap; | ||
use crate::core::animation_node::{AnimationNode, AnimationNodeType, NodeLike}; | ||
use crate::core::errors::GraphError; | ||
use crate::core::prelude::DataSpec; | ||
use crate::prelude::{PassContext, SpecContext}; | ||
use crate::utils::unwrap::UnwrapVal; | ||
use bevy::prelude::*; | ||
|
||
#[derive(Reflect, Clone, Debug, Default)] | ||
#[reflect(Default)] | ||
pub struct MulQuatNode {} | ||
|
||
impl MulQuatNode { | ||
pub const INPUT_A: &'static str = "a"; | ||
pub const INPUT_B: &'static str = "b"; | ||
pub const OUTPUT: &'static str = "out"; | ||
|
||
pub fn new() -> Self { | ||
Self {} | ||
} | ||
|
||
pub fn wrapped(self, name: impl Into<String>) -> AnimationNode { | ||
AnimationNode::new_from_nodetype(name.into(), AnimationNodeType::MulQuat(self)) | ||
} | ||
} | ||
|
||
impl NodeLike for MulQuatNode { | ||
fn update(&self, mut ctx: PassContext) -> Result<(), GraphError> { | ||
let a: Quat = ctx.data_back(Self::INPUT_A)?.val(); | ||
let b: Quat = ctx.data_back(Self::INPUT_B)?.val(); | ||
|
||
let output = a * b; | ||
|
||
ctx.set_data_fwd(Self::OUTPUT, output); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn data_input_spec(&self, _: SpecContext) -> PinMap<DataSpec> { | ||
[ | ||
(Self::INPUT_A.into(), DataSpec::Quat), | ||
(Self::INPUT_B.into(), DataSpec::Quat), | ||
] | ||
.into() | ||
} | ||
|
||
fn data_output_spec(&self, _: SpecContext) -> PinMap<DataSpec> { | ||
[(Self::OUTPUT.into(), DataSpec::Quat)].into() | ||
} | ||
|
||
fn display_name(&self) -> String { | ||
"× Multiply Quat".into() | ||
} | ||
} |
Oops, something went wrong.