Exemple #1
0
        public void CanWriteCustomData()
        {
            string usdFile = System.IO.Path.Combine(UnityEngine.Application.dataPath, "sceneFile.usda");

            filesToDelete.Add(usdFile);
            // Populate Values.
            var value = new MyCustomData();

            value.aString       = "IT'S ALIIIIIIIIIIIIIVE!";
            value.anArrayOfInts = new int[] { 1, 2, 3, 4 };
            value.aBoundingBox  = new UnityEngine.Bounds();

            // Writing the value.
            var scene = Scene.Create(usdFile);

            scene.Time = 1.0;
            scene.Write("/someValue", value);
            Debug.Log(scene.Stage.GetRootLayer().ExportToString());
            scene.Save();
            scene.Close();

            Assert.IsTrue(File.Exists(usdFile));

            // Reading the value.
            Debug.Log(usdFile);
            var newValue = new MyCustomData();

            scene      = Scene.Open(usdFile);
            scene.Time = 1.0;
            scene.Read("/someValue", newValue);

            Assert.AreEqual(value.aString, newValue.aString);

            scene.Close();
        }
        public void CanWriteCustomData()
        {
            // Populate Values.
            var value = new MyCustomData();

            value.aString       = "IT'S ALIIIIIIIIIIIIIVE!";
            value.anArrayOfInts = new int[] { 1, 2, 3, 4 };
            value.aBoundingBox  = new UnityEngine.Bounds();

            // Writing the value.
            string usdFile = CreateTmpUsdFile("sceneFile.usda");
            var    scene   = ImportHelpers.InitForOpen(usdFile);

            scene.Time = 1.0;
            scene.Write("/someValue", value);
            Debug.Log(scene.Stage.GetRootLayer().ExportToString());
            scene.Save();
            scene.Close();

            Assert.IsTrue(File.Exists(usdFile), "File not found.");

            // Reading the value.
            Debug.Log(usdFile);
            var newValue = new MyCustomData();

            scene      = Scene.Open(usdFile);
            scene.Time = 1.0;
            scene.Read("/someValue", newValue);

            Assert.AreEqual(value.aString, newValue.aString, "Serialized data don't match the original data.");

            scene.Close();
        }
Exemple #3
0
 public bool Load(string path)
 {
     if (!App.InitializeUsd())
     {
         return(false);
     }
     m_Scene = Scene.Open(path);
     return(m_Scene != null);
 }
Exemple #4
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);
        }