更改更合适的宏定义文件名,重构gltfPrimitive

reconstruct-gltfLoader
InkSoul 2025-04-06 00:27:17 +08:00
parent 7f3056d2fe
commit 19bb71ee57
13 changed files with 244 additions and 62 deletions

View File

@ -9,20 +9,26 @@ set(MAIN_FILE
)
set(GLTF_MODEL_LOADER
"${PLUMAGE_RENDER}/glTFModel_Marco.h"
"${PLUMAGE_RENDER}/glTFModel_common.h"
"${PLUMAGE_RENDER}/glTFBoundingBox.h"
"${PLUMAGE_RENDER}/glTFBoundingBox.cpp"
"${PLUMAGE_RENDER}/glTFTexture.h"
"${PLUMAGE_RENDER}/glTFTexture.cpp"
"render/glTFModel.h"
"render/glTFModel.cpp"
)
"${PLUMAGE_RENDER}/glTFModel.h"
"${PLUMAGE_RENDER}/glTFModel.cpp"
"${PLUMAGE_RENDER}/glTFMaterial.h"
"${PLUMAGE_RENDER}/glTFMaterial.cpp"
"${PLUMAGE_RENDER}/glTFPrimitive.cpp"
"render/glTFPrimitive.h")
set(VULKAN_BASE
"render/VulkanBase_Common.h"
"render/VulkanDevice.h"
"render/VulkanDevice.cpp"
"render/VulkanTextureSampler.h"
"render/VulkanTextureSampler.cpp"
"${PLUMAGE_RENDER}/VulkanBase_Marco.h"
"${PLUMAGE_RENDER}/VulkanDevice.h"
"${PLUMAGE_RENDER}/VulkanDevice.cpp"
"${PLUMAGE_RENDER}/VulkanTextureSampler.h"
"${PLUMAGE_RENDER}/VulkanTextureSampler.cpp"
)
# wayland requires additional source files

View File

@ -1,7 +1,7 @@
#ifndef VULKANDEVICE_H
#define VULKANDEVICE_H
#include "VulkanBase_Common.h"
#include "VulkanBase_Marco.h"
#include <vulkan/vulkan.h>
#include <vector>

View File

@ -1,7 +1,7 @@
#ifndef VULKANTEXTURESAMPLER_H
#define VULKANTEXTURESAMPLER_H
#include "VulkanBase_Common.h"
#include "VulkanBase_Marco.h"
#include <vulkan/vulkan.h>

View File

@ -3,49 +3,56 @@
GLTFLOADER_NAMESPACE_BEGIN
glTFBoundingBOX::glTFBoundingBOX()
: m_isValid(false)
glTFBoundingBox::glTFBoundingBox()
: m_isValid(true)
, m_Min(glm::vec3(0,0,0))
, m_Max(glm::vec3(1,1,1))
{
}
glTFBoundingBOX::glTFBoundingBOX(glm::vec3 min, glm::vec3 max)
: m_isValid(false)
glTFBoundingBox::glTFBoundingBox(glm::vec3 min, glm::vec3 max)
: m_isValid(true)
, m_Min(min)
, m_Max(max)
{
}
glTFBoundingBOX::~glTFBoundingBOX()
glTFBoundingBox::~glTFBoundingBox()
{
}
glTFBoundingBOX glTFBoundingBOX::getAABB(glm::mat4 matrix)
glTFBoundingBox glTFBoundingBox::getAABB(glm::mat4 matrix)
{
glm::vec3 min = glm::vec3(matrix[3]);
glm::vec3 max = min;
glm::vec3 v0, v1;
glm::vec3 right = glm::vec3(matrix[0]);
v0 = right * m_Min.x;
v1 = right * m_Max.x;
v0 = right * m_min.x;
v1 = right * m_max.x;
min += glm::min(v0, v1);
max += glm::max(v0, v1);
glm::vec3 up = glm::vec3(matrix[1]);
v0 = up * m_Min.y;
v1 = up * m_Max.y;
v0 = up * m_min.y;
v1 = up * m_max.y;
min += glm::min(v0, v1);
max += glm::max(v0, v1);
glm::vec3 back = glm::vec3(matrix[2]);
v0 = back * m_Min.z;
v1 = back * m_Max.z;
v0 = back * m_min.z;
v1 = back * m_max.z;
min += glm::min(v0, v1);
max += glm::max(v0, v1);
return glTFBoundingBOX(min, max);
return glTFBoundingBox(min, max);
}
void glTFBoundingBox::setBoundingBox(glm::vec3 min, glm::vec3 max)
{
m_min = min;
m_max = max;
m_isValid = true;
}

