diff --git a/engine/world_generation/src/mesh_generator.rs b/engine/world_generation/src/mesh_generator.rs index 5daa750..310d8dd 100644 --- a/engine/world_generation/src/mesh_generator.rs +++ b/engine/world_generation/src/mesh_generator.rs @@ -74,7 +74,7 @@ fn create_tile( let y_min = tex_y as f32 / 8.; const TX_UNIT: Vec2 = Vec2::new(1. / 11., 1. / 8.); - let uv_offset = Vec2::new(x_min + TX_UNIT.x / 2., y_min + TX_UNIT.y / 2.); + let uv_offset = Vec2::splat(0.5); let idx = verts.len() as u32; uvs.push(uv_offset); @@ -82,7 +82,7 @@ fn create_tile( for i in 0..6 { let p = pos + HEX_CORNERS[i]; verts.push(p); - let uv = (HEX_CORNERS[i].xz() * TX_UNIT / 2.) + uv_offset; + let uv = (HEX_CORNERS[i].xz() / 2.) + uv_offset; uvs.push(uv); indices.push(idx); indices.push(idx + 1 + i as u32); @@ -94,16 +94,7 @@ fn create_tile( match cur_n { Some(n_height) => { if n_height < pos.y { - create_tile_wall( - pos, - i, - n_height, - verts, - uvs, - indices, - Vec2::new(x_min, y_min), - Vec2::new(x_min + TX_UNIT.x, y_min + TX_UNIT.y), - ); + create_tile_wall(pos, i, n_height, verts, uvs, indices, Vec2::ZERO, Vec2::ONE); } } _ => {} diff --git a/game/main/assets/textures/world/stack.png b/game/main/assets/textures/world/stack.png new file mode 100644 index 0000000..daf9589 Binary files /dev/null and b/game/main/assets/textures/world/stack.png differ diff --git a/game/main/src/phos.rs b/game/main/src/phos.rs index f871d4b..f1422c0 100644 --- a/game/main/src/phos.rs +++ b/game/main/src/phos.rs @@ -1,4 +1,4 @@ -use bevy::pbr::MaterialExtension; +use bevy::pbr::{ExtendedMaterial, MaterialExtension}; use bevy::render::render_resource::{AsBindGroup, ShaderRef}; use bevy::{pbr::CascadeShadowConfig, prelude::*}; use camera_system::PhosCameraPlugin; @@ -47,11 +47,22 @@ fn init_game(mut commands: Commands) { }); } -fn load_textures(mut commands: Commands, asset_server: Res) { - let main_tex = asset_server.load("textures/world/test2.png"); +fn load_textures( + mut commands: Commands, + asset_server: Res, + mut images: ResMut>, +) { + let main_tex = asset_server.load("textures/world/stack.png"); commands.insert_resource(ChunkAtlas { handle: main_tex.clone(), }); + + //todo: wait for texture to load + let image = images.get_mut(&main_tex).unwrap(); + + // Create a new array texture asset from the loaded texture. + let array_layers = 7; + image.reinterpret_stacked_2d_as_array(array_layers); } fn draw_gizmos(mut gizmos: Gizmos, hm: Res) { @@ -84,9 +95,10 @@ fn draw_gizmos(mut gizmos: Gizmos, hm: Res) { } } +//todo: run after textures are ready fn create_map( mut commands: Commands, - mut materials: ResMut>, + mut materials: ResMut>>, mut meshes: ResMut>, atlas: Res, ) { @@ -150,15 +162,20 @@ fn create_map( 2, ); - let chunk_material = materials.add(StandardMaterial { - base_color_texture: Some(atlas.handle.clone()), - ..default() + let chunk_material = materials.add(ExtendedMaterial { + base: StandardMaterial { + base_color: Color::WHITE, + ..default() + }, + extension: ChunkMaterial { + array_texture: atlas.handle.clone(), + }, }); for chunk in &heightmap.chunks { let mesh = generate_chunk_mesh(&chunk, &heightmap); let pos = offset_to_world(chunk.chunk_offset * Chunk::SIZE as i32, 0.); - commands.spawn(PbrBundle { + commands.spawn(MaterialMeshBundle { mesh: meshes.add(mesh), material: chunk_material.clone(), transform: Transform::from_translation(pos),