/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #pragma once #include #include #include #include #include #include #include namespace AZ::RPI { class ModelLodAsset; class ModelAsset; class Model; } // namespace AZ::RPI namespace WhiteBox { class WhiteBoxMeshAtomData; //! A concrete implementation of RenderMeshInterface to support Atom rendering for the White Box Tool. class AtomRenderMesh : public RenderMeshInterface { public: AZ_RTTI(AtomRenderMesh, "{1F48D2F5-037C-400B-977C-7C0C9A34B84C}", RenderMeshInterface); // RenderMeshInterface ... void BuildMesh( const WhiteBoxRenderData& renderData, const AZ::Transform& worldFromLocal, AZ::EntityId entityId) override; void UpdateTransform(const AZ::Transform& worldFromLocal) override; void UpdateMaterial(const WhiteBoxMaterial& material) override; bool IsVisible() const override; void SetVisiblity(bool visibility) override; private: //! Creates an attribute buffer in the slot dictated by AttributeTypeT. template void CreateAttributeBuffer(const AZStd::vector& data) { const auto attribute_index = static_cast(AttributeTypeT); m_attributes[attribute_index] = AZStd::make_unique>(data); } //! Updates an attribute buffer in the slot dictated by AttributeTypeT. template void UpdateAttributeBuffer(const AZStd::vector& data) { const auto attribute_index = static_cast(AttributeTypeT); auto& att = AZStd::get(m_attributes[attribute_index]); att->UpdateData(data); } bool CreateMeshBuffers(const WhiteBoxMeshAtomData& meshData); bool UpdateMeshBuffers(const WhiteBoxMeshAtomData& meshData); bool MeshRequiresFullRebuild(const WhiteBoxMeshAtomData& meshData) const; bool CreateMesh(const WhiteBoxMeshAtomData& meshData, AZ::EntityId entityId); bool CreateLodAsset(const WhiteBoxMeshAtomData& meshData); void CreateModelAsset(); bool CreateModel(AZ::EntityId entityId); void AddLodBuffers(AZ::RPI::ModelLodAssetCreator& modelLodCreator); void AddMeshBuffers(AZ::RPI::ModelLodAssetCreator& modelLodCreator); bool AreAttributesValid() const; bool DoesMeshRequireFullRebuild(const WhiteBoxMeshAtomData& meshData) const; AZ::Data::Asset m_lodAsset; AZ::Data::Asset m_modelAsset; AZ::Data::Instance m_model; AZ::Render::MeshFeatureProcessorInterface* m_meshFeatureProcessor = nullptr; AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_meshHandle; uint32_t m_vertexCount = 0; AZStd::unique_ptr m_indexBuffer; AZStd::array< AZStd::variant< AZStd::unique_ptr, AZStd::unique_ptr, AZStd::unique_ptr, AZStd::unique_ptr, AZStd::unique_ptr, AZStd::unique_ptr>, NumAttributes> m_attributes; //! Default white box mesh material. // TODO: LYN-784 static constexpr AZStd::string_view TexturedMaterialPath = "materials/defaultpbr.azmaterial"; static constexpr AZStd::string_view SolidMaterialPath = "materials/defaultpbr.azmaterial"; static constexpr AZ::RPI::ModelMaterialSlot::StableId OneMaterialSlotId = 0; //! White box model name. static constexpr AZStd::string_view ModelName = "WhiteBoxMesh"; }; } // namespace WhiteBox