View File

@ -1,24 +1,26 @@
#ifndef GLTFBOUNDINGBOX_H
#ifndef GLTFBOUNDINGBOX_H
#define GLTFBOUNDINGBOX_H
#include "glTFModel_Common.h"
#include <glm/glm.hpp>
#include "glTFModel_Marco.h"
#include <glm.hpp>
GLTFLOADER_NAMESPACE_BEGIN
class glTFBoundingBOX
class glTFBoundingBox
{
public:
glTFBoundingBOX();
glTFBoundingBOX(glm::vec3 min, glm::vec3 max);
~glTFBoundingBOX();
glTFBoundingBox();
glTFBoundingBox(glm::vec3 min, glm::vec3 max);
~glTFBoundingBox();
glTFBoundingBOX getAABB(glm::mat4 matrix);
glTFBoundingBox getAABB(glm::mat4 matrix);
void setBoundingBox(glm::vec3 min, glm::vec3 max);
private:
glm::vec3 m_Min;
glm::vec3 m_Max;
glm::vec3 m_min;
glm::vec3 m_max;
bool m_isValid = false;
};

View File

@ -0,0 +1,19 @@
#include "glTFMaterial.h"
GLTFLOADER_NAMESPACE_BEGIN
glTFMaterial::glTFMaterial()
{
}
glTFMaterial::~glTFMaterial()
{
}
GLTFLOADER_NAMESPACE_END

View File

@ -0,0 +1,62 @@
#ifndef GLTFMATERIAL_H
#define GLTFMATERIAL_H
#include "glTFModel_Marco.h"
#include "glTFModel_common.h"
#include "glTFTexture.h"
#include <glm.hpp>
GLTFLOADER_NAMESPACE_BEGIN
class glTFMaterial
{
public:
glTFMaterial();
~glTFMaterial();
private:
AlphaMode m_alphaMode = ALPHAMODE_OPAQUE;
float m_alphaCutoff = 1.0f;
float m_metallicFactor = 1.0f;
float m_roughnessFactor = 1.0f;
glm::vec4 m_baseColorFactor = glm::vec4(1.0f);
glm::vec4 m_emissiveFactor = glm::vec4(1.0f);
glTFTexture* m_baseColorTexture = nullptr;
glTFTexture* m_metallicRoughnessTexture = nullptr;
glTFTexture* m_normalTexture = nullptr;
glTFTexture* m_occlusionTexture = nullptr;
glTFTexture* m_emissiveTexture = nullptr;
bool m_doubleSided = false;
struct TexCoordSets {
uint8_t baseColor = 0;
uint8_t metallicRoughness = 0;
uint8_t specularGlossiness = 0;
uint8_t normal = 0;
uint8_t occlusion = 0;
uint8_t emissive = 0;
} m_texCoordSets;
struct Extension {
glTFTexture* specularGlossinessTexture = nullptr;
glTFTexture* diffuseTexture = nullptr;
glm::vec4 diffuseFactor = glm::vec4(1.0f);
glm::vec3 specularFactor = glm::vec3(0.0f);
} m_extension;
struct PbrWorkflows {
bool metallicRoughness = true;
bool specularGlossiness = false;
} m_pbrWorkflows;
VkDescriptorSet m_descriptorSet = VK_NULL_HANDLE;
};
GLTFLOADER_NAMESPACE_END
#endif // !GLTFMATERIAL_H

View File

