Program Listing for File ModelAssembly.ixx#
↰ Return to documentation for file (Src/GraphicsEngineVulkan/scene/ModelAssembly.ixx)
module;
#include <cstddef>
#include <memory>
#include <vector>
#include <vulkan/vulkan.hpp>
#include "spdlog/spdlog.h"
export module kataglyphis.vulkan.model_assembly;
import kataglyphis.vulkan.model;
import kataglyphis.vulkan.device;
import kataglyphis.vulkan.mesh_range;
import kataglyphis.vulkan.obj_material;
import kataglyphis.vulkan.vertex;
import kataglyphis.vulkan.texture;
import kataglyphis.vulkan.sampler_builder;
export namespace Kataglyphis {
bool uploadPreconditionsMet(const std::shared_ptr<VulkanDevice> &device,
std::size_t vertexCount,
const char *loaderName)
{
if (!device) {
spdlog::error("{}::uploadParsed called on a device-free loader", loaderName);
return false;
}
if (vertexCount == 0) {
spdlog::error("{}::uploadParsed called before a successful parseCpu", loaderName);
return false;
}
return true;
}
void addTextureOrDefault(Model &model,
const std::shared_ptr<VulkanDevice> &device,
vk::CommandPool pool,
bool created,
Texture &&texture,
GltfSamplerDesc samplerDesc = {})
{
if (created) {
model.addTexture(std::move(texture), samplerDesc);
return;
}
Texture defaultTexture;
if (!defaultTexture.createDefaultTexture(device, pool)) {
spdlog::error("Default texture upload failed; slot will hold an empty texture.");
}
model.addTexture(std::move(defaultTexture));
}
void ensureAtLeastOneTexture(Model &model, const std::shared_ptr<VulkanDevice> &device, vk::CommandPool pool)
{
if (model.getTextureCount() != 0) { return; }
Texture defaultTexture;
if (!defaultTexture.createDefaultTexture(device, pool)) {
spdlog::error("Default texture upload failed; slot will hold an empty texture.");
}
model.addTexture(std::move(defaultTexture));
}
void addMeshesForRanges(Model &model,
const std::shared_ptr<VulkanDevice> &device,
vk::CommandPool pool,
std::vector<Vertex> &vertices,
std::vector<unsigned int> &indices,
std::vector<unsigned int> &materialIndex,
std::vector<ObjMaterial> &materials,
const std::vector<MeshRange> &ranges)
{
if (ranges.empty()) {
model.add_new_mesh(device, pool, vertices, indices, materialIndex, materials);
return;
}
for (const MeshRange &range : ranges) {
MeshSlice slice = sliceMeshRange(range, vertices, indices, materialIndex);
model.add_new_mesh(
device, pool, slice.vertices, slice.indices, slice.materialIndex, materials, range.doubleSided);
}
}
}// namespace Kataglyphis