コード例 #1
0
        /// Starts recording the transform to a named transform in a new usd file given by the path.
        public bool StartRecording(string path, string sketchName = "/Sketch", string xformName = "/VideoCamera")
        {
            m_xformName = sketchName + xformName;
            if (!InitUsd.Initialize() || string.IsNullOrEmpty(path))
            {
                return(false);
            }

            // Find the active camera.
            m_RecordingCamera = null;
            foreach (var c in GetComponentsInChildren <Camera>())
            {
                if (c.gameObject.activeInHierarchy && c.isActiveAndEnabled)
                {
                    m_RecordingCamera = c;
                }
            }
            if (m_RecordingCamera == null)
            {
                return(false);
            }

            var sketchRoot = ExportUsd.CreateSketchRoot();

            m_UsdCamera = new UsdCameraXformSample();
            try
            {
                m_Scene = USD.NET.Scene.Create(path);
            }
            catch (ApplicationException /*e*/)
            {
                Debug.LogError("Error creating usda file!");
                return(false);
            }

            m_Scene.Write(sketchName, sketchRoot);

            // The time code of the recording is in seconds.
            m_Scene.Stage.SetTimeCodesPerSecond(1);

            // CameraSample constructor converts the Unity Camera to USD.
            // Write the fallback camera parameters.
            var cameraSample = new UsdCameraSample(m_RecordingCamera);

            // Convert camera params to meters.
            cameraSample.clippingRange *= App.UNITS_TO_METERS;

            m_Scene.Write(m_xformName, cameraSample);

            m_Scene.Time      = 0;
            m_Scene.StartTime = 0;
            m_Scene.EndTime   = 0;

            m_IsRecording = true;
            return(true);
        }
コード例 #2
0
        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]);
        }