summaryrefslogtreecommitdiffstats
path: root/AssetLoader
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2021-03-27 09:12:40 +0000
committers-ol <s+removethis@s-ol.nu>2021-03-30 14:37:36 +0000
commit1b66dcfa8bd1f2deddb3e406653a3553c5549bf5 (patch)
treef29514aa4b05bad3a6ab1949549b2831102d28fd /AssetLoader
parentGLTF Loader: fixed default alpha channel value of 3-component textures (diff)
downloadDiligentTools-1b66dcfa8bd1f2deddb3e406653a3553c5549bf5.tar.gz
DiligentTools-1b66dcfa8bd1f2deddb3e406653a3553c5549bf5.zip
C API for GLTFLoader
Diffstat (limited to 'AssetLoader')
-rw-r--r--AssetLoader/CMakeLists.txt4
-rw-r--r--AssetLoader/include/GLTFLoader.hpp (renamed from AssetLoader/interface/GLTFLoader.hpp)139
-rw-r--r--AssetLoader/include/GLTFResourceManager.hpp (renamed from AssetLoader/interface/GLTFResourceManager.hpp)0
-rw-r--r--AssetLoader/interface/GLTFLoader.h178
-rw-r--r--AssetLoader/src/GLTFLoader.cpp75
5 files changed, 263 insertions, 133 deletions
diff --git a/AssetLoader/CMakeLists.txt b/AssetLoader/CMakeLists.txt
index 52b8694..fd4bf7b 100644
--- a/AssetLoader/CMakeLists.txt
+++ b/AssetLoader/CMakeLists.txt
@@ -4,12 +4,12 @@ project(Diligent-AssetLoader CXX)
set(INCLUDE
#include/GLTFLoader.hpp
+ #include/GLTFResourceManager.hpp
)
set(INTERFACE
- interface/GLTFLoader.hpp
+ interface/GLTFLoader.h
interface/DXSDKMeshLoader.hpp
- interface/GLTFResourceManager.hpp
)
set(SOURCE
diff --git a/AssetLoader/interface/GLTFLoader.hpp b/AssetLoader/include/GLTFLoader.hpp
index 3547775..83b9a4d 100644
--- a/AssetLoader/interface/GLTFLoader.hpp
+++ b/AssetLoader/include/GLTFLoader.hpp
@@ -39,6 +39,7 @@
#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/DeviceContext.h"
#include "../../../DiligentCore/Common/interface/RefCntAutoPtr.hpp"
#include "../../../DiligentCore/Common/interface/AdvancedMath.hpp"
+#include "GLTFLoader.h"
#include "GLTFResourceManager.hpp"
namespace tinygltf
@@ -55,33 +56,6 @@ namespace Diligent
namespace GLTF
{
-struct ResourceCacheUseInfo
-{
- ResourceManager* pResourceMgr = nullptr;
-
- Uint8 IndexBufferIdx = 0;
- Uint8 VertexBuffer0Idx = 0;
- Uint8 VertexBuffer1Idx = 0;
-
- /// Base color texture format.
- TEXTURE_FORMAT BaseColorFormat = TEX_FORMAT_RGBA8_UNORM;
-
- /// Base color texture format for alpha-cut and alpha-blend materials.
- TEXTURE_FORMAT BaseColorAlphaFormat = TEX_FORMAT_RGBA8_UNORM;
-
- /// Physical descriptor texture format.
- TEXTURE_FORMAT PhysicalDescFormat = TEX_FORMAT_RGBA8_UNORM;
-
- /// Normal map format.
- TEXTURE_FORMAT NormalFormat = TEX_FORMAT_RGBA8_UNORM;
-
- /// Occlusion texture format.
- TEXTURE_FORMAT OcclusionFormat = TEX_FORMAT_RGBA8_UNORM;
-
- /// Emissive texture format.
- TEXTURE_FORMAT EmissiveFormat = TEX_FORMAT_RGBA8_UNORM;
-};
-
struct Material
{
Material() noexcept
@@ -95,14 +69,6 @@ struct Material
PBR_WORKFLOW_SPEC_GLOSS
};
- enum ALPHA_MODE
- {
- ALPHA_MODE_OPAQUE = 0,
- ALPHA_MODE_MASK,
- ALPHA_MODE_BLEND,
- ALPHA_MODE_NUM_MODES
- };
-
// Material attributes packed in a shader-friendly format
struct ShaderAttribs
{
@@ -126,7 +92,7 @@ struct Material
float MetallicFactor = 1;
float RoughnessFactor = 1;
- int AlphaMode = ALPHA_MODE_OPAQUE;
+ int AlphaMode = GLTF_MAT_ALPHA_MODE_OPAQUE;
float AlphaCutoff = 0.5f;
float Dummy0;
@@ -327,9 +293,16 @@ struct Animation
float End = std::numeric_limits<float>::min();
};
+struct GLTF_TextureCacheType
+{
+ std::mutex TexturesMtx;
-struct Model
+ std::unordered_map<std::string, RefCntWeakPtr<ITexture>> Textures;
+};
+
+class Model : public IGLTFModel
{
+public:
struct VertexBasicAttribs
{
float3 pos;
@@ -344,14 +317,6 @@ struct Model
float4 weight0;
};
- enum BUFFER_ID
- {
- BUFFER_ID_VERTEX_BASIC_ATTRIBS = 0,
- BUFFER_ID_VERTEX_SKIN_ATTRIBS,
- BUFFER_ID_INDEX,
- BUFFER_ID_NUM_BUFFERS
- };
-
Uint32 IndexCount = 0;
/// Transformation matrix that transforms unit cube [0,1]x[0,1]x[0,1] into
@@ -374,76 +339,36 @@ struct Model
float3 max = float3{-FLT_MAX, -FLT_MAX, -FLT_MAX};
} dimensions;
- struct TextureCacheType
- {
- std::mutex TexturesMtx;
-
- std::unordered_map<std::string, RefCntWeakPtr<ITexture>> Textures;
- };
-
- /// Model create information
- struct CreateInfo
- {
- /// File name
- const char* FileName = nullptr;
-
- /// Optional texture cache to use when loading the model.
- /// The loader will try to find all the textures in the cache
- /// and add all new textures to the cache.
- TextureCacheType* pTextureCache = nullptr;
-
- /// Optional resource cache usage info.
- ResourceCacheUseInfo* pCacheInfo = nullptr;
-
- /// Whether to load animation and initialize skin attributes
- /// buffer.
- bool LoadAnimationAndSkin = true;
-
- CreateInfo() = default;
-
- explicit CreateInfo(const char* _FileName,
- TextureCacheType* _pTextureCache = nullptr,
- ResourceCacheUseInfo* _pCacheInfo = nullptr,
- bool _LoadAnimationAndSkin = true) :
- // clang-format off
- FileName {_FileName},
- pTextureCache {_pTextureCache},
- pCacheInfo {_pCacheInfo},
- LoadAnimationAndSkin{_LoadAnimationAndSkin}
- // clang-format on
- {
- }
- };
- Model(IRenderDevice* pDevice,
- IDeviceContext* pContext,
- const CreateInfo& CI);
+ Model(IRenderDevice* pDevice,
+ IDeviceContext* pContext,
+ const IGLTFModelCreateInfo& CI);
~Model();
- void UpdateAnimation(Uint32 index, float time);
+ virtual void UpdateAnimation(Uint32 index, float time) override final;
- void PrepareGPUResources(IRenderDevice* pDevice, IDeviceContext* pCtx);
+ virtual void PrepareGPUResources(IRenderDevice* pDevice, IDeviceContext* pCtx) override final;
- bool IsGPUDataInitialized() const
+ virtual bool IsGPUDataInitialized() const override final
{
return GPUDataInitialized.load();
}
- void Transform(const float4x4& Matrix);
+ virtual void Transform(const float* Matrix) override final;
- IBuffer* GetBuffer(BUFFER_ID BuffId)
+ virtual IBuffer* GetBuffer(GLTF_BUFFER_ID BuffId) override final
{
return Buffers[BuffId].pBuffer;
}
- ITexture* GetTexture(Uint32 Index)
+ virtual ITexture* GetTexture(Uint32 Index) override final
{
return Textures[Index].pTexture;
}
- Uint32 GetFirstIndexLocation() const
+ virtual Uint32 GetFirstIndexLocation() const override final
{
- auto& IndBuff = Buffers[BUFFER_ID_INDEX];
+ auto& IndBuff = Buffers[GLTF_BUFFER_ID_INDEX];
VERIFY(!IndBuff.pSuballocation || IndBuff.pSuballocation->GetOffset() % sizeof(Uint32) == 0,
"Allocation offset is not multiple of sizeof(Uint32)");
return IndBuff.pSuballocation ?
@@ -451,9 +376,9 @@ struct Model
0;
}
- Uint32 GetBaseVertex() const
+ virtual Uint32 GetBaseVertex() const override final
{
- auto& VertBuff = Buffers[BUFFER_ID_VERTEX_BASIC_ATTRIBS];
+ auto& VertBuff = Buffers[GLTF_BUFFER_ID_VERTEX_BASIC_ATTRIBS];
VERIFY(!VertBuff.pSuballocation || VertBuff.pSuballocation->GetOffset() % sizeof(VertexBasicAttribs) == 0,
"Allocation offset is not multiple of sizeof(VertexAttribs0)");
return VertBuff.pSuballocation ?
@@ -462,9 +387,9 @@ struct Model
}
private:
- void LoadFromFile(IRenderDevice* pDevice,
- IDeviceContext* pContext,
- const CreateInfo& CI);
+ void LoadFromFile(IRenderDevice* pDevice,
+ IDeviceContext* pContext,
+ const IGLTFModelCreateInfo& CI);
void LoadNode(Node* parent,
const tinygltf::Node& gltf_node,
@@ -476,11 +401,11 @@ private:
void LoadSkins(const tinygltf::Model& gltf_model);
- void LoadTextures(IRenderDevice* pDevice,
- const tinygltf::Model& gltf_model,
- const std::string& BaseDir,
- TextureCacheType* pTextureCache,
- ResourceManager* pResourceMgr);
+ void LoadTextures(IRenderDevice* pDevice,
+ const tinygltf::Model& gltf_model,
+ const std::string& BaseDir,
+ GLTF_TextureCacheType* pTextureCache,
+ ResourceManager* pResourceMgr);
void LoadTextureSamplers(IRenderDevice* pDevice, const tinygltf::Model& gltf_model);
void LoadMaterials(const tinygltf::Model& gltf_model);
@@ -497,7 +422,7 @@ private:
RefCntAutoPtr<IBuffer> pBuffer;
RefCntAutoPtr<IBufferSuballocation> pSuballocation;
};
- std::array<BufferInfo, BUFFER_ID_NUM_BUFFERS> Buffers;
+ std::array<BufferInfo, GLTF_BUFFER_ID_NUM_BUFFERS> Buffers;
struct TextureInfo
{
diff --git a/AssetLoader/interface/GLTFResourceManager.hpp b/AssetLoader/include/GLTFResourceManager.hpp
index a65f9e1..a65f9e1 100644
--- a/AssetLoader/interface/GLTFResourceManager.hpp
+++ b/AssetLoader/include/GLTFResourceManager.hpp
diff --git a/AssetLoader/interface/GLTFLoader.h b/AssetLoader/interface/GLTFLoader.h
new file mode 100644
index 0000000..810a7c4
--- /dev/null
+++ b/AssetLoader/interface/GLTFLoader.h
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2019-2021 Diligent Graphics LLC
+ * Copyright 2015-2019 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/RenderDevice.h"
+#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/DeviceContext.h"
+
+#if PLATFORM_ANDROID || PLATFORM_LINUX || PLATFORM_MACOS || PLATFORM_IOS || (PLATFORM_WIN32 && !defined(_MSC_VER))
+// https://gcc.gnu.org/wiki/Visibility
+# define API_QUALIFIER __attribute__((visibility("default")))
+#elif PLATFORM_WIN32
+# define API_QUALIFIER
+#else
+# error Unsupported platform
+#endif
+
+
+DILIGENT_BEGIN_NAMESPACE(Diligent)
+
+DILIGENT_BEGIN_NAMESPACE(GLTF)
+
+#if DILIGENT_CPP_INTERFACE
+ class ResourceManager;
+#else
+ struct ResourceManager;
+ typedef struct ResourceManager ResourceManager;
+#endif
+
+struct GLTF_ResourceCacheUseInfo
+{
+ ResourceManager* pResourceMgr DEFAULT_INITIALIZER(nullptr);
+
+ Uint8 IndexBufferIdx DEFAULT_INITIALIZER(0);
+ Uint8 VertexBuffer0Idx DEFAULT_INITIALIZER(0);
+ Uint8 VertexBuffer1Idx DEFAULT_INITIALIZER(0);
+
+ /// Base color texture format.
+ TEXTURE_FORMAT BaseColorFormat DEFAULT_INITIALIZER(TEX_FORMAT_RGBA8_UNORM);
+
+ /// Base color texture format for alpha-cut and alpha-blend materials.
+ TEXTURE_FORMAT BaseColorAlphaFormat DEFAULT_INITIALIZER(TEX_FORMAT_RGBA8_UNORM);
+
+ /// Physical descriptor texture format.
+ TEXTURE_FORMAT PhysicalDescFormat DEFAULT_INITIALIZER(TEX_FORMAT_RGBA8_UNORM);
+
+ /// Normal map format.
+ TEXTURE_FORMAT NormalFormat DEFAULT_INITIALIZER(TEX_FORMAT_RGBA8_UNORM);
+
+ /// Occlusion texture format.
+ TEXTURE_FORMAT OcclusionFormat DEFAULT_INITIALIZER(TEX_FORMAT_RGBA8_UNORM);
+
+ /// Emissive texture format.
+ TEXTURE_FORMAT EmissiveFormat DEFAULT_INITIALIZER(TEX_FORMAT_RGBA8_UNORM);
+};
+typedef struct GLTF_ResourceCacheUseInfo GLTF_ResourceCacheUseInfo;
+
+enum GLTF_MAT_ALPHA_MODE
+{
+ GLTF_MAT_ALPHA_MODE_OPAQUE = 0,
+ GLTF_MAT_ALPHA_MODE_MASK,
+ GLTF_MAT_ALPHA_MODE_BLEND,
+ GLTF_MAT_ALPHA_MODE_NUM_MODES
+};
+typedef enum GLTF_MAT_ALPHA_MODE GLTF_MAT_ALPHA_MODE;
+
+enum GLTF_BUFFER_ID
+{
+ GLTF_BUFFER_ID_VERTEX_BASIC_ATTRIBS = 0,
+ GLTF_BUFFER_ID_VERTEX_SKIN_ATTRIBS,
+ GLTF_BUFFER_ID_INDEX,
+ GLTF_BUFFER_ID_NUM_BUFFERS
+};
+typedef enum GLTF_BUFFER_ID GLTF_BUFFER_ID;
+
+struct GLTF_TextureCacheType;
+typedef struct GLTF_TextureCacheType GLTF_TextureCacheType;
+
+/// Model create information
+struct IGLTFModelCreateInfo
+{
+ /// File name
+ const char* FileName DEFAULT_INITIALIZER(nullptr);
+
+ /// Optional texture cache to use when loading the model.
+ /// The loader will try to find all the textures in the cache
+ /// and add all new textures to the cache.
+ GLTF_TextureCacheType* pTextureCache DEFAULT_INITIALIZER(nullptr);
+
+ /// Optional resource cache usage info.
+ GLTF_ResourceCacheUseInfo* pCacheInfo DEFAULT_INITIALIZER(nullptr);
+
+ /// Whether to load animation and initialize skin attributes
+ /// buffer.
+ bool LoadAnimationAndSkin DEFAULT_INITIALIZER(true);
+};
+typedef struct IGLTFModelCreateInfo IGLTFModelCreateInfo;
+
+#define DILIGENT_INTERFACE_NAME IGLTFModel
+#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h"
+
+#define IGLTFModelInclusiveMethods \
+ IGLTFModelMethods GLTF_Model
+
+// clang-format off
+
+DILIGENT_BEGIN_INTERFACE1(IGLTFModel)
+{
+ VIRTUAL void METHOD(UpdateAnimation)(THIS_ Uint32 index, float time) PURE;
+
+ VIRTUAL void METHOD(PrepareGPUResources)(THIS_ IRenderDevice* pDevice, IDeviceContext* pCtx) PURE;
+
+ VIRTUAL bool METHOD(IsGPUDataInitialized)(THIS) CONST PURE;
+
+ VIRTUAL void METHOD(Transform)(THIS_ const float* Matrix) PURE;
+
+ VIRTUAL IBuffer* METHOD(GetBuffer)(THIS_ GLTF_BUFFER_ID BuffId) PURE;
+
+ VIRTUAL ITexture* METHOD(GetTexture)(THIS_ Uint32 Index) PURE;
+
+ VIRTUAL Uint32 METHOD(GetFirstIndexLocation)(THIS) CONST PURE;
+
+ VIRTUAL Uint32 METHOD(GetBaseVertex)(THIS) CONST PURE;
+};
+DILIGENT_END_INTERFACE
+
+#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h"
+
+#if DILIGENT_C_INTERFACE
+
+# define IGLTFModel_UpdateAnimation(This, ...) CALL_IFACE_METHOD(GLTF_Model, UpdateAnimation, This, __VA_ARGS__)
+# define IGLTFModel_PrepareGPUResources(This, ...) CALL_IFACE_METHOD(GLTF_Model, PrepareGPUResources, This, __VA_ARGS__)
+# define IGLTFModel_IsGPUDataInitialized(This) CALL_IFACE_METHOD(GLTF_Model, IsGPUDataInitialized, This)
+# define IGLTFModel_Transform(This, ...) CALL_IFACE_METHOD(GLTF_Model, Transform, This, __VA_ARGS__)
+# define IGLTFModel_GetBuffer(This, ...) CALL_IFACE_METHOD(GLTF_Model, GetBuffer, This, __VA_ARGS__)
+# define IGLTFModel_GetTexture(This, ...) CALL_IFACE_METHOD(GLTF_Model, GetTexture, This, __VA_ARGS__)
+# define IGLTFModel_GetFirstIndexLocation(This) CALL_IFACE_METHOD(GLTF_Model, GetFirstIndexLocation, This)
+# define IGLTFModel_GetBaseVertex(This) CALL_IFACE_METHOD(GLTF_Model, GetBaseVertex, This)
+
+// clang-format on
+
+/// Initializes the renderer
+API_QUALIFIER
+struct IGLTFModel* DILIGENT_GLOBAL_FUNCTION(IGLTFModel_Create)(IRenderDevice* pDevice,
+ IDeviceContext* pCtx,
+ const IGLTFModelCreateInfo* CI);
+
+API_QUALIFIER
+void DILIGENT_GLOBAL_FUNCTION(IGLTFModel_Destroy)(struct IGLTFModel* model);
+#endif
+
+DILIGENT_END_NAMESPACE // namespace GLTF
+
+DILIGENT_END_NAMESPACE // namespace Diligent
diff --git a/AssetLoader/src/GLTFLoader.cpp b/AssetLoader/src/GLTFLoader.cpp
index b000caa..1c546f7 100644
--- a/AssetLoader/src/GLTFLoader.cpp
+++ b/AssetLoader/src/GLTFLoader.cpp
@@ -246,9 +246,9 @@ void Node::UpdateTransforms()
-Model::Model(IRenderDevice* pDevice,
- IDeviceContext* pContext,
- const CreateInfo& CI)
+Model::Model(IRenderDevice* pDevice,
+ IDeviceContext* pContext,
+ const IGLTFModelCreateInfo& CI)
{
LoadFromFile(pDevice, pContext, CI);
}
@@ -710,7 +710,7 @@ static float GetTextureAlphaCutoffValue(const tinygltf::Model& gltf_model, int T
void Model::LoadTextures(IRenderDevice* pDevice,
const tinygltf::Model& gltf_model,
const std::string& BaseDir,
- TextureCacheType* pTextureCache,
+ GLTF_TextureCacheType* pTextureCache,
ResourceManager* pResourceMgr)
{
for (const tinygltf::Texture& gltf_tex : gltf_model.textures)
@@ -1021,7 +1021,7 @@ void Model::PrepareGPUResources(IRenderDevice* pDevice, IDeviceContext* pCtx)
}
}
- auto UpdateBuffer = [&](BUFFER_ID BuffId) //
+ auto UpdateBuffer = [&](GLTF_BUFFER_ID BuffId) //
{
auto& BuffInfo = Buffers[BuffId];
IBuffer* pBuffer = nullptr;
@@ -1052,14 +1052,14 @@ void Model::PrepareGPUResources(IRenderDevice* pDevice, IDeviceContext* pCtx)
if (Buffers[BuffId].pBuffer != nullptr)
{
VERIFY_EXPR(Buffers[BuffId].pBuffer == pBuffer);
- Barriers.emplace_back(StateTransitionDesc{pBuffer, RESOURCE_STATE_UNKNOWN, BuffId == BUFFER_ID_INDEX ? RESOURCE_STATE_INDEX_BUFFER : RESOURCE_STATE_VERTEX_BUFFER, true});
+ Barriers.emplace_back(StateTransitionDesc{pBuffer, RESOURCE_STATE_UNKNOWN, BuffId == GLTF_BUFFER_ID_INDEX ? RESOURCE_STATE_INDEX_BUFFER : RESOURCE_STATE_VERTEX_BUFFER, true});
}
}
};
- UpdateBuffer(BUFFER_ID_VERTEX_BASIC_ATTRIBS);
- UpdateBuffer(BUFFER_ID_VERTEX_SKIN_ATTRIBS);
- UpdateBuffer(BUFFER_ID_INDEX);
+ UpdateBuffer(GLTF_BUFFER_ID_VERTEX_BASIC_ATTRIBS);
+ UpdateBuffer(GLTF_BUFFER_ID_VERTEX_SKIN_ATTRIBS);
+ UpdateBuffer(GLTF_BUFFER_ID_INDEX);
if (!Barriers.empty())
pCtx->TransitionResourceStates(static_cast<Uint32>(Barriers.size()), Barriers.data());
@@ -1195,11 +1195,11 @@ void Model::LoadMaterials(const tinygltf::Model& gltf_model)
const tinygltf::Parameter& param = alpha_mode_it->second;
if (param.string_value == "BLEND")
{
- Mat.Attribs.AlphaMode = Material::ALPHA_MODE_BLEND;
+ Mat.Attribs.AlphaMode = GLTF_MAT_ALPHA_MODE_BLEND;
}
if (param.string_value == "MASK")
{
- Mat.Attribs.AlphaMode = Material::ALPHA_MODE_MASK;
+ Mat.Attribs.AlphaMode = GLTF_MAT_ALPHA_MODE_MASK;
Mat.Attribs.AlphaCutoff = 0.5f;
}
}
@@ -1434,8 +1434,8 @@ namespace
struct ImageLoaderData
{
- Model::TextureCacheType* const pTextureCache;
- ResourceManager* const pResourceMgr;
+ GLTF_TextureCacheType* const pTextureCache;
+ ResourceManager* const pResourceMgr;
std::vector<RefCntAutoPtr<IObject>> TexturesHold;
@@ -1699,9 +1699,9 @@ bool ReadWholeFile(std::vector<unsigned char>* out,
} // namespace Callbacks
-void Model::LoadFromFile(IRenderDevice* pDevice,
- IDeviceContext* pContext,
- const CreateInfo& CI)
+void Model::LoadFromFile(IRenderDevice* pDevice,
+ IDeviceContext* pContext,
+ const IGLTFModelCreateInfo& CI)
{
if (CI.FileName == nullptr || *CI.FileName == 0)
LOG_ERROR_AND_THROW("File path must not be empty");
@@ -1799,7 +1799,7 @@ void Model::LoadFromFile(IRenderDevice* pDevice,
Extensions = gltf_model.extensionsUsed;
- auto CreateBuffer = [&](BUFFER_ID BuffId, const void* pData, size_t Size, BIND_FLAGS BindFlags, const char* Name) //
+ auto CreateBuffer = [&](GLTF_BUFFER_ID BuffId, const void* pData, size_t Size, BIND_FLAGS BindFlags, const char* Name) //
{
VERIFY_EXPR(Size > 0);
@@ -1809,13 +1809,13 @@ void Model::LoadFromFile(IRenderDevice* pDevice,
Uint32 CacheBufferIndex = 0;
switch (BuffId)
{
- case BUFFER_ID_INDEX:
+ case GLTF_BUFFER_ID_INDEX:
CacheBufferIndex = CI.pCacheInfo->IndexBufferIdx;
break;
- case BUFFER_ID_VERTEX_BASIC_ATTRIBS:
+ case GLTF_BUFFER_ID_VERTEX_BASIC_ATTRIBS:
CacheBufferIndex = CI.pCacheInfo->VertexBuffer0Idx;
break;
- case BUFFER_ID_VERTEX_SKIN_ATTRIBS:
+ case GLTF_BUFFER_ID_VERTEX_SKIN_ATTRIBS:
CacheBufferIndex = CI.pCacheInfo->VertexBuffer1Idx;
break;
default:
@@ -1840,18 +1840,18 @@ void Model::LoadFromFile(IRenderDevice* pDevice,
}
};
- CreateBuffer(BUFFER_ID_VERTEX_BASIC_ATTRIBS, VertexBasicData.data(), VertexBasicData.size() * sizeof(VertexBasicData[0]),
+ CreateBuffer(GLTF_BUFFER_ID_VERTEX_BASIC_ATTRIBS, VertexBasicData.data(), VertexBasicData.size() * sizeof(VertexBasicData[0]),
BIND_VERTEX_BUFFER, "GLTF vertex attribs 0 buffer");
if (!VertexSkinData.empty())
{
- CreateBuffer(BUFFER_ID_VERTEX_SKIN_ATTRIBS, VertexSkinData.data(), VertexSkinData.size() * sizeof(VertexSkinData[0]),
+ CreateBuffer(GLTF_BUFFER_ID_VERTEX_SKIN_ATTRIBS, VertexSkinData.data(), VertexSkinData.size() * sizeof(VertexSkinData[0]),
BIND_VERTEX_BUFFER, "GLTF vertex attribs 1 buffer");
}
if (!IndexData.empty())
{
- CreateBuffer(BUFFER_ID_INDEX, IndexData.data(), IndexData.size() * sizeof(IndexData[0]),
+ CreateBuffer(GLTF_BUFFER_ID_INDEX, IndexData.data(), IndexData.size() * sizeof(IndexData[0]),
BIND_INDEX_BUFFER, "GLTF index buffer");
}
@@ -1989,8 +1989,9 @@ void Model::UpdateAnimation(Uint32 index, float time)
}
}
-void Model::Transform(const float4x4& Matrix)
+void Model::Transform(const float* _Matrix)
{
+ auto Matrix = float4x4::MakeMatrix(_Matrix);
for (auto& root_node : Nodes)
{
root_node->Matrix *= Matrix;
@@ -2033,7 +2034,33 @@ Node* Model::NodeFromIndex(uint32_t index)
return nodeFound;
}
+API_QUALIFIER
+IGLTFModel* IGLTFModel_Create(IRenderDevice* pDevice,
+ IDeviceContext* pCtx,
+ const IGLTFModelCreateInfo* CI) {
+ return new Model(pDevice, pCtx, *CI);
+}
+
+API_QUALIFIER
+void IGLTFModel_Destroy(IGLTFModel* model) {
+ delete model;
+}
} // namespace GLTF
} // namespace Diligent
+
+extern "C"
+{
+ API_QUALIFIER
+ Diligent::GLTF::IGLTFModel* Diligent_IGLTFModel_Create(Diligent::IRenderDevice* pDevice,
+ Diligent::IDeviceContext* pCtx,
+ const Diligent::GLTF::IGLTFModelCreateInfo* CI) {
+ return Diligent::GLTF::IGLTFModel_Create(pDevice, pCtx, CI);
+ }
+
+ API_QUALIFIER
+ void Diligent_IGLTFModel_Destroy(Diligent::GLTF::IGLTFModel* model) {
+ Diligent::GLTF::IGLTFModel_Destroy(model);
+ }
+}