2.5
authorTon Roosendaal <ton@blender.org>
Mon, 19 Jan 2009 16:54:41 +0000 (16:54 +0000)
committerTon Roosendaal <ton@blender.org>
Mon, 19 Jan 2009 16:54:41 +0000 (16:54 +0000)
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:

- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes

Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).

To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.

Note about the code:
- currently view3d still stores some depricated settings, to
  convert from older files. Not all settings are copied over
  though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
  for it should keep track of that.

Bugfix in transform: quat initialize in operator-invoke missed
one zero.

Als brought back GE to compile for missing Ipos and channels.

53 files changed:
source/blender/blenkernel/BKE_context.h
source/blender/blenkernel/BKE_screen.h
source/blender/blenkernel/intern/context.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/screen.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/armature/editarmature.c
source/blender/editors/curve/editcurve.c
source/blender/editors/gpencil/gpencil.c
source/blender/editors/include/ED_object.h
source/blender/editors/include/ED_screen.h
source/blender/editors/include/ED_view3d.h
source/blender/editors/interface/interface_regions.c
source/blender/editors/mesh/editface.c
source/blender/editors/mesh/editmesh_add.c
source/blender/editors/mesh/editmesh_mods.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/mesh/meshtools.c
source/blender/editors/object/object_edit.c
source/blender/editors/screen/area.c
source/blender/editors/screen/screen_ops.c
source/blender/editors/sculpt/sculpt.c
source/blender/editors/space_api/spacetypes.c
source/blender/editors/space_view3d/drawarmature.c
source/blender/editors/space_view3d/drawmesh.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/space_view3d/view3d_header.c
source/blender/editors/space_view3d/view3d_intern.h
source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/space_view3d/view3d_view.c
source/blender/editors/space_view3d/vpaint.c
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform.h
source/blender/editors/transform/transform_constraints.c
source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_generics.c
source/blender/editors/transform/transform_manipulator.c
source/blender/editors/transform/transform_ops.c
source/blender/editors/transform/transform_orientations.c
source/blender/editors/transform/transform_snap.c
source/blender/gpu/GPU_draw.h
source/blender/gpu/intern/gpu_draw.c
source/blender/makesdna/DNA_object_types.h
source/blender/makesdna/DNA_screen_types.h
source/blender/makesdna/DNA_view3d_types.h
source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
source/gameengine/Converter/BL_ShapeActionActuator.cpp
source/gameengine/Converter/BL_ShapeDeformer.cpp
source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp

index 7d6542ada0816c9cbd5e4197b0c5686c44f04f13..160736d4a940b8f2188027b1a1acdc5303d6aeaa 100644 (file)
@@ -45,6 +45,8 @@ struct ReportList;
 struct Scene;
 struct ScrArea;
 struct SpaceLink;
+struct View3D;
+struct RegionView3D;
 struct StructRNA;
 struct ToolSettings;
 struct Image;
@@ -96,6 +98,7 @@ struct bScreen *CTX_wm_screen(const bContext *C);
 struct ScrArea *CTX_wm_area(const bContext *C);
 struct SpaceLink *CTX_wm_space_data(const bContext *C);
 struct View3D *CTX_wm_view3d(const bContext *C);
+struct RegionView3D *CTX_wm_region_view3d(const bContext *C);
 struct ARegion *CTX_wm_region(const bContext *C);
 void *CTX_wm_region_data(const bContext *C);
 struct uiBlock *CTX_wm_ui_block(const bContext *C);
index 7604dc8170b5605dded61ba10c4aa6937b8786c2..a2e9329a18adbd8f86cdcf35cd7e93ce741f8dcb 100644 (file)
@@ -105,6 +105,10 @@ typedef struct ARegionType {
        
        void            (*free)(struct ARegion *);
 
+       /* split region, copy data optionally */
+       void            *(*duplicate)(void *);
+
+       
        /* register operator types on startup */
        void            (*operatortypes)(void);
        /* add own items to keymap */
@@ -127,6 +131,7 @@ typedef struct ARegionType {
 
 /* spacetypes */
 struct SpaceType *BKE_spacetype_from_id(int spaceid);
+struct ARegionType *BKE_regiontype_from_id(struct SpaceType *st, int regionid);
 const struct ListBase *BKE_spacetypes_list(void);
 void BKE_spacetype_register(struct SpaceType *st);
 void BKE_spacetypes_free(void);        /* only for quitting blender */
@@ -136,8 +141,8 @@ void BKE_spacedata_freelist(ListBase *lb);
 void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2);
 
 /* area/regions */
-struct ARegion *BKE_area_region_copy(struct ARegion *ar);
-void   BKE_area_region_free(struct ARegion *ar);
+struct ARegion *BKE_area_region_copy(struct SpaceType *st, struct ARegion *ar);
+void   BKE_area_region_free(struct SpaceType *st, struct ARegion *ar);
 
 void BKE_screen_area_free(struct ScrArea *sa);
 
index 1fd569e10819ef22f65001ccac548068b4d082fb..81712acee5c574caf453f812924d2dc0ec8435e2 100644 (file)
@@ -171,6 +171,13 @@ View3D *CTX_wm_view3d(const bContext *C)
        return NULL;
 }
 
+RegionView3D *CTX_wm_region_view3d(const bContext *C)
+{
+       if(C->wm.area && C->wm.area->spacetype==SPACE_VIEW3D)
+               if(C->wm.region)
+                       return C->wm.region->regiondata;
+       return NULL;
+}
 
 ARegion *CTX_wm_region(const bContext *C)
 {
index 8b3f495e495ee09a941648428081413a0d0b1113..2718981e39856d6906b304c22ff2f3dc7e38a6fe 100644 (file)
@@ -546,11 +546,11 @@ void unlink_object(Scene *scene, Object *ob)
 
                                        if(v3d->camera==ob) {
                                                v3d->camera= NULL;
-                                               if(v3d->persp==V3D_CAMOB) v3d->persp= V3D_PERSP;
+                                               // XXX if(v3d->persp==V3D_CAMOB) v3d->persp= V3D_PERSP;
                                        }
                                        if(v3d->localvd && v3d->localvd->camera==ob ) {
                                                v3d->localvd->camera= NULL;
-                                               if(v3d->localvd->persp==V3D_CAMOB) v3d->localvd->persp= V3D_PERSP;
+                                               // XXX if(v3d->localvd->persp==V3D_CAMOB) v3d->localvd->persp= V3D_PERSP;
                                        }
                                }
                                else if(sl->spacetype==SPACE_OOPS) {
index fd15c69e775af9a4ccd9e4e8d60c25cea2f8d46f..a596827f4705e07b0ed06f5e0b089c2778461d74 100644 (file)
@@ -82,6 +82,19 @@ SpaceType *BKE_spacetype_from_id(int spaceid)
        return NULL;
 }
 
+ARegionType *BKE_regiontype_from_id(SpaceType *st, int regionid)
+{
+       ARegionType *art;
+       
+       for(art= st->regiontypes.first; art; art= art->next)
+               if(art->regionid==regionid)
+                       return art;
+       
+       printf("Error, region type missing in %s\n", st->name);
+       return st->regiontypes.first;
+}
+
+
 const ListBase *BKE_spacetypes_list()
 {
        return &spacetypes;
@@ -113,9 +126,9 @@ void BKE_spacedata_freelist(ListBase *lb)
                SpaceType *st= BKE_spacetype_from_id(sl->spacetype);
                
                /* free regions for pushed spaces */
-               for(ar=sl->regionbase.first; ar; ar=ar->next) {
-                       BKE_area_region_free(ar);
-               }
+               for(ar=sl->regionbase.first; ar; ar=ar->next)
+                       BKE_area_region_free(st, ar);
+
                BLI_freelistN(&sl->regionbase);
                
                if(st && st->free) 
@@ -125,19 +138,26 @@ void BKE_spacedata_freelist(ListBase *lb)
        BLI_freelistN(lb);
 }
 
-ARegion *BKE_area_region_copy(ARegion *ar)
+ARegion *BKE_area_region_copy(SpaceType *st, ARegion *ar)
 {
        ARegion *newar= MEM_dupallocN(ar);
        Panel *pa, *newpa, *patab;
        
+       newar->prev= newar->next= NULL;
        newar->handlers.first= newar->handlers.last= NULL;
        newar->uiblocks.first= newar->uiblocks.last= NULL;
        newar->swinid= 0;
        
-       /* XXX regiondata callback */
-       if(ar->regiondata)
-               newar->regiondata= MEM_dupallocN(ar->regiondata);
+       /* use optional regiondata callback */
+       if(ar->regiondata) {
+               ARegionType *art= BKE_regiontype_from_id(st, ar->regiontype);
 
+               if(art && art->duplicate)
+                       newar->regiondata= art->duplicate(ar->regiondata);
+               else
+                       newar->regiondata= MEM_dupallocN(ar->regiondata);
+       }
+       
        newar->panels.first= newar->panels.last= NULL;
        BLI_duplicatelist(&newar->panels, &ar->panels);
        
@@ -160,7 +180,7 @@ ARegion *BKE_area_region_copy(ARegion *ar)
 
 
 /* from lb2 to lb1, lb1 is supposed to be free'd */
-static void region_copylist(ListBase *lb1, ListBase *lb2)
+static void region_copylist(SpaceType *st, ListBase *lb1, ListBase *lb2)
 {
        ARegion *ar;
        
@@ -168,7 +188,7 @@ static void region_copylist(ListBase *lb1, ListBase *lb2)
        lb1->first= lb1->last= NULL;
        
        for(ar= lb2->first; ar; ar= ar->next) {
-               ARegion *arnew= BKE_area_region_copy(ar);
+               ARegion *arnew= BKE_area_region_copy(st, ar);
                BLI_addtail(lb1, arnew);
        }
 }
@@ -189,18 +209,21 @@ void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2)
                        
                        BLI_addtail(lb1, slnew);
                        
-                       region_copylist(&slnew->regionbase, &sl->regionbase);
+                       region_copylist(st, &slnew->regionbase, &sl->regionbase);
                }
        }
 }
 
 /* not region itself */
-void BKE_area_region_free(ARegion *ar)
+void BKE_area_region_free(SpaceType *st, ARegion *ar)
 {
+       if(st) {
+               ARegionType *art= BKE_regiontype_from_id(st, ar->regiontype);
+               
+               if(art && art->free)
+                       art->free(ar);
+       }
        if(ar) {
-               if(ar->type && ar->type->free)
-                       ar->type->free(ar);
-
                BLI_freelistN(&ar->panels);
        }
 }
@@ -208,16 +231,16 @@ void BKE_area_region_free(ARegion *ar)
 /* not area itself */
 void BKE_screen_area_free(ScrArea *sa)
 {
-       ARegion *ar, *arn;
+       SpaceType *st= BKE_spacetype_from_id(sa->spacetype);
+       ARegion *ar;
        
-       for(ar=sa->regionbase.first; ar; ar=arn) {
-               arn= ar->next;
-               BKE_area_region_free(ar);
-       }
+       for(ar=sa->regionbase.first; ar; ar=ar->next)
+               BKE_area_region_free(st, ar);
 
+       BLI_freelistN(&sa->regionbase);
+       
        BKE_spacedata_freelist(&sa->spacedata);
        
-       BLI_freelistN(&sa->regionbase);
        BLI_freelistN(&sa->actionzones);
        
 #ifndef DISABLE_PYTHON
@@ -229,12 +252,11 @@ void BKE_screen_area_free(ScrArea *sa)
 void free_screen(bScreen *sc)
 {
        ScrArea *sa, *san;
-       ARegion *ar, *arn;
+       ARegion *ar;
        
-       for(ar=sc->regionbase.first; ar; ar=arn) {
-               arn= ar->next;
-               BKE_area_region_free(ar);
-       }
+       for(ar=sc->regionbase.first; ar; ar=ar->next)
+               BKE_area_region_free(NULL, ar);
+
        BLI_freelistN(&sc->regionbase);
        
        for(sa= sc->areabase.first; sa; sa= san) {
index eb1693cd22e4fe3411505ba248e73d4c7578951d..13e7bf91c739ad950132f7014c6271f58439024d 100644 (file)
@@ -4101,8 +4101,6 @@ static void lib_link_screen(FileData *fd, Main *main)
                                                if(v3d->localvd) {
                                                        v3d->localvd->camera= newlibadr(fd, sc->id.lib, v3d->localvd->camera);
                                                }
-                                               v3d->depths= NULL;
-                                               v3d->ri= NULL;
                                        }
                                        else if(sl->spacetype==SPACE_IPO) {
                                                SpaceIpo *sipo= (SpaceIpo *)sl;
@@ -4409,7 +4407,7 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
        }
 }
 
-static void direct_link_region(FileData *fd, ARegion *ar)
+static void direct_link_region(FileData *fd, ARegion *ar, int spacetype)
 {
        Panel *pa;
 
@@ -4421,15 +4419,51 @@ static void direct_link_region(FileData *fd, ARegion *ar)
                pa->sortcounter= 0;
                pa->activedata= NULL;
        }
-
+       
+       ar->regiondata= newdataadr(fd, ar->regiondata);
+       if(ar->regiondata) {
+               if(spacetype==SPACE_VIEW3D) {
+                       RegionView3D *rv3d= ar->regiondata;
+                       
+                       rv3d->localvd= newdataadr(fd, rv3d->localvd);
+                       rv3d->clipbb= newdataadr(fd, rv3d->clipbb);
+                       
+                       rv3d->depths= NULL;
+                       rv3d->retopo_view_data= NULL;
+                       rv3d->ri= NULL;
+                       rv3d->sms= NULL;
+                       rv3d->smooth_timer= NULL;
+               }
+       }
+       
        ar->handlers.first= ar->handlers.last= NULL;
        ar->uiblocks.first= ar->uiblocks.last= NULL;
        ar->headerstr= NULL;
-       ar->regiondata= NULL;
        ar->swinid= 0;
        ar->type= NULL;
 }
 
+/* for the saved 2.50 files without regiondata */
+/* and as patch for 2.48 and older */
+static void view3d_split_250(View3D *v3d, ListBase *regions)
+{
+       ARegion *ar;
+       
+       for(ar= regions->first; ar; ar= ar->next) {
+               if(ar->regiontype==RGN_TYPE_WINDOW && ar->regiondata==NULL) {
+                       RegionView3D *rv3d;
+                       
+                       rv3d= ar->regiondata= MEM_callocN(sizeof(RegionView3D), "region v3d");
+                       rv3d->persp= v3d->persp;
+                       rv3d->view= v3d->view;
+                       rv3d->dist= v3d->dist;
+                       VECCOPY(rv3d->ofs, v3d->ofs);
+                       QUATCOPY(rv3d->viewquat, v3d->viewquat);
+                       Mat4One(rv3d->twmat);
+               }
+       }
+}
+
 static void direct_link_screen(FileData *fd, bScreen *sc)
 {
        ScrArea *sa;
@@ -4482,6 +4516,9 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                sa->handlers.first= sa->handlers.last= NULL;
                sa->type= NULL; /* spacetype callbacks */
                
+               for(ar= sa->regionbase.first; ar; ar= ar->next)
+                       direct_link_region(fd, ar, sa->spacetype);
+               
                /* accident can happen when read/save new file with older version */
                /* 2.50: we now always add spacedata for info */
                if(sa->spacedata.first==NULL) {
@@ -4489,12 +4526,15 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                        sa->spacetype= SPACE_INFO;
                        BLI_addtail(&sa->spacedata, sinfo);
                }
+               /* add local view3d too */
+               else if(sa->spacetype==SPACE_VIEW3D)
+                       view3d_split_250(sa->spacedata.first, &sa->regionbase);
                
                for (sl= sa->spacedata.first; sl; sl= sl->next) {
                        link_list(fd, &(sl->regionbase));
 
                        for(ar= sl->regionbase.first; ar; ar= ar->next)
-                               direct_link_region(fd, ar);
+                               direct_link_region(fd, ar, sl->spacetype);
 
                        if (sl->spacetype==SPACE_VIEW3D) {
                                View3D *v3d= (View3D*) sl;
@@ -4507,11 +4547,9 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                                }
                                v3d->localvd= newdataadr(fd, v3d->localvd);
                                v3d->afterdraw.first= v3d->afterdraw.last= NULL;
-                               v3d->clipbb= newdataadr(fd, v3d->clipbb);
-                               v3d->retopo_view_data= NULL;
                                v3d->properties_storage= NULL;
-                               v3d->sms= NULL;
-                               v3d->smooth_timer= NULL;
+                               
+                               view3d_split_250(v3d, &sl->regionbase);
                        }
                        else if (sl->spacetype==SPACE_OOPS) {
                                SpaceOops *soops= (SpaceOops*) sl;
@@ -4561,9 +4599,6 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                        }
                }
                
-               for(ar= sa->regionbase.first; ar; ar= ar->next)
-                       direct_link_region(fd, ar);
-               
                sa->actionzones.first= sa->actionzones.last= NULL;
 
                sa->v1= newdataadr(fd, sa->v1);
