[Bf-blender-cvs] [9a9b1e98849] blender2.8: GP: Revert replace custom function by standard API

Antonioya noreply at git.blender.org
Tue Aug 28 08:20:54 CEST 2018


Commit: 9a9b1e98849131358041cf2bb83bf7b7c9828119
Author: Antonioya
Date:   Tue Aug 28 08:16:30 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB9a9b1e98849131358041cf2bb83bf7b7c9828119

GP: Revert replace custom function by standard API

Using custom api breaks material at object level

===================================================================

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/editors/gpencil/gpencil_add_monkey.c
M	source/blender/editors/gpencil/gpencil_add_stroke.c
M	source/blender/editors/gpencil/gpencil_brush.c
M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_fill.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
M	source/blender/makesrna/intern/rna_brush.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 443d3426868..0aa7a0de7e6 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -94,6 +94,7 @@ void BKE_gpencil_frame_delete_laststroke(struct bGPDlayer *gpl, struct bGPDframe
 /* materials */
 void BKE_gpencil_material_index_remove(struct bGPdata *gpd, int index);
 void BKE_gpencil_material_remap(struct bGPdata *gpd, const unsigned int *remap, unsigned int remap_len);
+int BKE_gpencil_get_material_index(struct Object *ob, struct Material *ma);
 
 /* statistics functions */
 void BKE_gpencil_stats_update(struct bGPdata *gpd);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 4f126e065d0..6d771148723 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1543,3 +1543,18 @@ void BKE_gpencil_stats_update(bGPdata *gpd)
 	}
 
 }
+
+/* get material index */
+int BKE_gpencil_get_material_index(Object *ob, Material *ma)
+{
+	short *totcol = give_totcolp(ob);
+	Material *read_ma = NULL;
+	for (short i = 0; i < *totcol; i++) {
+		read_ma = give_current_material(ob, i + 1);
+		if (ma == read_ma) {
+			return i + 1;
+		}
+	}
+
+	return 0;
+}
diff --git a/source/blender/editors/gpencil/gpencil_add_monkey.c b/source/blender/editors/gpencil/gpencil_add_monkey.c
index 0f19485b3f7..78286e3f672 100644
--- a/source/blender/editors/gpencil/gpencil_add_monkey.c
+++ b/source/blender/editors/gpencil/gpencil_add_monkey.c
@@ -72,7 +72,7 @@ static int gpencil_monkey_color(Main *bmain, Object *ob, const ColorTemplate *pc
 	copy_v4_v4(ma->gp_style->stroke_rgba, pct->line);
 	copy_v4_v4(ma->gp_style->fill_rgba, pct->fill);
 
-	return BKE_object_material_slot_find_index(ob, ma) - 1;
+	return BKE_gpencil_get_material_index(ob, ma) - 1;
 }
 
 /* ***************************************************************** */
diff --git a/source/blender/editors/gpencil/gpencil_add_stroke.c b/source/blender/editors/gpencil/gpencil_add_stroke.c
index c99c93d4ac7..310abbe60f1 100644
--- a/source/blender/editors/gpencil/gpencil_add_stroke.c
+++ b/source/blender/editors/gpencil/gpencil_add_stroke.c
@@ -72,7 +72,7 @@ static int gp_stroke_material(Main *bmain, Object *ob, const ColorTemplate *pct)
 	copy_v4_v4(ma->gp_style->stroke_rgba, pct->line);
 	copy_v4_v4(ma->gp_style->fill_rgba, pct->fill);
 
-	return BKE_object_material_slot_find_index(ob, ma) - 1;
+	return BKE_gpencil_get_material_index(ob, ma) - 1;
 }
 
 /* ***************************************************************** */
diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index b7fc911100f..6eff4d3687f 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -1066,8 +1066,8 @@ static void gp_brush_clone_add(bContext *C, tGP_BrushEditData *gso)
 
 			/* Fix color references */
 			Material *ma = BLI_ghash_lookup(data->new_colors, &new_stroke->mat_nr);
-			if ((ma) && (BKE_object_material_slot_find_index(ob, ma) > 0)) {
-				gps->mat_nr = BKE_object_material_slot_find_index(ob, ma) - 1;
+			if ((ma) && (BKE_gpencil_get_material_index(ob, ma) > 0)) {
+				gps->mat_nr = BKE_gpencil_get_material_index(ob, ma) - 1;
 				CLAMP_MIN(gps->mat_nr, 0);
 			}
 			else {
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 14c5d35c78a..84706966c60 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -1373,7 +1373,7 @@ static int gp_stroke_change_color_exec(bContext *C, wmOperator *op)
 		}
 	}
 	/* try to find slot */
-	int idx = BKE_object_material_slot_find_index(ob, ma) - 1;
+	int idx = BKE_gpencil_get_material_index(ob, ma) - 1;
 	if (idx <= 0) {
 		return OPERATOR_CANCELLED;
 	}
