EditorMeshComponent.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 <AzFramework/Entity/EntityDebugDisplayBus.h>
  10. #include <AzToolsFramework/ToolsComponents/EditorVisibilityBus.h>
  11. #include <AzToolsFramework/API/ComponentEntitySelectionBus.h>
  12. #include <Atom/Feature/Utils/EditorRenderComponentAdapter.h>
  13. #include <AtomLyIntegration/CommonFeatures/Mesh/MeshComponentConstants.h>
  14. #include <Mesh/MeshComponent.h>
  15. #include <Mesh/EditorMeshStats.h>
  16. namespace AZ
  17. {
  18. namespace Render
  19. {
  20. /**
  21. * In-editor mesh component.
  22. * Conducts some additional listening and operations to ensure immediate
  23. * effects when changing fields in the editor.
  24. */
  25. class EditorMeshComponent final
  26. : public EditorRenderComponentAdapter<MeshComponentController, MeshComponent, MeshComponentConfig>
  27. , private AzToolsFramework::EditorComponentSelectionRequestsBus::Handler
  28. , private AzFramework::EntityDebugDisplayEventBus::Handler
  29. , private MeshComponentNotificationBus::Handler
  30. {
  31. public:
  32. using BaseClass = EditorRenderComponentAdapter<MeshComponentController, MeshComponent, MeshComponentConfig>;
  33. AZ_EDITOR_COMPONENT(AZ::Render::EditorMeshComponent, EditorMeshComponentTypeId, BaseClass);
  34. static void Reflect(AZ::ReflectContext* context);
  35. EditorMeshComponent() = default;
  36. explicit EditorMeshComponent(const MeshComponentConfig& config);
  37. // AZ::Component overrides ...
  38. void Activate() override;
  39. void Deactivate() override;
  40. /// Called when you want to change the game asset through code (like when creating components based on assets).
  41. void SetPrimaryAsset(const AZ::Data::AssetId& assetId) override;
  42. private:
  43. // EditorComponentSelectionRequestsBus overrides ...
  44. AZ::Aabb GetEditorSelectionBoundsViewport(const AzFramework::ViewportInfo& viewportInfo) override;
  45. bool EditorSelectionIntersectRayViewport(const AzFramework::ViewportInfo& viewportInfo, const AZ::Vector3& src, const AZ::Vector3& dir, float& distance) override;
  46. bool SupportsEditorRayIntersect() override;
  47. // EntityDebugDisplayEventBus overrides ...
  48. void DisplayEntityViewport(const AzFramework::ViewportInfo&, AzFramework::DebugDisplayRequests&) override;
  49. // MeshComponentNotificationBus overrides ...
  50. void OnModelReady(const Data::Asset<RPI::ModelAsset>& modelAsset, const Data::Instance<RPI::Model>& model) override;
  51. // AzToolsFramework::EditorEntityVisibilityNotificationBus::Handler overrides
  52. void OnEntityVisibilityChanged(bool visibility) override;
  53. // AzToolsFramework::Components::EditorComponentAdapter overrides
  54. bool ShouldActivateController() const override;
  55. AZ::u32 OnConfigurationChanged() override;
  56. AZ::Crc32 AddEditorMaterialComponent();
  57. bool HasEditorMaterialComponent() const;
  58. AZ::u32 GetEditorMaterialComponentVisibility() const;
  59. // Stats for current mesh asset
  60. EditorMeshStats m_stats;
  61. };
  62. } // namespace Render
  63. } // namespace AZ