block textures

This commit is contained in:
griffi-gh 2023-01-26 03:50:38 +01:00
parent dfdcc3e4b7
commit 941f563059
3 changed files with 48 additions and 22 deletions

View file

@ -25,6 +25,28 @@ impl Block {
collision: CollisionType::Solid, collision: CollisionType::Solid,
raycast_collision: true, raycast_collision: true,
}, },
Self::Dirt => BlockDescriptor {
name: "dirt",
render: RenderType::SolidBlock(CubeTexture::all(BlockTexture::Dirt)),
collision: CollisionType::Solid,
raycast_collision: true,
},
Self::Grass => BlockDescriptor {
name: "grass",
render: RenderType::SolidBlock(CubeTexture::top_sides_bottom(
BlockTexture::GrassTop,
BlockTexture::GrassSide,
BlockTexture::Dirt
)),
collision: CollisionType::Solid,
raycast_collision: true,
},
Self::Sand => BlockDescriptor {
name: "sand",
render: RenderType::SolidBlock(CubeTexture::all(BlockTexture::Sand)),
collision: CollisionType::Solid,
raycast_collision: true,
},
_ => todo!() _ => todo!()
} }
} }

View file

@ -1,6 +1,6 @@
use strum::{EnumIter, IntoEnumIterator}; use strum::{EnumIter, IntoEnumIterator};
use glam::{Vec3A, vec3a, IVec3, ivec3}; use glam::{Vec3A, vec3a, IVec3, ivec3};
use super::{render::ChunkVertex, chunk::CHUNK_SIZE, block::Block}; use super::{render::ChunkVertex, chunk::CHUNK_SIZE, block::{Block, RenderType}};
pub mod data; pub mod data;
use data::MeshGenData; use data::MeshGenData;
@ -103,26 +103,29 @@ pub fn generate_mesh(data: MeshGenData) -> (Vec<ChunkVertex>, Vec<u32>) {
for z in 0..CHUNK_SIZE { for z in 0..CHUNK_SIZE {
let coord = ivec3(x as i32, y as i32, z as i32); let coord = ivec3(x as i32, y as i32, z as i32);
let block = get_block(coord); let block = get_block(coord);
if block == Block::Air { let descriptor = block.descriptor();
if matches!(descriptor.render, RenderType::None) {
continue continue
} }
for face in CubeFace::iter() { for face in CubeFace::iter() {
let facing = CUBE_FACE_NORMALS[face as usize].as_ivec3(); let facing = CUBE_FACE_NORMALS[face as usize].as_ivec3();
let facing_coord = coord + facing; let facing_coord = coord + facing;
let show = { let show = matches!(get_block(facing_coord).descriptor().render, RenderType::None);
get_block(facing_coord) == Block::Air
};
if show { if show {
// let texures = descriptor.render.unwrap().1; match descriptor.render {
// let block_texture = match face { RenderType::SolidBlock(textures) => {
// CubeFace::Top => texures.top, let face_texture = match face {
// CubeFace::Front => texures.front, CubeFace::Top => textures.top,
// CubeFace::Left => texures.left, CubeFace::Front => textures.front,
// CubeFace::Right => texures.right, CubeFace::Left => textures.left,
// CubeFace::Back => texures.back, CubeFace::Right => textures.right,
// CubeFace::Bottom => texures.bottom, CubeFace::Back => textures.back,
// }; CubeFace::Bottom => textures.bottom,
builder.add_face(face, coord, 0); };
builder.add_face(face, coord, face_texture as u8);
},
_ => unimplemented!()
}
} }
} }
} }

View file

@ -6,17 +6,18 @@ use super::{
pub fn generate_world(position: IVec3, _seed: u32) -> BlockData { pub fn generate_world(position: IVec3, _seed: u32) -> BlockData {
let mut blocks = Box::new([[[Block::Air; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE]); let mut blocks = Box::new([[[Block::Air; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE]);
if position.y == -1 {
for x in 0..CHUNK_SIZE {
for z in 0..CHUNK_SIZE {
blocks[x][0][z] = Block::Grass;
}
}
} else {
blocks[0][0][0] = Block::Stone; blocks[0][0][0] = Block::Stone;
blocks[1][0][0] = Block::Stone; blocks[1][0][0] = Block::Stone;
blocks[0][1][0] = Block::Stone; blocks[0][1][0] = Block::Stone;
blocks[0][2][0] = Block::Stone; blocks[0][2][0] = Block::Stone;
blocks[0][0][1] = Block::Stone; blocks[0][0][1] = Block::Stone;
if position.y == 0 {
for x in 0..CHUNK_SIZE {
for z in 0..CHUNK_SIZE {
blocks[x][0][z] = Block::Stone;
}
}
} }
//TODO actual world generation //TODO actual world generation
blocks blocks