SkeletonModel.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. #pragma once
  9. #if !defined(Q_MOC_RUN)
  10. #include <EMotionFX/Source/Actor.h>
  11. #include <EMotionFX/Source/ActorInstance.h>
  12. #include <EMotionFX/Source/Node.h>
  13. #include <QtCore/QAbstractItemModel>
  14. #include <QtCore/QItemSelectionModel>
  15. #include <Editor/ActorEditorBus.h>
  16. #include <Editor/QtMetaTypes.h>
  17. #include <QIcon>
  18. #endif
  19. namespace EMotionFX
  20. {
  21. class Skeleton;
  22. // Skeleton model
  23. // Columns: Node Name
  24. class SkeletonModel
  25. : public QAbstractItemModel
  26. , private EMotionFX::ActorEditorNotificationBus::Handler
  27. {
  28. Q_OBJECT // AUTOMOC
  29. public:
  30. enum ColumnIndex
  31. {
  32. COLUMN_NAME,
  33. COLUMN_RAGDOLL_LIMIT,
  34. COLUMN_RAGDOLL_COLLIDERS,
  35. COLUMN_HITDETECTION_COLLIDERS,
  36. COLUMN_CLOTH_COLLIDERS,
  37. COLUMN_SIMULATED_JOINTS,
  38. COLUMN_SIMULATED_COLLIDERS
  39. };
  40. enum Role
  41. {
  42. ROLE_NODE_INDEX = Qt::UserRole,
  43. ROLE_POINTER,
  44. ROLE_ACTOR_POINTER,
  45. ROLE_ACTOR_INSTANCE_POINTER,
  46. ROLE_BONE,
  47. ROLE_HASMESH,
  48. ROLE_RAGDOLL,
  49. ROLE_HITDETECTION,
  50. ROLE_CLOTH,
  51. ROLE_SIMULATED_JOINT,
  52. ROLE_SIMULATED_OBJECT_COLLIDER,
  53. ROLE_IS_CHARACTER_ROOT_NODE,
  54. };
  55. SkeletonModel();
  56. ~SkeletonModel() override;
  57. QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
  58. QModelIndex parent(const QModelIndex& child) const override;
  59. int rowCount(const QModelIndex& parent = QModelIndex()) const override;
  60. int columnCount(const QModelIndex& parent = QModelIndex()) const override;
  61. QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
  62. QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
  63. Qt::ItemFlags flags(const QModelIndex& index) const override;
  64. bool setData(const QModelIndex& index, const QVariant& value, int role) override;
  65. QModelIndex GetModelIndex(Node* node) const;
  66. QModelIndexList GetModelIndicesForFullSkeleton() const;
  67. QItemSelectionModel& GetSelectionModel() { return m_selectionModel; }
  68. void SetCheckable(bool isCheckable);
  69. void ForEach(const AZStd::function<void(const QModelIndex& modelIndex)>& func);
  70. // ActorEditorNotificationBus overrides
  71. void ActorSelectionChanged(Actor* actor) override;
  72. void ActorInstanceSelectionChanged(EMotionFX::ActorInstance* actorInstance) override;
  73. Skeleton* GetSkeleton() const { return m_skeleton; }
  74. Actor* GetActor() const { return m_actor; }
  75. ActorInstance* GetActorInstance() const { return m_actorInstance; }
  76. static int s_defaultIconSize;
  77. static const char* s_jointIconPath;
  78. static const char* s_clothColliderIconPath;
  79. static const char* s_hitDetectionColliderIconPath;
  80. static const char* s_ragdollColliderIconPath;
  81. static const char* s_ragdollJointLimitIconPath;
  82. static const char* s_simulatedJointIconPath;
  83. static const char* s_simulatedColliderIconPath;
  84. static const char* s_characterIconPath;
  85. static bool IndexIsRootNode(const QModelIndex& idx);
  86. static bool IndicesContainRootNode(const QModelIndexList& indices);
  87. private:
  88. struct NodeInfo
  89. {
  90. bool m_hasMesh = false;
  91. bool m_isBone = false;
  92. bool m_checkable = false;
  93. Qt::CheckState m_checkState = Qt::Unchecked;
  94. };
  95. void SetActor(Actor* actor);
  96. void SetActorInstance(ActorInstance* actorInstance);
  97. void UpdateNodeInfos(Actor* actor);
  98. void Reset();
  99. NodeInfo& GetNodeInfo(const Node* node);
  100. const NodeInfo& GetNodeInfo(const Node* node) const;
  101. static int s_columnCount;
  102. AZStd::vector<NodeInfo> m_nodeInfos;
  103. Skeleton* m_skeleton;
  104. Actor* m_actor;
  105. ActorInstance* m_actorInstance;
  106. QItemSelectionModel m_selectionModel;
  107. Node* m_characterRootNode;
  108. QIcon m_jointIcon;
  109. QIcon m_clothColliderIcon;
  110. QIcon m_hitDetectionColliderIcon;
  111. QIcon m_ragdollColliderIcon;
  112. QIcon m_ragdollJointLimitIcon;
  113. QIcon m_simulatedJointIcon;
  114. QIcon m_simulatedColliderIcon;
  115. QIcon m_characterIcon;
  116. };
  117. } // namespace EMotionFX