@@ -5412,7 +5447,12 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
        
        if(sl) {
                /* if active spacetype has view2d data, copy that over to main region */
+               /* and we split view3d */
                switch(sl->spacetype) {
+                       case SPACE_VIEW3D:
+                               view3d_split_250((View3D *)sl, lb);
+                               break;          
+                                               
                        case SPACE_OOPS:
                        {
                                SpaceOops *soops= (SpaceOops *)sl;
@@ -8679,7 +8719,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        if(ma->nodetree && strlen(ma->nodetree->id.name)==0)
                                strcpy(ma->nodetree->id.name, "NTShader Nodetree");
                }
-
                /* and composit trees */
                for(sce= main->scene.first; sce; sce= sce->id.next) {
                        if(sce->nodetree && strlen(sce->nodetree->id.name)==0)
index a6f470493c88a838bfb979f19d69e50a29e83e40..2f31320444b6916c54d1e0f6c894d89f0d90144f 100644 (file)
@@ -1692,6 +1692,32 @@ static void write_windowmanagers(WriteData *wd, ListBase *lb)
        }
 }
 
+static void write_region(WriteData *wd, ARegion *ar, int spacetype)
+{      
+       writestruct(wd, DATA, "ARegion", 1, ar);
+       
+       if(ar->regiondata) {
+               switch(spacetype) {
+                       case SPACE_VIEW3D:
+                               if(ar->regiontype==RGN_TYPE_WINDOW) {
+                                       RegionView3D *rv3d= ar->regiondata;
+                                       writestruct(wd, DATA, "RegionView3D", 1, rv3d);
+                                       
+                                       if(rv3d->localvd)
+                                               writestruct(wd, DATA, "RegionView3D", 1, rv3d->localvd);
+                                       if(rv3d->clipbb) 
+                                               writestruct(wd, DATA, "BoundBox", 1, rv3d->clipbb);
+
+                               }
+                               else
+                                       printf("regiondata write missing!\n");
+                               break;
+                       default:
+                               printf("regiondata write missing!\n");
+               }
+       }
+}
+
 static void write_screens(WriteData *wd, ListBase *scrbase)
 {
        bScreen *sc;
@@ -1723,7 +1749,7 @@ static void write_screens(WriteData *wd, ListBase *scrbase)
                        writestruct(wd, DATA, "ScrArea", 1, sa);
                        
                        for(ar= sa->regionbase.first; ar; ar= ar->next) {
-                               writestruct(wd, DATA, "ARegion", 1, ar);
+                               write_region(wd, ar, sa->spacetype);
                                
                                for(pa= ar->panels.first; pa; pa= pa->next)
                                        writestruct(wd, DATA, "Panel", 1, pa);
@@ -1735,14 +1761,13 @@ static void write_screens(WriteData *wd, ListBase *scrbase)
                        sl= sa->spacedata.first;
                        while(sl) {
                                for(ar= sl->regionbase.first; ar; ar= ar->next)
-                                       writestruct(wd, DATA, "ARegion", 1, ar);
+                                       write_region(wd, ar, sl->spacetype);
                                
                                if(sl->spacetype==SPACE_VIEW3D) {
                                        View3D *v3d= (View3D *) sl;
                                        writestruct(wd, DATA, "View3D", 1, v3d);
                                        if(v3d->bgpic) writestruct(wd, DATA, "BGpic", 1, v3d->bgpic);
                                        if(v3d->localvd) writestruct(wd, DATA, "View3D", 1, v3d->localvd);
-                                       if(v3d->clipbb) writestruct(wd, DATA, "BoundBox", 1, v3d->clipbb);
                                        if(v3d->gpd) write_gpencil(wd, v3d->gpd);
                                }
                                else if(sl->spacetype==SPACE_IPO) {
index 5a751236e6e61e3b93aea50ce188733fd655f01b..67b8f211eaad57a6feb8892d5857e38cd742cfb4 100644 (file)
@@ -2023,7 +2023,7 @@ static EditBone *add_editbone(Object *obedit, char *name)
        return bone;
 }
 
-static void add_primitive_bone(Scene *scene, View3D *v3d, short newob)
+static void add_primitive_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d, short newob)
 {
        Object *obedit= scene->obedit; // XXX get from context
        float           obmat[3][3], curs[3], viewmat[3][3], totmat[3][3], imat[3][3];
@@ -2035,7 +2035,8 @@ static void add_primitive_bone(Scene *scene, View3D *v3d, short newob)
        Mat4Invert(obedit->imat, obedit->obmat);
        Mat4MulVecfl(obedit->imat, curs);
 
-       if ( !(newob) || (U.flag & USER_ADD_VIEWALIGNED) ) Mat3CpyMat4(obmat, v3d->viewmat);
+       if ( !(newob) || (U.flag & USER_ADD_VIEWALIGNED) ) 
+               Mat3CpyMat4(obmat, rv3d->viewmat);
        else Mat3One(obmat);
        
        Mat3CpyMat4(viewmat, obedit->obmat);
@@ -2058,6 +2059,7 @@ static void add_primitive_bone(Scene *scene, View3D *v3d, short newob)
 
 void add_primitiveArmature(Scene *scene, View3D *v3d, int type)
 {
+       RegionView3D *rv3d= NULL; // XXX get from context
        Object *obedit= scene->obedit; // XXX get from context
        short newob=0;
        
@@ -2071,7 +2073,7 @@ void add_primitiveArmature(Scene *scene, View3D *v3d, int type)
        /* If we're not the "obedit", make a new object and enter editmode */
        if (obedit==NULL) {
                add_object(scene, OB_ARMATURE);
-               ED_object_base_init_from_view(scene, v3d, BASACT);
+               ED_object_base_init_from_view(NULL, BASACT);    // XXX NULL is C
                obedit= BASACT->object;
                
                where_is_object(scene, obedit);
@@ -2082,7 +2084,7 @@ void add_primitiveArmature(Scene *scene, View3D *v3d, int type)
        }
        
        /* no primitive support yet */
-       add_primitive_bone(scene, v3d, newob);
+       add_primitive_bone(scene, v3d, rv3d, newob);
        
        countall(); // flushes selection!
 
@@ -4815,7 +4817,7 @@ void generateSkeletonFromReebGraph(Scene *scene, ReebGraph *rg)
        }
        
        dst = add_object(scene, OB_ARMATURE);
-       ED_object_base_init_from_view(scene, NULL, scene->basact);
+       ED_object_base_init_from_view(NULL, scene->basact);     // XXX NULL is C
        obedit= scene->basact->object;
        
        /* Copy orientation from source */
index e1455d7dfb083fefba053cabd40925217bc259c4..4d468fdd28b19e312de7cfd91d183f1468d587b3 100644 (file)
@@ -2827,6 +2827,7 @@ void mouse_nurb(bContext *C, short mval[2], int extend)
 static void spin_nurb(Scene *scene, Object *obedit, float *dvec, short mode)
 {
        ListBase *editnurb= curve_get_editcurve(obedit);
+       RegionView3D *rv3d= NULL; // XXX
        View3D *v3d= NULL; // XXX
        Nurb *nu;
        float *curs, si,phi,n[3],q[4],cmat[3][3],tmat[3][3],imat[3][3];
@@ -2837,7 +2838,7 @@ static void spin_nurb(Scene *scene, Object *obedit, float *dvec, short mode)
        if(v3d==0 || obedit==0 || obedit->type!=OB_SURF) return;
        if( (v3d->lay & obedit->lay)==0 ) return;
 
-       if (mode != 2) Mat3CpyMat4(persmat, v3d->viewmat);
+       if (mode != 2) Mat3CpyMat4(persmat, rv3d->viewmat);
        else Mat3One(persmat);
        Mat3Inv(persinv, persmat);
 
@@ -2854,9 +2855,9 @@ static void spin_nurb(Scene *scene, Object *obedit, float *dvec, short mode)
                n[0]=n[1]= 0.0;
                n[2]= 1.0;
        } else {
-               n[0]= v3d->viewinv[2][0];
-               n[1]= v3d->viewinv[2][1];
-               n[2]= v3d->viewinv[2][2];
+               n[0]= rv3d->viewinv[2][0];
+               n[1]= rv3d->viewinv[2][1];
+               n[2]= rv3d->viewinv[2][2];
                Normalize(n);
        }
 
@@ -4062,6 +4063,7 @@ Nurb *addNurbprim(Scene *scene, int type, int stype, int newname)
        Object *obedit= scene->obedit; // XXX
        ListBase *editnurb= curve_get_editcurve(obedit);
        View3D *v3d= NULL; // XXX
+       RegionView3D *rv3d= NULL; // XXX
        static int xzproj= 0;
        Nurb *nu = NULL;
        BezTriple *bezt;
@@ -4084,7 +4086,8 @@ Nurb *addNurbprim(Scene *scene, int type, int stype, int newname)
                cent[2]-= obedit->obmat[3][2];
                
                if (v3d) {
-                       if ( !(newname) || U.flag & USER_ADD_VIEWALIGNED) Mat3CpyMat4(imat, v3d->viewmat);
+                       if ( !(newname) || U.flag & USER_ADD_VIEWALIGNED) 
+                               Mat3CpyMat4(imat, rv3d->viewmat);
                        else Mat3One(imat);
                        Mat3MulVecfl(imat, cent);
                        Mat3MulMat3(cmat, imat, mat);
@@ -4515,7 +4518,7 @@ void add_primitiveCurve(Scene *scene, int stype)
        /* if no obedit: new object and enter editmode */
        if(obedit==NULL) {
 // XXX         add_object_draw(OB_CURVE);
-               ED_object_base_init_from_view(scene, v3d, BASACT);
+               ED_object_base_init_from_view(NULL, BASACT); // NULL is C
                obedit= BASACT->object;
                
                where_is_object(scene, obedit);
@@ -4558,7 +4561,6 @@ void add_primitiveNurb(Scene *scene, int type)
 {
        Object *obedit= scene->obedit; // XXX
        ListBase *editnurb= curve_get_editcurve(obedit);
-       View3D *v3d= NULL; // XXX
        Nurb *nu;
        int newname= 0;
        
@@ -4569,7 +4571,7 @@ void add_primitiveNurb(Scene *scene, int type)
        /* if no obedit: new object and enter editmode */
        if(obedit==0) {
 // XXX         add_object_draw(OB_SURF);
-               ED_object_base_init_from_view(scene, v3d, BASACT);
+               ED_object_base_init_from_view(NULL, BASACT); // NULL is C
                 obedit= BASACT->object;
                
                where_is_object(scene, obedit);
index 96fe598ecae86fc2001d0a496a8e1219d4771fd0..b7874f256702341ca44f02313a1f286de2e1f24a 100644 (file)
@@ -763,7 +763,6 @@ void gpencil_delete_menu (void)
 static void gp_strokepoint_convertcoords (bGPDstroke *gps, bGPDspoint *pt, float p3d[3])
 {
        ARegion *ar= NULL; // XXX
-       View3D *v3d= NULL; // XXX
        
        if (gps->flag & GP_STROKE_3DSPACE) {
                /* directly use 3d-coordinates */
@@ -790,8 +789,8 @@ static void gp_strokepoint_convertcoords (bGPDstroke *gps, bGPDspoint *pt, float
                /* convert screen coordinate to 3d coordinates 
                 *      - method taken from editview.c - mouse_cursor() 
                 */
-               project_short_noclip(ar, v3d, fp, mval);
-               window_to_3d(ar, v3d, dvec, mval[0]-mx, mval[1]-my);
+               project_short_noclip(ar, fp, mval);
+               window_to_3d(ar, dvec, mval[0]-mx, mval[1]-my);
                VecSubf(p3d, fp, dvec);
        }
 }
@@ -1037,6 +1036,7 @@ void gpencil_convert_operation (short mode)
 {
        Scene *scene= NULL; // XXX
        View3D *v3d= NULL; // XXX
+       RegionView3D *rv3d= NULL; // XXX
        bGPdata *gpd;   
        float *fp= give_cursor(scene, v3d);
        
@@ -1045,7 +1045,7 @@ void gpencil_convert_operation (short mode)
        if (gpd == NULL) return;
        
        /* initialise 3d-cursor correction globals */
-       initgrabz(v3d, fp[0], fp[1], fp[2]);
+       initgrabz(rv3d, fp[0], fp[1], fp[2]);
        
        /* handle selection modes */
        switch (mode) {
@@ -1195,7 +1195,6 @@ static short gp_stroke_filtermval (tGPsdata *p, short mval[2], short pmval[2])
 /* convert screen-coordinates to buffer-coordinates */
 static void gp_stroke_convertcoords (tGPsdata *p, short mval[], float out[])
 {
-       View3D *v3d= NULL; // XXX
        bGPdata *gpd= p->gpd;
        
        /* in 3d-space - pt->x/y/z are 3 side-by-side floats */
@@ -1215,8 +1214,8 @@ static void gp_stroke_convertcoords (tGPsdata *p, short mval[], float out[])
                 */
                
                /* method taken from editview.c - mouse_cursor() */
-               project_short_noclip(p->ar, v3d, fp, mval);
-               window_to_3d(p->ar, v3d, dvec, mval[0]-mx, mval[1]-my);
+               project_short_noclip(p->ar, fp, mval);
+               window_to_3d(p->ar, dvec, mval[0]-mx, mval[1]-my);
                VecSubf(out, fp, dvec);
        }
        
@@ -1549,7 +1548,6 @@ static short gp_stroke_eraser_strokeinside (short mval[], short mvalo[], short r
 static void gp_stroke_eraser_dostroke (tGPsdata *p, short mval[], short mvalo[], short rad, rcti *rect, bGPDframe *gpf, bGPDstroke *gps)
 {
        bGPDspoint *pt1, *pt2;
-       View3D *v3d= NULL;
        int x0=0, y0=0, x1=0, y1=0;
        short xyval[2];
        int i;
@@ -1563,7 +1561,7 @@ static void gp_stroke_eraser_dostroke (tGPsdata *p, short mval[], short mvalo[],
        else if (gps->totpoints == 1) {
                /* get coordinates */
                if (gps->flag & GP_STROKE_3DSPACE) {
-                       project_short(p->ar, v3d, &gps->points->x, xyval);
+                       project_short(p->ar, &gps->points->x, xyval);
                        x0= xyval[0];
                        y0= xyval[1];
                }
@@ -1609,11 +1607,11 @@ static void gp_stroke_eraser_dostroke (tGPsdata *p, short mval[], short mvalo[],
                        
                        /* get coordinates */
                        if (gps->flag & GP_STROKE_3DSPACE) {
-                               project_short(p->ar, v3d, &pt1->x, xyval);
+                               project_short(p->ar, &pt1->x, xyval);
                                x0= xyval[0];
                                y0= xyval[1];
                                
-                               project_short(p->ar, v3d, &pt2->x, xyval);
+                               project_short(p->ar, &pt2->x, xyval);
                                x1= xyval[0];
                                y1= xyval[1];
                        }
@@ -1881,8 +1879,10 @@ static void gp_paint_initstroke (tGPsdata *p, short paintmode)
                        case SPACE_VIEW3D:
                        {
                                View3D *v3d= (View3D *)p->sa->spacedata.first;
+                               RegionView3D *rv3d= NULL; // XXX
                                float *fp= give_cursor(p->scene, v3d);
-                               initgrabz(v3d, fp[0], fp[1], fp[2]);
+                               
+                               initgrabz(rv3d, fp[0], fp[1], fp[2]);
                                
                                p->gpd->sbuffer_sflag |= GP_STROKE_3DSPACE;
                        }
index 0b61f8b50a727ab572610a14f3740dd89c335d86..d0815bba65c8248615edabd16bc1bb6cdd4b7ced 100644 (file)
@@ -60,7 +60,7 @@ void ED_object_apply_obmat(struct Object *ob);
 void ED_object_exit_editmode(struct bContext *C, int flag);
 void ED_object_enter_editmode(struct bContext *C, int flag);
 
-void ED_object_base_init_from_view(struct Scene *scene, struct View3D *v3d, struct Base *base);
+void ED_object_base_init_from_view(struct bContext *C, struct Base *base);
 
 /* cleanup */
 int object_data_is_libdata(struct Object *ob);
index 7c38d167b0b00d69e99220fb8bd9ee1bfabeefda..a33e85b1fdbef6b9b461e069cfe90720374374a3 100644 (file)
@@ -53,7 +53,6 @@ void  ED_region_tag_redraw(struct ARegion *ar);
 /* spaces */
 void   ED_spacetypes_init(void);
 void   ED_spacetypes_keymap(struct wmWindowManager *wm);
-struct ARegionType *ED_regiontype_from_id(struct SpaceType *st, int regionid);
 int            ED_area_header_standardbuttons(const struct bContext *C, struct uiBlock *block, int yco);
 void   ED_area_overdraw(struct bContext *C);
 void   ED_area_overdraw_flush(struct bContext *C);
index f298fe14d648c693309251afc7b16b42d7726967..a8501e83b421ea1c3ea0092ff6b0655a4ffab503 100644 (file)
@@ -31,6 +31,7 @@
 /* ********* exports for space_view3d/ module ********** */
 struct ARegion;
 struct View3D;
+struct RegionView3D;
 struct ViewContext;
 struct BPoint;
 struct Nurb;
@@ -49,6 +50,7 @@ typedef struct ViewContext {
        Object *obedit;
        struct ARegion *ar;
        struct View3D *v3d;
+       struct RegionView3D *rv3d;
        struct EditMesh *em;
        short mval[2];
 } ViewContext;
@@ -56,8 +58,8 @@ typedef struct ViewContext {
 
 float *give_cursor(struct Scene *scene, struct View3D *v3d);
 
-void initgrabz(struct View3D *v3d, float x, float y, float z);
-void window_to_3d(struct ARegion *ar, struct View3D *v3d, float *vec, short mx, short my);
+void initgrabz(struct RegionView3D *rv3d, float x, float y, float z);
+void window_to_3d(struct ARegion *ar, float *vec, short mx, short my);
 
 /* Depth buffer */
 float read_cached_depth(struct ViewContext *vc, int x, int y);
@@ -65,14 +67,14 @@ void request_depth_update(struct ViewContext *vc);
 
 /* Projection */
 
-void project_short(struct ARegion *ar, struct View3D *v3d, float *vec, short *adr);
-void project_short_noclip(struct ARegion *ar, struct View3D *v3d, float *vec, short *adr);
+void project_short(struct ARegion *ar, float *vec, short *adr);
+void project_short_noclip(struct ARegion *ar, float *vec, short *adr);
 
-void project_int(struct ARegion *ar, struct View3D *v3d, float *vec, int *adr);
-void project_int_noclip(struct ARegion *ar, struct View3D *v3d, float *vec, int *adr);
+void project_int(struct ARegion *ar, float *vec, int *adr);
+void project_int_noclip(struct ARegion *ar, float *vec, int *adr);
 
-void project_float(struct ARegion *ar, struct View3D *v3d, float *vec, float *adr);
-void project_float_noclip(struct ARegion *ar, struct View3D *v3d, float *vec, float *adr);
+void project_float(struct ARegion *ar, float *vec, float *adr);
+void project_float_noclip(struct ARegion *ar, float *vec, float *adr);
 
 void viewline(struct ARegion *ar, struct View3D *v3d, short mval[2], float ray_start[3], float ray_end[3]);
 void viewray(struct ARegion *ar, struct View3D *v3d, short mval[2], float ray_start[3], float ray_normal[3]);
@@ -84,8 +86,8 @@ void mesh_foreachScreenFace(struct ViewContext *vc, void (*func)(void *userData,
 void nurbs_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct Nurb *nu, struct BPoint *bp, struct BezTriple *bezt, int beztindex, int x, int y), void *userData);
 void lattice_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct BPoint *bp, int x, int y), void *userData);
 
-int view3d_test_clipping(struct View3D *v3d, float *vec);
-void view3d_align_axis_to_vector(struct Scene *scene, struct View3D *v3d, int axisidx, float vec[3]);
+int view3d_test_clipping(struct RegionView3D *rv3d, float *vec);
+void view3d_align_axis_to_vector(struct View3D *v3d, struct RegionView3D *rv3d, int axisidx, float vec[3]);
 
 void drawcircball(int mode, float *cent, float rad, float tmat[][4]);
 
index e9ef10648e94be55facb05542a1918bacac841dd..cc9e76dbd9c2c7a2d26b5c3fa729a335d002f1cd 100644 (file)
@@ -238,7 +238,7 @@ ARegion *ui_add_temporary_region(bScreen *sc)
 void ui_remove_temporary_region(bContext *C, bScreen *sc, ARegion *ar)
 {
        ED_region_exit(C, ar);
-       BKE_area_region_free(ar);
+       BKE_area_region_free(NULL, ar);         /* NULL: no spacetype */
        BLI_freelinkN(&sc->regionbase, ar);
 }
 
index f5c14a3414045c8f62355fa82d8c86e946b560ef..4ca302ab06c58ac12744cd7e57b568ce6f8460a8 100644 (file)
@@ -177,14 +177,14 @@ static void uv_calc_center_vector(Scene *scene, View3D *v3d, float *result, Obje
        }
 }
 
-static void uv_calc_map_matrix(float result[][4], View3D *v3d, Object *ob, float upangledeg, float sideangledeg, float radius)
+static void uv_calc_map_matrix(float result[][4], RegionView3D *rv3d, Object *ob, float upangledeg, float sideangledeg, float radius)
 {
        float rotup[4][4], rotside[4][4], viewmatrix[4][4], rotobj[4][4];
        float sideangle= 0.0, upangle= 0.0;
        int k;
 
        /* get rotation of the current view matrix */
-       Mat4CpyMat4(viewmatrix,v3d->viewmat);
+       Mat4CpyMat4(viewmatrix, rv3d->viewmat);
        /* but shifting */
        for( k= 0; k< 4; k++) viewmatrix[3][k] =0.0;
 
@@ -219,6 +219,7 @@ static void uv_calc_map_matrix(float result[][4], View3D *v3d, Object *ob, float
 
 static void uv_calc_shift_project(ARegion *ar, View3D *v3d, float *target, float *shift, float rotmat[][4], int projectionmode, float *source, float *min, float *max)
 {
+       RegionView3D *rv3d= ar->regiondata;
        float pv[3];
 
        VecSubf(pv, source, shift);
@@ -257,7 +258,7 @@ static void uv_calc_shift_project(ARegion *ar, View3D *v3d, float *target, float
         Mat4MulVec4fl(rotmat, pv4); 
 
                /* almost project_short */
-           Mat4MulVec4fl(v3d->persmat, pv4);
+           Mat4MulVec4fl(rv3d->persmat, pv4);
                if (fabs(pv4[3]) > 0.00001) { /* avoid division by zero */
                        target[0] = dx/2.0 + (dx/2.0)*pv4[0]/pv4[3];
                        target[1] = dy/2.0 + (dy/2.0)*pv4[1]/pv4[3];
@@ -368,6 +369,7 @@ static void default_uv(float uv[][2], float size)
 
 static void calculate_uv_map(Scene *scene, ARegion *ar, View3D *v3d, EditMesh *em, unsigned short mapmode)
 {
+       RegionView3D *rv3d= ar->regiondata;
        MTFace *tface;
        Object *ob;
        EditFace *efa;
@@ -412,7 +414,7 @@ static void calculate_uv_map(Scene *scene, ARegion *ar, View3D *v3d, EditMesh *e
                max[0]= max[1]= -10000000.0;
 
                cent[0] = cent[1] = cent[2] = 0.0; 
-               uv_calc_map_matrix(rotatematrix, v3d, ob, upangledeg, sideangledeg, 1.0f);
+               uv_calc_map_matrix(rotatematrix, rv3d, ob, upangledeg, sideangledeg, 1.0f);
                
                for (efa= em->faces.first; efa; efa= efa->next) {
                        if (efa->f & SELECT) {
@@ -475,7 +477,7 @@ static void calculate_uv_map(Scene *scene, ARegion *ar, View3D *v3d, EditMesh *e
                if (scene->toolsettings->uvcalc_mapdir== 2)
                        Mat4One(rotatematrix);
                else 
-                       uv_calc_map_matrix(rotatematrix, v3d, ob, upangledeg,sideangledeg,radius);
+                       uv_calc_map_matrix(rotatematrix, rv3d, ob, upangledeg,sideangledeg,radius);
                for (efa= em->faces.first; efa; efa= efa->next) {
                        if (efa->f & SELECT) {
                                tface = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
index a84c57f2e8898345aa967ddf380c6e2a9b4f8094..e8311806ca6f741a6758e883d3f13ed05210f3fc 100644 (file)
@@ -1396,17 +1396,14 @@ static float new_primitive_matrix(bContext *C, float primmat[][4])
 {
        Object *obedit= CTX_data_edit_object(C);
        Scene *scene = CTX_data_scene(C);
-       ScrArea *sa = CTX_wm_area(C);
-       View3D *v3d = NULL;
+       View3D *v3d =CTX_wm_view3d(C);
+       ARegion *ar= CTX_wm_region(C);
        float *curs, mat[3][3], vmat[3][3], cmat[3][3], imat[3][3];
        
        Mat4One(primmat);
        
-       if(sa->spacetype==SPACE_VIEW3D)
-               v3d= sa->spacedata.first;
-       
-       if(v3d)
-               Mat3CpyMat4(vmat, v3d->viewmat);
+       if(ar)
+               Mat3CpyMat4(vmat, ((RegionView3D *)ar->regiondata)->viewmat);
        else
                Mat3One(vmat);
        
index f9793a14faa9062b14647900eadf91b24c60996c..200c6a173ea5f3e4b649f44e12d63740cd7dfaab 100644 (file)
@@ -467,7 +467,7 @@ static void findnearestedge__doClosest(void *userData, EditEdge *eed, int x0, in
                
        if(eed->f & SELECT) distance+=5;
        if(distance < data->dist) {
-               if(data->vc.v3d->flag & V3D_CLIPPING) {
+               if(data->vc.rv3d->rflag & RV3D_CLIPPING) {
                        float labda= labda_PdistVL2Dfl(data->mval, v1, v2);
                        float vec[3];
 
@@ -476,7 +476,7 @@ static void findnearestedge__doClosest(void *userData, EditEdge *eed, int x0, in
                        vec[2]= eed->v1->co[2] + labda*(eed->v2->co[2] - eed->v1->co[2]);
                        Mat4MulVecfl(data->vc.obedit->obmat, vec);
 
-                       if(view3d_test_clipping(data->vc.v3d, vec)==0) {
+                       if(view3d_test_clipping(data->vc.rv3d, vec)==0) {
                                data->dist = distance;
                                data->closest = eed;
                        }
@@ -4089,7 +4089,7 @@ static int mface_is_selected(MFace *mf)
         * which would use same as vertices method), then added
         * to interface! Hoera! - zr
         */
-void faceselect_align_view_to_selected(View3D *v3d, Mesh *me, int axis)
+void faceselect_align_view_to_selected(View3D *v3d, RegionView3D *rv3d, Mesh *me, int axis)
 {
        float norm[3];
        int i, totselected = 0;
@@ -4122,7 +4122,7 @@ void faceselect_align_view_to_selected(View3D *v3d, Mesh *me, int axis)
        if (totselected == 0)
                error("No faces selected.");
        else
-               view3d_align_axis_to_vector(NULL, v3d, axis, norm);
+               view3d_align_axis_to_vector(v3d, rv3d, axis, norm);
 }
 
 /* helper for below, to survive non-uniform scaled objects */
@@ -4146,7 +4146,7 @@ static void face_getnormal_obspace(Object *obedit, EditFace *efa, float *fno)
 }
 
 
-void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, View3D *v3d, int axis)
+void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, View3D *v3d, RegionView3D *rv3d, int axis)
 {
        int nselverts= EM_nvertices_selected(em);
        float norm[3]={0.0, 0.0, 0.0}; /* used for storing the mesh normal */
@@ -4167,7 +4167,7 @@ void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, View3D *v3d,
                        }
                }
 
-               view3d_align_axis_to_vector(NULL, v3d, axis, norm);
+               view3d_align_axis_to_vector(v3d, rv3d, axis, norm);
        } 
        else if (nselverts>2) {
                float cent[3];
@@ -4192,7 +4192,7 @@ void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, View3D *v3d,
                }
 
                Mat4Mul3Vecfl(obedit->obmat, norm);
-               view3d_align_axis_to_vector(NULL, v3d, axis, norm);
+               view3d_align_axis_to_vector(v3d, rv3d, axis, norm);
        } 
        else if (nselverts==2) { /* Align view to edge (or 2 verts) */ 
                EditVert *eve, *leve= NULL;
@@ -4209,7 +4209,7 @@ void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, View3D *v3d,
                        }
                }
                Mat4Mul3Vecfl(obedit->obmat, norm);
-               view3d_align_axis_to_vector(NULL, v3d, axis, norm);
+               view3d_align_axis_to_vector(v3d, rv3d, axis, norm);
        } 
        else if (nselverts==1) { /* Align view to vert normal */ 
                EditVert *eve;
@@ -4223,7 +4223,7 @@ void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, View3D *v3d,
                        }
                }
                Mat4Mul3Vecfl(obedit->obmat, norm);
-               view3d_align_axis_to_vector(NULL, v3d, axis, norm);
+               view3d_align_axis_to_vector(v3d, rv3d, axis, norm);
        }
 } 
 
index ad56ebd5f50fe54594aab3576b02a8cc691bfeea..bb81c7605e50e8bba362fcf47b7d0ef5e8afaebd 100644 (file)
@@ -688,15 +688,15 @@ void split_mesh(EditMesh *em)
 
 }
 
-void extrude_repeat_mesh(View3D *v3d, Object *obedit, EditMesh *em, int steps, float offs)
+void extrude_repeat_mesh(RegionView3D *rv3d, Object *obedit, EditMesh *em, int steps, float offs)
 {
        float dvec[3], tmat[3][3], bmat[3][3], nor[3]= {0.0, 0.0, 0.0};
        short a;
 
        /* dvec */
-       dvec[0]= v3d->persinv[2][0];
-       dvec[1]= v3d->persinv[2][1];
-       dvec[2]= v3d->persinv[2][2];
+       dvec[0]= rv3d->persinv[2][0];
+       dvec[1]= rv3d->persinv[2][1];
+       dvec[2]= rv3d->persinv[2][2];
        Normalize(dvec);
        dvec[0]*= offs;
        dvec[1]*= offs;
@@ -723,6 +723,7 @@ void extrude_repeat_mesh(View3D *v3d, Object *obedit, EditMesh *em, int steps, f
 
 void spin_mesh(View3D *v3d, Object *obedit, EditMesh *em, int steps, float degr, float *dvec, int mode)
 {
+       RegionView3D *rv3d= NULL; // XXX from context
        EditVert *eve,*nextve;
        float nor[3]= {0.0, 0.0, 0.0};
        float *curs, si,n[3],q[4],cmat[3][3],imat[3][3], tmat[3][3];
@@ -734,7 +735,7 @@ void spin_mesh(View3D *v3d, Object *obedit, EditMesh *em, int steps, float degr,
        Mat3CpyMat4(bmat, obedit->obmat);
        Mat3Inv(imat,bmat);
 
-       curs= give_cursor(NULL, v3d);
+       curs= give_cursor(NULL, v3d); // XXX
        VECCOPY(cent, curs);
        cent[0]-= obedit->obmat[3][0];
        cent[1]-= obedit->obmat[3][1];
@@ -746,13 +747,13 @@ void spin_mesh(View3D *v3d, Object *obedit, EditMesh *em, int steps, float degr,
 //     if(scene->toolsettings->editbutflag & B_CLOCKWISE) phi= -phi;
 
        if(dvec) {
-               n[0]= v3d->viewinv[1][0];
-               n[1]= v3d->viewinv[1][1];
-               n[2]= v3d->viewinv[1][2];
+               n[0]= rv3d->viewinv[1][0];
+               n[1]= rv3d->viewinv[1][1];
+               n[2]= rv3d->viewinv[1][2];
        } else {
-               n[0]= v3d->viewinv[2][0];
-               n[1]= v3d->viewinv[2][1];
-               n[2]= v3d->viewinv[2][2];
+               n[0]= rv3d->viewinv[2][0];
+               n[1]= rv3d->viewinv[2][1];
+               n[2]= rv3d->viewinv[2][2];
        }
        Normalize(n);
 
index 4f5426b44efb0e02b89d67a0846579c9b6780ba4..18169643bf506c6e9fed0d2d30465a4301759a5d 100644 (file)
@@ -437,6 +437,7 @@ static int float_sort(const void *v1, const void *v2)
 
 void sort_faces(Scene *scene, View3D *v3d)
 {
+       RegionView3D *rv3d= NULL; // get from context 
        Object *ob= OBACT;
        Mesh *me;
        CustomDataLayer *layer;
@@ -490,7 +491,7 @@ void sort_faces(Scene *scene, View3D *v3d)
                float cur[3];
                
                if (event == 1)
-                       Mat4MulMat4(mat, OBACT->obmat, v3d->viewmat); /* apply the view matrix to the object matrix */
+                       Mat4MulMat4(mat, OBACT->obmat, rv3d->viewmat); /* apply the view matrix to the object matrix */
                else if (event == 2) { /* sort from cursor */
                        if( v3d && v3d->localview ) {
                                VECCOPY(cur, v3d->cursor);
index f213e4f9cacc798dce1c4112ef281836bf46a0df..f76edc40f5344db4b997f33d65e76db2aa69a68c 100644 (file)
@@ -222,8 +222,10 @@ int object_data_is_libdata(Object *ob)
 
 
 /* exported */
-void ED_object_base_init_from_view(Scene *scene, View3D *v3d, Base *base)
+void ED_object_base_init_from_view(bContext *C, Base *base)
 {
+       View3D *v3d= CTX_wm_view3d(C);
+       Scene *scene= CTX_data_scene(C);
        Object *ob= base->object;
        
        if (scene==NULL)
@@ -244,10 +246,14 @@ void ED_object_base_init_from_view(Scene *scene, View3D *v3d, Base *base)
                }
                
                if (U.flag & USER_ADD_VIEWALIGNED) {
-                       v3d->viewquat[0]= -v3d->viewquat[0];
-                       
-                       QuatToEul(v3d->viewquat, ob->rot);
-                       v3d->viewquat[0]= -v3d->viewquat[0];
+                       ARegion *ar= CTX_wm_region(C);
+                       if(ar) {
+                               RegionView3D *rv3d= ar->regiondata;
+                               
+                               rv3d->viewquat[0]= -rv3d->viewquat[0];
+                               QuatToEul(rv3d->viewquat, ob->rot);
+                               rv3d->viewquat[0]= -rv3d->viewquat[0];
+                       }
                }
        }
 }
@@ -293,7 +299,7 @@ static int object_add_exec(bContext *C, wmOperator *op)
        ED_base_object_activate(C, BASACT);
        
        /* more editor stuff */
-       ED_object_base_init_from_view(scene, CTX_wm_view3d(C), BASACT);
+       ED_object_base_init_from_view(C, BASACT);
        
        DAG_scene_sort(scene);
        
index d6235384e6e8e011f31d4dfe9eef96f726c40696..4acbe360ab43646aecf319767b6c5bc786803541 100644 (file)
@@ -298,7 +298,7 @@ static int rct_fits(rcti *rect, char dir, int size)
        }
 }
 
-static void region_rect_recursive(ARegion *ar, rcti *remainder)
+static void region_rect_recursive(ARegion *ar, rcti *remainder, int quad)
 {
        int prefsizex, prefsizey;
        
@@ -307,7 +307,8 @@ static void region_rect_recursive(ARegion *ar, rcti *remainder)
        
        /* clear state flags first */
        ar->flag &= ~RGN_FLAG_TOO_SMALL;
-       if(ar->next==NULL)
+       /* user errors */
+       if(ar->next==NULL && ar->alignment!=RGN_ALIGN_QSPLIT)
                ar->alignment= RGN_ALIGN_NONE;
        
        prefsizex= ar->type->minsizex;
@@ -372,7 +373,7 @@ static void region_rect_recursive(ARegion *ar, rcti *remainder)
                        }
                }
        }
-       else {
+       else if(ar->alignment==RGN_ALIGN_VSPLIT || ar->alignment==RGN_ALIGN_HSPLIT) {
                /* percentage subdiv*/
                ar->winrct= *remainder;
                
@@ -395,11 +396,55 @@ static void region_rect_recursive(ARegion *ar, rcti *remainder)
                        }
                }
        }
+       else if(ar->alignment==RGN_ALIGN_QSPLIT) {
+               ar->winrct= *remainder;
+               
+               /* test if there's still 4 regions left */
+               if(quad==0) {
+                       ARegion *artest= ar->next;
+                       int count= 1;
+                       
+                       while(artest) {
+                               artest->alignment= RGN_ALIGN_QSPLIT;
+                               artest= artest->next;
+                               count++;
+                       }
+                       
+                       if(count!=4) {
+                               /* let's stop adding regions */
+                               BLI_init_rcti(remainder, 0, 0, 0, 0);
+                               printf("region quadsplit failed\n");
+                       }
+                       else quad= 1;
+               }
+               if(quad) {
+                       if(quad==1) { /* left bottom */
+                               ar->winrct.xmax = (remainder->xmin + remainder->xmax)/2;
+                               ar->winrct.ymax = (remainder->ymin + remainder->ymax)/2;
+                       }
+                       else if(quad==2) { /* left top */
+                               ar->winrct.xmax = (remainder->xmin + remainder->xmax)/2;
+                               ar->winrct.ymin = 1 + (remainder->ymin + remainder->ymax)/2;
+                       }
+                       else if(quad==3) { /* right bottom */
+                               ar->winrct.xmin = 1 + (remainder->xmin + remainder->xmax)/2;
+                               ar->winrct.ymax = (remainder->ymin + remainder->ymax)/2;
+                       }
+                       else {  /* right top */
+                               ar->winrct.xmin = 1 + (remainder->xmin + remainder->xmax)/2;
+                               ar->winrct.ymin = 1 + (remainder->ymin + remainder->ymax)/2;
+                               BLI_init_rcti(remainder, 0, 0, 0, 0);
+                       }
+
+                       quad++;
+               }
+       }
+       
        /* for speedup */
        ar->winx= ar->winrct.xmax - ar->winrct.xmin + 1;
        ar->winy= ar->winrct.ymax - ar->winrct.ymin + 1;
        
-       region_rect_recursive(ar->next, remainder);
+       region_rect_recursive(ar->next, remainder, quad);
 }
 
 static void area_calc_totrct(ScrArea *sa, int sizex, int sizey)
@@ -508,14 +553,14 @@ void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
        }
        
        for(ar= sa->regionbase.first; ar; ar= ar->next)
-               ar->type= ED_regiontype_from_id(sa->type, ar->regiontype);
+               ar->type= BKE_regiontype_from_id(sa->type, ar->regiontype);
        
        /* area sizes */
        area_calc_totrct(sa, win->sizex, win->sizey);
        
        /* region rect sizes */
        rect= sa->totrct;
-       region_rect_recursive(sa->regionbase.first, &rect);
+       region_rect_recursive(sa->regionbase.first, &rect, 0);
        
        /* default area handlers */
        ed_default_handlers(wm, &sa->handlers, sa->type->keymapflag);
@@ -569,11 +614,13 @@ void area_copy_data(ScrArea *sa1, ScrArea *sa2, int swap_space)
                BKE_spacedata_copylist(&sa1->spacedata, &sa2->spacedata);
        }
        
-       /* regions... XXX */
+       /* regions */
+       for(ar= sa1->regionbase.first; ar; ar= ar->next)
+               BKE_area_region_free(sa1->type, ar);
        BLI_freelistN(&sa1->regionbase);
        
        for(ar= sa2->regionbase.first; ar; ar= ar->next) {
-               ARegion *newar= BKE_area_region_copy(ar);
+               ARegion *newar= BKE_area_region_copy(sa2->type, ar);
                BLI_addtail(&sa1->regionbase, newar);
        }
                
index ca057cd0b4d2031cc8cbb774f2cdbf7982ca0eed..bcc162b2b748069d3ddbb9fc4af2010fa4eb1206 100644 (file)
@@ -34,6 +34,7 @@
 #include "BKE_customdata.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
+#include "BKE_report.h"
 #include "BKE_screen.h"
 #include "BKE_utildefines.h"
 
@@ -1402,21 +1403,28 @@ void SCREEN_OT_repeat_history(wmOperatorType *ot)
 /* insert a region in the area region list */
 static int region_split_exec(bContext *C, wmOperator *op)
 {
-       ScrArea *sa= CTX_wm_area(C);
        ARegion *ar= CTX_wm_region(C);
-       ARegion *newar= BKE_area_region_copy(ar);
-       int dir= RNA_enum_get(op->ptr, "direction");
-       
-       BLI_insertlinkafter(&sa->regionbase, CTX_wm_region(C), newar);
-       
-       newar->alignment= ar->alignment;
        
-       if(dir=='h')
-               ar->alignment= RGN_ALIGN_HSPLIT;
-       else
-               ar->alignment= RGN_ALIGN_VSPLIT;
+       if(ar->regiontype==RGN_TYPE_HEADER)
+               BKE_report(op->reports, RPT_ERROR, "Cannot split header");
+       else if(ar->alignment==RGN_ALIGN_QSPLIT)
+               BKE_report(op->reports, RPT_ERROR, "Cannot split further");
+       else {
+               ScrArea *sa= CTX_wm_area(C);
+               ARegion *newar= BKE_area_region_copy(sa->type, ar);
+               int dir= RNA_enum_get(op->ptr, "type");
        
-       WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL);
+               BLI_insertlinkafter(&sa->regionbase, ar, newar);
+               
+               newar->alignment= ar->alignment;
+               
+               if(dir=='h')
+                       ar->alignment= RGN_ALIGN_HSPLIT;
+               else
+                       ar->alignment= RGN_ALIGN_VSPLIT;
+               
+               WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL);
+       }
        
        return OPERATOR_FINISHED;
 }
@@ -1428,13 +1436,60 @@ void SCREEN_OT_region_split(wmOperatorType *ot)
        ot->idname= "SCREEN_OT_region_split";
        
        /* api callbacks */
-       ot->invoke= WM_operator_confirm;
+       ot->invoke= WM_menu_invoke;
        ot->exec= region_split_exec;
        ot->poll= ED_operator_areaactive;
        
-       RNA_def_enum(ot->srna, "direction", prop_direction_items, 'h', "Direction", "");
+       RNA_def_enum(ot->srna, "type", prop_direction_items, 'h', "Direction", "");
 }
 
+/* ************** region four-split operator ***************************** */
+
+/* insert a region in the area region list */
+static int region_foursplit_exec(bContext *C, wmOperator *op)
+{
+       ARegion *ar= CTX_wm_region(C);
+       
+       /* some rules... */
+       if(ar->regiontype!=RGN_TYPE_WINDOW)
+               BKE_report(op->reports, RPT_ERROR, "Only window region can be 4-splitted");
+       else if(ar->next)
+               BKE_report(op->reports, RPT_ERROR, "Only last region can be 4-splitted");
+       else if(ar->alignment==RGN_ALIGN_QSPLIT)
+               BKE_report(op->reports, RPT_ERROR, "Cannot split further");
+       else {
+               ScrArea *sa= CTX_wm_area(C);
+               ARegion *newar;
+               int count;
+               
+               ar->alignment= RGN_ALIGN_QSPLIT;
+               
+               for(count=0; count<3; count++) {
+                       newar= BKE_area_region_copy(sa->type, ar);
+                       BLI_addtail(&sa->regionbase, newar);
+               }
+               
+               WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL);
+       }
+       
+       
+       return OPERATOR_FINISHED;
+}
+
+void SCREEN_OT_region_foursplit(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Split Region in 4 Parts";
+       ot->idname= "SCREEN_OT_region_foursplit";
+       
+       /* api callbacks */
+       ot->invoke= WM_operator_confirm;
+       ot->exec= region_foursplit_exec;
+       ot->poll= ED_operator_areaactive;
+}
+
+
+
 /* ************** region flip operator ***************************** */
 
 /* flip a region alignment */
@@ -1583,6 +1638,7 @@ void ED_operatortypes_screen(void)
        WM_operatortype_append(SCREEN_OT_area_join);
        WM_operatortype_append(SCREEN_OT_area_rip);
        WM_operatortype_append(SCREEN_OT_region_split);
+       WM_operatortype_append(SCREEN_OT_region_foursplit);
        WM_operatortype_append(SCREEN_OT_region_flip);
        WM_operatortype_append(SCREEN_OT_screen_set);
        WM_operatortype_append(SCREEN_OT_screen_full_area);
@@ -1616,8 +1672,8 @@ void ED_keymap_screen(wmWindowManager *wm)
        WM_keymap_add_item(keymap, "SCREEN_OT_screen_full_area", SPACEKEY, KM_PRESS, KM_CTRL, 0);
 
         /* tests */
-       RNA_enum_set(WM_keymap_add_item(keymap, "SCREEN_OT_region_split", SKEY, KM_PRESS, KM_CTRL|KM_ALT, 0)->ptr, "direction", 'h');
-       RNA_enum_set(WM_keymap_add_item(keymap, "SCREEN_OT_region_split", SKEY, KM_PRESS, KM_CTRL|KM_ALT|KM_SHIFT, 0)->ptr, "direction", 'v');
+       WM_keymap_add_item(keymap, "SCREEN_OT_region_split", SKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
+       WM_keymap_add_item(keymap, "SCREEN_OT_region_foursplit", SKEY, KM_PRESS, KM_CTRL|KM_ALT|KM_SHIFT, 0);
        
        /*frame offsets*/
        WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", TIMER0, KM_ANY, KM_ANY, 0);
index b88eb1884644e274e4abc40952819c389e8f0fda..6cea3ba1928a35aa1632f652e208ca6503aba29f 100644 (file)
@@ -1552,11 +1552,11 @@ static void sculpt_load_mats(bglMats *mats, ViewContext *vc)
        float cpy[4][4];
        int i, j;
 
-       Mat4MulMat4(cpy, vc->v3d->viewmat, vc->obact->obmat);
+       Mat4MulMat4(cpy, vc->rv3d->viewmat, vc->obact->obmat);
 
        for(i = 0; i < 4; ++i) {
                for(j = 0; j < 4; ++j) {
-                       mats->projection[i*4+j] = vc->v3d->winmat[i][j];
+                       mats->projection[i*4+j] = vc->rv3d->winmat[i][j];
                        mats->modelview[i*4+j] = cpy[i][j];
                }
        }
index 89693b6cc2c7fc87b29b1d7a1feceb1faf709b08..b7fc3b3a5f8bb5a7e12b75411031581fab0f0e77 100644 (file)
 #include "ED_space_api.h"
 #include "ED_uvedit.h"
 
-ARegionType *ED_regiontype_from_id(SpaceType *st, int regionid)
-{
-       ARegionType *art;
-       
-       for(art= st->regiontypes.first; art; art= art->next)
-               if(art->regionid==regionid)
-                       return art;
-       
-       printf("Error, region type missing in %s\n", st->name);
-       return st->regiontypes.first;
-}
-
-
 /* only call once on startup, storage is global in BKE kernel listbase */
 void ED_spacetypes_init(void)
 {
index 3556e27bbb75b14119743c6c3ddfeb794fa804c0..b91ed0894e3a7c10ab6e341043f5f1030b71762b 100644 (file)
@@ -1268,7 +1268,7 @@ static void draw_bone(int dt, int armflag, int boneflag, int constflag, unsigned
        }
 }
 
-static void draw_custom_bone(Scene *scene, View3D *v3d, Object *ob, int dt, int armflag, int boneflag, unsigned int id, float length)
+static void draw_custom_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, int dt, int armflag, int boneflag, unsigned int id, float length)
 {
        if(ob==NULL) return;
        
@@ -1283,7 +1283,7 @@ static void draw_custom_bone(Scene *scene, View3D *v3d, Object *ob, int dt, int
                glLoadName((GLuint) id|BONESEL_BONE);
        }
        
-       draw_object_instance(scene, v3d, ob, dt, armflag & ARM_POSEMODE);
+       draw_object_instance(scene, v3d, rv3d, ob, dt, armflag & ARM_POSEMODE);
 }
 
 
@@ -1513,7 +1513,7 @@ static void draw_pose_dofs(Object *ob)
 }
 
 /* assumes object is Armature with pose */
-static void draw_pose_channels(Scene *scene, View3D *v3d, Base *base, int dt)
+static void draw_pose_channels(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt)
 {
        Object *ob= base->object;
        bArmature *arm= ob->data;
@@ -1590,7 +1590,7 @@ static void draw_pose_channels(Scene *scene, View3D *v3d, Base *base, int dt)
                                                if (pchan->bone->flag & BONE_DRAWWIRE) 
                                                        draw_wire= 1;
                                                else
-                                                       draw_custom_bone(scene, v3d, pchan->custom, OB_SOLID, arm->flag, flag, index, bone->length);
+                                                       draw_custom_bone(scene, v3d, rv3d, pchan->custom, OB_SOLID, arm->flag, flag, index, bone->length);
                                        }
                                        else if (arm->drawtype==ARM_LINE)
                                                ;       /* nothing in solid */
@@ -1656,7 +1656,7 @@ static void draw_pose_channels(Scene *scene, View3D *v3d, Base *base, int dt)
                                                        if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)))
                                                                flag &= ~BONE_CONNECTED;
                                                        
-                                                       draw_custom_bone(scene, v3d, pchan->custom, OB_WIRE, arm->flag, flag, index, bone->length);
+                                                       draw_custom_bone(scene, v3d, rv3d, pchan->custom, OB_WIRE, arm->flag, flag, index, bone->length);
                                                        
                                                        glPopMatrix();
                                                }
@@ -1684,7 +1684,7 @@ static void draw_pose_channels(Scene *scene, View3D *v3d, Base *base, int dt)
                }
                /* if solid && posemode, we draw again with polygonoffset */
                else if ((dt > OB_WIRE) && (arm->flag & ARM_POSEMODE)) {
-                       bglPolygonOffset(v3d->dist, 1.0);
+                       bglPolygonOffset(rv3d->dist, 1.0);
                }
                else {
                        /* and we use selection indices if not done yet */
@@ -1772,7 +1772,7 @@ static void draw_pose_channels(Scene *scene, View3D *v3d, Base *base, int dt)
                }
                /* restore things */
                if ((arm->drawtype!=ARM_LINE)&& (dt>OB_WIRE) && (arm->flag & ARM_POSEMODE))
-                       bglPolygonOffset(v3d->dist, 0.0);
+                       bglPolygonOffset(rv3d->dist, 0.0);
        }       
        
        /* restore */
@@ -1849,7 +1849,7 @@ static void set_matrix_editbone(EditBone *eBone)
        
 }
 
-static void draw_ebones(View3D *v3d, Object *ob, int dt)
+static void draw_ebones(View3D *v3d, RegionView3D *rv3d, Object *ob, int dt)
 {
        EditBone *eBone;
        bArmature *arm= ob->data;
@@ -1920,7 +1920,7 @@ static void draw_ebones(View3D *v3d, Object *ob, int dt)
                        index= 0;
        }
        else if (dt > OB_WIRE) 
-               bglPolygonOffset(v3d->dist, 1.0);
+               bglPolygonOffset(rv3d->dist, 1.0);
        else if (arm->flag & ARM_EDITMODE) 
                index= 0;       /* do selection codes */
        
@@ -1971,7 +1971,7 @@ static void draw_ebones(View3D *v3d, Object *ob, int dt)
        
        /* restore */
        if (arm->drawtype==ARM_LINE);
-       else if (dt>OB_WIRE) bglPolygonOffset(v3d->dist, 0.0);
+       else if (dt>OB_WIRE) bglPolygonOffset(rv3d->dist, 0.0);
        
        /* finally names and axes */
        if (arm->flag & (ARM_DRAWNAMES|ARM_DRAWAXES)) {
@@ -2020,7 +2020,7 @@ static void draw_ebones(View3D *v3d, Object *ob, int dt)
 /* draw bone paths
  *     - in view space 
  */
-static void draw_pose_paths(Scene *scene, View3D *v3d, Object *ob)
+static void draw_pose_paths(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob)
 {
        bArmature *arm= ob->data;
        bPoseChannel *pchan;
@@ -2035,7 +2035,7 @@ static void draw_pose_paths(Scene *scene, View3D *v3d, Object *ob)
        if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
        
        glPushMatrix();
-       glLoadMatrixf(v3d->viewmat);
+       glLoadMatrixf(rv3d->viewmat);
        
        /* version patch here - cannot access frame info from file reading */
        if (arm->pathsize == 0) arm->pathsize= 1;
@@ -2257,7 +2257,7 @@ static void ghost_poses_tag_unselected(Object *ob, short unset)
 /* draw ghosts that occur within a frame range 
  *     note: object should be in posemode 
  */
-static void draw_ghost_poses_range(Scene *scene, View3D *v3d, Base *base)
+static void draw_ghost_poses_range(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base)
 {
        Object *ob= base->object;
        bArmature *arm= ob->data;
@@ -2298,7 +2298,7 @@ static void draw_ghost_poses_range(Scene *scene, View3D *v3d, Base *base)
                
                //do_all_pose_actions(scene, ob);  // XXX old animation system
                where_is_pose(scene, ob);
-               draw_pose_channels(scene, v3d, base, OB_WIRE);
+               draw_pose_channels(scene, v3d, rv3d, base, OB_WIRE);
        }
        glDisable(GL_BLEND);
        if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
@@ -2318,7 +2318,7 @@ static void draw_ghost_poses_range(Scene *scene, View3D *v3d, Base *base)
 /* draw ghosts on keyframes in action within range 
  *     - object should be in posemode 
  */
-static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, Base *base)
+static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base)
 {
        Object *ob= base->object;
        bAction *act= ob->action; // XXX old animsys stuff... watch it!
@@ -2374,7 +2374,7 @@ static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, Base *base)
                
                //do_all_pose_actions(scene, ob);       // XXX old animation system
                where_is_pose(scene, ob);
-               draw_pose_channels(scene, v3d, base, OB_WIRE);
+               draw_pose_channels(scene, v3d, rv3d, base, OB_WIRE);
        }
        glDisable(GL_BLEND);
        if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
@@ -2394,7 +2394,7 @@ static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, Base *base)
 /* draw ghosts around current frame
  *     - object is supposed to be armature in posemode 
  */
-static void draw_ghost_poses(Scene *scene, View3D *v3d, Base *base)
+static void draw_ghost_poses(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base)
 {
        Object *ob= base->object;
        bArmature *arm= ob->data;
@@ -2456,7 +2456,7 @@ static void draw_ghost_poses(Scene *scene, View3D *v3d, Base *base)
                        if (CFRA!=cfrao) {
                                //do_all_pose_actions(scene, ob); // xxx old animation system crap
                                where_is_pose(scene, ob);
-                               draw_pose_channels(scene, v3d, base, OB_WIRE);
+                               draw_pose_channels(scene, v3d, rv3d, base, OB_WIRE);
                        }
                }
                
@@ -2472,7 +2472,7 @@ static void draw_ghost_poses(Scene *scene, View3D *v3d, Base *base)
                        if (CFRA != cfrao) {
                                //do_all_pose_actions(scene, ob); // XXX old animation system crap...
                                where_is_pose(scene, ob);
-                               draw_pose_channels(scene, v3d, base, OB_WIRE);
+                               draw_pose_channels(scene, v3d, rv3d, base, OB_WIRE);
                        }
                }
        }
@@ -2493,7 +2493,7 @@ static void draw_ghost_poses(Scene *scene, View3D *v3d, Base *base)
 /* ********************************** Armature Drawing - Main ************************* */
 
 /* called from drawobject.c, return 1 if nothing was drawn */
-int draw_armature(Scene *scene, View3D *v3d, Base *base, int dt, int flag)
+int draw_armature(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt, int flag)
 {
        Object *ob= base->object;
        bArmature *arm= ob->data;
@@ -2517,7 +2517,7 @@ int draw_armature(Scene *scene, View3D *v3d, Base *base, int dt, int flag)
        /* editmode? */
        if(arm->edbo) {
                arm->flag |= ARM_EDITMODE;
-               draw_ebones(v3d, ob, dt);
+               draw_ebones(v3d, rv3d, ob, dt);
                arm->flag &= ~ARM_EDITMODE;
        }
        else{
@@ -2531,14 +2531,14 @@ int draw_armature(Scene *scene, View3D *v3d, Base *base, int dt, int flag)
                                }
                                else if(ob->flag & OB_POSEMODE) {
                                        if (arm->ghosttype == ARM_GHOST_RANGE) {
-                                               draw_ghost_poses_range(scene, v3d, base);
+                                               draw_ghost_poses_range(scene, v3d, rv3d, base);
                                        }
                                        else if (arm->ghosttype == ARM_GHOST_KEYS) {
-                                               draw_ghost_poses_keys(scene, v3d, base);
+                                               draw_ghost_poses_keys(scene, v3d, rv3d, base);
                                        }
                                        else if (arm->ghosttype == ARM_GHOST_CUR) {
                                                if (arm->ghostep)
-                                                       draw_ghost_poses(scene, v3d, base);
+                                                       draw_ghost_poses(scene, v3d, rv3d, base);
                                        }
                                        if ((flag & DRAW_SCENESET)==0) {
                                                if(ob==OBACT) 
@@ -2547,11 +2547,11 @@ int draw_armature(Scene *scene, View3D *v3d, Base *base, int dt, int flag)
                                                        if(OBACT && ob==modifiers_isDeformedByArmature(OBACT))
                                                                arm->flag |= ARM_POSEMODE;
                                                }
-                                               draw_pose_paths(scene, v3d, ob);
+                                               draw_pose_paths(scene, v3d, rv3d, ob);
                                        }
                                }       
                        }
-                       draw_pose_channels(scene, v3d, base, dt);
+                       draw_pose_channels(scene, v3d, rv3d, base, dt);
                        arm->flag &= ~ARM_POSEMODE; 
                        
                        if(ob->flag & OB_POSEMODE)
index 1fa7a4d96e16666742b65ceee3252879f133ac58..f34f520e2695d78265028342c9935db8c387a871 100644 (file)
@@ -150,6 +150,7 @@ static int draw_tfaces3D__setHiddenOpts(void *userData, int index)
                return (flags & eEdge_Select);
        }
 }
