-
Notifications
You must be signed in to change notification settings - Fork 226
/
Mesh.h
178 lines (147 loc) · 3.68 KB
/
Mesh.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//--------------------------------------------------------------------------------------
// D3D12RaytracingAO.h
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#pragma once
#include <GraphicsMemory.h>
#include <Model.h>
namespace Parts
{
constexpr unsigned int MaxParts = 10;
}
namespace Textures
{
constexpr unsigned int MaxTextures = 10;
}
namespace Materials
{
constexpr unsigned int MaxMaterials = 10;
}
struct MeshInfo
{
unsigned int matID;
unsigned int numIndices;
unsigned int numVertices;
unsigned int stride;
Microsoft::WRL::ComPtr<ID3D12Resource> indexResource;
Microsoft::WRL::ComPtr<ID3D12Resource> vertexResource;
};
class MeshType
{
public:
MeshType(std::shared_ptr<DirectX::Model> pModel) :
m_model(pModel), m_meshIndex(0), m_partIndex(0)
{
}
MeshType(
std::shared_ptr<DirectX::Model> pModel,
size_t pMeshIndex,
size_t pPartIndex) :
m_model(pModel), m_meshIndex(pMeshIndex), m_partIndex(pPartIndex)
{
}
bool operator!=(const MeshType& rhs) const
{
return m_meshIndex != rhs.m_meshIndex || m_partIndex != rhs.m_partIndex;
}
MeshInfo operator*()
{
auto& meshPtr = m_model->meshes[m_meshIndex]->opaqueMeshParts[m_partIndex];
MeshInfo meshInfo {
meshPtr->materialIndex,
meshPtr->indexCount,
meshPtr->vertexCount,
meshPtr->vertexStride,
meshPtr->staticIndexBuffer,
meshPtr->staticVertexBuffer
};
return std::move(meshInfo);
}
MeshType& operator++()
{
// Do not update if at end.
if (m_meshIndex == m_model->meshes.size())
{
return *this;
}
m_partIndex++;
if (m_partIndex == m_model->meshes[m_meshIndex]->opaqueMeshParts.size())
{
m_meshIndex++;
m_partIndex = 0;
}
return *this;
}
private:
std::shared_ptr<DirectX::Model> m_model;
size_t m_meshIndex, m_partIndex;
};
class Mesh : public std::iterator<std::forward_iterator_tag, MeshType>
{
public:
Mesh(
ID3D12Device* device,
ID3D12CommandQueue* commandQueue,
const wchar_t* pFileName);
void SetTextureSRV(
ID3D12Device* device,
D3D12_CPU_DESCRIPTOR_HANDLE pStartHandle,
int matIndex);
void SetTextureSRVs(
ID3D12Device* device,
D3D12_CPU_DESCRIPTOR_HANDLE pStartHandle,
SIZE_T increment);
size_t size()
{
return length;
}
// Iterator
MeshType begin()
{
return std::move(
MeshType(
m_model,
0,
0)
);
}
const MeshType begin() const
{
return std::move(
MeshType(
m_model,
0,
0)
);
}
MeshType end()
{
return std::move(
MeshType(
m_model,
m_model->meshes.size(),
0)
);
}
const MeshType end() const
{
return std::move(
MeshType(
m_model,
m_model->meshes.size(),
0)
);
}
std::shared_ptr<DirectX::Model> getModel()
{
return m_model;
}
private:
std::shared_ptr<DirectX::Model> m_model;
std::unique_ptr<DirectX::EffectTextureFactory> m_textureFactory;
Microsoft::WRL::ComPtr<ID3D12Resource> m_indexResource;
Microsoft::WRL::ComPtr<ID3D12Resource> m_vertexResource;
size_t length = 0;
};