Skip to content

Commit

Permalink
Merge pull request #624 from AmbientRun/fix-anim-ref-count
Browse files Browse the repository at this point in the history
Fix animation node refcount handling
  • Loading branch information
FredrikNoren authored Jul 28, 2023
2 parents f43e866 + 66dce30 commit 9e99c8b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion guest/rust/api_core/src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ impl AnimationPlayer {

/// An animation node. Used in the animation player. It keeps an internal ref count.
#[derive(Debug)]
pub struct AnimationNode(pub EntityId);
pub struct AnimationNode(EntityId);
impl AnimationNode {
/// Use an existing node
pub fn from_entity(entity: EntityId) -> Self {
entity::mutate_component(entity, ref_count(), |x| *x += 1);
Self(entity)
}
}
impl Clone for AnimationNode {
fn clone(&self) -> Self {
entity::mutate_component(self.0, ref_count(), |x| *x += 1);
Expand Down Expand Up @@ -87,6 +94,10 @@ impl PlayClipFromUrlNode {
.spawn();
Self(AnimationNode(node))
}
/// Use an existing node
pub fn from_entity(entity: EntityId) -> Self {
Self(AnimationNode::from_entity(entity))
}
/// Set if the animation should loop or not
pub fn looping(&self, value: bool) {
entity::add_component(self.0 .0, looping(), value);
Expand Down Expand Up @@ -194,6 +205,10 @@ impl BlendNode {
entity::add_component(right.0, parent(), node);
Self(AnimationNode(node))
}
/// Use an existing node
pub fn from_entity(entity: EntityId) -> Self {
Self(AnimationNode::from_entity(entity))
}
/// Set the weight of this blend node.
///
/// If the weight is 0, only the left animation will play.
Expand Down

0 comments on commit 9e99c8b

Please sign in to comment.