[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15703] branches/soc-2008-nicholasbishop/ source/blender: Fix joining of multires meshes.
Nicholas Bishop
nicholasbishop at gmail.com
Wed Jul 23 01:48:18 CEST 2008
Revision: 15703
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15703
Author: nicholasbishop
Date: 2008-07-23 01:48:18 +0200 (Wed, 23 Jul 2008)
Log Message:
-----------
Fix joining of multires meshes. The resulting mesh always has all the displacements -- if the mesh being joined to didn't have multires, it will once it's joined with a multires mesh.
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/meshtools.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 23:05:06 UTC (rev 15702)
+++ branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_multires.h 2008-07-22 23:48:18 UTC (rev 15703)
@@ -129,6 +129,7 @@
struct DerivedMesh *multires_dm_create_from_derived(struct MultiresModifierData*, struct DerivedMesh*,
struct Mesh *, int, int);
+void multiresModifier_join(struct Object *ob);
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);
Modified: branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c 2008-07-22 23:05:06 UTC (rev 15702)
+++ branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c 2008-07-22 23:48:18 UTC (rev 15703)
@@ -34,7 +34,9 @@
#include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
#include "DNA_vec_types.h"
+#include "DNA_view3d_types.h"
#include "BIF_editmesh.h"
@@ -47,6 +49,7 @@
#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
#include "BKE_global.h"
+#include "BKE_modifier.h"
#include "BKE_multires.h"
#include "BKE_subsurf.h"
@@ -813,6 +816,69 @@
static const int multires_tri_tot[] = {3, 7, 19, 61, 217, 817, 3169, 12481, 49537, 197377, 787969, 3148801, 12589057};
static const int multires_side_tot[] = {2, 3, 5, 9, 17, 33, 65, 129, 257, 513, 1025, 2049, 4097};
+void multiresModifier_join(Object *ob)
+{
+ Base *base = NULL;
+ int highest_lvl = 0;
+
+ /* First find the highest level of subdivision */
+ base = FIRSTBASE;
+ while(base) {
+ if(TESTBASELIB_BGMODE(base) && base->object->type==OB_MESH) {
+ ModifierData *md;
+ for(md = base->object->modifiers.first; md; md = md->next) {
+ if(md->type == eModifierType_Multires) {
+ int totlvl = ((MultiresModifierData*)md)->totlvl;
+ if(totlvl > highest_lvl)
+ highest_lvl = totlvl;
+
+ /* Ensure that all updates are processed */
+ multires_force_update(base->object);
+ }
+ }
+ }
+ base = base->next;
+ }
+
+ /* No multires meshes selected */
+ if(highest_lvl == 0)
+ return;
+
+ /* Subdivide all the displacements to the highest level */
+ base = FIRSTBASE;
+ while(base) {
+ if(TESTBASELIB_BGMODE(base) && base->object->type==OB_MESH) {
+ ModifierData *md = NULL;
+ MultiresModifierData *mmd = NULL;
+
+ for(md = base->object->modifiers.first; md; md = md->next) {
+ if(md->type == eModifierType_Multires)
+ mmd = (MultiresModifierData*)md;
+ }
+
+ /* If the object didn't have multires enabled, give it a new modifier */
+ if(!mmd) {
+ ModifierData *md = base->object->modifiers.first;
+
+ while(md && modifierType_getInfo(md->type)->type == eModifierTypeType_OnlyDeform)
+ md = md->next;
+
+ mmd = (MultiresModifierData*)modifier_new(eModifierType_Multires);
+ BLI_insertlinkbefore(&base->object->modifiers, md, mmd);
+ }
+
+ if(mmd) {
+ int i;
+
+ /* TODO: subdivision should be doable in one step rather than iteratively. */
+ for(i = mmd->totlvl; i < highest_lvl; ++i)
+ multiresModifier_subdivide(mmd, base->object);
+ }
+ }
+ base = base->next;
+ }
+}
+
static void Mat3FromColVecs(float mat[][3], float v1[3], float v2[3], float v3[3])
{
VecCopyf(mat[0], v1);
Modified: branches/soc-2008-nicholasbishop/source/blender/src/meshtools.c
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/src/meshtools.c 2008-07-22 23:05:06 UTC (rev 15702)
+++ branches/soc-2008-nicholasbishop/source/blender/src/meshtools.c 2008-07-22 23:48:18 UTC (rev 15703)
@@ -72,6 +72,7 @@
#include "BKE_main.h"
#include "BKE_mesh.h"
#include "BKE_material.h"
+#include "BKE_multires.h"
#include "BKE_object.h"
#include "BKE_utildefines.h"
@@ -125,7 +126,7 @@
MFace *mface = NULL, *mfacemain;
float imat[4][4], cmat[4][4];
int a, b, totcol, totedge=0, totvert=0, totface=0, ok=0, vertofs, map[MAXMAT];
- int i, j, index, haskey=0, hasmulti=0, edgeofs, faceofs;
+ int i, j, index, haskey=0, hasmulti=0, edgeofs, faceofs;
bDeformGroup *dg, *odg;
MDeformVert *dvert;
CustomData vdata, edata, fdata;
@@ -265,6 +266,9 @@
base= base->next;
}
+ /* For multires, need to unify the modifiers to ensure displacements aren't destroyed */
+ multiresModifier_join(ob);
+
me= ob->data;
memset(&vdata, 0, sizeof(vdata));
More information about the Bf-blender-cvs
mailing list