From d98e235474da45f64dec6c9b8ff84ccbeab8cf6d Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Thu, 19 Sep 2024 17:59:14 -0700 Subject: [PATCH 1/2] Split CMO structs into a new header --- CMakeLists.txt | 1 + DirectXTK_Desktop_2019.vcxproj | 1 + DirectXTK_Desktop_2019.vcxproj.filters | 3 + DirectXTK_Desktop_2019_Win10.vcxproj | 1 + DirectXTK_Desktop_2019_Win10.vcxproj.filters | 3 + DirectXTK_Desktop_2022.vcxproj | 1 + DirectXTK_Desktop_2022.vcxproj.filters | 3 + DirectXTK_Desktop_2022_Win10.vcxproj | 1 + DirectXTK_Desktop_2022_Win10.vcxproj.filters | 3 + DirectXTK_GDK_2019.vcxproj | 3 +- DirectXTK_GDK_2019.vcxproj.filters | 6 + DirectXTK_GDK_2022.vcxproj | 1 + DirectXTK_GDK_2022.vcxproj.filters | 3 + DirectXTK_Windows10_2022.vcxproj | 1 + DirectXTK_Windows10_2022.vcxproj.filters | 3 + Src/CMO.h | 181 +++++++++++++++++++ Src/ModelLoadCMO.cpp | 157 +--------------- 17 files changed, 216 insertions(+), 156 deletions(-) create mode 100644 Src/CMO.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b9282ae30..bb6724eef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,7 @@ set(LIBRARY_SOURCES Src/BasicEffect.cpp Src/BasicPostProcess.cpp Src/BufferHelpers.cpp + Src/CMO.h Src/CommonStates.cpp Src/DDSTextureLoader.cpp Src/DebugEffect.cpp diff --git a/DirectXTK_Desktop_2019.vcxproj b/DirectXTK_Desktop_2019.vcxproj index b640aaef9..5fcac919a 100644 --- a/DirectXTK_Desktop_2019.vcxproj +++ b/DirectXTK_Desktop_2019.vcxproj @@ -42,6 +42,7 @@ + diff --git a/DirectXTK_Desktop_2019.vcxproj.filters b/DirectXTK_Desktop_2019.vcxproj.filters index ccd54fe27..0c8732b1b 100644 --- a/DirectXTK_Desktop_2019.vcxproj.filters +++ b/DirectXTK_Desktop_2019.vcxproj.filters @@ -120,6 +120,9 @@ Inc + + Src\Shared + diff --git a/DirectXTK_Desktop_2019_Win10.vcxproj b/DirectXTK_Desktop_2019_Win10.vcxproj index 45425d44a..5102994a2 100644 --- a/DirectXTK_Desktop_2019_Win10.vcxproj +++ b/DirectXTK_Desktop_2019_Win10.vcxproj @@ -54,6 +54,7 @@ + diff --git a/DirectXTK_Desktop_2019_Win10.vcxproj.filters b/DirectXTK_Desktop_2019_Win10.vcxproj.filters index aad175703..3eead7e89 100644 --- a/DirectXTK_Desktop_2019_Win10.vcxproj.filters +++ b/DirectXTK_Desktop_2019_Win10.vcxproj.filters @@ -135,6 +135,9 @@ Inc + + Src\Shared + diff --git a/DirectXTK_Desktop_2022.vcxproj b/DirectXTK_Desktop_2022.vcxproj index 20df2e9f5..d1bc9c74a 100644 --- a/DirectXTK_Desktop_2022.vcxproj +++ b/DirectXTK_Desktop_2022.vcxproj @@ -42,6 +42,7 @@ + diff --git a/DirectXTK_Desktop_2022.vcxproj.filters b/DirectXTK_Desktop_2022.vcxproj.filters index ccd54fe27..0c8732b1b 100644 --- a/DirectXTK_Desktop_2022.vcxproj.filters +++ b/DirectXTK_Desktop_2022.vcxproj.filters @@ -120,6 +120,9 @@ Inc + + Src\Shared + diff --git a/DirectXTK_Desktop_2022_Win10.vcxproj b/DirectXTK_Desktop_2022_Win10.vcxproj index 0aa9da367..d73fda678 100644 --- a/DirectXTK_Desktop_2022_Win10.vcxproj +++ b/DirectXTK_Desktop_2022_Win10.vcxproj @@ -54,6 +54,7 @@ + diff --git a/DirectXTK_Desktop_2022_Win10.vcxproj.filters b/DirectXTK_Desktop_2022_Win10.vcxproj.filters index aad175703..3eead7e89 100644 --- a/DirectXTK_Desktop_2022_Win10.vcxproj.filters +++ b/DirectXTK_Desktop_2022_Win10.vcxproj.filters @@ -135,6 +135,9 @@ Inc + + Src\Shared + diff --git a/DirectXTK_GDK_2019.vcxproj b/DirectXTK_GDK_2019.vcxproj index d4f89075b..e0eec539f 100644 --- a/DirectXTK_GDK_2019.vcxproj +++ b/DirectXTK_GDK_2019.vcxproj @@ -199,6 +199,7 @@ + @@ -321,4 +322,4 @@ - + \ No newline at end of file diff --git a/DirectXTK_GDK_2019.vcxproj.filters b/DirectXTK_GDK_2019.vcxproj.filters index 2af9a6b75..652969593 100644 --- a/DirectXTK_GDK_2019.vcxproj.filters +++ b/DirectXTK_GDK_2019.vcxproj.filters @@ -137,6 +137,9 @@ Inc + + Src\Shared + @@ -280,6 +283,9 @@ Src + + Src + diff --git a/DirectXTK_GDK_2022.vcxproj b/DirectXTK_GDK_2022.vcxproj index bba1cff03..69cac35d9 100644 --- a/DirectXTK_GDK_2022.vcxproj +++ b/DirectXTK_GDK_2022.vcxproj @@ -199,6 +199,7 @@ + diff --git a/DirectXTK_GDK_2022.vcxproj.filters b/DirectXTK_GDK_2022.vcxproj.filters index 8b7bb34df..652969593 100644 --- a/DirectXTK_GDK_2022.vcxproj.filters +++ b/DirectXTK_GDK_2022.vcxproj.filters @@ -137,6 +137,9 @@ Inc + + Src\Shared + diff --git a/DirectXTK_Windows10_2022.vcxproj b/DirectXTK_Windows10_2022.vcxproj index cdf2b5b0b..699f86899 100644 --- a/DirectXTK_Windows10_2022.vcxproj +++ b/DirectXTK_Windows10_2022.vcxproj @@ -53,6 +53,7 @@ + diff --git a/DirectXTK_Windows10_2022.vcxproj.filters b/DirectXTK_Windows10_2022.vcxproj.filters index 1a30b5868..e875551d9 100644 --- a/DirectXTK_Windows10_2022.vcxproj.filters +++ b/DirectXTK_Windows10_2022.vcxproj.filters @@ -132,6 +132,9 @@ Inc + + Src\Shared + diff --git a/Src/CMO.h b/Src/CMO.h new file mode 100644 index 000000000..c40151a05 --- /dev/null +++ b/Src/CMO.h @@ -0,0 +1,181 @@ +//-------------------------------------------------------------------------------------- +// File: CMO.h +// +// .CMO files are built by Visual Studio's MeshContentTask and an example renderer was +// provided in the VS Direct3D Starter Kit +// https://devblogs.microsoft.com/cppblog/developing-an-app-with-the-visual-studio-3d-starter-kit-part-1-of-3/ +// https://devblogs.microsoft.com/cppblog/developing-an-app-with-the-visual-studio-3d-starter-kit-part-2-of-3/ +// https://devblogs.microsoft.com/cppblog/developing-an-app-with-the-visual-studio-3d-starter-kit-part-3-of-3/ +// +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// +// http://go.microsoft.com/fwlink/?LinkId=248929 +// http://go.microsoft.com/fwlink/?LinkID=615561 +//-------------------------------------------------------------------------------------- + +#pragma once + +#include + +#include + + +namespace VSD3DStarter +{ + // .CMO files + + // UINT - Mesh count + // { [Mesh count] + // UINT - Length of name + // wchar_t[] - Name of mesh (if length > 0) + // UINT - Material count + // { [Material count] + // UINT - Length of material name + // wchar_t[] - Name of material (if length > 0) + // Material structure + // UINT - Length of pixel shader name + // wchar_t[] - Name of pixel shader (if length > 0) + // { [8] + // UINT - Length of texture name + // wchar_t[] - Name of texture (if length > 0) + // } + // } + // BYTE - 1 if there is skeletal animation data present + // UINT - SubMesh count + // { [SubMesh count] + // SubMesh structure + // } + // UINT - IB Count + // { [IB Count] + // UINT - Number of USHORTs in IB + // USHORT[] - Array of indices + // } + // UINT - VB Count + // { [VB Count] + // UINT - Number of verts in VB + // Vertex[] - Array of vertices + // } + // UINT - Skinning VB Count + // { [Skinning VB Count] + // UINT - Number of verts in Skinning VB + // SkinningVertex[] - Array of skinning verts + // } + // MeshExtents structure + // [If skeleton animation data is not present, file ends here] + // UINT - Bone count + // { [Bone count] + // UINT - Length of bone name + // wchar_t[] - Bone name (if length > 0) + // Bone structure + // } + // UINT - Animation clip count + // { [Animation clip count] + // UINT - Length of clip name + // wchar_t[] - Clip name (if length > 0) + // float - Start time + // float - End time + // UINT - Keyframe count + // { [Keyframe count] + // Keyframe structure + // } + // } + // } + +#pragma pack(push,1) + + struct Material + { + DirectX::XMFLOAT4 Ambient; + DirectX::XMFLOAT4 Diffuse; + DirectX::XMFLOAT4 Specular; + float SpecularPower; + DirectX::XMFLOAT4 Emissive; + DirectX::XMFLOAT4X4 UVTransform; + }; + + constexpr uint32_t MAX_TEXTURE = 8; + + struct SubMesh + { + uint32_t MaterialIndex; + uint32_t IndexBufferIndex; + uint32_t VertexBufferIndex; + uint32_t StartIndex; + uint32_t PrimCount; + }; + + constexpr uint32_t NUM_BONE_INFLUENCES = 4; + + // Vertex struct for Visual Studio Shader Designer (DGSL) holding position, normal, + // tangent, color (RGBA), and texture mapping information + struct VertexPositionNormalTangentColorTexture + { + DirectX::XMFLOAT3 position; + DirectX::XMFLOAT3 normal; + DirectX::XMFLOAT4 tangent; + uint32_t color; + DirectX::XMFLOAT2 textureCoordinate; + }; + + struct SkinningVertex + { + uint32_t boneIndex[NUM_BONE_INFLUENCES]; + float boneWeight[NUM_BONE_INFLUENCES]; + }; + + struct MeshExtents + { + float CenterX, CenterY, CenterZ; + float Radius; + + float MinX, MinY, MinZ; + float MaxX, MaxY, MaxZ; + }; + + struct Bone + { + int32_t ParentIndex; + DirectX::XMFLOAT4X4 InvBindPos; + DirectX::XMFLOAT4X4 BindPos; + DirectX::XMFLOAT4X4 LocalTransform; + }; + + struct Clip + { + float StartTime; + float EndTime; + uint32_t keys; + }; + + struct Keyframe + { + uint32_t BoneIndex; + float Time; + DirectX::XMFLOAT4X4 Transform; + }; + +#pragma pack(pop) + + const Material s_defMaterial = + { + { 0.2f, 0.2f, 0.2f, 1.f }, + { 0.8f, 0.8f, 0.8f, 1.f }, + { 0.0f, 0.0f, 0.0f, 1.f }, + 1.f, + { 0.0f, 0.0f, 0.0f, 1.0f }, + { 1.f, 0.f, 0.f, 0.f, + 0.f, 1.f, 0.f, 0.f, + 0.f, 0.f, 1.f, 0.f, + 0.f, 0.f, 0.f, 1.f }, + }; +} // namespace + +static_assert(sizeof(VSD3DStarter::Material) == 132, "CMO Mesh structure size incorrect"); +static_assert(sizeof(VSD3DStarter::SubMesh) == 20, "CMO Mesh structure size incorrect"); +static_assert(sizeof(VSD3DStarter::VertexPositionNormalTangentColorTexture) == 52, "CMO Mesh structure size incorrect"); +static_assert(sizeof(VSD3DStarter::SkinningVertex) == 32, "CMO Mesh structure size incorrect"); +static_assert(sizeof(VSD3DStarter::MeshExtents) == 40, "CMO Mesh structure size incorrect"); +static_assert(sizeof(VSD3DStarter::Bone) == 196, "CMO Mesh structure size incorrect"); +static_assert(sizeof(VSD3DStarter::Clip) == 12, "CMO Mesh structure size incorrect"); +static_assert(sizeof(VSD3DStarter::Keyframe) == 72, "CMO Mesh structure size incorrect"); diff --git a/Src/ModelLoadCMO.cpp b/Src/ModelLoadCMO.cpp index 36ada6036..84f6dd0d6 100644 --- a/Src/ModelLoadCMO.cpp +++ b/Src/ModelLoadCMO.cpp @@ -18,163 +18,10 @@ using namespace DirectX; using Microsoft::WRL::ComPtr; +#include "CMO.h" -//-------------------------------------------------------------------------------------- -// .CMO files are built by Visual Studio's MeshContentTask and an example renderer was -// provided in the VS Direct3D Starter Kit -// https://devblogs.microsoft.com/cppblog/developing-an-app-with-the-visual-studio-3d-starter-kit-part-1-of-3/ -// https://devblogs.microsoft.com/cppblog/developing-an-app-with-the-visual-studio-3d-starter-kit-part-2-of-3/ -// https://devblogs.microsoft.com/cppblog/developing-an-app-with-the-visual-studio-3d-starter-kit-part-3-of-3/ -//-------------------------------------------------------------------------------------- - -namespace VSD3DStarter -{ - // .CMO files - - // UINT - Mesh count - // { [Mesh count] - // UINT - Length of name - // wchar_t[] - Name of mesh (if length > 0) - // UINT - Material count - // { [Material count] - // UINT - Length of material name - // wchar_t[] - Name of material (if length > 0) - // Material structure - // UINT - Length of pixel shader name - // wchar_t[] - Name of pixel shader (if length > 0) - // { [8] - // UINT - Length of texture name - // wchar_t[] - Name of texture (if length > 0) - // } - // } - // BYTE - 1 if there is skeletal animation data present - // UINT - SubMesh count - // { [SubMesh count] - // SubMesh structure - // } - // UINT - IB Count - // { [IB Count] - // UINT - Number of USHORTs in IB - // USHORT[] - Array of indices - // } - // UINT - VB Count - // { [VB Count] - // UINT - Number of verts in VB - // Vertex[] - Array of vertices - // } - // UINT - Skinning VB Count - // { [Skinning VB Count] - // UINT - Number of verts in Skinning VB - // SkinningVertex[] - Array of skinning verts - // } - // MeshExtents structure - // [If skeleton animation data is not present, file ends here] - // UINT - Bone count - // { [Bone count] - // UINT - Length of bone name - // wchar_t[] - Bone name (if length > 0) - // Bone structure - // } - // UINT - Animation clip count - // { [Animation clip count] - // UINT - Length of clip name - // wchar_t[] - Clip name (if length > 0) - // float - Start time - // float - End time - // UINT - Keyframe count - // { [Keyframe count] - // Keyframe structure - // } - // } - // } - -#pragma pack(push,1) - - struct Material - { - DirectX::XMFLOAT4 Ambient; - DirectX::XMFLOAT4 Diffuse; - DirectX::XMFLOAT4 Specular; - float SpecularPower; - DirectX::XMFLOAT4 Emissive; - DirectX::XMFLOAT4X4 UVTransform; - }; - - constexpr uint32_t MAX_TEXTURE = 8; - - struct SubMesh - { - uint32_t MaterialIndex; - uint32_t IndexBufferIndex; - uint32_t VertexBufferIndex; - uint32_t StartIndex; - uint32_t PrimCount; - }; - - constexpr uint32_t NUM_BONE_INFLUENCES = 4; - - static_assert(sizeof(VertexPositionNormalTangentColorTexture) == 52, "mismatch with CMO vertex type"); +static_assert(sizeof(VertexPositionNormalTangentColorTexture) == sizeof(VSD3DStarter::VertexPositionNormalTangentColorTexture), "mismatch with CMO vertex type"); - struct SkinningVertex - { - uint32_t boneIndex[NUM_BONE_INFLUENCES]; - float boneWeight[NUM_BONE_INFLUENCES]; - }; - - struct MeshExtents - { - float CenterX, CenterY, CenterZ; - float Radius; - - float MinX, MinY, MinZ; - float MaxX, MaxY, MaxZ; - }; - - struct Bone - { - int32_t ParentIndex; - DirectX::XMFLOAT4X4 InvBindPos; - DirectX::XMFLOAT4X4 BindPos; - DirectX::XMFLOAT4X4 LocalTransform; - }; - - struct Clip - { - float StartTime; - float EndTime; - uint32_t keys; - }; - - struct Keyframe - { - uint32_t BoneIndex; - float Time; - DirectX::XMFLOAT4X4 Transform; - }; - -#pragma pack(pop) - - const Material s_defMaterial = - { - { 0.2f, 0.2f, 0.2f, 1.f }, - { 0.8f, 0.8f, 0.8f, 1.f }, - { 0.0f, 0.0f, 0.0f, 1.f }, - 1.f, - { 0.0f, 0.0f, 0.0f, 1.0f }, - { 1.f, 0.f, 0.f, 0.f, - 0.f, 1.f, 0.f, 0.f, - 0.f, 0.f, 1.f, 0.f, - 0.f, 0.f, 0.f, 1.f }, - }; -} // namespace - -static_assert(sizeof(VSD3DStarter::Material) == 132, "CMO Mesh structure size incorrect"); -static_assert(sizeof(VSD3DStarter::SubMesh) == 20, "CMO Mesh structure size incorrect"); -static_assert(sizeof(VSD3DStarter::SkinningVertex) == 32, "CMO Mesh structure size incorrect"); -static_assert(sizeof(VSD3DStarter::MeshExtents) == 40, "CMO Mesh structure size incorrect"); -static_assert(sizeof(VSD3DStarter::Bone) == 196, "CMO Mesh structure size incorrect"); -static_assert(sizeof(VSD3DStarter::Clip) == 12, "CMO Mesh structure size incorrect"); -static_assert(sizeof(VSD3DStarter::Keyframe) == 72, "CMO Mesh structure size incorrect"); namespace { From 9943b086baad38d9ea2f290071ab5bcdcb1a2793 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Thu, 19 Sep 2024 23:30:38 -0700 Subject: [PATCH 2/2] Minor filters fix --- DirectXTK_GDK_2019.vcxproj.filters | 2 +- DirectXTK_GDK_2022.vcxproj.filters | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DirectXTK_GDK_2019.vcxproj.filters b/DirectXTK_GDK_2019.vcxproj.filters index 652969593..f3b9fda7f 100644 --- a/DirectXTK_GDK_2019.vcxproj.filters +++ b/DirectXTK_GDK_2019.vcxproj.filters @@ -284,7 +284,7 @@ Src - Src + Audio diff --git a/DirectXTK_GDK_2022.vcxproj.filters b/DirectXTK_GDK_2022.vcxproj.filters index 652969593..f3b9fda7f 100644 --- a/DirectXTK_GDK_2022.vcxproj.filters +++ b/DirectXTK_GDK_2022.vcxproj.filters @@ -284,7 +284,7 @@ Src - Src + Audio