SpiecsEngine
 
Loading...
Searching...
No Matches
MeshComponent.cpp
Go to the documentation of this file.
1/**
2* @file MeshComponent.cpp.
3* @brief The MeshComponent Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
9
10#include "imgui_internal.h"
11#include "Render/FrameInfo.h"
12#include "World/Entity.h"
13
14namespace Spices {
15
17 {
18
19 }
20
22 {
23
24 }
25
27 {
29
30 ImGui::Spacing();
31 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2.0f, 6.0f));
32 float columnWidth = ImGuiH::GetLineItemSize().x * 5.0f;
33
34 ImGuiTreeNodeFlags treeNodeFlags =
35 ImGuiTreeNodeFlags_DefaultOpen |
36 ImGuiTreeNodeFlags_AllowItemOverlap |
37 ImGuiTreeNodeFlags_Framed |
38 ImGuiTreeNodeFlags_FramePadding ;
39 //ImGuiTreeNodeFlags_Bullet ;
40
41 {
42 SPICES_PROFILE_ZONEN("MeshComponent Mesh Pack");
43
44 ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(0.196f, 0.204f, 0.2f, 1.0f));
45 ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0.164f, 0.18f, 0.184f, 1.0f));
46 ImGui::PushStyleColor(ImGuiCol_HeaderActive, ImVec4(0.164f, 0.18f, 0.184f, 1.0f));
47 ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.196f, 0.204f, 0.2f, 1.0f));
48
49 if(ImGui::TreeNodeEx("Geometries", treeNodeFlags))
50 {
51 for (uint64_t i = 0; i < m_Mesh->GetPacks().size(); i++)
52 {
53 {
54 SPICES_PROFILE_ZONEN("MeshComponent Mesh Pack Item");
55
56 std::stringstream ss;
57 ss << "MeshPack [" << i << "]";
58 if(ImGui::TreeNodeEx(ss.str().c_str(), treeNodeFlags | ImGuiTreeNodeFlags_Bullet))
59 {
60 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2.0f, 2.0f));
61 const float imageIconSize = 3.0f * ImGuiH::GetLineItemSize().x + 2.0f * ImGui::GetStyle().ItemSpacing.y;
62 const float seperatorWidthS = ImGuiH::GetLineItemSize().x - 3.0f * ImGui::GetStyle().IndentSpacing;
63
64 {
65 SPICES_PROFILE_ZONEN("MeshComponent Mesh Pack Icon");
66
67 ImGui::Spacing();
68 ImGui::PushID("Geometries");
69 ImGui::Columns(2, 0, false);
70
71 ImGui::SetColumnWidth(0, columnWidth);
72 ImGui::ColorButton("##", ImVec4(1.0f, 0.0f, 0.0f, 0.0f), 0, ImVec2(imageIconSize, imageIconSize));
73 ImGui::NextColumn();
74
75 ImGui::BeginGroup();
76
77 const ImVec2 textSize = ImVec2(2.0f * ImGuiH::GetLineItemSize().x, ImGuiH::GetLineItemSize().y);
78
79 {
80 SPICES_PROFILE_ZONEN("MeshComponent Mesh Pack Prim");
81
82 std::stringstream ss0;
83 ss0 << "/World/MeshComponent/Mesh/" << ss.str();
84 ImGui::CenteredText("Prim", textSize);
85 ImGui::SameLine(2.0f * ImGuiH::GetLineItemSize().x);
86 char buffer0[256] = {};
87 ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGuiH::GetLineItemSize().x);
88 ImGui::InputTextWithHint("##_0", ICON_TEXT_ROW(" ", ss0.str().c_str()), buffer0, sizeof(buffer0));
89 ImGui::PopItemWidth();
90 }
91
92 {
93 SPICES_PROFILE_ZONEN("MeshComponent Mesh Pack Path");
94
95 std::stringstream ss1;
96 ss1 << "/World/MeshComponent/" << ss.str();
97 char buffer1[256] = {};
98 ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGuiH::GetLineItemSize().x);
99 ImGui::InputTextWithHint("##_2", ICON_TEXT_ROW(" ", ss1.str().c_str()), buffer1, sizeof(buffer1));
100 ImGui::PopItemWidth();
101 }
102
103 {
104 SPICES_PROFILE_ZONEN("MeshComponent Mesh Pack Type");
105
106 auto meshPack = *m_Mesh->GetPacks().find_value(static_cast<uint32_t>(i));
107 std::string type = meshPack->GetPackType();
108 ImGui::CenteredText("Type", textSize);
109 ImGui::SameLine(2.0f * ImGuiH::GetLineItemSize().x);
110 char buffer2[256] = {};
111 ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGuiH::GetLineItemSize().x);
112 ImGui::InputTextWithHint("##_1", ICON_TEXT_ROW(" ", type.c_str()), buffer2, sizeof(buffer2));
113 ImGui::PopItemWidth();
114 }
115 ImGui::EndGroup();
116
117 ImGui::Columns(1);
118 ImGui::PopID();
119 ImGui::Spacing();
120 ImGui::Separator();
121 }
122
123 ImGui::Spacing();
124
125 {
126 SPICES_PROFILE_ZONEN("MeshComponent Mesh Pack Shadows");
127
128 ImGuiH::DrawPropertyItem("Cast Shadows", columnWidth, nullptr, [&]() {
129 static bool isCastShadow = true;
130 ImGuiH::Checkbox(&isCastShadow);
131 ImGui::SameLine();
132 ImGui::PushItemWidth(100.0f);
133 ImGui::SeparatorText("##");
134 ImGui::PopItemWidth();
135 ImGui::SameLine(ImGui::GetContentRegionAvail().x - seperatorWidthS);
136 if (ImGuiH::DrawResetIcon(isCastShadow != true))
137 {
138 isCastShadow = true;
139 FrameInfo::Get().m_World->Mark(World::FrushStableFrame);
140 }
141 });
142 }
143
144 {
145 SPICES_PROFILE_ZONEN("MeshComponent Mesh Pack Visible");
146
147 ImGuiH::DrawPropertyItem("Visible", columnWidth, nullptr, [&]() {
148 static bool isVisible = true;
149 ImGuiH::Checkbox(&isVisible);
150 ImGui::SameLine();
151 ImGui::SeparatorText("##");
152 ImGui::SameLine(ImGui::GetContentRegionAvail().x - seperatorWidthS);
153 if (ImGuiH::DrawResetIcon(isVisible != true))
154 {
155 isVisible = true;
156 FrameInfo::Get().m_World->Mark(World::FrushStableFrame);
157 }
158 });
159 }
160
161 ImGui::Spacing();
162
163 ImGui::PopStyleVar();
164 ImGui::TreePop();
165 }
166 }
167
168
169 }
170
171 ImGui::TreePop();
172 }
173
174 ImGui::PopStyleColor(4);
175 }
176
177 {
178 SPICES_PROFILE_ZONEN("MeshComponent Materials");
179
180 ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(0.196f, 0.204f, 0.2f, 1.0f));
181 ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0.164f, 0.18f, 0.184f, 1.0f));
182 ImGui::PushStyleColor(ImGuiCol_HeaderActive, ImVec4(0.164f, 0.18f, 0.184f, 1.0f));
183 ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.196f, 0.204f, 0.2f, 1.0f));
184
185 if(ImGui::TreeNodeEx("Materials", treeNodeFlags))
186 {
187 for (uint64_t i = 0; i < m_Mesh->GetPacks().size(); i++)
188 {
189 {
190 SPICES_PROFILE_ZONEN("MeshComponent Materials Item");
191
192 std::stringstream ss;
193 ss << "Materials [" << i << "]";
194 if(ImGui::TreeNodeEx(ss.str().c_str(), treeNodeFlags | ImGuiTreeNodeFlags_Bullet))
195 {
196 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2.0f, 2.0f));
197 const float imageIconSize = 3.0f * ImGuiH::GetLineItemSize().x + 2.0f * ImGui::GetStyle().ItemSpacing.y;
198 const float seperatorWidthS = ImGuiH::GetLineItemSize().x - 3.0f * ImGui::GetStyle().IndentSpacing;
199
200 {
201 SPICES_PROFILE_ZONEN("MeshComponent Materials Icon");
202
203 ImGui::Spacing();
204 ImGui::PushID("Materials");
205 ImGui::Columns(2, 0, false);
206
207 ImGui::SetColumnWidth(0, columnWidth);
208 if(ImGui::ColorButton("##", ImVec4(0.0f, 1.0f, 0.0f, 0.0f), 0, ImVec2(imageIconSize, imageIconSize)))
209 {
210 FrameInfo::Get().m_PickMaterial = static_cast<uint32_t>(i);
211 }
212 ImGui::NextColumn();
213
214 ImGui::BeginGroup();
215
216 const ImVec2 textSize = ImVec2(2.0f * ImGuiH::GetLineItemSize().x, ImGuiH::GetLineItemSize().y);
217
218 {
219 SPICES_PROFILE_ZONEN("MeshComponent Materials Prim");
220
221 std::stringstream ss0;
222 ss0 << "/World/MeshComponent/Mesh/" << ss.str();
223 ImGui::CenteredText("Prim", textSize);
224 ImGui::SameLine(2.0f * ImGuiH::GetLineItemSize().x);
225 char buffer0[256] = {};
226 ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGuiH::GetLineItemSize().x);
227 ImGui::InputTextWithHint("##_0", ICON_TEXT_ROW(" ", ss0.str().c_str()), buffer0, sizeof(buffer0));
228 ImGui::PopItemWidth();
229 }
230
231 {
232 SPICES_PROFILE_ZONEN("MeshComponent Materials Path");
233
234 char buffer1[256] = {};
235 ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGuiH::GetLineItemSize().x);
236 auto meshPack = *m_Mesh->GetPacks().find_value(static_cast<uint32_t>(i));
237 ImGui::InputTextWithHint("##_2", ICON_TEXT_ROW(" ", meshPack->GetMaterial()->GetName().c_str()), buffer1, sizeof(buffer1));
238 ImGui::PopItemWidth();
239 }
240
241 {
242 SPICES_PROFILE_ZONEN("MeshComponent Materials Type");
243
244 ImGui::CenteredText("Type", textSize);
245 ImGui::SameLine(2.0f * ImGuiH::GetLineItemSize().x);
246 char buffer2[256] = {};
247 ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGuiH::GetLineItemSize().x);
248 ImGui::InputTextWithHint("##_1", ICON_TEXT_ROW(" ", "PathTracing Material"), buffer2, sizeof(buffer2));
249 ImGui::PopItemWidth();
250 }
251 ImGui::EndGroup();
252
253 ImGui::Columns(1);
254 ImGui::PopID();
255 ImGui::Spacing();
256 }
257
258 ImGui::PopStyleVar();
259 ImGui::TreePop();
260 }
261 }
262 }
263
264 ImGui::TreePop();
265 }
266
267 ImGui::PopStyleColor(4);
268 }
269
270 ImGui::PopStyleVar();
271 ImGui::Spacing();
272 }
273
274 void MeshComponent::SetMesh(std::shared_ptr<Mesh> mesh)
275 {
277
278 auto& e = FrameInfo::Get().m_World->QueryEntitybyID((uint32_t)m_Owner);
279
280 /**
281 * @brief Set m_Mesh.
282 */
283 m_Mesh = mesh;
284
285 /**
286 * @brief Registry this mesh to world.
287 */
288 mesh->GetPacks().for_each([&](auto& k, auto& v) {
289 v->GetMeshDesc().UpdatemodelAddress(e.GetComponent<TransformComponent>().GetModelBufferAddress());
290 v->GetMeshDesc().UpdateentityID((uint32_t)m_Owner);
291 return false;
292 });
293 }
294}
#define ICON_TEXT_ROW(icon, text)
Definition ImguiHelper.h:25
#define SPICES_PROFILE_ZONEN(...)
#define SPICES_PROFILE_ZONE
virtual void DrawThis() override
This interface defines how to draw this component to property panel.
virtual void OnSerialize() override
This interface defines how to serialize.
void SetMesh(std::shared_ptr< Mesh > mesh)
Set the Mesh this component handled.
virtual void OnDeSerialize() override
This interface defines how to deserialize.
MeshComponent Class. This class defines the specific behaves of MeshComponent.
MeshRenderer Class. This class is a wrapper of mashpack.
Definition Mesh.h:21