diff options
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r-- | source/blender/editors/space_view3d/drawarmature.c | 18 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawobject.c | 337 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawvolume.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/space_view3d.c | 9 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 63 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 36 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_fly.c | 4 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_header.c | 10 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_select.c | 45 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_snap.c | 41 |
11 files changed, 425 insertions, 141 deletions
diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c index a7bb1fb3ee6..c0046b089af 100644 --- a/source/blender/editors/space_view3d/drawarmature.c +++ b/source/blender/editors/space_view3d/drawarmature.c @@ -153,17 +153,17 @@ static short set_pchan_glColor (short colCode, int boneflag, short constflag) unsigned char cp[3]; if (boneflag & BONE_DRAW_ACTIVE) { - VECCOPY(cp, bcolor->active); + copy_v3_v3_char((char *)cp, bcolor->active); if(!(boneflag & BONE_SELECTED)) { cp_shade_color3ub(cp, -80); } } else if (boneflag & BONE_SELECTED) { - VECCOPY(cp, bcolor->select); + copy_v3_v3_char((char *)cp, bcolor->select); } else { /* a bit darker than solid */ - VECCOPY(cp, bcolor->solid); + copy_v3_v3_char((char *)cp, bcolor->solid); cp_shade_color3ub(cp, -50); } @@ -213,13 +213,13 @@ static short set_pchan_glColor (short colCode, int boneflag, short constflag) unsigned char cp[3]; if (boneflag & BONE_DRAW_ACTIVE) { - VECCOPY(cp, bcolor->active); + copy_v3_v3_char((char *)cp, bcolor->active); } else if (boneflag & BONE_SELECTED) { - VECCOPY(cp, bcolor->select); + copy_v3_v3_char((char *)cp, bcolor->select); } else { - VECCOPY(cp, bcolor->solid); + copy_v3_v3_char((char *)cp, bcolor->solid); } glColor3ubv(cp); @@ -239,15 +239,15 @@ static short set_pchan_glColor (short colCode, int boneflag, short constflag) unsigned char cp[3]; if (boneflag & BONE_DRAW_ACTIVE) { - VECCOPY(cp, bcolor->active); + copy_v3_v3_char((char *)cp, bcolor->active); cp_shade_color3ub(cp, 10); } else if (boneflag & BONE_SELECTED) { - VECCOPY(cp, bcolor->select); + copy_v3_v3_char((char *)cp, bcolor->select); cp_shade_color3ub(cp, -30); } else { - VECCOPY(cp, bcolor->solid); + copy_v3_v3_char((char *)cp, bcolor->solid); cp_shade_color3ub(cp, -30); } diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 41c48a1af58..fed671ade20 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -55,6 +55,7 @@ #include "BLI_utildefines.h" #include "BKE_anim.h" //for the where_on_path function +#include "BKE_camera.h" #include "BKE_constraint.h" // for the get_constraint_target function #include "BKE_curve.h" #include "BKE_DerivedMesh.h" @@ -75,6 +76,8 @@ #include "BKE_pointcache.h" #include "BKE_scene.h" #include "BKE_unit.h" +#include "BKE_movieclip.h" +#include "BKE_tracking.h" #include "smoke_API.h" @@ -104,11 +107,11 @@ /* this condition has been made more complex since editmode can draw textures */ -#define CHECK_OB_DRAWTEXTURE(vd, dt) \ - ((ELEM(vd->drawtype, OB_TEXTURE, OB_MATERIAL) && dt>OB_SOLID) || \ +#define CHECK_OB_DRAWTEXTURE(vd, dt) \ + ((ELEM(vd->drawtype, OB_TEXTURE, OB_MATERIAL) && dt>OB_SOLID) || \ (vd->drawtype==OB_SOLID && vd->flag2 & V3D_SOLID_TEX)) -static void draw_bounding_volume(Scene *scene, Object *ob, short type); +static void draw_bounding_volume(Scene *scene, Object *ob, char type); static void drawcube_size(float size); static void drawcircle_size(float size); @@ -201,6 +204,40 @@ static void view3d_project_short_noclip(ARegion *ar, const float vec[3], short * } } +/* same as view3d_project_short_clip but use persmat instead of persmatob for projection */ +static void view3d_project_short_clip_persmat(ARegion *ar, float *vec, short *adr, int local) +{ + RegionView3D *rv3d= ar->regiondata; + float fx, fy, vec4[4]; + + adr[0]= IS_CLIPPED; + + /* clipplanes in eye space */ + if(rv3d->rflag & RV3D_CLIPPING) { + if(ED_view3d_test_clipping(rv3d, vec, local)) + return; + } + + copy_v3_v3(vec4, vec); + vec4[3]= 1.0; + + mul_m4_v4(rv3d->persmat, vec4); + + /* clipplanes in window space */ + if( vec4[3] > (float)BL_NEAR_CLIP ) { /* is the NEAR clipping cutoff for picking */ + fx= (ar->winx/2)*(1 + vec4[0]/vec4[3]); + + if( fx>0 && fx<ar->winx) { + + fy= (ar->winy/2)*(1 + vec4[1]/vec4[3]); + + if(fy > 0.0f && fy < (float)ar->winy) { + adr[0]= (short)floorf(fx); + adr[1]= (short)floorf(fy); + } + } + } +} /* ************************ */ /* check for glsl drawing */ @@ -734,7 +771,12 @@ void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, int depth_write, floa for(vos= strings->first; vos; vos= vos->next) { if(mat && !(vos->flag & V3D_CACHE_TEXT_WORLDSPACE)) mul_m4_v3(mat, vos->vec); - view3d_project_short_clip(ar, vos->vec, vos->sco, 0); + + if(vos->flag&V3D_CACHE_TEXT_GLOBALSPACE) + view3d_project_short_clip_persmat(ar, vos->vec, vos->sco, 0); + else + view3d_project_short_clip(ar, vos->vec, vos->sco, 0); + if(vos->sco[0]!=IS_CLIPPED) tot++; } @@ -1366,16 +1408,203 @@ float view3d_camera_border_hack_col[4]; short view3d_camera_border_hack_test= FALSE; #endif +/* ****************** draw clip data *************** */ + +static void draw_bundle_sphere(void) +{ + static GLuint displist= 0; + + if (displist == 0) { + GLUquadricObj *qobj; + + displist= glGenLists(1); + glNewList(displist, GL_COMPILE); + + qobj= gluNewQuadric(); + gluQuadricDrawStyle(qobj, GLU_FILL); + glShadeModel(GL_SMOOTH); + gluSphere(qobj, 0.05, 8, 8); + glShadeModel(GL_FLAT); + gluDeleteQuadric(qobj); + + glEndList(); + } + + glCallList(displist); +} + +static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d, MovieClip *clip, int flag) +{ + MovieTracking *tracking= &clip->tracking; + MovieTrackingTrack *track; + float mat[4][4], imat[4][4], curcol[4]; + unsigned char col[4], scol[4]; + int bundlenr= 1; + + if((v3d->flag2&V3D_SHOW_RECONSTRUCTION)==0) + return; + + if(v3d->flag2&V3D_RENDER_OVERRIDE) + return; + + glGetFloatv(GL_CURRENT_COLOR, curcol); + + UI_GetThemeColor4ubv(TH_TEXT, col); + UI_GetThemeColor4ubv(TH_SELECT, scol); + + BKE_get_tracking_mat(scene, base->object, mat); + + glEnable(GL_LIGHTING); + glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); + glEnable(GL_COLOR_MATERIAL); + glShadeModel(GL_SMOOTH); + + /* current ogl matrix is translated in camera space, bundles should + be rendered in world space, so camera matrix should be "removed" + from current ogl matrix */ + invert_m4_m4(imat, base->object->obmat); + + glPushMatrix(); + glMultMatrixf(imat); + glMultMatrixf(mat); + + for ( track= tracking->tracks.first; track; track= track->next) { + int selected= track->flag&SELECT || track->pat_flag&SELECT || track->search_flag&SELECT; + if((track->flag&TRACK_HAS_BUNDLE)==0) + continue; + + if(flag&DRAW_PICKING) + glLoadName(base->selcol + (bundlenr<<16)); + + glPushMatrix(); + glTranslatef(track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]); + glScalef(v3d->bundle_size/0.05, v3d->bundle_size/0.05, v3d->bundle_size/0.05); + + if(v3d->drawtype==OB_WIRE) { + glDisable(GL_LIGHTING); + glDepthMask(0); + + if(selected) { + if(base==BASACT) UI_ThemeColor(TH_ACTIVE); + else UI_ThemeColor(TH_SELECT); + } else { + if(track->flag&TRACK_CUSTOMCOLOR) glColor3fv(track->color); + else UI_ThemeColor(TH_WIRE); + } + + drawaxes(0.05f, v3d->bundle_drawtype); + + glDepthMask(1); + glEnable(GL_LIGHTING); + } else if(v3d->drawtype>OB_WIRE) { + if(v3d->bundle_drawtype==OB_EMPTY_SPHERE) { + /* selection outline */ + if(selected) { + if(base==BASACT) UI_ThemeColor(TH_ACTIVE); + else UI_ThemeColor(TH_SELECT); + + glDepthMask(0); + glLineWidth(2.f); + glDisable(GL_LIGHTING); + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + + draw_bundle_sphere(); + + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glEnable(GL_LIGHTING); + glLineWidth(1.f); + glDepthMask(1); + } + + if(track->flag&TRACK_CUSTOMCOLOR) glColor3fv(track->color); + else UI_ThemeColor(TH_BUNDLE_SOLID); + + draw_bundle_sphere(); + } else { + glDisable(GL_LIGHTING); + glDepthMask(0); + + if(selected) { + if(base==BASACT) UI_ThemeColor(TH_ACTIVE); + else UI_ThemeColor(TH_SELECT); + } else { + if(track->flag&TRACK_CUSTOMCOLOR) glColor3fv(track->color); + else UI_ThemeColor(TH_WIRE); + } + + drawaxes(0.05f, v3d->bundle_drawtype); + + glDepthMask(1); + glEnable(GL_LIGHTING); + } + } + + glPopMatrix(); + + if((flag & DRAW_PICKING)==0 && (v3d->flag2&V3D_SHOW_BUNDLENAME)) { + float pos[3]; + unsigned char tcol[4]; + + if(selected) memcpy(tcol, scol, sizeof(tcol)); + else memcpy(tcol, col, sizeof(tcol)); + + mul_v3_m4v3(pos, mat, track->bundle_pos); + view3d_cached_text_draw_add(pos, track->name, 10, V3D_CACHE_TEXT_GLOBALSPACE, tcol); + } + + bundlenr++; + } + + if((flag & DRAW_PICKING)==0) { + if(v3d->flag2&V3D_SHOW_CAMERAPATH && clip->tracking.reconstruction.camnr) { + int a= 0; + MovieTrackingReconstruction *reconstruction= &tracking->reconstruction; + MovieReconstructedCamera *camera= tracking->reconstruction.cameras; + + glDisable(GL_LIGHTING); + UI_ThemeColor(TH_CAMERA_PATH); + glLineWidth(2.0f); + + glBegin(GL_LINE_STRIP); + for(a= 0; a<reconstruction->camnr; a++, camera++) { + glVertex3f(camera->mat[3][0], camera->mat[3][1], camera->mat[3][2]); + } + glEnd(); + + glLineWidth(1.0f); + glEnable(GL_LIGHTING); + } + } + + glPopMatrix(); + + /* restore */ + glShadeModel(GL_FLAT); + glDisable(GL_COLOR_MATERIAL); + glDisable(GL_LIGHTING); + + glColor4fv(curcol); + + if(flag&DRAW_PICKING) + glLoadName(base->selcol); +} + /* flag similar to draw_object() */ -static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, int flag) +static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int flag) { /* a standing up pyramid with (0,0,0) as top */ Camera *cam; + Object *ob= base->object; float tvec[3]; float vec[4][3], asp[2], shift[2], scale[3]; int i; float drawsize; const short is_view= (rv3d->persp==RV3D_CAMOB && ob==v3d->camera); + MovieClip *clip= object_get_movieclip(scene, base->object, 0); + + /* draw data for movie clip set as active for scene */ + if(clip) + draw_viewport_reconstruction(scene, base, v3d, clip, flag); #ifdef VIEW3D_CAMERA_BORDER_HACK if(is_view && !(G.f & G_PICKSEL)) { @@ -3674,7 +3903,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv totpart=psys->totpart; - cfra= bsystem_time(scene, NULL, (float)CFRA, 0.0f); + cfra= BKE_curframe(scene); if(draw_as==PART_DRAW_PATH && psys->pathcache==NULL && psys->childcache==NULL) draw_as=PART_DRAW_DOT; @@ -4923,7 +5152,7 @@ static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int skip= nu->resolu/16; while (nr-->0) { /* accounts for empty bevel lists */ - float fac= bevp->radius * ts->normalsize; + const float fac= bevp->radius * ts->normalsize; float vec_a[3]; // Offset perpendicular to the curve float vec_b[3]; // Delta along the curve @@ -4939,9 +5168,9 @@ static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, mul_qt_v3(bevp->quat, vec_b); add_v3_v3(vec_a, bevp->vec); add_v3_v3(vec_b, bevp->vec); - - VECSUBFAC(vec_a, vec_a, bevp->dir, fac); - VECSUBFAC(vec_b, vec_b, bevp->dir, fac); + + madd_v3_v3fl(vec_a, bevp->dir, -fac); + madd_v3_v3fl(vec_b, bevp->dir, -fac); glBegin(GL_LINE_STRIP); glVertex3fv(vec_a); @@ -5472,7 +5701,7 @@ static void get_local_bounds(Object *ob, float center[3], float size[3]) } #endif -static void draw_bb_quadric(BoundBox *bb, short type) +static void draw_bb_quadric(BoundBox *bb, char type) { float size[3], cent[3]; GLUquadricObj *qobj = gluNewQuadric(); @@ -5511,7 +5740,7 @@ static void draw_bb_quadric(BoundBox *bb, short type) gluDeleteQuadric(qobj); } -static void draw_bounding_volume(Scene *scene, Object *ob, short type) +static void draw_bounding_volume(Scene *scene, Object *ob, char type) { BoundBox *bb= NULL; @@ -5750,7 +5979,6 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) Object *ob; Curve *cu; RegionView3D *rv3d= ar->regiondata; - //float cfraont; float vec1[3], vec2[3]; unsigned int col=0; int /*sel, drawtype,*/ colindex= 0; @@ -5789,83 +6017,6 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) /* no return after this point, otherwise leaks */ view3d_cached_text_draw_begin(); - - /* draw keys? */ -#if 0 // XXX old animation system - if(base==(scene->basact) || (base->flag & (SELECT+BA_WAS_SEL))) { - if(flag==0 && warning_recursive==0 && ob!=scene->obedit) { - if(ob->ipo && ob->ipo->showkey && (ob->ipoflag & OB_DRAWKEY)) { - ListBase elems; - CfraElem *ce; - float temp[7][3]; - - warning_recursive= 1; - - elems.first= elems.last= 0; - // warning: no longer checks for certain ob-keys only... (so does this need to use the proper ipokeys then?) - make_cfra_list(ob->ipo, &elems); - - cfraont= (scene->r.cfra); - drawtype= v3d->drawtype; - if(drawtype>OB_WIRE) v3d->drawtype= OB_WIRE; - sel= base->flag; - memcpy(temp, &ob->loc, 7*3*sizeof(float)); - - ipoflag= ob->ipoflag; - ob->ipoflag &= ~OB_OFFS_OB; - - set_no_parent_ipo(1); - disable_speed_curve(1); - - if ((ob->ipoflag & OB_DRAWKEYSEL)==0) { - ce= elems.first; - while(ce) { - if(!ce->sel) { - (scene->r.cfra)= ce->cfra/scene->r.framelen; - - base->flag= 0; - - where_is_object_time(scene, ob, (scene->r.cfra)); - draw_object(scene, ar, v3d, base, 0); - } - ce= ce->next; - } - } - - ce= elems.first; - while(ce) { - if(ce->sel) { - (scene->r.cfra)= ce->cfra/scene->r.framelen; - - base->flag= SELECT; - - where_is_object_time(scene, ob, (scene->r.cfra)); - draw_object(scene, ar, v3d, base, 0); - } - ce= ce->next; - } - - set_no_parent_ipo(0); - disable_speed_curve(0); - - base->flag= sel; - ob->ipoflag= ipoflag; - - /* restore icu->curval */ - (scene->r.cfra)= cfraont; - - memcpy(&ob->loc, temp, 7*3*sizeof(float)); - where_is_object(scene, ob); - v3d->drawtype= drawtype; - - BLI_freelistN(&elems); - - warning_recursive= 0; - } - } - } -#endif // XXX old animation system - /* patch? children objects with a timeoffs change the parents. How to solve! */ /* if( ((int)ob->ctime) != F_(scene->r.cfra)) where_is_object(scene, ob); */ @@ -5923,7 +6074,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) if(base->flag & (SELECT+BA_WAS_SEL)) { /* uses darker active color for non-active + selected*/ theme_id= TH_GROUP_ACTIVE; - + if(scene->basact != base) { theme_shade= -16; } @@ -6161,7 +6312,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) break; case OB_CAMERA: if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0 || (rv3d->persp==RV3D_CAMOB && v3d->camera==ob)) /* special exception for active camera */ - drawcamera(scene, v3d, rv3d, ob, flag); + drawcamera(scene, v3d, rv3d, base, flag); break; case OB_SPEAKER: if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) @@ -6512,7 +6663,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) for (ct= targets.first; ct; ct= ct->next) { /* calculate target's matrix */ if (cti->get_target_matrix) - cti->get_target_matrix(curcon, cob, ct, bsystem_time(scene, ob, (float)(scene->r.cfra), give_timeoffset(ob))); + cti->get_target_matrix(curcon, cob, ct, BKE_curframe(scene)); else unit_m4(ct->matrix); diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c index 7c89ce0f689..6605d488d36 100644 --- a/source/blender/editors/space_view3d/drawvolume.c +++ b/source/blender/editors/space_view3d/drawvolume.c @@ -242,7 +242,7 @@ void draw_volume(ARegion *ar, GPUTexture *tex, float *min, float *max, int res[3 tstart(); - VECSUB(size, max, min); + sub_v3_v3v3(size, max, min); // maxx, maxy, maxz cv[0][0] = max[0]; diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index ef806cb8881..c493e4af944 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -250,6 +250,7 @@ static SpaceLink *view3d_new(const bContext *C) v3d->gridflag &= ~V3D_SHOW_Z; v3d->flag |= V3D_SELECT_OUTLINE; + v3d->flag2 |= V3D_SHOW_RECONSTRUCTION; v3d->lens= 35.0f; v3d->near= 0.01f; @@ -259,6 +260,9 @@ static SpaceLink *view3d_new(const bContext *C) v3d->twtype= V3D_MANIP_TRANSLATE; v3d->around= V3D_CENTROID; + v3d->bundle_size= 0.2f; + v3d->bundle_drawtype= OB_PLAINAXES; + /* header */ ar= MEM_callocN(sizeof(ARegion), "header for view3d"); @@ -744,6 +748,10 @@ static void view3d_main_area_listener(ARegion *ar, wmNotifier *wmn) /* same as above */ ED_region_tag_redraw(ar); break; + case NC_MOVIECLIP: + if(wmn->data==ND_DISPLAY) + ED_region_tag_redraw(ar); + break; case NC_SPACE: if(wmn->data == ND_SPACE_VIEW3D) { if (wmn->subtype == NS_VIEW3D_GPU) { @@ -874,6 +882,7 @@ static void view3d_buttons_area_listener(ARegion *ar, wmNotifier *wmn) case ND_MODE: case ND_LAYER: case ND_LAYER_CONTENT: + case ND_TOOLSETTINGS: ED_region_tag_redraw(ar); break; } diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index a8cb436a942..5c8e170dfc7 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -51,6 +51,7 @@ #include "BLI_utildefines.h" #include "BKE_anim.h" +#include "BKE_camera.h" #include "BKE_context.h" #include "BKE_customdata.h" #include "BKE_image.h" @@ -61,6 +62,7 @@ #include "BKE_scene.h" #include "BKE_screen.h" #include "BKE_unit.h" +#include "BKE_movieclip.h" #include "RE_engine.h" #include "RE_pipeline.h" // make_stars @@ -1486,7 +1488,8 @@ static void draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d) RegionView3D *rv3d= ar->regiondata; BGpic *bgpic; Image *ima; - ImBuf *ibuf= NULL; + MovieClip *clip; + ImBuf *ibuf= NULL, *freeibuf; float vec[4], fac, asp, zoomx, zoomy; float x1, y1, x2, y2, cx, cy; @@ -1497,15 +1500,46 @@ static void draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d) (bgpic->view & (1<<rv3d->view)) || /* check agaist flags */ (rv3d->persp==RV3D_CAMOB && bgpic->view == (1<<RV3D_VIEW_CAMERA)) ) { - ima= bgpic->ima; - if(ima==NULL) - continue; - BKE_image_user_calc_frame(&bgpic->iuser, CFRA, 0); - ibuf= BKE_image_get_ibuf(ima, &bgpic->iuser); - if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL) ) + freeibuf= NULL; + if(bgpic->source==V3D_BGPIC_IMAGE) { + ima= bgpic->ima; + if(ima==NULL) + continue; + BKE_image_user_calc_frame(&bgpic->iuser, CFRA, 0); + ibuf= BKE_image_get_ibuf(ima, &bgpic->iuser); + } else { + clip= NULL; + + if(bgpic->flag&V3D_BGPIC_CAMERACLIP) { + if(!scene->camera) + scene->camera= scene_find_camera(scene); + + if(scene->camera) + clip= object_get_movieclip(scene, scene->camera, 1); + } else clip= bgpic->clip; + + if(clip==NULL) + continue; + + BKE_movieclip_user_set_frame(&bgpic->cuser, CFRA); + ibuf= BKE_movieclip_get_ibuf(clip, &bgpic->cuser); + + /* working with ibuf from image and clip has got different workflow now. + ibuf acquired from clip is referenced by cache system and should + be dereferenced after usage. */ + freeibuf= ibuf; + } + + if(ibuf==NULL) continue; - if(ibuf->channels!=4) + + if((ibuf->rect==NULL && ibuf->rect_float==NULL) || ibuf->channels!=4) { /* invalid image format */ + if(freeibuf) + IMB_freeImBuf(freeibuf); + continue; + } + if(ibuf->rect==NULL) IMB_rect_from_float(ibuf); @@ -1544,10 +1578,12 @@ static void draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d) /* complete clip? */ - if(x2 < 0 ) continue; - if(y2 < 0 ) continue; - if(x1 > ar->winx ) continue; - if(y1 > ar->winy ) continue; + if(x2 < 0 || y2 < 0 || x1 > ar->winx || y1 > ar->winy) { + if(freeibuf) + IMB_freeImBuf(freeibuf); + + continue; + } zoomx= (x2-x1)/ibuf->x; zoomy= (y2-y1)/ibuf->y; @@ -1602,6 +1638,9 @@ static void draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d) glDepthMask(1); if(v3d->zbuf) glEnable(GL_DEPTH_TEST); + + if(freeibuf) + IMB_freeImBuf(freeibuf); } } } diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index e7fbdaf1deb..7331959ef51 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -2940,18 +2940,8 @@ void VIEW3D_OT_view_persportho(wmOperatorType *ot) static BGpic *background_image_add(bContext *C) { View3D *v3d= CTX_wm_view3d(C); - - BGpic *bgpic= MEM_callocN(sizeof(BGpic), "Background Image"); - bgpic->size= 5.0; - bgpic->blend= 0.5; - bgpic->iuser.fie_ima= 2; - bgpic->iuser.ok= 1; - bgpic->view= 0; /* 0 for all */ - bgpic->flag |= V3D_BGPIC_EXPANDED; - - BLI_addtail(&v3d->bgpicbase, bgpic); - - return bgpic; + + return ED_view3D_background_image_add(v3d); } static int background_image_add_exec(bContext *C, wmOperator *UNUSED(op)) @@ -3027,7 +3017,8 @@ static int background_image_remove_exec(bContext *C, wmOperator *op) if(bgpic_rem) { BLI_remlink(&vd->bgpicbase, bgpic_rem); - if(bgpic_rem->ima) bgpic_rem->ima->id.us--; + if(bgpic_rem->ima) id_us_min(&bgpic_rem->ima->id); + if(bgpic_rem->clip) id_us_min(&bgpic_rem->clip->id); MEM_freeN(bgpic_rem); WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, vd); return OPERATOR_FINISHED; @@ -3462,8 +3453,8 @@ int ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], cons data.margin= margin; data.depth= FLT_MAX; - VECCOPY2D(p1, mval_sta); - VECCOPY2D(p2, mval_end); + copy_v2_v2_int(p1, mval_sta); + copy_v2_v2_int(p2, mval_end); plot_line_v2v2i(p1, p2, depth_segment_cb, &data); @@ -3534,3 +3525,18 @@ void ED_view3d_to_object(Object *ob, const float ofs[3], const float quat[4], co ED_view3d_to_m4(mat, ofs, quat, dist); object_apply_mat4(ob, mat, TRUE, TRUE); } + +BGpic *ED_view3D_background_image_add(View3D *v3d) +{ + BGpic *bgpic= MEM_callocN(sizeof(BGpic), "Background Image"); + + bgpic->size= 5.0; + bgpic->blend= 0.5; + bgpic->iuser.fie_ima= 2; + bgpic->iuser.ok= 1; + bgpic->view= 0; /* 0 for all */ + + BLI_addtail(&v3d->bgpicbase, bgpic); + + return bgpic; +} diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index e9db9fe1d7e..0cdb7a19995 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -314,7 +314,7 @@ static int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *even fly->timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f); - VECCOPY2D(fly->mval, event->mval) + copy_v2_v2_int(fly->mval, event->mval); fly->ndof = NULL; fly->time_lastdraw= fly->time_lastwheel= PIL_check_seconds_timer(); @@ -475,7 +475,7 @@ static void flyEvent(FlyInfo *fly, wmEvent *event) fly->redraw = 1; } else if (event->type == MOUSEMOVE) { - VECCOPY2D(fly->mval, event->mval); + copy_v2_v2_int(fly->mval, event->mval); } else if (event->type == NDOF_MOTION) { // do these automagically get delivered? yes. diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index fa6611b9925..6eafb10d74c 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -83,9 +83,6 @@ * This can be cleaned when I make some new 'mode' icons. */ -#define TEST_EDITMESH if(obedit==0) return; \ - if( (v3d->lay & obedit->lay)==0 ) return; - /* view3d handler codes */ #define VIEW3D_HANDLER_BACKGROUND 1 #define VIEW3D_HANDLER_PROPERTIES 2 @@ -554,12 +551,9 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) if(obedit==NULL && v3d->localvd==NULL) { unsigned int ob_lay = ob ? ob->lay : 0; - + /* Layers */ - if (v3d->scenelock) - uiTemplateLayers(layout, &sceneptr, "layers", &v3dptr, "layers_used", ob_lay); - else - uiTemplateLayers(layout, &v3dptr, "layers", &v3dptr, "layers_used", ob_lay); + uiTemplateLayers(layout, v3d->scenelock ? &sceneptr : &v3dptr, "layers", &v3dptr, "layers_used", ob_lay); /* Scene lock */ uiItemR(layout, &v3dptr, "lock_camera_and_layers", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index b07d2d1ca73..5aa8d95912d 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -121,6 +121,7 @@ void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, int depth_write, floa #define V3D_CACHE_TEXT_ZBUF (1<<0) #define V3D_CACHE_TEXT_WORLDSPACE (1<<1) #define V3D_CACHE_TEXT_ASCII (1<<2) +#define V3D_CACHE_TEXT_GLOBALSPACE (1<<3) /* drawarmature.c */ int draw_armature(Scene *scene, View3D *v3d, ARegion *ar, Base *base, int dt, int flag, const short is_outline); diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 94d3469dc8c..0163c29c9aa 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -42,6 +42,7 @@ #include "DNA_meshdata_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "DNA_tracking_types.h" #include "MEM_guardedalloc.h" @@ -60,6 +61,9 @@ #include "BKE_context.h" #include "BKE_paint.h" #include "BKE_armature.h" +#include "BKE_movieclip.h" +#include "BKE_object.h" +#include "BKE_tracking.h" #include "BIF_gl.h" @@ -1373,6 +1377,7 @@ static int mouse_select(bContext *C, const int mval[2], short extend, short obce if(hits>0) { int has_bones= 0; + /* note: bundles are handling in the same way as bones */ for(a=0; a<hits; a++) if(buffer[4*a+3] & 0xFFFF0000) has_bones= 1; /* note; shift+alt goes to group-flush-selecting */ @@ -1383,7 +1388,45 @@ static int mouse_select(bContext *C, const int mval[2], short extend, short obce } if(has_bones && basact) { - if(ED_do_pose_selectbuffer(scene, basact, buffer, hits, extend) ) { /* then bone is found */ + if(basact->object->type==OB_CAMERA) { + if(BASACT==basact) { + int i, hitresult; + MovieTrackingTrack *track; + + for (i=0; i< hits; i++) { + hitresult= buffer[3+(i*4)]; + + /* if there's bundles in buffer select bundles first, + so non-camera elements should be ignored in buffer */ + if(basact->selcol != (hitresult & 0xFFFF)) + continue; + + /* index of bundle is 1<<16-based. if there's no "bone" index + in hight word, this buffer value belongs to camera,. not to bundle */ + if(buffer[4*i+3] & 0xFFFF0000) { + MovieClip *clip= object_get_movieclip(scene, basact->object, 0); + int selected; + track= BKE_tracking_indexed_track(&clip->tracking, hitresult >> 16); + + selected= (track->flag&SELECT) || (track->pat_flag&SELECT) || (track->search_flag&SELECT); + + if(selected && extend) BKE_tracking_deselect_track(track, TRACK_AREA_ALL); + else BKE_tracking_select_track(&clip->tracking, track, TRACK_AREA_ALL, extend); + + basact->flag|= SELECT; + basact->object->flag= basact->flag; + + retval= 1; + + WM_event_add_notifier(C, NC_MOVIECLIP|ND_SELECT, track); + WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene); + + break; + } + } + } + } + else if(ED_do_pose_selectbuffer(scene, basact, buffer, hits, extend) ) { /* then bone is found */ /* we make the armature selected: not-selected active object in posemode won't work well for tools */ diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index 1b726cd90b3..012e08f98cb 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -55,6 +55,7 @@ #include "BKE_lattice.h" #include "BKE_main.h" #include "BKE_object.h" +#include "BKE_tracking.h" #include "WM_api.h" #include "WM_types.h" @@ -753,6 +754,37 @@ void VIEW3D_OT_snap_cursor_to_grid(wmOperatorType *ot) /* **************************************************** */ +static void bundle_midpoint(Scene *scene, Object *ob, float vec[3]) +{ + MovieTrackingTrack *track; + MovieClip *clip= object_get_movieclip(scene, ob, 0); + int ok= 0; + float min[3], max[3], mat[4][4], pos[3]; + + if(!clip) + return; + + BKE_get_tracking_mat(scene, ob, mat); + + INIT_MINMAX(min, max); + + track= clip->tracking.tracks.first; + while(track) { + int selected= (track->flag&SELECT) || (track->pat_flag&SELECT) || (track->search_flag&SELECT); + if((track->flag&TRACK_HAS_BUNDLE) && selected) { + ok= 1; + mul_v3_m4v3(pos, mat, track->bundle_pos); + DO_MINMAX(pos, min, max); + } + + track= track->next; + } + + if(ok) { + interp_v3_v3v3(vec, min, max, 0.5); + } +} + static int snap_curs_to_sel(bContext *C, wmOperator *UNUSED(op)) { Object *obedit= CTX_data_edit_object(C); @@ -817,6 +849,15 @@ static int snap_curs_to_sel(bContext *C, wmOperator *UNUSED(op)) else { CTX_DATA_BEGIN(C, Object*, ob, selected_objects) { copy_v3_v3(vec, ob->obmat[3]); + + /* special case for camera -- snap to bundles */ + if(ob->type==OB_CAMERA) { + /* snap to bundles should happen only when bundles are visible */ + if(v3d->flag2&V3D_SHOW_RECONSTRUCTION) { + bundle_midpoint(scene, ob, vec); + } + } + add_v3_v3(centroid, vec); DO_MINMAX(vec, min, max); count++; |