[Bf-blender-cvs] [4fa55703dca] soc-2017-normal-tools: Fix critical issue with usage of unamed CD_PROP_INT layer.

Bastien Montagne noreply at git.blender.org
Tue Mar 6 16:14:45 CET 2018


Commit: 4fa55703dca64b3fab4ef8772c6c14a993867b98
Author: Bastien Montagne
Date:   Tue Mar 6 15:58:22 2018 +0100
Branches: soc-2017-normal-tools
https://developer.blender.org/rB4fa55703dca64b3fab4ef8772c6c14a993867b98

Fix critical issue with usage of unamed CD_PROP_INT layer.

Those types are generic, specific usages should always use named layers
with a specific 'id name'.

Also, make weightednormals modifier to show edited normals in 3DView in
edit mode.

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

M	source/blender/editors/mesh/editmesh_tools.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/modifiers/intern/MOD_weighted_normal.c

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

diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index d518b5e84ca..e70fd431a6a 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -7302,11 +7302,14 @@ static int edbm_mod_weighted_strength_exec(bContext *C, wmOperator *op)
 
 	BM_select_history_clear(bm);
 
-	int cd_prop_int_offset = CustomData_get_offset(&bm->pdata, CD_PROP_INT);
-	if (cd_prop_int_offset == -1) {
-		BM_data_layer_add(bm, &bm->pdata, CD_PROP_INT);
-		cd_prop_int_offset = CustomData_get_offset(&bm->pdata, CD_PROP_INT);
-	}
+	const char *layer_id = MOD_WEIGHTEDNORMALS_FACEWEIGHT_CDLAYER_ID;
+	int cd_prop_int_index = CustomData_get_named_layer_index(&bm->pdata, CD_PROP_INT, layer_id);
+	if (cd_prop_int_index == -1) {
+		BM_data_layer_add_named(bm, &bm->pdata, CD_PROP_INT, layer_id);
+		cd_prop_int_index = CustomData_get_named_layer_index(&bm->pdata, CD_PROP_INT, layer_id);
+	}
+	cd_prop_int_index -= CustomData_get_layer_index(&bm->pdata, CD_PROP_INT);
+	const int cd_prop_int_offset = CustomData_get_n_offset(&bm->pdata, CD_PROP_INT, cd_prop_int_index);
 
 	const int face_strength = scene->toolsettings->face_strength;
 	const bool set = RNA_boolean_get(op->ptr, "set");
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 6991d5edb6f..1602ac9aac3 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1629,6 +1629,9 @@ typedef struct WeightedNormalModifierData {
 	float thresh;
 } WeightedNormalModifierData;
 
+/* Name/id of the generic PROP_INT cdlayer storing face weights. */
+#define MOD_WEIGHTEDNORMALS_FACEWEIGHT_CDLAYER_ID "__mod_weightednormals_faceweight"
+
 /* WeightedNormalModifierData.mode */
 enum {
 	MOD_WEIGHTEDNORMAL_MODE_FACE = 0,
diff --git a/source/blender/modifiers/intern/MOD_weighted_normal.c b/source/blender/modifiers/intern/MOD_weighted_normal.c
index 2bed6eb6d8a..b4664b4aa9d 100644
--- a/source/blender/modifiers/intern/MOD_weighted_normal.c
+++ b/source/blender/modifiers/intern/MOD_weighted_normal.c
@@ -529,13 +529,13 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *dm,
 	}
 
 	short (*clnors)[2];
-
 	clnors = CustomData_duplicate_referenced_layer(&dm->loopData, CD_CUSTOMLOOPNORMAL, numLoops);
 	if (!clnors) {
 		DM_add_loop_layer(dm, CD_CUSTOMLOOPNORMAL, CD_CALLOC, NULL);
 		clnors = dm->getLoopDataArray(dm, CD_CUSTOMLOOPNORMAL);
 	}
-	int *strength = CustomData_get_layer(&dm->polyData, CD_PROP_INT);
+
+	int *strength = CustomData_get_layer_named(&dm->polyData, CD_PROP_INT, MOD_WEIGHTEDNORMALS_FACEWEIGHT_CDLAYER_ID);
 
 	modifier_get_vgroup(ob, dm, wnmd->defgrp_name, &dvert, &defgrp_index);
 
@@ -598,6 +598,7 @@ ModifierTypeInfo modifierType_WeightedNormal = {
 	/* structSize */        sizeof(WeightedNormalModifierData),
 	/* type */              eModifierTypeType_Constructive,
 	/* flags */             eModifierTypeFlag_AcceptsMesh |
+	                        eModifierTypeFlag_SupportsMapping |
 	                        eModifierTypeFlag_SupportsEditmode |
 	                        eModifierTypeFlag_EnableInEditmode,



More information about the Bf-blender-cvs mailing list