FbxAnimCurveNodeTest.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 FbxAnimCurveNodeTest : Base<FbxAnimCurveNode>
  13. {
  14. [Test]
  15. public void TestBasics()
  16. {
  17. var scene = FbxScene.Create(Manager, "scene");
  18. var node = FbxNode.Create(scene, "node");
  19. /* Test all we can test with a non-composite curve node, namely one that points to
  20. a lcl translation. */
  21. var animNode = FbxAnimCurveNode.CreateTypedCurveNode(node.LclTranslation, scene);
  22. Assert.IsFalse(animNode.IsComposite());
  23. Assert.AreEqual(3, animNode.GetChannelsCount());
  24. Assert.AreEqual(0, animNode.GetChannelIndex(Globals.FBXSDK_CURVENODE_COMPONENT_X));
  25. Assert.AreEqual(Globals.FBXSDK_CURVENODE_COMPONENT_Y, animNode.GetChannelName(1));
  26. var xcurve = animNode.CreateCurve(animNode.GetName(), Globals.FBXSDK_CURVENODE_COMPONENT_X);
  27. Assert.IsNotNull(xcurve);
  28. var xcurve2 = animNode.CreateCurve(animNode.GetName());
  29. Assert.IsNotNull(xcurve2);
  30. var ycurve = animNode.CreateCurve(animNode.GetName(), 1);
  31. Assert.IsNotNull(ycurve);
  32. animNode.SetChannelValue(Globals.FBXSDK_CURVENODE_COMPONENT_Z, 6);
  33. Assert.AreEqual(6, animNode.GetChannelValue(Globals.FBXSDK_CURVENODE_COMPONENT_Z, 0));
  34. Assert.AreEqual(6, animNode.GetChannelValue(2, 0));
  35. animNode.SetChannelValue(2, 0);
  36. Assert.AreEqual(2, animNode.GetCurveCount(0));
  37. Assert.AreEqual(1, animNode.GetCurveCount(1, animNode.GetName()));
  38. Assert.AreEqual(xcurve, animNode.GetCurve(0));
  39. Assert.AreEqual(xcurve2, animNode.GetCurve(0,1));
  40. Assert.AreEqual(xcurve2, animNode.GetCurve(0, 1, animNode.GetName()));
  41. Assert.IsNull(animNode.GetCurve(1,1));
  42. var key = xcurve.KeyAdd(FbxTime.FromSecondDouble(0));
  43. xcurve.KeySet(key, FbxTime.FromSecondDouble(0), 5);
  44. key = xcurve.KeyAdd(FbxTime.FromSecondDouble(1));
  45. xcurve.KeySet(key, FbxTime.FromSecondDouble(1), -5);
  46. Assert.IsTrue(animNode.IsAnimated());
  47. /* TODO: build a composite anim node and test this for real. */
  48. Assert.IsTrue(animNode.IsAnimated(true));
  49. var timespan = new FbxTimeSpan();
  50. Assert.IsTrue(animNode.GetAnimationInterval(timespan));
  51. Assert.AreEqual(FbxTime.FromSecondDouble(0), timespan.GetStart());
  52. Assert.AreEqual(FbxTime.FromSecondDouble(1), timespan.GetStop());
  53. /* Get a property that isn't a Double3; add a channel for it. */
  54. var boolNode = FbxAnimCurveNode.CreateTypedCurveNode(node.VisibilityInheritance, scene);
  55. Assert.IsFalse(boolNode.IsComposite());
  56. Assert.IsFalse(boolNode.IsAnimated());
  57. Assert.IsTrue(boolNode.AddChannel("vis", 1));
  58. }
  59. }
  60. }