private Schematic ProcessSchematicInXAxis(Schematic schematic, ShaderFill shaderFill) { int min = shaderFill.Limit; uint color = schematic.GetColorAtPaletteIndex(shaderFill.TargetColorIndex); for (int y = 0; y < schematic.Height; y++) { for (int z = 0; z < schematic.Length; z++) { if (shaderFill.FillDirection == FillDirection.PLUS) { for (int x = min; x < schematic.Width; x++) { schematic.AddVoxel(x, y, z, color, shaderFill.Replace); } } else { for (int x = min; x >= 0; x--) { schematic.AddVoxel(x, y, z, color, shaderFill.Replace); } } } } 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); }
private Schematic Convert(List <VoxelDTO> voxels) { int minX = voxels.Min(x => x.X); int minY = voxels.Min(x => x.Y); int minZ = voxels.Min(x => x.Z); Schematic schematic = new Schematic(); Console.WriteLine("[INFO] Started to write schematic from qb..."); Console.WriteLine("[INFO] Qb Width: " + schematic.Width); Console.WriteLine("[INFO] Qb Length: " + schematic.Length); Console.WriteLine("[INFO] Qb Height: " + schematic.Height); using (ProgressBar progressbar = new ProgressBar()) { for (var index = 0; index < voxels.Count; index++) { VoxelDTO voxel = voxels[index]; voxel.X -= minX; voxel.Y -= minY; voxel.Z -= minZ; ushort x = (ushort)voxel.X; ushort y = (ushort)voxel.Y; ushort z = (ushort)voxel.Z; schematic.AddVoxel(x, y, z, FctExtensions.ByteArrayToUInt(voxel.R, voxel.G, voxel.B, 1)); progressbar.Report((index / (float)voxels.Count)); } } Console.WriteLine("[INFO] Done."); return(schematic); }
private Schematic WriteSchematicFromBinvox() { using (LineReader lineReader = new LineReader(File.Open(PathFile, FileMode.Open), Encoding.UTF8)) { ReadHeader(lineReader); ReadVoxels(lineReader); Schematic schematic = new Schematic(); int xmult = (int)(mDimensions.Z * mDimensions.Y); int zmult = (int)(mDimensions.Z); for (int Y = 0; Y < mDimensions.Y; Y++) { for (int Z = 0; Z < mDimensions.Z; Z++) { for (int X = 0; X < mDimensions.X; X++) { int index = X * xmult + Z * zmult + Y; if (mVoxels[index] == 1) { schematic.AddVoxel(X, Y, Z, Color.Wheat.ToFileToVoxCoreColor()); } } } } return(schematic); } }
private Schematic CreateSchematic(RawSchematic rawSchematic) { if (rawSchematic.Heigth > Schematic.MAX_WORLD_HEIGHT || rawSchematic.Length > Schematic.MAX_WORLD_LENGTH || rawSchematic.Width > Schematic.MAX_WORLD_WIDTH) { throw new Exception("Schematic is too big"); } Console.WriteLine($"[INFO] Started to read all blocks of the schematic..."); //Sorted by height (bottom to top) then length then width -- the index of the block at X,Y,Z is (Y×length + Z)×width + X. Schematic schematic = new Schematic(); int total = (rawSchematic.Heigth) * (rawSchematic.Length) * (rawSchematic.Width); int indexProgress = 0; using (ProgressBar progressbar = new ProgressBar()) { for (int y = 0; y < (rawSchematic.Heigth); y++) { for (int z = 0; z < (rawSchematic.Length); z++) { for (int x = 0; x < (rawSchematic.Width); x++) { int index = (y * rawSchematic.Length + z) * rawSchematic.Width + x; int blockId = rawSchematic.Blocks[index]; if (blockId != 0) { Voxel voxel = new Voxel((ushort)x, (ushort)y, (ushort)z, GetBlockColor(rawSchematic.Blocks[index], rawSchematic.Data[index]).ColorToUInt()); if ((mExcavate && IsBlockConnectedToAir(rawSchematic, voxel, 0, rawSchematic.Heigth) || !mExcavate)) { if (!schematic.ContainsVoxel(x, y, z)) { schematic.AddVoxel(x, y, z, voxel.Color); } } } progressbar.Report(indexProgress++ / (float)total); } } } } Console.WriteLine($"[INFO] Done."); return(schematic); }
public override Schematic WriteSchematic() { Schematic schematic = new Schematic(); FileToVoxCore.Drawing.Color[] colorsPalette = mVoxModel.Palette; using (ProgressBar progressbar = new ProgressBar()) { int minX = (int)mVoxModel.TransformNodeChunks.MinBy(t => t.TranslationAt().X).TranslationAt().X; int minY = (int)mVoxModel.TransformNodeChunks.MinBy(t => t.TranslationAt().Y).TranslationAt().Y; int minZ = (int)mVoxModel.TransformNodeChunks.MinBy(t => t.TranslationAt().Z).TranslationAt().Z; for (int i = 0; i < mVoxModel.VoxelFrames.Count; i++) { VoxelData data = mVoxModel.VoxelFrames[i]; Vector3 worldPositionFrame = mVoxModel.TransformNodeChunks[i + 1].TranslationAt(); if (worldPositionFrame == Vector3.zero) { continue; } for (int y = 0; y < data.VoxelsTall; y++) { for (int z = 0; z < data.VoxelsDeep; z++) { for (int x = 0; x < data.VoxelsWide; x++) { int indexColor = data.Get(x, y, z); FileToVoxCore.Drawing.Color color = colorsPalette[indexColor]; if (color != FileToVoxCore.Drawing.Color.Empty) { schematic.AddVoxel((int)(z + worldPositionFrame.X - minX), (int)(y + (worldPositionFrame.Z - minZ)), (int)(x + worldPositionFrame.Y - minY), color.ColorToUInt()); } } } } progressbar.Report(i / (float)mVoxModel.VoxelFrames.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 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 WriteSchematicFromASC() { int nCols = 0; int nRows = 0; int cellSize = 0; int xllcorner = 0; int yllcorner = 0; int nodata = -9999; float[,] points = new float[0, 0]; //rows, cols using (StreamReader file = new StreamReader(PathFile)) { string line; int row = 0; while ((line = file.ReadLine()) != null) { string[] data = line.Split(" ").Where(d => !string.IsNullOrEmpty(d)).ToArray(); switch (data[0]) { case "ncols": nCols = Convert.ToInt32(data[1]); points = new float[nRows, nCols]; break; case "nrows": nRows = Convert.ToInt32(data[1]); points = new float[nRows, nCols]; break; case "xllcorner": xllcorner = Convert.ToInt32(data[1]); break; case "yllcorner": yllcorner = Convert.ToInt32(data[1]); break; case "cellsize": cellSize = Convert.ToInt32(data[1]); break; case "NODATA_value": nodata = Convert.ToInt32(data[1]); break; default: ProcessLine(data, row++, ref points); break; } } } Schematic schematic = new Schematic(); for (int i = 0; i < points.GetLength(0); i++) { for (int j = 0; j < points.GetLength(1); j++) { if (points[i, j] != nodata) { schematic.AddVoxel(i, (int)points[i, j], j, Color.White.ToFileToVoxCoreColor()); } } } return(schematic); }
protected void VoxelizeData(BodyDataDTO data) { mSchematic = new Schematic(); if (data.BodyVertices.Count == 0) { return; } Vector3 minX = data.BodyVertices.MinBy(t => t.X); Vector3 minY = data.BodyVertices.MinBy(t => t.Y); Vector3 minZ = data.BodyVertices.MinBy(t => t.Z); float min = Math.Abs(Math.Min(minX.X, Math.Min(minY.Y, minZ.Z))); for (int i = 0; i < data.BodyVertices.Count; i++) { data.BodyVertices[i] += new Vector3(min, min, min); //data.BodyVertices[i] = new Vector3((float)Math.Truncate(data.BodyVertices[i].X * Scale), (float)Math.Truncate(data.BodyVertices[i].Y * Scale), (float)Math.Truncate(data.BodyVertices[i].Z * Scale)); } Vector3 maxX = data.BodyVertices.MaxBy(t => t.X); Vector3 maxY = data.BodyVertices.MaxBy(t => t.Y); Vector3 maxZ = data.BodyVertices.MaxBy(t => t.Z); Console.WriteLine("[INFO] Max X: " + maxX.X + ", Y: " + maxY.Y + ", " + maxZ.Z); minX = data.BodyVertices.MinBy(t => t.X); minY = data.BodyVertices.MinBy(t => t.Y); minZ = data.BodyVertices.MinBy(t => t.Z); Console.WriteLine("[INFO] Min X: " + minX.X + ", Y: " + minY.Y + ", " + minZ.Z); Vector3 size = new Vector3(maxX.X - minX.X, maxY.Y - minY.Y, maxZ.Z - minZ.Z); Console.WriteLine("[INFO] Size X: " + size.X + ", Y: " + size.Y + ", " + size.Z); float max = Math.Max(size.X, Math.Max(size.Y, size.Z)); float factor = Scale / max; for (int i = 0; i < data.BodyVertices.Count; i++) { data.BodyVertices[i] = new Vector3((float)Math.Truncate(data.BodyVertices[i].X * factor), (float)Math.Truncate(data.BodyVertices[i].Y * factor), (float)Math.Truncate(data.BodyVertices[i].Z * factor)); } minX = data.BodyVertices.MinBy(t => t.X); minY = data.BodyVertices.MinBy(t => t.Y); minZ = data.BodyVertices.MinBy(t => t.Z); //HashSet<Vector3> set = new HashSet<Vector3>(); min = Math.Min(minX.X, Math.Min(minY.Y, minZ.Z)); Console.WriteLine("[INFO] Started to voxelize data..."); using (ProgressBar progressbar = new ProgressBar()) { for (int i = 0; i < data.BodyVertices.Count; i++) { float maxV = Math.Max(data.BodyVertices[i].X, Math.Max(data.BodyVertices[i].Y, data.BodyVertices[i].Z)); if (maxV - min >= 0) { data.BodyVertices[i] -= new Vector3(min, min, min); mSchematic.AddVoxel((int)(data.BodyVertices[i].X - minX.X), (int)(data.BodyVertices[i].Y - minY.Y), (int)(data.BodyVertices[i].Z - minZ.Z), data.BodyColors[i].ColorToUInt()); } //if (!set.Contains(data.BodyVertices[i])) //{ // set.Add(data.BodyVertices[i]); // //vertices.Add(data.BodyVertices[i]); // //colors.Add(data.BodyColors[i]); //} progressbar.Report(i / (float)data.BodyVertices.Count); } } Console.WriteLine("[INFO] Done."); //minX = vertices.MinBy(t => t.X); //minY = vertices.MinBy(t => t.Y); //minZ = vertices.MinBy(t => t.Z); //for (int i = 0; i < vertices.Count; i++) //{ // float max = Math.Max(vertices[i].X, Math.Max(vertices[i].Y, vertices[i].Z)); // if (/*max - min < 8000 && */max - min >= 0) // { // vertices[i] -= new Vector3(min, min, min); // _blocks.Add(new Voxel((ushort)vertices[i].X, (ushort)vertices[i].Y, (ushort)vertices[i].Z, colors[i].ColorToUInt())); // } //} }
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); }
public static void AddBlock(ref Schematic schematic, Voxel voxel) { schematic.AddVoxel(voxel); }
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); }
public Schematic CreateSchematic(Vector3 boxMin, Vector3 boxMax) { Vector3 position = new Vector3(); Vector3 chunkMinPos = GetChunkPosition(boxMin); Vector3 chunkMaxPos = GetChunkPosition(boxMax); int minX = (int)boxMin.X; int minY = (int)boxMin.Y; int minZ = (int)boxMin.Z; int maxX = (int)boxMax.X; int maxY = (int)boxMax.Y; int maxZ = (int)boxMax.Z; Schematic schematic = new Schematic(); for (float y = chunkMinPos.Y; y <= chunkMaxPos.Y; y += CHUNK_SIZE) { position.Y = y; for (float z = chunkMinPos.Z; z <= chunkMaxPos.Z; z += CHUNK_SIZE) { position.Z = z; for (float x = chunkMinPos.X; x <= chunkMaxPos.X; x += CHUNK_SIZE) { position.X = x; if (GetChunk(position, out VoxelChunk chunk, false)) { FastMath.FloorToInt(chunk.Position.X, chunk.Position.Y, chunk.Position.Z, out int chunkMinX, out int chunkMinY, out int chunkMinZ); chunkMinX -= CHUNK_HALF_SIZE; chunkMinY -= CHUNK_HALF_SIZE; chunkMinZ -= CHUNK_HALF_SIZE; for (int vy = 0; vy < CHUNK_SIZE; vy++) { int wy = chunkMinY + vy; if (wy < minY || wy > maxY) { continue; } int my = wy - minY; int voxelIndexY = vy * ONE_Y_ROW; for (int vz = 0; vz < CHUNK_SIZE; vz++) { int wz = chunkMinZ + vz; if (wz < minZ || wz > maxZ) { continue; } int mz = wz - minZ; int voxelIndex = voxelIndexY + vz * ONE_Z_ROW; for (int vx = 0; vx < CHUNK_SIZE; vx++, voxelIndex++) { int wx = chunkMinX + vx; if (wx < minX || wx > maxX) { continue; } int mx = wx - minX; schematic.AddVoxel(mx, my, mz, chunk.Voxels[voxelIndex].Color); } } } }