//Default Face Generation Checks ! public bool FaceGenerationCheck(ref TerraCube cube, ref Vector3I cubePosiInWorld, CubeFaces cubeFace, ref TerraCube NeightBorFaceCube) { //if (cubeFace != CubeFaces.Top) //{ // blockProfile NeightBorProfile = _wp.WorldParameters.Configuration.CubeProfiles[NeightBorFaceCube.Id]; // if ((!NeightBorProfile.IsBlockingLight && NeightBorProfile.CubeFamilly != enuCubeFamilly.Liquid)) // { // return true; // } //}else{ // if (cubePosiInWorld.Y == seaLevel || NeightBorFaceCube.Id == WorldConfiguration.CubeId.Air) // { // return true; // } //} BlockProfile NeightBorProfile = _wp.WorldParameters.Configuration.BlockProfiles[NeightBorFaceCube.Id]; if ((!NeightBorProfile.IsBlockingLight && NeightBorProfile.CubeFamilly != enuCubeFamilly.Liquid)) { return(true); } return(false); }
public void GenCubeFace(ref TerraCube cube, CubeFaces cubeFace, ref Vector4B cubePosition, ref Vector3I cubePosiInWorld, VisualChunk chunk, ref TerraCube topCube, Dictionary <long, int> verticeDico) { int yBlockOffsetAsInt = 0; float yBlockOffset = 0; int verticeCubeOffset = chunk.Graphics.LiquidCubeVertices.Count; int indiceCubeOffset = chunk.Graphics.LiquidCubeIndices.Count; ByteColor newColor = cube.EmissiveColor; BlockTag tag = null; BlockProfile blockProfile = _wp.WorldParameters.Configuration.BlockProfiles[cube.Id]; //Get the Cube Tag Informations if (blockProfile.IsTaggable) { tag = chunk.BlockData.GetTag(new Vector3I(cubePosition.X, cubePosition.Y, cubePosition.Z)); } bool IsEmissiveColor = blockProfile.IsEmissiveColorLightSource; bool vertexInDico; //Les 4 vertex de ma face.... en fct de leur position dans le cube leur valeur en Z va changer ! (Face Top, Bottom, ... Vector4B topLeft; Vector4B topRight; Vector4B bottomLeft; Vector4B bottomRight; //GetBlock Offset if (blockProfile.IsTaggable && tag is ICubeYOffsetModifier) { yBlockOffset = ((ICubeYOffsetModifier)tag).YOffset; } else { //Add a naturel Offset to StillWater when touching water at the surface ! if (topCube.Id != cube.Id) { yBlockOffset = (float)blockProfile.YBlockOffset; } } yBlockOffsetAsInt = (int)(yBlockOffset * 255); ChunkColumnInfo chunkInfo = chunk.BlockData.GetColumnInfo(new Vector2I(cubePosition.X, cubePosition.Z)); Vector4B vertexInfo2 = new Vector4B(chunkInfo.Moisture, chunkInfo.Temperature, (byte)0, (byte)0); Vector4B vertexInfo1 = new Vector4B((byte)cubeFace, (byte)0, //Is "UP" vertex blockProfile.BiomeColorArrayTexture, (byte)0); long hashVertex; int generatedVertex = 0; int vertexOffset0, vertexOffset1, vertexOffset2, vertexOffset3; int[] ind = new int[9]; //Get the index of the current cube. int baseIndex = _cubesHolder.Index(ref cubePosiInWorld); switch (cubeFace) { case CubeFaces.Front: //Get the 9 Facing cubes to the face _cubesHolder.SurroundingAxisIndex(_cubesHolder.FastIndex(baseIndex, cubePosiInWorld.Z, SingleArrayChunkContainer.IdxRelativeMove.Z_Plus1), cubePosiInWorld.X, cubePosiInWorld.Y, cubePosiInWorld.Z, SingleArrayChunkContainer.Axis.Z, ind, true); ByteColor Back_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.BaseIndex]].EmissiveColor; ByteColor BackLeft_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.LeftIndex]].EmissiveColor; ByteColor BackRight_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.RightIndex]].EmissiveColor; ByteColor BackTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpIndex]].EmissiveColor; ByteColor BackBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownIndex]].EmissiveColor; ByteColor BackLeftTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpLeftIndex]].EmissiveColor; ByteColor BackRightTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpRightIndex]].EmissiveColor; ByteColor BackLeftBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownLeftIndex]].EmissiveColor; ByteColor BackRightBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownRightIndex]].EmissiveColor; topLeft = cubePosition + new Vector4B(0, 1, 1, yBlockOffsetAsInt); topRight = cubePosition + new Vector4B(1, 1, 1, yBlockOffsetAsInt); bottomLeft = cubePosition + new Vector4B(0, 0, 1, yBlockOffsetAsInt); bottomRight = cubePosition + new Vector4B(1, 0, 1, yBlockOffsetAsInt); vertexInfo2.Z = blockProfile.Tex_Front.AnimationSpeed; vertexInfo2.W = blockProfile.Tex_Front.Texture.AnimationFrames; hashVertex = (long)cubeFace + ((long)topLeft.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffsetAsInt << 48); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset0); if (vertexInDico == false) { vertexOffset0 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset0); if (!IsEmissiveColor) { newColor = ByteColor.Average(Back_Cube, BackLeft_Cube, BackTop_Cube, BackLeftTop_Cube); } vertexInfo1.Y = 1; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref topLeft, blockProfile.Tex_Front.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)topRight.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffsetAsInt << 48); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset1); if (vertexInDico == false) { vertexOffset1 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset1); if (!IsEmissiveColor) { newColor = ByteColor.Average(Back_Cube, BackRight_Cube, BackTop_Cube, BackRightTop_Cube); } vertexInfo1.Y = 1; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref topRight, blockProfile.Tex_Front.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomLeft.GetHashCode() << 8) + ((long)cube.Id << 40); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset2); if (vertexInDico == false) { vertexOffset2 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset2); if (!IsEmissiveColor) { newColor = ByteColor.Average(Back_Cube, BackLeft_Cube, BackBottom_Cube, BackLeftBottom_Cube); } vertexInfo1.Y = 0; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref bottomLeft, blockProfile.Tex_Front.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomRight.GetHashCode() << 8) + ((long)cube.Id << 40); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset3); if (vertexInDico == false) { vertexOffset3 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset3); if (!IsEmissiveColor) { newColor = ByteColor.Average(Back_Cube, BackRight_Cube, BackBottom_Cube, BackRightBottom_Cube); } vertexInfo1.Y = 0; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref bottomRight, blockProfile.Tex_Front.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } //Create Vertices chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset0)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset3)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset1)); break; case CubeFaces.Back: //Get the 9 Facing cubes to the face _cubesHolder.SurroundingAxisIndex(_cubesHolder.FastIndex(baseIndex, cubePosiInWorld.Z, SingleArrayChunkContainer.IdxRelativeMove.Z_Minus1), cubePosiInWorld.X, cubePosiInWorld.Y, cubePosiInWorld.Z, SingleArrayChunkContainer.Axis.Z, ind, true); ByteColor Front_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.BaseIndex]].EmissiveColor; ByteColor FrontLeft_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.LeftIndex]].EmissiveColor; ByteColor FrontRight_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.RightIndex]].EmissiveColor; ByteColor FrontTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpIndex]].EmissiveColor; ByteColor FrontBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownIndex]].EmissiveColor; ByteColor FrontLeftTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpLeftIndex]].EmissiveColor; ByteColor FrontRightTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpRightIndex]].EmissiveColor; ByteColor FrontLeftBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownLeftIndex]].EmissiveColor; ByteColor FrontRightBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownRightIndex]].EmissiveColor; topLeft = cubePosition + new Vector4B(1, 1, 0, yBlockOffsetAsInt); topRight = cubePosition + new Vector4B(0, 1, 0, yBlockOffsetAsInt); bottomLeft = cubePosition + new Vector4B(1, 0, 0, yBlockOffsetAsInt); bottomRight = cubePosition + new Vector4B(0, 0, 0, yBlockOffsetAsInt); vertexInfo2.Z = blockProfile.Tex_Back.AnimationSpeed; vertexInfo2.W = blockProfile.Tex_Back.Texture.AnimationFrames; hashVertex = (long)cubeFace + ((long)topRight.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffsetAsInt << 48); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset0); if (vertexInDico == false) { vertexOffset0 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset0); if (!IsEmissiveColor) { newColor = ByteColor.Average(Front_Cube, FrontTop_Cube, FrontLeftTop_Cube, FrontLeft_Cube); } vertexInfo1.Y = 1; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref topRight, blockProfile.Tex_Back.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)topLeft.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffsetAsInt << 48); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset1); if (vertexInDico == false) { vertexOffset1 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset1); if (!IsEmissiveColor) { newColor = ByteColor.Average(Front_Cube, FrontTop_Cube, FrontRight_Cube, FrontRightTop_Cube); } vertexInfo1.Y = 1; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref topLeft, blockProfile.Tex_Back.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomRight.GetHashCode() << 8) + ((long)cube.Id << 40); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset2); if (vertexInDico == false) { vertexOffset2 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset2); if (!IsEmissiveColor) { newColor = ByteColor.Average(Front_Cube, FrontBottom_Cube, FrontLeft_Cube, FrontLeftBottom_Cube); } vertexInfo1.Y = 0; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref bottomRight, blockProfile.Tex_Back.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomLeft.GetHashCode() << 8) + ((long)cube.Id << 40); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset3); if (vertexInDico == false) { vertexOffset3 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset3); if (!IsEmissiveColor) { newColor = ByteColor.Average(Front_Cube, FrontBottom_Cube, FrontRight_Cube, FrontRightBottom_Cube); } vertexInfo1.Y = 0; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref bottomLeft, blockProfile.Tex_Back.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } //Create Vertices chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset0)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset3)); break; case CubeFaces.Top: //Get the 9 Facing cubes to the face _cubesHolder.SurroundingAxisIndex(_cubesHolder.FastIndex(baseIndex, cubePosiInWorld.Y, SingleArrayChunkContainer.IdxRelativeMove.Y_Plus1), cubePosiInWorld.X, cubePosiInWorld.Y, cubePosiInWorld.Z, SingleArrayChunkContainer.Axis.Y, ind, true); ByteColor Bottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.BaseIndex]].EmissiveColor; ByteColor BottomLeft_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.LeftIndex]].EmissiveColor; ByteColor BottomRight_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.RightIndex]].EmissiveColor; ByteColor BottomTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpIndex]].EmissiveColor; ByteColor BottomBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownIndex]].EmissiveColor; ByteColor BottomLeftTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpLeftIndex]].EmissiveColor; ByteColor BottomRightTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpRightIndex]].EmissiveColor; ByteColor BottomLeftBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownLeftIndex]].EmissiveColor; ByteColor BottomRightBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownRightIndex]].EmissiveColor; topLeft = cubePosition + new Vector4B(0, 1, 0, yBlockOffsetAsInt); topRight = cubePosition + new Vector4B(1, 1, 0, yBlockOffsetAsInt); bottomLeft = cubePosition + new Vector4B(0, 1, 1, yBlockOffsetAsInt); bottomRight = cubePosition + new Vector4B(1, 1, 1, yBlockOffsetAsInt); vertexInfo2.Z = blockProfile.Tex_Top.AnimationSpeed; vertexInfo2.W = blockProfile.Tex_Top.Texture.AnimationFrames; hashVertex = (long)cubeFace + ((long)topLeft.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffsetAsInt << 48); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset0); if (vertexInDico == false) { vertexOffset0 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset0); if (!IsEmissiveColor) { newColor = ByteColor.Average(Bottom_Cube, BottomLeft_Cube, BottomLeftTop_Cube, BottomTop_Cube); } vertexInfo1.Y = 1; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref topLeft, blockProfile.Tex_Top.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomRight.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffsetAsInt << 48); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset1); if (vertexInDico == false) { vertexOffset1 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset1); if (!IsEmissiveColor) { newColor = ByteColor.Average(Bottom_Cube, BottomRight_Cube, BottomBottom_Cube, BottomRightBottom_Cube); } vertexInfo1.Y = 1; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref bottomRight, blockProfile.Tex_Top.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomLeft.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffsetAsInt << 48); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset2); if (vertexInDico == false) { vertexOffset2 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset2); if (!IsEmissiveColor) { newColor = ByteColor.Average(Bottom_Cube, BottomBottom_Cube, BottomLeft_Cube, BottomLeftBottom_Cube); } vertexInfo1.Y = 1; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref bottomLeft, blockProfile.Tex_Top.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)topRight.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffsetAsInt << 48); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset3); if (vertexInDico == false) { vertexOffset3 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset3); if (!IsEmissiveColor) { newColor = ByteColor.Average(Bottom_Cube, BottomTop_Cube, BottomRight_Cube, BottomRightTop_Cube); } vertexInfo1.Y = 1; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref topRight, blockProfile.Tex_Top.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } //Create Vertices chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset0)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset0)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset3)); break; case CubeFaces.Bottom: //Get the 9 Facing cubes to the face _cubesHolder.SurroundingAxisIndex(_cubesHolder.FastIndex(baseIndex, cubePosiInWorld.Y, SingleArrayChunkContainer.IdxRelativeMove.Y_Minus1), cubePosiInWorld.X, cubePosiInWorld.Y, cubePosiInWorld.Z, SingleArrayChunkContainer.Axis.Y, ind, true); ByteColor Top_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.BaseIndex]].EmissiveColor; ByteColor TopLeft_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.LeftIndex]].EmissiveColor; ByteColor TopRight_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.RightIndex]].EmissiveColor; ByteColor TopTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpIndex]].EmissiveColor; ByteColor TopBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownIndex]].EmissiveColor; ByteColor TopLeftTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpLeftIndex]].EmissiveColor; ByteColor TopRightTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpRightIndex]].EmissiveColor; ByteColor TopLeftBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownLeftIndex]].EmissiveColor; ByteColor TopRightBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownRightIndex]].EmissiveColor; topLeft = cubePosition + new Vector4B(0, 0, 1, yBlockOffsetAsInt); topRight = cubePosition + new Vector4B(1, 0, 1, yBlockOffsetAsInt); bottomLeft = cubePosition + new Vector4B(0, 0, 0, yBlockOffsetAsInt); bottomRight = cubePosition + new Vector4B(1, 0, 0, yBlockOffsetAsInt); vertexInfo2.Z = blockProfile.Tex_Bottom.AnimationSpeed; vertexInfo2.W = blockProfile.Tex_Bottom.Texture.AnimationFrames; hashVertex = (long)cubeFace + ((long)topLeft.GetHashCode() << 8) + ((long)cube.Id << 40); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset0); if (vertexInDico == false) { vertexOffset0 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset0); if (!IsEmissiveColor) { newColor = ByteColor.Average(Top_Cube, TopBottom_Cube, TopLeft_Cube, TopLeftBottom_Cube); } vertexInfo1.Y = 0; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref topLeft, blockProfile.Tex_Bottom.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomLeft.GetHashCode() << 8) + ((long)cube.Id << 40); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset1); if (vertexInDico == false) { vertexOffset1 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset1); if (!IsEmissiveColor) { newColor = ByteColor.Average(Top_Cube, TopTop_Cube, TopLeft_Cube, TopLeftTop_Cube); } vertexInfo1.Y = 0; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref bottomLeft, blockProfile.Tex_Bottom.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)topRight.GetHashCode() << 8) + ((long)cube.Id << 40); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset2); if (vertexInDico == false) { vertexOffset2 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset2); if (!IsEmissiveColor) { newColor = ByteColor.Average(Top_Cube, TopBottom_Cube, TopRight_Cube, TopRightBottom_Cube); } vertexInfo1.Y = 0; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref topRight, blockProfile.Tex_Bottom.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomRight.GetHashCode() << 8) + ((long)cube.Id << 40); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset3); if (vertexInDico == false) { vertexOffset3 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset3); if (!IsEmissiveColor) { newColor = ByteColor.Average(Top_Cube, TopTop_Cube, TopRight_Cube, TopRightTop_Cube); } vertexInfo1.Y = 0; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref bottomRight, blockProfile.Tex_Bottom.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } //Create Vertices chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset0)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset3)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset2)); break; case CubeFaces.Left: //Get the 9 Facing cubes to the face _cubesHolder.SurroundingAxisIndex(_cubesHolder.FastIndex(baseIndex, cubePosiInWorld.X, SingleArrayChunkContainer.IdxRelativeMove.X_Minus1), cubePosiInWorld.X, cubePosiInWorld.Y, cubePosiInWorld.Z, SingleArrayChunkContainer.Axis.X, ind, true); ByteColor Right_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.BaseIndex]].EmissiveColor; ByteColor RightLeft_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.LeftIndex]].EmissiveColor; ByteColor RightRight_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.RightIndex]].EmissiveColor; ByteColor RightTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpIndex]].EmissiveColor; ByteColor RightBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownIndex]].EmissiveColor; ByteColor RightLeftTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpLeftIndex]].EmissiveColor; ByteColor RightRightTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpRightIndex]].EmissiveColor; ByteColor RightLeftBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownLeftIndex]].EmissiveColor; ByteColor RightRightBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownRightIndex]].EmissiveColor; topLeft = cubePosition + new Vector4B(0, 1, 0, yBlockOffsetAsInt); bottomRight = cubePosition + new Vector4B(0, 0, 1, yBlockOffsetAsInt); bottomLeft = cubePosition + new Vector4B(0, 0, 0, yBlockOffsetAsInt); topRight = cubePosition + new Vector4B(0, 1, 1, yBlockOffsetAsInt); vertexInfo2.Z = blockProfile.Tex_Left.AnimationSpeed; vertexInfo2.W = blockProfile.Tex_Left.Texture.AnimationFrames; hashVertex = (long)cubeFace + ((long)topLeft.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffsetAsInt << 48); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset0); if (vertexInDico == false) { vertexOffset0 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset0); if (!IsEmissiveColor) { newColor = ByteColor.Average(Right_Cube, RightTop_Cube, RightRight_Cube, RightRightTop_Cube); } vertexInfo1.Y = 1; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref topLeft, blockProfile.Tex_Left.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)topRight.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffsetAsInt << 48); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset1); if (vertexInDico == false) { vertexOffset1 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset1); if (!IsEmissiveColor) { newColor = ByteColor.Average(Right_Cube, RightTop_Cube, RightLeft_Cube, RightLeftTop_Cube); } vertexInfo1.Y = 1; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref topRight, blockProfile.Tex_Left.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomLeft.GetHashCode() << 8) + ((long)cube.Id << 40); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset2); if (vertexInDico == false) { vertexOffset2 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset2); if (!IsEmissiveColor) { newColor = ByteColor.Average(Right_Cube, RightBottom_Cube, RightRight_Cube, RightRightBottom_Cube); } vertexInfo1.Y = 0; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref bottomLeft, blockProfile.Tex_Left.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomRight.GetHashCode() << 8) + ((long)cube.Id << 40); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset3); if (vertexInDico == false) { vertexOffset3 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset3); if (!IsEmissiveColor) { newColor = ByteColor.Average(Right_Cube, RightBottom_Cube, RightLeft_Cube, RightLeftBottom_Cube); } vertexInfo1.Y = 0; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref bottomRight, blockProfile.Tex_Left.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } //Create Vertices chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset0)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset3)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset0)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset3)); break; case CubeFaces.Right: //Get the 9 Facing cubes to the face _cubesHolder.SurroundingAxisIndex(_cubesHolder.FastIndex(baseIndex, cubePosiInWorld.X, SingleArrayChunkContainer.IdxRelativeMove.X_Plus1), cubePosiInWorld.X, cubePosiInWorld.Y, cubePosiInWorld.Z, SingleArrayChunkContainer.Axis.X, ind, true); ByteColor Left_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.BaseIndex]].EmissiveColor; ByteColor LeftLeft_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.LeftIndex]].EmissiveColor; ByteColor LefttRight_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.RightIndex]].EmissiveColor; ByteColor LeftTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpIndex]].EmissiveColor; ByteColor LeftBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownIndex]].EmissiveColor; ByteColor LeftLeftTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpLeftIndex]].EmissiveColor; ByteColor LeftRightTop_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpRightIndex]].EmissiveColor; ByteColor LeftLeftBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownLeftIndex]].EmissiveColor; ByteColor LeftRightBottom_Cube = _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownRightIndex]].EmissiveColor; topLeft = cubePosition + new Vector4B(1, 1, 1, yBlockOffsetAsInt); topRight = cubePosition + new Vector4B(1, 1, 0, yBlockOffsetAsInt); bottomLeft = cubePosition + new Vector4B(1, 0, 1, yBlockOffsetAsInt); bottomRight = cubePosition + new Vector4B(1, 0, 0, yBlockOffsetAsInt); vertexInfo2.Z = blockProfile.Tex_Right.AnimationSpeed; vertexInfo2.W = blockProfile.Tex_Right.Texture.AnimationFrames; hashVertex = (long)cubeFace + ((long)topRight.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffsetAsInt << 48); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset0); if (vertexInDico == false) { vertexOffset0 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset0); if (!IsEmissiveColor) { newColor = ByteColor.Average(Left_Cube, LeftTop_Cube, LefttRight_Cube, LeftRightTop_Cube); } vertexInfo1.Y = 1; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref topRight, blockProfile.Tex_Right.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)topLeft.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffsetAsInt << 48); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset1); if (vertexInDico == false) { vertexOffset1 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset1); if (!IsEmissiveColor) { newColor = ByteColor.Average(Left_Cube, LeftTop_Cube, LeftLeft_Cube, LeftLeftTop_Cube); } vertexInfo1.Y = 1; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref topLeft, blockProfile.Tex_Right.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomLeft.GetHashCode() << 8) + ((long)cube.Id << 40); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset2); if (vertexInDico == false) { vertexOffset2 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset2); if (!IsEmissiveColor) { newColor = ByteColor.Average(Left_Cube, LeftBottom_Cube, LeftLeft_Cube, LeftLeftBottom_Cube); } vertexInfo1.Y = 0; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref bottomLeft, blockProfile.Tex_Right.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomRight.GetHashCode() << 8) + ((long)cube.Id << 40); vertexInDico = verticeDico.TryGetValue(hashVertex, out vertexOffset3); if (vertexInDico == false) { vertexOffset3 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset3); if (!IsEmissiveColor) { newColor = ByteColor.Average(Left_Cube, LeftBottom_Cube, LefttRight_Cube, LeftRightBottom_Cube); } vertexInfo1.Y = 0; chunk.Graphics.LiquidCubeVertices.Add(new VertexCubeLiquid(ref bottomRight, blockProfile.Tex_Right.TextureArrayId, ref newColor, ref vertexInfo2, ref vertexInfo1)); generatedVertex++; } //Create Vertices chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset0)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset3)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.LiquidCubeIndices.Add((ushort)(vertexOffset0)); break; } }
private void GenerateFaces(ref VoxelFrame voxelFrame, CubeFaces cubeFace, ref Dictionary <long, int> dico, Vector4B cubePosition, ref List <VertexVoxelInstanced> vertices, ref List <ushort> indices) { // hash and index var blockData = voxelFrame.BlockData; Vector4B topLeft; Vector4B topRight; Vector4B bottomLeft; Vector4B bottomRight; var chunkSize = blockData.ChunkSize; var cubeColor = blockData.GetBlock(cubePosition.X, cubePosition.Y, cubePosition.Z); var cubeFaceType = (byte)cubeFace; var faceTypeByte = (byte)cubeFace; int vertexOffset0, vertexOffset1, vertexOffset2, vertexOffset3; long hashVertex; bool vertexInDico; int generatedVertex = 0; var verticeCubeOffset = vertices.Count; switch (cubeFace) { #region Front case CubeFaces.Front: { var mirror = cubePosition.Z != chunkSize.Z - 1 ? voxelFrame.FrameMirror : FrameMirror.None; var lfront = IsEmpty(ref blockData, ref chunkSize, cubePosition.X, cubePosition.Y, cubePosition.Z + 1, mirror) ? 255 : 0; var ltopFront = IsEmpty(ref blockData, ref chunkSize, cubePosition.X, cubePosition.Y + 1, cubePosition.Z + 1, mirror) ? 255 : 0; var lbottomFront = IsEmpty(ref blockData, ref chunkSize, cubePosition.X, cubePosition.Y - 1, cubePosition.Z + 1, mirror) ? 255 : 0; var lrightFront = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y, cubePosition.Z + 1, mirror) ? 255 : 0; var lfrontLeft = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y, cubePosition.Z + 1, mirror) ? 255 : 0; var ltopLeftFront = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y + 1, cubePosition.Z + 1, mirror) ? 255 : 0; var ltopFrontRight = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y + 1, cubePosition.Z + 1, mirror) ? 255 : 0; var lbottomLeftFront = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y - 1, cubePosition.Z + 1, mirror) ? 255 : 0; var lbottomFrontRight = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y - 1, cubePosition.Z + 1, mirror) ? 255 : 0; topLeft = cubePosition + new Vector4B(0, 1, 1, 0); // topLeftFront topRight = cubePosition + new Vector4B(1, 1, 1, 0); // topRightFront bottomLeft = cubePosition + new Vector4B(0, 0, 1, 0); // bottomLeftFront bottomRight = cubePosition + new Vector4B(1, 0, 1, 0); // bottomRightFront hashVertex = Compress(cubeFaceType, topLeft.X, topLeft.Y, topLeft.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset0); if (!vertexInDico) { vertexOffset0 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset0); // topLeftFront var light = Avg(lfront, lfrontLeft, ltopFront, ltopLeftFront); vertices.Add(new VertexVoxelInstanced(topLeft, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, topRight.X, topRight.Y, topRight.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset1); if (!vertexInDico) { vertexOffset1 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset1); // topRightFront var light = Avg(lfront, ltopFront, lrightFront, ltopFrontRight); vertices.Add(new VertexVoxelInstanced(topRight, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, bottomLeft.X, bottomLeft.Y, bottomLeft.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset2); if (!vertexInDico) { vertexOffset2 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset2); // bottomLeftFront var light = Avg(lfront, lfrontLeft, lbottomFront, lbottomLeftFront); vertices.Add(new VertexVoxelInstanced(bottomLeft, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, bottomRight.X, bottomRight.Y, bottomRight.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset3); if (!vertexInDico) { vertexOffset3 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset3); // bottomRightFront var light = Avg(lfront, lrightFront, lbottomFront, lbottomFrontRight); vertices.Add(new VertexVoxelInstanced(bottomRight, faceTypeByte, light)); generatedVertex++; } //Create Vertices indices.Add((ushort)(vertexOffset0)); indices.Add((ushort)(vertexOffset2)); indices.Add((ushort)(vertexOffset1)); indices.Add((ushort)(vertexOffset2)); indices.Add((ushort)(vertexOffset3)); indices.Add((ushort)(vertexOffset1)); } break; #endregion #region Back case CubeFaces.Back: { var mirror = cubePosition.Z != 0 ? voxelFrame.FrameMirror : FrameMirror.None; var lback = IsEmpty(ref blockData, ref chunkSize, cubePosition.X, cubePosition.Y, cubePosition.Z - 1, mirror) ? 255 : 0; var ltopBack = IsEmpty(ref blockData, ref chunkSize, cubePosition.X, cubePosition.Y + 1, cubePosition.Z - 1, mirror) ? 255 : 0; var lbottomBack = IsEmpty(ref blockData, ref chunkSize, cubePosition.X, cubePosition.Y - 1, cubePosition.Z - 1, mirror) ? 255 : 0; var lbackRight = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y, cubePosition.Z - 1, mirror) ? 255 : 0; var lleftback = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y, cubePosition.Z - 1, mirror) ? 255 : 0; var ltopRightBack = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y + 1, cubePosition.Z - 1, mirror) ? 255 : 0; var ltopBackLeft = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y + 1, cubePosition.Z - 1, mirror) ? 255 : 0; var lbottomRightBack = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y - 1, cubePosition.Z - 1, mirror) ? 255 : 0; var lbottomBackLeft = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y - 1, cubePosition.Z - 1, mirror) ? 255 : 0; topLeft = cubePosition + new Vector4B(1, 1, 0, 0); // topRightBack topRight = cubePosition + new Vector4B(0, 1, 0, 0); // topLeftBack bottomLeft = cubePosition + new Vector4B(1, 0, 0, 0); // bottomRightBack bottomRight = cubePosition + new Vector4B(0, 0, 0, 0); // bottomLeftBack hashVertex = Compress(cubeFaceType, topRight.X, topRight.Y, topRight.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset0); if (!vertexInDico) { vertexOffset0 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset0); // topLeftBack var light = Avg(lback, ltopBack, lleftback, ltopBackLeft); vertices.Add(new VertexVoxelInstanced(topRight, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, topLeft.X, topLeft.Y, topLeft.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset1); if (!vertexInDico) { vertexOffset1 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset1); // topRightBack var light = Avg(lback, lbackRight, ltopBack, ltopRightBack); vertices.Add(new VertexVoxelInstanced(topLeft, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, bottomRight.X, bottomRight.Y, bottomRight.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset2); if (!vertexInDico) { vertexOffset2 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset2); // bottomLeftBack var light = Avg(lback, lbottomBack, lleftback, lbottomBackLeft); vertices.Add(new VertexVoxelInstanced(bottomRight, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, bottomLeft.X, bottomLeft.Y, bottomLeft.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset3); if (!vertexInDico) { vertexOffset3 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset3); // bottomRightBack var light = Avg(lback, lbackRight, lbottomBack, lbottomRightBack); vertices.Add(new VertexVoxelInstanced(bottomLeft, faceTypeByte, light)); generatedVertex++; } //Create Vertices indices.Add((ushort)(vertexOffset0)); indices.Add((ushort)(vertexOffset1)); indices.Add((ushort)(vertexOffset2)); indices.Add((ushort)(vertexOffset2)); indices.Add((ushort)(vertexOffset1)); indices.Add((ushort)(vertexOffset3)); } break; #endregion #region Top case CubeFaces.Top: { var mirror = cubePosition.Y != chunkSize.Y - 1 ? voxelFrame.FrameMirror : FrameMirror.None; var ltop = IsEmpty(ref blockData, ref chunkSize, cubePosition.X, cubePosition.Y + 1, cubePosition.Z, mirror) ? 255 : 0; var ltopLeft = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y + 1, cubePosition.Z, mirror) ? 255 : 0; var ltopBack = IsEmpty(ref blockData, ref chunkSize, cubePosition.X, cubePosition.Y + 1, cubePosition.Z - 1, mirror) ? 255 : 0; var ltopRight = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y + 1, cubePosition.Z, mirror) ? 255 : 0; var ltopFront = IsEmpty(ref blockData, ref chunkSize, cubePosition.X, cubePosition.Y + 1, cubePosition.Z + 1, mirror) ? 255 : 0; var ltopLeftFront = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y + 1, cubePosition.Z + 1, mirror) ? 255 : 0; var ltopFrontRight = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y + 1, cubePosition.Z + 1, mirror) ? 255 : 0; var ltopRightBack = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y + 1, cubePosition.Z - 1, mirror) ? 255 : 0; var ltopBackLeft = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y + 1, cubePosition.Z - 1, mirror) ? 255 : 0; topLeft = cubePosition + new Vector4B(0, 1, 0, 0); // topLeftBack topRight = cubePosition + new Vector4B(1, 1, 0, 0); // topRightBack bottomLeft = cubePosition + new Vector4B(0, 1, 1, 0); // topLeftFront bottomRight = cubePosition + new Vector4B(1, 1, 1, 0); // topRightFront hashVertex = Compress(cubeFaceType, topLeft.X, topLeft.Y, topLeft.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset0); if (!vertexInDico) { vertexOffset0 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset0); // topLeftBack var light = Avg(ltop, ltopLeft, ltopBack, ltopBackLeft); vertices.Add(new VertexVoxelInstanced(topLeft, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, bottomRight.X, bottomRight.Y, bottomRight.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset1); if (!vertexInDico) { vertexOffset1 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset1); // topRightFront var light = Avg(ltop, ltopRight, ltopFront, ltopFrontRight); vertices.Add(new VertexVoxelInstanced(bottomRight, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, bottomLeft.X, bottomLeft.Y, bottomLeft.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset2); if (!vertexInDico) { vertexOffset2 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset2); // topLeftFront var light = Avg(ltop, ltopLeft, ltopFront, ltopLeftFront); vertices.Add(new VertexVoxelInstanced(bottomLeft, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, topRight.X, topRight.Y, topRight.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset3); if (!vertexInDico) { vertexOffset3 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset3); // topRightBack var light = Avg(ltop, ltopRight, ltopBack, ltopRightBack); vertices.Add(new VertexVoxelInstanced(topRight, faceTypeByte, light)); generatedVertex++; } //Create Vertices indices.Add((ushort)(vertexOffset0)); indices.Add((ushort)(vertexOffset2)); indices.Add((ushort)(vertexOffset1)); indices.Add((ushort)(vertexOffset0)); indices.Add((ushort)(vertexOffset1)); indices.Add((ushort)(vertexOffset3)); } break; #endregion #region Bottom case CubeFaces.Bottom: { var mirror = cubePosition.Y != 0 ? voxelFrame.FrameMirror : FrameMirror.None; var lbottom = IsEmpty(ref blockData, ref chunkSize, cubePosition.X, cubePosition.Y - 1, cubePosition.Z, mirror) ? 255 : 0; var lbottomLeft = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y - 1, cubePosition.Z, mirror) ? 255 : 0; var lbottomBack = IsEmpty(ref blockData, ref chunkSize, cubePosition.X, cubePosition.Y - 1, cubePosition.Z - 1, mirror) ? 255 : 0; var lbottomright = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y - 1, cubePosition.Z, mirror) ? 255 : 0; var lbottomFront = IsEmpty(ref blockData, ref chunkSize, cubePosition.X, cubePosition.Y - 1, cubePosition.Z + 1, mirror) ? 255 : 0; var lbottomLeftFront = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y - 1, cubePosition.Z + 1, mirror) ? 255 : 0; var lbottomFrontRight = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y - 1, cubePosition.Z + 1, mirror) ? 255 : 0; var lbottomRightBack = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y - 1, cubePosition.Z - 1, mirror) ? 255 : 0; var lbottomBackLeft = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y - 1, cubePosition.Z - 1, mirror) ? 255 : 0; topLeft = cubePosition + new Vector4B(0, 0, 1, 0); // bottomLeftFront topRight = cubePosition + new Vector4B(1, 0, 1, 0); // bottomRightFront bottomLeft = cubePosition + new Vector4B(0, 0, 0, 0); // bottomLeftBack bottomRight = cubePosition + new Vector4B(1, 0, 0, 0); // bottomRightBack hashVertex = Compress(cubeFaceType, topLeft.X, topLeft.Y, topLeft.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset0); if (!vertexInDico) { vertexOffset0 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset0); // bottomLeftFront var light = Avg(lbottom, lbottomLeft, lbottomFront, lbottomLeftFront); vertices.Add(new VertexVoxelInstanced(topLeft, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, bottomLeft.X, bottomLeft.Y, bottomLeft.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset1); if (!vertexInDico) { vertexOffset1 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset1); // bottomLeftBack var light = Avg(lbottom, lbottomLeft, lbottomBack, lbottomBackLeft); vertices.Add(new VertexVoxelInstanced(bottomLeft, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, topRight.X, topRight.Y, topRight.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset2); if (!vertexInDico) { vertexOffset2 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset2); // bottomRightFront var light = Avg(lbottom, lbottomright, lbottomFront, lbottomFrontRight); vertices.Add(new VertexVoxelInstanced(topRight, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, bottomRight.X, bottomRight.Y, bottomRight.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset3); if (!vertexInDico) { vertexOffset3 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset3); // bottomRightBack var light = Avg(lbottom, lbottomright, lbottomBack, lbottomRightBack); vertices.Add(new VertexVoxelInstanced(bottomRight, faceTypeByte, light)); generatedVertex++; } //Create Vertices indices.Add((ushort)(vertexOffset0)); indices.Add((ushort)(vertexOffset1)); indices.Add((ushort)(vertexOffset2)); indices.Add((ushort)(vertexOffset1)); indices.Add((ushort)(vertexOffset3)); indices.Add((ushort)(vertexOffset2)); } break; #endregion #region Left case CubeFaces.Left: { var mirror = cubePosition.X != 0 ? voxelFrame.FrameMirror : FrameMirror.None; var lleft = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y, cubePosition.Z, mirror) ? 255 : 0; var ltopLeft = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y + 1, cubePosition.Z, mirror) ? 255 : 0; var lbottomLeft = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y - 1, cubePosition.Z, mirror) ? 255 : 0; var lfrontLeft = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y, cubePosition.Z + 1, mirror) ? 255 : 0; var lleftback = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y, cubePosition.Z - 1, mirror) ? 255 : 0; var ltopLeftFront = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y + 1, cubePosition.Z + 1, mirror) ? 255 : 0; var ltopBackLeft = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y + 1, cubePosition.Z - 1, mirror) ? 255 : 0; var lbottomLeftFront = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y - 1, cubePosition.Z + 1, mirror) ? 255 : 0; var lbottomBackLeft = IsEmpty(ref blockData, ref chunkSize, cubePosition.X - 1, cubePosition.Y - 1, cubePosition.Z - 1, mirror) ? 255 : 0; topLeft = cubePosition + new Vector4B(0, 1, 0, 0); // topLeftBack bottomRight = cubePosition + new Vector4B(0, 0, 1, 0); // bottomLeftFront bottomLeft = cubePosition + new Vector4B(0, 0, 0, 0); // bottomLeftBack topRight = cubePosition + new Vector4B(0, 1, 1, 0); // topLeftFront hashVertex = Compress(cubeFaceType, topLeft.X, topLeft.Y, topLeft.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset0); if (!vertexInDico) { vertexOffset0 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset0); // topLeftBack var light = Avg(lleft, ltopLeft, lleftback, ltopBackLeft); vertices.Add(new VertexVoxelInstanced(topLeft, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, topRight.X, topRight.Y, topRight.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset1); if (!vertexInDico) { vertexOffset1 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset1); // topLeftFront var light = Avg(lleft, ltopLeft, lfrontLeft, ltopLeftFront); vertices.Add(new VertexVoxelInstanced(topRight, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, bottomLeft.X, bottomLeft.Y, bottomLeft.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset2); if (!vertexInDico) { vertexOffset2 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset2); // bottomLeftBack var light = Avg(lleft, lbottomLeft, lleftback, lbottomBackLeft); vertices.Add(new VertexVoxelInstanced(bottomLeft, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, bottomRight.X, bottomRight.Y, bottomRight.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset3); if (!vertexInDico) { vertexOffset3 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset3); // bottomLeftFront var light = Avg(lleft, lbottomLeft, lfrontLeft, lbottomLeftFront); vertices.Add(new VertexVoxelInstanced(bottomRight, faceTypeByte, light)); generatedVertex++; } //Create Vertices indices.Add((ushort)(vertexOffset0)); indices.Add((ushort)(vertexOffset2)); indices.Add((ushort)(vertexOffset3)); indices.Add((ushort)(vertexOffset1)); indices.Add((ushort)(vertexOffset0)); indices.Add((ushort)(vertexOffset3)); } break; #endregion #region Right case CubeFaces.Right: { var mirror = cubePosition.X != chunkSize.X - 1 ? voxelFrame.FrameMirror : FrameMirror.None; var lright = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y, cubePosition.Z, mirror) ? 255 : 0; var ltopRight = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y + 1, cubePosition.Z, mirror) ? 255 : 0; var lbottomright = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y - 1, cubePosition.Z, mirror) ? 255 : 0; var lbackRight = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y, cubePosition.Z - 1, mirror) ? 255 : 0; var lrightFront = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y, cubePosition.Z + 1, mirror) ? 255 : 0; var ltopFrontRight = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y + 1, cubePosition.Z + 1, mirror) ? 255 : 0; var ltopRightBack = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y + 1, cubePosition.Z - 1, mirror) ? 255 : 0; var lbottomFrontRight = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y - 1, cubePosition.Z + 1, mirror) ? 255 : 0; var lbottomRightBack = IsEmpty(ref blockData, ref chunkSize, cubePosition.X + 1, cubePosition.Y - 1, cubePosition.Z - 1, mirror) ? 255 : 0; topLeft = cubePosition + new Vector4B(1, 1, 1, 0); // topRightFront topRight = cubePosition + new Vector4B(1, 1, 0, 0); // topRightBack bottomLeft = cubePosition + new Vector4B(1, 0, 1, 0); // bottomRightFront bottomRight = cubePosition + new Vector4B(1, 0, 0, 0); // bottonRightBack hashVertex = Compress(cubeFaceType, topRight.X, topRight.Y, topRight.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset0); if (!vertexInDico) { vertexOffset0 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset0); // topRightBack var light = Avg(lright, ltopRight, lbackRight, ltopRightBack); vertices.Add(new VertexVoxelInstanced(topRight, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, topLeft.X, topLeft.Y, topLeft.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset1); if (!vertexInDico) { vertexOffset1 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset1); // topRightFront var light = Avg(lright, ltopRight, lrightFront, ltopFrontRight); vertices.Add(new VertexVoxelInstanced(topLeft, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, bottomLeft.X, bottomLeft.Y, bottomLeft.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset2); if (!vertexInDico) { vertexOffset2 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset2); // bottomRightFront var light = Avg(lright, lbottomright, lrightFront, lbottomFrontRight); vertices.Add(new VertexVoxelInstanced(bottomLeft, faceTypeByte, light)); generatedVertex++; } hashVertex = Compress(cubeFaceType, bottomRight.X, bottomRight.Y, bottomRight.Z, cubeColor); vertexInDico = dico.TryGetValue(hashVertex, out vertexOffset3); if (!vertexInDico) { vertexOffset3 = generatedVertex + verticeCubeOffset; dico.Add(hashVertex, vertexOffset3); // bottonRightBack var light = Avg(lright, lbottomright, lbackRight, lbottomRightBack); vertices.Add(new VertexVoxelInstanced(bottomRight, faceTypeByte, light)); generatedVertex++; } //Create Vertices indices.Add((ushort)(vertexOffset0)); indices.Add((ushort)(vertexOffset2)); indices.Add((ushort)(vertexOffset3)); indices.Add((ushort)(vertexOffset1)); indices.Add((ushort)(vertexOffset2)); indices.Add((ushort)(vertexOffset0)); } break; #endregion } }
// Use this for initialization void Start() { create = FindObjectOfType <Create>(); cFace = new CubeFaces(); //SetPlayableArray(); }
public void GenCubeFace(ref TerraCube cube, CubeFaces cubeFace, ref Vector4B cubePosition, ref Vector3I cubePosiInWorld, VisualChunk chunk, ref TerraCube topCube, Dictionary <long, int> verticeDico) { byte yBlockOffset = 0; int verticeCubeOffset = chunk.Graphics.SolidCubeVertices.Count; int indiceCubeOffset = chunk.Graphics.SolidCubeIndices.Count; ByteColor newColor = cube.EmissiveColor; BlockProfile blockProfile = _wp.WorldParameters.Configuration.BlockProfiles[cube.Id]; bool IsEmissiveColor = blockProfile.IsEmissiveColorLightSource; //Les 4 vertex de ma face.... en fct de leur position dans le cube leur valeur en Z va changer ! (Face Top, Bottom, ...) Vector4B topLeft; Vector4B topRight; Vector4B bottomLeft; Vector4B bottomRight; //x = Is Upper VErtex or not //y = Cube Face //z = Not used //w = Cube "Offset" //GetBlock Offset //This "natural" offset should only be made when the upper block is not the same as the block itself if (topCube.Id != cube.Id) { yBlockOffset = (byte)(blockProfile.YBlockOffset * 255); } Vector4B vertexInfo = new Vector4B((byte)0, (byte)cubeFace, (byte)(0), yBlockOffset); long hashVertex; int generatedVertex = 0; int vertexOffset0, vertexOffset1, vertexOffset2, vertexOffset3; //Get the index of the current cube. int baseIndex = _cubesHolder.Index(ref cubePosiInWorld); int[] ind = new int[9]; ChunkColumnInfo chunkInfo = chunk.BlockData.GetColumnInfo(cubePosition.X, cubePosition.Z); Vector4B biomeInfo = new Vector4B(chunkInfo.Moisture, chunkInfo.Temperature, blockProfile.BiomeColorArrayTexture, blockProfile.SideOffsetMultiplier); switch (cubeFace) { case CubeFaces.Front: //Get the 9 Facing cubes to the face _cubesHolder.SurroundingAxisIndex(_cubesHolder.FastIndex(baseIndex, cubePosiInWorld.Z, SingleArrayChunkContainer.IdxRelativeMove.Z_Plus1), cubePosiInWorld.X, cubePosiInWorld.Y, cubePosiInWorld.Z, SingleArrayChunkContainer.Axis.Z, ind, false); ByteColor Back_Cube = (ind[SingleArrayChunkContainer.BaseIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.BaseIndex]].EmissiveColor : new ByteColor(); ByteColor BackLeft_Cube = (ind[SingleArrayChunkContainer.LeftIndex] != int.MaxValue) ?_cubesHolder.Cubes[ind[SingleArrayChunkContainer.LeftIndex]].EmissiveColor : new ByteColor(); ByteColor BackRight_Cube = (ind[SingleArrayChunkContainer.RightIndex] != int.MaxValue) ?_cubesHolder.Cubes[ind[SingleArrayChunkContainer.RightIndex]].EmissiveColor : new ByteColor(); ByteColor BackTop_Cube = (ind[SingleArrayChunkContainer.UpIndex] != int.MaxValue) ?_cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpIndex]].EmissiveColor : new ByteColor(); ByteColor BackBottom_Cube = (ind[SingleArrayChunkContainer.DownIndex] != int.MaxValue) ?_cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownIndex]].EmissiveColor : new ByteColor(); ByteColor BackLeftTop_Cube = (ind[SingleArrayChunkContainer.UpLeftIndex] != int.MaxValue) ?_cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpLeftIndex]].EmissiveColor : new ByteColor(); ByteColor BackRightTop_Cube = (ind[SingleArrayChunkContainer.UpRightIndex] != int.MaxValue) ?_cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpRightIndex]].EmissiveColor : new ByteColor(); ByteColor BackLeftBottom_Cube = (ind[SingleArrayChunkContainer.DownLeftIndex] != int.MaxValue) ?_cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownLeftIndex]].EmissiveColor : new ByteColor(); ByteColor BackRightBottom_Cube = (ind[SingleArrayChunkContainer.DownRightIndex] != int.MaxValue) ?_cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownRightIndex]].EmissiveColor : new ByteColor(); topLeft = cubePosition + new Vector4B(0, 1, 1, 0); topRight = cubePosition + new Vector4B(1, 1, 1, 0); bottomLeft = cubePosition + new Vector4B(0, 0, 1, 0); bottomRight = cubePosition + new Vector4B(1, 0, 1, 0); hashVertex = (long)cubeFace + ((long)topLeft.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffset << 48); if (verticeDico.TryGetValue(hashVertex, out vertexOffset0) == false) { vertexOffset0 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset0); if (!IsEmissiveColor) { newColor = ByteColor.Average(Back_Cube, BackLeft_Cube, BackTop_Cube, BackLeftTop_Cube); } vertexInfo.X = 1; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref topLeft, blockProfile.Tex_Front.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Front.AnimationSpeed, blockProfile.Tex_Front.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)topRight.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffset << 48); if (verticeDico.TryGetValue(hashVertex, out vertexOffset1) == false) { vertexOffset1 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset1); if (!IsEmissiveColor) { newColor = ByteColor.Average(Back_Cube, BackRight_Cube, BackTop_Cube, BackRightTop_Cube); } vertexInfo.X = 1; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref topRight, blockProfile.Tex_Front.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Front.AnimationSpeed, blockProfile.Tex_Front.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomLeft.GetHashCode() << 8) + ((long)cube.Id << 40); if (verticeDico.TryGetValue(hashVertex, out vertexOffset2) == false) { vertexOffset2 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset2); if (!IsEmissiveColor) { newColor = ByteColor.Average(Back_Cube, BackLeft_Cube, BackBottom_Cube, BackLeftBottom_Cube); } vertexInfo.X = 0; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref bottomLeft, blockProfile.Tex_Front.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Front.AnimationSpeed, blockProfile.Tex_Front.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomRight.GetHashCode() << 8) + ((long)cube.Id << 40); if (verticeDico.TryGetValue(hashVertex, out vertexOffset3) == false) { vertexOffset3 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset3); if (!IsEmissiveColor) { newColor = ByteColor.Average(Back_Cube, BackRight_Cube, BackBottom_Cube, BackRightBottom_Cube); } vertexInfo.X = 0; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref bottomRight, blockProfile.Tex_Front.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Front.AnimationSpeed, blockProfile.Tex_Front.Texture.AnimationFrames)); generatedVertex++; } //Create Vertices chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset0)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset3)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset1)); break; case CubeFaces.Back: //Get the 9 Facing cubes to the face _cubesHolder.SurroundingAxisIndex(_cubesHolder.FastIndex(baseIndex, cubePosiInWorld.Z, SingleArrayChunkContainer.IdxRelativeMove.Z_Minus1), cubePosiInWorld.X, cubePosiInWorld.Y, cubePosiInWorld.Z, SingleArrayChunkContainer.Axis.Z, ind, false); ByteColor Front_Cube = (ind[SingleArrayChunkContainer.BaseIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.BaseIndex]].EmissiveColor : new ByteColor(); ByteColor FrontLeft_Cube = (ind[SingleArrayChunkContainer.LeftIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.LeftIndex]].EmissiveColor : new ByteColor(); ByteColor FrontRight_Cube = (ind[SingleArrayChunkContainer.RightIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.RightIndex]].EmissiveColor : new ByteColor(); ByteColor FrontTop_Cube = (ind[SingleArrayChunkContainer.UpIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpIndex]].EmissiveColor : new ByteColor(); ByteColor FrontBottom_Cube = (ind[SingleArrayChunkContainer.DownIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownIndex]].EmissiveColor : new ByteColor(); ByteColor FrontLeftTop_Cube = (ind[SingleArrayChunkContainer.UpLeftIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpLeftIndex]].EmissiveColor : new ByteColor(); ByteColor FrontRightTop_Cube = (ind[SingleArrayChunkContainer.UpRightIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpRightIndex]].EmissiveColor : new ByteColor(); ByteColor FrontLeftBottom_Cube = (ind[SingleArrayChunkContainer.DownLeftIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownLeftIndex]].EmissiveColor : new ByteColor(); ByteColor FrontRightBottom_Cube = (ind[SingleArrayChunkContainer.DownRightIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownRightIndex]].EmissiveColor : new ByteColor(); topLeft = cubePosition + new Vector4B(1, 1, 0, 0); topRight = cubePosition + new Vector4B(0, 1, 0, 0); bottomLeft = cubePosition + new Vector4B(1, 0, 0, 0); bottomRight = cubePosition + new Vector4B(0, 0, 0, 0); hashVertex = (long)cubeFace + ((long)topRight.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffset << 48); if (verticeDico.TryGetValue(hashVertex, out vertexOffset0) == false) { vertexOffset0 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset0); if (!IsEmissiveColor) { newColor = ByteColor.Average(Front_Cube, FrontTop_Cube, FrontLeftTop_Cube, FrontLeft_Cube); } vertexInfo.X = 1; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref topRight, blockProfile.Tex_Back.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Back.AnimationSpeed, blockProfile.Tex_Back.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)topLeft.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffset << 48); if (verticeDico.TryGetValue(hashVertex, out vertexOffset1) == false) { vertexOffset1 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset1); if (!IsEmissiveColor) { newColor = ByteColor.Average(Front_Cube, FrontTop_Cube, FrontRight_Cube, FrontRightTop_Cube); } vertexInfo.X = 1; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref topLeft, blockProfile.Tex_Back.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Back.AnimationSpeed, blockProfile.Tex_Back.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomRight.GetHashCode() << 8) + ((long)cube.Id << 40); if (verticeDico.TryGetValue(hashVertex, out vertexOffset2) == false) { vertexOffset2 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset2); if (!IsEmissiveColor) { newColor = ByteColor.Average(Front_Cube, FrontBottom_Cube, FrontLeft_Cube, FrontLeftBottom_Cube); } vertexInfo.X = 0; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref bottomRight, blockProfile.Tex_Back.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Back.AnimationSpeed, blockProfile.Tex_Back.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomLeft.GetHashCode() << 8) + ((long)cube.Id << 40); if (verticeDico.TryGetValue(hashVertex, out vertexOffset3) == false) { vertexOffset3 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset3); if (!IsEmissiveColor) { newColor = ByteColor.Average(Front_Cube, FrontBottom_Cube, FrontRight_Cube, FrontRightBottom_Cube); } vertexInfo.X = 0; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref bottomLeft, blockProfile.Tex_Back.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Back.AnimationSpeed, blockProfile.Tex_Back.Texture.AnimationFrames)); generatedVertex++; } //Create Vertices chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset0)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset3)); break; case CubeFaces.Top: //Get the 9 Facing cubes to the face _cubesHolder.SurroundingAxisIndex(_cubesHolder.FastIndex(baseIndex, cubePosiInWorld.Y, SingleArrayChunkContainer.IdxRelativeMove.Y_Plus1), cubePosiInWorld.X, cubePosiInWorld.Y, cubePosiInWorld.Z, SingleArrayChunkContainer.Axis.Y, ind, false); ByteColor Bottom_Cube = (ind[SingleArrayChunkContainer.BaseIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.BaseIndex]].EmissiveColor : new ByteColor(); ByteColor BottomLeft_Cube = (ind[SingleArrayChunkContainer.LeftIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.LeftIndex]].EmissiveColor : new ByteColor(); ByteColor BottomRight_Cube = (ind[SingleArrayChunkContainer.RightIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.RightIndex]].EmissiveColor : new ByteColor(); ByteColor BottomTop_Cube = (ind[SingleArrayChunkContainer.UpIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpIndex]].EmissiveColor : new ByteColor(); ByteColor BottomBottom_Cube = (ind[SingleArrayChunkContainer.DownIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownIndex]].EmissiveColor : new ByteColor(); ByteColor BottomLeftTop_Cube = (ind[SingleArrayChunkContainer.UpLeftIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpLeftIndex]].EmissiveColor : new ByteColor(); ByteColor BottomRightTop_Cube = (ind[SingleArrayChunkContainer.UpRightIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpRightIndex]].EmissiveColor : new ByteColor(); ByteColor BottomLeftBottom_Cube = (ind[SingleArrayChunkContainer.DownLeftIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownLeftIndex]].EmissiveColor : new ByteColor(); ByteColor BottomRightBottom_Cube = (ind[SingleArrayChunkContainer.DownRightIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownRightIndex]].EmissiveColor : new ByteColor(); topLeft = cubePosition + new Vector4B(0, 1, 0, 0); topRight = cubePosition + new Vector4B(1, 1, 0, 0); bottomLeft = cubePosition + new Vector4B(0, 1, 1, 0); bottomRight = cubePosition + new Vector4B(1, 1, 1, 0); hashVertex = (long)cubeFace + ((long)topLeft.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffset << 48); if (verticeDico.TryGetValue(hashVertex, out vertexOffset0) == false) { vertexOffset0 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset0); if (!IsEmissiveColor) { newColor = ByteColor.Average(Bottom_Cube, BottomLeft_Cube, BottomLeftTop_Cube, BottomTop_Cube); } vertexInfo.X = 1; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref topLeft, blockProfile.Tex_Top.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Top.AnimationSpeed, blockProfile.Tex_Top.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomRight.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffset << 48); if (verticeDico.TryGetValue(hashVertex, out vertexOffset1) == false) { vertexOffset1 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset1); if (!IsEmissiveColor) { newColor = ByteColor.Average(Bottom_Cube, BottomRight_Cube, BottomBottom_Cube, BottomRightBottom_Cube); } vertexInfo.X = 1; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref bottomRight, blockProfile.Tex_Top.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Top.AnimationSpeed, blockProfile.Tex_Top.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomLeft.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffset << 48); if (verticeDico.TryGetValue(hashVertex, out vertexOffset2) == false) { vertexOffset2 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset2); if (!IsEmissiveColor) { newColor = ByteColor.Average(Bottom_Cube, BottomBottom_Cube, BottomLeft_Cube, BottomLeftBottom_Cube); } vertexInfo.X = 1; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref bottomLeft, blockProfile.Tex_Top.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Top.AnimationSpeed, blockProfile.Tex_Top.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)topRight.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffset << 48); if (verticeDico.TryGetValue(hashVertex, out vertexOffset3) == false) { vertexOffset3 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset3); if (!IsEmissiveColor) { newColor = ByteColor.Average(Bottom_Cube, BottomTop_Cube, BottomRight_Cube, BottomRightTop_Cube); } vertexInfo.X = 1; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref topRight, blockProfile.Tex_Top.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Top.AnimationSpeed, blockProfile.Tex_Top.Texture.AnimationFrames)); generatedVertex++; } //Create Vertices chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset0)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset0)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset3)); break; case CubeFaces.Bottom: //Get the 9 Facing cubes to the face _cubesHolder.SurroundingAxisIndex(_cubesHolder.FastIndex(baseIndex, cubePosiInWorld.Y, SingleArrayChunkContainer.IdxRelativeMove.Y_Minus1), cubePosiInWorld.X, cubePosiInWorld.Y, cubePosiInWorld.Z, SingleArrayChunkContainer.Axis.Y, ind, false); ByteColor Top_Cube = (ind[SingleArrayChunkContainer.BaseIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.BaseIndex]].EmissiveColor : new ByteColor(); ByteColor TopLeft_Cube = (ind[SingleArrayChunkContainer.LeftIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.LeftIndex]].EmissiveColor : new ByteColor(); ByteColor TopRight_Cube = (ind[SingleArrayChunkContainer.RightIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.RightIndex]].EmissiveColor : new ByteColor(); ByteColor TopTop_Cube = (ind[SingleArrayChunkContainer.UpIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpIndex]].EmissiveColor : new ByteColor(); ByteColor TopBottom_Cube = (ind[SingleArrayChunkContainer.DownIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownIndex]].EmissiveColor : new ByteColor(); ByteColor TopLeftTop_Cube = (ind[SingleArrayChunkContainer.UpLeftIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpLeftIndex]].EmissiveColor : new ByteColor(); ByteColor TopRightTop_Cube = (ind[SingleArrayChunkContainer.UpRightIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpRightIndex]].EmissiveColor : new ByteColor(); ByteColor TopLeftBottom_Cube = (ind[SingleArrayChunkContainer.DownLeftIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownLeftIndex]].EmissiveColor : new ByteColor(); ByteColor TopRightBottom_Cube = (ind[SingleArrayChunkContainer.DownRightIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownRightIndex]].EmissiveColor : new ByteColor(); topLeft = cubePosition + new Vector4B(0, 0, 1, 0); topRight = cubePosition + new Vector4B(1, 0, 1, 0); bottomLeft = cubePosition + new Vector4B(0, 0, 0, 0); bottomRight = cubePosition + new Vector4B(1, 0, 0, 0); hashVertex = (long)cubeFace + ((long)topLeft.GetHashCode() << 8) + ((long)cube.Id << 40); if (verticeDico.TryGetValue(hashVertex, out vertexOffset0) == false) { vertexOffset0 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset0); if (!IsEmissiveColor) { newColor = ByteColor.Average(Top_Cube, TopBottom_Cube, TopLeft_Cube, TopLeftBottom_Cube); } vertexInfo.X = 0; chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref topLeft, blockProfile.Tex_Bottom.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Bottom.AnimationSpeed, blockProfile.Tex_Bottom.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomLeft.GetHashCode() << 8) + ((long)cube.Id << 40); if (verticeDico.TryGetValue(hashVertex, out vertexOffset1) == false) { vertexOffset1 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset1); if (!IsEmissiveColor) { newColor = ByteColor.Average(Top_Cube, TopTop_Cube, TopLeft_Cube, TopLeftTop_Cube); } vertexInfo.X = 0; chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref bottomLeft, blockProfile.Tex_Bottom.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Bottom.AnimationSpeed, blockProfile.Tex_Bottom.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)topRight.GetHashCode() << 8) + ((long)cube.Id << 40); if (verticeDico.TryGetValue(hashVertex, out vertexOffset2) == false) { vertexOffset2 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset2); if (!IsEmissiveColor) { newColor = ByteColor.Average(Top_Cube, TopBottom_Cube, TopRight_Cube, TopRightBottom_Cube); } vertexInfo.X = 0; chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref topRight, blockProfile.Tex_Bottom.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Bottom.AnimationSpeed, blockProfile.Tex_Bottom.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomRight.GetHashCode() << 8) + ((long)cube.Id << 40); if (verticeDico.TryGetValue(hashVertex, out vertexOffset3) == false) { vertexOffset3 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset3); if (!IsEmissiveColor) { newColor = ByteColor.Average(Top_Cube, TopTop_Cube, TopRight_Cube, TopRightTop_Cube); } vertexInfo.X = 0; chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref bottomRight, blockProfile.Tex_Bottom.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Bottom.AnimationSpeed, blockProfile.Tex_Bottom.Texture.AnimationFrames)); generatedVertex++; } //Create Vertices chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset0)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset3)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset2)); break; case CubeFaces.Left: //Get the 9 Facing cubes to the face _cubesHolder.SurroundingAxisIndex(_cubesHolder.FastIndex(baseIndex, cubePosiInWorld.X, SingleArrayChunkContainer.IdxRelativeMove.X_Minus1), cubePosiInWorld.X, cubePosiInWorld.Y, cubePosiInWorld.Z, SingleArrayChunkContainer.Axis.X, ind, false); ByteColor Right_Cube = (ind[SingleArrayChunkContainer.BaseIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.BaseIndex]].EmissiveColor : new ByteColor(); ByteColor RightLeft_Cube = (ind[SingleArrayChunkContainer.LeftIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.LeftIndex]].EmissiveColor : new ByteColor(); ByteColor RightRight_Cube = (ind[SingleArrayChunkContainer.RightIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.RightIndex]].EmissiveColor : new ByteColor(); ByteColor RightTop_Cube = (ind[SingleArrayChunkContainer.UpIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpIndex]].EmissiveColor : new ByteColor(); ByteColor RightBottom_Cube = (ind[SingleArrayChunkContainer.DownIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownIndex]].EmissiveColor : new ByteColor(); ByteColor RightLeftTop_Cube = (ind[SingleArrayChunkContainer.UpLeftIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpLeftIndex]].EmissiveColor : new ByteColor(); ByteColor RightRightTop_Cube = (ind[SingleArrayChunkContainer.UpRightIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpRightIndex]].EmissiveColor : new ByteColor(); ByteColor RightLeftBottom_Cube = (ind[SingleArrayChunkContainer.DownLeftIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownLeftIndex]].EmissiveColor : new ByteColor(); ByteColor RightRightBottom_Cube = (ind[SingleArrayChunkContainer.DownRightIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownRightIndex]].EmissiveColor : new ByteColor(); topLeft = cubePosition + new Vector4B(0, 1, 0, 0); bottomRight = cubePosition + new Vector4B(0, 0, 1, 0); bottomLeft = cubePosition + new Vector4B(0, 0, 0, 0); topRight = cubePosition + new Vector4B(0, 1, 1, 0); hashVertex = (long)cubeFace + ((long)topLeft.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffset << 48); if (verticeDico.TryGetValue(hashVertex, out vertexOffset0) == false) { vertexOffset0 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset0); if (!IsEmissiveColor) { newColor = ByteColor.Average(Right_Cube, RightTop_Cube, RightRight_Cube, RightRightTop_Cube); } vertexInfo.X = 1; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref topLeft, blockProfile.Tex_Left.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Left.AnimationSpeed, blockProfile.Tex_Left.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)topRight.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffset << 48); if (verticeDico.TryGetValue(hashVertex, out vertexOffset1) == false) { vertexOffset1 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset1); if (!IsEmissiveColor) { newColor = ByteColor.Average(Right_Cube, RightTop_Cube, RightLeft_Cube, RightLeftTop_Cube); } vertexInfo.X = 1; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref topRight, blockProfile.Tex_Left.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Left.AnimationSpeed, blockProfile.Tex_Left.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomLeft.GetHashCode() << 8) + ((long)cube.Id << 40); if (verticeDico.TryGetValue(hashVertex, out vertexOffset2) == false) { vertexOffset2 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset2); if (!IsEmissiveColor) { newColor = ByteColor.Average(Right_Cube, RightBottom_Cube, RightRight_Cube, RightRightBottom_Cube); } vertexInfo.X = 0; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref bottomLeft, blockProfile.Tex_Left.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Left.AnimationSpeed, blockProfile.Tex_Left.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomRight.GetHashCode() << 8) + ((long)cube.Id << 40); if (verticeDico.TryGetValue(hashVertex, out vertexOffset3) == false) { vertexOffset3 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset3); if (!IsEmissiveColor) { newColor = ByteColor.Average(Right_Cube, RightBottom_Cube, RightLeft_Cube, RightLeftBottom_Cube); } vertexInfo.X = 0; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref bottomRight, blockProfile.Tex_Left.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Left.AnimationSpeed, blockProfile.Tex_Left.Texture.AnimationFrames)); generatedVertex++; } //Create Vertices chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset0)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset3)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset0)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset3)); break; case CubeFaces.Right: //Get the 9 Facing cubes to the face _cubesHolder.SurroundingAxisIndex(_cubesHolder.FastIndex(baseIndex, cubePosiInWorld.X, SingleArrayChunkContainer.IdxRelativeMove.X_Plus1), cubePosiInWorld.X, cubePosiInWorld.Y, cubePosiInWorld.Z, SingleArrayChunkContainer.Axis.X, ind, false); ByteColor Left_Cube = (ind[SingleArrayChunkContainer.BaseIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.BaseIndex]].EmissiveColor : new ByteColor(); ByteColor LeftLeft_Cube = (ind[SingleArrayChunkContainer.LeftIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.LeftIndex]].EmissiveColor : new ByteColor(); ByteColor LefttRight_Cube = (ind[SingleArrayChunkContainer.RightIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.RightIndex]].EmissiveColor : new ByteColor(); ByteColor LeftTop_Cube = (ind[SingleArrayChunkContainer.UpIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpIndex]].EmissiveColor : new ByteColor(); ByteColor LeftBottom_Cube = (ind[SingleArrayChunkContainer.DownIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownIndex]].EmissiveColor : new ByteColor(); ByteColor LeftLeftTop_Cube = (ind[SingleArrayChunkContainer.UpLeftIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpLeftIndex]].EmissiveColor : new ByteColor(); ByteColor LeftRightTop_Cube = (ind[SingleArrayChunkContainer.UpRightIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.UpRightIndex]].EmissiveColor : new ByteColor(); ByteColor LeftLeftBottom_Cube = (ind[SingleArrayChunkContainer.DownLeftIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownLeftIndex]].EmissiveColor : new ByteColor(); ByteColor LeftRightBottom_Cube = (ind[SingleArrayChunkContainer.DownRightIndex] != int.MaxValue) ? _cubesHolder.Cubes[ind[SingleArrayChunkContainer.DownRightIndex]].EmissiveColor : new ByteColor(); topLeft = cubePosition + new Vector4B(1, 1, 1, 0); topRight = cubePosition + new Vector4B(1, 1, 0, 0); bottomLeft = cubePosition + new Vector4B(1, 0, 1, 0); bottomRight = cubePosition + new Vector4B(1, 0, 0, 0); hashVertex = (long)cubeFace + ((long)topRight.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffset << 48); if (verticeDico.TryGetValue(hashVertex, out vertexOffset0) == false) { vertexOffset0 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset0); if (!IsEmissiveColor) { newColor = ByteColor.Average(Left_Cube, LeftTop_Cube, LefttRight_Cube, LeftRightTop_Cube); } vertexInfo.X = 1; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref topRight, blockProfile.Tex_Right.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Right.AnimationSpeed, blockProfile.Tex_Left.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)topLeft.GetHashCode() << 8) + ((long)cube.Id << 40) + ((long)yBlockOffset << 48); if (verticeDico.TryGetValue(hashVertex, out vertexOffset1) == false) { vertexOffset1 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset1); if (!IsEmissiveColor) { newColor = ByteColor.Average(Left_Cube, LeftTop_Cube, LeftLeft_Cube, LeftLeftTop_Cube); } vertexInfo.X = 1; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref topLeft, blockProfile.Tex_Right.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Right.AnimationSpeed, blockProfile.Tex_Left.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomLeft.GetHashCode() << 8) + ((long)cube.Id << 40); if (verticeDico.TryGetValue(hashVertex, out vertexOffset2) == false) { vertexOffset2 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset2); if (!IsEmissiveColor) { newColor = ByteColor.Average(Left_Cube, LeftBottom_Cube, LeftLeft_Cube, LeftLeftBottom_Cube); } vertexInfo.X = 0; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref bottomLeft, blockProfile.Tex_Right.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Right.AnimationSpeed, blockProfile.Tex_Left.Texture.AnimationFrames)); generatedVertex++; } hashVertex = (long)cubeFace + ((long)bottomRight.GetHashCode() << 8) + ((long)cube.Id << 40); if (verticeDico.TryGetValue(hashVertex, out vertexOffset3) == false) { vertexOffset3 = generatedVertex + verticeCubeOffset; verticeDico.Add(hashVertex, vertexOffset3); if (!IsEmissiveColor) { newColor = ByteColor.Average(Left_Cube, LeftBottom_Cube, LefttRight_Cube, LeftRightBottom_Cube); } vertexInfo.X = 0; //if (chunk.SliceValue > 0 && newColor == ByteColor.Zero) newColor = new ByteColor(0, 0, 0, 40); chunk.Graphics.SolidCubeVertices.Add(new VertexCubeSolid(ref bottomRight, blockProfile.Tex_Right.TextureArrayId, ref newColor, ref vertexInfo, ref biomeInfo, blockProfile.Tex_Right.AnimationSpeed, blockProfile.Tex_Left.Texture.AnimationFrames)); generatedVertex++; } //Create Vertices chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset0)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset3)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset1)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset2)); chunk.Graphics.SolidCubeIndices.Add((ushort)(vertexOffset0)); break; } }
//Default Face Generation Checks ! public bool FaceGenerationCheck(ref TerraCube cube, ref Vector3I cubePosiInWorld, CubeFaces cubeFace, ref TerraCube NeightBorFaceCube) { //By default I don't need to trace the cubeFace of my cube if the face NeightBor cube is blocking light ! (Not see-through) BlockProfile blockProfile = _wp.WorldParameters.Configuration.BlockProfiles[cube.Id]; BlockProfile NeighborCubeProfile = _wp.WorldParameters.Configuration.BlockProfiles[NeightBorFaceCube.Id]; if ((NeighborCubeProfile.IsSeeThrough) || ((blockProfile.SideOffsetMultiplier > 0 ^ NeighborCubeProfile.SideOffsetMultiplier > 0) && cube.Id != NeightBorFaceCube.Id)) { return(true); } //Else draw the face return(false); }
private void GenerateCubesFace(CubeFaces cubeFace, VisualChunk chunk) { TerraCube currentCube, neightborCube, topCube; BlockProfile blockProfile, neightborCubeProfile; Vector4B cubePosiInChunk = new Vector4B(0, 0, 0, 1); Vector3I cubePosiInWorld; int XWorld, YWorld, ZWorld; int neightborCubeIndex; int baseCubeIndex = _cubesHolder.Index(chunk.CubeRange.Position.X, chunk.CubeRange.Position.Y, chunk.CubeRange.Position.Z); int cubeIndexX = baseCubeIndex; int cubeIndexZ = baseCubeIndex; int cubeIndex = baseCubeIndex; var worldRangeMaxX = _visualWorldParameters.WorldRange.Max.X; var worldRangeMaxY = _visualWorldParameters.WorldRange.Max.Y; var worldRangeMaxZ = _visualWorldParameters.WorldRange.Max.Z; int xNeight, yNeight, zNeight; byte yMin = (byte)(chunk.Graphics.SliceValue == -1 ? 0 : Math.Max(0, chunk.Graphics.SliceValue - 5)); byte yMax = (byte)(chunk.Graphics.SliceValue == -1 ? chunk.CubeRange.Size.Y : chunk.Graphics.SliceValue); Dictionary <long, int> verticeDico = new Dictionary <long, int>(); for (byte x = 0; x < AbstractChunk.ChunkSize.X; x++) { XWorld = (x + chunk.CubeRange.Position.X); if (x != 0) { cubeIndexX += _cubesHolder.MoveX; cubeIndexZ = cubeIndexX; cubeIndex = cubeIndexX; } for (byte z = 0; z < AbstractChunk.ChunkSize.Z; z++) { ZWorld = (z + chunk.CubeRange.Position.Z); if (z != 0) { cubeIndexZ += _cubesHolder.MoveZ; cubeIndex = cubeIndexZ; } for (byte y = yMin; y < yMax; y++) { //_cubeRange in fact identify the chunk, the chunk position in the world being _cubeRange.Min YWorld = (y + chunk.CubeRange.Position.Y); if (y != yMin) { cubeIndex += _cubesHolder.MoveY; } else { cubeIndex += _cubesHolder.MoveY * yMin; } //_cubesHolder.Cubes[] is the BIG table containing all terraCube in the visible world. //For speed access, I use an array with only one dimension, thus the table index must be computed from the X, Y, Z position of the terracube. //Computing myself this index, is faster than using an array defined as [x,y,z] //Terra Cube contain only the data that are variables, and could be different between 2 cube. currentCube = _cubesHolder.Cubes[cubeIndex]; // ? Am I an Air Cube ? ==> Default Value, not needed to render ! if (currentCube.Id == WorldConfiguration.CubeId.Air) { continue; } //The Cube profile contain the value that are fixed for a block type. blockProfile = _visualWorldParameters.WorldParameters.Configuration.BlockProfiles[currentCube.Id]; cubePosiInWorld = new Vector3I(XWorld, YWorld, ZWorld); cubePosiInChunk.X = x; //cubePosiInChunk = new Vector4B(x, y, z); cubePosiInChunk.Y = y; cubePosiInChunk.Z = z; //Check to see if the face needs to be generated or not ! //Border Chunk test ! ==> Don't generate faces that are "border" chunks //BorderChunk value is true if the chunk is at the border of the visible world. int topCubeIndex = cubeIndex + _cubesHolder.MoveY; xNeight = x; yNeight = y; zNeight = z; switch (cubeFace) { case CubeFaces.Back: if (ZWorld - 1 < _visualWorldParameters.WorldRange.Position.Z) { continue; } neightborCubeIndex = _cubesHolder.FastIndex(cubeIndex, ZWorld, SingleArrayChunkContainer.IdxRelativeMove.Z_Minus1); zNeight--; break; case CubeFaces.Front: if (ZWorld + 1 >= worldRangeMaxZ) { continue; } neightborCubeIndex = _cubesHolder.FastIndex(cubeIndex, ZWorld, SingleArrayChunkContainer.IdxRelativeMove.Z_Plus1); zNeight++; break; case CubeFaces.Bottom: if (YWorld - 1 < yMin) { continue; } neightborCubeIndex = cubeIndex - _cubesHolder.MoveY; yNeight--; break; case CubeFaces.Top: if (YWorld + 1 > worldRangeMaxY) { continue; } neightborCubeIndex = topCubeIndex; yNeight++; break; case CubeFaces.Left: if (XWorld - 1 < _visualWorldParameters.WorldRange.Position.X) { continue; } neightborCubeIndex = _cubesHolder.FastIndex(cubeIndex, XWorld, SingleArrayChunkContainer.IdxRelativeMove.X_Minus1); xNeight--; break; case CubeFaces.Right: if (XWorld + 1 >= worldRangeMaxX) { continue; } neightborCubeIndex = _cubesHolder.FastIndex(cubeIndex, XWorld, SingleArrayChunkContainer.IdxRelativeMove.X_Plus1); xNeight++; break; default: throw new NullReferenceException(); } if (YWorld + 1 < yMax) { neightborCube = _cubesHolder.Cubes[neightborCubeIndex]; } else { neightborCube = new TerraCube(WorldConfiguration.CubeId.Air); } neightborCubeProfile = _visualWorldParameters.WorldParameters.Configuration.BlockProfiles[neightborCube.Id]; //Check if a tag is present and ICubeYOffsetModifier is implementad by the tag; float cubeYOffset = (float)blockProfile.YBlockOffset; //Natural YOffset of the Cube if (blockProfile.IsTaggable) { BlockTag tag = chunk.BlockData.GetTag(new Vector3I(x, y, z)); ICubeYOffsetModifier tagOffset = tag as ICubeYOffsetModifier; //If block is taggle then it will overide the natural UOffset if (tagOffset != null) { cubeYOffset = tagOffset.YOffset; } } float neightborcubeYOffset = (float)neightborCubeProfile.YBlockOffset; if (neightborCubeProfile.IsTaggable) { //Find the chunk where this neightboor is located !! (Could be a chunk next to this one !) Vector3I NeightCubeWorldPosition = new Vector3I(xNeight + chunk.CubeRange.Position.X, yNeight, zNeight + chunk.CubeRange.Position.Z); VisualChunk neighbChunk = WorldChunks.GetChunk(NeightCubeWorldPosition); BlockTag tag = neighbChunk.BlockData.GetTag(new Vector3I(NeightCubeWorldPosition.X - neighbChunk.CubeRange.Position.X, yNeight, NeightCubeWorldPosition.Z - neighbChunk.CubeRange.Position.Z)); ICubeYOffsetModifier tagOffset = tag as ICubeYOffsetModifier; if (tagOffset != null) { neightborcubeYOffset = tagOffset.YOffset; } } bool yOffsetDiff = (cubeYOffset < neightborcubeYOffset && cubeFace != CubeFaces.Top) || (cubeYOffset > 0 && cubeFace == CubeFaces.Top); // && neightborCube.Id != currentCube.Id); switch (blockProfile.CubeFamilly) { case enuCubeFamilly.Solid: //Default linked to : CubeMeshFactory.GenSolidCubeFace; if (!yOffsetDiff && !_solidCubeMeshFactory.FaceGenerationCheck(ref currentCube, ref cubePosiInWorld, cubeFace, ref neightborCube)) { continue; } topCube = _cubesHolder.Cubes[topCubeIndex]; _solidCubeMeshFactory.GenCubeFace(ref currentCube, cubeFace, ref cubePosiInChunk, ref cubePosiInWorld, chunk, ref topCube, verticeDico); break; case enuCubeFamilly.Liquid: //Default linked to : CubeMeshFactory.GenLiquidCubeFace; //In case of Water block, never display the bottom or up face if both cube are of the same type ! if (cubeFace == CubeFaces.Top || cubeFace == CubeFaces.Bottom) { if (neightborCube.Id == currentCube.Id) { continue; } } if (!yOffsetDiff && !_liquidCubeMeshFactory.FaceGenerationCheck(ref currentCube, ref cubePosiInWorld, cubeFace, ref neightborCube)) { continue; } topCube = _cubesHolder.Cubes[topCubeIndex]; _liquidCubeMeshFactory.GenCubeFace(ref currentCube, cubeFace, ref cubePosiInChunk, ref cubePosiInWorld, chunk, ref topCube, verticeDico); break; case enuCubeFamilly.Other: break; } } } } verticeDico.Clear(); }