-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMesh.cpp
More file actions
151 lines (129 loc) · 4.83 KB
/
Copy pathMesh.cpp
File metadata and controls
151 lines (129 loc) · 4.83 KB
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
#include "Mesh.h"
#include "Camera.h"
#include "MeshOptimizer.h"
// ★ DeviceState.h include가 여기 있었다 (A-③, 2026-08-09).
//
// MakeShadowOptimizedBuffer의 DirectX11::CreateBuffer 때문이었다. 그것을
// 걷었으므로 이 파일에 DX11이 남지 않는다 - Mesh.cpp는 이제 CPU 배열만
// 다룬다.
// CreateLODBuffers 헬퍼가 여기 있었다.
//
// 이름대로 LOD별 DX11 정점·인덱스 버퍼를 만들던 함수인데, 그 두 본문이
// 앞선 정리에서 비워지고 indexCount 대입 한 줄만 남아 있었다. 껍데기를
// 함수로 감싸 두면 "여기서 GPU 자원이 생긴다"로 읽히므로 호출부에 편다.
Mesh::Mesh(std::string_view _name, const std::vector<Vertex>& _vertices, const std::vector<uint32>& _indices) :
m_name(_name),
m_vertices(_vertices),
m_indices(_indices)
{
}
Mesh::Mesh(std::string_view _name, std::vector<Vertex>&& _vertices, std::vector<uint32>&& _indices) :
m_name(_name), m_vertices(std::move(_vertices)), m_indices(std::move(_indices))
{
}
Mesh::Mesh(Mesh&& _other) noexcept :
m_vertices(std::move(_other.m_vertices)),
m_indices(std::move(_other.m_indices)),
m_name(std::move(_other.m_name)),
m_materialIndex(_other.m_materialIndex),
m_boundingBox(_other.m_boundingBox),
m_boundingSphere(_other.m_boundingSphere),
m_hashingMesh(_other.m_hashingMesh),
m_modelName(std::move(_other.m_modelName))
{
}
Mesh::~Mesh()
{
}
void Mesh::AssetInit()
{
}
void Mesh::RecalculateBounds()
{
if (m_vertices.empty()) return;
math::vector3 minimum = m_vertices.front().position;
math::vector3 maximum = minimum;
for (const Vertex& vertex : m_vertices)
{
minimum = math::min(minimum, vertex.position);
maximum = math::max(maximum, vertex.position);
}
m_boundingBox = math::aabb::from_min_max(minimum, maximum);
m_boundingSphere = math::bounding_sphere(m_boundingBox);
}
// [NEW] Check if LODs have been generated
bool Mesh::HasLODs() const
{
return !m_LODs.empty();
}
// [NEW] Generate LODs
void Mesh::GenerateLODs(const std::vector<float>&lodThresholds)
{
if (m_vertices.empty() || m_indices.empty())
{
std::cerr << "Mesh::GenerateLODs: Original mesh data is empty. Cannot generate LODs." << std::endl;
return;
}
// Store the thresholds
m_LODThresholds = lodThresholds;
// Clear existing LODs (if any) before generating new ones
m_LODs.clear();
m_LODs.reserve(1 + lodThresholds.size()); // LOD 0 + generated LODs
// Add LOD 0 (original mesh) as the first LOD resource
LODResource lod0_resource;
lod0_resource.indexCount = static_cast<uint32>(m_indices.size());
m_LODs.push_back(lod0_resource);
// Generate simplified LODs using MeshOptimizer
std::optional<std::vector<MeshOptimizer::LOD>> generatedLODs =
MeshOptimizer::GenerateLODs(
*this, // Pass the current Mesh object (which has GetVertices/GetIndices)
lodThresholds);
if (generatedLODs.has_value())
{
for (uint32_t i = 0; i < generatedLODs->size(); ++i)
{
const auto& lod_data = generatedLODs->at(i);
LODResource lod_resource;
lod_resource.indexCount = static_cast<uint32>(lod_data.indices.size());
m_LODs.push_back(lod_resource);
}
}
else
{
std::cerr << "Mesh::GenerateLODs: MeshOptimizer failed to generate LODs." << std::endl;
// If generation fails, m_LODs will only contain LOD 0.
}
}
// ── Mesh에서 DX11이 사라진 자취 ──
//
// ① 드로우 8종 (T5). Draw ×2 · DrawShadow ×2 · DrawInstanced · DrawLOD ·
// DrawShadowLOD · DrawInstancedLOD. 유일한 소비자가 PrimitiveRenderProxy의
// 드로우 셋이었고 그 셋도 호출자가 0이었다 - DX11 렌더러가 은퇴하면서
// 함께 도달 불가가 됐다.
//
// ② 정점·인덱스 버퍼 (D4). 예전 주석은 "EffectSystem의 MeshModuleGPU가
// GetVertexBuffer/GetIndexBuffer로 쓰므로 남는다"였는데, 그 EffectSystem이
// PHASE 10에서 통째로 걷혔다. 소비자가 함께 사라져 버퍼도 갔다.
//
// ③ 그림자 최적화 계통 (A-③, 2026-08-09). MakeShadowOptimizedBuffer와
// m_shadow* 여섯.
//
// ★ 만들기만 하고 아무도 안 그렸다. 게터 둘(GetShadowVertexBuffer/
// GetShadowIndexBuffer)의 호출자가 0이었고, 더 안쪽을 보면 애초에
// MakeShadowOptimizedBuffer를 부르는 곳도 0이었으며, 원본이 될
// m_shadowVertices/m_shadowIndices를 채우는 코드도 없었다
// (MeshOptimizer는 그림자를 아예 다루지 않는다).
//
// 즉 빈 배열로 크기 0짜리 DX11 버퍼를 만드는 경로였고, 그 죽은 경로
// 하나 때문에 Mesh.cpp가 DeviceState.h를 붙들고 있었다.
//
// 그림자용 저정점 메시가 다시 필요해지면 DX12 쪽에서 CPU 배열을
// 원본으로 새로 세운다 - 여기 남은 껍데기를 되살릴 이유는 없다.
UIMesh::UIMesh()
{
m_vertices = UIQuad;
m_indices = UIIndices;
}
UIMesh::~UIMesh()
{
}