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, short dx, short dy)
125 if (t->spacetype==SPACE_VIEW3D) {
126 if (t->ar->regiontype == RGN_TYPE_WINDOW)
128 window_to_3d_delta(t->ar, vec, dx, dy);
131 else if(t->spacetype==SPACE_IMAGE) {
132 View2D *v2d = t->view;
133 float divx, divy, aspx, aspy;
135 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
137 divx= v2d->mask.xmax-v2d->mask.xmin;
138 divy= v2d->mask.ymax-v2d->mask.ymin;
140 vec[0]= aspx*(v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
141 vec[1]= aspy*(v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
144 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
145 View2D *v2d = t->view;
148 divx= v2d->mask.xmax-v2d->mask.xmin;
149 divy= v2d->mask.ymax-v2d->mask.ymin;
151 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx) / (divx);
152 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy) / (divy);
155 else if(t->spacetype==SPACE_NODE) {
156 View2D *v2d = &t->ar->v2d;
159 divx= v2d->mask.xmax-v2d->mask.xmin;
160 divy= v2d->mask.ymax-v2d->mask.ymin;
162 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
163 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
166 else if(t->spacetype==SPACE_SEQ) {
167 View2D *v2d = &t->ar->v2d;
170 divx= v2d->mask.xmax-v2d->mask.xmin;
171 divy= v2d->mask.ymax-v2d->mask.ymin;
173 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
174 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
179 void projectIntView(TransInfo *t, float *vec, int *adr)
181 if (t->spacetype==SPACE_VIEW3D) {
182 if(t->ar->regiontype == RGN_TYPE_WINDOW)
183 project_int_noclip(t->ar, vec, adr);
185 else if(t->spacetype==SPACE_IMAGE) {
186 float aspx, aspy, v[2];
188 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
192 UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr+1);
194 else if(t->spacetype == SPACE_ACTION) {
195 SpaceAction *sact = t->sa->spacedata.first;
198 if (sact->flag & SACTION_DRAWTIME) {
199 //vec[0] = vec[0]/((t->scene->r.frs_sec / t->scene->r.frs_sec_base));
201 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
204 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
210 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
213 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
217 else if(t->spacetype==SPACE_SEQ) { /* XXX not tested yet, but should work */
220 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
226 void projectFloatView(TransInfo *t, float *vec, float *adr)
228 if (t->spacetype==SPACE_VIEW3D) {
229 if(t->ar->regiontype == RGN_TYPE_WINDOW)
230 project_float_noclip(t->ar, vec, adr);
232 else if(t->spacetype==SPACE_IMAGE) {
235 projectIntView(t, vec, a);
239 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
242 projectIntView(t, vec, a);
248 void applyAspectRatio(TransInfo *t, float *vec)
250 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
251 SpaceImage *sima= t->sa->spacedata.first;
254 if((sima->flag & SI_COORDFLOATS)==0) {
256 ED_space_image_size(sima, &width, &height);
262 ED_space_image_uv_aspect(sima, &aspx, &aspy);
268 void removeAspectRatio(TransInfo *t, float *vec)
270 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
271 SpaceImage *sima= t->sa->spacedata.first;
274 if((sima->flag & SI_COORDFLOATS)==0) {
276 ED_space_image_size(sima, &width, &height);
282 ED_space_image_uv_aspect(sima, &aspx, &aspy);
288 static void viewRedrawForce(const bContext *C, TransInfo *t)
290 if (t->spacetype == SPACE_VIEW3D)
292 /* Do we need more refined tags? */
294 WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
296 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
298 /* for realtime animation record - send notifiers recognised by animation editors */
299 // XXX: is this notifier a lame duck?
300 if ((t->animtimer) && IS_AUTOKEY_ON(t->scene))
301 WM_event_add_notifier(C, NC_OBJECT|ND_KEYS, NULL);
304 else if (t->spacetype == SPACE_ACTION) {
305 //SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
306 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
308 else if (t->spacetype == SPACE_IPO) {
309 //SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
310 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
312 else if (t->spacetype == SPACE_NLA) {
313 WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_EDITED, NULL);
315 else if(t->spacetype == SPACE_NODE)
317 //ED_area_tag_redraw(t->sa);
318 WM_event_add_notifier(C, NC_SPACE|ND_SPACE_NODE_VIEW, NULL);
320 else if(t->spacetype == SPACE_SEQ)
322 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, NULL);
324 else if (t->spacetype==SPACE_IMAGE) {
325 // XXX how to deal with lock?
326 SpaceImage *sima= (SpaceImage*)t->sa->spacedata.first;
327 if(sima->lock) WM_event_add_notifier(C, NC_GEOM|ND_DATA, t->obedit->data);
328 else ED_area_tag_redraw(t->sa);
332 static void viewRedrawPost(bContext *C, TransInfo *t)
334 ED_area_headerprint(t->sa, NULL);
336 if(t->spacetype == SPACE_VIEW3D) {
337 /* if autokeying is enabled, send notifiers that keyframes were added */
338 if (IS_AUTOKEY_ON(t->scene))
339 WM_main_add_notifier(NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
341 /* XXX temp, first hack to get auto-render in compositor work (ton) */
342 WM_event_add_notifier(C, NC_SCENE|ND_TRANSFORM_DONE, CTX_data_scene(C));
346 #if 0 // TRANSFORM_FIX_ME
347 if(t->spacetype==SPACE_VIEW3D) {
348 allqueue(REDRAWBUTSOBJECT, 0);
349 allqueue(REDRAWVIEW3D, 0);
351 else if(t->spacetype==SPACE_IMAGE) {
352 allqueue(REDRAWIMAGE, 0);
353 allqueue(REDRAWVIEW3D, 0);
355 else if(ELEM3(t->spacetype, SPACE_ACTION, SPACE_NLA, SPACE_IPO)) {
356 allqueue(REDRAWVIEW3D, 0);
357 allqueue(REDRAWACTION, 0);
358 allqueue(REDRAWNLA, 0);
359 allqueue(REDRAWIPO, 0);
360 allqueue(REDRAWTIME, 0);
361 allqueue(REDRAWBUTSOBJECT, 0);
364 scrarea_queue_headredraw(curarea);
368 /* ************************** TRANSFORMATIONS **************************** */
370 void BIF_selectOrientation(void) {
371 #if 0 // TRANSFORM_FIX_ME
373 char *str_menu = BIF_menustringTransformOrientation("Orientation");
374 val= pupmenu(str_menu);
383 static void view_editmove(unsigned short UNUSED(event))
385 #if 0 // TRANSFORM_FIX_ME
387 /* Regular: Zoom in */
388 /* Shift: Scroll up */
389 /* Ctrl: Scroll right */
390 /* Alt-Shift: Rotate up */
391 /* Alt-Ctrl: Rotate right */
393 /* only work in 3D window for now
394 * In the end, will have to send to event to a 2D window handler instead
396 if (Trans.flag & T_2D_EDIT)
402 if( G.qual & LR_SHIFTKEY ) {
403 if( G.qual & LR_ALTKEY ) {
404 G.qual &= ~LR_SHIFTKEY;
406 G.qual |= LR_SHIFTKEY;
410 } else if( G.qual & LR_CTRLKEY ) {
411 if( G.qual & LR_ALTKEY ) {
412 G.qual &= ~LR_CTRLKEY;
414 G.qual |= LR_CTRLKEY;
418 } else if(U.uiflag & USER_WHEELZOOMDIR)
419 persptoetsen(PADMINUS);
421 persptoetsen(PADPLUSKEY);
426 if( G.qual & LR_SHIFTKEY ) {
427 if( G.qual & LR_ALTKEY ) {
428 G.qual &= ~LR_SHIFTKEY;
430 G.qual |= LR_SHIFTKEY;
434 } else if( G.qual & LR_CTRLKEY ) {
435 if( G.qual & LR_ALTKEY ) {
436 G.qual &= ~LR_CTRLKEY;
438 G.qual |= LR_CTRLKEY;
442 } else if(U.uiflag & USER_WHEELZOOMDIR)
443 persptoetsen(PADPLUSKEY);
445 persptoetsen(PADMINUS);
452 setTransformViewMatrices(&Trans);
456 /* ************************************************* */
458 /* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
459 #define TFM_MODAL_CANCEL 1
460 #define TFM_MODAL_CONFIRM 2
461 #define TFM_MODAL_TRANSLATE 3
462 #define TFM_MODAL_ROTATE 4
463 #define TFM_MODAL_RESIZE 5
464 #define TFM_MODAL_SNAP_INV_ON 6
465 #define TFM_MODAL_SNAP_INV_OFF 7
466 #define TFM_MODAL_SNAP_TOGGLE 8
467 #define TFM_MODAL_AXIS_X 9
468 #define TFM_MODAL_AXIS_Y 10
469 #define TFM_MODAL_AXIS_Z 11
470 #define TFM_MODAL_PLANE_X 12
471 #define TFM_MODAL_PLANE_Y 13
472 #define TFM_MODAL_PLANE_Z 14
473 #define TFM_MODAL_CONS_OFF 15
474 #define TFM_MODAL_ADD_SNAP 16
475 #define TFM_MODAL_REMOVE_SNAP 17
476 /* 18 and 19 used by numinput, defined in transform.h
478 #define TFM_MODAL_PROPSIZE_UP 20
479 #define TFM_MODAL_PROPSIZE_DOWN 21
480 #define TFM_MODAL_AUTOIK_LEN_INC 22
481 #define TFM_MODAL_AUTOIK_LEN_DEC 23
483 /* called in transform_ops.c, on each regeneration of keymaps */
484 wmKeyMap* transform_modal_keymap(wmKeyConfig *keyconf)
486 static EnumPropertyItem modal_items[] = {
487 {TFM_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
488 {TFM_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
489 {TFM_MODAL_TRANSLATE, "TRANSLATE", 0, "Translate", ""},
490 {TFM_MODAL_ROTATE, "ROTATE", 0, "Rotate", ""},
491 {TFM_MODAL_RESIZE, "RESIZE", 0, "Resize", ""},
492 {TFM_MODAL_SNAP_INV_ON, "SNAP_INV_ON", 0, "Invert Snap On", ""},
493 {TFM_MODAL_SNAP_INV_OFF, "SNAP_INV_OFF", 0, "Invert Snap Off", ""},
494 {TFM_MODAL_SNAP_TOGGLE, "SNAP_TOGGLE", 0, "Snap Toggle", ""},
495 {TFM_MODAL_AXIS_X, "AXIS_X", 0, "Orientation X axis", ""},
496 {TFM_MODAL_AXIS_Y, "AXIS_Y", 0, "Orientation Y axis", ""},
497 {TFM_MODAL_AXIS_Z, "AXIS_Z", 0, "Orientation Z axis", ""},
498 {TFM_MODAL_PLANE_X, "PLANE_X", 0, "Orientation X plane", ""},
499 {TFM_MODAL_PLANE_Y, "PLANE_Y", 0, "Orientation Y plane", ""},
500 {TFM_MODAL_PLANE_Z, "PLANE_Z", 0, "Orientation Z plane", ""},
501 {TFM_MODAL_CONS_OFF, "CONS_OFF", 0, "Remove Constraints", ""},
502 {TFM_MODAL_ADD_SNAP, "ADD_SNAP", 0, "Add Snap Point", ""},
503 {TFM_MODAL_REMOVE_SNAP, "REMOVE_SNAP", 0, "Remove Last Snap Point", ""},
504 {NUM_MODAL_INCREMENT_UP, "INCREMENT_UP", 0, "Numinput Increment Up", ""},
505 {NUM_MODAL_INCREMENT_DOWN, "INCREMENT_DOWN", 0, "Numinput Increment Down", ""},
506 {TFM_MODAL_PROPSIZE_UP, "PROPORTIONAL_SIZE_UP", 0, "Increase Proportional Influence", ""},
507 {TFM_MODAL_PROPSIZE_DOWN, "PROPORTIONAL_SIZE_DOWN", 0, "Decrease Poportional Influence", ""},
508 {TFM_MODAL_AUTOIK_LEN_INC, "AUTOIK_CHAIN_LEN_UP", 0, "Increase Max AutoIK Chain Length", ""},
509 {TFM_MODAL_AUTOIK_LEN_DEC, "AUTOIK_CHAIN_LEN_DOWN", 0, "Decrease Max AutoIK Chain Length", ""},
510 {0, NULL, 0, NULL, NULL}};
512 wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "Transform Modal Map");
514 /* this function is called for each spacetype, only needs to add map once */
515 if(keymap) return NULL;
517 keymap= WM_modalkeymap_add(keyconf, "Transform Modal Map", modal_items);
519 /* items for modal map */
520 WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CANCEL);
521 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
522 WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
523 WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
525 WM_modalkeymap_add_item(keymap, GKEY, KM_PRESS, 0, 0, TFM_MODAL_TRANSLATE);
526 WM_modalkeymap_add_item(keymap, RKEY, KM_PRESS, 0, 0, TFM_MODAL_ROTATE);
527 WM_modalkeymap_add_item(keymap, SKEY, KM_PRESS, 0, 0, TFM_MODAL_RESIZE);
529 WM_modalkeymap_add_item(keymap, TABKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_SNAP_TOGGLE);
531 WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_SNAP_INV_ON);
532 WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, TFM_MODAL_SNAP_INV_OFF);
534 WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_SNAP_INV_ON);
535 WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_RELEASE, KM_ANY, 0, TFM_MODAL_SNAP_INV_OFF);
537 WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, 0, 0, TFM_MODAL_ADD_SNAP);
538 WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, KM_ALT, 0, TFM_MODAL_REMOVE_SNAP);
540 WM_modalkeymap_add_item(keymap, PAGEUPKEY, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_UP);
541 WM_modalkeymap_add_item(keymap, PAGEDOWNKEY, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_DOWN);
542 WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_UP);
543 WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_DOWN);
545 WM_modalkeymap_add_item(keymap, PAGEUPKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_INC);
546 WM_modalkeymap_add_item(keymap, PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_DEC);
547 WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_INC);
548 WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_DEC);
554 int transformEvent(TransInfo *t, wmEvent *event)
556 float mati[3][3]= MAT3_UNITY;
557 char cmode = constraintModeToChar(t);
560 t->redraw |= handleMouseInput(t, &t->mouse, event);
562 if (event->type == MOUSEMOVE)
564 if (t->modifiers & MOD_CONSTRAINT_SELECT)
565 t->con.mode |= CON_SELECT;
567 t->mval[0] = event->x - t->ar->winrct.xmin;
568 t->mval[1] = event->y - t->ar->winrct.ymin;
570 // t->redraw |= TREDRAW_SOFT; /* Use this for soft redraw. Might cause flicker in object mode */
571 t->redraw |= TREDRAW_HARD;
574 if (t->state == TRANS_STARTING) {
575 t->state = TRANS_RUNNING;
578 applyMouseInput(t, &t->mouse, t->mval, t->values);
581 /* handle modal keymap first */
582 if (event->type == EVT_MODAL_MAP) {
583 switch (event->val) {
584 case TFM_MODAL_CANCEL:
585 t->state = TRANS_CANCEL;
587 case TFM_MODAL_CONFIRM:
588 t->state = TRANS_CONFIRM;
590 case TFM_MODAL_TRANSLATE:
591 /* only switch when... */
592 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
593 resetTransRestrictions(t);
594 restoreTransObjects(t);
596 initSnapping(t, NULL); // need to reinit after mode change
597 t->redraw |= TREDRAW_HARD;
600 case TFM_MODAL_ROTATE:
601 /* only switch when... */
602 if(!(t->options & CTX_TEXTURE)) {
603 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
605 resetTransRestrictions(t);
607 if (t->mode == TFM_ROTATION) {
608 restoreTransObjects(t);
612 restoreTransObjects(t);
615 initSnapping(t, NULL); // need to reinit after mode change
616 t->redraw |= TREDRAW_HARD;
620 case TFM_MODAL_RESIZE:
621 /* only switch when... */
622 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
623 resetTransRestrictions(t);
624 restoreTransObjects(t);
626 initSnapping(t, NULL); // need to reinit after mode change
627 t->redraw |= TREDRAW_HARD;
631 case TFM_MODAL_SNAP_INV_ON:
632 t->modifiers |= MOD_SNAP_INVERT;
633 t->redraw |= TREDRAW_HARD;
635 case TFM_MODAL_SNAP_INV_OFF:
636 t->modifiers &= ~MOD_SNAP_INVERT;
637 t->redraw |= TREDRAW_HARD;
639 case TFM_MODAL_SNAP_TOGGLE:
640 t->modifiers ^= MOD_SNAP;
641 t->redraw |= TREDRAW_HARD;
643 case TFM_MODAL_AXIS_X:
644 if ((t->flag & T_NO_CONSTRAINT)==0) {
649 if (t->flag & T_2D_EDIT) {
650 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0), "along X");
653 setUserConstraint(t, t->current_orientation, (CON_AXIS0), "along %s X");
656 t->redraw |= TREDRAW_HARD;
659 case TFM_MODAL_AXIS_Y:
660 if ((t->flag & T_NO_CONSTRAINT)==0) {
665 if (t->flag & T_2D_EDIT) {
666 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1), "along Y");
669 setUserConstraint(t, t->current_orientation, (CON_AXIS1), "along %s Y");
672 t->redraw |= TREDRAW_HARD;
675 case TFM_MODAL_AXIS_Z:
676 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
681 setUserConstraint(t, t->current_orientation, (CON_AXIS2), "along %s Z");
683 t->redraw |= TREDRAW_HARD;
686 case TFM_MODAL_PLANE_X:
687 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
692 setUserConstraint(t, t->current_orientation, (CON_AXIS1|CON_AXIS2), "locking %s X");
694 t->redraw |= TREDRAW_HARD;
697 case TFM_MODAL_PLANE_Y:
698 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
703 setUserConstraint(t, t->current_orientation, (CON_AXIS0|CON_AXIS2), "locking %s Y");
705 t->redraw |= TREDRAW_HARD;
708 case TFM_MODAL_PLANE_Z:
709 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
714 setUserConstraint(t, t->current_orientation, (CON_AXIS0|CON_AXIS1), "locking %s Z");
716 t->redraw |= TREDRAW_HARD;
719 case TFM_MODAL_CONS_OFF:
720 if ((t->flag & T_NO_CONSTRAINT)==0) {
722 t->redraw |= TREDRAW_HARD;
725 case TFM_MODAL_ADD_SNAP:
727 t->redraw |= TREDRAW_HARD;
729 case TFM_MODAL_REMOVE_SNAP:
731 t->redraw |= TREDRAW_HARD;
733 case TFM_MODAL_PROPSIZE_UP:
734 if(t->flag & T_PROP_EDIT) {
736 if(t->spacetype==SPACE_VIEW3D && t->persp != RV3D_ORTHO)
737 t->prop_size= MIN2(t->prop_size, ((View3D *)t->view)->far);
738 calculatePropRatio(t);
740 t->redraw |= TREDRAW_HARD;
742 case TFM_MODAL_PROPSIZE_DOWN:
743 if (t->flag & T_PROP_EDIT) {
744 t->prop_size*= 0.90909090f;
745 calculatePropRatio(t);
747 t->redraw |= TREDRAW_HARD;
749 case TFM_MODAL_AUTOIK_LEN_INC:
750 if (t->flag & T_AUTOIK)
751 transform_autoik_update(t, 1);
752 t->redraw |= TREDRAW_HARD;
754 case TFM_MODAL_AUTOIK_LEN_DEC:
755 if (t->flag & T_AUTOIK)
756 transform_autoik_update(t, -1);
757 t->redraw |= TREDRAW_HARD;
764 // Modal numinput events
765 t->redraw |= handleNumInput(&(t->num), event);
767 /* else do non-mapped events */
768 else if (event->val==KM_PRESS) {
769 switch (event->type){
771 t->state = TRANS_CANCEL;
773 /* enforce redraw of transform when modifiers are used */
776 t->modifiers |= MOD_CONSTRAINT_PLANE;
777 t->redraw |= TREDRAW_HARD;
781 if ((t->spacetype==SPACE_VIEW3D) && event->alt) {
782 #if 0 // TRANSFORM_FIX_ME
786 BIF_selectOrientation();
787 calc_manipulator_stats(curarea);
788 copy_m3_m4(t->spacemtx, G.vd->twmat);
789 warp_pointer(mval[0], mval[1]);
793 t->state = TRANS_CONFIRM;
798 if ((t->flag & T_NO_CONSTRAINT)==0) {
799 /* exception for switching to dolly, or trackball, in camera view */
800 if (t->flag & T_CAMERA) {
801 if (t->mode==TFM_TRANSLATION)
802 setLocalConstraint(t, (CON_AXIS2), "along local Z");
803 else if (t->mode==TFM_ROTATION) {
804 restoreTransObjects(t);
809 t->modifiers |= MOD_CONSTRAINT_SELECT;
810 if (t->con.mode & CON_APPLY) {
815 initSelectConstraint(t, t->spacemtx);
818 /* bit hackish... but it prevents mmb select to print the orientation from menu */
819 strcpy(t->spacename, "global");
820 initSelectConstraint(t, mati);
822 postSelectConstraint(t);
825 t->redraw |= TREDRAW_HARD;
829 t->state = TRANS_CANCEL;
833 t->state = TRANS_CONFIRM;
836 /* only switch when... */
837 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
838 resetTransRestrictions(t);
839 restoreTransObjects(t);
841 initSnapping(t, NULL); // need to reinit after mode change
842 t->redraw |= TREDRAW_HARD;
846 /* only switch when... */
847 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
848 resetTransRestrictions(t);
849 restoreTransObjects(t);
851 initSnapping(t, NULL); // need to reinit after mode change
852 t->redraw |= TREDRAW_HARD;
856 /* only switch when... */
857 if(!(t->options & CTX_TEXTURE)) {
858 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
860 resetTransRestrictions(t);
862 if (t->mode == TFM_ROTATION) {
863 restoreTransObjects(t);
867 restoreTransObjects(t);
870 initSnapping(t, NULL); // need to reinit after mode change
871 t->redraw |= TREDRAW_HARD;
877 t->flag ^= T_PROP_CONNECTED;
878 sort_trans_data_dist(t);
879 calculatePropRatio(t);
884 t->redraw |= TREDRAW_HARD;
888 if ((t->flag & T_NO_CONSTRAINT)==0) {
889 if (t->flag & T_2D_EDIT) {
893 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0), "along X");
897 if (t->con.orientation != V3D_MANIP_GLOBAL) {
900 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
901 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
902 setUserConstraint(t, orientation, (CON_AXIS0), "along %s X");
903 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
904 setUserConstraint(t, orientation, (CON_AXIS1|CON_AXIS2), "locking %s X");
907 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
908 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0), "along %s X");
909 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
910 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1|CON_AXIS2), "locking %s X");
913 t->redraw |= TREDRAW_HARD;
917 if ((t->flag & T_NO_CONSTRAINT)==0) {
918 if (t->flag & T_2D_EDIT) {
922 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1), "along Y");
926 if (t->con.orientation != V3D_MANIP_GLOBAL) {
929 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
930 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
931 setUserConstraint(t, orientation, (CON_AXIS1), "along %s Y");
932 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
933 setUserConstraint(t, orientation, (CON_AXIS0|CON_AXIS2), "locking %s Y");
936 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
937 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1), "along %s Y");
938 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
939 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0|CON_AXIS2), "locking %s Y");
942 t->redraw |= TREDRAW_HARD;
946 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))==0) {
948 if (t->con.orientation != V3D_MANIP_GLOBAL) {
951 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
952 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
953 setUserConstraint(t, orientation, (CON_AXIS2), "along %s Z");
954 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
955 setUserConstraint(t, orientation, (CON_AXIS0|CON_AXIS1), "locking %s Z");
958 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
959 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS2), "along %s Z");
960 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
961 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0|CON_AXIS1), "locking %s Z");
963 t->redraw |= TREDRAW_HARD;
967 if (t->flag & T_PROP_EDIT && event->shift) {
968 t->prop_mode = (t->prop_mode + 1) % 6;
969 calculatePropRatio(t);
970 t->redraw |= TREDRAW_HARD;
974 if(event->alt && t->flag & T_PROP_EDIT) {
975 t->prop_size *= 1.1f;
976 if(t->spacetype==SPACE_VIEW3D && t->persp != RV3D_ORTHO)
977 t->prop_size= MIN2(t->prop_size, ((View3D *)t->view)->far);
978 calculatePropRatio(t);
984 if (t->flag & T_AUTOIK) {
985 transform_autoik_update(t, 1);
987 else view_editmove(event->type);
991 if(event->alt && t->flag & T_PROP_EDIT) {
992 t->prop_size*= 0.90909090f;
993 calculatePropRatio(t);
999 if (t->flag & T_AUTOIK) {
1000 transform_autoik_update(t, -1);
1002 else view_editmove(event->type);
1013 // Numerical input events
1014 t->redraw |= handleNumInput(&(t->num), event);
1016 // NDof input events
1017 switch(handleNDofInput(&(t->ndof), event))
1020 if ((t->options & CTX_NDOF) == 0)
1022 /* Confirm on normal transform only */
1023 t->state = TRANS_CONFIRM;
1027 if (t->options & CTX_NDOF)
1029 /* Cancel on pure NDOF transform */
1030 t->state = TRANS_CANCEL;
1034 /* Otherwise, just redraw, NDof input was cancelled */
1035 t->redraw |= TREDRAW_HARD;
1039 if (t->options & CTX_NDOF)
1041 /* Confirm on pure NDOF transform */
1042 t->state = TRANS_CONFIRM;
1046 t->redraw |= TREDRAW_HARD;
1054 t->redraw |= handleSnapping(t, event);
1057 else if (event->val==KM_RELEASE) {
1058 switch (event->type){
1061 t->modifiers &= ~MOD_CONSTRAINT_PLANE;
1062 t->redraw |= TREDRAW_HARD;
1066 if ((t->flag & T_NO_CONSTRAINT)==0) {
1067 t->modifiers &= ~MOD_CONSTRAINT_SELECT;
1068 postSelectConstraint(t);
1069 t->redraw |= TREDRAW_HARD;
1074 // if(WM_modal_tweak_exit(event, t->event_type))
1075 //// if (t->options & CTX_TWEAK)
1076 // t->state = TRANS_CONFIRM;
1083 /* confirm transform if launch key is released after mouse move */
1084 if (t->flag & T_RELEASE_CONFIRM)
1086 /* XXX Keyrepeat bug in Xorg fucks this up, will test when fixed */
1087 if (event->type == t->launch_event && (t->launch_event == LEFTMOUSE || t->launch_event == RIGHTMOUSE))
1089 t->state = TRANS_CONFIRM;
1094 // Per transform event, if present
1096 t->redraw |= t->handleEvent(t, event);
1098 if (handled || t->redraw)
1101 return OPERATOR_PASS_THROUGH;
1104 int calculateTransformCenter(bContext *C, int centerMode, float *vec)
1106 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data");
1109 t->state = TRANS_RUNNING;
1111 t->options = CTX_NONE;
1113 t->mode = TFM_DUMMY;
1115 initTransInfo(C, t, NULL, NULL); // internal data, mouse, vectors
1117 createTransData(C, t); // make TransData structs from selection
1119 t->around = centerMode; // override userdefined mode
1121 if (t->total == 0) {
1129 // Copy center from constraint center. Transform center can be local
1130 VECCOPY(vec, t->con.center);
1134 /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
1135 special_aftertrans_update(C, t);
1150 static void drawArrow(ArrowDirection d, short offset, short length, short size)
1160 glVertex2s( offset, 0);
1161 glVertex2s( offset + length, 0);
1162 glVertex2s( offset + length, 0);
1163 glVertex2s( offset + length - size, -size);
1164 glVertex2s( offset + length, 0);
1165 glVertex2s( offset + length - size, size);
1174 glVertex2s( 0, offset);
1175 glVertex2s( 0, offset + length);
1176 glVertex2s( 0, offset + length);
1177 glVertex2s(-size, offset + length - size);
1178 glVertex2s( 0, offset + length);
1179 glVertex2s( size, offset + length - size);
1185 static void drawArrowHead(ArrowDirection d, short size)
1194 glVertex2s( -size, -size);
1196 glVertex2s( -size, size);
1204 glVertex2s(-size, -size);
1206 glVertex2s( size, -size);
1212 static void drawArc(float size, float angle_start, float angle_end, int segments)
1214 float delta = (angle_end - angle_start) / segments;
1217 glBegin(GL_LINE_STRIP);
1219 for( angle = angle_start; angle < angle_end; angle += delta)
1221 glVertex2f( cosf(angle) * size, sinf(angle) * size);
1223 glVertex2f( cosf(angle_end) * size, sinf(angle_end) * size);
1228 static int helpline_poll(bContext *C)
1230 ARegion *ar= CTX_wm_region(C);
1232 if(ar && ar->regiontype==RGN_TYPE_WINDOW)
1237 static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
1239 TransInfo *t = (TransInfo*)customdata;
1241 if (t->helpline != HLP_NONE && !(t->flag & T_USES_MANIPULATOR))
1243 float vecrot[3], cent[2];
1249 VECCOPY(vecrot, t->center);
1250 if(t->flag & T_EDIT) {
1251 Object *ob= t->obedit;
1252 if(ob) mul_m4_v3(ob->obmat, vecrot);
1254 else if(t->flag & T_POSE) {
1255 Object *ob=t->poseobj;
1256 if(ob) mul_m4_v3(ob->obmat, vecrot);
1259 projectFloatView(t, vecrot, cent); // no overflow in extreme cases
1266 UI_ThemeColor(TH_WIRE);
1269 glBegin(GL_LINE_STRIP);
1270 glVertex2sv(t->mval);
1274 glTranslatef(mval[0], mval[1], 0);
1275 glRotatef(-RAD2DEGF(atan2f(cent[0] - t->mval[0], cent[1] - t->mval[1])), 0, 0, 1);
1279 drawArrow(UP, 5, 10, 5);
1280 drawArrow(DOWN, 5, 10, 5);
1284 UI_ThemeColor(TH_WIRE);
1286 glTranslatef(mval[0], mval[1], 0);
1289 drawArrow(RIGHT, 5, 10, 5);
1290 drawArrow(LEFT, 5, 10, 5);
1294 UI_ThemeColor(TH_WIRE);
1296 glTranslatef(mval[0], mval[1], 0);
1300 drawArrow(UP, 5, 10, 5);
1301 drawArrow(DOWN, 5, 10, 5);
1306 float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
1307 float angle = atan2f(dy, dx);
1308 float dist = sqrtf(dx*dx + dy*dy);
1309 float delta_angle = MIN2(15.0f / dist, (float)M_PI/4.0f);
1310 float spacing_angle = MIN2(5.0f / dist, (float)M_PI/12.0f);
1311 UI_ThemeColor(TH_WIRE);
1314 glBegin(GL_LINE_STRIP);
1315 glVertex2sv(t->mval);
1319 glTranslatef(cent[0] - t->mval[0] + mval[0], cent[1] - t->mval[1] + mval[1], 0);
1323 drawArc(dist, angle - delta_angle, angle - spacing_angle, 10);
1324 drawArc(dist, angle + spacing_angle, angle + delta_angle, 10);
1328 glTranslatef(cosf(angle - delta_angle) * dist, sinf(angle - delta_angle) * dist, 0);
1329 glRotatef(RAD2DEGF(angle - delta_angle), 0, 0, 1);
1331 drawArrowHead(DOWN, 5);
1335 glTranslatef(cosf(angle + delta_angle) * dist, sinf(angle + delta_angle) * dist, 0);
1336 glRotatef(RAD2DEGF(angle + delta_angle), 0, 0, 1);
1338 drawArrowHead(UP, 5);
1345 unsigned char col[3], col2[3];
1346 UI_GetThemeColor3ubv(TH_GRID, col);
1348 glTranslatef(mval[0], mval[1], 0);
1352 UI_make_axis_color(col, col2, 'X');
1353 glColor3ubv((GLubyte *)col2);
1355 drawArrow(RIGHT, 5, 10, 5);
1356 drawArrow(LEFT, 5, 10, 5);
1358 UI_make_axis_color(col, col2, 'Y');
1359 glColor3ubv((GLubyte *)col2);
1361 drawArrow(UP, 5, 10, 5);
1362 drawArrow(DOWN, 5, 10, 5);
1372 static void drawTransformView(const struct bContext *C, struct ARegion *UNUSED(ar), void *arg)
1377 drawPropCircle(C, t);
1382 static void drawTransformPixel(const struct bContext *UNUSED(C), struct ARegion *UNUSED(ar), void *UNUSED(arg))
1384 // TransInfo *t = arg;
1386 // drawHelpline(C, t->mval[0], t->mval[1], t);
1390 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
1392 ToolSettings *ts = CTX_data_tool_settings(C);
1393 int constraint_axis[3] = {0, 0, 0};
1394 int proportional = 0;
1396 if (RNA_struct_find_property(op->ptr, "value"))
1398 if (t->flag & T_AUTOVALUES)
1400 RNA_float_set_array(op->ptr, "value", t->auto_values);
1404 RNA_float_set_array(op->ptr, "value", t->values);
1408 /* convert flag to enum */
1409 switch(t->flag & (T_PROP_EDIT|T_PROP_CONNECTED))
1411 case (T_PROP_EDIT|T_PROP_CONNECTED):
1412 proportional = PROP_EDIT_CONNECTED;
1415 proportional = PROP_EDIT_ON;
1418 proportional = PROP_EDIT_OFF;
1421 // If modal, save settings back in scene if not set as operator argument
1422 if (t->flag & T_MODAL) {
1424 /* save settings if not set in operator */
1425 if (RNA_struct_find_property(op->ptr, "proportional") && !RNA_property_is_set(op->ptr, "proportional")) {
1427 ts->proportional = proportional;
1429 ts->proportional_objects = (proportional != PROP_EDIT_OFF);
1432 if (RNA_struct_find_property(op->ptr, "proportional_size") && !RNA_property_is_set(op->ptr, "proportional_size")) {
1433 ts->proportional_size = t->prop_size;
1436 if (RNA_struct_find_property(op->ptr, "proportional_edit_falloff") && !RNA_property_is_set(op->ptr, "proportional_edit_falloff")) {
1437 ts->prop_mode = t->prop_mode;
1440 /* do we check for parameter? */
1441 if (t->modifiers & MOD_SNAP) {
1442 ts->snap_flag |= SCE_SNAP;
1444 ts->snap_flag &= ~SCE_SNAP;
1447 if(t->spacetype == SPACE_VIEW3D) {
1448 if (RNA_struct_find_property(op->ptr, "constraint_orientation") && !RNA_property_is_set(op->ptr, "constraint_orientation")) {
1449 View3D *v3d = t->view;
1451 v3d->twmode = t->current_orientation;
1456 if (RNA_struct_find_property(op->ptr, "proportional"))
1458 RNA_enum_set(op->ptr, "proportional", proportional);
1459 RNA_enum_set(op->ptr, "proportional_edit_falloff", t->prop_mode);
1460 RNA_float_set(op->ptr, "proportional_size", t->prop_size);
1463 if (RNA_struct_find_property(op->ptr, "axis"))
1465 RNA_float_set_array(op->ptr, "axis", t->axis);
1468 if (RNA_struct_find_property(op->ptr, "mirror"))
1470 RNA_boolean_set(op->ptr, "mirror", t->flag & T_MIRROR);
1473 if (RNA_struct_find_property(op->ptr, "constraint_axis"))
1475 /* constraint orientation can be global, event if user selects something else
1476 * so use the orientation in the constraint if set
1478 if (t->con.mode & CON_APPLY) {
1479 RNA_enum_set(op->ptr, "constraint_orientation", t->con.orientation);
1481 RNA_enum_set(op->ptr, "constraint_orientation", t->current_orientation);
1484 if (t->con.mode & CON_APPLY)
1486 if (t->con.mode & CON_AXIS0) {
1487 constraint_axis[0] = 1;
1489 if (t->con.mode & CON_AXIS1) {
1490 constraint_axis[1] = 1;
1492 if (t->con.mode & CON_AXIS2) {
1493 constraint_axis[2] = 1;
1497 RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis);
1501 /* note: caller needs to free 't' on a 0 return */
1502 int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int mode)
1508 /* added initialize, for external calls to set stuff in TransInfo, like undo string */
1510 t->state = TRANS_STARTING;
1512 if(RNA_struct_find_property(op->ptr, "texture_space"))
1513 if(RNA_boolean_get(op->ptr, "texture_space"))
1514 options |= CTX_TEXTURE;
1516 t->options = options;
1520 t->launch_event = event ? event->type : -1;
1522 if (t->launch_event == EVT_TWEAK_R)
1524 t->launch_event = RIGHTMOUSE;
1526 else if (t->launch_event == EVT_TWEAK_L)
1528 t->launch_event = LEFTMOUSE;
1531 // XXX Remove this when wm_operator_call_internal doesn't use window->eventstate (which can have type = 0)
1532 // For manipulator only, so assume LEFTMOUSE
1533 if (t->launch_event == 0)
1535 t->launch_event = LEFTMOUSE;
1538 if (!initTransInfo(C, t, op, event)) // internal data, mouse, vectors
1543 if(t->spacetype == SPACE_VIEW3D)
1545 //calc_manipulator_stats(curarea);
1546 initTransformOrientation(C, t);
1548 t->draw_handle_apply = ED_region_draw_cb_activate(t->ar->type, drawTransformApply, t, REGION_DRAW_PRE_VIEW);
1549 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
1550 //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
1551 t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
1553 else if(t->spacetype == SPACE_IMAGE) {
1554 unit_m3(t->spacemtx);
1555 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
1556 //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
1559 unit_m3(t->spacemtx);
1561 createTransData(C, t); // make TransData structs from selection
1563 if (t->total == 0) {
1568 /* Stupid code to have Ctrl-Click on manipulator work ok */
1571 wmKeyMap *keymap = WM_keymap_active(CTX_wm_manager(C), op->type->modalkeymap);
1574 for (kmi = keymap->items.first; kmi; kmi = kmi->next)
1576 if (kmi->propvalue == TFM_MODAL_SNAP_INV_ON && kmi->val == KM_PRESS)
1578 if ((ELEM(kmi->type, LEFTCTRLKEY, RIGHTCTRLKEY) && event->ctrl) ||
1579 (ELEM(kmi->type, LEFTSHIFTKEY, RIGHTSHIFTKEY) && event->shift) ||
1580 (ELEM(kmi->type, LEFTALTKEY, RIGHTALTKEY) && event->alt) ||
1581 (kmi->type == OSKEY && event->oskey)) {
1582 t->modifiers |= MOD_SNAP_INVERT;
1590 initSnapping(t, op); // Initialize snapping data AFTER mode flags
1592 /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
1593 /* EVIL2: we gave as argument also texture space context bit... was cleared */
1594 /* EVIL3: extend mode for animation editors also switches modes... but is best way to avoid duplicate code */
1597 calculatePropRatio(t);
1600 initMouseInput(t, &t->mouse, t->center2d, t->imval);
1603 case TFM_TRANSLATION:
1621 case TFM_SHRINKFATTEN:
1622 initShrinkFatten(t);
1627 case TFM_CURVE_SHRINKFATTEN:
1628 initCurveShrinkFatten(t);
1640 { /* used for both B-Bone width (bonesize) as for deform-dist (envelope) */
1641 bArmature *arm= t->poseobj->data;
1642 if(arm->drawtype==ARM_ENVELOPE)
1643 initBoneEnvelope(t);
1648 case TFM_BONE_ENVELOPE:
1649 initBoneEnvelope(t);
1651 case TFM_EDGE_SLIDE:
1657 case TFM_TIME_TRANSLATE:
1658 initTimeTranslate(t);
1660 case TFM_TIME_SLIDE:
1663 case TFM_TIME_SCALE:
1666 case TFM_TIME_DUPLICATE:
1667 /* same as TFM_TIME_EXTEND, but we need the mode info for later
1668 * so that duplicate-culling will work properly
1670 if ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)
1673 initTimeTranslate(t);
1676 case TFM_TIME_EXTEND:
1677 /* now that transdata has been made, do like for TFM_TIME_TRANSLATE (for most Animation
1678 * Editors because they have only 1D transforms for time values) or TFM_TRANSLATION
1679 * (for Graph/NLA Editors only since they uses 'standard' transforms to get 2D movement)
1680 * depending on which editor this was called from
1682 if ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)
1685 initTimeTranslate(t);
1707 if(t->state == TRANS_CANCEL)
1714 /* overwrite initial values if operator supplied a non-null vector */
1715 if (RNA_property_is_set(op->ptr, "value"))
1717 float values[4]= {0}; /* incase value isn't length 4, avoid uninitialized memory */
1718 RNA_float_get_array(op->ptr, "value", values);
1719 QUATCOPY(t->values, values);
1720 QUATCOPY(t->auto_values, values);
1721 t->flag |= T_AUTOVALUES;
1724 /* Transformation axis from operator */
1725 if (RNA_struct_find_property(op->ptr, "axis") && RNA_property_is_set(op->ptr, "axis"))
1727 RNA_float_get_array(op->ptr, "axis", t->axis);
1728 normalize_v3(t->axis);
1729 copy_v3_v3(t->axis_orig, t->axis);
1732 /* Constraint init from operator */
1733 if (RNA_struct_find_property(op->ptr, "constraint_axis") && RNA_property_is_set(op->ptr, "constraint_axis"))
1735 int constraint_axis[3];
1737 RNA_boolean_get_array(op->ptr, "constraint_axis", constraint_axis);
1739 if (constraint_axis[0] || constraint_axis[1] || constraint_axis[2])
1741 t->con.mode |= CON_APPLY;
1743 if (constraint_axis[0]) {
1744 t->con.mode |= CON_AXIS0;
1746 if (constraint_axis[1]) {
1747 t->con.mode |= CON_AXIS1;
1749 if (constraint_axis[2]) {
1750 t->con.mode |= CON_AXIS2;
1753 setUserConstraint(t, t->current_orientation, t->con.mode, "%s");
1762 void transformApply(bContext *C, TransInfo *t)
1766 if ((t->redraw & TREDRAW_HARD) || (t->draw_handle_apply == NULL && (t->redraw & TREDRAW_SOFT)))
1768 selectConstraint(t);
1770 t->transform(t, t->mval); // calls recalcData()
1771 viewRedrawForce(C, t);
1773 t->redraw = TREDRAW_NOTHING;
1774 } else if (t->redraw & TREDRAW_SOFT) {
1775 viewRedrawForce(C, t);
1778 /* If auto confirm is on, break after one pass */
1779 if (t->options & CTX_AUTOCONFIRM)
1781 t->state = TRANS_CONFIRM;
1784 if (BKE_ptcache_get_continue_physics())
1787 //do_screenhandlers(G.curscreen);
1788 t->redraw |= TREDRAW_HARD;
1794 void drawTransformApply(const bContext *C, struct ARegion *UNUSED(ar), void *arg)
1798 if (t->redraw & TREDRAW_SOFT) {
1799 t->redraw |= TREDRAW_HARD;
1800 transformApply((bContext *)C, t);
1804 int transformEnd(bContext *C, TransInfo *t)
1806 int exit_code = OPERATOR_RUNNING_MODAL;
1810 if (t->state != TRANS_STARTING && t->state != TRANS_RUNNING)
1812 /* handle restoring objects */
1813 if(t->state == TRANS_CANCEL)
1815 /* exception, edge slide transformed UVs too */
1816 if(t->mode==TFM_EDGE_SLIDE)
1817 doEdgeSlide(t, 0.0f);
1819 exit_code = OPERATOR_CANCELLED;
1820 restoreTransObjects(t); // calls recalcData()
1824 exit_code = OPERATOR_FINISHED;
1827 /* aftertrans does insert keyframes, and clears base flags, doesnt read transdata */
1828 special_aftertrans_update(C, t);
1833 /* send events out for redraws */
1834 viewRedrawPost(C, t);
1836 /* Undo as last, certainly after special_trans_update! */
1838 if(t->state == TRANS_CANCEL) {
1839 // if(t->undostr) ED_undo_push(C, t->undostr);
1842 // if(t->undostr) ED_undo_push(C, t->undostr);
1843 // else ED_undo_push(C, transform_to_undostr(t));
1847 viewRedrawForce(C, t);
1855 /* ************************** TRANSFORM LOCKS **************************** */
1857 static void protectedTransBits(short protectflag, float *vec)
1859 if(protectflag & OB_LOCK_LOCX)
1861 if(protectflag & OB_LOCK_LOCY)
1863 if(protectflag & OB_LOCK_LOCZ)
1867 static void protectedSizeBits(short protectflag, float *size)
1869 if(protectflag & OB_LOCK_SCALEX)
1871 if(protectflag & OB_LOCK_SCALEY)
1873 if(protectflag & OB_LOCK_SCALEZ)
1877 static void protectedRotateBits(short protectflag, float *eul, float *oldeul)
1879 if(protectflag & OB_LOCK_ROTX)
1881 if(protectflag & OB_LOCK_ROTY)
1883 if(protectflag & OB_LOCK_ROTZ)
1888 /* this function only does the delta rotation */
1889 /* axis-angle is usually internally stored as quats... */
1890 static void protectedAxisAngleBits(short protectflag, float axis[3], float *angle, float oldAxis[3], float oldAngle)
1892 /* check that protection flags are set */
1893 if ((protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) == 0)
1896 if (protectflag & OB_LOCK_ROT4D) {
1897 /* axis-angle getting limited as 4D entities that they are... */
1898 if (protectflag & OB_LOCK_ROTW)
1900 if (protectflag & OB_LOCK_ROTX)
1901 axis[0]= oldAxis[0];
1902 if (protectflag & OB_LOCK_ROTY)
1903 axis[1]= oldAxis[1];
1904 if (protectflag & OB_LOCK_ROTZ)
1905 axis[2]= oldAxis[2];
1908 /* axis-angle get limited with euler... */
1909 float eul[3], oldeul[3];
1911 axis_angle_to_eulO( eul, EULER_ORDER_DEFAULT,axis, *angle);
1912 axis_angle_to_eulO( oldeul, EULER_ORDER_DEFAULT,oldAxis, oldAngle);
1914 if (protectflag & OB_LOCK_ROTX)
1916 if (protectflag & OB_LOCK_ROTY)
1918 if (protectflag & OB_LOCK_ROTZ)
1921 eulO_to_axis_angle( axis, angle,eul, EULER_ORDER_DEFAULT);
1923 /* when converting to axis-angle, we need a special exception for the case when there is no axis */
1924 if (IS_EQF(axis[0], axis[1]) && IS_EQF(axis[1], axis[2])) {
1925 /* for now, rotate around y-axis then (so that it simply becomes the roll) */
1931 /* this function only does the delta rotation */
1932 static void protectedQuaternionBits(short protectflag, float *quat, float *oldquat)
1934 /* check that protection flags are set */
1935 if ((protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) == 0)
1938 if (protectflag & OB_LOCK_ROT4D) {
1939 /* quaternions getting limited as 4D entities that they are... */
1940 if (protectflag & OB_LOCK_ROTW)
1941 quat[0]= oldquat[0];
1942 if (protectflag & OB_LOCK_ROTX)
1943 quat[1]= oldquat[1];
1944 if (protectflag & OB_LOCK_ROTY)
1945 quat[2]= oldquat[2];
1946 if (protectflag & OB_LOCK_ROTZ)
1947 quat[3]= oldquat[3];
1950 /* quaternions get limited with euler... (compatability mode) */
1951 float eul[3], oldeul[3], nquat[4], noldquat[4];
1954 qlen= normalize_qt_qt(nquat, quat);
1955 normalize_qt_qt(noldquat, oldquat);
1957 quat_to_eul(eul, nquat);
1958 quat_to_eul(oldeul, noldquat);
1960 if (protectflag & OB_LOCK_ROTX)
1962 if (protectflag & OB_LOCK_ROTY)
1964 if (protectflag & OB_LOCK_ROTZ)
1967 eul_to_quat( quat,eul);
1969 /* restore original quat size */
1970 mul_qt_fl(quat, qlen);
1972 /* quaternions flip w sign to accumulate rotations correctly */
1973 if ( (nquat[0]<0.0f && quat[0]>0.0f) || (nquat[0]>0.0f && quat[0]<0.0f) ) {
1974 mul_qt_fl(quat, -1.0f);
1979 /* ******************* TRANSFORM LIMITS ********************** */
1981 static void constraintTransLim(TransInfo *UNUSED(t), TransData *td)
1984 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
1985 bConstraintOb cob= {NULL};
1988 /* Make a temporary bConstraintOb for using these limit constraints
1989 * - they only care that cob->matrix is correctly set ;-)
1990 * - current space should be local
1992 unit_m4(cob.matrix);
1993 VECCOPY(cob.matrix[3], td->loc);
1995 /* Evaluate valid constraints */
1996 for (con= td->con; con; con= con->next) {
1999 /* only consider constraint if enabled */
2000 if (con->flag & CONSTRAINT_DISABLE) continue;
2001 if (con->enforce == 0.0f) continue;
2003 /* only use it if it's tagged for this purpose (and the right type) */
2004 if (con->type == CONSTRAINT_TYPE_LOCLIMIT) {
2005 bLocLimitConstraint *data= con->data;
2007 if ((data->flag2 & LIMIT_TRANSFORM)==0)
2010 /* do space conversions */
2011 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2012 /* just multiply by td->mtx (this should be ok) */
2013 copy_m4_m4(tmat, cob.matrix);
2014 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
2016 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
2017 /* skip... incompatable spacetype */
2022 cti->evaluate_constraint(con, &cob, NULL);
2024 /* convert spaces again */
2025 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2026 /* just multiply by td->mtx (this should be ok) */
2027 copy_m4_m4(tmat, cob.matrix);
2028 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
2033 /* copy results from cob->matrix */
2034 VECCOPY(td->loc, cob.matrix[3]);
2038 static void constraintob_from_transdata(bConstraintOb *cob, TransData *td)
2040 /* Make a temporary bConstraintOb for use by limit constraints
2041 * - they only care that cob->matrix is correctly set ;-)
2042 * - current space should be local
2044 memset(cob, 0, sizeof(bConstraintOb));
2047 if (td->ext->rotOrder == ROT_MODE_QUAT) {
2049 /* objects and bones do normalization first too, otherwise
2050 we don't necessarily end up with a rotation matrix, and
2051 then conversion back to quat gives a different result */
2053 normalize_qt_qt(quat, td->ext->quat);
2054 quat_to_mat4(cob->matrix, quat);
2056 else if (td->ext->rotOrder == ROT_MODE_AXISANGLE) {
2058 axis_angle_to_mat4(cob->matrix, &td->ext->quat[1], td->ext->quat[0]);
2062 eulO_to_mat4(cob->matrix, td->ext->rot, td->ext->rotOrder);
2067 static void constraintRotLim(TransInfo *UNUSED(t), TransData *td)
2070 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
2075 /* Evaluate valid constraints */
2076 for (con= td->con; con; con= con->next) {
2077 /* only consider constraint if enabled */
2078 if (con->flag & CONSTRAINT_DISABLE) continue;
2079 if (con->enforce == 0.0f) continue;
2081 /* we're only interested in Limit-Rotation constraints */
2082 if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
2083 bRotLimitConstraint *data= con->data;
2086 /* only use it if it's tagged for this purpose */
2087 if ((data->flag2 & LIMIT_TRANSFORM)==0)
2090 /* skip incompatable spacetypes */
2091 if (!ELEM(con->ownspace, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL))
2094 /* only do conversion if necessary, to preserve quats and eulers */
2096 constraintob_from_transdata(&cob, td);
2100 /* do space conversions */
2101 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2102 /* just multiply by td->mtx (this should be ok) */
2103 copy_m4_m4(tmat, cob.matrix);
2104 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
2108 cti->evaluate_constraint(con, &cob, NULL);
2110 /* convert spaces again */
2111 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2112 /* just multiply by td->mtx (this should be ok) */
2113 copy_m4_m4(tmat, cob.matrix);
2114 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
2120 /* copy results from cob->matrix */
2121 if (td->ext->rotOrder == ROT_MODE_QUAT) {
2123 mat4_to_quat( td->ext->quat,cob.matrix);
2125 else if (td->ext->rotOrder == ROT_MODE_AXISANGLE) {
2127 mat4_to_axis_angle( &td->ext->quat[1], &td->ext->quat[0],cob.matrix);
2131 mat4_to_eulO( td->ext->rot, td->ext->rotOrder,cob.matrix);
2137 static void constraintSizeLim(TransInfo *t, TransData *td)
2139 if (td->con && td->ext) {
2140 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
2141 bConstraintOb cob= {NULL};
2144 /* Make a temporary bConstraintOb for using these limit constraints
2145 * - they only care that cob->matrix is correctly set ;-)
2146 * - current space should be local
2148 if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
2149 /* scale val and reset size */
2150 return; // TODO: fix this case
2153 /* Reset val if SINGLESIZE but using a constraint */
2154 if (td->flag & TD_SINGLESIZE)
2157 size_to_mat4( cob.matrix,td->ext->size);
2160 /* Evaluate valid constraints */
2161 for (con= td->con; con; con= con->next) {
2162 /* only consider constraint if enabled */
2163 if (con->flag & CONSTRAINT_DISABLE) continue;
2164 if (con->enforce == 0.0f) continue;
2166 /* we're only interested in Limit-Scale constraints */
2167 if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
2168 bSizeLimitConstraint *data= con->data;
2171 /* only use it if it's tagged for this purpose */
2172 if ((data->flag2 & LIMIT_TRANSFORM)==0)
2175 /* do space conversions */
2176 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2177 /* just multiply by td->mtx (this should be ok) */
2178 copy_m4_m4(tmat, cob.matrix);
2179 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
2181 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
2182 /* skip... incompatable spacetype */
2187 cti->evaluate_constraint(con, &cob, NULL);
2189 /* convert spaces again */
2190 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2191 /* just multiply by td->mtx (this should be ok) */
2192 copy_m4_m4(tmat, cob.matrix);
2193 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
2198 /* copy results from cob->matrix */
2199 if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
2200 /* scale val and reset size */
2201 return; // TODO: fix this case
2204 /* Reset val if SINGLESIZE but using a constraint */
2205 if (td->flag & TD_SINGLESIZE)
2208 mat4_to_size( td->ext->size,cob.matrix);
2213 /* ************************** WARP *************************** */
2215 static void postInputWarp(TransInfo *t, float values[3])
2217 mul_v3_fl(values, (float)(M_PI * 2));
2219 if (t->customData) /* non-null value indicates reversed input */
2225 void initWarp(TransInfo *t)
2227 float max[3], min[3];
2231 t->transform = Warp;
2232 t->handleEvent = handleEventWarp;
2234 setInputPostFct(&t->mouse, postInputWarp);
2235 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2240 t->snap[1] = 5.0f / 180.0f * (float)M_PI;
2241 t->snap[2] = 1.0f / 180.0f * (float)M_PI;
2243 t->num.increment = 1.0f;
2245 t->flag |= T_NO_CONSTRAINT;
2247 /* we need min/max in view space */
2248 for(i = 0; i < t->total; i++) {
2250 copy_v3_v3(center, t->data[i].center);
2251 mul_m3_v3(t->data[i].mtx, center);
2252 mul_m4_v3(t->viewmat, center);
2253 sub_v3_v3(center, t->viewmat[3]);
2255 minmax_v3v3_v3(min, max, center);
2257 copy_v3_v3(max, center);
2258 copy_v3_v3(min, center);
2262 mid_v3_v3v3(t->center, min, max);
2264 if (max[0] == min[0]) max[0] += 0.1f; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */
2265 t->val= (max[0]-min[0])/2.0f; /* t->val is X dimension projected boundbox */
2268 int handleEventWarp(TransInfo *t, wmEvent *event)
2272 if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
2274 // Use customData pointer to signal warp direction
2275 if (t->customData == NULL)
2276 t->customData = (void*)1;
2278 t->customData = NULL;
2286 int Warp(TransInfo *t, short UNUSED(mval[2]))
2288 TransData *td = t->data;
2289 float vec[3], circumfac, dist, phi0, co, si, *curs, cursor[3], gcursor[3];
2293 curs= give_cursor(t->scene, t->view);
2295 * gcursor is the one used for helpline.
2296 * It has to be in the same space as the drawing loop
2297 * (that means it needs to be in the object's space when in edit mode and
2298 * in global space in object mode)
2300 * cursor is used for calculations.
2301 * It needs to be in view space, but we need to take object's offset
2302 * into account if in Edit mode.
2304 VECCOPY(cursor, curs);
2305 VECCOPY(gcursor, cursor);
2306 if (t->flag & T_EDIT) {
2307 sub_v3_v3(cursor, t->obedit->obmat[3]);
2308 sub_v3_v3(gcursor, t->obedit->obmat[3]);
2309 mul_m3_v3(t->data->smtx, gcursor);
2311 mul_m4_v3(t->viewmat, cursor);
2312 sub_v3_v3(cursor, t->viewmat[3]);
2314 /* amount of radians for warp */
2315 circumfac = t->values[0];
2317 snapGrid(t, &circumfac);
2318 applyNumInput(&t->num, &circumfac);
2320 /* header print for NumInput */
2321 if (hasNumInput(&t->num)) {
2324 outputNumInput(&(t->num), c);
2326 sprintf(str, "Warp: %s", c);
2328 circumfac = DEG2RADF(circumfac);
2331 /* default header print */
2332 sprintf(str, "Warp: %.3f", RAD2DEGF(circumfac));
2335 t->values[0] = circumfac;
2337 circumfac /= 2; /* only need 180 on each side to make 360 */
2339 for(i = 0; i < t->total; i++, td++) {
2341 if (td->flag & TD_NOACTION)
2344 if (td->flag & TD_SKIP)
2347 /* translate point to center, rotate in such a way that outline==distance */
2348 VECCOPY(vec, td->iloc);
2349 mul_m3_v3(td->mtx, vec);
2350 mul_m4_v3(t->viewmat, vec);
2351 sub_v3_v3(vec, t->viewmat[3]);
2353 dist= vec[0]-cursor[0];
2355 /* t->val is X dimension projected boundbox */
2356 phi0= (circumfac*dist/t->val);
2358 vec[1]= (vec[1]-cursor[1]);
2360 co= (float)cos(phi0);
2361 si= (float)sin(phi0);
2362 loc[0]= -si*vec[1]+cursor[0];
2363 loc[1]= co*vec[1]+cursor[1];
2366 mul_m4_v3(t->viewinv, loc);
2367 sub_v3_v3(loc, t->viewinv[3]);
2368 mul_m3_v3(td->smtx, loc);
2370 sub_v3_v3(loc, td->iloc);
2371 mul_v3_fl(loc, td->factor);
2372 add_v3_v3v3(td->loc, td->iloc, loc);
2377 ED_area_headerprint(t->sa, str);
2382 /* ************************** SHEAR *************************** */
2384 static void postInputShear(TransInfo *UNUSED(t), float values[3])
2386 mul_v3_fl(values, 0.05f);
2389 void initShear(TransInfo *t)
2391 t->mode = TFM_SHEAR;
2392 t->transform = Shear;
2393 t->handleEvent = handleEventShear;
2395 setInputPostFct(&t->mouse, postInputShear);
2396 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2402 t->snap[2] = t->snap[1] * 0.1f;
2404 t->num.increment = 0.1f;
2406 t->flag |= T_NO_CONSTRAINT;
2409 int handleEventShear(TransInfo *t, wmEvent *event)
2413 if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
2415 // Use customData pointer to signal Shear direction
2416 if (t->customData == NULL)
2418 initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
2419 t->customData = (void*)1;
2423 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2424 t->customData = NULL;
2434 int Shear(TransInfo *t, short UNUSED(mval[2]))
2436 TransData *td = t->data;
2438 float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3];
2443 copy_m3_m4(persmat, t->viewmat);
2444 invert_m3_m3(persinv, persmat);
2446 value = t->values[0];
2448 snapGrid(t, &value);
2450 applyNumInput(&t->num, &value);
2452 /* header print for NumInput */
2453 if (hasNumInput(&t->num)) {
2456 outputNumInput(&(t->num), c);
2458 sprintf(str, "Shear: %s %s", c, t->proptext);
2461 /* default header print */
2462 sprintf(str, "Shear: %.3f %s", value, t->proptext);
2467 // Custom data signals shear direction
2468 if (t->customData == NULL)
2473 mul_m3_m3m3(tmat, smat, persmat);
2474 mul_m3_m3m3(totmat, persinv, tmat);
2476 for(i = 0 ; i < t->total; i++, td++) {
2477 if (td->flag & TD_NOACTION)
2480 if (td->flag & TD_SKIP)
2485 mul_m3_m3m3(mat3, totmat, td->mtx);
2486 mul_m3_m3m3(tmat, td->smtx, mat3);
2489 copy_m3_m3(tmat, totmat);
2491 sub_v3_v3v3(vec, td->center, t->center);
2493 mul_m3_v3(tmat, vec);
2495 add_v3_v3(vec, t->center);
2496 sub_v3_v3(vec, td->center);
2498 mul_v3_fl(vec, td->factor);
2500 add_v3_v3v3(td->loc, td->iloc, vec);
2505 ED_area_headerprint(t->sa, str);
2510 /* ************************** RESIZE *************************** */
2512 void initResize(TransInfo *t)
2514 t->mode = TFM_RESIZE;
2515 t->transform = Resize;
2517 initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
2519 t->flag |= T_NULL_ONE;
2520 t->num.flag |= NUM_NULL_ONE;
2521 t->num.flag |= NUM_AFFECT_ALL;
2523 t->flag |= T_NO_ZERO;
2524 t->num.flag |= NUM_NO_ZERO;
2531 t->snap[2] = t->snap[1] * 0.1f;
2533 t->num.increment = t->snap[1];
2536 static void headerResize(TransInfo *t, float vec[3], char *str) {
2539 if (hasNumInput(&t->num)) {
2540 outputNumInput(&(t->num), tvec);
2543 sprintf(&tvec[0], "%.4f", vec[0]);
2544 sprintf(&tvec[20], "%.4f", vec[1]);
2545 sprintf(&tvec[40], "%.4f", vec[2]);
2548 if (t->con.mode & CON_APPLY) {
2549 switch(t->num.idx_max) {
2551 spos += sprintf(spos, "Scale: %s%s %s", &tvec[0], t->con.text, t->proptext);
2554 spos += sprintf(spos, "Scale: %s : %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2557 spos += sprintf(spos, "Scale: %s : %s : %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2561 if (t->flag & T_2D_EDIT)
2562 spos += sprintf(spos, "Scale X: %s Y: %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2564 spos += sprintf(spos, "Scale X: %s Y: %s Z: %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2567 if (t->flag & (T_PROP_EDIT|T_PROP_CONNECTED)) {
2568 spos += sprintf(spos, " Proportional size: %.2f", t->prop_size);
2574 #define SIGN(a) (a<-FLT_EPSILON?1:a>FLT_EPSILON?2:3)
2575 #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)
2577 /* smat is reference matrix, only scaled */
2578 static void TransMat3ToSize( float mat[][3], float smat[][3], float *size)
2582 copy_v3_v3(vec, mat[0]);
2583 size[0]= normalize_v3(vec);
2584 copy_v3_v3(vec, mat[1]);
2585 size[1]= normalize_v3(vec);
2586 copy_v3_v3(vec, mat[2]);
2587 size[2]= normalize_v3(vec);
2589 /* first tried with dotproduct... but the sign flip is crucial */
2590 if( VECSIGNFLIP(mat[0], smat[0]) ) size[0]= -size[0];
2591 if( VECSIGNFLIP(mat[1], smat[1]) ) size[1]= -size[1];
2592 if( VECSIGNFLIP(mat[2], smat[2]) ) size[2]= -size[2];
2596 static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
2597 float tmat[3][3], smat[3][3], center[3];
2600 if (t->flag & T_EDIT) {
2601 mul_m3_m3m3(smat, mat, td->mtx);
2602 mul_m3_m3m3(tmat, td->smtx, smat);
2605 copy_m3_m3(tmat, mat);
2608 if (t->con.applySize) {
2609 t->con.applySize(t, td, tmat);
2612 /* local constraint shouldn't alter center */
2613 if (t->around == V3D_LOCAL) {
2614 if (t->flag & T_OBJECT) {
2615 VECCOPY(center, td->center);
2617 else if (t->flag & T_EDIT) {
2619 if(t->around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
2620 VECCOPY(center, td->center);
2623 VECCOPY(center, t->center);
2627 VECCOPY(center, t->center);
2631 VECCOPY(center, t->center);
2637 if (t->flag & (T_OBJECT|T_TEXTURE|T_POSE)) {
2638 float obsizemat[3][3];
2639 // Reorient the size mat to fit the oriented object.
2640 mul_m3_m3m3(obsizemat, tmat, td->axismtx);
2641 //print_m3("obsizemat", obsizemat);
2642 TransMat3ToSize(obsizemat, td->axismtx, fsize);
2643 //print_v3("fsize", fsize);
2646 mat3_to_size( fsize,tmat);
2649 protectedSizeBits(td->protectflag, fsize);
2651 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't resize objects itself
2652 if((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)){
2653 /* scale val and reset size */
2654 *td->val = td->ival * (1 + (fsize[0] - 1) * td->factor);
2656 td->ext->size[0] = td->ext->isize[0];
2657 td->ext->size[1] = td->ext->isize[1];
2658 td->ext->size[2] = td->ext->isize[2];
2661 /* Reset val if SINGLESIZE but using a constraint */
2662 if (td->flag & TD_SINGLESIZE)
2663 *td->val = td->ival;
2665 td->ext->size[0] = td->ext->isize[0] * (1 + (fsize[0] - 1) * td->factor);
2666 td->ext->size[1] = td->ext->isize[1] * (1 + (fsize[1] - 1) * td->factor);
2667 td->ext->size[2] = td->ext->isize[2] * (1 + (fsize[2] - 1) * td->factor);
2671 constraintSizeLim(t, td);
2674 /* For individual element center, Editmode need to use iloc */
2675 if (t->flag & T_POINTS)
2676 sub_v3_v3v3(vec, td->iloc, center);
2678 sub_v3_v3v3(vec, td->center, center);
2680 mul_m3_v3(tmat, vec);
2682 add_v3_v3(vec, center);
2683 if (t->flag & T_POINTS)
2684 sub_v3_v3(vec, td->iloc);
2686 sub_v3_v3(vec, td->center);
2688 mul_v3_fl(vec, td->factor);
2690 if (t->flag & (T_OBJECT|T_POSE)) {
2691 mul_m3_v3(td->smtx, vec);
2694 protectedTransBits(td->protectflag, vec);
2695 add_v3_v3v3(td->loc, td->iloc, vec);
2697 constraintTransLim(t, td);
2700 int Resize(TransInfo *t, short mval[2])
2703 float size[3], mat[3][3];
2708 /* for manipulator, center handle, the scaling can't be done relative to center */
2709 if( (t->flag & T_USES_MANIPULATOR) && t->con.mode==0)
2711 ratio = 1.0f - ((t->imval[0] - mval[0]) + (t->imval[1] - mval[1]))/100.0f;
2715 ratio = t->values[0];
2718 size[0] = size[1] = size[2] = ratio;
2722 if (hasNumInput(&t->num)) {
2723 applyNumInput(&t->num, size);
2724 constraintNumInput(t, size);
2727 applySnapping(t, size);
2729 if (t->flag & T_AUTOVALUES)
2731 VECCOPY(size, t->auto_values);
2734 VECCOPY(t->values, size);
2736 size_to_mat3( mat,size);
2738 if (t->con.applySize) {
2739 t->con.applySize(t, NULL, mat);
2742 copy_m3_m3(t->mat, mat); // used in manipulator
2744 headerResize(t, size, str);
2746 for(i = 0, td=t->data; i < t->total; i++, td++) {
2747 if (td->flag & TD_NOACTION)
2750 if (td->flag & TD_SKIP)
2753 ElementResize(t, td, mat);
2756 /* evil hack - redo resize if cliping needed */
2757 if (t->flag & T_CLIP_UV && clipUVTransform(t, size, 1)) {
2758 size_to_mat3( mat,size);
2760 if (t->con.applySize)
2761 t->con.applySize(t, NULL, mat);
2763 for(i = 0, td=t->data; i < t->total; i++, td++)
2764 ElementResize(t, td, mat);
2769 ED_area_headerprint(t->sa, str);
2774 /* ************************** TOSPHERE *************************** */
2776 void initToSphere(TransInfo *t)
2778 TransData *td = t->data;
2781 t->mode = TFM_TOSPHERE;
2782 t->transform = ToSphere;
2784 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2790 t->snap[2] = t->snap[1] * 0.1f;
2792 t->num.increment = t->snap[1];
2794 t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
2795 t->flag |= T_NO_CONSTRAINT;
2797 // Calculate average radius
2798 for(i = 0 ; i < t->total; i++, td++) {
2799 t->val += len_v3v3(t->center, td->iloc);
2802 t->val /= (float)t->total;
2805 int ToSphere(TransInfo *t, short UNUSED(mval[2]))
2808 float ratio, radius;
2811 TransData *td = t->data;
2813 ratio = t->values[0];
2815 snapGrid(t, &ratio);
2817 applyNumInput(&t->num, &ratio);
2824 t->values[0] = ratio;
2826 /* header print for NumInput */
2827 if (hasNumInput(&t->num)) {
2830 outputNumInput(&(t->num), c);
2832 sprintf(str, "To Sphere: %s %s", c, t->proptext);
2835 /* default header print */
2836 sprintf(str, "To Sphere: %.4f %s", ratio, t->proptext);
2840 for(i = 0 ; i < t->total; i++, td++) {
2842 if (td->flag & TD_NOACTION)
2845 if (td->flag & TD_SKIP)
2848 sub_v3_v3v3(vec, td->iloc, t->center);
2850 radius = normalize_v3(vec);
2852 tratio = ratio * td->factor;
2854 mul_v3_fl(vec, radius * (1.0f - tratio) + t->val * tratio);
2856 add_v3_v3v3(td->loc, t->center, vec);
2862 ED_area_headerprint(t->sa, str);
2867 /* ************************** ROTATION *************************** */
2870 static void postInputRotation(TransInfo *t, float values[3])
2872 if ((t->con.mode & CON_APPLY) && t->con.applyRot) {
2873 t->con.applyRot(t, NULL, t->axis, values);
2877 void initRotation(TransInfo *t)
2879 t->mode = TFM_ROTATION;
2880 t->transform = Rotation;
2882 setInputPostFct(&t->mouse, postInputRotation);
2883 initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
2886 /* Scale down and flip input for rotation */
2887 t->ndof.factor[0] = -0.2f;
2892 t->snap[1] = (float)((5.0/180)*M_PI);
2893 t->snap[2] = t->snap[1] * 0.2f;
2895 t->num.increment = 1.0f;
2897 if (t->flag & T_2D_EDIT)
2898 t->flag |= T_NO_CONSTRAINT;
2900 negate_v3_v3(t->axis, t->viewinv[2]);
2901 normalize_v3(t->axis);
2903 copy_v3_v3(t->axis_orig, t->axis);
2906 static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short around) {
2907 float vec[3], totmat[3][3], smat[3][3];
2908 float eul[3], fmat[3][3], quat[4];
2909 float *center = t->center;
2911 /* local constraint shouldn't alter center */
2912 if (around == V3D_LOCAL) {
2913 if (t->flag & (T_OBJECT|T_POSE)) {
2914 center = td->center;
2917 if(around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
2918 center = td->center;
2923 if (t->flag & T_POINTS) {
2924 mul_m3_m3m3(totmat, mat, td->mtx);
2925 mul_m3_m3m3(smat, td->smtx, totmat);
2927 sub_v3_v3v3(vec, td->iloc, center);
2928 mul_m3_v3(smat, vec);
2930 add_v3_v3v3(td->loc, vec, center);
2932 sub_v3_v3v3(vec,td->loc,td->iloc);
2933 protectedTransBits(td->protectflag, vec);
2934 add_v3_v3v3(td->loc, td->iloc, vec);
2937 if(td->flag & TD_USEQUAT) {
2938 mul_serie_m3(fmat, td->mtx, mat, td->smtx, NULL, NULL, NULL, NULL, NULL);
2939 mat3_to_quat( quat,fmat); // Actual transform
2942 mul_qt_qtqt(td->ext->quat, quat, td->ext->iquat);
2944 /* is there a reason not to have this here? -jahka */
2945 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2952 * This is some VERY ugly special case to deal with pose mode.
2954 * The problem is that mtx and smtx include each bone orientation.
2956 * That is needed to rotate each bone properly, HOWEVER, to calculate
2957 * the translation component, we only need the actual armature object's
2958 * matrix (and inverse). That is not all though. Once the proper translation
2959 * has been computed, it has to be converted back into the bone's space.
2961 else if (t->flag & T_POSE) {
2962 float pmtx[3][3], imtx[3][3];
2964 // Extract and invert armature object matrix
2965 copy_m3_m4(pmtx, t->poseobj->obmat);