diff options
Diffstat (limited to 'source/blender/editors/transform/transform_snap.c')
-rw-r--r-- | source/blender/editors/transform/transform_snap.c | 90 |
1 files changed, 38 insertions, 52 deletions
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 93403ea5817..778698d3060 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -48,7 +48,6 @@ #include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_blenlib.h" -#include "BLI_utildefines.h" //#include "BDR_drawobject.h" // @@ -106,19 +105,17 @@ float ResizeBetween(TransInfo *t, float p1[3], float p2[3]); /****************** IMPLEMENTATIONS *********************/ -#if 0 int BIF_snappingSupported(Object *obedit) { int status = 0; - if (obedit == NULL || ELEM4(obedit->type, OB_MESH, OB_ARMATURE, OB_CURVE, OB_LATTICE)) /* only support object mesh, armature, curves */ + if (obedit == NULL || ELEM3(obedit->type, OB_MESH, OB_ARMATURE, OB_CURVE)) /* only support object mesh, armature, curves */ { status = 1; } return status; } -#endif int validSnap(TransInfo *t) { @@ -136,30 +133,30 @@ void drawSnapping(const struct bContext *C, TransInfo *t) if (validSnap(t) && activeSnap(t)) { - unsigned char col[4]; + char col[4] = {1, 0, 1}; UI_GetThemeColor3ubv(TH_TRANSFORM, col); - col[3]= 128; - glColor4ubv(col); + glColor4ub(col[0], col[1], col[2], 128); if (t->spacetype == SPACE_VIEW3D) { TransSnapPoint *p; View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); - float imat[4][4]; + float tmat[4][4], imat[4][4]; float size; glDisable(GL_DEPTH_TEST); - size = 2.5f * UI_GetThemeValuef(TH_VERTEX_SIZE); - - invert_m4_m4(imat, rv3d->viewmat); + size = 0.5f * UI_GetThemeValuef(TH_VERTEX_SIZE); + + copy_m4_m4(tmat, rv3d->viewmat); + invert_m4_m4(imat, tmat); for (p = t->tsnap.points.first; p; p = p->next) { - drawcircball(GL_LINE_LOOP, p->co, view3d_pixel_size(rv3d, p->co) * size, imat); + drawcircball(GL_LINE_LOOP, p->co, size * get_drawsize(t->ar, p->co), imat); } if (t->tsnap.status & POINT_INIT) { - drawcircball(GL_LINE_LOOP, t->tsnap.snapPoint, view3d_pixel_size(rv3d, t->tsnap.snapPoint) * size, imat); + drawcircball(GL_LINE_LOOP, t->tsnap.snapPoint, size * get_drawsize(t->ar, t->tsnap.snapPoint), imat); } /* draw normal if needed */ @@ -214,7 +211,7 @@ void drawSnapping(const struct bContext *C, TransInfo *t) } } -int handleSnapping(TransInfo *UNUSED(t), wmEvent *UNUSED(event)) +int handleSnapping(TransInfo *t, wmEvent *event) { int status = 0; @@ -265,8 +262,6 @@ void applyProject(TransInfo *t) } else if (t->flag & T_OBJECT) { - td->ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME; - object_handle_update(t->scene, td->ob); VECCOPY(iloc, td->ob->obmat[3]); } @@ -376,10 +371,9 @@ void initSnappingMode(TransInfo *t) /* Edit mode */ if (t->tsnap.applySnap != NULL && // A snapping function actually exist - (obedit != NULL && ELEM4(obedit->type, OB_MESH, OB_ARMATURE, OB_CURVE, OB_LATTICE)) ) // Temporary limited to edit mode meshes, armature, curves + (obedit != NULL && ELEM3(obedit->type, OB_MESH, OB_ARMATURE, OB_CURVE)) ) // Temporary limited to edit mode meshes, armature, curves { - /* editmode meshes now supported */ - if ((obedit->type != OB_MESH) && ((t->flag & T_PROP_EDIT) || t->tsnap.project)) /* also exclude edit for project, for now */ + if ((t->flag & T_PROP_EDIT) || t->tsnap.project) /* also exclude edit for project, for now */ { t->tsnap.modeSelect = SNAP_NOT_OBEDIT; } @@ -603,7 +597,7 @@ void ApplySnapResize(TransInfo *t, float vec[3]) /********************** DISTANCE **************************/ -float TranslationBetween(TransInfo *UNUSED(t), float p1[3], float p2[3]) +float TranslationBetween(TransInfo *t, float p1[3], float p2[3]) { return len_v3v3(p1, p2); } @@ -687,12 +681,12 @@ float ResizeBetween(TransInfo *t, float p1[3], float p2[3]) /********************** CALC **************************/ -void CalcSnapGrid(TransInfo *t, float *UNUSED(vec)) +void CalcSnapGrid(TransInfo *t, float *vec) { snapGridAction(t, t->tsnap.snapPoint, BIG_GEARS); } -void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec)) +void CalcSnapGeometry(TransInfo *t, float *vec) { if (t->spacetype == SPACE_VIEW3D) { @@ -710,7 +704,7 @@ void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec)) ListBase depth_peels; DepthPeel *p1, *p2; float *last_p = NULL; - float max_dist = FLT_MAX; + float dist = FLT_MAX; float p[3] = {0.0f, 0.0f, 0.0f}; depth_peels.first = depth_peels.last = NULL; @@ -774,27 +768,23 @@ void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec)) if (last_p == NULL) { VECCOPY(p, vec); - max_dist = 0; + dist = 0; break; } new_dist = len_v3v3(last_p, vec); - if (new_dist < max_dist) + if (new_dist < dist) { VECCOPY(p, vec); - max_dist = new_dist; + dist = new_dist; } } } - if (max_dist != FLT_MAX) + if (dist != FLT_MAX) { VECCOPY(loc, p); - /* XXX, is there a correct normal in this case ???, for now just z up */ - no[0]= 0.0; - no[1]= 0.0; - no[2]= 1.0; found = 1; } @@ -1201,7 +1191,7 @@ int snapVertex(ARegion *ar, float vco[3], short vno[3], float mval[2], float ray return retval; } -int snapArmature(short snap_mode, ARegion *ar, Object *ob, bArmature *arm, float obmat[][4], float ray_start[3], float ray_normal[3], float mval[2], float *loc, float *UNUSED(no), int *dist, float *depth) +int snapArmature(short snap_mode, ARegion *ar, Object *ob, bArmature *arm, float obmat[][4], float ray_start[3], float ray_normal[3], float mval[2], float *loc, float *no, int *dist, float *depth) { float imat[4][4]; float ray_start_local[3], ray_normal_local[3]; @@ -1271,7 +1261,7 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E int retval = 0; int totvert = dm->getNumVerts(dm); int totface = dm->getNumFaces(dm); - + if (totvert > 0) { float imat[4][4]; float timat[3][3]; /* transpose inverse matrix for normals */ @@ -1308,19 +1298,15 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E BVHTreeRayHit hit; BVHTreeFromMesh treeData; - /* local scale in normal direction */ - float local_scale = len_v3(ray_normal_local); - - treeData.em_evil= em; bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 4, 6); hit.index = -1; - hit.dist = *depth * (*depth == FLT_MAX ? 1.0f : local_scale); + hit.dist = *depth; if(treeData.tree && BLI_bvhtree_ray_cast(treeData.tree, ray_start_local, ray_normal_local, 0.0f, &hit, treeData.raycast_callback, &treeData) != -1) { - if(hit.dist/local_scale <= *depth) { - *depth= hit.dist/local_scale; + if(hit.dist<=*depth) { + *depth= hit.dist; copy_v3_v3(loc, hit.co); copy_v3_v3(no, hit.no); @@ -1546,8 +1532,7 @@ int snapObject(Scene *scene, ARegion *ar, Object *ob, int editobject, float obma if (editobject) { em = ((Mesh *)ob->data)->edit_mesh; - /* dm = editmesh_get_derived_cage(scene, ob, em, CD_MASK_BAREMESH); */ - dm = editmesh_get_derived_base(ob, em); /* limitation, em & dm MUST have the same number of faces */ + dm = editmesh_get_derived_cage(scene, ob, em, CD_MASK_BAREMESH); } else { @@ -1593,9 +1578,10 @@ int snapObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, float mv Object *ob = base->object; retval |= snapObject(scene, ar, ob, 0, ob->obmat, ray_start, ray_normal, mval, loc, no, dist, &depth); } - + + base= FIRSTBASE; for ( base = FIRSTBASE; base != NULL; base = base->next ) { - if ( BASE_VISIBLE(v3d, base) && (base->flag & (BA_HAS_RECALC_OB|BA_HAS_RECALC_DATA)) == 0 && ((mode == SNAP_NOT_SELECTED && (base->flag & (SELECT|BA_WAS_SEL)) == 0) || (ELEM(mode, SNAP_ALL, SNAP_NOT_OBEDIT) && base != BASACT)) ) { + if ( BASE_SELECTABLE(v3d, base) && (base->flag & (BA_HAS_RECALC_OB|BA_HAS_RECALC_DATA)) == 0 && ((mode == SNAP_NOT_SELECTED && (base->flag & (SELECT|BA_WAS_SEL)) == 0) || (ELEM(mode, SNAP_ALL, SNAP_NOT_OBEDIT) && base != BASACT)) ) { Object *ob = base->object; if (ob->transflag & OB_DUPLI) @@ -1690,7 +1676,7 @@ void addDepthPeel(ListBase *depth_peels, float depth, float p[3], float no[3], O peel->flag = 0; } -int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[][4], float ray_start[3], float ray_normal[3], float UNUSED(mval[2]), ListBase *depth_peels) +int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[][4], float ray_start[3], float ray_normal[3], float mval[2], ListBase *depth_peels) { int retval = 0; int totvert = dm->getNumVerts(dm); @@ -1817,25 +1803,25 @@ int peelObjects(Scene *scene, View3D *v3d, ARegion *ar, Object *obedit, ListBase for(dupli_ob = lb->first; dupli_ob; dupli_ob = dupli_ob->next) { - Object *dob = dupli_ob->ob; + Object *ob = dupli_ob->ob; - if (dob->type == OB_MESH) { + if (ob->type == OB_MESH) { EditMesh *em; DerivedMesh *dm = NULL; int val; - if (dob != obedit) + if (ob != obedit) { - dm = mesh_get_derived_final(scene, dob, CD_MASK_BAREMESH); + dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); - val = peelDerivedMesh(dob, dm, dob->obmat, ray_start, ray_normal, mval, depth_peels); + val = peelDerivedMesh(ob, dm, ob->obmat, ray_start, ray_normal, mval, depth_peels); } else { - em = ((Mesh *)dob->data)->edit_mesh; + em = ((Mesh *)ob->data)->edit_mesh; dm = editmesh_get_derived_cage(scene, obedit, em, CD_MASK_BAREMESH); - val = peelDerivedMesh(dob, dm, dob->obmat, ray_start, ray_normal, mval, depth_peels); + val = peelDerivedMesh(ob, dm, ob->obmat, ray_start, ray_normal, mval, depth_peels); } retval = retval || val; |