[Bf-blender-cvs] [dbdd79fabe2] master: UV/VCol layers creation: add option to not init those new data.

Bastien Montagne noreply at git.blender.org
Tue Mar 5 21:48:52 CET 2019


Commit: dbdd79fabe2934de6184c0230f91b2e8af716a7b
Author: Bastien Montagne
Date:   Tue Mar 5 21:34:48 2019 +0100
Branches: master
https://developer.blender.org/rBdbdd79fabe2934de6184c0230f91b2e8af716a7b

UV/VCol layers creation: add option to not init those new data.

`ED_mesh_uv_texture_add()`/`ED_mesh_color_add()` would always either
copy data from current active one, or (for UVs), generate default
'valid' UVs for every face.

This commit adds an option to not do that, just keeping default values
from raw CDLayer creation. It is only used/exposed from RNA API
currently.

This is especially useful for importer add-ons, since some formats
support multiple layers of those kind, as well as 'partial' dataset not
explicitely defining values for all mesh items.

Preliminary step to fix T62224.

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

M	source/blender/editors/include/ED_mesh.h
M	source/blender/editors/mesh/mesh_data.c
M	source/blender/editors/physics/dynamicpaint_ops.c
M	source/blender/editors/uvedit/uvedit_unwrap_ops.c
M	source/blender/makesrna/intern/rna_mesh.c

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

diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h
index ae851febf2c..7318df8adab 100644
--- a/source/blender/editors/include/ED_mesh.h
+++ b/source/blender/editors/include/ED_mesh.h
@@ -316,14 +316,14 @@ void ED_mesh_calc_tessface(struct Mesh *mesh, bool free_mpoly);
 void ED_mesh_update(struct Mesh *mesh, struct bContext *C, bool calc_edges, bool calc_edges_loose, bool calc_tessface);
 
 void ED_mesh_uv_texture_ensure(struct Mesh *me, const char *name);
-int  ED_mesh_uv_texture_add(struct Mesh *me, const char *name, const bool active_set);
+int  ED_mesh_uv_texture_add(struct Mesh *me, const char *name, const bool active_set, const bool do_init);
 bool ED_mesh_uv_texture_remove_index(struct Mesh *me, const int n);
 bool ED_mesh_uv_texture_remove_active(struct Mesh *me);
 bool ED_mesh_uv_texture_remove_named(struct Mesh *me, const char *name);
 void ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me);
 void ED_mesh_uv_loop_reset_ex(struct Mesh *me, const int layernum);
 bool ED_mesh_color_ensure(struct Mesh *me, const char *name);
-int  ED_mesh_color_add(struct Mesh *me, const char *name, const bool active_set);
+int  ED_mesh_color_add(struct Mesh *me, const char *name, const bool active_set, const bool do_init);
 bool ED_mesh_color_remove_index(struct Mesh *me, const int n);
 bool ED_mesh_color_remove_active(struct Mesh *me);
 bool ED_mesh_color_remove_named(struct Mesh *me, const char *name);
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c
index a1c2f5e0121..ea64adbffa3 100644
--- a/source/blender/editors/mesh/mesh_data.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -250,7 +250,7 @@ void ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me)
 }
 
 /* note: keep in sync with ED_mesh_color_add */
