diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-08-06 12:47:25 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-08-06 12:50:09 +0300 |
commit | 459365443f62d2f8e8718c1d1b0fbaafd6d765de (patch) | |
tree | 2a2235cacdf240b99135aa3f6b1831cec4d5c2bc /source/blender/editors/space_view3d/view3d_manipulator_lamp.c | |
parent | 48adef4444a8276ce1d89b122346ae0426493574 (diff) |
Manipulator: experimental lamp positioning tool
- New manipulator tracks lamps to position under cursor.
- Works with multiple lamps, keeping relative offsets.
- Holding Ctrl moves the lamp.
- Access via manipulator or Shift-T.
Code could be improved, but like to get feedback from users.
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_manipulator_lamp.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_manipulator_lamp.c | 72 |
1 files changed, 68 insertions, 4 deletions
diff --git a/source/blender/editors/space_view3d/view3d_manipulator_lamp.c b/source/blender/editors/space_view3d/view3d_manipulator_lamp.c index 451addaaeae..4b550fd0b2e 100644 --- a/source/blender/editors/space_view3d/view3d_manipulator_lamp.c +++ b/source/blender/editors/space_view3d/view3d_manipulator_lamp.c @@ -50,8 +50,6 @@ /** \name Spot Lamp Manipulators * \{ */ -/* Spot Lamp */ - static bool WIDGETGROUP_lamp_spot_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt)) { Object *ob = CTX_data_active_object(C); @@ -122,8 +120,6 @@ void VIEW3D_WGT_lamp_spot(wmManipulatorGroupType *wgt) /** \name Area Lamp Manipulators * \{ */ -/* Area Lamp */ - /* translate callbacks */ static void manipulator_area_lamp_prop_size_get( const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop, @@ -231,3 +227,71 @@ void VIEW3D_WGT_lamp_area(wmManipulatorGroupType *wgt) } /** \} */ + + +/* -------------------------------------------------------------------- */ + +/** \name Lamp Target Manipulator + * \{ */ + +static bool WIDGETGROUP_lamp_target_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt)) +{ + Object *ob = CTX_data_active_object(C); + + if (ob != NULL) { + if (ob->type == OB_LAMP) { + Lamp *la = ob->data; + return (ELEM(la->type, LA_SUN, LA_SPOT, LA_HEMI, LA_AREA)); + } + else if (ob->type == OB_CAMERA) { + return true; + } + } + return false; +} + +static void WIDGETGROUP_lamp_target_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup) +{ + const float color[4] = {1.0f, 1.0f, 0.5f, 1.0f}; + const float color_hi[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + + wmManipulatorWrapper *wwrapper = MEM_mallocN(sizeof(wmManipulatorWrapper), __func__); + wwrapper->manipulator = WM_manipulator_new("MANIPULATOR_WT_grab_3d", mgroup, NULL); + wmManipulator *mpr = wwrapper->manipulator; + + mgroup->customdata = wwrapper; + + WM_manipulator_set_color(mpr, color); + WM_manipulator_set_color_highlight(mpr, color_hi); + + mpr->scale_basis = 0.05f; + + wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_transform_axis_target", true); + WM_manipulator_set_operator(mpr, ot, NULL); +} + +static void WIDGETGROUP_lamp_target_draw_prepare(const bContext *C, wmManipulatorGroup *mgroup) +{ + wmManipulatorWrapper *wwrapper = mgroup->customdata; + Object *ob = CTX_data_active_object(C); + wmManipulator *mpr = wwrapper->manipulator; + + copy_m4_m4(mpr->matrix_basis, ob->obmat); + unit_m4(mpr->matrix_offset); + mpr->matrix_offset[3][2] = -2.4f / mpr->scale_basis; +} + +void VIEW3D_WGT_lamp_target(wmManipulatorGroupType *wgt) +{ + wgt->name = "Target Lamp Widgets"; + wgt->idname = "VIEW3D_WGT_lamp_target"; + + wgt->flag |= (WM_MANIPULATORGROUPTYPE_PERSISTENT | + WM_MANIPULATORGROUPTYPE_3D); + + wgt->poll = WIDGETGROUP_lamp_target_poll; + wgt->setup = WIDGETGROUP_lamp_target_setup; + wgt->draw_prepare = WIDGETGROUP_lamp_target_draw_prepare; +} + +/** \} */
\ No newline at end of file |