From 103f0c2ab0c9c4c54d168b98a86bc10d0dac0449 Mon Sep 17 00:00:00 2001 From: assiduous Date: Thu, 30 Jan 2020 19:38:22 -0800 Subject: Renamed .h -> .hpp where appropriate --- AssetLoader/interface/DXSDKMeshLoader.h | 437 ------------------------------ AssetLoader/interface/DXSDKMeshLoader.hpp | 437 ++++++++++++++++++++++++++++++ AssetLoader/interface/GLTFLoader.h | 302 --------------------- AssetLoader/interface/GLTFLoader.hpp | 302 +++++++++++++++++++++ 4 files changed, 739 insertions(+), 739 deletions(-) delete mode 100644 AssetLoader/interface/DXSDKMeshLoader.h create mode 100644 AssetLoader/interface/DXSDKMeshLoader.hpp delete mode 100644 AssetLoader/interface/GLTFLoader.h create mode 100644 AssetLoader/interface/GLTFLoader.hpp (limited to 'AssetLoader/interface') diff --git a/AssetLoader/interface/DXSDKMeshLoader.h b/AssetLoader/interface/DXSDKMeshLoader.h deleted file mode 100644 index b27a721..0000000 --- a/AssetLoader/interface/DXSDKMeshLoader.h +++ /dev/null @@ -1,437 +0,0 @@ -/* - * Copyright 2019-2020 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 - -#include "../../../DiligentCore/Primitives/interface/BasicTypes.h" -#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/RenderDevice.h" -#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/DeviceContext.h" -#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/Buffer.h" -#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/Texture.h" -#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/TextureView.h" -#include "../../../DiligentCore/Common/interface/BasicMath.hpp" -#include "../../../DiligentCore/Common/interface/RefCntAutoPtr.hpp" - -namespace Diligent -{ - -//-------------------------------------------------------------------------------------- -// Hard Defines for the various structures -//-------------------------------------------------------------------------------------- -#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 - -// Enumerated Types. -enum DXSDKMESH_PRIMITIVE_TYPE -{ - PT_TRIANGLE_LIST = 0, - PT_TRIANGLE_STRIP, - PT_LINE_LIST, - PT_LINE_STRIP, - PT_POINT_LIST, - PT_TRIANGLE_LIST_ADJ, - PT_TRIANGLE_STRIP_ADJ, - PT_LINE_LIST_ADJ, - PT_LINE_STRIP_ADJ, - PT_QUAD_PATCH_LIST, - PT_TRIANGLE_PATCH_LIST, -}; - -enum DXSDKMESH_INDEX_TYPE -{ - IT_16BIT = 0, - IT_32BIT, -}; - -enum FRAME_TRANSFORM_TYPE -{ - FTT_RELATIVE = 0, - 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. -struct DXSDKMESH_HEADER -{ - //Basic Info and sizes - Uint32 Version; - Uint8 IsBigEndian; - Uint64 HeaderSize; - Uint64 NonBufferDataSize; - Uint64 BufferDataSize; - - //Stats - Uint32 NumVertexBuffers; - Uint32 NumIndexBuffers; - Uint32 NumMeshes; - Uint32 NumTotalSubsets; - Uint32 NumFrames; - Uint32 NumMaterials; - - //Offsets to Data - Uint64 VertexStreamHeadersOffset; - Uint64 IndexStreamHeadersOffset; - Uint64 MeshDataOffset; - Uint64 SubsetDataOffset; - Uint64 FrameDataOffset; - Uint64 MaterialDataOffset; -}; - -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 -}; - -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. -}; - -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 -}; - - -struct DXSDKMESH_VERTEX_BUFFER_HEADER -{ - Uint64 NumVertices; - Uint64 SizeUint8s; - Uint64 StrideUint8s; - - static constexpr size_t MaxVertexElements = 32; - DXSDKMESH_VERTEX_ELEMENT Decl[MaxVertexElements]; - union - { - Uint64 DataOffset; //(This also forces the union to 64bits) - IBuffer* pVB; - }; -}; - -struct DXSDKMESH_INDEX_BUFFER_HEADER -{ - Uint64 NumIndices; - Uint64 SizeUint8s; - Uint32 IndexType; - union - { - Uint64 DataOffset; //(This also forces the union to 64bits) - IBuffer* pIB; - }; -}; - -struct DXSDKMESH_MESH -{ - static constexpr size_t MaxMeshName = 100; - char Name[MaxMeshName]; - Uint8 NumVertexBuffers; - static constexpr size_t MaxVertexStreams = 16; - 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 - }; - union - { - 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; -}; - -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 -}; - -struct DXSDKMESH_MATERIAL -{ - static constexpr size_t MaxMaterialName = 100; - char Name[MaxMaterialName]; - - // Use MaterialInstancePath - static constexpr size_t MaxMaterialPath = 260; - 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]; - - float4 Diffuse; - float4 Ambient; - float4 Specular; - float4 Emissive; - float Power; - - union - { - Uint64 Force64_1; //Force the union to 64bits - ITexture* pDiffuseTexture = nullptr; - }; - union - { - Uint64 Force64_2; //Force the union to 64bits - ITexture* pNormalTexture = nullptr; - }; - union - { - Uint64 Force64_3; //Force the union to 64bits - ITexture* pSpecularTexture = nullptr; - }; - - union - { - Uint64 Force64_4; //Force the union to 64bits - ITextureView* pDiffuseRV = nullptr; - }; - union - { - Uint64 Force64_5; //Force the union to 64bits - ITextureView* pNormalRV = nullptr; - }; - union - { - Uint64 Force64_6; //Force the union to 64bits - ITextureView* pSpecularRV = nullptr; - }; -}; - -struct SDKANIMATION_FILE_HEADER -{ - Uint32 Version; - Uint8 IsBigEndian; - Uint32 FrameTransformType; - Uint32 NumFrames; - Uint32 NumAnimationKeys; - Uint32 AnimationFPS; - Uint64 AnimationDataSize; - Uint64 AnimationDataOffset; -}; - -struct SDKANIMATION_DATA -{ - float3 Translation; - float4 Orientation; - float3 Scaling; -}; - -struct SDKANIMATION_FRAME_DATA -{ - static constexpr size_t MaxFrameName = 100; - char FrameName[MaxFrameName]; - union - { - Uint64 DataOffset; - SDKANIMATION_DATA* pAnimationData; - }; -}; - - -// This class reads the DXSDKMesh file formats -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(); - - //Helpers - 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; - } - - // 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 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]]; - } - - Uint32 GetMeshVertexStride(Uint32 iMesh, Uint32 iVB) const - { - return (Uint32)m_pVertexBufferArray[m_pMeshArray[iMesh].VertexBuffers[iVB]].StrideUint8s; - } - - Uint32 GetVertexStride(Uint32 iVB) const - { - return (Uint32)m_pVertexBufferArray[iVB].StrideUint8s; - } - - Uint64 GetNumMeshVertices(Uint32 iMesh, Uint32 iVB) const - { - return m_pVertexBufferArray[m_pMeshArray[iMesh].VertexBuffers[iVB]].NumVertices; - } - - Uint64 GetNumMeshIndices(Uint32 iMesh) const - { - return m_pIndexBufferArray[m_pMeshArray[iMesh].IndexBuffer].NumIndices; - } - - IBuffer* GetMeshVertexBuffer(Uint32 iMesh, Uint32 iVB) - { - return m_VertexBuffers[m_pMeshArray[iMesh].VertexBuffers[iVB]]; - } - - IBuffer* GetMeshIndexBuffer(Uint32 iMesh) - { - return m_IndexBuffers[m_pMeshArray[iMesh].IndexBuffer]; - } - - 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 CreateFromMemory(Uint8* pData, - Uint32 DataUint8s); - - void ComputeBoundingBoxes(); - - //These are the pointers to the two chunks of data loaded in from the mesh file - std::vector m_StaticMeshData; - //Uint8* m_pAnimationData = nullptr; - std::vector m_ppVertices; - std::vector m_ppIndices; - - std::vector> m_VertexBuffers; - std::vector> 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; - - // Adjacency information (not part of the m_pStaticMeshData, so it must be created and destroyed separately ) - //DXSDKMESH_INDEX_BUFFER_HEADER* m_pAdjacencyIndexBufferArray = nullptr; - - //Animation (TODO: Add ability to load/track multiple animation sets) - //SDKANIMATION_FILE_HEADER* m_pAnimationHeader = nullptr; - //SDKANIMATION_FRAME_DATA* m_pAnimationFrameData = nullptr; - //float4x4* m_pBindPoseFrameMatrices = nullptr; - //float4x4* m_pTransformedFrameMatrices = nullptr; - //float4x4* m_pWorldPoseFrameMatrices = nullptr; -}; - -} // namespace Diligent diff --git a/AssetLoader/interface/DXSDKMeshLoader.hpp b/AssetLoader/interface/DXSDKMeshLoader.hpp new file mode 100644 index 0000000..b27a721 --- /dev/null +++ b/AssetLoader/interface/DXSDKMeshLoader.hpp @@ -0,0 +1,437 @@ +/* + * Copyright 2019-2020 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 + +#include "../../../DiligentCore/Primitives/interface/BasicTypes.h" +#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/RenderDevice.h" +#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/DeviceContext.h" +#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/Buffer.h" +#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/Texture.h" +#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/TextureView.h" +#include "../../../DiligentCore/Common/interface/BasicMath.hpp" +#include "../../../DiligentCore/Common/interface/RefCntAutoPtr.hpp" + +namespace Diligent +{ + +//-------------------------------------------------------------------------------------- +// Hard Defines for the various structures +//-------------------------------------------------------------------------------------- +#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 + +// Enumerated Types. +enum DXSDKMESH_PRIMITIVE_TYPE +{ + PT_TRIANGLE_LIST = 0, + PT_TRIANGLE_STRIP, + PT_LINE_LIST, + PT_LINE_STRIP, + PT_POINT_LIST, + PT_TRIANGLE_LIST_ADJ, + PT_TRIANGLE_STRIP_ADJ, + PT_LINE_LIST_ADJ, + PT_LINE_STRIP_ADJ, + PT_QUAD_PATCH_LIST, + PT_TRIANGLE_PATCH_LIST, +}; + +enum DXSDKMESH_INDEX_TYPE +{ + IT_16BIT = 0, + IT_32BIT, +}; + +enum FRAME_TRANSFORM_TYPE +{ + FTT_RELATIVE = 0, + 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. +struct DXSDKMESH_HEADER +{ + //Basic Info and sizes + Uint32 Version; + Uint8 IsBigEndian; + Uint64 HeaderSize; + Uint64 NonBufferDataSize; + Uint64 BufferDataSize; + + //Stats + Uint32 NumVertexBuffers; + Uint32 NumIndexBuffers; + Uint32 NumMeshes; + Uint32 NumTotalSubsets; + Uint32 NumFrames; + Uint32 NumMaterials; + + //Offsets to Data + Uint64 VertexStreamHeadersOffset; + Uint64 IndexStreamHeadersOffset; + Uint64 MeshDataOffset; + Uint64 SubsetDataOffset; + Uint64 FrameDataOffset; + Uint64 MaterialDataOffset; +}; + +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 +}; + +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. +}; + +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 +}; + + +struct DXSDKMESH_VERTEX_BUFFER_HEADER +{ + Uint64 NumVertices; + Uint64 SizeUint8s; + Uint64 StrideUint8s; + + static constexpr size_t MaxVertexElements = 32; + DXSDKMESH_VERTEX_ELEMENT Decl[MaxVertexElements]; + union + { + Uint64 DataOffset; //(This also forces the union to 64bits) + IBuffer* pVB; + }; +}; + +struct DXSDKMESH_INDEX_BUFFER_HEADER +{ + Uint64 NumIndices; + Uint64 SizeUint8s; + Uint32 IndexType; + union + { + Uint64 DataOffset; //(This also forces the union to 64bits) + IBuffer* pIB; + }; +}; + +struct DXSDKMESH_MESH +{ + static constexpr size_t MaxMeshName = 100; + char Name[MaxMeshName]; + Uint8 NumVertexBuffers; + static constexpr size_t MaxVertexStreams = 16; + 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 + }; + union + { + 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; +}; + +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 +}; + +struct DXSDKMESH_MATERIAL +{ + static constexpr size_t MaxMaterialName = 100; + char Name[MaxMaterialName]; + + // Use MaterialInstancePath + static constexpr size_t MaxMaterialPath = 260; + 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]; + + float4 Diffuse; + float4 Ambient; + float4 Specular; + float4 Emissive; + float Power; + + union + { + Uint64 Force64_1; //Force the union to 64bits + ITexture* pDiffuseTexture = nullptr; + }; + union + { + Uint64 Force64_2; //Force the union to 64bits + ITexture* pNormalTexture = nullptr; + }; + union + { + Uint64 Force64_3; //Force the union to 64bits + ITexture* pSpecularTexture = nullptr; + }; + + union + { + Uint64 Force64_4; //Force the union to 64bits + ITextureView* pDiffuseRV = nullptr; + }; + union + { + Uint64 Force64_5; //Force the union to 64bits + ITextureView* pNormalRV = nullptr; + }; + union + { + Uint64 Force64_6; //Force the union to 64bits + ITextureView* pSpecularRV = nullptr; + }; +}; + +struct SDKANIMATION_FILE_HEADER +{ + Uint32 Version; + Uint8 IsBigEndian; + Uint32 FrameTransformType; + Uint32 NumFrames; + Uint32 NumAnimationKeys; + Uint32 AnimationFPS; + Uint64 AnimationDataSize; + Uint64 AnimationDataOffset; +}; + +struct SDKANIMATION_DATA +{ + float3 Translation; + float4 Orientation; + float3 Scaling; +}; + +struct SDKANIMATION_FRAME_DATA +{ + static constexpr size_t MaxFrameName = 100; + char FrameName[MaxFrameName]; + union + { + Uint64 DataOffset; + SDKANIMATION_DATA* pAnimationData; + }; +}; + + +// This class reads the DXSDKMesh file formats +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(); + + //Helpers + 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; + } + + // 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 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]]; + } + + Uint32 GetMeshVertexStride(Uint32 iMesh, Uint32 iVB) const + { + return (Uint32)m_pVertexBufferArray[m_pMeshArray[iMesh].VertexBuffers[iVB]].StrideUint8s; + } + + Uint32 GetVertexStride(Uint32 iVB) const + { + return (Uint32)m_pVertexBufferArray[iVB].StrideUint8s; + } + + Uint64 GetNumMeshVertices(Uint32 iMesh, Uint32 iVB) const + { + return m_pVertexBufferArray[m_pMeshArray[iMesh].VertexBuffers[iVB]].NumVertices; + } + + Uint64 GetNumMeshIndices(Uint32 iMesh) const + { + return m_pIndexBufferArray[m_pMeshArray[iMesh].IndexBuffer].NumIndices; + } + + IBuffer* GetMeshVertexBuffer(Uint32 iMesh, Uint32 iVB) + { + return m_VertexBuffers[m_pMeshArray[iMesh].VertexBuffers[iVB]]; + } + + IBuffer* GetMeshIndexBuffer(Uint32 iMesh) + { + return m_IndexBuffers[m_pMeshArray[iMesh].IndexBuffer]; + } + + 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 CreateFromMemory(Uint8* pData, + Uint32 DataUint8s); + + void ComputeBoundingBoxes(); + + //These are the pointers to the two chunks of data loaded in from the mesh file + std::vector m_StaticMeshData; + //Uint8* m_pAnimationData = nullptr; + std::vector m_ppVertices; + std::vector m_ppIndices; + + std::vector> m_VertexBuffers; + std::vector> 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; + + // Adjacency information (not part of the m_pStaticMeshData, so it must be created and destroyed separately ) + //DXSDKMESH_INDEX_BUFFER_HEADER* m_pAdjacencyIndexBufferArray = nullptr; + + //Animation (TODO: Add ability to load/track multiple animation sets) + //SDKANIMATION_FILE_HEADER* m_pAnimationHeader = nullptr; + //SDKANIMATION_FRAME_DATA* m_pAnimationFrameData = nullptr; + //float4x4* m_pBindPoseFrameMatrices = nullptr; + //float4x4* m_pTransformedFrameMatrices = nullptr; + //float4x4* m_pWorldPoseFrameMatrices = nullptr; +}; + +} // namespace Diligent diff --git a/AssetLoader/interface/GLTFLoader.h b/AssetLoader/interface/GLTFLoader.h deleted file mode 100644 index 5996999..0000000 --- a/AssetLoader/interface/GLTFLoader.h +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright 2019-2020 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 -#include -#include - -#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/RenderDevice.h" -#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/DeviceContext.h" -#include "../../../DiligentCore/Common/interface/RefCntAutoPtr.hpp" -#include "../../../DiligentCore/Common/interface/AdvancedMath.hpp" - -namespace tinygltf -{ - -class Node; -class Model; - -} // namespace tinygltf - -namespace Diligent -{ - -namespace GLTF -{ - -struct Material -{ - Material() noexcept {} - - enum ALPHA_MODE - { - ALPHAMODE_OPAQUE, - ALPHAMODE_MASK, - ALPHAMODE_BLEND - }; - 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); - - RefCntAutoPtr pBaseColorTexture; - RefCntAutoPtr pMetallicRoughnessTexture; - RefCntAutoPtr pNormalTexture; - RefCntAutoPtr pOcclusionTexture; - RefCntAutoPtr pEmissiveTexture; - - struct TextureCoordinateSets - { - Uint8 BaseColor = 0; - Uint8 MetallicRoughness = 0; - Uint8 SpecularGlossiness = 0; - Uint8 Normal = 0; - Uint8 Occlusion = 0; - Uint8 Emissive = 0; - }; - TextureCoordinateSets TexCoordSets; - - struct Extension - { - RefCntAutoPtr pSpecularGlossinessTexture; - RefCntAutoPtr pDiffuseTexture; - float4 DiffuseFactor = float4(1.0f, 1.0f, 1.0f, 1.0f); - float3 SpecularFactor = float3(1.0f, 1.0f, 1.0f); - }; - Extension extension; - - enum class PbrWorkflow - { - MetallicRoughness, - SpecularGlossiness - }; - PbrWorkflow workflow = PbrWorkflow::MetallicRoughness; -}; - - -struct Primitive -{ - Uint32 FirstIndex = 0; - Uint32 IndexCount = 0; - Uint32 VertexCount = 0; - Material& material; - bool hasIndices; - - BoundBox BB; - bool IsValidBB = false; - - Primitive(Uint32 _FirstIndex, - Uint32 _IndexCount, - Uint32 _VertexCount, - Material& _material) : - 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; - IsValidBB = true; - } -}; - - - -struct Mesh -{ - std::vector> Primitives; - - BoundBox BB; - BoundBox AABB; - bool IsValidBB = false; - - struct TransformData - { - static constexpr Uint32 MaxNumJoints = 128u; - - float4x4 matrix; - float4x4 jointMatrix[MaxNumJoints] = {}; - int jointcount = 0; - }; - - TransformData Transforms; - - Mesh(IRenderDevice* pDevice, const float4x4& matrix); - void SetBoundingBox(const float3& min, const float3& max); -}; - - -struct Node; -struct Skin -{ - std::string Name; - Node* pSkeletonRoot = nullptr; - std::vector InverseBindMatrices; - std::vector Joints; -}; - - -struct Node -{ - std::string Name; - Node* Parent = nullptr; - Uint32 Index; - - std::vector> Children; - - float4x4 Matrix; - std::unique_ptr _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(); -}; - - -struct AnimationChannel -{ - enum PATH_TYPE - { - TRANSLATION, - ROTATION, - SCALE - }; - PATH_TYPE PathType; - Node* node = nullptr; - Uint32 SamplerIndex = static_cast(-1); -}; - - -struct AnimationSampler -{ - enum INTERPOLATION_TYPE - { - LINEAR, - STEP, - CUBICSPLINE - }; - INTERPOLATION_TYPE Interpolation; - std::vector Inputs; - std::vector OutputsVec4; -}; - -struct Animation -{ - std::string Name; - std::vector Samplers; - std::vector Channels; - - float Start = std::numeric_limits::max(); - float End = std::numeric_limits::min(); -}; - - -struct Model -{ - struct Vertex - { - float3 pos; - float3 normal; - float2 uv0; - float2 uv1; - float4 joint0; - float4 weight0; - }; - - RefCntAutoPtr pVertexBuffer; - RefCntAutoPtr pIndexBuffer; - Uint32 IndexCount = 0; - - float4x4 aabb; - - std::vector> Nodes; - std::vector LinearNodes; - - std::vector> Skins; - - std::vector> Textures; - std::vector> TextureSamplers; - std::vector Materials; - std::vector Animations; - std::vector Extensions; - - struct Dimensions - { - 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); - - 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& indexBuffer, - std::vector& vertexBuffer); - - void LoadSkins(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(); - Node* FindNode(Node* parent, Uint32 index); - Node* NodeFromIndex(uint32_t index); -}; - -} // namespace GLTF - -} // namespace Diligent diff --git a/AssetLoader/interface/GLTFLoader.hpp b/AssetLoader/interface/GLTFLoader.hpp new file mode 100644 index 0000000..5996999 --- /dev/null +++ b/AssetLoader/interface/GLTFLoader.hpp @@ -0,0 +1,302 @@ +/* + * Copyright 2019-2020 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 +#include +#include + +#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/RenderDevice.h" +#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/DeviceContext.h" +#include "../../../DiligentCore/Common/interface/RefCntAutoPtr.hpp" +#include "../../../DiligentCore/Common/interface/AdvancedMath.hpp" + +namespace tinygltf +{ + +class Node; +class Model; + +} // namespace tinygltf + +namespace Diligent +{ + +namespace GLTF +{ + +struct Material +{ + Material() noexcept {} + + enum ALPHA_MODE + { + ALPHAMODE_OPAQUE, + ALPHAMODE_MASK, + ALPHAMODE_BLEND + }; + 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); + + RefCntAutoPtr pBaseColorTexture; + RefCntAutoPtr pMetallicRoughnessTexture; + RefCntAutoPtr pNormalTexture; + RefCntAutoPtr pOcclusionTexture; + RefCntAutoPtr pEmissiveTexture; + + struct TextureCoordinateSets + { + Uint8 BaseColor = 0; + Uint8 MetallicRoughness = 0; + Uint8 SpecularGlossiness = 0; + Uint8 Normal = 0; + Uint8 Occlusion = 0; + Uint8 Emissive = 0; + }; + TextureCoordinateSets TexCoordSets; + + struct Extension + { + RefCntAutoPtr pSpecularGlossinessTexture; + RefCntAutoPtr pDiffuseTexture; + float4 DiffuseFactor = float4(1.0f, 1.0f, 1.0f, 1.0f); + float3 SpecularFactor = float3(1.0f, 1.0f, 1.0f); + }; + Extension extension; + + enum class PbrWorkflow + { + MetallicRoughness, + SpecularGlossiness + }; + PbrWorkflow workflow = PbrWorkflow::MetallicRoughness; +}; + + +struct Primitive +{ + Uint32 FirstIndex = 0; + Uint32 IndexCount = 0; + Uint32 VertexCount = 0; + Material& material; + bool hasIndices; + + BoundBox BB; + bool IsValidBB = false; + + Primitive(Uint32 _FirstIndex, + Uint32 _IndexCount, + Uint32 _VertexCount, + Material& _material) : + 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; + IsValidBB = true; + } +}; + + + +struct Mesh +{ + std::vector> Primitives; + + BoundBox BB; + BoundBox AABB; + bool IsValidBB = false; + + struct TransformData + { + static constexpr Uint32 MaxNumJoints = 128u; + + float4x4 matrix; + float4x4 jointMatrix[MaxNumJoints] = {}; + int jointcount = 0; + }; + + TransformData Transforms; + + Mesh(IRenderDevice* pDevice, const float4x4& matrix); + void SetBoundingBox(const float3& min, const float3& max); +}; + + +struct Node; +struct Skin +{ + std::string Name; + Node* pSkeletonRoot = nullptr; + std::vector InverseBindMatrices; + std::vector Joints; +}; + + +struct Node +{ + std::string Name; + Node* Parent = nullptr; + Uint32 Index; + + std::vector> Children; + + float4x4 Matrix; + std::unique_ptr _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(); +}; + + +struct AnimationChannel +{ + enum PATH_TYPE + { + TRANSLATION, + ROTATION, + SCALE + }; + PATH_TYPE PathType; + Node* node = nullptr; + Uint32 SamplerIndex = static_cast(-1); +}; + + +struct AnimationSampler +{ + enum INTERPOLATION_TYPE + { + LINEAR, + STEP, + CUBICSPLINE + }; + INTERPOLATION_TYPE Interpolation; + std::vector Inputs; + std::vector OutputsVec4; +}; + +struct Animation +{ + std::string Name; + std::vector Samplers; + std::vector Channels; + + float Start = std::numeric_limits::max(); + float End = std::numeric_limits::min(); +}; + + +struct Model +{ + struct Vertex + { + float3 pos; + float3 normal; + float2 uv0; + float2 uv1; + float4 joint0; + float4 weight0; + }; + + RefCntAutoPtr pVertexBuffer; + RefCntAutoPtr pIndexBuffer; + Uint32 IndexCount = 0; + + float4x4 aabb; + + std::vector> Nodes; + std::vector LinearNodes; + + std::vector> Skins; + + std::vector> Textures; + std::vector> TextureSamplers; + std::vector Materials; + std::vector Animations; + std::vector Extensions; + + struct Dimensions + { + 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); + + 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& indexBuffer, + std::vector& vertexBuffer); + + void LoadSkins(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(); + Node* FindNode(Node* parent, Uint32 index); + Node* NodeFromIndex(uint32_t index); +}; + +} // namespace GLTF + +} // namespace Diligent -- cgit v1.2.3