1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software Foundation,
14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 *
16 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17 * All rights reserved.
18 */
19
20 /** \file
21 * \ingroup edtransform
22 */
23
24 #include "MEM_guardedalloc.h"
25
26 #include "BLI_math.h"
27
28 #include "BKE_context.h"
29 #include "BKE_paint.h"
30 #include "BKE_report.h"
31
32 #include "ED_sculpt.h"
33
34 #include "transform.h"
35 #include "transform_convert.h"
36
37 /* -------------------------------------------------------------------- */
38 /** \name Sculpt Transform Creation
39 *
40 * \{ */
41
createTransSculpt(bContext * C,TransInfo * t)42 void createTransSculpt(bContext *C, TransInfo *t)
43 {
44 TransData *td;
45
46 Scene *scene = t->scene;
47 if (ID_IS_LINKED(scene)) {
48 BKE_report(t->reports, RPT_ERROR, "Linked data can't text-space transform");
49 return;
50 }
51
52 Object *ob = CTX_data_active_object(t->context);
53 SculptSession *ss = ob->sculpt;
54
55 {
56 BLI_assert(t->data_container_len == 1);
57 TransDataContainer *tc = t->data_container;
58 tc->data_len = 1;
59 tc->is_active = 1;
60 td = tc->data = MEM_callocN(sizeof(TransData), "TransSculpt");
61 td->ext = tc->data_ext = MEM_callocN(sizeof(TransDataExtension), "TransSculpt");
62 }
63
64 td->flag = TD_SELECTED;
65 copy_v3_v3(td->center, ss->pivot_pos);
66 mul_m4_v3(ob->obmat, td->center);
67 td->ob = ob;
68
69 td->loc = ss->pivot_pos;
70 copy_v3_v3(td->iloc, ss->pivot_pos);
71
72 if (is_zero_v4(ss->pivot_rot)) {
73 ss->pivot_rot[3] = 1.0f;
74 }
75
76 float obmat_inv[3][3];
77 copy_m3_m4(obmat_inv, ob->obmat);
78 invert_m3(obmat_inv);
79
80 td->ext->rot = NULL;
81 td->ext->rotAxis = NULL;
82 td->ext->rotAngle = NULL;
83 td->ext->quat = ss->pivot_rot;
84 copy_m4_m4(td->ext->obmat, ob->obmat);
85 copy_m3_m3(td->ext->l_smtx, obmat_inv);
86 copy_m3_m4(td->ext->r_mtx, ob->obmat);
87 copy_m3_m3(td->ext->r_smtx, obmat_inv);
88
89 copy_qt_qt(td->ext->iquat, ss->pivot_rot);
90 td->ext->rotOrder = ROT_MODE_QUAT;
91
92 ss->pivot_scale[0] = 1.0f;
93 ss->pivot_scale[1] = 1.0f;
94 ss->pivot_scale[2] = 1.0f;
95 td->ext->size = ss->pivot_scale;
96 copy_v3_v3(ss->init_pivot_scale, ss->pivot_scale);
97 copy_v3_v3(td->ext->isize, ss->init_pivot_scale);
98
99 copy_m3_m3(td->smtx, obmat_inv);
100 copy_m3_m4(td->mtx, ob->obmat);
101 copy_m3_m4(td->axismtx, ob->obmat);
102
103 BLI_assert(!(t->options & CTX_PAINT_CURVE));
104 ED_sculpt_init_transform(C);
105 }
106
107 /** \} */
108
109 /* -------------------------------------------------------------------- */
110 /** \name Recalc Data object
111 *
112 * \{ */
113
recalcData_sculpt(TransInfo * t)114 void recalcData_sculpt(TransInfo *t)
115 {
116 ED_sculpt_update_modal_transform(t->context);
117 }
118
special_aftertrans_update__sculpt(bContext * C,TransInfo * t)119 void special_aftertrans_update__sculpt(bContext *C, TransInfo *t)
120 {
121 Scene *scene = t->scene;
122 if (ID_IS_LINKED(scene)) {
123 /* `ED_sculpt_init_transform` was not called in this case. */
124 return;
125 }
126
127 BLI_assert(!(t->options & CTX_PAINT_CURVE));
128 ED_sculpt_end_transform(C);
129 }
130
131 /** \} */
132