Exemple #1
0
        private static void ProcessFolder(string inputFolder, string outputFile, bool logs, bool debug)
        {
            string folder = Path.GetFullPath(inputFolder);

            List <string> files = Directory.GetFiles(folder).ToList();

            List <VoxModel> models = new List <VoxModel>();
            VoxReader       reader = new VoxReader();

            Console.WriteLine("[LOG] Started to read all vox files at path: " + folder);
            foreach (string file in files)
            {
                if (Path.GetExtension(file) == ".vox")
                {
                    Console.WriteLine("[LOG] Started to load model: " + file);
                    models.Add(reader.LoadModel(file));
                }
            }

            VoxWriterCustom writer = new VoxWriterCustom();

            if (outputFile.Contains(".vox"))
            {
                writer.WriteModel(outputFile, models);
                reader.LoadModel(outputFile, logs, debug);
            }
            else
            {
                writer.WriteModel(outputFile + ".vox", models);
                reader.LoadModel(outputFile + ".vox", logs, debug);
            }
        }
Exemple #2
0
        private static void ReadVoxelModels(List <string> files, ProgramOptions programOptions)
        {
            List <VoxModel> models = new List <VoxModel>();
            VoxReader       reader = new VoxReader();

            foreach (string file in files.Where(file => Path.GetExtension(file) == ".vox"))
            {
                Console.WriteLine("[LOG] Started to load model: " + file);
                models.Add(reader.LoadModel(file, false, false, false, false));
            }

            VoxWriterCustom writer = new VoxWriterCustom();

            if (models.Count == 0)
            {
                Console.WriteLine("[ERR] No models founds! Abort.");
            }
            else
            {
                writer.WriteModel(programOptions.GetSageOutputFile(), models);
                if (programOptions.EnableDebug)
                {
                    reader.LoadModel(programOptions.OutputFile, programOptions.EnableLogs, true);
                }
            }
        }
Exemple #3
0
 private static void CheckVerbose()
 {
     if (_verbose)
     {
         VoxReader reader = new VoxReader();
         reader.LoadModel(_outputPath + ".vox");
     }
 }
Exemple #4
0
 private static void CheckDebug()
 {
     if (Schematic.DEBUG)
     {
         VoxReader reader = new VoxReader();
         reader.LoadModel(FormatOutputDestination(OUTPUT_PATH));
     }
 }
Exemple #5
0
 private static void CheckVerbose()
 {
     if (DEBUG)
     {
         VoxReader reader = new VoxReader();
         reader.LoadModel(OUTPUT_PATH + ".vox");
     }
 }
Exemple #6
0
    BakedPointCloud ImportAsBakedPointCloud(string path)
    {
        VoxReader voxReader = new VoxReader();
        VoxModel  model     = voxReader.LoadModel(path);

        if (model == null)
        {
            return(null);
        }

        List <Vector3> positions     = new List <Vector3>();
        List <Color>   colors        = new List <Color>();
        var            colorsPalette = model.Palette;

        for (int i = 0; i < model.VoxelFrames.Count; i++)
        {
            VoxelData data = model.VoxelFrames[i];
            FileToVoxCore.Schematics.Tools.Vector3 worldPositionFrame = model.TransformNodeChunks[i + 1].TranslationAt();

            if (worldPositionFrame == FileToVoxCore.Schematics.Tools.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);
                        var color      = colorsPalette[indexColor];
                        if (color != FileToVoxCore.Drawing.Color.Empty)
                        {
                            positions.Add(new Vector3(z + worldPositionFrame.X, y + worldPositionFrame.Z, x + worldPositionFrame.Y));
                            colors.Add(color.ToUnityColor());
                        }
                    }
                }
            }
        }

        BakedPointCloud bakedPointCloud = ScriptableObject.CreateInstance <BakedPointCloud>();

        bakedPointCloud.Initialize(positions, colors);
        bakedPointCloud.name = Path.GetFileNameWithoutExtension(path);
        return(bakedPointCloud);
    }
Exemple #7
0
        public VoxToSchematic(string path) : base(path)
        {
            VoxReader reader = new VoxReader();

            mVoxModel = reader.LoadModel(path);
        }
