initial commit-moved from vulkan_guide

This commit is contained in:
2025-10-10 22:53:54 +09:00
commit 8853429937
2484 changed files with 973414 additions and 0 deletions

72
src/scene/vk_loader.h Normal file
View File

@@ -0,0 +1,72 @@
// vulkan_engine.h : Include file for standard system include files,
// or project specific include files.
#pragma once
#include <core/vk_types.h>
#include "core/vk_descriptors.h"
#include <unordered_map>
#include <filesystem>
class VulkanEngine;
struct Bounds
{
glm::vec3 origin;
float sphereRadius;
glm::vec3 extents;
};
struct GLTFMaterial
{
MaterialInstance data;
};
struct GeoSurface
{
uint32_t startIndex;
uint32_t count;
Bounds bounds;
std::shared_ptr<GLTFMaterial> material;
};
struct MeshAsset
{
std::string name;
std::vector<GeoSurface> surfaces;
GPUMeshBuffers meshBuffers;
};
struct LoadedGLTF : public IRenderable
{
// storage for all the data on a given gltf file
std::unordered_map<std::string, std::shared_ptr<MeshAsset> > meshes;
std::unordered_map<std::string, std::shared_ptr<Node> > nodes;
std::unordered_map<std::string, AllocatedImage> images;
std::unordered_map<std::string, std::shared_ptr<GLTFMaterial> > materials;
// nodes that dont have a parent, for iterating through the file in tree order
std::vector<std::shared_ptr<Node> > topNodes;
std::vector<VkSampler> samplers;
DescriptorAllocatorGrowable descriptorPool;
AllocatedBuffer materialDataBuffer;
VulkanEngine *creator;
~LoadedGLTF() { clearAll(); };
void clearMeshes(){ clearAll(); };
virtual void Draw(const glm::mat4 &topMatrix, DrawContext &ctx);
private:
void clearAll();
};
std::optional<std::shared_ptr<LoadedGLTF> > loadGltf(VulkanEngine *engine, std::string_view filePath);