[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15696] branches/soc-2008-nicholasbishop/ source/blender: Added a reshape button to the multires modifier.

Nicholas Bishop nicholasbishop at gmail.com
Tue Jul 22 19:03:44 CEST 2008


Revision: 15696
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15696
Author:   nicholasbishop
Date:     2008-07-22 19:03:44 +0200 (Tue, 22 Jul 2008)

Log Message:
-----------
Added a reshape button to the multires modifier. It copies the vertices from another selected mesh into the current level. Allows indirect editing of multires levels other than the base in editmode, and more importantly allows for editing multires levels in other programs. Of course, vertex order and overall topology must match. Additionally, the copy is only exact for the first and last level. All other levels will do the usual catmull-clark subdivision.

Modified Paths:
--------------
    branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_multires.h
    branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c
    branches/soc-2008-nicholasbishop/source/blender/src/buttons_editing.c

Modified: branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_multires.h
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_multires.h	2008-07-22 16:44:35 UTC (rev 15695)
+++ branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_multires.h	2008-07-22 17:03:44 UTC (rev 15696)
@@ -131,6 +131,7 @@
 
 void multiresModifier_subdivide(struct MultiresModifierData *mmd, struct Object *ob);
 void multiresModifier_setLevel(void *mmd_v, void *ob_v);
+int multiresModifier_reshape(struct MultiresModifierData *mmd, struct Object *dst, struct Object *src);
 
 void multires_displacer_init(MultiresDisplacer *d, struct DerivedMesh *dm,
 			     const int face_index, const int invert);

Modified: branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c	2008-07-22 16:44:35 UTC (rev 15695)
+++ branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c	2008-07-22 17:03:44 UTC (rev 15696)
@@ -1365,8 +1365,28 @@
 	}
 }
 
+/* Returns 0 on success, 1 if the src's totvert doesn't match */
+int multiresModifier_reshape(MultiresModifierData *mmd, Object *dst, Object *src)
+{
+	Mesh *src_me = get_mesh(src);
+	DerivedMesh *mrdm = dst->derivedFinal;
 
+	if(mrdm && mrdm->getNumVerts(mrdm) == src_me->totvert) {
+		MVert *mvert = CDDM_get_verts(mrdm);
+		int i;
 
+		for(i = 0; i < src_me->totvert; ++i)
+			VecCopyf(mvert[i].co, src_me->mvert[i].co);
+		mrdm->needsFree = 1;
+		mrdm->release(mrdm);
+		dst->derivedFinal = NULL;
+
+		return 0;
+	}
+
+	return 1;
+}
+
 static void multiresModifier_update(DerivedMesh *dm)
 {
 	MDisps *mdisps;

Modified: branches/soc-2008-nicholasbishop/source/blender/src/buttons_editing.c
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/src/buttons_editing.c	2008-07-22 16:44:35 UTC (rev 15695)
+++ branches/soc-2008-nicholasbishop/source/blender/src/buttons_editing.c	2008-07-22 17:03:44 UTC (rev 15696)
@@ -1671,6 +1671,27 @@
 	}
 }
 
+static void multiresModifier_reshape_button(void *mmd_v, void *ob_v)
+{
+	MultiresModifierData *mmd = mmd_v;
+	if(mmd && ob_v) {
+		Base *base = FIRSTBASE;
+		if(base && base->object != ob_v) {
+			Object *src = base->object;
+			if(src->type == OB_MESH) {
+				if(multiresModifier_reshape(mmd, ob_v, src))
+					error("Vertex count mismatch");
+				else
+					BIF_undo_push("Multires reshape");
+			}
+			else
+				error("Second selection not a mesh");
+		}
+		else
+			error("Second selection required");
+	}
+}
+
 static int modifier_is_fluid_particles(ModifierData *md) {
 	if(md->type == eModifierType_ParticleSystem) {
 		if(((ParticleSystemModifierData *)md)->psys->part->type == PART_FLUID)
@@ -1841,7 +1862,7 @@
 		} else if (md->type==eModifierType_Explode) {
 			height = 94;
 		} else if (md->type==eModifierType_Multires) {
-			height = 48;
+			height = 72;
 		}
 							/* roundbox 4 free variables: corner-rounding, nop, roundbox type, shade */
 		uiDefBut(block, ROUNDBOX, 0, "", x-10, y-height-2, width, height-2, NULL, 5.0, 0.0, 12, 40, ""); 
@@ -2471,6 +2492,10 @@
 		
 			but = uiDefButC(block,NUM,B_MODIFIER_RECALC,"Level: ",lx,(cy-=19),buttonWidth,19, &mmd->lvl, 1.0, mmd->totlvl, 0,0,"");
 			uiButSetFunc(but, multiresModifier_setLevel, mmd, ob);
+
+			uiBlockBeginAlign(block);
+			but = uiDefBut(block,BUT,B_MODIFIER_RECALC,"Reshape", lx,(cy-=24),buttonWidth/2,19,0,0,0,0,0,"Copy vertices from another selected mesh into the current level");
+			uiButSetFunc(but, multiresModifier_reshape_button, mmd, ob);
 		}
 
 		uiBlockEndAlign(block);





More information about the Bf-blender-cvs mailing list