public void Export(TileModel model, TilePropagator propagator, string filename, DeBroglieConfig config, ExportOptions exportOptions)
        {
            if (config.Animate)
            {
                if (exportOptions is BitmapExportOptions)
                {
                    var topoArray = propagator.ToWeightedArraySets().Map(WeightedColorAverage);
                    var bitmap    = BitmapUtils.ToBitmap(topoArray.ToArray2d());
                    bitmap.Save(filename);
                }
                else if (exportOptions is BitmapSetExportOptions bseo)
                {
                    var topoArray    = propagator.ToWeightedArraySets();
                    var tileTopology = topoArray.Topology.AsGridTopology().WithSize(bseo.TileWidth, bseo.TileHeight, 1);
                    var subTiles     = bseo.Bitmaps.ToDictionary(x => x.Key, x => TopoArray.Create(BitmapUtils.ToColorArray(x.Value), tileTopology).Map(c => new Tile(c)));
                    var exploded     = MoreTopoArrayUtils.ExplodeWeightedTiles(topoArray, subTiles, bseo.TileWidth, bseo.TileHeight, 1).Map(WeightedColorAverage);
                    var bitmap       = BitmapUtils.ToBitmap(exploded.ToArray2d());
                    bitmap.Save(filename);
                }
                else
                {
                    throw new System.Exception($"Cannot export from {exportOptions.TypeDescription} to bitmap.");
                }
            }
            else
            {
                if (exportOptions is BitmapExportOptions)
                {
                    var topoArray = propagator.ToValueArray(Rgba32.Gray, Rgba32.Magenta);
                    var bitmap    = BitmapUtils.ToBitmap(topoArray.ToArray2d());
                    bitmap.Save(filename);
                }
                else if (exportOptions is BitmapSetExportOptions bseo)
                {
                    var undecided     = new Tile(new object());
                    var contradiction = new Tile(new object());
                    var topoArray     = propagator.ToArray(undecided, contradiction);

                    var tileTopology = topoArray.Topology.AsGridTopology().WithSize(bseo.TileWidth, bseo.TileHeight, 1);
                    var subTiles     = bseo.Bitmaps.ToDictionary(x => x.Key, x => TopoArray.Create(BitmapUtils.ToColorArray(x.Value), tileTopology));
                    subTiles[undecided]     = TopoArray.FromConstant(Rgba32.Gray, tileTopology);
                    subTiles[contradiction] = TopoArray.FromConstant(Rgba32.Magenta, tileTopology);

                    var exploded = MoreTopoArrayUtils.ExplodeTiles(topoArray, subTiles, bseo.TileWidth, bseo.TileHeight, 1);
                    var bitmap   = BitmapUtils.ToBitmap(exploded.ToArray2d());
                    bitmap.Save(filename);
                }
                else
                {
                    throw new System.Exception($"Cannot export from {exportOptions.TypeDescription} to bitmap.");
                }
            }
        }
Beispiel #2
0
        public static void Export(TileModel model, TilePropagator tilePropagator, string filename, DeBroglieConfig config, ExportOptions exportOptions)
        {
            var exporter = GetExporter(filename);

            // Handle conversions
            if (exporter is BitmapExporter && exportOptions is TiledExportOptions)
            {
                if (tilePropagator.Topology.AsGridTopology().Directions.Type != Topo.DirectionSetType.Cartesian2d)
                {
                    throw new NotSupportedException("Converting from Tiled format to bitmaps only supported for square grids.");
                }

                exportOptions = ConvertToBitmaps(exportOptions as TiledExportOptions);
            }

            exporter.Export(model, tilePropagator, filename, config, exportOptions);
        }