@ -1,30 +1,22 @@
#pragma once
#ifndef GLTFMODEL_COMMON_H
#define GLTFMODEL_COMMON_H
/// 命名空间宏
#define GLTFLOADER_NAMESPACE_BEGIN namespace glTFLoader {
#define GLTFLOADER_NAMESPACE_END }
#include "glTFModel_Marco.h"
/// windows 导入导出宏GLTFLOADER_EXPORTS将在cmake中定义
/// unix-like 下提供符号可见性控制
#ifdef GLTFLOADER_STATIC_BUILD
#define GLTFLOADER_API
#define GLTFLOADER_LOCAL
#else
#ifdef _WIN32
#ifdef GLTFLOADER_EXPORTS
#define GLTFLOADER_API __declspec(dllexport)
#define GLTFLOADER_LOCAL
#else
#define GLTFLOADER_API __declspec(dllimport)
#define GLTFLOADER_LOCAL
#endif
#else
#if __GNUC__ >= 4 || defined(__clang__)
#define GLTFLOADER_API __attribute__ ((visibility ("default")))
#define GLTFLOADER_LOCAL __attribute__ ((visibility ("hidden")))
#else
#define GLTFLOADER_API
#define GLTFLOADER_LOCAL
#endif
#endif
#endif
GLTFLOADER_NAMESPACE_BEGIN
enum AlphaMode
{
ALPHAMODE_OPAQUE,
ALPHAMODE_MASK,
ALPHAMODE_BLEND
};
GLTFLOADER_NAMESPACE_END
#endif // !GLTFMODEL_COMMON_H

View File

@ -0,0 +1,30 @@
#pragma once
/// 命名空间宏
#define GLTFLOADER_NAMESPACE_BEGIN namespace glTFLoader {
#define GLTFLOADER_NAMESPACE_END }
/// windows 导入导出宏GLTFLOADER_EXPORTS将在cmake中定义
/// unix-like 下提供符号可见性控制
#ifdef GLTFLOADER_STATIC_BUILD
#define GLTFLOADER_API
#define GLTFLOADER_LOCAL
#else
#ifdef _WIN32
#ifdef GLTFLOADER_EXPORTS
#define GLTFLOADER_API __declspec(dllexport)
#define GLTFLOADER_LOCAL
#else
#define GLTFLOADER_API __declspec(dllimport)
#define GLTFLOADER_LOCAL
#endif
#else
#if __GNUC__ >= 4 || defined(__clang__)
#define GLTFLOADER_API __attribute__ ((visibility ("default")))
#define GLTFLOADER_LOCAL __attribute__ ((visibility ("hidden")))
#else
#define GLTFLOADER_API
#define GLTFLOADER_LOCAL
#endif
#endif
#endif

View File

@ -0,0 +1,25 @@
#include "glTFPrimitive.h"
GLTFLOADER_NAMESPACE_BEGIN
glTFPrimitive::glTFPrimitive(uint32_t firstIndex, uint32_t indexCount, uint32_t vertexCount, glTFMaterial& material)
:m_firstIndex(firstIndex)
,m_indexCount(indexCount)
,m_vertexCount(vertexCount)
,m_material(material)
{
m_hasIndices = indexCount > 0;
}
glTFPrimitive::~glTFPrimitive()
{
}
void glTFPrimitive::setBoundingBox(glm::vec3 min, glm::vec3 max)
{
m_boundingBox.setBoundingBox(min, max);
}
GLTFLOADER_NAMESPACE_END

View File

@ -0,0 +1,39 @@
#ifndef GLTFPRIMITIVE_H
#define GLTFPRIMITIVE_H
#include "glTFModel_Marco.h"
#include "glTFMaterial.h"
#include "glTFBoundingBox.h"
#include <glm.hpp>
#include <cstdint>
GLTFLOADER_NAMESPACE_BEGIN
class GLTFLOADER_API glTFPrimitive
{
public:
glTFPrimitive(uint32_t firstIndex, uint32_t indexCount, uint32_t vertexCount, glTFMaterial& material);
~glTFPrimitive();
void setBoundingBox(glm::vec3 min, glm::vec3 max);
private:
uint32_t m_firstIndex;
uint32_t m_indexCount;
uint32_t m_vertexCount;
glTFMaterial& m_material;
bool m_hasIndices;
glTFBoundingBox m_boundingBox;
};
GLTFLOADER_NAMESPACE_END
#endif // !GLTFPRIMITIVE_H

View File

@ -1,7 +1,7 @@
#ifndef GLTFTEXTURE_H
#define GLTFTEXTURE_H
#include "glTFModel_Common.h"
#include "glTFModel_Marco.h"
#include "VulkanDevice.h"
#include "VulkanTextureSampler.h"