2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2019 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2019-07-30 17:55:20 -03:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup draw_engine
|
|
|
|
|
*
|
|
|
|
|
* Engine for drawing a selection map where the pixels indicate the selection indices.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "BKE_editmesh.h"
|
2023-08-02 22:14:18 +02:00
|
|
|
#include "BKE_mesh.hh"
|
2023-10-09 23:41:53 +02:00
|
|
|
#include "BKE_object.hh"
|
2019-07-30 17:55:20 -03:00
|
|
|
|
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "ED_view3d.hh"
|
2019-07-30 17:55:20 -03:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph.hh"
|
|
|
|
|
#include "DEG_depsgraph_query.hh"
|
2019-07-30 17:55:20 -03:00
|
|
|
|
2023-10-04 14:32:18 -03:00
|
|
|
#include "DRW_select_buffer.hh"
|
2019-08-12 12:10:44 -03:00
|
|
|
|
2023-08-03 20:04:50 -04:00
|
|
|
#include "draw_cache_impl.hh"
|
2019-07-30 17:55:20 -03:00
|
|
|
|
2023-10-04 14:32:18 -03:00
|
|
|
#include "select_private.hh"
|
2019-07-30 17:55:20 -03:00
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Draw Utilities
|
|
|
|
|
* \{ */
|
2019-08-15 10:31:54 -03:00
|
|
|
|
2019-08-01 23:00:16 -03:00
|
|
|
short select_id_get_object_select_mode(Scene *scene, Object *ob)
|
|
|
|
|
{
|
|
|
|
|
short r_select_mode = 0;
|
2019-09-12 14:14:40 +02:00
|
|
|
if (ob->mode & (OB_MODE_WEIGHT_PAINT | OB_MODE_VERTEX_PAINT | OB_MODE_TEXTURE_PAINT)) {
|
2019-09-19 13:18:52 +10:00
|
|
|
/* In order to sample flat colors for vertex weights / texture-paint / vertex-paint
|
2019-09-12 14:14:40 +02:00
|
|
|
* we need to be in SCE_SELECT_FACE mode so select_cache_init() correctly sets up
|
|
|
|
|
* a shgroup with select_id_flat.
|
2019-09-19 13:18:52 +10:00
|
|
|
* Note this is not working correctly for vertex-paint (yet), but has been discussed
|
2023-02-12 14:37:16 +11:00
|
|
|
* in #66645 and there is a solution by @mano-wii in P1032.
|
2019-09-12 14:14:40 +02:00
|
|
|
* So OB_MODE_VERTEX_PAINT is already included here [required for P1032 I guess]. */
|
2023-07-27 14:16:58 +02:00
|
|
|
Mesh *me_orig = static_cast<Mesh *>(DEG_get_original_object(ob)->data);
|
2019-09-12 14:14:40 +02:00
|
|
|
if (me_orig->editflag & ME_EDIT_PAINT_VERT_SEL) {
|
2019-09-03 23:43:15 +10:00
|
|
|
r_select_mode = SCE_SELECT_VERTEX;
|
|
|
|
|
}
|
2019-09-12 14:14:40 +02:00
|
|
|
else {
|
2019-09-03 23:43:15 +10:00
|
|
|
r_select_mode = SCE_SELECT_FACE;
|
2019-08-01 23:00:16 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
r_select_mode = scene->toolsettings->selectmode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r_select_mode;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:21:39 +01:00
|
|
|
static bool check_ob_drawface_dot(short select_mode, const View3D *v3d, eDrawType dt)
|
2019-07-30 17:55:20 -03:00
|
|
|
{
|
|
|
|
|
if (select_mode & SCE_SELECT_FACE) {
|
|
|
|
|
if ((dt < OB_SOLID) || XRAY_FLAG_ENABLED(v3d)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_FACE_DOT) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void draw_select_id_edit_mesh(SELECTID_StorageList *stl,
|
|
|
|
|
Object *ob,
|
|
|
|
|
short select_mode,
|
|
|
|
|
bool draw_facedot,
|
|
|
|
|
uint initial_offset,
|
|
|
|
|
uint *r_vert_offset,
|
|
|
|
|
uint *r_edge_offset,
|
|
|
|
|
uint *r_face_offset)
|
|
|
|
|
{
|
2023-07-27 14:16:58 +02:00
|
|
|
Mesh *me = static_cast<Mesh *>(ob->data);
|
2019-07-30 17:55:20 -03:00
|
|
|
BMEditMesh *em = me->edit_mesh;
|
|
|
|
|
|
|
|
|
|
BM_mesh_elem_table_ensure(em->bm, BM_VERT | BM_EDGE | BM_FACE);
|
|
|
|
|
|
2019-07-30 18:26:35 -03:00
|
|
|
if (select_mode & SCE_SELECT_FACE) {
|
2023-07-28 09:38:07 +10:00
|
|
|
GPUBatch *geom_faces = DRW_mesh_batch_cache_get_triangles_with_select_id(me);
|
2019-08-17 18:40:08 -03:00
|
|
|
DRWShadingGroup *face_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_face_flat);
|
2019-07-30 17:55:20 -03:00
|
|
|
DRW_shgroup_uniform_int_copy(face_shgrp, "offset", *(int *)&initial_offset);
|
2019-08-17 18:40:08 -03:00
|
|
|
DRW_shgroup_call_no_cull(face_shgrp, geom_faces, ob);
|
2019-07-30 17:55:20 -03:00
|
|
|
|
|
|
|
|
if (draw_facedot) {
|
2023-07-28 09:38:07 +10:00
|
|
|
GPUBatch *geom_facedots = DRW_mesh_batch_cache_get_facedots_with_select_id(me);
|
2019-08-15 10:31:54 -03:00
|
|
|
DRW_shgroup_call_no_cull(face_shgrp, geom_facedots, ob);
|
2019-07-30 17:55:20 -03:00
|
|
|
}
|
|
|
|
|
*r_face_offset = initial_offset + em->bm->totface;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2019-08-17 18:40:08 -03:00
|
|
|
if (ob->dt >= OB_SOLID) {
|
2019-09-17 08:26:38 -03:00
|
|
|
#ifdef USE_CAGE_OCCLUSION
|
2023-07-28 09:38:07 +10:00
|
|
|
GPUBatch *geom_faces = DRW_mesh_batch_cache_get_triangles_with_select_id(me);
|
2019-09-17 08:26:38 -03:00
|
|
|
#else
|
2019-08-17 18:40:08 -03:00
|
|
|
struct GPUBatch *geom_faces = DRW_mesh_batch_cache_get_surface(me);
|
2019-09-17 08:26:38 -03:00
|
|
|
#endif
|
2019-08-17 18:40:08 -03:00
|
|
|
DRWShadingGroup *face_shgrp = stl->g_data->shgrp_face_unif;
|
|
|
|
|
DRW_shgroup_call_no_cull(face_shgrp, geom_faces, ob);
|
|
|
|
|
}
|
2019-07-30 17:55:20 -03:00
|
|
|
*r_face_offset = initial_offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Unlike faces, only draw edges if edge select mode. */
|
|
|
|
|
if (select_mode & SCE_SELECT_EDGE) {
|
2023-07-28 09:38:07 +10:00
|
|
|
GPUBatch *geom_edges = DRW_mesh_batch_cache_get_edges_with_select_id(me);
|
2019-07-30 17:55:20 -03:00
|
|
|
DRWShadingGroup *edge_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_edge);
|
|
|
|
|
DRW_shgroup_uniform_int_copy(edge_shgrp, "offset", *(int *)r_face_offset);
|
2019-08-15 10:31:54 -03:00
|
|
|
DRW_shgroup_call_no_cull(edge_shgrp, geom_edges, ob);
|
2019-07-30 17:55:20 -03:00
|
|
|
*r_edge_offset = *r_face_offset + em->bm->totedge;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Note that `r_vert_offset` is calculated from `r_edge_offset`.
|
2023-02-12 14:37:16 +11:00
|
|
|
* Otherwise the first vertex is never selected, see: #53512. */
|
2019-07-30 17:55:20 -03:00
|
|
|
*r_edge_offset = *r_face_offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Unlike faces, only verts if vert select mode. */
|
|
|
|
|
if (select_mode & SCE_SELECT_VERTEX) {
|
2023-07-28 09:38:07 +10:00
|
|
|
GPUBatch *geom_verts = DRW_mesh_batch_cache_get_verts_with_select_id(me);
|
2019-07-30 17:55:20 -03:00
|
|
|
DRWShadingGroup *vert_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_vert);
|
|
|
|
|
DRW_shgroup_uniform_int_copy(vert_shgrp, "offset", *(int *)r_edge_offset);
|
2019-08-15 10:31:54 -03:00
|
|
|
DRW_shgroup_call_no_cull(vert_shgrp, geom_verts, ob);
|
2019-07-30 17:55:20 -03:00
|
|
|
*r_vert_offset = *r_edge_offset + em->bm->totvert;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
*r_vert_offset = *r_edge_offset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-30 18:26:35 -03:00
|
|
|
static void draw_select_id_mesh(SELECTID_StorageList *stl,
|
|
|
|
|
Object *ob,
|
|
|
|
|
short select_mode,
|
|
|
|
|
uint initial_offset,
|
|
|
|
|
uint *r_vert_offset,
|
|
|
|
|
uint *r_edge_offset,
|
|
|
|
|
uint *r_face_offset)
|
2019-07-30 17:55:20 -03:00
|
|
|
{
|
2023-07-27 14:16:58 +02:00
|
|
|
Mesh *me = static_cast<Mesh *>(ob->data);
|
2019-07-30 17:55:20 -03:00
|
|
|
|
2023-07-28 09:38:07 +10:00
|
|
|
GPUBatch *geom_faces = DRW_mesh_batch_cache_get_triangles_with_select_id(me);
|
2019-07-30 18:26:35 -03:00
|
|
|
DRWShadingGroup *face_shgrp;
|
|
|
|
|
if (select_mode & SCE_SELECT_FACE) {
|
|
|
|
|
face_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_face_flat);
|
|
|
|
|
DRW_shgroup_uniform_int_copy(face_shgrp, "offset", *(int *)&initial_offset);
|
2023-07-24 22:06:55 +02:00
|
|
|
*r_face_offset = initial_offset + me->faces_num;
|
2019-07-30 18:26:35 -03:00
|
|
|
}
|
|
|
|
|
else {
|
2019-07-30 17:55:20 -03:00
|
|
|
/* Only draw faces to mask out verts, we don't want their selection ID's. */
|
2019-08-01 22:24:07 -03:00
|
|
|
face_shgrp = stl->g_data->shgrp_face_unif;
|
2019-07-30 18:26:35 -03:00
|
|
|
*r_face_offset = initial_offset;
|
|
|
|
|
}
|
2019-08-15 10:31:54 -03:00
|
|
|
DRW_shgroup_call_no_cull(face_shgrp, geom_faces, ob);
|
2019-07-30 17:55:20 -03:00
|
|
|
|
2019-07-30 18:26:35 -03:00
|
|
|
if (select_mode & SCE_SELECT_EDGE) {
|
2023-07-28 09:38:07 +10:00
|
|
|
GPUBatch *geom_edges = DRW_mesh_batch_cache_get_edges_with_select_id(me);
|
2019-07-30 18:26:35 -03:00
|
|
|
DRWShadingGroup *edge_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_edge);
|
|
|
|
|
DRW_shgroup_uniform_int_copy(edge_shgrp, "offset", *(int *)r_face_offset);
|
2019-08-15 10:31:54 -03:00
|
|
|
DRW_shgroup_call_no_cull(edge_shgrp, geom_edges, ob);
|
2019-07-30 18:26:35 -03:00
|
|
|
*r_edge_offset = *r_face_offset + me->totedge;
|
2019-07-30 17:55:20 -03:00
|
|
|
}
|
|
|
|
|
else {
|
2019-07-30 18:26:35 -03:00
|
|
|
*r_edge_offset = *r_face_offset;
|
|
|
|
|
}
|
2019-07-30 17:55:20 -03:00
|
|
|
|
2019-07-30 18:26:35 -03:00
|
|
|
if (select_mode & SCE_SELECT_VERTEX) {
|
2023-07-28 09:38:07 +10:00
|
|
|
GPUBatch *geom_verts = DRW_mesh_batch_cache_get_verts_with_select_id(me);
|
2019-07-30 18:26:35 -03:00
|
|
|
DRWShadingGroup *vert_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_vert);
|
2019-08-01 22:27:04 -03:00
|
|
|
DRW_shgroup_uniform_int_copy(vert_shgrp, "offset", *r_edge_offset);
|
2019-08-15 10:31:54 -03:00
|
|
|
DRW_shgroup_call_no_cull(vert_shgrp, geom_verts, ob);
|
2019-07-30 18:26:35 -03:00
|
|
|
*r_vert_offset = *r_edge_offset + me->totvert;
|
2019-07-30 17:55:20 -03:00
|
|
|
}
|
2019-08-06 17:26:52 -03:00
|
|
|
else {
|
|
|
|
|
*r_vert_offset = *r_edge_offset;
|
|
|
|
|
}
|
2019-07-30 17:55:20 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void select_id_draw_object(void *vedata,
|
|
|
|
|
View3D *v3d,
|
|
|
|
|
Object *ob,
|
|
|
|
|
short select_mode,
|
|
|
|
|
uint initial_offset,
|
|
|
|
|
uint *r_vert_offset,
|
|
|
|
|
uint *r_edge_offset,
|
|
|
|
|
uint *r_face_offset)
|
|
|
|
|
{
|
|
|
|
|
SELECTID_StorageList *stl = ((SELECTID_Data *)vedata)->stl;
|
|
|
|
|
|
|
|
|
|
BLI_assert(initial_offset > 0);
|
|
|
|
|
|
|
|
|
|
switch (ob->type) {
|
|
|
|
|
case OB_MESH:
|
|
|
|
|
if (ob->mode & OB_MODE_EDIT) {
|
2023-07-27 14:16:58 +02:00
|
|
|
bool draw_facedot = check_ob_drawface_dot(select_mode, v3d, eDrawType(ob->dt));
|
2019-07-30 17:55:20 -03:00
|
|
|
draw_select_id_edit_mesh(stl,
|
|
|
|
|
ob,
|
|
|
|
|
select_mode,
|
|
|
|
|
draw_facedot,
|
|
|
|
|
initial_offset,
|
|
|
|
|
r_vert_offset,
|
|
|
|
|
r_edge_offset,
|
|
|
|
|
r_face_offset);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2019-07-30 18:26:35 -03:00
|
|
|
draw_select_id_mesh(
|
|
|
|
|
stl, ob, select_mode, initial_offset, r_vert_offset, r_edge_offset, r_face_offset);
|
2019-07-30 17:55:20 -03:00
|
|
|
}
|
|
|
|
|
break;
|
2022-02-18 09:50:29 -06:00
|
|
|
case OB_CURVES_LEGACY:
|
2019-07-30 17:55:20 -03:00
|
|
|
case OB_SURF:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
#undef SELECT_ENGINE
|