[Bf-blender-cvs] [3800be695bc] blender2.8: Modifier stack: move vgroup editing modifiers to new Mesh-based system.

Bastien Montagne noreply at git.blender.org
Mon May 7 18:18:20 CEST 2018


Commit: 3800be695bc19dcbefc23fe7b157f104b1efb8dc
Author: Bastien Montagne
Date:   Mon May 7 18:15:27 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB3800be695bc19dcbefc23fe7b157f104b1efb8dc

Modifier stack: move vgroup editing modifiers to new Mesh-based system.

Some notes here:
* Proximity with non-mesh objects (like curve, see TEST_2 scene in
weightvg testfile) are not working currently. This is known TODO of COW
depsgraph project.
* Proximity modifier is slower, due to some other TODO pending on
BVHTree creation/caching for Mesh.

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

M	source/blender/modifiers/intern/MOD_weightvg_util.c
M	source/blender/modifiers/intern/MOD_weightvg_util.h
M	source/blender/modifiers/intern/MOD_weightvgedit.c
M	source/blender/modifiers/intern/MOD_weightvgmix.c
M	source/blender/modifiers/intern/MOD_weightvgproximity.c

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

diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.c b/source/blender/modifiers/intern/MOD_weightvg_util.c
index 416f2964d6e..bb8ccb8899e 100644
--- a/source/blender/modifiers/intern/MOD_weightvg_util.c
+++ b/source/blender/modifiers/intern/MOD_weightvg_util.c
@@ -34,13 +34,14 @@
 #include "BLI_utildefines.h"
 
 #include "DNA_color_types.h"      /* CurveMapping. */
+#include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_modifier_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 
-#include "BKE_cdderivedmesh.h"
 #include "BKE_colortools.h"       /* CurveMapping. */
+#include "BKE_customdata.h"
 #include "BKE_deform.h"
 #include "BKE_modifier.h"
 #include "BKE_texture.h"          /* Texture masking. */
