Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Vazquez <blendergit@gmail.com>2019-07-30 17:51:18 +0300
committerAntonio Vazquez <blendergit@gmail.com>2019-07-30 17:51:37 +0300
commit406e960327191b548f736382571ed55cff91bc2c (patch)
tree462efd87636aa449a930d0a7d4b813ad41f975dc /source/blender/editors/gpencil
parent77cc69d66ff0a3cd0cd05c8818b7977418054046 (diff)
Fix T67904: GPencil clone brush doesn't copy the right color and layer
When using the clone brush, the first time the brush worked, but the next time no. The reasons were two: 1) The strokes were copied to the active layer, but if there were more than one layer, the stroke must be copied to the original layer. 2) The materials were not assigned properly and the materials were set as the first slot in the list always. Now, the original layer name is used to try to find the same layer in destination. If the layer is missing, the active layer is used. For materials, the bug in the hash lookup is fixed and the material is assigned to the right slot.
Diffstat (limited to 'source/blender/editors/gpencil')
-rw-r--r--source/blender/editors/gpencil/gpencil_brush.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index c183091dbb1..d97207baed8 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -1050,10 +1050,8 @@ static void gp_brush_clone_add(bContext *C, tGP_BrushEditData *gso)
tGPSB_CloneBrushData *data = gso->customdata;
Object *ob = CTX_data_active_object(C);
- bGPDlayer *gpl = CTX_data_active_gpencil_layer(C);
+ bGPdata *gpd = (bGPdata *)ob->data;
Scene *scene = CTX_data_scene(C);
-
- bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_ADD_NEW);
bGPDstroke *gps;
float delta[3];
@@ -1072,6 +1070,18 @@ static void gp_brush_clone_add(bContext *C, tGP_BrushEditData *gso)
bGPDspoint *pt;
int i;
+ bGPDlayer *gpl = NULL;
+ /* Try to use original layer. */
+ if (gps->runtime.tmp_layerinfo != NULL) {
+ gpl = BLI_findstring(&gpd->layers, gps->runtime.tmp_layerinfo, offsetof(bGPDlayer, info));
+ }
+
+ /* if not available, use active layer. */
+ if (gpl == NULL) {
+ gpl = CTX_data_active_gpencil_layer(C);
+ }
+ bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_ADD_NEW);
+
/* Make a new stroke */
new_stroke = MEM_dupallocN(gps);
@@ -1086,10 +1096,10 @@ static void gp_brush_clone_add(bContext *C, tGP_BrushEditData *gso)
BLI_addtail(&gpf->strokes, new_stroke);
/* Fix color references */
- Material *ma = BLI_ghash_lookup(data->new_colors, &new_stroke->mat_nr);
- gps->mat_nr = BKE_gpencil_object_material_get_index(ob, ma);
- if (!ma || gps->mat_nr) {
- gps->mat_nr = 0;
+ Material *ma = BLI_ghash_lookup(data->new_colors, POINTER_FROM_INT(new_stroke->mat_nr));
+ new_stroke->mat_nr = BKE_gpencil_object_material_get_index(ob, ma);
+ if (!ma || new_stroke->mat_nr < 0) {
+ new_stroke->mat_nr = 0;
}
/* Adjust all the stroke's points, so that the strokes
* get pasted relative to where the cursor is now