Unravel Engine C++ Reference
Loading...
Searching...
No Matches
entity_panel.cpp
Go to the documentation of this file.
1#include "entity_panel.h"
2#include "panel.h"
13#include <engine/engine.h>
14
15
16namespace unravel
17{
18
19entity_panel::entity_panel(imgui_panels* parent) : parent_(parent)
20{
21}
25
26void entity_panel::duplicate_entities(const std::vector<entt::handle>& entities)
27{
28 auto& ctx = engine::context();
29 auto& em = ctx.get_cached<editing_manager>();
30 em.queue_action("Duplicate Entities",
31 [entities]() mutable
32 {
33 auto& ctx = engine::context();
34 auto& ec = ctx.get_cached<ecs>();
35 auto& em = ctx.get_cached<editing_manager>();
36 em.unselect(false);
37
38 // Get the active scene based on edit mode
39 auto* active_scene = em.get_active_scene(ctx);
40 if(!active_scene)
41 {
42 return;
43 }
44
45 for(auto entity : entities)
46 {
47 if(!entity.valid())
48 {
49 return;
50 }
51 auto object = active_scene->clone_entity(entity);
52
53 em.select(object, editing_manager::select_mode::shift);
54 }
55 });
56}
57
58void entity_panel::focus_entities(entt::handle camera, const std::vector<entt::handle>& entities)
59{
60 auto& ctx = engine::context();
61 auto& em = ctx.get_cached<editing_manager>();
62 em.queue_action("Focus Entities",
63 [camera, entities]() mutable
64 {
66 });
67}
68
69void entity_panel::delete_entities(const std::vector<entt::handle>& entities)
70{
71 auto& ctx = engine::context();
72 auto& em = ctx.get_cached<editing_manager>();
73 em.queue_action("Delete Entities",
74 [entities]() mutable
75 {
76 auto& ctx = engine::context();
77 auto& em = ctx.get_cached<editing_manager>();
78 for(auto entity : entities)
79 {
80 if(!entity.valid())
81 {
82 return;
83 }
84
85 em.unselect(entity);
86
88
89 entity.destroy();
90 }
91 });
92}
93
94
100auto entity_panel::get_entity_name(entt::handle entity) -> std::string
101{
102 if(!entity)
103 {
104 return "Unknown";
105 }
106
107 auto* tag_comp = entity.try_get<tag_component>();
108 if(tag_comp && !tag_comp->name.empty())
109 {
110 return tag_comp->name;
111 }
112
113 // Fallback to entity ID if no name
114 return "Entity_" + std::to_string(static_cast<uint32_t>(entity.entity()));
115}
116
117auto entity_panel::get_entity_icon(entt::handle entity) -> std::string
118{
119 bool is_bone = entity.all_of<bone_component>();
120 bool has_source = entity.any_of<prefab_component>();
121
122 auto icon = has_source ? ICON_MDI_CUBE " " : ICON_MDI_CUBE_OUTLINE " ";
123 if(is_bone)
124 {
125 icon = ICON_MDI_BONE " ";
126 }
127
128 return icon;
129}
130
132{
133 auto& trans_comp = entity.get<transform_component>();
134 bool is_bone = entity.all_of<bone_component>();
135 bool is_submesh = entity.all_of<submesh_component>();
136 bool is_active_global = trans_comp.is_active_global();
137 bool has_source = entity.any_of<prefab_component, prefab_id_component>();
138 bool has_broken_source = false;
139
140 if(auto pfb = entity.try_get<prefab_component>())
141 {
142 if(!pfb->source)
143 {
144 has_source = false;
145 has_broken_source = true;
146 }
147 }
148
149 auto col = ImGui::GetStyleColorVec4(ImGuiCol_Text);
150
151 col = ImLerp(col, ImVec4(0.5f, 0.85f, 1.0f, 1.0f), float(has_source) * 0.5f);
152 col = ImLerp(col, ImVec4(1.0f, 0.0f, 0.0f, 1.0f), float(has_broken_source) * 0.5f);
153 col = ImLerp(col, ImVec4(0.5f, 0.85f, 1.0f, 1.0f), float(is_bone) * 0.5f);
154 col = ImLerp(col, ImVec4(0.8f, 0.4f, 0.4f, 1.0f), float(is_submesh) * 0.5f);
155 col = ImLerp(col, ImVec4(col.x * 0.75f, col.y * 0.75f, col.z * 0.75f, col.w * 0.75f), float(!is_active_global));
156
157 return col;
158}
159
160} // namespace unravel
Class representing a camera. Contains functionality for manipulating and updating a camera....
Definition camera.h:35
static auto get_entity_icon(entt::handle entity) -> std::string
void focus_entities(entt::handle camera, const std::vector< entt::handle > &entities)
void duplicate_entities(const std::vector< entt::handle > &entities)
static auto get_entity_name(entt::handle entity) -> std::string
Gets the entity name from tag component.
static auto get_entity_display_color(entt::handle entity) -> ImVec4
entity_panel(imgui_panels *parent)
void delete_entities(const std::vector< entt::handle > &entities)
Component that handles transformations (position, rotation, scale, etc.) in the ACE framework.
#define ICON_MDI_CUBE_OUTLINE
#define ICON_MDI_BONE
#define ICON_MDI_CUBE
const char * icon
entt::entity entity
static void focus_camera_on_entities(entt::handle camera, const std::vector< entt::handle > &entities)
Focuses a camera on a specified entity.
Definition defaults.cpp:783
Manages the entity-component-system (ECS) operations for the ACE framework.
Definition ecs.h:12
void queue_action(const std::string &name, const std::function< void()> &action)
static auto context() -> rtti::context &
Definition engine.cpp:115
Component that holds a reference to a prefab asset and tracks property overrides.
Component that provides a unique identifier (UUID) for a prefab.
static void mark_entity_as_removed(entt::handle entity)
Marks an entity as removed from the prefab instance.
Component that provides a tag (name or label) for an entity.