// Copyright (C) 2024 Jérôme "SirLynix" 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 namespace Nz::Loaders { ModelLoader::Entry GetModelLoader_Mesh() { ModelLoader::Entry loaderEntry; loaderEntry.extensionSupport = [](std::string_view extension) { return Utility::Instance()->GetMeshLoader().IsExtensionSupported(extension); }; loaderEntry.streamLoader = [](Stream& stream, const ModelParams& parameters) -> Result, ResourceLoadingError> { std::shared_ptr mesh = Mesh::LoadFromStream(stream, parameters.mesh); if (!mesh) return Err(ResourceLoadingError::Unrecognized); if (parameters.meshCallback) { Result res = parameters.meshCallback(mesh); if (!res) return Err(res.GetError()); } std::shared_ptr gfxMesh = GraphicalMesh::BuildFromMesh(*mesh); if (!gfxMesh) return Err(ResourceLoadingError::Internal); std::shared_ptr model = std::make_shared(std::move(gfxMesh)); if (parameters.loadMaterials) { for (std::size_t matIndex = 0; matIndex < model->GetMaterialCount(); ++matIndex) { if (std::shared_ptr matInstance = MaterialInstance::Build(mesh->GetMaterialData(matIndex))) model->SetMaterial(matIndex, std::move(matInstance)); } } return model; }; loaderEntry.parameterFilter = [](const ModelParams& parameters) { if (auto result = parameters.custom.GetBooleanParameter("SkipNativeMeshLoader"); result.GetValueOr(false)) return false; return true; }; return loaderEntry; } }