[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37351] branches/soc-2011-onion/source/ blender/editors/uvedit/uvedit_unwrap_ops.c: subsurf-aware UV solver commit #3:

Ryakiotakis Antonis kalast at gmail.com
Fri Jun 10 02:19:14 CEST 2011


Revision: 37351
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37351
Author:   psy-fi
Date:     2011-06-10 00:19:12 +0000 (Fri, 10 Jun 2011)
Log Message:
-----------
subsurf-aware UV solver commit #3:
Feature implemented :) Made unwrap work with post-subsurf vertex positions in the solver. There are some issues with crashes. Need to investigate. Also pending is addition of setting to select subdivision level to calculate.

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_unwrap_ops.c

Modified: branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_unwrap_ops.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_unwrap_ops.c	2011-06-09 23:15:41 UTC (rev 37350)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_unwrap_ops.c	2011-06-10 00:19:12 UTC (rev 37351)
@@ -42,6 +42,7 @@
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_modifier_types.h"
 
 #include "BLI_math.h"
 #include "BLI_edgehash.h"
@@ -49,6 +50,8 @@
 #include "BLI_uvproject.h"
 #include "BLI_utildefines.h"
 
+#include "BKE_cdderivedmesh.h"
+#include "BKE_subsurf.h"
 #include "BKE_context.h"
 #include "BKE_customdata.h"
 #include "BKE_depsgraph.h"
@@ -134,7 +137,7 @@
 
 /****************** Parametrizer Conversion ***************/
 
-static ParamHandle *construct_param_handle(Scene *scene, EditMesh *em, short implicit, short fill, short sel, short correct_aspect)
+static ParamHandle *construct_param_handle(Scene *scene, EditMesh *em, short implicit, short fill, short sel, short correct_aspect, short use_subsurf)
 {
 	ParamHandle *handle;
 	EditFace *efa;
@@ -142,6 +145,17 @@
 	EditVert *ev;
 	MTFace *tf;
 	int a;
+
+	/* modifier initialization data, will  control what type of subdivision will happen*/
+	SubsurfModifierData smd;
+	/* Used to hold subsurfed Mesh */
+	DerivedMesh *derivedMesh, *initialDerived;
+	/* holds original indices for subsurfed mesh */
+	int *origIndices;
+	/* Holds vertices of subdivided mesh */
+	MVert *subsurfedVerts;
+	/* holds a map from mesh indices to subsurfedMesh indices */
+	int *indexMap = NULL;
 	
 	handle = param_construct_begin();
 
@@ -159,6 +173,45 @@
 		}
 	}
 	
+	if(use_subsurf)
+	{
+		int numOfVerts;
+		
+		/* ad hoc, will change later */
+		smd.levels = 2;
+		/* no cache here */
+		smd.emCache = NULL;
+		smd.mCache = NULL;
+		/* will not be used here I think */
+		smd.renderLevels = 0;
+		/* catmull clark subdiv(simple makes no difference, apart from roasting the CPU) */
+		smd.subdivType = ME_CC_SUBSURF;
+		//smd.flags = ;
+		
+		initialDerived = CDDM_from_editmesh(em, NULL);
+		/* This is not very useful actually, we need to be able to account for mirror modifiers etc.
+		   However it -is- useful as a proof-of-concept implementation :) */
+		derivedMesh = subsurf_make_derived_from_derived(initialDerived, &smd, NULL,
+			0, NULL, 1, 1, 0);
+
+		initialDerived->release(initialDerived);
+
+		subsurfedVerts = derivedMesh->getVertArray(derivedMesh);
+		origIndices = derivedMesh->getVertDataArray(derivedMesh, CD_ORIGINDEX);
+		
+		numOfVerts = derivedMesh->getNumVerts(derivedMesh);
+		
+		indexMap = MEM_mallocN(em->totvert*sizeof(int), "mesh_to_subsurfed_index_map");
+		
+		/* remap indices. DerivedMesh vertices that do not correspond to
+		   original mesh have -1 index on ORIGINDEX layer */
+		for(a = 0; a < numOfVerts; a++)
+		{
+			if(origIndices[a] != -1)
+				indexMap[origIndices[a]] = a;
+		}
+	}
+
 	/* we need the vert indices */
 	for(ev= em->verts.first, a=0; ev; ev= ev->next, a++)
 		ev->tmp.l = a;
