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"
4#include <memory>
15#include <engine/engine.h>
16
17
18namespace unravel
19{
20
22{
23}
24
25void entity_panel::duplicate_entities(const std::vector<entt::handle>& entities)
26{
27 auto& ctx = engine::context();
28 auto& em = ctx.get_cached<editing_manager>();
29 em.queue_action("Duplicate Entities",
30 [entities]() mutable
31 {
32 auto& ctx = engine::context();
33 auto& ec = ctx.get_cached<ecs>();
34 auto& em = ctx.get_cached<editing_manager>();
35 em.unselect(false);
36
37 // Get the active scene based on edit mode
38 auto* active_scene = em.get_active_scene(ctx);
39 if(!active_scene)
40 {
41 return;
42 }
43
44 for(auto entity : entities)
45 {
46 if(!entity.valid())
47 {
48 return;
49 }
50 auto object = active_scene->clone_entity(entity);
51
52 em.select(object, editing_manager::select_mode::shift);
53 }
54 });
55}
56
57void entity_panel::focus_entities(entt::handle camera, const std::vector<entt::handle>& entities)
58{
59 auto& ctx = engine::context();
60 auto& em = ctx.get_cached<editing_manager>();
61 em.queue_action("Focus Entities",
62 [camera, entities]() mutable
63 {
65 });
66}
67
68void entity_panel::delete_entities(const std::vector<entt::handle>& entities)
69{
70 auto& ctx = engine::context();
71 auto& em = ctx.get_cached<editing_manager>();
72
74 for(auto entity : entities)
75 {
76 em.unselect(entity);
77 }
78 em.queue_action("Delete Entities", std::make_shared<delete_entities_action_t>(entities));
79 em.pop_undo_stack_enabled();
80}
81
82
88auto entity_panel::get_entity_name(entt::handle entity) -> std::string
89{
90 if(!entity)
91 {
92 return "Unknown";
93 }
94
95 auto* tag_comp = entity.try_get<tag_component>();
96 if(tag_comp && !tag_comp->name.empty())
97 {
98 return tag_comp->name;
99 }
100
101 // Fallback to entity ID if no name
102 return "Entity_" + std::to_string(static_cast<uint32_t>(entity.entity()));
103}
104
105auto entity_panel::get_entity_icon(entt::handle entity) -> std::string
106{
107 bool is_bone = entity.all_of<bone_component>();
108 bool has_source = entity.any_of<prefab_component>();
109
110 auto icon = has_source ? ICON_MDI_CUBE " " : ICON_MDI_CUBE_OUTLINE " ";
111 if(is_bone)
112 {
113 icon = ICON_MDI_BONE " ";
114 }
115
116 return icon;
117}
118
120{
121 auto& trans_comp = entity.get<transform_component>();
122 bool is_bone = entity.all_of<bone_component>();
123 bool is_submesh = entity.all_of<submesh_component>();
124 bool is_active_global = trans_comp.is_active_global();
125 bool has_source = entity.any_of<prefab_component, prefab_id_component>();
126 bool has_broken_source = false;
127
128 if(auto pfb = entity.try_get<prefab_component>())
129 {
130 if(!pfb->source)
131 {
132 has_source = false;
133 has_broken_source = true;
134 }
135 }
136
137 auto col = ImGui::GetStyleColorVec4(ImGuiCol_Text);
138
139 col = ImLerp(col, ImVec4(0.5f, 0.85f, 1.0f, 1.0f), float(has_source) * 0.5f);
140 col = ImLerp(col, ImVec4(1.0f, 0.0f, 0.0f, 1.0f), float(has_broken_source) * 0.5f);
141 col = ImLerp(col, ImVec4(0.5f, 0.85f, 1.0f, 1.0f), float(is_bone) * 0.5f);
142 col = ImLerp(col, ImVec4(0.8f, 0.4f, 0.4f, 1.0f), float(is_submesh) * 0.5f);
143 col = ImLerp(col, ImVec4(col.x * 0.75f, col.y * 0.75f, col.z * 0.75f, col.w * 0.75f), float(!is_active_global));
144
145 return col;
146}
147
148} // namespace unravel
Class representing a camera. Contains functionality for manipulating and updating a camera....
Definition camera.h:62
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, const char *name)
void delete_entities(const std::vector< entt::handle > &entities)
Component that handles transformations (position, rotation, scale, etc.) in the ACE framework.
const char * icon
std::string name
Definition hub.cpp:33
#define ICON_MDI_CUBE_OUTLINE
#define ICON_MDI_BONE
#define ICON_MDI_CUBE
std::vector< size_t > parent_
entt::handle entity
static void focus_camera_on_entities(entt::handle camera, hpp::span< const entt::handle > entities, float duration=0.0f)
Focuses a camera on a specified entity with a timed transition.
Manages the entity-component-system (ECS) operations for the ACE framework.
Definition ecs.h:12
void push_undo_stack_enabled(bool enabled)
void queue_action(const std::string &name, const std::function< void()> &action)
static auto context() -> rtti::context &
Definition engine.cpp:111
Component that holds a reference to a prefab asset and tracks property overrides.
Component that provides a unique identifier (UUID) for a prefab.
Component that provides a tag (name or label) for an entity.