public static void TraverseTest() { // // Setup a stage with parents and children. // TODO: Add tests with classes and instancing. // UsdStage s = UsdStage.CreateInMemory(); var foo = s.DefinePrim(new SdfPath("/Foo")); s.DefinePrim(new SdfPath("/Foo/P1")); s.DefinePrim(new SdfPath("/Foo/P2")); s.DefinePrim(new SdfPath("/Foo/P3")); s.DefinePrim(new SdfPath("/Foo/P4")); s.DefinePrim(new SdfPath("/Foo/P5")); var bar = s.DefinePrim(new SdfPath("/Bar")); s.DefinePrim(new SdfPath("/Bar/B1")); s.DefinePrim(new SdfPath("/Bar/B2")); s.DefinePrim(new SdfPath("/Bar/B3")); s.DefinePrim(new SdfPath("/Bar/B3/C1")); s.DefinePrim(new SdfPath("/Bar/B3/C2")); s.DefinePrim(new SdfPath("/Bar/B3/C3")); s.DefinePrim(new SdfPath("/Bar/B4")); // Prim children Console.WriteLine(""); Console.WriteLine("Foo children:"); foreach (UsdPrim curPrim in foo.GetChildren()) { Console.WriteLine(curPrim.GetPath()); } Console.WriteLine(""); Console.WriteLine("Bar children:"); foreach (UsdPrim curPrim in bar.GetChildren()) { Console.WriteLine(curPrim.GetPath()); } // Prim Descendants Console.WriteLine(""); Console.WriteLine("Bar descendants:"); foreach (UsdPrim curPrim in bar.GetDescendants()) { Console.WriteLine(curPrim.GetPath()); } // Basic Stage traversal. Console.WriteLine(""); Console.WriteLine("All Prims:"); List <UsdPrim> primList = s.Traverse().ToList(); int i = 0; foreach (UsdPrim curPrim in s.Traverse()) { Console.WriteLine(curPrim.GetPath()); AssertEqual(primList[i++], curPrim); } // Traversal with child pruning. Console.WriteLine(""); Console.WriteLine("/Bar children pruned:"); var range = new USD.NET.RangeIterator(s.Traverse()); foreach (UsdPrim curPrim in range) { Console.WriteLine(curPrim.GetPath()); if (curPrim.GetPath() == "/Bar/B3") { range.PruneChildren(); Console.WriteLine("pruned."); } } // Fully general pre/post traversal. Console.WriteLine(""); Console.WriteLine("Pre/Post Traversal with all children pruned:"); var prePostRange = new USD.NET.RangeIterator(UsdPrimRange.PreAndPostVisit(s.GetPseudoRoot())); bool[] expected = { false, false, true, false, true, true }; bool[] actual = new bool[6]; i = 0; foreach (UsdPrim curPrim in prePostRange) { Console.WriteLine("IsPostVisit: " + prePostRange.IsPostVisit().ToString() + ", " + curPrim.GetPath()); if (!prePostRange.IsPostVisit() && i > 0) { // It's only valid to prune on the pre-traversal. prePostRange.PruneChildren(); } actual[i++] = prePostRange.IsPostVisit(); } AssertEqual(expected, actual); }
public static void ApiTest() { UsdStage s = UsdStage.CreateInMemory(); var prim = s.DefinePrim(new SdfPath("/Foo")); s.SetStartTimeCode(1.0); s.SetEndTimeCode(10.0); AssertEqual(1.0, s.GetStartTimeCode()); AssertEqual(10.0, s.GetEndTimeCode()); var defultPrimToken = new TfToken("defaultPrim"); var value = new VtValue(); // Verify initial default prim / built-in metadata states. { AssertFalse(s.HasDefaultPrim()); AssertFalse(s.GetDefaultPrim().IsValid()); // defaultPrim is always valid metadata, it's built-in. AssertTrue(s.HasMetadata(defultPrimToken)); // But it should not yet have an *authored* value. AssertFalse(s.HasAuthoredMetadata(defultPrimToken)); // Even though it's not authored, reading it should succeed. AssertTrue(s.GetMetadata(defultPrimToken, value)); AssertEqual(((TfToken)value).ToString(), ""); } // Set the default prim, which should set the defaultPrim metadata. s.SetDefaultPrim(prim); { // Verify via the Stage API AssertTrue(s.HasDefaultPrim()); AssertTrue(s.GetDefaultPrim().IsValid()); AssertEqual(s.GetDefaultPrim().GetPath(), new SdfPath("/Foo")); // Verify via the metadata API AssertTrue(s.HasMetadata(defultPrimToken)); AssertTrue(s.HasAuthoredMetadata(defultPrimToken)); AssertTrue(s.GetMetadata(defultPrimToken, value)); AssertEqual(((TfToken)value).ToString(), "Foo"); } string str = s.GetRootLayer().ExportToString(); s.ClearDefaultPrim(); { AssertFalse(s.HasDefaultPrim()); AssertFalse(s.GetDefaultPrim().IsValid()); AssertFalse(s.HasAuthoredMetadata(defultPrimToken)); AssertTrue(s.GetMetadata(defultPrimToken, value)); AssertEqual(((TfToken)value).ToString(), ""); } var classPrim = s.CreateClassPrim(new SdfPath("/Foo_class_")); { AssertTrue(classPrim.IsValid()); AssertEqual(classPrim.GetPath(), new SdfPath("/Foo_class_")); } AssertEqual(s.GetFramesPerSecond(), 24.0); s.SetFramesPerSecond(90.0); AssertEqual(s.GetFramesPerSecond(), 90.0); }