168 lines
6.1 KiB
Rust
168 lines
6.1 KiB
Rust
use bevy::render::mesh::MeshVertexAttribute;
|
|
use bevy::render::render_resource::VertexFormat;
|
|
use bevy::tasks::TaskPoolBuilder;
|
|
use bevy_egui::EguiPlugin;
|
|
|
|
use bevy::{
|
|
pbr::wireframe::{WireframeConfig, WireframePlugin},
|
|
prelude::*,
|
|
render::settings::WgpuSettings,
|
|
};
|
|
use common::space::level_tile::LevelTile;
|
|
use common::space::three_dimensional::hash_map_container::VoxelHashMapLayer;
|
|
use common::space::three_dimensional::vec3generic::Vec3Generic;
|
|
use common::space::two_dimensional::depth_tiles::DepthTileContainer;
|
|
use components::cursor_layer::VoxelCursorLayer;
|
|
use components::property_pane::PropertyPane;
|
|
use smooth_bevy_cameras::controllers::orbit::{
|
|
OrbitCameraBundle, OrbitCameraController, OrbitCameraPlugin,
|
|
};
|
|
use smooth_bevy_cameras::{LookTransform, LookTransformPlugin};
|
|
use systems::{generic_command_queue::CommandQueue, layer_spawner::LayerSpawnerCommand, ui::ui_spawner::{UiSpawnerCommand, UiSpawnerState}};
|
|
use voxels::bool_voxel::BoolVoxel;
|
|
use voxels::mesh::into_domain;
|
|
mod components;
|
|
mod systems;
|
|
mod voxels;
|
|
|
|
pub const ATTRIBUTE_POSITION: MeshVertexAttribute =
|
|
MeshVertexAttribute::new("Position", 88238261, VertexFormat::Float32x3);
|
|
pub const ATTRIBUTE_NORMAL: MeshVertexAttribute =
|
|
MeshVertexAttribute::new("Normal", 508828962, VertexFormat::Float32x3);
|
|
pub const ATTRIBUTE_UV: MeshVertexAttribute =
|
|
MeshVertexAttribute::new("UV", 1982256274, VertexFormat::Float32x2);
|
|
|
|
fn main() {
|
|
App::new()
|
|
// .insert_resource(WgpuSettings {
|
|
// // features: WgpuFeatures::POLYGON_MODE_LINE,
|
|
// ..Default::default()
|
|
// })
|
|
.insert_resource(Msaa::Sample4)
|
|
.insert_resource(CommandQueue::<LayerSpawnerCommand>::default())
|
|
.insert_resource(CommandQueue::<UiSpawnerCommand>::default())
|
|
.insert_resource(UiSpawnerState::default())
|
|
// .insert_resource(TaskPoolBuilder::new().num_threads(1).build())
|
|
.add_plugins(DefaultPlugins)
|
|
.add_plugins(WireframePlugin)
|
|
.add_plugins(EguiPlugin)
|
|
.add_plugins(LookTransformPlugin)
|
|
.add_plugins(OrbitCameraPlugin {
|
|
override_input_system: false,
|
|
})
|
|
.add_system(systems::ui::layers::layer_ui)
|
|
.add_system(systems::ui::properties::properties_ui)
|
|
.add_system(systems::ui::properties::clean_up_closed_panes)
|
|
.add_system(
|
|
systems::mutable_mesh_refresher::mutable_mesh_refresher::<
|
|
VoxelHashMapLayer<LevelTile>,
|
|
LevelTile,
|
|
>,
|
|
)
|
|
.add_system(
|
|
systems::mutable_mesh_refresher::mutable_mesh_refresher::<
|
|
DepthTileContainer<LevelTile>,
|
|
LevelTile,
|
|
>,
|
|
)
|
|
.add_system(
|
|
systems::mutable_mesh_refresher::mutable_mesh_refresher::<VoxelCursorLayer, BoolVoxel>,
|
|
)
|
|
// .add_system(move_camera_system)
|
|
// .add_system(look_at_cursor_system)
|
|
.add_system(systems::layer_spawner::layer_spawner)
|
|
.add_system(systems::ui::ui_spawner::ui_spawner)
|
|
.add_startup_system(setup)
|
|
.run();
|
|
}
|
|
|
|
fn setup(
|
|
mut commands: Commands,
|
|
mut wireframe_config: ResMut<WireframeConfig>,
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
) {
|
|
wireframe_config.global = false;
|
|
|
|
commands.spawn(PointLightBundle {
|
|
transform: Transform::from_translation(Vec3::new(25.0, 25.0, 25.0)),
|
|
point_light: PointLight {
|
|
range: 200.0,
|
|
intensity: 8000.0,
|
|
..Default::default()
|
|
},
|
|
..Default::default()
|
|
});
|
|
let _camera_bundle = commands
|
|
.spawn(OrbitCameraBundle::new(
|
|
OrbitCameraController::default(),
|
|
Vec3::new(-10.0, 21.0, -10.0),
|
|
Vec3::new(0.0, 0.0, 0.0),
|
|
Vec3::new(0.0, 0.0, 1.0), // up ? (guess)
|
|
))
|
|
.insert(Camera3dBundle::default())
|
|
.insert(PropertyPane::new("Camera".to_string(), false));
|
|
/*.insert_bundle(Camera3dBundle {
|
|
projection: OrthographicProjection {
|
|
scale: 1.0,
|
|
scaling_mode: ScalingMode::FixedVertical(32.0),
|
|
..default()
|
|
}.into(),
|
|
transform: Transform::from_translation(Vec3::new(50.0, 15.0, 50.0))
|
|
.looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y),
|
|
..Default::default()
|
|
}); */
|
|
|
|
voxels::layers::container_to_layer_component(
|
|
"cursor".to_string(),
|
|
VoxelCursorLayer {
|
|
position: Vec3Generic { x: 5, y: 5, z: 3 },
|
|
},
|
|
StandardMaterial::from(Color::rgba(10.0, 0.0, 0.0, 0.5)),
|
|
&mut meshes,
|
|
&mut commands,
|
|
&mut materials,
|
|
);
|
|
|
|
// voxels::layers::container_to_layer_component(
|
|
// "bounds".to_string(),
|
|
// VoxelFnLayer { is_solid: Arc::new(|p: Vec3Generic<i32>| p.x % 3 == 0) },
|
|
// StandardMaterial::from(Color::rgba(0.0, 3.0, 3.0, 0.5)),
|
|
// &mut meshes,
|
|
// &mut commands,
|
|
// &mut materials);
|
|
}
|
|
|
|
// fn move_camera_system(mut cameras: Query<&mut LookTransform>) {
|
|
// for mut c in cameras.iter_mut() {
|
|
// c.target += Vec3::new(1.0, 1.0, 1.0);
|
|
// }
|
|
// }
|
|
|
|
// fn look_at_cursor_system(
|
|
// mut cameras: Query<&mut LookTransform>,
|
|
// cursor_mesh: Query<(&VoxelCursorLayer, &Handle<Mesh>)>,
|
|
// ) {
|
|
// match cursor_mesh.get_single() {
|
|
// Ok((cursor, _cursor_mesh)) => {
|
|
// let cursor_pos = into_domain(/*unused?*/ 0, cursor.position.into());
|
|
// // assume cursor is a single voxel size
|
|
// let cursor_size = into_domain(/*unused?*/ 0, [1, 1, 1]);
|
|
|
|
// // add half the cursor size so that the look target is in the middle of the cursor
|
|
// let look_target = cursor_pos + (cursor_size); //((cursor_pos * 2.0) + 1.0) / 2.0;
|
|
|
|
// let mut camera = cameras.single_mut();
|
|
// camera.target = Vec3 {
|
|
// x: look_target.x,
|
|
// y: look_target.y,
|
|
// z: look_target.z,
|
|
// };
|
|
// }
|
|
// Err(_) => (), // maybe cursor mesh was hidden?
|
|
// }
|
|
// }
|
|
|
|
const SAMPLE_WORLD: &[u8] = include_bytes!("../res/sample_level_2.vox");
|
|
const SAMPLE_WORLD_OLD: &[u8] = include_bytes!("../res/sample_level_1.vox");
|