mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-21 22:38:41 -06:00
refactor transparency descriptor
This commit is contained in:
parent
e1f1ba706c
commit
62c3c2105e
|
@ -63,81 +63,108 @@ impl Block {
|
|||
},
|
||||
Self::Stone => BlockDescriptor {
|
||||
name: "stone",
|
||||
render: RenderType::SolidBlock(CubeTexture::all(BlockTexture::Stone)),
|
||||
render: RenderType::Cube(
|
||||
Transparency::Solid,
|
||||
CubeTexture::all(BlockTexture::Stone)
|
||||
),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Dirt => BlockDescriptor {
|
||||
name: "dirt",
|
||||
render: RenderType::SolidBlock(CubeTexture::all(BlockTexture::Dirt)),
|
||||
render: RenderType::Cube(
|
||||
Transparency::Solid,
|
||||
CubeTexture::all(BlockTexture::Dirt)
|
||||
),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Grass => BlockDescriptor {
|
||||
name: "grass",
|
||||
render: RenderType::SolidBlock(CubeTexture::top_sides_bottom(
|
||||
BlockTexture::GrassTop,
|
||||
BlockTexture::GrassSide,
|
||||
BlockTexture::Dirt
|
||||
)),
|
||||
render: RenderType::Cube(
|
||||
Transparency::Solid,
|
||||
CubeTexture::top_sides_bottom(
|
||||
BlockTexture::GrassTop,
|
||||
BlockTexture::GrassSide,
|
||||
BlockTexture::Dirt
|
||||
)
|
||||
),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Sand => BlockDescriptor {
|
||||
name: "sand",
|
||||
render: RenderType::SolidBlock(CubeTexture::all(BlockTexture::Sand)),
|
||||
render: RenderType::Cube(
|
||||
Transparency::Solid,
|
||||
CubeTexture::all(BlockTexture::Sand)
|
||||
),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Cobblestone => BlockDescriptor {
|
||||
name: "cobblestone",
|
||||
render: RenderType::SolidBlock(CubeTexture::all(BlockTexture::Cobblestone)),
|
||||
render: RenderType::Cube(
|
||||
Transparency::Solid,
|
||||
CubeTexture::all(BlockTexture::Cobblestone)
|
||||
),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::TallGrass => BlockDescriptor {
|
||||
name: "tall grass",
|
||||
render: RenderType::CrossShape(CrossTexture::all(BlockTexture::TallGrass)),
|
||||
render: RenderType::Cross(CrossTexture::all(BlockTexture::TallGrass)),
|
||||
collision: CollisionType::None,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Planks => BlockDescriptor {
|
||||
name: "planks",
|
||||
render: RenderType::SolidBlock(CubeTexture::all(BlockTexture::Planks)),
|
||||
render: RenderType::Cube(
|
||||
Transparency::Solid,
|
||||
CubeTexture::all(BlockTexture::Planks)
|
||||
),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Torch => BlockDescriptor {
|
||||
name: "torch",
|
||||
render: RenderType::CrossShape(CrossTexture::all(BlockTexture::Torch)),
|
||||
render: RenderType::Cross(CrossTexture::all(BlockTexture::Torch)),
|
||||
collision: CollisionType::None,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Wood => BlockDescriptor {
|
||||
name: "leaf",
|
||||
render: RenderType::SolidBlock(CubeTexture::horizontal_vertical(BlockTexture::Wood, BlockTexture::WoodTop)),
|
||||
render: RenderType::Cube(
|
||||
Transparency::Solid,
|
||||
CubeTexture::horizontal_vertical(BlockTexture::Wood, BlockTexture::WoodTop)
|
||||
),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Leaf => BlockDescriptor {
|
||||
name: "leaf",
|
||||
render: RenderType::BinaryTransparency(CubeTexture::all(BlockTexture::Leaf)),
|
||||
render: RenderType::Cube(
|
||||
Transparency::Binary,
|
||||
CubeTexture::all(BlockTexture::Leaf)
|
||||
),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Water => BlockDescriptor {
|
||||
name: "water",
|
||||
render: RenderType::TransBlock(CubeTexture::all(BlockTexture::Water)),
|
||||
render: RenderType::Cube(
|
||||
Transparency::Trans,
|
||||
CubeTexture::all(BlockTexture::Water)
|
||||
),
|
||||
collision: CollisionType::None,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
|
@ -214,11 +241,16 @@ pub enum CollisionType {
|
|||
Solid,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum Transparency {
|
||||
Solid,
|
||||
Binary,
|
||||
Trans,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum RenderType {
|
||||
None,
|
||||
SolidBlock(CubeTexture),
|
||||
TransBlock(CubeTexture),
|
||||
BinaryTransparency(CubeTexture),
|
||||
CrossShape(CrossTexture),
|
||||
Cube(Transparency, CubeTexture),
|
||||
Cross(CrossTexture),
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use glam::{IVec3, ivec3};
|
||||
use strum::IntoEnumIterator;
|
||||
use kubi_shared::block::{Block, BlockTexture, RenderType};
|
||||
use kubi_shared::block::{Block, BlockTexture, RenderType, Transparency};
|
||||
use crate::world::chunk::CHUNK_SIZE;
|
||||
use crate::rendering::world::ChunkVertex;
|
||||
|
||||
|
@ -43,26 +43,23 @@ pub fn generate_mesh(data: MeshGenData) -> (
|
|||
let descriptor = block.descriptor();
|
||||
match descriptor.render {
|
||||
RenderType::None => continue,
|
||||
RenderType::SolidBlock(textures) |
|
||||
RenderType::BinaryTransparency(textures) |
|
||||
RenderType::TransBlock(textures) => {
|
||||
RenderType::Cube(trans_type, textures) => {
|
||||
for face in CubeFace::iter() {
|
||||
let facing_direction = face.normal();
|
||||
let facing_coord = coord + facing_direction;
|
||||
let facing_block = get_block(facing_coord);
|
||||
let facing_descriptor = facing_block.descriptor();
|
||||
let face_obstructed = match descriptor.render {
|
||||
RenderType::SolidBlock(_) => matches!(facing_descriptor.render, RenderType::SolidBlock(_)),
|
||||
RenderType::BinaryTransparency(_) |
|
||||
RenderType::TransBlock(_) => {
|
||||
let face_obstructed = match trans_type {
|
||||
Transparency::Solid => matches!(facing_descriptor.render, RenderType::Cube(Transparency::Solid, _)),
|
||||
Transparency::Binary | Transparency::Trans => {
|
||||
match facing_descriptor.render {
|
||||
RenderType::SolidBlock(_) => true,
|
||||
RenderType::BinaryTransparency(_) |
|
||||
RenderType::TransBlock(_) => block == facing_block,
|
||||
RenderType::Cube(trans_type, _) => match trans_type {
|
||||
Transparency::Solid => true,
|
||||
Transparency::Binary | Transparency::Trans => block == facing_block,
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
},
|
||||
_ => unreachable!(),
|
||||
};
|
||||
if !face_obstructed {
|
||||
let face_texture = match face {
|
||||
|
@ -73,15 +70,15 @@ pub fn generate_mesh(data: MeshGenData) -> (
|
|||
CubeFace::Back => textures.back,
|
||||
CubeFace::Bottom => textures.bottom,
|
||||
};
|
||||
let cur_builder = match descriptor.render {
|
||||
RenderType::TransBlock(_) => &mut trans_builder,
|
||||
let target_builder = match trans_type {
|
||||
Transparency::Trans => &mut trans_builder,
|
||||
_ => &mut builder,
|
||||
};
|
||||
cur_builder.add_face(face, coord, face_texture as u8);
|
||||
target_builder.add_face(face, coord, face_texture as u8);
|
||||
}
|
||||
}
|
||||
},
|
||||
RenderType::CrossShape(textures) => {
|
||||
RenderType::Cross(textures) => {
|
||||
builder.add_diagonal_face(
|
||||
coord,
|
||||
DiagonalFace::LeftZ,
|
||||
|
|
Loading…
Reference in a new issue