@@ -2123,7 +2123,7 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op)
 
 				for (short i = 0; i < *totcol; i++) {
 					Material *tmp_ma = give_current_material(ob_src, i + 1);
-					if (BKE_object_material_slot_find_index(ob_dst, tmp_ma) == 0) {
+					if (BKE_gpencil_get_material_index(ob_dst, tmp_ma) == 0) {
 						BKE_object_material_slot_add(bmain, ob_dst);
 						assign_material(bmain, ob_dst, tmp_ma, ob_dst->totcol, BKE_MAT_ASSIGN_USERPREF);
 					}
@@ -2163,7 +2163,7 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op)
 							/* reasign material. Look old material and try to find in dst */
 							ma_src = give_current_material(ob_src, gps->mat_nr + 1);
 							if (ma_src != NULL) {
-								idx = BKE_object_material_slot_find_index(ob_dst, ma_src);
+								idx = BKE_gpencil_get_material_index(ob_dst, ma_src);
 								if (idx > 0) {
 									gps->mat_nr = idx - 1;
 								}
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 49202149d31..df786b4e675 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -768,7 +768,7 @@ GHash *gp_copybuf_validate_colormap(bContext *C)
 		char *ma_name = BLI_ghashIterator_getValue(&gh_iter);
 		Material *ma = BLI_ghash_lookup(name_to_ma, ma_name);
 
-		if (ma != NULL && BKE_object_material_slot_find_index(ob, ma) == 0) {
+		if (ma != NULL && BKE_gpencil_get_material_index(ob, ma) == 0) {
 			BKE_object_material_slot_add(bmain, ob);
 			assign_material(bmain, ob, ma, ob->totcol, BKE_MAT_ASSIGN_USERPREF);
 		}
@@ -1022,8 +1022,8 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op)
 
 				/* Remap material */
 				Material *ma = BLI_ghash_lookup(new_colors, &new_stroke->mat_nr);
-				if ((ma) && (BKE_object_material_slot_find_index(ob, ma) > 0)) {
-					gps->mat_nr = BKE_object_material_slot_find_index(ob, ma) - 1;
+				if ((ma) && (BKE_gpencil_get_material_index(ob, ma) > 0)) {
+					gps->mat_nr = BKE_gpencil_get_material_index(ob, ma) - 1;
 					CLAMP_MIN(gps->mat_nr, 0);
 				}
 				else {
@@ -3239,7 +3239,7 @@ static int gp_stroke_separate_exec(bContext *C, wmOperator *op)
 
 							/* add duplicate materials */
 							ma = give_current_material(ob, gps->mat_nr + 1);
-							idx = BKE_object_material_slot_find_index(ob_dst, ma);
+							idx = BKE_gpencil_get_material_index(ob_dst, ma);
 							if (idx == 0) {
 
 								totadd++;
diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c
index 6d1c2c56d7b..09a21cbca1e 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -841,7 +841,7 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf)
 	gps->flag |= GP_STROKE_CYCLIC;
 	gps->flag |= GP_STROKE_3DSPACE;
 
-	gps->mat_nr = BKE_object_material_slot_find_index(tgpf->ob, tgpf->mat) - 1;
+	gps->mat_nr = BKE_gpencil_get_material_index(tgpf->ob, tgpf->mat) - 1;
 	if (gps->mat_nr < 0) {
 		BKE_object_material_slot_add(tgpf->bmain, tgpf->ob);
 		assign_material(tgpf->bmain, tgpf->ob, tgpf->mat, tgpf->ob->totcol, BKE_MAT_ASSIGN_USERPREF);
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 113950075fc..aa163e02cfe 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1164,7 +1164,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
 	}
 
 	/* Save material index */
-	gps->mat_nr = BKE_object_material_slot_find_index(p->ob, p->material) - 1;
+	gps->mat_nr = BKE_gpencil_get_material_index(p->ob, p->material) - 1;
 
 	/* calculate UVs along the stroke */
 	ED_gpencil_calc_stroke_uv(obact, gps);
@@ -1616,7 +1616,7 @@ static void gp_init_colors(tGPsdata *p)
 	}
 
 	/* check if the material is already on object material slots and add it if missing */
-	if (BKE_object_material_slot_find_index(p->ob, p->material) == 0) {
+	if (BKE_gpencil_get_material_index(p->ob, p->material) == 0) {
 		BKE_object_material_slot_add(p->bmain, p->ob);
 		assign_material(p->bmain, p->ob, ma, p->ob->totcol, BKE_MAT_ASSIGN_USERPREF);
 	}
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index 28c6f83522d..6fa7d0b7a81 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -177,7 +177,7 @@ static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi)
 	gps->flag |= GP_STROKE_CYCLIC;
 	gps->flag |= GP_STROKE_3DSPACE;
 
-	gps->mat_nr = BKE_object_material_slot_find_index(tgpi->ob, tgpi->mat) - 1;
+	gps->mat_nr = BKE_gpencil_get_material_index(tgpi->ob, tgpi->mat) - 1;
 
 	/* allocate memory for storage points, but keep empty */
 	gps->totpoints = 0;
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
index 5c2e5e89d0b..9ddc6a1e3e4 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
@@ -171,7 +171,7 @@ void gpencil_apply_modifier_material(
 			DEG_id_tag_update(&newmat->id, DEG_TAG_COPY_ON_WRITE);
 		}
 		/* reasign color index */
-		int idx = BKE_object_material_slot_find_index(ob, newmat);
+		int idx = BKE_gpencil_get_material_index(ob, newmat);
 		gps->mat_nr = idx - 1;
 	}
 	else {
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index bc5b1fa7f13..3df84a3a85b 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -171,7 +171,6 @@ static EnumPropertyItem rna_enum_gpencil_brush_icons_items[] = {
 #include "BKE_colorband.h"
 #include "BKE_brush.h"
 #include "BKE_icons.h"
-#include "BKE_material.h"
 #include "BKE_gpencil.h"
 #include "BKE_paint.h"
 
@@ -426,7 +425,7 @@ static void rna_Brush_material_update(bContext *C, PointerRNA *ptr)
 		BrushGpencilSettings *gpencil_settings = br->gpencil_settings;
 		if (gpencil_settings->material != NULL) {
 
-			index = BKE_object_material_slot_find_index(ob, gpencil_settings->material);
+			index = BKE_gpencil_get_material_index(ob, gpenc

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list