[Bf-blender-cvs] [2dfd53e] temp_depsgraph_split_ubereval: Moved code for modifier evaluation out of DerivedMesh.c.

Lukas Tönne noreply at git.blender.org
Thu Apr 21 10:01:46 CEST 2016


Commit: 2dfd53e8e94b79ac7ba3ca45b5eae605bb361813
Author: Lukas Tönne
Date:   Thu Apr 21 09:34:02 2016 +0200
Branches: temp_depsgraph_split_ubereval
https://developer.blender.org/rB2dfd53e8e94b79ac7ba3ca45b5eae605bb361813

Moved code for modifier evaluation out of DerivedMesh.c.

These files contained a confusing mix of DM code (for manipulating DMs
and various utility functions relating to these types), and the code
for evaluating object modifier stacks. These are two very distinct
areas and putting them in a single huge file doesn't promote code
clarity at all.

This commit only moves code, but does not alter any of it. This is
important for log continuity, so history of specific functions can be
clearly traced back!

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

M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/DerivedMesh.c
A	source/blender/blenkernel/intern/modifier_calc.c

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

diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 7311f33..1c31df5 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -133,6 +133,7 @@ set(SRC
 	intern/mesh_validate.c
 	intern/modifier.c
 	intern/modifiers_bmesh.c
+	intern/modifier_calc.c
 	intern/movieclip.c
 	intern/multires.c
 	intern/nla.c
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 411d6ee..a58f541 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -29,73 +29,32 @@
  *  \ingroup bke
  */
 
-
-#include <string.h>
-#include <limits.h>
-
 #include "MEM_guardedalloc.h"
 
-#include "DNA_cloth_types.h"
 #include "DNA_key_types.h"
 #include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
-#include "DNA_scene_types.h"
 
 #include "BLI_array.h"
 #include "BLI_blenlib.h"
-#include "BLI_bitmap.h"
 #include "BLI_math.h"
-#include "BLI_utildefines.h"
-#include "BLI_linklist.h"
 
 #include "BKE_cdderivedmesh.h"
-#include "BKE_depsgraph.h"
-#include "BKE_editmesh.h"
 #include "BKE_key.h"
 #include "BKE_library.h"
 #include "BKE_material.h"
-#include "BKE_modifier.h"
 #include "BKE_mesh.h"
 #include "BKE_mesh_mapping.h"
 #include "BKE_object.h"
-#include "BKE_object_deform.h"
-#include "BKE_paint.h"
-#include "BKE_texture.h"
-#include "BKE_multires.h"
-#include "BKE_bvhutils.h"
-#include "BKE_deform.h"
 #include "BKE_global.h" /* For debug flag, DM_update_tessface_data() func. */
 
-#ifdef WITH_GAMEENGINE
-#include "BKE_navmesh_conversion.h"
-static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm);
-#endif
-
-#include "BLI_sys_types.h" /* for intptr_t support */
-
 #include "GPU_buffers.h"
 #include "GPU_glew.h"
 #include "GPU_shader.h"
 
-#ifdef WITH_OPENSUBDIV
-#  include "DNA_userdef_types.h"
-#endif
-
-/* very slow! enable for testing only! */
-//#define USE_MODIFIER_VALIDATE
-
-#ifdef USE_MODIFIER_VALIDATE
-#  define ASSERT_IS_VALID_DM(dm) (BLI_assert((dm == NULL) || (DM_is_valid(dm) == true)))
-#else
-#  define ASSERT_IS_VALID_DM(dm)
-#endif
-
-static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *ob);
 static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape_uid);
 
-
 /* -------------------------------------------------------------------- */
 
 static MVert *dm_getVertArray(DerivedMesh *dm)
@@ -433,12 +392,6 @@ void DM_ensure_normals(DerivedMesh *dm)
 	BLI_assert((dm->dirty & DM_DIRTY_NORMALS) == 0);
 }
 
-static void DM_calc_loop_normals(DerivedMesh *dm, const bool use_split_normals, float split_angle)
-{
-	dm->calcLoopNormals(dm, use_split_normals, split_angle);
-	dm->dirty |= DM_DIRTY_TESS_CDLAYERS;
-}
-
 /* note: until all modifiers can take MPoly's as input,
  * use this at the start of modifiers  */
 void DM_ensure_tessface(DerivedMesh *dm)
@@ -1104,479 +1057,6 @@ void DM_interp_poly_data(
 	                  weights, NULL, count, dest_index);
 }
 
