public static string ExportScene() { var current = SaveLoadScript.m_Instance.SceneFile; string safeHumanName = FileUtils.SanitizeFilename(current.HumanName); string basename = FileUtils.SanitizeFilename( (current.Valid && (safeHumanName != "")) ? safeHumanName : "Untitled"); string parent = FileUtils.GenerateNonexistentFilename(App.UserExportPath(), basename, ""); if (!FileUtils.InitializeDirectoryWithUserError( parent, "Failed to create export directory")) { return(""); } // Set up progress bar. var progress = new Progress(); if (App.PlatformConfig.EnableExportJson) { progress.SetWork("json"); } #if FBX_SUPPORTED if (App.PlatformConfig.EnableExportFbx) { progress.SetWork("fbx"); } #endif #if USD_SUPPORTED if (App.PlatformConfig.EnableExportUsd) { progress.SetWork("usd"); } #endif #if (UNITY_EDITOR || EXPERIMENTAL_ENABLED) if (Config.IsExperimental) { progress.SetWork("wrl"); progress.SetWork("stl"); #if FBX_SUPPORTED progress.SetWork("obj"); #endif } #endif if (App.PlatformConfig.EnableExportGlb) { progress.SetWork("glb"); } string filename; if (App.PlatformConfig.EnableExportJson && (filename = MakeExportPath(parent, basename, "json")) != null) { using (var unused = new AutoTimer("raw export")) { OverlayManager.m_Instance.UpdateProgress(0.1f); ExportRaw.Export(filename); } } progress.CompleteWork("json"); #if FBX_SUPPORTED if (App.PlatformConfig.EnableExportFbx && (filename = MakeExportPath(parent, basename, "fbx")) != null) { using (var unused = new AutoTimer("fbx export")) { OverlayManager.m_Instance.UpdateProgress(0.3f); ExportFbx.Export(filename, App.UserConfig.Export.ExportBinaryFbx ? ExportFbx.kFbxBinary : ExportFbx.kFbxAscii, App.UserConfig.Export.ExportFbxVersion); OverlayManager.m_Instance.UpdateProgress(0.5f); } } progress.CompleteWork("fbx"); #endif #if USD_SUPPORTED if (App.PlatformConfig.EnableExportUsd && (filename = MakeExportPath(parent, basename, "usd")) != null) { using (var unused = new AutoTimer("usd export")) { ExportUsd.ExportPayload(filename); } } progress.CompleteWork("usd"); #endif #if (UNITY_EDITOR || EXPERIMENTAL_ENABLED) if (Config.IsExperimental && (filename = MakeExportPath(parent, basename, "wrl")) != null) { ExportVrml.Export(filename); progress.CompleteWork("wrl"); } if (Config.IsExperimental && (filename = MakeExportPath(parent, basename, "stl")) != null) { ExportStl.Export(filename); progress.CompleteWork("stl"); } #if FBX_SUPPORTED if (Config.IsExperimental && App.PlatformConfig.EnableExportFbx && (filename = MakeExportPath(parent, basename, "obj")) != null) { // This has never been tested with the new fbx export style and may not work ExportFbx.Export(filename, ExportFbx.kObj); progress.CompleteWork("obj"); } #endif #endif var results = new ExportGlTF.ExportResults(); if (App.PlatformConfig.EnableExportGlb) { string extension = App.Config.m_EnableGlbVersion2 ? "glb" : "glb1"; int gltfVersion = App.Config.m_EnableGlbVersion2 ? 2 : 1; filename = MakeExportPath(parent, basename, extension); if (filename != null) { using (var unused = new AutoTimer("glb export")) { OverlayManager.m_Instance.UpdateProgress(0.7f); var exporter = new ExportGlTF(); // TBT doesn't need (or want) brush textures in the output because it replaces all // the materials, so it's fine to keep those http:. However, Sketchfab doesn't support // http textures so if uploaded, this glb will have missing textures. results = exporter.ExportBrushStrokes( filename, AxisConvention.kGltf2, binary: true, doExtras: false, includeLocalMediaContent: true, gltfVersion: gltfVersion); progress.CompleteWork("glb"); } } } OutputWindowScript.m_Instance.CreateInfoCardAtController( InputManager.ControllerName.Brush, basename + " exported! Your download will begin in 5 seconds."); ControllerConsoleScript.m_Instance.AddNewLine("Located in " + App.UserExportPath()); string readmeFilename = Path.Combine(App.UserExportPath(), kExportReadmeName); if (!File.Exists(readmeFilename) && !Directory.Exists(readmeFilename)) { File.WriteAllText(readmeFilename, kExportReadmeBody); } return(results.exportedFiles[0]); }
private static void ExportEnvironments() { #if !GAMEOBJ_EXPORT_TO_GLTF Debug.LogError("Enable the define and fix up the code"); #else // Save the original RenderSettings Environment.RenderSettingsLite originalRenderSettings = Environment.GetRenderSettings(); // Clear out the existing environments directory to do a clean export string projectPath = Path.GetDirectoryName(Application.dataPath); string environmentExportPath = Path.Combine(projectPath, ExportUtils.kProjectRelativeEnvironmentExportRoot); try { Directory.Delete(environmentExportPath, recursive: true); } catch (DirectoryNotFoundException) { // It's okay if this directory doesn't exist yet as it will be created later. } // Clear out the existing textures directory to do a clean export string textureExportPath = Path.Combine(projectPath, ExportUtils.kProjectRelativeTextureExportRoot); try { Directory.Delete(textureExportPath, recursive: true); } catch (DirectoryNotFoundException) { // It's okay if this directory doesn't exist yet as it will be created later. } if (!FileUtils.InitializeDirectoryWithUserError( textureExportPath, "Failed to export, can't create texture export directory")) { return; } // Get the environment TiltBrushManifest manifest = AssetDatabase.LoadAssetAtPath <TiltBrushManifest>("Assets/Manifest.asset"); foreach (Environment env in manifest.Environments) { // Copy over the RenderSettings Environment.SetRenderSettings(env.m_RenderSettings); // Set up the environment string envGuid = env.m_Guid.ToString("D"); Debug.LogFormat("Exporting environment: {0}", env.m_RenderSettings.m_EnvironmentPrefab); GameObject envPrefab = Resources.Load <GameObject>(env.m_RenderSettings.m_EnvironmentPrefab); GameObject envGameObject = UObject.Instantiate(envPrefab); envGameObject.name = envGuid; // Hide game objects that don't get exported to Poly. foreach (Transform child in envGameObject.transform) { if (SceneSettings.ExcludeFromPolyExport(child)) { child.gameObject.SetActive(false); } } // Set up the environment export directory string directoryName = Path.Combine(environmentExportPath, envGuid); if (!FileUtils.InitializeDirectoryWithUserError( directoryName, "Failed to export, can't create environment export directory")) { return; } string basename = FileUtils.SanitizeFilename(envGameObject.name); string gltfName = Path.Combine(directoryName, basename + ".gltf"); var exporter = new ExportGlTF(); exporter.ExportGameObject(envGameObject, gltfName, env); // DestroyImmediate is required because editor mode never runs object garbage collection. UObject.DestroyImmediate(envGameObject); } // Restore the original RenderSettings Environment.SetRenderSettings(originalRenderSettings); #endif }