-int ED_mesh_uv_texture_add(Mesh *me, const char *name, const bool active_set)
+int ED_mesh_uv_texture_add(Mesh *me, const char *name, const bool active_set, const bool do_init)
 {
 	BMEditMesh *em;
 	int layernum_dst;
@@ -267,7 +267,7 @@ int ED_mesh_uv_texture_add(Mesh *me, const char *name, const bool active_set)
 		/* CD_MLOOPUV */
 		BM_data_layer_add_named(em->bm, &em->bm->ldata, CD_MLOOPUV, name);
 		/* copy data from active UV */
-		if (layernum_dst) {
+		if (layernum_dst && do_init) {
 			const int layernum_src = CustomData_get_active_layer(&em->bm->ldata, CD_MLOOPUV);
 			BM_data_layer_copy(em->bm, &em->bm->ldata, CD_MLOOPUV, layernum_src, layernum_dst);
 
@@ -282,7 +282,7 @@ int ED_mesh_uv_texture_add(Mesh *me, const char *name, const bool active_set)
 		if (layernum_dst >= MAX_MTFACE)
 			return -1;
 
-		if (me->mloopuv) {
+		if (me->mloopuv && do_init) {
 			CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_DUPLICATE, me->mloopuv, me->totloop, name);
 			CustomData_add_layer_named(&me->fdata, CD_MTFACE, CD_DUPLICATE, me->mtface, me->totface, name);
 			is_init = true;
@@ -301,7 +301,7 @@ int ED_mesh_uv_texture_add(Mesh *me, const char *name, const bool active_set)
 	}
 
 	/* don't overwrite our copied coords */
-	if (is_init == false) {
+	if (!is_init && do_init) {
 		ED_mesh_uv_loop_reset_ex(me, layernum_dst);
 	}
 
@@ -321,12 +321,12 @@ void ED_mesh_uv_texture_ensure(struct Mesh *me, const char *name)
 
 		layernum_dst = CustomData_number_of_layers(&em->bm->ldata, CD_MLOOPUV);
 		if (layernum_dst == 0)
-			ED_mesh_uv_texture_add(me, name, true);
+			ED_mesh_uv_texture_add(me, name, true, true);
 	}
 	else {
 		layernum_dst = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
 		if (layernum_dst == 0)
-			ED_mesh_uv_texture_add(me, name, true);
+			ED_mesh_uv_texture_add(me, name, true, true);
 	}
 }
 
@@ -377,7 +377,7 @@ bool ED_mesh_uv_texture_remove_named(Mesh *me, const char *name)
 }
 
 /* note: keep in sync with ED_mesh_uv_texture_add */
-int ED_mesh_color_add(Mesh *me, const char *name, const bool active_set)
+int ED_mesh_color_add(Mesh *me, const char *name, const bool active_set, const bool do_init)
 {
 	BMEditMesh *em;
 	int layernum;
@@ -393,7 +393,7 @@ int ED_mesh_color_add(Mesh *me, const char *name, const bool active_set)
 		/* CD_MLOOPCOL */
 		BM_data_layer_add_named(em->bm, &em->bm->ldata, CD_MLOOPCOL, name);
 		/* copy data from active vertex color layer */
-		if (layernum) {
+		if (layernum && do_init) {
 			const int layernum_dst = CustomData_get_active_layer(&em->bm->ldata, CD_MLOOPCOL);
 			BM_data_layer_copy(em->bm, &em->bm->ldata, CD_MLOOPCOL, layernum_dst, layernum);
 		}
@@ -407,7 +407,7 @@ int ED_mesh_color_add(Mesh *me, const char *name, const bool active_set)
 			return -1;
 		}
 
-		if (me->mloopcol) {
+		if (me->mloopcol && do_init) {
 			CustomData_add_layer_named(&me->ldata, CD_MLOOPCOL, CD_DUPLICATE, me->mloopcol, me->totloop, name);
 			CustomData_add_layer_named(&me->fdata, CD_MCOL, CD_DUPLICATE, me->mcol, me->totface, name);
 		}
@@ -499,7 +499,7 @@ static int mesh_uv_texture_add_exec(bContext *C, wmOperator *UNUSED(op))
 	Object *ob = ED_object_context(C);
 	Mesh *me = ob->data;
 
-	if (ED_mesh_uv_texture_add(me, NULL, true) == -1)
+	if (ED_mesh_uv_texture_add(me, NULL, true, true) == -1)
 		return OPERATOR_CANCELLED;
 
 	if (ob->mode & OB_MODE_TEXTURE_PAINT) {
@@ -565,7 +565,7 @@ static int mesh_vertex_color_add_exec(bContext *C, wmOperator *UNUSED(op))
 	Object *ob = ED_object_context(C);
 	Mesh *me = ob->data;
 
-	if (ED_mesh_color_add(me, NULL, true) == -1)
+	if (ED_mesh_color_add(me, NULL, true, true) == -1)
 		return OPERATOR_CANCELLED;
 
 	return OPERATOR_FINISHED;
diff --git a/source/blender/editors/physics/dynamicpaint_ops.c b/source/blender/editors/physics/dynamicpaint_ops.c
index a4ea8df1d4f..a88d2089ea1 100644
--- a/source/blender/editors/physics/dynamicpaint_ops.c
+++ b/source/blender/editors/physics/dynamicpaint_ops.c
@@ -230,7 +230,7 @@ static int output_toggle_exec(bContext *C, wmOperator *op)
 		/* Vertex Color Layer */
 		if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
 			if (!exists)
-				ED_mesh_color_add(ob->data, name, true);
+				ED_mesh_color_add(ob->data, name, true, true);
 			else
 				ED_mesh_color_remove_named(ob->data, name);
 		}
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 1dc681e8ec1..19925c2fcd7 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -111,7 +111,7 @@ static bool ED_uvedit_ensure_uvs(bContext *C, Scene *UNUSED(scene), Object *obed
 		return 1;
 
 	if (em && em->bm->totface && !CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV))
-		ED_mesh_uv_texture_add(obedit->data, NULL, true);
+		ED_mesh_uv_texture_add(obedit->data, NULL, true, true);
 
 	if (!ED_uvedit_test(obedit))
 		return 0;
diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c
index 9494d0f49c6..c9a8da51e40 100644
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@ -1368,12 +1368,12 @@ static int rna_Mesh_tot_face_get(PointerRNA *ptr)
 	return me->edit_mesh ? me->edit_mesh->bm->totfacesel : 0;
 }
 
-static PointerRNA rna_Mesh_vertex_color_new(struct Mesh *me, const char *name)
+static PointerRNA rna_Mesh_vertex_color_new(struct Mesh *me, const char *name, const bool do_init)
 {
 	PointerRNA ptr;
 	CustomData *ldata;
 	CustomDataLayer *cdl = NULL;
-	int index = ED_mesh_color_add(me, name, false);
+	int index = ED_mesh_color_add(me, name, false, do_init);
 
 	if (index != -1) {
 		ldata = rna_mesh_ldata_helper(me);
@@ -1415,12 +1415,12 @@ DEFINE_CUSTOMDATA_PROPERTY_API(polygon, int, CD_PROP_INT, pdata, totpoly, MeshPo
 DEFINE_CUSTOMDATA_PROPERTY_API(polygon, string, CD_PROP_STR, pdata, totpoly, MeshPolygonStringPropertyLayer)
 #undef DEFINE_CUSTOMDATA_PROPERTY_API
 
-static PointerRNA rna_Mesh_uv_layers_new(struct Mesh *me, const char *name)
+static PointerRNA rna_Mesh_uv_layers_new(struct Mesh *me, const char *name, const bool do_init)
 {
 	PointerRNA ptr;
 	CustomData *ldata;
 	CustomDataLayer *cdl = NULL;
-	int index = ED_mesh_uv_texture_add(me, name, false);
+	int index = ED_mesh_uv_texture_add(me, name, false, do_init);
 
 	if (index != -1) {
 		ldata = rna_mesh_ldata_helper(me);
@@ -2213,6 +2213,8 @@ static void rna_def_loop_colors(BlenderRNA *brna, PropertyRNA *cprop)
 	func = RNA_def_function(srna, "new", "rna_Mesh_vertex_color_new");
 	RNA_def_function_ui_description(func, "Add a vertex color layer to Mesh");
 	RNA_def_string(func, "name", "Col", 0, "", "Vertex color name");
+	RNA_def_boolean(func, "do_init", true, "",
+	                "Whether new layer's data should be initialized by copying current active one");
 	parm = RNA_def_pointer(func, "layer", "MeshLoopColorLayer", "", "The newly created layer");
 	RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
 	RNA_def_function_return(func, parm);
@@ -2255,6 +2257,9 @@ static void rna_def_uv_layers(BlenderRNA *brna, PropertyRNA *cprop)
 	func = RNA_def_function(srna, "new", "rna_Mesh_uv_layers_new");
 	RNA_def_function_ui_description(func, "Add a UV map layer to Mesh");
 	RNA_def_string(func, "name", "UVMap", 0, "", "UV map name");
+	RNA_def_boolean(func, "do_init", true, "",
+	                "Whether new layer's data should be initialized by copying current active one, "
+	                "or if none is active, with a default UVmap");
 	parm = RNA_def_pointer(func, "layer", "MeshUVLoopLayer", "", "The newly created layer");
 	RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
 	RNA_def_function_return(func, parm);



More information about the Bf-blender-cvs mailing list