-DerivedMesh *mesh_create_derived(Mesh *me, float (*vertCos)[3])
-{
-	DerivedMesh *dm = CDDM_from_mesh(me);
-	
-	if (!dm)
-		return NULL;
-	
-	if (vertCos) {
-		CDDM_apply_vert_coords(dm, vertCos);
-	}
-
-	return dm;
-}
-
-DerivedMesh *mesh_create_derived_for_modifier(
-        Scene *scene, Object *ob,
-        ModifierData *md, int build_shapekey_layers)
-{
-	Mesh *me = ob->data;
-	const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
-	DerivedMesh *dm;
-	KeyBlock *kb;
-
-	md->scene = scene;
-	
-	if (!(md->mode & eModifierMode_Realtime)) {
-		return NULL;
-	}
-
-	if (mti->isDisabled && mti->isDisabled(md, 0)) {
-		return NULL;
-	}
-	
-	if (build_shapekey_layers && me->key && (kb = BLI_findlink(&me->key->block, ob->shapenr - 1))) {
-		BKE_keyblock_convert_to_mesh(kb, me);
-	}
-	
-	if (mti->type == eModifierTypeType_OnlyDeform) {
-		int numVerts;
-		float (*deformedVerts)[3] = BKE_mesh_vertexCos_get(me, &numVerts);
-
-		modwrap_deformVerts(md, ob, NULL, deformedVerts, numVerts, 0);
-		dm = mesh_create_derived(me, deformedVerts);
-
-		if (build_shapekey_layers)
-			add_shapekey_layers(dm, me, ob);
-		
-		MEM_freeN(deformedVerts);
-	}
-	else {
-		DerivedMesh *tdm = mesh_create_derived(me, NULL);
-
-		if (build_shapekey_layers)
-			add_shapekey_layers(tdm, me, ob);
-		
-		dm = modwrap_applyModifier(md, ob, tdm, 0);
-		ASSERT_IS_VALID_DM(dm);
-
-		if (tdm != dm) tdm->release(tdm);
-	}
-
-	return dm;
-}
-
-static float (*get_editbmesh_orco_verts(BMEditMesh *em))[3]
-{
-	BMIter iter;
-	BMVert *eve;
-	float (*orco)[3];
-	int i;
-
-	/* these may not really be the orco's, but it's only for preview.
-	 * could be solver better once, but isn't simple */
-	
-	orco = MEM_mallocN(sizeof(float) * 3 * em->bm->totvert, "BMEditMesh Orco");
-
-	BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) {
-		copy_v3_v3(orco[i], eve->co);
-	}
-	
-	return orco;
-}
-
-/* orco custom data layer */
-static float (*get_orco_coords_dm(Object *ob, BMEditMesh *em, int layer, int *free))[3]
-{
-	*free = 0;
-
-	if (layer == CD_ORCO) {
-		/* get original coordinates */
-		*free = 1;
-
-		if (em)
-			return get_editbmesh_orco_verts(em);
-		else
-			return BKE_mesh_orco_verts_get(ob);
-	}
-	else if (layer == CD_CLOTH_ORCO) {
-		/* apply shape key for cloth, this should really be solved
-		 * by a more flexible customdata system, but not simple */
-		if (!em) {
-			ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
-			KeyBlock *kb = BKE_keyblock_from_key(BKE_key_from_object(ob), clmd->sim_parms->shapekey_rest);
-
-			if (kb && kb->data) {
-				return kb->data;
-			}
-		}
-
-		return NULL;
-	}
-
-	return NULL;
-}
-
-static DerivedMesh *create_orco_dm(Object *ob, Mesh *me, BMEditMesh *em, int layer)
-{
-	DerivedMesh *dm;
-	float (*orco)[3];
-	int free;
-
-	if (em) {
-		dm = CDDM_from_editbmesh(em, false, false);
-	}
-	else {
-		dm = CDDM_from_mesh(me);
-	}
-
-	orco = get_orco_coords_dm(ob, em, layer, &free);
-
-	if (orco) {
-		CDDM_apply_vert_coords(dm, orco);
-		if (free) MEM_freeN(orco);
-	}
-
-	return dm;
-}
-
-static void add_orco_dm(
-        Object *ob, BMEditMesh *em, DerivedMesh *dm,
-        DerivedMesh *orcodm, int layer)
-{
-	float (*orco)[3], (*layerorco)[3];
-	int totvert, free;
-
-	totvert = dm->getNumVerts(dm);
-
-	if (orcodm) {
-		orco = MEM_callocN(sizeof(float[3]) * totvert, "dm orco");
-		free = 1;
-
-		if (orcodm->getNumVerts(orcodm) == totvert)
-			orcodm->getVertCos(orcodm, orco);
-		else
-			dm->getVertCos(dm, orco);
-	}
-	else
-		orco = get_orco_coords_dm(ob, em, layer, &free);
-
-	if (orco) {
-		if (layer == CD_ORCO)
-			BKE_mesh_orco_verts_transform(ob->data, orco, totvert, 0);
-
-		if (!(layerorco = DM_get_vert_data_layer(dm, layer))) {
-			DM_add_vert_layer(dm, layer, CD_CALLOC, NULL);
-			layerorco = DM_get_vert_data_layer(dm, layer);
-		}
-
-		memcpy(layerorco, orco, sizeof(float) * 3 * totvert);
-		if (free) MEM_freeN(orco);
-	}
-}
-
-/* weight paint colors */
-
-/* Something of a hack, at the moment deal with weightpaint
- * by tucking into colors during modifier eval, only in
- * wpaint mode. Works ok but need to make sure recalc
- * happens on enter/exit wpaint.
- */
-
-void weight_to_rgb(float r_rgb[3], const float weight)
-{
-	const float blend = ((weight / 2.0f) + 0.5f);
-
-	if (weight <= 0.25f) {    /* blue->cyan */
-		r_rgb[0] = 0.0f;
-		r_rgb[1] = blend * weight * 4.0f;
-		r_rgb[2] = blend;
-	}
-	else if (weight <= 0.50f) {  /* cyan->green */
-		r_rgb[0] = 0.0f;
-		r_rgb[1] = blend;
-		r_rgb[2] = blend * (1.0f - ((weight - 0.25f) * 4.0f));
-	}
-	else if (weight <= 0.75f) {  /* green->yellow */
-		r_rgb[0] = blend * ((weight - 0.50f) * 4.0f);
-		r_rgb[1] = blend;
-		r_rgb[2] = 0.0f;
-	}
-	else if (weight <= 1.0f) {  /* yellow->red */
-		r_rgb[0] = blend;
-		r_rgb[1] = blend * (1.0f - ((weight - 0.75f) * 4.0f));
-		r_rgb[2] = 0.0f;
-	}
-	else {
-		/* exceptional value, unclamped or nan,
-		 * avoid uninitialized memory use */
-		r_rgb[0] = 1.0f;
-		r_rgb[1] = 0.0f;
-		r_rgb[2] = 1.0f;
-	}
-}
-
-/* draw_flag's for calc_weightpaint_vert_color */
-enum {
-	/* only one of these should be set, keep first (for easy bit-shifting) */
-	CALC_WP_GROUP_USER_ACTIVE   = (1 << 1),
-	CALC_WP_GROUP_USER_ALL      = (1 << 2),
-
-	CALC_WP_MULTIPAINT          = (1 << 3),
-	CALC_WP_AUTO_NORMALIZE      = (1 << 4),
-	CALC_WP_MIRROR_X            = (1 << 5),
-};
-
-typedef struct DMWeightColorInfo {
-	const ColorBand *coba;
-	const char *alert_color;
-} DMWeightColorInfo;
-
-
-static int dm_drawflag_calc(const ToolSettings *ts, const Mesh *me)
-{
-	return ((ts->multipaint ? CALC_WP_MULTIPAINT : 0) |
-	        /* CALC_WP_GROUP_USER_ACTIVE or CALC_WP_GROUP_USER_ALL */
-	        (1 << ts->weightuser) |
-	        (ts->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0) |
-	        ((me->editflag & ME_EDIT_MIRROR_X) ? CALC_WP_MIRROR_X : 0));
-}
-
-static void weightpaint_color(unsigned char r_col[4], DMWeightColorInfo *dm_wcinfo, const float input)
-{
-	float colf[4];
-
-	if (dm_wcinfo && dm_wcinfo->coba) {
-		do_colorband(dm_wcinfo->coba, input, colf);
-	}
-	else {
-		weight_to_rgb(colf, input);
-	}
-
-	/* don't use rgb_float_to_uchar() here because
-	 * the resulting float doesn't need 0-1 clamp check */
-	r_col[0] = (unsigned char)(colf[0] * 255.0f);
-	r_col[1] = (unsigned char)(colf[1] * 255.0f);
-	r_col[2] = (unsigned char)(colf[2] * 255.0f);
-	r_col[3] = 255;
-}
-
-
-static void calc_weightpaint_vert_color(
-        unsigned char r_col[4],
-        const MDeformVert *dv,
-        DMWeightColorInfo *dm_wcinfo,
-        const int defbase_tot, const int defbase_act,
-        const bool *defbase_sel, const int defbase_sel_tot,
-        const int draw_flag)
-{
-	float input = 0.0f;
-	
-	bool show_alert_color = false;
-
-	if ((defbase_sel_tot > 1) && (draw_flag & CALC_WP_MULTIPAINT)) {
-		/* Multi-Paint feature */
-		input = BKE_defvert_multipaint_collective_weight(
-		        dv, defbase_tot, defbase_sel, defbase_sel_tot, (draw_flag & CALC_WP_AUTO_NORMALIZE) != 0);
-
-		/* make it black if the selected groups have no weight on a vertex */
-		if (input == 0.0f) {
-		

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list