Blender V4.3
overlay_gpencil_legacy.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DRW_render.hh"
10
11#include "BKE_gpencil_legacy.h"
12
13#include "UI_resources.hh"
14
16
18
19#include "ED_view3d.hh"
20
21#include "overlay_private.hh"
22
23#include "draw_common_c.hh"
24#include "draw_manager_text.hh"
25
27{
28 OVERLAY_PassList *psl = vedata->psl;
29 OVERLAY_PrivateData *pd = vedata->stl->pd;
30 GPUShader *sh;
31 DRWShadingGroup *grp;
32
33 /* Default: Display nothing. */
34 pd->edit_gpencil_points_grp = nullptr;
35 pd->edit_gpencil_wires_grp = nullptr;
36 psl->edit_gpencil_ps = nullptr;
37
40 psl->edit_gpencil_curve_ps = nullptr;
41
42 const DRWContextState *draw_ctx = DRW_context_state_get();
43 View3D *v3d = draw_ctx->v3d;
44 Object *ob = draw_ctx->obact;
45 bGPdata *gpd = ob ? (bGPdata *)ob->data : nullptr;
46 Scene *scene = draw_ctx->scene;
47 ToolSettings *ts = scene->toolsettings;
48
49 if (gpd == nullptr || ob->type != OB_GPENCIL_LEGACY) {
50 return;
51 }
52
53 /* For sculpt show only if mask mode, and only points if not stroke mode. */
54 const bool use_sculpt_mask = (GPENCIL_SCULPT_MODE(gpd) &&
56 const bool show_sculpt_points = (GPENCIL_SCULPT_MODE(gpd) &&
60
61 /* For vertex paint show only if mask mode, and only points if not stroke mode. */
62 bool use_vertex_mask = (GPENCIL_VERTEX_MODE(gpd) &&
64 const bool show_vertex_points = (GPENCIL_VERTEX_MODE(gpd) &&
68
69 /* If Sculpt or Vertex mode and the mask is disabled, the select must be hidden. */
70 const bool hide_select = ((GPENCIL_SCULPT_MODE(gpd) && !use_sculpt_mask) ||
71 (GPENCIL_VERTEX_MODE(gpd) && !use_vertex_mask));
72
73 const bool do_multiedit = GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
74 const bool show_multi_edit_lines = (do_multiedit) &&
77
78 const bool show_lines = (v3d->gp_flag & V3D_GP_SHOW_EDIT_LINES) || show_multi_edit_lines;
79
80 const bool hide_lines = !GPENCIL_EDIT_MODE(gpd) && !GPENCIL_WEIGHT_MODE(gpd) &&
81 !use_sculpt_mask && !use_vertex_mask && !show_lines;
82
83 /* Special case when vertex paint and multiedit lines. */
84 if (do_multiedit && show_multi_edit_lines && GPENCIL_VERTEX_MODE(gpd)) {
85 use_vertex_mask = true;
86 }
87
88 const bool is_weight_paint = (gpd) && (gpd->flag & GP_DATA_STROKE_WEIGHTMODE);
89
90 /* Show Edit points if:
91 * Edit mode: Not in Stroke selection mode
92 * Sculpt mode: If use Mask and not Stroke mode
93 * Weight mode: Always
94 * Vertex mode: If use Mask and not Stroke mode
95 */
96 const bool show_points = show_sculpt_points || is_weight_paint || show_vertex_points ||
97 (GPENCIL_EDIT_MODE(gpd) &&
99
101 ((!GPENCIL_VERTEX_MODE(gpd) && !GPENCIL_PAINT_MODE(gpd)) || use_vertex_mask))
102 {
106
107 if (show_lines && !hide_lines) {
110 DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
111 DRW_shgroup_uniform_bool_copy(grp, "doMultiframe", show_multi_edit_lines);
112 DRW_shgroup_uniform_bool_copy(grp, "doWeightColor", is_weight_paint);
113 DRW_shgroup_uniform_bool_copy(grp, "hideSelect", hide_select);
114 DRW_shgroup_uniform_float_copy(grp, "gpEditOpacity", v3d->vertex_opacity);
115 DRW_shgroup_uniform_texture(grp, "weightTex", G_draw.weight_ramp);
116 }
117
118 if (show_points && !hide_select) {
121 DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
122 DRW_shgroup_uniform_bool_copy(grp, "doMultiframe", do_multiedit);
123 DRW_shgroup_uniform_bool_copy(grp, "doWeightColor", is_weight_paint);
124 DRW_shgroup_uniform_float_copy(grp, "gpEditOpacity", v3d->vertex_opacity);
125 DRW_shgroup_uniform_texture(grp, "weightTex", G_draw.weight_ramp);
126 }
127 }
128
129 /* Handles and curve point for Curve Edit sub-mode. */
133
134 /* Edit lines. */
135 if (show_lines) {
138 DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
139 DRW_shgroup_uniform_bool_copy(grp, "doMultiframe", show_multi_edit_lines);
140 DRW_shgroup_uniform_bool_copy(grp, "doWeightColor", is_weight_paint);
141 DRW_shgroup_uniform_bool_copy(grp, "hideSelect", hide_select);
142 DRW_shgroup_uniform_float_copy(grp, "gpEditOpacity", v3d->vertex_opacity);
143 DRW_shgroup_uniform_texture(grp, "weightTex", G_draw.weight_ramp);
144 }
145
148 DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
149 DRW_shgroup_uniform_bool_copy(grp, "showCurveHandles", pd->edit_curve.show_handles);
150 DRW_shgroup_uniform_int_copy(grp, "curveHandleDisplay", pd->edit_curve.handle_display);
152
155 DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
156 DRW_shgroup_uniform_bool_copy(grp, "showCurveHandles", pd->edit_curve.show_handles);
157 DRW_shgroup_uniform_int_copy(grp, "curveHandleDisplay", pd->edit_curve.handle_display);
158 }
159
160 /* control points for primitives and speed guide */
161 const bool is_cppoint = (gpd->runtime.tot_cp_points > 0);
162 const bool is_speed_guide = (ts->gp_sculpt.guide.use_guide &&
164 const bool is_show_gizmo = (((v3d->gizmo_flag & V3D_GIZMO_HIDE) == 0) &&
165 ((v3d->gizmo_flag & V3D_GIZMO_HIDE_TOOL) == 0));
166
167 if ((is_cppoint || is_speed_guide) && (is_show_gizmo)) {
170
173
174 if (gpd->runtime.cp_points != nullptr) {
175 for (int i = 0; i < gpd->runtime.tot_cp_points; i++) {
176 bGPDcontrolpoint *cp = &gpd->runtime.cp_points[i];
177 grp = DRW_shgroup_create_sub(grp);
178 DRW_shgroup_uniform_vec3_copy(grp, "pPosition", &cp->x);
179 DRW_shgroup_uniform_float_copy(grp, "pSize", cp->size * 0.8f * G_draw.block.size_pixel);
180 DRW_shgroup_uniform_vec4_copy(grp, "pColor", cp->color);
181 DRW_shgroup_call_procedural_points(grp, nullptr, 1);
182 }
183 }
184
185 if (ts->gp_sculpt.guide.use_guide) {
186 float color[4];
190 }
192 ts->gp_sculpt.guide.reference_object != nullptr)
193 {
196 }
197 else {
199 DRW_shgroup_uniform_vec3_copy(grp, "pPosition", scene->cursor.location);
200 }
201 DRW_shgroup_uniform_vec4_copy(grp, "pColor", color);
202 DRW_shgroup_uniform_float_copy(grp, "pSize", 8.0f * G_draw.block.size_pixel);
203 DRW_shgroup_call_procedural_points(grp, nullptr, 1);
204 }
205 }
206}
207
209{
210 OVERLAY_PassList *psl = vedata->psl;
211 OVERLAY_PrivateData *pd = vedata->stl->pd;
212 GPUShader *sh;
213 DRWShadingGroup *grp;
214
215 /* Default: Display nothing. */
216 psl->gpencil_canvas_ps = nullptr;
217
218 const DRWContextState *draw_ctx = DRW_context_state_get();
219 View3D *v3d = draw_ctx->v3d;
220 Object *ob = draw_ctx->obact;
221 bGPdata *gpd = ob ? (bGPdata *)ob->data : nullptr;
222 Scene *scene = draw_ctx->scene;
223 ToolSettings *ts = scene->toolsettings;
224 const View3DCursor *cursor = &scene->cursor;
225
228
229 if (gpd == nullptr || ob->type != OB_GPENCIL_LEGACY) {
230 return;
231 }
232
233 const bool show_overlays = (v3d->flag2 & V3D_HIDE_OVERLAYS) == 0;
234 const bool show_grid = (v3d->gp_flag & V3D_GP_SHOW_GRID) != 0 &&
235 ((ts->gpencil_v3d_align &
237 const bool grid_xray = (v3d->gp_flag & V3D_GP_SHOW_GRID_XRAY);
238
239 if (show_grid && show_overlays) {
240 const char *grid_unit = nullptr;
241 float mat[4][4];
242 float col_grid[4];
243 float size[2];
244
245 /* set color */
246 copy_v3_v3(col_grid, gpd->grid.color);
247 col_grid[3] = max_ff(v3d->overlay.gpencil_grid_opacity, 0.01f);
248
249 copy_m4_m4(mat, ob->object_to_world().ptr());
250
251 /* Rotate and scale except align to cursor. */
253 if (gpl != nullptr) {
255 float matrot[3][3];
256 copy_m3_m4(matrot, gpl->layer_mat);
257 mul_m4_m4m3(mat, mat, matrot);
258 }
259 }
260
261 float viewinv[4][4];
262 /* Set the grid in the selected axis */
263 switch (ts->gp_sculpt.lock_axis) {
264 case GP_LOCKAXIS_X:
265 swap_v4_v4(mat[0], mat[2]);
266 break;
267 case GP_LOCKAXIS_Y:
268 swap_v4_v4(mat[1], mat[2]);
269 break;
270 case GP_LOCKAXIS_Z:
271 /* Default. */
272 break;
273 case GP_LOCKAXIS_CURSOR: {
274 const float3 size_vec = {1.0f, 1.0f, 1.0f};
275 loc_eul_size_to_mat4(mat, cursor->location, cursor->rotation_euler, size_vec);
276 break;
277 }
278 case GP_LOCKAXIS_VIEW:
279 /* view aligned */
280 DRW_view_viewmat_get(nullptr, viewinv, true);
281 copy_v3_v3(mat[0], viewinv[0]);
282 copy_v3_v3(mat[1], viewinv[1]);
283 break;
284 }
285
286 /* Move the grid to the right location depending of the align type.
287 * This is required only for 3D Cursor or Origin. */
289 copy_v3_v3(mat[3], cursor->location);
290 }
292 copy_v3_v3(mat[3], ob->object_to_world().location());
293 }
294
295 translate_m4(mat, gpd->grid.offset[0], gpd->grid.offset[1], 0.0f);
296 mul_v2_v2fl(size, gpd->grid.scale, 2.0f * ED_scene_grid_scale(scene, &grid_unit));
297 const float3 scale_vec = {size[0], size[1], 0.0f};
298 rescale_m4(mat, scale_vec);
299
300 /* Apply layer loc transform, except cursor mode. */
301 if ((gpl != nullptr) && (ts->gpencil_v3d_align & GP_PROJECT_CURSOR) == 0) {
302 add_v3_v3(mat[3], gpl->layer_mat[3]);
303 }
304
305 const int gridlines = (gpd->grid.lines <= 0) ? 1 : gpd->grid.lines;
306 const int line_count = gridlines * 4 + 2;
307
310
312
315 DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
316 DRW_shgroup_uniform_vec4_copy(grp, "color", col_grid);
317 DRW_shgroup_uniform_vec3_copy(grp, "xAxis", mat[0]);
318 DRW_shgroup_uniform_vec3_copy(grp, "yAxis", mat[1]);
319 DRW_shgroup_uniform_vec3_copy(grp, "origin", mat[3]);
320 DRW_shgroup_uniform_int_copy(grp, "halfLineCount", line_count / 2);
321 DRW_shgroup_call_procedural_lines(grp, nullptr, line_count);
322 }
323}
324
326{
327 OVERLAY_PassList *psl = vedata->psl;
328
329 if (psl->gpencil_canvas_ps) {
331 }
332}
333
335{
336 OVERLAY_PassList *psl = vedata->psl;
337
338 if (psl->edit_gpencil_gizmos_ps) {
340 }
341
342 if (psl->edit_gpencil_ps) {
344 }
345
346 /* Curve edit handles. */
347 if (psl->edit_gpencil_curve_ps) {
349 }
350}
struct bGPDlayer * BKE_gpencil_layer_active_get(struct bGPdata *gpd)
MINLINE float max_ff(float a, float b)
void copy_m3_m4(float m1[3][3], const float m2[4][4])
void mul_m4_m4m3(float R[4][4], const float A[4][4], const float B[3][3])
void translate_m4(float mat[4][4], float Tx, float Ty, float Tz)
void rescale_m4(float mat[4][4], const float scale[3])
void copy_m4_m4(float m1[4][4], const float m2[4][4])
void loc_eul_size_to_mat4(float R[4][4], const float loc[3], const float eul[3], const float size[3])
MINLINE void swap_v4_v4(float a[4], float b[4])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f)
MINLINE void add_v3_v3(float r[3], const float a[3])
#define GPENCIL_ANY_VERTEX_MASK(flag)
#define GPENCIL_VERTEX_MODE(gpd)
#define GPENCIL_EDIT_MODE(gpd)
#define GPENCIL_WEIGHT_MODE(gpd)
#define GPENCIL_SCULPT_MODE(gpd)
#define GPENCIL_MULTIEDIT_SESSIONS_ON(gpd)
#define GPENCIL_PAINT_MODE(gpd)
#define GPENCIL_ANY_SCULPT_MASK(flag)
@ GP_DATA_STROKE_WEIGHTMODE
#define GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)
@ OB_MODE_PAINT_GREASE_PENCIL
@ OB_GPENCIL_LEGACY
@ GP_GUIDE_REF_OBJECT
@ GP_GUIDE_REF_CUSTOM
@ GP_LOCKAXIS_X
@ GP_LOCKAXIS_VIEW
@ GP_LOCKAXIS_Y
@ GP_LOCKAXIS_Z
@ GP_LOCKAXIS_CURSOR
@ GP_SELECTMODE_STROKE
@ GP_SCULPT_MASK_SELECTMODE_POINT
@ GP_SCULPT_MASK_SELECTMODE_SEGMENT
@ GP_VERTEX_MASK_SELECTMODE_SEGMENT
@ GP_VERTEX_MASK_SELECTMODE_POINT
@ GP_PROJECT_VIEWSPACE
@ GP_PROJECT_DEPTH_VIEW
@ GP_PROJECT_CURSOR
@ GP_PROJECT_DEPTH_STROKE
@ V3D_GIZMO_HIDE_TOOL
@ V3D_GIZMO_HIDE
@ V3D_HIDE_OVERLAYS
@ V3D_GP_SHOW_MULTIEDIT_LINES
@ V3D_GP_SHOW_GRID_XRAY
@ V3D_GP_SHOW_EDIT_LINES
@ V3D_GP_SHOW_GRID
@ CURVE_HANDLE_NONE
#define DRW_PASS_CREATE(pass, state)
#define DRW_shgroup_uniform_block(shgroup, name, ubo)
float ED_scene_grid_scale(const Scene *scene, const char **r_grid_unit)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a color
@ TH_REDALERT
@ TH_GIZMO_PRIMARY
@ TH_GIZMO_SECONDARY
void UI_GetThemeColor4fv(int colorid, float col[4])
struct GPUShader GPUShader
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
DRW_Global G_draw
const DRWContextState * DRW_context_state_get()
DRWShadingGroup * DRW_shgroup_create(GPUShader *shader, DRWPass *pass)
void DRW_shgroup_uniform_float_copy(DRWShadingGroup *shgroup, const char *name, const float value)
void DRW_shgroup_uniform_texture(DRWShadingGroup *shgroup, const char *name, const GPUTexture *tex)
void DRW_shgroup_state_enable(DRWShadingGroup *shgroup, DRWState state)
void DRW_shgroup_uniform_vec3_copy(DRWShadingGroup *shgroup, const char *name, const float *value)
DRWShadingGroup * DRW_shgroup_create_sub(DRWShadingGroup *shgroup)
void DRW_shgroup_uniform_int_copy(DRWShadingGroup *shgroup, const char *name, const int value)
void DRW_shgroup_call_procedural_points(DRWShadingGroup *shgroup, const Object *ob, uint point_count)
void DRW_shgroup_call_procedural_lines(DRWShadingGroup *shgroup, const Object *ob, uint line_count)
void DRW_shgroup_uniform_vec4_copy(DRWShadingGroup *shgroup, const char *name, const float *value)
void DRW_shgroup_uniform_bool_copy(DRWShadingGroup *shgroup, const char *name, const bool value)
void DRW_view_viewmat_get(const DRWView *view, float mat[4][4], bool inverse)
void DRW_draw_pass(DRWPass *pass)
DRWState
Definition draw_state.hh:25
@ DRW_STATE_BLEND_ALPHA
Definition draw_state.hh:55
@ DRW_STATE_WRITE_DEPTH
Definition draw_state.hh:29
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:30
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition draw_state.hh:38
@ DRW_STATE_DEPTH_ALWAYS
Definition draw_state.hh:36
static ulong state[N]
void OVERLAY_gpencil_legacy_cache_init(OVERLAY_Data *vedata)
void OVERLAY_gpencil_legacy_draw(OVERLAY_Data *vedata)
void OVERLAY_edit_gpencil_legacy_draw(OVERLAY_Data *vedata)
void OVERLAY_edit_gpencil_legacy_cache_init(OVERLAY_Data *vedata)
GPUShader * OVERLAY_shader_edit_gpencil_wire()
GPUShader * OVERLAY_shader_edit_gpencil_point()
GPUShader * OVERLAY_shader_edit_curve_handle()
GPUShader * OVERLAY_shader_edit_gpencil_guide_point()
GPUShader * OVERLAY_shader_edit_curve_point()
GPUShader * OVERLAY_shader_gpencil_canvas()
eObjectMode object_mode
struct Object * reference_object
struct GP_Sculpt_Guide guide
OVERLAY_PassList * psl
OVERLAY_StorageList * stl
DRWPass * edit_gpencil_ps
DRWPass * edit_gpencil_gizmos_ps
DRWPass * gpencil_canvas_ps
DRWPass * edit_gpencil_curve_ps
DRWShadingGroup * edit_gpencil_points_grp
DRWShadingGroup * edit_gpencil_wires_grp
struct OVERLAY_PrivateData::@017025346316061011333067144345352107066311354153 edit_curve
DRWShadingGroup * edit_gpencil_curve_handle_grp
DRWShadingGroup * edit_gpencil_curve_points_grp
OVERLAY_PrivateData * pd
float loc[3]
struct ToolSettings * toolsettings
View3DCursor cursor
char gpencil_selectmode_vertex
char gpencil_selectmode_sculpt
struct GP_Sculpt_Settings gp_sculpt
float rotation_euler[3]
float vertex_opacity
View3DOverlay overlay
bGPDcontrolpoint * cp_points
bGPdata_Runtime runtime