FbxLayerTest.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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.UnitTests
  11. {
  12. public class FbxLayerTest : TestBase<FbxLayer>
  13. {
  14. private FbxMesh m_fbxMesh;
  15. private FbxManager m_fbxManager;
  16. private FbxLayer m_fbxLayer;
  17. [SetUp]
  18. public void Init ()
  19. {
  20. m_fbxManager = FbxManager.Create ();
  21. m_fbxMesh = FbxMesh.Create (m_fbxManager, "");
  22. m_fbxLayer = m_fbxMesh.GetLayer (0);
  23. if (m_fbxLayer == null)
  24. {
  25. m_fbxMesh.CreateLayer ();
  26. m_fbxLayer = m_fbxMesh.GetLayer (0 /* default layer */);
  27. }
  28. }
  29. [TearDown]
  30. public void Term ()
  31. {
  32. m_fbxManager.Destroy ();
  33. }
  34. [Test]
  35. public void TestSetNormals ()
  36. {
  37. // make sure nothing crashes
  38. m_fbxLayer.SetNormals (FbxLayerElementNormal.Create (m_fbxMesh, ""));
  39. Assert.IsNotNull (m_fbxLayer.GetNormals ());
  40. // test null
  41. m_fbxLayer.SetNormals(null);
  42. Assert.IsNull (m_fbxLayer.GetNormals ());
  43. // test destroyed
  44. FbxLayerElementNormal normals = FbxLayerElementNormal.Create (m_fbxMesh, "");
  45. normals.Dispose ();
  46. m_fbxLayer.SetNormals (normals);
  47. }
  48. [Test]
  49. public void TestSetBinormals ()
  50. {
  51. // make sure nothing crashes
  52. m_fbxLayer.SetBinormals (FbxLayerElementBinormal.Create (m_fbxMesh, ""));
  53. Assert.IsNotNull (m_fbxLayer.GetBinormals ());
  54. // test null
  55. m_fbxLayer.SetBinormals(null);
  56. Assert.IsNull (m_fbxLayer.GetBinormals ());
  57. // test destroyed
  58. FbxLayerElementBinormal binormals = FbxLayerElementBinormal.Create (m_fbxMesh, "");
  59. binormals.Dispose ();
  60. m_fbxLayer.SetBinormals (binormals);
  61. }
  62. [Test]
  63. public void TestSetTangents ()
  64. {
  65. // make sure nothing crashes
  66. m_fbxLayer.SetTangents (FbxLayerElementTangent.Create (m_fbxMesh, ""));
  67. Assert.IsNotNull (m_fbxLayer.GetTangents ());
  68. // test null
  69. m_fbxLayer.SetTangents(null);
  70. Assert.IsNull (m_fbxLayer.GetTangents ());
  71. // test destroyed
  72. FbxLayerElementTangent tangents = FbxLayerElementTangent.Create (m_fbxMesh, "");
  73. tangents.Dispose ();
  74. m_fbxLayer.SetTangents (tangents);
  75. }
  76. [Test]
  77. public void TestSetVertexColors ()
  78. {
  79. // make sure nothing crashes
  80. m_fbxLayer.SetVertexColors (FbxLayerElementVertexColor.Create (m_fbxMesh, ""));
  81. Assert.IsNotNull (m_fbxLayer.GetVertexColors ());
  82. // test null
  83. m_fbxLayer.SetVertexColors(null);
  84. Assert.IsNull (m_fbxLayer.GetVertexColors ());
  85. // test destroyed
  86. FbxLayerElementVertexColor vertexColor = FbxLayerElementVertexColor.Create (m_fbxMesh, "");
  87. vertexColor.Dispose ();
  88. m_fbxLayer.SetVertexColors(vertexColor);
  89. }
  90. [Test]
  91. public void TestSetMaterials()
  92. {
  93. // make sure nothing crashes
  94. m_fbxLayer.SetMaterials(FbxLayerElementMaterial.Create (m_fbxMesh, ""));
  95. Assert.IsNotNull (m_fbxLayer.GetMaterials ());
  96. // test null
  97. m_fbxLayer.SetMaterials(null);
  98. Assert.IsNull (m_fbxLayer.GetMaterials ());
  99. // test destroyed
  100. FbxLayerElementMaterial material = FbxLayerElementMaterial.Create (m_fbxMesh, "");
  101. material.Dispose ();
  102. m_fbxLayer.SetMaterials(material);
  103. }
  104. [Test]
  105. public void TestSetUVs ()
  106. {
  107. // make sure nothing crashes
  108. m_fbxLayer.SetUVs (FbxLayerElementUV.Create (m_fbxMesh, ""));
  109. // test with type identifier
  110. m_fbxLayer.SetUVs(FbxLayerElementUV.Create (m_fbxMesh, ""), FbxLayerElement.EType.eEdgeCrease);
  111. // TODO: why does this return null?
  112. Assert.IsNull(m_fbxLayer.GetUVs(FbxLayerElement.EType.eEdgeCrease));
  113. // test null
  114. m_fbxLayer.SetUVs(null);
  115. Assert.IsNull (m_fbxLayer.GetUVs ());
  116. // test destroyed
  117. FbxLayerElementUV uvs = FbxLayerElementUV.Create (m_fbxMesh, "");
  118. uvs.Dispose ();
  119. m_fbxLayer.SetUVs (uvs);
  120. }
  121. [Test]
  122. public void TestDispose()
  123. {
  124. // make sure that calling SetNormals on a disposed layer throws
  125. m_fbxLayer.Dispose ();
  126. Assert.That(() => m_fbxLayer.SetNormals (FbxLayerElementNormal.Create(m_fbxMesh, "")),
  127. Throws.Exception.TypeOf<System.ArgumentNullException>());
  128. }
  129. /* Test all the equality functions we can find. */
  130. [Test]
  131. public void TestEquality() {
  132. var aIndex = m_fbxMesh.CreateLayer();
  133. var bIndex = m_fbxMesh.CreateLayer();
  134. var a = m_fbxMesh.GetLayer(aIndex);
  135. var b = m_fbxMesh.GetLayer(bIndex);
  136. var acopy = m_fbxMesh.GetLayer(aIndex);
  137. EqualityTester<FbxLayer>.TestEquality(a, b, acopy);
  138. }
  139. }
  140. }