Time Record: 2024-11-30
Currently implemented the function to remove internal invisible blocks.
Project Link and Introduction
Personal Thoughts#
At the same time as completing this phase, the project name was changed to:bevy-Demo-Spirit-Realm (Spirit Realm)
Here, I borrowed from Qian Lao's insights on VR and the name for VR; I also feel that this name is very fitting (it seems like it should be called this), and I want to incorporate virtual reality technology into the game.
Personally, I believe that virtual reality technology is not just about simulating reality in a virtual environment, but should attempt to combine the virtual and the real, complementing each other.
Phase Code Explanation#
Block Culling:Create a hashmap (chunk_blocks), traverse the xyz axes and store all blocks in the hashmap, then use another loop to traverse chunk_blocks, and directly use an if statement to check if the six faces of the current cube are adjacent to blocks, then negate it to generate the block.
if !(
chunk_blocks.contains_key(&[pos[0], pos[1] + 1, pos[2]]) &&
chunk_blocks.contains_key(&[pos[0], pos[1] - 1, pos[2]]) &&
chunk_blocks.contains_key(&[pos[0] + 1, pos[1], pos[2]]) &&
chunk_blocks.contains_key(&[pos[0] - 1, pos[1], pos[2]]) &&
chunk_blocks.contains_key(&[pos[0], pos[1], pos[2] + 1]) &&
chunk_blocks.contains_key(&[pos[0], pos[1], pos[2] - 1])
){
add_cube_to_mesh(&mut positions, &mut normals, &mut uvs, &mut indices, [pos[0] as f32, pos[1] as f32, pos[2] as f32]);
}
Currently, this piece of code needs at least two more optimization iterations. One is to judge based on the block type; for example, if a block's face is adjacent to a water block, it does not need to be culled. Currently, there are only two block types: 1: solid block, 0: air, and there will be more block types in the future, like water blocks. (Currently, for optimization convenience, only a line of triangles is displayed.)
The other is that blocks exposed to air have not been fully optimized; a block can only see three faces from any angle, while the other three faces are not visible, which also needs to be culled.
The image shows a cube composed of 32x * 64y * 32z blocks.