SimpleActors.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/std/smart_ptr/unique_ptr.h>
  9. #include <AzCore/std/string/conversions.h>
  10. #include <AzCore/std/typetraits/integral_constant.h>
  11. #include <EMotionFX/Source/Mesh.h>
  12. #include <EMotionFX/Source/Node.h>
  13. #include <MCore/Source/RefCounted.h>
  14. #include <Tests/TestAssetCode/SimpleActors.h>
  15. #include <Tests/TestAssetCode/MeshFactory.h>
  16. #include <numeric>
  17. namespace EMotionFX
  18. {
  19. SimpleJointChainActor::SimpleJointChainActor(size_t jointCount, const char* name)
  20. : Actor(name)
  21. {
  22. if (jointCount)
  23. {
  24. AddNode(0, "rootJoint");
  25. GetBindPose()->SetLocalSpaceTransform(0, Transform::CreateIdentity());
  26. }
  27. for (uint32 i = 1; i < jointCount; ++i)
  28. {
  29. AddNode(i, ("joint" + AZStd::to_string(i)).c_str(), i - 1);
  30. Transform transform = Transform::CreateIdentity();
  31. transform.m_position = AZ::Vector3(static_cast<float>(i), 0.0f, 0.0f);
  32. GetBindPose()->SetLocalSpaceTransform(i, transform);
  33. }
  34. }
  35. AllRootJointsActor::AllRootJointsActor(size_t jointCount, const char* name)
  36. : Actor(name)
  37. {
  38. for (uint32 i = 0; i < jointCount; ++i)
  39. {
  40. AddNode(i, ("rootJoint" + AZStd::to_string(i)).c_str());
  41. Transform transform = Transform::CreateIdentity();
  42. transform.m_position = AZ::Vector3(static_cast<float>(i), 0.0f, 0.0f);
  43. GetBindPose()->SetLocalSpaceTransform(i, transform);
  44. }
  45. }
  46. PlaneActor::PlaneActor(const char* name)
  47. : SimpleJointChainActor(1, name)
  48. {
  49. SetMesh(0, 0, CreatePlane({
  50. AZ::Vector3(-1.0f, -1.0f, 0.0f),
  51. AZ::Vector3(1.0f, -1.0f, 0.0f),
  52. AZ::Vector3(-1.0f, 1.0f, 0.0f),
  53. AZ::Vector3(1.0f, -1.0f, 0.0f),
  54. AZ::Vector3(-1.0f, 1.0f, 0.0f),
  55. AZ::Vector3(1.0f, 1.0f, 0.0f)
  56. }));
  57. }
  58. Mesh* PlaneActor::CreatePlane(const AZStd::vector<AZ::Vector3>& points) const
  59. {
  60. const auto vertCount = static_cast<uint32>(points.size());
  61. AZStd::vector<AZ::u32> indices(vertCount);
  62. std::iota(indices.begin(), indices.end(), 0);
  63. AZStd::vector<AZ::Vector3> normals {vertCount, {0.0f, 0.0f, 1.0f}};
  64. return EMotionFX::MeshFactory::Create(
  65. indices,
  66. points,
  67. normals
  68. );
  69. }
  70. PlaneActorWithJoints::PlaneActorWithJoints(size_t jointCount, const char* name)
  71. : PlaneActor(name)
  72. {
  73. for (uint32 i = 1; i < jointCount; ++i)
  74. {
  75. AddNode(i, ("joint" + AZStd::to_string(i)).c_str(), i - 1);
  76. Transform transform = Transform::CreateIdentity();
  77. transform.m_position = AZ::Vector3(static_cast<float>(i), 0.0f, 0.0f);
  78. GetBindPose()->SetLocalSpaceTransform(i, transform);
  79. }
  80. }
  81. } // namespace EMotionFX