4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
30 /** \file blender/editors/transform/transform.c
31 * \ingroup edtransform
47 #include "MEM_guardedalloc.h"
49 #include "DNA_anim_types.h"
50 #include "DNA_armature_types.h"
51 #include "DNA_constraint_types.h"
52 #include "DNA_meshdata_types.h"
53 #include "DNA_scene_types.h" /* PET modes */
55 #include "RNA_access.h"
58 #include "BIF_glutil.h"
61 #include "BKE_bmesh.h"
62 #include "BKE_context.h"
63 #include "BKE_constraint.h"
64 #include "BKE_global.h"
65 #include "BKE_particle.h"
66 #include "BKE_pointcache.h"
70 #include "ED_keyframing.h"
71 #include "ED_screen.h"
72 #include "ED_space_api.h"
73 #include "ED_markers.h"
74 #include "ED_view3d.h"
77 #include "UI_view2d.h"
82 #include "BLI_blenlib.h"
83 #include "BLI_utildefines.h"
84 #include "BLI_editVert.h"
85 #include "BLI_ghash.h"
86 #include "BLI_linklist.h"
88 #include "UI_resources.h"
90 //#include "blendef.h"
92 //#include "mydevice.h"
94 #include "transform.h"
96 void drawTransformApply(const struct bContext *C, struct ARegion *ar, void *arg);
97 int doEdgeSlide(TransInfo *t, float perc);
99 /* ************************** SPACE DEPENDANT CODE **************************** */
101 void setTransformViewMatrices(TransInfo *t)
103 if(t->spacetype==SPACE_VIEW3D && t->ar && t->ar->regiontype == RGN_TYPE_WINDOW) {
104 RegionView3D *rv3d = t->ar->regiondata;
106 copy_m4_m4(t->viewmat, rv3d->viewmat);
107 copy_m4_m4(t->viewinv, rv3d->viewinv);
108 copy_m4_m4(t->persmat, rv3d->persmat);
109 copy_m4_m4(t->persinv, rv3d->persinv);
110 t->persp = rv3d->persp;
117 t->persp = RV3D_ORTHO;
120 calculateCenter2D(t);
123 void convertViewVec(TransInfo *t, float *vec, int dx, int dy)
125 if (t->spacetype==SPACE_VIEW3D) {
126 if (t->ar->regiontype == RGN_TYPE_WINDOW) {
130 ED_view3d_win_to_delta(t->ar, mval_f, vec);
133 else if(t->spacetype==SPACE_IMAGE) {
134 View2D *v2d = t->view;
135 float divx, divy, aspx, aspy;
137 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
139 divx= v2d->mask.xmax-v2d->mask.xmin;
140 divy= v2d->mask.ymax-v2d->mask.ymin;
142 vec[0]= aspx*(v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
143 vec[1]= aspy*(v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
146 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
147 View2D *v2d = t->view;
150 divx= v2d->mask.xmax-v2d->mask.xmin;
151 divy= v2d->mask.ymax-v2d->mask.ymin;
153 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx) / (divx);
154 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy) / (divy);
157 else if(t->spacetype==SPACE_NODE) {
158 View2D *v2d = &t->ar->v2d;
161 divx= v2d->mask.xmax-v2d->mask.xmin;
162 divy= v2d->mask.ymax-v2d->mask.ymin;
164 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
165 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
168 else if(t->spacetype==SPACE_SEQ) {
169 View2D *v2d = &t->ar->v2d;
172 divx= v2d->mask.xmax-v2d->mask.xmin;
173 divy= v2d->mask.ymax-v2d->mask.ymin;
175 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
176 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
181 void projectIntView(TransInfo *t, float *vec, int *adr)
183 if (t->spacetype==SPACE_VIEW3D) {
184 if(t->ar->regiontype == RGN_TYPE_WINDOW)
185 project_int_noclip(t->ar, vec, adr);
187 else if(t->spacetype==SPACE_IMAGE) {
188 float aspx, aspy, v[2];
190 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
194 UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr+1);
196 else if(t->spacetype == SPACE_ACTION) {
199 SpaceAction *sact = t->sa->spacedata.first;
201 if (sact->flag & SACTION_DRAWTIME) {
202 //vec[0] = vec[0]/((t->scene->r.frs_sec / t->scene->r.frs_sec_base));
204 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
209 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
215 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
218 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
222 else if(t->spacetype==SPACE_SEQ) { /* XXX not tested yet, but should work */
225 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
231 void projectFloatView(TransInfo *t, float *vec, float *adr)
233 if (t->spacetype==SPACE_VIEW3D) {
234 if(t->ar->regiontype == RGN_TYPE_WINDOW)
235 project_float_noclip(t->ar, vec, adr);
237 else if(t->spacetype==SPACE_IMAGE) {
240 projectIntView(t, vec, a);
244 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
247 projectIntView(t, vec, a);
253 void applyAspectRatio(TransInfo *t, float *vec)
255 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
256 SpaceImage *sima= t->sa->spacedata.first;
259 if((sima->flag & SI_COORDFLOATS)==0) {
261 ED_space_image_size(sima, &width, &height);
267 ED_space_image_uv_aspect(sima, &aspx, &aspy);
273 void removeAspectRatio(TransInfo *t, float *vec)
275 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
276 SpaceImage *sima= t->sa->spacedata.first;
279 if((sima->flag & SI_COORDFLOATS)==0) {
281 ED_space_image_size(sima, &width, &height);
287 ED_space_image_uv_aspect(sima, &aspx, &aspy);
293 static void viewRedrawForce(const bContext *C, TransInfo *t)
295 if (t->spacetype == SPACE_VIEW3D)
297 /* Do we need more refined tags? */
299 WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
301 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
303 /* for realtime animation record - send notifiers recognised by animation editors */
304 // XXX: is this notifier a lame duck?
305 if ((t->animtimer) && IS_AUTOKEY_ON(t->scene))
306 WM_event_add_notifier(C, NC_OBJECT|ND_KEYS, NULL);
309 else if (t->spacetype == SPACE_ACTION) {
310 //SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
311 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
313 else if (t->spacetype == SPACE_IPO) {
314 //SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
315 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
317 else if (t->spacetype == SPACE_NLA) {
318 WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_EDITED, NULL);
320 else if(t->spacetype == SPACE_NODE)
322 //ED_area_tag_redraw(t->sa);
323 WM_event_add_notifier(C, NC_SPACE|ND_SPACE_NODE_VIEW, NULL);
325 else if(t->spacetype == SPACE_SEQ)
327 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, NULL);
329 else if (t->spacetype==SPACE_IMAGE) {
330 // XXX how to deal with lock?
331 SpaceImage *sima= (SpaceImage*)t->sa->spacedata.first;
332 if(sima->lock) WM_event_add_notifier(C, NC_GEOM|ND_DATA, t->obedit->data);
333 else ED_area_tag_redraw(t->sa);
337 static void viewRedrawPost(bContext *C, TransInfo *t)
339 ED_area_headerprint(t->sa, NULL);
341 if(t->spacetype == SPACE_VIEW3D) {
342 /* if autokeying is enabled, send notifiers that keyframes were added */
343 if (IS_AUTOKEY_ON(t->scene))
344 WM_main_add_notifier(NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
346 /* XXX temp, first hack to get auto-render in compositor work (ton) */
347 WM_event_add_notifier(C, NC_SCENE|ND_TRANSFORM_DONE, CTX_data_scene(C));
351 #if 0 // TRANSFORM_FIX_ME
352 if(t->spacetype==SPACE_VIEW3D) {
353 allqueue(REDRAWBUTSOBJECT, 0);
354 allqueue(REDRAWVIEW3D, 0);
356 else if(t->spacetype==SPACE_IMAGE) {
357 allqueue(REDRAWIMAGE, 0);
358 allqueue(REDRAWVIEW3D, 0);
360 else if(ELEM3(t->spacetype, SPACE_ACTION, SPACE_NLA, SPACE_IPO)) {
361 allqueue(REDRAWVIEW3D, 0);
362 allqueue(REDRAWACTION, 0);
363 allqueue(REDRAWNLA, 0);
364 allqueue(REDRAWIPO, 0);
365 allqueue(REDRAWTIME, 0);
366 allqueue(REDRAWBUTSOBJECT, 0);
369 scrarea_queue_headredraw(curarea);
373 /* ************************** TRANSFORMATIONS **************************** */
375 void BIF_selectOrientation(void) {
376 #if 0 // TRANSFORM_FIX_ME
378 char *str_menu = BIF_menustringTransformOrientation("Orientation");
379 val= pupmenu(str_menu);
388 static void view_editmove(unsigned short UNUSED(event))
390 #if 0 // TRANSFORM_FIX_ME
392 /* Regular: Zoom in */
393 /* Shift: Scroll up */
394 /* Ctrl: Scroll right */
395 /* Alt-Shift: Rotate up */
396 /* Alt-Ctrl: Rotate right */
398 /* only work in 3D window for now
399 * In the end, will have to send to event to a 2D window handler instead
401 if (Trans.flag & T_2D_EDIT)
407 if( G.qual & LR_SHIFTKEY ) {
408 if( G.qual & LR_ALTKEY ) {
409 G.qual &= ~LR_SHIFTKEY;
411 G.qual |= LR_SHIFTKEY;
415 } else if( G.qual & LR_CTRLKEY ) {
416 if( G.qual & LR_ALTKEY ) {
417 G.qual &= ~LR_CTRLKEY;
419 G.qual |= LR_CTRLKEY;
423 } else if(U.uiflag & USER_WHEELZOOMDIR)
424 persptoetsen(PADMINUS);
426 persptoetsen(PADPLUSKEY);
431 if( G.qual & LR_SHIFTKEY ) {
432 if( G.qual & LR_ALTKEY ) {
433 G.qual &= ~LR_SHIFTKEY;
435 G.qual |= LR_SHIFTKEY;
439 } else if( G.qual & LR_CTRLKEY ) {
440 if( G.qual & LR_ALTKEY ) {
441 G.qual &= ~LR_CTRLKEY;
443 G.qual |= LR_CTRLKEY;
447 } else if(U.uiflag & USER_WHEELZOOMDIR)
448 persptoetsen(PADPLUSKEY);
450 persptoetsen(PADMINUS);
457 setTransformViewMatrices(&Trans);
461 /* ************************************************* */
463 /* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
464 #define TFM_MODAL_CANCEL 1
465 #define TFM_MODAL_CONFIRM 2
466 #define TFM_MODAL_TRANSLATE 3
467 #define TFM_MODAL_ROTATE 4
468 #define TFM_MODAL_RESIZE 5
469 #define TFM_MODAL_SNAP_INV_ON 6
470 #define TFM_MODAL_SNAP_INV_OFF 7
471 #define TFM_MODAL_SNAP_TOGGLE 8
472 #define TFM_MODAL_AXIS_X 9
473 #define TFM_MODAL_AXIS_Y 10
474 #define TFM_MODAL_AXIS_Z 11
475 #define TFM_MODAL_PLANE_X 12
476 #define TFM_MODAL_PLANE_Y 13
477 #define TFM_MODAL_PLANE_Z 14
478 #define TFM_MODAL_CONS_OFF 15
479 #define TFM_MODAL_ADD_SNAP 16
480 #define TFM_MODAL_REMOVE_SNAP 17
481 /* 18 and 19 used by numinput, defined in transform.h
483 #define TFM_MODAL_PROPSIZE_UP 20
484 #define TFM_MODAL_PROPSIZE_DOWN 21
485 #define TFM_MODAL_AUTOIK_LEN_INC 22
486 #define TFM_MODAL_AUTOIK_LEN_DEC 23
488 /* called in transform_ops.c, on each regeneration of keymaps */
489 wmKeyMap* transform_modal_keymap(wmKeyConfig *keyconf)
491 static EnumPropertyItem modal_items[] = {
492 {TFM_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
493 {TFM_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
494 {TFM_MODAL_TRANSLATE, "TRANSLATE", 0, "Translate", ""},
495 {TFM_MODAL_ROTATE, "ROTATE", 0, "Rotate", ""},
496 {TFM_MODAL_RESIZE, "RESIZE", 0, "Resize", ""},
497 {TFM_MODAL_SNAP_INV_ON, "SNAP_INV_ON", 0, "Invert Snap On", ""},
498 {TFM_MODAL_SNAP_INV_OFF, "SNAP_INV_OFF", 0, "Invert Snap Off", ""},
499 {TFM_MODAL_SNAP_TOGGLE, "SNAP_TOGGLE", 0, "Snap Toggle", ""},
500 {TFM_MODAL_AXIS_X, "AXIS_X", 0, "Orientation X axis", ""},
501 {TFM_MODAL_AXIS_Y, "AXIS_Y", 0, "Orientation Y axis", ""},
502 {TFM_MODAL_AXIS_Z, "AXIS_Z", 0, "Orientation Z axis", ""},
503 {TFM_MODAL_PLANE_X, "PLANE_X", 0, "Orientation X plane", ""},
504 {TFM_MODAL_PLANE_Y, "PLANE_Y", 0, "Orientation Y plane", ""},
505 {TFM_MODAL_PLANE_Z, "PLANE_Z", 0, "Orientation Z plane", ""},
506 {TFM_MODAL_CONS_OFF, "CONS_OFF", 0, "Remove Constraints", ""},
507 {TFM_MODAL_ADD_SNAP, "ADD_SNAP", 0, "Add Snap Point", ""},
508 {TFM_MODAL_REMOVE_SNAP, "REMOVE_SNAP", 0, "Remove Last Snap Point", ""},
509 {NUM_MODAL_INCREMENT_UP, "INCREMENT_UP", 0, "Numinput Increment Up", ""},
510 {NUM_MODAL_INCREMENT_DOWN, "INCREMENT_DOWN", 0, "Numinput Increment Down", ""},
511 {TFM_MODAL_PROPSIZE_UP, "PROPORTIONAL_SIZE_UP", 0, "Increase Proportional Influence", ""},
512 {TFM_MODAL_PROPSIZE_DOWN, "PROPORTIONAL_SIZE_DOWN", 0, "Decrease Poportional Influence", ""},
513 {TFM_MODAL_AUTOIK_LEN_INC, "AUTOIK_CHAIN_LEN_UP", 0, "Increase Max AutoIK Chain Length", ""},
514 {TFM_MODAL_AUTOIK_LEN_DEC, "AUTOIK_CHAIN_LEN_DOWN", 0, "Decrease Max AutoIK Chain Length", ""},
515 {0, NULL, 0, NULL, NULL}};
517 wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "Transform Modal Map");
519 /* this function is called for each spacetype, only needs to add map once */
520 if(keymap) return NULL;
522 keymap= WM_modalkeymap_add(keyconf, "Transform Modal Map", modal_items);
524 /* items for modal map */
525 WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CANCEL);
526 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
527 WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
528 WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
530 WM_modalkeymap_add_item(keymap, GKEY, KM_PRESS, 0, 0, TFM_MODAL_TRANSLATE);
531 WM_modalkeymap_add_item(keymap, RKEY, KM_PRESS, 0, 0, TFM_MODAL_ROTATE);
532 WM_modalkeymap_add_item(keymap, SKEY, KM_PRESS, 0, 0, TFM_MODAL_RESIZE);
534 WM_modalkeymap_add_item(keymap, TABKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_SNAP_TOGGLE);
536 WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_SNAP_INV_ON);
537 WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, TFM_MODAL_SNAP_INV_OFF);
539 WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_SNAP_INV_ON);
540 WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_RELEASE, KM_ANY, 0, TFM_MODAL_SNAP_INV_OFF);
542 WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, 0, 0, TFM_MODAL_ADD_SNAP);
543 WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, KM_ALT, 0, TFM_MODAL_REMOVE_SNAP);
545 WM_modalkeymap_add_item(keymap, PAGEUPKEY, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_UP);
546 WM_modalkeymap_add_item(keymap, PAGEDOWNKEY, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_DOWN);
547 WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_UP);
548 WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_DOWN);
550 WM_modalkeymap_add_item(keymap, PAGEUPKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_INC);
551 WM_modalkeymap_add_item(keymap, PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_DEC);
552 WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_INC);
553 WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_DEC);
559 int transformEvent(TransInfo *t, wmEvent *event)
561 float mati[3][3]= MAT3_UNITY;
562 char cmode = constraintModeToChar(t);
565 t->redraw |= handleMouseInput(t, &t->mouse, event);
567 if (event->type == MOUSEMOVE)
569 if (t->modifiers & MOD_CONSTRAINT_SELECT)
570 t->con.mode |= CON_SELECT;
572 VECCOPY2D(t->mval, event->mval);
574 // t->redraw |= TREDRAW_SOFT; /* Use this for soft redraw. Might cause flicker in object mode */
575 t->redraw |= TREDRAW_HARD;
578 if (t->state == TRANS_STARTING) {
579 t->state = TRANS_RUNNING;
582 applyMouseInput(t, &t->mouse, t->mval, t->values);
585 /* handle modal keymap first */
586 if (event->type == EVT_MODAL_MAP) {
587 switch (event->val) {
588 case TFM_MODAL_CANCEL:
589 t->state = TRANS_CANCEL;
591 case TFM_MODAL_CONFIRM:
592 t->state = TRANS_CONFIRM;
594 case TFM_MODAL_TRANSLATE:
595 /* only switch when... */
596 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
597 resetTransRestrictions(t);
598 restoreTransObjects(t);
600 initSnapping(t, NULL); // need to reinit after mode change
601 t->redraw |= TREDRAW_HARD;
604 case TFM_MODAL_ROTATE:
605 /* only switch when... */
606 if(!(t->options & CTX_TEXTURE)) {
607 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
609 resetTransRestrictions(t);
611 if (t->mode == TFM_ROTATION) {
612 restoreTransObjects(t);
616 restoreTransObjects(t);
619 initSnapping(t, NULL); // need to reinit after mode change
620 t->redraw |= TREDRAW_HARD;
624 case TFM_MODAL_RESIZE:
625 /* only switch when... */
626 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
627 resetTransRestrictions(t);
628 restoreTransObjects(t);
630 initSnapping(t, NULL); // need to reinit after mode change
631 t->redraw |= TREDRAW_HARD;
635 case TFM_MODAL_SNAP_INV_ON:
636 t->modifiers |= MOD_SNAP_INVERT;
637 t->redraw |= TREDRAW_HARD;
639 case TFM_MODAL_SNAP_INV_OFF:
640 t->modifiers &= ~MOD_SNAP_INVERT;
641 t->redraw |= TREDRAW_HARD;
643 case TFM_MODAL_SNAP_TOGGLE:
644 t->modifiers ^= MOD_SNAP;
645 t->redraw |= TREDRAW_HARD;
647 case TFM_MODAL_AXIS_X:
648 if ((t->flag & T_NO_CONSTRAINT)==0) {
653 if (t->flag & T_2D_EDIT) {
654 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0), "along X");
657 setUserConstraint(t, t->current_orientation, (CON_AXIS0), "along %s X");
660 t->redraw |= TREDRAW_HARD;
663 case TFM_MODAL_AXIS_Y:
664 if ((t->flag & T_NO_CONSTRAINT)==0) {
669 if (t->flag & T_2D_EDIT) {
670 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1), "along Y");
673 setUserConstraint(t, t->current_orientation, (CON_AXIS1), "along %s Y");
676 t->redraw |= TREDRAW_HARD;
679 case TFM_MODAL_AXIS_Z:
680 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
685 setUserConstraint(t, t->current_orientation, (CON_AXIS2), "along %s Z");
687 t->redraw |= TREDRAW_HARD;
690 case TFM_MODAL_PLANE_X:
691 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
696 setUserConstraint(t, t->current_orientation, (CON_AXIS1|CON_AXIS2), "locking %s X");
698 t->redraw |= TREDRAW_HARD;
701 case TFM_MODAL_PLANE_Y:
702 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
707 setUserConstraint(t, t->current_orientation, (CON_AXIS0|CON_AXIS2), "locking %s Y");
709 t->redraw |= TREDRAW_HARD;
712 case TFM_MODAL_PLANE_Z:
713 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
718 setUserConstraint(t, t->current_orientation, (CON_AXIS0|CON_AXIS1), "locking %s Z");
720 t->redraw |= TREDRAW_HARD;
723 case TFM_MODAL_CONS_OFF:
724 if ((t->flag & T_NO_CONSTRAINT)==0) {
726 t->redraw |= TREDRAW_HARD;
729 case TFM_MODAL_ADD_SNAP:
731 t->redraw |= TREDRAW_HARD;
733 case TFM_MODAL_REMOVE_SNAP:
735 t->redraw |= TREDRAW_HARD;
737 case TFM_MODAL_PROPSIZE_UP:
738 if(t->flag & T_PROP_EDIT) {
740 if(t->spacetype==SPACE_VIEW3D && t->persp != RV3D_ORTHO)
741 t->prop_size= MIN2(t->prop_size, ((View3D *)t->view)->far);
742 calculatePropRatio(t);
744 t->redraw |= TREDRAW_HARD;
746 case TFM_MODAL_PROPSIZE_DOWN:
747 if (t->flag & T_PROP_EDIT) {
748 t->prop_size*= 0.90909090f;
749 calculatePropRatio(t);
751 t->redraw |= TREDRAW_HARD;
753 case TFM_MODAL_AUTOIK_LEN_INC:
754 if (t->flag & T_AUTOIK)
755 transform_autoik_update(t, 1);
756 t->redraw |= TREDRAW_HARD;
758 case TFM_MODAL_AUTOIK_LEN_DEC:
759 if (t->flag & T_AUTOIK)
760 transform_autoik_update(t, -1);
761 t->redraw |= TREDRAW_HARD;
768 // Modal numinput events
769 t->redraw |= handleNumInput(&(t->num), event);
771 /* else do non-mapped events */
772 else if (event->val==KM_PRESS) {
773 switch (event->type){
775 t->state = TRANS_CANCEL;
777 /* enforce redraw of transform when modifiers are used */
780 t->modifiers |= MOD_CONSTRAINT_PLANE;
781 t->redraw |= TREDRAW_HARD;
785 if ((t->spacetype==SPACE_VIEW3D) && event->alt) {
786 #if 0 // TRANSFORM_FIX_ME
790 BIF_selectOrientation();
791 calc_manipulator_stats(curarea);
792 copy_m3_m4(t->spacemtx, G.vd->twmat);
793 warp_pointer(mval[0], mval[1]);
797 t->state = TRANS_CONFIRM;
802 if ((t->flag & T_NO_CONSTRAINT)==0) {
803 /* exception for switching to dolly, or trackball, in camera view */
804 if (t->flag & T_CAMERA) {
805 if (t->mode==TFM_TRANSLATION)
806 setLocalConstraint(t, (CON_AXIS2), "along local Z");
807 else if (t->mode==TFM_ROTATION) {
808 restoreTransObjects(t);
813 t->modifiers |= MOD_CONSTRAINT_SELECT;
814 if (t->con.mode & CON_APPLY) {
819 initSelectConstraint(t, t->spacemtx);
822 /* bit hackish... but it prevents mmb select to print the orientation from menu */
823 strcpy(t->spacename, "global");
824 initSelectConstraint(t, mati);
826 postSelectConstraint(t);
829 t->redraw |= TREDRAW_HARD;
833 t->state = TRANS_CANCEL;
837 t->state = TRANS_CONFIRM;
840 /* only switch when... */
841 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
842 resetTransRestrictions(t);
843 restoreTransObjects(t);
845 initSnapping(t, NULL); // need to reinit after mode change
846 t->redraw |= TREDRAW_HARD;
850 /* only switch when... */
851 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
852 resetTransRestrictions(t);
853 restoreTransObjects(t);
855 initSnapping(t, NULL); // need to reinit after mode change
856 t->redraw |= TREDRAW_HARD;
860 /* only switch when... */
861 if(!(t->options & CTX_TEXTURE)) {
862 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
864 resetTransRestrictions(t);
866 if (t->mode == TFM_ROTATION) {
867 restoreTransObjects(t);
871 restoreTransObjects(t);
874 initSnapping(t, NULL); // need to reinit after mode change
875 t->redraw |= TREDRAW_HARD;
881 t->flag ^= T_PROP_CONNECTED;
882 sort_trans_data_dist(t);
883 calculatePropRatio(t);
888 t->redraw |= TREDRAW_HARD;
892 if ((t->flag & T_NO_CONSTRAINT)==0) {
893 if (t->flag & T_2D_EDIT) {
897 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0), "along X");
901 if (t->con.orientation != V3D_MANIP_GLOBAL) {
904 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
905 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
906 setUserConstraint(t, orientation, (CON_AXIS0), "along %s X");
907 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
908 setUserConstraint(t, orientation, (CON_AXIS1|CON_AXIS2), "locking %s X");
911 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
912 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0), "along %s X");
913 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
914 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1|CON_AXIS2), "locking %s X");
917 t->redraw |= TREDRAW_HARD;
921 if ((t->flag & T_NO_CONSTRAINT)==0) {
922 if (t->flag & T_2D_EDIT) {
926 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1), "along Y");
930 if (t->con.orientation != V3D_MANIP_GLOBAL) {
933 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
934 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
935 setUserConstraint(t, orientation, (CON_AXIS1), "along %s Y");
936 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
937 setUserConstraint(t, orientation, (CON_AXIS0|CON_AXIS2), "locking %s Y");
940 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
941 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1), "along %s Y");
942 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
943 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0|CON_AXIS2), "locking %s Y");
946 t->redraw |= TREDRAW_HARD;
950 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))==0) {
952 if (t->con.orientation != V3D_MANIP_GLOBAL) {
955 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
956 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
957 setUserConstraint(t, orientation, (CON_AXIS2), "along %s Z");
958 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
959 setUserConstraint(t, orientation, (CON_AXIS0|CON_AXIS1), "locking %s Z");
962 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
963 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS2), "along %s Z");
964 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
965 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0|CON_AXIS1), "locking %s Z");
967 t->redraw |= TREDRAW_HARD;
971 if (t->flag & T_PROP_EDIT && event->shift) {
972 t->prop_mode = (t->prop_mode + 1) % PROP_MODE_MAX;
973 calculatePropRatio(t);
974 t->redraw |= TREDRAW_HARD;
978 if(event->alt && t->flag & T_PROP_EDIT) {
979 t->prop_size *= 1.1f;
980 if(t->spacetype==SPACE_VIEW3D && t->persp != RV3D_ORTHO)
981 t->prop_size= MIN2(t->prop_size, ((View3D *)t->view)->far);
982 calculatePropRatio(t);
988 if (t->flag & T_AUTOIK) {
989 transform_autoik_update(t, 1);
991 else view_editmove(event->type);
995 if(event->alt && t->flag & T_PROP_EDIT) {
996 t->prop_size*= 0.90909090f;
997 calculatePropRatio(t);
1003 if (t->flag & T_AUTOIK) {
1004 transform_autoik_update(t, -1);
1006 else view_editmove(event->type);
1017 // Numerical input events
1018 t->redraw |= handleNumInput(&(t->num), event);
1020 // NDof input events
1021 switch(handleNDofInput(&(t->ndof), event))
1024 if ((t->options & CTX_NDOF) == 0)
1026 /* Confirm on normal transform only */
1027 t->state = TRANS_CONFIRM;
1031 if (t->options & CTX_NDOF)
1033 /* Cancel on pure NDOF transform */
1034 t->state = TRANS_CANCEL;
1038 /* Otherwise, just redraw, NDof input was cancelled */
1039 t->redraw |= TREDRAW_HARD;
1043 if (t->options & CTX_NDOF)
1045 /* Confirm on pure NDOF transform */
1046 t->state = TRANS_CONFIRM;
1050 t->redraw |= TREDRAW_HARD;
1058 t->redraw |= handleSnapping(t, event);
1061 else if (event->val==KM_RELEASE) {
1062 switch (event->type){
1065 t->modifiers &= ~MOD_CONSTRAINT_PLANE;
1066 t->redraw |= TREDRAW_HARD;
1070 if ((t->flag & T_NO_CONSTRAINT)==0) {
1071 t->modifiers &= ~MOD_CONSTRAINT_SELECT;
1072 postSelectConstraint(t);
1073 t->redraw |= TREDRAW_HARD;
1078 // if(WM_modal_tweak_exit(event, t->event_type))
1079 //// if (t->options & CTX_TWEAK)
1080 // t->state = TRANS_CONFIRM;
1087 /* confirm transform if launch key is released after mouse move */
1088 if (t->flag & T_RELEASE_CONFIRM)
1090 /* XXX Keyrepeat bug in Xorg fucks this up, will test when fixed */
1091 if (event->type == t->launch_event && (t->launch_event == LEFTMOUSE || t->launch_event == RIGHTMOUSE))
1093 t->state = TRANS_CONFIRM;
1098 // Per transform event, if present
1100 t->redraw |= t->handleEvent(t, event);
1102 if (handled || t->redraw)
1105 return OPERATOR_PASS_THROUGH;
1108 int calculateTransformCenter(bContext *C, int centerMode, float *vec)
1110 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data");
1113 t->state = TRANS_RUNNING;
1115 t->options = CTX_NONE;
1117 t->mode = TFM_DUMMY;
1119 initTransInfo(C, t, NULL, NULL); // internal data, mouse, vectors
1121 createTransData(C, t); // make TransData structs from selection
1123 t->around = centerMode; // override userdefined mode
1125 if (t->total == 0) {
1133 // Copy center from constraint center. Transform center can be local
1134 VECCOPY(vec, t->con.center);
1138 /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
1139 special_aftertrans_update(C, t);
1154 static void drawArrow(ArrowDirection d, short offset, short length, short size)
1164 glVertex2s( offset, 0);
1165 glVertex2s( offset + length, 0);
1166 glVertex2s( offset + length, 0);
1167 glVertex2s( offset + length - size, -size);
1168 glVertex2s( offset + length, 0);
1169 glVertex2s( offset + length - size, size);
1178 glVertex2s( 0, offset);
1179 glVertex2s( 0, offset + length);
1180 glVertex2s( 0, offset + length);
1181 glVertex2s(-size, offset + length - size);
1182 glVertex2s( 0, offset + length);
1183 glVertex2s( size, offset + length - size);
1189 static void drawArrowHead(ArrowDirection d, short size)
1198 glVertex2s( -size, -size);
1200 glVertex2s( -size, size);
1208 glVertex2s(-size, -size);
1210 glVertex2s( size, -size);
1216 static void drawArc(float size, float angle_start, float angle_end, int segments)
1218 float delta = (angle_end - angle_start) / segments;
1221 glBegin(GL_LINE_STRIP);
1223 for( angle = angle_start; angle < angle_end; angle += delta)
1225 glVertex2f( cosf(angle) * size, sinf(angle) * size);
1227 glVertex2f( cosf(angle_end) * size, sinf(angle_end) * size);
1232 static int helpline_poll(bContext *C)
1234 ARegion *ar= CTX_wm_region(C);
1236 if(ar && ar->regiontype==RGN_TYPE_WINDOW)
1241 static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
1243 TransInfo *t = (TransInfo*)customdata;
1245 if (t->helpline != HLP_NONE && !(t->flag & T_USES_MANIPULATOR))
1247 float vecrot[3], cent[2];
1253 VECCOPY(vecrot, t->center);
1254 if(t->flag & T_EDIT) {
1255 Object *ob= t->obedit;
1256 if(ob) mul_m4_v3(ob->obmat, vecrot);
1258 else if(t->flag & T_POSE) {
1259 Object *ob=t->poseobj;
1260 if(ob) mul_m4_v3(ob->obmat, vecrot);
1263 projectFloatView(t, vecrot, cent); // no overflow in extreme cases
1270 UI_ThemeColor(TH_WIRE);
1273 glBegin(GL_LINE_STRIP);
1274 glVertex2iv(t->mval);
1278 glTranslatef(mval[0], mval[1], 0);
1279 glRotatef(-RAD2DEGF(atan2f(cent[0] - t->mval[0], cent[1] - t->mval[1])), 0, 0, 1);
1283 drawArrow(UP, 5, 10, 5);
1284 drawArrow(DOWN, 5, 10, 5);
1288 UI_ThemeColor(TH_WIRE);
1290 glTranslatef(mval[0], mval[1], 0);
1293 drawArrow(RIGHT, 5, 10, 5);
1294 drawArrow(LEFT, 5, 10, 5);
1298 UI_ThemeColor(TH_WIRE);
1300 glTranslatef(mval[0], mval[1], 0);
1304 drawArrow(UP, 5, 10, 5);
1305 drawArrow(DOWN, 5, 10, 5);
1310 float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
1311 float angle = atan2f(dy, dx);
1312 float dist = sqrtf(dx*dx + dy*dy);
1313 float delta_angle = MIN2(15.0f / dist, (float)M_PI/4.0f);
1314 float spacing_angle = MIN2(5.0f / dist, (float)M_PI/12.0f);
1315 UI_ThemeColor(TH_WIRE);
1318 glBegin(GL_LINE_STRIP);
1319 glVertex2iv(t->mval);
1323 glTranslatef(cent[0] - t->mval[0] + mval[0], cent[1] - t->mval[1] + mval[1], 0);
1327 drawArc(dist, angle - delta_angle, angle - spacing_angle, 10);
1328 drawArc(dist, angle + spacing_angle, angle + delta_angle, 10);
1332 glTranslatef(cosf(angle - delta_angle) * dist, sinf(angle - delta_angle) * dist, 0);
1333 glRotatef(RAD2DEGF(angle - delta_angle), 0, 0, 1);
1335 drawArrowHead(DOWN, 5);
1339 glTranslatef(cosf(angle + delta_angle) * dist, sinf(angle + delta_angle) * dist, 0);
1340 glRotatef(RAD2DEGF(angle + delta_angle), 0, 0, 1);
1342 drawArrowHead(UP, 5);
1349 unsigned char col[3], col2[3];
1350 UI_GetThemeColor3ubv(TH_GRID, col);
1352 glTranslatef(mval[0], mval[1], 0);
1356 UI_make_axis_color(col, col2, 'X');
1357 glColor3ubv((GLubyte *)col2);
1359 drawArrow(RIGHT, 5, 10, 5);
1360 drawArrow(LEFT, 5, 10, 5);
1362 UI_make_axis_color(col, col2, 'Y');
1363 glColor3ubv((GLubyte *)col2);
1365 drawArrow(UP, 5, 10, 5);
1366 drawArrow(DOWN, 5, 10, 5);
1376 static void drawTransformView(const struct bContext *C, struct ARegion *UNUSED(ar), void *arg)
1381 drawPropCircle(C, t);
1386 static void drawTransformPixel(const struct bContext *UNUSED(C), struct ARegion *UNUSED(ar), void *UNUSED(arg))
1388 // TransInfo *t = arg;
1390 // drawHelpline(C, t->mval[0], t->mval[1], t);
1394 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
1396 ToolSettings *ts = CTX_data_tool_settings(C);
1397 int constraint_axis[3] = {0, 0, 0};
1398 int proportional = 0;
1400 if (RNA_struct_find_property(op->ptr, "value"))
1402 if (t->flag & T_AUTOVALUES)
1404 RNA_float_set_array(op->ptr, "value", t->auto_values);
1408 RNA_float_set_array(op->ptr, "value", t->values);
1412 /* convert flag to enum */
1413 switch(t->flag & (T_PROP_EDIT|T_PROP_CONNECTED))
1415 case (T_PROP_EDIT|T_PROP_CONNECTED):
1416 proportional = PROP_EDIT_CONNECTED;
1419 proportional = PROP_EDIT_ON;
1422 proportional = PROP_EDIT_OFF;
1425 // If modal, save settings back in scene if not set as operator argument
1426 if (t->flag & T_MODAL) {
1428 /* save settings if not set in operator */
1429 if (RNA_struct_find_property(op->ptr, "proportional") && !RNA_property_is_set(op->ptr, "proportional")) {
1431 ts->proportional = proportional;
1433 ts->proportional_objects = (proportional != PROP_EDIT_OFF);
1436 if (RNA_struct_find_property(op->ptr, "proportional_size") && !RNA_property_is_set(op->ptr, "proportional_size")) {
1437 ts->proportional_size = t->prop_size;
1440 if (RNA_struct_find_property(op->ptr, "proportional_edit_falloff") && !RNA_property_is_set(op->ptr, "proportional_edit_falloff")) {
1441 ts->prop_mode = t->prop_mode;
1444 /* do we check for parameter? */
1445 if (t->modifiers & MOD_SNAP) {
1446 ts->snap_flag |= SCE_SNAP;
1448 ts->snap_flag &= ~SCE_SNAP;
1451 if(t->spacetype == SPACE_VIEW3D) {
1452 if (RNA_struct_find_property(op->ptr, "constraint_orientation") && !RNA_property_is_set(op->ptr, "constraint_orientation")) {
1453 View3D *v3d = t->view;
1455 v3d->twmode = t->current_orientation;
1460 if (RNA_struct_find_property(op->ptr, "proportional"))
1462 RNA_enum_set(op->ptr, "proportional", proportional);
1463 RNA_enum_set(op->ptr, "proportional_edit_falloff", t->prop_mode);
1464 RNA_float_set(op->ptr, "proportional_size", t->prop_size);
1467 if (RNA_struct_find_property(op->ptr, "axis"))
1469 RNA_float_set_array(op->ptr, "axis", t->axis);
1472 if (RNA_struct_find_property(op->ptr, "mirror"))
1474 RNA_boolean_set(op->ptr, "mirror", t->flag & T_MIRROR);
1477 if (RNA_struct_find_property(op->ptr, "constraint_axis"))
1479 /* constraint orientation can be global, event if user selects something else
1480 * so use the orientation in the constraint if set
1482 if (t->con.mode & CON_APPLY) {
1483 RNA_enum_set(op->ptr, "constraint_orientation", t->con.orientation);
1485 RNA_enum_set(op->ptr, "constraint_orientation", t->current_orientation);
1488 if (t->con.mode & CON_APPLY)
1490 if (t->con.mode & CON_AXIS0) {
1491 constraint_axis[0] = 1;
1493 if (t->con.mode & CON_AXIS1) {
1494 constraint_axis[1] = 1;
1496 if (t->con.mode & CON_AXIS2) {
1497 constraint_axis[2] = 1;
1501 RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis);
1505 /* note: caller needs to free 't' on a 0 return */
1506 int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int mode)
1512 /* added initialize, for external calls to set stuff in TransInfo, like undo string */
1514 t->state = TRANS_STARTING;
1516 if(RNA_struct_find_property(op->ptr, "texture_space"))
1517 if(RNA_boolean_get(op->ptr, "texture_space"))
1518 options |= CTX_TEXTURE;
1520 t->options = options;
1524 t->launch_event = event ? event->type : -1;
1526 if (t->launch_event == EVT_TWEAK_R)
1528 t->launch_event = RIGHTMOUSE;
1530 else if (t->launch_event == EVT_TWEAK_L)
1532 t->launch_event = LEFTMOUSE;
1535 // XXX Remove this when wm_operator_call_internal doesn't use window->eventstate (which can have type = 0)
1536 // For manipulator only, so assume LEFTMOUSE
1537 if (t->launch_event == 0)
1539 t->launch_event = LEFTMOUSE;
1542 if (!initTransInfo(C, t, op, event)) // internal data, mouse, vectors
1547 if(t->spacetype == SPACE_VIEW3D)
1549 //calc_manipulator_stats(curarea);
1550 initTransformOrientation(C, t);
1552 t->draw_handle_apply = ED_region_draw_cb_activate(t->ar->type, drawTransformApply, t, REGION_DRAW_PRE_VIEW);
1553 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
1554 //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
1555 t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
1557 else if(t->spacetype == SPACE_IMAGE) {
1558 unit_m3(t->spacemtx);
1559 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
1560 //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
1563 unit_m3(t->spacemtx);
1565 createTransData(C, t); // make TransData structs from selection
1567 if (t->total == 0) {
1572 /* Stupid code to have Ctrl-Click on manipulator work ok */
1575 wmKeyMap *keymap = WM_keymap_active(CTX_wm_manager(C), op->type->modalkeymap);
1578 for (kmi = keymap->items.first; kmi; kmi = kmi->next)
1580 if (kmi->propvalue == TFM_MODAL_SNAP_INV_ON && kmi->val == KM_PRESS)
1582 if ((ELEM(kmi->type, LEFTCTRLKEY, RIGHTCTRLKEY) && event->ctrl) ||
1583 (ELEM(kmi->type, LEFTSHIFTKEY, RIGHTSHIFTKEY) && event->shift) ||
1584 (ELEM(kmi->type, LEFTALTKEY, RIGHTALTKEY) && event->alt) ||
1585 (kmi->type == OSKEY && event->oskey)) {
1586 t->modifiers |= MOD_SNAP_INVERT;
1594 initSnapping(t, op); // Initialize snapping data AFTER mode flags
1596 /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
1597 /* EVIL2: we gave as argument also texture space context bit... was cleared */
1598 /* EVIL3: extend mode for animation editors also switches modes... but is best way to avoid duplicate code */
1601 calculatePropRatio(t);
1604 initMouseInput(t, &t->mouse, t->center2d, t->imval);
1607 case TFM_TRANSLATION:
1625 case TFM_SHRINKFATTEN:
1626 initShrinkFatten(t);
1631 case TFM_CURVE_SHRINKFATTEN:
1632 initCurveShrinkFatten(t);
1644 { /* used for both B-Bone width (bonesize) as for deform-dist (envelope) */
1645 bArmature *arm= t->poseobj->data;
1646 if(arm->drawtype==ARM_ENVELOPE)
1647 initBoneEnvelope(t);
1652 case TFM_BONE_ENVELOPE:
1653 initBoneEnvelope(t);
1655 case TFM_EDGE_SLIDE:
1661 case TFM_TIME_TRANSLATE:
1662 initTimeTranslate(t);
1664 case TFM_TIME_SLIDE:
1667 case TFM_TIME_SCALE:
1670 case TFM_TIME_DUPLICATE:
1671 /* same as TFM_TIME_EXTEND, but we need the mode info for later
1672 * so that duplicate-culling will work properly
1674 if ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)
1677 initTimeTranslate(t);
1680 case TFM_TIME_EXTEND:
1681 /* now that transdata has been made, do like for TFM_TIME_TRANSLATE (for most Animation
1682 * Editors because they have only 1D transforms for time values) or TFM_TRANSLATION
1683 * (for Graph/NLA Editors only since they uses 'standard' transforms to get 2D movement)
1684 * depending on which editor this was called from
1686 if ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)
1689 initTimeTranslate(t);
1711 if(t->state == TRANS_CANCEL)
1718 /* overwrite initial values if operator supplied a non-null vector */
1719 if (RNA_property_is_set(op->ptr, "value"))
1721 float values[4]= {0}; /* incase value isn't length 4, avoid uninitialized memory */
1722 RNA_float_get_array(op->ptr, "value", values);
1723 QUATCOPY(t->values, values);
1724 QUATCOPY(t->auto_values, values);
1725 t->flag |= T_AUTOVALUES;
1728 /* Transformation axis from operator */
1729 if (RNA_struct_find_property(op->ptr, "axis") && RNA_property_is_set(op->ptr, "axis"))
1731 RNA_float_get_array(op->ptr, "axis", t->axis);
1732 normalize_v3(t->axis);
1733 copy_v3_v3(t->axis_orig, t->axis);
1736 /* Constraint init from operator */
1737 if (RNA_struct_find_property(op->ptr, "constraint_axis") && RNA_property_is_set(op->ptr, "constraint_axis"))
1739 int constraint_axis[3];
1741 RNA_boolean_get_array(op->ptr, "constraint_axis", constraint_axis);
1743 if (constraint_axis[0] || constraint_axis[1] || constraint_axis[2])
1745 t->con.mode |= CON_APPLY;
1747 if (constraint_axis[0]) {
1748 t->con.mode |= CON_AXIS0;
1750 if (constraint_axis[1]) {
1751 t->con.mode |= CON_AXIS1;
1753 if (constraint_axis[2]) {
1754 t->con.mode |= CON_AXIS2;
1757 setUserConstraint(t, t->current_orientation, t->con.mode, "%s");
1766 void transformApply(bContext *C, TransInfo *t)
1770 if ((t->redraw & TREDRAW_HARD) || (t->draw_handle_apply == NULL && (t->redraw & TREDRAW_SOFT)))
1772 selectConstraint(t);
1774 t->transform(t, t->mval); // calls recalcData()
1775 viewRedrawForce(C, t);
1777 t->redraw = TREDRAW_NOTHING;
1778 } else if (t->redraw & TREDRAW_SOFT) {
1779 viewRedrawForce(C, t);
1782 /* If auto confirm is on, break after one pass */
1783 if (t->options & CTX_AUTOCONFIRM)
1785 t->state = TRANS_CONFIRM;
1788 if (BKE_ptcache_get_continue_physics())
1791 //do_screenhandlers(G.curscreen);
1792 t->redraw |= TREDRAW_HARD;
1798 void drawTransformApply(const bContext *C, struct ARegion *UNUSED(ar), void *arg)
1802 if (t->redraw & TREDRAW_SOFT) {
1803 t->redraw |= TREDRAW_HARD;
1804 transformApply((bContext *)C, t);
1808 int transformEnd(bContext *C, TransInfo *t)
1810 int exit_code = OPERATOR_RUNNING_MODAL;
1814 if (t->state != TRANS_STARTING && t->state != TRANS_RUNNING)
1816 /* handle restoring objects */
1817 if(t->state == TRANS_CANCEL)
1819 /* exception, edge slide transformed UVs too */
1820 if(t->mode==TFM_EDGE_SLIDE)
1821 doEdgeSlide(t, 0.0f);
1823 exit_code = OPERATOR_CANCELLED;
1824 restoreTransObjects(t); // calls recalcData()
1828 exit_code = OPERATOR_FINISHED;
1831 /* aftertrans does insert keyframes, and clears base flags, doesnt read transdata */
1832 special_aftertrans_update(C, t);
1837 /* send events out for redraws */
1838 viewRedrawPost(C, t);
1840 /* Undo as last, certainly after special_trans_update! */
1842 if(t->state == TRANS_CANCEL) {
1843 // if(t->undostr) ED_undo_push(C, t->undostr);
1846 // if(t->undostr) ED_undo_push(C, t->undostr);
1847 // else ED_undo_push(C, transform_to_undostr(t));
1851 viewRedrawForce(C, t);
1859 /* ************************** TRANSFORM LOCKS **************************** */
1861 static void protectedTransBits(short protectflag, float *vec)
1863 if(protectflag & OB_LOCK_LOCX)
1865 if(protectflag & OB_LOCK_LOCY)
1867 if(protectflag & OB_LOCK_LOCZ)
1871 static void protectedSizeBits(short protectflag, float *size)
1873 if(protectflag & OB_LOCK_SCALEX)
1875 if(protectflag & OB_LOCK_SCALEY)
1877 if(protectflag & OB_LOCK_SCALEZ)
1881 static void protectedRotateBits(short protectflag, float *eul, float *oldeul)
1883 if(protectflag & OB_LOCK_ROTX)
1885 if(protectflag & OB_LOCK_ROTY)
1887 if(protectflag & OB_LOCK_ROTZ)
1892 /* this function only does the delta rotation */
1893 /* axis-angle is usually internally stored as quats... */
1894 static void protectedAxisAngleBits(short protectflag, float axis[3], float *angle, float oldAxis[3], float oldAngle)
1896 /* check that protection flags are set */
1897 if ((protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) == 0)
1900 if (protectflag & OB_LOCK_ROT4D) {
1901 /* axis-angle getting limited as 4D entities that they are... */
1902 if (protectflag & OB_LOCK_ROTW)
1904 if (protectflag & OB_LOCK_ROTX)
1905 axis[0]= oldAxis[0];
1906 if (protectflag & OB_LOCK_ROTY)
1907 axis[1]= oldAxis[1];
1908 if (protectflag & OB_LOCK_ROTZ)
1909 axis[2]= oldAxis[2];
1912 /* axis-angle get limited with euler... */
1913 float eul[3], oldeul[3];
1915 axis_angle_to_eulO( eul, EULER_ORDER_DEFAULT,axis, *angle);
1916 axis_angle_to_eulO( oldeul, EULER_ORDER_DEFAULT,oldAxis, oldAngle);
1918 if (protectflag & OB_LOCK_ROTX)
1920 if (protectflag & OB_LOCK_ROTY)
1922 if (protectflag & OB_LOCK_ROTZ)
1925 eulO_to_axis_angle( axis, angle,eul, EULER_ORDER_DEFAULT);
1927 /* when converting to axis-angle, we need a special exception for the case when there is no axis */
1928 if (IS_EQF(axis[0], axis[1]) && IS_EQF(axis[1], axis[2])) {
1929 /* for now, rotate around y-axis then (so that it simply becomes the roll) */
1935 /* this function only does the delta rotation */
1936 static void protectedQuaternionBits(short protectflag, float *quat, float *oldquat)
1938 /* check that protection flags are set */
1939 if ((protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) == 0)
1942 if (protectflag & OB_LOCK_ROT4D) {
1943 /* quaternions getting limited as 4D entities that they are... */
1944 if (protectflag & OB_LOCK_ROTW)
1945 quat[0]= oldquat[0];
1946 if (protectflag & OB_LOCK_ROTX)
1947 quat[1]= oldquat[1];
1948 if (protectflag & OB_LOCK_ROTY)
1949 quat[2]= oldquat[2];
1950 if (protectflag & OB_LOCK_ROTZ)
1951 quat[3]= oldquat[3];
1954 /* quaternions get limited with euler... (compatability mode) */
1955 float eul[3], oldeul[3], nquat[4], noldquat[4];
1958 qlen= normalize_qt_qt(nquat, quat);
1959 normalize_qt_qt(noldquat, oldquat);
1961 quat_to_eul(eul, nquat);
1962 quat_to_eul(oldeul, noldquat);
1964 if (protectflag & OB_LOCK_ROTX)
1966 if (protectflag & OB_LOCK_ROTY)
1968 if (protectflag & OB_LOCK_ROTZ)
1971 eul_to_quat( quat,eul);
1973 /* restore original quat size */
1974 mul_qt_fl(quat, qlen);
1976 /* quaternions flip w sign to accumulate rotations correctly */
1977 if ( (nquat[0]<0.0f && quat[0]>0.0f) || (nquat[0]>0.0f && quat[0]<0.0f) ) {
1978 mul_qt_fl(quat, -1.0f);
1983 /* ******************* TRANSFORM LIMITS ********************** */
1985 static void constraintTransLim(TransInfo *t, TransData *td)
1988 bConstraintTypeInfo *ctiLoc= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
1989 bConstraintTypeInfo *ctiDist= get_constraint_typeinfo(CONSTRAINT_TYPE_DISTLIMIT);
1991 bConstraintOb cob= {NULL};
1993 float ctime = (float)(t->scene->r.cfra);
1995 /* Make a temporary bConstraintOb for using these limit constraints
1996 * - they only care that cob->matrix is correctly set ;-)
1997 * - current space should be local
1999 unit_m4(cob.matrix);
2000 VECCOPY(cob.matrix[3], td->loc);
2002 /* Evaluate valid constraints */
2003 for (con= td->con; con; con= con->next) {
2004 bConstraintTypeInfo *cti = NULL;
2005 ListBase targets = {NULL, NULL};
2008 /* only consider constraint if enabled */
2009 if (con->flag & CONSTRAINT_DISABLE) continue;
2010 if (con->enforce == 0.0f) continue;
2012 /* only use it if it's tagged for this purpose (and the right type) */
2013 if (con->type == CONSTRAINT_TYPE_LOCLIMIT) {
2014 bLocLimitConstraint *data= con->data;
2016 if ((data->flag2 & LIMIT_TRANSFORM)==0)
2020 else if (con->type == CONSTRAINT_TYPE_DISTLIMIT) {
2021 bDistLimitConstraint *data= con->data;
2023 if ((data->flag & LIMITDIST_TRANSFORM)==0)
2029 /* do space conversions */
2030 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2031 /* just multiply by td->mtx (this should be ok) */
2032 copy_m4_m4(tmat, cob.matrix);
2033 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
2035 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
2036 /* skip... incompatable spacetype */
2040 /* get constraint targets if needed */
2041 get_constraint_targets_for_solving(con, &cob, &targets, ctime);
2044 cti->evaluate_constraint(con, &cob, &targets);
2046 /* convert spaces again */
2047 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2048 /* just multiply by td->mtx (this should be ok) */
2049 copy_m4_m4(tmat, cob.matrix);
2050 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
2053 /* free targets list */
2054 BLI_freelistN(&targets);
2058 /* copy results from cob->matrix */
2059 VECCOPY(td->loc, cob.matrix[3]);
2063 static void constraintob_from_transdata(bConstraintOb *cob, TransData *td)
2065 /* Make a temporary bConstraintOb for use by limit constraints
2066 * - they only care that cob->matrix is correctly set ;-)
2067 * - current space should be local
2069 memset(cob, 0, sizeof(bConstraintOb));
2072 if (td->ext->rotOrder == ROT_MODE_QUAT) {
2074 /* objects and bones do normalization first too, otherwise
2075 we don't necessarily end up with a rotation matrix, and
2076 then conversion back to quat gives a different result */
2078 normalize_qt_qt(quat, td->ext->quat);
2079 quat_to_mat4(cob->matrix, quat);
2081 else if (td->ext->rotOrder == ROT_MODE_AXISANGLE) {
2083 axis_angle_to_mat4(cob->matrix, &td->ext->quat[1], td->ext->quat[0]);
2087 eulO_to_mat4(cob->matrix, td->ext->rot, td->ext->rotOrder);
2092 static void constraintRotLim(TransInfo *UNUSED(t), TransData *td)
2095 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
2100 /* Evaluate valid constraints */
2101 for (con= td->con; con; con= con->next) {
2102 /* only consider constraint if enabled */
2103 if (con->flag & CONSTRAINT_DISABLE) continue;
2104 if (con->enforce == 0.0f) continue;
2106 /* we're only interested in Limit-Rotation constraints */
2107 if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
2108 bRotLimitConstraint *data= con->data;
2111 /* only use it if it's tagged for this purpose */
2112 if ((data->flag2 & LIMIT_TRANSFORM)==0)
2115 /* skip incompatable spacetypes */
2116 if (!ELEM(con->ownspace, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL))
2119 /* only do conversion if necessary, to preserve quats and eulers */
2121 constraintob_from_transdata(&cob, td);
2125 /* do space conversions */
2126 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2127 /* just multiply by td->mtx (this should be ok) */
2128 copy_m4_m4(tmat, cob.matrix);
2129 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
2133 cti->evaluate_constraint(con, &cob, NULL);
2135 /* convert spaces again */
2136 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2137 /* just multiply by td->mtx (this should be ok) */
2138 copy_m4_m4(tmat, cob.matrix);
2139 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
2145 /* copy results from cob->matrix */
2146 if (td->ext->rotOrder == ROT_MODE_QUAT) {
2148 mat4_to_quat( td->ext->quat,cob.matrix);
2150 else if (td->ext->rotOrder == ROT_MODE_AXISANGLE) {
2152 mat4_to_axis_angle( &td->ext->quat[1], &td->ext->quat[0],cob.matrix);
2156 mat4_to_eulO( td->ext->rot, td->ext->rotOrder,cob.matrix);
2162 static void constraintSizeLim(TransInfo *t, TransData *td)
2164 if (td->con && td->ext) {
2165 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
2166 bConstraintOb cob= {NULL};
2169 /* Make a temporary bConstraintOb for using these limit constraints
2170 * - they only care that cob->matrix is correctly set ;-)
2171 * - current space should be local
2173 if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
2174 /* scale val and reset size */
2175 return; // TODO: fix this case
2178 /* Reset val if SINGLESIZE but using a constraint */
2179 if (td->flag & TD_SINGLESIZE)
2182 size_to_mat4( cob.matrix,td->ext->size);
2185 /* Evaluate valid constraints */
2186 for (con= td->con; con; con= con->next) {
2187 /* only consider constraint if enabled */
2188 if (con->flag & CONSTRAINT_DISABLE) continue;
2189 if (con->enforce == 0.0f) continue;
2191 /* we're only interested in Limit-Scale constraints */
2192 if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
2193 bSizeLimitConstraint *data= con->data;
2196 /* only use it if it's tagged for this purpose */
2197 if ((data->flag2 & LIMIT_TRANSFORM)==0)
2200 /* do space conversions */
2201 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2202 /* just multiply by td->mtx (this should be ok) */
2203 copy_m4_m4(tmat, cob.matrix);
2204 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
2206 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
2207 /* skip... incompatable spacetype */
2212 cti->evaluate_constraint(con, &cob, NULL);
2214 /* convert spaces again */
2215 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2216 /* just multiply by td->mtx (this should be ok) */
2217 copy_m4_m4(tmat, cob.matrix);
2218 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
2223 /* copy results from cob->matrix */
2224 if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
2225 /* scale val and reset size */
2226 return; // TODO: fix this case
2229 /* Reset val if SINGLESIZE but using a constraint */
2230 if (td->flag & TD_SINGLESIZE)
2233 mat4_to_size( td->ext->size,cob.matrix);
2238 /* ************************** WARP *************************** */
2240 static void postInputWarp(TransInfo *t, float values[3])
2242 mul_v3_fl(values, (float)(M_PI * 2));
2244 if (t->customData) /* non-null value indicates reversed input */
2250 void initWarp(TransInfo *t)
2252 float max[3], min[3];
2256 t->transform = Warp;
2257 t->handleEvent = handleEventWarp;
2259 setInputPostFct(&t->mouse, postInputWarp);
2260 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2265 t->snap[1] = 5.0f / 180.0f * (float)M_PI;
2266 t->snap[2] = 1.0f / 180.0f * (float)M_PI;
2268 t->num.increment = 1.0f;
2270 t->flag |= T_NO_CONSTRAINT;
2272 /* we need min/max in view space */
2273 for(i = 0; i < t->total; i++) {
2275 copy_v3_v3(center, t->data[i].center);
2276 mul_m3_v3(t->data[i].mtx, center);
2277 mul_m4_v3(t->viewmat, center);
2278 sub_v3_v3(center, t->viewmat[3]);
2280 minmax_v3v3_v3(min, max, center);
2282 copy_v3_v3(max, center);
2283 copy_v3_v3(min, center);
2287 mid_v3_v3v3(t->center, min, max);
2289 if (max[0] == min[0]) max[0] += 0.1f; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */
2290 t->val= (max[0]-min[0])/2.0f; /* t->val is X dimension projected boundbox */
2293 int handleEventWarp(TransInfo *t, wmEvent *event)
2297 if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
2299 // Use customData pointer to signal warp direction
2300 if (t->customData == NULL)
2301 t->customData = (void*)1;
2303 t->customData = NULL;
2311 int Warp(TransInfo *t, const int UNUSED(mval[2]))
2313 TransData *td = t->data;
2314 float vec[3], circumfac, dist, phi0, co, si, *curs, cursor[3], gcursor[3];
2318 curs= give_cursor(t->scene, t->view);
2320 * gcursor is the one used for helpline.
2321 * It has to be in the same space as the drawing loop
2322 * (that means it needs to be in the object's space when in edit mode and
2323 * in global space in object mode)
2325 * cursor is used for calculations.
2326 * It needs to be in view space, but we need to take object's offset
2327 * into account if in Edit mode.
2329 VECCOPY(cursor, curs);
2330 VECCOPY(gcursor, cursor);
2331 if (t->flag & T_EDIT) {
2332 sub_v3_v3(cursor, t->obedit->obmat[3]);
2333 sub_v3_v3(gcursor, t->obedit->obmat[3]);
2334 mul_m3_v3(t->data->smtx, gcursor);
2336 mul_m4_v3(t->viewmat, cursor);
2337 sub_v3_v3(cursor, t->viewmat[3]);
2339 /* amount of radians for warp */
2340 circumfac = t->values[0];
2342 snapGrid(t, &circumfac);
2343 applyNumInput(&t->num, &circumfac);
2345 /* header print for NumInput */
2346 if (hasNumInput(&t->num)) {
2349 outputNumInput(&(t->num), c);
2351 sprintf(str, "Warp: %s", c);
2353 circumfac = DEG2RADF(circumfac);
2356 /* default header print */
2357 sprintf(str, "Warp: %.3f", RAD2DEGF(circumfac));
2360 t->values[0] = circumfac;
2362 circumfac /= 2; /* only need 180 on each side to make 360 */
2364 for(i = 0; i < t->total; i++, td++) {
2366 if (td->flag & TD_NOACTION)
2369 if (td->flag & TD_SKIP)
2372 /* translate point to center, rotate in such a way that outline==distance */
2373 VECCOPY(vec, td->iloc);
2374 mul_m3_v3(td->mtx, vec);
2375 mul_m4_v3(t->viewmat, vec);
2376 sub_v3_v3(vec, t->viewmat[3]);
2378 dist= vec[0]-cursor[0];
2380 /* t->val is X dimension projected boundbox */
2381 phi0= (circumfac*dist/t->val);
2383 vec[1]= (vec[1]-cursor[1]);
2385 co= (float)cos(phi0);
2386 si= (float)sin(phi0);
2387 loc[0]= -si*vec[1]+cursor[0];
2388 loc[1]= co*vec[1]+cursor[1];
2391 mul_m4_v3(t->viewinv, loc);
2392 sub_v3_v3(loc, t->viewinv[3]);
2393 mul_m3_v3(td->smtx, loc);
2395 sub_v3_v3(loc, td->iloc);
2396 mul_v3_fl(loc, td->factor);
2397 add_v3_v3v3(td->loc, td->iloc, loc);
2402 ED_area_headerprint(t->sa, str);
2407 /* ************************** SHEAR *************************** */
2409 static void postInputShear(TransInfo *UNUSED(t), float values[3])
2411 mul_v3_fl(values, 0.05f);
2414 void initShear(TransInfo *t)
2416 t->mode = TFM_SHEAR;
2417 t->transform = Shear;
2418 t->handleEvent = handleEventShear;
2420 setInputPostFct(&t->mouse, postInputShear);
2421 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2427 t->snap[2] = t->snap[1] * 0.1f;
2429 t->num.increment = 0.1f;
2431 t->flag |= T_NO_CONSTRAINT;
2434 int handleEventShear(TransInfo *t, wmEvent *event)
2438 if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
2440 // Use customData pointer to signal Shear direction
2441 if (t->customData == NULL)
2443 initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
2444 t->customData = (void*)1;
2448 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2449 t->customData = NULL;
2459 int Shear(TransInfo *t, const int UNUSED(mval[2]))
2461 TransData *td = t->data;
2463 float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3];
2468 copy_m3_m4(persmat, t->viewmat);
2469 invert_m3_m3(persinv, persmat);
2471 value = t->values[0];
2473 snapGrid(t, &value);
2475 applyNumInput(&t->num, &value);
2477 /* header print for NumInput */
2478 if (hasNumInput(&t->num)) {
2481 outputNumInput(&(t->num), c);
2483 sprintf(str, "Shear: %s %s", c, t->proptext);
2486 /* default header print */
2487 sprintf(str, "Shear: %.3f %s", value, t->proptext);
2492 // Custom data signals shear direction
2493 if (t->customData == NULL)
2498 mul_m3_m3m3(tmat, smat, persmat);
2499 mul_m3_m3m3(totmat, persinv, tmat);
2501 for(i = 0 ; i < t->total; i++, td++) {
2502 if (td->flag & TD_NOACTION)
2505 if (td->flag & TD_SKIP)
2510 mul_m3_m3m3(mat3, totmat, td->mtx);
2511 mul_m3_m3m3(tmat, td->smtx, mat3);
2514 copy_m3_m3(tmat, totmat);
2516 sub_v3_v3v3(vec, td->center, t->center);
2518 mul_m3_v3(tmat, vec);
2520 add_v3_v3(vec, t->center);
2521 sub_v3_v3(vec, td->center);
2523 mul_v3_fl(vec, td->factor);
2525 add_v3_v3v3(td->loc, td->iloc, vec);
2530 ED_area_headerprint(t->sa, str);
2535 /* ************************** RESIZE *************************** */
2537 void initResize(TransInfo *t)
2539 t->mode = TFM_RESIZE;
2540 t->transform = Resize;
2542 initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
2544 t->flag |= T_NULL_ONE;
2545 t->num.flag |= NUM_NULL_ONE;
2546 t->num.flag |= NUM_AFFECT_ALL;
2548 t->flag |= T_NO_ZERO;
2549 t->num.flag |= NUM_NO_ZERO;
2556 t->snap[2] = t->snap[1] * 0.1f;
2558 t->num.increment = t->snap[1];
2561 static void headerResize(TransInfo *t, float vec[3], char *str) {
2564 if (hasNumInput(&t->num)) {
2565 outputNumInput(&(t->num), tvec);
2568 sprintf(&tvec[0], "%.4f", vec[0]);
2569 sprintf(&tvec[20], "%.4f", vec[1]);
2570 sprintf(&tvec[40], "%.4f", vec[2]);
2573 if (t->con.mode & CON_APPLY) {
2574 switch(t->num.idx_max) {
2576 spos += sprintf(spos, "Scale: %s%s %s", &tvec[0], t->con.text, t->proptext);
2579 spos += sprintf(spos, "Scale: %s : %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2582 spos += sprintf(spos, "Scale: %s : %s : %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2586 if (t->flag & T_2D_EDIT)
2587 spos += sprintf(spos, "Scale X: %s Y: %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2589 spos += sprintf(spos, "Scale X: %s Y: %s Z: %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2592 if (t->flag & (T_PROP_EDIT|T_PROP_CONNECTED)) {
2593 spos += sprintf(spos, " Proportional size: %.2f", t->prop_size);
2599 #define SIGN(a) (a<-FLT_EPSILON?1:a>FLT_EPSILON?2:3)
2600 #define VECSIGNFLIP(a, b) ((SIGN(a[0]) & SIGN(b[0]))==0 || (SIGN(a[1]) & SIGN(b[1]))==0 || (SIGN(a[2]) & SIGN(b[2]))==0)
2602 /* smat is reference matrix, only scaled */
2603 static void TransMat3ToSize( float mat[][3], float smat[][3], float *size)
2607 copy_v3_v3(vec, mat[0]);
2608 size[0]= normalize_v3(vec);
2609 copy_v3_v3(vec, mat[1]);
2610 size[1]= normalize_v3(vec);
2611 copy_v3_v3(vec, mat[2]);
2612 size[2]= normalize_v3(vec);
2614 /* first tried with dotproduct... but the sign flip is crucial */
2615 if( VECSIGNFLIP(mat[0], smat[0]) ) size[0]= -size[0];
2616 if( VECSIGNFLIP(mat[1], smat[1]) ) size[1]= -size[1];
2617 if( VECSIGNFLIP(mat[2], smat[2]) ) size[2]= -size[2];
2621 static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
2622 float tmat[3][3], smat[3][3], center[3];
2625 if (t->flag & T_EDIT) {
2626 mul_m3_m3m3(smat, mat, td->mtx);
2627 mul_m3_m3m3(tmat, td->smtx, smat);
2630 copy_m3_m3(tmat, mat);
2633 if (t->con.applySize) {
2634 t->con.applySize(t, td, tmat);
2637 /* local constraint shouldn't alter center */
2638 if (t->around == V3D_LOCAL) {
2639 if (t->flag & T_OBJECT) {
2640 VECCOPY(center, td->center);
2642 else if (t->flag & T_EDIT) {
2644 if(t->around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
2645 VECCOPY(center, td->center);
2648 VECCOPY(center, t->center);
2652 VECCOPY(center, t->center);
2656 VECCOPY(center, t->center);
2662 if (t->flag & (T_OBJECT|T_TEXTURE|T_POSE)) {
2663 float obsizemat[3][3];
2664 // Reorient the size mat to fit the oriented object.
2665 mul_m3_m3m3(obsizemat, tmat, td->axismtx);
2666 //print_m3("obsizemat", obsizemat);
2667 TransMat3ToSize(obsizemat, td->axismtx, fsize);
2668 //print_v3("fsize", fsize);
2671 mat3_to_size( fsize,tmat);
2674 protectedSizeBits(td->protectflag, fsize);
2676 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't resize objects itself
2677 if((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)){
2678 /* scale val and reset size */
2679 *td->val = td->ival * (1 + (fsize[0] - 1) * td->factor);
2681 td->ext->size[0] = td->ext->isize[0];
2682 td->ext->size[1] = td->ext->isize[1];
2683 td->ext->size[2] = td->ext->isize[2];
2686 /* Reset val if SINGLESIZE but using a constraint */
2687 if (td->flag & TD_SINGLESIZE)
2688 *td->val = td->ival;
2690 td->ext->size[0] = td->ext->isize[0] * (1 + (fsize[0] - 1) * td->factor);
2691 td->ext->size[1] = td->ext->isize[1] * (1 + (fsize[1] - 1) * td->factor);
2692 td->ext->size[2] = td->ext->isize[2] * (1 + (fsize[2] - 1) * td->factor);
2696 constraintSizeLim(t, td);
2699 /* For individual element center, Editmode need to use iloc */
2700 if (t->flag & T_POINTS)
2701 sub_v3_v3v3(vec, td->iloc, center);
2703 sub_v3_v3v3(vec, td->center, center);
2705 mul_m3_v3(tmat, vec);
2707 add_v3_v3(vec, center);
2708 if (t->flag & T_POINTS)
2709 sub_v3_v3(vec, td->iloc);
2711 sub_v3_v3(vec, td->center);
2713 mul_v3_fl(vec, td->factor);
2715 if (t->flag & (T_OBJECT|T_POSE)) {
2716 mul_m3_v3(td->smtx, vec);
2719 protectedTransBits(td->protectflag, vec);
2720 add_v3_v3v3(td->loc, td->iloc, vec);
2722 constraintTransLim(t, td);
2725 int Resize(TransInfo *t, const int mval[2])
2728 float size[3], mat[3][3];
2733 /* for manipulator, center handle, the scaling can't be done relative to center */
2734 if( (t->flag & T_USES_MANIPULATOR) && t->con.mode==0)
2736 ratio = 1.0f - ((t->imval[0] - mval[0]) + (t->imval[1] - mval[1]))/100.0f;
2740 ratio = t->values[0];
2743 size[0] = size[1] = size[2] = ratio;
2747 if (hasNumInput(&t->num)) {
2748 applyNumInput(&t->num, size);
2749 constraintNumInput(t, size);
2752 applySnapping(t, size);
2754 if (t->flag & T_AUTOVALUES)
2756 VECCOPY(size, t->auto_values);
2759 VECCOPY(t->values, size);
2761 size_to_mat3( mat,size);
2763 if (t->con.applySize) {
2764 t->con.applySize(t, NULL, mat);
2767 copy_m3_m3(t->mat, mat); // used in manipulator
2769 headerResize(t, size, str);
2771 for(i = 0, td=t->data; i < t->total; i++, td++) {
2772 if (td->flag & TD_NOACTION)
2775 if (td->flag & TD_SKIP)
2778 ElementResize(t, td, mat);
2781 /* evil hack - redo resize if cliping needed */
2782 if (t->flag & T_CLIP_UV && clipUVTransform(t, size, 1)) {
2783 size_to_mat3( mat,size);
2785 if (t->con.applySize)
2786 t->con.applySize(t, NULL, mat);
2788 for(i = 0, td=t->data; i < t->total; i++, td++)
2789 ElementResize(t, td, mat);
2794 ED_area_headerprint(t->sa, str);
2799 /* ************************** TOSPHERE *************************** */
2801 void initToSphere(TransInfo *t)
2803 TransData *td = t->data;
2806 t->mode = TFM_TOSPHERE;
2807 t->transform = ToSphere;
2809 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2815 t->snap[2] = t->snap[1] * 0.1f;
2817 t->num.increment = t->snap[1];
2819 t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
2820 t->flag |= T_NO_CONSTRAINT;
2822 // Calculate average radius
2823 for(i = 0 ; i < t->total; i++, td++) {
2824 t->val += len_v3v3(t->center, td->iloc);
2827 t->val /= (float)t->total;
2830 int ToSphere(TransInfo *t, const int UNUSED(mval[2]))
2833 float ratio, radius;
2836 TransData *td = t->data;
2838 ratio = t->values[0];
2840 snapGrid(t, &ratio);
2842 applyNumInput(&t->num, &ratio);
2849 t->values[0] = ratio;
2851 /* header print for NumInput */
2852 if (hasNumInput(&t->num)) {
2855 outputNumInput(&(t->num), c);
2857 sprintf(str, "To Sphere: %s %s", c, t->proptext);
2860 /* default header print */
2861 sprintf(str, "To Sphere: %.4f %s", ratio, t->proptext);
2865 for(i = 0 ; i < t->total; i++, td++) {
2867 if (td->flag & TD_NOACTION)
2870 if (td->flag & TD_SKIP)
2873 sub_v3_v3v3(vec, td->iloc, t->center);
2875 radius = normalize_v3(vec);
2877 tratio = ratio * td->factor;
2879 mul_v3_fl(vec, radius * (1.0f - tratio) + t->val * tratio);
2881 add_v3_v3v3(td->loc, t->center, vec);
2887 ED_area_headerprint(t->sa, str);
2892 /* ************************** ROTATION *************************** */