support setting spawn point
This commit is contained in:
@@ -213,3 +213,9 @@
|
||||
( 3840 832 320 ) ( 3840 832 321 ) ( 3840 833 320 ) TinyTexPack2/Brick/Brick_14_window [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1
|
||||
}
|
||||
}
|
||||
// entity 1
|
||||
{
|
||||
"classname" "spawn_point"
|
||||
"origin" "152 232 -248"
|
||||
"scale" "50"
|
||||
}
|
||||
|
||||
BIN
assets/models/spawn.glb
Normal file
BIN
assets/models/spawn.glb
Normal file
Binary file not shown.
52
src/main.rs
52
src/main.rs
@@ -1,6 +1,9 @@
|
||||
use bevy::core_pipeline::tonemapping::Tonemapping;
|
||||
use bevy::ecs::component::ComponentId;
|
||||
use bevy::ecs::world::DeferredWorld;
|
||||
use bevy::math::*;
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::view::ColorGrading;
|
||||
use bevy_flycam::prelude::*;
|
||||
use bevy_trenchbroom::prelude::*;
|
||||
|
||||
@@ -22,6 +25,37 @@ pub struct MyBaseClass {
|
||||
struct DebugVisuals {
|
||||
pub unlit: bool,
|
||||
pub tonemapping: Tonemapping,
|
||||
pub exposure: f32,
|
||||
pub shadows: bool,
|
||||
}
|
||||
|
||||
#[derive(PointClass, Component, Reflect, Default)]
|
||||
#[reflect(Component)]
|
||||
#[require(Transform)]
|
||||
#[component(on_add = Self::on_add)]
|
||||
#[model({ "path": "models/spawn.glb", "scale": scale })]
|
||||
pub struct SpawnPoint {
|
||||
scale: f32,
|
||||
}
|
||||
|
||||
impl SpawnPoint {
|
||||
fn on_add(mut world: DeferredWorld, entity: Entity, _id: ComponentId) {
|
||||
let Some(asset_server) = world.get_resource::<AssetServer>() else {
|
||||
return;
|
||||
};
|
||||
|
||||
// let scale = world.entity(entity).get::<Self>().unwrap().scale;
|
||||
|
||||
let mut t = world.entity(entity).get::<Transform>().unwrap().clone();
|
||||
t.scale = Vec3::splat(1.0);
|
||||
|
||||
let mesh = asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/spawn.glb"));
|
||||
|
||||
world
|
||||
.commands()
|
||||
.entity(entity)
|
||||
.insert((Name::new("spawn"), SceneRoot(mesh), t));
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -31,6 +65,8 @@ fn main() {
|
||||
app.insert_resource(DebugVisuals {
|
||||
unlit: true,
|
||||
tonemapping: Tonemapping::None,
|
||||
exposure: 0.,
|
||||
shadows: false,
|
||||
});
|
||||
|
||||
app.add_plugins(DefaultPlugins.set(ImagePlugin {
|
||||
@@ -54,7 +90,7 @@ fn main() {
|
||||
|
||||
app.add_systems(Startup, write_trenchbroom_config);
|
||||
app.add_systems(PostStartup, setup_scene);
|
||||
app.add_systems(Update, (set_materials_unlit, set_tonemapping));
|
||||
app.add_systems(Update, (set_materials_unlit, set_tonemapping, set_shadows));
|
||||
|
||||
app.run();
|
||||
}
|
||||
@@ -84,9 +120,13 @@ fn write_trenchbroom_config(server: Res<TrenchBroomServer>) {
|
||||
server.config.write_folder("trenchbroom/hedz").unwrap()
|
||||
}
|
||||
|
||||
fn set_tonemapping(mut cams: Query<&mut Tonemapping, With<Camera>>, visuals: Res<DebugVisuals>) {
|
||||
for mut tm in cams.iter_mut() {
|
||||
fn set_tonemapping(
|
||||
mut cams: Query<(&mut Tonemapping, &mut ColorGrading), With<Camera>>,
|
||||
visuals: Res<DebugVisuals>,
|
||||
) {
|
||||
for (mut tm, mut color) in cams.iter_mut() {
|
||||
*tm = visuals.tonemapping;
|
||||
color.global.exposure = visuals.exposure;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,3 +142,9 @@ fn set_materials_unlit(
|
||||
material.unlit = visuals.unlit;
|
||||
}
|
||||
}
|
||||
|
||||
fn set_shadows(mut lights: Query<&mut DirectionalLight>, visuals: Res<DebugVisuals>) {
|
||||
for mut l in lights.iter_mut() {
|
||||
l.shadows_enabled = visuals.shadows;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,11 @@
|
||||
my_value(integer) : "my_value" : 0 : "MY AWESOME VALUE!!"
|
||||
]
|
||||
|
||||
@PointClass base(transform) model({ "path": "models/spawn.glb", "scale": scale }) = spawn_point
|
||||
[
|
||||
scale(float) : "scale" : "0" : ""
|
||||
]
|
||||
|
||||
@BaseClass = transform
|
||||
[
|
||||
origin(vector) : "Translation/Origin" : "0 0 0" : ""
|
||||
|
||||
Reference in New Issue
Block a user