Blender V5.3
overlay_axes.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#pragma once
12
13#include "overlay_base.hh"
14
15namespace blender::draw::overlay {
16
22class Axes : Overlay {
23 using EmptyInstanceBuf = ShapeInstanceBuf<ExtraInstanceData>;
24
25 private:
26 const SelectionType selection_type_;
27
28 PassSimple ps_ = {"Axes"};
29
30 EmptyInstanceBuf axes_buf = {selection_type_, "object_axes"};
31 EmptyInstanceBuf xform_origins_buf = {selection_type_, "xform_origins"};
32
33 public:
34 Axes(const SelectionType selection_type) : selection_type_{selection_type} {};
35
36 void begin_sync(Resources & /*res*/, const State &state) final
37 {
38 enabled_ = state.is_space_v3d();
39
40 ps_.init();
41 axes_buf.clear();
42 xform_origins_buf.clear();
43 }
44
45 void object_sync(Manager & /*manager*/,
46 const ObjectRef &ob_ref,
47 Resources &res,
48 const State &state) final
49 {
50 if (!enabled_) {
51 return;
52 }
53
54 Object *ob = ob_ref.object;
55 if (is_from_dupli_or_set(ob)) {
56 return;
57 }
58
59 const bool use_display_axis = (ob->dtx & OB_AXIS) != 0;
60 const bool use_xform_origins_axis = state.ctx_mode == CTX_MODE_OBJECT &&
61 (state.scene->toolsettings->transform_flag &
64 const bool use_xform_sculpt_pivot_axis = state.ctx_mode == CTX_MODE_SCULPT &&
65 ob == state.object_active &&
66 ob->runtime->sculpt_session != nullptr &&
67 (state.scene->toolsettings->transform_flag &
69 if (!use_display_axis && !use_xform_origins_axis && !use_xform_sculpt_pivot_axis) {
70 return;
71 }
72 float4x4 target = ob->object_to_world();
73
74 if (use_xform_sculpt_pivot_axis) {
75 const SculptSession *ss = ob->runtime->sculpt_session;
76 const float4x4 local_pivot_orientation = math::from_loc_rot<float4x4>(
78 target = target * local_pivot_orientation;
79 }
80
81 ExtraInstanceData data(target, res.object_wire_color(ob_ref, state), 1.0f);
82 if (use_xform_origins_axis || use_xform_sculpt_pivot_axis) {
83 data.color_ = float4(0.15f, 0.15f, 0.15f, 0.7f);
84 xform_origins_buf.append(data, select::SelectMap::select_invalid_id());
85 }
86 else {
87 axes_buf.append(data, res.select_id(ob_ref));
88 }
89 }
90
91 void end_sync(Resources &res, const State &state) final
92 {
93 if (!enabled_) {
94 return;
95 }
97 ps_.state_set(state_common | DRW_STATE_DEPTH_LESS_EQUAL, state.clipping_plane_count);
98 ps_.shader_set(res.shaders->extra_shape.get());
99 ps_.bind_ubo(OVERLAY_GLOBALS_SLOT, &res.globals_buf);
100 ps_.bind_ubo(DRW_CLIPPING_UBO_SLOT, &res.clip_planes_buf);
101 res.select_bind(ps_);
102
103 axes_buf.end_sync(ps_, res.shapes.arrows.get());
104
105 PassSimple::Sub &xform_origins_ps = ps_.sub("XForm Origins");
106 xform_origins_ps.state_set(state_common | DRW_STATE_DEPTH_ALWAYS, state.clipping_plane_count);
107
108 xform_origins_buf.end_sync(xform_origins_ps, res.shapes.arrows.get());
109 }
110
111 void draw_line(Framebuffer &framebuffer, Manager &manager, View &view) final
112 {
113 if (!enabled_) {
114 return;
115 }
116
117 GPU_framebuffer_bind(framebuffer);
118 manager.submit(ps_, view);
119 }
120};
121
122} // namespace blender::draw::overlay
void state_set(DRWState state, int clip_plane_count=0)
detail::PassBase< command::DrawCommandBuf > Sub
Definition draw_pass.hh:509
Axes(const SelectionType selection_type)
void draw_line(Framebuffer &framebuffer, Manager &manager, View &view) final
void end_sync(Resources &res, const State &state) final
void object_sync(Manager &, const ObjectRef &ob_ref, Resources &res, const State &state) final
void begin_sync(Resources &, const State &state) final
#define DRW_CLIPPING_UBO_SLOT
#define OVERLAY_GLOBALS_SLOT
const int state
select::SelectionType SelectionType
detail::Pass< command::DrawCommandBuf > PassSimple
QuaternionBase< float > Quaternion
MatT from_loc_rot(const typename MatT::loc_type &location, const RotationT &rotation)
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
@ CTX_MODE_SCULPT
@ CTX_MODE_OBJECT
BMesh const char void * data
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:32
@ DRW_STATE_WRITE_DEPTH
Definition draw_state.hh:31
@ DRW_STATE_DEPTH_ALWAYS
Definition draw_state.hh:38
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition draw_state.hh:40
eObject_DrawExtraFlag dtx
bke::ObjectRuntime * runtime