Cowboy prototyping

This commit is contained in:
Danny McGee
2023-10-10 19:46:40 -04:00
parent c84fd31387
commit 86a948ef09
17 changed files with 1191 additions and 40 deletions
+32 -5
View File
@@ -1,3 +1,4 @@
use bevy::math::vec3;
#[rustfmt::skip]
use bevy::{
pbr::NotShadowCaster,
@@ -6,7 +7,10 @@ use bevy::{
render::render_resource::{AsBindGroup, ShaderRef},
};
use crate::orbit_cam::{CameraMotionSystem, OrbitCam};
use crate::{
interaction::Selected,
orbit_cam::{CameraMotionSystem, OrbitCam},
};
pub struct TestScenePlugin;
@@ -15,6 +19,7 @@ impl Plugin for TestScenePlugin {
app.insert_resource(ClearColor(Color::hsl(0.0, 0.0, 0.25)))
.add_plugins(MaterialPlugin::<ProceduralGridMaterial>::default())
.add_systems(Startup, spawn_scene)
.add_systems(Update, right_round_round_round)
.add_systems(PostUpdate, move_plane_with_camera.after(CameraMotionSystem));
}
}
@@ -22,6 +27,9 @@ impl Plugin for TestScenePlugin {
#[derive(Component)]
struct WorldGridPlane;
#[derive(Component)]
struct Spin(Vec3); // TODO: Debug
fn spawn_scene(
mut cmd: Commands,
assets: Res<AssetServer>,
@@ -29,10 +37,18 @@ fn spawn_scene(
mut mat_proc_grid: ResMut<Assets<ProceduralGridMaterial>>,
) {
// Skeletal mesh
cmd.spawn(SceneBundle {
scene: assets.load("gltf/base_human_male.gltf#Scene0"),
..default()
});
cmd.spawn((SpatialBundle::default(), Spin(Vec3::Y * 0.5)))
.with_children(|parent| {
parent.spawn((
SceneBundle {
scene: assets.load("gltf/base_human_male.gltf#Scene0"),
transform: Transform::from_translation(vec3(0., 0., 2.5)),
..default()
},
Selected,
Spin(vec3(0., -1.5, 1.)),
));
});
// Plane
let plane = meshes.add(Mesh::from(shape::Plane {
@@ -79,6 +95,17 @@ fn move_plane_with_camera(
}
}
fn right_round_round_round(mut q_spin: Query<(&mut Transform, &Spin)>, time: Res<Time>) {
let dt = time.delta_seconds();
for (mut xform, spin) in q_spin.iter_mut() {
let speed = spin.0.length();
let axis = spin.0 / speed;
xform.rotate_local_axis(axis, std::f32::consts::PI * speed * dt);
}
}
#[derive(AsBindGroup, Clone, TypePath, TypeUuid)]
#[uuid = "CE331A13-F247-4F5B-A75E-670B2BD5776A"]
struct ProceduralGridMaterial {}