Beispiel #1
0
        /// <summary>
        /// Ensure each layer path is expressed in the USD sub layer stack of the given scene,
        /// creating the sublayer USD files if needed.
        /// </summary>
        public void SaveLayerStack(Scene scene, string[] layerStack)
        {
            if (scene == null)
            {
                throw new NullReferenceException("Null scene provided to SaveLayerStack");
            }

            SdfSubLayerProxy subLayers = scene.Stage.GetRootLayer().GetSubLayerPaths();

            for (int i = 0; i < m_layerStack.Length; i++)
            {
                string absoluteLayerPath = m_layerStack[i];
                string relativeLayerPath = ImporterBase.MakeRelativePath(scene.FilePath, absoluteLayerPath);
                if (!System.IO.File.Exists(absoluteLayerPath))
                {
                    var newSubLayer = Scene.Create(absoluteLayerPath);
                    SetupNewSubLayer(scene, newSubLayer);
                    newSubLayer.Save();
                    newSubLayer.Close();
                }

                if (subLayers.Count(relativeLayerPath) == 0)
                {
                    subLayers.push_back(relativeLayerPath);
                }
            }

            scene.Save();
        }
Beispiel #2
0
        public string CreateTmpUsdFile(string fileName)
        {
            var filePath = System.IO.Path.Combine(UnityEngine.Application.dataPath, fileName);
            var scene    = Scene.Create(filePath);

            scene.Save();
            scene.Close();
            m_filesToDelete.Add(filePath);
            return(filePath);
        }
Beispiel #3
0
        /// <summary>
        /// Writes overrides to the currently targeted subLayer.
        /// </summary>
        public void SaveToLayer()
        {
            var stageRoot = GetComponent <UsdAsset>();

            Scene subLayerScene = Scene.Create(m_targetLayer);

            if (subLayerScene == null)
            {
                throw new NullReferenceException("Could not create layer: " + m_targetLayer);
            }

            Scene rootScene = Scene.Open(stageRoot.usdFullPath);

            if (rootScene == null)
            {
                throw new NullReferenceException("Could not open base layer: " + stageRoot.usdFullPath);
            }

            SetupNewSubLayer(rootScene, subLayerScene);

            rootScene.Close();
            rootScene = null;

            try
            {
                SceneExporter.Export(stageRoot.gameObject,
                                     subLayerScene,
                                     stageRoot.m_changeHandedness,
                                     exportUnvarying: false,
                                     zeroRootTransform: false);
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
                return;
            }
            finally
            {
                if (subLayerScene != null)
                {
                    subLayerScene.Save();
                    subLayerScene.Close();
                    subLayerScene = null;
                }
            }
        }