mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-22 14:58:44 -06:00
block textures
This commit is contained in:
parent
dfdcc3e4b7
commit
941f563059
|
@ -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!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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]);
|
||||||
blocks[0][0][0] = Block::Stone;
|
if position.y == -1 {
|
||||||
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 {
|
|
||||||
for x in 0..CHUNK_SIZE {
|
for x in 0..CHUNK_SIZE {
|
||||||
for z 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
|
//TODO actual world generation
|
||||||
blocks
|
blocks
|
||||||
|
|
Loading…
Reference in a new issue