FbxGeometryBaseTest.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 FbxGeometryBaseTestBase<T> : FbxLayerContainerBase<T> where T : FbxGeometryBase
  13. {
  14. override public void TestBasics(T geometryBase, FbxNodeAttribute.EType typ)
  15. {
  16. base.TestBasics(geometryBase, typ);
  17. geometryBase.InitControlPoints (24);
  18. Assert.AreEqual (geometryBase.GetControlPointsCount (), 24);
  19. geometryBase.SetControlPointAt(new FbxVector4(1,2,3,4), 0);
  20. Assert.AreEqual(new FbxVector4(1,2,3,4), geometryBase.GetControlPointAt(0));
  21. int layerId0 = geometryBase.CreateLayer();
  22. int layerId1 = geometryBase.CreateLayer();
  23. var layer0 = geometryBase.GetLayer(layerId0);
  24. var layer1 = geometryBase.GetLayer(layerId1);
  25. Assert.AreNotEqual(layer0, layer1);
  26. // Fbx crashes setting a negative control point index, so we do some testing:
  27. Assert.That (() => geometryBase.SetControlPointAt (new FbxVector4(), -1), Throws.Exception.TypeOf<System.ArgumentOutOfRangeException>());
  28. // It doesn't crash with past-the-end, it resizes; make sure we don't block that.
  29. geometryBase.SetControlPointAt (new FbxVector4(1,2,3,4), 50); // does not throw
  30. Assert.AreEqual (geometryBase.GetControlPointsCount (), 51);
  31. // Out of bounds returns FbxVector4(0,0,0). FBX code crashes with
  32. // index < 0. Don't crash and return the documented value
  33. Assert.That( geometryBase.GetControlPointAt(-1), Is.EqualTo(new FbxVector4(0,0,0)));
  34. geometryBase.GetControlPointAt(geometryBase.GetControlPointsCount() + 1);
  35. var elementNormal = geometryBase.CreateElementNormal ();
  36. Assert.IsInstanceOf<FbxLayerElementNormal> (elementNormal);
  37. var elementTangent = geometryBase.CreateElementTangent ();
  38. Assert.IsInstanceOf<FbxLayerElementTangent> (elementTangent);
  39. }
  40. }
  41. public class FbxGeometryBaseTest : FbxGeometryBaseTestBase<FbxGeometryBase> {
  42. [Test]
  43. public void TestBasics()
  44. {
  45. base.TestBasics(CreateObject("geometry base"), FbxNodeAttribute.EType.eUnknown);
  46. // You can even initialize to a negative number of control points:
  47. using (FbxGeometryBase geometryBase2 = CreateObject ("geometry base")) {
  48. // make sure this doesn't crash
  49. geometryBase2.InitControlPoints (-1);
  50. }
  51. }
  52. }
  53. public class FbxGeometryTestBase<T> : FbxGeometryBaseTestBase<T> where T : FbxGeometry
  54. {
  55. override public void TestBasics(T fbxGeometry, FbxNodeAttribute.EType typ)
  56. {
  57. base.TestBasics(fbxGeometry, typ);
  58. int origCount = fbxGeometry.GetDeformerCount ();
  59. // test get blendshape deformer
  60. FbxBlendShape blendShape = FbxBlendShape.Create (Manager, "blendShape");
  61. int index = fbxGeometry.AddDeformer (blendShape);
  62. Assert.GreaterOrEqual (index, 0);
  63. origCount++;
  64. // TODO: (UNI-19581): If we add the blendShape after the skin, then the below
  65. // tests fail.
  66. Assert.AreEqual (blendShape, fbxGeometry.GetBlendShapeDeformer (index));
  67. Assert.AreEqual (blendShape, fbxGeometry.GetBlendShapeDeformer (index, null));
  68. Assert.AreEqual (blendShape, fbxGeometry.GetDeformer (index, FbxDeformer.EDeformerType.eBlendShape));
  69. Assert.AreEqual (1, fbxGeometry.GetDeformerCount (FbxDeformer.EDeformerType.eBlendShape));
  70. // test add deformer
  71. FbxSkin skin = FbxSkin.Create (Manager, "skin");
  72. int skinIndex = fbxGeometry.AddDeformer (skin);
  73. Assert.GreaterOrEqual (skinIndex, 0);
  74. Assert.AreEqual(skin, fbxGeometry.GetDeformer(skinIndex));
  75. // test get invalid deformer index doesn't crash
  76. fbxGeometry.GetDeformer(-1, new FbxStatus());
  77. fbxGeometry.GetDeformer(int.MaxValue, new FbxStatus());
  78. // test get deformer null FbxStatus
  79. fbxGeometry.GetDeformer(0, null);
  80. // check right index but wrong type
  81. Assert.IsNull (fbxGeometry.GetDeformer (skinIndex, FbxDeformer.EDeformerType.eVertexCache, null));
  82. Assert.AreEqual (origCount+1, fbxGeometry.GetDeformerCount ());
  83. // test add null deformer
  84. Assert.That (() => fbxGeometry.AddDeformer(null), Throws.Exception.TypeOf<System.ArgumentNullException>());
  85. // test add invalid deformer
  86. skin.Destroy();
  87. Assert.That (() => fbxGeometry.AddDeformer(skin), Throws.Exception.TypeOf<System.ArgumentNullException>());
  88. }
  89. }
  90. public class FbxGeometryTest : FbxGeometryTestBase<FbxGeometry>
  91. {
  92. [Test]
  93. public void TestBasics()
  94. {
  95. base.TestBasics(CreateObject ("geometry"), FbxNodeAttribute.EType.eUnknown);
  96. }
  97. }
  98. public class FbxShapeTest : FbxGeometryBaseTestBase<FbxShape>
  99. {
  100. [Test]
  101. public void TestBasics()
  102. {
  103. base.TestBasics(CreateObject ("shape"), FbxNodeAttribute.EType.eShape);
  104. }
  105. }
  106. }