Unravel Engine C++ Reference
Loading...
Searching...
No Matches
picking_manager.h
Go to the documentation of this file.
1#pragma once
2
3#include <base/basetypes.hpp>
7#include <hpp/optional.hpp>
8#include <functional>
9
10#include "editing_manager.h"
11
12namespace gfx
13{
14struct frame_buffer;
15struct texture;
16} // namespace gfx
17
18namespace unravel
19{
20
22{
23public:
24 // Callback type for custom pick actions
25 using pick_callback = std::function<void(entt::handle entity, const math::vec2& screen_pos)>;
26
29
30 auto init(rtti::context& ctx) -> bool;
31 auto deinit(rtti::context& ctx) -> bool;
32
33 // Original pick function - maintains backward compatibility
34 void request_pick(const camera& cam, editing_manager::select_mode mode, math::vec2 pos, math::vec2 area = {});
35
36 // New function for querying without selection
37 void query_pick(math::vec2 pos, const camera& cam, pick_callback callback, bool force = false);
38
39 // Check if a pick operation is in progress
40 auto is_picking() const -> bool;
41
42 void cancel_pick();
43
44 constexpr static int tex_id_dim = 1;
45
46 void on_frame_render(rtti::context& ctx, delta_t dt);
47
48 void on_frame_pick(rtti::context& ctx, delta_t dt);
49
50 auto get_pick_texture() const -> const std::shared_ptr<gfx::texture>&;
51
52private:
53 // Common picking setup function
54 void setup_pick_camera(const camera& cam, math::vec2 pos, math::vec2 area = {});
55
56 // Process picking results and call appropriate handlers
57 void process_pick_result(rtti::context& ctx, scene* target_scene, ENTT_ID_TYPE id_key);
58
60 std::shared_ptr<gfx::frame_buffer> surface_;
62 std::shared_ptr<gfx::texture> blit_tex_;
64 std::unique_ptr<gpu_program> program_;
65
66 std::unique_ptr<gpu_program> program_gizmos_;
67
68 std::unique_ptr<gpu_program> program_skinned_;
70 std::array<std::uint8_t, tex_id_dim * tex_id_dim * 4> blit_data_;
72 std::uint32_t reading_ = 0;
73
74 bool start_readback_ = false;
75
76 std::shared_ptr<int> sentinel_ = std::make_shared<int>(0);
77
78 hpp::optional<camera> pick_camera_{};
79
81
82 // Store the original pick position for callbacks
83 math::vec2 pick_position_{};
84
85 math::vec2 pick_area_{};
86
87 // Optional callback for custom pick actions
88 pick_callback pick_callback_{};
89
90
91};
92} // namespace unravel
Class representing a camera. Contains functionality for manipulating and updating a camera....
Definition camera.h:35
void query_pick(math::vec2 pos, const camera &cam, pick_callback callback, bool force=false)
std::function< void(entt::handle entity, const math::vec2 &screen_pos)> pick_callback
auto init(rtti::context &ctx) -> bool
void request_pick(const camera &cam, editing_manager::select_mode mode, math::vec2 pos, math::vec2 area={})
static constexpr int tex_id_dim
auto is_picking() const -> bool
void on_frame_render(rtti::context &ctx, delta_t dt)
void on_frame_pick(rtti::context &ctx, delta_t dt)
auto get_pick_texture() const -> const std::shared_ptr< gfx::texture > &
auto deinit(rtti::context &ctx) -> bool
std::chrono::duration< float > delta_t
Definition bbox.cpp:5
entt::entity entity
Represents a scene in the ACE framework, managing entities and their relationships.
Definition scene.h:21