mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-26 00:38:44 -06:00
block textures
This commit is contained in:
parent
dfdcc3e4b7
commit
941f563059
|
@ -25,6 +25,28 @@ impl Block {
|
|||
collision: CollisionType::Solid,
|
||||
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!()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use strum::{EnumIter, IntoEnumIterator};
|
||||
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;
|
||||
use data::MeshGenData;
|
||||
|
@ -103,26 +103,29 @@ pub fn generate_mesh(data: MeshGenData) -> (Vec<ChunkVertex>, Vec<u32>) {
|
|||
for z in 0..CHUNK_SIZE {
|
||||
let coord = ivec3(x as i32, y as i32, z as i32);
|
||||
let block = get_block(coord);
|
||||
if block == Block::Air {
|
||||
let descriptor = block.descriptor();
|
||||
if matches!(descriptor.render, RenderType::None) {
|
||||
continue
|
||||
}
|
||||
for face in CubeFace::iter() {
|
||||
let facing = CUBE_FACE_NORMALS[face as usize].as_ivec3();
|
||||
let facing_coord = coord + facing;
|
||||
let show = {
|
||||
get_block(facing_coord) == Block::Air
|
||||
};
|
||||
let show = matches!(get_block(facing_coord).descriptor().render, RenderType::None);
|
||||
if show {
|
||||
// let texures = descriptor.render.unwrap().1;
|
||||
// let block_texture = match face {
|
||||
// CubeFace::Top => texures.top,
|
||||
// CubeFace::Front => texures.front,
|
||||
// CubeFace::Left => texures.left,
|
||||
// CubeFace::Right => texures.right,
|
||||
// CubeFace::Back => texures.back,
|
||||
// CubeFace::Bottom => texures.bottom,
|
||||
// };
|
||||
builder.add_face(face, coord, 0);
|
||||
match descriptor.render {
|
||||
RenderType::SolidBlock(textures) => {
|
||||
let face_texture = match face {
|
||||
CubeFace::Top => textures.top,
|
||||
CubeFace::Front => textures.front,
|
||||
CubeFace::Left => textures.left,
|
||||
CubeFace::Right => textures.right,
|
||||
CubeFace::Back => textures.back,
|
||||
CubeFace::Bottom => textures.bottom,
|
||||
};
|
||||
builder.add_face(face, coord, face_texture as u8);
|
||||
},
|
||||
_ => unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,17 +6,18 @@ use super::{
|
|||
|
||||
pub fn generate_world(position: IVec3, _seed: u32) -> BlockData {
|
||||
let mut blocks = Box::new([[[Block::Air; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE]);
|
||||
blocks[0][0][0] = Block::Stone;
|
||||
blocks[1][0][0] = Block::Stone;
|
||||
blocks[0][1][0] = Block::Stone;
|
||||
blocks[0][2][0] = Block::Stone;
|
||||
blocks[0][0][1] = Block::Stone;
|
||||
if position.y == 0 {
|
||||
if position.y == -1 {
|
||||
for x in 0..CHUNK_SIZE {
|
||||
for z in 0..CHUNK_SIZE {
|
||||
blocks[x][0][z] = Block::Stone;
|
||||
blocks[x][0][z] = Block::Grass;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
blocks[0][0][0] = Block::Stone;
|
||||
blocks[1][0][0] = Block::Stone;
|
||||
blocks[0][1][0] = Block::Stone;
|
||||
blocks[0][2][0] = Block::Stone;
|
||||
blocks[0][0][1] = Block::Stone;
|
||||
}
|
||||
//TODO actual world generation
|
||||
blocks
|
||||
|
|
Loading…
Reference in a new issue