[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43117] trunk/blender/source/blender: de-duplicate wave modifier texture function.

Campbell Barton ideasman42 at gmail.com
Wed Jan 4 06:40:06 CET 2012


Revision: 43117
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43117
Author:   campbellbarton
Date:     2012-01-04 05:39:56 +0000 (Wed, 04 Jan 2012)
Log Message:
-----------
de-duplicate wave modifier texture function.

cmon - copying large functions between files is obviously stupid, dont do it!

Modified Paths:
--------------
    trunk/blender/source/blender/makesdna/DNA_modifier_types.h
    trunk/blender/source/blender/makesrna/intern/rna_modifier.c
    trunk/blender/source/blender/modifiers/intern/MOD_wave.c

Modified: trunk/blender/source/blender/makesdna/DNA_modifier_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_modifier_types.h	2012-01-04 05:24:01 UTC (rev 43116)
+++ trunk/blender/source/blender/makesdna/DNA_modifier_types.h	2012-01-04 05:39:56 UTC (rev 43117)
@@ -313,13 +313,13 @@
 	char uvlayer_name[32];
 	int uvlayer_tmp;
 	int texmapping;
-	int pad10;
 	/* end MappingInfoModifierData */
 
 	float strength;
 	int direction;
 	char defgrp_name[32];
 	float midlevel;
+	int pad;
 } DisplaceModifierData;
 
 /* DisplaceModifierData->direction */
@@ -413,20 +413,22 @@
 typedef struct WaveModifierData {
 	ModifierData modifier;
 
-	struct Object *objectcenter;
-	char defgrp_name[32];
+	/* keep in sync with MappingInfoModifierData */
 	struct Tex *texture;
 	struct Object *map_object;
+	char uvlayer_name[32];
+	int uvlayer_tmp;
+	int texmapping;
+	/* end MappingInfoModifierData */
 
+	struct Object *objectcenter;
+	char defgrp_name[32];
+
 	short flag, pad;
 
 	float startx, starty, height, width;
 	float narrow, speed, damp, falloff;
 
-	int texmapping, uvlayer_tmp;
-
-	char uvlayer_name[32];
-
 	float timeoffs, lifetime;
 	float pad1;
 } WaveModifierData;
@@ -815,19 +817,17 @@
 	char uvlayer_name[32];
 	int uvlayer_tmp;
 	int texmapping;
-	int pad10;
 	/* end MappingInfoModifierData */
 
-	float strength;
-
 	struct Object *object_from;
 	struct Object *object_to;
 	struct CurveMapping *curfalloff;
 	char defgrp_name[32];			/* optional vertexgroup name */
+	float strength;
 	float falloff_radius;
 	char flag; /* not used yet */
 	char falloff_type;
-	char pad[2];
+	char pad[6];
 } WarpModifierData;
 
 #define MOD_WARP_VOLUME_PRESERVE 1

Modified: trunk/blender/source/blender/makesrna/intern/rna_modifier.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_modifier.c	2012-01-04 05:24:01 UTC (rev 43116)
+++ trunk/blender/source/blender/makesrna/intern/rna_modifier.c	2012-01-04 05:39:56 UTC (rev 43117)
@@ -452,12 +452,6 @@
 	rna_object_vgroup_name_set(ptr, value, tmd->defgrp_name, sizeof(tmd->defgrp_name));
 }
 
