public Schematic WriteSchematic() { Schematic finalSchematic = new Schematic(); if (mSchematic != null) { finalSchematic = new Schematic(mSchematic.GetAllVoxels()); } Console.WriteLine("[INFO] Count steps: " + mHeightmapData.Steps.Length); for (int index = 0; index < mHeightmapData.Steps.Length; index++) { Console.WriteLine("[INFO] Start parse heightmap for step : " + index); HeightmapStep step = mHeightmapData.Steps[index]; step.ValidateSettings(); step.DisplayInfo(); Bitmap bitmap = new Bitmap(new FileInfo(step.TexturePath).FullName); Bitmap bitmapColor = null; if (!string.IsNullOrEmpty(step.ColorTexturePath)) { bitmapColor = new Bitmap(new FileInfo(step.ColorTexturePath).FullName); } Schematic schematicStep = ImageUtils.WriteSchematicFromImage(bitmap, bitmapColor, step); finalSchematic = SchematicMerger.Merge(finalSchematic, schematicStep, step); } return(finalSchematic); }
private Schematic ProcessShaderPatina(Schematic schematic) { using (ProgressBar progressBar = new ProgressBar()) { int index = 0; List <Voxel> allVoxels = schematic.GetAllVoxels(); int colorChanged = 0; foreach (Voxel voxel in allVoxels) { if (Grows(schematic, voxel)) { uint newColor = GetCrowColor(schematic, voxel); if (voxel.Color != newColor) { schematic.ReplaceVoxel(voxel, newColor); colorChanged++; } } progressBar.Report(index++ / (float)(allVoxels.Count)); } Console.WriteLine("COLOR CHANGED: " + colorChanged); if (colorChanged == 0) { mShouldBreak = true; Console.WriteLine("[INFO] NO COLORS CHANGED, BREAK"); } } return(schematic); }
public Schematic ApplyShader(Schematic schematic, ShaderStep shaderStep) { List <Voxel> allVoxels = schematic.GetAllVoxels(); int index = 0; using (ProgressBar progressBar = new ProgressBar()) { foreach (Voxel voxel in allVoxels) { int x = voxel.X; int y = voxel.Y; int z = voxel.Z; if (x == 0 || y == 0 || z == 0) { continue; } if (schematic.GetColorAtVoxelIndex(x - 1, y, z) == 0 && schematic.GetColorAtVoxelIndex(x + 1, y, z) == 0 && schematic.GetColorAtVoxelIndex(x, y - 1, z) == 0 && schematic.GetColorAtVoxelIndex(x, y + 1, z) == 0 && schematic.GetColorAtVoxelIndex(x, y, z - 1) == 0 && schematic.GetColorAtVoxelIndex(x, y, z + 1) == 0) { schematic.RemoveVoxel(x, y, z); } progressBar.Report(index++ / (float)allVoxels.Count); } } Console.WriteLine("[INFO] Done."); return(schematic); }
public Schematic ConvertSchematic(Schematic schematic) { Console.WriteLine("[INFO] Started to convert all colors of blocks to match the palette"); Schematic newSchematic = new Schematic(GetPaletteUint()); List <uint> colors = schematic.UsedColors; Dictionary <uint, int> paletteDictionary = new Dictionary <uint, int>(); foreach (uint color in colors) { int index = ColorComparison.CompareColorRGB(_colors, color.UIntToColor()); paletteDictionary[color] = index; } using (ProgressBar progressbar = new ProgressBar()) { int i = 0; List <Voxel> allVoxels = schematic.GetAllVoxels(); foreach (Voxel block in allVoxels) { newSchematic.AddVoxel(block.X, block.Y, block.Z, _colors[paletteDictionary[block.Color]].ColorToUInt()); progressbar.Report(i++ / (float)allVoxels.Count); } } Console.WriteLine("[INFO] Done."); return(newSchematic); }
public override Schematic WriteSchematic() { List <Voxel> list = Quantization.ApplyQuantization(mSchematic.GetAllVoxels(), ColorLimit); Schematic schematic = new Schematic(list); return(schematic); }
private Schematic ProcessShaderColorDenoiserWithStrictMode(Schematic schematic) { int colorChanged = 0; int index = 0; using (ProgressBar progressBar = new ProgressBar()) { List <Voxel> voxels = schematic.GetAllVoxels(); foreach (Voxel voxel in voxels) { int x = voxel.X; int y = voxel.Y; int z = voxel.Z; uint left = schematic.GetColorAtVoxelIndex(x - 1, y, z); uint right = schematic.GetColorAtVoxelIndex(x + 1, y, z); uint top = schematic.GetColorAtVoxelIndex(x, y + 1, z); uint bottom = schematic.GetColorAtVoxelIndex(x, y - 1, z); uint front = schematic.GetColorAtVoxelIndex(x, y, z + 1); uint back = schematic.GetColorAtVoxelIndex(x, y, z - 1); progressBar.Report(index++ / (float)voxels.Count); if (left == right && left == front && left == back && left != 0 && voxel.Color != left) { schematic.ReplaceVoxel(voxel, left); colorChanged++; continue; } if (left == right && left == top && left == bottom && left != 0 && voxel.Color != left) { schematic.ReplaceVoxel(voxel, left); colorChanged++; continue; } if (front == back && front == top && front == bottom && front != 0 && voxel.Color != front) { schematic.ReplaceVoxel(voxel, front); colorChanged++; continue; } } } if (colorChanged == 0) { mShouldBreak = true; Console.WriteLine("[INFO] NO COLORS CHANGED, BREAK"); } Console.WriteLine("[INFO] Color changed: " + colorChanged); Console.WriteLine("[INFO] Done."); return(schematic); }
private Schematic ProcessSchematicInDeleteMode(Schematic schematic, ShaderFill shaderFill) { List <Voxel> allVoxels = schematic.GetAllVoxels(); using (ProgressBar progressBar = new ProgressBar()) { int index = 0; foreach (Voxel voxel in allVoxels) { int x = voxel.X; int y = voxel.Y; int z = voxel.Z; bool shouldDelete = false; switch (shaderFill.RotationMode) { case RotationMode.X: shouldDelete = shaderFill.FillDirection == FillDirection.PLUS ? x >= shaderFill.Limit : x <= shaderFill.Limit; break; case RotationMode.Y: shouldDelete = shaderFill.FillDirection == FillDirection.PLUS ? y >= shaderFill.Limit : y <= shaderFill.Limit; break; case RotationMode.Z: shouldDelete = shaderFill.FillDirection == FillDirection.PLUS ? z >= shaderFill.Limit : z <= shaderFill.Limit; break; default: throw new ArgumentOutOfRangeException(); } if (shouldDelete) { schematic.RemoveVoxel(x, y, z); } progressBar.Report(index++ / (float)allVoxels.Count); } } return(schematic); }
private static Schematic MergeAdditive(Schematic schematicA, Schematic schematicB) { Console.WriteLine("[INFO] Start to merge schematic with additive mode"); using (ProgressBar progressbar = new ProgressBar()) { int index = 0; List <Voxel> allVoxelsB = schematicB.GetAllVoxels(); foreach (Voxel voxel in allVoxelsB) { schematicA.AddVoxel(voxel); progressbar.Report(index++ / (float)allVoxelsB.Count); } } Console.WriteLine("[INFO] Done"); return(schematicA); }
private static Schematic MergeReplace(Schematic schematicA, Schematic schematicB) { Console.WriteLine("[INFO] Start to merge schematic with replace mode"); using (ProgressBar progressbar = new ProgressBar()) { int index = 0; List <Voxel> allVoxelsB = schematicB.GetAllVoxels(); foreach (var voxel in allVoxelsB) { if (schematicA.GetColorAtVoxelIndex(voxel.X, voxel.Y, voxel.Z) != 0) { schematicA.ReplaceVoxel(voxel.X, voxel.Y, voxel.Z, voxel.Color); } progressbar.Report(index++ / (float)allVoxelsB.Count); } } Console.WriteLine("[INFO] Done"); return(schematicA); }
private Schematic ProcessShaderCase(Schematic schematic, ShaderCase shaderCase) { List <Voxel> allVoxels = schematic.GetAllVoxels(); using (ProgressBar progressBar = new ProgressBar()) { int index = 0; foreach (Voxel voxel in allVoxels) { int x = voxel.X; int y = voxel.Y; int z = voxel.Z; if (x == 0 || y == 0 || z == 0) { continue; } for (int minX = x - 1; minX < x + 1; minX++) { for (int minY = y - 1; minY < y + 1; minY++) { for (int minZ = z - 1; minZ < z + 1; minZ++) { if (!schematic.ContainsVoxel(minX, minY, minZ)) { if (shaderCase.TargetColorIndex != -1 && schematic.GetPaletteIndex(voxel.Color) == shaderCase.TargetColorIndex || shaderCase.TargetColorIndex == -1) { schematic.AddVoxel(minX, minY, minZ, voxel.Color); } } } } } progressBar.Report(index++ / (float)allVoxels.Count); } } return(schematic); }
private Schematic ProcessShaderColorDenoiserWithColorRange(Schematic schematic, int colorRange) { int colorChanged = 0; int index = 0; using (ProgressBar progressBar = new ProgressBar()) { List <Voxel> voxels = schematic.GetAllVoxels(); foreach (Voxel voxel in voxels) { progressBar.Report(index++ / (float)voxels.Count); int x = voxel.X; int y = voxel.Y; int z = voxel.Z; Voxel left = null; Voxel right = null; Voxel top = null; Voxel bottom = null; Voxel front = null; Voxel back = null; if (schematic.GetVoxel(x - 1, y, z, out Voxel v)) { left = v; } if (schematic.GetVoxel(x + 1, y, z, out v)) { right = v; } if (schematic.GetVoxel(x, y + 1, z, out v)) { top = v; } if (schematic.GetVoxel(x, y - 1, z, out v)) { bottom = v; } if (schematic.GetVoxel(x, y, z + 1, out v)) { front = v; } if (schematic.GetVoxel(x, y, z - 1, out v)) { back = v; } List <Voxel> list = new List <Voxel>() { right, left, top, bottom, front, back }; list = list.Where(v => v != null).ToList(); if (DistanceAverage(schematic, voxel, list) <= colorRange) { schematic.ReplaceVoxel(voxel, GetDominantColor(list)); colorChanged++; } } } if (colorChanged == 0) { mShouldBreak = true; Console.WriteLine("[INFO] NO COLORS CHANGED, BREAK"); } Console.WriteLine("[INFO] Color changed: " + colorChanged); Console.WriteLine("[INFO] Done."); return(schematic); }
private Schematic ProcessShaderFixHoles(Schematic schematic) { List <Voxel> allVoxels = schematic.GetAllVoxels(); int index = 0; int fixedHoles = 0; int total = (int)(schematic.RegionDict.Values.Count(region => region.BlockDict.Count > 0) * MathF.Pow(Schematic.CHUNK_SIZE, 3)); Console.WriteLine("[INFO] Count voxel before: " + allVoxels.Count); using (ProgressBar progressBar = new ProgressBar()) { foreach (Region region in schematic.RegionDict.Values.Where(region => region.BlockDict.Count > 0)) { for (int x = region.X; x < region.X + Schematic.CHUNK_SIZE; x++) { for (int y = region.Y; y < region.Y + Schematic.CHUNK_SIZE; y++) { for (int z = region.Z; z < region.Z + Schematic.CHUNK_SIZE; z++) { progressBar.Report(index++ / (float)total); if (!region.GetVoxel(x, y, z, out Voxel voxel)) { uint left = region.GetColorAtVoxelIndex(x - 1, y, z); uint left2 = region.GetColorAtVoxelIndex(x - 2, y, z); uint right = region.GetColorAtVoxelIndex(x + 1, y, z); uint right2 = region.GetColorAtVoxelIndex(x + 1, y, z); uint top = region.GetColorAtVoxelIndex(x, y + 1, z); uint bottom = region.GetColorAtVoxelIndex(x, y - 1, z); uint front = region.GetColorAtVoxelIndex(x, y, z + 1); uint front2 = region.GetColorAtVoxelIndex(x, y, z + 2); uint back = region.GetColorAtVoxelIndex(x, y, z - 1); uint back2 = region.GetColorAtVoxelIndex(x, y, z - 2); //1x1 if (left != 0 && right != 0 && front != 0 && back != 0) { schematic.AddVoxel(x, y, z, left); fixedHoles++; continue; } if (left != 0 && right != 0 && top != 0 && bottom != 0) { schematic.AddVoxel(x, y, z, top); fixedHoles++; continue; } if (front != 0 && back != 0 && top != 0 && bottom != 0) { schematic.AddVoxel(x, y, z, front); fixedHoles++; continue; } //Edges horizontal bottom if (left != 0 && right != 0 && bottom != 0 && front != 0) { schematic.AddVoxel(x, y, z, front); fixedHoles++; continue; } if (left != 0 && right != 0 && bottom != 0 && back != 0) { schematic.AddVoxel(x, y, z, back); fixedHoles++; continue; } if (front != 0 && back != 0 && bottom != 0 && left != 0) { schematic.AddVoxel(x, y, z, front); fixedHoles++; continue; } if (front != 0 && back != 0 && bottom != 0 && right != 0) { schematic.AddVoxel(x, y, z, right); fixedHoles++; continue; } //Edges horizontal top if (left != 0 && right != 0 && top != 0 && front != 0) { schematic.AddVoxel(x, y, z, front); fixedHoles++; continue; } if (left != 0 && right != 0 && top != 0 && back != 0) { schematic.AddVoxel(x, y, z, back); fixedHoles++; continue; } if (front != 0 && back != 0 && top != 0 && left != 0) { schematic.AddVoxel(x, y, z, front); fixedHoles++; continue; } if (front != 0 && back != 0 && top != 0 && right != 0) { schematic.AddVoxel(x, y, z, right); fixedHoles++; continue; } //Edges vertical (4) if (left != 0 && top != 0 && bottom != 0 && front != 0) { schematic.AddVoxel(x, y, z, left); fixedHoles++; continue; } if (left != 0 && top != 0 && bottom != 0 && back != 0) { schematic.AddVoxel(x, y, z, back); fixedHoles++; continue; } if (right != 0 && top != 0 && bottom != 0 && front != 0) { schematic.AddVoxel(x, y, z, right); fixedHoles++; continue; } if (right != 0 && top != 0 && bottom != 0 && back != 0) { schematic.AddVoxel(x, y, z, back); fixedHoles++; continue; } /* * ** * 10* ** ** */ uint frontRight = region.GetColorAtVoxelIndex(x + 1, y, z + 1); uint backRight = region.GetColorAtVoxelIndex(x + 1, y, z - 1); if (left != 0 && front != 0 && right == 0 && right2 != 0 && back != 0 && frontRight != 0 && backRight != 0) { schematic.AddVoxel(x, y, z, left); fixedHoles++; continue; } /* * ** * 01* ** ** */ uint frontLeft = region.GetColorAtVoxelIndex(x - 1, y, z + 1); uint backLeft = region.GetColorAtVoxelIndex(x - 1, y, z - 1); if (right != 0 && front != 0 && back != 0 && left == 0 && frontLeft != 0 && left2 != 0 && backLeft != 0) { schematic.AddVoxel(x, y, z, right); fixedHoles++; continue; } /* * * * 1* * 0* * * */ if (left != 0 && right != 0 && front != 0 && back == 0 && backLeft != 0 && backRight != 0 && back2 != 0) { schematic.AddVoxel(x, y, z, right); fixedHoles++; continue; } /* * * * 0* * 1* * * */ if (left != 0 && right != 0 && front == 0 && back != 0 && frontLeft != 0 && frontRight != 0 && front2 != 0) { schematic.AddVoxel(x, y, z, right); fixedHoles++; continue; } /* * ** * 10* * 00* ** ** */ uint backRight2 = region.GetColorAtVoxelIndex(x + 2, y, z - 1); uint back2Right = region.GetColorAtVoxelIndex(x + 1, y, z - 2); if (left != 0 && front != 0 && right == 0 && frontRight != 0 && right2 != 0 && back == 0 && backLeft != 0 && backRight == 0 && back2 != 0 && backRight2 != 0 && back2Right != 0) { schematic.AddVoxel(x, y, z, left); fixedHoles++; continue; } /* * ** * 01* * 00* ** ** */ uint backLeft2 = region.GetColorAtVoxelIndex(x - 2, y, z - 1); uint back2Left = region.GetColorAtVoxelIndex(x - 1, y, z - 2); if (right != 0 && front != 0 && left == 0 && left2 != 0 && frontLeft != 0 && back == 0 && backRight != 0 && backLeft == 0 && backLeft2 != 0 && back2 != 0 && back2Left != 0) { schematic.AddVoxel(x, y, z, right); fixedHoles++; continue; } } } } } } } if (fixedHoles == 0) { mShouldBreak = true; Console.WriteLine("[INFO] NO VOXEL CHANGED, BREAK"); } Console.WriteLine("[INFO] Fixed holes: " + fixedHoles); Console.WriteLine("[INFO] Done."); return(schematic); }
private static Schematic MergeTopOnly(Schematic schematicA, Schematic schematicB, HeightmapStep step) { Console.WriteLine("[INFO] Start to merge schematic with top only mode"); List <Voxel> allVoxels = schematicA.GetAllVoxels(); List <Voxel> allVoxelsB = schematicB.GetAllVoxels(); using (ProgressBar progressbar = new ProgressBar()) { //int max = schematicA.Length * schematicA.Width; int max = allVoxels.Count + allVoxelsB.Count; int index = 0; Dictionary <int, List <int> > tops = new Dictionary <int, List <int> >(); foreach (Voxel voxel in allVoxels) { int x = voxel.X; int y = voxel.Y; int z = voxel.Z; if (x == 0 || y == 0 || z == 0) { continue; } Vector3Int position; int index2d = Schematic.GetVoxelIndex2DFromRotation(x, y, z, step.RotationMode); switch (step.RotationMode) { case RotationMode.X: position = new Vector3Int(x + 1, y, z); break; case RotationMode.Y: position = new Vector3Int(x, y + 1, z); break; case RotationMode.Z: position = new Vector3Int(x, y, z + 1); break; default: position = new Vector3Int(x, y + 1, z); break; } if (schematicA.GetColorAtVoxelIndex(position) == 0) { if (!tops.ContainsKey(index2d)) { tops[index2d] = new List <int>(); } if (step.RotationMode == RotationMode.Y) { tops[index2d].Add(y); } else if (step.RotationMode == RotationMode.X) { tops[index2d].Add(x); } else if (step.RotationMode == RotationMode.Z) { tops[index2d].Add(z); } } progressbar.Report(index++ / (double)max); } foreach (Voxel voxel in allVoxelsB) { int x = voxel.X; int y = voxel.Y; int z = voxel.Z; int index2d = Schematic.GetVoxelIndex2DFromRotation(x, y, z, step.RotationMode); if (tops.ContainsKey(index2d)) { foreach (int maxHeight in tops[index2d]) { switch (step.RotationMode) { case RotationMode.X: schematicA.AddVoxel(x + maxHeight + step.OffsetMerge, y, z, voxel.Color); break; case RotationMode.Y: schematicA.AddVoxel(x, y + maxHeight + step.OffsetMerge, z, voxel.Color); break; case RotationMode.Z: schematicA.AddVoxel(x, y, z + maxHeight + step.OffsetMerge, voxel.Color); break; } } } progressbar.Report(index++ / (double)max); } } Console.WriteLine("[INFO] Done"); return(schematicA); }