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<ScriptComponent>(const ScriptComponent* component) {
181 if (ImGui::CollapsingHeader("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("删除组件##ScriptComponent")) {
187 g_editorGlobal.componentToDelete = entt::type_hash<ScriptComponent>::value();
188 }
189
190 ImGui::Unindent();
191 }
192 }
193
194 template<>
195 inline void renderComponent<CacheRotationMatrix>(const CacheRotationMatrix* component) {
196 if (ImGui::CollapsingHeader("CacheRotationMatrix", ImGuiTreeNodeFlags_DefaultOpen)) {
197 ImGui::Indent();
198 ImGui::Text("旋转矩阵 (缓存)");
199 ImGui::Text("[%.3f, %.3f, %.3f, %.3f]",
200 component->rotationMatrix.m[0], component->rotationMatrix.m[1],
201 component->rotationMatrix.m[2], component->rotationMatrix.m[3]);
202 ImGui::Text("[%.3f, %.3f, %.3f, %.3f]",
203 component->rotationMatrix.m[4], component->rotationMatrix.m[5],
204 component->rotationMatrix.m[6], component->rotationMatrix.m[7]);
205 ImGui::Text("[%.3f, %.3f, %.3f, %.3f]",
206 component->rotationMatrix.m[8], component->rotationMatrix.m[9],
207 component->rotationMatrix.m[10], component->rotationMatrix.m[11]);
208 ImGui::Text("[%.3f, %.3f, %.3f, %.3f]",
209 component->rotationMatrix.m[12], component->rotationMatrix.m[13],
210 component->rotationMatrix.m[14], component->rotationMatrix.m[15]);
211 ImGui::Unindent();
212 }
213 }
214
215 template<>
217 if (ImGui::CollapsingHeader("CacheModelMatrix", ImGuiTreeNodeFlags_DefaultOpen)) {
218 ImGui::Indent();
219 ImGui::Text("模型矩阵 (缓存)");
220 ImGui::Text("Uniform已缓存并上传到GPU");
221 ImGui::Unindent();
222 }
223 }
224
225 template<>
226 inline void renderComponent<DirectionalLightComponent>(const DirectionalLightComponent* component) {
227 if (ImGui::CollapsingHeader("Directional Light", ImGuiTreeNodeFlags_DefaultOpen)) {
228 ImGui::Indent();
229
230 static float direction[3] = {component->direction.x, component->direction.y, component->direction.z};
231 direction[0] = component->direction.x;
232 direction[1] = component->direction.y;
233 direction[2] = component->direction.z;
234
235 if (ImGui::DragFloat3("Direction", direction, 0.01f, -1.0f, 1.0f)) {
236 auto& selectedEntity = g_editorGlobal.selectedEntity;
237 if (selectedEntity.scene) {
238 entt::registry* registry;
239 if (selectedEntity.isGlobal) {
240 registry = &selectedEntity.scene->getRegistry();
241 } else {
242 SceneTrunk* trunk = selectedEntity.scene->getLoadedTrunk(selectedEntity.trunkName);
243 if (!trunk) return;
244 registry = &trunk->getRegistry();
245 }
246
247 if (registry->valid(selectedEntity.entity)) {
248 auto* mutableComponent = registry->try_get<DirectionalLightComponent>(selectedEntity.entity);
249 if (mutableComponent) {
250 mutableComponent->direction.x = direction[0];
251 mutableComponent->direction.y = direction[1];
252 mutableComponent->direction.z = direction[2];
253 }
254 }
255 }
256 }
257
258 static float color[3] = {component->color.x, component->color.y, component->color.z};
259 color[0] = component->color.x;
260 color[1] = component->color.y;
261 color[2] = component->color.z;
262
263 if (ImGui::ColorEdit3("Color", color)) {
264 auto& selectedEntity = g_editorGlobal.selectedEntity;
265 if (selectedEntity.scene) {
266 entt::registry* registry;
267 if (selectedEntity.isGlobal) {
268 registry = &selectedEntity.scene->getRegistry();
269 } else {
270 SceneTrunk* trunk = selectedEntity.scene->getLoadedTrunk(selectedEntity.trunkName);
271 if (!trunk) return;
272 registry = &trunk->getRegistry();
273 }
274
275 if (registry->valid(selectedEntity.entity)) {
276 auto* mutableComponent = registry->try_get<DirectionalLightComponent>(selectedEntity.entity);
277 if (mutableComponent) {
278 mutableComponent->color.x = color[0];
279 mutableComponent->color.y = color[1];
280 mutableComponent->color.z = color[2];
281 }
282 }
283 }
284 }
285
286 static float intensity = component->intensity;
287 intensity = component->intensity;
288
289 if (ImGui::SliderFloat("Intensity", &intensity, 0.0f, 5.0f)) {
290 auto& selectedEntity = g_editorGlobal.selectedEntity;
291 if (selectedEntity.scene) {
292 entt::registry* registry;
293 if (selectedEntity.isGlobal) {
294 registry = &selectedEntity.scene->getRegistry();
295 } else {
296 SceneTrunk* trunk = selectedEntity.scene->getLoadedTrunk(selectedEntity.trunkName);
297 if (!trunk) return;
298 registry = &trunk->getRegistry();
299 }
300
301 if (registry->valid(selectedEntity.entity)) {
302 auto* mutableComponent = registry->try_get<DirectionalLightComponent>(selectedEntity.entity);
303 if (mutableComponent) {
304 mutableComponent->intensity = intensity;
305 }
306 }
307 }
308 }
309
310 static bool enabled = component->enabled;
311 enabled = component->enabled;
312
313 if (ImGui::Checkbox("Enabled", &enabled)) {
314 auto& selectedEntity = g_editorGlobal.selectedEntity;
315 if (selectedEntity.scene) {
316 entt::registry* registry;
317 if (selectedEntity.isGlobal) {
318 registry = &selectedEntity.scene->getRegistry();
319 } else {
320 SceneTrunk* trunk = selectedEntity.scene->getLoadedTrunk(selectedEntity.trunkName);
321 if (!trunk) return;
322 registry = &trunk->getRegistry();
323 }
324
325 if (registry->valid(selectedEntity.entity)) {
326 auto* mutableComponent = registry->try_get<DirectionalLightComponent>(selectedEntity.entity);
327 if (mutableComponent) {
328 mutableComponent->enabled = enabled;
329 }
330 }
331 }
332 }
333
334 ImGui::Spacing();
335 if (ImGui::Button("删除组件##DirectionalLightComponent")) {
336 g_editorGlobal.componentToDelete = entt::type_hash<DirectionalLightComponent>::value();
337 }
338
339 ImGui::Unindent();
340 }
341 }
342
343 template<>
344 inline void renderComponent<DiffuseTextureComponent>(const DiffuseTextureComponent* component) {
345 if (ImGui::CollapsingHeader("Diffuse Texture", ImGuiTreeNodeFlags_DefaultOpen)) {
346 ImGui::Indent();
347 ImGui::Text("模型UUID: %s", component->modelUuid.empty() ? "未设置" : component->modelUuid.c_str());
348 ImGui::Text("纹理路径: %s", component->texturePath.empty() ? "未设置" : component->texturePath.c_str());
349 ImGui::Text("纹理状态: %s", component->texture ? "已加载" : "未加载");
350
351 ImGui::Spacing();
352 if (ImGui::Button("删除组件##DiffuseTextureComponent")) {
353 g_editorGlobal.componentToDelete = entt::type_hash<DiffuseTextureComponent>::value();
354 }
355
356 ImGui::Unindent();
357 }
358 }
359
360} // MQEngine
361
362#endif //COMPONENTRENDERER_H
A header file containing third party libraries and macros for platform
定义 SceneTrunk.h:23
entt::registry & getRegistry()
定义 SceneTrunk.h:29
定义 application.h:5
void renderComponent< DiffuseTextureComponent >(const DiffuseTextureComponent *component)
定义 ComponentRenderer.h:344
void renderComponent< ScriptComponent >(const ScriptComponent *component)
定义 ComponentRenderer.h:180
void renderComponent< RotationComponent >(const RotationComponent *component)
定义 ComponentRenderer.h:63
void renderComponent< DirectionalLightComponent >(const DirectionalLightComponent *component)
定义 ComponentRenderer.h:226
void renderComponent< PositionComponent >(const PositionComponent *component)
定义 ComponentRenderer.h:21
void renderComponent< ScaleComponent >(const ScaleComponent *component)
定义 ComponentRenderer.h:105
void renderComponent< CacheRotationMatrix >(const CacheRotationMatrix *component)
定义 ComponentRenderer.h:195
void renderComponent< CacheModelMatrix >(const CacheModelMatrix *component)
定义 ComponentRenderer.h:216
EditorGlobal g_editorGlobal
定义 EditorApplication.cpp:4
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:12
FCT::StaticMesh< uint32_t > * mesh
定义 Component.h:15
std::string modelUuid
定义 Component.h:13
std::string meshName
定义 Component.h:14