add physics
This commit is contained in:
48
src/main.rs
48
src/main.rs
@@ -1,3 +1,5 @@
|
||||
use avian3d::PhysicsPlugins;
|
||||
use avian3d::prelude::*;
|
||||
use bevy::core_pipeline::tonemapping::Tonemapping;
|
||||
use bevy::ecs::component::ComponentId;
|
||||
use bevy::ecs::world::DeferredWorld;
|
||||
@@ -9,17 +11,9 @@ use bevy_trenchbroom::prelude::*;
|
||||
|
||||
#[derive(SolidClass, Component, Reflect)]
|
||||
#[reflect(Component)]
|
||||
#[geometry(GeometryProvider::new().smooth_by_default_angle().render())]
|
||||
#[geometry(GeometryProvider::new().convex_collider().smooth_by_default_angle().render())]
|
||||
pub struct Worldspawn;
|
||||
|
||||
#[derive(SolidClass, Component, Reflect, Default)]
|
||||
#[reflect(Component)]
|
||||
#[geometry(GeometryProvider::new().smooth_by_default_angle().render())]
|
||||
pub struct MyBaseClass {
|
||||
/// MY AWESOME VALUE!!
|
||||
pub my_value: u32,
|
||||
}
|
||||
|
||||
#[derive(Resource, Reflect, Debug)]
|
||||
#[reflect(Resource)]
|
||||
struct DebugVisuals {
|
||||
@@ -51,10 +45,13 @@ impl SpawnPoint {
|
||||
|
||||
let mesh = asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/spawn.glb"));
|
||||
|
||||
world
|
||||
.commands()
|
||||
.entity(entity)
|
||||
.insert((Name::new("spawn"), SceneRoot(mesh), t));
|
||||
world.commands().entity(entity).insert((
|
||||
Name::new("spawn"),
|
||||
SceneRoot(mesh),
|
||||
t,
|
||||
RigidBody::Static,
|
||||
ColliderConstructorHierarchy::new(ColliderConstructor::TrimeshFromMesh),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +70,8 @@ fn main() {
|
||||
default_sampler: repeating_image_sampler(false),
|
||||
}));
|
||||
|
||||
app.add_plugins(PhysicsPlugins::default());
|
||||
|
||||
// bevy_flycam setup so we can get a closer look at the scene, mainly for debugging
|
||||
app.add_plugins(PlayerPlugin);
|
||||
|
||||
@@ -90,7 +89,10 @@ fn main() {
|
||||
|
||||
app.add_systems(Startup, write_trenchbroom_config);
|
||||
app.add_systems(PostStartup, setup_scene);
|
||||
app.add_systems(Update, (set_materials_unlit, set_tonemapping, set_shadows));
|
||||
app.add_systems(
|
||||
Update,
|
||||
(set_materials_unlit, set_tonemapping, set_shadows, spawn_box),
|
||||
);
|
||||
|
||||
app.run();
|
||||
}
|
||||
@@ -116,6 +118,24 @@ fn setup_scene(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
),));
|
||||
}
|
||||
|
||||
fn spawn_box(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
keys: Res<ButtonInput<KeyCode>>,
|
||||
) {
|
||||
if keys.just_pressed(KeyCode::Enter) {
|
||||
commands.spawn((
|
||||
RigidBody::Dynamic,
|
||||
Collider::cuboid(1.0, 1.0, 1.0),
|
||||
AngularVelocity(Vec3::new(2.5, 3.5, 1.5)),
|
||||
Mesh3d(meshes.add(Cuboid::from_length(1.0))),
|
||||
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
|
||||
Transform::from_xyz(0.0, 4.0, 0.0),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
fn write_trenchbroom_config(server: Res<TrenchBroomServer>) {
|
||||
server.config.write_folder("trenchbroom/hedz").unwrap()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user