// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Graphics module" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include #include #include #include #include #include #include namespace Nz { Model::Model(std::shared_ptr graphicalMesh, const Boxf& aabb) : m_graphicalMesh(std::move(graphicalMesh)) { m_submeshes.reserve(m_graphicalMesh->GetSubMeshCount()); for (std::size_t i = 0; i < m_graphicalMesh->GetSubMeshCount(); ++i) { auto& subMeshData = m_submeshes.emplace_back(); //subMeshData.material = DefaultMaterial; //< TODO subMeshData.vertexBufferData = { { 0, m_graphicalMesh->GetVertexDeclaration(i) } }; } UpdateAABB(aabb); } void Model::BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector>& elements, const Recti& scissorBox) const { for (std::size_t i = 0; i < m_submeshes.size(); ++i) { const auto& submeshData = m_submeshes[i]; const auto& materialPass = submeshData.material->GetPass(passIndex); if (!materialPass) continue; const auto& indexBuffer = m_graphicalMesh->GetIndexBuffer(i); const auto& vertexBuffer = m_graphicalMesh->GetVertexBuffer(i); const auto& renderPipeline = materialPass->GetPipeline()->GetRenderPipeline(submeshData.vertexBufferData); elements.emplace_back(std::make_unique(GetRenderLayer(), materialPass, renderPipeline, worldInstance, m_graphicalMesh->GetIndexCount(i), indexBuffer, vertexBuffer, scissorBox)); } } const std::shared_ptr& Model::GetIndexBuffer(std::size_t subMeshIndex) const { return m_graphicalMesh->GetIndexBuffer(subMeshIndex); } std::size_t Model::GetIndexCount(std::size_t subMeshIndex) const { return m_graphicalMesh->GetIndexCount(subMeshIndex); } const std::shared_ptr& Model::GetMaterial(std::size_t subMeshIndex) const { assert(subMeshIndex < m_submeshes.size()); const auto& subMeshData = m_submeshes[subMeshIndex]; return subMeshData.material; } std::size_t Model::GetMaterialCount() const { return m_submeshes.size(); } const std::vector& Model::GetVertexBufferData(std::size_t subMeshIndex) const { assert(subMeshIndex < m_submeshes.size()); const auto& subMeshData = m_submeshes[subMeshIndex]; return subMeshData.vertexBufferData; } const std::shared_ptr& Model::GetVertexBuffer(std::size_t subMeshIndex) const { return m_graphicalMesh->GetVertexBuffer(subMeshIndex); } }