Skip to content

Commit

Permalink
update example on GLTF to use names
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Jan 1, 2021
1 parent 85768bf commit d22dad0
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions examples/3d/load_gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ fn main() {
.add_resource(Msaa { samples: 4 })
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())
.add_system(display_only_parts.system())
.run();
}

Expand All @@ -21,3 +22,36 @@ fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
..Default::default()
});
}

// When pressing spacebar, it will display only part of the model, rotating between the parts
fn display_only_parts(
mut enabled: Local<bool>,
keyboard_input: Res<Input<KeyCode>>,
time: Res<Time>,
mut names: Query<(&mut Transform, &bevy::core::Name)>,
) {
if keyboard_input.just_pressed(KeyCode::Space) {
*enabled = !*enabled;
for (mut transform, _) in names.iter_mut() {
transform.translation.x = 0.0
}
}

if *enabled {
let nodes = vec![
Name::new("Hose_low".to_string()),
Name::new("RubberWood_low".to_string()),
Name::new("GlassPlastic_low".to_string()),
Name::new("MetalParts_low".to_string()),
Name::new("LeatherParts_low".to_string()),
Name::new("Lenses_low".to_string()),
];
for (mut transform, name) in names.iter_mut() {
if *name == nodes[time.seconds_since_startup().floor() as usize % 6] {
transform.translation.x = 0.0
} else {
transform.translation.x = 500.0
}
}
}
}

0 comments on commit d22dad0

Please sign in to comment.