private static void SchematicToVox(AbstractToSchematic converter, string outputPath) { Schematic schematic = converter.WriteSchematic(); Console.WriteLine($"[INFO] Vox Width: {schematic.Width}"); Console.WriteLine($"[INFO] Vox Length: {schematic.Length}"); Console.WriteLine($"[INFO] Vox Height: {schematic.Height}"); if (schematic.Width > MAX_WORLD_WIDTH || schematic.Length > MAX_WORLD_LENGTH || schematic.Height > MAX_WORLD_HEIGHT) { Console.WriteLine("[ERROR] Voxel model is too big ! MagicaVoxel can't support model bigger than 2000^3"); return; } VoxWriter writer = new VoxWriter(); if (_inputPaletteFile != null) { PaletteSchematicConverter converterPalette = new PaletteSchematicConverter(_inputPaletteFile, _colorLimit); schematic = converterPalette.ConvertSchematic(schematic); writer.WriteModel(_chunkSize, outputPath + ".vox", converterPalette.GetPalette(), schematic); } else { writer.WriteModel(_chunkSize, outputPath + ".vox", null, schematic); } }
private static bool SchematicToVox(AbstractToSchematic converter) { Schematic schematic = converter.WriteSchematic(); Console.WriteLine($"[INFO] Vox Width: {schematic.Width}"); Console.WriteLine($"[INFO] Vox Length: {schematic.Length}"); Console.WriteLine($"[INFO] Vox Height: {schematic.Height}"); if (schematic.Width > Schematic.MAX_WORLD_WIDTH || schematic.Length > Schematic.MAX_WORLD_LENGTH || schematic.Height > Schematic.MAX_WORLD_HEIGHT) { Console.WriteLine("[ERROR] Model is too big ! MagicaVoxel can't support model bigger than 2000x2000x1000"); return(false); } VoxWriter writer = new VoxWriter(); if (INPUT_PALETTE_FILE != null) { PaletteSchematicConverter converterPalette = new PaletteSchematicConverter(INPUT_PALETTE_FILE); schematic = converterPalette.ConvertSchematic(schematic); return(writer.WriteModel(FormatOutputDestination(OUTPUT_PATH), converterPalette.GetPalette(), schematic)); } if (INPUT_SHADER_FILE != null) { JsonToSchematic jsonParser = new JsonToSchematic(INPUT_SHADER_FILE, schematic); schematic = jsonParser.WriteSchematic(); } return(writer.WriteModel(FormatOutputDestination(OUTPUT_PATH), null, schematic)); }
private static bool SchematicToVox(AbstractToSchematic converter, string outputPath) { Schematic schematic = converter.WriteSchematic(); Console.WriteLine($"[INFO] Vox Width: {schematic.Width}"); Console.WriteLine($"[INFO] Vox Length: {schematic.Length}"); Console.WriteLine($"[INFO] Vox Height: {schematic.Height}"); if (schematic.Width > Schematic.MAX_WORLD_WIDTH || schematic.Length > Schematic.MAX_WORLD_LENGTH || schematic.Height > Schematic.MAX_WORLD_HEIGHT) { Console.WriteLine("[ERROR] Model is too big ! MagicaVoxel can't support model bigger than 2000x2000x1000"); return(false); } VoxWriter writer = new VoxWriter(); if (INPUT_PALETTE_FILE != null) { PaletteSchematicConverter converterPalette = new PaletteSchematicConverter(INPUT_PALETTE_FILE, COLOR_LIMIT); schematic = converterPalette.ConvertSchematic(schematic); return(writer.WriteModel(CHUNK_SIZE, outputPath + ".vox", converterPalette.GetPalette(), schematic)); } return(writer.WriteModel(CHUNK_SIZE, outputPath + ".vox", null, schematic)); }
private static void ProcessCA() { string[] values = _caRule.Split('-'); if (values.Length != 5) { Console.WriteLine("[ERROR] Missing arguments for --ca option"); } try { int width = Convert.ToInt32(values[0]); int length = Convert.ToInt32(values[1]); int height = Convert.ToInt32(values[2]); int lifetime = Convert.ToInt32(values[3]); string[] conditions = values[4].Split('/'); int a = Convert.ToInt32(conditions[0]); int b = Convert.ToInt32(conditions[1]); int[,,] field = new int[width, length, height]; // Random initial positions Random r = new Random((int)DateTime.Now.Ticks); for (int y = 0; y < height; y++) { for (int z = 0; z < length; z++) { for (int x = 0; x < width; x++) { field[x, y, z] = r.Next(0, 1 + 1); } } } //for (int y = 0; y < height; y++) //{ // for (int z = 0; z < length; z++) // { // for (int x = 0; x < width; x++) // { // field[x, y, z] = 1; // } // } //} RuleSet ruleSet = new RuleGeneric(field, width, length, height, a, b); RuleSetToSchematic converter = new RuleSetToSchematic("", ruleSet, lifetime); Schematic schematic = converter.WriteSchematic(); VoxWriter writer = new VoxWriter(); writer.WriteModel(_outputFile + ".vox", schematic, _direction); } catch (Exception e) { Console.WriteLine(e); Console.ReadLine(); } }
private static void ProcessFile() { if (!File.Exists(_inputFile)) { throw new FileNotFoundException("[ERROR] Input file not found", _inputFile); } try { BaseToSchematic converter; switch (Path.GetExtension(_inputFile)) { case ".schematic": converter = new SchematicToSchematic(_inputFile, _ignoreMinY, _ignoreMaxY, _excavate, _scale); break; case ".png": converter = new PNGToSchematic(_inputFile, _inputColorFile, _heightmap, _excavate, _color, _top); break; case ".asc": converter = new ASCToSchematic(_inputColorFile); break; case ".binvox": converter = new BinvoxToSchematic(_inputFile); break; case ".qb": converter = new QbToSchematic(_inputColorFile); break; case ".obj": converter = new ObjToSchematic(_inputFile, _gridSize, _excavate, _slow); break; default: Console.WriteLine("[ERROR] Unknown file extension !"); Console.ReadKey(); return; } Schematic schematic = converter.WriteSchematic(); VoxWriter writer = new VoxWriter(); writer.WriteModel(_outputFile + ".vox", schematic, _direction); } catch (Exception e) { Console.WriteLine(e); Console.ReadLine(); } }
private static void ProcessAscFile() { try { Schematic schematic = ASCToSchematic.WriteSchematic(_inputFile); VoxWriter writer = new VoxWriter(); writer.WriteModel(_outputFile + ".vox", schematic, _direction); } catch (Exception e) { Console.WriteLine(e); Console.ReadLine(); } }
private static void ProcessImageFile() { try { Schematic schematic = PNGToSchematic.WriteSchematic(_inputFile, _inputColorFile, _heightmap, _excavate, _color, _top); VoxWriter writer = new VoxWriter(); writer.WriteModel(_outputFile + ".vox", schematic, _direction); } catch (Exception e) { Console.WriteLine(e); Console.ReadLine(); } }
private static void ProcessSchematicFile() { try { Schematic schematic = SchematicReader.LoadSchematic(_inputFile, _ignoreMinY, _ignoreMaxY, _excavate, _scale); VoxWriter writer = new VoxWriter(); writer.WriteModel(_outputFile + ".vox", schematic, _direction); } catch (Exception e) { Console.WriteLine(e); Console.ReadLine(); } }
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"); } }
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"); } }
private static void ProcessFile() { string path = Path.GetFullPath(_inputFile); if (!File.Exists(path)) { throw new FileNotFoundException("[ERROR] Input file not found", _inputFile); } try { AbstractToSchematic converter; switch (Path.GetExtension(_inputFile)) { case ".schematic": converter = new SchematicToSchematic(path, _ignoreMinY, _ignoreMaxY, _excavate, _scale); break; case ".png": converter = new PNGToSchematic(path, _inputColorFile, _heightmap, _excavate, _color, _top); break; case ".tif": converter = new TIFtoSchematic(path, _inputColorFile, _heightmap, _excavate, _color, _top); break; case ".asc": converter = new ASCToSchematic(path); break; case ".binvox": converter = new BinvoxToSchematic(path); break; case ".qb": converter = new QBToSchematic(path); break; case ".obj": converter = new OBJToSchematic(path, _gridSize, _excavate, _slow); break; case ".ply": converter = new PLYToSchematic(path, _scale); break; case ".xyz": converter = new XYZToSchematic(path, _scale); break; case ".csv": converter = new CSVToSchematic(path, _scale); break; default: Console.WriteLine("[ERROR] Unknown file extension !"); Console.ReadKey(); return; } Schematic schematic = converter.WriteSchematic(); Console.WriteLine($"[INFO] Vox Width: {schematic.Width}"); Console.WriteLine($"[INFO] Vox Length: {schematic.Length}"); Console.WriteLine($"[INFO] Vox Height: {schematic.Heigth}"); VoxWriter writer = new VoxWriter(); writer.WriteModel(_outputFile + ".vox", schematic, _direction); } catch (Exception e) { Console.WriteLine(e); Console.ReadLine(); } }