Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.

Commit 4d48747

Browse files
committed
build fix
1 parent f9f0201 commit 4d48747

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

rpg-tutorial1-character-controller/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ edition = "2018"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
fyrox = {path = "../../fyrox", version = "0.28"}
9+
fyrox = {path = "../../fyrox", version = "0.29"}

rpg-tutorial1-character-controller/src/level/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use fyrox::{
22
core::pool::Handle,
3-
engine::resource_manager::{ ResourceManager},
3+
engine::resource_manager::ResourceManager,
44
scene::{node::Node, Scene},
55
};
66

@@ -11,12 +11,10 @@ pub struct Level {
1111
impl Level {
1212
pub async fn new(resource_manager: ResourceManager, scene: &mut Scene) -> Self {
1313
let root = resource_manager
14-
.request_model(
15-
"data/levels/level.rgs"
16-
)
14+
.request_model("data/levels/level.rgs")
1715
.await
1816
.unwrap()
19-
.instantiate_geometry(scene);
17+
.instantiate(scene);
2018

2119
Self { root }
2220
}

rpg-tutorial1-character-controller/src/player/mod.rs

+36-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::player::camera::CameraController;
22
use fyrox::{
33
animation::{
4-
machine::{Machine, Parameter, PoseNode, State, Transition},
4+
machine::{Machine, MachineLayer, Parameter, PoseNode, State, Transition},
55
Animation,
66
},
77
core::{
@@ -12,9 +12,14 @@ use fyrox::{
1212
event::{DeviceEvent, ElementState, KeyboardInput, VirtualKeyCode},
1313
resource::model::Model,
1414
scene::{
15-
base::BaseBuilder, collider::ColliderBuilder, collider::ColliderShape,
16-
graph::physics::CoefficientCombineRule, node::Node, rigidbody::RigidBodyBuilder,
17-
transform::TransformBuilder, Scene,
15+
animation::AnimationPlayer,
16+
base::BaseBuilder,
17+
collider::{ColliderBuilder, ColliderShape},
18+
graph::physics::CoefficientCombineRule,
19+
node::Node,
20+
rigidbody::RigidBodyBuilder,
21+
transform::TransformBuilder,
22+
Scene,
1823
},
1924
};
2025

@@ -44,7 +49,7 @@ impl Player {
4449
.request_model("data/models/paladin/paladin.fbx")
4550
.await
4651
.unwrap()
47-
.instantiate_geometry(scene);
52+
.instantiate(scene);
4853

4954
// Scale down paladin's model because it is too big.
5055
scene.graph[model]
@@ -218,20 +223,20 @@ impl Player {
218223
fn create_play_animation_state(
219224
animation_resource: Model,
220225
name: &str,
221-
machine: &mut Machine,
226+
layer: &mut MachineLayer,
222227
scene: &mut Scene,
223228
model: Handle<Node>,
224229
) -> (Handle<Animation>, Handle<State>) {
225230
// Animations retargetting just makes an instance of animation and binds it to
226231
// given model using names of bones.
227232
let animation = *animation_resource
228-
.retarget_animations(model, scene)
233+
.retarget_animations(model, &mut scene.graph)
229234
.get(0)
230235
.unwrap();
231236
// Create new PlayAnimation node and add it to machine.
232-
let node = machine.add_node(PoseNode::make_play_animation(animation));
237+
let node = layer.add_node(PoseNode::make_play_animation(animation));
233238
// Make a state using the node we've made.
234-
let state = machine.add_state(State::new(name, node));
239+
let state = layer.add_state(State::new(name, node));
235240
(animation, state)
236241
}
237242

@@ -242,6 +247,7 @@ pub struct AnimationMachineInput {
242247

243248
pub struct AnimationMachine {
244249
machine: Machine,
250+
animation_player: Handle<Node>,
245251
}
246252

247253
impl AnimationMachine {
@@ -254,7 +260,13 @@ impl AnimationMachine {
254260
model: Handle<Node>,
255261
resource_manager: ResourceManager,
256262
) -> Self {
257-
let mut machine = Machine::new(model);
263+
let animation_player = scene.graph.find(model, &mut |n| {
264+
n.query_component_ref::<AnimationPlayer>().is_some()
265+
});
266+
267+
let mut machine = Machine::new();
268+
269+
let root = machine.layers_mut().first_mut().unwrap();
258270

259271
// Load animations in parallel.
260272
let (walk_animation_resource, idle_animation_resource) = fyrox::core::futures::join!(
@@ -266,21 +278,21 @@ impl AnimationMachine {
266278
let (_, idle_state) = create_play_animation_state(
267279
idle_animation_resource.unwrap(),
268280
"Idle",
269-
&mut machine,
281+
root,
270282
scene,
271283
model,
272284
);
273285

274286
let (walk_animation, walk_state) = create_play_animation_state(
275287
walk_animation_resource.unwrap(),
276288
"Walk",
277-
&mut machine,
289+
root,
278290
scene,
279291
model,
280292
);
281293

282294
// Next, define transitions between states.
283-
machine.add_transition(Transition::new(
295+
root.add_transition(Transition::new(
284296
// A name for debugging.
285297
"Idle->Walk",
286298
// Source state.
@@ -292,7 +304,7 @@ impl AnimationMachine {
292304
// A name of transition rule parameter.
293305
Self::IDLE_TO_WALK,
294306
));
295-
machine.add_transition(Transition::new(
307+
root.add_transition(Transition::new(
296308
"Walk->Idle",
297309
walk_state,
298310
idle_state,
@@ -301,18 +313,25 @@ impl AnimationMachine {
301313
));
302314

303315
// Define entry state.
304-
machine.set_entry_state(idle_state);
316+
root.set_entry_state(idle_state);
305317

306-
Self { machine }
318+
Self {
319+
machine,
320+
animation_player,
321+
}
307322
}
308323

309324
pub fn update(&mut self, scene: &mut Scene, dt: f32, input: AnimationMachineInput) {
325+
let animation_player = scene.graph[self.animation_player]
326+
.query_component_ref::<AnimationPlayer>()
327+
.unwrap();
328+
310329
self.machine
311330
// Set transition parameters.
312331
.set_parameter(Self::WALK_TO_IDLE, Parameter::Rule(!input.walk))
313332
.set_parameter(Self::IDLE_TO_WALK, Parameter::Rule(input.walk))
314333
// Update machine and evaluate final pose.
315-
.evaluate_pose(&scene.animations, dt)
334+
.evaluate_pose(animation_player.animations(), dt)
316335
// Apply the pose to the graph.
317336
.apply(&mut scene.graph);
318337
}

0 commit comments

Comments
 (0)