[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40249] branches/bmesh/blender/source/ blender/modifiers/intern/MOD_mirror.c: Fix mirror modifier for mirroring relative to another object
Andrew Wiggin
ender79bl at gmail.com
Fri Sep 16 06:14:47 CEST 2011
Revision: 40249
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40249
Author: ender79
Date: 2011-09-16 04:14:46 +0000 (Fri, 16 Sep 2011)
Log Message:
-----------
Fix mirror modifier for mirroring relative to another object
Modified Paths:
--------------
branches/bmesh/blender/source/blender/modifiers/intern/MOD_mirror.c
Modified: branches/bmesh/blender/source/blender/modifiers/intern/MOD_mirror.c
===================================================================
--- branches/bmesh/blender/source/blender/modifiers/intern/MOD_mirror.c 2011-09-16 02:42:50 UTC (rev 40248)
+++ branches/bmesh/blender/source/blender/modifiers/intern/MOD_mirror.c 2011-09-16 04:14:46 UTC (rev 40249)
@@ -48,6 +48,9 @@
#include "depsgraph_private.h"
+/*from MOD_array.c*/
+void vertgroup_flip_name (char *name, int strip_number);
+
static void initData(ModifierData *md)
{
MirrorModifierData *mmd = (MirrorModifierData*) md;
@@ -65,7 +68,7 @@
tmmd->axis = mmd->axis;
tmmd->flag = mmd->flag;
tmmd->tolerance = mmd->tolerance;
- tmmd->mirror_ob = mmd->mirror_ob;;
+ tmmd->mirror_ob = mmd->mirror_ob;
}
static void foreachObjectLink(
@@ -96,18 +99,17 @@
/* Mirror */
#define VERT_NEW 1
-void vertgroup_flip_name (char *name, int strip_number);
DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
Object *ob,
DerivedMesh *dm,
int UNUSED(initFlags),
int axis)
{
- float tolerance = mmd->tolerance;
+ float tolerance_sq;
DerivedMesh *cddm, *origdm;
bDeformGroup *def, *defb;
bDeformGroup **vector_def = NULL;
- MVert *mv;
+ MVert *mv, *ov;
MEdge *me;
MLoop *ml;
MPoly *mp;
@@ -115,6 +117,8 @@
int i, j, *vtargetmap = NULL;
BLI_array_declare(vtargetmap);
int vector_size=0, a, b, totshape;
+
+ tolerance_sq = mmd->tolerance * mmd->tolerance;
origdm = dm;
if (!CDDM_Check(dm))
@@ -134,13 +138,27 @@
}
}
+ /*mtx is the mirror transformation*/
+ unit_m4(mtx);
+ mtx[axis][axis] = -1.0;
+
if (mmd->mirror_ob) {
- float mtx2[4][4];
+ float tmp[4][4];
+ float itmp[4][4];
- invert_m4_m4(mtx2, mmd->mirror_ob->obmat);
- mul_m4_m4m4(mtx, ob->obmat, mtx2);
- } else {
- unit_m4(mtx);
+ /*tmp is a transform from coords relative to the object's own origin, to
+ coords relative to the mirror object origin*/
+ invert_m4_m4(tmp, mmd->mirror_ob->obmat);
+ mul_m4_m4m4(tmp, ob->obmat, tmp);
+
+ /*itmp is the reverse transform back to origin-relative coordiantes*/
+ invert_m4_m4(itmp, tmp);
+
+ /*combine matrices to get a single matrix that translates coordinates into
+ mirror-object-relative space, does the mirror, and translates back to
+ origin-relative space*/
+ mul_m4_m4m4(mtx, tmp, mtx);
+ mul_m4_m4m4(mtx, mtx, itmp);
}
cddm = CDDM_from_template(dm, dm->numVertData*2, dm->numEdgeData*2, 0, dm->numLoopData*2, dm->numPolyData*2);
@@ -157,12 +175,18 @@
CustomData_copy_data(&dm->polyData, &cddm->polyData, 0, dm->numPolyData, dm->numPolyData);
/*mirror vertex coordinates*/
- mv = CDDM_get_verts(cddm) + dm->numVertData;
- for (i=0; i<dm->numVertData; i++, mv++) {
- mv->co[axis] = -mv->co[axis];
- if (fabs(mv->co[axis]) < tolerance) {
+ ov = CDDM_get_verts(cddm);
+ mv = ov + dm->numVertData;
+ for (i=0; i<dm->numVertData; i++, mv++, ov++) {
+ mul_m4_v3(mtx, mv->co);
+ /*compare location of the original and mirrored vertex, to see if they
+ should be mapped for merging*/
+ if (len_squared_v3v3(ov->co, mv->co) < tolerance_sq) {
BLI_array_append(vtargetmap, i+dm->numVertData);
- } else BLI_array_append(vtargetmap, -1);
+ }
+ else {
+ BLI_array_append(vtargetmap, -1);
+ }
}
/*handle shape keys*/
@@ -170,7 +194,7 @@
for (a=0; a<totshape; a++) {
float (*cos)[3] = CustomData_get_layer_n(&cddm->vertData, CD_SHAPEKEY, a);
for (i=dm->numVertData; i<cddm->numVertData; i++) {
- cos[i][axis] = -cos[i][axis];
+ mul_m4_v3(mtx, cos[i]);
}
}
More information about the Bf-blender-cvs
mailing list