+
 static int draw_tfaces3D__setSeamOpts(void *userData, int index)
 {
        struct { Mesh *me; EdgeHash *eh; } *data = userData;
@@ -166,6 +167,7 @@ static int draw_tfaces3D__setSeamOpts(void *userData, int index)
                return 0;
        }
 }
+
 static int draw_tfaces3D__setSelectOpts(void *userData, int index)
 {
        struct { Mesh *me; EdgeHash *eh; } *data = userData;
@@ -174,6 +176,7 @@ static int draw_tfaces3D__setSelectOpts(void *userData, int index)
 
        return flags & eEdge_Select;
 }
+
 static int draw_tfaces3D__setActiveOpts(void *userData, int index)
 {
        struct { Mesh *me; EdgeHash *eh; } *data = userData;
@@ -186,6 +189,7 @@ static int draw_tfaces3D__setActiveOpts(void *userData, int index)
                return 0;
        }
 }
+
 static int draw_tfaces3D__drawFaceOpts(void *userData, int index)
 {
        Mesh *me = (Mesh*)userData;
@@ -196,7 +200,8 @@ static int draw_tfaces3D__drawFaceOpts(void *userData, int index)
        else
                return 0;
 }
-static void draw_tfaces3D(View3D *v3d, Object *ob, Mesh *me, DerivedMesh *dm)
+
+static void draw_tfaces3D(RegionView3D *rv3d, Object *ob, Mesh *me, DerivedMesh *dm)
 {
        struct { Mesh *me; EdgeHash *eh; } data;
 
@@ -205,7 +210,7 @@ static void draw_tfaces3D(View3D *v3d, Object *ob, Mesh *me, DerivedMesh *dm)
 
        glEnable(GL_DEPTH_TEST);
        glDisable(GL_LIGHTING);
-       bglPolygonOffset(v3d->dist, 1.0);
+       bglPolygonOffset(rv3d->dist, 1.0);
 
                /* Draw (Hidden) Edges */
        UI_ThemeColor(TH_EDGE_FACESEL);
@@ -232,7 +237,7 @@ static void draw_tfaces3D(View3D *v3d, Object *ob, Mesh *me, DerivedMesh *dm)
                glDisable(GL_BLEND);
        }
        
-       bglPolygonOffset(v3d->dist, 1.0);
+       bglPolygonOffset(rv3d->dist, 1.0);
 
                /* Draw Stippled Outline for selected faces */
        glColor3ub(255, 255, 255);
@@ -242,7 +247,7 @@ static void draw_tfaces3D(View3D *v3d, Object *ob, Mesh *me, DerivedMesh *dm)
 
        dm->drawMappedEdges(dm, draw_tfaces3D__setActiveOpts, &data);
 
-       bglPolygonOffset(v3d->dist, 0.0);       // resets correctly now, even after calling accumulated offsets
+       bglPolygonOffset(rv3d->dist, 0.0);      // resets correctly now, even after calling accumulated offsets
 
        BLI_edgehash_free(data.eh, NULL);
 }
@@ -335,7 +340,7 @@ struct TextureDrawState {
        unsigned char obcol[4];
 } Gtexdraw = {NULL, 0, 0, {0, 0, 0, 0}};
 
-static void draw_textured_begin(Scene *scene, View3D *v3d, Object *ob)
+static void draw_textured_begin(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob)
 {
        unsigned char obcol[4];
        int istex, solidtex= 0;
@@ -348,7 +353,7 @@ static void draw_textured_begin(Scene *scene, View3D *v3d, Object *ob)
        }
        else
                /* draw with lights in the scene otherwise */
-               Gtexdraw.islit= GPU_scene_object_lights(scene, ob, v3d->lay, v3d->viewmat);
+               Gtexdraw.islit= GPU_scene_object_lights(scene, ob, v3d->lay, rv3d->viewmat);
        
        obcol[0]= CLAMPIS(ob->col[0]*255, 0, 255);
        obcol[1]= CLAMPIS(ob->col[1]*255, 0, 255);
@@ -540,7 +545,7 @@ void draw_mesh_text(Scene *scene, Object *ob, int glsl)
        ddm->release(ddm);
 }
 
-void draw_mesh_textured(Scene *scene, View3D *v3d, Object *ob, DerivedMesh *dm, int faceselect)
+void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *dm, int faceselect)
 {
        Mesh *me= ob->data;
        
@@ -549,7 +554,7 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, Object *ob, DerivedMesh *dm,
        else glFrontFace(GL_CCW);
        
        /* draw the textured mesh */
-       draw_textured_begin(scene, v3d, ob);
+       draw_textured_begin(scene, v3d, rv3d, ob);
 
        if(me->edit_mesh) {
                dm->drawMappedFacesTex(dm, draw_em_tf_mapped__set_draw, me->edit_mesh);
@@ -570,7 +575,7 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, Object *ob, DerivedMesh *dm,
        
        /* draw edges and selected faces over textured mesh */
        if(!me->edit_mesh && faceselect)
-               draw_tfaces3D(v3d, ob, me, dm);
+               draw_tfaces3D(rv3d, ob, me, dm);
 
        /* reset from negative scale correction */
        glFrontFace(GL_CCW);
index 7a01e1ada7a208a3d4c3067fcf07fc943879aaf1..ad9de1453f5e58f8578b8e28d301ca47fe128ffa 100644 (file)
 #include "view3d_intern.h"     // own include
 
 
+/* this condition has been made more complex since editmode can draw textures */
+#define CHECK_OB_DRAWTEXTURE(vd, dt) \
+((vd->drawtype==OB_TEXTURE && dt>OB_SOLID) || \
+       (vd->drawtype==OB_SOLID && vd->flag2 & V3D_SOLID_TEX))
+
+#define CHECK_OB_DRAWFACEDOT(sce, vd, dt) \
+(      (sce->selectmode & SCE_SELECT_FACE) && \
+       (vd->drawtype<=OB_SOLID) && \
+       (((vd->drawtype==OB_SOLID) && (dt>=OB_SOLID) && (vd->flag2 & V3D_SOLID_TEX) && (vd->flag & V3D_ZBUF_SELECT)) == 0) \
+       )
+
+
 /* pretty stupid */
 /* editmball.c */
 extern ListBase editelems;
@@ -386,12 +398,12 @@ void drawcircball(int mode, float *cent, float rad, float tmat[][4])
 }
 
 /* circle for object centers, special_color is for library or ob users */
-static void drawcentercircle(View3D *v3d, float *vec, int selstate, int special_color)
+static void drawcentercircle(View3D *v3d, RegionView3D *rv3d, float *vec, int selstate, int special_color)
 {
        float size;
        
-       size= v3d->persmat[0][3]*vec[0]+ v3d->persmat[1][3]*vec[1]+ v3d->persmat[2][3]*vec[2]+ v3d->persmat[3][3];
-       size*= v3d->pixsize*((float)U.obcenter_dia*0.5f);
+       size= rv3d->persmat[0][3]*vec[0]+ rv3d->persmat[1][3]*vec[1]+ rv3d->persmat[2][3]*vec[2]+ rv3d->persmat[3][3];
+       size*= rv3d->pixsize*((float)U.obcenter_dia*0.5f);
 
        /* using gldepthfunc guarantees that it does write z values, but not checks for it, so centers remain visible independt order of drawing */
        if(v3d->zbuf)  glDepthFunc(GL_ALWAYS);
@@ -407,10 +419,10 @@ static void drawcentercircle(View3D *v3d, float *vec, int selstate, int special_
                else if (selstate == SELECT) UI_ThemeColorShadeAlpha(TH_SELECT, 0, -80);
                else if (selstate == DESELECT) UI_ThemeColorShadeAlpha(TH_TRANSFORM, 0, -80);
        }
-       drawcircball(GL_POLYGON, vec, size, v3d->viewinv);
+       drawcircball(GL_POLYGON, vec, size, rv3d->viewinv);
        
        UI_ThemeColorShadeAlpha(TH_WIRE, 0, -30);
-       drawcircball(GL_LINE_LOOP, vec, size, v3d->viewinv);
+       drawcircball(GL_LINE_LOOP, vec, size, rv3d->viewinv);
        
        glDisable(GL_BLEND);
        if(v3d->zbuf)  glDepthFunc(GL_LEQUAL);
@@ -645,7 +657,7 @@ static void spotvolume(float *lvec, float *vvec, float inp)
        return;
 }
 
-static void drawlamp(Scene *scene, View3D *v3d, Object *ob)
+static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob)
 {
        Lamp *la;
        float vec[3], lvec[3], vvec[3], circrad, x,y,z;
@@ -660,15 +672,15 @@ static void drawlamp(Scene *scene, View3D *v3d, Object *ob)
        
        /* we first draw only the screen aligned & fixed scale stuff */
        glPushMatrix();
-       wmLoadMatrix(v3d->viewmat);
+       wmLoadMatrix(rv3d->viewmat);
 
        /* lets calculate the scale: */
-       pixsize= v3d->persmat[0][3]*ob->obmat[3][0]+ v3d->persmat[1][3]*ob->obmat[3][1]+ v3d->persmat[2][3]*ob->obmat[3][2]+ v3d->persmat[3][3];
-       pixsize*= v3d->pixsize;
+       pixsize= rv3d->persmat[0][3]*ob->obmat[3][0]+ rv3d->persmat[1][3]*ob->obmat[3][1]+ rv3d->persmat[2][3]*ob->obmat[3][2]+ rv3d->persmat[3][3];
+       pixsize*= rv3d->pixsize;
        lampsize= pixsize*((float)U.obcenter_dia*0.5f);
 
        /* and view aligned matrix: */
-       Mat4CpyMat4(imat, v3d->viewinv);
+       Mat4CpyMat4(imat, rv3d->viewinv);
        Normalize(imat[0]);
        Normalize(imat[1]);
        
@@ -753,9 +765,9 @@ static void drawlamp(Scene *scene, View3D *v3d, Object *ob)
        if ((la->type==LA_SPOT) || (la->type==LA_YF_PHOTON)) {  
                lvec[0]=lvec[1]= 0.0; 
                lvec[2] = 1.0;
-               x = v3d->persmat[0][2];
-               y = v3d->persmat[1][2];
-               z = v3d->persmat[2][2];
+               x = rv3d->persmat[0][2];
+               y = rv3d->persmat[1][2];
+               z = rv3d->persmat[2][2];
                vvec[0]= x*ob->obmat[0][0] + y*ob->obmat[0][1] + z*ob->obmat[0][2];
                vvec[1]= x*ob->obmat[1][0] + y*ob->obmat[1][1] + z*ob->obmat[1][2];
                vvec[2]= x*ob->obmat[2][0] + y*ob->obmat[2][1] + z*ob->obmat[2][2];
@@ -871,7 +883,7 @@ static void drawlamp(Scene *scene, View3D *v3d, Object *ob)
        }
        
        /* and back to viewspace */
-       wmLoadMatrix(v3d->viewmat);
+       wmLoadMatrix(rv3d->viewmat);
        VECCOPY(vec, ob->obmat[3]);
 
        setlinestyle(0);
@@ -937,7 +949,7 @@ static void draw_focus_cross(float dist, float size)
 }
 
 /* flag similar to draw_object() */
