EditorClothComponent.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #include <AzCore/std/containers/unordered_set.h>
  10. #include <AzToolsFramework/ToolsComponents/EditorComponentBase.h>
  11. #include <AtomLyIntegration/CommonFeatures/Mesh/MeshComponentBus.h>
  12. #include <Components/ClothConfiguration.h>
  13. namespace NvCloth
  14. {
  15. class ClothComponentMesh;
  16. //! Class for in-editor Cloth Component.
  17. class EditorClothComponent
  18. : public AzToolsFramework::Components::EditorComponentBase
  19. , public AZ::Render::MeshComponentNotificationBus::Handler
  20. {
  21. public:
  22. AZ_EDITOR_COMPONENT(EditorClothComponent, "{2C99B4EF-8A5F-4585-89F9-86D50754DF7E}", AzToolsFramework::Components::EditorComponentBase);
  23. static void Reflect(AZ::ReflectContext* context);
  24. EditorClothComponent();
  25. ~EditorClothComponent();
  26. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  27. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  28. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  29. const MeshNodeList& GetMeshNodeList() const;
  30. const AZStd::unordered_set<AZStd::string>& GetMeshNodesWithBackstopData() const;
  31. // EditorComponentBase overrides ...
  32. void BuildGameEntity(AZ::Entity* gameEntity) override;
  33. // AZ::Component overrides ...
  34. void Activate() override;
  35. void Deactivate() override;
  36. // AZ::Render::MeshComponentNotificationBus::Handler overrides ...
  37. void OnModelReady(const AZ::Data::Asset<AZ::RPI::ModelAsset>& modelAsset, const AZ::Data::Instance<AZ::RPI::Model>& model) override;
  38. void OnModelPreDestroy() override;
  39. private:
  40. bool IsSimulatedInEditor() const;
  41. AZ::u32 OnSimulatedInEditorToggled();
  42. void OnConfigurationChanged();
  43. bool ContainsBackstopData(AssetHelper* assetHelper, const AZStd::string& meshNode) const;
  44. void UpdateConfigMeshNodeData();
  45. ClothConfiguration m_config;
  46. AZStd::unique_ptr<ClothComponentMesh> m_clothComponentMesh;
  47. // List of mesh nodes from the asset that contains cloth data.
  48. // This list is not serialized, it's compiled when the asset has been received via MeshComponentNotificationBus.
  49. MeshNodeList m_meshNodeList;
  50. AZStd::string m_lastKnownMeshNode;
  51. AZStd::unordered_set<AZStd::string> m_meshNodesWithBackstopData;
  52. bool m_simulateInEditor = false;
  53. };
  54. } // namespace NvCloth