Esempio n. 1
0
        public void ExportMesh(IRenderable mesh, string filePath, MeshExportFormat format)
        {
            switch (format)
            {
            case MeshExportFormat.OBJ:
                ExportOBJ(mesh, filePath);
                break;

            case MeshExportFormat.PLY:
                ExportPLY(mesh, filePath);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(format), format, null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Export an entire dream to a 3D format with textures.
        /// </summary>
        /// <param name="dream">The dream we're exporting.</param>
        /// <param name="combineChunks">Whether or not chunks should be combined into a single mesh.</param>
        /// <param name="exportFormat">The mesh format to export the level mesh in.</param>
        /// <param name="exportDirectory">The directory we're exporting meshes to.</param>
        public void ExportDream(Dream dream, bool combineChunks, MeshExportFormat exportFormat, string exportDirectory)
        {
            Log.Information($"Exporting dream to: {exportDirectory}");

            Log.Information($"Dream width: {dream.LevelWidth}");

            // create the directory
            Directory.CreateDirectory(exportDirectory);

            // combine tilelayouts of each LBDDocument into single renderables
            List <IRenderable> chunkRenderables = new List <IRenderable>();

            for (int i = 0; i < dream.Chunks.Count; i++)
            {
                Log.Information($"Processing dream chunk {i + 1}/{dream.Chunks.Count}...");

                var lbdChunk        = dream.Chunks[i];
                var chunkRenderable = HeadlessMesh.CombineMeshes(lbdChunk.TileLayout.ToArray());

                // position the LBD chunk based on tiling (if we're tiling)
                if (dream.LevelWidth > 0)
                {
                    int xPos = i % dream.LevelWidth;
                    int yPos = i / dream.LevelWidth;

                    // handle staggered tiling, every other row
                    int xMod = 0;
                    if (yPos % 2 == 1)
                    {
                        xMod = Dream.CHUNK_DIMENSION / 2; // stagger by half the width of a chunk
                    }

                    chunkRenderable.Transform.Position = new Vector3(xPos * Dream.CHUNK_DIMENSION - xMod, 0,
                                                                     yPos * Dream.CHUNK_DIMENSION);
                }

                chunkRenderables.Add(chunkRenderable);
            }

            string pathToLevel = Path.Combine(exportDirectory, "dream");

            if (combineChunks)
            {
                // if we're combining chunks, we now need to combine everything into a single renderable
                IRenderable dreamRenderable = HeadlessMesh.CombineMeshes(chunkRenderables.ToArray());
                ExportMesh(dreamRenderable, pathToLevel, exportFormat);
            }
            else
            {
                // otherwise we can export the list of chunk renderables
                ExportMeshes(chunkRenderables, pathToLevel, exportFormat);
            }

            // now, export each TIXDocument texture set as a combined VRAM export
            string pathToTextureSet = Path.Combine(exportDirectory, "textureset");

            string[] textureSetNames = { "-normal.png", "-kanji.png", "-downer.png", "-upper.png" };
            for (int i = 0; i < 4; i++)
            {
                Log.Information($"Exporting texture set {i + 1}/4...");
                var    textureSetTix = dream.TextureSets[i].Document;
                string exportPath    = pathToTextureSet + textureSetNames[i];
                ExportImages(textureSetTix, exportPath, separate: false, ImageFormat.Png);
            }

            Log.Information("Dream export complete");
        }