Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a node to build Vec3 from three f32 values #58

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use super::{
use crate::{
core::{animation_clip::GraphClip, errors::AssetLoaderError},
nodes::{
AbsF32, AddF32, BlendNode, ChainNode, ClampF32, ClipNode, CompareF32, ConstBool, DivF32,
FSMNode, FireEventNode, FlipLRNode, GraphNode, LoopNode, MulF32, PaddingNode,
RotationArcNode, RotationNode, SpeedNode, SubF32, TwoBoneIKNode,
AbsF32, AddF32, BlendNode, BuildVec3Node, ChainNode, ClampF32, ClipNode, CompareF32,
ConstBool, DivF32, FSMNode, FireEventNode, FlipLRNode, GraphNode, LoopNode, MulF32,
PaddingNode, RotationArcNode, RotationNode, SpeedNode, SubF32, TwoBoneIKNode,
},
prelude::DummyNode,
};
Expand Down Expand Up @@ -192,6 +192,9 @@ impl AssetLoader for AnimationGraphLoader {
AnimationNodeTypeSerial::Padding {
interpolation_period,
} => PaddingNode::new(*interpolation_period).wrapped(&serial_node.name),
AnimationNodeTypeSerial::BuildVec3() => {
BuildVec3Node::new().wrapped(&serial_node.name)
}
};
graph.add_node(node);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub enum AnimationNodeTypeSerial {
CompareF32(CompareOp),
AbsF32,
ConstBool(bool),
BuildVec3(),
RotationArc,
FireEvent(AnimationEvent),
// IntoBoneSpace,
Expand Down Expand Up @@ -182,6 +183,7 @@ impl From<&AnimationNodeType> for AnimationNodeTypeSerial {
AnimationNodeType::CompareF32(n) => AnimationNodeTypeSerial::CompareF32(n.op),
AnimationNodeType::AbsF32(_) => AnimationNodeTypeSerial::AbsF32,
AnimationNodeType::ConstBool(n) => AnimationNodeTypeSerial::ConstBool(n.constant),
AnimationNodeType::BuildVec3(_) => AnimationNodeTypeSerial::BuildVec3(),
AnimationNodeType::RotationArc(_) => AnimationNodeTypeSerial::RotationArc,
AnimationNodeType::Fsm(n) => {
AnimationNodeTypeSerial::Fsm(n.fsm.path().unwrap().to_string())
Expand Down
10 changes: 7 additions & 3 deletions crates/bevy_animation_graph/src/core/animation_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use super::{
};
use crate::{
nodes::{
AbsF32, AddF32, BlendNode, ChainNode, ClampF32, ClipNode, CompareF32, ConstBool, DivF32,
DummyNode, FSMNode, FireEventNode, FlipLRNode, GraphNode, LoopNode, MulF32, PaddingNode,
RotationArcNode, RotationNode, SpeedNode, SubF32, TwoBoneIKNode,
AbsF32, AddF32, BlendNode, BuildVec3Node, ChainNode, ClampF32, ClipNode, CompareF32,
ConstBool, DivF32, DummyNode, FSMNode, FireEventNode, FlipLRNode, GraphNode, LoopNode,
MulF32, PaddingNode, RotationArcNode, RotationNode, SpeedNode, SubF32, TwoBoneIKNode,
},
prelude::{PassContext, SpecContext},
};
Expand Down Expand Up @@ -204,6 +204,7 @@ pub enum AnimationNodeType {
// --- Vec3 arithmetic nodes
// ------------------------------------------------
RotationArc(RotationArcNode),
BuildVec3(BuildVec3Node),
// ------------------------------------------------
Fsm(#[reflect(ignore)] FSMNode),
// HACK: needs to be ignored for now due to:
Expand Down Expand Up @@ -241,6 +242,7 @@ impl AnimationNodeType {
AnimationNodeType::CompareF32(n) => f(n),
AnimationNodeType::AbsF32(n) => f(n),
AnimationNodeType::ConstBool(n) => f(n),
AnimationNodeType::BuildVec3(n) => f(n),
AnimationNodeType::RotationArc(n) => f(n),
AnimationNodeType::Fsm(n) => f(n),
AnimationNodeType::Graph(n) => f(n),
Expand Down Expand Up @@ -276,6 +278,7 @@ impl AnimationNodeType {
AnimationNodeType::CompareF32(n) => f(n),
AnimationNodeType::AbsF32(n) => f(n),
AnimationNodeType::ConstBool(n) => f(n),
AnimationNodeType::BuildVec3(n) => f(n),
AnimationNodeType::RotationArc(n) => f(n),
AnimationNodeType::Fsm(n) => f(n),
AnimationNodeType::Graph(n) => f(n),
Expand Down Expand Up @@ -317,6 +320,7 @@ impl AnimationNodeType {
AnimationNodeType::CompareF32(n) => n,
AnimationNodeType::AbsF32(n) => n,
AnimationNodeType::ConstBool(n) => n,
AnimationNodeType::BuildVec3(n) => n,
AnimationNodeType::RotationArc(n) => n,
AnimationNodeType::Fsm(n) => n,
AnimationNodeType::Graph(n) => n,
Expand Down
55 changes: 55 additions & 0 deletions crates/bevy_animation_graph/src/nodes/arithmetic/vec3/from_f32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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 BuildVec3Node {}

impl BuildVec3Node {
pub const INPUT_X: &'static str = "x";
pub const INPUT_Y: &'static str = "y";
pub const INPUT_Z: &'static str = "z";
pub const OUTPUT: &'static str = "vec";

pub fn new() -> Self {
Self {}
}

pub fn wrapped(self, name: impl Into<String>) -> AnimationNode {
AnimationNode::new_from_nodetype(name.into(), AnimationNodeType::BuildVec3(self))
}
}

impl NodeLike for BuildVec3Node {
fn update(&self, mut ctx: PassContext) -> Result<(), GraphError> {
let x: f32 = ctx.data_back(Self::INPUT_X)?.val();
let y: f32 = ctx.data_back(Self::INPUT_X)?.val();
let z: f32 = ctx.data_back(Self::INPUT_X)?.val();

ctx.set_data_fwd(Self::OUTPUT, Vec3::new(x, y, z));

Ok(())
}

fn data_input_spec(&self, _: SpecContext) -> PinMap<DataSpec> {
[
(Self::INPUT_X.into(), DataSpec::F32),
(Self::INPUT_Y.into(), DataSpec::F32),
(Self::INPUT_Z.into(), DataSpec::F32),
]
.into()
}

fn data_output_spec(&self, _: SpecContext) -> PinMap<DataSpec> {
[(Self::OUTPUT.into(), DataSpec::Vec3)].into()
}

fn display_name(&self) -> String {
"Build Vec3".into()
}
}
2 changes: 2 additions & 0 deletions crates/bevy_animation_graph/src/nodes/arithmetic/vec3/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod from_f32;
mod rotation_arc;

pub use from_f32::*;
pub use rotation_arc::*;
Loading