Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }