Skip to content

Commit

Permalink
Split CMO structs into a new header (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn authored Sep 20, 2024
1 parent 78d1a3e commit d2baf97
Show file tree
Hide file tree
Showing 17 changed files with 217 additions and 157 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions DirectXTK_Desktop_2019.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<ClInclude Include="Src\AlignedNew.h" />
<ClInclude Include="Src\Bezier.h" />
<ClInclude Include="Src\BinaryReader.h" />
<ClInclude Include="Src\CMO.h" />
<ClInclude Include="Src\DemandCreate.h" />
<ClInclude Include="Src\EffectCommon.h" />
<ClInclude Include="Src\Geometry.h" />
Expand Down
3 changes: 3 additions & 0 deletions DirectXTK_Desktop_2019.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<ClInclude Include="Inc\BufferHelpers.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="Src\CMO.h">
<Filter>Src\Shared</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Src\CommonStates.cpp">
Expand Down
1 change: 1 addition & 0 deletions DirectXTK_Desktop_2019_Win10.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<ClInclude Include="Src\AlignedNew.h" />
<ClInclude Include="Src\Bezier.h" />
<ClInclude Include="Src\BinaryReader.h" />
<ClInclude Include="Src\CMO.h" />
<ClInclude Include="Src\DemandCreate.h" />
<ClInclude Include="Src\EffectCommon.h" />
<ClInclude Include="Src\Geometry.h" />
Expand Down
3 changes: 3 additions & 0 deletions DirectXTK_Desktop_2019_Win10.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
<ClInclude Include="Inc\BufferHelpers.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="Src\CMO.h">
<Filter>Src\Shared</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Src\CommonStates.cpp">
Expand Down
1 change: 1 addition & 0 deletions DirectXTK_Desktop_2022.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<ClInclude Include="Src\AlignedNew.h" />
<ClInclude Include="Src\Bezier.h" />
<ClInclude Include="Src\BinaryReader.h" />
<ClInclude Include="Src\CMO.h" />
<ClInclude Include="Src\DemandCreate.h" />
<ClInclude Include="Src\EffectCommon.h" />
<ClInclude Include="Src\Geometry.h" />
Expand Down
3 changes: 3 additions & 0 deletions DirectXTK_Desktop_2022.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<ClInclude Include="Inc\BufferHelpers.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="Src\CMO.h">
<Filter>Src\Shared</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Src\CommonStates.cpp">
Expand Down
1 change: 1 addition & 0 deletions DirectXTK_Desktop_2022_Win10.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<ClInclude Include="Src\AlignedNew.h" />
<ClInclude Include="Src\Bezier.h" />
<ClInclude Include="Src\BinaryReader.h" />
<ClInclude Include="Src\CMO.h" />
<ClInclude Include="Src\DemandCreate.h" />
<ClInclude Include="Src\EffectCommon.h" />
<ClInclude Include="Src\Geometry.h" />
Expand Down
3 changes: 3 additions & 0 deletions DirectXTK_Desktop_2022_Win10.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
<ClInclude Include="Inc\BufferHelpers.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="Src\CMO.h">
<Filter>Src\Shared</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Src\CommonStates.cpp">
Expand Down
3 changes: 2 additions & 1 deletion DirectXTK_GDK_2019.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
<ClInclude Include="Src\AlignedNew.h" />
<ClInclude Include="Src\Bezier.h" />
<ClInclude Include="Src\BinaryReader.h" />
<ClInclude Include="Src\CMO.h" />
<ClInclude Include="Src\DemandCreate.h" />
<ClInclude Include="Src\EffectCommon.h" />
<ClInclude Include="Src\Geometry.h" />
Expand Down Expand Up @@ -321,4 +322,4 @@
<Delete Files="@(_ATGShaderHeaders)" />
<Delete Files="@(_ATGShaderSymbols)" />
</Target>
</Project>
</Project>
6 changes: 6 additions & 0 deletions DirectXTK_GDK_2019.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@
<ClInclude Include="Inc\BufferHelpers.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="Src\CMO.h">
<Filter>Src\Shared</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Src\CommonStates.cpp">
Expand Down Expand Up @@ -280,6 +283,9 @@
<ClCompile Include="Src\DirectXHelpers.cpp">
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Audio\SoundStreamInstance.cpp">
<Filter>Audio</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Src\Shaders\CompileShaders.cmd">
Expand Down
1 change: 1 addition & 0 deletions DirectXTK_GDK_2022.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
<ClInclude Include="Src\AlignedNew.h" />
<ClInclude Include="Src\Bezier.h" />
<ClInclude Include="Src\BinaryReader.h" />
<ClInclude Include="Src\CMO.h" />
<ClInclude Include="Src\DemandCreate.h" />
<ClInclude Include="Src\EffectCommon.h" />
<ClInclude Include="Src\Geometry.h" />
Expand Down
5 changes: 4 additions & 1 deletion DirectXTK_GDK_2022.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@
<ClInclude Include="Inc\BufferHelpers.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="Src\CMO.h">
<Filter>Src\Shared</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Src\CommonStates.cpp">
Expand Down Expand Up @@ -281,7 +284,7 @@
<Filter>Src</Filter>
</ClCompile>
<ClCompile Include="Audio\SoundStreamInstance.cpp">
<Filter>Src</Filter>
<Filter>Audio</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions DirectXTK_Windows10_2022.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<ClInclude Include="Src\AlignedNew.h" />
<ClInclude Include="Src\Bezier.h" />
<ClInclude Include="Src\BinaryReader.h" />
<ClInclude Include="Src\CMO.h" />
<ClInclude Include="Src\DDS.h" />
<ClInclude Include="Src\DemandCreate.h" />
<ClInclude Include="Src\EffectCommon.h" />
Expand Down
3 changes: 3 additions & 0 deletions DirectXTK_Windows10_2022.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
<ClInclude Include="Inc\BufferHelpers.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="Src\CMO.h">
<Filter>Src\Shared</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="Src\Shaders\CompileShaders.cmd">
Expand Down
181 changes: 181 additions & 0 deletions Src/CMO.h
Original file line number Diff line number Diff line change
@@ -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 <DirectXMath.h>

#include <cstdint>


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");
Loading

0 comments on commit d2baf97

Please sign in to comment.