[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49046] branches/soc-2012-bratwurst/source /blender: * Cleanup of subsurf unwrap code

Antony Riakiotakis kalast at gmail.com
Wed Jul 18 23:43:38 CEST 2012


Revision: 49046
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49046
Author:   psy-fi
Date:     2012-07-18 21:43:37 +0000 (Wed, 18 Jul 2012)
Log Message:
-----------
* Cleanup of subsurf unwrap code

Now take subsurf levels and type from the modifier stack (Now simple
subdivision will work too). Subsurf unwrap won't work if there's no
subsurf first or after mirror in the modifier stack. This is done to
alleviate having to set subsurf levels in two places, usually user will
want the tool to autodetect the setting from the stack. This sets the
paradigm that will be followed by mirrored unwrap as well.

Modified Paths:
--------------
    branches/soc-2012-bratwurst/source/blender/editors/uvedit/uvedit_unwrap_ops.c
    branches/soc-2012-bratwurst/source/blender/makesdna/DNA_scene_types.h

Modified: branches/soc-2012-bratwurst/source/blender/editors/uvedit/uvedit_unwrap_ops.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/uvedit/uvedit_unwrap_ops.c	2012-07-18 21:13:06 UTC (rev 49045)
+++ branches/soc-2012-bratwurst/source/blender/editors/uvedit/uvedit_unwrap_ops.c	2012-07-18 21:43:37 UTC (rev 49046)
@@ -177,9 +177,35 @@
 	return 0;
 }
 
+static void modifier_unwrap_state(Object *obedit, Scene *scene, short *use_subsurf, short *use_mirror)
+{
+	ModifierData *md;
+	short subsurf = scene->toolsettings->uvcalc_flag & UVCALC_USESUBSURF;
+	short mirror = scene->toolsettings->uvcalc_flag & UVCALC_USEMIRROR_MOD;
+
+	md = obedit->modifiers.first;
+
+	/* only account for mirroring if first modifier is mirror */
+	if(!(md->type == eModifierType_Mirror))
+		mirror = 0;
+
+	/* subsurf will take the modifier settings only if modifier is first or right after mirror */
+	if (subsurf) {
+		if (mirror) {
+			md = md->next;
+		}
+
+		if (!(md->type == eModifierType_Subsurf))
+			subsurf = 0;
+	}
+
+	*use_subsurf = subsurf;
+	*use_mirror = mirror;
+}
+
 static ParamHandle *construct_param_handle(Scene *scene, BMEditMesh *em, 
                                            short implicit, short fill, short sel,
-                                           short correct_aspect)
+                                           short correct_aspect, short mirrored)
 {
 	ScanFillContext sf_ctx;
 	ParamHandle *handle;
@@ -351,7 +377,7 @@
 
 /* unwrap handle initialization for subsurf aware-unwrapper. The many modifications required to make the original function(see above)
  * work justified the existence of a new function. */
-static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BMEditMesh *em, short fill, short sel, short correct_aspect)
+static ParamHandle *construct_param_handle_subsurfed(Scene *scene, Object *obedit, short fill, short sel, short correct_aspect, short mirrored)
 {
 	ParamHandle *handle;
 	/* index pointers */
@@ -359,11 +385,14 @@
 	MEdge *edge;
 	BMFace *editFace;
 	int i;
-
+	/* pointers to modifier data for unwrap control */
+	ModifierData *md;
+	SubsurfModifierData *smd_real;
 	/* modifier initialization data, will  control what type of subdivision will happen*/
 	SubsurfModifierData smd = {{0}};
 	/* Used to hold subsurfed Mesh */
 	DerivedMesh *derivedMesh, *initialDerived;
+	BMEditMesh *em;
 	/* holds original indices for subsurfed mesh */
 	int *origVertIndices, *origFaceIndices, *origEdgeIndices;
 	/* Holds vertices of subsurfed mesh */
@@ -378,6 +407,8 @@
 	/* similar to the above, we need a way to map edges to their original ones */
 	BMEdge **edgeMap;
 
+	em = BMEdit_FromObject(obedit);
+
 	handle = param_construct_begin();
 
 	if (correct_aspect) {
@@ -398,8 +429,14 @@
 	}
 
 	/* number of subdivisions to perform */
-	smd.levels = scene->toolsettings->uv_subsurf_level;
-	smd.subdivType = ME_CC_SUBSURF;
+	md = obedit->modifiers.first;
+	if(mirrored)
+		md = md->next;
+	smd_real = (SubsurfModifierData *)md;
+
+	smd.levels = smd_real->levels;
+
+	smd.subdivType = smd_real->subdivType;
 		
 	initialDerived = CDDM_from_BMEditMesh(em, NULL, 0, 0);
 	derivedMesh = subsurf_make_derived_from_derived(initialDerived, &smd,
@@ -536,7 +573,7 @@
 	ms->blend = RNA_float_get(op->ptr, "blend");
 	ms->iterations = RNA_int_get(op->ptr, "iterations");
 	ms->i = 0;
-	ms->handle = construct_param_handle(scene, em, implicit, fill_holes, 1, 1);
+	ms->handle = construct_param_handle(scene, em, implicit, fill_holes, 1, 1, 0);
 	ms->lasttime = PIL_check_seconds_timer();
 
 	param_stretch_begin(ms->handle);
@@ -732,7 +769,7 @@
 		RNA_float_set(op->ptr, "margin", scene->toolsettings->uvcalc_margin);
 	}
 
-	handle = construct_param_handle(scene, em, implicit, 0, 1, 1);
+	handle = construct_param_handle(scene, em, implicit, 0, 1, 1, 0);
 	param_pack(handle, scene->toolsettings->uvcalc_margin);
 	param_flush(handle);
 	param_delete(handle);
@@ -774,7 +811,7 @@
 		return OPERATOR_CANCELLED;
 	}
 
