NoJobEngine 2.0.7
Loading...
Searching...
No Matches
InspectorPanel.cpp
Go to the documentation of this file.
5
11#include "Engine/Scene/Scene.h"
19
21#include <imgui.h>
22#include <glm/gtc/type_ptr.hpp>
23
24#include <algorithm>
25#include <cstdio>
26#include <filesystem>
27#include <string>
28#include <vector>
29
30namespace NoJob
31{
32 void EditorLayer::DrawInspector()
33 {
34 ImGui::Begin("Inspector");
35
36 if (m_SelectedEntity)
37 {
38 auto& tag =
39 m_SelectedEntity.GetComponent<TagComponent>().Tag;
40
41 char tagBuffer[256]{};
42 std::snprintf(
43 tagBuffer,
44 sizeof(tagBuffer),
45 "%s",
46 tag.c_str());
47
48 if (m_RenameSelectedRequested)
49 {
50 ImGui::SetKeyboardFocusHere();
51 m_RenameSelectedRequested = false;
52 }
53 if (ImGui::InputText(
54 "##EntityName",
55 tagBuffer,
56 sizeof(tagBuffer),
57 ImGuiInputTextFlags_EnterReturnsTrue))
58 {
59 tag = tagBuffer;
60 }
61 if (m_MultiSelection.size() > 1)
62 {
63 ImGui::SameLine();
64 ImGui::TextDisabled("%zu selected", m_MultiSelection.size());
65 }
66 // Entity Layer
67 if (m_SelectedEntity.HasComponent<LayerComponent>())
68 {
69 auto& layer =
70 m_SelectedEntity.GetComponent<LayerComponent>();
71
72 constexpr const char* layerNames[] = {
73 "Default",
74 "Player",
75 "Enemy",
76 "Environment",
77 "Interactable"
78 };
79
80 const std::uint32_t currentLayer =
81 std::min(layer.Layer, std::uint32_t{ 31 });
82
83 const char* preview =
84 currentLayer < IM_ARRAYSIZE(layerNames)
85 ? layerNames[currentLayer]
86 : "Custom Layer";
87
88 if (ImGui::BeginCombo("Layer##Entity", preview))
89 {
90 for (std::uint32_t i = 0; i < IM_ARRAYSIZE(layerNames); ++i)
91 {
92 const bool selected = layer.Layer == i;
93
94 if (ImGui::Selectable(layerNames[i], selected))
95 {
96 CaptureUndoSnapshot();
97 layer.Layer = i;
98 }
99
100 if (selected)
101 ImGui::SetItemDefaultFocus();
102 }
103
104 ImGui::EndCombo();
105 }
106 }
107 ImGui::Separator();
108
109 if (ImGui::CollapsingHeader(
110 "Transform",
111 ImGuiTreeNodeFlags_DefaultOpen))
112 {
113 auto& transform =
114 m_SelectedEntity.GetComponent<TransformComponent>();
115
116 // Unity-style numeric transform fields with Undo/Redo transactions.
117 auto editTransform = [&](const char* label, glm::vec3& value)
118 {
119 ImGui::SetNextItemWidth(-1.0f);
120 ImGui::DragFloat3(
121 label,
122 &value.x,
123 0.01f,
124 0.0f,
125 0.0f,
126 "%.3f");
127
128 if (ImGui::IsItemActivated() && !m_TransformEditSnapshot)
129 m_TransformEditSnapshot = m_Scene->Copy();
130
131 if (ImGui::IsItemDeactivatedAfterEdit()
132 && m_TransformEditSnapshot)
133 {
134 PushUndoSnapshot(std::move(m_TransformEditSnapshot));
135 }
136 else if (ImGui::IsItemDeactivated()
137 && m_TransformEditSnapshot)
138 {
139 m_TransformEditSnapshot.reset();
140 }
141 };
142
143 editTransform("Position", transform.Position);
144 editTransform("Rotation", transform.Rotation);
145 editTransform("Scale", transform.Scale);
146
147 ImGui::TextDisabled(
148 "Ctrl + click to type | Ctrl+Z / Ctrl+Y to undo/redo.");
149 }
150
151 {
152 Entity parent = m_Scene->GetParent(m_SelectedEntity);
153 if (parent)
154 {
155 ImGui::TextDisabled(
156 "Parent: %s",
157 parent.GetComponent<TagComponent>().Tag.c_str());
158
159 ImGui::SameLine();
160 if (ImGui::SmallButton("Unparent"))
161 {
162 CaptureUndoSnapshot();
163 m_Scene->Unparent(m_SelectedEntity, true);
164 }
165 }
166 else
167 {
168 ImGui::TextDisabled("Parent: None");
169 }
170 }
171
172 if (m_SelectedEntity.HasComponent<MeshComponent>())
173 {
174 ImGui::Separator();
175
176 if (ImGui::CollapsingHeader(
177 "Mesh",
178 ImGuiTreeNodeFlags_DefaultOpen))
179 {
180 ImGui::TextDisabled("Primitive Mesh");
181 }
182 }
183
184 ImGui::Separator();
185 auto drawScript = [&](NativeScriptComponent& script, int scriptIndex)
186 {
187 ImGui::PushID(scriptIndex);
189 // BTAssetAgent is an engine builtin, not a project DLL script.
190 // Register it when displaying saved scripts as well as in Add Component.
193
194 const std::string header =
195 "Native Script: " + script.ScriptName;
196 if (ImGui::CollapsingHeader(
197 header.c_str(), ImGuiTreeNodeFlags_DefaultOpen))
198 {
199 auto beginEdit = [&]()
200 {
201 if (ImGui::IsItemActivated() &&
202 !m_ScriptFieldEditSnapshot)
203 m_ScriptFieldEditSnapshot = m_Scene->Copy();
204 };
205 auto endEdit = [&]()
206 {
207 if (ImGui::IsItemDeactivatedAfterEdit() &&
208 m_ScriptFieldEditSnapshot)
209 PushUndoSnapshot(
210 std::move(m_ScriptFieldEditSnapshot));
211 else if (ImGui::IsItemDeactivated() &&
212 m_ScriptFieldEditSnapshot)
213 m_ScriptFieldEditSnapshot.reset();
214 };
215
216 ImGui::Checkbox(
217 "Enabled##NativeScript", &script.Enabled);
218 beginEdit(); endEdit();
219 ImGui::TextDisabled("C++ Native Script");
220
221 const auto* definition =
222 ScriptRegistry::Find(script.ScriptName);
223 if (!definition)
224 {
225 ImGui::TextDisabled(
226 "Script definition not loaded. Compile Scripts.");
227 }
228 else
229 {
230 for (const auto& fieldDef : definition->Fields)
231 {
232 auto it = script.Fields.find(fieldDef.Name);
233 if (it == script.Fields.end()) continue;
234 auto& field = it->second;
235
236 ImGui::PushID(fieldDef.Name.c_str());
237 if ((script.ScriptName == "NeuralTrainingAgent" || script.ScriptName == "GenericNeuralAgent") &&
238 (fieldDef.Name == "TrainingOutputName" || fieldDef.Name == "ResumeSourceName" ||
239 fieldDef.Name == "TrainingPreset")) {
240 ImGui::TextDisabled("Configured in Neural Training below");
241 }
242 else if (field.Type == ScriptFieldType::Int &&
243 script.ScriptName == "GenericNeuralAgent" && fieldDef.Name == "ObservationPreset") {
244 const char* presets[]={"Relative Target XZ (2)","Target/Self Y (3)","Pong Ball State (6)"};
245 field.Int=std::clamp(field.Int,0,2);
246 ImGui::Combo("Observations",&field.Int,presets,3);
247 }
248 else if (field.Type == ScriptFieldType::Int &&
249 script.ScriptName == "GenericNeuralAgent" && fieldDef.Name == "ActionMode") {
250 const char* actions[]={"NavAgent XZ (2)","Move Transform Y (1)","Move Transform XZ (2)"};
251 field.Int=std::clamp(field.Int,0,2);
252 ImGui::Combo("Actions",&field.Int,actions,3);
253 }
254 else if (field.Type == ScriptFieldType::Float)
255 ImGui::DragFloat(
256 fieldDef.Name.c_str(), &field.Float, 0.05f);
257 else if (field.Type == ScriptFieldType::Int)
258 ImGui::DragInt(
259 fieldDef.Name.c_str(), &field.Int);
260 else if (field.Type == ScriptFieldType::Bool)
261 ImGui::Checkbox(
262 fieldDef.Name.c_str(), &field.Bool);
263 else if (field.Type == ScriptFieldType::String &&
264 script.ScriptName == "BTAssetAgent" &&
265 fieldDef.Name == "BehaviorTreeAsset")
266 {
267 const auto names = ListBTAssetNames();
268 const char* preview = field.String.empty() ? "Select a tree..." : field.String.c_str();
269 if (ImGui::BeginCombo("Behavior Tree Asset", preview))
270 {
271 for (const auto& name : names)
272 {
273 if (ImGui::Selectable(name.c_str(), field.String == name))
274 field.String = name;
275 }
276 ImGui::EndCombo();
277 }
278 if (names.empty()) ImGui::TextDisabled("No .njbt assets found. Create one in Behavior Tree Editor.");
279 else if (std::find(names.begin(), names.end(), field.String) == names.end())
280 ImGui::TextDisabled("Selected tree not found on disk.");
281 }
282 else if (field.Type == ScriptFieldType::String &&
283 script.ScriptName == "NeuralTrainingAgent" && fieldDef.Name == "ModelName")
284 {
285 const auto names=ListNeuralAssetNames();
286 if (ImGui::BeginCombo("Neural Model",field.String.empty()?"Select / create...":field.String.c_str())) {
287 for(const auto& name:names)
288 if(ImGui::Selectable(name.c_str(),field.String==name)) field.String=name;
289 ImGui::EndCombo();
290 }
291 ImGui::TextDisabled("Active model only. Training output is configured separately.");
292 }
293 else if (field.Type == ScriptFieldType::String &&
294 script.ScriptName == "GenericNeuralAgent" && fieldDef.Name == "ActiveModel")
295 {
296 const auto names=ListNeuralAssetNames();
297 if (ImGui::BeginCombo("Active Neural Model",field.String.empty()?"Select model...":field.String.c_str())) {
298 for(const auto& name:names)
299 if(ImGui::Selectable(name.c_str(),field.String==name)) field.String=name;
300 ImGui::EndCombo();
301 }
302 }
303 else if (field.Type == ScriptFieldType::String)
304 {
305 char buffer[256]{};
306 std::snprintf(buffer, sizeof(buffer), "%s", field.String.c_str());
307 if (ImGui::InputText(fieldDef.Name.c_str(), buffer, sizeof(buffer))) field.String = buffer;
308 }
309 else if (field.Type == ScriptFieldType::Vec3)
310 ImGui::DragFloat3(
311 fieldDef.Name.c_str(), &field.Vec3.x, 0.05f);
312 beginEdit(); endEdit();
313 ImGui::PopID();
314 }
315 if(script.ScriptName == "NeuralTrainingAgent" || script.ScriptName == "GenericNeuralAgent") {
316 ImGui::Separator();
317 ImGui::TextUnformatted("Supervised Neural Training");
318 ImGui::TextDisabled("Active Model and Save As are independent.");
319 auto& fields=script.Fields;
320 auto ensure=[&](const char* key, ScriptFieldValue value) {
321 if(!fields.count(key)) fields.emplace(key,std::move(value));
322 };
323 ensure("TrainingOutputName",ScriptFieldValue::MakeString("NeuralFollowerNew"));
324 ensure("ResumeSourceName",ScriptFieldValue::MakeString(""));
325 ensure("TrainingPreset",ScriptFieldValue::MakeInt(0));
326 auto& output=fields.at("TrainingOutputName").String;
327 auto& source=fields.at("ResumeSourceName").String;
328 auto& preset=fields.at("TrainingPreset").Int;
329 preset=std::clamp(preset,0,2);
330 const char* activeKey=script.ScriptName=="GenericNeuralAgent"?"ActiveModel":"ModelName";
331 ImGui::Text("Active: %s",fields.count(activeKey)?fields.at(activeKey).String.c_str():"(none)");
332 char outputBuffer[256]{};
333 std::snprintf(outputBuffer,sizeof(outputBuffer),"%s",output.c_str());
334 if(ImGui::InputText("Save Training As",outputBuffer,sizeof(outputBuffer))) output=outputBuffer;
335 const auto names=ListNeuralAssetNames();
336 if(ImGui::BeginCombo("Resume Source",source.empty()?"None (fresh training)":source.c_str())) {
337 if(ImGui::Selectable("None (fresh training)",source.empty())) source.clear();
338 for(const auto& item:names)
339 if(ImGui::Selectable(item.c_str(),source==item)) source=item;
340 ImGui::EndCombo();
341 }
342 const char* presets[]={"Follow XZ (2 -> 2)","Track Y (3 -> 1)","Pong (6 -> 1)"};
343 ImGui::Combo("Training Dataset",&preset,presets,3);
344 ImGui::TextDisabled("Pong uses a reference intercept heuristic, not RL.");
345 if(script.ScriptName=="NeuralTrainingAgent")
346 ImGui::TextDisabled("TrainOnPlay in the legacy agent only supports Follow XZ.");
347 const bool exists=IsValidNeuralAssetName(output) && std::filesystem::exists(NeuralAssetPath(output));
348 const bool overwrite=fields.count("OverwriteModel") && fields.at("OverwriteModel").Bool;
349 const bool resume=fields.count("ResumeTraining") && fields.at("ResumeTraining").Bool;
350 if(exists && !overwrite) ImGui::TextColored(ImVec4(1.f,.65f,.25f,1.f),"Output exists: enable OverwriteModel or choose another name.");
351 static std::string trainingStatus;
352 ImGui::BeginDisabled(!IsValidNeuralAssetName(output) || (exists && !overwrite) || (resume && source.empty()));
353 if(ImGui::Button("Train & Save As .njn")) {
354 try {
355 const int epochs=fields.count("Epochs")?fields.at("Epochs").Int:1500;
356 const float rate=fields.count("LearningRate")?fields.at("LearningRate").Float:0.01f;
357 auto history=NeuralAgent::TrainPreset(output,source,
358 static_cast<NeuralAgent::TrainingPreset>(preset),epochs,rate,resume,overwrite);
359 const float loss=history.epochLoss.empty()?0.f:history.epochLoss.back();
360 char msg[256];std::snprintf(msg,sizeof(msg),"Saved %s.njn | MSE %.8f",output.c_str(),loss);
361 trainingStatus=msg;
362 std::printf("[Neural Training] %s\n",msg);
363 } catch(const std::exception& e) {
364 trainingStatus=std::string("Training failed: ")+e.what();
365 std::fprintf(stderr,"[Neural Training] %s\n",e.what());
366 }
367 }
368 ImGui::EndDisabled();
369 if(!trainingStatus.empty()) ImGui::TextWrapped("%s",trainingStatus.c_str());
370 ImGui::TextDisabled("To use the saved model, select it in Active Neural Model.");
371 }
372 if(script.ScriptName == "GenericNeuralAgent") {
373 ImGui::Separator();
374 ImGui::TextDisabled("ObservationPreset: 0=Relative XZ, 1=Track Y, 2=Pong 6-input");
375 ImGui::TextDisabled("ActionMode: 0=NavAgent XZ, 1=Move Y, 2=Move XZ");
376 ImGui::TextDisabled("Compatible pairs: (0,0), (1,1), (2,1).");
377 ImGui::TextDisabled("Training is available above; select output as Active Model after training.");
378 }
379 ImGui::TextDisabled(
380 "Scene/Prefab persistent | Hot-reload safe");
381 }
382 }
383 if (ImGui::SmallButton("Remove Script"))
384 {
385 CaptureUndoSnapshot();
386 if (scriptIndex == 0)
387 {
388 auto& extras = m_Scene->GetAdditionalNativeScripts(m_SelectedEntity.GetHandle());
389 if (!extras.empty())
390 {
391 m_SelectedEntity.GetComponent<NativeScriptComponent>() = extras.front();
392 extras.erase(extras.begin());
393 }
394 else m_SelectedEntity.RemoveComponent<NativeScriptComponent>();
395 }
396 else
397 {
398 auto& extras = m_Scene->GetAdditionalNativeScripts(m_SelectedEntity.GetHandle());
399 extras.erase(extras.begin() + (scriptIndex - 1));
400 }
401 }
402 ImGui::PopID();
403 };
404 if (m_SelectedEntity.HasComponent<NativeScriptComponent>())
405 {
406 drawScript(m_SelectedEntity.GetComponent<NativeScriptComponent>(), 0);
407 auto& extras = m_Scene->GetAdditionalNativeScripts(m_SelectedEntity.GetHandle());
408 for (std::size_t i = 0; i < extras.size(); ++i)
409 {
410 const auto sizeBefore = extras.size();
411 drawScript(extras[i], static_cast<int>(i + 1));
412 if (extras.size() != sizeBefore) break;
413 }
414 }
415
416 ImGui::Separator();
417 if (m_SelectedEntity.HasComponent<RigidbodyComponent>())
418 {
419 if (ImGui::CollapsingHeader(
420 "Rigidbody",
421 ImGuiTreeNodeFlags_DefaultOpen))
422 {
423 auto& body =
424 m_SelectedEntity.GetComponent<RigidbodyComponent>();
425
426 const char* bodyTypes[] = {
427 "Static", "Dynamic", "Kinematic"
428 };
429 int type = static_cast<int>(body.Type);
430 if (ImGui::Combo(
431 "Body Type",
432 &type,
433 bodyTypes,
434 IM_ARRAYSIZE(bodyTypes)))
435 {
436 body.Type = static_cast<RigidbodyType>(type);
437 }
438
439 if (body.Type == RigidbodyType::Dynamic)
440 {
441 ImGui::DragFloat(
442 "Mass",
443 &body.Mass,
444 0.05f,
445 0.001f,
446 10000.0f);
447 ImGui::Checkbox("Use Gravity", &body.UseGravity);
448 }
449 else if (body.Type == RigidbodyType::Kinematic)
450 {
451 ImGui::Checkbox("Use Gravity", &body.UseGravity);
452 ImGui::TextDisabled(
453 "Kinematic motion control comes in a later step.");
454 }
455
456 if (ImGui::Button("Remove Rigidbody"))
457 m_SelectedEntity.RemoveComponent<RigidbodyComponent>();
458 }
459 }
460 if (m_SelectedEntity.HasComponent<NavAgentComponent>())
461 {
462 ImGui::Separator();
463
464 if (ImGui::CollapsingHeader(
465 "Nav Agent",
466 ImGuiTreeNodeFlags_DefaultOpen))
467 {
468 auto& agent =
469 m_SelectedEntity.GetComponent<NavAgentComponent>();
470
471 ImGui::Checkbox(
472 "Enabled##NavAgent",
473 &agent.Enabled);
474
475 ImGui::DragFloat(
476 "Speed##NavAgent",
477 &agent.Speed,
478 0.05f,
479 0.0f,
480 100.0f,
481 "%.2f");
482
483 ImGui::DragFloat(
484 "Stopping Distance##NavAgent",
485 &agent.StoppingDistance,
486 0.01f,
487 0.0f,
488 100.0f,
489 "%.2f");
490
491 ImGui::DragFloat(
492 "Repath Interval##NavAgent",
493 &agent.RepathInterval,
494 0.05f,
495 0.05f,
496 10.0f,
497 "%.2f s");
498
499 agent.RepathInterval =
500 std::clamp(agent.RepathInterval, 0.05f, 10.0f);
501 agent.Speed =
502 std::max(
503 agent.Speed,
504 0.0f);
505
506 agent.StoppingDistance =
507 std::max(
508 agent.StoppingDistance,
509 0.0f);
510
511 ImGui::SeparatorText(
512 "Destination");
513
514 ImGui::DragFloat3(
515 "Position##NavAgentDestination",
516 &agent.Destination.x,
517 0.05f,
518 0.0f,
519 0.0f,
520 "%.3f");
521
522 ImGui::Checkbox(
523 "Has Destination##NavAgent",
524 &agent.HasDestination);
525
526 ImGui::TextDisabled(
527 "Path is calculated in Play Mode "
528 "using the baked NavMesh.");
529
530 if (ImGui::Button(
531 "Remove Nav Agent"))
532 {
533 m_SelectedEntity
534 .RemoveComponent<
535 NavAgentComponent>();
536 }
537 }
538 }
539
540 if (m_SelectedEntity.HasComponent<PerceptionComponent>())
541 {
542 ImGui::Separator();
543 if (ImGui::CollapsingHeader("Perception", ImGuiTreeNodeFlags_DefaultOpen))
544 {
545 auto& perception = m_SelectedEntity.GetComponent<PerceptionComponent>();
546 ImGui::Checkbox("Enabled##Perception", &perception.Enabled);
547 ImGui::SeparatorText("Detection Layers");
548
549 constexpr const char* detectionLayerNames[] = {
550 "Default",
551 "Player",
552 "Enemy",
553 "Environment",
554 "Interactable"
555 };
556
557 for (std::uint32_t i = 0;
558 i < IM_ARRAYSIZE(detectionLayerNames);
559 ++i)
560 {
561 const LayerMask bit = EntityLayers::Bit(i);
562
563 bool enabled = (perception.DetectionMask & bit) != 0;
564
565 if (ImGui::Checkbox(detectionLayerNames[i], &enabled))
566 {
567 CaptureUndoSnapshot();
568
569 if (enabled)
570 perception.DetectionMask |= bit;
571 else
572 perception.DetectionMask &= ~bit;
573 }
574 }
575 ImGui::DragFloat("Detection Radius##Perception", &perception.DetectionRadius,
576 0.1f, 0.0f, 10000.0f, "%.2f");
577 ImGui::SliderFloat("Field of View##Perception", &perception.FieldOfView,
578 0.0f, 360.0f, "%.1f deg");
579 ImGui::DragFloat(
580 "Eye Height##Perception",
581 &perception.EyeHeight,
582 0.05f,
583 0.0f,
584 100.0f,
585 "%.2f"
586 );
587 ImGui::DragFloat("Memory Duration##Perception", &perception.MemoryDuration,
588 0.05f, 0.0f, 3600.0f, "%.2f s");
589 ImGui::DragFloat("Update Interval##Perception", &perception.UpdateInterval,
590 0.01f, 0.01f, 60.0f, "%.2f s");
591 ImGui::Checkbox("Debug Draw##Perception", &perception.DebugDraw);
592 perception.DetectionRadius = std::max(0.0f, perception.DetectionRadius);
593 perception.FieldOfView = std::clamp(perception.FieldOfView, 0.0f, 360.0f);
594 perception.EyeHeight =
595 std::clamp(perception.EyeHeight, 0.0f, 100.0f);
596 perception.MemoryDuration = std::max(0.0f, perception.MemoryDuration);
597 perception.UpdateInterval = std::clamp(perception.UpdateInterval, 0.01f, 60.0f);
598 ImGui::SeparatorText("Runtime Perception");
599 if (m_IsPlaying && perception.Enabled)
600 {
601 const auto targets = m_Scene->GetPerceivedTargets(m_SelectedEntity.GetHandle());
602 int visibleCount = 0;
603 for (const auto& target : targets)
604 if (target.IsVisible) ++visibleCount;
605 ImGui::Text("Visible: %d | Remembered: %d", visibleCount,
606 static_cast<int>(targets.size()) - visibleCount);
607 for (const auto& target : targets)
608 {
609 ImGui::PushID(static_cast<int>(target.EntityHandle));
610 ImGui::TextColored(target.IsVisible
611 ? ImVec4(0.25f, 0.9f, 0.4f, 1.0f)
612 : ImVec4(1.0f, 0.8f, 0.25f, 1.0f),
613 "%s | Entity %u | Last seen %.2fs ago",
614 target.IsVisible ? "VISIBLE" : "MEMORY",
615 target.EntityHandle, target.TimeSinceLastSeen);
616 ImGui::PopID();
617 }
618 }
619 else
620 ImGui::TextDisabled("Available in Play Mode");
621 if (ImGui::Button("Remove Perception"))
622 {
623 CaptureUndoSnapshot();
624 m_SelectedEntity.RemoveComponent<PerceptionComponent>();
625 }
626 }
627 }
628
629 if (m_SelectedEntity.HasComponent<BoxColliderComponent>())
630 {
631 if (ImGui::CollapsingHeader(
632 "Box Collider",
633 ImGuiTreeNodeFlags_DefaultOpen))
634 {
635 auto& c = m_SelectedEntity.GetComponent<BoxColliderComponent>();
636 ImGui::DragFloat3("Size##Box", &c.Size.x, 0.05f, 0.01f, 1000.0f);
637 c.Size = glm::max(c.Size, glm::vec3(0.01f));
638 ImGui::Checkbox("Is Trigger##Box", &c.IsTrigger);
639 ImGui::SliderFloat("Friction##Box", &c.Material.Friction, 0.0f, 1.0f);
640 ImGui::SliderFloat("Bounciness##Box", &c.Material.Bounciness, 0.0f, 1.0f);
641 if (ImGui::Button("Remove Box Collider"))
642 m_SelectedEntity.RemoveComponent<BoxColliderComponent>();
643 }
644 }
645
646
647 if (m_SelectedEntity.HasComponent<SphereColliderComponent>())
648 {
649 if (ImGui::CollapsingHeader(
650 "Sphere Collider",
651 ImGuiTreeNodeFlags_DefaultOpen))
652 {
653 auto& c = m_SelectedEntity.GetComponent<SphereColliderComponent>();
654 ImGui::DragFloat("Radius##Sphere", &c.Radius, 0.02f, 0.01f, 1000.0f);
655 c.Radius = std::max(c.Radius, 0.01f);
656 ImGui::Checkbox("Is Trigger##Sphere", &c.IsTrigger);
657 ImGui::SliderFloat("Friction##Sphere", &c.Material.Friction, 0.0f, 1.0f);
658 ImGui::SliderFloat("Bounciness##Sphere", &c.Material.Bounciness, 0.0f, 1.0f);
659 if (ImGui::Button("Remove Sphere Collider"))
660 m_SelectedEntity.RemoveComponent<SphereColliderComponent>();
661 }
662 }
663
664
665 if (m_SelectedEntity.HasComponent<CapsuleColliderComponent>())
666 {
667 if (ImGui::CollapsingHeader(
668 "Capsule Collider",
669 ImGuiTreeNodeFlags_DefaultOpen))
670 {
671 auto& c = m_SelectedEntity.GetComponent<CapsuleColliderComponent>();
672 ImGui::DragFloat("Radius##Capsule", &c.Radius, 0.02f, 0.01f, 1000.0f);
673 ImGui::DragFloat("Height##Capsule", &c.Height, 0.05f, 0.02f, 1000.0f);
674 c.Radius = std::max(c.Radius, 0.01f);
675 c.Height = std::max(c.Height, c.Radius * 2.0f);
676 ImGui::Checkbox("Is Trigger##Capsule", &c.IsTrigger);
677 ImGui::SliderFloat("Friction##Capsule", &c.Material.Friction, 0.0f, 1.0f);
678 ImGui::SliderFloat("Bounciness##Capsule", &c.Material.Bounciness, 0.0f, 1.0f);
679 if (ImGui::Button("Remove Capsule Collider"))
680 m_SelectedEntity.RemoveComponent<CapsuleColliderComponent>();
681 }
682 }
683
684
685 ImGui::Separator();
686
687 if (m_SelectedEntity.HasComponent<ParticleSystemComponent>())
688 {
689 if (ImGui::CollapsingHeader("Particle System", ImGuiTreeNodeFlags_DefaultOpen))
690 {
691 auto& p = m_SelectedEntity.GetComponent<ParticleSystemComponent>();
692 ImGui::Checkbox("Playing##Particles", &p.Playing);
693 ImGui::SameLine();
694 ImGui::Checkbox("Loop##Particles", &p.Loop);
695 ImGui::DragFloat("Duration##Particles", &p.Duration, 0.1f, 0.0f, 120.0f);
696 ImGui::SeparatorText("Main");
697 ImGui::DragFloat("Start Lifetime##Particles", &p.StartLifetime, 0.05f, 0.01f, 60.0f);
698 ImGui::SliderFloat("Lifetime Random##Particles", &p.LifetimeRandom, 0.0f, 1.0f);
699 ImGui::DragFloat("Start Speed##Particles", &p.StartSpeed, 0.05f, -100.0f, 100.0f);
700 ImGui::SliderFloat("Speed Random##Particles", &p.SpeedRandom, 0.0f, 1.0f);
701 ImGui::DragFloat("Start Size##Particles", &p.StartSize, 0.01f, 0.001f, 20.0f);
702 ImGui::SliderFloat("Size Random##Particles", &p.SizeRandom, 0.0f, 1.0f);
703 ImGui::ColorEdit4("Start Color##Particles", &p.StartColor.x);
704 ImGui::ColorEdit4("End Color##Particles", &p.EndColor.x);
705 ImGui::SliderFloat("End Size Multiplier##Particles", &p.EndSizeMultiplier, 0.0f, 4.0f);
706 ImGui::DragFloat3("Gravity##Particles", &p.Gravity.x, 0.02f);
707
708 ImGui::SeparatorText("Emission");
709 ImGui::DragFloat("Emission Rate##Particles", &p.EmissionRate, 0.5f, 0.0f, 10000.0f);
710 int maxParticles = static_cast<int>(p.MaxParticles);
711 if (ImGui::DragInt("Max Particles##Particles", &maxParticles, 1.0f, 1, 100000))
712 p.MaxParticles = static_cast<std::uint32_t>(std::max(maxParticles, 1));
713
714 ImGui::SeparatorText("Shape");
715 const char* shapes[] = { "Point", "Sphere", "Cone" };
716 int shape = static_cast<int>(p.Shape);
717 if (ImGui::Combo("Emitter Shape##Particles", &shape, shapes, 3))
718 p.Shape = static_cast<ParticleShape>(shape);
719 ImGui::DragFloat3("Direction##Particles", &p.Direction.x, 0.02f);
720 if (p.Shape == ParticleShape::Sphere)
721 ImGui::DragFloat("Sphere Radius##Particles", &p.ShapeRadius, 0.02f, 0.0f, 100.0f);
722 if (p.Shape == ParticleShape::Cone)
723 ImGui::SliderFloat("Cone Angle##Particles", &p.ConeAngle, 0.0f, 89.0f);
724
725 ImGui::SeparatorText("Renderer");
726 const char* blends[] = { "Alpha", "Additive" };
727 int blend = static_cast<int>(p.BlendMode);
728 if (ImGui::Combo("Blend Mode##Particles", &blend, blends, 2))
729 p.BlendMode = static_cast<ParticleBlendMode>(blend);
730 ImGui::TextWrapped("Texture: %s", p.TexturePath.empty() ? "<none>" : p.TexturePath.c_str());
731 ImGui::Button(p.TexturePath.empty() ? "Drop Texture Here##Particles" : "Texture Assigned##Particles", ImVec2(-1.0f, 0.0f));
732 if (ImGui::BeginDragDropTarget())
733 {
734 if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("NOJOB_TEXTURE_ASSET"))
735 p.TexturePath = static_cast<const char*>(payload->Data);
736 ImGui::EndDragDropTarget();
737 }
738 if (!p.TexturePath.empty())
739 {
740 if (ImGui::Button("Clear Texture##Particles")) p.TexturePath.clear();
741 }
742 ImGui::TextDisabled("Simulation runs in Play Mode. Rendering is instanced per emitter.");
743 if (ImGui::Button("Remove Particle System"))
744 m_SelectedEntity.RemoveComponent<ParticleSystemComponent>();
745 }
746 }
747
748 ImGui::Separator();
749
750 if (m_SelectedEntity.HasComponent<AudioSourceComponent>())
751 {
752 if (ImGui::CollapsingHeader("Audio Source", ImGuiTreeNodeFlags_DefaultOpen))
753 {
754 auto& audio = m_SelectedEntity.GetComponent<AudioSourceComponent>();
755 ImGui::TextWrapped("Clip: %s", audio.ClipPath.empty() ? "<none>" : audio.ClipPath.c_str());
756 ImGui::Button(audio.ClipPath.empty() ? "Drop Audio Clip Here" : "Audio Clip Assigned", ImVec2(-1.0f, 0.0f));
757 if (ImGui::BeginDragDropTarget())
758 {
759 if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("NOJOB_AUDIO_ASSET"))
760 {
761 audio.ClipPath = static_cast<const char*>(payload->Data);
762 AudioEngine::Stop(m_SelectedEntity.GetHandle());
763 }
764 ImGui::EndDragDropTarget();
765 }
766 if (ImGui::Button("Load Audio Clip"))
767 {
768 const std::string path = OpenInspectorAudioFileDialog();
769 if (!path.empty())
770 {
771 std::filesystem::path selected(path);
772 std::error_code ec;
773 const auto relative = std::filesystem::relative(selected, m_ProjectPanel.GetCurrentDirectoryPath(), ec);
774 audio.ClipPath = (!ec && !relative.empty() && relative.generic_string().rfind("..", 0) != 0)
775 ? relative.generic_string() : selected.lexically_normal().string();
776 }
777 }
778 ImGui::SameLine();
779 if (ImGui::Button("Clear##AudioClip")) audio.ClipPath.clear();
780 ImGui::Checkbox("Play On Awake", &audio.PlayOnAwake);
781 ImGui::Checkbox("Loop##Audio", &audio.Loop);
782 ImGui::SliderFloat("Volume##Audio", &audio.Volume, 0.0f, 1.0f);
783 ImGui::SliderFloat("Pitch##Audio", &audio.Pitch, 0.1f, 3.0f);
784 ImGui::SeparatorText("Spatial Audio");
785 ImGui::SliderFloat("Spatial Blend##Audio", &audio.SpatialBlend, 0.0f, 1.0f, "%.2f");
786 ImGui::DragFloat("Min Distance##Audio", &audio.MinDistance, 0.1f, 0.01f, 10000.0f);
787 ImGui::DragFloat("Max Distance##Audio", &audio.MaxDistance, 0.25f, 0.02f, 100000.0f);
788 ImGui::SliderFloat("Doppler Factor##Audio", &audio.DopplerFactor, 0.0f, 5.0f);
789 audio.MinDistance = std::max(0.01f, audio.MinDistance);
790 audio.MaxDistance = std::max(audio.MinDistance + 0.01f, audio.MaxDistance);
791 audio.SpatialBlend = std::clamp(audio.SpatialBlend, 0.0f, 1.0f);
792 if (audio.SpatialBlend <= 0.001f)
793 ImGui::TextDisabled("2D: position and distance attenuation are disabled.");
794 else
795 ImGui::TextDisabled("3D: source follows the entity world Transform.");
796 if (ImGui::Button("Preview Play"))
797 {
798 const glm::mat4 world = m_Scene->GetWorldTransform(m_SelectedEntity);
799 AudioEngine::Play(m_SelectedEntity.GetHandle(), audio, glm::vec3(world[3]));
800 }
801 ImGui::SameLine();
802 if (ImGui::Button("Preview Stop")) AudioEngine::Stop(m_SelectedEntity.GetHandle());
803 if (!AudioEngine::GetLastError().empty())
804 ImGui::TextWrapped("Audio: %s", AudioEngine::GetLastError().c_str());
805 if (ImGui::Button("Remove Audio Source"))
806 {
807 AudioEngine::Stop(m_SelectedEntity.GetHandle());
808 m_SelectedEntity.RemoveComponent<AudioSourceComponent>();
809 }
810 }
811 }
812
813 if (m_SelectedEntity.HasComponent<AudioListenerComponent>())
814 {
815 if (ImGui::CollapsingHeader("Audio Listener", ImGuiTreeNodeFlags_DefaultOpen))
816 {
817 auto& listener = m_SelectedEntity.GetComponent<AudioListenerComponent>();
818 ImGui::Checkbox("Enabled##AudioListener", &listener.Enabled);
819 ImGui::TextDisabled("Uses this entity's world position and orientation.");
820 ImGui::TextDisabled("The first enabled listener in the runtime scene is active.");
821 if (ImGui::Button("Remove Audio Listener"))
822 m_SelectedEntity.RemoveComponent<AudioListenerComponent>();
823 }
824 }
825
826 if (m_SelectedEntity.HasComponent<CameraComponent>())
827 {
828 if (ImGui::CollapsingHeader(
829 "Camera",
830 ImGuiTreeNodeFlags_DefaultOpen))
831 {
832 auto& camera =
833 m_SelectedEntity.GetComponent<CameraComponent>();
834
835 ImGui::Checkbox("Primary", &camera.Primary);
836
837 const char* projectionTypes[] =
838 { "Perspective", "Orthographic" };
839 int projectionType =
840 static_cast<int>(camera.ProjectionType);
841 if (ImGui::Combo(
842 "Projection",
843 &projectionType,
844 projectionTypes,
845 IM_ARRAYSIZE(projectionTypes)))
846 {
847 camera.ProjectionType =
848 static_cast<CameraProjectionType>(projectionType);
849 }
850
851 if (camera.ProjectionType ==
853 {
854 ImGui::SliderFloat(
855 "Field of View",
856 &camera.PerspectiveFOV,
857 1.0f, 179.0f);
858 ImGui::DragFloat(
859 "Near Clip",
860 &camera.PerspectiveNear,
861 0.01f, 0.001f, 100.0f);
862 ImGui::DragFloat(
863 "Far Clip",
864 &camera.PerspectiveFar,
865 1.0f, 1.0f, 100000.0f);
866 camera.PerspectiveFar =
867 std::max(
868 camera.PerspectiveFar,
869 camera.PerspectiveNear + 0.01f);
870 }
871 else
872 {
873 ImGui::DragFloat(
874 "Size",
875 &camera.OrthographicSize,
876 0.1f, 0.01f, 10000.0f);
877 ImGui::DragFloat(
878 "Near Clip##Ortho",
879 &camera.OrthographicNear,
880 0.1f);
881 ImGui::DragFloat(
882 "Far Clip##Ortho",
883 &camera.OrthographicFar,
884 1.0f);
885 }
886
887 if (ImGui::Button("Remove Camera"))
888 m_SelectedEntity.RemoveComponent<CameraComponent>();
889 }
890 }
891
892
893 if (m_SelectedEntity.HasComponent<DirectionalLightComponent>())
894 {
895 if (ImGui::CollapsingHeader(
896 "Directional Light",
897 ImGuiTreeNodeFlags_DefaultOpen))
898 {
899 auto& light =
900 m_SelectedEntity.GetComponent<DirectionalLightComponent>();
901 ImGui::ColorEdit3("Color##Directional", &light.Color.x);
902 ImGui::DragFloat(
903 "Intensity##Directional",
904 &light.Intensity, 0.05f, 0.0f, 100.0f);
905 ImGui::Checkbox("Cast Shadows##Directional", &light.CastShadows);
906 ImGui::DragFloat("Shadow Bias##Directional", &light.ShadowBias, 0.0001f, 0.00001f, 0.05f, "%.5f");
907 if (ImGui::Button("Remove Directional Light"))
908 m_SelectedEntity.RemoveComponent<DirectionalLightComponent>();
909 }
910 }
911
912
913 if (m_SelectedEntity.HasComponent<PointLightComponent>())
914 {
915 if (ImGui::CollapsingHeader(
916 "Point Light",
917 ImGuiTreeNodeFlags_DefaultOpen))
918 {
919 auto& light =
920 m_SelectedEntity.GetComponent<PointLightComponent>();
921 ImGui::ColorEdit3("Color##Point", &light.Color.x);
922 ImGui::DragFloat(
923 "Intensity##Point",
924 &light.Intensity, 0.05f, 0.0f, 100.0f);
925 ImGui::DragFloat(
926 "Range##Point",
927 &light.Range, 0.1f, 0.01f, 10000.0f);
928 ImGui::Checkbox("Cast Shadows##Point", &light.CastShadows);
929 ImGui::DragFloat("Shadow Bias##Point", &light.ShadowBias, 0.001f, 0.001f, 0.25f, "%.4f");
930 if (ImGui::Button("Remove Point Light"))
931 m_SelectedEntity.RemoveComponent<PointLightComponent>();
932 }
933 }
934
935
936 if (m_SelectedEntity.HasComponent<SpotLightComponent>())
937 {
938 if (ImGui::CollapsingHeader(
939 "Spot Light",
940 ImGuiTreeNodeFlags_DefaultOpen))
941 {
942 auto& light =
943 m_SelectedEntity.GetComponent<SpotLightComponent>();
944 ImGui::ColorEdit3("Color##Spot", &light.Color.x);
945 ImGui::DragFloat(
946 "Intensity##Spot",
947 &light.Intensity, 0.05f, 0.0f, 100.0f);
948 ImGui::DragFloat(
949 "Range##Spot",
950 &light.Range, 0.1f, 0.01f, 10000.0f);
951 ImGui::SliderFloat(
952 "Inner Angle",
953 &light.InnerAngle, 0.1f, 89.0f);
954 ImGui::SliderFloat(
955 "Outer Angle",
956 &light.OuterAngle, 0.1f, 89.0f);
957 light.OuterAngle =
958 std::max(light.OuterAngle, light.InnerAngle);
959 ImGui::Checkbox("Cast Shadows##Spot", &light.CastShadows);
960 ImGui::DragFloat("Shadow Bias##Spot", &light.ShadowBias, 0.0001f, 0.00001f, 0.05f, "%.5f");
961 if (ImGui::Button("Remove Spot Light"))
962 m_SelectedEntity.RemoveComponent<SpotLightComponent>();
963 }
964 }
965
966
967 if (m_SelectedEntity.HasComponent<AnimatorComponent>())
968 {
969 ImGui::Separator();
970 if (ImGui::CollapsingHeader("Animator", ImGuiTreeNodeFlags_DefaultOpen))
971 {
972 auto& animator = m_SelectedEntity.GetComponent<AnimatorComponent>();
973 ImGui::Checkbox("Playing", &animator.Playing);
974 ImGui::SameLine(); ImGui::Checkbox("Loop", &animator.Loop);
975 ImGui::DragFloat("Speed", &animator.Speed, 0.05f, -4.0f, 4.0f);
976 if (animator.Animation && !animator.Animation->Clips().empty())
977 {
978 const auto& clips = animator.Animation->Clips();
979 animator.ClipIndex = std::clamp(animator.ClipIndex, 0, (int)clips.size() - 1);
980 if (ImGui::BeginCombo("Clip", clips[animator.ClipIndex].Name.c_str()))
981 {
982 for (int ci = 0;ci < (int)clips.size();++ci)
983 if (ImGui::Selectable(clips[ci].Name.c_str(), ci == animator.ClipIndex))
984 {
985 animator.ClipIndex = ci; animator.TimeSeconds = 0.0f;
986 }
987 ImGui::EndCombo();
988 }
989 ImGui::Text("Skeleton bones: %zu", animator.Animation->Bones().size());
990 ImGui::Text("Time: %.2f / %.2f s", animator.TimeSeconds,
991 (float)clips[animator.ClipIndex].DurationSeconds());
992 }
993 else ImGui::TextDisabled("No animation asset loaded.");
994 }
995 }
996
997 DrawComponentTools();
998
999 ImGui::Separator();
1000 ImGui::Spacing();
1001 const float addWidth = std::min(260.0f, ImGui::GetContentRegionAvail().x);
1002 ImGui::SetCursorPosX(ImGui::GetCursorPosX() +
1003 std::max(0.0f, (ImGui::GetContentRegionAvail().x - addWidth) * 0.5f));
1004 if (ImGui::Button("Add Component", ImVec2(addWidth, 0.0f)))
1005 ImGui::OpenPopup("AddComponentPopup");
1006
1007 if (ImGui::BeginPopup("AddComponentPopup"))
1008 {
1009 static char componentSearch[96]{};
1010 ImGui::SetNextItemWidth(300.0f);
1011 ImGui::InputTextWithHint("##ComponentSearch", "Search components...",
1012 componentSearch, sizeof(componentSearch));
1013 ImGui::Separator();
1014
1015 std::string filter = componentSearch;
1016 std::transform(filter.begin(), filter.end(), filter.begin(),
1017 [](unsigned char c) { return (char)std::tolower(c); });
1018 auto visible = [&](const char* name)
1019 {
1020 if (filter.empty()) return true;
1021 std::string n = name;
1022 std::transform(n.begin(), n.end(), n.begin(),
1023 [](unsigned char c) { return (char)std::tolower(c); });
1024 return n.find(filter) != std::string::npos;
1025 };
1026 auto addItem = [&](const char* category, const char* name, bool enabled, auto add)
1027 {
1028 if (!visible(name)) return;
1029 ImGui::TextDisabled("%s", category);
1030 ImGui::SameLine(95.0f);
1031 if (!enabled) ImGui::BeginDisabled();
1032 if (ImGui::Selectable(name, false, enabled ? 0 : ImGuiSelectableFlags_Disabled))
1033 {
1034 CaptureUndoSnapshot();
1035 add();
1036 ImGui::CloseCurrentPopup();
1037 }
1038 if (!enabled) ImGui::EndDisabled();
1039 };
1040
1041 addItem("Physics", "Rigidbody",
1042 !m_SelectedEntity.HasComponent<RigidbodyComponent>(),
1043 [&] { m_SelectedEntity.AddComponent<RigidbodyComponent>(); });
1044
1045 addItem("AI", "Nav Agent",
1046 !m_SelectedEntity.HasComponent<NavAgentComponent>(),
1047 [&]
1048 {
1049 m_SelectedEntity
1050 .AddComponent<
1051 NavAgentComponent>();
1052 });
1053
1054 addItem("AI", "Perception",
1055 !m_SelectedEntity.HasComponent<PerceptionComponent>(),
1056 [&] { m_SelectedEntity.AddComponent<PerceptionComponent>(); });
1057
1058 const bool noCollider =
1059 !m_SelectedEntity.HasComponent<BoxColliderComponent>() &&
1060 !m_SelectedEntity.HasComponent<SphereColliderComponent>() &&
1061 !m_SelectedEntity.HasComponent<CapsuleColliderComponent>();
1062 addItem("Physics", "Box Collider", noCollider,
1063 [&] { m_SelectedEntity.AddComponent<BoxColliderComponent>(); });
1064 addItem("Physics", "Sphere Collider", noCollider,
1065 [&] { m_SelectedEntity.AddComponent<SphereColliderComponent>(); });
1066 addItem("Physics", "Capsule Collider", noCollider,
1067 [&] { m_SelectedEntity.AddComponent<CapsuleColliderComponent>(); });
1068
1069 const bool noViewLight =
1070 !m_SelectedEntity.HasComponent<CameraComponent>() &&
1071 !m_SelectedEntity.HasComponent<DirectionalLightComponent>() &&
1072 !m_SelectedEntity.HasComponent<PointLightComponent>() &&
1073 !m_SelectedEntity.HasComponent<SpotLightComponent>();
1074 addItem("Rendering", "Camera", noViewLight,
1075 [&] { m_SelectedEntity.AddComponent<CameraComponent>(); });
1076 addItem("Rendering", "Directional Light", noViewLight,
1077 [&] { m_SelectedEntity.AddComponent<DirectionalLightComponent>(); });
1078 addItem("Rendering", "Point Light", noViewLight,
1079 [&] { m_SelectedEntity.AddComponent<PointLightComponent>(); });
1080 addItem("Rendering", "Spot Light", noViewLight,
1081 [&] { m_SelectedEntity.AddComponent<SpotLightComponent>(); });
1082
1083 addItem("Effects", "Particle System",
1084 !m_SelectedEntity.HasComponent<ParticleSystemComponent>(),
1085 [&] { m_SelectedEntity.AddComponent<ParticleSystemComponent>(); });
1086
1087 addItem("Audio", "Audio Source",
1088 !m_SelectedEntity.HasComponent<AudioSourceComponent>(),
1089 [&] { m_SelectedEntity.AddComponent<AudioSourceComponent>(); });
1090 addItem("Audio", "Audio Listener",
1091 !m_SelectedEntity.HasComponent<AudioListenerComponent>(),
1092 [&] { m_SelectedEntity.AddComponent<AudioListenerComponent>(); });
1093
1094 addItem("Animation", "Animator",
1095 !m_SelectedEntity.HasComponent<AnimatorComponent>(),
1096 [&] { m_SelectedEntity.AddComponent<AnimatorComponent>(); });
1100 for (const auto* definition : ScriptRegistry::All())
1101 {
1102 const std::string label = definition->Name + " Script";
1103 addItem("Scripting", label.c_str(),
1104 true,
1105 [&, definition] {
1106 NativeScriptComponent component;
1107 component.ScriptName = definition->Name;
1108 ScriptRegistry::ApplyDefaults(component);
1109 if (!m_SelectedEntity.HasComponent<NativeScriptComponent>())
1110 m_SelectedEntity.AddComponent<NativeScriptComponent>(component);
1111 else
1112 m_Scene->GetAdditionalNativeScripts(m_SelectedEntity.GetHandle()).push_back(component);
1113 });
1114 }
1115
1116 ImGui::EndPopup();
1117 }
1118
1119 if (m_SelectedEntity.HasComponent<PrefabInstanceComponent>())
1120 {
1121 ImGui::Separator();
1122 if (ImGui::CollapsingHeader("Prefab Instance", ImGuiTreeNodeFlags_DefaultOpen))
1123 {
1124 auto& pi = m_SelectedEntity.GetComponent<PrefabInstanceComponent>();
1125 ImGui::TextWrapped("Source: %s", pi.SourcePath.c_str());
1126 if (ImGui::Button("Apply to Prefab"))
1127 {
1128 CaptureUndoSnapshot();
1129 PrefabSerializer::Apply(m_SelectedEntity, pi.SourcePath);
1130 }
1131 ImGui::SameLine();
1132 if (ImGui::Button("Revert"))
1133 {
1134 CaptureUndoSnapshot();
1135 Entity reverted = PrefabSerializer::Revert(
1136 m_SelectedEntity, m_DefaultCubeMesh, m_DefaultCubeMaterial);
1137 if (reverted) m_SelectedEntity = reverted;
1138 }
1139 }
1140 }
1141
1142 if (m_SelectedEntity.HasComponent<MeshRendererComponent>())
1143 {
1144 ImGui::Separator();
1145
1146 if (ImGui::CollapsingHeader(
1147 "Mesh Renderer",
1148 ImGuiTreeNodeFlags_DefaultOpen))
1149 {
1150 auto& renderer =
1151 m_SelectedEntity.GetComponent<MeshRendererComponent>();
1152
1153 // Upgrade V1 renderers to the slot representation lazily.
1154 if (renderer.Materials.empty() && renderer.MaterialAsset)
1155 renderer.Materials.push_back(renderer.MaterialAsset);
1156 else if (!renderer.Materials.empty() && !renderer.MaterialAsset)
1157 renderer.MaterialAsset = renderer.Materials.front();
1158
1159 if (!renderer.Materials.empty())
1160 {
1161 if (m_SelectedMaterialSlot >= renderer.Materials.size())
1162 m_SelectedMaterialSlot = 0;
1163
1164 ImGui::SeparatorText("Materials");
1165 for (std::size_t slot = 0;
1166 slot < renderer.Materials.size();
1167 ++slot)
1168 {
1169 ImGui::PushID(static_cast<int>(slot));
1170
1171 const bool selected =
1172 slot == m_SelectedMaterialSlot;
1173 const char* state =
1174 renderer.Materials[slot] ? "Assigned" : "None";
1175
1176 std::string label =
1177 "Element " + std::to_string(slot) +
1178 " [" + state + "]";
1179
1180 if (ImGui::Selectable(label.c_str(), selected))
1181 m_SelectedMaterialSlot = slot;
1182
1183 // Every element is a real material drop target.
1184 if (ImGui::BeginDragDropTarget())
1185 {
1186 if (const ImGuiPayload* payload =
1187 ImGui::AcceptDragDropPayload(
1188 "NOJOB_MATERIAL_ASSET"))
1189 {
1190 const char* relativePath =
1191 static_cast<const char*>(payload->Data);
1192
1193 AssetRegistry registry(
1195 registry.Load();
1196
1197 std::shared_ptr<Shader> shader;
1198 if (renderer.Materials[slot])
1199 shader =
1200 renderer.Materials[slot]->GetShader();
1201 else if (renderer.MaterialAsset)
1202 shader =
1203 renderer.MaterialAsset->GetShader();
1204
1205 auto loaded = MaterialSerializer::Load(
1207 relativePath,
1208 shader,
1209 registry);
1210
1211 if (loaded)
1212 {
1213 renderer.Materials[slot] = loaded;
1214 if (slot == 0)
1215 renderer.MaterialAsset = loaded;
1216 }
1217 }
1218 ImGui::EndDragDropTarget();
1219 }
1220
1221 ImGui::PopID();
1222 }
1223
1224 auto& activeMaterial =
1225 renderer.Materials[m_SelectedMaterialSlot];
1226
1227 if (!activeMaterial)
1228 {
1229 ImGui::TextDisabled(
1230 "Selected material slot is empty.");
1231 }
1232 else
1233 {
1234 // Keep the legacy slot-0 alias synchronized.
1235 if (m_SelectedMaterialSlot == 0)
1236 renderer.MaterialAsset = activeMaterial;
1237
1238 ImGui::SeparatorText(
1239 ("Element " +
1240 std::to_string(m_SelectedMaterialSlot))
1241 .c_str());
1242
1243 const char* surfaceModes[] =
1244 {
1245 "Opaque",
1246 "Alpha Clip",
1247 "Transparent"
1248 };
1249
1250 int surfaceMode =
1251 static_cast<int>(
1252 activeMaterial->SurfaceMode());
1253
1254 if (ImGui::Combo(
1255 "Rendering Mode",
1256 &surfaceMode,
1257 surfaceModes,
1258 3))
1259 {
1260 activeMaterial->SurfaceMode() =
1261 static_cast<MaterialSurfaceMode>(
1262 surfaceMode);
1263 }
1264
1265 if (activeMaterial->SurfaceMode() ==
1267 {
1268 ImGui::SliderFloat(
1269 "Alpha Cutoff",
1270 &activeMaterial->AlphaCutoff(),
1271 0.0f,
1272 1.0f);
1273 }
1274
1275 ImGui::TextUnformatted("Material");
1276 ImGui::SameLine();
1277 ImGui::Button(
1278 "Material Slot",
1279 ImVec2(
1280 ImGui::GetContentRegionAvail().x,
1281 0.0f));
1282
1283 if (ImGui::BeginDragDropTarget())
1284 {
1285 if (const ImGuiPayload* materialPayload =
1286 ImGui::AcceptDragDropPayload(
1287 "NOJOB_MATERIAL_ASSET"))
1288 {
1289 const char* relativePath =
1290 static_cast<const char*>(
1291 materialPayload->Data);
1292
1293 AssetRegistry registry(
1295 registry.Load();
1296
1297 auto loaded = MaterialSerializer::Load(
1299 relativePath,
1300 activeMaterial->GetShader(),
1301 registry);
1302
1303 if (loaded)
1304 {
1305 activeMaterial = loaded;
1306 if (m_SelectedMaterialSlot == 0)
1307 renderer.MaterialAsset = loaded;
1308 }
1309 }
1310
1311 if (const ImGuiPayload* texturePayload =
1312 ImGui::AcceptDragDropPayload(
1313 "NOJOB_TEXTURE_ASSET"))
1314 {
1315 const char* relativePath =
1316 static_cast<const char*>(
1317 texturePayload->Data);
1318 try
1319 {
1320 activeMaterial->SetTexture(
1322 relativePath));
1323 activeMaterial->UseTexture() = true;
1324 }
1325 catch (const std::exception&) {}
1326 }
1327
1328 ImGui::EndDragDropTarget();
1329 }
1330
1331 ImGui::Separator();
1332 auto& color = activeMaterial->GetColor();
1333 ImGui::ColorEdit4(
1334 "Material Color", &color.x);
1335
1336 ImGui::SeparatorText("PBR Surface");
1337 ImGui::SliderFloat(
1338 "Metallic",
1339 &activeMaterial->Metallic(), 0.0f, 1.0f);
1340 ImGui::SliderFloat(
1341 "Roughness",
1342 &activeMaterial->Roughness(), 0.04f, 1.0f);
1343 ImGui::SliderFloat(
1344 "Ambient Occlusion",
1345 &activeMaterial->AmbientOcclusion(),
1346 0.0f, 1.0f);
1347 ImGui::SliderFloat(
1348 "Normal Strength",
1349 &activeMaterial->NormalStrength(),
1350 0.0f, 2.0f);
1351 ImGui::ColorEdit3(
1352 "Emissive Color",
1353 &activeMaterial->EmissiveColor().x);
1354 ImGui::SliderFloat(
1355 "Emissive Strength",
1356 &activeMaterial->EmissiveStrength(),
1357 0.0f, 20.0f);
1358
1359 ImGui::SeparatorText("PBR Texture Maps");
1360 auto selectPBRMap =
1361 [&](const char* label, auto setter)
1362 {
1363 if (ImGui::Button(label))
1364 {
1365 const std::string path =
1366 OpenInspectorTextureFileDialog();
1367 if (!path.empty())
1368 {
1369 try
1370 {
1371 const auto importedPath =
1373 path);
1374 setter(
1376 importedPath));
1377 }
1378 catch (const std::exception&) {}
1379 }
1380 }
1381 };
1382
1383 selectPBRMap(
1384 "Normal Map...",
1385 [&](std::shared_ptr<Texture2D> v)
1386 {
1387 activeMaterial->SetNormalTexture(
1388 std::move(v));
1389 });
1390 ImGui::SameLine();
1391 selectPBRMap(
1392 "Metallic Map...",
1393 [&](std::shared_ptr<Texture2D> v)
1394 {
1395 activeMaterial->SetMetallicTexture(
1396 std::move(v));
1397 });
1398 selectPBRMap(
1399 "Roughness Map...",
1400 [&](std::shared_ptr<Texture2D> v)
1401 {
1402 activeMaterial->SetRoughnessTexture(
1403 std::move(v));
1404 });
1405 ImGui::SameLine();
1406 selectPBRMap(
1407 "AO Map...",
1408 [&](std::shared_ptr<Texture2D> v)
1409 {
1410 activeMaterial->SetAOTexture(
1411 std::move(v));
1412 });
1413 selectPBRMap(
1414 "Emissive Map...",
1415 [&](std::shared_ptr<Texture2D> v)
1416 {
1417 activeMaterial->SetEmissiveTexture(
1418 std::move(v));
1419 });
1420
1421 ImGui::Checkbox(
1422 "Use Texture",
1423 &activeMaterial->UseTexture());
1424
1425 if (ImGui::Button("Select Texture..."))
1426 {
1427 const std::string path =
1428 OpenInspectorTextureFileDialog();
1429 if (!path.empty())
1430 {
1431 try
1432 {
1433 const auto importedPath =
1435 activeMaterial->SetTexture(
1437 importedPath));
1438 activeMaterial->UseTexture() = true;
1439 }
1440 catch (const std::exception&) {}
1441 }
1442 }
1443
1444 ImGui::SameLine();
1445 if (ImGui::Button("Checkerboard"))
1446 {
1447 activeMaterial->SetTexture(
1449 activeMaterial->UseTexture() = true;
1450 }
1451
1452 if (ImGui::Button("Save Material Asset"))
1453 {
1454 const auto& entityTag =
1455 m_SelectedEntity
1456 .GetComponent<TagComponent>().Tag;
1457
1458 const auto materialPath =
1460 "Materials" /
1461 (entityTag + "_Element" +
1462 std::to_string(
1463 m_SelectedMaterialSlot) +
1464 ".nojobmat");
1465
1466 AssetRegistry registry(
1468 registry.Load();
1470 *activeMaterial,
1471 materialPath,
1472 registry);
1473 registry.Register(
1474 materialPath,
1476 registry.Save();
1477 }
1478
1479 ImGui::SameLine();
1480 if (ImGui::Button("Create Prefab"))
1481 {
1483 m_SelectedEntity,
1485 [this](const std::string& message) { LogInspectorMessage(message); });
1486 }
1487
1488 if (activeMaterial->GetTexture())
1489 {
1490 const auto& texture =
1491 activeMaterial->GetTexture();
1492 const std::filesystem::path texturePath(
1493 texture->GetPath());
1494
1495 const std::string displayName =
1496 texture->GetPath() == "Checkerboard"
1497 ? std::string("Checkerboard")
1498 : texturePath.filename().string();
1499
1500 ImGui::TextDisabled(
1501 "Texture: %s",
1502 displayName.c_str());
1503
1504 ImGui::Image(
1505 static_cast<ImTextureID>(
1506 static_cast<intptr_t>(
1507 texture->GetRendererID())),
1508 ImVec2(96.0f, 96.0f));
1509 }
1510 }
1511 }
1512 else
1513 {
1514 ImGui::TextDisabled("No material assigned.");
1515 }
1516 }
1517 }
1518
1519 ImGui::Separator();
1520
1521 const auto id =
1522 m_SelectedEntity.GetComponent<IDComponent>().ID;
1523
1524 ImGui::Text(
1525 "Entity ID: %llu",
1526 static_cast<unsigned long long>(id));
1527 }
1528 else
1529 {
1530 ImGui::TextDisabled(
1531 "Select an entity in Hierarchy.");
1532 }
1533
1534 ImGui::End();
1535 }
1536
1537 void EditorLayer::DrawComponentTools()
1538 {
1539 if (!m_SelectedEntity) return;
1540
1541 ImGui::SeparatorText("Component Actions");
1542 static int componentIndex = 0;
1543
1544 struct Entry { const char* Name; int Id; };
1545 std::vector<Entry> entries;
1546 entries.push_back({ "Transform", 0 });
1547 if (m_SelectedEntity.HasComponent<NativeScriptComponent>()) entries.push_back({ "Native Script",1 });
1548 if (m_SelectedEntity.HasComponent<RigidbodyComponent>()) entries.push_back({ "Rigidbody",2 });
1549 if (m_SelectedEntity.HasComponent<BoxColliderComponent>()) entries.push_back({ "Box Collider",3 });
1550 if (m_SelectedEntity.HasComponent<SphereColliderComponent>()) entries.push_back({ "Sphere Collider",4 });
1551 if (m_SelectedEntity.HasComponent<CapsuleColliderComponent>()) entries.push_back({ "Capsule Collider",5 });
1552 if (m_SelectedEntity.HasComponent<CameraComponent>()) entries.push_back({ "Camera",6 });
1553 if (m_SelectedEntity.HasComponent<DirectionalLightComponent>()) entries.push_back({ "Directional Light",7 });
1554 if (m_SelectedEntity.HasComponent<PointLightComponent>()) entries.push_back({ "Point Light",8 });
1555 if (m_SelectedEntity.HasComponent<SpotLightComponent>()) entries.push_back({ "Spot Light",9 });
1556 if (m_SelectedEntity.HasComponent<AnimatorComponent>()) entries.push_back({ "Animator",10 });
1557 if (m_SelectedEntity.HasComponent<NavAgentComponent>())
1558 entries.push_back({ "Nav Agent",11 });
1559 if (m_SelectedEntity.HasComponent<PerceptionComponent>())
1560 entries.push_back({ "Perception", 12 });
1561 componentIndex = std::clamp(componentIndex, 0, (int)entries.size() - 1);
1562 if (ImGui::BeginCombo("Component", entries[componentIndex].Name))
1563 {
1564 for (int i = 0;i < (int)entries.size();++i)
1565 if (ImGui::Selectable(entries[i].Name, i == componentIndex))
1566 componentIndex = i;
1567 ImGui::EndCombo();
1568 }
1569
1570 const int id = entries[componentIndex].Id;
1571 auto copy = [&] {
1572 switch (id) {
1573 case 0:m_ComponentClipboard = m_SelectedEntity.GetComponent<TransformComponent>();break;
1574 case 1:m_ComponentClipboard = m_SelectedEntity.GetComponent<NativeScriptComponent>();break;
1575 case 2:m_ComponentClipboard = m_SelectedEntity.GetComponent<RigidbodyComponent>();break;
1576 case 3:m_ComponentClipboard = m_SelectedEntity.GetComponent<BoxColliderComponent>();break;
1577 case 4:m_ComponentClipboard = m_SelectedEntity.GetComponent<SphereColliderComponent>();break;
1578 case 5:m_ComponentClipboard = m_SelectedEntity.GetComponent<CapsuleColliderComponent>();break;
1579 case 6:m_ComponentClipboard = m_SelectedEntity.GetComponent<CameraComponent>();break;
1580 case 7:m_ComponentClipboard = m_SelectedEntity.GetComponent<DirectionalLightComponent>();break;
1581 case 8:m_ComponentClipboard = m_SelectedEntity.GetComponent<PointLightComponent>();break;
1582 case 9:m_ComponentClipboard = m_SelectedEntity.GetComponent<SpotLightComponent>();break;
1583 case 10:m_ComponentClipboard = m_SelectedEntity.GetComponent<AnimatorComponent>();break;
1584 case 11:m_ComponentClipboard = m_SelectedEntity.GetComponent<NavAgentComponent>();break;
1585 case 12:m_ComponentClipboard = m_SelectedEntity.GetComponent<PerceptionComponent>();break;
1586 }
1587 };
1588 auto reset = [&] {
1589 CaptureUndoSnapshot();
1590 switch (id) {
1591 case 0:m_SelectedEntity.GetComponent<TransformComponent>() = {};break;
1592 case 1:m_SelectedEntity.GetComponent<NativeScriptComponent>() = {};break;
1593 case 2:m_SelectedEntity.GetComponent<RigidbodyComponent>() = {};break;
1594 case 3:m_SelectedEntity.GetComponent<BoxColliderComponent>() = {};break;
1595 case 4:m_SelectedEntity.GetComponent<SphereColliderComponent>() = {};break;
1596 case 5:m_SelectedEntity.GetComponent<CapsuleColliderComponent>() = {};break;
1597 case 6:m_SelectedEntity.GetComponent<CameraComponent>() = {};break;
1598 case 7:m_SelectedEntity.GetComponent<DirectionalLightComponent>() = {};break;
1599 case 8:m_SelectedEntity.GetComponent<PointLightComponent>() = {};break;
1600 case 9:m_SelectedEntity.GetComponent<SpotLightComponent>() = {};break;
1601 case 10:m_SelectedEntity.GetComponent<AnimatorComponent>() = {};break;
1602 case 11:m_SelectedEntity.GetComponent<NavAgentComponent>() = {}; break;
1603 case 12:m_SelectedEntity.GetComponent<PerceptionComponent>() = {};break;
1604 }
1605 };
1606 auto paste = [&] {
1607 CaptureUndoSnapshot();
1608 switch (id) {
1609 case 0:if (auto p = std::get_if<TransformComponent>(&m_ComponentClipboard))m_SelectedEntity.GetComponent<TransformComponent>() = *p;break;
1610 case 1:if (auto p = std::get_if<NativeScriptComponent>(&m_ComponentClipboard))m_SelectedEntity.GetComponent<NativeScriptComponent>() = *p;break;
1611 case 2:if (auto p = std::get_if<RigidbodyComponent>(&m_ComponentClipboard))m_SelectedEntity.GetComponent<RigidbodyComponent>() = *p;break;
1612 case 3:if (auto p = std::get_if<BoxColliderComponent>(&m_ComponentClipboard))m_SelectedEntity.GetComponent<BoxColliderComponent>() = *p;break;
1613 case 4:if (auto p = std::get_if<SphereColliderComponent>(&m_ComponentClipboard))m_SelectedEntity.GetComponent<SphereColliderComponent>() = *p;break;
1614 case 5:if (auto p = std::get_if<CapsuleColliderComponent>(&m_ComponentClipboard))m_SelectedEntity.GetComponent<CapsuleColliderComponent>() = *p;break;
1615 case 6:if (auto p = std::get_if<CameraComponent>(&m_ComponentClipboard))m_SelectedEntity.GetComponent<CameraComponent>() = *p;break;
1616 case 7:if (auto p = std::get_if<DirectionalLightComponent>(&m_ComponentClipboard))m_SelectedEntity.GetComponent<DirectionalLightComponent>() = *p;break;
1617 case 8:if (auto p = std::get_if<PointLightComponent>(&m_ComponentClipboard))m_SelectedEntity.GetComponent<PointLightComponent>() = *p;break;
1618 case 9:if (auto p = std::get_if<SpotLightComponent>(&m_ComponentClipboard))m_SelectedEntity.GetComponent<SpotLightComponent>() = *p;break;
1619 case 10:if (auto p = std::get_if<AnimatorComponent>(&m_ComponentClipboard))m_SelectedEntity.GetComponent<AnimatorComponent>() = *p;break;
1620 case 11: if (auto p = std::get_if<NavAgentComponent>(&m_ComponentClipboard)) { m_SelectedEntity.GetComponent<NavAgentComponent>() = *p; } break;
1621 case 12:if (auto p = std::get_if<PerceptionComponent>(&m_ComponentClipboard))m_SelectedEntity.GetComponent<PerceptionComponent>() = *p;break;
1622 }
1623 };
1624
1625 if (ImGui::SmallButton("Reset")) reset();
1626 ImGui::SameLine();
1627 if (ImGui::SmallButton("Copy")) copy();
1628 ImGui::SameLine();
1629 if (ImGui::SmallButton("Paste")) paste();
1630 ImGui::SameLine();
1631
1632 const bool removable = id != 0;
1633 if (!removable) ImGui::BeginDisabled();
1634 if (ImGui::SmallButton("Remove") && removable)
1635 {
1636 CaptureUndoSnapshot();
1637 switch (id) {
1638 case 1:m_SelectedEntity.RemoveComponent<NativeScriptComponent>();break;
1639 case 2:m_SelectedEntity.RemoveComponent<RigidbodyComponent>();break;
1640 case 3:m_SelectedEntity.RemoveComponent<BoxColliderComponent>();break;
1641 case 4:m_SelectedEntity.RemoveComponent<SphereColliderComponent>();break;
1642 case 5:m_SelectedEntity.RemoveComponent<CapsuleColliderComponent>();break;
1643 case 6:m_SelectedEntity.RemoveComponent<CameraComponent>();break;
1644 case 7:m_SelectedEntity.RemoveComponent<DirectionalLightComponent>();break;
1645 case 8:m_SelectedEntity.RemoveComponent<PointLightComponent>();break;
1646 case 9:m_SelectedEntity.RemoveComponent<SpotLightComponent>();break;
1647 case 10:m_SelectedEntity.RemoveComponent<AnimatorComponent>();break;
1648 case 11:m_SelectedEntity.RemoveComponent<NavAgentComponent>();break;
1649 case 12:m_SelectedEntity.RemoveComponent<PerceptionComponent>();break;
1650 }
1651 componentIndex = 0;
1652 }
1653 if (!removable) ImGui::EndDisabled();
1654 ImGui::TextDisabled("F2 Rename | Ctrl+D Duplicate | Delete | Ctrl+Z/Y Undo/Redo");
1655 }
1656}
Animation declarations for the Animation subsystem.
AssetManager declarations for the Asset subsystem.
AssetRegistry declarations for the Asset Management subsystem.
AudioEngine declarations for the Audio subsystem.
BTAssetPaths declarations for the Behavior Trees subsystem.
BTGameplay declarations for the Behavior Trees subsystem.
BTScriptExample declarations for the Behavior Trees subsystem.
Components declarations for the Scenes and Native Scripting subsystem.
Main editor interaction, rendering and debugging layer.
Material declarations for the Rendering subsystem.
MaterialSerializer declarations for the Asset Management subsystem.
Mesh declarations for the Rendering subsystem.
Built-in gameplay scripts and neural agent examples.
PrefabSerializer declarations for the Asset Management subsystem.
ProjectAssetOperations declarations for the Asset Management subsystem.
Scene declarations for the Scenes and Native Scripting subsystem.
Registration and creation of native gameplay scripts.
Texture declarations for the Rendering subsystem.
static const std::filesystem::path & GetProjectRoot()
static std::filesystem::path ImportTexture(const std::filesystem::path &sourcePath)
static std::shared_ptr< Texture2D > LoadTexture(const std::filesystem::path &path)
static const std::filesystem::path & GetAssetsDirectory()
static bool Play(std::uint32_t entityHandle, const AudioSourceComponent &source, const glm::vec3 &position=glm::vec3(0.0f))
static void Stop(std::uint32_t entityHandle)
static const std::string & GetLastError()
static std::shared_ptr< Material > Load(const std::filesystem::path &, const std::shared_ptr< Shader > &, AssetRegistry &)
static bool Save(const Material &, const std::filesystem::path &, const AssetRegistry &)
static Entity Revert(Entity instance, const std::shared_ptr< Mesh > &fallback, const std::shared_ptr< Material > &base)
static bool Apply(Entity instance, const std::filesystem::path &)
static std::filesystem::path CreatePrefab(Entity source, const std::filesystem::path &directory, const LogFunction &log={})
static void ApplyDefaults(NativeScriptComponent &component)
static const ScriptDefinition * Find(const std::string &name)
static std::vector< const ScriptDefinition * > All()
static std::shared_ptr< Texture2D > CreateCheckerboard(std::uint32_t width=256, std::uint32_t height=256)
Definition Texture.cpp:6
constexpr LayerMask Bit(std::uint32_t layer)
Definition Components.h:54
TrainingPreset
Supported supervised training datasets and target mappings.
Neural::TrainingHistory TrainPreset(const std::string &outputName, const std::string &sourceName, TrainingPreset preset, int epochs, float learningRate, bool resume, bool overwrite)
Trains a preset model and saves it independently of the active model.
ParticleBlendMode
Definition Components.h:164
MaterialSurfaceMode
Definition Material.h:16
void RegisterBuiltinScripts()
std::uint32_t LayerMask
Definition Components.h:37
CameraProjectionType
Definition Components.h:106
RigidbodyType
Definition Components.h:223
void RegisterBTExampleMover()
void RegisterBTAssetAgent()
Definition BTGameplay.h:281
ParticleShape
Definition Components.h:163
bool IsValidNeuralAssetName(const std::string &name)
std::vector< std::string > ListNeuralAssetNames()
std::filesystem::path NeuralAssetPath(const std::string &name)
std::vector< std::string > ListBTAssetNames()
static ScriptFieldValue MakeInt(int value)
Definition Components.h:309
static ScriptFieldValue MakeString(std::string value)
Definition Components.h:311