@@ -197,10 +250,16 @@
 		vkeys[1] = (ParamKey)efa->v2->tmp.l;
 		vkeys[2] = (ParamKey)efa->v3->tmp.l;
 
-		co[0] = efa->v1->co;
-		co[1] = efa->v2->co;
-		co[2] = efa->v3->co;
-
+		if(use_subsurf){
+			co[0] = subsurfedVerts[indexMap[vkeys[0]]].co;
+			co[1] = subsurfedVerts[indexMap[vkeys[1]]].co;
+			co[2] = subsurfedVerts[indexMap[vkeys[2]]].co;
+		} else {
+			co[0] = efa->v1->co;
+			co[1] = efa->v2->co;
+			co[2] = efa->v3->co;
+		}
+		
 		uv[0] = tf->uv[0];
 		uv[1] = tf->uv[1];
 		uv[2] = tf->uv[2];
@@ -215,7 +274,11 @@
 
 		if(efa->v4) {
 			vkeys[3] = (ParamKey)efa->v4->tmp.l;
-			co[3] = efa->v4->co;
+			if(use_subsurf){
+				co[3] = subsurfedVerts[indexMap[vkeys[3]]].co;
+			} else {
+				co[3] = efa->v4->co;
+			}
 			uv[3] = tf->uv[3];
 			pin[3] = ((tf->unwrap & TF_PIN4) != 0);
 			select[3] = (uvedit_uv_selected(scene, efa, tf, 3) != 0);
@@ -240,6 +303,12 @@
 
 	param_construct_end(handle, fill, implicit);
 
+	/* cleanup */
+	if(use_subsurf)
+	{
+		derivedMesh->release(derivedMesh);
+		MEM_freeN(indexMap);
+	}
 	return handle;
 }
 
@@ -270,7 +339,7 @@
 	ms->em= em;
 	ms->blend= RNA_float_get(op->ptr, "blend");
 	ms->iterations= RNA_int_get(op->ptr, "iterations");
-	ms->handle= construct_param_handle(scene, em, 1, fill_holes, 1, 1);
+	ms->handle= construct_param_handle(scene, em, 1, fill_holes, 1, 1, 0);
 	ms->lasttime= PIL_check_seconds_timer();
 
 	param_stretch_begin(ms->handle);
@@ -453,7 +522,7 @@
 		RNA_float_set(op->ptr, "margin", scene->toolsettings->uvcalc_margin);
 	}
 
-	handle = construct_param_handle(scene, em, 1, 0, 1, 1);
+	handle = construct_param_handle(scene, em, 1, 0, 1, 1, 0);
 	param_pack(handle, scene->toolsettings->uvcalc_margin);
 	param_flush(handle);
 	param_delete(handle);
@@ -489,7 +558,7 @@
 	EditMesh *em= BKE_mesh_get_editmesh((Mesh*)obedit->data);
 	ParamHandle *handle;
 
-	handle= construct_param_handle(scene, em, 1, 0, 1, 1);
+	handle= construct_param_handle(scene, em, 1, 0, 1, 1, 0);
 	param_average(handle);
 	param_flush(handle);
 	param_delete(handle);
@@ -529,7 +598,7 @@
 		return;
 	}
 
-	liveHandle = construct_param_handle(scene, em, 0, fillholes, 1, 1);
+	liveHandle = construct_param_handle(scene, em, 0, fillholes, 1, 1, use_subsurf);
 
 	param_lscm_begin(liveHandle, PARAM_TRUE, abf);
 	BKE_mesh_end_editmesh(obedit->data, em);
@@ -840,7 +909,7 @@
 	const short correct_aspect= !(scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT);
 	const short use_subsurf = scene->toolsettings->uvcalc_flag & UVCALC_USESUBSURF;
 
-	ParamHandle *handle= construct_param_handle(scene, em, 0, fill_holes, sel, correct_aspect);
+	ParamHandle *handle= construct_param_handle(scene, em, 0, fill_holes, sel, correct_aspect, use_subsurf);
 
 	param_lscm_begin(handle, PARAM_FALSE, scene->toolsettings->unwrapper == 0);
 	param_lscm_solve(handle);




More information about the Bf-blender-cvs mailing list