Tool System: initial support for UV-sculpt
This currently conflicts with the UV-sculpt toggle being manually set, ideally this would work more like other paint modes in Blender.
This commit is contained in:
parent
c15439bcdc
commit
143ece7199
|
@ -1190,6 +1190,15 @@ class _defs_weight_paint:
|
|||
|
||||
class _defs_image_generic:
|
||||
|
||||
@staticmethod
|
||||
def poll_uvedit(context):
|
||||
ob = context.edit_object
|
||||
if ob is not None:
|
||||
data = ob.data
|
||||
if data is not None:
|
||||
return bool(getattr(data, "uv_layers", False))
|
||||
return False
|
||||
|
||||
@ToolDef.from_fn
|
||||
def cursor():
|
||||
return dict(
|
||||
|
@ -1282,6 +1291,18 @@ class _defs_image_uv_select:
|
|||
)
|
||||
|
||||
|
||||
class _defs_image_uv_sculpt:
|
||||
|
||||
@staticmethod
|
||||
def generate_from_brushes(context):
|
||||
return generate_from_enum_ex(
|
||||
context,
|
||||
icon_prefix="brush.uv_sculpt.",
|
||||
data=context.tool_settings,
|
||||
attr="uv_sculpt_tool",
|
||||
)
|
||||
|
||||
|
||||
class _defs_gpencil_paint:
|
||||
@staticmethod
|
||||
def draw_color_selector(context, layout):
|
||||
|
@ -1772,6 +1793,12 @@ class IMAGE_PT_tools_active(ToolSelectPanelHelper, Panel):
|
|||
*_tools_transform,
|
||||
None,
|
||||
*_tools_annotate,
|
||||
None,
|
||||
lambda context: (
|
||||
_defs_image_uv_sculpt.generate_from_brushes(context)
|
||||
if _defs_image_generic.poll_uvedit(context)
|
||||
else ()
|
||||
),
|
||||
],
|
||||
'MASK': [
|
||||
None,
|
||||
|
|
|
@ -90,7 +90,10 @@ static void rna_WorkspaceTool_refresh_from_context(
|
|||
if (ob == NULL) {
|
||||
/* pass */
|
||||
}
|
||||
else if (ob->mode & OB_MODE_PARTICLE_EDIT) {
|
||||
else if ((tref->space_type == SPACE_VIEW3D) &&
|
||||
(tref->mode == CTX_MODE_PARTICLE) &&
|
||||
(ob->mode & OB_MODE_PARTICLE_EDIT))
|
||||
{
|
||||
const EnumPropertyItem *items = rna_enum_particle_edit_hair_brush_items;
|
||||
const int i = RNA_enum_from_value(items, ts->particle.brushtype);
|
||||
const EnumPropertyItem *item = &items[i];
|
||||
|
@ -99,6 +102,18 @@ static void rna_WorkspaceTool_refresh_from_context(
|
|||
STRNCPY(tref->idname, item->name);
|
||||
}
|
||||
}
|
||||
else if ((tref->space_type == SPACE_IMAGE) &&
|
||||
(tref->mode == SI_MODE_VIEW) &&
|
||||
(ob->mode & OB_MODE_EDIT))
|
||||
{
|
||||
const EnumPropertyItem *items = rna_enum_uv_sculpt_tool_items;
|
||||
const int i = RNA_enum_from_value(items, ts->uv_sculpt_tool);
|
||||
const EnumPropertyItem *item = &items[i];
|
||||
if (!STREQ(tref_rt->data_block, item->identifier)) {
|
||||
STRNCPY(tref_rt->data_block, item->identifier);
|
||||
STRNCPY(tref->idname, item->name);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Paint *paint = BKE_paint_get_active(scene, view_layer);
|
||||
if (paint) {
|
||||
|
|
|
@ -169,6 +169,14 @@ void WM_toolsystem_unlink(bContext *C, WorkSpace *workspace, const bToolKey *tke
|
|||
}
|
||||
}
|
||||
|
||||
static void toolsystem_ref_link__refresh_image_uv_sculpt(bContext *C, Scene *scene)
|
||||
{
|
||||
PointerRNA ptr;
|
||||
RNA_pointer_create(&scene->id, &RNA_ToolSettings, scene->toolsettings, &ptr);
|
||||
PropertyRNA *prop = RNA_struct_find_property(&ptr, "use_uv_sculpt");
|
||||
RNA_property_update(C, &ptr, prop);
|
||||
}
|
||||
|
||||
static void toolsystem_ref_link(bContext *C, WorkSpace *workspace, bToolRef *tref)
|
||||
{
|
||||
bToolRef_Runtime *tref_rt = tref->runtime;
|
||||
|
@ -205,6 +213,30 @@ static void toolsystem_ref_link(bContext *C, WorkSpace *workspace, bToolRef *tre
|
|||
}
|
||||
}
|
||||
}
|
||||
if ((tref->space_type == SPACE_IMAGE) &&
|
||||
(tref->mode == SI_MODE_VIEW))
|
||||
{
|
||||
/* Note that switching uv-sculpt boolean is a hack at the moment.
|
||||
* It would be best to make this either an operator or a higher level mode (like mesh-object sculpt mode). */
|
||||
const EnumPropertyItem *items = rna_enum_uv_sculpt_tool_items;
|
||||
const int i = RNA_enum_from_identifier(items, tref_rt->data_block);
|
||||
if (i != -1) {
|
||||
const int value = items[i].value;
|
||||
wmWindowManager *wm = bmain->wm.first;
|
||||
for (wmWindow *win = wm->windows.first; win; win = win->next) {
|
||||
if (workspace == WM_window_get_active_workspace(win)) {
|
||||
Scene *scene = WM_window_get_active_scene(win);
|
||||
ToolSettings *ts = scene->toolsettings;
|
||||
ts->uv_sculpt_tool = value;
|
||||
|
||||
if (ts->use_uv_sculpt == false) {
|
||||
ts->use_uv_sculpt = true;
|
||||
toolsystem_ref_link__refresh_image_uv_sculpt(C, scene);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
struct Brush *brush = (struct Brush *)BKE_libblock_find_name(bmain, ID_BR, tref_rt->data_block);
|
||||
if (brush) {
|
||||
|
@ -224,6 +256,25 @@ static void toolsystem_ref_link(bContext *C, WorkSpace *workspace, bToolRef *tre
|
|||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* XXX, this part is weak, disables uv_sculpt when non uv-tool set. */
|
||||
if ((tref->space_type == SPACE_IMAGE) &&
|
||||
(tref->mode == SI_MODE_VIEW))
|
||||
{
|
||||
Main *bmain = CTX_data_main(C);
|
||||
wmWindowManager *wm = bmain->wm.first;
|
||||
for (wmWindow *win = wm->windows.first; win; win = win->next) {
|
||||
if (workspace == WM_window_get_active_workspace(win)) {
|
||||
Scene *scene = WM_window_get_active_scene(win);
|
||||
ToolSettings *ts = scene->toolsettings;
|
||||
if (ts->use_uv_sculpt == true) {
|
||||
ts->use_uv_sculpt = false;
|
||||
toolsystem_ref_link__refresh_image_uv_sculpt(C, scene);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void toolsystem_refresh_ref(bContext *C, WorkSpace *workspace, bToolRef *tref)
|
||||
|
|
Loading…
Reference in New Issue