-static void drawcamera(Scene *scene, View3D *v3d, Object *ob, int flag)
+static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, int flag)
 {
        /* a standing up pyramid with (0,0,0) as top */
        Camera *cam;
@@ -953,14 +965,14 @@ static void drawcamera(Scene *scene, View3D *v3d, Object *ob, int flag)
        glDisable(GL_LIGHTING);
        glDisable(GL_CULL_FACE);
        
-       if(v3d->persp>=2 && cam->type==CAM_ORTHO && ob==v3d->camera) {
+       if(rv3d->persp>=2 && cam->type==CAM_ORTHO && ob==v3d->camera) {
                facx= 0.5*cam->ortho_scale*1.28;
                facy= 0.5*cam->ortho_scale*1.024;
                depth= -cam->clipsta-0.1;
        }
        else {
                fac= cam->drawsize;
-               if(v3d->persp>=2 && ob==v3d->camera) fac= cam->clipsta+0.1; /* that way it's always visible */
+               if(rv3d->persp>=2 && ob==v3d->camera) fac= cam->clipsta+0.1; /* that way it's always visible */
                
                depth= - fac*cam->lens/16.0;
                facx= fac*1.28;
@@ -981,7 +993,7 @@ static void drawcamera(Scene *scene, View3D *v3d, Object *ob, int flag)
        glEnd();
        
 
-       if(v3d->persp>=2 && ob==v3d->camera) return;
+       if(rv3d->persp>=2 && ob==v3d->camera) return;
        
        glBegin(GL_LINE_STRIP);
                glVertex3fv(vec[2]); 
@@ -1022,13 +1034,13 @@ static void drawcamera(Scene *scene, View3D *v3d, Object *ob, int flag)
 
        if(flag==0) {
                if(cam->flag & (CAM_SHOWLIMITS+CAM_SHOWMIST)) {
-                       wmLoadMatrix(v3d->viewmat);
+                       wmLoadMatrix(rv3d->viewmat);
                        Mat4CpyMat4(vec, ob->obmat);
                        Mat4Ortho(vec);
                        wmMultMatrix(vec);
 
-                       MTC_Mat4SwapMat4(v3d->persmat, tmat);
-                       wmGetSingleMatrix(v3d->persmat);
+                       MTC_Mat4SwapMat4(rv3d->persmat, tmat);
+                       wmGetSingleMatrix(rv3d->persmat);
 
                        if(cam->flag & CAM_SHOWLIMITS) {
                                draw_limit_line(cam->clipsta, cam->clipend, 0x77FFFF);
@@ -1040,7 +1052,7 @@ static void drawcamera(Scene *scene, View3D *v3d, Object *ob, int flag)
                        if(cam->flag & CAM_SHOWMIST) 
                                if(wrld) draw_limit_line(wrld->miststa, wrld->miststa+wrld->mistdist, 0xFFFFFF);
                                
-                       MTC_Mat4SwapMat4(v3d->persmat, tmat);
+                       MTC_Mat4SwapMat4(rv3d->persmat, tmat);
                }
        }
 }
@@ -1087,11 +1099,11 @@ void lattice_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, BPo
        int i, N = lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
        short s[2];
 
-       view3d_get_object_project_mat(vc->v3d, vc->obedit, pmat, vmat);
+       view3d_get_object_project_mat(vc->rv3d, vc->obedit, pmat, vmat);
 
        for (i=0; i<N; i++, bp++, co+=3) {
                if (bp->hide==0) {
-                       view3d_project_short_clip(vc->ar, vc->v3d, dl?co:bp->vec, s, pmat, vmat);
+                       view3d_project_short_clip(vc->ar, dl?co:bp->vec, s, pmat, vmat);
                        func(userData, bp, s[0], s[1]);
                }
        }
@@ -1192,7 +1204,7 @@ static void mesh_foreachScreenVert__mapFunc(void *userData, int index, float *co
 
        if (eve->h==0) {
                if (data->clipVerts) {
-                       view3d_project_short_clip(data->vc.ar, data->vc.v3d, co, s, data->pmat, data->vmat);
+                       view3d_project_short_clip(data->vc.ar, co, s, data->pmat, data->vmat);
                } else {
                        view3d_project_short_noclip(data->vc.ar, co, s, data->pmat);
                }
@@ -1211,7 +1223,7 @@ void mesh_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, EditVe
        data.userData = userData;
        data.clipVerts = clipVerts;
 
-       view3d_get_object_project_mat(vc->v3d, vc->obedit, data.pmat, data.vmat);
+       view3d_get_object_project_mat(vc->rv3d, vc->obedit, data.pmat, data.vmat);
 
        EM_init_index_arrays(vc->em, 1, 0, 0);
        dm->foreachMappedVert(dm, mesh_foreachScreenVert__mapFunc, &data);
@@ -1228,8 +1240,8 @@ static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, float *v0
 
        if (eed->h==0) {
                if (data->clipVerts==1) {
-                       view3d_project_short_clip(data->vc.ar, data->vc.v3d, v0co, s[0], data->pmat, data->vmat);
-                       view3d_project_short_clip(data->vc.ar, data->vc.v3d, v1co, s[1], data->pmat, data->vmat);
+                       view3d_project_short_clip(data->vc.ar, v0co, s[0], data->pmat, data->vmat);
+                       view3d_project_short_clip(data->vc.ar, v1co, s[1], data->pmat, data->vmat);
                } else {
                        view3d_project_short_noclip(data->vc.ar, v0co, s[0], data->pmat);
                        view3d_project_short_noclip(data->vc.ar, v1co, s[1], data->pmat);
@@ -1255,7 +1267,7 @@ void mesh_foreachScreenEdge(ViewContext *vc, void (*func)(void *userData, EditEd
        data.userData = userData;
        data.clipVerts = clipVerts;
 
-       view3d_get_object_project_mat(vc->v3d, vc->obedit, data.pmat, data.vmat);
+       view3d_get_object_project_mat(vc->rv3d, vc->obedit, data.pmat, data.vmat);
 
        EM_init_index_arrays(vc->em, 0, 1, 0);
        dm->foreachMappedEdge(dm, mesh_foreachScreenEdge__mapFunc, &data);
@@ -1271,7 +1283,7 @@ static void mesh_foreachScreenFace__mapFunc(void *userData, int index, float *ce
        short s[2];
 
        if (efa && efa->h==0 && efa->fgonf!=EM_FGON) {
-               view3d_project_short_clip(data->vc.ar, data->vc.v3d, cent, s, data->pmat, data->vmat);
+               view3d_project_short_clip(data->vc.ar, cent, s, data->pmat, data->vmat);
 
                data->func(data->userData, efa, s[0], s[1], index);
        }
@@ -1286,7 +1298,7 @@ void mesh_foreachScreenFace(ViewContext *vc, void (*func)(void *userData, EditFa
        data.func = func;
        data.userData = userData;
 
-       view3d_get_object_project_mat(vc->v3d, vc->obedit, data.pmat, data.vmat);
+       view3d_get_object_project_mat(vc->rv3d, vc->obedit, data.pmat, data.vmat);
 
        EM_init_index_arrays(vc->em, 0, 0, 1);
        dm->foreachMappedFaceCenter(dm, mesh_foreachScreenFace__mapFunc, &data);
@@ -1303,7 +1315,7 @@ void nurbs_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, Nurb
        Nurb *nu;
        int i;
 
-       view3d_get_object_project_mat(vc->v3d, vc->obedit, pmat, vmat);
+       view3d_get_object_project_mat(vc->rv3d, vc->obedit, pmat, vmat);
 
        for (nu= cu->editnurb->first; nu; nu=nu->next) {
                if((nu->type & 7)==CU_BEZIER) {
@@ -1312,17 +1324,17 @@ void nurbs_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, Nurb
 
                                if(bezt->hide==0) {
                                        if (G.f & G_HIDDENHANDLES) {
-                                               view3d_project_short_clip(vc->ar, vc->v3d, bezt->vec[1], s, pmat, vmat);
+                                               view3d_project_short_clip(vc->ar, bezt->vec[1], s, pmat, vmat);
                                                if (s[0] != IS_CLIPPED)
                                                        func(userData, nu, NULL, bezt, 1, s[0], s[1]);
                                        } else {
-                                               view3d_project_short_clip(vc->ar, vc->v3d, bezt->vec[0], s, pmat, vmat);
+                                               view3d_project_short_clip(vc->ar, bezt->vec[0], s, pmat, vmat);
                                                if (s[0] != IS_CLIPPED)
                                                        func(userData, nu, NULL, bezt, 0, s[0], s[1]);
-                                               view3d_project_short_clip(vc->ar, vc->v3d, bezt->vec[1], s, pmat, vmat);
+                                               view3d_project_short_clip(vc->ar, bezt->vec[1], s, pmat, vmat);
                                                if (s[0] != IS_CLIPPED)
                                                        func(userData, nu, NULL, bezt, 1, s[0], s[1]);
-                                               view3d_project_short_clip(vc->ar, vc->v3d, bezt->vec[2], s, pmat, vmat);
+                                               view3d_project_short_clip(vc->ar, bezt->vec[2], s, pmat, vmat);
                                                if (s[0] != IS_CLIPPED)
                                                        func(userData, nu, NULL, bezt, 2, s[0], s[1]);
                                        }
@@ -1334,7 +1346,7 @@ void nurbs_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, Nurb
                                BPoint *bp = &nu->bp[i];
 
                                if(bp->hide==0) {
-                                       view3d_project_short_clip(vc->ar, vc->v3d, bp->vec, s, pmat, vmat);
+                                       view3d_project_short_clip(vc->ar, bp->vec, s, pmat, vmat);
                                        func(userData, nu, bp, NULL, -1, s[0], s[1]);
                                }
                        }
@@ -1759,7 +1771,7 @@ static void draw_em_fancy_edges(Scene *scene, View3D *v3d, DerivedMesh *cageDM,
        }
 }      
 
-static void draw_em_measure_stats(View3D *v3d, Object *ob, EditMesh *em)
+static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, EditMesh *em)
 {
        EditEdge *eed;
        EditFace *efa;
@@ -1788,7 +1800,7 @@ static void draw_em_measure_stats(View3D *v3d, Object *ob, EditMesh *em)
        if(v3d->zbuf && (v3d->flag & V3D_ZBUF_SELECT)==0)
                glDisable(GL_DEPTH_TEST);
 
-       if(v3d->zbuf) bglPolygonOffset(v3d->dist, 5.0);
+       if(v3d->zbuf) bglPolygonOffset(rv3d->dist, 5.0);
        
        if(G.f & G_DRAW_EDGELEN) {
                UI_GetThemeColor3fv(TH_TEXT, col);
@@ -1923,7 +1935,7 @@ static void draw_em_measure_stats(View3D *v3d, Object *ob, EditMesh *em)
        
        if(v3d->zbuf) {
                glEnable(GL_DEPTH_TEST);
-               bglPolygonOffset(v3d->dist, 0.0);
+               bglPolygonOffset(rv3d->dist, 0.0);
        }
 }
 
@@ -1946,7 +1958,7 @@ static int draw_em_fancy__setGLSLFaceOpts(void *userData, int index)
        return (efa->h==0);
 }
 
-static void draw_em_fancy(Scene *scene, View3D *v3d, Object *ob, EditMesh *em, DerivedMesh *cageDM, DerivedMesh *finalDM, int dt)
+static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, EditMesh *em, DerivedMesh *cageDM, DerivedMesh *finalDM, int dt)
 {
        Mesh *me = ob->data;
        EditFace *efa_act = EM_get_actFace(em, 0); /* annoying but active faces is stored differently */
@@ -1979,7 +1991,7 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, Object *ob, EditMesh *em, D
                                glFrontFace(GL_CCW);
                        }
                        else {
-                               draw_mesh_textured(scene, v3d, ob, finalDM, 0);
+                               draw_mesh_textured(scene, v3d, rv3d, ob, finalDM, 0);
                        }
                }
                else {
@@ -1998,7 +2010,7 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, Object *ob, EditMesh *em, D
                // write to show selected edge wires better
                UI_ThemeColor(TH_WIRE);
 
-               bglPolygonOffset(v3d->dist, 1.0);
+               bglPolygonOffset(rv3d->dist, 1.0);
                glDepthMask(0);
        } 
        else {
@@ -2096,12 +2108,12 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, Object *ob, EditMesh *em, D
                }
 
                if(G.f & (G_DRAW_EDGELEN|G_DRAW_FACEAREA|G_DRAW_EDGEANG))
-                       draw_em_measure_stats(v3d, ob, em);
+                       draw_em_measure_stats(v3d, rv3d, ob, em);
        }
 
        if(dt>OB_WIRE) {
                glDepthMask(1);
-               bglPolygonOffset(v3d->dist, 0.0);
+               bglPolygonOffset(rv3d->dist, 0.0);
                GPU_disable_material();
        }
 
@@ -2140,7 +2152,7 @@ static int wpaint__setSolidDrawOptions(void *userData, int index, int *drawSmoot
        return 1;
 }
 
-static void draw_mesh_fancy(Scene *scene, View3D *v3d, Base *base, int dt, int flag)
+static void draw_mesh_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt, int flag)
 {
        Object *ob= base->object;
        Mesh *me = ob->data;
@@ -2200,7 +2212,7 @@ static void draw_mesh_fancy(Scene *scene, View3D *v3d, Base *base, int dt, int f
                        glFrontFace(GL_CCW);
                }
                else {
-                       draw_mesh_textured(scene, v3d, ob, dm, faceselect);
+                       draw_mesh_textured(scene, v3d, rv3d, ob, dm, faceselect);
                }
 
                if(!faceselect) {
@@ -2333,7 +2345,7 @@ static void draw_mesh_fancy(Scene *scene, View3D *v3d, Base *base, int dt, int f
                                * otherwise this wire is to overlay solid mode faces so do some depth buffer tricks.
                                */
                if (dt!=OB_WIRE && draw_wire==2) {
-                       bglPolygonOffset(v3d->dist, 1.0);
+                       bglPolygonOffset(rv3d->dist, 1.0);
                        glDepthMask(0); // disable write in zbuffer, selected edge wires show better
                }
                
@@ -2341,7 +2353,7 @@ static void draw_mesh_fancy(Scene *scene, View3D *v3d, Base *base, int dt, int f
                
                if (dt!=OB_WIRE && draw_wire==2) {
                        glDepthMask(1);
-                       bglPolygonOffset(v3d->dist, 0.0);
+                       bglPolygonOffset(rv3d->dist, 0.0);
                }
        }
 
@@ -2349,7 +2361,7 @@ static void draw_mesh_fancy(Scene *scene, View3D *v3d, Base *base, int dt, int f
 }
 
 /* returns 1 if nothing was drawn, for detecting to draw an object center */
-static int draw_mesh_object(Scene *scene, View3D *v3d, Base *base, int dt, int flag)
+static int draw_mesh_object(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt, int flag)
 {
        Object *ob= base->object;
        Object *obedit= scene->obedit; // XXX hrumf, see below
@@ -2374,10 +2386,10 @@ static int draw_mesh_object(Scene *scene, View3D *v3d, Base *base, int dt, int f
                if(dt>OB_WIRE) {
                        // no transp in editmode, the fancy draw over goes bad then
                        glsl = draw_glsl_material(scene, ob, v3d, dt);
-                       GPU_set_object_materials(v3d, scene, ob, glsl, NULL);
+                       GPU_set_object_materials(v3d, rv3d, scene, ob, glsl, NULL);
                }
 
-               draw_em_fancy(scene, v3d, ob, em, cageDM, finalDM, dt);
+               draw_em_fancy(scene, v3d, rv3d, ob, em, cageDM, finalDM, dt);
 
                if (obedit!=ob && finalDM)
                        finalDM->release(finalDM);
@@ -2388,16 +2400,16 @@ static int draw_mesh_object(Scene *scene, View3D *v3d, Base *base, int dt, int f
 //     }
        else {
                /* don't create boundbox here with mesh_get_bb(), the derived system will make it, puts deformed bb's OK */
-               if(me->totface<=4 || boundbox_clip(v3d, ob->obmat, (ob->bb)? ob->bb: me->bb)) {
+               if(me->totface<=4 || boundbox_clip(rv3d, ob->obmat, (ob->bb)? ob->bb: me->bb)) {
                        glsl = draw_glsl_material(scene, ob, v3d, dt);
                        check_alpha = check_material_alpha(base, me, glsl);
 
                        if(dt==OB_SOLID || glsl) {
-                               GPU_set_object_materials(v3d, scene, ob, glsl,
+                               GPU_set_object_materials(v3d, rv3d, scene, ob, glsl,
                                        (check_alpha)? &do_alpha_pass: NULL);
                        }
 
-                       draw_mesh_fancy(scene, v3d, base, dt, flag);
+                       draw_mesh_fancy(scene, v3d, rv3d, base, dt, flag);
                        
                        if(me->totvert==0) retval= 1;
                }
@@ -2677,7 +2689,7 @@ static void drawDispListshaded(ListBase *lb, Object *ob)
 }
 
 /* returns 1 when nothing was drawn */
-static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
+static int drawDispList(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt)
 {
        Object *ob= base->object;
        ListBase *lb=0;
@@ -2708,7 +2720,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                        }
                        else {
                                if(draw_glsl_material(scene, ob, v3d, dt)) {
-                                       GPU_set_object_materials(v3d, scene, ob, 1, NULL);
+                                       GPU_set_object_materials(v3d, rv3d, scene, ob, 1, NULL);
                                        drawDispListsolid(lb, ob, 1);
                                }
                                else if(dt == OB_SHADED) {
@@ -2716,7 +2728,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                                        drawDispListshaded(lb, ob);
                                }
                                else {
-                                       GPU_set_object_materials(v3d, scene, ob, 0, NULL);
+                                       GPU_set_object_materials(v3d, rv3d, scene, ob, 0, NULL);
                                        glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
                                        drawDispListsolid(lb, ob, 0);
                                }
@@ -2746,7 +2758,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                        if(dl->nors==NULL) addnormalsDispList(ob, lb);
                        
                        if(draw_glsl_material(scene, ob, v3d, dt)) {
-                               GPU_set_object_materials(v3d, scene, ob, 1, NULL);
+                               GPU_set_object_materials(v3d, rv3d, scene, ob, 1, NULL);
                                drawDispListsolid(lb, ob, 1);
                        }
                        else if(dt==OB_SHADED) {
@@ -2754,7 +2766,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                                drawDispListshaded(lb, ob);
                        }
                        else {
-                               GPU_set_object_materials(v3d, scene, ob, 0, NULL);
+                               GPU_set_object_materials(v3d, rv3d, scene, ob, 0, NULL);
                                glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
                        
                                drawDispListsolid(lb, ob, 0);
@@ -2774,7 +2786,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                        if(solid) {
                                
                                if(draw_glsl_material(scene, ob, v3d, dt)) {
-                                       GPU_set_object_materials(v3d, scene, ob, 1, NULL);
+                                       GPU_set_object_materials(v3d, rv3d, scene, ob, 1, NULL);
                                        drawDispListsolid(lb, ob, 1);
                                }
                                else if(dt == OB_SHADED) {
@@ -2783,7 +2795,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
                                        drawDispListshaded(lb, ob);
                                }
                                else {
-                                       GPU_set_object_materials(v3d, scene, ob, 0, NULL);
+                                       GPU_set_object_materials(v3d, rv3d, scene, ob, 0, NULL);
                                        glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
                                
                                        drawDispListsolid(lb, ob, 0);
@@ -2810,7 +2822,7 @@ static int drawDispList(Scene *scene, View3D *v3d, Base *base, int dt)
 /* 5. start filling the arrays                         */
 /* 6. draw the arrays                                          */
 /* 7. clean up                                                         */
-static void draw_new_particle_system(Scene *scene, View3D *v3d, Base *base, ParticleSystem *psys, int dt)
+static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, ParticleSystem *psys, int dt)
 {
        Object *ob=base->object;
        ParticleSystemModifierData *psmd;
@@ -2899,7 +2911,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, Base *base, Part
 
        timestep= psys_get_timestep(part);
 
-       wmLoadMatrix(v3d->viewmat);
+       wmLoadMatrix(rv3d->viewmat);
 
        if( (base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP) ) {
                float mat[4][4];
@@ -2935,15 +2947,15 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, Base *base, Part
                        break;
                case PART_DRAW_CIRC:
                        /* calculate view aligned matrix: */
-                       Mat4CpyMat4(imat, v3d->viewinv);
+                       Mat4CpyMat4(imat, rv3d->viewinv);
                        Normalize(imat[0]);
                        Normalize(imat[1]);
                        /* no break! */
                case PART_DRAW_CROSS:
                case PART_DRAW_AXIS:
                        /* lets calculate the scale: */
-                       pixsize= v3d->persmat[0][3]*ob->obmat[3][0]+ v3d->persmat[1][3]*ob->obmat[3][1]+ v3d->persmat[2][3]*ob->obmat[3][2]+ v3d->persmat[3][3];
-                       pixsize*= v3d->pixsize;
+                       pixsize= rv3d->persmat[0][3]*ob->obmat[3][0]+ rv3d->persmat[1][3]*ob->obmat[3][1]+ rv3d->persmat[2][3]*ob->obmat[3][2]+ rv3d->persmat[3][3];
+                       pixsize*= rv3d->pixsize;
                        if(part->draw_size==0.0)
                                pixsize*=2.0;
                        else
@@ -2984,7 +2996,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, Base *base, Part
                        break;
        }
        if(part->draw & PART_DRAW_SIZE && part->draw_as!=PART_DRAW_CIRC){
-               Mat4CpyMat4(imat, v3d->viewinv);
+               Mat4CpyMat4(imat, rv3d->viewinv);
                Normalize(imat[0]);
                Normalize(imat[1]);
        }
@@ -3486,11 +3498,11 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, Base *base, Part
                psys->lattice= NULL;
        }
 
-       wmLoadMatrix(v3d->viewmat);
+       wmLoadMatrix(rv3d->viewmat);
        wmMultMatrix(ob->obmat);        // bring back local matrix for dtx
 }
 
-static void draw_particle_edit(Scene *scene, View3D *v3d, Object *ob, ParticleSystem *psys, int dt)
+static void draw_particle_edit(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, ParticleSystem *psys, int dt)
 {
        ParticleEdit *edit = psys->edit;
        ParticleData *pa;
@@ -3522,7 +3534,7 @@ static void draw_particle_edit(Scene *scene, View3D *v3d, Object *ob, ParticleSy
        if((v3d->flag & V3D_ZBUF_SELECT)==0)
                glDisable(GL_DEPTH_TEST);
 
-       wmLoadMatrix(v3d->viewmat);
+       wmLoadMatrix(rv3d->viewmat);
 
        /* get selection theme colors */
        UI_GetThemeColor3ubv(TH_VERTEX_SELECT, sel);
@@ -3878,7 +3890,7 @@ static void draw_editnurb(Object *ob, Nurb *nurb, int sel)
        }
 }
 
-static void drawnurb(Scene *scene, View3D *v3d, Base *base, Nurb *nurb, int dt)
+static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, Nurb *nurb, int dt)
 {
        Object *ob= base->object;
        Curve *cu = ob->data;
@@ -3889,7 +3901,7 @@ static void drawnurb(Scene *scene, View3D *v3d, Base *base, Nurb *nurb, int dt)
 
        /* DispList */
        UI_ThemeColor(TH_WIRE);
-       drawDispList(scene, v3d, base, dt);
+       drawDispList(scene, v3d, rv3d, base, dt);
 
        if(v3d->zbuf) glDisable(GL_DEPTH_TEST);
        
@@ -4171,7 +4183,7 @@ static void drawcone(float *vec, float radius, float height, float tmat[][4])
        glEnd();
 }
 /* return 1 if nothing was drawn */
-static int drawmball(Scene *scene, View3D *v3d, Base *base, int dt)
+static int drawmball(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt)
 {
        Object *ob= base->object;
        MetaBall *mb;
@@ -4183,12 +4195,12 @@ static int drawmball(Scene *scene, View3D *v3d, Base *base, int dt)
 
        if(mb->editelems) {
                UI_ThemeColor(TH_WIRE);
-               if((G.f & G_PICKSEL)==0 ) drawDispList(scene, v3d, base, dt);
+               if((G.f & G_PICKSEL)==0 ) drawDispList(scene, v3d, rv3d, base, dt);
                ml= mb->editelems->first;
        }
        else {
                if((base->flag & OB_FROMDUPLI)==0) 
-                       drawDispList(scene, v3d, base, dt);
+                       drawDispList(scene, v3d, rv3d, base, dt);
                ml= mb->elems.first;
        }
 
@@ -4553,7 +4565,7 @@ static void drawtexspace(Object *ob)
 }
 
 /* draws wire outline */
-static void drawSolidSelect(Scene *scene, View3D *v3d, Base *base) 
+static void drawSolidSelect(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base) 
 {
        Object *ob= base->object;
        
@@ -4562,7 +4574,7 @@ static void drawSolidSelect(Scene *scene, View3D *v3d, Base *base)
        
        if(ELEM3(ob->type, OB_FONT,OB_CURVE, OB_SURF)) {
                Curve *cu = ob->data;
-               if (displist_has_faces(&cu->disp) && boundbox_clip(v3d, ob->obmat, cu->bb)) {
+               if (displist_has_faces(&cu->disp) && boundbox_clip(rv3d, ob->obmat, cu->bb)) {
                        draw_index_wire= 0;
                        drawDispListwire(&cu->disp);
                        draw_index_wire= 1;
@@ -4573,14 +4585,14 @@ static void drawSolidSelect(Scene *scene, View3D *v3d, Base *base)
        }
        else if(ob->type==OB_ARMATURE) {
                if(!(ob->flag & OB_POSEMODE))
-                       draw_armature(scene, v3d, base, OB_WIRE, 0);
+                       draw_armature(scene, v3d, rv3d, base, OB_WIRE, 0);
        }
 
        glLineWidth(1.0);
        glDepthMask(1);
 }
 
-static void drawWireExtra(Scene *scene, View3D *v3d, Object *ob) 
+static void drawWireExtra(Scene *scene, RegionView3D *rv3d, Object *ob) 
 {
        // XXX scene->obedit warning
        if(ob!=scene->obedit && (ob->flag & SELECT)) {
@@ -4605,12 +4617,12 @@ static void drawWireExtra(Scene *scene, View3D *v3d, Object *ob)
                }
        }
        
-       bglPolygonOffset(v3d->dist, 1.0);
+       bglPolygonOffset(rv3d->dist, 1.0);
        glDepthMask(0); // disable write in zbuffer, selected edge wires show better
        
        if (ELEM3(ob->type, OB_FONT, OB_CURVE, OB_SURF)) {
                Curve *cu = ob->data;
-               if (boundbox_clip(v3d, ob->obmat, cu->bb)) {
+               if (boundbox_clip(rv3d, ob->obmat, cu->bb)) {
                        if (ob->type==OB_CURVE)
                                draw_index_wire= 0;
                        drawDispListwire(&cu->disp);
@@ -4622,7 +4634,7 @@ static void drawWireExtra(Scene *scene, View3D *v3d, Object *ob)
        }
 
        glDepthMask(1);
-       bglPolygonOffset(v3d->dist, 0.0);
+       bglPolygonOffset(rv3d->dist, 0.0);
 }
 
 /* should be called in view space */
@@ -4701,6 +4713,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
        static int warning_recursive= 0;
        Object *ob;
        Curve *cu;
+       RegionView3D *rv3d= ar->regiondata;
        //float cfraont;
        float vec1[3], vec2[3];
        unsigned int col=0;
@@ -4814,7 +4827,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
 
        /* which wire color */
        if((flag & DRAW_CONSTCOLOR) == 0) {
-               project_short(ar, v3d, ob->obmat[3], &base->sx);
+               project_short(ar, ob->obmat[3], &base->sx);
 
                if((G.moving & G_TRANSFORM_OBJ) && (base->flag & (SELECT+BA_WAS_SEL))) UI_ThemeColor(TH_TRANSFORM);
                else {
@@ -4903,7 +4916,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
        if((v3d->flag & V3D_SELECT_OUTLINE) && ob->type!=OB_MESH) {
                if(dt>OB_WIRE && dt<OB_TEXTURE && ob!=scene->obedit && (flag && DRAW_SCENESET)==0) {
                        if (!(ob->dtx&OB_DRAWWIRE) && (ob->flag&SELECT) && !(flag&DRAW_PICKING)) {
-                               drawSolidSelect(scene, v3d, base);
+                               drawSolidSelect(scene, v3d, rv3d, base);
                        }
                }
        }
@@ -4911,7 +4924,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
        switch( ob->type) {
                case OB_MESH:
                        if (!(base->flag&OB_RADIO)) {
-                               empty_object= draw_mesh_object(scene, v3d, base, dt, flag);
+                               empty_object= draw_mesh_object(scene, v3d, rv3d, base, dt, flag);
                                if(flag!=DRAW_CONSTCOLOR) dtx &= ~OB_DRAWWIRE; // mesh draws wire itself
                        }
 
@@ -4925,10 +4938,10 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                                if (cu->flag & CU_FAST) {
                                        cpack(0xFFFFFF);
                                        set_inverted_drawing(1);
-                                       drawDispList(scene, v3d, base, OB_WIRE);
+                                       drawDispList(scene, v3d, rv3d, base, OB_WIRE);
                                        set_inverted_drawing(0);
                                } else {
-                                       drawDispList(scene, v3d, base, dt);
+                                       drawDispList(scene, v3d, rv3d, base, dt);
                                }
 
                                if (cu->linewidth != 0.0) {
@@ -5003,8 +5016,8 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        }
                        else if(dt==OB_BOUNDBOX) 
                                draw_bounding_volume(scene, ob);
-                       else if(boundbox_clip(v3d, ob->obmat, cu->bb)) 
-                               empty_object= drawDispList(scene, v3d, base, dt);
+                       else if(boundbox_clip(rv3d, ob->obmat, cu->bb)) 
+                               empty_object= drawDispList(scene, v3d, rv3d, base, dt);
 
                        break;
                case OB_CURVE:
@@ -5014,12 +5027,12 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        if (cu->disp.first==NULL) makeDispListCurveTypes(scene, ob, 0);
 
                        if(cu->editnurb) {
-                               drawnurb(scene, v3d, base, cu->editnurb->first, dt);
+                               drawnurb(scene, v3d, rv3d, base, cu->editnurb->first, dt);
                        }
                        else if(dt==OB_BOUNDBOX) 
                                draw_bounding_volume(scene, ob);
-                       else if(boundbox_clip(v3d, ob->obmat, cu->bb)) {
-                               empty_object= drawDispList(scene, v3d, base, dt);
+                       else if(boundbox_clip(rv3d, ob->obmat, cu->bb)) {
+                               empty_object= drawDispList(scene, v3d, rv3d, base, dt);
                                
                                if(cu->path)
                                        curve_draw_speed(scene, ob);
@@ -5030,29 +5043,29 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        MetaBall *mb= ob->data;
                        
                        if(mb->editelems) 
-                               drawmball(scene, v3d, base, dt);
+                               drawmball(scene, v3d, rv3d, base, dt);
                        else if(dt==OB_BOUNDBOX) 
                                draw_bounding_volume(scene, ob);
                        else 
-                               empty_object= drawmball(scene, v3d, base, dt);
+                               empty_object= drawmball(scene, v3d, rv3d, base, dt);
                        break;
                }
                case OB_EMPTY:
                        drawaxes(ob->empty_drawsize, flag, ob->empty_drawtype);
                        break;
                case OB_LAMP:
-                       drawlamp(scene, v3d, ob);
+                       drawlamp(scene, v3d, rv3d, ob);
                        if(dtx || (base->flag & SELECT)) wmMultMatrix(ob->obmat);
                        break;
                case OB_CAMERA:
-                       drawcamera(scene, v3d, ob, flag);
+                       drawcamera(scene, v3d, rv3d, ob, flag);
                        break;
                case OB_LATTICE:
                        drawlattice(scene, v3d, ob);
                        break;
                case OB_ARMATURE:
                        if(dt>OB_WIRE) GPU_enable_material(0, NULL); // we use default material
-                       empty_object= draw_armature(scene, v3d, base, dt, flag);
+                       empty_object= draw_armature(scene, v3d, rv3d, base, dt, flag);
                        if(dt>OB_WIRE) GPU_disable_material();
                        break;
                default:
@@ -5071,12 +5084,12 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                glDepthMask(GL_FALSE);
                
                for(psys=ob->particlesystem.first; psys; psys=psys->next)
-                       draw_new_particle_system(scene, v3d, base, psys, dt);
+                       draw_new_particle_system(scene, v3d, rv3d, base, psys, dt);
                
                if(G.f & G_PARTICLEEDIT && ob==OBACT) {
                        psys= NULL; // XXX PE_get_current(ob);
                        if(psys && !scene->obedit && psys_in_edit_mode(scene, psys))
-                               draw_particle_edit(scene, v3d, ob, psys, dt);
+                               draw_particle_edit(scene, v3d, rv3d, ob, psys, dt);
                }
                glDepthMask(GL_TRUE); 
                if(col) cpack(col);
@@ -5115,7 +5128,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        }
                }
                /*if(dtx & OB_DRAWIMAGE) drawDispListwire(&ob->disp);*/
-               if((dtx & OB_DRAWWIRE) && dt>=OB_SOLID) drawWireExtra(scene, v3d, ob);
+               if((dtx & OB_DRAWWIRE) && dt>=OB_SOLID) drawWireExtra(scene, rv3d, ob);
        }
 
        if(dt<OB_SHADED) {
@@ -5133,7 +5146,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                }
        }
 
-       wmLoadMatrix(v3d->viewmat);
+       wmLoadMatrix(rv3d->viewmat);
 
        if(zbufoff) glDisable(GL_DEPTH_TEST);
 
@@ -5161,7 +5174,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        } 
                        else if((flag & DRAW_CONSTCOLOR)==0) {
                                /* we don't draw centers for duplicators and sets */
-                               drawcentercircle(v3d, ob->obmat[3], do_draw_center, ob->id.lib || ob->id.us>1);
+                               drawcentercircle(v3d, rv3d, ob->obmat[3], do_draw_center, ob->id.lib || ob->id.us>1);
                        }
                }
        }
@@ -5231,41 +5244,6 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
        free_old_images();
 }
 
-void draw_object_ext(ARegion *ar, View3D *v3d, Scene *scene, Base *base)
-{
-       
-       if(v3d==NULL || base==NULL) return;
-       
-       if(v3d->drawtype > OB_WIRE) {
-               v3d->zbuf= 1;
-               glEnable(GL_DEPTH_TEST);
-       }
-       
-       G.f |= G_DRAW_EXT;
-
-       glDrawBuffer(GL_FRONT);
-// XXX persp(PERSP_VIEW);
-
-       if(v3d->flag & V3D_CLIPPING)
-               view3d_set_clipping(v3d);
-       
-       draw_object(scene, ar, v3d, base, 0);
-
-       if(v3d->flag & V3D_CLIPPING)
-               view3d_clr_clipping();
-       
-       G.f &= ~G_DRAW_EXT;
-
-       bglFlush();             /* reveil frontbuffer drawing */
-       glDrawBuffer(GL_BACK);
-       
-       if(v3d->zbuf) {
-               v3d->zbuf= 0;
-               glDisable(GL_DEPTH_TEST);
-       }
-// XXX ar->win_swap= WIN_FRONT_OK;
-}
-
 /* ***************** BACKBUF SEL (BBS) ********* */
 
 static void bbs_mesh_verts__mapFunc(void *userData, int index, float *co, float *no_f, short *no_s)
@@ -5372,7 +5350,7 @@ static void bbs_mesh_solid(Scene *scene, View3D *v3d, Object *ob)
        dm->release(dm);
 }
 
-void draw_object_backbufsel(Scene *scene, View3D *v3d, Object *ob)
+void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob)
 {
 
        wmMultMatrix(ob->obmat);
@@ -5396,7 +5374,7 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, Object *ob)
                        else
                                em_solidoffs= 1;
                        
-                       bglPolygonOffset(v3d->dist, 1.0);
+                       bglPolygonOffset(rv3d->dist, 1.0);
                        
                        // we draw edges always, for loop (select) tools
                        bbs_mesh_wire(dm, em_solidoffs);
@@ -5409,7 +5387,7 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, Object *ob)
                        }
                        else em_vertoffs= em_wireoffs;
                        
-                       bglPolygonOffset(v3d->dist, 0.0);
+                       bglPolygonOffset(rv3d->dist, 0.0);
 
                        dm->release(dm);
 
@@ -5423,7 +5401,7 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, Object *ob)
                break;
        }
 
-       wmLoadMatrix(v3d->viewmat);
+       wmLoadMatrix(rv3d->viewmat);
 }
 
 
@@ -5431,7 +5409,8 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, Object *ob)
 /*               assumes all matrices/etc set OK */
 
 /* helper function for drawing object instances - meshes */
-static void draw_object_mesh_instance(Scene *scene, View3D *v3d, Object *ob, int dt, int outline)
+static void draw_object_mesh_instance(Scene *scene, View3D *v3d, RegionView3D *rv3d, 
+                                                                         Object *ob, int dt, int outline)
 {
        Mesh *me= ob->data;
        DerivedMesh *dm=NULL, *edm=NULL;
@@ -5454,7 +5433,7 @@ static void draw_object_mesh_instance(Scene *scene, View3D *v3d, Object *ob, int
 
                if(dm) {
                        glsl = draw_glsl_material(scene, ob, v3d, dt);
-                       GPU_set_object_materials(v3d, scene, ob, glsl, NULL);
+                       GPU_set_object_materials(v3d, rv3d, scene, ob, glsl, NULL);
                }
                else {
                        glEnable(GL_COLOR_MATERIAL);
@@ -5480,14 +5459,14 @@ static void draw_object_mesh_instance(Scene *scene, View3D *v3d, Object *ob, int
        if(dm) dm->release(dm);
 }
 
-void draw_object_instance(Scene *scene, View3D *v3d, Object *ob, int dt, int outline)
+void draw_object_instance(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, int dt, int outline)
 {
        if (ob == NULL) 
                return;
                
        switch (ob->type) {
                case OB_MESH:
-                       draw_object_mesh_instance(scene, v3d, ob, dt, outline);
+                       draw_object_mesh_instance(scene, v3d, rv3d, ob, dt, outline);
                        break;
                case OB_EMPTY:
                        drawaxes(ob->empty_drawsize, 0, ob->empty_drawtype);
index a645f8f359d0d0ca6732c0d7882aa63aa041cbba..0bb891e11b4722aecb9ba68b9626488c9e41a89f 100644 (file)
@@ -66,53 +66,54 @@ static SpaceLink *view3d_new(const bContext *C)
 {
        Scene *scene= CTX_data_scene(C);
        ARegion *ar;
-       View3D *vd;
+       View3D *v3d;
+       RegionView3D *rv3d;
        
-       vd= MEM_callocN(sizeof(View3D), "initview3d");
-       vd->spacetype= SPACE_VIEW3D;
-       vd->blockscale= 0.7f;
-       vd->lay= vd->layact= 1;
+       v3d= MEM_callocN(sizeof(View3D), "initview3d");
+       v3d->spacetype= SPACE_VIEW3D;
+       v3d->blockscale= 0.7f;
+       v3d->lay= v3d->layact= 1;
        if(scene) {
-               vd->lay= vd->layact= scene->lay;
-               vd->camera= scene->camera;
+               v3d->lay= v3d->layact= scene->lay;
+               v3d->camera= scene->camera;
        }
-       vd->scenelock= 1;
-       vd->grid= 1.0f;
-       vd->gridlines= 16;
-       vd->gridsubdiv = 10;
-       vd->drawtype= OB_WIRE;
-       
-       vd->gridflag |= V3D_SHOW_X;
-       vd->gridflag |= V3D_SHOW_Y;
-       vd->gridflag |= V3D_SHOW_FLOOR;
-       vd->gridflag &= ~V3D_SHOW_Z;
-       
-       vd->depths= NULL;
-       
-       /* XXX move view data to region? */
-       vd->viewquat[0]= 1.0f;
-       vd->viewquat[1]= vd->viewquat[2]= vd->viewquat[3]= 0.0f;
-       vd->persp= 1;
-       vd->view= 7;
-       vd->dist= 10.0;
-       vd->lens= 35.0f;
-       vd->near= 0.01f;
-       vd->far= 500.0f;
+       v3d->scenelock= 1;
+       v3d->grid= 1.0f;
+       v3d->gridlines= 16;
+       v3d->gridsubdiv = 10;
+       v3d->drawtype= OB_WIRE;
+       
+       v3d->gridflag |= V3D_SHOW_X;
+       v3d->gridflag |= V3D_SHOW_Y;
+       v3d->gridflag |= V3D_SHOW_FLOOR;
+       v3d->gridflag &= ~V3D_SHOW_Z;
+       
+       v3d->lens= 35.0f;
+       v3d->near= 0.01f;
+       v3d->far= 500.0f;
        
        /* header */
        ar= MEM_callocN(sizeof(ARegion), "header for view3d");
        
-       BLI_addtail(&vd->regionbase, ar);
+       BLI_addtail(&v3d->regionbase, ar);
        ar->regiontype= RGN_TYPE_HEADER;
        ar->alignment= RGN_ALIGN_BOTTOM;
        
        /* main area */
        ar= MEM_callocN(sizeof(ARegion), "main area for view3d");
        
-       BLI_addtail(&vd->regionbase, ar);
+       BLI_addtail(&v3d->regionbase, ar);
        ar->regiontype= RGN_TYPE_WINDOW;
        
-       return (SpaceLink *)vd;
+       ar->regiondata= MEM_callocN(sizeof(RegionView3D), "region view3d");
+       rv3d= ar->regiondata;
+       rv3d->viewquat[0]= 1.0f;
+       rv3d->persp= 1;
+       rv3d->view= 7;
+       rv3d->dist= 10.0;
+       Mat4One(rv3d->twmat);
+       
+       return (SpaceLink *)v3d;
 }
 
 /* not spacelink itself */
@@ -126,19 +127,8 @@ static void view3d_free(SpaceLink *sl)
        }
        
        if(vd->localvd) MEM_freeN(vd->localvd);
-       if(vd->clipbb) MEM_freeN(vd->clipbb);
-       if(vd->depths) {
-               if(vd->depths->depths) MEM_freeN(vd->depths->depths);
-               MEM_freeN(vd->depths);
-               vd->depths= NULL;
-       }
-       
-// XXX retopo_free_view_data(vd);
        
        if(vd->properties_storage) MEM_freeN(vd->properties_storage);
-       if(vd->ri) { 
-// XXX         BIF_view3d_previewrender_free(vd);
-       }
        
 }
 
@@ -157,8 +147,6 @@ static SpaceLink *view3d_duplicate(SpaceLink *sl)
        /* clear or remove stuff from old */
        
 // XXX BIF_view3d_previewrender_free(v3do);
-       v3do->depths= NULL;
-       v3do->retopo_view_data= NULL;
        
        if(v3do->localvd) {
 // XXX         restore_localviewdata(v3do);
@@ -174,8 +162,6 @@ static SpaceLink *view3d_duplicate(SpaceLink *sl)
                v3dn->bgpic= MEM_dupallocN(v3dn->bgpic);
                if(v3dn->bgpic->ima) v3dn->bgpic->ima->id.us++;
        }
-       v3dn->clipbb= MEM_dupallocN(v3dn->clipbb);
-       v3dn->ri= NULL;
        v3dn->properties_storage= NULL;
        
        return (SpaceLink *)v3dn;
@@ -200,6 +186,54 @@ static void view3d_main_area_init(wmWindowManager *wm, ARegion *ar)
        
 }
 
+/* type callback, not region itself */
+static void view3d_main_area_free(ARegion *ar)
+{
+       RegionView3D *rv3d= ar->regiondata;
+       
+       if(rv3d) {
+               if(rv3d->localvd) MEM_freeN(rv3d->localvd);
+               if(rv3d->clipbb) MEM_freeN(rv3d->clipbb);
+
+               // XXX  retopo_free_view_data(rv3d);
+               if(rv3d->ri) { 
+                       // XXX          BIF_view3d_previewrender_free(rv3d);
+               }
+               
+               if(rv3d->depths) {
+                       if(rv3d->depths->depths) MEM_freeN(rv3d->depths->depths);
+                       MEM_freeN(rv3d->depths);
+               }
+               MEM_freeN(rv3d);
+               ar->regiondata= NULL;
+       }
+}
+
+/* copy regiondata */
+static void *view3d_main_area_duplicate(void *poin)
+{
+       if(poin) {
+               RegionView3D *rv3d= poin, *new;
+       
+               new= MEM_dupallocN(rv3d);
+               if(rv3d->localvd) 
+                       new->localvd= MEM_dupallocN(rv3d->localvd);
+               if(rv3d->clipbb) 
+                       new->clipbb= MEM_dupallocN(rv3d->clipbb);
+               
+               new->depths= NULL;
+               new->retopo_view_data= NULL;
+               new->ri= NULL;
+               new->gpd= NULL;
+               new->sms= NULL;
+               new->smooth_timer= NULL;
+               
+               return new;
+       }
+       return NULL;
+}
+
+
 static void view3d_modal_keymaps(wmWindowManager *wm, ARegion *ar, int stype)
 {
        ListBase *keymap;
@@ -422,6 +456,8 @@ void ED_spacetype_view3d(void)
        art->regionid = RGN_TYPE_WINDOW;
        art->draw= view3d_main_area_draw;
        art->init= view3d_main_area_init;
+       art->free= view3d_main_area_free;
+       art->duplicate= view3d_main_area_duplicate;
        art->listener= view3d_main_area_listener;
        art->cursor= view3d_main_area_cursor;
        BLI_addhead(&st->regiontypes, art);
index 618d30eea60e06d1293fd845379b36b9b65f4b28..b2b4c2afb0d9040fece9ed3e030d97c4a8dbd7e9 100644 (file)
@@ -145,9 +145,9 @@ void circ(float x, float y, float rad)
 
 /* ********* custom clipping *********** */
 
-static void view3d_draw_clipping(View3D *v3d)
+static void view3d_draw_clipping(RegionView3D *rv3d)
 {
-       BoundBox *bb= v3d->clipbb;
+       BoundBox *bb= rv3d->clipbb;
        
        UI_ThemeColorShade(TH_BACK, -8);
        
@@ -163,13 +163,13 @@ static void view3d_draw_clipping(View3D *v3d)
        glEnd();
 }
 
-void view3d_set_clipping(View3D *v3d)
+void view3d_set_clipping(RegionView3D *rv3d)
 {
        double plane[4];
        int a;
        
        for(a=0; a<4; a++) {
-               QUATCOPY(plane, v3d->clip[a]);
+               QUATCOPY(plane, rv3d->clip[a]);
                glClipPlane(GL_CLIP_PLANE0+a, plane);
                glEnable(GL_CLIP_PLANE0+a);
        }
@@ -184,17 +184,17 @@ void view3d_clr_clipping(void)
        }
 }
 
-int view3d_test_clipping(View3D *v3d, float *vec)
+int view3d_test_clipping(RegionView3D *rv3d, float *vec)
 {
        /* vec in world coordinates, returns 1 if clipped */
        float view[3];
        
        VECCOPY(view, vec);
        
-       if(0.0f < v3d->clip[0][3] + INPR(view, v3d->clip[0]))
-               if(0.0f < v3d->clip[1][3] + INPR(view, v3d->clip[1]))
-                       if(0.0f < v3d->clip[2][3] + INPR(view, v3d->clip[2]))
-                               if(0.0f < v3d->clip[3][3] + INPR(view, v3d->clip[3]))
+       if(0.0f < rv3d->clip[0][3] + INPR(view, rv3d->clip[0]))
+               if(0.0f < rv3d->clip[1][3] + INPR(view, rv3d->clip[1]))
+                       if(0.0f < rv3d->clip[2][3] + INPR(view, rv3d->clip[2]))
+                               if(0.0f < rv3d->clip[3][3] + INPR(view, rv3d->clip[3]))
                                        return 0;
        
        return 1;
@@ -252,6 +252,7 @@ void make_axis_color(char *col, char *col2, char axis)
 static void drawgrid(ARegion *ar, View3D *v3d)
 {
        /* extern short bgpicmode; */
+       RegionView3D *rv3d= ar->regiondata;
        float wx, wy, x, y, fw, fx, fy, dx;
        float vec4[4];
        char col[3], col2[3];
@@ -259,7 +260,7 @@ static void drawgrid(ARegion *ar, View3D *v3d)
        
        vec4[0]=vec4[1]=vec4[2]=0.0; 
        vec4[3]= 1.0;
-       Mat4MulVec4fl(v3d->persmat, vec4);
+       Mat4MulVec4fl(rv3d->persmat, vec4);
        fx= vec4[0]; 
        fy= vec4[1]; 
        fw= vec4[3];
@@ -273,7 +274,7 @@ static void drawgrid(ARegion *ar, View3D *v3d)
        vec4[0]=vec4[1]=v3d->grid; 
        vec4[2]= 0.0;
        vec4[3]= 1.0;
-       Mat4MulVec4fl(v3d->persmat, vec4);
+       Mat4MulVec4fl(rv3d->persmat, vec4);
        fx= vec4[0]; 
        fy= vec4[1]; 
        fw= vec4[3];
@@ -359,13 +360,13 @@ static void drawgrid(ARegion *ar, View3D *v3d)
        setlinestyle(0);
        
        /* center cross */
-       if(v3d->view==3) make_axis_color(col, col2, 'y');
+       if(rv3d->view==3) make_axis_color(col, col2, 'y');
        else make_axis_color(col, col2, 'x');
        glColor3ubv((GLubyte *)col2);
        
        fdrawline(0.0,  y,  (float)ar->winx,  y); 
        
-       if(v3d->view==7) make_axis_color(col, col2, 'y');
+       if(rv3d->view==7) make_axis_color(col, col2, 'y');
        else make_axis_color(col, col2, 'z');
        glColor3ubv((GLubyte *)col2);
 
@@ -506,7 +507,7 @@ static void drawcursor(Scene *scene, ARegion *ar, View3D *v3d)
        /* we dont want the clipping for cursor */
        flag= v3d->flag;
        v3d->flag= 0;
-       project_short(ar, v3d, give_cursor(scene, v3d), co);
+       project_short(ar, give_cursor(scene, v3d), co);
        v3d->flag= flag;
        
        mx = co[0];
@@ -530,7 +531,7 @@ static void drawcursor(Scene *scene, ARegion *ar, View3D *v3d)
 }
 
 /* Draw a live substitute of the view icon, which is always shown */
-static void draw_view_axis(View3D *v3d)
+static void draw_view_axis(RegionView3D *rv3d)
 {
        const float k = U.rvisize;   /* axis size */
        const float toll = 0.5;      /* used to see when view is quasi-orthogonal */
@@ -558,7 +559,7 @@ static void draw_view_axis(View3D *v3d)
        /* X */
        vec[0] = vec[3] = 1;
        vec[1] = vec[2] = 0;
-       QuatMulVecf(v3d->viewquat, vec);
+       QuatMulVecf(rv3d->viewquat, vec);
        
        make_axis_color((char *)gridcol, (char *)col, 'x');
        rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v);
@@ -579,7 +580,7 @@ static void draw_view_axis(View3D *v3d)
        /* Y */
        vec[1] = vec[3] = 1;
        vec[0] = vec[2] = 0;
-       QuatMulVecf(v3d->viewquat, vec);
+       QuatMulVecf(rv3d->viewquat, vec);
        
        make_axis_color((char *)gridcol, (char *)col, 'y');
        rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v);
@@ -600,7 +601,7 @@ static void draw_view_axis(View3D *v3d)
        /* Z */
        vec[2] = vec[3] = 1;
        vec[1] = vec[0] = 0;
-       QuatMulVecf(v3d->viewquat, vec);
+       QuatMulVecf(rv3d->viewquat, vec);
        
        make_axis_color((char *)gridcol, (char *)col, 'z');
        rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v);
@@ -623,13 +624,13 @@ static void draw_view_axis(View3D *v3d)
 }
 
 
-static void draw_view_icon(View3D *v3d)
+static void draw_view_icon(RegionView3D *rv3d)
 {
        BIFIconID icon;
        
-       if(v3d->view==7) icon= ICON_AXIS_TOP;
-       else if(v3d->view==1) icon= ICON_AXIS_FRONT;
-       else if(v3d->view==3) icon= ICON_AXIS_SIDE;
+       if(rv3d->view==7) icon= ICON_AXIS_TOP;
+       else if(rv3d->view==1) icon= ICON_AXIS_FRONT;
+       else if(rv3d->view==3) icon= ICON_AXIS_SIDE;
        else return ;
        
        glEnable(GL_BLEND);
@@ -640,31 +641,31 @@ static void draw_view_icon(View3D *v3d)
        glDisable(GL_BLEND);
 }
 
-char *view3d_get_name(View3D *v3d)
+static char *view3d_get_name(View3D *v3d, RegionView3D *rv3d)
 {
        char *name = NULL;
        
-       switch (v3d->view) {
+       switch (rv3d->view) {
                case 1:
-                       if (v3d->persp == V3D_ORTHO)
-                               name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Back Ortho" : "Front Ortho";
+                       if (rv3d->persp == V3D_ORTHO)
+                               name = (rv3d->rflag & RV3D_OPP_DIRECTION_NAME) ? "Back Ortho" : "Front Ortho";
                        else
-                               name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Back Persp" : "Front Persp";
+                               name = (rv3d->rflag & RV3D_OPP_DIRECTION_NAME) ? "Back Persp" : "Front Persp";
                        break;
                case 3:
-                       if (v3d->persp == V3D_ORTHO)
-                               name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Left Ortho" : "Right Ortho";
+                       if (rv3d->persp == V3D_ORTHO)
+                               name = (rv3d->rflag & RV3D_OPP_DIRECTION_NAME) ? "Left Ortho" : "Right Ortho";
                        else
-                               name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Left Persp" : "Right Persp";
+                               name = (rv3d->rflag & RV3D_OPP_DIRECTION_NAME) ? "Left Persp" : "Right Persp";
                        break;
                case 7:
-                       if (v3d->persp == V3D_ORTHO)
-                               name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Bottom Ortho" : "Top Ortho";
+                       if (rv3d->persp == V3D_ORTHO)
+                               name = (rv3d->rflag & RV3D_OPP_DIRECTION_NAME) ? "Bottom Ortho" : "Top Ortho";
                        else
-                               name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Bottom Persp" : "Top Persp";
+                               name = (rv3d->rflag & RV3D_OPP_DIRECTION_NAME) ? "Bottom Persp" : "Top Persp";
                        break;
                default:
-                       if (v3d->persp==V3D_CAMOB) {
+                       if (rv3d->persp==V3D_CAMOB) {
                                if ((v3d->camera) && (v3d->camera->type == OB_CAMERA)) {
                                        Camera *cam;
                                        cam = v3d->camera->data;
@@ -673,7 +674,7 @@ char *view3d_get_name(View3D *v3d)
                                        name = "Object as Camera";
                                }
                        } else { 
-                               name = (v3d->persp == V3D_ORTHO) ? "User Ortho" : "User Persp";
+                               name = (rv3d->persp == V3D_ORTHO) ? "User Ortho" : "User Persp";
                        }
                        break;
        }
@@ -683,7 +684,8 @@ char *view3d_get_name(View3D *v3d)
 
 static void draw_viewport_name(ARegion *ar, View3D *v3d)
 {
-       char *name = view3d_get_name(v3d);
+       RegionView3D *rv3d= ar->regiondata;
+       char *name = view3d_get_name(v3d, rv3d);
        char *printable = NULL;
        
        if (v3d->localview) {
@@ -841,6 +843,7 @@ static void view3d_get_viewborder_size(Scene *scene, ARegion *ar, float size_r[2
 
 void calc_viewborder(Scene *scene, ARegion *ar, View3D *v3d, rctf *viewborder_r)
 {
+       RegionView3D *rv3d= ar->regiondata;
        float zoomfac, size[2];
        float dx= 0.0f, dy= 0.0f;
        
@@ -854,7 +857,7 @@ void calc_viewborder(Scene *scene, ARegion *ar, View3D *v3d, rctf *viewborder_r)
                * with multiple keypad presses (ton)
                */
        
-       zoomfac= (M_SQRT2 + v3d->camzoom/50.0);
+       zoomfac= (M_SQRT2 + rv3d->camzoom/50.0);
        zoomfac= (zoomfac*zoomfac)*0.25;
        
        size[0]= size[0]*zoomfac;
@@ -866,8 +869,8 @@ void calc_viewborder(Scene *scene, ARegion *ar, View3D *v3d, rctf *viewborder_r)
        viewborder_r->xmax= viewborder_r->xmin + size[0];
        viewborder_r->ymax= viewborder_r->ymin + size[1];
        
-       dx= ar->winx*v3d->camdx*zoomfac*2.0f;
-       dy= ar->winy*v3d->camdy*zoomfac*2.0f;
+       dx= ar->winx*rv3d->camdx*zoomfac*2.0f;
+       dy= ar->winy*rv3d->camdy*zoomfac*2.0f;
        
        /* apply offset */
        viewborder_r->xmin-= dx;
@@ -888,15 +891,16 @@ void calc_viewborder(Scene *scene, ARegion *ar, View3D *v3d, rctf *viewborder_r)
        }
 }
 
-void view3d_set_1_to_1_viewborder(Scene *scene, ARegion *ar, View3D *v3d)
+void view3d_set_1_to_1_viewborder(Scene *scene, ARegion *ar)
 {
+       RegionView3D *rv3d= ar->regiondata;
        float size[2];
        int im_width= (scene->r.size*scene->r.xsch)/100;
        
        view3d_get_viewborder_size(scene, ar, size);
        
-       v3d->camzoom= (sqrt(4.0*im_width/size[0]) - M_SQRT2)*50.0;
-       v3d->camzoom= CLAMPIS(v3d->camzoom, -30, 300);
+       rv3d->camzoom= (sqrt(4.0*im_width/size[0]) - M_SQRT2)*50.0;
+       rv3d->camzoom= CLAMPIS(rv3d->camzoom, -30, 300);
 }
 
 
@@ -1047,6 +1051,7 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
 
 void backdrawview3d(Scene *scene, ARegion *ar, View3D *v3d)
 {
+       RegionView3D *rv3d= ar->regiondata;
        struct Base *base;
 
 /*for 2.43 release, don't use glext and just define the constant.
@@ -1099,14 +1104,14 @@ void backdrawview3d(Scene *scene, ARegion *ar, View3D *v3d)
                glDisable(GL_DEPTH_TEST);
        }
        
-       if(v3d->flag & V3D_CLIPPING)
-               view3d_set_clipping(v3d);
+       if(rv3d->rflag & RV3D_CLIPPING)
+               view3d_set_clipping(rv3d);
        
        G.f |= G_BACKBUFSEL;
        
        base= (scene->basact);
        if(base && (base->lay & v3d->lay)) {
-               draw_object_backbufsel(scene, v3d, base->object);
+               draw_object_backbufsel(scene, v3d, rv3d, base->object);
        }
 
        v3d->flag &= ~V3D_NEEDBACKBUFDRAW;
@@ -1116,7 +1121,7 @@ void backdrawview3d(Scene *scene, ARegion *ar, View3D *v3d)
        glDisable(GL_DEPTH_TEST);
        glEnable(GL_DITHER);
 
-       if(v3d->flag & V3D_CLIPPING)
+       if(rv3d->rflag & RV3D_CLIPPING)
                view3d_clr_clipping();
 
 #ifdef GL_MULTISAMPLE_ARB
@@ -1279,6 +1284,7 @@ exit:
 
 static void draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d)
 {
+       RegionView3D *rv3d= ar->regiondata;
        BGpic *bgpic;
        Image *ima;
        ImBuf *ibuf= NULL;
@@ -1299,7 +1305,7 @@ static void draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d)
        if(ibuf->rect==NULL)
                IMB_rect_from_float(ibuf);
        
-       if(v3d->persp==2) {
+       if(rv3d->persp==2) {
                rctf vb;
                
                calc_viewborder(scene, ar, v3d, &vb);
@@ -1313,15 +1319,15 @@ static void draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d)
                float sco[2];
                
                /* calc window coord */
-               initgrabz(v3d, 0.0, 0.0, 0.0);
-               window_to_3d(ar, v3d, vec, 1, 0);
+               initgrabz(rv3d, 0.0, 0.0, 0.0);
+               window_to_3d(ar, vec, 1, 0);
                fac= MAX3( fabs(vec[0]), fabs(vec[1]), fabs(vec[1]) );
                fac= 1.0/fac;
                
                asp= ( (float)ibuf->y)/(float)ibuf->x;
                
                vec[0] = vec[1] = vec[2] = 0.0;
-               view3d_project_float(ar, vec, sco, v3d->persmat);
+               view3d_project_float(ar, vec, sco, rv3d->persmat);
                cx = sco[0];
                cy = sco[1];
                
@@ -1463,6 +1469,7 @@ static void view3d_draw_transp(Scene *scene, ARegion *ar, View3D *v3d)
  */
 static void draw_dupli_objects_color(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int color)
 {      
+       RegionView3D *rv3d= ar->regiondata;
        ListBase *lb;
        DupliObject *dob;
        Base tbase;
@@ -1523,9 +1530,9 @@ static void draw_dupli_objects_color(Scene *scene, ARegion *ar, View3D *v3d, Bas
                        }
                        if(use_displist) {
                                wmMultMatrix(dob->mat);
-                               if(boundbox_clip(v3d, dob->mat, bb))
+                               if(boundbox_clip(rv3d, dob->mat, bb))
                                        glCallList(displist);
-                               wmLoadMatrix(v3d->viewmat);
+                               wmLoadMatrix(rv3d->viewmat);
                        }
                        else {
                                Mat4CpyMat4(dob->ob->obmat, dob->mat);
@@ -1562,10 +1569,12 @@ static void draw_dupli_objects(Scene *scene, ARegion *ar, View3D *v3d, Base *bas
 
 void view3d_update_depths(ARegion *ar, View3D *v3d)
 {
+       RegionView3D *rv3d= ar->regiondata;
+       
        /* Create storage for, and, if necessary, copy depth buffer */
-       if(!v3d->depths) v3d->depths= MEM_callocN(sizeof(ViewDepths),"ViewDepths");
-       if(v3d->depths) {
-               ViewDepths *d= v3d->depths;
+       if(!rv3d->depths) rv3d->depths= MEM_callocN(sizeof(ViewDepths),"ViewDepths");
+       if(rv3d->depths) {
+               ViewDepths *d= rv3d->depths;
                if(d->w != ar->winx ||
                   d->h != ar->winy ||
                   !d->depths) {
@@ -1621,6 +1630,7 @@ static void draw_sculpt_depths(Scene *scene, ARegion *ar, View3D *v3d)
 
 void draw_depth(Scene *scene, ARegion *ar, View3D *v3d, int (* func)(void *))
 {
+       RegionView3D *rv3d= ar->regiondata;
        Base *base;
        Scene *sce;
        short zbuf, flag;
@@ -1635,20 +1645,20 @@ void draw_depth(Scene *scene, ARegion *ar, View3D *v3d, int (* func)(void *))
        U.glalphaclip = 0.5; /* not that nice but means we wont zoom into billboards */
        v3d->flag &= ~V3D_SELECT_OUTLINE;
        
-       setwinmatrixview3d(v3d, ar->winx, ar->winy, NULL);      /* 0= no pick rect */
-       setviewmatrixview3d(scene, v3d);        /* note: calls where_is_object for camera... */
+       setwinmatrixview3d(ar, v3d, NULL);      /* 0= no pick rect */
+       setviewmatrixview3d(scene, v3d, rv3d);  /* note: calls where_is_object for camera... */
        
-       Mat4MulMat4(v3d->persmat, v3d->viewmat, v3d->winmat);
-       Mat4Invert(v3d->persinv, v3d->persmat);
-       Mat4Invert(v3d->viewinv, v3d->viewmat);
+       Mat4MulMat4(rv3d->persmat, rv3d->viewmat, rv3d->winmat);
+       Mat4Invert(rv3d->persinv, rv3d->persmat);
+       Mat4Invert(rv3d->viewinv, rv3d->viewmat);
        
        glClear(GL_DEPTH_BUFFER_BIT);
        
-       wmLoadMatrix(v3d->viewmat);
+       wmLoadMatrix(rv3d->viewmat);
 //     persp(PERSP_STORE);  // store correct view for persp(PERSP_VIEW) calls
        
-       if(v3d->flag & V3D_CLIPPING) {
-               view3d_set_clipping(v3d);
+       if(rv3d->rflag & RV3D_CLIPPING) {
+               view3d_set_clipping(rv3d);
        }
        
        v3d->zbuf= TRUE;
@@ -1842,8 +1852,8 @@ static CustomDataMask get_viewedit_datamask(bScreen *screen)
 void view3d_main_area_draw(const bContext *C, ARegion *ar)
 {
        Scene *scene= CTX_data_scene(C);
-       ScrArea *sa= CTX_wm_area(C);
-       View3D *v3d= sa->spacedata.first;       /* XXX get from region */
+       View3D *v3d = CTX_wm_view3d(C);
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
        Scene *sce;
        Base *base;
        Object *ob;
@@ -1871,27 +1881,27 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar)
        if(draw_glsl_material(scene, NULL, v3d, v3d->drawtype))
                gpu_update_lamps_shadows(scene, v3d);
        
-       setwinmatrixview3d(v3d, ar->winx, ar->winy, NULL);      /* 0= no pick rect */
-       setviewmatrixview3d(scene, v3d);        /* note: calls where_is_object for camera... */
+       setwinmatrixview3d(ar, v3d, NULL);      /* 0= no pick rect */
+       setviewmatrixview3d(scene, v3d, rv3d);  /* note: calls where_is_object for camera... */
        
-       Mat4MulMat4(v3d->persmat, v3d->viewmat, v3d->winmat);
-       Mat4Invert(v3d->persinv, v3d->persmat);
-       Mat4Invert(v3d->viewinv, v3d->viewmat);
+       Mat4MulMat4(rv3d->persmat, rv3d->viewmat, rv3d->winmat);
+       Mat4Invert(rv3d->persinv, rv3d->persmat);
+       Mat4Invert(rv3d->viewinv, rv3d->viewmat);
        
        /* calculate pixelsize factor once, is used for lamps and obcenters */
        {
                float len1, len2, vec[3];
                
-               VECCOPY(vec, v3d->persinv[0]);
+               VECCOPY(vec, rv3d->persinv[0]);
                len1= Normalize(vec);
-               VECCOPY(vec, v3d->persinv[1]);
+               VECCOPY(vec, rv3d->persinv[1]);
                len2= Normalize(vec);
                
-               v3d->pixsize= 2.0f*(len1>len2?len1:len2);
+               rv3d->pixsize= 2.0f*(len1>len2?len1:len2);
                
                /* correct for window size */
-               if(ar->winx > ar->winy) v3d->pixsize/= (float)ar->winx;
-               else v3d->pixsize/= (float)ar->winy;
+               if(ar->winx > ar->winy) rv3d->pixsize/= (float)ar->winx;
+               else rv3d->pixsize/= (float)ar->winy;
        }
        
        if(v3d->drawtype > OB_WIRE) {
@@ -1909,10 +1919,10 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar)
                glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        }
        
-       wmLoadMatrix(v3d->viewmat);
+       wmLoadMatrix(rv3d->viewmat);
        
-       if(v3d->flag & V3D_CLIPPING)
-               view3d_draw_clipping(v3d);
+       if(rv3d->rflag & RV3D_CLIPPING)
+               view3d_draw_clipping(rv3d);
        
        /* set zbuffer after we draw clipping region */
        if(v3d->drawtype > OB_WIRE) {
@@ -1923,9 +1933,9 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar)
        // needs to be done always, gridview is adjusted in drawgrid() now
        v3d->gridview= v3d->grid;
        
-       if(v3d->view==0 || v3d->persp!=0) {
+       if(rv3d->view==0 || rv3d->persp!=0) {
                drawfloor(scene, v3d);
-               if(v3d->persp==2) {
+               if(rv3d->persp==2) {
                        if(scene->world) {
                                if(scene->world->mode & WO_STARS) {
                                        RE_make_stars(NULL, scene, star_stuff_init_func, star_stuff_vertex_func,
@@ -1940,17 +1950,17 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar)
                drawgrid(ar, v3d);
                /* XXX make function? replaces persp(1) */
                glMatrixMode(GL_PROJECTION);
-               wmLoadMatrix(v3d->winmat);
+               wmLoadMatrix(rv3d->winmat);
                glMatrixMode(GL_MODELVIEW);
-               wmLoadMatrix(v3d->viewmat);
+               wmLoadMatrix(rv3d->viewmat);
                
                if(v3d->flag & V3D_DISPBGPIC) {
                        draw_bgpic(scene, ar, v3d);
                }
        }
        
-       if(v3d->flag & V3D_CLIPPING)
-               view3d_set_clipping(v3d);
+       if(rv3d->rflag & RV3D_CLIPPING)
+               view3d_set_clipping(rv3d);
        
        /* draw set first */
        if(scene->set) {
@@ -2020,7 +2030,7 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar)
                view3d_update_depths(ar, v3d);
        }
        
-       if(v3d->flag & V3D_CLIPPING)
+       if(rv3d->rflag & RV3D_CLIPPING)
                view3d_clr_clipping();
        
 //     BIF_draw_manipulator(ar);
@@ -2043,8 +2053,8 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar)
        
        /* Draw particle edit brush XXX (removed) */
        
-       if(v3d->persp>1) drawviewborder(scene, ar, v3d);
-       if(v3d->flag2 & V3D_FLYMODE) drawviewborder_flymode(ar);
+       if(rv3d->persp>1) drawviewborder(scene, ar, v3d);
+       if(rv3d->rflag & RV3D_FLYMODE) drawviewborder_flymode(ar);
        
        /* draw grease-pencil stuff */
 //     if (v3d->flag2 & V3D_DISPGP)
@@ -2053,9 +2063,9 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar)
        drawcursor(scene, ar, v3d);
        
        if(U.uiflag & USER_SHOW_ROTVIEWICON)
-               draw_view_axis(v3d);
+               draw_view_axis(rv3d);
        else    
-               draw_view_icon(v3d);
+               draw_view_icon(rv3d);
        
        /* XXX removed viewport fps */
        if(U.uiflag & USER_SHOW_VIEWPORTNAME) {
index 3ccb5eb026c409120fd21b96f019015be4e92e5e..b96dc4010bd58f32f0b591766306cb905ef2e285 100644 (file)
 
 typedef struct ViewOpsData {
        ARegion *ar;
-       View3D *v3d;
+       RegionView3D *rv3d;
 
        float oldquat[4];
        float trackvec[3];
        float ofs[3], obofs[3];
        float reverse, dist0;
-
+       float grid, far;
+       
        int origx, origy, oldx, oldy;
        int origkey;
 
@@ -130,26 +131,30 @@ static void calctrackballvec(rcti *rect, int mx, int my, float *vec)
 
 static void viewops_data(bContext *C, wmOperator *op, wmEvent *event)
 {
-       ScrArea *sa= CTX_wm_area(C);
-       View3D *v3d= sa->spacedata.first;
+       View3D *v3d = CTX_wm_view3d(C);
+       RegionView3D *rv3d;
        ViewOpsData *vod= MEM_callocN(sizeof(ViewOpsData), "viewops data");
 
        /* store data */
        op->customdata= vod;
        vod->ar= CTX_wm_region(C);
-       vod->v3d= v3d;
-       vod->dist0= v3d->dist;
-       QUATCOPY(vod->oldquat, v3d->viewquat);
+       vod->rv3d= rv3d= vod->ar->regiondata;
+       vod->dist0= rv3d->dist;
+       QUATCOPY(vod->oldquat, rv3d->viewquat);
        vod->origx= vod->oldx= event->x;
        vod->origy= vod->oldy= event->y;
        vod->origkey= event->type;
-
+       
+       /* lookup, we dont pass on v3d to prevent confusement */
+       vod->grid= v3d->grid;
+       vod->far= v3d->far;
+       
        calctrackballvec(&vod->ar->winrct, event->x, event->y, vod->trackvec);
 
-       initgrabz(v3d, -v3d->ofs[0], -v3d->ofs[1], -v3d->ofs[2]);
+       initgrabz(rv3d, -rv3d->ofs[0], -rv3d->ofs[1], -rv3d->ofs[2]);
 
        vod->reverse= 1.0f;
-       if (v3d->persmat[2][1] < 0.0f)
+       if (rv3d->persmat[2][1] < 0.0f)
                vod->reverse= -1.0f;
 
 }
@@ -209,10 +214,10 @@ static float snapquats[39][6] = {
 
 static void viewrotate_apply(ViewOpsData *vod, int x, int y, int ctrl)
 {
-       View3D *v3d= vod->v3d;
+       RegionView3D *rv3d= vod->rv3d;
        int use_sel= 0; /* XXX */
 
-       v3d->view= 0; /* need to reset everytime because of view snapping */
+       rv3d->view= 0; /* need to reset everytime because of view snapping */
 
        if (U.flag & USER_TRACKBALL) {
                float phi, si, q1[4], dvec[3], newvec[3];
@@ -244,19 +249,19 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y, int ctrl)
                q1[1]*= si;
                q1[2]*= si;
                q1[3]*= si;
-               QuatMul(v3d->viewquat, q1, vod->oldquat);
+               QuatMul(rv3d->viewquat, q1, vod->oldquat);
 
                if (use_sel) {
                        /* compute the post multiplication quat, to rotate the offset correctly */
                        QUATCOPY(q1, vod->oldquat);
                        QuatConj(q1);
-                       QuatMul(q1, q1, v3d->viewquat);
+                       QuatMul(q1, q1, rv3d->viewquat);
 
                        QuatConj(q1); /* conj == inv for unit quat */
-                       VECCOPY(v3d->ofs, vod->ofs);
-                       VecSubf(v3d->ofs, v3d->ofs, vod->obofs);
-                       QuatMulVecf(q1, v3d->ofs);
-                       VecAddf(v3d->ofs, v3d->ofs, vod->obofs);
+                       VECCOPY(rv3d->ofs, vod->ofs);
+                       VecSubf(rv3d->ofs, rv3d->ofs, vod->obofs);
+                       QuatMulVecf(q1, rv3d->ofs);
+                       VecAddf(rv3d->ofs, rv3d->ofs, vod->obofs);
                }
        }
        else {
@@ -272,7 +277,7 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y, int ctrl)
                const float sensitivity = 0.0035;
 
                /* Get the 3x3 matrix and its inverse from the quaternion */
-               QuatToMat3(v3d->viewquat, m);
+               QuatToMat3(rv3d->viewquat, m);
                Mat3Inv(m_inv,m);
 
                /* Determine the direction of the x vector (for rotating up and down) */
@@ -286,13 +291,13 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y, int ctrl)
                q1[1] = si * xvec[0];
                q1[2] = si * xvec[1];
                q1[3] = si * xvec[2];
-               QuatMul(v3d->viewquat, v3d->viewquat, q1);
+               QuatMul(rv3d->viewquat, rv3d->viewquat, q1);
 
                if (use_sel) {
                        QuatConj(q1); /* conj == inv for unit quat */
-                       VecSubf(v3d->ofs, v3d->ofs, vod->obofs);
-                       QuatMulVecf(q1, v3d->ofs);
-                       VecAddf(v3d->ofs, v3d->ofs, vod->obofs);
+                       VecSubf(rv3d->ofs, rv3d->ofs, vod->obofs);
+                       QuatMulVecf(q1, rv3d->ofs);
+                       VecAddf(rv3d->ofs, rv3d->ofs, vod->obofs);
                }
 
                /* Perform the orbital rotation */
@@ -300,13 +305,13 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y, int ctrl)
                q1[0] = cos(phi);
                q1[1] = q1[2] = 0.0;
                q1[3] = sin(phi);
-               QuatMul(v3d->viewquat, v3d->viewquat, q1);
+               QuatMul(rv3d->viewquat, rv3d->viewquat, q1);
 
                if (use_sel) {
                        QuatConj(q1);
-                       VecSubf(v3d->ofs, v3d->ofs, vod->obofs);
-                       QuatMulVecf(q1, v3d->ofs);
-                       VecAddf(v3d->ofs, v3d->ofs, vod->obofs);
+                       VecSubf(rv3d->ofs, rv3d->ofs, vod->obofs);
+                       QuatMulVecf(q1, rv3d->ofs);
+                       VecAddf(rv3d->ofs, rv3d->ofs, vod->obofs);
                }
        }
 
@@ -316,7 +321,7 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y, int ctrl)
                float viewmat[3][3];
 
 
-               QuatToMat3(v3d->viewquat, viewmat);
+               QuatToMat3(rv3d->viewquat, viewmat);
 
                for (i = 0 ; i < 39; i++){
                        float snapmat[3][3];
@@ -329,14 +334,14 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y, int ctrl)
                                (Inpf(snapmat[1], viewmat[1]) > thres) &&
                                (Inpf(snapmat[2], viewmat[2]) > thres)){
 
-                               QUATCOPY(v3d->viewquat, snapquats[i]);
+                               QUATCOPY(rv3d->viewquat, snapquats[i]);
 
-                               v3d->view = view;
+                               rv3d->view = view;
                                if (view){
                                        if (oposite_dir){
-                                               v3d->flag2 |= V3D_OPP_DIRECTION_NAME;
+                                               rv3d->rflag |= RV3D_OPP_DIRECTION_NAME;
                                        }else{
-                                               v3d->flag2 &= ~V3D_OPP_DIRECTION_NAME;
+                                               rv3d->rflag &= ~RV3D_OPP_DIRECTION_NAME;
                                        }
                                }
 
@@ -382,12 +387,12 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, wmEvent *event)
        vod= op->customdata;
 
        /* switch from camera view when: */
-       if(vod->v3d->persp != V3D_PERSP) {
+       if(vod->rv3d->persp != V3D_PERSP) {
 
                if (U.uiflag & USER_AUTOPERSP)
-                       vod->v3d->persp= V3D_PERSP;
-               else if(vod->v3d->persp==V3D_CAMOB)
-                       vod->v3d->persp= V3D_PERSP;
+                       vod->rv3d->persp= V3D_PERSP;
+               else if(vod->rv3d->persp==V3D_CAMOB)
+                       vod->rv3d->persp= V3D_PERSP;
                ED_region_tag_redraw(vod->ar);
        }
 
@@ -415,20 +420,20 @@ void VIEW3D_OT_viewrotate(wmOperatorType *ot)
 
 static void viewmove_apply(ViewOpsData *vod, int x, int y)
 {
-       if(vod->v3d->persp==V3D_CAMOB) {
+       if(vod->rv3d->persp==V3D_CAMOB) {
                float max= (float)MAX2(vod->ar->winx, vod->ar->winy);
 
-               vod->v3d->camdx += (vod->oldx - x)/(max);
-               vod->v3d->camdy += (vod->oldy - y)/(max);
-               CLAMP(vod->v3d->camdx, -1.0f, 1.0f);
-               CLAMP(vod->v3d->camdy, -1.0f, 1.0f);
+               vod->rv3d->camdx += (vod->oldx - x)/(max);
+               vod->rv3d->camdy += (vod->oldy - y)/(max);
+               CLAMP(vod->rv3d->camdx, -1.0f, 1.0f);
+               CLAMP(vod->rv3d->camdy, -1.0f, 1.0f);
 // XXX         preview3d_event= 0;
        }
        else {
                float dvec[3];
 
-               window_to_3d(vod->ar, vod->v3d, dvec, x-vod->oldx, y-vod->oldy);
-               VecAddf(vod->v3d->ofs, vod->v3d->ofs, dvec);
+               window_to_3d(vod->ar, dvec, x-vod->oldx, y-vod->oldy);
+               VecAddf(vod->rv3d->ofs, vod->rv3d->ofs, dvec);
        }
 
        vod->oldx= x;
@@ -488,8 +493,10 @@ void VIEW3D_OT_viewmove(wmOperatorType *ot)
 
 /* ************************ viewzoom ******************************** */
 
-static void view_zoom_mouseloc(ARegion *ar, View3D *v3d, float dfac, int mx, int my)
+static void view_zoom_mouseloc(ARegion *ar, float dfac, int mx, int my)
 {
+       RegionView3D *rv3d= ar->regiondata;
+       
        if(U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
                float dvec[3];
                float tvec[3];
@@ -504,13 +511,13 @@ static void view_zoom_mouseloc(ARegion *ar, View3D *v3d, float dfac, int mx, int
                vb[0] = ar->winx;
                vb[1] = ar->winy;
 
-               tpos[0] = -v3d->ofs[0];
-               tpos[1] = -v3d->ofs[1];
-               tpos[2] = -v3d->ofs[2];
+               tpos[0] = -rv3d->ofs[0];
+               tpos[1] = -rv3d->ofs[1];
+               tpos[2] = -rv3d->ofs[2];
 
                /* Project cursor position into 3D space */
-               initgrabz(v3d, tpos[0], tpos[1], tpos[2]);
-               window_to_3d(ar, v3d, dvec, mouseloc[0]-vb[0]/2, mouseloc[1]-vb[1]/2);
+               initgrabz(rv3d, tpos[0], tpos[1], tpos[2]);
+               window_to_3d(ar, dvec, mouseloc[0]-vb[0]/2, mouseloc[1]-vb[1]/2);
 
                /* Calculate view target position for dolly */
                tvec[0] = -(tpos[0] + dvec[0]);
@@ -518,19 +525,19 @@ static void view_zoom_mouseloc(ARegion *ar, View3D *v3d, float dfac, int mx, int
                tvec[2] = -(tpos[2] + dvec[2]);
 
                /* Offset to target position and dolly */
-               new_dist = v3d->dist * dfac;
+               new_dist = rv3d->dist * dfac;
 
-               VECCOPY(v3d->ofs, tvec);
-               v3d->dist = new_dist;
+               VECCOPY(rv3d->ofs, tvec);
+               rv3d->dist = new_dist;
 
                /* Calculate final offset */
                dvec[0] = tvec[0] + dvec[0] * dfac;
                dvec[1] = tvec[1] + dvec[1] * dfac;
                dvec[2] = tvec[2] + dvec[2] * dfac;
 
-               VECCOPY(v3d->ofs, dvec);
+               VECCOPY(rv3d->ofs, dvec);
        } else {
-               v3d->dist *= dfac;
+               rv3d->dist *= dfac;
        }
 }
 
@@ -553,36 +560,36 @@ static void viewzoom_apply(ViewOpsData *vod, int x, int y)
                len1 = (int)sqrt((ctr[0] - x)*(ctr[0] - x) + (ctr[1] - y)*(ctr[1] - y)) + 5;
                len2 = (int)sqrt((ctr[0] - vod->origx)*(ctr[0] - vod->origx) + (ctr[1] - vod->origy)*(ctr[1] - vod->origy)) + 5;
 
-               zfac = vod->dist0 * ((float)len2/len1) / vod->v3d->dist;
+               zfac = vod->dist0 * ((float)len2/len1) / vod->rv3d->dist;
        }
        else {  /* USER_ZOOM_DOLLY */
                float len1 = (vod->ar->winrct.ymax - y) + 5;
                float len2 = (vod->ar->winrct.ymax - vod->origy) + 5;
-               zfac = vod->dist0 * (2.0*((len2/len1)-1.0) + 1.0) / vod->v3d->dist;
+               zfac = vod->dist0 * (2.0*((len2/len1)-1.0) + 1.0) / vod->rv3d->dist;
        }
 
-       if(zfac != 1.0 && zfac*vod->v3d->dist > 0.001*vod->v3d->grid &&
-                               zfac*vod->v3d->dist < 10.0*vod->v3d->far)
-               view_zoom_mouseloc(vod->ar, vod->v3d, zfac, vod->oldx, vod->oldy);
+       if(zfac != 1.0 && zfac*vod->rv3d->dist > 0.001*vod->grid &&
+                               zfac*vod->rv3d->dist < 10.0*vod->far)
+               view_zoom_mouseloc(vod->ar, zfac, vod->oldx, vod->oldy);
 
 
-       if ((U.uiflag & USER_ORBIT_ZBUF) && (U.viewzoom==USER_ZOOM_CONT) && (vod->v3d->persp==V3D_PERSP)) {
+       if ((U.uiflag & USER_ORBIT_ZBUF) && (U.viewzoom==USER_ZOOM_CONT) && (vod->rv3d->persp==V3D_PERSP)) {
                float upvec[3], mat[3][3];
 
                /* Secret apricot feature, translate the view when in continues mode */
                upvec[0] = upvec[1] = 0.0f;
-               upvec[2] = (vod->dist0 - vod->v3d->dist) * vod->v3d->grid;
-               vod->v3d->dist = vod->dist0;
-               Mat3CpyMat4(mat, vod->v3d->viewinv);
+               upvec[2] = (vod->dist0 - vod->rv3d->dist) * vod->grid;
+               vod->rv3d->dist = vod->dist0;
+               Mat3CpyMat4(mat, vod->rv3d->viewinv);
                Mat3MulVecfl(mat, upvec);
-               VecAddf(vod->v3d->ofs, vod->v3d->ofs, upvec);
+               VecAddf(vod->rv3d->ofs, vod->rv3d->ofs, upvec);
        } else {
-               /* these limits are in toets.c too */
-               if(vod->v3d->dist<0.001*vod->v3d->grid) vod->v3d->dist= 0.001*vod->v3d->grid;
-               if(vod->v3d->dist>10.0*vod->v3d->far) vod->v3d->dist=10.0*vod->v3d->far;
+               /* these limits were in old code too */
+               if(vod->rv3d->dist<0.001*vod->grid) vod->rv3d->dist= 0.001*vod->grid;
+               if(vod->rv3d->dist>10.0*vod->far) vod->rv3d->dist=10.0*vod->far;
        }
 
-// XXX if(vod->v3d->persp==V3D_ORTHO || vod->v3d->persp==V3D_CAMOB) preview3d_event= 0;
+// XXX if(vod->rv3d->persp==V3D_ORTHO || vod->rv3d->persp==V3D_CAMOB) preview3d_event= 0;
 
        ED_region_tag_redraw(vod->ar);
 }
@@ -613,24 +620,24 @@ static int viewzoom_modal(bContext *C, wmOperator *op, wmEvent *event)
 
 static int viewzoom_exec(bContext *C, wmOperator *op)
 {
-       ScrArea *sa= CTX_wm_area(C);
-       View3D *v3d= sa->spacedata.first;
+       View3D *v3d = CTX_wm_view3d(C);
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
        int delta= RNA_int_get(op->ptr, "delta");
 
        if(delta < 0) {
                /* this min and max is also in viewmove() */
-               if(v3d->persp==V3D_CAMOB) {
-                       v3d->camzoom-= 10;
-                       if(v3d->camzoom<-30) v3d->camzoom= -30;
+               if(rv3d->persp==V3D_CAMOB) {
+                       rv3d->camzoom-= 10;
+                       if(rv3d->camzoom<-30) rv3d->camzoom= -30;
                }
-               else if(v3d->dist<10.0*v3d->far) v3d->dist*=1.2f;
+               else if(rv3d->dist<10.0*v3d->far) rv3d->dist*=1.2f;
        }
        else {
-               if(v3d->persp==V3D_CAMOB) {
-                       v3d->camzoom+= 10;
-                       if(v3d->camzoom>300) v3d->camzoom= 300;
+               if(rv3d->persp==V3D_CAMOB) {
+                       rv3d->camzoom+= 10;
+                       if(rv3d->camzoom>300) rv3d->camzoom= 300;
                }
-               else if(v3d->dist> 0.001*v3d->grid) v3d->dist*=.83333f;
+               else if(rv3d->dist> 0.001*v3d->grid) rv3d->dist*=.83333f;
        }
 
        ED_region_tag_redraw(CTX_wm_region(C));
@@ -675,9 +682,9 @@ void VIEW3D_OT_viewzoom(wmOperatorType *ot)
 
 static int viewhome_exec(bContext *C, wmOperator *op) /* was view3d_home() in 2.4x */
 {
-       ScrArea *sa= CTX_wm_area(C);
        ARegion *ar= CTX_wm_region(C);
-       View3D *v3d= sa->spacedata.first;
+       View3D *v3d = CTX_wm_view3d(C);
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
        Scene *scene= CTX_data_scene(C);
        Base *base;
 
@@ -724,8 +731,8 @@ static int viewhome_exec(bContext *C, wmOperator *op) /* was view3d_home() in 2.
                        new_dist*= size;
                }
 
-               if (v3d->persp==V3D_CAMOB) {
-                       v3d->persp= V3D_PERSP;
+               if (rv3d->persp==V3D_CAMOB) {
+                       rv3d->persp= V3D_PERSP;
                        smooth_view(C, NULL, v3d->camera, new_ofs, NULL, &new_dist, NULL); 
                }
        }
@@ -749,9 +756,9 @@ void VIEW3D_OT_viewhome(wmOperatorType *ot)
 
 static int viewcenter_exec(bContext *C, wmOperator *op) /* like a localview without local!, was centerview() in 2.4x */
 {
-       ScrArea *sa= CTX_wm_area(C);
        ARegion *ar= CTX_wm_region(C);
-       View3D *v3d= sa->spacedata.first;
+       View3D *v3d = CTX_wm_view3d(C);
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
        Scene *scene= CTX_data_scene(C);
        Object *ob= OBACT;
        Object *obedit= CTX_data_edit_object(C);
@@ -850,8 +857,8 @@ static int viewcenter_exec(bContext *C, wmOperator *op) /* like a localview with
        v3d->cursor[1]= -new_ofs[1];
        v3d->cursor[2]= -new_ofs[2];
 
-       if (v3d->persp==V3D_CAMOB) {
-               v3d->persp= V3D_PERSP;
+       if (rv3d->persp==V3D_CAMOB) {
+               rv3d->persp= V3D_PERSP;
                smooth_view(C, v3d->camera, NULL, new_ofs, NULL, &new_dist, NULL);
        } 
        else {
@@ -878,9 +885,8 @@ void VIEW3D_OT_viewcenter(wmOperatorType *ot)
 
 static int render_border_exec(bContext *C, wmOperator *op)
 {
-       ScrArea *sa= CTX_wm_area(C);
+       View3D *v3d = CTX_wm_view3d(C);
        ARegion *ar= CTX_wm_region(C);
-       View3D *v3d= sa->spacedata.first;
        Scene *scene= CTX_data_scene(C);
        
        rcti rect;
@@ -924,11 +930,10 @@ static int render_border_exec(bContext *C, wmOperator *op)
 
 static int view3d_render_border_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
-       ScrArea *sa= CTX_wm_area(C);
-       View3D *v3d= sa->spacedata.first;
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
        
        /* if not in camera view do not exec the operator*/
-       if (v3d->persp == V3D_CAMOB) return WM_border_select_invoke(C, op, event);      
+       if (rv3d->persp == V3D_CAMOB) return WM_border_select_invoke(C, op, event);     
        else return OPERATOR_PASS_THROUGH;
 }
 
@@ -956,9 +961,9 @@ void VIEW3D_OT_render_border(wmOperatorType *ot)
 
 static int view3d_border_zoom_exec(bContext *C, wmOperator *op)
 {
-       ScrArea *sa= CTX_wm_area(C);
        ARegion *ar= CTX_wm_region(C);
-       View3D *v3d= sa->spacedata.first;
+       View3D *v3d = CTX_wm_view3d(C);
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
        Scene *scene= CTX_data_scene(C);
        
        /* Zooms in on a border drawn by the user */
@@ -990,9 +995,9 @@ static int view3d_border_zoom_exec(bContext *C, wmOperator *op)
        draw_depth(scene, ar, v3d, NULL);
 
        /* force updating */
-       if (v3d->depths) {
+       if (rv3d->depths) {
                had_depth = 1;
-               v3d->depths->damaged = 1;
+               rv3d->depths->damaged = 1;
        }
 
        view3d_update_depths(ar, v3d);
@@ -1000,14 +1005,14 @@ static int view3d_border_zoom_exec(bContext *C, wmOperator *op)
        /* Constrain rect to depth bounds */
        if (rect.xmin < 0) rect.xmin = 0;
        if (rect.ymin < 0) rect.ymin = 0;
-       if (rect.xmax >= v3d->depths->w) rect.xmax = v3d->depths->w-1;
-       if (rect.ymax >= v3d->depths->h) rect.ymax = v3d->depths->h-1;
+       if (rect.xmax >= rv3d->depths->w) rect.xmax = rv3d->depths->w-1;
+       if (rect.ymax >= rv3d->depths->h) rect.ymax = rv3d->depths->h-1;
 
        /* Find the closest Z pixel */
        for (xs=rect.xmin; xs < rect.xmax; xs++) {
                for (ys=rect.ymin; ys < rect.ymax; ys++) {
-                       depth= v3d->depths->depths[ys*v3d->depths->w+xs];
-                       if(depth < v3d->depths->depth_range[1] && depth > v3d->depths->depth_range[0]) {
+                       depth= rv3d->depths->depths[ys*rv3d->depths->w+xs];
+                       if(depth < rv3d->depths->depth_range[1] && depth > rv3d->depths->depth_range[0]) {
                                if (depth_close > depth) {
                                        depth_close = depth;
                                }
@@ -1016,15 +1021,15 @@ static int view3d_border_zoom_exec(bContext *C, wmOperator *op)
        }
 
        if (had_depth==0) {
-               MEM_freeN(v3d->depths->depths);
-               v3d->depths->depths = NULL;
+               MEM_freeN(rv3d->depths->depths);
+               rv3d->depths->depths = NULL;
        }
-       v3d->depths->damaged = 1;
+       rv3d->depths->damaged = 1;
 
        cent[0] = (((double)rect.xmin)+((double)rect.xmax)) / 2;
        cent[1] = (((double)rect.ymin)+((double)rect.ymax)) / 2;
 
-       if (v3d->persp==V3D_PERSP) {
+       if (rv3d->persp==V3D_PERSP) {
                double p_corner[3];
 
                /* no depths to use, we cant do anything! */
@@ -1052,7 +1057,7 @@ static int view3d_border_zoom_exec(bContext *C, wmOperator *op)
                vb[0] = ar->winx;
                vb[1] = ar->winy;
 
-               new_dist = v3d->dist;
+               new_dist = rv3d->dist;
 
                /* convert the drawn rectangle into 3d space */
                if (depth_close!=MAXFLOAT && gluUnProject(cent[0], cent[1], depth_close, mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2])) {
@@ -1061,13 +1066,13 @@ static int view3d_border_zoom_exec(bContext *C, wmOperator *op)
                        new_ofs[2] = -p[2];
                } else {
                        /* We cant use the depth, fallback to the old way that dosnt set the center depth */
-                       new_ofs[0] = v3d->ofs[0];
-                       new_ofs[1] = v3d->ofs[1];
-                       new_ofs[2] = v3d->ofs[2];
+                       new_ofs[0] = rv3d->ofs[0];
+                       new_ofs[1] = rv3d->ofs[1];
+                       new_ofs[2] = rv3d->ofs[2];
 
-                       initgrabz(v3d, -new_ofs[0], -new_ofs[1], -new_ofs[2]);
+                       initgrabz(rv3d, -new_ofs[0], -new_ofs[1], -new_ofs[2]);
 
-                       window_to_3d(ar, v3d, dvec, (rect.xmin+rect.xmax-vb[0])/2, (rect.ymin+rect.ymax-vb[1])/2);
+                       window_to_3d(ar, dvec, (rect.xmin+rect.xmax-vb[0])/2, (rect.ymin+rect.ymax-vb[1])/2);
                        /* center the view to the center of the rectangle */
                        VecSubf(new_ofs, new_ofs, dvec);
                }
@@ -1085,15 +1090,18 @@ static int view3d_border_zoom_exec(bContext *C, wmOperator *op)
        
        return OPERATOR_FINISHED;
 }
+
 static int view3d_border_zoom_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
-       ScrArea *sa= CTX_wm_area(C);
-       View3D *v3d= sa->spacedata.first;
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
        
        /* if in camera view do not exec the operator so we do not conflict with set render border*/
-       if (v3d->persp != V3D_CAMOB) return WM_border_select_invoke(C, op, event);      
-       else return OPERATOR_PASS_THROUGH;
+       if (rv3d->persp != V3D_CAMOB) 
+               return WM_border_select_invoke(C, op, event);   
+       else 
+               return OPERATOR_PASS_THROUGH;
 }
+
 void VIEW3D_OT_border_zoom(wmOperatorType *ot)
 {
        
@@ -1136,26 +1144,28 @@ static EnumPropertyItem prop_view_items[] = {
        {V3D_VIEW_PANDOWN, "PANDOWN", "Pan Down", "Pan the view Down"},
        {0, NULL, NULL, NULL}};
 
-static void axis_set_view(bContext *C, View3D *v3d, float q1, float q2, float q3, float q4, short view, int perspo)
+static void axis_set_view(bContext *C, float q1, float q2, float q3, float q4, short view, int perspo)
 {
+       View3D *v3d = CTX_wm_view3d(C);
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
        float new_quat[4];
+       
        new_quat[0]= q1; new_quat[1]= q2;
        new_quat[2]= q3; new_quat[3]= q4;
-       v3d->view=0;
-
-       v3d->view= view;
        
-       if (v3d->persp==V3D_CAMOB && v3d->camera) {
+       rv3d->view= view;
+       
+       if (rv3d->persp==V3D_CAMOB && v3d->camera) {
 
-               if (U.uiflag & USER_AUTOPERSP) v3d->persp= V3D_ORTHO;
-               else if(v3d->persp==V3D_CAMOB) v3d->persp= perspo;
+               if (U.uiflag & USER_AUTOPERSP) rv3d->persp= V3D_ORTHO;
+               else if(rv3d->persp==V3D_CAMOB) rv3d->persp= perspo;
 
-               smooth_view(C, v3d->camera, NULL, v3d->ofs, new_quat, NULL, NULL); 
+               smooth_view(C, v3d->camera, NULL, rv3d->ofs, new_quat, NULL, NULL); 
        } 
        else {
 
-               if (U.uiflag & USER_AUTOPERSP) v3d->persp= V3D_ORTHO;
-               else if(v3d->persp==V3D_CAMOB) v3d->persp= perspo;
+               if (U.uiflag & USER_AUTOPERSP) rv3d->persp= V3D_ORTHO;
+               else if(rv3d->persp==V3D_CAMOB) rv3d->persp= perspo;
 
                smooth_view(C, NULL, NULL, NULL, new_quat, NULL, NULL);
        }
@@ -1165,9 +1175,9 @@ static void axis_set_view(bContext *C, View3D *v3d, float q1, float q2, float q3
 
 static int viewnumpad_exec(bContext *C, wmOperator *op)
 {
-       ScrArea *sa= CTX_wm_area(C);
        ARegion *ar= CTX_wm_region(C);
-       View3D *v3d= sa->spacedata.first;
+       View3D *v3d = CTX_wm_view3d(C);
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
        Scene *scene= CTX_data_scene(C);
        float phi, si, q1[4], vec[3];
        static int perspo=V3D_PERSP;
@@ -1180,40 +1190,40 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
        /* Indicate that this view is inverted,
         * but only if it actually _was_ inverted (jobbe) */
        if (viewnum == V3D_VIEW_BOTTOM || viewnum == V3D_VIEW_BACK || viewnum == V3D_VIEW_LEFT)
-               v3d->flag2 |= V3D_OPP_DIRECTION_NAME;
+               rv3d->rflag |= RV3D_OPP_DIRECTION_NAME;
        else if (viewnum != V3D_VIEW_PERSPORTHO)
-                       v3d->flag2 &= ~V3D_OPP_DIRECTION_NAME;
+                       rv3d->rflag &= ~RV3D_OPP_DIRECTION_NAME;
 
        switch (viewnum) {
                case V3D_VIEW_BOTTOM :
-                       axis_set_view(C, v3d, 0.0, -1.0, 0.0, 0.0, 7, perspo);
+                       axis_set_view(C, 0.0, -1.0, 0.0, 0.0, 7, perspo);
                        break;
 
                case V3D_VIEW_BACK:
-                       axis_set_view(C, v3d, 0.0, 0.0, (float)-cos(M_PI/4.0), (float)-cos(M_PI/4.0), 1, perspo);
+                       axis_set_view(C, 0.0, 0.0, (float)-cos(M_PI/4.0), (float)-cos(M_PI/4.0), 1, perspo);
                        break;
 
                case V3D_VIEW_LEFT:
-                       axis_set_view(C, v3d, 0.5, -0.5, 0.5, 0.5, 3, perspo);
+                       axis_set_view(C, 0.5, -0.5, 0.5, 0.5, 3, perspo);
                        break;
 
                case V3D_VIEW_TOP:
-                       axis_set_view(C, v3d, 1.0, 0.0, 0.0, 0.0, 7, perspo);
+                       axis_set_view(C, 1.0, 0.0, 0.0, 0.0, 7, perspo);
                        break;
 
                case V3D_VIEW_FRONT:
-                       axis_set_view(C, v3d, (float)cos(M_PI/4.0), (float)-sin(M_PI/4.0), 0.0, 0.0, 1, perspo);
+                       axis_set_view(C, (float)cos(M_PI/4.0), (float)-sin(M_PI/4.0), 0.0, 0.0, 1, perspo);
                        break;
 
                case V3D_VIEW_RIGHT:
-                       axis_set_view(C, v3d, 0.5, -0.5, -0.5, -0.5, 3, perspo);
+                       axis_set_view(C, 0.5, -0.5, -0.5, -0.5, 3, perspo);
                        break;
 
                case V3D_VIEW_PERSPORTHO:
 
-                       if(v3d->persp!=V3D_ORTHO) 
-                               v3d->persp=V3D_ORTHO;
-                       else v3d->persp=V3D_PERSP;
+                       if(rv3d->persp!=V3D_ORTHO) 
+                               rv3d->persp=V3D_ORTHO;
+                       else rv3d->persp=V3D_PERSP;
 
                        ED_region_tag_redraw(ar);
                        break;
@@ -1221,11 +1231,11 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
                case V3D_VIEW_CAMERA:
                        /* lastview -  */
 
-                       if(v3d->persp != V3D_CAMOB) {
+                       if(rv3d->persp != V3D_CAMOB) {
                                /* store settings of current view before allowing overwriting with camera view */
-                               QUATCOPY(v3d->lviewquat, v3d->viewquat);
-                               v3d->lview= v3d->view;
-                               v3d->lpersp= v3d->persp;
+                               QUATCOPY(rv3d->lviewquat, rv3d->viewquat);
+                               rv3d->lview= rv3d->view;
+                               rv3d->lpersp= rv3d->persp;
                                
 #if 0
                                if(G.qual==LR_ALTKEY) {
@@ -1248,14 +1258,14 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
                                        v3d->camera= scene_find_camera(scene);
                                        /*handle_view3d_lock();*/
                                }
-                               v3d->persp= V3D_CAMOB;
-                               smooth_view(C, NULL, v3d->camera, v3d->ofs, v3d->viewquat, &v3d->dist, &v3d->lens);
+                               rv3d->persp= V3D_CAMOB;
+                               smooth_view(C, NULL, v3d->camera, rv3d->ofs, rv3d->viewquat, &rv3d->dist, &v3d->lens);
                                
                        }
                        else{
                                /* return to settings of last view */
                                /* does smooth_view too */
-                               axis_set_view(C, v3d, v3d->lviewquat[0], v3d->lviewquat[1], v3d->lviewquat[2], v3d->lviewquat[3], v3d->lview, v3d->lpersp);
+                               axis_set_view(C, rv3d->lviewquat[0], rv3d->lviewquat[1], rv3d->lviewquat[2], rv3d->lviewquat[3], rv3d->lview, rv3d->lpersp);
                        }
                        break;
 
@@ -1264,7 +1274,7 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
                case V3D_VIEW_STEPUP:
                case V3D_VIEW_STEPDOWN:
 
-                       if(v3d->persp != V3D_CAMOB) {
+                       if(rv3d->persp != V3D_CAMOB) {
                                if(viewnum == V3D_VIEW_STEPLEFT || viewnum == V3D_VIEW_STEPRIGHT) {
                                        /* z-axis */
                                        phi= (float)(M_PI/360.0)*U.pad_rot_angle;
@@ -1273,12 +1283,12 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
                                        q1[0]= (float)cos(phi);
                                        q1[1]= q1[2]= 0.0;
                                        q1[3]= si;
-                                       QuatMul(v3d->viewquat, v3d->viewquat, q1);
-                                       v3d->view= 0;
+                                       QuatMul(rv3d->viewquat, rv3d->viewquat, q1);
+                                       rv3d->view= 0;
                                }
                                if(viewnum == V3D_VIEW_STEPDOWN || viewnum == V3D_VIEW_STEPUP) {
                                        /* horizontal axis */
-                                       VECCOPY(q1+1, v3d->viewinv[0]);
+                                       VECCOPY(q1+1, rv3d->viewinv[0]);
 
                                        Normalize(q1+1);
                                        phi= (float)(M_PI/360.0)*U.pad_rot_angle;
@@ -1288,8 +1298,8 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
                                        q1[1]*= si;
                                        q1[2]*= si;
                                        q1[3]*= si;
-                                       QuatMul(v3d->viewquat, v3d->viewquat, q1);
-                                       v3d->view= 0;
+                                       QuatMul(rv3d->viewquat, rv3d->viewquat, q1);
+                                       rv3d->view= 0;
                                }
                                ED_region_tag_redraw(ar);
                        }
@@ -1300,15 +1310,15 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
                case V3D_VIEW_PANUP:
                case V3D_VIEW_PANDOWN:
 
-                       initgrabz(v3d, 0.0, 0.0, 0.0);
+                       initgrabz(rv3d, 0.0, 0.0, 0.0);
 
-                       if(viewnum == V3D_VIEW_PANRIGHT) window_to_3d(ar, v3d, vec, -32, 0);
-                       else if(viewnum == V3D_VIEW_PANLEFT) window_to_3d(ar, v3d, vec, 32, 0);
-                       else if(viewnum == V3D_VIEW_PANUP) window_to_3d(ar, v3d, vec, 0, -25);
-                       else if(viewnum == V3D_VIEW_PANDOWN) window_to_3d(ar, v3d, vec, 0, 25);
-                       v3d->ofs[0]+= vec[0];
-                       v3d->ofs[1]+= vec[1];
-                       v3d->ofs[2]+= vec[2];
+                       if(viewnum == V3D_VIEW_PANRIGHT) window_to_3d(ar, vec, -32, 0);
+                       else if(viewnum == V3D_VIEW_PANLEFT) window_to_3d(ar, vec, 32, 0);
+                       else if(viewnum == V3D_VIEW_PANUP) window_to_3d(ar, vec, 0, -25);
+                       else if(viewnum == V3D_VIEW_PANDOWN) window_to_3d(ar, vec, 0, 25);
+                       rv3d->ofs[0]+= vec[0];
+                       rv3d->ofs[1]+= vec[1];
+                       rv3d->ofs[2]+= vec[2];
 
                        ED_region_tag_redraw(ar);
                        break;
@@ -1317,7 +1327,7 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
                        break;
        }
 
-       if(v3d->persp != V3D_CAMOB) perspo= v3d->persp;
+       if(rv3d->persp != V3D_CAMOB) perspo= rv3d->persp;
 
        return OPERATOR_FINISHED;
 }
@@ -1341,8 +1351,7 @@ void VIEW3D_OT_viewnumpad(wmOperatorType *ot)
 
 static int view3d_clipping_exec(bContext *C, wmOperator *op)
 {
-       ScrArea *sa= CTX_wm_area(C);
-       View3D *v3d= sa->spacedata.first;
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
        rcti rect;
        double mvmatrix[16];
        double projmatrix[16];
@@ -1355,8 +1364,8 @@ static int view3d_clipping_exec(bContext *C, wmOperator *op)
        rect.xmax= RNA_int_get(op->ptr, "xmax");
        rect.ymax= RNA_int_get(op->ptr, "ymax");
 
-       v3d->flag |= V3D_CLIPPING;
-       v3d->clipbb= MEM_callocN(sizeof(BoundBox), "clipbb");
+       rv3d->rflag |= RV3D_CLIPPING;
+       rv3d->clipbb= MEM_callocN(sizeof(BoundBox), "clipbb");
 
        /* note; otherwise opengl won't work */
        view3d_operator_needs_opengl(C);
@@ -1383,35 +1392,35 @@ static int view3d_clipping_exec(bContext *C, wmOperator *op)
                ys= (val==0||val==1)?rect.ymin:rect.ymax;
 
                gluUnProject(xs, ys, 0.0, mvmatrix, projmatrix, viewport, &p[0], &p[1], &p[2]);
-               VECCOPY(v3d->clipbb->vec[val], p);
+               VECCOPY(rv3d->clipbb->vec[val], p);
 
                gluUnProject(xs, ys, 1.0, mvmatrix, projmatrix, viewport, &p[0], &p[1], &p[2]);
-               VECCOPY(v3d->clipbb->vec[4+val], p);
+               VECCOPY(rv3d->clipbb->vec[4+val], p);
        }
 
        /* then plane equations */
        for(val=0; val<4; val++) {
 
-               CalcNormFloat(v3d->clipbb->vec[val], v3d->clipbb->vec[val==3?0:val+1], v3d->clipbb->vec[val+4],
-                                         v3d->clip[val]);
+               CalcNormFloat(rv3d->clipbb->vec[val], rv3d->clipbb->vec[val==3?0:val+1], rv3d->clipbb->vec[val+4],
+                                         rv3d->clip[val]);
 
-               v3d->clip[val][3]= - v3d->clip[val][0]*v3d->clipbb->vec[val][0]
-                       - v3d->clip[val][1]*v3d->clipbb->vec[val][1]
-                       - v3d->clip[val][2]*v3d->clipbb->vec[val][2];
+               rv3d->clip[val][3]= - rv3d->clip[val][0]*rv3d->clipbb->vec[val][0]
+                       - rv3d->clip[val][1]*rv3d->clipbb->vec[val][1]
+                       - rv3d->clip[val][2]*rv3d->clipbb->vec[val][2];
        }
        return OPERATOR_FINISHED;
 }
 
 static int view3d_clipping_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
-       ScrArea *sa= CTX_wm_area(C);
-       View3D *v3d= sa->spacedata.first;
-
-       if(v3d->flag & V3D_CLIPPING) {
-               v3d->flag &= ~V3D_CLIPPING;
-               ED_area_tag_redraw(sa);
-               if(v3d->clipbb) MEM_freeN(v3d->clipbb);
-               v3d->clipbb= NULL;
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
+       ARegion *ar= CTX_wm_region(C);
+
+       if(rv3d->rflag & RV3D_CLIPPING) {
+               rv3d->rflag &= ~RV3D_CLIPPING;
+               ED_region_tag_redraw(ar);
+               if(rv3d->clipbb) MEM_freeN(rv3d->clipbb);
+               rv3d->clipbb= NULL;
                return OPERATOR_FINISHED;
        }
        else {
@@ -1445,30 +1454,22 @@ void VIEW3D_OT_clipping(wmOperatorType *ot)
 
 static int view3d_drawtype_exec(bContext *C, wmOperator *op)
 {
-       ScrArea *sa= CTX_wm_area(C);
-       View3D *v3d= sa->spacedata.first;
+       View3D *v3d = CTX_wm_view3d(C);
        int dt, dt_alt;
 
        dt  = RNA_int_get(op->ptr, "draw_type");
        dt_alt = RNA_int_get(op->ptr, "draw_type_alternate");
        
-       if (dt_alt != -1)
-       {
+       if (dt_alt != -1) {
                if (v3d->drawtype == dt)
-               {
                        v3d->drawtype = dt_alt;
-               }
                else
-               {
                        v3d->drawtype = dt;
-               }
        }
        else
-       {
                v3d->drawtype = dt;
-       }
 
-       ED_area_tag_redraw(sa);
+       ED_area_tag_redraw(CTX_wm_area(C));
        
        return OPERATOR_FINISHED;
 }
@@ -1503,7 +1504,8 @@ static int set_3dcursor_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        Scene *scene= CTX_data_scene(C);
        ARegion *ar= CTX_wm_region(C);
-       View3D *v3d= CTX_wm_view3d(C);
+       View3D *v3d = CTX_wm_view3d(C);
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
        float dx, dy, fz, *fp = NULL, dvec[3], oldcurs[3];
        short mx, my, mval[2];
 //     short ctrl= 0; // XXX
@@ -1515,26 +1517,26 @@ static int set_3dcursor_invoke(bContext *C, wmOperator *op, wmEvent *event)
        
        mx= event->x - ar->winrct.xmin;
        my= event->y - ar->winrct.ymin;
-       project_short_noclip(ar, v3d, fp, mval);
+       project_short_noclip(ar, fp, mval);
        
-       initgrabz(v3d, fp[0], fp[1], fp[2]);
+       initgrabz(rv3d, fp[0], fp[1], fp[2]);
        
        if(mval[0]!=IS_CLIPPED) {
                
-               window_to_3d(ar, v3d, dvec, mval[0]-mx, mval[1]-my);
+               window_to_3d(ar, dvec, mval[0]-mx, mval[1]-my);
                VecSubf(fp, fp, dvec);
        }
        else {
                
-               dx= ((float)(mx-(ar->winx/2)))*v3d->zfac/(ar->winx/2);
-               dy= ((float)(my-(ar->winy/2)))*v3d->zfac/(ar->winy/2);
+               dx= ((float)(mx-(ar->winx/2)))*rv3d->zfac/(ar->winx/2);
+               dy= ((float)(my-(ar->winy/2)))*rv3d->zfac/(ar->winy/2);
                
-               fz= v3d->persmat[0][3]*fp[0]+ v3d->persmat[1][3]*fp[1]+ v3d->persmat[2][3]*fp[2]+ v3d->persmat[3][3];
-               fz= fz/v3d->zfac;
+               fz= rv3d->persmat[0][3]*fp[0]+ rv3d->persmat[1][3]*fp[1]+ rv3d->persmat[2][3]*fp[2]+ rv3d->persmat[3][3];
+               fz= fz/rv3d->zfac;
                
-               fp[0]= (v3d->persinv[0][0]*dx + v3d->persinv[1][0]*dy+ v3d->persinv[2][0]*fz)-v3d->ofs[0];
-               fp[1]= (v3d->persinv[0][1]*dx + v3d->persinv[1][1]*dy+ v3d->persinv[2][1]*fz)-v3d->ofs[1];
-               fp[2]= (v3d->persinv[0][2]*dx + v3d->persinv[1][2]*dy+ v3d->persinv[2][2]*fz)-v3d->ofs[2];
+               fp[0]= (rv3d->persinv[0][0]*dx + rv3d->persinv[1][0]*dy+ rv3d->persinv[2][0]*fz)-rv3d->ofs[0];
+               fp[1]= (rv3d->persinv[0][1]*dx + rv3d->persinv[1][1]*dy+ rv3d->persinv[2][1]*fz)-rv3d->ofs[1];
+               fp[2]= (rv3d->persinv[0][2]*dx + rv3d->persinv[1][2]*dy+ rv3d->persinv[2][2]*fz)-rv3d->ofs[2];
        }
        
 //     if(lr_click) {
@@ -1573,18 +1575,14 @@ void VIEW3D_OT_cursor3d(wmOperatorType *ot)
 /* XXX todo Zooms in on a border drawn by the user */
 int view_autodist(Scene *scene, ARegion *ar, View3D *v3d, short *mval, float mouse_worldloc[3] ) //, float *autodist )
 {
+       RegionView3D *rv3d= ar->regiondata;
+       bglMats mats; /* ZBuffer depth vars */
        rcti rect;
-       /* ZBuffer depth vars */
-       bglMats mats;
        float depth, depth_close= MAXFLOAT;
        int had_depth = 0;
        double cent[2],  p[3];
        int xs, ys;
 
-       // XXX          getmouseco_areawin(mval);
-
-       // XXX  persp(PERSP_VIEW);
-
        rect.xmax = mval[0] + 4;
        rect.ymax = mval[1] + 4;
 
@@ -1596,9 +1594,9 @@ int view_autodist(Scene *scene, ARegion *ar, View3D *v3d, short *mval, float mou
        draw_depth(scene, ar, v3d, NULL);
 
        /* force updating */
-       if (v3d->depths) {
+       if (rv3d->depths) {
                had_depth = 1;
-               v3d->depths->damaged = 1;
+               rv3d->depths->damaged = 1;
        }
 
        view3d_update_depths(ar, v3d);
@@ -1606,14 +1604,14 @@ int view_autodist(Scene *scene, ARegion *ar, View3D *v3d, short *mval, float mou
        /* Constrain rect to depth bounds */
        if (rect.xmin < 0) rect.xmin = 0;
        if (rect.ymin < 0) rect.ymin = 0;
-       if (rect.xmax >= v3d->depths->w) rect.xmax = v3d->depths->w-1;
-       if (rect.ymax >= v3d->depths->h) rect.ymax = v3d->depths->h-1;
+       if (rect.xmax >= rv3d->depths->w) rect.xmax = rv3d->depths->w-1;
+       if (rect.ymax >= rv3d->depths->h) rect.ymax = rv3d->depths->h-1;
 
        /* Find the closest Z pixel */
        for (xs=rect.xmin; xs < rect.xmax; xs++) {
                for (ys=rect.ymin; ys < rect.ymax; ys++) {
-                       depth= v3d->depths->depths[ys*v3d->depths->w+xs];
-                       if(depth < v3d->depths->depth_range[1] && depth > v3d->depths->depth_range[0]) {
+                       depth= rv3d->depths->depths[ys*rv3d->depths->w+xs];
+                       if(depth < rv3d->depths->depth_range[1] && depth > rv3d->depths->depth_range[0]) {
                                if (depth_close > depth) {
                                        depth_close = depth;
                                }
@@ -1625,10 +1623,10 @@ int view_autodist(Scene *scene, ARegion *ar, View3D *v3d, short *mval, float mou
                return 0;
 
        if (had_depth==0) {
-               MEM_freeN(v3d->depths->depths);
-               v3d->depths->depths = NULL;
+               MEM_freeN(rv3d->depths->depths);
+               rv3d->depths->depths = NULL;
        }
-       v3d->depths->damaged = 1;
+       rv3d->depths->damaged = 1;
 
        cent[0] = (double)mval[0];
        cent[1] = (double)mval[1];
@@ -1693,8 +1691,8 @@ void filterNDOFvalues(float *sbval)
                        sbval[i]=0.0;
 }
 
-// statics for controlling v3d->dist corrections.
-// viewmoveNDOF zeros and adjusts v3d->ofs.
+// statics for controlling rv3d->dist corrections.
+// viewmoveNDOF zeros and adjusts rv3d->ofs.
 // viewmove restores based on dz_flag state.
 
 int dz_flag = 0;
@@ -1702,6 +1700,7 @@ float m_dist;
 
 void viewmoveNDOFfly(ARegion *ar, View3D *v3d, int mode)
 {
+       RegionView3D *rv3d= ar->regiondata;
     int i;
     float phi;
     float dval[7];
@@ -1752,10 +1751,10 @@ void viewmoveNDOFfly(ARegion *ar, View3D *v3d, int mode)
        // until the first draw and doesn't update the menu
        // to reflect persp mode.
 
-       v3d->persp = V3D_PERSP;
+       rv3d->persp = V3D_PERSP;
 
 
-       // Correct the distance jump if v3d->dist != 0
+       // Correct the distance jump if rv3d->dist != 0
 
        // This is due to a side effect of the original
        // mouse view rotation code. The rotation point is
@@ -1767,15 +1766,15 @@ void viewmoveNDOFfly(ARegion *ar, View3D *v3d, int mode)
        // movement devices must subtract this from their
        // view transformations.
 
-       if(v3d->dist != 0.0) {
+       if(rv3d->dist != 0.0) {
                dz_flag = 1;
-               m_dist = v3d->dist;
+               m_dist = rv3d->dist;
                upvec[0] = upvec[1] = 0;
-               upvec[2] = v3d->dist;
-               Mat3CpyMat4(mat, v3d->viewinv);
+               upvec[2] = rv3d->dist;
+               Mat3CpyMat4(mat, rv3d->viewinv);
                Mat3MulVecfl(mat, upvec);
-               VecSubf(v3d->ofs, v3d->ofs, upvec);
-               v3d->dist = 0.0;
+               VecSubf(rv3d->ofs, rv3d->ofs, upvec);
+               rv3d->dist = 0.0;
        }
 
 
@@ -1788,7 +1787,7 @@ void viewmoveNDOFfly(ARegion *ar, View3D *v3d, int mode)
 
        // rotate device x and y by view z
 
-       Mat3CpyMat4(mat, v3d->viewinv);
+       Mat3CpyMat4(mat, rv3d->viewinv);
        mat[2][2] = 0.0f;
        Mat3MulVecfl(mat, rvec);
 
@@ -1797,7 +1796,7 @@ void viewmoveNDOFfly(ARegion *ar, View3D *v3d, int mode)
        phi = Normalize(rvec);
        if(phi != 0) {
                VecRotToQuat(rvec,phi,q1);
-               QuatMul(v3d->viewquat, v3d->viewquat, q1);
+               QuatMul(rv3d->viewquat, rv3d->viewquat, q1);
        }
 
 
@@ -1810,13 +1809,13 @@ void viewmoveNDOFfly(ARegion *ar, View3D *v3d, int mode)
        // the next three lines rotate the x and y translation coordinates
        // by the current z axis angle
 
-       Mat3CpyMat4(mat, v3d->viewinv);
+       Mat3CpyMat4(mat, rv3d->viewinv);
        mat[2][2] = 0.0f;
        Mat3MulVecfl(mat, tvec);
 
        // translate the view
 
-       VecSubf(v3d->ofs, v3d->ofs, tvec);
+       VecSubf(rv3d->ofs, rv3d->ofs, tvec);
 
 
        /*----------------------------------------------------
@@ -1828,55 +1827,56 @@ void viewmoveNDOFfly(ARegion *ar, View3D *v3d, int mode)
 // XXX BIF_view3d_previewrender_signal(ar, PR_DBASE|PR_DISPRECT);
 }
 
-void viewmoveNDOF(Scene *scene, View3D *v3d, int mode)
+void viewmoveNDOF(Scene *scene, ARegion *ar, View3D *v3d, int mode)
 {
-    float fval[7];
-    float dvec[3];
-    float sbadjust = 1.0f;
-    float len;
+       RegionView3D *rv3d= ar->regiondata;
+       float fval[7];
+       float dvec[3];
+       float sbadjust = 1.0f;
+       float len;
        short use_sel = 0;
        Object *ob = OBACT;
-    float m[3][3];
-    float m_inv[3][3];
-    float xvec[3] = {1,0,0};
-    float yvec[3] = {0,-1,0};
-    float zvec[3] = {0,0,1};
+       float m[3][3];
+       float m_inv[3][3];
+       float xvec[3] = {1,0,0};
+       float yvec[3] = {0,-1,0};
+       float zvec[3] = {0,0,1};
        float phi, si;
-    float q1[4];
-    float obofs[3];
-    float reverse;
-    //float diff[4];
-    float d, curareaX, curareaY;
-    float mat[3][3];
-    float upvec[3];
+       float q1[4];
+       float obofs[3];
+       float reverse;
+       //float diff[4];
+       float d, curareaX, curareaY;
+       float mat[3][3];
+       float upvec[3];
 
     /* Sensitivity will control how fast the view rotates.  The value was
      * obtained experimentally by tweaking until the author didn't get dizzy watching.
      * Perhaps this should be a configurable user parameter.
      */
-    float psens = 0.005f * (float) U.ndof_pan;   /* pan sensitivity */
-    float rsens = 0.005f * (float) U.ndof_rotate;  /* rotate sensitivity */
-    float zsens = 0.3f;   /* zoom sensitivity */
+       float psens = 0.005f * (float) U.ndof_pan;   /* pan sensitivity */
+       float rsens = 0.005f * (float) U.ndof_rotate;  /* rotate sensitivity */
+       float zsens = 0.3f;   /* zoom sensitivity */
 
-    const float minZoom = -30.0f;
-    const float maxZoom = 300.0f;
+       const float minZoom = -30.0f;
+       const float maxZoom = 300.0f;
 
        //reset view type
-       v3d->view = 0;
+       rv3d->view = 0;
 //printf("passing here \n");
 //
        if (scene->obedit==NULL && ob && !(ob->flag & OB_POSEMODE)) {
                use_sel = 1;
        }
 
-    if((dz_flag)||v3d->dist==0) {
+       if((dz_flag)||rv3d->dist==0) {
                dz_flag = 0;
-               v3d->dist = m_dist;
+               rv3d->dist = m_dist;
                upvec[0] = upvec[1] = 0;
-               upvec[2] = v3d->dist;
-               Mat3CpyMat4(mat, v3d->viewinv);
+               upvec[2] = rv3d->dist;
+               Mat3CpyMat4(mat, rv3d->viewinv);
                Mat3MulVecfl(mat, upvec);
-               VecAddf(v3d->ofs, v3d->ofs, upvec);
+               VecAddf(rv3d->ofs, rv3d->ofs, upvec);
        }
 
     /*----------------------------------------------------
@@ -1904,25 +1904,24 @@ void viewmoveNDOF(Scene *scene, View3D *v3d, int mode)
 
 
     // put scaling back here, was previously in ghostwinlay
-    fval[0] = fval[0] * (1.0f/600.0f);
-    fval[1] = fval[1] * (1.0f/600.0f);
-    fval[2] = fval[2] * (1.0f/1100.0f);
-    fval[3] = fval[3] * 0.00005f;
-    fval[4] =-fval[4] * 0.00005f;
-    fval[5] = fval[5] * 0.00005f;
-    fval[6] = fval[6] / 1000000.0f;
+       fval[0] = fval[0] * (1.0f/600.0f);
+       fval[1] = fval[1] * (1.0f/600.0f);
+       fval[2] = fval[2] * (1.0f/1100.0f);
+       fval[3] = fval[3] * 0.00005f;
+       fval[4] =-fval[4] * 0.00005f;
+       fval[5] = fval[5] * 0.00005f;
+       fval[6] = fval[6] / 1000000.0f;
 
     // scale more if not in perspective mode
-    if (v3d->persp == V3D_ORTHO) {
-        fval[0] = fval[0] * 0.05f;
-        fval[1] = fval[1] * 0.05f;
-        fval[2] = fval[2] * 0.05f;
-        fval[3] = fval[3] * 0.9f;
-        fval[4] = fval[4] * 0.9f;
-        fval[5] = fval[5] * 0.9f;
-        zsens *= 8;
-    }
-
+       if (rv3d->persp == V3D_ORTHO) {
+               fval[0] = fval[0] * 0.05f;
+               fval[1] = fval[1] * 0.05f;
+               fval[2] = fval[2] * 0.05f;
+               fval[3] = fval[3] * 0.9f;
+               fval[4] = fval[4] * 0.9f;
+               fval[5] = fval[5] * 0.9f;
+               zsens *= 8;
+       }
 
     /* set object offset */
        if (ob) {
@@ -1931,7 +1930,7 @@ void viewmoveNDOF(Scene *scene, View3D *v3d, int mode)
                obofs[2] = -ob->obmat[3][2];
        }
        else {
-               VECCOPY(obofs, v3d->ofs);
+               VECCOPY(obofs, rv3d->ofs);
        }
 
     /* calc an adjustment based on distance from camera
@@ -1939,12 +1938,12 @@ void viewmoveNDOF(Scene *scene, View3D *v3d, int mode)
      d = 1.0f;
 
 /*    if (ob) {
-        VecSubf(diff, obofs, v3d->ofs);
+        VecSubf(diff, obofs, rv3d->ofs);
         d = VecLength(diff);
     }
 */
 
-    reverse = (v3d->persmat[2][1] < 0.0f) ? -1.0f : 1.0f;
+    reverse = (rv3d->persmat[2][1] < 0.0f) ? -1.0f : 1.0f;
 
     /*----------------------------------------------------
      * ndof device pan
@@ -1952,25 +1951,25 @@ void viewmoveNDOF(Scene *scene, View3D *v3d, int mode)
     psens *= 1.0f + d;
     curareaX = sbadjust * psens * fval[0];
     curareaY = sbadjust * psens * fval[1];
-    dvec[0] = curareaX * v3d->persinv[0][0] + curareaY * v3d->persinv[1][0];
-    dvec[1] = curareaX * v3d->persinv[0][1] + curareaY * v3d->persinv[1][1];
-    dvec[2] = curareaX * v3d->persinv[0][2] + curareaY * v3d->persinv[1][2];
-    VecAddf(v3d->ofs, v3d->ofs, dvec);
+    dvec[0] = curareaX * rv3d->persinv[0][0] + curareaY * rv3d->persinv[1][0];
+    dvec[1] = curareaX * rv3d->persinv[0][1] + curareaY * rv3d->persinv[1][1];
+    dvec[2] = curareaX * rv3d->persinv[0][2] + curareaY * rv3d->persinv[1][2];
+    VecAddf(rv3d->ofs, rv3d->ofs, dvec);
 
     /*----------------------------------------------------
      * ndof device dolly
      */
     len = zsens * sbadjust * fval[2];
 
-    if (v3d->persp==V3D_CAMOB) {
-        if(v3d->persp==V3D_CAMOB) { /* This is stupid, please fix - TODO */
-            v3d->camzoom+= 10.0f * -len;
+    if (rv3d->persp==V3D_CAMOB) {
+        if(rv3d->persp==V3D_CAMOB) { /* This is stupid, please fix - TODO */
+            rv3d->camzoom+= 10.0f * -len;
         }
-        if (v3d->camzoom < minZoom) v3d->camzoom = minZoom;
-        else if (v3d->camzoom > maxZoom) v3d->camzoom = maxZoom;
+        if (rv3d->camzoom < minZoom) rv3d->camzoom = minZoom;
+        else if (rv3d->camzoom > maxZoom) rv3d->camzoom = maxZoom;
     }
-    else if ((v3d->dist> 0.001*v3d->grid) && (v3d->dist<10.0*v3d->far)) {
-        v3d->dist*=(1.0 + len);
+    else if ((rv3d->dist> 0.001*v3d->grid) && (rv3d->dist<10.0*v3d->far)) {
+        rv3d->dist*=(1.0 + len);
     }
 
 
@@ -1980,7 +1979,7 @@ void viewmoveNDOF(Scene *scene, View3D *v3d, int mode)
      */
 
     /* Get the 3x3 matrix and its inverse from the quaternion */
-    QuatToMat3(v3d->viewquat, m);
+    QuatToMat3(rv3d->viewquat, m);
     Mat3Inv(m_inv,m);
 
     /* Determine the direction of the x vector (for rotating up and down) */
@@ -1996,13 +1995,13 @@ void viewmoveNDOF(Scene *scene, View3D *v3d, int mode)
     q1[1] = si * xvec[0];
     q1[2] = si * xvec[1];
     q1[3] = si * xvec[2];
-    QuatMul(v3d->viewquat, v3d->viewquat, q1);
+    QuatMul(rv3d->viewquat, rv3d->viewquat, q1);
 
     if (use_sel) {
         QuatConj(q1); /* conj == inv for unit quat */
         VecSubf(v3d->ofs, v3d->ofs, obofs);
-        QuatMulVecf(q1, v3d->ofs);
-        VecAddf(v3d->ofs, v3d->ofs, obofs);
+        QuatMulVecf(q1, rv3d->ofs);
+        VecAddf(rv3d->ofs, rv3d->ofs, obofs);
     }
 
     /* Perform the orbital rotation */
@@ -2021,13 +2020,13 @@ void viewmoveNDOF(Scene *scene, View3D *v3d, int mode)
     q1[0] = cos(phi);
     q1[1] = q1[2] = 0.0;
     q1[3] = sin(phi);
-    QuatMul(v3d->viewquat, v3d->viewquat, q1);
+    QuatMul(rv3d->viewquat, rv3d->viewquat, q1);
 
     if (use_sel) {
         QuatConj(q1);
-        VecSubf(v3d->ofs, v3d->ofs, obofs);
-        QuatMulVecf(q1, v3d->ofs);
-        VecAddf(v3d->ofs, v3d->ofs, obofs);
+        VecSubf(rv3d->ofs, rv3d->ofs, obofs);
+        QuatMulVecf(q1, rv3d->ofs);
+        VecAddf(rv3d->ofs, rv3d->ofs, obofs);
     }
 
     /*----------------------------------------------------
index fd37b5bcddd2a8da8e99412362714563b1780a16..95dd74893924199ac9a12e116dbf1dff4a3ee370 100644 (file)
@@ -118,9 +118,6 @@ static void allqueue(int x, int y) {}
 static void persptoetsen(int x) {}
 static void fly(void) {}
 static void editmesh_align_view_to_selected(void *x, int y) {}
-static void play_anim(int x) {}
-static void add_blockhandler(void *x, int y, int z) {}
-static void toggle_blockhandler(void *x, int y, int z) {}
 static void countall(void) {}
 extern void borderselect();
 static int retopo_mesh_paint_check() {return 0;}
@@ -188,13 +185,14 @@ static void do_view3d_buttons(bContext *C, void *arg, int event);
 #define B_LAY          201
 
 
-/* temp hack to get the region window */
-static ARegion *ed_regionwin(ScrArea *sa)
+static RegionView3D *wm_region_view3d(const bContext *C)
 {
+       ScrArea *sa= CTX_wm_area(C);
        ARegion *ar;
+       /* XXX handle foursplit? */
        for(ar= sa->regionbase.first; ar; ar= ar->next)
                if(ar->regiontype==RGN_TYPE_WINDOW)
-                       return ar;
+                       return ar->regiondata;
        return NULL;
 }
 
@@ -252,7 +250,6 @@ void do_layer_buttons(bContext *C, short event)
 static void do_view3d_view_camerasmenu(bContext *C, void *arg, int event)
 {
        Scene *scene= CTX_data_scene(C);
-       View3D *v3d= (View3D*)CTX_wm_space_data(C);
        Base *base;
        int i=1;
        
@@ -260,31 +257,16 @@ static void do_view3d_view_camerasmenu(bContext *C, void *arg, int event)
                /* Set Active Object as Active Camera */
                /* XXX ugly hack alert */
 //             G.qual |= LR_CTRLKEY;
-               persptoetsen(PAD0);
+//             persptoetsen(PAD0);
 //             G.qual &= ~LR_CTRLKEY;
        } else {
-               /* store settings of current view before allowing overwriting with camera view */
-               /* this is a copy of the code in toets.c */
-               if(v3d->persp != V3D_CAMOB) {
-                       QUATCOPY(v3d->lviewquat, v3d->viewquat);
-                       v3d->lview= v3d->view;
-                       v3d->lpersp= v3d->persp;
-               }
 
                for( base = FIRSTBASE; base; base = base->next ) {
                        if (base->object->type == OB_CAMERA) {
                                i++;
                                
                                if (event==i) {
-                                       
-                                       if (v3d->camera == base->object && v3d->persp==V3D_CAMOB)
-                                               return;
-                                       
-                                       /* XXX handle smooth view */
-                                       v3d->camera= base->object;
-                                       handle_view3d_lock();
-                                       v3d->persp= V3D_CAMOB;
-                                       v3d->view= 0;
+                                       /* XXX use api call! */
                                        
                                        break;
                                }
@@ -514,40 +496,25 @@ static uiBlock *view3d_view_spacehandlers(bContext *C, uiMenuBlockHandle *handle
 
 static void do_view3d_viewmenu(bContext *C, void *arg, int event)
 {
-       Scene *scene= CTX_data_scene(C);
-       ScrArea *sa= CTX_wm_area(C);
-       View3D *v3d= sa->spacedata.first;
        
        switch(event) {
        case 0: /* User */
-               v3d->viewbut = 0;
-               v3d->persp = V3D_PERSP;
                break;
        case 1: /* Camera */
-               persptoetsen(PAD0);
                break;
        case 2: /* Top */
-               persptoetsen(PAD7);
                break;
        case 3: /* Front */
-               persptoetsen(PAD1);
                break;
        case 4: /* Side */
-               persptoetsen(PAD3);
                break;
        case 5: /* Perspective */
-               v3d->persp=V3D_PERSP;
                break;
        case 6: /* Orthographic */
-               v3d->persp=V3D_ORTHO;
                break;
        case 7: /* Local View */
-               v3d->localview= 1;
-               initlocalview(scene, ed_regionwin(sa), v3d);
                break;
        case 8: /* Global View */
-               v3d->localview= 0;
-               endlocalview(scene, sa);
                break;
        case 9: /* View All (Home) */
                WM_operator_name_call(C, "VIEW3D_OT_viewhome", WM_OP_EXEC_REGION_WIN, NULL);
@@ -556,28 +523,27 @@ static void do_view3d_viewmenu(bContext *C, void *arg, int event)
                WM_operator_name_call(C, "VIEW3D_OT_viewcenter", WM_OP_EXEC_REGION_WIN, NULL);
                break;
        case 13: /* Play Back Animation */
-               play_anim(0);
                break;
        case 15: /* Background Image... */
-               add_blockhandler(sa, VIEW3D_HANDLER_BACKGROUND, UI_PNL_UNSTOW);
+//             add_blockhandler(sa, VIEW3D_HANDLER_BACKGROUND, UI_PNL_UNSTOW);
                break;
        case 16: /* View  Panel */
-               add_blockhandler(sa, VIEW3D_HANDLER_PROPERTIES, UI_PNL_UNSTOW);
+//             add_blockhandler(sa, VIEW3D_HANDLER_PROPERTIES, UI_PNL_UNSTOW);
                break;
        case 17: /* Set Clipping Border */
                WM_operator_name_call(C, "VIEW3D_OT_clipping", WM_OP_INVOKE_REGION_WIN, NULL);
                break;
        case 18: /* render preview */
-               toggle_blockhandler(sa, VIEW3D_HANDLER_PREVIEW, 0);
+//             toggle_blockhandler(sa, VIEW3D_HANDLER_PREVIEW, 0);
                break;
        case 19: /* zoom within border */
 //             view3d_border_zoom();
                break;
        case 20: /* Transform  Space Panel */
-               add_blockhandler(sa, VIEW3D_HANDLER_TRANSFORM, UI_PNL_UNSTOW);
+//             add_blockhandler(sa, VIEW3D_HANDLER_TRANSFORM, UI_PNL_UNSTOW);
                break;  
        case 21: /* Grease Pencil */
-               add_blockhandler(sa, VIEW3D_HANDLER_GREASEPENCIL, UI_PNL_UNSTOW);
+//             add_blockhandler(sa, VIEW3D_HANDLER_GREASEPENCIL, UI_PNL_UNSTOW);
                break;          
        case 22: /* View all layers */
                do_layer_buttons(C, -2);
@@ -590,6 +556,7 @@ static uiBlock *view3d_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *ar
 {
        ScrArea *sa= CTX_wm_area(C);
        View3D *v3d= sa->spacedata.first;
+       RegionView3D *rv3d= wm_region_view3d(C);
        uiBlock *block;
        short yco= 0, menuwidth=120;
        
@@ -604,24 +571,24 @@ static uiBlock *view3d_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *ar
        
        uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
        
-       if ((v3d->viewbut == 0) && !(v3d->persp == V3D_CAMOB)) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "User",                      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
+       if ((rv3d->viewbut == 0) && !(rv3d->persp == V3D_CAMOB)) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "User",                    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
        else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "User",                                              0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
-       if (v3d->persp == V3D_CAMOB) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Camera|NumPad 0",     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
+       if (rv3d->persp == V3D_CAMOB) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Camera|NumPad 0",    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
        else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Camera|NumPad 0",                   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, "");
-       if (v3d->viewbut == 1) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Top|NumPad 7",                      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
+       if (rv3d->viewbut == 1) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Top|NumPad 7",                     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
        else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Top|NumPad 7",                              0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");
-       if (v3d->viewbut == 2) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Front|NumPad 1",            0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
+       if (rv3d->viewbut == 2) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Front|NumPad 1",           0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
        else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Front|NumPad 1",                    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, "");
-       if (v3d->viewbut == 3) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Side|NumPad 3",             0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
+       if (rv3d->viewbut == 3) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Side|NumPad 3",            0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
        else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Side|NumPad 3",                     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
        
        uiDefIconTextBlockBut(block, view3d_view_camerasmenu, NULL, ICON_RIGHTARROW_THIN, "Cameras", 0, yco-=20, 120, 19, "");
        
        uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
        
-       if(v3d->persp==V3D_PERSP) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Perspective|NumPad 5",   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
+       if(rv3d->persp==V3D_PERSP) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Perspective|NumPad 5",  0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
        else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Perspective|NumPad 5",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, "");
-       if(v3d->persp==V3D_ORTHO) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Orthographic|NumPad 5", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
+       if(rv3d->persp==V3D_ORTHO) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Orthographic|NumPad 5", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
        else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Orthographic|NumPad 5", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
        
        uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
@@ -643,11 +610,11 @@ static uiBlock *view3d_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *ar
        
        uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
        
-       if(v3d->flag & V3D_CLIPPING)
+       if(rv3d->rflag & RV3D_CLIPPING)
                uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Clear Clipping Border|Alt B",                    0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 17, "");
        else
                uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set Clipping Border|Alt B",                      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 17, "");
-       if (v3d->persp==V3D_ORTHO) uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom Within Border...|Shift B",                       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 19, "");
+       if (rv3d->persp==V3D_ORTHO) uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom Within Border...|Shift B",                      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 19, "");
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View Selected|NumPad .",                 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 11, "");
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home",          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
        if(!sa->full) uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Maximize Window|Ctrl UpArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 99, "");
@@ -675,9 +642,9 @@ static uiBlock *view3d_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *ar
        return block;
 }
 
+#if 0
 void do_view3d_select_object_typemenu(bContext *C, void *arg, int event)
 {
-#if 0
 
        extern void selectall_type(short obtype);
        
@@ -717,7 +684,6 @@ void do_view3d_select_object_typemenu(bContext *C, void *arg, int event)
                break;
        }
        allqueue(REDRAWVIEW3D, 0);
-#endif
 }
 
 static uiBlock *view3d_select_object_typemenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
@@ -750,6 +716,7 @@ static uiBlock *view3d_select_object_typemenu(bContext *C, uiMenuBlockHandle *ha
        return block;
 }
 
+
 void do_view3d_select_object_layermenu(bContext *C, void *arg, int event)
 {
 // XXX extern void selectall_layer(unsigned int layernum);
@@ -821,7 +788,6 @@ static uiBlock *view3d_select_object_layermenu(bContext *C, uiMenuBlockHandle *h
 
 void do_view3d_select_object_linkedmenu(bContext *C, void *arg, int event)
 {
-#if 0
        switch(event) {
        case 1: /* Object Ipo */
        case 2: /* ObData */
@@ -832,7 +798,6 @@ void do_view3d_select_object_linkedmenu(bContext *C, void *arg, int event)
        }
        countall();
        allqueue(REDRAWVIEW3D, 0);
-#endif
 }
 
 static uiBlock *view3d_select_object_linkedmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
@@ -855,7 +820,7 @@ static uiBlock *view3d_select_object_linkedmenu(bContext *C, uiMenuBlockHandle *
 
 void do_view3d_select_object_groupedmenu(bContext *C, void *arg, int event)
 {
-#if 0
+
        switch(event) {
        case 1: /* Children */
        case 2: /* Immediate Children */
@@ -872,7 +837,7 @@ void do_view3d_select_object_groupedmenu(bContext *C, void *arg, int event)
                break;
        }
        allqueue(REDRAWVIEW3D, 0);
-#endif
+
 }
 
 static uiBlock *view3d_select_object_groupedmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
@@ -900,10 +865,12 @@ static uiBlock *view3d_select_object_groupedmenu(bContext *C, uiMenuBlockHandle
        return block;
 }
 
+#endif
+
 static uiBlock *view3d_select_objectmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
        uiBlock *block;
-       short yco= 0, menuwidth=120;
+//     short yco= 0, menuwidth=120;
        
        block= uiBeginBlock(C, handle->region, "view3d_select_objectmenu", UI_EMBOSSP, UI_HELV);
        
@@ -4852,7 +4819,6 @@ uiBlock *view3d_sculpt_inputmenu(bContext *C, uiMenuBlockHandle *handle, void *a
 
 uiBlock *view3d_sculptmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       Scene *scene= CTX_data_scene(C);
        ScrArea *sa= CTX_wm_area(C);
        View3D *v3d= sa->spacedata.first;
        uiBlock *block;
@@ -5357,19 +5323,9 @@ static void do_view3d_buttons(bContext *C, void *arg, int event)
                
        case B_VIEWBUT:
        
-               if(v3d->viewbut==1) persptoetsen(PAD7);
-               else if(v3d->viewbut==2) persptoetsen(PAD1);
-               else if(v3d->viewbut==3) persptoetsen(PAD3);
-               break;
 
        case B_PERSP:
        
-               if(v3d->persp==V3D_CAMOB) persptoetsen(PAD0);
-               else {
-                       if (v3d->persp==V3D_ORTHO)                      v3d->persp = V3D_PERSP; 
-                       else if (v3d->persp==V3D_PERSP) v3d->persp = V3D_ORTHO;
-                       persptoetsen(PAD5);
-               }
                
                break;
        case B_VIEWRENDER:
@@ -5585,20 +5541,21 @@ static void do_view3d_buttons(bContext *C, void *arg, int event)
        }
 }
 
-static void view3d_header_pulldowns(const bContext *C, uiBlock *block, View3D *v3d, Object *ob, int *xcoord, int yco)
+static void view3d_header_pulldowns(const bContext *C, uiBlock *block, Object *ob, int *xcoord, int yco)
 {
        Object *obedit = CTX_data_edit_object(C);
+       RegionView3D *rv3d= wm_region_view3d(C);
        short xmax, xco= *xcoord;
        
+       
        /* pull down menus */
        uiBlockSetEmboss(block, UI_EMBOSSP);
        
        /* compensate for local mode when setting up the viewing menu/iconrow values */
-       if(v3d->view==7) v3d->viewbut= 1;
-       else if(v3d->view==1) v3d->viewbut= 2;
-       else if(v3d->view==3) v3d->viewbut= 3;
-       else v3d->viewbut= 0;
-       
+       if(rv3d->view==7) rv3d->viewbut= 1;
+       else if(rv3d->view==1) rv3d->viewbut= 2;
+       else if(rv3d->view==3) rv3d->viewbut= 3;
+       else rv3d->viewbut= 0;
        
        /* the 'xmax - 3' rather than xmax is to prevent some weird flickering where the highlighted
         * menu is drawn wider than it should be. The ypos of -2 is to make it properly fill the
@@ -5746,7 +5703,7 @@ void view3d_header_buttons(const bContext *C, ARegion *ar)
        xco= ED_area_header_standardbuttons(C, block, yco);
 
        if((sa->flag & HEADER_NO_PULLDOWN)==0) 
-               view3d_header_pulldowns(C, block, v3d, ob, &xco, yco);
+               view3d_header_pulldowns(C, block, ob, &xco, yco);
 
        /* other buttons: */
        uiBlockSetEmboss(block, UI_EMBOSS);
index f40344dd95b162dcfe09ead7244840d2954a3f2c..fcdd2cd77f83f326f3a11288e2d98cd9b693aa87 100644 (file)
@@ -87,21 +87,21 @@ void VIEW3D_OT_drawtype(struct wmOperatorType *ot);
 /* drawobject.c */
 void draw_object(Scene *scene, struct ARegion *ar, View3D *v3d, Base *base, int flag);
 int draw_glsl_material(Scene *scene, Object *ob, View3D *v3d, int dt);
-void draw_object_instance(Scene *scene, View3D *v3d, Object *ob, int dt, int outline);
-void draw_object_backbufsel(Scene *scene, View3D *v3d, Object *ob);
+void draw_object_instance(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, int dt, int outline);
+void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob);
 void drawaxes(float size, int flag, char drawtype);
 
 /* drawarmature.c */
-int draw_armature(Scene *scene, View3D *v3d, Base *base, int dt, int flag);
+int draw_armature(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt, int flag);
 
 /* drawmesh.c */
-void draw_mesh_textured(Scene *scene, View3D *v3d, Object *ob, struct DerivedMesh *dm, int faceselect);
+void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, struct DerivedMesh *dm, int faceselect);
 
 /* view3d_draw.c */
 void view3d_main_area_draw(const struct bContext *C, struct ARegion *ar);
 void draw_depth(Scene *scene, struct ARegion *ar, View3D *v3d, int (* func)(void *));
 void view3d_clr_clipping(void);
-void view3d_set_clipping(View3D *v3d);
+void view3d_set_clipping(RegionView3D *rv3d);
 void add_view3d_after(View3D *v3d, Base *base, int type, int flag);
 void make_axis_color(char *col, char *col2, char axis);
 void calc_viewborder(Scene *scene, struct ARegion *ar, View3D *v3d, rctf *viewborder_r);
@@ -127,14 +127,14 @@ void VIEW3D_OT_wpaint(struct wmOperatorType *ot);
 void VIEW3D_OT_smoothview(struct wmOperatorType *ot);
 void VIEW3D_OT_setcameratoview(struct wmOperatorType *ot);
 
-int boundbox_clip(View3D *v3d, float obmat[][4], struct BoundBox *bb);
+int boundbox_clip(RegionView3D *rv3d, float obmat[][4], struct BoundBox *bb);
 
-void view3d_project_short_clip(struct ARegion *ar, View3D *v3d, float *vec, short *adr, float projmat[4][4], float wmat[4][4]);
+void view3d_project_short_clip(struct ARegion *ar, float *vec, short *adr, float projmat[4][4], float wmat[4][4]);
 void view3d_project_short_noclip(struct ARegion *ar, float *vec, short *adr, float mat[4][4]);
 void view3d_project_float(struct ARegion *a, float *vec, float *adr, float mat[4][4]);
-void view3d_get_object_project_mat(View3D *v3d, struct Object *ob, float pmat[4][4], float vmat[4][4]);
+void view3d_get_object_project_mat(RegionView3D *v3d, struct Object *ob, float pmat[4][4], float vmat[4][4]);
 
-int get_view3d_viewplane(View3D *v3d, int winxi, int winyi, rctf *viewplane, float *clipsta, float *clipend, float *pixsize);
+int get_view3d_viewplane(View3D *v3d, RegionView3D *rv3d, int winxi, int winyi, rctf *viewplane, float *clipsta, float *clipend, float *pixsize);
 
 void initlocalview(Scene *scene, struct ARegion *ar, View3D *v3d);
 void restore_localviewdata(View3D *vd);
@@ -144,8 +144,8 @@ void centerview(struct ARegion *ar, View3D *v3d);
 
 void smooth_view(struct bContext *C, Object *, Object *, float *ofs, float *quat, float *dist, float *lens);
 
-void setwinmatrixview3d(View3D *v3d, int winx, int winy, rctf *rect);  /* rect: for picking */
-void setviewmatrixview3d(Scene *scene, View3D *v3d);
+void setwinmatrixview3d(ARegion *ar, View3D *v3d, rctf *rect); /* rect: for picking */
+void setviewmatrixview3d(Scene *scene, View3D *v3d, RegionView3D *rv3d);
 
 #endif /* ED_VIEW3D_INTERN_H */
 
index d6f6b0439fdf4007f051024568526aa0da2f2d9f..ef29e21d047d528e34b8fe19bba3452e55c33f85 100644 (file)
@@ -80,6 +80,7 @@
 #include "ED_object.h"
 #include "ED_screen.h"
 #include "ED_types.h"
+#include "ED_util.h"
 
 #include "UI_interface.h"
 #include "UI_resources.h"
@@ -96,6 +97,7 @@ void view3d_set_viewcontext(bContext *C, ViewContext *vc)
        vc->ar= CTX_wm_region(C);
        vc->scene= CTX_data_scene(C);
        vc->v3d= CTX_wm_view3d(C);
+       vc->rv3d= vc->ar->regiondata;
        vc->obact= CTX_data_active_object(C);
        vc->obedit= CTX_data_edit_object(C); 
 }
@@ -310,10 +312,10 @@ static void do_lasso_select_pose(ViewContext *vc, short mcords[][2], short moves
        for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
                VECCOPY(vec, pchan->pose_head);
                Mat4MulVecfl(ob->obmat, vec);
-               project_short(vc->ar, vc->v3d, vec, sco1);
+               project_short(vc->ar, vec, sco1);
                VECCOPY(vec, pchan->pose_tail);
                Mat4MulVecfl(ob->obmat, vec);
-               project_short(vc->ar, vc->v3d, vec, sco2);
+               project_short(vc->ar, vec, sco2);
                
                if(lasso_inside_edge(mcords, moves, sco1[0], sco1[1], sco2[0], sco2[1])) {
                        if(select) pchan->bone->flag |= BONE_SELECTED;
@@ -329,7 +331,7 @@ static void do_lasso_select_objects(ViewContext *vc, short mcords[][2], short mo
        
        for(base= vc->scene->base.first; base; base= base->next) {
                if(base->lay & vc->v3d->lay) {
-                       project_short(vc->ar, vc->v3d, base->object->obmat[3], &base->sx);
+                       project_short(vc->ar, base->object->obmat[3], &base->sx);
                        if(lasso_inside(mcords, moves, base->sx, base->sy)) {
                                
                                if(select) ED_base_object_select(base, BA_SELECT);
@@ -572,10 +574,10 @@ static void do_lasso_select_armature(ViewContext *vc, short mcords[][2], short m
 
                VECCOPY(vec, ebone->head);
                Mat4MulVecfl(vc->obedit->obmat, vec);
-               project_short(vc->ar, vc->v3d, vec, sco1);
+               project_short(vc->ar, vec, sco1);
                VECCOPY(vec, ebone->tail);
                Mat4MulVecfl(vc->obedit->obmat, vec);
-               project_short(vc->ar, vc->v3d, vec, sco2);
+               project_short(vc->ar, vec, sco2);
                
                didpoint= 0;
                if(lasso_inside(mcords, moves, sco1[0], sco1[1])) {
@@ -819,7 +821,7 @@ static Base *mouse_select_menu(ViewContext *vc, unsigned int *buffer, int hits,
                        else {
                                int temp, dist=15;
                                
-                               project_short(vc->ar, vc->v3d, base->object->obmat[3], &base->sx);
+                               project_short(vc->ar, base->object->obmat[3], &base->sx);
                                
                                temp= abs(base->sx -mval[0]) + abs(base->sy -mval[1]);
                                if(temp<dist ) baseList[baseCount] = base;
@@ -937,7 +939,7 @@ static void mouse_select(bContext *C, short *mval, short extend, short obcenter)
                        base= startbase;
                        while(base) {
                                if (BASE_SELECTABLE(v3d, base)) {
-                                       project_short(ar, v3d, base->object->obmat[3], &base->sx);
+                                       project_short(ar, base->object->obmat[3], &base->sx);
                                        
                                        temp= abs(base->sx -mval[0]) + abs(base->sy -mval[1]);
                                        if(base==BASACT) temp+=10;
@@ -1758,7 +1760,7 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op)
                
                for(base= FIRSTBASE; base; base= base->next) {
                        if(base->lay & v3d->lay) {
-                               project_short(ar, v3d, base->object->obmat[3], &base->sx);
+                               project_short(ar, base->object->obmat[3], &base->sx);
                                if(base->sx!=IS_CLIPPED) {
                                        int dx= base->sx-x;
                                        int dy= base->sy-y;
index f97375c767a3c0e80b20476fc6996ea7e16bc324..1f2ba4b4b96ec2f64cf6cd53cb63a7f2596bc9b1 100644 (file)
@@ -94,14 +94,13 @@ void view3d_operator_needs_opengl(const bContext *C)
        if(ar->regiontype!=RGN_TYPE_WINDOW)
                printf("view3d_operator_needs_opengl error, wrong region\n");
        else {
-               ScrArea *sa= CTX_wm_area(C);
-               View3D *v3d= sa->spacedata.first;
+               RegionView3D *rv3d= ar->regiondata;
                
                wmSubWindowSet(CTX_wm_window(C), ar->swinid);
                glMatrixMode(GL_PROJECTION);
-               wmLoadMatrix(v3d->winmat);
+               wmLoadMatrix(rv3d->winmat);
                glMatrixMode(GL_MODELVIEW);
-               wmLoadMatrix(v3d->viewmat);
+               wmLoadMatrix(rv3d->viewmat);
        }
 }
 
@@ -145,8 +144,7 @@ static void object_lens_clip_settings(Object *ob, float *lens, float *clipsta, f
 * 
 * The dist is not modified for this function, if NULL its assimed zero
 * */
-/* Scene can be NULL */
-static void view_settings_from_ob(Scene *scene, Object *ob, float *ofs, float *quat, float *dist, float *lens)
+static void view_settings_from_ob(Object *ob, float *ofs, float *quat, float *dist, float *lens)
 {      
        float bmat[4][4];
        float imat[4][4];
@@ -156,8 +154,6 @@ static void view_settings_from_ob(Scene *scene, Object *ob, float *ofs, float *q
        
        /* Offset */
        if (ofs) {
-               /* this should not be needed, nly for camera to prevent lag */
-               if(scene) where_is_object(scene, ob);   
                VECCOPY(ofs, ob->obmat[3]);
                VecMulf(ofs, -1.0f); /*flip the vector*/
        }
@@ -204,14 +200,14 @@ struct SmoothViewStore {
 /* the arguments are the desired situation */
 void smooth_view(bContext *C, Object *oldcamera, Object *camera, float *ofs, float *quat, float *dist, float *lens)
 {
-       Scene *scene= CTX_data_scene(C);
-       View3D *v3d= (View3D *)CTX_wm_space_data(C);
+       View3D *v3d = CTX_wm_view3d(C);
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
        struct SmoothViewStore sms;
        
        /* initialize sms */
-       VECCOPY(sms.new_ofs, v3d->ofs);
-       QUATCOPY(sms.new_quat, v3d->viewquat);
-       sms.new_dist= v3d->dist;
+       VECCOPY(sms.new_ofs, rv3d->ofs);
+       QUATCOPY(sms.new_quat, rv3d->viewquat);
+       sms.new_dist= rv3d->dist;
        sms.new_lens= v3d->lens;
        sms.to_camera= 0;
        
@@ -222,27 +218,27 @@ void smooth_view(bContext *C, Object *oldcamera, Object *camera, float *ofs, flo
        if(lens) sms.new_lens= *lens;
        
        if (camera) {
-               view_settings_from_ob(scene, camera, sms.new_ofs, sms.new_quat, &sms.new_dist, &sms.new_lens);
+               view_settings_from_ob(camera, sms.new_ofs, sms.new_quat, &sms.new_dist, &sms.new_lens);
                sms.to_camera= 1; /* restore view3d values in end */
        }
        
        if (C && U.smooth_viewtx) {
                int changed = 0; /* zero means no difference */
                
-               if (sms.new_dist != v3d->dist)
+               if (sms.new_dist != rv3d->dist)
                        changed = 1;
                if (sms.new_lens != v3d->lens)
                        changed = 1;
                
-               if ((sms.new_ofs[0]!=v3d->ofs[0]) ||
-                       (sms.new_ofs[1]!=v3d->ofs[1]) ||
-                       (sms.new_ofs[2]!=v3d->ofs[2]) )
+               if ((sms.new_ofs[0]!=rv3d->ofs[0]) ||
+                       (sms.new_ofs[1]!=rv3d->ofs[1]) ||
+                       (sms.new_ofs[2]!=rv3d->ofs[2]) )
                        changed = 1;
                
-               if ((sms.new_quat[0]!=v3d->viewquat[0]) ||
-                       (sms.new_quat[1]!=v3d->viewquat[1]) ||
-                       (sms.new_quat[2]!=v3d->viewquat[2]) ||
-                       (sms.new_quat[3]!=v3d->viewquat[3]) )
+               if ((sms.new_quat[0]!=rv3d->viewquat[0]) ||
+                       (sms.new_quat[1]!=rv3d->viewquat[1]) ||
+                       (sms.new_quat[2]!=rv3d->viewquat[2]) ||
+                       (sms.new_quat[3]!=rv3d->viewquat[3]) )
                        changed = 1;
                
                /* The new view is different from the old one
@@ -268,30 +264,30 @@ void smooth_view(bContext *C, Object *oldcamera, Object *camera, float *ofs, flo
                        
                        /* original values */
                        if (oldcamera) {
-                               sms.orig_dist= v3d->dist; // below function does weird stuff with it...
-                               view_settings_from_ob(scene, oldcamera, sms.orig_ofs, sms.orig_quat, &sms.orig_dist, &sms.orig_lens);
+                               sms.orig_dist= rv3d->dist; // below function does weird stuff with it...
+                               view_settings_from_ob(oldcamera, sms.orig_ofs, sms.orig_quat, &sms.orig_dist, &sms.orig_lens);
                        }
                        else {
-                               VECCOPY(sms.orig_ofs, v3d->ofs);
-                               QUATCOPY(sms.orig_quat, v3d->viewquat);
-                               sms.orig_dist= v3d->dist;
+                               VECCOPY(sms.orig_ofs, rv3d->ofs);
+                               QUATCOPY(sms.orig_quat, rv3d->viewquat);
+                               sms.orig_dist= rv3d->dist;
                                sms.orig_lens= v3d->lens;
                        }
                        /* grid draw as floor */
-                       sms.orig_view= v3d->view;
-                       v3d->view= 0;
+                       sms.orig_view= rv3d->view;
+                       rv3d->view= 0;
                        
                        /* ensure it shows correct */
-                       if(sms.to_camera) v3d->persp= V3D_PERSP;
+                       if(sms.to_camera) rv3d->persp= V3D_PERSP;
                        
                        /* keep track of running timer! */
-                       if(v3d->sms==NULL)
-                               v3d->sms= MEM_mallocN(sizeof(struct SmoothViewStore), "smoothview v3d");
-                       *v3d->sms= sms;
-                       if(v3d->smooth_timer)
-                               WM_event_remove_window_timer(CTX_wm_window(C), v3d->smooth_timer);
+                       if(rv3d->sms==NULL)
+                               rv3d->sms= MEM_mallocN(sizeof(struct SmoothViewStore), "smoothview v3d");
+                       *rv3d->sms= sms;
+                       if(rv3d->smooth_timer)
+                               WM_event_remove_window_timer(CTX_wm_window(C), rv3d->smooth_timer);
                        /* TIMER1 is hardcoded in keymap */
-                       v3d->smooth_timer= WM_event_add_window_timer(CTX_wm_window(C), TIMER1, 1.0/30.0);       /* max 30 frs/sec */
+                       rv3d->smooth_timer= WM_event_add_window_timer(CTX_wm_window(C), TIMER1, 1.0/30.0);      /* max 30 frs/sec */
                        
                        return;
                }
@@ -299,9 +295,9 @@ void smooth_view(bContext *C, Object *oldcamera, Object *camera, float *ofs, flo
        
        /* if we get here nothing happens */
        if(sms.to_camera==0) {
-               VECCOPY(v3d->ofs, sms.new_ofs);
-               QUATCOPY(v3d->viewquat, sms.new_quat);
-               v3d->dist = sms.new_dist;
+               VECCOPY(rv3d->ofs, sms.new_ofs);
+               QUATCOPY(rv3d->viewquat, sms.new_quat);
+               rv3d->dist = sms.new_dist;
                v3d->lens = sms.new_lens;
        }
        ED_region_tag_redraw(CTX_wm_region(C));
@@ -310,40 +306,41 @@ void smooth_view(bContext *C, Object *oldcamera, Object *camera, float *ofs, flo
 /* only meant for timer usage */
 static int view3d_smoothview_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
-       View3D *v3d= (View3D *)CTX_wm_space_data(C);
-       struct SmoothViewStore *sms= v3d->sms;
+       View3D *v3d = CTX_wm_view3d(C);
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
+       struct SmoothViewStore *sms= rv3d->sms;
        double step, step_inv;
        
        /* escape if not our timer */
-       if(v3d->smooth_timer==NULL || v3d->smooth_timer!=event->customdata)
+       if(rv3d->smooth_timer==NULL || rv3d->smooth_timer!=event->customdata)
                return OPERATOR_PASS_THROUGH;
        
-       step =  (v3d->smooth_timer->duration)/sms->time_allowed;
+       step =  (rv3d->smooth_timer->duration)/sms->time_allowed;
        
        /* end timer */
        if(step >= 1.0f) {
                
                /* if we went to camera, store the original */
                if(sms->to_camera) {
-                       v3d->persp= V3D_CAMOB;
-                       VECCOPY(v3d->ofs, sms->orig_ofs);
-                       QUATCOPY(v3d->viewquat, sms->orig_quat);
-                       v3d->dist = sms->orig_dist;
+                       rv3d->persp= V3D_CAMOB;
+                       VECCOPY(rv3d->ofs, sms->orig_ofs);
+                       QUATCOPY(rv3d->viewquat, sms->orig_quat);
+                       rv3d->dist = sms->orig_dist;
                        v3d->lens = sms->orig_lens;
                }
                else {
-                       VECCOPY(v3d->ofs, sms->new_ofs);
-                       QUATCOPY(v3d->viewquat, sms->new_quat);
-                       v3d->dist = sms->new_dist;
+                       VECCOPY(rv3d->ofs, sms->new_ofs);
+                       QUATCOPY(rv3d->viewquat, sms->new_quat);
+                       rv3d->dist = sms->new_dist;
                        v3d->lens = sms->new_lens;
                }
-               v3d->view= sms->orig_view;
+               rv3d->view= sms->orig_view;
                
-               MEM_freeN(v3d->sms);
-               v3d->sms= NULL;
+               MEM_freeN(rv3d->sms);
+               rv3d->sms= NULL;
                
-               WM_event_remove_window_timer(CTX_wm_window(C), v3d->smooth_timer);
-               v3d->smooth_timer= NULL;
+               WM_event_remove_window_timer(CTX_wm_window(C), rv3d->smooth_timer);
+               rv3d->smooth_timer= NULL;
        }
        else {
                int i;
@@ -355,11 +352,11 @@ static int view3d_smoothview_invoke(bContext *C, wmOperator *op, wmEvent *event)
                step_inv = 1.0-step;
 
                for (i=0; i<3; i++)
-                       v3d->ofs[i] = sms->new_ofs[i]*step + sms->orig_ofs[i]*step_inv;
+                       rv3d->ofs[i] = sms->new_ofs[i]*step + sms->orig_ofs[i]*step_inv;
 
-               QuatInterpol(v3d->viewquat, sms->orig_quat, sms->new_quat, step);
+               QuatInterpol(rv3d->viewquat, sms->orig_quat, sms->new_quat, step);
                
-               v3d->dist = sms->new_dist*step + sms->orig_dist*step_inv;
+               rv3d->dist = sms->new_dist*step + sms->orig_dist*step_inv;
                v3d->lens = sms->new_lens*step + sms->orig_lens*step_inv;
        }
        
@@ -380,27 +377,25 @@ void VIEW3D_OT_smoothview(wmOperatorType *ot)
        
        ot->poll= ED_operator_view3d_active;
 }
+
 static int view3d_setcameratoview_exec(bContext *C, wmOperator *op)
 {
-       ScrArea *sa= CTX_wm_area(C);
-       View3D *v3d= sa->spacedata.first;
+       View3D *v3d = CTX_wm_view3d(C);
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
        Object *ob;
        float dvec[3];
        
        ob= v3d->camera;
-       dvec[0]= v3d->dist*v3d->viewinv[2][0];
-       dvec[1]= v3d->dist*v3d->viewinv[2][1];
-       dvec[2]= v3d->dist*v3d->viewinv[2][2];                                  
+       dvec[0]= rv3d->dist*rv3d->viewinv[2][0];
+       dvec[1]= rv3d->dist*rv3d->viewinv[2][1];
+       dvec[2]= rv3d->dist*rv3d->viewinv[2][2];
+       
        VECCOPY(ob->loc, dvec);
        VecSubf(ob->loc, ob->loc, v3d->ofs);
-       v3d->viewquat[0]= -v3d->viewquat[0];
-       /*  */
-       /*if (ob->transflag & OB_QUAT) {
-               QUATCOPY(ob->quat, v3d->viewquat);
-       } else {*/
-       QuatToEul(v3d->viewquat, ob->rot);
-       /*}*/
-       v3d->viewquat[0]= -v3d->viewquat[0];
+       rv3d->viewquat[0]= -rv3d->viewquat[0];
+
+       QuatToEul(rv3d->viewquat, ob->rot);
+       rv3d->viewquat[0]= -rv3d->viewquat[0];
        
        ob->recalc= OB_RECALC_OB;
        
@@ -409,6 +404,7 @@ static int view3d_setcameratoview_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 
 }
+
 void VIEW3D_OT_setcameratoview(wmOperatorType *ot)
 {
        
@@ -426,23 +422,24 @@ void VIEW3D_OT_setcameratoview(wmOperatorType *ot)
 /* create intersection coordinates in view Z direction at mouse coordinates */
 void viewline(ARegion *ar, View3D *v3d, short mval[2], float ray_start[3], float ray_end[3])
 {
+       RegionView3D *rv3d= ar->regiondata;
        float vec[4];
        
-       if(v3d->persp != V3D_ORTHO){
+       if(rv3d->persp != V3D_ORTHO){
                vec[0]= 2.0f * mval[0] / ar->winx - 1;
                vec[1]= 2.0f * mval[1] / ar->winy - 1;
                vec[2]= -1.0f;
                vec[3]= 1.0f;
                
-               Mat4MulVec4fl(v3d->persinv, vec);
+               Mat4MulVec4fl(rv3d->persinv, vec);
                VecMulf(vec, 1.0f / vec[3]);
                
-               VECCOPY(ray_start, v3d->viewinv[3]);
+               VECCOPY(ray_start, rv3d->viewinv[3]);
                VECSUB(vec, vec, ray_start);
                Normalize(vec);
                
-               VECADDFAC(ray_start, v3d->viewinv[3], vec, v3d->near);
-               VECADDFAC(ray_end, v3d->viewinv[3], vec, v3d->far);
+               VECADDFAC(ray_start, rv3d->viewinv[3], vec, v3d->near);
+               VECADDFAC(ray_end, rv3d->viewinv[3], vec, v3d->far);
        }
        else {
                vec[0] = 2.0f * mval[0] / ar->winx - 1;
@@ -450,10 +447,10 @@ void viewline(ARegion *ar, View3D *v3d, short mval[2], float ray_start[3], float
                vec[2] = 0.0f;
                vec[3] = 1.0f;
                
-               Mat4MulVec4fl(v3d->persinv, vec);
+               Mat4MulVec4fl(rv3d->persinv, vec);
                
-               VECADDFAC(ray_start, vec, v3d->viewinv[2],  1000.0f);
-               VECADDFAC(ray_end, vec, v3d->viewinv[2], -1000.0f);
+               VECADDFAC(ray_start, vec, rv3d->viewinv[2],  1000.0f);