-	handle = construct_param_handle(scene, em, implicit, 0, 1, 1);
+	handle = construct_param_handle(scene, em, implicit, 0, 1, 1, 0);
 	param_average(handle);
 	param_flush(handle);
 	param_delete(handle);
@@ -808,17 +845,19 @@
 	BMEditMesh *em = BMEdit_FromObject(obedit);
 	short abf = scene->toolsettings->unwrapper == 0;
 	short fillholes = scene->toolsettings->uvcalc_flag & UVCALC_FILLHOLES;
-	short use_subsurf = scene->toolsettings->uvcalc_flag & UVCALC_USESUBSURF;
-	short use_mirror = scene->toolsettings->uvcalc_flag & UVCALC_USEMIRROR_MOD;
+	short use_subsurf;
+	short use_mirror;
 
+	modifier_unwrap_state(obedit, scene, &use_subsurf, &use_mirror);
+
 	if (!ED_uvedit_test(obedit)) {
 		return;
 	}
 
 	if (use_subsurf)
-		liveHandle = construct_param_handle_subsurfed(scene, em, fillholes, 0, 1);
+		liveHandle = construct_param_handle_subsurfed(scene, obedit, fillholes, 0, 1, use_mirror);
 	else
-		liveHandle = construct_param_handle(scene, em, 0, fillholes, 0, 1);
+		liveHandle = construct_param_handle(scene, em, 0, fillholes, 0, 1, use_mirror);
 
 	param_lscm_begin(liveHandle, PARAM_TRUE, abf);
 }
@@ -1138,13 +1177,15 @@
 
 	const short fill_holes = scene->toolsettings->uvcalc_flag & UVCALC_FILLHOLES;
 	const short correct_aspect = !(scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT);
-	const short use_subsurf = scene->toolsettings->uvcalc_flag & UVCALC_USESUBSURF;
-	const short use_mirror = scene->toolsettings->uvcalc_flag & UVCALC_USEMIRROR_MOD;
+	short use_subsurf;
+	short use_mirror;
 
+	modifier_unwrap_state(obedit, scene, &use_subsurf, &use_mirror);
+
 	if (use_subsurf)
