texture mapping

This commit is contained in:
2024-04-01 23:54:50 -04:00
parent 23ae1391c0
commit 83dbf82478
9 changed files with 66 additions and 18 deletions

View File

@@ -33,7 +33,7 @@ fn setup(mut commands: Commands) {
..default()
},
PhosCamera {
speed: 50.,
speed: 100.,
..default()
},
));

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -1,6 +1,8 @@
use bevy::prelude::*;
use bevy_inspector_egui::quick::WorldInspectorPlugin;
mod phos;
mod prelude;
use phos::PhosGamePlugin;
fn main() {

View File

@@ -6,13 +6,15 @@ use world_generation::{
heightmap::generate_heightmap, mesh_generator::generate_chunk_mesh, prelude::*,
};
use crate::prelude::*;
pub struct PhosGamePlugin;
impl Plugin for PhosGamePlugin {
fn build(&self, app: &mut App) {
app.add_plugins(PhosCameraPlugin);
app.add_systems(Startup, init_game)
.add_systems(Startup, create_map);
.add_systems(Startup, (load_textures, create_map).chain());
app.add_plugins(bevy::diagnostic::FrameTimeDiagnosticsPlugin)
.add_plugins(bevy::diagnostic::EntityCountDiagnosticsPlugin)
.add_plugins(bevy::diagnostic::SystemInformationDiagnosticsPlugin)
@@ -38,11 +40,18 @@ fn init_game(mut commands: Commands) {
bounds: vec![500., 1000., 2000., 5000.],
..default()
},
transform: Transform::from_xyz(500., 160.0, 500.).looking_at(Vec3::ZERO, Vec3::Y),
transform: Transform::from_xyz(500., 260.0, 500.).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
}
fn load_textures(mut commands: Commands, asset_server: Res<AssetServer>) {
let main_tex = asset_server.load("textures/world/test2.png");
commands.insert_resource(ChunkAtlas {
handle: main_tex.clone(),
});
}
fn draw_gizmos(mut gizmos: Gizmos, hm: Res<Map>) {
gizmos.arrow(Vec3::ZERO, Vec3::Y * 1.5, Color::GREEN);
gizmos.arrow(Vec3::ZERO, Vec3::Z * 1.5, Color::BLUE);
@@ -77,6 +86,7 @@ fn create_map(
mut commands: Commands,
mut materials: ResMut<Assets<StandardMaterial>>,
mut meshes: ResMut<Assets<Mesh>>,
atlas: Res<ChunkAtlas>,
) {
let heightmap = generate_heightmap(
&GenerationConfig {
@@ -133,13 +143,13 @@ fn create_map(
noise_scale: 350.,
sea_level: 4.,
border_size: 64.,
size: (32, 32).into(),
size: UVec2::splat(1024 / Chunk::SIZE as u32),
},
2,
);
let debug_material = materials.add(StandardMaterial {
// base_color_texture: Some(images.add(uv_debug_texture())),
let chunk_material = materials.add(StandardMaterial {
base_color_texture: Some(atlas.handle.clone()),
..default()
});
@@ -148,7 +158,7 @@ fn create_map(
let pos = offset_to_world(chunk.chunk_offset * Chunk::SIZE as i32, 0.);
commands.spawn(PbrBundle {
mesh: meshes.add(mesh),
material: debug_material.clone(),
material: chunk_material.clone(),
transform: Transform::from_translation(pos),
..default()
});

7
game/main/src/prelude.rs Normal file
View File

@@ -0,0 +1,7 @@
use bevy::asset::Handle;
use bevy::prelude::{Image, Resource};
#[derive(Resource)]
pub struct ChunkAtlas {
pub handle: Handle<Image>,
}