InstancesExportTest.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.Generic;
  9. using Autodesk.Fbx;
  10. namespace Autodesk.Fbx.UseCaseTests
  11. {
  12. public class InstancesExportTest : TransformExportTest
  13. {
  14. protected string m_meshName = "shared mesh";
  15. protected string m_materialName = "shared material";
  16. protected override FbxScene CreateScene (FbxManager manager)
  17. {
  18. FbxScene scene = base.CreateScene (manager);
  19. // mesh shared by all instances
  20. FbxMesh sharedMesh = FbxMesh.Create (scene, m_meshName);
  21. FbxSurfaceMaterial sharedMaterial = FbxSurfacePhong.Create (scene, m_materialName);
  22. // add mesh to all nodes
  23. Queue<FbxNode> nodes = new Queue<FbxNode>();
  24. for (int i = 0; i < scene.GetRootNode ().GetChildCount (); i++) {
  25. nodes.Enqueue (scene.GetRootNode ().GetChild (i));
  26. }
  27. while (nodes.Count > 0) {
  28. FbxNode node = nodes.Dequeue ();
  29. node.SetNodeAttribute (sharedMesh);
  30. node.AddMaterial(sharedMaterial);
  31. for (int i = 0; i < node.GetChildCount (); i++) {
  32. nodes.Enqueue (node.GetChild (i));
  33. }
  34. }
  35. return scene;
  36. }
  37. protected override void CheckScene (FbxScene scene)
  38. {
  39. base.CheckScene (scene);
  40. FbxNode rootNode = scene.GetRootNode ().GetChild(0);
  41. Assert.IsNotNull (rootNode);
  42. FbxMesh sharedMesh = rootNode.GetMesh ();
  43. Assert.IsNotNull (sharedMesh);
  44. Assert.AreEqual (m_meshName, sharedMesh.GetName ());
  45. int matIndex = rootNode.GetMaterialIndex (m_materialName);
  46. Assert.GreaterOrEqual (matIndex, 0);
  47. FbxSurfaceMaterial sharedMat = rootNode.GetMaterial(matIndex);
  48. Assert.IsNotNull (sharedMat);
  49. // check that the mesh is the same for all children
  50. CheckSceneHelper (rootNode, sharedMesh, sharedMat);
  51. }
  52. private void CheckSceneHelper(FbxNode node, FbxMesh mesh, FbxSurfaceMaterial material)
  53. {
  54. if (node == null) {
  55. return;
  56. }
  57. Assert.AreEqual (mesh, node.GetMesh ());
  58. int matIndex = node.GetMaterialIndex (m_materialName);
  59. Assert.GreaterOrEqual (matIndex, 0);
  60. Assert.AreEqual (material, node.GetMaterial (matIndex));
  61. for (int i = 0; i < node.GetChildCount (); i++) {
  62. // recurse through the hierarchy
  63. CheckSceneHelper (node.GetChild (i), mesh, material);
  64. }
  65. }
  66. }
  67. }