HierarchyExportTest.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // ***********************************************************************
  2. // Copyright (c) 2017 Unity Technologies. All rights reserved.
  3. //
  4. // Licensed under the ##LICENSENAME##.
  5. // See LICENSE.md file in the project root for full license information.
  6. // ***********************************************************************
  7. using NUnit.Framework;
  8. using System.Collections;
  9. using Autodesk.Fbx;
  10. namespace Autodesk.Fbx.UseCaseTests
  11. {
  12. public class HierarchyExportTest : RoundTripTestBase
  13. {
  14. [SetUp]
  15. public override void Init ()
  16. {
  17. fileNamePrefix = "_safe_to_delete__hierarchy_export_test_";
  18. base.Init ();
  19. }
  20. protected override FbxScene CreateScene (FbxManager manager)
  21. {
  22. // create the following node hierarchy to test:
  23. // Root
  24. // / \
  25. // Child0 Child1
  26. // |
  27. // Child2
  28. // / | \
  29. // Child3 Child4 Child5
  30. FbxScene scene = FbxScene.Create (manager, "myScene");
  31. FbxNode root = FbxNode.Create (scene, "Root");
  32. FbxNode[] children = new FbxNode[6];
  33. for (int i = 0; i < children.Length; i++) {
  34. children [i] = FbxNode.Create (scene, "Child" + i);
  35. }
  36. scene.GetRootNode ().AddChild (root);
  37. root.AddChild (children [0]);
  38. root.AddChild (children [1]);
  39. children [1].AddChild (children [2]);
  40. children [2].AddChild (children [3]);
  41. children [2].AddChild (children [4]);
  42. children [2].AddChild (children [5]);
  43. return scene;
  44. }
  45. protected override void CheckScene (FbxScene scene)
  46. {
  47. FbxScene origScene = CreateScene (FbxManager);
  48. // Compare the hierarchy of the two scenes
  49. FbxNode origRoot = origScene.GetRootNode();
  50. FbxNode importRoot = scene.GetRootNode ();
  51. CheckSceneHelper (origRoot, importRoot);
  52. }
  53. // compare the hierarchy of two nodes
  54. private void CheckSceneHelper(FbxNode node1, FbxNode node2)
  55. {
  56. if (node1 == null && node2 == null) {
  57. return;
  58. }
  59. Assert.IsNotNull (node1);
  60. Assert.IsNotNull (node2);
  61. Assert.AreEqual (node1.GetChildCount (), node2.GetChildCount ());
  62. Assert.AreEqual (node1.GetName (), node2.GetName ());
  63. for (int i = 0; i < node1.GetChildCount (); i++) {
  64. // recurse through the hierarchy
  65. CheckSceneHelper (node1.GetChild (i), node2.GetChild (i));
  66. }
  67. }
  68. }
  69. }