Partial fix for [#20166] Snap to grid issues
authorMartin Poirier <theeth@yahoo.com>
Sun, 27 Dec 2009 18:09:17 +0000 (18:09 +0000)
committerMartin Poirier <theeth@yahoo.com>
Sun, 27 Dec 2009 18:09:17 +0000 (18:09 +0000)
Move gridview (the actual drawn grid size, including adaptation to zoom) to RegionView3D from View3D.

This solves the transform increment bug but not the Snap Menu bug (context is not set to the correct rv3d when executing operator from menu).

source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/space_view3d/view3d_snap.c
source/blender/editors/transform/transform.c
source/blender/makesdna/DNA_view3d_types.h

index be607d7ea778bdaeff65141e1b61bbf56d60d02b..2cef7461e851cc9e41b314aaeeef0f5ac6c5949e 100644 (file)
@@ -307,7 +307,7 @@ static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, char **grid_u
                                /* Store the smallest drawn grid size units name so users know how big each grid cell is */
                                if(*grid_unit==NULL) {
                                        *grid_unit= bUnit_GetNameDisplay(usys, i);
-                                       v3d->gridview= (scalar * unit->scale_length);
+                                       rv3d->gridview= (scalar * unit->scale_length);
                                }
                                blend_fac= 1-((GRID_MIN_PX*2)/dx_scalar);
 
@@ -326,15 +326,15 @@ static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, char **grid_u
                short sublines = v3d->gridsubdiv;
 
                if(dx<GRID_MIN_PX) {
-                       v3d->gridview*= sublines;
+                       rv3d->gridview*= sublines;
                        dx*= sublines;
                        
                        if(dx<GRID_MIN_PX) {
-                               v3d->gridview*= sublines;
+                               rv3d->gridview*= sublines;
                                dx*= sublines;
 
                                if(dx<GRID_MIN_PX) {
-                                       v3d->gridview*= sublines;
+                                       rv3d->gridview*= sublines;
                                        dx*=sublines;
                                        if(dx<GRID_MIN_PX);
                                        else {
@@ -360,10 +360,10 @@ static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, char **grid_u
                }
                else {
                        if(dx>(GRID_MIN_PX*10)) {               // start blending in
-                               v3d->gridview/= sublines;
+                               rv3d->gridview/= sublines;
                                dx/= sublines;
                                if(dx>(GRID_MIN_PX*10)) {               // start blending in
-                                       v3d->gridview/= sublines;
+                                       rv3d->gridview/= sublines;
                                        dx/= sublines;
                                        if(dx>(GRID_MIN_PX*10)) {
                                                UI_ThemeColor(TH_GRID);
@@ -2034,7 +2034,7 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar)
                v3d->zbuf= FALSE;
        
        // needs to be done always, gridview is adjusted in drawgrid() now
-       v3d->gridview= v3d->grid;
+       rv3d->gridview= v3d->grid;
        
        if(rv3d->view==0 || rv3d->persp!=0) {
                drawfloor(scene, v3d);
index 3147abd499b7328bec256f54ec6ef54beb6271f8..b56a853d5b785aaaa256116bb0566bb2bd4378f2 100644 (file)
@@ -440,12 +440,12 @@ static int snap_sel_to_grid(bContext *C, wmOperator *op)
        extern float originmat[3][3];   /* XXX object.c */
        Object *obedit= CTX_data_edit_object(C);
        Scene *scene= CTX_data_scene(C);
-       View3D *v3d= CTX_wm_view3d(C);
+       RegionView3D *rv3d= CTX_wm_region_data(C);
        TransVert *tv;
        float gridf, imat[3][3], bmat[3][3], vec[3];
        int a;
 
-       gridf= v3d->gridview;
+       gridf= rv3d->gridview;
 
        if(obedit) {
                tottrans= 0;
@@ -463,9 +463,9 @@ static int snap_sel_to_grid(bContext *C, wmOperator *op)
                        VECCOPY(vec, tv->loc);
                        mul_m3_v3(bmat, vec);
                        add_v3_v3v3(vec, vec, obedit->obmat[3]);
-                       vec[0]= v3d->gridview*floor(.5+ vec[0]/gridf);
-                       vec[1]= v3d->gridview*floor(.5+ vec[1]/gridf);
-                       vec[2]= v3d->gridview*floor(.5+ vec[2]/gridf);
+                       vec[0]= gridf*floor(.5+ vec[0]/gridf);
+                       vec[1]= gridf*floor(.5+ vec[1]/gridf);
+                       vec[2]= gridf*floor(.5+ vec[2]/gridf);
                        sub_v3_v3v3(vec, vec, obedit->obmat[3]);
                        
                        mul_m3_v3(imat, vec);
@@ -518,9 +518,9 @@ static int snap_sel_to_grid(bContext *C, wmOperator *op)
                        else {
                                ob->recalc |= OB_RECALC_OB;
                                
-                               vec[0]= -ob->obmat[3][0]+v3d->gridview*floor(.5+ ob->obmat[3][0]/gridf);
-                               vec[1]= -ob->obmat[3][1]+v3d->gridview*floor(.5+ ob->obmat[3][1]/gridf);
-                               vec[2]= -ob->obmat[3][2]+v3d->gridview*floor(.5+ ob->obmat[3][2]/gridf);
+                               vec[0]= -ob->obmat[3][0]+gridf*floor(.5+ ob->obmat[3][0]/gridf);
+                               vec[1]= -ob->obmat[3][1]+gridf*floor(.5+ ob->obmat[3][1]/gridf);
+                               vec[2]= -ob->obmat[3][2]+gridf*floor(.5+ ob->obmat[3][2]/gridf);
                                
                                if(ob->parent) {
                                        where_is_object(scene, ob);
@@ -696,15 +696,16 @@ void VIEW3D_OT_snap_selected_to_cursor(wmOperatorType *ot)
 static int snap_curs_to_grid(bContext *C, wmOperator *op)
 {
        Scene *scene= CTX_data_scene(C);
+       RegionView3D *rv3d= CTX_wm_region_data(C);
        View3D *v3d= CTX_wm_view3d(C);
        float gridf, *curs;
 
-       gridf= v3d->gridview;
+       gridf= rv3d->gridview;
        curs= give_cursor(scene, v3d);
 
-       curs[0]= v3d->gridview*floor(.5+curs[0]/gridf);
-       curs[1]= v3d->gridview*floor(.5+curs[1]/gridf);
-       curs[2]= v3d->gridview*floor(.5+curs[2]/gridf);
+       curs[0]= gridf*floor(.5+curs[0]/gridf);
+       curs[1]= gridf*floor(.5+curs[1]/gridf);
+       curs[2]= gridf*floor(.5+curs[2]/gridf);
        
        WM_event_add_notifier(C, NC_SCENE|ND_TRANSFORM, scene); // hrm
        
index 40db0f7b2721216388f6a5225ff294bdb308cd87..fa435f29773b4d305f4152e92e8ddfe95737ab66 100644 (file)
@@ -3083,10 +3083,10 @@ void initTranslation(TransInfo *t)
        t->ndof.axis = (t->flag & T_2D_EDIT)? 1|2: 1|2|4;
 
        if(t->spacetype == SPACE_VIEW3D) {
-               View3D *v3d = t->view;
+               RegionView3D *rv3d = t->ar->regiondata;
 
                t->snap[0] = 0.0f;
-               t->snap[1] = v3d->gridview * 1.0f;
+               t->snap[1] = rv3d->gridview * 1.0f;
                t->snap[2] = t->snap[1] * 0.1f;
        }
        else if(t->spacetype == SPACE_IMAGE) {
index 5326c17688dbefe4a64356b328c62a02a91200c3..1ea060c2eea43f7da42976e39bbd333ab257234e 100644 (file)
@@ -114,8 +114,9 @@ typedef struct RegionView3D {
        /* last view */
        float lviewquat[4];
        short lpersp, lview;
-       int pad3;
+       float gridview;
        
+
 } RegionView3D;
 
 /* 3D ViewPort Struct */
@@ -151,8 +152,10 @@ typedef struct View3D {
        
        short pivot_last; /* pivot_last is for rotating around the last edited element */
        
-       float lens, grid, gridview, padf, near, far;
-       float ofs[3];                   /* XXX depricated */
+       float lens, grid;
+       float gridview; /* XXX deprecated, now in RegionView3D */
+       float padf, near, far;
+       float ofs[3];                   /* XXX deprecated */
        float cursor[3];
 
        short gridlines, pad4;