2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2004-2008 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2008-12-12 18:47:12 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup spview3d
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
|
2023-07-22 11:27:25 +10:00
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstring>
|
2008-12-12 18:47:12 +00:00
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
2008-12-12 18:47:12 +00:00
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
|
|
|
|
#include "BKE_editmesh.hh"
|
2024-01-23 15:18:09 -05:00
|
|
|
#include "BKE_layer.hh"
|
Fix #44834: Add bone selection icon next to face and vertex selection in weight paint mode
Currently, in weight paint mode, there is an icon for
face and vertex selection mode, but there isn't one
for the default mode where the user can select a bone
in any tool by alt clicking.
This lack of indication might lead to confusion for the users
when they are not able to select a bone by
alt clicking during weight painting.
By adding a bone selection icon when there is a pose
mode armature, we can communicate to the user that:
1. they can select a bone while the bone selection icon is active.
(when they are not in face or vertex selection mode)
2. they have forgot to select an armature when entering
weight paint mode by not showing the bone selection
icon at all when there is no pose mode armature.
When the bone selection icon is inactive,
the user can't select a bone.
(alt clicking selects face and vertex mode's respective element)
When no armature is selected when entering weight paint mode,
the bone selection icon doesn't show up indicating that the user
has forgot to select an armature.
(The user is also unable to select a bone by alt clicking.)
## Selection tool for bone selection mode
Currently, while selection tools exist for face and vertex
selection mode, one doesn't exist for the default mode
(bone selection mode). As the default mode will be getting
a clear indicator that it will function as a bone selection mode,
I added a selection tool entry for the bone selection mode.
Face and vertex selection modes has the shortcut 1 and 2,
so it seemed natural to give bone selection mode the shortcut of 3.
Pull Request: https://projects.blender.org/blender/blender/pulls/115409
2023-12-01 13:38:58 +01:00
|
|
|
#include "BKE_object.hh"
|
2008-12-12 18:47:12 +00:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph.hh"
|
2017-06-08 10:14:53 +02:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
2024-07-10 18:30:02 +02:00
|
|
|
#include "RNA_prototypes.hh"
|
2013-03-07 02:44:55 +00:00
|
|
|
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "WM_api.hh"
|
|
|
|
|
#include "WM_types.hh"
|
2013-03-07 02:44:55 +00:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_interface.hh"
|
|
|
|
|
#include "UI_resources.hh"
|
2008-12-12 18:47:12 +00:00
|
|
|
|
2024-03-26 20:34:48 -04:00
|
|
|
#include "view3d_intern.hh"
|
2008-12-12 18:47:12 +00:00
|
|
|
|
2018-06-08 16:12:25 +02:00
|
|
|
/* -------------------------------------------------------------------- */
|
2018-07-05 12:28:03 +02:00
|
|
|
/** \name Toggle Matcap Flip Operator
|
2018-06-08 16:12:25 +02:00
|
|
|
* \{ */
|
|
|
|
|
|
2023-10-05 12:57:31 +11:00
|
|
|
static int toggle_matcap_flip_exec(bContext *C, wmOperator * /*op*/)
|
2018-06-08 16:12:25 +02:00
|
|
|
{
|
|
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-18 19:26:01 +01:00
|
|
|
if (v3d) {
|
|
|
|
|
v3d->shading.flag ^= V3D_SHADING_MATCAP_FLIP_X;
|
|
|
|
|
ED_view3d_shade_update(CTX_data_main(C), v3d, CTX_wm_area(C));
|
|
|
|
|
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
scene->display.shading.flag ^= V3D_SHADING_MATCAP_FLIP_X;
|
2024-02-19 15:54:08 +01:00
|
|
|
DEG_id_tag_update(&scene->id, ID_RECALC_SYNC_TO_EVAL);
|
2020-05-08 16:44:23 +02:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
|
2019-03-18 19:26:01 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-08 16:12:25 +02:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VIEW3D_OT_toggle_matcap_flip(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Flip MatCap";
|
|
|
|
|
ot->description = "Flip MatCap";
|
|
|
|
|
ot->idname = "VIEW3D_OT_toggle_matcap_flip";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
2023-10-05 12:57:31 +11:00
|
|
|
ot->exec = toggle_matcap_flip_exec;
|
2018-06-08 16:12:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
2019-03-28 15:00:27 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name UI Templates
|
|
|
|
|
* \{ */
|
2018-05-22 14:12:47 +02:00
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
void uiTemplateEditModeSelection(uiLayout *layout, bContext *C)
|
2011-05-02 11:34:57 +00:00
|
|
|
{
|
|
|
|
|
Object *obedit = CTX_data_edit_object(C);
|
2022-02-03 17:36:05 -06:00
|
|
|
if (!obedit || obedit->type != OB_MESH) {
|
|
|
|
|
return;
|
2011-05-02 11:34:57 +00:00
|
|
|
}
|
2022-02-03 17:36:05 -06:00
|
|
|
|
|
|
|
|
BMEditMesh *em = BKE_editmesh_from_object(obedit);
|
|
|
|
|
uiLayout *row = uiLayoutRow(layout, true);
|
|
|
|
|
|
|
|
|
|
PointerRNA op_ptr;
|
|
|
|
|
wmOperatorType *ot = WM_operatortype_find("MESH_OT_select_mode", true);
|
|
|
|
|
uiItemFullO_ptr(row,
|
|
|
|
|
ot,
|
|
|
|
|
"",
|
|
|
|
|
ICON_VERTEXSEL,
|
2023-07-12 18:02:56 +02:00
|
|
|
nullptr,
|
2022-02-03 17:36:05 -06:00
|
|
|
WM_OP_INVOKE_DEFAULT,
|
2023-07-29 15:06:33 +10:00
|
|
|
(em->selectmode & SCE_SELECT_VERTEX) ? UI_ITEM_O_DEPRESS : UI_ITEM_NONE,
|
2022-02-03 17:36:05 -06:00
|
|
|
&op_ptr);
|
|
|
|
|
RNA_enum_set(&op_ptr, "type", SCE_SELECT_VERTEX);
|
|
|
|
|
uiItemFullO_ptr(row,
|
|
|
|
|
ot,
|
|
|
|
|
"",
|
|
|
|
|
ICON_EDGESEL,
|
2023-07-12 18:02:56 +02:00
|
|
|
nullptr,
|
2022-02-03 17:36:05 -06:00
|
|
|
WM_OP_INVOKE_DEFAULT,
|
2023-07-29 15:06:33 +10:00
|
|
|
(em->selectmode & SCE_SELECT_EDGE) ? UI_ITEM_O_DEPRESS : UI_ITEM_NONE,
|
2022-02-03 17:36:05 -06:00
|
|
|
&op_ptr);
|
|
|
|
|
RNA_enum_set(&op_ptr, "type", SCE_SELECT_EDGE);
|
|
|
|
|
uiItemFullO_ptr(row,
|
|
|
|
|
ot,
|
|
|
|
|
"",
|
|
|
|
|
ICON_FACESEL,
|
2023-07-12 18:02:56 +02:00
|
|
|
nullptr,
|
2022-02-03 17:36:05 -06:00
|
|
|
WM_OP_INVOKE_DEFAULT,
|
2023-07-29 15:06:33 +10:00
|
|
|
(em->selectmode & SCE_SELECT_FACE) ? UI_ITEM_O_DEPRESS : UI_ITEM_NONE,
|
2022-02-03 17:36:05 -06:00
|
|
|
&op_ptr);
|
|
|
|
|
RNA_enum_set(&op_ptr, "type", SCE_SELECT_FACE);
|
2011-05-02 11:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
static void uiTemplatePaintModeSelection(uiLayout *layout, bContext *C)
|
2018-05-01 20:12:06 +02:00
|
|
|
{
|
2022-09-14 21:33:51 +02:00
|
|
|
const Scene *scene = CTX_data_scene(C);
|
2018-05-01 20:12:06 +02:00
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
2022-09-14 21:33:51 +02:00
|
|
|
BKE_view_layer_synced_ensure(scene, view_layer);
|
2022-09-01 10:00:53 +02:00
|
|
|
Object *ob = BKE_view_layer_active_object_get(view_layer);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-14 23:49:00 +02:00
|
|
|
/* Gizmos aren't used in paint modes */
|
2018-05-01 20:12:06 +02:00
|
|
|
if (!ELEM(ob->mode, OB_MODE_SCULPT, OB_MODE_PARTICLE_EDIT)) {
|
|
|
|
|
/* masks aren't used for sculpt and particle painting */
|
2025-01-24 16:45:32 +01:00
|
|
|
PointerRNA meshptr = RNA_pointer_create_discrete(
|
|
|
|
|
static_cast<ID *>(ob->data), &RNA_Mesh, ob->data);
|
2020-06-18 12:21:38 +10:00
|
|
|
if (ob->mode & OB_MODE_TEXTURE_PAINT) {
|
2018-05-01 20:12:06 +02:00
|
|
|
uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
uiLayout *row = uiLayoutRow(layout, true);
|
|
|
|
|
uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
|
2019-01-08 15:15:35 +11:00
|
|
|
uiItemR(row, &meshptr, "use_paint_mask_vertex", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
|
Fix #44834: Add bone selection icon next to face and vertex selection in weight paint mode
Currently, in weight paint mode, there is an icon for
face and vertex selection mode, but there isn't one
for the default mode where the user can select a bone
in any tool by alt clicking.
This lack of indication might lead to confusion for the users
when they are not able to select a bone by
alt clicking during weight painting.
By adding a bone selection icon when there is a pose
mode armature, we can communicate to the user that:
1. they can select a bone while the bone selection icon is active.
(when they are not in face or vertex selection mode)
2. they have forgot to select an armature when entering
weight paint mode by not showing the bone selection
icon at all when there is no pose mode armature.
When the bone selection icon is inactive,
the user can't select a bone.
(alt clicking selects face and vertex mode's respective element)
When no armature is selected when entering weight paint mode,
the bone selection icon doesn't show up indicating that the user
has forgot to select an armature.
(The user is also unable to select a bone by alt clicking.)
## Selection tool for bone selection mode
Currently, while selection tools exist for face and vertex
selection mode, one doesn't exist for the default mode
(bone selection mode). As the default mode will be getting
a clear indicator that it will function as a bone selection mode,
I added a selection tool entry for the bone selection mode.
Face and vertex selection modes has the shortcut 1 and 2,
so it seemed natural to give bone selection mode the shortcut of 3.
Pull Request: https://projects.blender.org/blender/blender/pulls/115409
2023-12-01 13:38:58 +01:00
|
|
|
|
|
|
|
|
/* Show the bone selection mode icon only if there is a pose mode armature */
|
|
|
|
|
Object *ob_armature = BKE_object_pose_armature_get(ob);
|
|
|
|
|
if (ob_armature) {
|
|
|
|
|
uiItemR(row, &meshptr, "use_paint_bone_selection", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
|
|
|
|
|
}
|
2018-05-01 20:12:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
void uiTemplateHeader3D_mode(uiLayout *layout, bContext *C)
|
2018-05-01 20:12:06 +02:00
|
|
|
{
|
2022-09-14 21:33:51 +02:00
|
|
|
const Scene *scene = CTX_data_scene(C);
|
2018-05-01 20:12:06 +02:00
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
2022-09-14 21:33:51 +02:00
|
|
|
BKE_view_layer_synced_ensure(scene, view_layer);
|
2022-09-01 10:00:53 +02:00
|
|
|
Object *ob = BKE_view_layer_active_object_get(view_layer);
|
2018-05-01 20:12:06 +02:00
|
|
|
Object *obedit = CTX_data_edit_object(C);
|
2024-10-07 18:21:28 +02:00
|
|
|
|
|
|
|
|
bool is_paint = (ob && ELEM(ob->mode,
|
|
|
|
|
OB_MODE_SCULPT,
|
|
|
|
|
OB_MODE_VERTEX_PAINT,
|
|
|
|
|
OB_MODE_WEIGHT_PAINT,
|
|
|
|
|
OB_MODE_TEXTURE_PAINT));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-01 20:12:06 +02:00
|
|
|
uiTemplateEditModeSelection(layout, C);
|
2023-07-12 18:02:56 +02:00
|
|
|
if ((obedit == nullptr) && is_paint) {
|
2018-05-01 20:12:06 +02:00
|
|
|
uiTemplatePaintModeSelection(layout, C);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-28 15:00:27 +11:00
|
|
|
|
|
|
|
|
/** \} */
|