diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3cef7ac..15d650c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/render/VulkanBase_Common.h b/src/render/VulkanBase_Marco.h similarity index 100% rename from src/render/VulkanBase_Common.h rename to src/render/VulkanBase_Marco.h diff --git a/src/render/VulkanDevice.h b/src/render/VulkanDevice.h index be86484..68a0c88 100644 --- a/src/render/VulkanDevice.h +++ b/src/render/VulkanDevice.h @@ -1,7 +1,7 @@ #ifndef VULKANDEVICE_H #define VULKANDEVICE_H -#include "VulkanBase_Common.h" +#include "VulkanBase_Marco.h" #include #include diff --git a/src/render/VulkanTextureSampler.h b/src/render/VulkanTextureSampler.h index 7eb6956..e5b877e 100644 --- a/src/render/VulkanTextureSampler.h +++ b/src/render/VulkanTextureSampler.h @@ -1,7 +1,7 @@ #ifndef VULKANTEXTURESAMPLER_H #define VULKANTEXTURESAMPLER_H -#include "VulkanBase_Common.h" +#include "VulkanBase_Marco.h" #include diff --git a/src/render/glTFBoundingBox.cpp b/src/render/glTFBoundingBox.cpp index 425e71f..1f864f1 100644 --- a/src/render/glTFBoundingBox.cpp +++ b/src/render/glTFBoundingBox.cpp @@ -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; } diff --git a/src/render/glTFBoundingBox.h b/src/render/glTFBoundingBox.h index 657a692..f5b98a6 100644 --- a/src/render/glTFBoundingBox.h +++ b/src/render/glTFBoundingBox.h @@ -1,24 +1,26 @@ -#ifndef GLTFBOUNDINGBOX_H +#ifndef GLTFBOUNDINGBOX_H #define GLTFBOUNDINGBOX_H -#include "glTFModel_Common.h" -#include +#include "glTFModel_Marco.h" +#include 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; }; diff --git a/src/render/glTFMaterial.cpp b/src/render/glTFMaterial.cpp new file mode 100644 index 0000000..34d5053 --- /dev/null +++ b/src/render/glTFMaterial.cpp @@ -0,0 +1,19 @@ +#include "glTFMaterial.h" + + +GLTFLOADER_NAMESPACE_BEGIN + +glTFMaterial::glTFMaterial() +{ +} + +glTFMaterial::~glTFMaterial() +{ +} + + + + + + +GLTFLOADER_NAMESPACE_END \ No newline at end of file diff --git a/src/render/glTFMaterial.h b/src/render/glTFMaterial.h new file mode 100644 index 0000000..e467119 --- /dev/null +++ b/src/render/glTFMaterial.h @@ -0,0 +1,62 @@ +#ifndef GLTFMATERIAL_H +#define GLTFMATERIAL_H + +#include "glTFModel_Marco.h" + +#include "glTFModel_common.h" + +#include "glTFTexture.h" + +#include + +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 diff --git a/src/render/glTFModel_Common.h b/src/render/glTFModel_Common.h index dfe4d56..72c520f 100644 --- a/src/render/glTFModel_Common.h +++ b/src/render/glTFModel_Common.h @@ -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 \ No newline at end of file +GLTFLOADER_NAMESPACE_BEGIN + +enum AlphaMode +{ + ALPHAMODE_OPAQUE, + ALPHAMODE_MASK, + ALPHAMODE_BLEND +}; + + + +GLTFLOADER_NAMESPACE_END + + + + +#endif // !GLTFMODEL_COMMON_H diff --git a/src/render/glTFModel_Marco.h b/src/render/glTFModel_Marco.h new file mode 100644 index 0000000..dfe4d56 --- /dev/null +++ b/src/render/glTFModel_Marco.h @@ -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 \ No newline at end of file diff --git a/src/render/glTFPrimitive.cpp b/src/render/glTFPrimitive.cpp new file mode 100644 index 0000000..c1e3571 --- /dev/null +++ b/src/render/glTFPrimitive.cpp @@ -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 \ No newline at end of file diff --git a/src/render/glTFPrimitive.h b/src/render/glTFPrimitive.h new file mode 100644 index 0000000..9505e7e --- /dev/null +++ b/src/render/glTFPrimitive.h @@ -0,0 +1,39 @@ +#ifndef GLTFPRIMITIVE_H +#define GLTFPRIMITIVE_H + +#include "glTFModel_Marco.h" + +#include "glTFMaterial.h" +#include "glTFBoundingBox.h" + +#include +#include + +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 diff --git a/src/render/glTFTexture.h b/src/render/glTFTexture.h index e4f6953..19680ec 100644 --- a/src/render/glTFTexture.h +++ b/src/render/glTFTexture.h @@ -1,7 +1,7 @@ #ifndef GLTFTEXTURE_H #define GLTFTEXTURE_H -#include "glTFModel_Common.h" +#include "glTFModel_Marco.h" #include "VulkanDevice.h" #include "VulkanTextureSampler.h"