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 stage, the project name has been 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 (as if 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.
Stage Code Explanation#
Block Removal: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 whether 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 water blocks, it does not need to be removed. Currently, there are only two types of blocks: 1: solid block, 0: air. More block types will be added in the future, like water blocks. (Currently, for optimization convenience, only a line of triangles is displayed.)
Another is that blocks exposed to air have not been thoroughly optimized. A block can only see three faces from any angle; the other three faces are not visible, which also needs to be removed.
The image shows a cube made up of 32x * 64y * 32z blocks.