Beispiel #3
0
        public void Export(TileModel model, TilePropagator tilePropagator, string filename, DeBroglieConfig config, ExportOptions exportOptions)
        {
            var tiledExportOptions = exportOptions as TiledExportOptions;

            if (tiledExportOptions == null)
            {
                throw new System.Exception($"Cannot export from {exportOptions.TypeDescription} to .tmx");
            }

            var map         = tiledExportOptions.Template;
            var srcFilename = tiledExportOptions.SrcFileName;

            var layerArray = tilePropagator.ToArray();

            map.Layers = new BaseLayer[layerArray.Topology.Depth];
            for (var z = 0; z < layerArray.Topology.Depth; z++)
            {
                map.Layers[z] = TiledUtil.MakeTileLayer(map, layerArray, z);
            }
            map.Width  = map.Layers[0].Width;
            map.Height = map.Layers[0].Height;
            TiledUtil.Save(filename, map);

            // Check for any external files that may also need copying
            foreach (var tileset in map.Tilesets)
            {
                if (tileset is ExternalTileset e)
                {
                    var srcPath  = Path.Combine(Path.GetDirectoryName(srcFilename), e.source);
                    var destPath = Path.Combine(Path.GetDirectoryName(filename), e.source);
                    if (File.Exists(srcPath) && !File.Exists(destPath))
                    {
                        File.Copy(srcPath, destPath);
                    }
                }
                if (tileset.ImagePath != null)
                {
                    var srcImagePath  = Path.Combine(Path.GetDirectoryName(srcFilename), tileset.ImagePath);
                    var destImagePath = Path.Combine(Path.GetDirectoryName(filename), tileset.ImagePath);
                    if (File.Exists(srcImagePath) && !File.Exists(destImagePath))
                    {
                        File.Copy(srcImagePath, destImagePath);
                    }
                }
            }
        }
Beispiel #4
0
        public void Export(TileModel model, TilePropagator tilePropagator, string filename, DeBroglieConfig config, ExportOptions exportOptions)
        {
            var array = tilePropagator.ToArray(new Tile("?"), new Tile("!"));

            using (var s = File.OpenWrite(filename))
                using (var tw = new StreamWriter(s))
                {
                    for (var z = 0; z < array.Topology.Depth; z++)
                    {
                        if (z != 0)
                        {
                            tw.WriteLine();
                        }
                        for (var y = 0; y < array.Topology.Height; y++)
                        {
                            for (var x = 0; x < array.Topology.Width; x++)
                            {
                                if (x != 0)
                                {
                                    tw.Write(",");
                                }
                                tw.Write(array.Get(x, y, z).Value?.ToString());
                            }
                            tw.WriteLine();
                        }
                    }
                }
        }
Beispiel #5
0
        public void Export(TileModel model, TilePropagator tilePropagator, string filename, DeBroglieConfig config, ExportOptions exportOptions)
        {
            var topoArray = tilePropagator.ToArray(new Tile("?"), new Tile("!"));
            var topology  = topoArray.Topology;

            using (var s = File.Open(filename, FileMode.Create))
                using (var tw = new StreamWriter(s))
                {
                    tw.WriteLine("%YAML 1.1");
                    tw.WriteLine("%TAG !u! tag:unity3d.com,2011:");
                    int id = 1;
                    foreach (var index in topology.GetIndices())
                    {
                        var objectId    = id++;
                        var transformId = id++;
                        topology.GetCoord(index, out var x, out var y, out var z);
                        var str = @"
--- !u!1 &objectId
GameObject:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  serializedVersion: 6
  m_Component:
  - component: {fileID: transformId}
  m_Layer: 0
  m_Name: objectName
  m_TagString: Untagged
  m_Icon: {fileID: 0}
  m_NavMeshLayer: 0
  m_StaticEditorFlags: 0
  m_IsActive: 1
--- !u!4 &transformId
Transform:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  m_GameObject: {fileID: objectId}
  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
  m_LocalPosition: {x: transformX, y: transformY, z: transformZ}
  m_LocalScale: {x: 1, y: 1, z: 1}
  m_Children: []
  m_Father: {fileID: 0}
  m_RootOrder: 0
  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
";
                        str = str
                              .Trim()
                              .Replace("objectId", objectId.ToString())
                              .Replace("transformId", transformId.ToString())
                              .Replace("transformX", x.ToString())
                              .Replace("transformY", y.ToString())
                              .Replace("transformZ", z.ToString())
                              .Replace("objectName", topoArray.Get(index).Value?.ToString())
                        ;
                        tw.WriteLine(str);
                    }
                }
        }
