Esempio n. 1
0
        private ExportResults ExportHelper(
            SceneStatePayload payload,
            string outputFile,
            bool binary,
            bool doExtras,
            int gltfVersion,
            bool allowHttpUri)
        {
            // TODO: Ownership of this temp directory is sloppy.
            // Payload and export share the same dir and we assume that the exporter:
            // 1. will not write files whose names conflict with payload's
            // 2. will clean up the entire directory when done
            // This works, as long as the payload isn't used for more than one export (it currently isn't)
            using (var exporter = new GlTF_ScriptableExporter(payload.temporaryDirectory, gltfVersion))
            {
                exporter.AllowHttpUri = allowHttpUri;
                try
                {
                    m_exporter        = exporter;
                    exporter.G.binary = binary;

                    exporter.BeginExport(outputFile);
                    exporter.SetMetadata(payload.generator, copyright: null);
                    if (doExtras)
                    {
                        SetExtras(exporter, payload);
                    }

                    if (payload.env.skyCubemap != null)
                    {
                        // Add the skybox texture to the export.
                        string texturePath     = ExportUtils.GetTexturePath(payload.env.skyCubemap);
                        string textureFilename = Path.GetFileName(texturePath);
                        exporter.G.extras["TB_EnvironmentSkybox"] =
                            ExportFileReference.CreateLocal(texturePath, textureFilename);
                    }

                    WriteObjectsAndConnections(exporter, payload);

                    string[] exportedFiles = exporter.EndExport();
                    return(new ExportResults
                    {
                        success = true,
                        exportedFiles = exportedFiles,
                        numTris = exporter.NumTris
                    });
                }
                catch (InvalidOperationException e)
                {
                    OutputWindowScript.Error("glTF export failed", e.Message);
                    // TODO: anti-pattern. Let the exception bubble up so caller can log it properly
                    // Actually, InvalidOperationException is now somewhat expected in experimental, since
                    // the gltf exporter does not check IExportableMaterial.SupportsDetailedMaterialInfo.
                    // But we still want the logging for standalone builds.
                    Debug.LogException(e);
                    return(new ExportResults {
                        success = false
                    });
                }
                catch (IOException e)
                {
                    OutputWindowScript.Error("glTF export failed", e.Message);
                    return(new ExportResults {
                        success = false
                    });
                }
                finally
                {
                    payload.Destroy();
                    // The lifetime of ExportGlTF, GlTF_ScriptableExporter, and GlTF_Globals instances
                    // is identical. This is solely to be pedantic.
                    m_exporter = null;
                }
            }
        }