[Bf-blender-cvs] [0639de4ceba] greasepencil-object: WIP: Start the working in operators

Antonio Vazquez noreply at git.blender.org
Thu Apr 26 12:35:45 CEST 2018


Commit: 0639de4ceba0274ea4c41f3c1e67abf0bf51b929
Author: Antonio Vazquez
Date:   Tue Apr 24 17:38:15 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rB0639de4ceba0274ea4c41f3c1e67abf0bf51b929

WIP: Start the working in operators

- Delete Material->Strokes
- Move material in the list->Reasign Strokes

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenkernel/intern/material.c
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenloader/intern/versioning_280.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index fe8c31b2ea5..236adb3f1dc 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -92,6 +92,10 @@ void BKE_gpencil_make_local(struct Main *bmain, struct bGPdata *gpd, const bool
 
 void BKE_gpencil_frame_delete_laststroke(struct bGPDlayer *gpl, struct bGPDframe *gpf);
 
+/* 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);
+
 /* Utilities for creating and populating GP strokes */
 /* - Number of values defining each point in the built-in data 
  *   buffers for primitives (e.g. 2D Monkey) 
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 5d0ad7efda5..fef6344a557 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -2301,3 +2301,55 @@ float BKE_gpencil_multiframe_falloff_calc(bGPDframe *gpf, int actnum, int f_init
 	
 	return value;
 }
+
+/* remove strokes using a material */
+void BKE_gpencil_material_index_remove(bGPdata *gpd, int index)
+{
+	bGPDstroke *gps, *gpsn;
+
+		for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+			for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+				for (gps = gpf->strokes.first; gps; gps = gpsn) {
+					gpsn = gps->next;
+					if (gps->matindex == index) {
+						if (gps->points) {
+							BKE_gpencil_free_stroke_weights(gps);
+							MEM_freeN(gps->points);
+						}
+						if (gps->triangles) MEM_freeN(gps->triangles);
+						BLI_freelinkN(&gpf->strokes, gps);
+					}
+					else {
+						/* reassign strokes */
+						if (gps->matindex > index) {
+							gps->matindex--;
+						}
+					}
+				}
+			}
+		}
+		BKE_gpencil_batch_cache_dirty(gpd);
+}
+
+void BKE_gpencil_material_remap(struct bGPdata *gpd, const unsigned int *remap, unsigned int remap_len)
+{
+	const short remap_len_short = (short)remap_len;
+
+#define MAT_NR_REMAP(n) \
+	if (n < remap_len_short) { \
+		BLI_assert(n >= 0 && remap[n] < remap_len_short); \
+		n = remap[n]; \
+	} ((void)0)
+
+	for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+		for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+			for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+				/* reassign strokes */
+				MAT_NR_REMAP(gps->matindex);
+			}
+		}
+	}
+
+#undef MAT_NR_REMAP
+
+}
\ No newline at end of file
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index beb809ccd0a..e06cb082715 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -59,6 +59,7 @@
 #include "BKE_animsys.h"
 #include "BKE_displist.h"
 #include "BKE_global.h"
+#include "BKE_gpencil.h"
 #include "BKE_icons.h"
 #include "BKE_image.h"
 #include "BKE_library.h"
@@ -344,6 +345,9 @@ static void material_data_index_remove_id(ID *id, short index)
 		case ID_MB:
 			/* meta-elems don't have materials atm */
 			break;
+		case ID_GD:
+			BKE_gpencil_material_index_remove((bGPdata *)id, index);
+			break;
 		default:
 			break;
 	}
@@ -758,6 +762,9 @@ void BKE_material_remap_object(Object *ob, const unsigned int *remap)
 	else if (ELEM(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
 		BKE_curve_material_remap(ob->data, remap, ob->totcol);
 	}
+	if (ob->type == OB_GPENCIL) {
+		BKE_gpencil_material_remap(ob->data, remap, ob->totcol);
+	}
 	else {
 		/* add support for this object data! */
 		BLI_assert(matar == NULL);
@@ -955,7 +962,7 @@ bool BKE_object_material_slot_remove(Object *ob)
 	}
 
 	/* check indices from mesh */
-	if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT)) {
+	if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_GPENCIL)) {
 		material_data_index_remove_id((ID *)ob->data, actcol - 1);
 		if (ob->curve_cache) {
 			BKE_displist_free(&ob->curve_cache->disp);
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index e3c4ba17f66..1be9377a344 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1,3 +1,4 @@
+/*
 /*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index a466e6e8380..20dafc4dbe8 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -791,7 +791,7 @@ void do_versions_after_linking_280(Main *main)
 						for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
 							for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
 								if ((palette == gps->palette) && (STREQ(gps->colorname, palcolor->info))) {
-									gps->matindex = ob->totcol;
+									gps->matindex = ob->totcol - 1;
 								}
 							}
 						}



More information about the Bf-blender-cvs mailing list