-static void rna_WaveModifier_uvlayer_set(PointerRNA *ptr, const char *value)
-{
-	WaveModifierData *wmd= (WaveModifierData*)ptr->data;
-	rna_object_uvlayer_name_set(ptr, value, wmd->uvlayer_name, sizeof(wmd->uvlayer_name));
-}
-
 static void rna_WeightVGModifier_mask_uvlayer_set(PointerRNA *ptr, const char *value)
 {
 	ModifierData *md = (ModifierData*)ptr->data;
@@ -1125,13 +1119,6 @@
 	StructRNA *srna;
 	PropertyRNA *prop;
 
-	static EnumPropertyItem prop_texture_coordinates_items[] = {
-		{MOD_DISP_MAP_LOCAL, "LOCAL", 0, "Local", ""},
-		{MOD_DISP_MAP_GLOBAL, "GLOBAL", 0, "Global", ""},
-		{MOD_DISP_MAP_OBJECT, "OBJECT", 0, "Object", ""},
-		{MOD_DISP_MAP_UV, "MAP_UV", 0, "UV", ""},
-		{0, NULL, 0, NULL, NULL}};
-
 	srna= RNA_def_struct(brna, "WaveModifier", "Modifier");
 	RNA_def_struct_ui_text(srna, "Wave Modifier", "Wave effect modifier");
 	RNA_def_struct_sdna(srna, "WaveModifierData");
@@ -1223,29 +1210,6 @@
 	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_WaveModifier_vgroup_set");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
-	prop= RNA_def_property(srna, "texture", PROP_POINTER, PROP_NONE);
-	RNA_def_property_ui_text(prop, "Texture", "Texture for modulating the wave");
-	RNA_def_property_flag(prop, PROP_EDITABLE);
-	RNA_def_property_update(prop, 0, "rna_Modifier_update");
-
-	prop= RNA_def_property(srna, "texture_coords", PROP_ENUM, PROP_NONE);
-	RNA_def_property_enum_sdna(prop, NULL, "texmapping");
-	RNA_def_property_enum_items(prop, prop_texture_coordinates_items);
-	RNA_def_property_ui_text(prop, "Texture Coordinates", "Texture coordinates used for modulating input");
-	RNA_def_property_update(prop, 0, "rna_Modifier_update");
-
-	prop= RNA_def_property(srna, "uv_layer", PROP_STRING, PROP_NONE);
-	RNA_def_property_string_sdna(prop, NULL, "uvlayer_name");
-	RNA_def_property_ui_text(prop, "UV Map", "UV map name");
-	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_WaveModifier_uvlayer_set");
-	RNA_def_property_update(prop, 0, "rna_Modifier_update");
-
-	prop= RNA_def_property(srna, "texture_coords_object", PROP_POINTER, PROP_NONE);
-	RNA_def_property_pointer_sdna(prop, NULL, "map_object");
-	RNA_def_property_ui_text(prop, "Texture Coordinates Object", "");
-	RNA_def_property_flag(prop, PROP_EDITABLE|PROP_ID_SELF_CHECK);
-	RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
-
 	prop= RNA_def_property(srna, "speed", PROP_FLOAT, PROP_NONE);
 	RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
 	RNA_def_property_ui_range(prop, -1, 1, 10, 2);
@@ -1270,6 +1234,8 @@
 	RNA_def_property_ui_range(prop, 0, 10, 10, 2);
 	RNA_def_property_ui_text(prop, "Narrowness", "Distance between the top and the base of a wave, the higher the value, the more narrow the wave");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	rna_def_modifier_generic_map_info(srna);
 }
 
 static void rna_def_modifier_armature(BlenderRNA *brna)

Modified: trunk/blender/source/blender/modifiers/intern/MOD_wave.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_wave.c	2012-01-04 05:24:01 UTC (rev 43116)
+++ trunk/blender/source/blender/modifiers/intern/MOD_wave.c	2012-01-04 05:39:56 UTC (rev 43117)
@@ -170,91 +170,6 @@
 	return dataMask;
 }
 
