diff options
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r-- | source/blender/editors/space_view3d/drawobject.c | 30 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 8 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 26 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_intern.h | 3 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_ops.c | 3 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 55 |
6 files changed, 86 insertions, 39 deletions
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 58f41b63b66..44bacd7a20e 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -2819,28 +2819,34 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object if(dt>OB_WIRE) { if(CHECK_OB_DRAWTEXTURE(v3d, dt)) { if(draw_glsl_material(scene, ob, v3d, dt)) { - glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW); + /* if em has no faces the drawMappedFaces callback will fail */ + if(em->bm->totface) { + glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW); - finalDM->drawMappedFacesGLSL(finalDM, GPU_enable_material, - draw_em_fancy__setGLSLFaceOpts, em); - GPU_disable_material(); + finalDM->drawMappedFacesGLSL(finalDM, GPU_enable_material, + draw_em_fancy__setGLSLFaceOpts, em); + GPU_disable_material(); - glFrontFace(GL_CCW); + glFrontFace(GL_CCW); + } } else { draw_mesh_textured(scene, v3d, rv3d, ob, finalDM, 0); } } else { - /* 3 floats for position, 3 for normal and times two because the faces may actually be quads instead of triangles */ - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, me->flag & ME_TWOSIDED); + /* if em has no faces the drawMappedFaces callback will fail */ + if(em->bm->totface) { + /* 3 floats for position, 3 for normal and times two because the faces may actually be quads instead of triangles */ + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, me->flag & ME_TWOSIDED); - glEnable(GL_LIGHTING); - glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW); - finalDM->drawMappedFaces(finalDM, draw_em_fancy__setFaceOpts, me->edit_btmesh, 0, GPU_enable_material, NULL); + glEnable(GL_LIGHTING); + glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW); + finalDM->drawMappedFaces(finalDM, draw_em_fancy__setFaceOpts, me->edit_btmesh, 0, GPU_enable_material, NULL); - glFrontFace(GL_CCW); - glDisable(GL_LIGHTING); + glFrontFace(GL_CCW); + glDisable(GL_LIGHTING); + } } // Setup for drawing wire over, disable zbuffer diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index edcaed43de6..7ce758d4f47 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -2878,6 +2878,10 @@ static void view3d_main_area_draw_info(const bContext *C, ARegion *ar, const cha else draw_view_icon(rv3d); + ob= OBACT; + if(U.uiflag & USER_DRAWVIEWINFO) + draw_selected_name(scene, ob); + if(rv3d->render_engine) { view3d_main_area_draw_engine_info(rv3d, ar); return; @@ -2899,10 +2903,6 @@ static void view3d_main_area_draw_info(const bContext *C, ARegion *ar, const cha BLF_draw_default_ascii(22, ar->winy-(USER_SHOW_VIEWPORTNAME?40:20), 0.0f, tstr[0]?tstr : grid_unit, sizeof(tstr)); /* XXX, use real length */ } - - ob= OBACT; - if(U.uiflag & USER_DRAWVIEWINFO) - draw_selected_name(scene, ob); } void view3d_main_area_draw(const bContext *C, ARegion *ar) diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 0329b6c3739..7eaa5d42dd0 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -1031,21 +1031,17 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event rv3d->view = RV3D_VIEW_USER; if (U.flag & USER_TRACKBALL) { - const int invert_roll = U.ndof_flag & NDOF_ROLL_INVERT_AXIS; - const int invert_tilt = U.ndof_flag & NDOF_TILT_INVERT_AXIS; - const int invert_rot = U.ndof_flag & NDOF_ROTATE_INVERT_AXIS; - float rot[4]; float axis[3]; float angle = rot_sensitivity * ndof_to_axis_angle(ndof, axis); - if (invert_roll) + if (U.ndof_flag & NDOF_ROLL_INVERT_AXIS) axis[2] = -axis[2]; - if (invert_tilt) + if (U.ndof_flag & NDOF_TILT_INVERT_AXIS) axis[0] = -axis[0]; - if (invert_rot) + if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS) axis[1] = -axis[1]; // transform rotation axis from view to world coordinates @@ -1061,8 +1057,6 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); } else { /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */ - const int invert = U.ndof_flag & NDOF_ORBIT_INVERT_AXES; - float angle, rot[4]; float xvec[3] = {1,0,0}; @@ -1071,7 +1065,7 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event /* Perform the up/down rotation */ angle = rot_sensitivity * dt * ndof->rvec[0]; - if (invert) + if (U.ndof_flag & NDOF_TILT_INVERT_AXIS) angle = -angle; rot[0] = cos(angle); mul_v3_v3fl(rot+1, xvec, sin(angle)); @@ -1079,7 +1073,7 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event /* Perform the orbital rotation */ angle = rot_sensitivity * dt * ndof->rvec[1]; - if (invert) + if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS) angle = -angle; // update the onscreen doo-dad @@ -1164,23 +1158,19 @@ static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) const float vertical_sensitivity = 0.4f; const float lateral_sensitivity = 0.6f; - const int invert_panx = U.ndof_flag & NDOF_PANX_INVERT_AXIS; - const int invert_pany = U.ndof_flag & NDOF_PANY_INVERT_AXIS; - const int invert_panz = U.ndof_flag & NDOF_PANZ_INVERT_AXIS; - float pan_vec[3]; - if (invert_panx) + if (U.ndof_flag & NDOF_PANX_INVERT_AXIS) pan_vec[0] = -lateral_sensitivity * ndof->tvec[0]; else pan_vec[0] = lateral_sensitivity * ndof->tvec[0]; - if (invert_panz) + if (U.ndof_flag & NDOF_PANZ_INVERT_AXIS) pan_vec[1] = -vertical_sensitivity * ndof->tvec[1]; else pan_vec[1] = vertical_sensitivity * ndof->tvec[1]; - if (invert_pany) + if (U.ndof_flag & NDOF_PANY_INVERT_AXIS) pan_vec[2] = -forward_sensitivity * ndof->tvec[2]; else pan_vec[2] = forward_sensitivity * ndof->tvec[2]; diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index fa2d5db21df..775cb45066a 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -155,7 +155,8 @@ void VIEW3D_OT_select_border(struct wmOperatorType *ot); void VIEW3D_OT_select_lasso(struct wmOperatorType *ot); void VIEW3D_OT_smoothview(struct wmOperatorType *ot); -void VIEW3D_OT_setcameratoview(struct wmOperatorType *ot); +void VIEW3D_OT_camera_to_view(struct wmOperatorType *ot); +void VIEW3D_OT_camera_to_view_selected(struct wmOperatorType *ot); void VIEW3D_OT_object_as_camera(struct wmOperatorType *ot); void VIEW3D_OT_localview(struct wmOperatorType *ot); void VIEW3D_OT_game_start(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c index 6e26fb15873..aeb850243c5 100644 --- a/source/blender/editors/space_view3d/view3d_ops.c +++ b/source/blender/editors/space_view3d/view3d_ops.c @@ -85,7 +85,8 @@ void view3d_operatortypes(void) WM_operatortype_append(VIEW3D_OT_enable_manipulator); WM_operatortype_append(VIEW3D_OT_cursor3d); WM_operatortype_append(VIEW3D_OT_select_lasso); - WM_operatortype_append(VIEW3D_OT_setcameratoview); + WM_operatortype_append(VIEW3D_OT_camera_to_view); + WM_operatortype_append(VIEW3D_OT_camera_to_view_selected); WM_operatortype_append(VIEW3D_OT_object_as_camera); WM_operatortype_append(VIEW3D_OT_localview); WM_operatortype_append(VIEW3D_OT_game_start); diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index ca03ee56260..1b4b26aeaaa 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -43,6 +43,7 @@ #include "BKE_anim.h" #include "BKE_action.h" +#include "BKE_camera.h" #include "BKE_context.h" #include "BKE_depsgraph.h" #include "BKE_object.h" @@ -406,9 +407,8 @@ static int view3d_setcameratoview_poll(bContext *C) return 0; } -void VIEW3D_OT_setcameratoview(wmOperatorType *ot) +void VIEW3D_OT_camera_to_view(wmOperatorType *ot) { - /* identifiers */ ot->name= "Align Camera To View"; ot->description= "Set camera view to active view"; @@ -422,6 +422,55 @@ void VIEW3D_OT_setcameratoview(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +/* unlike VIEW3D_OT_view_selected this is for framing a render and not + * meant to take into account vertex/bone selection for eg. */ +static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Scene *scene= CTX_data_scene(C); + View3D *v3d = CTX_wm_view3d(C); + Object *camera_ob= v3d->camera; + + float r_co[3]; /* the new location to apply */ + + /* this function does all the important stuff */ + if (camera_view_frame_fit_to_scene(scene, v3d, camera_ob, r_co)) { + + ObjectTfmProtectedChannels obtfm; + float obmat_new[4][4]; + + copy_m4_m4(obmat_new, camera_ob->obmat); + copy_v3_v3(obmat_new[3], r_co); + + /* only touch location */ + object_tfm_protected_backup(camera_ob, &obtfm); + object_apply_mat4(camera_ob, obmat_new, TRUE, TRUE); + object_tfm_protected_restore(camera_ob, &obtfm, OB_LOCK_SCALE | OB_LOCK_ROT4D); + + /* notifiers */ + DAG_id_tag_update(&camera_ob->id, OB_RECALC_OB); + WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, camera_ob); + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } +} + +void VIEW3D_OT_camera_to_view_selected(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Camera Fit Frame to Selected"; + ot->description= "Move the camera so selected objects are framed"; + ot->idname= "VIEW3D_OT_camera_to_view_selected"; + + /* api callbacks */ + ot->exec= view3d_camera_to_view_selected_exec; + // ot->poll= view3d_setcameratoview_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + static int view3d_setobjectascamera_exec(bContext *C, wmOperator *UNUSED(op)) { @@ -461,7 +510,7 @@ void VIEW3D_OT_object_as_camera(wmOperatorType *ot) ot->idname= "VIEW3D_OT_object_as_camera"; /* api callbacks */ - ot->exec= view3d_setobjectascamera_exec; + ot->exec= view3d_setobjectascamera_exec; ot->poll= ED_operator_rv3d_unlock_poll; /* flags */ |