forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathempty_variable_curve.rs
103 lines (89 loc) · 3.04 KB
/
empty_variable_curve.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use std::time::Duration;
use uuid::Uuid;
use bevy::{
animation::{AnimationTarget, AnimationTargetId},
app::App,
asset::{DirectAssetAccessExt, Handle},
core::Name,
math::Quat,
prelude::{
AnimationClip, AnimationGraph, AnimationPlayer, AnimationTransitions, BuildWorldChildren,
Transform, TransformBundle, VariableCurve,
},
};
/// [Issue 14776](https://github.com/bevyengine/bevy/issues/14766)
///
/// An [`AnimationClip`] that has an empty [`VariableCurve`] would causes an `attempt to subtract with overflow`
/// on play.
#[test]
fn empty_variable_curve() {
let mut app = App::new();
app.add_plugins((
bevy_internal::asset::AssetPlugin::default(),
bevy_internal::time::TimePlugin,
bevy_internal::animation::AnimationPlugin,
));
let root_target_id = AnimationTargetId(Uuid::new_v4());
let point_target_id = AnimationTargetId(Uuid::new_v4());
let mut animation_clip = AnimationClip::default();
animation_clip.add_curve_to_target(
root_target_id,
VariableCurve {
keyframe_timestamps: vec![0., 16.],
keyframes: bevy::prelude::Keyframes::Rotation(vec![
Quat::default(),
Quat::from_euler(
bevy::math::EulerRot::XYZ,
std::f32::consts::FRAC_PI_2,
0.,
0.,
),
]),
interpolation: bevy::prelude::Interpolation::Linear,
},
);
animation_clip.add_curve_to_target(
point_target_id,
VariableCurve {
keyframe_timestamps: vec![],
keyframes: bevy::prelude::Keyframes::Rotation(vec![]),
interpolation: bevy::prelude::Interpolation::Linear,
},
);
let animation_clip_handle = app.world_mut().add_asset(animation_clip);
let (animation_graph, node_index) = AnimationGraph::from_clip(animation_clip_handle);
let animation_graph_handle: Handle<AnimationGraph> = app.world_mut().add_asset(animation_graph);
let mut animation_player = AnimationPlayer::default();
let mut animation_transitions = AnimationTransitions::new();
animation_transitions.play(&mut animation_player, node_index, Duration::ZERO);
let root = app
.world_mut()
.spawn((
Name::new("root"),
TransformBundle::default(),
animation_player,
animation_transitions,
animation_graph_handle,
))
.id();
app.world_mut()
.entity_mut(root)
.insert(AnimationTarget {
id: root_target_id,
player: root,
})
.with_children(|builder| {
builder.spawn((
Name::new("point"),
TransformBundle {
local: Transform::from_xyz(3., 0., 0.),
..Default::default()
},
AnimationTarget {
id: point_target_id,
player: root,
},
));
});
app.update();
}