|
| 1 | +//-------------------------------------------------------------------------------------- |
| 2 | +// File: CMO.h |
| 3 | +// |
| 4 | +// .CMO files are built by Visual Studio's MeshContentTask and an example renderer was |
| 5 | +// provided in the VS Direct3D Starter Kit |
| 6 | +// https://devblogs.microsoft.com/cppblog/developing-an-app-with-the-visual-studio-3d-starter-kit-part-1-of-3/ |
| 7 | +// https://devblogs.microsoft.com/cppblog/developing-an-app-with-the-visual-studio-3d-starter-kit-part-2-of-3/ |
| 8 | +// https://devblogs.microsoft.com/cppblog/developing-an-app-with-the-visual-studio-3d-starter-kit-part-3-of-3/ |
| 9 | +// |
| 10 | +// Copyright (c) Microsoft Corporation. |
| 11 | +// Licensed under the MIT License. |
| 12 | +// |
| 13 | +// http://go.microsoft.com/fwlink/?LinkId=248929 |
| 14 | +// http://go.microsoft.com/fwlink/?LinkID=615561 |
| 15 | +//-------------------------------------------------------------------------------------- |
| 16 | + |
| 17 | +#pragma once |
| 18 | + |
| 19 | +#include <DirectXMath.h> |
| 20 | + |
| 21 | +#include <cstdint> |
| 22 | + |
| 23 | + |
| 24 | +namespace VSD3DStarter |
| 25 | +{ |
| 26 | + // .CMO files |
| 27 | + |
| 28 | + // UINT - Mesh count |
| 29 | + // { [Mesh count] |
| 30 | + // UINT - Length of name |
| 31 | + // wchar_t[] - Name of mesh (if length > 0) |
| 32 | + // UINT - Material count |
| 33 | + // { [Material count] |
| 34 | + // UINT - Length of material name |
| 35 | + // wchar_t[] - Name of material (if length > 0) |
| 36 | + // Material structure |
| 37 | + // UINT - Length of pixel shader name |
| 38 | + // wchar_t[] - Name of pixel shader (if length > 0) |
| 39 | + // { [8] |
| 40 | + // UINT - Length of texture name |
| 41 | + // wchar_t[] - Name of texture (if length > 0) |
| 42 | + // } |
| 43 | + // } |
| 44 | + // BYTE - 1 if there is skeletal animation data present |
| 45 | + // UINT - SubMesh count |
| 46 | + // { [SubMesh count] |
| 47 | + // SubMesh structure |
| 48 | + // } |
| 49 | + // UINT - IB Count |
| 50 | + // { [IB Count] |
| 51 | + // UINT - Number of USHORTs in IB |
| 52 | + // USHORT[] - Array of indices |
| 53 | + // } |
| 54 | + // UINT - VB Count |
| 55 | + // { [VB Count] |
| 56 | + // UINT - Number of verts in VB |
| 57 | + // Vertex[] - Array of vertices |
| 58 | + // } |
| 59 | + // UINT - Skinning VB Count |
| 60 | + // { [Skinning VB Count] |
| 61 | + // UINT - Number of verts in Skinning VB |
| 62 | + // SkinningVertex[] - Array of skinning verts |
| 63 | + // } |
| 64 | + // MeshExtents structure |
| 65 | + // [If skeleton animation data is not present, file ends here] |
| 66 | + // UINT - Bone count |
| 67 | + // { [Bone count] |
| 68 | + // UINT - Length of bone name |
| 69 | + // wchar_t[] - Bone name (if length > 0) |
| 70 | + // Bone structure |
| 71 | + // } |
| 72 | + // UINT - Animation clip count |
| 73 | + // { [Animation clip count] |
| 74 | + // UINT - Length of clip name |
| 75 | + // wchar_t[] - Clip name (if length > 0) |
| 76 | + // float - Start time |
| 77 | + // float - End time |
| 78 | + // UINT - Keyframe count |
| 79 | + // { [Keyframe count] |
| 80 | + // Keyframe structure |
| 81 | + // } |
| 82 | + // } |
| 83 | + // } |
| 84 | + |
| 85 | +#pragma pack(push,1) |
| 86 | + |
| 87 | + struct Material |
| 88 | + { |
| 89 | + DirectX::XMFLOAT4 Ambient; |
| 90 | + DirectX::XMFLOAT4 Diffuse; |
| 91 | + DirectX::XMFLOAT4 Specular; |
| 92 | + float SpecularPower; |
| 93 | + DirectX::XMFLOAT4 Emissive; |
| 94 | + DirectX::XMFLOAT4X4 UVTransform; |
| 95 | + }; |
| 96 | + |
| 97 | + constexpr uint32_t MAX_TEXTURE = 8; |
| 98 | + |
| 99 | + struct SubMesh |
| 100 | + { |
| 101 | + uint32_t MaterialIndex; |
| 102 | + uint32_t IndexBufferIndex; |
| 103 | + uint32_t VertexBufferIndex; |
| 104 | + uint32_t StartIndex; |
| 105 | + uint32_t PrimCount; |
| 106 | + }; |
| 107 | + |
| 108 | + constexpr uint32_t NUM_BONE_INFLUENCES = 4; |
| 109 | + |
| 110 | + // Vertex struct for Visual Studio Shader Designer (DGSL) holding position, normal, |
| 111 | + // tangent, color (RGBA), and texture mapping information |
| 112 | + struct VertexPositionNormalTangentColorTexture |
| 113 | + { |
| 114 | + DirectX::XMFLOAT3 position; |
| 115 | + DirectX::XMFLOAT3 normal; |
| 116 | + DirectX::XMFLOAT4 tangent; |
| 117 | + uint32_t color; |
| 118 | + DirectX::XMFLOAT2 textureCoordinate; |
| 119 | + }; |
| 120 | + |
| 121 | + struct SkinningVertex |
| 122 | + { |
| 123 | + uint32_t boneIndex[NUM_BONE_INFLUENCES]; |
| 124 | + float boneWeight[NUM_BONE_INFLUENCES]; |
| 125 | + }; |
| 126 | + |
| 127 | + struct MeshExtents |
| 128 | + { |
| 129 | + float CenterX, CenterY, CenterZ; |
| 130 | + float Radius; |
| 131 | + |
| 132 | + float MinX, MinY, MinZ; |
| 133 | + float MaxX, MaxY, MaxZ; |
| 134 | + }; |
| 135 | + |
| 136 | + struct Bone |
| 137 | + { |
| 138 | + int32_t ParentIndex; |
| 139 | + DirectX::XMFLOAT4X4 InvBindPos; |
| 140 | + DirectX::XMFLOAT4X4 BindPos; |
| 141 | + DirectX::XMFLOAT4X4 LocalTransform; |
| 142 | + }; |
| 143 | + |
| 144 | + struct Clip |
| 145 | + { |
| 146 | + float StartTime; |
| 147 | + float EndTime; |
| 148 | + uint32_t keys; |
| 149 | + }; |
| 150 | + |
| 151 | + struct Keyframe |
| 152 | + { |
| 153 | + uint32_t BoneIndex; |
| 154 | + float Time; |
| 155 | + DirectX::XMFLOAT4X4 Transform; |
| 156 | + }; |
| 157 | + |
| 158 | +#pragma pack(pop) |
| 159 | + |
| 160 | + const Material s_defMaterial = |
| 161 | + { |
| 162 | + { 0.2f, 0.2f, 0.2f, 1.f }, |
| 163 | + { 0.8f, 0.8f, 0.8f, 1.f }, |
| 164 | + { 0.0f, 0.0f, 0.0f, 1.f }, |
| 165 | + 1.f, |
| 166 | + { 0.0f, 0.0f, 0.0f, 1.0f }, |
| 167 | + { 1.f, 0.f, 0.f, 0.f, |
| 168 | + 0.f, 1.f, 0.f, 0.f, |
| 169 | + 0.f, 0.f, 1.f, 0.f, |
| 170 | + 0.f, 0.f, 0.f, 1.f }, |
| 171 | + }; |
| 172 | +} // namespace |
| 173 | + |
| 174 | +static_assert(sizeof(VSD3DStarter::Material) == 132, "CMO Mesh structure size incorrect"); |
| 175 | +static_assert(sizeof(VSD3DStarter::SubMesh) == 20, "CMO Mesh structure size incorrect"); |
| 176 | +static_assert(sizeof(VSD3DStarter::VertexPositionNormalTangentColorTexture) == 52, "CMO Mesh structure size incorrect"); |
| 177 | +static_assert(sizeof(VSD3DStarter::SkinningVertex) == 32, "CMO Mesh structure size incorrect"); |
| 178 | +static_assert(sizeof(VSD3DStarter::MeshExtents) == 40, "CMO Mesh structure size incorrect"); |
| 179 | +static_assert(sizeof(VSD3DStarter::Bone) == 196, "CMO Mesh structure size incorrect"); |
| 180 | +static_assert(sizeof(VSD3DStarter::Clip) == 12, "CMO Mesh structure size incorrect"); |
| 181 | +static_assert(sizeof(VSD3DStarter::Keyframe) == 72, "CMO Mesh structure size incorrect"); |
0 commit comments