private void AmbiantSoundProcessing(VisualChunk chunk, ICharacterEntity player) { ChunkColumnInfo columnInfo = chunk.BlockData.GetColumnInfo(player.Position.ToCubePosition().X - chunk.ChunkPositionBlockUnit.X, player.Position.ToCubePosition().Z - chunk.ChunkPositionBlockUnit.Y); bool playerAboveMaxChunkheight = (columnInfo.MaxHeight - player.Position.ToCubePosition().Y < -15); bool playerBelowMaxChunkheight = (columnInfo.MaxHeight - player.Position.ToCubePosition().Y > 15); Biome currentBiome = _biomesParams.Biomes[chunk.BlockData.ChunkMetaData.ChunkMasterBiomeType]; //Ambiant sound are just for surface "chunk", if not stop playing them ! if (playerAboveMaxChunkheight || playerBelowMaxChunkheight || player.HealthState == DynamicEntityHealthState.Dead) { if (_currentlyPLayingAmbiantSound != null) { if (_currentlyPLayingAmbiantSound.IsPlaying) { _currentlyPLayingAmbiantSound.Stop(1000); _currentlyPLayingAmbiantSound = null; } _previousBiomePlaying = null; } return; } //IF first pass or biome did change or currently player sound is finished if ( _previousBiomePlaying == null || currentBiome != _previousBiomePlaying || (_currentlyPLayingAmbiantSound != null && _currentlyPLayingAmbiantSound.IsPlaying == false) ) { if (_currentlyPLayingAmbiantSound != null) { if (_currentlyPLayingAmbiantSound.IsPlaying) { _currentlyPLayingAmbiantSound.Stop(1000); _currentlyPLayingAmbiantSound = null; } } //Pickup next biome ambiant sound, and start it ! if (currentBiome.AmbientSound.Count > 0) { int nextAmbientSoundId = _rnd.Next(0, currentBiome.AmbientSound.Count); _currentlyPLayingAmbiantSound = _soundEngine.StartPlay2D(currentBiome.AmbientSound[nextAmbientSoundId].Alias, SourceCategory.Music, false, 3000); _previousBiomePlaying = currentBiome; } } }
/// <summary> /// Specialy created to render quickly the landscape in order to be used by LandscapeItem Manager /// </summary> /// <param name="chunkBytes"></param> /// <param name="chunkPosition"></param> public void GenerateMacroLandscape(Vector3I chunkPosition, out Biome biome, out byte[] chunkBytes, out FastRandom chunkRnd, out ChunkColumnInfo[] columnsInfo) { Range3I chunkWorldRange = new Range3I() { Position = new Vector3I(chunkPosition.X * AbstractChunk.ChunkSize.X, 0, chunkPosition.Z * AbstractChunk.ChunkSize.Z), Size = AbstractChunk.ChunkSize }; chunkBytes = new byte[AbstractChunk.ChunkBlocksByteLength]; columnsInfo = new ChunkColumnInfo[AbstractChunk.ChunkSize.X * AbstractChunk.ChunkSize.Z]; chunkRnd = new FastRandom(_worldParameters.Seed + chunkPosition.GetHashCode()); double[,] biomeMap; GenerateLandscape(chunkBytes, ref chunkWorldRange, out biomeMap); TerraForming(chunkBytes, columnsInfo, ref chunkWorldRange, biomeMap, chunkRnd); var metaData = CreateChunkMetaData(columnsInfo); biome = _config.ProcessorParam.Biomes[metaData.ChunkMasterBiomeType]; }
public void Generate(Range3I generationRange, GeneratedChunk[,,] chunks) { generationRange.Foreach(pos => { //Get the chunk var chunk = chunks[pos.X - generationRange.Position.X, pos.Y - generationRange.Position.Y, pos.Z - generationRange.Position.Z]; var chunkWorldPosition = new Vector3D(chunk.Position.X * AbstractChunk.ChunkSize.X, 0.0, chunk.Position.Z * AbstractChunk.ChunkSize.Z); //Create the Rnd component to be used by the landscape creator var chunkRnd = new FastRandom(_worldParameters.Seed + chunk.Position.GetHashCode()); //If already generated, the buffer will take care of sending back directly the landscape from buffer zone, otherwhile landscape is generated. //The buffer has the advantage to be shared between client/server in "Single player" mode. //It means that a chunk, if generated by the server, won't need to be generated by the client because it will be stored into the buffer. //The buffer is heavily use for landscape entities that can span on multiple chunks like trees. LandscapeChunkBuffer landscapeBuffer = _landscapeBufferManager.Get(chunk.Position); while (landscapeBuffer.ProcessingState != LandscapeChunkBuffer.LandscapeChunkBufferState.Processed) { Thread.Sleep(100); landscapeBuffer = _landscapeBufferManager.Get(chunk.Position); } var columnsInfo = new ChunkColumnInfo[AbstractChunk.ChunkSize.X * AbstractChunk.ChunkSize.Z]; var chunkBytes = new byte[AbstractChunk.ChunkBlocksByteLength]; Array.Copy(landscapeBuffer.chunkBytesBuffer, chunkBytes, landscapeBuffer.chunkBytesBuffer.Length); Array.Copy(landscapeBuffer.ColumnsInfoBuffer, columnsInfo, columnsInfo.Length); var metaData = CreateChunkMetaData(columnsInfo); chunk.BlockData.ColumnsInfo = columnsInfo; //Save Columns info Array chunk.BlockData.ChunkMetaData = metaData; //Save the metaData Informations PopulateChunk(chunk, chunkBytes, metaData, chunkRnd, _entityFactory, landscapeBuffer.Entities); RefreshChunkMetaData(metaData, columnsInfo); chunk.BlockData.SetBlockBytes(chunkBytes); //Save block array }); }
private void ApplyBiomeColor(ref Color baseColor, byte biomeColorId, ChunkColumnInfo ci) { //Apply weather offset var m = ((ci.Moisture / 256f) * 0.6f) + 0.2f; var moistureAmount = MathHelper.Clamp(m + _weather.MoistureOffset, 0f, 1f); var t = ((ci.Temperature / 256f) * 0.6f) + 0.2f; var tempAmount = MathHelper.Clamp(t + _weather.TemperatureOffset, 0f, 1f); //X = Moisture int moisture = (int)MathHelper.FullLerp(0, _colorsBiome[biomeColorId].Width - 1, 0.0, 1.0, moistureAmount); //Y = Temperature int temp = (int)MathHelper.FullLerp(0, _colorsBiome[biomeColorId].Height - 1, 0.0, 1.0, tempAmount); var sampledColor = _colorsBiome[biomeColorId].GetPixel(moisture, temp); int red = (int)MathHelper.FullLerp(0.0, (double)sampledColor.R, 0.0, 255.0, (double)baseColor.R, true); int green = (int)MathHelper.FullLerp(0.0, (double)sampledColor.G, 0.0, 255.0, (double)baseColor.G, true); int blue = (int)MathHelper.FullLerp(0.0, (double)sampledColor.B, 0.0, 255.0, (double)baseColor.B, true); baseColor.R = (byte)red; baseColor.G = (byte)green; baseColor.B = (byte)blue; }
private void TerraForming(byte[] ChunkCubes, ChunkColumnInfo[] columnsInfo, ref Range3I chunkWorldRange, double[,] biomeMap, FastRandom chunkRnd) { int surface, surfaceLayer; int inWaterMaxLevel = 0; Biome currentBiome; ChunkColumnInfo columnInfo; int index = 0; int noise2DIndex = 0; for (int X = 0; X < AbstractChunk.ChunkSize.X; X++) { for (int Z = 0; Z < AbstractChunk.ChunkSize.Z; Z++) { //Get Biomes informations for this Column============================================ bool mustPlacedSnow; double temperature = biomeMap[noise2DIndex, 1]; double moisture = biomeMap[noise2DIndex, 2]; double zoneValue = biomeMap[noise2DIndex, 3]; byte biomeId = _biomeHelper.GetBiome(biomeMap[noise2DIndex, 0], temperature, moisture, zoneValue); //Get this landscape Column Biome value currentBiome = _config.ProcessorParam.Biomes[biomeId]; //Get Temperature and Moisture columnInfo = new ChunkColumnInfo() { Biome = biomeId, Moisture = (byte)(moisture * 255), Temperature = (byte)(temperature * 255), MaxHeight = byte.MaxValue, Zone = (byte)(zoneValue * 255), IsWild = true }; mustPlacedSnow = (temperature <0.2 && moisture> 0.5); //==================================================================================== surface = chunkRnd.Next(currentBiome.UnderSurfaceLayers.Min, currentBiome.UnderSurfaceLayers.Max + 1); inWaterMaxLevel = 0; surfaceLayer = 0; bool solidGroundHitted = false; for (int Y = _worldGeneratedHeight - 1; Y >= 0; Y--) //Y { index = ((Z * AbstractChunk.ChunkSize.X) + X) * AbstractChunk.ChunkSize.Y + Y; byte cubeId = ChunkCubes[index]; //Restart Surface layer if needed if (surfaceLayer > 0 && cubeId == UtopiaProcessorParams.CubeId.Air && Y > (_config.ProcessorParam.WaterLevel - 5)) { surfaceLayer = 1; } if (cubeId == UtopiaProcessorParams.CubeId.Stone) { if (solidGroundHitted == false) { if (columnInfo.MaxHeight < Y || inWaterMaxLevel == 0) { columnInfo.MaxHeight = (byte)Y; } columnInfo.MaxGroundHeight = (byte)Y; solidGroundHitted = true; } cubeId = currentBiome.GroundCube; //Under water soil if (Y < _config.ProcessorParam.WaterLevel && inWaterMaxLevel != 0) { if (cubeId == currentBiome.GroundCube) { ChunkCubes[index] = currentBiome.UnderSurfaceCube; } break; } inWaterMaxLevel = 0; //Surface Layer handling if (surface > surfaceLayer) { if (surfaceLayer == 0) { if (mustPlacedSnow) { //Get cube index above this one //Place a snow block on it ChunkCubes[((Z * AbstractChunk.ChunkSize.X) + X) * AbstractChunk.ChunkSize.Y + (Y + 1)] = UtopiaProcessorParams.CubeId.Snow; mustPlacedSnow = false; } ChunkCubes[index] = currentBiome.SurfaceCube; } else { ChunkCubes[index] = currentBiome.UnderSurfaceCube; } surfaceLayer++; } } else //This block is not Stone (Air, Water, or BedRock) { if (cubeId == UtopiaProcessorParams.CubeId.WaterStill) { if (mustPlacedSnow) { //Get cube index above this one //Place a snow block on it ChunkCubes[index] = UtopiaProcessorParams.CubeId.Ice; } inWaterMaxLevel = Y; columnInfo.MaxHeight = (byte)Y; } else { if (inWaterMaxLevel > 0 && cubeId == UtopiaProcessorParams.CubeId.Air) { ChunkCubes[index] = UtopiaProcessorParams.CubeId.WaterStill; } } } } columnsInfo[noise2DIndex] = columnInfo; noise2DIndex++; } } }
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; } }
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; } }