SpiecsEngine
 
Loading...
Searching...
No Matches
ImguiMaterialPanel.cpp
Go to the documentation of this file.
1/**
2* @file ImguiMaterialPanel.cpp.
3* @brief The ImguiMaterialPanel Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
9
10namespace Spices {
11
13 {
15
16 /**
17 * @brief Begin render Property.
18 */
19 Begin();
20
21 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(2.0f, 4.0f));
22
23 /**
24 * @brief Search String.
25 */
26 static std::string searchString;
27 static bool isEnableSearch = false;
28
29 /**
30 * @brief Begin render Search Input Text.
31 */
32 {
33 SPICES_PROFILE_ZONEN("ImguiMaterialPanel::Search");
34
35 ImGui::Spacing();
36 ImGui::PushItemWidth(m_PanelSize.x - ImGuiH::GetLineItemSize().x * 2.0f - ImGui::GetStyle().WindowPadding.x);
37 static char search[256] = {};
38 if (ImGui::InputTextWithHint("##", ICON_TEXT(ICON_MD_SEARCH, Search), search, 128))
39 {
40 searchString = std::string(search);
41 if (searchString.size() == 0) isEnableSearch = false;
42 else isEnableSearch = true;
43 }
44 ImGui::PopItemWidth();
45
46 ImGui::SameLine(m_PanelSize.x - ImGuiH::GetLineItemSize().x * 2.0f);
47 ImGui::Button(ICON_MD_FILTER_ALT, ImGuiH::GetLineItemSize());
48 ImGui::SameLine(m_PanelSize.x - ImGuiH::GetLineItemSize().x * 1.0f);
49 ImGui::Button(ICON_MD_REORDER, ImGuiH::GetLineItemSize());
50 ImGui::Spacing();
51 }
52
53 if(m_FrameInfo.m_PickEntityID.size() == 0)
54 {
55 ImGui::PopStyleVar();
56 End();
57 return;
58 }
59
60 Entity entity(static_cast<entt::entity>(*m_FrameInfo.m_PickEntityID.end_k()), m_FrameInfo.m_World.get());
61 if(!entity.HasComponent<MeshComponent>())
62 {
63 ImGui::PopStyleVar();
64 End();
65 return;
66 }
67
68 MeshComponent meshComp = entity.GetComponent<MeshComponent>();
69 const uint32_t materialIndex = FrameInfo::Get().m_PickMaterial;
70
71 if(!meshComp.GetMesh()->GetPacks().has_key(materialIndex))
72 {
73 ImGui::PopStyleVar();
74 End();
75 return;
76 }
77
78 float columeWidth = ImGuiH::GetLineItemSize().x * 6.5f;
79 ImGuiTreeNodeFlags treeNodeFlags =
80 ImGuiTreeNodeFlags_DefaultOpen |
81 ImGuiTreeNodeFlags_AllowItemOverlap |
82 ImGuiTreeNodeFlags_Framed |
83 ImGuiTreeNodeFlags_FramePadding ;
84 //ImGuiTreeNodeFlags_Bullet ;
85
86 const std::shared_ptr<MeshPack>& meshPack = *meshComp.GetMesh()->GetPacks().find_value(materialIndex);
87 std::shared_ptr<Material> material = meshPack->GetMaterial();
88
89 /**
90 * @brief End if not a select entity.
91 */
92 if (m_FrameInfo.m_PickEntityID.size() == 0)
93 {
94 SPICES_PROFILE_ZONEN("ImguiMaterialPanel::End");
95
96 ImGui::PopStyleVar();
97 End();
98
99 return;
100 }
101
102 /**
103 * @brief Render Datails.
104 */
105 {
106 SPICES_PROFILE_ZONEN("ImguiMaterialPanel::Datails");
107
108 {
109 ImGui::PushID("ImguiMaterialPanel::Add");
110
111 ImGui::Columns(2, 0, false);
112 ImGui::SetColumnWidth(0, ImGuiH::GetLineItemSize().x * 4.0f);
113 ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.16f, 0.16f, 0.16f, 1.0f));
114 ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.619f, 0.619f, 0.619f, 1.0f));
115 ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.408f, 0.451f, 0.18f, 1.0f));
116 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.341f, 0.486f, 0.353f, 1.0f));
117 ImGui::Button(ICON_TEXT(ICON_MD_ADD, Add));
118 ImGui::PopStyleColor(4);
119 ImGui::NextColumn();
120
121 ImGui::PushItemWidth(m_PanelSize.x - ImGuiH::GetLineItemSize().x * 4.0f);
122 char text[128] = "";
123 if (ImGui::InputTextWithHint("##", ICON_TEXT_ROW(" ", material->GetName().c_str()), text, 128)) {}
124 ImGui::PopItemWidth();
125
126 ImGui::Columns(1);
127 ImGui::PopID();
128 }
129
130 {
131 ImGui::PushID("ImguiMaterialPanel::Prim Path");
132 ImGui::Columns(2, 0, false);
133 ImGui::SetColumnWidth(0, ImGuiH::GetLineItemSize().x * 4.0f);
134 ImGui::Text("Prim Path");
135 ImGui::NextColumn();
136
137 std::stringstream ss;
138 ss << "/" << material->GetName();
139 ImGui::PushItemWidth(m_PanelSize.x - ImGuiH::GetLineItemSize().x * 4.0f);
140 char textpath[128] = "";
141 if (ImGui::InputTextWithHint("##", ICON_TEXT_ROW(" ", ss.str().c_str()), textpath, 128)) {}
142 ImGui::PopItemWidth();
143
144 ImGui::Columns(1);
145 ImGui::PopID();
146 }
147
148 {
149 ImGui::PushID("ImguiMaterialPanel::Instanceable");
150 ImGui::Columns(2, 0, false);
151 ImGui::SetColumnWidth(0, ImGuiH::GetLineItemSize().x * 4.0f);
152 ImGui::Text("Instanceable");
153 ImGui::NextColumn();
154
155 static bool isChecked;
156 ImGuiH::Checkbox(&isChecked);
157 ImGui::Columns(1);
158 ImGui::PopID();
159 }
160 }
161
162
163 /**
164 * @brief Render All Parameter.
165 */
166 {
167 SPICES_PROFILE_ZONEN("ImguiMaterialPanel::Parameter");
168
169 {
170 SPICES_PROFILE_ZONEN("ImguiMaterialPanel::ShaderParameter");
171
172 ImGuiH::DrawTreeTitle("Shader", nullptr, [&](){
173 for(auto& pair : material->GetShaderPath())
174 {
175 ImGuiH::DrawPropertyItem(pair.first, columeWidth, nullptr, [&](){
176
177 ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGuiH::GetLineItemSize().x);
178 char buffer[128] = {};
179 ImGui::InputTextWithHint("##", ICON_TEXT_ROW(" ", pair.second[0].c_str()), buffer, sizeof(buffer));
180 ImGui::PopItemWidth();
181
182 ImGui::SameLine();
183 ImGuiH::DrawResetIcon(false);
184 });
185 }
186 });
187 }
188
189 {
190 SPICES_PROFILE_ZONEN("ImguiMaterialPanel::TextureParameter");
191
192 ImGuiH::DrawTreeTitle("Texture", nullptr, [&](){
193 material->GetTextureParams().for_each([&](const auto& k, const auto& v) {
194
195 ImGuiH::DrawPropertyItem(k, columeWidth, nullptr, [&](){
196
197 ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGuiH::GetLineItemSize().x);
198 char buffer[128] = {};
199 ImGui::InputTextWithHint("##", ICON_TEXT_ROW(" ", v.texturePath.c_str()), buffer, sizeof(buffer));
200 ImGui::PopItemWidth();
201
202 ImGui::SameLine();
203 ImGuiH::DrawResetIcon(false);
204 });
205 return false;
206 });
207 });
208 }
209
210 {
211 SPICES_PROFILE_ZONEN("ImguiMaterialPanel::ConstantParameter");
212
213 ImGuiH::DrawTreeTitle("Parameter", nullptr, [&](){
214 material->GetConstantParams().for_each([&](const std::string& k, ConstantParams& v){
215 ImGuiH::DrawPropertyItem(k, columeWidth, nullptr, [&](){
216 if (v.value.paramType == "float")
217 {
218 if (ImGuiH::DrawMaterialConstParams<float>(material, ImGuiDataType_Float, 1, "%.3f", v))
219 {
220 FrameInfo::Get().m_World->Mark(World::NeedUpdateTLAS | World::FrushStableFrame);
221 }
222 }
223 else if (v.value.paramType == "float2")
224 {
225 if (ImGuiH::DrawMaterialConstParams<glm::vec2>(material, ImGuiDataType_Float, 2, "%.3f", v))
226 {
227 FrameInfo::Get().m_World->Mark(World::NeedUpdateTLAS | World::FrushStableFrame);
228 }
229 }
230 else if (v.value.paramType == "float3")
231 {
232 if (ImGuiH::DrawMaterialConstParams<glm::vec3>(material, ImGuiDataType_Float, 3, "%.3f", v))
233 {
234 FrameInfo::Get().m_World->Mark(World::NeedUpdateTLAS | World::FrushStableFrame);
235 }
236 }
237 else if (v.value.paramType == "float4")
238 {
239 if (ImGuiH::DrawMaterialConstParams<glm::vec4>(material, ImGuiDataType_Float, 4, "%.3f", v))
240 {
241 FrameInfo::Get().m_World->Mark(World::NeedUpdateTLAS | World::FrushStableFrame);
242 }
243 }
244 else if (v.value.paramType == "int")
245 {
246 if (ImGuiH::DrawMaterialConstParams<int>(material, ImGuiDataType_S32, 1, "%d", v))
247 {
248 FrameInfo::Get().m_World->Mark(World::NeedUpdateTLAS | World::FrushStableFrame);
249 }
250 }
251 else if (v.value.paramType == "bool")
252 {
253
254 }
255 });
256 return false;
257 });
258 });
259 }
260
261 {
262 SPICES_PROFILE_ZONEN("ImguiMaterialPanel::Property");
263
264
265 }
266 }
267
268 /**
269 * @brief End render Property.
270 */
271 ImGui::PopStyleVar();
272 End();
273 }
274}
#define ICON_TEXT(icon, text)
Definition ImguiHelper.h:24
#define ICON_TEXT_ROW(icon, text)
Definition ImguiHelper.h:25
#define SPICES_PROFILE_ZONEN(...)
#define SPICES_PROFILE_ZONE
Entity Class. This class defines the specific behaves of Entity.
Definition Entity.h:20
uint32_t m_PickMaterial
Identify of selected material.
Definition FrameInfo.h:89
static FrameInfo & Get()
Get FrameInfo.
Definition FrameInfo.cpp:14
FrameInfo Class. This class defines the FrameInfo data.
Definition FrameInfo.h:32
static void Checkbox(bool *isChecked)
ImGuiHelper Style Checkbox.
static void DrawTreeTitle(const std::string &treeName, std::function< void()> optionFunc, std::function< void()> treeFunc)
Draw a stylized tree title bar.
The ImGuiH Class. This class defines helper function for slate render.
Definition ImguiHelper.h:61
virtual void OnRender() override
This interface is called On SlateRenderer Render.
The ImguiMaterialPanel Class. This class defines how to render a Material Property.
FrameInfo & m_FrameInfo
The FrameData reference.
Definition ImguiUtils.h:166
void End()
End a slate.
Material Class. This class contains a branch of parameter and shader, also descriptor.
Definition Material.h:62
MeshComponent Class. This class defines the specific behaves of MeshComponent.
MeshPack Class. This class defines some basic behaves and variables. This class need to be inherited ...
Definition MeshPack.h:156