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);
        }
Beispiel #2
0
        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);
        }