Exemple #8
0
        static void Main(string[] args)
        {
            VoxReader reader = new VoxReader();
            VoxWriter writer = new VoxWriter();

            DisplayInformations();

            if (args.Length < 2)
            {
                Console.WriteLine("[ERROR] Missing arguments");
                Console.WriteLine("Usage: VoxSlicer.exe SIZE FILE");
                return;
            }

            try
            {
                short size = Convert.ToInt16(args[0]);
                if (size <= 10 || size > 256)
                {
                    Console.WriteLine("[ERROR] Size must be between 10 and 256");
                    return;
                }

                VoxModel model = reader.LoadModel(args[1]);

                if (model == null)
                {
                    Console.WriteLine("[ERROR] Failed to load model");
                    return;
                }

                Schematic.CHUNK_SIZE = size;
                DirectoryInfo directory = Directory.CreateDirectory(Path.GetFileNameWithoutExtension(args[1]));
                foreach (VoxelData data in model.VoxelFrames)
                {
                    int sizeX = (int)Math.Ceiling((decimal)data.VoxelsWide / size);
                    int sizeY = (int)Math.Ceiling((decimal)data.VoxelsTall / size);
                    int sizeZ = (int)Math.Ceiling((decimal)data.VoxelsDeep / size);

                    Schematic[,,] schematics = new Schematic[sizeX, sizeY, sizeZ];
                    Color[] colors = model.Palette;
                    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 posX = x / size;
                                int posY = y / size;
                                int posZ = z / size;

                                schematics[posX, posY, posZ] ??= new Schematic();
                                int   indexColor = data.Get(x, y, z);
                                Color color      = colors[indexColor];

                                if (indexColor != 0)
                                {
                                    schematics[posX, posY, posZ].AddVoxel(x, y, z, color);
                                }
                            }
                        }
                    }

                    for (int x = 0; x < schematics.GetLength(0); x++)
                    {
                        for (int y = 0; y < schematics.GetLength(1); y++)
                        {
                            for (int z = 0; z < schematics.GetLength(2); z++)
                            {
                                if (schematics[x, y, z].GetAllVoxels().Count != 0)
                                {
                                    var    rotation = model.TransformNodeChunks.First().RotationAt();
                                    string name     = $"{Path.GetFileNameWithoutExtension(args[1])}-{x}-{y}-{z}.vox";
                                    Console.WriteLine("[INFO] Started to process: " + name);
                                    string outputPath = Path.Combine(directory.FullName, name);
                                    writer.WriteModel(size, outputPath, model.Palette.ToList(), schematics[x, y, z], rotation);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("[ERROR] Failed to read voxel volume size");
            }
        }
Exemple #9
0
        static void Main(string[] args)
        {
            VoxReader reader = new VoxReader();
            VoxWriter writer = new VoxWriter();

            if (args.Length < 2)
            {
                Console.WriteLine("[ERROR] Missing arguments");
                Console.WriteLine("Usage: VoxSlicer.exe SIZE FILE");
                return;
            }

            try
            {
                short size = Convert.ToInt16(args[0]);
                if (size >= 126)
                {
                    Console.WriteLine("[ERROR] Size must be lower than 126");
                    return;
                }

                VoxModel model = reader.LoadModel(args[1]);
                if (model == null)
                {
                    return;
                }

                DirectoryInfo directory = Directory.CreateDirectory(Path.GetFileNameWithoutExtension(args[1]));

                foreach (var data in model.voxelFrames)
                {
                    SchematicConstants.WidthSchematic  = size;
                    SchematicConstants.HeightSchematic = size;
                    SchematicConstants.LengthSchematic = size;

                    int sizeX = (int)Math.Ceiling((decimal)data.VoxelsWide / size);
                    int sizeY = (int)Math.Ceiling((decimal)data.VoxelsTall / size);
                    int sizeZ = (int)Math.Ceiling((decimal)data.VoxelsDeep / size);
                    Schematic[,,] schematics = new Schematic[sizeX, sizeY, sizeZ];

                    Color[] colors = model.palette;
                    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 posX = x / size;
                                int posY = y / size;
                                int posZ = z / size;

                                if (schematics[posX, posY, posZ] == null)
                                {
                                    schematics[posX, posY, posZ] = new Schematic()
                                    {
                                        Blocks = new System.Collections.Generic.HashSet <Block>(),
                                        Heigth = size,
                                        Length = size,
                                        Width  = size
                                    };
                                }
                                int   indexColor = data.Get(x, y, z);
                                Color color      = colors[indexColor];
                                if (!color.IsEmpty)
                                {
                                    schematics[posX, posY, posZ].Blocks.Add(new Block((ushort)x, (ushort)y, (ushort)z, color.ColorToUInt()));
                                }
                            }
                        }
                    }

                    for (int x = 0; x < schematics.GetLength(0); x++)
                    {
                        for (int y = 0; y < schematics.GetLength(1); y++)
                        {
                            for (int z = 0; z < schematics.GetLength(2); z++)
                            {
                                if (schematics[x, y, z].TotalCount != 0)
                                {
                                    string name = $"{Path.GetFileNameWithoutExtension(args[1])}-{x}-{y}-{z}.vox";
                                    Console.WriteLine("[INFO] Started to process: " + name);
                                    writer.WriteModel(Path.Combine(directory.FullName, name), schematics[x, y, z], 0, size);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("[ERROR] Failed to read voxel volume size");
            }
        }