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_movieclip_types.h"
54 #include "DNA_scene_types.h" /* PET modes */
56 #include "RNA_access.h"
59 #include "BIF_glutil.h"
62 #include "BKE_bmesh.h"
63 #include "BKE_context.h"
64 #include "BKE_constraint.h"
65 #include "BKE_global.h"
66 #include "BKE_particle.h"
67 #include "BKE_pointcache.h"
71 #include "ED_keyframing.h"
72 #include "ED_screen.h"
73 #include "ED_space_api.h"
74 #include "ED_markers.h"
75 #include "ED_view3d.h"
79 #include "UI_view2d.h"
84 #include "BLI_blenlib.h"
85 #include "BLI_utildefines.h"
86 #include "BLI_editVert.h"
87 #include "BLI_ghash.h"
88 #include "BLI_linklist.h"
90 #include "UI_resources.h"
92 //#include "blendef.h"
94 //#include "mydevice.h"
96 #include "transform.h"
98 void drawTransformApply(const struct bContext *C, struct ARegion *ar, void *arg);
99 int doEdgeSlide(TransInfo *t, float perc);
101 /* ************************** SPACE DEPENDANT CODE **************************** */
103 void setTransformViewMatrices(TransInfo *t)
105 if(t->spacetype==SPACE_VIEW3D && t->ar && t->ar->regiontype == RGN_TYPE_WINDOW) {
106 RegionView3D *rv3d = t->ar->regiondata;
108 copy_m4_m4(t->viewmat, rv3d->viewmat);
109 copy_m4_m4(t->viewinv, rv3d->viewinv);
110 copy_m4_m4(t->persmat, rv3d->persmat);
111 copy_m4_m4(t->persinv, rv3d->persinv);
112 t->persp = rv3d->persp;
119 t->persp = RV3D_ORTHO;
122 calculateCenter2D(t);
125 void convertViewVec(TransInfo *t, float *vec, int dx, int dy)
127 if (t->spacetype==SPACE_VIEW3D) {
128 if (t->ar->regiontype == RGN_TYPE_WINDOW) {
132 ED_view3d_win_to_delta(t->ar, mval_f, vec);
135 else if(t->spacetype==SPACE_IMAGE) {
136 View2D *v2d = t->view;
137 float divx, divy, aspx, aspy;
139 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
141 divx= v2d->mask.xmax-v2d->mask.xmin;
142 divy= v2d->mask.ymax-v2d->mask.ymin;
144 vec[0]= aspx*(v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
145 vec[1]= aspy*(v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
148 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
149 View2D *v2d = t->view;
152 divx= v2d->mask.xmax-v2d->mask.xmin;
153 divy= v2d->mask.ymax-v2d->mask.ymin;
155 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx) / (divx);
156 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy) / (divy);
159 else if(t->spacetype==SPACE_NODE) {
160 View2D *v2d = &t->ar->v2d;
163 divx= v2d->mask.xmax-v2d->mask.xmin;
164 divy= v2d->mask.ymax-v2d->mask.ymin;
166 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
167 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
170 else if(t->spacetype==SPACE_SEQ) {
171 View2D *v2d = &t->ar->v2d;
174 divx= v2d->mask.xmax-v2d->mask.xmin;
175 divy= v2d->mask.ymax-v2d->mask.ymin;
177 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
178 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
181 else if(t->spacetype==SPACE_CLIP) {
182 View2D *v2d = t->view;
185 divx= v2d->mask.xmax-v2d->mask.xmin;
186 divy= v2d->mask.ymax-v2d->mask.ymin;
188 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
189 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
194 void projectIntView(TransInfo *t, float *vec, int *adr)
196 if (t->spacetype==SPACE_VIEW3D) {
197 if(t->ar->regiontype == RGN_TYPE_WINDOW)
198 project_int_noclip(t->ar, vec, adr);
200 else if(t->spacetype==SPACE_IMAGE) {
201 float aspx, aspy, v[2];
203 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
207 UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr+1);
209 else if(t->spacetype == SPACE_ACTION) {
212 SpaceAction *sact = t->sa->spacedata.first;
214 if (sact->flag & SACTION_DRAWTIME) {
215 //vec[0] = vec[0]/((t->scene->r.frs_sec / t->scene->r.frs_sec_base));
217 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
222 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
228 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
231 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
235 else if(t->spacetype==SPACE_SEQ) { /* XXX not tested yet, but should work */
238 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
242 else if(t->spacetype==SPACE_CLIP) {
243 UI_view2d_to_region_no_clip(t->view, vec[0], vec[1], adr, adr+1);
247 void projectFloatView(TransInfo *t, float *vec, float *adr)
249 if (t->spacetype==SPACE_VIEW3D) {
250 if(t->ar->regiontype == RGN_TYPE_WINDOW)
251 project_float_noclip(t->ar, vec, adr);
253 else if(ELEM(t->spacetype, SPACE_IMAGE, SPACE_CLIP)) {
256 projectIntView(t, vec, a);
260 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
263 projectIntView(t, vec, a);
269 void applyAspectRatio(TransInfo *t, float *vec)
271 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
272 SpaceImage *sima= t->sa->spacedata.first;
275 if((sima->flag & SI_COORDFLOATS)==0) {
277 ED_space_image_size(sima, &width, &height);
283 ED_space_image_uv_aspect(sima, &aspx, &aspy);
289 void removeAspectRatio(TransInfo *t, float *vec)
291 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
292 SpaceImage *sima= t->sa->spacedata.first;
295 if((sima->flag & SI_COORDFLOATS)==0) {
297 ED_space_image_size(sima, &width, &height);
303 ED_space_image_uv_aspect(sima, &aspx, &aspy);
309 static void viewRedrawForce(const bContext *C, TransInfo *t)
311 if (t->spacetype == SPACE_VIEW3D)
313 /* Do we need more refined tags? */
315 WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
317 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
319 /* for realtime animation record - send notifiers recognised by animation editors */
320 // XXX: is this notifier a lame duck?
321 if ((t->animtimer) && IS_AUTOKEY_ON(t->scene))
322 WM_event_add_notifier(C, NC_OBJECT|ND_KEYS, NULL);
325 else if (t->spacetype == SPACE_ACTION) {
326 //SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
327 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
329 else if (t->spacetype == SPACE_IPO) {
330 //SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
331 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
333 else if (t->spacetype == SPACE_NLA) {
334 WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_EDITED, NULL);
336 else if(t->spacetype == SPACE_NODE)
338 //ED_area_tag_redraw(t->sa);
339 WM_event_add_notifier(C, NC_SPACE|ND_SPACE_NODE_VIEW, NULL);
341 else if(t->spacetype == SPACE_SEQ)
343 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, NULL);
345 else if (t->spacetype==SPACE_IMAGE) {
346 // XXX how to deal with lock?
347 SpaceImage *sima= (SpaceImage*)t->sa->spacedata.first;
348 if(sima->lock) WM_event_add_notifier(C, NC_GEOM|ND_DATA, t->obedit->data);
349 else ED_area_tag_redraw(t->sa);
351 else if (t->spacetype==SPACE_CLIP) {
352 SpaceClip *sc= (SpaceClip*)t->sa->spacedata.first;
353 MovieClip *clip= ED_space_clip(sc);
355 /* objects could be parented to tracking data, so send this for viewport refresh */
356 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
358 WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, clip);
362 static void viewRedrawPost(bContext *C, TransInfo *t)
364 ED_area_headerprint(t->sa, NULL);
366 if(t->spacetype == SPACE_VIEW3D) {
367 /* if autokeying is enabled, send notifiers that keyframes were added */
368 if (IS_AUTOKEY_ON(t->scene))
369 WM_main_add_notifier(NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
371 /* XXX temp, first hack to get auto-render in compositor work (ton) */
372 WM_event_add_notifier(C, NC_SCENE|ND_TRANSFORM_DONE, CTX_data_scene(C));
376 #if 0 // TRANSFORM_FIX_ME
377 if(t->spacetype==SPACE_VIEW3D) {
378 allqueue(REDRAWBUTSOBJECT, 0);
379 allqueue(REDRAWVIEW3D, 0);
381 else if(t->spacetype==SPACE_IMAGE) {
382 allqueue(REDRAWIMAGE, 0);
383 allqueue(REDRAWVIEW3D, 0);
385 else if(ELEM3(t->spacetype, SPACE_ACTION, SPACE_NLA, SPACE_IPO)) {
386 allqueue(REDRAWVIEW3D, 0);
387 allqueue(REDRAWACTION, 0);
388 allqueue(REDRAWNLA, 0);
389 allqueue(REDRAWIPO, 0);
390 allqueue(REDRAWTIME, 0);
391 allqueue(REDRAWBUTSOBJECT, 0);
394 scrarea_queue_headredraw(curarea);
398 /* ************************** TRANSFORMATIONS **************************** */
400 void BIF_selectOrientation(void) {
401 #if 0 // TRANSFORM_FIX_ME
403 char *str_menu = BIF_menustringTransformOrientation("Orientation");
404 val= pupmenu(str_menu);
413 static void view_editmove(unsigned short UNUSED(event))
415 #if 0 // TRANSFORM_FIX_ME
417 /* Regular: Zoom in */
418 /* Shift: Scroll up */
419 /* Ctrl: Scroll right */
420 /* Alt-Shift: Rotate up */
421 /* Alt-Ctrl: Rotate right */
423 /* only work in 3D window for now
424 * In the end, will have to send to event to a 2D window handler instead
426 if (Trans.flag & T_2D_EDIT)
432 if( G.qual & LR_SHIFTKEY ) {
433 if( G.qual & LR_ALTKEY ) {
434 G.qual &= ~LR_SHIFTKEY;
436 G.qual |= LR_SHIFTKEY;
440 } else if( G.qual & LR_CTRLKEY ) {
441 if( G.qual & LR_ALTKEY ) {
442 G.qual &= ~LR_CTRLKEY;
444 G.qual |= LR_CTRLKEY;
448 } else if(U.uiflag & USER_WHEELZOOMDIR)
449 persptoetsen(PADMINUS);
451 persptoetsen(PADPLUSKEY);
456 if( G.qual & LR_SHIFTKEY ) {
457 if( G.qual & LR_ALTKEY ) {
458 G.qual &= ~LR_SHIFTKEY;
460 G.qual |= LR_SHIFTKEY;
464 } else if( G.qual & LR_CTRLKEY ) {
465 if( G.qual & LR_ALTKEY ) {
466 G.qual &= ~LR_CTRLKEY;
468 G.qual |= LR_CTRLKEY;
472 } else if(U.uiflag & USER_WHEELZOOMDIR)
473 persptoetsen(PADPLUSKEY);
475 persptoetsen(PADMINUS);
482 setTransformViewMatrices(&Trans);
486 /* ************************************************* */
488 /* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
489 #define TFM_MODAL_CANCEL 1
490 #define TFM_MODAL_CONFIRM 2
491 #define TFM_MODAL_TRANSLATE 3
492 #define TFM_MODAL_ROTATE 4
493 #define TFM_MODAL_RESIZE 5
494 #define TFM_MODAL_SNAP_INV_ON 6
495 #define TFM_MODAL_SNAP_INV_OFF 7
496 #define TFM_MODAL_SNAP_TOGGLE 8
497 #define TFM_MODAL_AXIS_X 9
498 #define TFM_MODAL_AXIS_Y 10
499 #define TFM_MODAL_AXIS_Z 11
500 #define TFM_MODAL_PLANE_X 12
501 #define TFM_MODAL_PLANE_Y 13
502 #define TFM_MODAL_PLANE_Z 14
503 #define TFM_MODAL_CONS_OFF 15
504 #define TFM_MODAL_ADD_SNAP 16
505 #define TFM_MODAL_REMOVE_SNAP 17
506 /* 18 and 19 used by numinput, defined in transform.h
508 #define TFM_MODAL_PROPSIZE_UP 20
509 #define TFM_MODAL_PROPSIZE_DOWN 21
510 #define TFM_MODAL_AUTOIK_LEN_INC 22
511 #define TFM_MODAL_AUTOIK_LEN_DEC 23
513 /* called in transform_ops.c, on each regeneration of keymaps */
514 wmKeyMap* transform_modal_keymap(wmKeyConfig *keyconf)
516 static EnumPropertyItem modal_items[] = {
517 {TFM_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
518 {TFM_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
519 {TFM_MODAL_TRANSLATE, "TRANSLATE", 0, "Translate", ""},
520 {TFM_MODAL_ROTATE, "ROTATE", 0, "Rotate", ""},
521 {TFM_MODAL_RESIZE, "RESIZE", 0, "Resize", ""},
522 {TFM_MODAL_SNAP_INV_ON, "SNAP_INV_ON", 0, "Invert Snap On", ""},
523 {TFM_MODAL_SNAP_INV_OFF, "SNAP_INV_OFF", 0, "Invert Snap Off", ""},
524 {TFM_MODAL_SNAP_TOGGLE, "SNAP_TOGGLE", 0, "Snap Toggle", ""},
525 {TFM_MODAL_AXIS_X, "AXIS_X", 0, "Orientation X axis", ""},
526 {TFM_MODAL_AXIS_Y, "AXIS_Y", 0, "Orientation Y axis", ""},
527 {TFM_MODAL_AXIS_Z, "AXIS_Z", 0, "Orientation Z axis", ""},
528 {TFM_MODAL_PLANE_X, "PLANE_X", 0, "Orientation X plane", ""},
529 {TFM_MODAL_PLANE_Y, "PLANE_Y", 0, "Orientation Y plane", ""},
530 {TFM_MODAL_PLANE_Z, "PLANE_Z", 0, "Orientation Z plane", ""},
531 {TFM_MODAL_CONS_OFF, "CONS_OFF", 0, "Remove Constraints", ""},
532 {TFM_MODAL_ADD_SNAP, "ADD_SNAP", 0, "Add Snap Point", ""},
533 {TFM_MODAL_REMOVE_SNAP, "REMOVE_SNAP", 0, "Remove Last Snap Point", ""},
534 {NUM_MODAL_INCREMENT_UP, "INCREMENT_UP", 0, "Numinput Increment Up", ""},
535 {NUM_MODAL_INCREMENT_DOWN, "INCREMENT_DOWN", 0, "Numinput Increment Down", ""},
536 {TFM_MODAL_PROPSIZE_UP, "PROPORTIONAL_SIZE_UP", 0, "Increase Proportional Influence", ""},
537 {TFM_MODAL_PROPSIZE_DOWN, "PROPORTIONAL_SIZE_DOWN", 0, "Decrease Poportional Influence", ""},
538 {TFM_MODAL_AUTOIK_LEN_INC, "AUTOIK_CHAIN_LEN_UP", 0, "Increase Max AutoIK Chain Length", ""},
539 {TFM_MODAL_AUTOIK_LEN_DEC, "AUTOIK_CHAIN_LEN_DOWN", 0, "Decrease Max AutoIK Chain Length", ""},
540 {0, NULL, 0, NULL, NULL}};
542 wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "Transform Modal Map");
544 /* this function is called for each spacetype, only needs to add map once */
545 if(keymap) return NULL;
547 keymap= WM_modalkeymap_add(keyconf, "Transform Modal Map", modal_items);
549 /* items for modal map */
550 WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CANCEL);
551 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
552 WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
553 WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
555 WM_modalkeymap_add_item(keymap, GKEY, KM_PRESS, 0, 0, TFM_MODAL_TRANSLATE);
556 WM_modalkeymap_add_item(keymap, RKEY, KM_PRESS, 0, 0, TFM_MODAL_ROTATE);
557 WM_modalkeymap_add_item(keymap, SKEY, KM_PRESS, 0, 0, TFM_MODAL_RESIZE);
559 WM_modalkeymap_add_item(keymap, TABKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_SNAP_TOGGLE);
561 WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_SNAP_INV_ON);
562 WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, TFM_MODAL_SNAP_INV_OFF);
564 WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_SNAP_INV_ON);
565 WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_RELEASE, KM_ANY, 0, TFM_MODAL_SNAP_INV_OFF);
567 WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, 0, 0, TFM_MODAL_ADD_SNAP);
568 WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, KM_ALT, 0, TFM_MODAL_REMOVE_SNAP);
570 WM_modalkeymap_add_item(keymap, PAGEUPKEY, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_UP);
571 WM_modalkeymap_add_item(keymap, PAGEDOWNKEY, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_DOWN);
572 WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_UP);
573 WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_DOWN);
575 WM_modalkeymap_add_item(keymap, PAGEUPKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_INC);
576 WM_modalkeymap_add_item(keymap, PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_DEC);
577 WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_INC);
578 WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_DEC);
584 int transformEvent(TransInfo *t, wmEvent *event)
586 float mati[3][3]= MAT3_UNITY;
587 char cmode = constraintModeToChar(t);
590 t->redraw |= handleMouseInput(t, &t->mouse, event);
592 if (event->type == MOUSEMOVE)
594 if (t->modifiers & MOD_CONSTRAINT_SELECT)
595 t->con.mode |= CON_SELECT;
597 VECCOPY2D(t->mval, event->mval);
599 // t->redraw |= TREDRAW_SOFT; /* Use this for soft redraw. Might cause flicker in object mode */
600 t->redraw |= TREDRAW_HARD;
603 if (t->state == TRANS_STARTING) {
604 t->state = TRANS_RUNNING;
607 applyMouseInput(t, &t->mouse, t->mval, t->values);
610 /* handle modal keymap first */
611 if (event->type == EVT_MODAL_MAP) {
612 switch (event->val) {
613 case TFM_MODAL_CANCEL:
614 t->state = TRANS_CANCEL;
616 case TFM_MODAL_CONFIRM:
617 t->state = TRANS_CONFIRM;
619 case TFM_MODAL_TRANSLATE:
620 /* only switch when... */
621 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
622 resetTransRestrictions(t);
623 restoreTransObjects(t);
625 initSnapping(t, NULL); // need to reinit after mode change
626 t->redraw |= TREDRAW_HARD;
628 else if(t->mode == TFM_TRANSLATION) {
629 if(t->options&CTX_MOVIECLIP) {
630 restoreTransObjects(t);
632 t->flag^= T_ALT_TRANSFORM;
633 t->redraw |= TREDRAW_HARD;
637 case TFM_MODAL_ROTATE:
638 /* only switch when... */
639 if(!(t->options & CTX_TEXTURE) && !(t->options & CTX_MOVIECLIP)) {
640 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
642 resetTransRestrictions(t);
644 if (t->mode == TFM_ROTATION) {
645 restoreTransObjects(t);
649 restoreTransObjects(t);
652 initSnapping(t, NULL); // need to reinit after mode change
653 t->redraw |= TREDRAW_HARD;
657 case TFM_MODAL_RESIZE:
658 /* only switch when... */
659 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
660 resetTransRestrictions(t);
661 restoreTransObjects(t);
663 initSnapping(t, NULL); // need to reinit after mode change
664 t->redraw |= TREDRAW_HARD;
668 case TFM_MODAL_SNAP_INV_ON:
669 t->modifiers |= MOD_SNAP_INVERT;
670 t->redraw |= TREDRAW_HARD;
672 case TFM_MODAL_SNAP_INV_OFF:
673 t->modifiers &= ~MOD_SNAP_INVERT;
674 t->redraw |= TREDRAW_HARD;
676 case TFM_MODAL_SNAP_TOGGLE:
677 t->modifiers ^= MOD_SNAP;
678 t->redraw |= TREDRAW_HARD;
680 case TFM_MODAL_AXIS_X:
681 if ((t->flag & T_NO_CONSTRAINT)==0) {
686 if (t->flag & T_2D_EDIT) {
687 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0), "along X");
690 setUserConstraint(t, t->current_orientation, (CON_AXIS0), "along %s X");
693 t->redraw |= TREDRAW_HARD;
696 case TFM_MODAL_AXIS_Y:
697 if ((t->flag & T_NO_CONSTRAINT)==0) {
702 if (t->flag & T_2D_EDIT) {
703 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1), "along Y");
706 setUserConstraint(t, t->current_orientation, (CON_AXIS1), "along %s Y");
709 t->redraw |= TREDRAW_HARD;
712 case TFM_MODAL_AXIS_Z:
713 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
718 setUserConstraint(t, t->current_orientation, (CON_AXIS2), "along %s Z");
720 t->redraw |= TREDRAW_HARD;
723 case TFM_MODAL_PLANE_X:
724 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
729 setUserConstraint(t, t->current_orientation, (CON_AXIS1|CON_AXIS2), "locking %s X");
731 t->redraw |= TREDRAW_HARD;
734 case TFM_MODAL_PLANE_Y:
735 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
740 setUserConstraint(t, t->current_orientation, (CON_AXIS0|CON_AXIS2), "locking %s Y");
742 t->redraw |= TREDRAW_HARD;
745 case TFM_MODAL_PLANE_Z:
746 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
751 setUserConstraint(t, t->current_orientation, (CON_AXIS0|CON_AXIS1), "locking %s Z");
753 t->redraw |= TREDRAW_HARD;
756 case TFM_MODAL_CONS_OFF:
757 if ((t->flag & T_NO_CONSTRAINT)==0) {
759 t->redraw |= TREDRAW_HARD;
762 case TFM_MODAL_ADD_SNAP:
764 t->redraw |= TREDRAW_HARD;
766 case TFM_MODAL_REMOVE_SNAP:
768 t->redraw |= TREDRAW_HARD;
770 case TFM_MODAL_PROPSIZE_UP:
771 if(t->flag & T_PROP_EDIT) {
773 if(t->spacetype==SPACE_VIEW3D && t->persp != RV3D_ORTHO)
774 t->prop_size= MIN2(t->prop_size, ((View3D *)t->view)->far);
775 calculatePropRatio(t);
777 t->redraw |= TREDRAW_HARD;
779 case TFM_MODAL_PROPSIZE_DOWN:
780 if (t->flag & T_PROP_EDIT) {
781 t->prop_size*= 0.90909090f;
782 calculatePropRatio(t);
784 t->redraw |= TREDRAW_HARD;
786 case TFM_MODAL_AUTOIK_LEN_INC:
787 if (t->flag & T_AUTOIK)
788 transform_autoik_update(t, 1);
789 t->redraw |= TREDRAW_HARD;
791 case TFM_MODAL_AUTOIK_LEN_DEC:
792 if (t->flag & T_AUTOIK)
793 transform_autoik_update(t, -1);
794 t->redraw |= TREDRAW_HARD;
801 // Modal numinput events
802 t->redraw |= handleNumInput(&(t->num), event);
804 /* else do non-mapped events */
805 else if (event->val==KM_PRESS) {
806 switch (event->type){
808 t->state = TRANS_CANCEL;
810 /* enforce redraw of transform when modifiers are used */
813 t->modifiers |= MOD_CONSTRAINT_PLANE;
814 t->redraw |= TREDRAW_HARD;
818 if ((t->spacetype==SPACE_VIEW3D) && event->alt) {
819 #if 0 // TRANSFORM_FIX_ME
823 BIF_selectOrientation();
824 calc_manipulator_stats(curarea);
825 copy_m3_m4(t->spacemtx, G.vd->twmat);
826 warp_pointer(mval[0], mval[1]);
830 t->state = TRANS_CONFIRM;
835 if ((t->flag & T_NO_CONSTRAINT)==0) {
836 /* exception for switching to dolly, or trackball, in camera view */
837 if (t->flag & T_CAMERA) {
838 if (t->mode==TFM_TRANSLATION)
839 setLocalConstraint(t, (CON_AXIS2), "along local Z");
840 else if (t->mode==TFM_ROTATION) {
841 restoreTransObjects(t);
846 t->modifiers |= MOD_CONSTRAINT_SELECT;
847 if (t->con.mode & CON_APPLY) {
852 initSelectConstraint(t, t->spacemtx);
855 /* bit hackish... but it prevents mmb select to print the orientation from menu */
856 strcpy(t->spacename, "global");
857 initSelectConstraint(t, mati);
859 postSelectConstraint(t);
862 t->redraw |= TREDRAW_HARD;
866 t->state = TRANS_CANCEL;
870 t->state = TRANS_CONFIRM;
873 /* only switch when... */
874 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
875 resetTransRestrictions(t);
876 restoreTransObjects(t);
878 initSnapping(t, NULL); // need to reinit after mode change
879 t->redraw |= TREDRAW_HARD;
883 /* only switch when... */
884 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
885 resetTransRestrictions(t);
886 restoreTransObjects(t);
888 initSnapping(t, NULL); // need to reinit after mode change
889 t->redraw |= TREDRAW_HARD;
893 /* only switch when... */
894 if(!(t->options & CTX_TEXTURE) && !(t->options & CTX_MOVIECLIP)) {
895 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
897 resetTransRestrictions(t);
899 if (t->mode == TFM_ROTATION) {
900 restoreTransObjects(t);
904 restoreTransObjects(t);
907 initSnapping(t, NULL); // need to reinit after mode change
908 t->redraw |= TREDRAW_HARD;
914 t->flag ^= T_PROP_CONNECTED;
915 sort_trans_data_dist(t);
916 calculatePropRatio(t);
921 t->redraw |= TREDRAW_HARD;
925 if ((t->flag & T_NO_CONSTRAINT)==0) {
926 if (t->flag & T_2D_EDIT) {
930 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0), "along X");
934 if (t->con.orientation != V3D_MANIP_GLOBAL) {
937 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
938 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
939 setUserConstraint(t, orientation, (CON_AXIS0), "along %s X");
940 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
941 setUserConstraint(t, orientation, (CON_AXIS1|CON_AXIS2), "locking %s X");
944 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
945 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0), "along %s X");
946 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
947 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1|CON_AXIS2), "locking %s X");
950 t->redraw |= TREDRAW_HARD;
954 if ((t->flag & T_NO_CONSTRAINT)==0) {
955 if (t->flag & T_2D_EDIT) {
959 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1), "along Y");
963 if (t->con.orientation != V3D_MANIP_GLOBAL) {
966 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
967 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
968 setUserConstraint(t, orientation, (CON_AXIS1), "along %s Y");
969 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
970 setUserConstraint(t, orientation, (CON_AXIS0|CON_AXIS2), "locking %s Y");
973 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
974 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1), "along %s Y");
975 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
976 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0|CON_AXIS2), "locking %s Y");
979 t->redraw |= TREDRAW_HARD;
983 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))==0) {
985 if (t->con.orientation != V3D_MANIP_GLOBAL) {
988 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
989 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
990 setUserConstraint(t, orientation, (CON_AXIS2), "along %s Z");
991 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
992 setUserConstraint(t, orientation, (CON_AXIS0|CON_AXIS1), "locking %s Z");
995 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
996 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS2), "along %s Z");
997 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
998 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0|CON_AXIS1), "locking %s Z");
1000 t->redraw |= TREDRAW_HARD;
1004 if (t->flag & T_PROP_EDIT && event->shift) {
1005 t->prop_mode = (t->prop_mode + 1) % PROP_MODE_MAX;
1006 calculatePropRatio(t);
1007 t->redraw |= TREDRAW_HARD;
1011 if(event->alt && t->flag & T_PROP_EDIT) {
1012 t->prop_size *= 1.1f;
1013 if(t->spacetype==SPACE_VIEW3D && t->persp != RV3D_ORTHO)
1014 t->prop_size= MIN2(t->prop_size, ((View3D *)t->view)->far);
1015 calculatePropRatio(t);
1020 case WHEELDOWNMOUSE:
1021 if (t->flag & T_AUTOIK) {
1022 transform_autoik_update(t, 1);
1024 else view_editmove(event->type);
1028 if(event->alt && t->flag & T_PROP_EDIT) {
1029 t->prop_size*= 0.90909090f;
1030 calculatePropRatio(t);
1036 if (t->flag & T_AUTOIK) {
1037 transform_autoik_update(t, -1);
1039 else view_editmove(event->type);
1047 // Numerical input events
1048 t->redraw |= handleNumInput(&(t->num), event);
1051 t->redraw |= handleSnapping(t, event);
1054 else if (event->val==KM_RELEASE) {
1055 switch (event->type){
1058 t->modifiers &= ~MOD_CONSTRAINT_PLANE;
1059 t->redraw |= TREDRAW_HARD;
1063 if ((t->flag & T_NO_CONSTRAINT)==0) {
1064 t->modifiers &= ~MOD_CONSTRAINT_SELECT;
1065 postSelectConstraint(t);
1066 t->redraw |= TREDRAW_HARD;
1071 // if(WM_modal_tweak_exit(event, t->event_type))
1072 //// if (t->options & CTX_TWEAK)
1073 // t->state = TRANS_CONFIRM;
1080 /* confirm transform if launch key is released after mouse move */
1081 if (t->flag & T_RELEASE_CONFIRM)
1083 /* XXX Keyrepeat bug in Xorg fucks this up, will test when fixed */
1084 if (event->type == t->launch_event && (t->launch_event == LEFTMOUSE || t->launch_event == RIGHTMOUSE))
1086 t->state = TRANS_CONFIRM;
1091 // Per transform event, if present
1093 t->redraw |= t->handleEvent(t, event);
1095 if (handled || t->redraw)
1098 return OPERATOR_PASS_THROUGH;
1101 int calculateTransformCenter(bContext *C, int centerMode, float *vec)
1103 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data");
1106 t->state = TRANS_RUNNING;
1108 t->options = CTX_NONE;
1110 t->mode = TFM_DUMMY;
1112 initTransInfo(C, t, NULL, NULL); // internal data, mouse, vectors
1114 createTransData(C, t); // make TransData structs from selection
1116 t->around = centerMode; // override userdefined mode
1118 if (t->total == 0) {
1126 // Copy center from constraint center. Transform center can be local
1127 copy_v3_v3(vec, t->con.center);
1131 /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
1132 special_aftertrans_update(C, t);
1147 static void drawArrow(ArrowDirection d, short offset, short length, short size)
1157 glVertex2s( offset, 0);
1158 glVertex2s( offset + length, 0);
1159 glVertex2s( offset + length, 0);
1160 glVertex2s( offset + length - size, -size);
1161 glVertex2s( offset + length, 0);
1162 glVertex2s( offset + length - size, size);
1171 glVertex2s( 0, offset);
1172 glVertex2s( 0, offset + length);
1173 glVertex2s( 0, offset + length);
1174 glVertex2s(-size, offset + length - size);
1175 glVertex2s( 0, offset + length);
1176 glVertex2s( size, offset + length - size);
1182 static void drawArrowHead(ArrowDirection d, short size)
1191 glVertex2s( -size, -size);
1193 glVertex2s( -size, size);
1201 glVertex2s(-size, -size);
1203 glVertex2s( size, -size);
1209 static void drawArc(float size, float angle_start, float angle_end, int segments)
1211 float delta = (angle_end - angle_start) / segments;
1214 glBegin(GL_LINE_STRIP);
1216 for( angle = angle_start; angle < angle_end; angle += delta)
1218 glVertex2f( cosf(angle) * size, sinf(angle) * size);
1220 glVertex2f( cosf(angle_end) * size, sinf(angle_end) * size);
1225 static int helpline_poll(bContext *C)
1227 ARegion *ar= CTX_wm_region(C);
1229 if(ar && ar->regiontype==RGN_TYPE_WINDOW)
1234 static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
1236 TransInfo *t = (TransInfo*)customdata;
1238 if (t->helpline != HLP_NONE && !(t->flag & T_USES_MANIPULATOR))
1240 float vecrot[3], cent[2];
1246 copy_v3_v3(vecrot, t->center);
1247 if(t->flag & T_EDIT) {
1248 Object *ob= t->obedit;
1249 if(ob) mul_m4_v3(ob->obmat, vecrot);
1251 else if(t->flag & T_POSE) {
1252 Object *ob=t->poseobj;
1253 if(ob) mul_m4_v3(ob->obmat, vecrot);
1256 projectFloatView(t, vecrot, cent); // no overflow in extreme cases
1263 UI_ThemeColor(TH_WIRE);
1266 glBegin(GL_LINE_STRIP);
1267 glVertex2iv(t->mval);
1271 glTranslatef(mval[0], mval[1], 0);
1272 glRotatef(-RAD2DEGF(atan2f(cent[0] - t->mval[0], cent[1] - t->mval[1])), 0, 0, 1);
1276 drawArrow(UP, 5, 10, 5);
1277 drawArrow(DOWN, 5, 10, 5);
1281 UI_ThemeColor(TH_WIRE);
1283 glTranslatef(mval[0], mval[1], 0);
1286 drawArrow(RIGHT, 5, 10, 5);
1287 drawArrow(LEFT, 5, 10, 5);
1291 UI_ThemeColor(TH_WIRE);
1293 glTranslatef(mval[0], mval[1], 0);
1297 drawArrow(UP, 5, 10, 5);
1298 drawArrow(DOWN, 5, 10, 5);
1303 float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
1304 float angle = atan2f(dy, dx);
1305 float dist = sqrtf(dx*dx + dy*dy);
1306 float delta_angle = MIN2(15.0f / dist, (float)M_PI/4.0f);
1307 float spacing_angle = MIN2(5.0f / dist, (float)M_PI/12.0f);
1308 UI_ThemeColor(TH_WIRE);
1311 glBegin(GL_LINE_STRIP);
1312 glVertex2iv(t->mval);
1316 glTranslatef(cent[0] - t->mval[0] + mval[0], cent[1] - t->mval[1] + mval[1], 0);
1320 drawArc(dist, angle - delta_angle, angle - spacing_angle, 10);
1321 drawArc(dist, angle + spacing_angle, angle + delta_angle, 10);
1325 glTranslatef(cosf(angle - delta_angle) * dist, sinf(angle - delta_angle) * dist, 0);
1326 glRotatef(RAD2DEGF(angle - delta_angle), 0, 0, 1);
1328 drawArrowHead(DOWN, 5);
1332 glTranslatef(cosf(angle + delta_angle) * dist, sinf(angle + delta_angle) * dist, 0);
1333 glRotatef(RAD2DEGF(angle + delta_angle), 0, 0, 1);
1335 drawArrowHead(UP, 5);
1342 unsigned char col[3], col2[3];
1343 UI_GetThemeColor3ubv(TH_GRID, col);
1345 glTranslatef(mval[0], mval[1], 0);
1349 UI_make_axis_color(col, col2, 'X');
1350 glColor3ubv((GLubyte *)col2);
1352 drawArrow(RIGHT, 5, 10, 5);
1353 drawArrow(LEFT, 5, 10, 5);
1355 UI_make_axis_color(col, col2, 'Y');
1356 glColor3ubv((GLubyte *)col2);
1358 drawArrow(UP, 5, 10, 5);
1359 drawArrow(DOWN, 5, 10, 5);
1369 static void drawTransformView(const struct bContext *C, struct ARegion *UNUSED(ar), void *arg)
1374 drawPropCircle(C, t);
1379 static void drawTransformPixel(const struct bContext *UNUSED(C), struct ARegion *UNUSED(ar), void *UNUSED(arg))
1381 // TransInfo *t = arg;
1383 // drawHelpline(C, t->mval[0], t->mval[1], t);
1387 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
1389 ToolSettings *ts = CTX_data_tool_settings(C);
1390 int constraint_axis[3] = {0, 0, 0};
1391 int proportional = 0;
1394 // Save back mode in case we're in the generic operator
1395 if ((prop= RNA_struct_find_property(op->ptr, "mode"))) {
1396 RNA_property_enum_set(op->ptr, prop, t->mode);
1399 if ((prop= RNA_struct_find_property(op->ptr, "value"))) {
1400 float *values= (t->flag & T_AUTOVALUES) ? t->auto_values : t->values;
1401 if (RNA_property_array_check(prop)) {
1402 RNA_property_float_set_array(op->ptr, prop, values);
1405 RNA_property_float_set(op->ptr, prop, values[0]);
1409 /* convert flag to enum */
1410 switch(t->flag & (T_PROP_EDIT|T_PROP_CONNECTED))
1412 case (T_PROP_EDIT|T_PROP_CONNECTED):
1413 proportional = PROP_EDIT_CONNECTED;
1416 proportional = PROP_EDIT_ON;
1419 proportional = PROP_EDIT_OFF;
1422 // If modal, save settings back in scene if not set as operator argument
1423 if (t->flag & T_MODAL) {
1425 /* save settings if not set in operator */
1426 if (RNA_struct_find_property(op->ptr, "proportional") && !RNA_property_is_set(op->ptr, "proportional")) {
1428 ts->proportional = proportional;
1430 ts->proportional_objects = (proportional != PROP_EDIT_OFF);
1433 if (RNA_struct_find_property(op->ptr, "proportional_size") && !RNA_property_is_set(op->ptr, "proportional_size")) {
1434 ts->proportional_size = t->prop_size;
1437 if (RNA_struct_find_property(op->ptr, "proportional_edit_falloff") && !RNA_property_is_set(op->ptr, "proportional_edit_falloff")) {
1438 ts->prop_mode = t->prop_mode;
1441 /* do we check for parameter? */
1442 if (t->modifiers & MOD_SNAP) {
1443 ts->snap_flag |= SCE_SNAP;
1445 ts->snap_flag &= ~SCE_SNAP;
1448 if(t->spacetype == SPACE_VIEW3D) {
1449 if (RNA_struct_find_property(op->ptr, "constraint_orientation") && !RNA_property_is_set(op->ptr, "constraint_orientation")) {
1450 View3D *v3d = t->view;
1452 v3d->twmode = t->current_orientation;
1457 if (RNA_struct_find_property(op->ptr, "proportional"))
1459 RNA_enum_set(op->ptr, "proportional", proportional);
1460 RNA_enum_set(op->ptr, "proportional_edit_falloff", t->prop_mode);
1461 RNA_float_set(op->ptr, "proportional_size", t->prop_size);
1464 if (RNA_struct_find_property(op->ptr, "axis"))
1466 RNA_float_set_array(op->ptr, "axis", t->axis);
1469 if (RNA_struct_find_property(op->ptr, "mirror"))
1471 RNA_boolean_set(op->ptr, "mirror", t->flag & T_MIRROR);
1474 if (RNA_struct_find_property(op->ptr, "constraint_axis"))
1476 /* constraint orientation can be global, event if user selects something else
1477 * so use the orientation in the constraint if set
1479 if (t->con.mode & CON_APPLY) {
1480 RNA_enum_set(op->ptr, "constraint_orientation", t->con.orientation);
1482 RNA_enum_set(op->ptr, "constraint_orientation", t->current_orientation);
1485 if (t->con.mode & CON_APPLY)
1487 if (t->con.mode & CON_AXIS0) {
1488 constraint_axis[0] = 1;
1490 if (t->con.mode & CON_AXIS1) {
1491 constraint_axis[1] = 1;
1493 if (t->con.mode & CON_AXIS2) {
1494 constraint_axis[2] = 1;
1498 RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis);
1502 /* note: caller needs to free 't' on a 0 return */
1503 int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int mode)
1509 /* added initialize, for external calls to set stuff in TransInfo, like undo string */
1511 t->state = TRANS_STARTING;
1513 if(RNA_struct_find_property(op->ptr, "texture_space"))
1514 if(RNA_boolean_get(op->ptr, "texture_space"))
1515 options |= CTX_TEXTURE;
1517 t->options = options;
1521 t->launch_event = event ? event->type : -1;
1523 if (t->launch_event == EVT_TWEAK_R)
1525 t->launch_event = RIGHTMOUSE;
1527 else if (t->launch_event == EVT_TWEAK_L)
1529 t->launch_event = LEFTMOUSE;
1532 // XXX Remove this when wm_operator_call_internal doesn't use window->eventstate (which can have type = 0)
1533 // For manipulator only, so assume LEFTMOUSE
1534 if (t->launch_event == 0)
1536 t->launch_event = LEFTMOUSE;
1539 if (!initTransInfo(C, t, op, event)) // internal data, mouse, vectors
1544 if(t->spacetype == SPACE_VIEW3D)
1546 //calc_manipulator_stats(curarea);
1547 initTransformOrientation(C, t);
1549 t->draw_handle_apply = ED_region_draw_cb_activate(t->ar->type, drawTransformApply, t, REGION_DRAW_PRE_VIEW);
1550 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
1551 //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
1552 t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
1554 else if(t->spacetype == SPACE_IMAGE) {
1555 unit_m3(t->spacemtx);
1556 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
1557 //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
1559 else if(t->spacetype == SPACE_CLIP) {
1560 unit_m3(t->spacemtx);
1561 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
1562 t->options |= CTX_MOVIECLIP;
1565 unit_m3(t->spacemtx);
1567 createTransData(C, t); // make TransData structs from selection
1569 if (t->total == 0) {
1574 /* Stupid code to have Ctrl-Click on manipulator work ok */
1577 wmKeyMap *keymap = WM_keymap_active(CTX_wm_manager(C), op->type->modalkeymap);
1580 for (kmi = keymap->items.first; kmi; kmi = kmi->next)
1582 if (kmi->propvalue == TFM_MODAL_SNAP_INV_ON && kmi->val == KM_PRESS)
1584 if ((ELEM(kmi->type, LEFTCTRLKEY, RIGHTCTRLKEY) && event->ctrl) ||
1585 (ELEM(kmi->type, LEFTSHIFTKEY, RIGHTSHIFTKEY) && event->shift) ||
1586 (ELEM(kmi->type, LEFTALTKEY, RIGHTALTKEY) && event->alt) ||
1587 (kmi->type == OSKEY && event->oskey)) {
1588 t->modifiers |= MOD_SNAP_INVERT;
1596 initSnapping(t, op); // Initialize snapping data AFTER mode flags
1598 /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
1599 /* EVIL2: we gave as argument also texture space context bit... was cleared */
1600 /* EVIL3: extend mode for animation editors also switches modes... but is best way to avoid duplicate code */
1603 calculatePropRatio(t);
1606 initMouseInput(t, &t->mouse, t->center2d, t->imval);
1609 case TFM_TRANSLATION:
1627 case TFM_SHRINKFATTEN:
1628 initShrinkFatten(t);
1633 case TFM_CURVE_SHRINKFATTEN:
1634 initCurveShrinkFatten(t);
1646 { /* used for both B-Bone width (bonesize) as for deform-dist (envelope) */
1647 bArmature *arm= t->poseobj->data;
1648 if(arm->drawtype==ARM_ENVELOPE)
1649 initBoneEnvelope(t);
1654 case TFM_BONE_ENVELOPE:
1655 initBoneEnvelope(t);
1657 case TFM_EDGE_SLIDE:
1663 case TFM_TIME_TRANSLATE:
1664 initTimeTranslate(t);
1666 case TFM_TIME_SLIDE:
1669 case TFM_TIME_SCALE:
1672 case TFM_TIME_DUPLICATE:
1673 /* same as TFM_TIME_EXTEND, but we need the mode info for later
1674 * so that duplicate-culling will work properly
1676 if ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)
1679 initTimeTranslate(t);
1682 case TFM_TIME_EXTEND:
1683 /* now that transdata has been made, do like for TFM_TIME_TRANSLATE (for most Animation
1684 * Editors because they have only 1D transforms for time values) or TFM_TRANSLATION
1685 * (for Graph/NLA Editors only since they uses 'standard' transforms to get 2D movement)
1686 * depending on which editor this was called from
1688 if ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)
1691 initTimeTranslate(t);
1713 if(t->state == TRANS_CANCEL)
1720 /* overwrite initial values if operator supplied a non-null vector */
1721 if (RNA_property_is_set(op->ptr, "value"))
1723 float values[4]= {0}; /* incase value isn't length 4, avoid uninitialized memory */
1724 PropertyRNA *prop= RNA_struct_find_property(op->ptr, "value");
1726 if(RNA_property_array_check(prop)) {
1727 RNA_float_get_array(op->ptr, "value", values);
1729 values[0]= RNA_float_get(op->ptr, "value");
1732 QUATCOPY(t->values, values);
1733 QUATCOPY(t->auto_values, values);
1734 t->flag |= T_AUTOVALUES;
1737 /* Transformation axis from operator */
1738 if (RNA_struct_find_property(op->ptr, "axis") && RNA_property_is_set(op->ptr, "axis"))
1740 RNA_float_get_array(op->ptr, "axis", t->axis);
1741 normalize_v3(t->axis);
1742 copy_v3_v3(t->axis_orig, t->axis);
1745 /* Constraint init from operator */
1746 if (RNA_struct_find_property(op->ptr, "constraint_axis") && RNA_property_is_set(op->ptr, "constraint_axis"))
1748 int constraint_axis[3];
1750 RNA_boolean_get_array(op->ptr, "constraint_axis", constraint_axis);
1752 if (constraint_axis[0] || constraint_axis[1] || constraint_axis[2])
1754 t->con.mode |= CON_APPLY;
1756 if (constraint_axis[0]) {
1757 t->con.mode |= CON_AXIS0;
1759 if (constraint_axis[1]) {
1760 t->con.mode |= CON_AXIS1;
1762 if (constraint_axis[2]) {
1763 t->con.mode |= CON_AXIS2;
1766 setUserConstraint(t, t->current_orientation, t->con.mode, "%s");
1775 void transformApply(bContext *C, TransInfo *t)
1779 if ((t->redraw & TREDRAW_HARD) || (t->draw_handle_apply == NULL && (t->redraw & TREDRAW_SOFT)))
1781 selectConstraint(t);
1783 t->transform(t, t->mval); // calls recalcData()
1784 viewRedrawForce(C, t);
1786 t->redraw = TREDRAW_NOTHING;
1787 } else if (t->redraw & TREDRAW_SOFT) {
1788 viewRedrawForce(C, t);
1791 /* If auto confirm is on, break after one pass */
1792 if (t->options & CTX_AUTOCONFIRM)
1794 t->state = TRANS_CONFIRM;
1797 if (BKE_ptcache_get_continue_physics())
1800 //do_screenhandlers(G.curscreen);
1801 t->redraw |= TREDRAW_HARD;
1807 void drawTransformApply(const bContext *C, struct ARegion *UNUSED(ar), void *arg)
1811 if (t->redraw & TREDRAW_SOFT) {
1812 t->redraw |= TREDRAW_HARD;
1813 transformApply((bContext *)C, t);
1817 int transformEnd(bContext *C, TransInfo *t)
1819 int exit_code = OPERATOR_RUNNING_MODAL;
1823 if (t->state != TRANS_STARTING && t->state != TRANS_RUNNING)
1825 /* handle restoring objects */
1826 if(t->state == TRANS_CANCEL)
1828 /* exception, edge slide transformed UVs too */
1829 if(t->mode==TFM_EDGE_SLIDE)
1830 doEdgeSlide(t, 0.0f);
1832 exit_code = OPERATOR_CANCELLED;
1833 restoreTransObjects(t); // calls recalcData()
1837 exit_code = OPERATOR_FINISHED;
1840 /* aftertrans does insert keyframes, and clears base flags, doesnt read transdata */
1841 special_aftertrans_update(C, t);
1846 /* send events out for redraws */
1847 viewRedrawPost(C, t);
1849 /* Undo as last, certainly after special_trans_update! */
1851 if(t->state == TRANS_CANCEL) {
1852 // if(t->undostr) ED_undo_push(C, t->undostr);
1855 // if(t->undostr) ED_undo_push(C, t->undostr);
1856 // else ED_undo_push(C, transform_to_undostr(t));
1860 viewRedrawForce(C, t);
1868 /* ************************** TRANSFORM LOCKS **************************** */
1870 static void protectedTransBits(short protectflag, float *vec)
1872 if(protectflag & OB_LOCK_LOCX)
1874 if(protectflag & OB_LOCK_LOCY)
1876 if(protectflag & OB_LOCK_LOCZ)
1880 static void protectedSizeBits(short protectflag, float *size)
1882 if(protectflag & OB_LOCK_SCALEX)
1884 if(protectflag & OB_LOCK_SCALEY)
1886 if(protectflag & OB_LOCK_SCALEZ)
1890 static void protectedRotateBits(short protectflag, float *eul, float *oldeul)
1892 if(protectflag & OB_LOCK_ROTX)
1894 if(protectflag & OB_LOCK_ROTY)
1896 if(protectflag & OB_LOCK_ROTZ)
1901 /* this function only does the delta rotation */
1902 /* axis-angle is usually internally stored as quats... */
1903 static void protectedAxisAngleBits(short protectflag, float axis[3], float *angle, float oldAxis[3], float oldAngle)
1905 /* check that protection flags are set */
1906 if ((protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) == 0)
1909 if (protectflag & OB_LOCK_ROT4D) {
1910 /* axis-angle getting limited as 4D entities that they are... */
1911 if (protectflag & OB_LOCK_ROTW)
1913 if (protectflag & OB_LOCK_ROTX)
1914 axis[0]= oldAxis[0];
1915 if (protectflag & OB_LOCK_ROTY)
1916 axis[1]= oldAxis[1];
1917 if (protectflag & OB_LOCK_ROTZ)
1918 axis[2]= oldAxis[2];
1921 /* axis-angle get limited with euler... */
1922 float eul[3], oldeul[3];
1924 axis_angle_to_eulO( eul, EULER_ORDER_DEFAULT,axis, *angle);
1925 axis_angle_to_eulO( oldeul, EULER_ORDER_DEFAULT,oldAxis, oldAngle);
1927 if (protectflag & OB_LOCK_ROTX)
1929 if (protectflag & OB_LOCK_ROTY)
1931 if (protectflag & OB_LOCK_ROTZ)
1934 eulO_to_axis_angle( axis, angle,eul, EULER_ORDER_DEFAULT);
1936 /* when converting to axis-angle, we need a special exception for the case when there is no axis */
1937 if (IS_EQF(axis[0], axis[1]) && IS_EQF(axis[1], axis[2])) {
1938 /* for now, rotate around y-axis then (so that it simply becomes the roll) */
1944 /* this function only does the delta rotation */
1945 static void protectedQuaternionBits(short protectflag, float *quat, float *oldquat)
1947 /* check that protection flags are set */
1948 if ((protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) == 0)
1951 if (protectflag & OB_LOCK_ROT4D) {
1952 /* quaternions getting limited as 4D entities that they are... */
1953 if (protectflag & OB_LOCK_ROTW)
1954 quat[0]= oldquat[0];
1955 if (protectflag & OB_LOCK_ROTX)
1956 quat[1]= oldquat[1];
1957 if (protectflag & OB_LOCK_ROTY)
1958 quat[2]= oldquat[2];
1959 if (protectflag & OB_LOCK_ROTZ)
1960 quat[3]= oldquat[3];
1963 /* quaternions get limited with euler... (compatability mode) */
1964 float eul[3], oldeul[3], nquat[4], noldquat[4];
1967 qlen= normalize_qt_qt(nquat, quat);
1968 normalize_qt_qt(noldquat, oldquat);
1970 quat_to_eul(eul, nquat);
1971 quat_to_eul(oldeul, noldquat);
1973 if (protectflag & OB_LOCK_ROTX)
1975 if (protectflag & OB_LOCK_ROTY)
1977 if (protectflag & OB_LOCK_ROTZ)
1980 eul_to_quat( quat,eul);
1982 /* restore original quat size */
1983 mul_qt_fl(quat, qlen);
1985 /* quaternions flip w sign to accumulate rotations correctly */
1986 if ( (nquat[0]<0.0f && quat[0]>0.0f) || (nquat[0]>0.0f && quat[0]<0.0f) ) {
1987 mul_qt_fl(quat, -1.0f);
1992 /* ******************* TRANSFORM LIMITS ********************** */
1994 static void constraintTransLim(TransInfo *t, TransData *td)
1997 bConstraintTypeInfo *ctiLoc= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
1998 bConstraintTypeInfo *ctiDist= get_constraint_typeinfo(CONSTRAINT_TYPE_DISTLIMIT);
2000 bConstraintOb cob= {NULL};
2002 float ctime = (float)(t->scene->r.cfra);
2004 /* Make a temporary bConstraintOb for using these limit constraints
2005 * - they only care that cob->matrix is correctly set ;-)
2006 * - current space should be local
2008 unit_m4(cob.matrix);
2009 copy_v3_v3(cob.matrix[3], td->loc);
2011 /* Evaluate valid constraints */
2012 for (con= td->con; con; con= con->next) {
2013 bConstraintTypeInfo *cti = NULL;
2014 ListBase targets = {NULL, NULL};
2017 /* only consider constraint if enabled */
2018 if (con->flag & CONSTRAINT_DISABLE) continue;
2019 if (con->enforce == 0.0f) continue;
2021 /* only use it if it's tagged for this purpose (and the right type) */
2022 if (con->type == CONSTRAINT_TYPE_LOCLIMIT) {
2023 bLocLimitConstraint *data= con->data;
2025 if ((data->flag2 & LIMIT_TRANSFORM)==0)
2029 else if (con->type == CONSTRAINT_TYPE_DISTLIMIT) {
2030 bDistLimitConstraint *data= con->data;
2032 if ((data->flag & LIMITDIST_TRANSFORM)==0)
2038 /* do space conversions */
2039 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2040 /* just multiply by td->mtx (this should be ok) */
2041 copy_m4_m4(tmat, cob.matrix);
2042 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
2044 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
2045 /* skip... incompatable spacetype */
2049 /* get constraint targets if needed */
2050 get_constraint_targets_for_solving(con, &cob, &targets, ctime);
2053 cti->evaluate_constraint(con, &cob, &targets);
2055 /* convert spaces again */
2056 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2057 /* just multiply by td->mtx (this should be ok) */
2058 copy_m4_m4(tmat, cob.matrix);
2059 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
2062 /* free targets list */
2063 BLI_freelistN(&targets);
2067 /* copy results from cob->matrix */
2068 copy_v3_v3(td->loc, cob.matrix[3]);
2072 static void constraintob_from_transdata(bConstraintOb *cob, TransData *td)
2074 /* Make a temporary bConstraintOb for use by limit constraints
2075 * - they only care that cob->matrix is correctly set ;-)
2076 * - current space should be local
2078 memset(cob, 0, sizeof(bConstraintOb));
2081 if (td->ext->rotOrder == ROT_MODE_QUAT) {
2083 /* objects and bones do normalization first too, otherwise
2084 we don't necessarily end up with a rotation matrix, and
2085 then conversion back to quat gives a different result */
2087 normalize_qt_qt(quat, td->ext->quat);
2088 quat_to_mat4(cob->matrix, quat);
2090 else if (td->ext->rotOrder == ROT_MODE_AXISANGLE) {
2092 axis_angle_to_mat4(cob->matrix, &td->ext->quat[1], td->ext->quat[0]);
2096 eulO_to_mat4(cob->matrix, td->ext->rot, td->ext->rotOrder);
2101 static void constraintRotLim(TransInfo *UNUSED(t), TransData *td)
2104 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
2109 /* Evaluate valid constraints */
2110 for (con= td->con; con; con= con->next) {
2111 /* only consider constraint if enabled */
2112 if (con->flag & CONSTRAINT_DISABLE) continue;
2113 if (con->enforce == 0.0f) continue;
2115 /* we're only interested in Limit-Rotation constraints */
2116 if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
2117 bRotLimitConstraint *data= con->data;
2120 /* only use it if it's tagged for this purpose */
2121 if ((data->flag2 & LIMIT_TRANSFORM)==0)
2124 /* skip incompatable spacetypes */
2125 if (!ELEM(con->ownspace, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL))
2128 /* only do conversion if necessary, to preserve quats and eulers */
2130 constraintob_from_transdata(&cob, td);
2134 /* do space conversions */
2135 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2136 /* just multiply by td->mtx (this should be ok) */
2137 copy_m4_m4(tmat, cob.matrix);
2138 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
2142 cti->evaluate_constraint(con, &cob, NULL);
2144 /* convert spaces again */
2145 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2146 /* just multiply by td->mtx (this should be ok) */
2147 copy_m4_m4(tmat, cob.matrix);
2148 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
2154 /* copy results from cob->matrix */
2155 if (td->ext->rotOrder == ROT_MODE_QUAT) {
2157 mat4_to_quat( td->ext->quat,cob.matrix);
2159 else if (td->ext->rotOrder == ROT_MODE_AXISANGLE) {
2161 mat4_to_axis_angle( &td->ext->quat[1], &td->ext->quat[0],cob.matrix);
2165 mat4_to_eulO( td->ext->rot, td->ext->rotOrder,cob.matrix);
2171 static void constraintSizeLim(TransInfo *t, TransData *td)
2173 if (td->con && td->ext) {
2174 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
2175 bConstraintOb cob= {NULL};
2178 /* Make a temporary bConstraintOb for using these limit constraints
2179 * - they only care that cob->matrix is correctly set ;-)
2180 * - current space should be local
2182 if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
2183 /* scale val and reset size */
2184 return; // TODO: fix this case
2187 /* Reset val if SINGLESIZE but using a constraint */
2188 if (td->flag & TD_SINGLESIZE)
2191 size_to_mat4( cob.matrix,td->ext->size);
2194 /* Evaluate valid constraints */
2195 for (con= td->con; con; con= con->next) {
2196 /* only consider constraint if enabled */
2197 if (con->flag & CONSTRAINT_DISABLE) continue;
2198 if (con->enforce == 0.0f) continue;
2200 /* we're only interested in Limit-Scale constraints */
2201 if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
2202 bSizeLimitConstraint *data= con->data;
2205 /* only use it if it's tagged for this purpose */
2206 if ((data->flag2 & LIMIT_TRANSFORM)==0)
2209 /* do space conversions */
2210 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2211 /* just multiply by td->mtx (this should be ok) */
2212 copy_m4_m4(tmat, cob.matrix);
2213 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
2215 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
2216 /* skip... incompatable spacetype */
2221 cti->evaluate_constraint(con, &cob, NULL);
2223 /* convert spaces again */
2224 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2225 /* just multiply by td->mtx (this should be ok) */
2226 copy_m4_m4(tmat, cob.matrix);
2227 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
2232 /* copy results from cob->matrix */
2233 if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
2234 /* scale val and reset size */
2235 return; // TODO: fix this case
2238 /* Reset val if SINGLESIZE but using a constraint */
2239 if (td->flag & TD_SINGLESIZE)
2242 mat4_to_size( td->ext->size,cob.matrix);
2247 /* ************************** WARP *************************** */
2249 static void postInputWarp(TransInfo *t, float values[3])
2251 mul_v3_fl(values, (float)(M_PI * 2));
2253 if (t->customData) /* non-null value indicates reversed input */
2259 void initWarp(TransInfo *t)
2261 float max[3], min[3];
2265 t->transform = Warp;
2266 t->handleEvent = handleEventWarp;
2268 setInputPostFct(&t->mouse, postInputWarp);
2269 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2274 t->snap[1] = 5.0f / 180.0f * (float)M_PI;
2275 t->snap[2] = 1.0f / 180.0f * (float)M_PI;
2277 t->num.increment = 1.0f;
2279 t->flag |= T_NO_CONSTRAINT;
2281 /* we need min/max in view space */
2282 for(i = 0; i < t->total; i++) {
2284 copy_v3_v3(center, t->data[i].center);
2285 mul_m3_v3(t->data[i].mtx, center);
2286 mul_m4_v3(t->viewmat, center);
2287 sub_v3_v3(center, t->viewmat[3]);
2289 minmax_v3v3_v3(min, max, center);
2291 copy_v3_v3(max, center);
2292 copy_v3_v3(min, center);
2296 mid_v3_v3v3(t->center, min, max);
2298 if (max[0] == min[0]) max[0] += 0.1f; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */
2299 t->val= (max[0]-min[0])/2.0f; /* t->val is X dimension projected boundbox */
2302 int handleEventWarp(TransInfo *t, wmEvent *event)
2306 if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
2308 // Use customData pointer to signal warp direction
2309 if (t->customData == NULL)
2310 t->customData = (void*)1;
2312 t->customData = NULL;
2320 int Warp(TransInfo *t, const int UNUSED(mval[2]))
2322 TransData *td = t->data;
2323 float vec[3], circumfac, dist, phi0, co, si, *curs, cursor[3], gcursor[3];
2327 curs= give_cursor(t->scene, t->view);
2329 * gcursor is the one used for helpline.
2330 * It has to be in the same space as the drawing loop
2331 * (that means it needs to be in the object's space when in edit mode and
2332 * in global space in object mode)
2334 * cursor is used for calculations.
2335 * It needs to be in view space, but we need to take object's offset
2336 * into account if in Edit mode.
2338 copy_v3_v3(cursor, curs);
2339 copy_v3_v3(gcursor, cursor);
2340 if (t->flag & T_EDIT) {
2341 sub_v3_v3(cursor, t->obedit->obmat[3]);
2342 sub_v3_v3(gcursor, t->obedit->obmat[3]);
2343 mul_m3_v3(t->data->smtx, gcursor);
2345 mul_m4_v3(t->viewmat, cursor);
2346 sub_v3_v3(cursor, t->viewmat[3]);
2348 /* amount of radians for warp */
2349 circumfac = t->values[0];
2351 snapGrid(t, &circumfac);
2352 applyNumInput(&t->num, &circumfac);
2354 /* header print for NumInput */
2355 if (hasNumInput(&t->num)) {
2358 outputNumInput(&(t->num), c);
2360 sprintf(str, "Warp: %s", c);
2362 circumfac = DEG2RADF(circumfac);
2365 /* default header print */
2366 sprintf(str, "Warp: %.3f", RAD2DEGF(circumfac));
2369 t->values[0] = circumfac;
2371 circumfac /= 2; /* only need 180 on each side to make 360 */
2373 for(i = 0; i < t->total; i++, td++) {
2375 if (td->flag & TD_NOACTION)
2378 if (td->flag & TD_SKIP)
2381 /* translate point to center, rotate in such a way that outline==distance */
2382 copy_v3_v3(vec, td->iloc);
2383 mul_m3_v3(td->mtx, vec);
2384 mul_m4_v3(t->viewmat, vec);
2385 sub_v3_v3(vec, t->viewmat[3]);
2387 dist= vec[0]-cursor[0];
2389 /* t->val is X dimension projected boundbox */
2390 phi0= (circumfac*dist/t->val);
2392 vec[1]= (vec[1]-cursor[1]);
2394 co= (float)cos(phi0);
2395 si= (float)sin(phi0);
2396 loc[0]= -si*vec[1]+cursor[0];
2397 loc[1]= co*vec[1]+cursor[1];
2400 mul_m4_v3(t->viewinv, loc);
2401 sub_v3_v3(loc, t->viewinv[3]);
2402 mul_m3_v3(td->smtx, loc);
2404 sub_v3_v3(loc, td->iloc);
2405 mul_v3_fl(loc, td->factor);
2406 add_v3_v3v3(td->loc, td->iloc, loc);
2411 ED_area_headerprint(t->sa, str);
2416 /* ************************** SHEAR *************************** */
2418 static void postInputShear(TransInfo *UNUSED(t), float values[3])
2420 mul_v3_fl(values, 0.05f);
2423 void initShear(TransInfo *t)
2425 t->mode = TFM_SHEAR;
2426 t->transform = Shear;
2427 t->handleEvent = handleEventShear;
2429 setInputPostFct(&t->mouse, postInputShear);
2430 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2436 t->snap[2] = t->snap[1] * 0.1f;
2438 t->num.increment = 0.1f;
2440 t->flag |= T_NO_CONSTRAINT;
2443 int handleEventShear(TransInfo *t, wmEvent *event)
2447 if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
2449 // Use customData pointer to signal Shear direction
2450 if (t->customData == NULL)
2452 initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
2453 t->customData = (void*)1;
2457 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2458 t->customData = NULL;
2468 int Shear(TransInfo *t, const int UNUSED(mval[2]))
2470 TransData *td = t->data;
2472 float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3];
2477 copy_m3_m4(persmat, t->viewmat);
2478 invert_m3_m3(persinv, persmat);
2480 value = t->values[0];
2482 snapGrid(t, &value);
2484 applyNumInput(&t->num, &value);
2486 /* header print for NumInput */
2487 if (hasNumInput(&t->num)) {
2490 outputNumInput(&(t->num), c);
2492 sprintf(str, "Shear: %s %s", c, t->proptext);
2495 /* default header print */
2496 sprintf(str, "Shear: %.3f %s", value, t->proptext);
2501 // Custom data signals shear direction
2502 if (t->customData == NULL)
2507 mul_m3_m3m3(tmat, smat, persmat);
2508 mul_m3_m3m3(totmat, persinv, tmat);
2510 for(i = 0 ; i < t->total; i++, td++) {
2511 if (td->flag & TD_NOACTION)
2514 if (td->flag & TD_SKIP)
2519 mul_m3_m3m3(mat3, totmat, td->mtx);
2520 mul_m3_m3m3(tmat, td->smtx, mat3);
2523 copy_m3_m3(tmat, totmat);
2525 sub_v3_v3v3(vec, td->center, t->center);
2527 mul_m3_v3(tmat, vec);
2529 add_v3_v3(vec, t->center);
2530 sub_v3_v3(vec, td->center);
2532 mul_v3_fl(vec, td->factor);
2534 add_v3_v3v3(td->loc, td->iloc, vec);
2539 ED_area_headerprint(t->sa, str);
2544 /* ************************** RESIZE *************************** */
2546 void initResize(TransInfo *t)
2548 t->mode = TFM_RESIZE;
2549 t->transform = Resize;
2551 initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
2553 t->flag |= T_NULL_ONE;
2554 t->num.flag |= NUM_NULL_ONE;
2555 t->num.flag |= NUM_AFFECT_ALL;
2557 t->flag |= T_NO_ZERO;
2558 t->num.flag |= NUM_NO_ZERO;
2565 t->snap[2] = t->snap[1] * 0.1f;
2567 t->num.increment = t->snap[1];
2570 static void headerResize(TransInfo *t, float vec[3], char *str) {
2573 if (hasNumInput(&t->num)) {
2574 outputNumInput(&(t->num), tvec);
2577 sprintf(&tvec[0], "%.4f", vec[0]);
2578 sprintf(&tvec[20], "%.4f", vec[1]);
2579 sprintf(&tvec[40], "%.4f", vec[2]);
2582 if (t->con.mode & CON_APPLY) {
2583 switch(t->num.idx_max) {
2585 spos += sprintf(spos, "Scale: %s%s %s", &tvec[0], t->con.text, t->proptext);
2588 spos += sprintf(spos, "Scale: %s : %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2591 spos += sprintf(spos, "Scale: %s : %s : %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2595 if (t->flag & T_2D_EDIT)
2596 spos += sprintf(spos, "Scale X: %s Y: %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2598 spos += sprintf(spos, "Scale X: %s Y: %s Z: %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2601 if (t->flag & (T_PROP_EDIT|T_PROP_CONNECTED)) {
2602 spos += sprintf(spos, " Proportional size: %.2f", t->prop_size);
2608 #define SIGN(a) (a<-FLT_EPSILON?1:a>FLT_EPSILON?2:3)
2609 #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)
2611 /* smat is reference matrix, only scaled */
2612 static void TransMat3ToSize( float mat[][3], float smat[][3], float *size)
2616 copy_v3_v3(vec, mat[0]);
2617 size[0]= normalize_v3(vec);
2618 copy_v3_v3(vec, mat[1]);
2619 size[1]= normalize_v3(vec);
2620 copy_v3_v3(vec, mat[2]);
2621 size[2]= normalize_v3(vec);
2623 /* first tried with dotproduct... but the sign flip is crucial */
2624 if( VECSIGNFLIP(mat[0], smat[0]) ) size[0]= -size[0];
2625 if( VECSIGNFLIP(mat[1], smat[1]) ) size[1]= -size[1];
2626 if( VECSIGNFLIP(mat[2], smat[2]) ) size[2]= -size[2];
2630 static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
2631 float tmat[3][3], smat[3][3], center[3];
2634 if (t->flag & T_EDIT) {
2635 mul_m3_m3m3(smat, mat, td->mtx);
2636 mul_m3_m3m3(tmat, td->smtx, smat);
2639 copy_m3_m3(tmat, mat);
2642 if (t->con.applySize) {
2643 t->con.applySize(t, td, tmat);
2646 /* local constraint shouldn't alter center */
2647 if (t->around == V3D_LOCAL) {
2648 if (t->flag & T_OBJECT) {
2649 copy_v3_v3(center, td->center);
2651 else if (t->flag & T_EDIT) {
2653 if(t->around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
2654 copy_v3_v3(center, td->center);
2657 copy_v3_v3(center, t->center);
2661 copy_v3_v3(center, t->center);
2665 copy_v3_v3(center, t->center);
2671 if (t->flag & (T_OBJECT|T_TEXTURE|T_POSE)) {
2672 float obsizemat[3][3];
2673 // Reorient the size mat to fit the oriented object.
2674 mul_m3_m3m3(obsizemat, tmat, td->axismtx);
2675 //print_m3("obsizemat", obsizemat);
2676 TransMat3ToSize(obsizemat, td->axismtx, fsize);
2677 //print_v3("fsize", fsize);
2680 mat3_to_size( fsize,tmat);
2683 protectedSizeBits(td->protectflag, fsize);
2685 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't resize objects itself
2686 if((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)){
2687 /* scale val and reset size */
2688 *td->val = td->ival * (1 + (fsize[0] - 1) * td->factor);
2690 td->ext->size[0] = td->ext->isize[0];
2691 td->ext->size[1] = td->ext->isize[1];
2692 td->ext->size[2] = td->ext->isize[2];
2695 /* Reset val if SINGLESIZE but using a constraint */
2696 if (td->flag & TD_SINGLESIZE)
2697 *td->val = td->ival;
2699 td->ext->size[0] = td->ext->isize[0] * (1 + (fsize[0] - 1) * td->factor);
2700 td->ext->size[1] = td->ext->isize[1] * (1 + (fsize[1] - 1) * td->factor);
2701 td->ext->size[2] = td->ext->isize[2] * (1 + (fsize[2] - 1) * td->factor);
2705 constraintSizeLim(t, td);
2708 /* For individual element center, Editmode need to use iloc */
2709 if (t->flag & T_POINTS)
2710 sub_v3_v3v3(vec, td->iloc, center);
2712 sub_v3_v3v3(vec, td->center, center);
2714 mul_m3_v3(tmat, vec);
2716 add_v3_v3(vec, center);
2717 if (t->flag & T_POINTS)
2718 sub_v3_v3(vec, td->iloc);
2720 sub_v3_v3(vec, td->center);
2722 mul_v3_fl(vec, td->factor);
2724 if (t->flag & (T_OBJECT|T_POSE)) {
2725 mul_m3_v3(td->smtx, vec);
2728 protectedTransBits(td->protectflag, vec);
2729 add_v3_v3v3(td->loc, td->iloc, vec);
2731 constraintTransLim(t, td);
2734 int Resize(TransInfo *t, const int mval[2])
2737 float size[3], mat[3][3];
2742 /* for manipulator, center handle, the scaling can't be done relative to center */
2743 if( (t->flag & T_USES_MANIPULATOR) && t->con.mode==0)
2745 ratio = 1.0f - ((t->imval[0] - mval[0]) + (t->imval[1] - mval[1]))/100.0f;
2749 ratio = t->values[0];
2752 size[0] = size[1] = size[2] = ratio;
2756 if (hasNumInput(&t->num)) {
2757 applyNumInput(&t->num, size);
2758 constraintNumInput(t, size);
2761 applySnapping(t, size);
2763 if (t->flag & T_AUTOVALUES)
2765 copy_v3_v3(size, t->auto_values);
2768 copy_v3_v3(t->values, size);
2770 size_to_mat3( mat,size);
2772 if (t->con.applySize) {
2773 t->con.applySize(t, NULL, mat);
2776 copy_m3_m3(t->mat, mat); // used in manipulator
2778 headerResize(t, size, str);
2780 for(i = 0, td=t->data; i < t->total; i++, td++) {
2781 if (td->flag & TD_NOACTION)
2784 if (td->flag & TD_SKIP)
2787 ElementResize(t, td, mat);
2790 /* evil hack - redo resize if cliping needed */
2791 if (t->flag & T_CLIP_UV && clipUVTransform(t, size, 1)) {
2792 size_to_mat3( mat,size);
2794 if (t->con.applySize)
2795 t->con.applySize(t, NULL, mat);
2797 for(i = 0, td=t->data; i < t->total; i++, td++)
2798 ElementResize(t, td, mat);
2803 ED_area_headerprint(t->sa, str);
2808 /* ************************** TOSPHERE *************************** */
2810 void initToSphere(TransInfo *t)
2812 TransData *td = t->data;
2815 t->mode = TFM_TOSPHERE;
2816 t->transform = ToSphere;
2818 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2824 t->snap[2] = t->snap[1] * 0.1f;
2826 t->num.increment = t->snap[1];
2828 t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
2829 t->flag |= T_NO_CONSTRAINT;
2831 // Calculate average radius
2832 for(i = 0 ; i < t->total; i++, td++) {
2833 t->val += len_v3v3(t->center, td->iloc);
2836 t->val /= (float)t->total;
2839 int ToSphere(TransInfo *t, const int UNUSED(mval[2]))
2842 float ratio, radius;
2845 TransData *td = t->data;
2847 ratio = t->values[0];
2849 snapGrid(t, &ratio);
2851 applyNumInput(&t->num, &ratio);
2858 t->values[0] = ratio;
2860 /* header print for NumInput */
2861 if (hasNumInput(&t->num)) {
2864 outputNumInput(&(t->num), c);
2866 sprintf(str, "To Sphere: %s %s", c, t->proptext);
2869 /* default header print */
2870 sprintf(str, "To Sphere: %.4f %s", ratio, t->proptext);
2874 for(i = 0 ; i < t->total; i++, td++) {
2876 if (td->flag & TD_NOACTION)
2879 if (td->flag & TD_SKIP)
2882 sub_v3_v3v3(vec, td->iloc, t->center);
2884 radius = normalize_v3(vec);
2886 tratio = ratio * td->factor;
2888 mul_v3_fl(vec, radius * (1.0f - tratio) + t->val * tratio);
2890 add_v3_v3v3(td->loc, t->center, vec);
2896 ED_area_headerprint(t->sa, str);