MQEngine
载入中...
搜索中...
未找到
ComponentRenderer.h
浏览该文件的文档.
1#ifndef COMPONENTRENDERER_H
2#define COMPONENTRENDERER_H
3
5
6namespace MQEngine {
7
8 template<typename T>
9 void renderComponent(const T* component);
10
11 template<>
12 inline void renderComponent<NameTag>(const NameTag* component) {
13 if (ImGui::CollapsingHeader("NameTag", ImGuiTreeNodeFlags_DefaultOpen)) {
14 ImGui::Indent();
15 ImGui::Text("名称: %s", component->name.c_str());
16 ImGui::Unindent();
17 }
18 }
19
20 template<>
22 if (ImGui::CollapsingHeader("Position", ImGuiTreeNodeFlags_DefaultOpen)) {
23 ImGui::Indent();
24
25 static float pos[3] = {component->position.x, component->position.y, component->position.z};
26 pos[0] = component->position.x;
27 pos[1] = component->position.y;
28 pos[2] = component->position.z;
29
30 if (ImGui::DragFloat3("Position", pos, 0.1f)) {
31 auto& selectedEntity = g_editorGlobal.selectedEntity;
32 if (selectedEntity.scene) {
33 entt::registry* registry;
34 if (selectedEntity.isGlobal) {
35 registry = &selectedEntity.scene->getRegistry();
36 } else {
37 SceneTrunk* trunk = selectedEntity.scene->getLoadedTrunk(selectedEntity.trunkName);
38 if (!trunk) return;
39 registry = &trunk->getRegistry();
40 }
41
42 if (registry->valid(selectedEntity.entity)) {
43 auto* mutableComponent = registry->try_get<PositionComponent>(selectedEntity.entity);
44 if (mutableComponent) {
45 mutableComponent->position.x = pos[0];
46 mutableComponent->position.y = pos[1];
47 mutableComponent->position.z = pos[2];
48 }
49 }
50 }
51 }
52
53 ImGui::Spacing();
54 if (ImGui::Button("删除组件##PositionComponent")) {
55 g_editorGlobal.componentToDelete = entt::type_hash<PositionComponent>::value();
56 }
57
58 ImGui::Unindent();
59 }
60 }
61
62 template<>
63 inline void renderComponent<RotationComponent>(const RotationComponent* component) {
64 if (ImGui::CollapsingHeader("Rotation", ImGuiTreeNodeFlags_DefaultOpen)) {
65 ImGui::Indent();
66
67 static float rot[3] = {component->rotation.x, component->rotation.y, component->rotation.z};
68 rot[0] = component->rotation.x;
69 rot[1] = component->rotation.y;
70 rot[2] = component->rotation.z;
71
72 if (ImGui::DragFloat3("Rotation (degrees)", rot, 1.0f)) {
73 auto& selectedEntity = g_editorGlobal.selectedEntity;
74 if (selectedEntity.scene) {
75 entt::registry* registry;
76 if (selectedEntity.isGlobal) {
77 registry = &selectedEntity.scene->getRegistry();
78 } else {
79 SceneTrunk* trunk = selectedEntity.scene->getLoadedTrunk(selectedEntity.trunkName);
80 if (!trunk) return;
81 registry = &trunk->getRegistry();
82 }
83
84 if (registry->valid(selectedEntity.entity)) {
85 auto* mutableComponent = registry->try_get<RotationComponent>(selectedEntity.entity);
86 if (mutableComponent) {
87 mutableComponent->rotation.x = rot[0];
88 mutableComponent->rotation.y = rot[1];
89 mutableComponent->rotation.z = rot[2];
90 }
91 }
92 }
93 }
94
95 ImGui::Spacing();
96 if (ImGui::Button("删除组件##RotationComponent")) {
97 g_editorGlobal.componentToDelete = entt::type_hash<RotationComponent>::value();
98 }
99
100 ImGui::Unindent();
101 }
102 }
103
104 template<>
105 inline void renderComponent<ScaleComponent>(const ScaleComponent* component) {
106 if (ImGui::CollapsingHeader("Scale", ImGuiTreeNodeFlags_DefaultOpen)) {
107 ImGui::Indent();
108
109 static float scale[3] = {component->scale.x, component->scale.y, component->scale.z};
110 scale[0] = component->scale.x;
111 scale[1] = component->scale.y;
112 scale[2] = component->scale.z;
113
114 if (ImGui::DragFloat3("Scale", scale, 0.01f, 0.001f, 100.0f)) {
115 auto& selectedEntity = g_editorGlobal.selectedEntity;
116 if (selectedEntity.scene) {
117 entt::registry* registry;
118 if (selectedEntity.isGlobal) {
119 registry = &selectedEntity.scene->getRegistry();
120 } else {
121 SceneTrunk* trunk = selectedEntity.scene->getLoadedTrunk(selectedEntity.trunkName);
122 if (!trunk) return;
123 registry = &trunk->getRegistry();
124 }
125
126 if (registry->valid(selectedEntity.entity)) {
127 auto* mutableComponent = registry->try_get<ScaleComponent>(selectedEntity.entity);
128 if (mutableComponent) {
129 mutableComponent->scale.x = scale[0];
130 mutableComponent->scale.y = scale[1];
131 mutableComponent->scale.z = scale[2];
132 }
133 }
134 }
135 }
136
137 ImGui::Spacing();
138 if (ImGui::Button("删除组件##ScaleComponent")) {
139 g_editorGlobal.componentToDelete = entt::type_hash<ScaleComponent>::value();
140 }
141
142 ImGui::Unindent();
143 }
144 }
145
146 template<>
147 inline void renderComponent<CameraComponent>(const CameraComponent* component) {
148 if (ImGui::CollapsingHeader("Camera", ImGuiTreeNodeFlags_DefaultOpen)) {
149 ImGui::Indent();
150 ImGui::Text("激活: %s", component->active ? "是" : "否");
151 ImGui::Text("视野角度: %.1f°", component->fov);
152 ImGui::Text("近平面: %.3f", component->nearPlane);
153 ImGui::Text("远平面: %.1f", component->farPlane);
154 ImGui::Unindent();
155 }
156 }
157
158 template<>
160 if (ImGui::CollapsingHeader("StaticMeshInstance", ImGuiTreeNodeFlags_DefaultOpen)) {
161 ImGui::Indent();
162 ImGui::Text("模型UUID: %s", component->modelUuid.empty() ? "未设置" : component->modelUuid.c_str());
163 ImGui::Text("网格体名称: %s", component->meshName.empty() ? "未设置" : component->meshName.c_str());
164 if (component->mesh) {
165 ImGui::Text("网格状态: 已加载");
166 } else {
167 ImGui::Text("网格状态: 未加载");
168 }
169
170 ImGui::Spacing();
171 if (ImGui::Button("删除组件##StaticMeshInstance")) {
172 g_editorGlobal.componentToDelete = entt::type_hash<StaticMeshInstance>::value();
173 }
174
175 ImGui::Unindent();
176 }
177 }
178
179 template<>
180 inline void renderComponent<TickerScriptComponent>(const TickerScriptComponent* component) {
181 if (ImGui::CollapsingHeader("Ticker Script", ImGuiTreeNodeFlags_DefaultOpen)) {
182 ImGui::Indent();
183 ImGui::Text("函数名: %s", component->functionName.empty() ? "未设置" : component->functionName.c_str());
184
185 ImGui::Spacing();
186 if (ImGui::Button("删除组件##TickerScriptComponent")) {
187 g_editorGlobal.componentToDelete = entt::type_hash<TickerScriptComponent>::value();
188 }
189
190 ImGui::Unindent();
191 }
192 }
193
194 template<>
195 inline void renderComponent<OnStartScriptComponent>(const OnStartScriptComponent* component) {
196 if (ImGui::CollapsingHeader("OnStart Script", ImGuiTreeNodeFlags_DefaultOpen)) {
197 ImGui::Indent();
198 ImGui::Text("函数名: %s", component->functionName.empty() ? "未设置" : component->functionName.c_str());
199
200 ImGui::Spacing();
201 if (ImGui::Button("删除组件##OnStartScriptComponent")) {
202 g_editorGlobal.componentToDelete = entt::type_hash<OnStartScriptComponent>::value();
203 }
204
205 ImGui::Unindent();
206 }
207 }
208
209 template<>
210 inline void renderComponent<CacheRotationMatrix>(const CacheRotationMatrix* component) {
211 if (ImGui::CollapsingHeader("CacheRotationMatrix", ImGuiTreeNodeFlags_DefaultOpen)) {
212 ImGui::Indent();
213 ImGui::Text("旋转矩阵 (缓存)");
214 ImGui::Text("[%.3f, %.3f, %.3f, %.3f]",
215 component->rotationMatrix.m[0], component->rotationMatrix.m[1],
216 component->rotationMatrix.m[2], component->rotationMatrix.m[3]);
217 ImGui::Text("[%.3f, %.3f, %.3f, %.3f]",
218 component->rotationMatrix.m[4], component->rotationMatrix.m[5],
219 component->rotationMatrix.m[6], component->rotationMatrix.m[7]);
220 ImGui::Text("[%.3f, %.3f, %.3f, %.3f]",
221 component->rotationMatrix.m[8], component->rotationMatrix.m[9],
222 component->rotationMatrix.m[10], component->rotationMatrix.m[11]);
223 ImGui::Text("[%.3f, %.3f, %.3f, %.3f]",
224 component->rotationMatrix.m[12], component->rotationMatrix.m[13],
225 component->rotationMatrix.m[14], component->rotationMatrix.m[15]);
226 ImGui::Unindent();
227 }
228 }
229
230 template<>
232 if (ImGui::CollapsingHeader("CacheModelMatrix", ImGuiTreeNodeFlags_DefaultOpen)) {
233 ImGui::Indent();
234 ImGui::Text("模型矩阵 (缓存)");
235 ImGui::Text("Uniform已缓存并上传到GPU");
236 ImGui::Unindent();
237 }
238 }
239
240 template<>
241 inline void renderComponent<DirectionalLightComponent>(const DirectionalLightComponent* component) {
242 if (ImGui::CollapsingHeader("Directional Light", ImGuiTreeNodeFlags_DefaultOpen)) {
243 ImGui::Indent();
244
245 static float direction[3] = {component->direction.x, component->direction.y, component->direction.z};
246 direction[0] = component->direction.x;
247 direction[1] = component->direction.y;
248 direction[2] = component->direction.z;
249
250 if (ImGui::DragFloat3("Direction", direction, 0.01f, -1.0f, 1.0f)) {
251 auto& selectedEntity = g_editorGlobal.selectedEntity;
252 if (selectedEntity.scene) {
253 entt::registry* registry;
254 if (selectedEntity.isGlobal) {
255 registry = &selectedEntity.scene->getRegistry();
256 } else {
257 SceneTrunk* trunk = selectedEntity.scene->getLoadedTrunk(selectedEntity.trunkName);
258 if (!trunk) return;
259 registry = &trunk->getRegistry();
260 }
261
262 if (registry->valid(selectedEntity.entity)) {
263 auto* mutableComponent = registry->try_get<DirectionalLightComponent>(selectedEntity.entity);
264 if (mutableComponent) {
265 mutableComponent->direction.x = direction[0];
266 mutableComponent->direction.y = direction[1];
267 mutableComponent->direction.z = direction[2];
268 }
269 }
270 }
271 }
272
273 static float color[3] = {component->color.x, component->color.y, component->color.z};
274 color[0] = component->color.x;
275 color[1] = component->color.y;
276 color[2] = component->color.z;
277
278 if (ImGui::ColorEdit3("Color", color)) {
279 auto& selectedEntity = g_editorGlobal.selectedEntity;
280 if (selectedEntity.scene) {
281 entt::registry* registry;
282 if (selectedEntity.isGlobal) {
283 registry = &selectedEntity.scene->getRegistry();
284 } else {
285 SceneTrunk* trunk = selectedEntity.scene->getLoadedTrunk(selectedEntity.trunkName);
286 if (!trunk) return;
287 registry = &trunk->getRegistry();
288 }
289
290 if (registry->valid(selectedEntity.entity)) {
291 auto* mutableComponent = registry->try_get<DirectionalLightComponent>(selectedEntity.entity);
292 if (mutableComponent) {
293 mutableComponent->color.x = color[0];
294 mutableComponent->color.y = color[1];
295 mutableComponent->color.z = color[2];
296 }
297 }
298 }
299 }
300
301 static float intensity = component->intensity;
302 intensity = component->intensity;
303
304 if (ImGui::SliderFloat("Intensity", &intensity, 0.0f, 5.0f)) {
305 auto& selectedEntity = g_editorGlobal.selectedEntity;
306 if (selectedEntity.scene) {
307 entt::registry* registry;
308 if (selectedEntity.isGlobal) {
309 registry = &selectedEntity.scene->getRegistry();
310 } else {
311 SceneTrunk* trunk = selectedEntity.scene->getLoadedTrunk(selectedEntity.trunkName);
312 if (!trunk) return;
313 registry = &trunk->getRegistry();
314 }
315
316 if (registry->valid(selectedEntity.entity)) {
317 auto* mutableComponent = registry->try_get<DirectionalLightComponent>(selectedEntity.entity);
318 if (mutableComponent) {
319 mutableComponent->intensity = intensity;
320 }
321 }
322 }
323 }
324
325 static bool enabled = component->enabled;
326 enabled = component->enabled;
327
328 if (ImGui::Checkbox("Enabled", &enabled)) {
329 auto& selectedEntity = g_editorGlobal.selectedEntity;
330 if (selectedEntity.scene) {
331 entt::registry* registry;
332 if (selectedEntity.isGlobal) {
333 registry = &selectedEntity.scene->getRegistry();
334 } else {
335 SceneTrunk* trunk = selectedEntity.scene->getLoadedTrunk(selectedEntity.trunkName);
336 if (!trunk) return;
337 registry = &trunk->getRegistry();
338 }
339
340 if (registry->valid(selectedEntity.entity)) {
341 auto* mutableComponent = registry->try_get<DirectionalLightComponent>(selectedEntity.entity);
342 if (mutableComponent) {
343 mutableComponent->enabled = enabled;
344 }
345 }
346 }
347 }
348
349 ImGui::Spacing();
350 if (ImGui::Button("删除组件##DirectionalLightComponent")) {
351 g_editorGlobal.componentToDelete = entt::type_hash<DirectionalLightComponent>::value();
352 }
353
354 ImGui::Unindent();
355 }
356 }
357
358 template<>
359 inline void renderComponent<DiffuseTextureComponent>(const DiffuseTextureComponent* component) {
360 if (ImGui::CollapsingHeader("Diffuse Texture", ImGuiTreeNodeFlags_DefaultOpen)) {
361 ImGui::Indent();
362 ImGui::Text("模型UUID: %s", component->modelUuid.empty() ? "未设置" : component->modelUuid.c_str());
363 ImGui::Text("纹理路径: %s", component->texturePath.empty() ? "未设置" : component->texturePath.c_str());
364 ImGui::Text("纹理状态: %s", component->texture ? "已加载" : "未加载");
365
366 ImGui::Spacing();
367 if (ImGui::Button("删除组件##DiffuseTextureComponent")) {
368 g_editorGlobal.componentToDelete = entt::type_hash<DiffuseTextureComponent>::value();
369 }
370
371 ImGui::Unindent();
372 }
373 }
374
375 template<>
376 inline void renderComponent<NormalMapComponent>(const NormalMapComponent* component) {
377 if (ImGui::CollapsingHeader("Normal Map", ImGuiTreeNodeFlags_DefaultOpen)) {
378 ImGui::Indent();
379 ImGui::Text("模型UUID: %s", component->modelUuid.empty() ? "未设置" : component->modelUuid.c_str());
380 ImGui::Text("纹理路径: %s", component->texturePath.empty() ? "未设置" : component->texturePath.c_str());
381 ImGui::Text("纹理状态: %s", component->texture ? "已加载" : "未加载");
382
383 ImGui::Spacing();
384 if (ImGui::Button("删除组件##NormalMapComponent")) {
385 g_editorGlobal.componentToDelete = entt::type_hash<NormalMapComponent>::value();
386 }
387
388 ImGui::Unindent();
389 }
390 }
391
392 template<>
393 inline void renderComponent<ShininessComponent>(const ShininessComponent* component) {
394 if (ImGui::CollapsingHeader("Shininess", ImGuiTreeNodeFlags_DefaultOpen)) {
395 ImGui::Indent();
396
397 static float shininess = component->shininess;
398 shininess = component->shininess;
399
400 if (ImGui::DragFloat("Shininess", &shininess, 1.0f, 1.0f, 256.0f)) {
401 auto& selectedEntity = g_editorGlobal.selectedEntity;
402 if (selectedEntity.scene) {
403 entt::registry* registry;
404 if (selectedEntity.isGlobal) {
405 registry = &selectedEntity.scene->getRegistry();
406 } else {
407 SceneTrunk* trunk = selectedEntity.scene->getLoadedTrunk(selectedEntity.trunkName);
408 if (!trunk) return;
409 registry = &trunk->getRegistry();
410 }
411
412 if (registry->valid(selectedEntity.entity)) {
413 auto* mutableComponent = registry->try_get<ShininessComponent>(selectedEntity.entity);
414 if (mutableComponent) {
415 mutableComponent->shininess = shininess;
416 }
417 }
418 }
419 }
420
421 ImGui::Spacing();
422 if (ImGui::Button("删除组件##ShininessComponent")) {
423 g_editorGlobal.componentToDelete = entt::type_hash<ShininessComponent>::value();
424 }
425
426 ImGui::Unindent();
427 }
428 }
429
430} // MQEngine
431
432#endif //COMPONENTRENDERER_H
A header file containing third party libraries and macros for platform
定义 SceneTrunk.h:23
entt::registry & getRegistry()
定义 SceneTrunk.h:29
Entrypoint for the program.
定义 application.h:5
void renderComponent< DiffuseTextureComponent >(const DiffuseTextureComponent *component)
定义 ComponentRenderer.h:359
void renderComponent< RotationComponent >(const RotationComponent *component)
定义 ComponentRenderer.h:63
void renderComponent< NormalMapComponent >(const NormalMapComponent *component)
定义 ComponentRenderer.h:376
void renderComponent< ShininessComponent >(const ShininessComponent *component)
定义 ComponentRenderer.h:393
void renderComponent< DirectionalLightComponent >(const DirectionalLightComponent *component)
定义 ComponentRenderer.h:241
void renderComponent< PositionComponent >(const PositionComponent *component)
定义 ComponentRenderer.h:21
void renderComponent< OnStartScriptComponent >(const OnStartScriptComponent *component)
定义 ComponentRenderer.h:195
void renderComponent< TickerScriptComponent >(const TickerScriptComponent *component)
定义 ComponentRenderer.h:180
void renderComponent< ScaleComponent >(const ScaleComponent *component)
定义 ComponentRenderer.h:105
void renderComponent< CacheRotationMatrix >(const CacheRotationMatrix *component)
定义 ComponentRenderer.h:210
void renderComponent< CacheModelMatrix >(const CacheModelMatrix *component)
定义 ComponentRenderer.h:231
EditorGlobal g_editorGlobal
定义 EditorApplication.cpp:5
void renderComponent(const T *component)
void renderComponent< CameraComponent >(const CameraComponent *component)
定义 ComponentRenderer.h:147
void renderComponent< NameTag >(const NameTag *component)
定义 ComponentRenderer.h:12
void renderComponent< StaticMeshInstance >(const StaticMeshInstance *component)
定义 ComponentRenderer.h:159
定义 Camera.h:67
定义 NameTag.h:9
std::string name
定义 NameTag.h:10
定义 Camera.h:16
FCT::Vec3 position
定义 Camera.h:17
定义 Component.h:13
FCT::StaticMesh< uint32_t > * mesh
定义 Component.h:16
std::string modelUuid
定义 Component.h:14
std::string meshName
定义 Component.h:15