FbxTextureTest.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 Autodesk.Fbx;
  9. using System.Collections.Generic;
  10. namespace Autodesk.Fbx.UnitTests
  11. {
  12. public class FbxTextureTest : Base<FbxTexture>
  13. {
  14. public static void CommonTextureTests<T>(T tex) where T : FbxTexture
  15. {
  16. // get all the properties
  17. TestGetter(tex.Alpha);
  18. TestGetter(tex.WrapModeU);
  19. TestGetter(tex.WrapModeV);
  20. TestGetter(tex.UVSwap);
  21. TestGetter(tex.PremultiplyAlpha);
  22. TestGetter(tex.Translation);
  23. TestGetter(tex.Rotation);
  24. TestGetter(tex.Scaling);
  25. TestGetter(tex.RotationPivot);
  26. TestGetter(tex.ScalingPivot);
  27. TestGetter(tex.CurrentTextureBlendMode);
  28. TestGetter(tex.UVSet);
  29. // call all the functions
  30. tex.SetSwapUV(true);
  31. Assert.IsTrue(tex.GetSwapUV());
  32. tex.SetPremultiplyAlpha(true);
  33. Assert.IsTrue(tex.GetPremultiplyAlpha());
  34. tex.SetAlphaSource(FbxTexture.EAlphaSource.eRGBIntensity);
  35. Assert.AreEqual(FbxTexture.EAlphaSource.eRGBIntensity, tex.GetAlphaSource());
  36. tex.SetCropping(1, 2, 3, 4);
  37. Assert.AreEqual(1, tex.GetCroppingLeft());
  38. Assert.AreEqual(2, tex.GetCroppingTop());
  39. Assert.AreEqual(3, tex.GetCroppingRight());
  40. Assert.AreEqual(4, tex.GetCroppingBottom());
  41. tex.SetMappingType(FbxTexture.EMappingType.eSpherical);
  42. Assert.AreEqual(FbxTexture.EMappingType.eSpherical, tex.GetMappingType());
  43. tex.SetPlanarMappingNormal(FbxTexture.EPlanarMappingNormal.ePlanarNormalY);
  44. Assert.AreEqual(FbxTexture.EPlanarMappingNormal.ePlanarNormalY, tex.GetPlanarMappingNormal());
  45. tex.SetTextureUse(FbxTexture.ETextureUse.eShadowMap);
  46. Assert.AreEqual(FbxTexture.ETextureUse.eShadowMap, tex.GetTextureUse());
  47. tex.SetWrapMode(FbxTexture.EWrapMode.eRepeat, FbxTexture.EWrapMode.eClamp);
  48. Assert.AreEqual(FbxTexture.EWrapMode.eRepeat, tex.GetWrapModeU());
  49. Assert.AreEqual(FbxTexture.EWrapMode.eClamp, tex.GetWrapModeV());
  50. tex.SetBlendMode(FbxTexture.EBlendMode.eAdditive);
  51. Assert.AreEqual(FbxTexture.EBlendMode.eAdditive, tex.GetBlendMode());
  52. tex.SetDefaultAlpha(0.5);
  53. Assert.AreEqual(0.5, tex.GetDefaultAlpha());
  54. tex.SetTranslation(1, 2);
  55. Assert.AreEqual(1, tex.GetTranslationU());
  56. Assert.AreEqual(2, tex.GetTranslationV());
  57. tex.SetRotation(20, 30, 40);
  58. Assert.AreEqual(20, tex.GetRotationU());
  59. Assert.AreEqual(30, tex.GetRotationV());
  60. Assert.AreEqual(40, tex.GetRotationW());
  61. tex.SetRotation(20, 30);
  62. Assert.AreEqual(20, tex.GetRotationU());
  63. Assert.AreEqual(30, tex.GetRotationV());
  64. Assert.AreEqual(0, tex.GetRotationW());
  65. tex.SetScale(2, 3);
  66. Assert.AreEqual(2, tex.GetScaleU());
  67. Assert.AreEqual(3, tex.GetScaleV());
  68. tex.Reset();
  69. }
  70. [Test]
  71. public void TestBasics() {
  72. var tex = FbxTexture.Create(Manager, "tex");
  73. CommonTextureTests(tex);
  74. TestGetter(FbxTexture.sVectorSpace);
  75. TestGetter(FbxTexture.sVectorSpaceWorld);
  76. TestGetter(FbxTexture.sVectorSpaceObject);
  77. TestGetter(FbxTexture.sVectorSpaceTangent);
  78. TestGetter(FbxTexture.sVectorEncoding);
  79. TestGetter(FbxTexture.sVectorEncodingFP);
  80. TestGetter(FbxTexture.sVectorEncodingSE);
  81. }
  82. }
  83. public class FbxFileTextureTest : Base<FbxFileTexture>
  84. {
  85. [Test]
  86. public void TestBasics() {
  87. var tex = FbxFileTexture.Create(Manager, "tex");
  88. FbxTextureTest.CommonTextureTests(tex);
  89. TestGetter(tex.UseMaterial);
  90. TestGetter(tex.UseMipMap);
  91. tex.SetFileName("/a/b/c/d.png");
  92. Assert.AreEqual("/a/b/c/d.png", tex.GetFileName());
  93. tex.SetRelativeFileName("d.png");
  94. Assert.AreEqual("d.png", tex.GetRelativeFileName());
  95. tex.SetMaterialUse(FbxFileTexture.EMaterialUse.eDefaultMaterial);
  96. Assert.AreEqual(FbxFileTexture.EMaterialUse.eDefaultMaterial, tex.GetMaterialUse());
  97. }
  98. }
  99. }