-		handle = construct_param_handle_subsurfed(scene, em, fill_holes, sel, correct_aspect);
+		handle = construct_param_handle_subsurfed(scene, obedit, fill_holes, sel, correct_aspect, use_mirror);
 	else
-		handle = construct_param_handle(scene, em, 0, fill_holes, sel, correct_aspect);
+		handle = construct_param_handle(scene, em, 0, fill_holes, sel, correct_aspect, use_mirror);
 
 	param_lscm_begin(handle, PARAM_FALSE, scene->toolsettings->unwrapper == 0);
 	param_lscm_solve(handle);
@@ -1168,7 +1209,6 @@
 	int correct_aspect = RNA_boolean_get(op->ptr, "correct_aspect");
 	int use_subsurf = RNA_boolean_get(op->ptr, "use_subsurf_data");
 	int use_mirror = RNA_boolean_get(op->ptr, "use_mirror_mod");
-	int subsurf_level = RNA_int_get(op->ptr, "uv_subsurf_level");
 	float obsize[3], unitsize[3] = {1.0f, 1.0f, 1.0f};
 	short implicit = 0;
 
@@ -1191,8 +1231,6 @@
 	else
 		RNA_enum_set(op->ptr, "method", scene->toolsettings->unwrapper);
 
-	scene->toolsettings->uv_subsurf_level = subsurf_level;
-
 	if (fill_holes) scene->toolsettings->uvcalc_flag |=  UVCALC_FILLHOLES;
 	else scene->toolsettings->uvcalc_flag &= ~UVCALC_FILLHOLES;
 
@@ -1243,8 +1281,6 @@
 	                "Take mirror modifier output into account to make more symmetric unwraps. Only works if mirror modifier is first");
 	RNA_def_boolean(ot->srna, "use_subsurf_data", 0, "Use Subsurf Data",
 	                "Map UVs taking vertex position after subsurf into account");
-	RNA_def_int(ot->srna, "uv_subsurf_level", 1, 1, 6, "SubSurf Target",
-	            "Number of times to subdivide before calculating UVs", 1, 6);
 }
 
 /**************** Project From View operator **************/

Modified: branches/soc-2012-bratwurst/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/makesdna/DNA_scene_types.h	2012-07-18 21:13:06 UTC (rev 49045)
+++ branches/soc-2012-bratwurst/source/blender/makesdna/DNA_scene_types.h	2012-07-18 21:43:37 UTC (rev 49046)
@@ -931,8 +931,8 @@
 	short uvcalc_mapalign;
 	short uvcalc_flag;
 	short uv_flag, uv_selectmode;
-	short uv_subsurf_level;
-	
+	short pad2;
+
 	/* Grease Pencil */
 	short gpencil_flags;
 	
@@ -959,7 +959,7 @@
 
 	/* Multires */
 	char multires_subdiv_type;
-	char pad2[5];
+	char pad3[5];
 
 	/* Skeleton generation */
 	short skgen_resolution;
@@ -995,12 +995,12 @@
 
 	/* Transform */
 	char snap_mode, snap_node_mode;
-	char pad3;
+	char pad4;
 	short snap_flag, snap_target;
 	short proportional, prop_mode;
 	char proportional_objects; /* proportional edit, object mode */
 	char proportional_mask; /* proportional edit, object mode */
-	char pad4[2];
+	char pad5[2];
 
 	char auto_normalize; /*auto normalizing mode in wpaint*/
 	char multipaint; /* paint multiple bones in wpaint */
@@ -1012,7 +1012,7 @@
 	int uv_relax_method;
 	/* XXX: these sculpt_paint_* fields are deprecated, use the
 	 * unified_paint_settings field instead! */
-	short sculpt_paint_settings DNA_DEPRECATED;	short pad5;
+	short sculpt_paint_settings DNA_DEPRECATED;	short pad6;
 	int sculpt_paint_unified_size DNA_DEPRECATED;
 	float sculpt_paint_unified_unprojected_radius DNA_DEPRECATED;
 	float sculpt_paint_unified_alpha DNA_DEPRECATED;




More information about the Bf-blender-cvs mailing list