3
0

DrawableMeshEntity.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 <Draw/EditorStateMeshDrawPacket.h>
  10. #include <Atom/RPI.Reflect/Model/ModelLodIndex.h>
  11. #include <AtomCore/Instance/Instance.h>
  12. #include <AtomLyIntegration/CommonFeatures/Mesh/MeshHandleStateBus.h>
  13. #include <AzCore/std/containers/vector.h>
  14. namespace AZ::Render
  15. {
  16. //! Representation of a focused entity's Atom mesh (if any).
  17. //! @note It is not an error for an entity to not have any Atom mesh.
  18. class DrawableMeshEntity
  19. : private AZ::Render::MeshHandleStateNotificationBus::Handler
  20. {
  21. public:
  22. DrawableMeshEntity(EntityId entityId, Data::Instance<RPI::Material> maskMaterial, Name drawList);
  23. ~DrawableMeshEntity();
  24. //! Returns true if this entity can be drawn, otherwise false.
  25. bool CanDraw() const;
  26. //! Draws the entity's Atom mesh.
  27. void Draw();
  28. private:
  29. //! Retrieves the levol of detail index for this entity's Atom mesh.
  30. RPI::ModelLodIndex GetModelLodIndex(const RPI::ViewPtr view, Data::Instance<RPI::Model> model) const;
  31. // MeshHandleStateNotificationBus overrides ...
  32. void OnMeshHandleSet(const MeshFeatureProcessorInterface::MeshHandle* meshHandle) override;
  33. //! Builds the entity's drawable mesh data from scratch, overwriting any existing data.
  34. void CreateOrUpdateMeshDrawPackets(
  35. const MeshFeatureProcessorInterface* featureProcessor,
  36. const RPI::ModelLodIndex modelLodIndex,
  37. Data::Instance<RPI::Model> model);
  38. //! Clears the entity's mesh draw packets and other draw state.
  39. void ClearDrawData();
  40. // Builds the mesh draw packets for the Atom mesh.
  41. void BuildMeshDrawPackets(
  42. const Data::Asset<RPI::ModelAsset> modelAsset, Data::Instance<RPI::ShaderResourceGroup> meshObjectSrg);
  43. // Creates the mask shader resource group for the Atom mesh.
  44. Data::Instance<RPI::ShaderResourceGroup> CreateMaskShaderResourceGroup(
  45. const MeshFeatureProcessorInterface* featureProcessor) const;
  46. EntityId m_entityId;
  47. const MeshFeatureProcessorInterface::MeshHandle* m_meshHandle = nullptr;
  48. Data::Instance<RPI::Material> m_maskMaterial = nullptr;
  49. Name m_drawList;
  50. RPI::ModelLodIndex m_modelLodIndex = RPI::ModelLodIndex::Null;
  51. AZStd::vector<EditorStateMeshDrawPacket> m_meshDrawPackets;
  52. };
  53. } // namespace AZ::Render