diff options
author | Dennis Ranish <Codec> | 2022-06-08 22:10:32 +0300 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2022-06-08 22:10:32 +0300 |
commit | 9c28f0eb37aebd6e5eae0763b008ef02d5ce081b (patch) | |
tree | 65bc5d816ffc13a30ebf9aa454dd6fee7f512ed1 /source/blender/editors | |
parent | f69c565a33ca58bb95a2bd22de0e211799508182 (diff) |
D14823: Adds operator to duplicate the active color attribute layer
Fixes T97706
Adds operator to duplicate the active color attribute layer.
Adds `"Color Attribute Specials"` menu to color attribute ui to access the `"geometry.color_attribute_duplicate"` operator.
Internally adds a function that duplicates a referenced CustomDataLayer
- `BKE_id_attribute_duplicate` mostly copies the existing `BKE_id_attribute_new`
- but gets the type and domain from the referenced layer
- and copies the data from the old layer into the new layer
Reviewed By: Joseph Eagar & Hans Goudey & Julien Kaspar
Differential Revision: https://developer.blender.org/D14823
Ref D14823
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/geometry/geometry_attributes.cc | 52 | ||||
-rw-r--r-- | source/blender/editors/geometry/geometry_intern.hh | 1 | ||||
-rw-r--r-- | source/blender/editors/geometry/geometry_ops.cc | 1 |
3 files changed, 54 insertions, 0 deletions
diff --git a/source/blender/editors/geometry/geometry_attributes.cc b/source/blender/editors/geometry/geometry_attributes.cc index 63059a49a9e..37ec7a61bcb 100644 --- a/source/blender/editors/geometry/geometry_attributes.cc +++ b/source/blender/editors/geometry/geometry_attributes.cc @@ -498,6 +498,7 @@ static bool geometry_color_attributes_remove_poll(bContext *C) return false; } + void GEOMETRY_OT_color_attribute_remove(wmOperatorType *ot) { /* identifiers */ @@ -513,6 +514,57 @@ void GEOMETRY_OT_color_attribute_remove(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } +static int geometry_color_attribute_duplicate_exec(bContext *C, wmOperator *op) +{ + Object *ob = ED_object_context(C); + ID *id = static_cast<ID *>(ob->data); + CustomDataLayer *layer = BKE_id_attributes_active_color_get(id); + + if (layer == nullptr) { + return OPERATOR_CANCELLED; + } + + CustomDataLayer *newLayer = BKE_id_attribute_duplicate(id, layer, op->reports); + + BKE_id_attributes_active_color_set(id, newLayer); + + DEG_id_tag_update(id, ID_RECALC_GEOMETRY); + WM_main_add_notifier(NC_GEOM | ND_DATA, id); + + return OPERATOR_FINISHED; +} + +static bool geometry_color_attributes_duplicate_poll(bContext *C) +{ + if (!geometry_attributes_poll(C)) { + return false; + } + + Object *ob = ED_object_context(C); + ID *data = ob ? static_cast<ID *>(ob->data) : nullptr; + + if (BKE_id_attributes_active_color_get(data) != nullptr) { + return true; + } + + return false; +} + +void GEOMETRY_OT_color_attribute_duplicate(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Duplicate Color Attribute"; + ot->description = "Duplicate color attribute"; + ot->idname = "GEOMETRY_OT_color_attribute_duplicate"; + + /* api callbacks */ + ot->exec = geometry_color_attribute_duplicate_exec; + ot->poll = geometry_color_attributes_duplicate_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + static void geometry_attribute_convert_ui(bContext *UNUSED(C), wmOperator *op) { uiLayout *layout = op->layout; diff --git a/source/blender/editors/geometry/geometry_intern.hh b/source/blender/editors/geometry/geometry_intern.hh index bbcb682d6bf..a1000a5d01f 100644 --- a/source/blender/editors/geometry/geometry_intern.hh +++ b/source/blender/editors/geometry/geometry_intern.hh @@ -17,6 +17,7 @@ void GEOMETRY_OT_attribute_remove(struct wmOperatorType *ot); void GEOMETRY_OT_color_attribute_add(struct wmOperatorType *ot); void GEOMETRY_OT_color_attribute_remove(struct wmOperatorType *ot); void GEOMETRY_OT_color_attribute_render_set(struct wmOperatorType *ot); +void GEOMETRY_OT_color_attribute_duplicate(struct wmOperatorType *ot); void GEOMETRY_OT_attribute_convert(struct wmOperatorType *ot); } // namespace blender::ed::geometry diff --git a/source/blender/editors/geometry/geometry_ops.cc b/source/blender/editors/geometry/geometry_ops.cc index 23f6e6f29f4..acac757ecf1 100644 --- a/source/blender/editors/geometry/geometry_ops.cc +++ b/source/blender/editors/geometry/geometry_ops.cc @@ -22,5 +22,6 @@ void ED_operatortypes_geometry(void) WM_operatortype_append(GEOMETRY_OT_color_attribute_add); WM_operatortype_append(GEOMETRY_OT_color_attribute_remove); WM_operatortype_append(GEOMETRY_OT_color_attribute_render_set); + WM_operatortype_append(GEOMETRY_OT_color_attribute_duplicate); WM_operatortype_append(GEOMETRY_OT_attribute_convert); } |