@@ -114,9 +115,9 @@ void weightvg_do_map(int num, float *new_w, short falloff_type, CurveMapping *cm
  * vertex index (in case the weight tables do not cover the whole vertices...).
  * XXX The standard "factor" value is assumed in [0.0, 1.0] range. Else, weird results might appear.
  */
-void weightvg_do_mask(int num, const int *indices, float *org_w, const float *new_w,
-                      Object *ob, DerivedMesh *dm, float fact, const char defgrp_name[MAX_VGROUP_NAME],
-                      Scene *scene, Tex *texture, int tex_use_channel, int tex_mapping,
+void weightvg_do_mask(const int num, const int *indices, float *org_w, const float *new_w,
+                      Object *ob, Mesh *mesh, const float fact, const char defgrp_name[MAX_VGROUP_NAME],
+                      Scene *scene, Tex *texture, const int tex_use_channel, const int tex_mapping,
                       Object *tex_map_object, const char *tex_uvlayer_name)
 {
 	int ref_didx;
@@ -131,8 +132,7 @@ void weightvg_do_mask(int num, const int *indices, float *org_w, const float *ne
 		float (*tex_co)[3];
 		/* See mapping note below... */
 		MappingInfoModifierData t_map;
-		float (*v_co)[3];
-		int numVerts = dm->getNumVerts(dm);
+		const int numVerts = mesh->totvert;
 
 		/* Use new generic get_texture_coords, but do not modify our DNA struct for it...
 		 * XXX Why use a ModifierData stuff here ? Why not a simple, generic struct for parameters ?
@@ -143,11 +143,9 @@ void weightvg_do_mask(int num, const int *indices, float *org_w, const float *ne
 		t_map.map_object = tex_map_object;
 		BLI_strncpy(t_map.uvlayer_name, tex_uvlayer_name, sizeof(t_map.uvlayer_name));
 		t_map.texmapping = tex_mapping;
-		v_co = MEM_malloc_arrayN(numVerts, sizeof(*v_co), "WeightVG Modifier, TEX mode, v_co");
-		dm->getVertCos(dm, v_co);
+
 		tex_co = MEM_calloc_arrayN(numVerts, sizeof(*tex_co), "WeightVG Modifier, TEX mode, tex_co");
-		get_texture_coords(&t_map, ob, dm, v_co, tex_co, num);
-		MEM_freeN(v_co);
+		get_texture_coords_mesh(&t_map, ob, mesh, tex_co);
 
 		modifier_init_texture(scene, texture);
 
@@ -209,9 +207,11 @@ void weightvg_do_mask(int num, const int *indices, float *org_w, const float *ne
 
 		/* Proceed only if vgroup is valid, else use constant factor. */
 		/* Get actual dverts (ie vertex group data). */
-		dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
+		dvert = CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT);
 		/* Proceed only if vgroup is valid, else assume factor = O. */
-		if (dvert == NULL) return;
+		if (dvert == NULL) {
+			return;
+		}
 
 		/* For each weight (vertex), make the mix between org and new weights. */
 		for (i = 0; i < num; i++) {
diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.h b/source/blender/modifiers/intern/MOD_weightvg_util.h
index 03bcbb6eb97..73552e50d0f 100644
--- a/source/blender/modifiers/intern/MOD_weightvg_util.h
+++ b/source/blender/modifiers/intern/MOD_weightvg_util.h
@@ -32,7 +32,9 @@
 #define __MOD_WEIGHTVG_UTIL_H__
 
 struct CurveMapping;
-struct DerivedMesh;
+struct MDeformVert;
+struct MDeformWeight;
+struct Mesh;
 struct Object;
 struct Tex;
 struct Scene;
@@ -70,16 +72,16 @@ void weightvg_do_map(int num, float *new_w, short mode, struct CurveMapping *cma
  * vertex index (in case the weight tables do not cover the whole vertices...).
  * XXX The standard "factor" value is assumed in [0.0, 1.0] range. Else, weird results might appear.
  */
-void weightvg_do_mask(int num, const int *indices, float *org_w, const float *new_w, Object *ob,
-                      DerivedMesh *dm, float fact, const char defgrp_name[MAX_VGROUP_NAME],
-                      struct Scene *scene, Tex *texture, int tex_use_channel, int tex_mapping,
+void weightvg_do_mask(const int num, const int *indices, float *org_w, const float *new_w, Object *ob,
+                      struct Mesh *mesh, const float fact, const char defgrp_name[MAX_VGROUP_NAME],
+                      struct Scene *scene, Tex *texture, const int tex_use_channel, const int tex_mapping,
                       Object *tex_map_object, const char *tex_uvlayer_name);
 
 /* Applies weights to given vgroup (defgroup), and optionally add/remove vertices from the group.
  * If indices is not NULL, it must be a table of same length as weights, mapping to the real
  * vertex index (in case the weight table does not cover the whole vertices...).
  */
-void weightvg_update_vg(MDeformVert *dvert, int defgrp_idx, MDeformWeight **dws, int num,
+void weightvg_update_vg(struct MDeformVert *dvert, int defgrp_idx, struct MDeformWeight **dws, int num,
                         const int *indices, const float *weights, const bool do_add,
                         const float add_thresh, const bool do_rem, const float rem_thresh);
 
diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.c b/source/blender/modifiers/intern/MOD_weightvgedit.c
index 1a9651909dd..cc000cbee09 100644
--- a/source/blender/modifiers/intern/MOD_weightvgedit.c
+++ b/source/blender/modifiers/intern/MOD_weightvgedit.c
@@ -34,11 +34,11 @@
 #include "BLI_rand.h"
 
 #include "DNA_color_types.h"      /* CurveMapping. */
+#include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_modifier_types.h"
 #include "DNA_object_types.h"
 
-#include "BKE_cdderivedmesh.h"
 #include "BKE_colortools.h"       /* CurveMapping. */
 #include "BKE_deform.h"
 #include "BKE_library.h"
@@ -154,19 +154,18 @@ static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams))
 	return (wmd->defgrp_name[0] == '\0');
 }
 
-static DerivedMesh *applyModifier(ModifierData *md,
+static Mesh *applyModifier(ModifierData *md,
                                   const ModifierEvalContext *ctx,
-                                  DerivedMesh *derivedData)
+                                  Mesh *mesh)
 {
 	WeightVGEditModifierData *wmd = (WeightVGEditModifierData *) md;
-	DerivedMesh *dm = derivedData;
+
 	MDeformVert *dvert = NULL;
 	MDeformWeight **dw = NULL;
 	float *org_w; /* Array original weights. */
 	float *new_w; /* Array new weights. */
-	int numVerts;
-	int defgrp_index;
 	int i;
+
 	/* Flags. */
 	const bool do_add  = (wmd->edit_flags & MOD_WVG_EDIT_ADD2VG) != 0;
 	const bool do_rem  = (wmd->edit_flags & MOD_WVG_EDIT_REMFVG) != 0;
@@ -176,30 +175,50 @@ static DerivedMesh *applyModifier(ModifierData *md,
 #endif
 
 	/* Get number of verts. */
-	numVerts = dm->getNumVerts(dm);
+	const int numVerts = mesh->totvert;
 
 	/* Check if we can just return the original mesh.
 	 * Must have verts and therefore verts assigned to vgroups to do anything useful!
 	 */
-	if ((numVerts == 0) || BLI_listbase_is_empty(&ctx->object->defbase))
-		return dm;
+	if ((numVerts == 0) || BLI_listbase_is_empty(&ctx->object->defbase)) {
+		return mesh;
+	}
 
 	/* Get vgroup idx from its name. */
-	defgrp_index = defgroup_name_index(ctx->object, wmd->defgrp_name);
-	if (defgrp_index == -1)
-		return dm;
+	const int defgrp_index = defgroup_name_index(ctx->object, wmd->defgrp_name);
+	if (defgrp_index == -1) {
+		return mesh;
+	}
 
-	dvert = CustomData_duplicate_referenced_layer(&dm->vertData, CD_MDEFORMVERT, numVerts);
+	const bool has_mdef = CustomData_has_layer(&mesh->vdata, CD_MDEFORMVERT);
 	/* If no vertices were ever added to an object's vgroup, dvert might be NULL. */
-	if (!dvert) {
+	if (!has_mdef) {
 		/* If this modifier is not allowed to add vertices, just return. */
-		if (!do_add)
-			return dm;
-		/* Else, add a valid data layer! */
-		dvert = CustomData_add_layer(&dm->vertData, CD_MDEFORMVERT, CD_CALLOC, NULL, numVerts);
-		/* Ultimate security check. */
-		if (!dvert)
-			return dm;
+		if (!do_add) {
+			return mesh;
+		}
+	}
+
+	Mesh *result;
+	BKE_id_copy_ex(
+	            NULL, &mesh->id, (ID **)&result,
+	            LIB_ID_CREATE_NO_MAIN |
+	            LIB_ID_CREATE_NO_USER_REFCOUNT |
+	            LIB_ID_CREATE_NO_DEG_TAG|
+	            LIB_ID_COPY_NO_PREVIEW,
+	            false);
+
+	if (has_mdef) {
+		dvert = CustomData_get_layer(&result->vdata, CD_MDEFORMVERT);
+	}
+	else {
+		/* Add a valid data layer! */
+		dvert = CustomData_add_layer(&result->vdata, CD_MDEFORMVERT, CD_CALLOC, NULL, numVerts);
+	}
+	/* Ultimate security check. */
+	if (!dvert) {
+		BKE_id_free(NULL, result);
+		return mesh;
 	}
 
 	/* Get org weights, assuming 0.0 for vertices not in given vgroup. */
@@ -220,17 +239,19 @@ static DerivedMesh *applyModifier(ModifierData *md,
 	if (wmd->falloff_type != MOD_WVG_MAPPING_NONE) {
 		RNG *rng = NULL;
 
-		if (wmd->falloff_type == MOD_WVG_MAPPING_RANDOM)
+		if (wmd->falloff_type == MOD_WVG_MAPPING_RANDOM) {
 			rng = BLI_rng_new_srandom(BLI_ghashutil_strhash(ctx->object->id.name + 2));
+		}
 
 		weightvg_do_map(numVerts, new_w, wmd->falloff_type, wmd->cmap_curve, rng);
 
-		if (rng)
+		if (rng) {
 			BLI_rng_free(rng);
+		}
 	}
 
 	/* Do masking. */
-	weightvg_do_mask(numVerts, NULL, org_w, new_w, ctx->object, dm, wmd->mask_constant,
+	weightvg_do_mask(numVerts, NULL, org_w, new_w, ctx->object, result, wmd->mask_constant,
 	                 wmd->mask_defgrp_name, wmd->modifier.scene, wmd->mask_texture,
 	                 wmd->mask_tex_use_channel, wmd->mask_tex_mapping,
 	                 wmd->mask_tex_map_obj, wmd->mask_tex_uvlayer_name);
@@ -251,7 +272,7 @@ static DerivedMesh *applyModifier(ModifierData *md,
 	MEM_freeN(dw);
 
 	/* Return the vgroup-modified mesh. */
-	return dm;
+	return result;
 }
 
 
@@ -271,14 +292,14 @@ ModifierTypeInfo modifierType_WeightVG

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list