mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-22 11:50:53 +00:00
528e13a250
* feat(bevy_gltf_components): * create crate * added SystemSet (GltfComponentsSet) to run process_loaded_scenes (where components are injected) in a specific systemset & allow ordering other systems relative to it * feat(bevy_gltf_blueprints): * created crate * made the blueprint library path configurable * added BluePrintBundle helper * added SystemSet (GltfBlueprintsSet) for better system ordering * integrated into advanced demo * feat(tools-blender-auto-export): * renamed blender tool to gltf_auto_export * rewritten auto_export * added blueprint / prefab support * creates scene with empties with BlueprintName components in the scene * export of the main scene now exports this scene instead of real main scene * changes collection stand in names in original scene & sets them back after export to have correctly named collection instance exports * also added an additional 'SpawnHere' component to not conflate BlueprintNames & spawning requests * toggling & blueprint library output parameters added * added correct handling/ restoring of saved selection when using blueprints * feat(examples): * added advanced example * general example renamed to "basic", and cleaned up * feat(various): a lot of experiments with saving & loading etc * chore(assets): updated blend & generated assets * fix(examples-advanced): disabling hot reloading as it messes up scenes in experiments with save & loading * docs(): * added & fleshing out docs for the various crates & main README * added process doc image & tweaks to README * added missing licence info where relevant * fixed broken links * clarified some aspects * added updated screenshots where relevant * added tweaks & improvements etc
110 lines
3.0 KiB
Rust
110 lines
3.0 KiB
Rust
use bevy::prelude::*;
|
|
use bevy_rapier3d::prelude::*;
|
|
use crate::insert_dependant_component;
|
|
|
|
// this file is just for demo purposes, contains various types of components, systems etc
|
|
|
|
#[derive(Component, Reflect, Default, Debug, )]
|
|
#[reflect(Component)]
|
|
pub enum SoundMaterial{
|
|
Metal,
|
|
Wood,
|
|
Rock,
|
|
Cloth,
|
|
Squishy,
|
|
#[default]
|
|
None
|
|
}
|
|
|
|
|
|
#[derive(Component, Reflect, Default, Debug, )]
|
|
#[reflect(Component)]
|
|
/// Demo marker component
|
|
pub struct Player;
|
|
|
|
#[derive(Component, Reflect, Default, Debug, )]
|
|
#[reflect(Component)]
|
|
/// Demo component showing auto injection of components
|
|
pub struct ShouldBeWithPlayer;
|
|
|
|
|
|
#[derive(Component, Reflect, Default, Debug, )]
|
|
#[reflect(Component)]
|
|
/// Demo marker component
|
|
pub struct Interactible;
|
|
|
|
#[derive(Component, Reflect, Default, Debug, )]
|
|
#[reflect(Component)]
|
|
/// Demo marker component
|
|
pub struct Pickable;
|
|
|
|
|
|
|
|
fn player_move_demo(
|
|
keycode: Res<Input<KeyCode>>,
|
|
mut players: Query<&mut Transform, With<Player>>,
|
|
){
|
|
|
|
let speed = 0.2;
|
|
if let Ok(mut player) = players.get_single_mut() {
|
|
if keycode.pressed(KeyCode::Left) {
|
|
player.translation.x += speed;
|
|
}
|
|
if keycode.pressed(KeyCode::Right) {
|
|
player.translation.x -= speed;
|
|
}
|
|
|
|
if keycode.pressed(KeyCode::Up) {
|
|
player.translation.z += speed;
|
|
}
|
|
if keycode.pressed(KeyCode::Down) {
|
|
player.translation.z -= speed;
|
|
}
|
|
}
|
|
}
|
|
|
|
// collision tests/debug
|
|
pub fn test_collision_events(
|
|
mut collision_events: EventReader<CollisionEvent>,
|
|
mut contact_force_events: EventReader<ContactForceEvent>,
|
|
)
|
|
{
|
|
for collision_event in collision_events.iter() {
|
|
println!("collision");
|
|
match collision_event {
|
|
CollisionEvent::Started(_entity1, _entity2 ,_) => {
|
|
println!("collision started")
|
|
}
|
|
CollisionEvent::Stopped(_entity1, _entity2 ,_) => {
|
|
println!("collision ended")
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
for contact_force_event in contact_force_events.iter() {
|
|
println!("Received contact force event: {:?}", contact_force_event);
|
|
}
|
|
}
|
|
|
|
|
|
pub struct DemoPlugin;
|
|
impl Plugin for DemoPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app
|
|
.register_type::<Interactible>()
|
|
.register_type::<Pickable>()
|
|
.register_type::<SoundMaterial>()
|
|
.register_type::<Player>()
|
|
// little helper utility, to automatically inject components that are dependant on an other component
|
|
// ie, here an Entity with a Player component should also always have a ShouldBeWithPlayer component
|
|
// you get a warning if you use this, as I consider this to be stop-gap solution (usually you should have either a bundle, or directly define all needed components)
|
|
.add_systems(Update, (
|
|
insert_dependant_component::<Player, ShouldBeWithPlayer>,
|
|
player_move_demo, //.run_if(in_state(AppState::Running)),
|
|
test_collision_events
|
|
))
|
|
;
|
|
}
|
|
}
|