Beispiel #6
0
        public void Export(TileModel model, TilePropagator propagator, string filename, DeBroglieConfig config, ExportOptions exportOptions)
        {
            if (config.Animate)
            {
                if (exportOptions is BitmapExportOptions)
                {
                    var topoArray = propagator.ToValueSets <Rgba32>().Map(BitmapUtils.ColorAverage);
                    var bitmap    = BitmapUtils.ToBitmap(topoArray.ToArray2d());
                    bitmap.Save(filename);
                }
                else if (exportOptions is BitmapSetExportOptions bseo)
                {
                    var topoArray    = propagator.ToArraySets();
                    var tileTopology = topoArray.Topology.AsGridTopology().WithSize(bseo.TileWidth, bseo.TileHeight, 1);
                    var subTiles     = bseo.Bitmaps.ToDictionary(x => x.Key, x => TopoArray.Create(BitmapUtils.ToColorArray(x.Value), tileTopology));
                    var exploded     = MoreTopoArrayUtils.ExplodeTileSets(topoArray, subTiles, bseo.TileWidth, bseo.TileHeight, 1).Map(BitmapUtils.ColorAverage);
                    var bitmap       = BitmapUtils.ToBitmap(exploded.ToArray2d());
                    bitmap.Save(filename);
                }
                else
                {
                    throw new System.Exception($"Cannot export from {exportOptions.TypeDescription} to bitmap.");
                }
            }
            else
            {
                if (exportOptions is BitmapExportOptions)
                {
                    var topoArray = propagator.ToValueArray(Rgba32.Gray, Rgba32.Magenta);
                    var bitmap    = BitmapUtils.ToBitmap(topoArray.ToArray2d());

                    var index         = 0;
                    var noExtension   = Path.GetFileNameWithoutExtension(filename);
                    var justExtension = Path.GetExtension(filename);
                    var pathNoFile    = Path.GetDirectoryName(filename);

                    var seqFilename = "";
                    do
                    {
                        seqFilename = pathNoFile + Path.DirectorySeparatorChar + noExtension + (index == 0 ? "" : index.ToString()) + justExtension;
                        index++;
                    } while (File.Exists(seqFilename));

                    bitmap.Save(seqFilename);
                }
                else if (exportOptions is BitmapSetExportOptions bseo)
                {
                    var undecided     = new Tile(new object());
                    var contradiction = new Tile(new object());
                    var topoArray     = propagator.ToArray(undecided, contradiction);

                    var tileTopology = topoArray.Topology.AsGridTopology().WithSize(bseo.TileWidth, bseo.TileHeight, 1);
                    var subTiles     = bseo.Bitmaps.ToDictionary(x => x.Key, x => TopoArray.Create(BitmapUtils.ToColorArray(x.Value), tileTopology));
                    subTiles[undecided]     = TopoArray.FromConstant(Rgba32.Gray, tileTopology);
                    subTiles[contradiction] = TopoArray.FromConstant(Rgba32.Magenta, tileTopology);

                    var exploded = MoreTopoArrayUtils.ExplodeTiles(topoArray, subTiles, bseo.TileWidth, bseo.TileHeight, 1);
                    var bitmap   = BitmapUtils.ToBitmap(exploded.ToArray2d());
                    bitmap.Save(filename);
                }
                else
                {
                    throw new System.Exception($"Cannot export from {exportOptions.TypeDescription} to bitmap.");
                }
            }
        }
        public void Export(TileModel model, TilePropagator tilePropagator, string filename, DeBroglieConfig config, ExportOptions exportOptions)
        {
            Vox vox;
            ITopoArray <byte> array;

            if (exportOptions is VoxExportOptions veo)
            {
                vox   = veo.Template;
                array = tilePropagator.ToValueArray <byte>();
            }
            else if (exportOptions is VoxSetExportOptions vseo)
            {
                vox = vseo.Template;
                var tileArray = tilePropagator.ToArray();
                var subTiles  = vseo.SubTiles.ToDictionary(x => x.Key, x => VoxUtils.ToTopoArray(x.Value));
                array = MoreTopoArrayUtils.ExplodeTiles(tileArray, subTiles, vseo.TileWidth, vseo.TileHeight, vseo.TileDepth);
            }
            else
            {
                throw new System.Exception($"Cannot export from {exportOptions.TypeDescription} to .vox");
            }

            VoxUtils.Save(vox, array);

            using (var stream = new FileStream(filename, FileMode.Create))
            {
                var br = new BinaryWriter(stream);
                VoxSerializer.Write(br, vox);
            }
        }