-static void wavemod_get_texture_coords(WaveModifierData *wmd, Object *ob,
-					   DerivedMesh *dm,
-	   float (*co)[3], float (*texco)[3],
-		   int numVerts)
-{
-	int i;
-	int texmapping = wmd->texmapping;
-
-	if(texmapping == MOD_DISP_MAP_OBJECT) {
-		if(wmd->map_object)
-			invert_m4_m4(wmd->map_object->imat, wmd->map_object->obmat);
-		else /* if there is no map object, default to local */
-			texmapping = MOD_DISP_MAP_LOCAL;
-	}
-
-	/* UVs need special handling, since they come from faces */
-	if(texmapping == MOD_DISP_MAP_UV) {
-		if(CustomData_has_layer(&dm->faceData, CD_MTFACE)) {
-			MFace *mface = dm->getFaceArray(dm);
-			MFace *mf;
-			char *done = MEM_callocN(sizeof(*done) * numVerts,
-					"get_texture_coords done");
-			int numFaces = dm->getNumFaces(dm);
-			char uvname[32];
-			MTFace *tf;
-
-			CustomData_validate_layer_name(&dm->faceData, CD_MTFACE, wmd->uvlayer_name, uvname);
-			tf = CustomData_get_layer_named(&dm->faceData, CD_MTFACE, uvname);
-
-			/* verts are given the UV from the first face that uses them */
-			for(i = 0, mf = mface; i < numFaces; ++i, ++mf, ++tf) {
-				if(!done[mf->v1]) {
-					texco[mf->v1][0] = tf->uv[0][0];
-					texco[mf->v1][1] = tf->uv[0][1];
-					texco[mf->v1][2] = 0;
-					done[mf->v1] = 1;
-				}
-				if(!done[mf->v2]) {
-					texco[mf->v2][0] = tf->uv[1][0];
-					texco[mf->v2][1] = tf->uv[1][1];
-					texco[mf->v2][2] = 0;
-					done[mf->v2] = 1;
-				}
-				if(!done[mf->v3]) {
-					texco[mf->v3][0] = tf->uv[2][0];
-					texco[mf->v3][1] = tf->uv[2][1];
-					texco[mf->v3][2] = 0;
-					done[mf->v3] = 1;
-				}
-				if(!done[mf->v4]) {
-					texco[mf->v4][0] = tf->uv[3][0];
-					texco[mf->v4][1] = tf->uv[3][1];
-					texco[mf->v4][2] = 0;
-					done[mf->v4] = 1;
-				}
-			}
-
-			/* remap UVs from [0, 1] to [-1, 1] */
-			for(i = 0; i < numVerts; ++i) {
-				texco[i][0] = texco[i][0] * 2 - 1;
-				texco[i][1] = texco[i][1] * 2 - 1;
-			}
-
-			MEM_freeN(done);
-			return;
-		} else /* if there are no UVs, default to local */
-			texmapping = MOD_DISP_MAP_LOCAL;
-	}
-
-	for(i = 0; i < numVerts; ++i, ++co, ++texco) {
-		switch(texmapping) {
-			case MOD_DISP_MAP_LOCAL:
-				copy_v3_v3(*texco, *co);
-				break;
-			case MOD_DISP_MAP_GLOBAL:
-				mul_v3_m4v3(*texco, ob->obmat, *co);
-				break;
-			case MOD_DISP_MAP_OBJECT:
-				mul_v3_m4v3(*texco, ob->obmat, *co);
-				mul_m4_v3(wmd->map_object->imat, *texco);
-				break;
-		}
-	}
-}
-
 static void waveModifier_do(WaveModifierData *md, 
 		Scene *scene, Object *ob, DerivedMesh *dm,
 	   float (*vertexCos)[3], int numVerts)
@@ -305,7 +220,7 @@
 	if(wmd->texture) {
 		tex_co = MEM_mallocN(sizeof(*tex_co) * numVerts,
 					 "waveModifier_do tex_co");
-		wavemod_get_texture_coords(wmd, ob, dm, vertexCos, tex_co, numVerts);
+		get_texture_coords((MappingInfoModifierData *)wmd, ob, dm, vertexCos, tex_co, numVerts);
 	}
 
 	if(lifefac != 0.0f) {



More information about the Bf-blender-cvs mailing list