Advertisement Jump to content
Sign in to follow this  

Chunk Optimization Algorithm

This topic is 1080 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am struggling to create an algorithm to remove the unseen triangles from the mesh of the chunk I tried by checking if the adyacent voxels are air. Here is some of my code

	for(int y=CHUNK_HEIGHT-1;y>0;y--){
		for(int x=0;x<CHUNK_WIDTH;x++){
			for(int z=0;z<CHUNK_WIDTH;z++){


				CubeData cube = new CubeData(CubeData.CreateCubeColor(m_blocks[x,y,z].GetColor(m_blocks[x,y,z].Type)),new OpenTK.Vector3(x+OffsetX, y, z+OffsetZ));

				cube = CubeData.CutCubeFace(cube, CutFaceMode.ONLY, Face.ALL);
				bool yP = false, yN = false, xP = false, xN = false, zP = false, zN = false;
				if(x < CHUNK_WIDTH-1 && m_blocks[x+1,y,z].Type == BlockType.AIR)
					xP = true;
				if(x > 0 && m_blocks[x-1,y,z].Type == BlockType.AIR)
					xN = true;
				if(z < CHUNK_WIDTH-1 && m_blocks[x,y,z+1].Type == BlockType.AIR)
					zP = true;
				if(z > 0 && m_blocks[x,y,z-1].Type == BlockType.AIR)
					zN = true;
				if(y < CHUNK_HEIGHT-1 && m_blocks[x,y+1,z].Type == BlockType.AIR)
					yP = true;
				if(y > 0 && m_blocks[x,y-1,z].Type == BlockType.AIR)
					yN = true;
					cube = CubeData.CutCubeFace(cube, CutFaceMode.ADD, Face.FRONT);
				        cube = CubeData.CutCubeFace(cube, CutFaceMode.ADD, Face.BACK);
				        cube = CubeData.CutCubeFace(cube, CutFaceMode.ADD, Face.LEFT);
					cube = CubeData.CutCubeFace(cube, CutFaceMode.ADD, Face.RIGHT);
					cube = CubeData.CutCubeFace(cube, CutFaceMode.ADD, Face.UP);
					cube = CubeData.CutCubeFace(cube, CutFaceMode.ADD, Face.DOWN);


However this lead to some weird effects when 2 air blocks are adyacent, below are some images.


Those are air blocks separeted



As you can see when more air blocks are added just some faces appear incomplete or without sense.


Thank you for your time and If anyone can give me any advice or help i would appreciate it.


EDIT: I already solved it, but always remeber PREMATURE OPTIMIZATION IS THE ROOT OF ALL EVIL!!!!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!