summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-11-25 02:19:06 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-11-25 02:19:06 +0000
commit4e1be5d0d33cb62bd296c3ffee3926945052843d (patch)
tree2db724b41fe93094723c9d51cec3c3340d625645
parentRenamed INSTALL_DILIGENT_TOOLS cmake option to DILIGENT_INSTALL_TOOLS (diff)
downloadDiligentTools-4e1be5d0d33cb62bd296c3ffee3926945052843d.tar.gz
DiligentTools-4e1be5d0d33cb62bd296c3ffee3926945052843d.zip
clang-formatted AssetLoader
-rw-r--r--AssetLoader/interface/DXSDKMeshLoader.h273
-rw-r--r--AssetLoader/interface/GLTFLoader.h157
-rw-r--r--AssetLoader/src/DXSDKMeshLoader.cpp128
-rw-r--r--AssetLoader/src/GLTFLoader.cpp306
4 files changed, 447 insertions, 417 deletions
diff --git a/AssetLoader/interface/DXSDKMeshLoader.h b/AssetLoader/interface/DXSDKMeshLoader.h
index 9881b10..aac9753 100644
--- a/AssetLoader/interface/DXSDKMeshLoader.h
+++ b/AssetLoader/interface/DXSDKMeshLoader.h
@@ -40,15 +40,15 @@ namespace Diligent
//--------------------------------------------------------------------------------------
// Hard Defines for the various structures
//--------------------------------------------------------------------------------------
-#define DXSDKMESH_FILE_VERSION 101
+#define DXSDKMESH_FILE_VERSION 101
-#define INVALID_FRAME ((Uint32)-1)
-#define INVALID_MESH ((Uint32)-1)
-#define INVALID_MATERIAL ((Uint32)-1)
-#define INVALID_SUBSET ((Uint32)-1)
-#define INVALID_ANIMATION_DATA ((Uint32)-1)
-#define INVALID_SAMPLER_SLOT ((Uint32)-1)
-#define ERROR_RESOURCE_VALUE 1
+#define INVALID_FRAME ((Uint32)-1)
+#define INVALID_MESH ((Uint32)-1)
+#define INVALID_MATERIAL ((Uint32)-1)
+#define INVALID_SUBSET ((Uint32)-1)
+#define INVALID_ANIMATION_DATA ((Uint32)-1)
+#define INVALID_SAMPLER_SLOT ((Uint32)-1)
+#define ERROR_RESOURCE_VALUE 1
// Enumerated Types.
enum DXSDKMESH_PRIMITIVE_TYPE
@@ -75,7 +75,7 @@ enum DXSDKMESH_INDEX_TYPE
enum FRAME_TRANSFORM_TYPE
{
FTT_RELATIVE = 0,
- FTT_ABSOLUTE, //This is not currently used but is here to support absolute transformations in the future
+ FTT_ABSOLUTE, //This is not currently used but is here to support absolute transformations in the future
};
// Structures. Unions with pointers are forced to 64bit.
@@ -108,53 +108,53 @@ struct DXSDKMESH_HEADER
enum DXSDKMESH_VERTEX_SEMANTIC
{
DXSDKMESH_VERTEX_SEMANTIC_POSITION = 0,
- DXSDKMESH_VERTEX_SEMANTIC_BLENDWEIGHT, // 1
- DXSDKMESH_VERTEX_SEMANTIC_BLENDINDICES, // 2
- DXSDKMESH_VERTEX_SEMANTIC_NORMAL, // 3
- DXSDKMESH_VERTEX_SEMANTIC_PSIZE, // 4
- DXSDKMESH_VERTEX_SEMANTIC_TEXCOORD, // 5
- DXSDKMESH_VERTEX_SEMANTIC_TANGENT, // 6
- DXSDKMESH_VERTEX_SEMANTIC_BINORMAL, // 7
- DXSDKMESH_VERTEX_SEMANTIC_TESSFACTOR, // 8
- DXSDKMESH_VERTEX_SEMANTIC_POSITIONT, // 9
- DXSDKMESH_VERTEX_SEMANTIC_COLOR, // 10
- DXSDKMESH_VERTEX_SEMANTIC_FOG, // 11
- DXSDKMESH_VERTEX_SEMANTIC_DEPTH, // 12
- DXSDKMESH_VERTEX_SEMANTIC_SAMPLE // 13
+ DXSDKMESH_VERTEX_SEMANTIC_BLENDWEIGHT, // 1
+ DXSDKMESH_VERTEX_SEMANTIC_BLENDINDICES, // 2
+ DXSDKMESH_VERTEX_SEMANTIC_NORMAL, // 3
+ DXSDKMESH_VERTEX_SEMANTIC_PSIZE, // 4
+ DXSDKMESH_VERTEX_SEMANTIC_TEXCOORD, // 5
+ DXSDKMESH_VERTEX_SEMANTIC_TANGENT, // 6
+ DXSDKMESH_VERTEX_SEMANTIC_BINORMAL, // 7
+ DXSDKMESH_VERTEX_SEMANTIC_TESSFACTOR, // 8
+ DXSDKMESH_VERTEX_SEMANTIC_POSITIONT, // 9
+ DXSDKMESH_VERTEX_SEMANTIC_COLOR, // 10
+ DXSDKMESH_VERTEX_SEMANTIC_FOG, // 11
+ DXSDKMESH_VERTEX_SEMANTIC_DEPTH, // 12
+ DXSDKMESH_VERTEX_SEMANTIC_SAMPLE // 13
};
enum DXSDKMESH_VERTEX_DATA_TYPE
{
- DXSDKMESH_VERTEX_DATA_TYPE_FLOAT1 = 0, // 1D float expanded to (value, 0., 0., 1.)
- DXSDKMESH_VERTEX_DATA_TYPE_FLOAT2 = 1, // 2D float expanded to (value, value, 0., 1.)
- DXSDKMESH_VERTEX_DATA_TYPE_FLOAT3 = 2, // 3D float expanded to (value, value, value, 1.)
- DXSDKMESH_VERTEX_DATA_TYPE_FLOAT4 = 3, // 4D float
- DXSDKMESH_VERTEX_DATA_TYPE_D3DCOLOR = 4, // 4D packed unsigned bytes mapped to 0. to 1. range
- // Input is in D3DCOLOR format (ARGB) expanded to (R, G, B, A)
- DXSDKMESH_VERTEX_DATA_TYPE_UBYTE4 = 5, // 4D unsigned byte
- DXSDKMESH_VERTEX_DATA_TYPE_SHORT2 = 6, // 2D signed short expanded to (value, value, 0., 1.)
- DXSDKMESH_VERTEX_DATA_TYPE_SHORT4 = 7, // 4D signed short
-
- DXSDKMESH_VERTEX_DATA_TYPE_UBYTE4N = 8, // Each of 4 bytes is normalized by dividing to 255.0
- DXSDKMESH_VERTEX_DATA_TYPE_SHORT2N = 9, // 2D signed short normalized (v[0]/32767.0,v[1]/32767.0,0,1)
- DXSDKMESH_VERTEX_DATA_TYPE_SHORT4N = 10, // 4D signed short normalized (v[0]/32767.0,v[1]/32767.0,v[2]/32767.0,v[3]/32767.0)
- DXSDKMESH_VERTEX_DATA_TYPE_USHORT2N = 11, // 2D unsigned short normalized (v[0]/65535.0,v[1]/65535.0,0,1)
- DXSDKMESH_VERTEX_DATA_TYPE_USHORT4N = 12, // 4D unsigned short normalized (v[0]/65535.0,v[1]/65535.0,v[2]/65535.0,v[3]/65535.0)
- DXSDKMESH_VERTEX_DATA_TYPE_UDEC3 = 13, // 3D unsigned 10 10 10 format expanded to (value, value, value, 1)
- DXSDKMESH_VERTEX_DATA_TYPE_DEC3N = 14, // 3D signed 10 10 10 format normalized and expanded to (v[0]/511.0, v[1]/511.0, v[2]/511.0, 1)
- DXSDKMESH_VERTEX_DATA_TYPE_FLOAT16_2 = 15, // Two 16-bit floating point values, expanded to (value, value, 0, 1)
- DXSDKMESH_VERTEX_DATA_TYPE_FLOAT16_4 = 16, // Four 16-bit floating point values
- DXSDKMESH_VERTEX_DATA_TYPE_UNUSED = 17, // When the type field in a decl is unused.
+ DXSDKMESH_VERTEX_DATA_TYPE_FLOAT1 = 0, // 1D float expanded to (value, 0., 0., 1.)
+ DXSDKMESH_VERTEX_DATA_TYPE_FLOAT2 = 1, // 2D float expanded to (value, value, 0., 1.)
+ DXSDKMESH_VERTEX_DATA_TYPE_FLOAT3 = 2, // 3D float expanded to (value, value, value, 1.)
+ DXSDKMESH_VERTEX_DATA_TYPE_FLOAT4 = 3, // 4D float
+ DXSDKMESH_VERTEX_DATA_TYPE_D3DCOLOR = 4, // 4D packed unsigned bytes mapped to 0. to 1. range
+ // Input is in D3DCOLOR format (ARGB) expanded to (R, G, B, A)
+ DXSDKMESH_VERTEX_DATA_TYPE_UBYTE4 = 5, // 4D unsigned byte
+ DXSDKMESH_VERTEX_DATA_TYPE_SHORT2 = 6, // 2D signed short expanded to (value, value, 0., 1.)
+ DXSDKMESH_VERTEX_DATA_TYPE_SHORT4 = 7, // 4D signed short
+
+ DXSDKMESH_VERTEX_DATA_TYPE_UBYTE4N = 8, // Each of 4 bytes is normalized by dividing to 255.0
+ DXSDKMESH_VERTEX_DATA_TYPE_SHORT2N = 9, // 2D signed short normalized (v[0]/32767.0,v[1]/32767.0,0,1)
+ DXSDKMESH_VERTEX_DATA_TYPE_SHORT4N = 10, // 4D signed short normalized (v[0]/32767.0,v[1]/32767.0,v[2]/32767.0,v[3]/32767.0)
+ DXSDKMESH_VERTEX_DATA_TYPE_USHORT2N = 11, // 2D unsigned short normalized (v[0]/65535.0,v[1]/65535.0,0,1)
+ DXSDKMESH_VERTEX_DATA_TYPE_USHORT4N = 12, // 4D unsigned short normalized (v[0]/65535.0,v[1]/65535.0,v[2]/65535.0,v[3]/65535.0)
+ DXSDKMESH_VERTEX_DATA_TYPE_UDEC3 = 13, // 3D unsigned 10 10 10 format expanded to (value, value, value, 1)
+ DXSDKMESH_VERTEX_DATA_TYPE_DEC3N = 14, // 3D signed 10 10 10 format normalized and expanded to (v[0]/511.0, v[1]/511.0, v[2]/511.0, 1)
+ DXSDKMESH_VERTEX_DATA_TYPE_FLOAT16_2 = 15, // Two 16-bit floating point values, expanded to (value, value, 0, 1)
+ DXSDKMESH_VERTEX_DATA_TYPE_FLOAT16_4 = 16, // Four 16-bit floating point values
+ DXSDKMESH_VERTEX_DATA_TYPE_UNUSED = 17, // When the type field in a decl is unused.
};
struct DXSDKMESH_VERTEX_ELEMENT
{
- Uint16 Stream; // Stream index
- Uint16 Offset; // Offset in the stream in Uint8s
- Uint8 Type; // Data type
- Uint8 Method; // Processing method
- Uint8 Usage; // Semantics
- Uint8 UsageIndex; // Semantic index
+ Uint16 Stream; // Stream index
+ Uint16 Offset; // Offset in the stream in Uint8s
+ Uint8 Type; // Data type
+ Uint8 Method; // Processing method
+ Uint8 Usage; // Semantics
+ Uint8 UsageIndex; // Semantic index
};
@@ -164,11 +164,11 @@ struct DXSDKMESH_VERTEX_BUFFER_HEADER
Uint64 SizeUint8s;
Uint64 StrideUint8s;
- static constexpr size_t MaxVertexElements = 32;
+ static constexpr size_t MaxVertexElements = 32;
DXSDKMESH_VERTEX_ELEMENT Decl[MaxVertexElements];
union
{
- Uint64 DataOffset; //(This also forces the union to 64bits)
+ Uint64 DataOffset; //(This also forces the union to 64bits)
IBuffer* pVB;
};
};
@@ -180,7 +180,7 @@ struct DXSDKMESH_INDEX_BUFFER_HEADER
Uint32 IndexType;
union
{
- Uint64 DataOffset; //(This also forces the union to 64bits)
+ Uint64 DataOffset; //(This also forces the union to 64bits)
IBuffer* pIB;
};
};
@@ -188,103 +188,103 @@ struct DXSDKMESH_INDEX_BUFFER_HEADER
struct DXSDKMESH_MESH
{
static constexpr size_t MaxMeshName = 100;
- char Name[MaxMeshName];
- Uint8 NumVertexBuffers;
+ char Name[MaxMeshName];
+ Uint8 NumVertexBuffers;
static constexpr size_t MaxVertexStreams = 16;
- Uint32 VertexBuffers[MaxVertexStreams];
- Uint32 IndexBuffer;
- Uint32 NumSubsets;
- Uint32 NumFrameInfluences; //aka bones
+ Uint32 VertexBuffers[MaxVertexStreams];
+ Uint32 IndexBuffer;
+ Uint32 NumSubsets;
+ Uint32 NumFrameInfluences; //aka bones
float3 BoundingBoxCenter;
float3 BoundingBoxExtents;
union
{
- Uint64 SubsetOffset; //Offset to list of subsets (This also forces the union to 64bits)
- Uint32* pSubsets; //Pointer to list of subsets
+ Uint64 SubsetOffset; //Offset to list of subsets (This also forces the union to 64bits)
+ Uint32* pSubsets; //Pointer to list of subsets
};
union
{
- Uint64 FrameInfluenceOffset; //Offset to list of frame influences (This also forces the union to 64bits)
- Uint32* pFrameInfluences; //Pointer to list of frame influences
+ Uint64 FrameInfluenceOffset; //Offset to list of frame influences (This also forces the union to 64bits)
+ Uint32* pFrameInfluences; //Pointer to list of frame influences
};
};
struct DXSDKMESH_SUBSET
{
static constexpr size_t MaxSubsetName = 100;
- char Name[MaxSubsetName];
- Uint32 MaterialID;
- Uint32 PrimitiveType;
- Uint64 IndexStart;
- Uint64 IndexCount;
- Uint64 VertexStart;
- Uint64 VertexCount;
+ char Name[MaxSubsetName];
+ Uint32 MaterialID;
+ Uint32 PrimitiveType;
+ Uint64 IndexStart;
+ Uint64 IndexCount;
+ Uint64 VertexStart;
+ Uint64 VertexCount;
};
struct DXSDKMESH_FRAME
{
static constexpr size_t MaxFrameName = 100;
- char Name[MaxFrameName];
- Uint32 Mesh;
- Uint32 ParentFrame;
- Uint32 ChildFrame;
- Uint32 SiblingFrame;
- float4x4 Matrix;
- Uint32 AnimationDataIndex; //Used to index which set of keyframes transforms this frame
+ char Name[MaxFrameName];
+ Uint32 Mesh;
+ Uint32 ParentFrame;
+ Uint32 ChildFrame;
+ Uint32 SiblingFrame;
+ float4x4 Matrix;
+ Uint32 AnimationDataIndex; //Used to index which set of keyframes transforms this frame
};
struct DXSDKMESH_MATERIAL
{
static constexpr size_t MaxMaterialName = 100;
- char Name[MaxMaterialName];
+ char Name[MaxMaterialName];
// Use MaterialInstancePath
static constexpr size_t MaxMaterialPath = 260;
- char MaterialInstancePath[MaxMaterialPath];
+ char MaterialInstancePath[MaxMaterialPath];
// Or fall back to d3d8-type materials
static constexpr size_t MaxTextureName = 260;
- char DiffuseTexture[MaxTextureName];
- char NormalTexture[MaxTextureName];
- char SpecularTexture[MaxTextureName];
+ char DiffuseTexture[MaxTextureName];
+ char NormalTexture[MaxTextureName];
+ char SpecularTexture[MaxTextureName];
float4 Diffuse;
float4 Ambient;
float4 Specular;
float4 Emissive;
- float Power;
+ float Power;
union
{
- Uint64 Force64_1; //Force the union to 64bits
+ Uint64 Force64_1; //Force the union to 64bits
ITexture* pDiffuseTexture = nullptr;
};
union
{
- Uint64 Force64_2; //Force the union to 64bits
+ Uint64 Force64_2; //Force the union to 64bits
ITexture* pNormalTexture = nullptr;
};
union
{
- Uint64 Force64_3; //Force the union to 64bits
+ Uint64 Force64_3; //Force the union to 64bits
ITexture* pSpecularTexture = nullptr;
};
union
{
- Uint64 Force64_4; //Force the union to 64bits
+ Uint64 Force64_4; //Force the union to 64bits
ITextureView* pDiffuseRV = nullptr;
};
union
{
- Uint64 Force64_5; //Force the union to 64bits
+ Uint64 Force64_5; //Force the union to 64bits
ITextureView* pNormalRV = nullptr;
};
union
{
- Uint64 Force64_6; //Force the union to 64bits
+ Uint64 Force64_6; //Force the union to 64bits
ITextureView* pSpecularRV = nullptr;
};
};
@@ -292,7 +292,7 @@ struct DXSDKMESH_MATERIAL
struct SDKANIMATION_FILE_HEADER
{
Uint32 Version;
- Uint8 IsBigEndian;
+ Uint8 IsBigEndian;
Uint32 FrameTransformType;
Uint32 NumFrames;
Uint32 NumAnimationKeys;
@@ -311,10 +311,10 @@ struct SDKANIMATION_DATA
struct SDKANIMATION_FRAME_DATA
{
static constexpr size_t MaxFrameName = 100;
- char FrameName[MaxFrameName];
+ char FrameName[MaxFrameName];
union
{
- Uint64 DataOffset;
+ Uint64 DataOffset;
SDKANIMATION_DATA* pAnimationData;
};
};
@@ -326,96 +326,98 @@ class DXSDKMesh
public:
virtual ~DXSDKMesh();
- bool Create( const Char* szFileName );
- bool Create( Uint8* pData, Uint32 DataUint8s );
- void LoadGPUResources(const Char* ResourceDirectory, IRenderDevice* pDevice, IDeviceContext* pDeviceCtx);
- void Destroy();
+ bool Create(const Char* szFileName);
+ bool Create(Uint8* pData, Uint32 DataUint8s);
+ void LoadGPUResources(const Char* ResourceDirectory, IRenderDevice* pDevice, IDeviceContext* pDeviceCtx);
+ void Destroy();
//Helpers
- static PRIMITIVE_TOPOLOGY GetPrimitiveType( DXSDKMESH_PRIMITIVE_TYPE PrimType );
- VALUE_TYPE GetIBFormat( Uint32 iMesh ) const;
- DXSDKMESH_INDEX_TYPE GetIndexType( Uint32 iMesh ) const
+ static PRIMITIVE_TOPOLOGY GetPrimitiveType(DXSDKMESH_PRIMITIVE_TYPE PrimType);
+ VALUE_TYPE GetIBFormat(Uint32 iMesh) const;
+ DXSDKMESH_INDEX_TYPE GetIndexType(Uint32 iMesh) const
{
- return ( DXSDKMESH_INDEX_TYPE ) m_pIndexBufferArray[m_pMeshArray[ iMesh ].IndexBuffer].IndexType;
+ return (DXSDKMESH_INDEX_TYPE)m_pIndexBufferArray[m_pMeshArray[iMesh].IndexBuffer].IndexType;
}
- Uint32 GetNumMeshes() const { return m_pMeshHeader ? m_pMeshHeader->NumMeshes : 0;}
- Uint32 GetNumMaterials()const { return m_pMeshHeader ? m_pMeshHeader->NumMaterials : 0;}
- Uint32 GetNumVBs() const { return m_pMeshHeader ? m_pMeshHeader->NumVertexBuffers : 0;}
- Uint32 GetNumIBs() const { return m_pMeshHeader ? m_pMeshHeader->NumIndexBuffers : 0;}
+ // clang-format off
+ Uint32 GetNumMeshes() const { return m_pMeshHeader ? m_pMeshHeader->NumMeshes : 0; }
+ Uint32 GetNumMaterials() const { return m_pMeshHeader ? m_pMeshHeader->NumMaterials : 0; }
+ Uint32 GetNumVBs() const { return m_pMeshHeader ? m_pMeshHeader->NumVertexBuffers : 0; }
+ Uint32 GetNumIBs() const { return m_pMeshHeader ? m_pMeshHeader->NumIndexBuffers : 0; }
+ // clang-format on
- const Uint8* GetRawVerticesAt( Uint32 iVB ) const {return m_ppVertices[iVB];}
- const Uint8* GetRawIndicesAt( Uint32 iIB ) const {return m_ppIndices[iIB]; }
- const DXSDKMESH_MATERIAL& GetMaterial( Uint32 iMaterial )const {return m_pMaterialArray[ iMaterial ];}
+ const Uint8* GetRawVerticesAt(Uint32 iVB) const { return m_ppVertices[iVB]; }
+ const Uint8* GetRawIndicesAt(Uint32 iIB) const { return m_ppIndices[iIB]; }
+ const DXSDKMESH_MATERIAL& GetMaterial(Uint32 iMaterial) const { return m_pMaterialArray[iMaterial]; }
- const DXSDKMESH_MESH& GetMesh( Uint32 iMesh ) const { return m_pMeshArray[ iMesh ];}
- Uint32 GetNumSubsets( Uint32 iMesh ) const { return m_pMeshArray[ iMesh ].NumSubsets; }
- const DXSDKMESH_SUBSET& GetSubset( Uint32 iMesh, Uint32 iSubset ) const
+ const DXSDKMESH_MESH& GetMesh(Uint32 iMesh) const { return m_pMeshArray[iMesh]; }
+ Uint32 GetNumSubsets(Uint32 iMesh) const { return m_pMeshArray[iMesh].NumSubsets; }
+ const DXSDKMESH_SUBSET& GetSubset(Uint32 iMesh, Uint32 iSubset) const
{
- return m_pSubsetArray[ m_pMeshArray[ iMesh ].pSubsets[iSubset] ];
+ return m_pSubsetArray[m_pMeshArray[iMesh].pSubsets[iSubset]];
}
- Uint32 GetMeshVertexStride( Uint32 iMesh, Uint32 iVB ) const
+ Uint32 GetMeshVertexStride(Uint32 iMesh, Uint32 iVB) const
{
- return ( Uint32 )m_pVertexBufferArray[ m_pMeshArray[ iMesh ].VertexBuffers[iVB] ].StrideUint8s;
+ return (Uint32)m_pVertexBufferArray[m_pMeshArray[iMesh].VertexBuffers[iVB]].StrideUint8s;
}
- Uint32 GetVertexStride( Uint32 iVB ) const
+ Uint32 GetVertexStride(Uint32 iVB) const
{
- return ( Uint32 )m_pVertexBufferArray[ iVB ].StrideUint8s;
+ return (Uint32)m_pVertexBufferArray[iVB].StrideUint8s;
}
- Uint64 GetNumMeshVertices( Uint32 iMesh, Uint32 iVB ) const
+ Uint64 GetNumMeshVertices(Uint32 iMesh, Uint32 iVB) const
{
- return m_pVertexBufferArray[ m_pMeshArray[ iMesh ].VertexBuffers[iVB] ].NumVertices;
+ return m_pVertexBufferArray[m_pMeshArray[iMesh].VertexBuffers[iVB]].NumVertices;
}
- Uint64 GetNumMeshIndices( Uint32 iMesh ) const
+ Uint64 GetNumMeshIndices(Uint32 iMesh) const
{
- return m_pIndexBufferArray[ m_pMeshArray[ iMesh ].IndexBuffer ].NumIndices;
+ return m_pIndexBufferArray[m_pMeshArray[iMesh].IndexBuffer].NumIndices;
}
IBuffer* GetMeshVertexBuffer(Uint32 iMesh, Uint32 iVB)
{
- return m_VertexBuffers[m_pMeshArray[ iMesh ].VertexBuffers[iVB]];
+ return m_VertexBuffers[m_pMeshArray[iMesh].VertexBuffers[iVB]];
}
IBuffer* GetMeshIndexBuffer(Uint32 iMesh)
{
- return m_IndexBuffers[ m_pMeshArray[ iMesh ].IndexBuffer];
+ return m_IndexBuffers[m_pMeshArray[iMesh].IndexBuffer];
}
- const DXSDKMESH_VERTEX_ELEMENT* VBElements( Uint32 iVB ) const { return m_pVertexBufferArray[0].Decl; }
+ const DXSDKMESH_VERTEX_ELEMENT* VBElements(Uint32 iVB) const { return m_pVertexBufferArray[0].Decl; }
//Uint32 GetNumFrames();
//DXSDKMESH_FRAME* GetFrame( Uint32 iFrame );
//DXSDKMESH_FRAME* FindFrame( char* pszName );
protected:
- bool CreateFromFile( const char* szFileName );
+ bool CreateFromFile(const char* szFileName);
- bool CreateFromMemory( Uint8* pData,
- Uint32 DataUint8s );
+ bool CreateFromMemory(Uint8* pData,
+ Uint32 DataUint8s);
- void ComputeBoundingBoxes();
+ void ComputeBoundingBoxes();
//These are the pointers to the two chunks of data loaded in from the mesh file
- std::vector<Uint8> m_StaticMeshData;
+ std::vector<Uint8> m_StaticMeshData;
//Uint8* m_pAnimationData = nullptr;
- std::vector<Uint8*> m_ppVertices;
- std::vector<Uint8*> m_ppIndices;
+ std::vector<Uint8*> m_ppVertices;
+ std::vector<Uint8*> m_ppIndices;
std::vector<RefCntAutoPtr<IBuffer>> m_VertexBuffers;
std::vector<RefCntAutoPtr<IBuffer>> m_IndexBuffers;
//General mesh info
- DXSDKMESH_HEADER* m_pMeshHeader = nullptr;
- DXSDKMESH_VERTEX_BUFFER_HEADER* m_pVertexBufferArray = nullptr;
- DXSDKMESH_INDEX_BUFFER_HEADER* m_pIndexBufferArray = nullptr;
- DXSDKMESH_MESH* m_pMeshArray = nullptr;
- DXSDKMESH_SUBSET* m_pSubsetArray = nullptr;
- DXSDKMESH_FRAME* m_pFrameArray = nullptr;
- DXSDKMESH_MATERIAL* m_pMaterialArray = nullptr;
+ DXSDKMESH_HEADER* m_pMeshHeader = nullptr;
+ DXSDKMESH_VERTEX_BUFFER_HEADER* m_pVertexBufferArray = nullptr;
+ DXSDKMESH_INDEX_BUFFER_HEADER* m_pIndexBufferArray = nullptr;
+ DXSDKMESH_MESH* m_pMeshArray = nullptr;
+ DXSDKMESH_SUBSET* m_pSubsetArray = nullptr;
+ DXSDKMESH_FRAME* m_pFrameArray = nullptr;
+ DXSDKMESH_MATERIAL* m_pMaterialArray = nullptr;
// Adjacency information (not part of the m_pStaticMeshData, so it must be created and destroyed separately )
//DXSDKMESH_INDEX_BUFFER_HEADER* m_pAdjacencyIndexBufferArray = nullptr;
@@ -426,7 +428,6 @@ protected:
//float4x4* m_pBindPoseFrameMatrices = nullptr;
//float4x4* m_pTransformedFrameMatrices = nullptr;
//float4x4* m_pWorldPoseFrameMatrices = nullptr;
-
};
-} \ No newline at end of file
+} // namespace Diligent
diff --git a/AssetLoader/interface/GLTFLoader.h b/AssetLoader/interface/GLTFLoader.h
index f99cdea..7bd263c 100644
--- a/AssetLoader/interface/GLTFLoader.h
+++ b/AssetLoader/interface/GLTFLoader.h
@@ -33,9 +33,11 @@
namespace tinygltf
{
+
class Node;
class Model;
-}
+
+} // namespace tinygltf
namespace Diligent
{
@@ -44,7 +46,7 @@ namespace GLTF
{
struct Material
-{
+{
enum ALPHA_MODE
{
ALPHAMODE_OPAQUE,
@@ -53,17 +55,17 @@ struct Material
};
ALPHA_MODE AlphaMode = ALPHAMODE_OPAQUE;
- float AlphaCutoff = 1.0f;
- float MetallicFactor = 1.0f;
- float RoughnessFactor = 1.0f;
- float4 BaseColorFactor = float4(1.0f, 1.0f, 1.0f, 1.0f);
- float4 EmissiveFactor = float4(1.0f, 1.0f, 1.0f, 1.0f);
+ float AlphaCutoff = 1.0f;
+ float MetallicFactor = 1.0f;
+ float RoughnessFactor = 1.0f;
+ float4 BaseColorFactor = float4(1.0f, 1.0f, 1.0f, 1.0f);
+ float4 EmissiveFactor = float4(1.0f, 1.0f, 1.0f, 1.0f);
- RefCntAutoPtr<ITexture> pBaseColorTexture;
- RefCntAutoPtr<ITexture> pMetallicRoughnessTexture;
- RefCntAutoPtr<ITexture> pNormalTexture;
- RefCntAutoPtr<ITexture> pOcclusionTexture;
- RefCntAutoPtr<ITexture> pEmissiveTexture;
+ RefCntAutoPtr<ITexture> pBaseColorTexture;
+ RefCntAutoPtr<ITexture> pMetallicRoughnessTexture;
+ RefCntAutoPtr<ITexture> pNormalTexture;
+ RefCntAutoPtr<ITexture> pOcclusionTexture;
+ RefCntAutoPtr<ITexture> pEmissiveTexture;
struct TextureCoordinateSets
{
@@ -80,8 +82,8 @@ struct Material
{
RefCntAutoPtr<ITexture> pSpecularGlossinessTexture;
RefCntAutoPtr<ITexture> pDiffuseTexture;
- float4 DiffuseFactor = float4(1.0f, 1.0f, 1.0f, 1.0f);
- float3 SpecularFactor = float3(1.0f, 1.0f, 1.0f);
+ float4 DiffuseFactor = float4(1.0f, 1.0f, 1.0f, 1.0f);
+ float3 SpecularFactor = float3(1.0f, 1.0f, 1.0f);
};
Extension extension;
@@ -93,14 +95,14 @@ struct Material
PbrWorkflow workflow = PbrWorkflow::MetallicRoughness;
};
-
+
struct Primitive
{
- Uint32 FirstIndex = 0;
- Uint32 IndexCount = 0;
- Uint32 VertexCount = 0;
+ Uint32 FirstIndex = 0;
+ Uint32 IndexCount = 0;
+ Uint32 VertexCount = 0;
Material& material;
- bool hasIndices;
+ bool hasIndices;
BoundBox BB;
bool IsValidBB = false;
@@ -109,18 +111,18 @@ struct Primitive
Uint32 _IndexCount,
Uint32 _VertexCount,
Material& _material) :
- FirstIndex (_FirstIndex),
- IndexCount (_IndexCount),
- VertexCount (_VertexCount),
- material (_material),
- hasIndices (_IndexCount > 0)
+ FirstIndex{_FirstIndex},
+ IndexCount{_IndexCount},
+ VertexCount{_VertexCount},
+ material{_material},
+ hasIndices{_IndexCount > 0}
{
}
void SetBoundingBox(const float3& min, const float3& max)
{
- BB.Min = min;
- BB.Max = max;
+ BB.Min = min;
+ BB.Max = max;
IsValidBB = true;
}
};
@@ -141,7 +143,7 @@ struct Mesh
float4x4 matrix;
float4x4 jointMatrix[MaxNumJoints] = {};
- int jointcount = 0;
+ int jointcount = 0;
};
TransformData Transforms;
@@ -155,7 +157,7 @@ struct Node;
struct Skin
{
std::string Name;
- Node* pSkeletonRoot = nullptr;
+ Node* pSkeletonRoot = nullptr;
std::vector<float4x4> InverseBindMatrices;
std::vector<Node*> Joints;
};
@@ -163,24 +165,26 @@ struct Skin
struct Node
{
- std::string Name;
- Node* Parent = nullptr;
- Uint32 Index;
- std::vector<std::unique_ptr<Node>> Children;
- float4x4 Matrix;
- std::unique_ptr<Mesh> _Mesh;
- Skin* _Skin = nullptr;
- Int32 SkinIndex = -1;
- float3 Translation;
- float3 Scale = float3(1.0f, 1.0f, 1.0f);
- Quaternion Rotation;
- BoundBox BVH;
- BoundBox AABB;
- bool IsValidBVH = false;
-
- float4x4 LocalMatrix()const;
- float4x4 GetMatrix()const;
- void Update();
+ std::string Name;
+ Node* Parent = nullptr;
+ Uint32 Index;
+
+ std::vector<std::unique_ptr<Node>> Children;
+
+ float4x4 Matrix;
+ std::unique_ptr<Mesh> _Mesh;
+ Skin* _Skin = nullptr;
+ Int32 SkinIndex = -1;
+ float3 Translation;
+ float3 Scale = float3(1.0f, 1.0f, 1.0f);
+ Quaternion Rotation;
+ BoundBox BVH;
+ BoundBox AABB;
+ bool IsValidBVH = false;
+
+ float4x4 LocalMatrix() const;
+ float4x4 GetMatrix() const;
+ void Update();
};
@@ -193,8 +197,8 @@ struct AnimationChannel
SCALE
};
PATH_TYPE PathType;
- Node* node = nullptr;
- Uint32 SamplerIndex = static_cast<Uint32>(-1);
+ Node* node = nullptr;
+ Uint32 SamplerIndex = static_cast<Uint32>(-1);
};
@@ -206,16 +210,16 @@ struct AnimationSampler
STEP,
CUBICSPLINE
};
- INTERPOLATION_TYPE Interpolation;
- std::vector<float> Inputs;
- std::vector<float4> OutputsVec4;
+ INTERPOLATION_TYPE Interpolation;
+ std::vector<float> Inputs;
+ std::vector<float4> OutputsVec4;
};
struct Animation
{
- std::string Name;
- std::vector<AnimationSampler> Samplers;
- std::vector<AnimationChannel> Channels;
+ std::string Name;
+ std::vector<AnimationSampler> Samplers;
+ std::vector<AnimationChannel> Channels;
float Start = std::numeric_limits<float>::max();
float End = std::numeric_limits<float>::min();
@@ -247,46 +251,45 @@ struct Model
std::vector<RefCntAutoPtr<ITexture>> Textures;
std::vector<RefCntAutoPtr<ISampler>> TextureSamplers;
- std::vector<Material> Materials;
- std::vector<Animation> Animations;
- std::vector<std::string> Extensions;
+ std::vector<Material> Materials;
+ std::vector<Animation> Animations;
+ std::vector<std::string> Extensions;
struct Dimensions
{
- float3 min = float3(+FLT_MAX, +FLT_MAX, +FLT_MAX);
- float3 max = float3(-FLT_MAX, -FLT_MAX, -FLT_MAX);
+ float3 min = float3{+FLT_MAX, +FLT_MAX, +FLT_MAX};
+ float3 max = float3{-FLT_MAX, -FLT_MAX, -FLT_MAX};
} dimensions;
- Model(IRenderDevice* pDevice, IDeviceContext* pContext, const std::string &filename);
+ Model(IRenderDevice* pDevice, IDeviceContext* pContext, const std::string& filename);
void UpdateAnimation(Uint32 index, float time);
private:
- void LoadFromFile(IRenderDevice* pDevice, IDeviceContext* pContext, const std::string &filename);
- void LoadNode(IRenderDevice* pDevice,
- Node* parent,
- const tinygltf::Node& gltf_node,
- uint32_t nodeIndex,
- const tinygltf::Model& gltf_model,
- std::vector<uint32_t>& indexBuffer,
- std::vector<Vertex>& vertexBuffer);
+ void LoadFromFile(IRenderDevice* pDevice, IDeviceContext* pContext, const std::string& filename);
+ void LoadNode(IRenderDevice* pDevice,
+ Node* parent,
+ const tinygltf::Node& gltf_node,
+ uint32_t nodeIndex,
+ const tinygltf::Model& gltf_model,
+ std::vector<uint32_t>& indexBuffer,
+ std::vector<Vertex>& vertexBuffer);
void LoadSkins(const tinygltf::Model& gltf_model);
- void LoadTextures(IRenderDevice* pDevice,
- IDeviceContext* pCtx,
- const tinygltf::Model& gltf_model);
+ void LoadTextures(IRenderDevice* pDevice,
+ IDeviceContext* pCtx,
+ const tinygltf::Model& gltf_model);
- void LoadTextureSamplers(IRenderDevice* pDevice, const tinygltf::Model& gltf_model);
- void LoadMaterials(const tinygltf::Model& gltf_model);
- void LoadAnimations(const tinygltf::Model& gltf_model);
- void CalculateBoundingBox(Node* node, const Node* parent);
- void GetSceneDimensions();
+ void LoadTextureSamplers(IRenderDevice* pDevice, const tinygltf::Model& gltf_model);
+ void LoadMaterials(const tinygltf::Model& gltf_model);
+ void LoadAnimations(const tinygltf::Model& gltf_model);
+ void CalculateBoundingBox(Node* node, const Node* parent);
+ void GetSceneDimensions();
Node* FindNode(Node* parent, Uint32 index);
Node* NodeFromIndex(uint32_t index);
};
-
} // namespace GLTF
} // namespace Diligent
diff --git a/AssetLoader/src/DXSDKMeshLoader.cpp b/AssetLoader/src/DXSDKMeshLoader.cpp
index e81d24e..00049f2 100644
--- a/AssetLoader/src/DXSDKMeshLoader.cpp
+++ b/AssetLoader/src/DXSDKMeshLoader.cpp
@@ -36,7 +36,7 @@ namespace Diligent
//--------------------------------------------------------------------------------------
-bool DXSDKMesh::CreateFromFile( const char* szFileName )
+bool DXSDKMesh::CreateFromFile(const char* szFileName)
{
FileWrapper File;
File.Open(FileOpenAttribs{szFileName});
@@ -51,40 +51,42 @@ bool DXSDKMesh::CreateFromFile( const char* szFileName )
File.Close();
- auto res = CreateFromMemory( reinterpret_cast<Uint8*>(pFileData->GetDataPtr()),
- static_cast<Uint32>(pFileData->GetSize()));
-
+ auto res = CreateFromMemory(reinterpret_cast<Uint8*>(pFileData->GetDataPtr()),
+ static_cast<Uint32>(pFileData->GetSize()));
+
return res;
}
void DXSDKMesh::ComputeBoundingBoxes()
{
- for( Uint32 i = 0; i < m_pMeshHeader->NumMeshes; i++ )
+ for (Uint32 i = 0; i < m_pMeshHeader->NumMeshes; i++)
{
auto& Mesh = m_pMeshArray[i];
- float3 Min(+FLT_MAX, +FLT_MAX, +FLT_MAX);
- float3 Max(-FLT_MAX, -FLT_MAX, -FLT_MAX);
- const auto& VertexData = m_pVertexBufferArray[ Mesh.VertexBuffers[0] ];
- auto* PosDecl = VertexData.Decl;
+
+ float3 Min{+FLT_MAX, +FLT_MAX, +FLT_MAX};
+ float3 Max{-FLT_MAX, -FLT_MAX, -FLT_MAX};
+
+ const auto& VertexData = m_pVertexBufferArray[Mesh.VertexBuffers[0]];
+ auto* PosDecl = VertexData.Decl;
while (PosDecl->Stream != 0xFF && PosDecl->Usage != DXSDKMESH_VERTEX_SEMANTIC_POSITION)
++PosDecl;
VERIFY(PosDecl->Stream != 0xFF, "Position semantic not found in this buffer");
VERIFY(PosDecl->Type == DXSDKMESH_VERTEX_DATA_TYPE_FLOAT3, "Vertex is expected to be a 3-component float vector");
-
- auto IndexType = GetIndexType(i);
- const auto* Vertices = GetRawVerticesAt(Mesh.VertexBuffers[0]);
- const auto* Indices = GetRawIndicesAt(Mesh.IndexBuffer);
- auto Stride = GetVertexStride(Mesh.VertexBuffers[0]);
- for(Uint32 subsetIdx = 0; subsetIdx < Mesh.NumSubsets; ++subsetIdx)
+
+ auto IndexType = GetIndexType(i);
+ const auto* Vertices = GetRawVerticesAt(Mesh.VertexBuffers[0]);
+ const auto* Indices = GetRawIndicesAt(Mesh.IndexBuffer);
+ auto Stride = GetVertexStride(Mesh.VertexBuffers[0]);
+ for (Uint32 subsetIdx = 0; subsetIdx < Mesh.NumSubsets; ++subsetIdx)
{
- auto& Subset = m_pSubsetArray[ Mesh.pSubsets[subsetIdx] ];
-
- for(Uint32 v = 0; v < Subset.IndexCount; ++v)
+ auto& Subset = m_pSubsetArray[Mesh.pSubsets[subsetIdx]];
+
+ for (Uint32 v = 0; v < Subset.IndexCount; ++v)
{
Uint32 Index = IndexType == IT_16BIT ?
- reinterpret_cast<const Uint16*>(Indices)[Subset.IndexStart + v] :
+ reinterpret_cast<const Uint16*>(Indices)[Subset.IndexStart + v] :
reinterpret_cast<const Uint32*>(Indices)[Subset.IndexStart + v];
- const float3& Vertex =
+ const float3& Vertex =
reinterpret_cast<const float3&>(Vertices[Index * Stride + PosDecl->Offset]);
Min = std::min(Min, Vertex);
Max = std::max(Max, Vertex);
@@ -95,25 +97,27 @@ void DXSDKMesh::ComputeBoundingBoxes()
}
}
-bool DXSDKMesh::CreateFromMemory( Uint8* pData,
- Uint32 DataUint8s )
+bool DXSDKMesh::CreateFromMemory(Uint8* pData,
+ Uint32 DataUint8s)
{
m_StaticMeshData.resize(DataUint8s);
memcpy(m_StaticMeshData.data(), pData, DataUint8s);
// Pointer fixup
auto* pStaticMeshData = m_StaticMeshData.data();
- m_pMeshHeader = reinterpret_cast<DXSDKMESH_HEADER*> (pStaticMeshData);
+
+ // clang-format off
m_pVertexBufferArray = reinterpret_cast<DXSDKMESH_VERTEX_BUFFER_HEADER*>(pStaticMeshData + m_pMeshHeader->VertexStreamHeadersOffset);
m_pIndexBufferArray = reinterpret_cast<DXSDKMESH_INDEX_BUFFER_HEADER*> (pStaticMeshData + m_pMeshHeader->IndexStreamHeadersOffset);
m_pMeshArray = reinterpret_cast<DXSDKMESH_MESH*> (pStaticMeshData + m_pMeshHeader->MeshDataOffset);
m_pSubsetArray = reinterpret_cast<DXSDKMESH_SUBSET*> (pStaticMeshData + m_pMeshHeader->SubsetDataOffset);
m_pFrameArray = reinterpret_cast<DXSDKMESH_FRAME*> (pStaticMeshData + m_pMeshHeader->FrameDataOffset);
m_pMaterialArray = reinterpret_cast<DXSDKMESH_MATERIAL*> (pStaticMeshData + m_pMeshHeader->MaterialDataOffset);
+ // clang-format on
- for( Uint32 i = 0; i < m_pMeshHeader->NumMaterials; i++ )
+ for (Uint32 i = 0; i < m_pMeshHeader->NumMaterials; i++)
{
- auto& Mat = m_pMaterialArray[i];
+ auto& Mat = m_pMaterialArray[i];
Mat.pDiffuseTexture = nullptr;
Mat.pNormalTexture = nullptr;
Mat.pSpecularTexture = nullptr;
@@ -123,14 +127,14 @@ bool DXSDKMesh::CreateFromMemory( Uint8* pData,
}
// Setup subsets
- for( Uint32 i = 0; i < m_pMeshHeader->NumMeshes; i++ )
+ for (Uint32 i = 0; i < m_pMeshHeader->NumMeshes; i++)
{
m_pMeshArray[i].pSubsets = reinterpret_cast<Uint32*>(pStaticMeshData + m_pMeshArray[i].SubsetOffset);
m_pMeshArray[i].pFrameInfluences = reinterpret_cast<Uint32*>(pStaticMeshData + m_pMeshArray[i].FrameInfluenceOffset);
}
// error condition
- if( m_pMeshHeader->Version != DXSDKMESH_FILE_VERSION )
+ if (m_pMeshHeader->Version != DXSDKMESH_FILE_VERSION)
{
LOG_ERROR("Unexpected SDK mesh file version");
return false;
@@ -144,16 +148,16 @@ bool DXSDKMesh::CreateFromMemory( Uint8* pData,
// Create VBs
m_ppVertices.resize(m_pMeshHeader->NumVertexBuffers);
- for( Uint32 i = 0; i < m_pMeshHeader->NumVertexBuffers; i++ )
+ for (Uint32 i = 0; i < m_pMeshHeader->NumVertexBuffers; i++)
{
- m_ppVertices[i] = reinterpret_cast<Uint8*>(pBufferData + ( m_pVertexBufferArray[i].DataOffset - BufferDataStart));
+ m_ppVertices[i] = reinterpret_cast<Uint8*>(pBufferData + (m_pVertexBufferArray[i].DataOffset - BufferDataStart));
}
// Create IBs
m_ppIndices.resize(m_pMeshHeader->NumIndexBuffers);
- for( Uint32 i = 0; i < m_pMeshHeader->NumIndexBuffers; i++ )
+ for (Uint32 i = 0; i < m_pMeshHeader->NumIndexBuffers; i++)
{
- m_ppIndices[i] = reinterpret_cast<Uint8*>( pBufferData + ( m_pIndexBufferArray[i].DataOffset - BufferDataStart ) );
+ m_ppIndices[i] = reinterpret_cast<Uint8*>(pBufferData + (m_pIndexBufferArray[i].DataOffset - BufferDataStart));
}
ComputeBoundingBoxes();
@@ -194,7 +198,7 @@ static void LoadTexture(IRenderDevice* pDevice,
void DXSDKMesh::LoadGPUResources(const Char* ResourceDirectory, IRenderDevice* pDevice, IDeviceContext* pDeviceCtx)
{
std::vector<StateTransitionDesc> Barriers;
- for( Uint32 i = 0; i < m_pMeshHeader->NumMaterials; i++ )
+ for (Uint32 i = 0; i < m_pMeshHeader->NumMaterials; i++)
{
auto& Mat = m_pMaterialArray[i];
if (Mat.DiffuseTexture[0] != 0)
@@ -214,14 +218,14 @@ void DXSDKMesh::LoadGPUResources(const Char* ResourceDirectory, IRenderDevice* p
}
m_VertexBuffers.resize(m_pMeshHeader->NumVertexBuffers);
- for( Uint32 i = 0; i < m_pMeshHeader->NumVertexBuffers; i++ )
+ for (Uint32 i = 0; i < m_pMeshHeader->NumVertexBuffers; i++)
{
const auto& VBArr = m_pVertexBufferArray[i];
std::stringstream ss;
ss << "DXSDK Mesh vertex buffer #" << i;
- std::string VBName = ss.str();
- BufferDesc VBDesc;
+ std::string VBName = ss.str();
+ BufferDesc VBDesc;
VBDesc.Name = VBName.c_str();
VBDesc.Usage = USAGE_STATIC;
VBDesc.uiSizeInBytes = static_cast<Uint32>(VBArr.NumVertices * VBArr.StrideUint8s);
@@ -235,18 +239,18 @@ void DXSDKMesh::LoadGPUResources(const Char* ResourceDirectory, IRenderDevice* p
// Create IBs
m_IndexBuffers.resize(m_pMeshHeader->NumIndexBuffers);
- for( Uint32 i = 0; i < m_pMeshHeader->NumIndexBuffers; i++ )
+ for (Uint32 i = 0; i < m_pMeshHeader->NumIndexBuffers; i++)
{
const auto& IBArr = m_pIndexBufferArray[i];
std::stringstream ss;
ss << "DXSDK Mesh index buffer #" << i;
- std::string IBName = ss.str();
+ std::string IBName = ss.str();
BufferDesc IBDesc;
IBDesc.Name = IBName.c_str();
IBDesc.Usage = USAGE_STATIC;
- IBDesc.uiSizeInBytes = static_cast<Uint32>(IBArr.NumIndices * (IBArr.IndexType == IT_16BIT ? 2 : 4));
+ IBDesc.uiSizeInBytes = static_cast<Uint32>(IBArr.NumIndices * (IBArr.IndexType == IT_16BIT ? 2 : 4));
IBDesc.BindFlags = BIND_INDEX_BUFFER;
BufferData InitData{GetRawIndicesAt(i), static_cast<Uint32>(IBArr.SizeUint8s)};
@@ -265,21 +269,21 @@ DXSDKMesh::~DXSDKMesh()
}
//--------------------------------------------------------------------------------------
-bool DXSDKMesh::Create( const Char* szFileName )
+bool DXSDKMesh::Create(const Char* szFileName)
{
- return CreateFromFile( szFileName );
+ return CreateFromFile(szFileName);
}
//--------------------------------------------------------------------------------------
-bool DXSDKMesh::Create( Uint8* pData, Uint32 DataUint8s )
+bool DXSDKMesh::Create(Uint8* pData, Uint32 DataUint8s)
{
- return CreateFromMemory( pData, DataUint8s );
+ return CreateFromMemory(pData, DataUint8s);
}
//--------------------------------------------------------------------------------------
void DXSDKMesh::Destroy()
{
- for( Uint32 i = 0; i < m_pMeshHeader->NumMaterials; i++ )
+ for (Uint32 i = 0; i < m_pMeshHeader->NumMaterials; i++)
{
auto& Mat = m_pMaterialArray[i];
if (Mat.pDiffuseTexture)
@@ -307,7 +311,7 @@ void DXSDKMesh::Destroy()
m_StaticMeshData.clear();
//delete[] m_pAdjacencyIndexBufferArray; m_pAdjacencyIndexBufferArray = nullptr;
-
+
//delete[] m_pAnimationData; m_pAnimationData = nullptr;
//delete[] m_pBindPoseFrameMatrices; m_pBindPoseFrameMatrices = nullptr;
//delete[] m_pTransformedFrameMatrices; m_pTransformedFrameMatrices = nullptr;
@@ -330,41 +334,41 @@ void DXSDKMesh::Destroy()
//--------------------------------------------------------------------------------------
-PRIMITIVE_TOPOLOGY DXSDKMesh::GetPrimitiveType( DXSDKMESH_PRIMITIVE_TYPE PrimType )
+PRIMITIVE_TOPOLOGY DXSDKMesh::GetPrimitiveType(DXSDKMESH_PRIMITIVE_TYPE PrimType)
{
- switch( PrimType )
+ switch (PrimType)
{
case PT_TRIANGLE_LIST:
return PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
-
+
case PT_TRIANGLE_STRIP:
return PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
-
+
case PT_LINE_LIST:
return PRIMITIVE_TOPOLOGY_LINE_LIST;
-
+
case PT_LINE_STRIP:
return PRIMITIVE_TOPOLOGY_UNDEFINED;
-
+
case PT_POINT_LIST:
return PRIMITIVE_TOPOLOGY_POINT_LIST;
-
+
case PT_TRIANGLE_LIST_ADJ:
UNEXPECTED("Unsupported primitive topolgy type");
- return PRIMITIVE_TOPOLOGY_UNDEFINED;// PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ;
-
+ return PRIMITIVE_TOPOLOGY_UNDEFINED; // PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ;
+
case PT_TRIANGLE_STRIP_ADJ:
UNEXPECTED("Unsupported primitive topolgy type");
- return PRIMITIVE_TOPOLOGY_UNDEFINED;// PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ;
-
+ return PRIMITIVE_TOPOLOGY_UNDEFINED; // PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ;
+
case PT_LINE_LIST_ADJ:
UNEXPECTED("Unsupported primitive topolgy type");
- return PRIMITIVE_TOPOLOGY_UNDEFINED;// PRIMITIVE_TOPOLOGY_LINELIST_ADJ;
-
+ return PRIMITIVE_TOPOLOGY_UNDEFINED; // PRIMITIVE_TOPOLOGY_LINELIST_ADJ;
+
case PT_LINE_STRIP_ADJ:
UNEXPECTED("Unsupported primitive topolgy type");
- return PRIMITIVE_TOPOLOGY_UNDEFINED;// D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ;
-
+ return PRIMITIVE_TOPOLOGY_UNDEFINED; // D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ;
+
default:
UNEXPECTED("Unknown primitive topolgy type");
return PRIMITIVE_TOPOLOGY_UNDEFINED;
@@ -372,9 +376,9 @@ PRIMITIVE_TOPOLOGY DXSDKMesh::GetPrimitiveType( DXSDKMESH_PRIMITIVE_TYPE PrimTyp
}
//--------------------------------------------------------------------------------------
-VALUE_TYPE DXSDKMesh::GetIBFormat( Uint32 iMesh )const
+VALUE_TYPE DXSDKMesh::GetIBFormat(Uint32 iMesh) const
{
- switch( m_pIndexBufferArray[ m_pMeshArray[ iMesh ].IndexBuffer ].IndexType )
+ switch (m_pIndexBufferArray[m_pMeshArray[iMesh].IndexBuffer].IndexType)
{
case IT_16BIT:
return VT_UINT16;
@@ -386,4 +390,4 @@ VALUE_TYPE DXSDKMesh::GetIBFormat( Uint32 iMesh )const
}
}
-} \ No newline at end of file
+} // namespace Diligent
diff --git a/AssetLoader/src/GLTFLoader.cpp b/AssetLoader/src/GLTFLoader.cpp
index a008965..db80ea6 100644
--- a/AssetLoader/src/GLTFLoader.cpp
+++ b/AssetLoader/src/GLTFLoader.cpp
@@ -53,6 +53,7 @@ RefCntAutoPtr<ITexture> TextureFromGLTFImage(IRenderDevice* pDevice,
ISampler* pSampler)
{
std::vector<Uint8> RGBA;
+
const Uint8* pTextureData = nullptr;
if (gltfimage.component == 3)
{
@@ -66,7 +67,7 @@ RefCntAutoPtr<ITexture> TextureFromGLTFImage(IRenderDevice* pDevice,
rgba[j] = rgb[j];
}
rgba += 4;
- rgb += 3;
+ rgb += 3;
}
pTextureData = RGBA.data();
}
@@ -80,22 +81,22 @@ RefCntAutoPtr<ITexture> TextureFromGLTFImage(IRenderDevice* pDevice,
}
TextureDesc TexDesc;
- TexDesc.Name = "GLTF Texture";
- TexDesc.Type = RESOURCE_DIM_TEX_2D;
- TexDesc.Usage = USAGE_DEFAULT;
- TexDesc.BindFlags = BIND_SHADER_RESOURCE;
- TexDesc.Width = gltfimage.width;
- TexDesc.Height = gltfimage.height;
- TexDesc.Format = TEX_FORMAT_RGBA8_UNORM;
- TexDesc.MipLevels = 0;
- TexDesc.MiscFlags = MISC_TEXTURE_FLAG_GENERATE_MIPS;
+ TexDesc.Name = "GLTF Texture";
+ TexDesc.Type = RESOURCE_DIM_TEX_2D;
+ TexDesc.Usage = USAGE_DEFAULT;
+ TexDesc.BindFlags = BIND_SHADER_RESOURCE;
+ TexDesc.Width = gltfimage.width;
+ TexDesc.Height = gltfimage.height;
+ TexDesc.Format = TEX_FORMAT_RGBA8_UNORM;
+ TexDesc.MipLevels = 0;
+ TexDesc.MiscFlags = MISC_TEXTURE_FLAG_GENERATE_MIPS;
RefCntAutoPtr<ITexture> pTexture;
pDevice->CreateTexture(TexDesc, nullptr, &pTexture);
Box UpdateBox;
UpdateBox.MaxX = TexDesc.Width;
UpdateBox.MaxY = TexDesc.Height;
- TextureSubResData Level0Data(pTextureData, gltfimage.width*4);
+ TextureSubResData Level0Data(pTextureData, gltfimage.width * 4);
pCtx->UpdateTexture(pTexture, 0, 0, UpdateBox, Level0Data, RESOURCE_STATE_TRANSITION_MODE_NONE, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
pTexture->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE)->SetSampler(pSampler);
@@ -111,8 +112,8 @@ Mesh::Mesh(IRenderDevice* pDevice, const float4x4& matrix)
void Mesh::SetBoundingBox(const float3& min, const float3& max)
{
- BB.Min = min;
- BB.Max = max;
+ BB.Min = min;
+ BB.Max = max;
IsValidBB = true;
}
@@ -120,16 +121,16 @@ void Mesh::SetBoundingBox(const float3& min, const float3& max)
-float4x4 Node::LocalMatrix()const
+float4x4 Node::LocalMatrix() const
{
return Matrix * float4x4::Scale(Scale) * Rotation.ToMatrix() * float4x4::Translation(Translation);
}
-float4x4 Node::GetMatrix()const
+float4x4 Node::GetMatrix() const
{
- auto mat = LocalMatrix();
-
- for(auto* p = Parent; p != nullptr; p = p->Parent)
+ auto mat = LocalMatrix();
+
+ for (auto* p = Parent; p != nullptr; p = p->Parent)
{
mat = mat * p->LocalMatrix();
}
@@ -144,19 +145,21 @@ void Node::Update()
if (_Skin != nullptr)
{
// Update join matrices
- auto InverseTransform = _Mesh->Transforms.matrix.Inverse(); // TODO: do not use inverse tranform here
- size_t numJoints = std::min((uint32_t)_Skin->Joints.size(), Uint32{Mesh::TransformData::MaxNumJoints});
+ auto InverseTransform = _Mesh->Transforms.matrix.Inverse(); // TODO: do not use inverse tranform here
+ size_t numJoints = std::min((uint32_t)_Skin->Joints.size(), Uint32{Mesh::TransformData::MaxNumJoints});
for (size_t i = 0; i < numJoints; i++)
{
auto* JointNode = _Skin->Joints[i];
- auto JointMat = _Skin->InverseBindMatrices[i] * JointNode->GetMatrix() * InverseTransform;
+ auto JointMat = _Skin->InverseBindMatrices[i] * JointNode->GetMatrix() * InverseTransform;
+
_Mesh->Transforms.jointMatrix[i] = JointMat;
}
_Mesh->Transforms.jointcount = static_cast<int>(numJoints);
}
}
- for (auto& child : Children) {
+ for (auto& child : Children)
+ {
child->Update();
}
}
@@ -164,25 +167,25 @@ void Node::Update()
-Model::Model(IRenderDevice* pDevice, IDeviceContext* pContext, const std::string &filename)
+Model::Model(IRenderDevice* pDevice, IDeviceContext* pContext, const std::string& filename)
{
LoadFromFile(pDevice, pContext, filename);
}
-void Model::LoadNode(IRenderDevice* pDevice,
- Node* parent,
- const tinygltf::Node& gltf_node,
- uint32_t nodeIndex,
- const tinygltf::Model& gltf_model,
- std::vector<uint32_t>& indexBuffer,
- std::vector<Vertex>& vertexBuffer)
+void Model::LoadNode(IRenderDevice* pDevice,
+ Node* parent,
+ const tinygltf::Node& gltf_node,
+ uint32_t nodeIndex,
+ const tinygltf::Model& gltf_model,
+ std::vector<uint32_t>& indexBuffer,
+ std::vector<Vertex>& vertexBuffer)
{
std::unique_ptr<Node> NewNode(new Node{});
- NewNode->Index = nodeIndex;
- NewNode->Parent = parent;
- NewNode->Name = gltf_node.name;
- NewNode->SkinIndex = gltf_node.skin;
- NewNode->Matrix = float4x4::Identity();
+ NewNode->Index = nodeIndex;
+ NewNode->Parent = parent;
+ NewNode->Name = gltf_node.name;
+ NewNode->SkinIndex = gltf_node.skin;
+ NewNode->Matrix = float4x4::Identity();
// Generate local node matrix
//float3 Translation;
@@ -224,14 +227,15 @@ void Model::LoadNode(IRenderDevice* pDevice,
for (size_t j = 0; j < gltf_mesh.primitives.size(); j++)
{
const tinygltf::Primitive& primitive = gltf_mesh.primitives[j];
+
uint32_t indexStart = static_cast<uint32_t>(indexBuffer.size());
uint32_t vertexStart = static_cast<uint32_t>(vertexBuffer.size());
uint32_t indexCount = 0;
uint32_t vertexCount = 0;
- float3 PosMin;
- float3 PosMax;
- bool hasSkin = false;
- bool hasIndices = primitive.indices > -1;
+ float3 PosMin;
+ float3 PosMax;
+ bool hasSkin = false;
+ bool hasIndices = primitive.indices > -1;
// Vertices
{
@@ -247,20 +251,21 @@ void Model::LoadNode(IRenderDevice* pDevice,
const tinygltf::Accessor& posAccessor = gltf_model.accessors[position_it->second];
const tinygltf::BufferView& posView = gltf_model.bufferViews[posAccessor.bufferView];
+
bufferPos = reinterpret_cast<const float*>(&(gltf_model.buffers[posView.buffer].data[posAccessor.byteOffset + posView.byteOffset]));
- PosMin =
- float3
+ PosMin =
+ float3 //
{
static_cast<float>(posAccessor.minValues[0]),
static_cast<float>(posAccessor.minValues[1]),
- static_cast<float>(posAccessor.minValues[2])
+ static_cast<float>(posAccessor.minValues[2]) //
};
PosMax =
- float3
+ float3 //
{
static_cast<float>(posAccessor.maxValues[0]),
static_cast<float>(posAccessor.maxValues[1]),
- static_cast<float>(posAccessor.maxValues[2])
+ static_cast<float>(posAccessor.maxValues[2]) //
};
vertexCount = static_cast<uint32_t>(posAccessor.count);
@@ -268,20 +273,23 @@ void Model::LoadNode(IRenderDevice* pDevice,
if (primitive.attributes.find("NORMAL") != primitive.attributes.end())
{
const tinygltf::Accessor& normAccessor = gltf_model.accessors[primitive.attributes.find("NORMAL")->second];
- const tinygltf::BufferView& normView = gltf_model.bufferViews[normAccessor.bufferView];
+ const tinygltf::BufferView& normView = gltf_model.bufferViews[normAccessor.bufferView];
+
bufferNormals = reinterpret_cast<const float*>(&(gltf_model.buffers[normView.buffer].data[normAccessor.byteOffset + normView.byteOffset]));
}
if (primitive.attributes.find("TEXCOORD_0") != primitive.attributes.end())
{
const tinygltf::Accessor& uvAccessor = gltf_model.accessors[primitive.attributes.find("TEXCOORD_0")->second];
- const tinygltf::BufferView& uvView = gltf_model.bufferViews[uvAccessor.bufferView];
+ const tinygltf::BufferView& uvView = gltf_model.bufferViews[uvAccessor.bufferView];
+
bufferTexCoordSet0 = reinterpret_cast<const float*>(&(gltf_model.buffers[uvView.buffer].data[uvAccessor.byteOffset + uvView.byteOffset]));
}
if (primitive.attributes.find("TEXCOORD_1") != primitive.attributes.end())
{
const tinygltf::Accessor& uvAccessor = gltf_model.accessors[primitive.attributes.find("TEXCOORD_1")->second];
- const tinygltf::BufferView& uvView = gltf_model.bufferViews[uvAccessor.bufferView];
+ const tinygltf::BufferView& uvView = gltf_model.bufferViews[uvAccessor.bufferView];
+
bufferTexCoordSet1 = reinterpret_cast<const float*>(&(gltf_model.buffers[uvView.buffer].data[uvAccessor.byteOffset + uvView.byteOffset]));
}
@@ -290,14 +298,16 @@ void Model::LoadNode(IRenderDevice* pDevice,
if (primitive.attributes.find("JOINTS_0") != primitive.attributes.end())
{
const tinygltf::Accessor& jointAccessor = gltf_model.accessors[primitive.attributes.find("JOINTS_0")->second];
- const tinygltf::BufferView& jointView = gltf_model.bufferViews[jointAccessor.bufferView];
+ const tinygltf::BufferView& jointView = gltf_model.bufferViews[jointAccessor.bufferView];
+
bufferJoints = reinterpret_cast<const uint16_t*>(&(gltf_model.buffers[jointView.buffer].data[jointAccessor.byteOffset + jointView.byteOffset]));
}
if (primitive.attributes.find("WEIGHTS_0") != primitive.attributes.end())
{
const tinygltf::Accessor& uvAccessor = gltf_model.accessors[primitive.attributes.find("WEIGHTS_0")->second];
- const tinygltf::BufferView& uvView = gltf_model.bufferViews[uvAccessor.bufferView];
+ const tinygltf::BufferView& uvView = gltf_model.bufferViews[uvAccessor.bufferView];
+
bufferWeights = reinterpret_cast<const float*>(&(gltf_model.buffers[uvView.buffer].data[uvAccessor.byteOffset + uvView.byteOffset]));
}
@@ -306,14 +316,16 @@ void Model::LoadNode(IRenderDevice* pDevice,
for (size_t v = 0; v < posAccessor.count; v++)
{
Vertex vert{};
- vert.pos = float4(float3::MakeVector(&bufferPos[v * 3]), 1.0f);
+ vert.pos = float4(float3::MakeVector(&bufferPos[v * 3]), 1.0f);
+ // clang-format off
vert.normal = bufferNormals != nullptr ? normalize(float3::MakeVector(&bufferNormals[v * 3])) : float3{};
vert.uv0 = bufferTexCoordSet0 != nullptr ? float2::MakeVector(&bufferTexCoordSet0[v * 2]) : float2{};
vert.uv1 = bufferTexCoordSet1 != nullptr ? float2::MakeVector(&bufferTexCoordSet1[v * 2]) : float2{};
+ // clang-format on
if (hasSkin)
{
- vert.joint0 = float4::MakeVector(&bufferJoints [v * 4]);
+ vert.joint0 = float4::MakeVector(&bufferJoints[v * 4]);
vert.weight0 = float4::MakeVector(&bufferWeights[v * 4]);
}
vertexBuffer.push_back(vert);
@@ -323,18 +335,19 @@ void Model::LoadNode(IRenderDevice* pDevice,
// Indices
if (hasIndices)
{
- const tinygltf::Accessor& accessor = gltf_model.accessors[primitive.indices > -1 ? primitive.indices : 0];
- const tinygltf::BufferView& bufferView = gltf_model.bufferViews[accessor.bufferView];
- const tinygltf::Buffer& buffer = gltf_model.buffers[bufferView.buffer];
+ const tinygltf::Accessor& accessor = gltf_model.accessors[primitive.indices > -1 ? primitive.indices : 0];
+ const tinygltf::BufferView& bufferView = gltf_model.bufferViews[accessor.bufferView];
+ const tinygltf::Buffer& buffer = gltf_model.buffers[bufferView.buffer];
indexCount = static_cast<uint32_t>(accessor.count);
- const void *dataPtr = &(buffer.data[accessor.byteOffset + bufferView.byteOffset]);
+
+ const void* dataPtr = &(buffer.data[accessor.byteOffset + bufferView.byteOffset]);
switch (accessor.componentType)
{
case TINYGLTF_PARAMETER_TYPE_UNSIGNED_INT:
{
- const uint32_t *buf = static_cast<const uint32_t*>(dataPtr);
+ const uint32_t* buf = static_cast<const uint32_t*>(dataPtr);
for (size_t index = 0; index < accessor.count; index++)
{
indexBuffer.push_back(buf[index] + vertexStart);
@@ -343,7 +356,7 @@ void Model::LoadNode(IRenderDevice* pDevice,
}
case TINYGLTF_PARAMETER_TYPE_UNSIGNED_SHORT:
{
- const uint16_t *buf = static_cast<const uint16_t*>(dataPtr);
+ const uint16_t* buf = static_cast<const uint16_t*>(dataPtr);
for (size_t index = 0; index < accessor.count; index++)
{
indexBuffer.push_back(buf[index] + vertexStart);
@@ -352,7 +365,7 @@ void Model::LoadNode(IRenderDevice* pDevice,
}
case TINYGLTF_PARAMETER_TYPE_UNSIGNED_BYTE:
{
- const uint8_t *buf = static_cast<const uint8_t*>(dataPtr);
+ const uint8_t* buf = static_cast<const uint8_t*>(dataPtr);
for (size_t index = 0; index < accessor.count; index++)
{
indexBuffer.push_back(buf[index] + vertexStart);
@@ -363,15 +376,15 @@ void Model::LoadNode(IRenderDevice* pDevice,
std::cerr << "Index component type " << accessor.componentType << " not supported!" << std::endl;
return;
}
- }
+ }
std::unique_ptr<Primitive> newPrimitive(
- new Primitive
+ new Primitive //
{
indexStart,
indexCount,
vertexCount,
- primitive.material > -1 ? Materials[primitive.material] : Materials.back()
- }
+ primitive.material > -1 ? Materials[primitive.material] : Materials.back() //
+ } //
);
newPrimitive->SetBoundingBox(PosMin, PosMax);
@@ -409,9 +422,9 @@ void Model::LoadSkins(const tinygltf::Model& gltf_model)
{
for (const auto& source : gltf_model.skins)
{
- std::unique_ptr<Skin> NewSkin( new Skin{} );
+ std::unique_ptr<Skin> NewSkin(new Skin{});
NewSkin->Name = source.name;
-
+
// Find skeleton root node
if (source.skeleton > -1)
{
@@ -431,9 +444,9 @@ void Model::LoadSkins(const tinygltf::Model& gltf_model)
// Get inverse bind matrices from buffer
if (source.inverseBindMatrices > -1)
{
- const tinygltf::Accessor& accessor = gltf_model.accessors[source.inverseBindMatrices];
- const tinygltf::BufferView& bufferView = gltf_model.bufferViews[accessor.bufferView];
- const tinygltf::Buffer& buffer = gltf_model.buffers[bufferView.buffer];
+ const tinygltf::Accessor& accessor = gltf_model.accessors[source.inverseBindMatrices];
+ const tinygltf::BufferView& bufferView = gltf_model.bufferViews[accessor.bufferView];
+ const tinygltf::Buffer& buffer = gltf_model.buffers[bufferView.buffer];
NewSkin->InverseBindMatrices.resize(accessor.count);
memcpy(NewSkin->InverseBindMatrices.data(), &buffer.data[accessor.byteOffset + bufferView.byteOffset], accessor.count * sizeof(float4x4));
}
@@ -443,13 +456,13 @@ void Model::LoadSkins(const tinygltf::Model& gltf_model)
}
-void Model::LoadTextures(IRenderDevice* pDevice,
- IDeviceContext* pCtx,
- const tinygltf::Model& gltf_model)
+void Model::LoadTextures(IRenderDevice* pDevice,
+ IDeviceContext* pCtx,
+ const tinygltf::Model& gltf_model)
{
for (const tinygltf::Texture& gltf_tex : gltf_model.textures)
{
- const tinygltf::Image& gltf_image = gltf_model.images[gltf_tex.source];
+ const tinygltf::Image& gltf_image = gltf_model.images[gltf_tex.source];
RefCntAutoPtr<ISampler> pSampler;
if (gltf_tex.sampler == -1)
{
@@ -479,7 +492,7 @@ void Model::LoadTextures(IRenderDevice* pDevice,
namespace
{
-TEXTURE_ADDRESS_MODE GetWrapMode(int32_t wrapMode)
+TEXTURE_ADDRESS_MODE GetWrapMode(int32_t wrapMode)
{
switch (wrapMode)
{
@@ -495,7 +508,7 @@ TEXTURE_ADDRESS_MODE GetWrapMode(int32_t wrapMode)
}
}
-std::pair<FILTER_TYPE, FILTER_TYPE> GetFilterMode(int32_t filterMode)
+std::pair<FILTER_TYPE, FILTER_TYPE> GetFilterMode(int32_t filterMode)
{
switch (filterMode)
{
@@ -507,9 +520,9 @@ std::pair<FILTER_TYPE, FILTER_TYPE> GetFilterMode(int32_t filterMode)
return {FILTER_TYPE_POINT, FILTER_TYPE_POINT};
case 9985: // LINEAR_MIPMAP_NEAREST
return {FILTER_TYPE_LINEAR, FILTER_TYPE_POINT};
- case 9986: // NEAREST_MIPMAP_LINEAR
+ case 9986: // NEAREST_MIPMAP_LINEAR
return {FILTER_TYPE_LINEAR, FILTER_TYPE_LINEAR}; // use linear min filter instead as point makes no sesne
- case 9987: // LINEAR_MIPMAP_LINEAR
+ case 9987: // LINEAR_MIPMAP_LINEAR
return {FILTER_TYPE_LINEAR, FILTER_TYPE_LINEAR};
default:
LOG_WARNING_MESSAGE("Unknown gltf filter mode: ", filterMode, ". Defaulting to linear.");
@@ -625,7 +638,7 @@ void Model::LoadMaterials(const tinygltf::Model& gltf_model)
if (param.string_value == "MASK")
{
Mat.AlphaCutoff = 0.5f;
- Mat.AlphaMode = Material::ALPHAMODE_MASK;
+ Mat.AlphaMode = Material::ALPHAMODE_MASK;
}
}
}
@@ -637,7 +650,7 @@ void Model::LoadMaterials(const tinygltf::Model& gltf_model)
Mat.AlphaCutoff = static_cast<float>(alpha_cutoff_it->second.Factor());
}
}
-
+
{
auto emissive_fctr_it = gltf_mat.additionalValues.find("emissiveFactor");
if (emissive_fctr_it != gltf_mat.additionalValues.end())
@@ -655,16 +668,16 @@ void Model::LoadMaterials(const tinygltf::Model& gltf_model)
{
if (ext_it->second.Has("specularGlossinessTexture"))
{
- auto index = ext_it->second.Get("specularGlossinessTexture").Get("index");
+ auto index = ext_it->second.Get("specularGlossinessTexture").Get("index");
Mat.extension.pSpecularGlossinessTexture = Textures[index.Get<int>()];
- auto texCoordSet = ext_it->second.Get("specularGlossinessTexture").Get("texCoord");
- Mat.TexCoordSets.SpecularGlossiness = static_cast<Uint8>(texCoordSet.Get<int>());
- Mat.workflow = Material::PbrWorkflow::SpecularGlossiness;
+ auto texCoordSet = ext_it->second.Get("specularGlossinessTexture").Get("texCoord");
+ Mat.TexCoordSets.SpecularGlossiness = static_cast<Uint8>(texCoordSet.Get<int>());
+ Mat.workflow = Material::PbrWorkflow::SpecularGlossiness;
}
if (ext_it->second.Has("diffuseTexture"))
{
- auto index = ext_it->second.Get("diffuseTexture").Get("index");
+ auto index = ext_it->second.Get("diffuseTexture").Get("index");
Mat.extension.pDiffuseTexture = Textures[index.Get<int>()];
}
@@ -673,7 +686,7 @@ void Model::LoadMaterials(const tinygltf::Model& gltf_model)
auto factor = ext_it->second.Get("diffuseFactor");
for (uint32_t i = 0; i < factor.ArrayLen(); i++)
{
- auto val = factor.Get(i);
+ auto val = factor.Get(i);
Mat.extension.DiffuseFactor[i] = val.IsNumber() ? (float)val.Get<double>() : (float)val.Get<int>();
}
}
@@ -683,7 +696,7 @@ void Model::LoadMaterials(const tinygltf::Model& gltf_model)
auto factor = ext_it->second.Get("specularFactor");
for (uint32_t i = 0; i < factor.ArrayLen(); i++)
{
- auto val = factor.Get(i);
+ auto val = factor.Get(i);
Mat.extension.SpecularFactor[i] = val.IsNumber() ? (float)val.Get<double>() : (float)val.Get<int>();
}
}
@@ -710,7 +723,7 @@ void Model::LoadAnimations(const tinygltf::Model& gltf_model)
}
// Samplers
- for (auto &samp : gltf_anim.samplers)
+ for (auto& samp : gltf_anim.samplers)
{
AnimationSampler AnimSampler{};
@@ -735,8 +748,8 @@ void Model::LoadAnimations(const tinygltf::Model& gltf_model)
VERIFY_EXPR(accessor.componentType == TINYGLTF_COMPONENT_TYPE_FLOAT);
- const void *dataPtr = &buffer.data[accessor.byteOffset + bufferView.byteOffset];
- const float *buf = static_cast<const float*>(dataPtr);
+ const void* dataPtr = &buffer.data[accessor.byteOffset + bufferView.byteOffset];
+ const float* buf = static_cast<const float*>(dataPtr);
for (size_t index = 0; index < accessor.count; index++)
{
AnimSampler.Inputs.push_back(buf[index]);
@@ -755,7 +768,7 @@ void Model::LoadAnimations(const tinygltf::Model& gltf_model)
}
}
- // Read sampler output T/R/S values
+ // Read sampler output T/R/S values
{
const tinygltf::Accessor& accessor = gltf_model.accessors[samp.output];
const tinygltf::BufferView& bufferView = gltf_model.bufferViews[accessor.bufferView];
@@ -763,7 +776,7 @@ void Model::LoadAnimations(const tinygltf::Model& gltf_model)
VERIFY_EXPR(accessor.componentType == TINYGLTF_COMPONENT_TYPE_FLOAT);
- const void *dataPtr = &buffer.data[accessor.byteOffset + bufferView.byteOffset];
+ const void* dataPtr = &buffer.data[accessor.byteOffset + bufferView.byteOffset];
switch (accessor.type)
{
@@ -860,11 +873,11 @@ bool LoadImageData(tinygltf::Image* gltf_image,
{
if (error != nullptr)
{
- *error += FormatString("Unknown format for image[", gltf_image_idx, "] name = \"", gltf_image->name, "\"");
+ *error += FormatString("Unknown format for image[", gltf_image_idx, "] name = '", gltf_image->name, "'");
}
return false;
}
-
+
RefCntAutoPtr<DataBlobImpl> pImageData(MakeNewRCObj<DataBlobImpl>()(size));
memcpy(pImageData->GetDataPtr(), image_data, size);
RefCntAutoPtr<Image> pImage;
@@ -873,21 +886,22 @@ bool LoadImageData(tinygltf::Image* gltf_image,
{
if (error != nullptr)
{
- *error += FormatString("Failed to load image[", gltf_image_idx, "] name = \"", gltf_image->name, "\"");
+ *error += FormatString("Failed to load image[", gltf_image_idx, "] name = '", gltf_image->name, "'");
}
return false;
}
const auto& ImgDesc = pImage->GetDesc();
-
+
if (req_width > 0)
{
if (static_cast<Uint32>(req_width) != ImgDesc.Width)
{
- if (error != nullptr)
+ if (error != nullptr)
{
(*error) += FormatString("Image width mismatch for image[",
- gltf_image_idx, "] name = \"", gltf_image->name, "\":"
- " requested width: ", req_width, ", actual width: ",
+ gltf_image_idx, "] name = '", gltf_image->name,
+ "': requested width: ",
+ req_width, ", actual width: ",
ImgDesc.Width);
}
return false;
@@ -898,11 +912,12 @@ bool LoadImageData(tinygltf::Image* gltf_image,
{
if (static_cast<Uint32>(req_height) != ImgDesc.Height)
{
- if (error != nullptr)
+ if (error != nullptr)
{
(*error) += FormatString("Image height mismatch for image[",
- gltf_image_idx, "] name = \"", gltf_image->name, "\":"
- " requested height: ", req_height, ", actual height: ",
+ gltf_image_idx, "] name = '", gltf_image->name,
+ "': requested height: ",
+ req_height, ", actual height: ",
ImgDesc.Height);
}
return false;
@@ -914,18 +929,19 @@ bool LoadImageData(tinygltf::Image* gltf_image,
gltf_image->component = 4;
gltf_image->bits = GetValueSize(ImgDesc.ComponentType) * 8;
gltf_image->pixel_type = TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE;
- auto DstRowSize = gltf_image->width * gltf_image->component * (gltf_image->bits / 8);
+ auto DstRowSize = gltf_image->width * gltf_image->component * (gltf_image->bits / 8);
gltf_image->image.resize(static_cast<size_t>(gltf_image->height * DstRowSize));
- auto* pPixelsBlob = pImage->GetData();
- const Uint8* pSrcPixels = reinterpret_cast<const Uint8*>(pPixelsBlob->GetDataPtr());
+ auto* pPixelsBlob = pImage->GetData();
+ const Uint8* pSrcPixels = reinterpret_cast<const Uint8*>(pPixelsBlob->GetDataPtr());
if (ImgDesc.NumComponents == 3)
{
- for (Uint32 row=0; row < ImgDesc.Height; ++row)
+ for (Uint32 row = 0; row < ImgDesc.Height; ++row)
{
- for (Uint32 col=0; col < ImgDesc.Width; ++col)
+ for (Uint32 col = 0; col < ImgDesc.Width; ++col)
{
- Uint8* DstPixel = gltf_image->image.data() + DstRowSize * row + col * gltf_image->component;
+ Uint8* DstPixel = gltf_image->image.data() + DstRowSize * row + col * gltf_image->component;
const Uint8* SrcPixel = pSrcPixels + ImgDesc.RowStride * row + col * ImgDesc.NumComponents;
+
DstPixel[0] = SrcPixel[0];
DstPixel[1] = SrcPixel[1];
DstPixel[2] = SrcPixel[2];
@@ -933,9 +949,9 @@ bool LoadImageData(tinygltf::Image* gltf_image,
}
}
}
- else if(gltf_image->component == 4)
+ else if (gltf_image->component == 4)
{
- for(Uint32 row=0; row < ImgDesc.Height; ++row)
+ for (Uint32 row = 0; row < ImgDesc.Height; ++row)
{
memcpy(gltf_image->image.data() + DstRowSize * row, pSrcPixels + ImgDesc.RowStride * row, DstRowSize);
}
@@ -978,7 +994,7 @@ bool ReadWholeFile(std::vector<unsigned char>* out,
}
return false;
}
-
+
out->resize(size);
pFile->Read(out->data(), size);
@@ -989,28 +1005,29 @@ bool ReadWholeFile(std::vector<unsigned char>* out,
} // namespace Callbacks
-void Model::LoadFromFile(IRenderDevice* pDevice, IDeviceContext* pContext, const std::string &filename)
+void Model::LoadFromFile(IRenderDevice* pDevice, IDeviceContext* pContext, const std::string& filename)
{
tinygltf::Model gltf_model;
tinygltf::TinyGLTF gltf_context;
gltf_context.SetImageLoader(Callbacks::LoadImageData, this);
tinygltf::FsCallbacks fsCallbacks = {};
- fsCallbacks.ExpandFilePath = tinygltf::ExpandFilePath;
- fsCallbacks.FileExists = Callbacks::FileExists;
- fsCallbacks.ReadWholeFile = Callbacks::ReadWholeFile;
- fsCallbacks.WriteWholeFile = tinygltf::WriteWholeFile;
- fsCallbacks.user_data = this;
+ fsCallbacks.ExpandFilePath = tinygltf::ExpandFilePath;
+ fsCallbacks.FileExists = Callbacks::FileExists;
+ fsCallbacks.ReadWholeFile = Callbacks::ReadWholeFile;
+ fsCallbacks.WriteWholeFile = tinygltf::WriteWholeFile;
+ fsCallbacks.user_data = this;
gltf_context.SetFsCallbacks(fsCallbacks);
- bool binary = false;
+ bool binary = false;
size_t extpos = filename.rfind('.', filename.length());
if (extpos != std::string::npos)
{
binary = (filename.substr(extpos + 1, filename.length() - extpos) == "glb");
- }
+ }
std::string error;
std::string warning;
+
bool fileLoaded;
if (binary)
fileLoaded = gltf_context.LoadBinaryFromFile(&gltf_model, &error, &warning, filename.c_str());
@@ -1025,8 +1042,8 @@ void Model::LoadFromFile(IRenderDevice* pDevice, IDeviceContext* pContext, const
LOG_WARNING_MESSAGE("Loaded gltf file ", filename, " with the following warning:", warning);
}
- std::vector<Uint32> IndexBuffer;
- std::vector<Vertex> VertexBuffer;
+ std::vector<Uint32> IndexBuffer;
+ std::vector<Vertex> VertexBuffer;
LoadTextureSamplers(pDevice, gltf_model);
LoadTextures(pDevice, pContext, gltf_model);
@@ -1066,17 +1083,18 @@ void Model::LoadFromFile(IRenderDevice* pDevice, IDeviceContext* pContext, const
size_t vertexBufferSize = VertexBuffer.size() * sizeof(Vertex);
size_t indexBufferSize = IndexBuffer.size() * sizeof(Uint32);
+
IndexCount = static_cast<Uint32>(IndexBuffer.size());
VERIFY_EXPR(vertexBufferSize > 0);
{
BufferDesc VBDesc;
- VBDesc.Name = "GLTF vertex buffer";
- VBDesc.uiSizeInBytes = static_cast<Uint32>(vertexBufferSize);
- VBDesc.BindFlags = BIND_VERTEX_BUFFER;
- VBDesc.Usage = USAGE_STATIC;
-
+ VBDesc.Name = "GLTF vertex buffer";
+ VBDesc.uiSizeInBytes = static_cast<Uint32>(vertexBufferSize);
+ VBDesc.BindFlags = BIND_VERTEX_BUFFER;
+ VBDesc.Usage = USAGE_STATIC;
+
BufferData BuffData(VertexBuffer.data(), static_cast<Uint32>(vertexBufferSize));
pDevice->CreateBuffer(VBDesc, &BuffData, &pVertexBuffer);
}
@@ -1084,11 +1102,11 @@ void Model::LoadFromFile(IRenderDevice* pDevice, IDeviceContext* pContext, const
if (indexBufferSize > 0)
{
BufferDesc IBDesc;
- IBDesc.Name = "GLTF inde buffer";
- IBDesc.uiSizeInBytes = static_cast<Uint32>(indexBufferSize);
- IBDesc.BindFlags = BIND_INDEX_BUFFER;
- IBDesc.Usage = USAGE_STATIC;
-
+ IBDesc.Name = "GLTF inde buffer";
+ IBDesc.uiSizeInBytes = static_cast<Uint32>(indexBufferSize);
+ IBDesc.BindFlags = BIND_INDEX_BUFFER;
+ IBDesc.Usage = USAGE_STATIC;
+
BufferData BuffData(IndexBuffer.data(), static_cast<Uint32>(indexBufferSize));
pDevice->CreateBuffer(IBDesc, &BuffData, &pIndexBuffer);
}
@@ -1105,20 +1123,23 @@ BoundBox GetAABB(const BoundBox& bb, const float4x4& m)
float3 min = float3::MakeVector(m[3]);
float3 max = min;
float3 v0, v1;
-
+
float3 right = float3::MakeVector(m[0]);
+
v0 = right * bb.Min.x;
v1 = right * bb.Max.x;
min += std::min(v0, v1);
max += std::max(v0, v1);
float3 up = float3::MakeVector(m[1]);
+
v0 = up * bb.Min.y;
v1 = up * bb.Max.y;
min += std::min(v0, v1);
max += std::max(v0, v1);
float3 back = float3::MakeVector(m[2]);
+
v0 = back * bb.Min.z;
v1 = back * bb.Max.z;
min += std::min(v0, v1);
@@ -1127,7 +1148,7 @@ BoundBox GetAABB(const BoundBox& bb, const float4x4& m)
return BoundBox{min, max};
}
-}
+} // namespace
void Model::CalculateBoundingBox(Node* node, const Node* parent)
{
@@ -1140,8 +1161,8 @@ void Model::CalculateBoundingBox(Node* node, const Node* parent)
node->AABB = GetAABB(node->_Mesh->BB, node->GetMatrix());
if (node->Children.empty())
{
- node->BVH.Min = node->AABB.Min;
- node->BVH.Max = node->AABB.Max;
+ node->BVH.Min = node->AABB.Min;
+ node->BVH.Max = node->AABB.Max;
node->IsValidBVH = true;
}
}
@@ -1164,8 +1185,8 @@ void Model::GetSceneDimensions()
CalculateBoundingBox(node, nullptr);
}
- dimensions.min = float3(+FLT_MAX, +FLT_MAX, +FLT_MAX);
- dimensions.max = float3(-FLT_MAX, -FLT_MAX, -FLT_MAX);
+ dimensions.min = float3{+FLT_MAX, +FLT_MAX, +FLT_MAX};
+ dimensions.max = float3{-FLT_MAX, -FLT_MAX, -FLT_MAX};
for (const auto* node : LinearNodes)
{
@@ -1177,13 +1198,13 @@ void Model::GetSceneDimensions()
}
// Calculate scene aabb
- aabb = float4x4::Scale(dimensions.max[0] - dimensions.min[0], dimensions.max[1] - dimensions.min[1], dimensions.max[2] - dimensions.min[2]);
+ aabb = float4x4::Scale(dimensions.max[0] - dimensions.min[0], dimensions.max[1] - dimensions.min[1], dimensions.max[2] - dimensions.min[2]);
aabb[3][0] = dimensions.min[0];
aabb[3][1] = dimensions.min[1];
aabb[3][2] = dimensions.min[2];
}
-void Model::UpdateAnimation(Uint32 index, float time)
+void Model::UpdateAnimation(Uint32 index, float time)
{
if (index > static_cast<Uint32>(Animations.size()) - 1)
{
@@ -1212,14 +1233,14 @@ void Model::UpdateAnimation(Uint32 index, float time)
{
case AnimationChannel::PATH_TYPE::TRANSLATION:
{
- float4 trans = lerp(sampler.OutputsVec4[i], sampler.OutputsVec4[i + 1], u);
+ float4 trans = lerp(sampler.OutputsVec4[i], sampler.OutputsVec4[i + 1], u);
channel.node->Translation = float3(trans);
break;
}
case AnimationChannel::PATH_TYPE::SCALE:
{
- float4 scale = lerp(sampler.OutputsVec4[i], sampler.OutputsVec4[i + 1], u);
+ float4 scale = lerp(sampler.OutputsVec4[i], sampler.OutputsVec4[i + 1], u);
channel.node->Scale = float3(scale);
break;
}
@@ -1237,6 +1258,7 @@ void Model::UpdateAnimation(Uint32 index, float time)
q2.q.y = sampler.OutputsVec4[i + 1].y;
q2.q.z = sampler.OutputsVec4[i + 1].z;
q2.q.w = sampler.OutputsVec4[i + 1].w;
+
channel.node->Rotation = normalize(slerp(q1, q2, u));
break;
}
@@ -1256,7 +1278,7 @@ void Model::UpdateAnimation(Uint32 index, float time)
}
}
-
+
Node* Model::FindNode(Node* parent, Uint32 index)
{
Node* nodeFound = nullptr;
@@ -1279,7 +1301,7 @@ Node* Model::FindNode(Node* parent, Uint32 index)
Node* Model::NodeFromIndex(uint32_t index)
{
Node* nodeFound = nullptr;
- for (auto &node : Nodes)
+ for (auto& node : Nodes)
{
nodeFound = FindNode(node.get(), index);
if (nodeFound)
@@ -1291,6 +1313,6 @@ Node* Model::NodeFromIndex(uint32_t index)
}
-}
+} // namespace GLTF
-}
+} // namespace Diligent