diff options
author | Pablo Dobarro <pablodp606@gmail.com> | 2019-09-10 20:55:15 +0300 |
---|---|---|
committer | Pablo Dobarro <pablodp606@gmail.com> | 2019-09-11 14:07:19 +0300 |
commit | 309cd047ef46fcbd21b26b2509b40c55c5dab61e (patch) | |
tree | ec1873a13b391026bffc0110d84aafc855b648df /source/blender/editors/transform | |
parent | ef18b672f5a57d86d264af0f875a37c6a9c6677a (diff) |
Sculpt: Transform tool
The sculpt mode transform tool applies the sculpt pivot transformation to all vertices, taking XYZ symmetry into account.
This commit also includes an operator to set the pivot point initial position.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D5717
Diffstat (limited to 'source/blender/editors/transform')
7 files changed, 146 insertions, 1 deletions
diff --git a/source/blender/editors/transform/CMakeLists.txt b/source/blender/editors/transform/CMakeLists.txt index 210cc5cbca7..e3ff8b92081 100644 --- a/source/blender/editors/transform/CMakeLists.txt +++ b/source/blender/editors/transform/CMakeLists.txt @@ -56,6 +56,7 @@ set(SRC transform_convert_object.c transform_convert_paintcurve.c transform_convert_particle.c + transform_convert_sculpt.c transform_convert_sequencer.c transform_convert_tracking.c transform_generics.c diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 019db4f74fa..d3b331faca9 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -79,6 +79,7 @@ #include "ED_clip.h" #include "ED_node.h" #include "ED_gpencil.h" +#include "ED_sculpt.h" #include "WM_types.h" #include "WM_api.h" @@ -2299,6 +2300,10 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op) } } + if (t->options & CTX_SCULPT) { + ED_sculpt_end_transform(C); + } + if ((prop = RNA_struct_find_property(op->ptr, "correct_uv"))) { RNA_property_boolean_set( op->ptr, prop, (t->settings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) != 0); @@ -2342,6 +2347,11 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve } } + Object *ob = CTX_data_active_object(C); + if (ob && ob->mode == OB_MODE_SCULPT && ob->sculpt) { + options |= CTX_SCULPT; + } + t->options = options; t->mode = mode; @@ -2404,6 +2414,10 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve createTransData(C, t); // make TransData structs from selection + if (t->options & CTX_SCULPT) { + ED_sculpt_init_transform(C); + } + if (t->data_len_all == 0) { postTrans(C, t); return 0; diff --git a/source/blender/editors/transform/transform_convert.c b/source/blender/editors/transform/transform_convert.c index 6da03d917a6..dfdd7b71332 100644 --- a/source/blender/editors/transform/transform_convert.c +++ b/source/blender/editors/transform/transform_convert.c @@ -2264,6 +2264,9 @@ void special_aftertrans_update(bContext *C, TransInfo *t) else if (t->options & CTX_PAINT_CURVE) { /* pass */ } + else if (t->options & CTX_SCULPT) { + /* pass */ + } else if ((t->view_layer->basact) && (ob = t->view_layer->basact->object) && (ob->mode & OB_MODE_PARTICLE_EDIT) && PE_get_current(t->scene, ob)) { /* do nothing */ @@ -2414,6 +2417,10 @@ void createTransData(bContext *C, TransInfo *t) } countAndCleanTransDataContainer(t); } + else if (t->options & CTX_SCULPT) { + createTransSculpt(t); + countAndCleanTransDataContainer(t); + } else if (t->options & CTX_TEXTURE) { t->flag |= T_TEXTURE; t->obedit_type = -1; diff --git a/source/blender/editors/transform/transform_convert.h b/source/blender/editors/transform/transform_convert.h index ee6f181a133..02ad4688ab6 100644 --- a/source/blender/editors/transform/transform_convert.h +++ b/source/blender/editors/transform/transform_convert.h @@ -129,6 +129,8 @@ void createTransTexspace(TransInfo *t); void createTransPaintCurveVerts(bContext *C, TransInfo *t); /* transform_convert_particle.c */ void createTransParticleVerts(bContext *C, TransInfo *t); +/* transform_convert_sculpt.c */ +void createTransSculpt(TransInfo *t); /* transform_convert_sequence.c */ void createTransSeqData(bContext *C, TransInfo *t); /* transform_convert_tracking.c */ diff --git a/source/blender/editors/transform/transform_convert_sculpt.c b/source/blender/editors/transform/transform_convert_sculpt.c new file mode 100644 index 00000000000..b02ad71da07 --- /dev/null +++ b/source/blender/editors/transform/transform_convert_sculpt.c @@ -0,0 +1,101 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + */ + +/** \file + * \ingroup edtransform + */ + +#include "DNA_space_types.h" + +#include "MEM_guardedalloc.h" + +#include "BLI_math.h" + +#include "BKE_context.h" +#include "BKE_report.h" +#include "BKE_scene.h" +#include "BKE_paint.h" + +#include "transform.h" +#include "transform_convert.h" + +/* -------------------------------------------------------------------- */ +/** \name Sculpt Transform Creation + * + * \{ */ + +void createTransSculpt(TransInfo *t) +{ + TransData *td; + + Scene *scene = t->scene; + if (ID_IS_LINKED(scene)) { + BKE_report(t->reports, RPT_ERROR, "Linked data can't text-space transform"); + return; + } + + Object *ob = CTX_data_active_object(t->context); + SculptSession *ss = ob->sculpt; + + { + BLI_assert(t->data_container_len == 1); + TransDataContainer *tc = t->data_container; + tc->data_len = 1; + tc->is_active = 1; + td = tc->data = MEM_callocN(sizeof(TransData), "TransTexspace"); + td->ext = tc->data_ext = MEM_callocN(sizeof(TransDataExtension), "TransTexspace"); + } + + td->flag = TD_SELECTED; + copy_v3_v3(td->center, ss->pivot_pos); + td->ob = NULL; + + float tquat[4]; + normalize_qt_qt(tquat, ss->pivot_rot); + quat_to_mat3(td->axismtx, tquat); + + td->loc = ss->pivot_pos; + copy_v3_v3(td->iloc, ss->pivot_pos); + + if (is_zero_v4(ss->pivot_rot)) { + ss->pivot_rot[3] = 1.0f; + } + + td->ext->rot = NULL; + td->ext->rotAxis = NULL; + td->ext->rotAngle = NULL; + td->ext->quat = ss->pivot_rot; + + copy_qt_qt(td->ext->iquat, ss->pivot_rot); + td->ext->rotOrder = ROT_MODE_QUAT; + + ss->pivot_scale[0] = 1.0f; + ss->pivot_scale[1] = 1.0f; + ss->pivot_scale[2] = 1.0f; + td->ext->size = ss->pivot_scale; + copy_v3_v3(td->ext->isize, ss->pivot_scale); + + float obmat_inv[3][3]; + copy_m3_m4(obmat_inv, ob->obmat); + invert_m3(obmat_inv); + copy_m3_m3(td->smtx, obmat_inv); + copy_m3_m4(td->mtx, ob->obmat); +} + +/** \} */ diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index c4da7780a22..32d8c7381e7 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -99,6 +99,7 @@ #include "ED_clip.h" #include "ED_screen.h" #include "ED_gpencil.h" +#include "ED_sculpt.h" #include "WM_types.h" #include "WM_api.h" @@ -1206,6 +1207,11 @@ static void recalcData_gpencil_strokes(TransInfo *t) } } +static void recalcData_sculpt(TransInfo *t) +{ + ED_sculpt_update_modal_transform(t->context); +} + /* called for updating while transform acts, once per redraw */ void recalcData(TransInfo *t) { @@ -1226,6 +1232,9 @@ void recalcData(TransInfo *t) /* set recalc triangle cache flag */ recalcData_gpencil_strokes(t); } + if (t->options & CTX_SCULPT) { + recalcData_sculpt(t); + } else if (t->spacetype == SPACE_IMAGE) { recalcData_image(t); } diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c index 64fdbe5f8b1..bd8cf047db7 100644 --- a/source/blender/editors/transform/transform_gizmo_3d.c +++ b/source/blender/editors/transform/transform_gizmo_3d.c @@ -55,6 +55,7 @@ #include "BKE_scene.h" #include "BKE_workspace.h" #include "BKE_object.h" +#include "BKE_paint.h" #include "DEG_depsgraph.h" @@ -1056,7 +1057,13 @@ int ED_transform_calc_gizmo_stats(const bContext *C, } } else if (ob && (ob->mode & OB_MODE_ALL_PAINT)) { - /* pass */ + if (ob->mode & OB_MODE_SCULPT) { + totsel = 1; + calc_tw_center_with_matrix(tbounds, ob->sculpt->pivot_pos, false, ob->obmat); + mul_m4_v3(ob->obmat, tbounds->center); + mul_m4_v3(ob->obmat, tbounds->min); + mul_m4_v3(ob->obmat, tbounds->max); + } } else if (ob && ob->mode & OB_MODE_PARTICLE_EDIT) { PTCacheEdit *edit = PE_get_current(scene, ob); @@ -1168,6 +1175,10 @@ static void gizmo_prepare_mat(const bContext *C, if (gpd && (gpd->flag & GP_DATA_STROKE_EDITMODE)) { /* pass */ } + else if (ob->sculpt) { + SculptSession *ss = ob->sculpt; + copy_v3_v3(rv3d->twmat[3], ss->pivot_pos); + } else if (ob != NULL) { ED_object_calc_active_center(ob, false, rv3d->twmat[3]); } |