2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): none yet.
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file blender/editors/transform/transform.c
29 * \ingroup edtransform
45 #include "MEM_guardedalloc.h"
47 #include "DNA_anim_types.h"
48 #include "DNA_armature_types.h"
49 #include "DNA_constraint_types.h"
50 #include "DNA_mesh_types.h"
51 #include "DNA_meshdata_types.h"
52 #include "DNA_movieclip_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"
78 #include "UI_view2d.h"
83 #include "BLI_blenlib.h"
84 #include "BLI_utildefines.h"
85 #include "BLI_ghash.h"
86 #include "BLI_linklist.h"
87 #include "BLI_smallhash.h"
88 #include "BLI_array.h"
90 #include "UI_resources.h"
92 //#include "blendef.h"
94 //#include "mydevice.h"
96 #include "transform.h"
100 static void drawTransformApply(const struct bContext *C, struct ARegion *ar, void *arg);
101 static int doEdgeSlide(TransInfo *t, float perc);
103 /* ************************** SPACE DEPENDANT CODE **************************** */
105 void setTransformViewMatrices(TransInfo *t)
107 if (t->spacetype==SPACE_VIEW3D && t->ar && t->ar->regiontype == RGN_TYPE_WINDOW) {
108 RegionView3D *rv3d = t->ar->regiondata;
110 copy_m4_m4(t->viewmat, rv3d->viewmat);
111 copy_m4_m4(t->viewinv, rv3d->viewinv);
112 copy_m4_m4(t->persmat, rv3d->persmat);
113 copy_m4_m4(t->persinv, rv3d->persinv);
114 t->persp = rv3d->persp;
121 t->persp = RV3D_ORTHO;
124 calculateCenter2D(t);
127 static void convertViewVec2D(View2D *v2d, float vec[3], int dx, int dy)
131 divx= v2d->mask.xmax - v2d->mask.xmin;
132 divy= v2d->mask.ymax - v2d->mask.ymin;
134 vec[0]= (v2d->cur.xmax - v2d->cur.xmin) * dx / divx;
135 vec[1]= (v2d->cur.ymax - v2d->cur.ymin) * dy / divy;
139 void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy)
141 if ((t->spacetype == SPACE_VIEW3D) && (t->ar->regiontype == RGN_TYPE_WINDOW)) {
145 ED_view3d_win_to_delta(t->ar, mval_f, r_vec);
147 else if (t->spacetype==SPACE_IMAGE) {
150 convertViewVec2D(t->view, r_vec, dx, dy);
152 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
156 else if (ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
157 convertViewVec2D(t->view, r_vec, dx, dy);
159 else if (ELEM(t->spacetype, SPACE_NODE, SPACE_SEQ)) {
160 convertViewVec2D(&t->ar->v2d, r_vec, dx, dy);
162 else if (t->spacetype==SPACE_CLIP) {
163 View2D *v2d = t->view;
166 divx = v2d->mask.xmax-v2d->mask.xmin;
167 divy = v2d->mask.ymax-v2d->mask.ymin;
169 r_vec[0] = (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
170 r_vec[1] = (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
174 printf("%s: called in an invalid context\n", __func__);
179 void projectIntView(TransInfo *t, const float vec[3], int adr[2])
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) {
197 SpaceAction *sact = t->sa->spacedata.first;
199 if (sact->flag & SACTION_DRAWTIME) {
200 //vec[0] = vec[0]/((t->scene->r.frs_sec / t->scene->r.frs_sec_base));
202 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
207 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
213 else if (ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
216 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
220 else if (t->spacetype==SPACE_SEQ) { /* XXX not tested yet, but should work */
223 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
227 else if (t->spacetype==SPACE_CLIP) {
228 UI_view2d_to_region_no_clip(t->view, vec[0], vec[1], adr, adr+1);
232 void projectFloatView(TransInfo *t, const float vec[3], float adr[2])
234 switch (t->spacetype) {
237 if (t->ar->regiontype == RGN_TYPE_WINDOW) {
238 project_float_noclip(t->ar, vec, adr);
249 projectIntView(t, vec, a);
259 void applyAspectRatio(TransInfo *t, float *vec)
261 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
262 SpaceImage *sima= t->sa->spacedata.first;
265 if ((sima->flag & SI_COORDFLOATS)==0) {
267 ED_space_image_size(sima, &width, &height);
273 ED_space_image_uv_aspect(sima, &aspx, &aspy);
279 void removeAspectRatio(TransInfo *t, float *vec)
281 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
282 SpaceImage *sima= t->sa->spacedata.first;
285 if ((sima->flag & SI_COORDFLOATS)==0) {
287 ED_space_image_size(sima, &width, &height);
293 ED_space_image_uv_aspect(sima, &aspx, &aspy);
299 static void viewRedrawForce(const bContext *C, TransInfo *t)
301 if (t->spacetype == SPACE_VIEW3D) {
302 /* Do we need more refined tags? */
303 if (t->flag & T_POSE)
304 WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
306 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
308 /* for realtime animation record - send notifiers recognised by animation editors */
309 // XXX: is this notifier a lame duck?
310 if ((t->animtimer) && IS_AUTOKEY_ON(t->scene))
311 WM_event_add_notifier(C, NC_OBJECT|ND_KEYS, NULL);
314 else if (t->spacetype == SPACE_ACTION) {
315 //SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
316 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
318 else if (t->spacetype == SPACE_IPO) {
319 //SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
320 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
322 else if (t->spacetype == SPACE_NLA) {
323 WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_EDITED, NULL);
325 else if (t->spacetype == SPACE_NODE) {
326 //ED_area_tag_redraw(t->sa);
327 WM_event_add_notifier(C, NC_SPACE|ND_SPACE_NODE_VIEW, NULL);
329 else if (t->spacetype == SPACE_SEQ) {
330 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, NULL);
332 else if (t->spacetype==SPACE_IMAGE) {
333 // XXX how to deal with lock?
334 SpaceImage *sima= (SpaceImage*)t->sa->spacedata.first;
335 if (sima->lock) WM_event_add_notifier(C, NC_GEOM|ND_DATA, t->obedit->data);
336 else ED_area_tag_redraw(t->sa);
338 else if (t->spacetype==SPACE_CLIP) {
339 SpaceClip *sc = (SpaceClip*)t->sa->spacedata.first;
340 MovieClip *clip = ED_space_clip(sc);
342 /* objects could be parented to tracking data, so send this for viewport refresh */
343 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
345 WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, clip);
349 static void viewRedrawPost(bContext *C, TransInfo *t)
351 ED_area_headerprint(t->sa, NULL);
353 if (t->spacetype == SPACE_VIEW3D) {
354 /* if autokeying is enabled, send notifiers that keyframes were added */
355 if (IS_AUTOKEY_ON(t->scene))
356 WM_main_add_notifier(NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
358 /* XXX temp, first hack to get auto-render in compositor work (ton) */
359 WM_event_add_notifier(C, NC_SCENE|ND_TRANSFORM_DONE, CTX_data_scene(C));
363 #if 0 // TRANSFORM_FIX_ME
364 if (t->spacetype==SPACE_VIEW3D) {
365 allqueue(REDRAWBUTSOBJECT, 0);
366 allqueue(REDRAWVIEW3D, 0);
368 else if (t->spacetype==SPACE_IMAGE) {
369 allqueue(REDRAWIMAGE, 0);
370 allqueue(REDRAWVIEW3D, 0);
372 else if (ELEM3(t->spacetype, SPACE_ACTION, SPACE_NLA, SPACE_IPO)) {
373 allqueue(REDRAWVIEW3D, 0);
374 allqueue(REDRAWACTION, 0);
375 allqueue(REDRAWNLA, 0);
376 allqueue(REDRAWIPO, 0);
377 allqueue(REDRAWTIME, 0);
378 allqueue(REDRAWBUTSOBJECT, 0);
381 scrarea_queue_headredraw(curarea);
385 /* ************************** TRANSFORMATIONS **************************** */
387 void BIF_selectOrientation(void)
389 #if 0 // TRANSFORM_FIX_ME
391 char *str_menu = BIF_menustringTransformOrientation("Orientation");
392 val= pupmenu(str_menu);
401 static void view_editmove(unsigned short UNUSED(event))
403 #if 0 // TRANSFORM_FIX_ME
405 /* Regular: Zoom in */
406 /* Shift: Scroll up */
407 /* Ctrl: Scroll right */
408 /* Alt-Shift: Rotate up */
409 /* Alt-Ctrl: Rotate right */
411 /* only work in 3D window for now
412 * In the end, will have to send to event to a 2D window handler instead
414 if (Trans.flag & T_2D_EDIT)
420 if ( G.qual & LR_SHIFTKEY ) {
421 if ( G.qual & LR_ALTKEY ) {
422 G.qual &= ~LR_SHIFTKEY;
424 G.qual |= LR_SHIFTKEY;
430 else if ( G.qual & LR_CTRLKEY ) {
431 if ( G.qual & LR_ALTKEY ) {
432 G.qual &= ~LR_CTRLKEY;
434 G.qual |= LR_CTRLKEY;
440 else if (U.uiflag & USER_WHEELZOOMDIR)
441 persptoetsen(PADMINUS);
443 persptoetsen(PADPLUSKEY);
448 if ( G.qual & LR_SHIFTKEY ) {
449 if ( G.qual & LR_ALTKEY ) {
450 G.qual &= ~LR_SHIFTKEY;
452 G.qual |= LR_SHIFTKEY;
458 else if ( G.qual & LR_CTRLKEY ) {
459 if ( G.qual & LR_ALTKEY ) {
460 G.qual &= ~LR_CTRLKEY;
462 G.qual |= LR_CTRLKEY;
468 else if (U.uiflag & USER_WHEELZOOMDIR)
469 persptoetsen(PADPLUSKEY);
471 persptoetsen(PADMINUS);
478 setTransformViewMatrices(&Trans);
482 /* ************************************************* */
484 /* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
485 #define TFM_MODAL_CANCEL 1
486 #define TFM_MODAL_CONFIRM 2
487 #define TFM_MODAL_TRANSLATE 3
488 #define TFM_MODAL_ROTATE 4
489 #define TFM_MODAL_RESIZE 5
490 #define TFM_MODAL_SNAP_INV_ON 6
491 #define TFM_MODAL_SNAP_INV_OFF 7
492 #define TFM_MODAL_SNAP_TOGGLE 8
493 #define TFM_MODAL_AXIS_X 9
494 #define TFM_MODAL_AXIS_Y 10
495 #define TFM_MODAL_AXIS_Z 11
496 #define TFM_MODAL_PLANE_X 12
497 #define TFM_MODAL_PLANE_Y 13
498 #define TFM_MODAL_PLANE_Z 14
499 #define TFM_MODAL_CONS_OFF 15
500 #define TFM_MODAL_ADD_SNAP 16
501 #define TFM_MODAL_REMOVE_SNAP 17
502 /* 18 and 19 used by numinput, defined in transform.h
504 #define TFM_MODAL_PROPSIZE_UP 20
505 #define TFM_MODAL_PROPSIZE_DOWN 21
506 #define TFM_MODAL_AUTOIK_LEN_INC 22
507 #define TFM_MODAL_AUTOIK_LEN_DEC 23
509 /* called in transform_ops.c, on each regeneration of keymaps */
510 wmKeyMap* transform_modal_keymap(wmKeyConfig *keyconf)
512 static EnumPropertyItem modal_items[] = {
513 {TFM_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
514 {TFM_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
515 {TFM_MODAL_TRANSLATE, "TRANSLATE", 0, "Translate", ""},
516 {TFM_MODAL_ROTATE, "ROTATE", 0, "Rotate", ""},
517 {TFM_MODAL_RESIZE, "RESIZE", 0, "Resize", ""},
518 {TFM_MODAL_SNAP_INV_ON, "SNAP_INV_ON", 0, "Invert Snap On", ""},
519 {TFM_MODAL_SNAP_INV_OFF, "SNAP_INV_OFF", 0, "Invert Snap Off", ""},
520 {TFM_MODAL_SNAP_TOGGLE, "SNAP_TOGGLE", 0, "Snap Toggle", ""},
521 {TFM_MODAL_AXIS_X, "AXIS_X", 0, "Orientation X axis", ""},
522 {TFM_MODAL_AXIS_Y, "AXIS_Y", 0, "Orientation Y axis", ""},
523 {TFM_MODAL_AXIS_Z, "AXIS_Z", 0, "Orientation Z axis", ""},
524 {TFM_MODAL_PLANE_X, "PLANE_X", 0, "Orientation X plane", ""},
525 {TFM_MODAL_PLANE_Y, "PLANE_Y", 0, "Orientation Y plane", ""},
526 {TFM_MODAL_PLANE_Z, "PLANE_Z", 0, "Orientation Z plane", ""},
527 {TFM_MODAL_CONS_OFF, "CONS_OFF", 0, "Remove Constraints", ""},
528 {TFM_MODAL_ADD_SNAP, "ADD_SNAP", 0, "Add Snap Point", ""},
529 {TFM_MODAL_REMOVE_SNAP, "REMOVE_SNAP", 0, "Remove Last Snap Point", ""},
530 {NUM_MODAL_INCREMENT_UP, "INCREMENT_UP", 0, "Numinput Increment Up", ""},
531 {NUM_MODAL_INCREMENT_DOWN, "INCREMENT_DOWN", 0, "Numinput Increment Down", ""},
532 {TFM_MODAL_PROPSIZE_UP, "PROPORTIONAL_SIZE_UP", 0, "Increase Proportional Influence", ""},
533 {TFM_MODAL_PROPSIZE_DOWN, "PROPORTIONAL_SIZE_DOWN", 0, "Decrease Proportional Influence", ""},
534 {TFM_MODAL_AUTOIK_LEN_INC, "AUTOIK_CHAIN_LEN_UP", 0, "Increase Max AutoIK Chain Length", ""},
535 {TFM_MODAL_AUTOIK_LEN_DEC, "AUTOIK_CHAIN_LEN_DOWN", 0, "Decrease Max AutoIK Chain Length", ""},
536 {0, NULL, 0, NULL, NULL}};
538 wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "Transform Modal Map");
540 /* this function is called for each spacetype, only needs to add map once */
541 if (keymap && keymap->modal_items) return NULL;
543 keymap= WM_modalkeymap_add(keyconf, "Transform Modal Map", modal_items);
545 /* items for modal map */
546 WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CANCEL);
547 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
548 WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
549 WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
551 WM_modalkeymap_add_item(keymap, GKEY, KM_PRESS, 0, 0, TFM_MODAL_TRANSLATE);
552 WM_modalkeymap_add_item(keymap, RKEY, KM_PRESS, 0, 0, TFM_MODAL_ROTATE);
553 WM_modalkeymap_add_item(keymap, SKEY, KM_PRESS, 0, 0, TFM_MODAL_RESIZE);
555 WM_modalkeymap_add_item(keymap, TABKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_SNAP_TOGGLE);
557 WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_SNAP_INV_ON);
558 WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, TFM_MODAL_SNAP_INV_OFF);
560 WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_SNAP_INV_ON);
561 WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_RELEASE, KM_ANY, 0, TFM_MODAL_SNAP_INV_OFF);
563 WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, 0, 0, TFM_MODAL_ADD_SNAP);
564 WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, KM_ALT, 0, TFM_MODAL_REMOVE_SNAP);
566 WM_modalkeymap_add_item(keymap, PAGEUPKEY, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_UP);
567 WM_modalkeymap_add_item(keymap, PAGEDOWNKEY, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_DOWN);
568 WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_UP);
569 WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_DOWN);
571 WM_modalkeymap_add_item(keymap, PAGEUPKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_INC);
572 WM_modalkeymap_add_item(keymap, PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_DEC);
573 WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_INC);
574 WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_DEC);
580 int transformEvent(TransInfo *t, wmEvent *event)
582 float mati[3][3]= MAT3_UNITY;
583 char cmode = constraintModeToChar(t);
586 t->redraw |= handleMouseInput(t, &t->mouse, event);
588 if (event->type == MOUSEMOVE) {
589 copy_v2_v2_int(t->mval, event->mval);
591 // t->redraw |= TREDRAW_SOFT; /* Use this for soft redraw. Might cause flicker in object mode */
592 t->redraw |= TREDRAW_HARD;
595 if (t->state == TRANS_STARTING) {
596 t->state = TRANS_RUNNING;
599 applyMouseInput(t, &t->mouse, t->mval, t->values);
601 // Snapping mouse move events
602 t->redraw |= handleSnapping(t, event);
605 /* handle modal keymap first */
606 if (event->type == EVT_MODAL_MAP) {
607 switch (event->val) {
608 case TFM_MODAL_CANCEL:
609 t->state = TRANS_CANCEL;
611 case TFM_MODAL_CONFIRM:
612 t->state = TRANS_CONFIRM;
614 case TFM_MODAL_TRANSLATE:
615 /* only switch when... */
616 if ( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
617 resetTransRestrictions(t);
618 restoreTransObjects(t);
620 initSnapping(t, NULL); // need to reinit after mode change
621 t->redraw |= TREDRAW_HARD;
623 else if (t->mode == TFM_TRANSLATION) {
624 if (t->options&CTX_MOVIECLIP) {
625 restoreTransObjects(t);
627 t->flag^= T_ALT_TRANSFORM;
628 t->redraw |= TREDRAW_HARD;
632 case TFM_MODAL_ROTATE:
633 /* only switch when... */
634 if (!(t->options & CTX_TEXTURE) && !(t->options & CTX_MOVIECLIP)) {
635 if ( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
637 resetTransRestrictions(t);
639 if (t->mode == TFM_ROTATION) {
640 restoreTransObjects(t);
644 restoreTransObjects(t);
647 initSnapping(t, NULL); // need to reinit after mode change
648 t->redraw |= TREDRAW_HARD;
652 case TFM_MODAL_RESIZE:
653 /* only switch when... */
654 if ( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
655 resetTransRestrictions(t);
656 restoreTransObjects(t);
658 initSnapping(t, NULL); // need to reinit after mode change
659 t->redraw |= TREDRAW_HARD;
663 case TFM_MODAL_SNAP_INV_ON:
664 t->modifiers |= MOD_SNAP_INVERT;
665 t->redraw |= TREDRAW_HARD;
667 case TFM_MODAL_SNAP_INV_OFF:
668 t->modifiers &= ~MOD_SNAP_INVERT;
669 t->redraw |= TREDRAW_HARD;
671 case TFM_MODAL_SNAP_TOGGLE:
672 t->modifiers ^= MOD_SNAP;
673 t->redraw |= TREDRAW_HARD;
675 case TFM_MODAL_AXIS_X:
676 if ((t->flag & T_NO_CONSTRAINT)==0) {
681 if (t->flag & T_2D_EDIT) {
682 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0), "along X");
685 setUserConstraint(t, t->current_orientation, (CON_AXIS0), "along %s X");
688 t->redraw |= TREDRAW_HARD;
691 case TFM_MODAL_AXIS_Y:
692 if ((t->flag & T_NO_CONSTRAINT)==0) {
697 if (t->flag & T_2D_EDIT) {
698 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1), "along Y");
701 setUserConstraint(t, t->current_orientation, (CON_AXIS1), "along %s Y");
704 t->redraw |= TREDRAW_HARD;
707 case TFM_MODAL_AXIS_Z:
708 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
713 setUserConstraint(t, t->current_orientation, (CON_AXIS2), "along %s Z");
715 t->redraw |= TREDRAW_HARD;
718 case TFM_MODAL_PLANE_X:
719 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
724 setUserConstraint(t, t->current_orientation, (CON_AXIS1|CON_AXIS2), "locking %s X");
726 t->redraw |= TREDRAW_HARD;
729 case TFM_MODAL_PLANE_Y:
730 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
735 setUserConstraint(t, t->current_orientation, (CON_AXIS0|CON_AXIS2), "locking %s Y");
737 t->redraw |= TREDRAW_HARD;
740 case TFM_MODAL_PLANE_Z:
741 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
746 setUserConstraint(t, t->current_orientation, (CON_AXIS0|CON_AXIS1), "locking %s Z");
748 t->redraw |= TREDRAW_HARD;
751 case TFM_MODAL_CONS_OFF:
752 if ((t->flag & T_NO_CONSTRAINT)==0) {
754 t->redraw |= TREDRAW_HARD;
757 case TFM_MODAL_ADD_SNAP:
759 t->redraw |= TREDRAW_HARD;
761 case TFM_MODAL_REMOVE_SNAP:
763 t->redraw |= TREDRAW_HARD;
765 case TFM_MODAL_PROPSIZE_UP:
766 if (t->flag & T_PROP_EDIT) {
768 if (t->spacetype==SPACE_VIEW3D && t->persp != RV3D_ORTHO)
769 t->prop_size= MIN2(t->prop_size, ((View3D *)t->view)->far);
770 calculatePropRatio(t);
772 t->redraw |= TREDRAW_HARD;
774 case TFM_MODAL_PROPSIZE_DOWN:
775 if (t->flag & T_PROP_EDIT) {
776 t->prop_size*= 0.90909090f;
777 calculatePropRatio(t);
779 t->redraw |= TREDRAW_HARD;
781 case TFM_MODAL_AUTOIK_LEN_INC:
782 if (t->flag & T_AUTOIK)
783 transform_autoik_update(t, 1);
784 t->redraw |= TREDRAW_HARD;
786 case TFM_MODAL_AUTOIK_LEN_DEC:
787 if (t->flag & T_AUTOIK)
788 transform_autoik_update(t, -1);
789 t->redraw |= TREDRAW_HARD;
796 // Modal numinput events
797 t->redraw |= handleNumInput(&(t->num), event);
799 /* else do non-mapped events */
800 else if (event->val == KM_PRESS) {
801 switch (event->type) {
803 t->state = TRANS_CANCEL;
805 /* enforce redraw of transform when modifiers are used */
808 t->modifiers |= MOD_CONSTRAINT_PLANE;
809 t->redraw |= TREDRAW_HARD;
813 if ((t->spacetype==SPACE_VIEW3D) && event->alt) {
814 #if 0 // TRANSFORM_FIX_ME
818 BIF_selectOrientation();
819 calc_manipulator_stats(curarea);
820 copy_m3_m4(t->spacemtx, G.vd->twmat);
821 warp_pointer(mval[0], mval[1]);
825 t->state = TRANS_CONFIRM;
830 if ((t->flag & T_NO_CONSTRAINT)==0) {
831 /* exception for switching to dolly, or trackball, in camera view */
832 if (t->flag & T_CAMERA) {
833 if (t->mode==TFM_TRANSLATION)
834 setLocalConstraint(t, (CON_AXIS2), "along local Z");
835 else if (t->mode==TFM_ROTATION) {
836 restoreTransObjects(t);
841 t->modifiers |= MOD_CONSTRAINT_SELECT;
842 if (t->con.mode & CON_APPLY) {
847 initSelectConstraint(t, t->spacemtx);
850 /* bit hackish... but it prevents mmb select to print the orientation from menu */
851 strcpy(t->spacename, "global");
852 initSelectConstraint(t, mati);
854 postSelectConstraint(t);
857 t->redraw |= TREDRAW_HARD;
861 t->state = TRANS_CANCEL;
865 t->state = TRANS_CONFIRM;
868 /* only switch when... */
869 if ( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
870 resetTransRestrictions(t);
871 restoreTransObjects(t);
873 initSnapping(t, NULL); // need to reinit after mode change
874 t->redraw |= TREDRAW_HARD;
878 /* only switch when... */
879 if ( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
880 resetTransRestrictions(t);
881 restoreTransObjects(t);
883 initSnapping(t, NULL); // need to reinit after mode change
884 t->redraw |= TREDRAW_HARD;
888 /* only switch when... */
889 if (!(t->options & CTX_TEXTURE) && !(t->options & CTX_MOVIECLIP)) {
890 if ( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
892 resetTransRestrictions(t);
894 if (t->mode == TFM_ROTATION) {
895 restoreTransObjects(t);
899 restoreTransObjects(t);
902 initSnapping(t, NULL); // need to reinit after mode change
903 t->redraw |= TREDRAW_HARD;
909 t->flag ^= T_PROP_CONNECTED;
910 sort_trans_data_dist(t);
911 calculatePropRatio(t);
916 t->redraw |= TREDRAW_HARD;
920 if ((t->flag & T_NO_CONSTRAINT)==0) {
921 if (t->flag & T_2D_EDIT) {
926 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0), "along X");
931 if (t->con.orientation != V3D_MANIP_GLOBAL) {
935 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
936 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
937 setUserConstraint(t, orientation, (CON_AXIS0), "along %s X");
938 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
939 setUserConstraint(t, orientation, (CON_AXIS1|CON_AXIS2), "locking %s X");
943 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
944 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0), "along %s X");
945 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
946 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1|CON_AXIS2), "locking %s X");
949 t->redraw |= TREDRAW_HARD;
953 if ((t->flag & T_NO_CONSTRAINT)==0) {
954 if (t->flag & T_2D_EDIT) {
959 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1), "along Y");
964 if (t->con.orientation != V3D_MANIP_GLOBAL) {
968 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
969 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
970 setUserConstraint(t, orientation, (CON_AXIS1), "along %s Y");
971 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
972 setUserConstraint(t, orientation, (CON_AXIS0|CON_AXIS2), "locking %s Y");
976 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
977 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1), "along %s Y");
978 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
979 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0|CON_AXIS2), "locking %s Y");
982 t->redraw |= TREDRAW_HARD;
986 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))==0) {
988 if (t->con.orientation != V3D_MANIP_GLOBAL) {
992 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
993 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
994 setUserConstraint(t, orientation, (CON_AXIS2), "along %s Z");
995 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
996 setUserConstraint(t, orientation, (CON_AXIS0|CON_AXIS1), "locking %s Z");
1000 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
1001 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS2), "along %s Z");
1002 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
1003 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0|CON_AXIS1), "locking %s Z");
1005 t->redraw |= TREDRAW_HARD;
1009 if (t->flag & T_PROP_EDIT && event->shift) {
1010 t->prop_mode = (t->prop_mode + 1) % PROP_MODE_MAX;
1011 calculatePropRatio(t);
1012 t->redraw |= TREDRAW_HARD;
1016 if (event->alt && t->flag & T_PROP_EDIT) {
1017 t->prop_size *= 1.1f;
1018 if (t->spacetype==SPACE_VIEW3D && t->persp != RV3D_ORTHO)
1019 t->prop_size= MIN2(t->prop_size, ((View3D *)t->view)->far);
1020 calculatePropRatio(t);
1025 case WHEELDOWNMOUSE:
1026 if (t->flag & T_AUTOIK) {
1027 transform_autoik_update(t, 1);
1029 else view_editmove(event->type);
1033 if (event->alt && t->flag & T_PROP_EDIT) {
1034 t->prop_size*= 0.90909090f;
1035 calculatePropRatio(t);
1041 if (t->flag & T_AUTOIK) {
1042 transform_autoik_update(t, -1);
1044 else view_editmove(event->type);
1052 // Numerical input events
1053 t->redraw |= handleNumInput(&(t->num), event);
1055 // Snapping key events
1056 t->redraw |= handleSnapping(t, event);
1059 else if (event->val==KM_RELEASE) {
1060 switch (event->type) {
1063 t->modifiers &= ~MOD_CONSTRAINT_PLANE;
1064 t->redraw |= TREDRAW_HARD;
1068 if ((t->flag & T_NO_CONSTRAINT)==0) {
1069 t->modifiers &= ~MOD_CONSTRAINT_SELECT;
1070 postSelectConstraint(t);
1071 t->redraw |= TREDRAW_HARD;
1076 // if (WM_modal_tweak_exit(event, t->event_type))
1077 //// if (t->options & CTX_TWEAK)
1078 // t->state = TRANS_CONFIRM;
1085 /* confirm transform if launch key is released after mouse move */
1086 if (t->flag & T_RELEASE_CONFIRM) {
1087 /* XXX Keyrepeat bug in Xorg fucks this up, will test when fixed */
1088 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 copy_v3_v3(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)
1159 glVertex2s( offset, 0);
1160 glVertex2s( offset + length, 0);
1161 glVertex2s( offset + length, 0);
1162 glVertex2s( offset + length - size, -size);
1163 glVertex2s( offset + length, 0);
1164 glVertex2s( offset + length - size, size);
1173 glVertex2s( 0, offset);
1174 glVertex2s( 0, offset + length);
1175 glVertex2s( 0, offset + length);
1176 glVertex2s(-size, offset + length - size);
1177 glVertex2s( 0, offset + length);
1178 glVertex2s( size, offset + length - size);
1184 static void drawArrowHead(ArrowDirection d, short size)
1192 glVertex2s( -size, -size);
1194 glVertex2s( -size, size);
1202 glVertex2s(-size, -size);
1204 glVertex2s( size, -size);
1210 static void drawArc(float size, float angle_start, float angle_end, int segments)
1212 float delta = (angle_end - angle_start) / segments;
1215 glBegin(GL_LINE_STRIP);
1217 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)) {
1239 float vecrot[3], cent[2];
1245 copy_v3_v3(vecrot, t->center);
1246 if (t->flag & T_EDIT) {
1247 Object *ob= t->obedit;
1248 if (ob) mul_m4_v3(ob->obmat, vecrot);
1250 else if (t->flag & T_POSE) {
1251 Object *ob=t->poseobj;
1252 if (ob) mul_m4_v3(ob->obmat, vecrot);
1255 projectFloatView(t, vecrot, cent); // no overflow in extreme cases
1259 switch (t->helpline) {
1261 UI_ThemeColor(TH_WIRE);
1264 glBegin(GL_LINE_STRIP);
1265 glVertex2iv(t->mval);
1269 glTranslatef(mval[0], mval[1], 0);
1270 glRotatef(-RAD2DEGF(atan2f(cent[0] - t->mval[0], cent[1] - t->mval[1])), 0, 0, 1);
1274 drawArrow(UP, 5, 10, 5);
1275 drawArrow(DOWN, 5, 10, 5);
1279 UI_ThemeColor(TH_WIRE);
1281 glTranslatef(mval[0], mval[1], 0);
1284 drawArrow(RIGHT, 5, 10, 5);
1285 drawArrow(LEFT, 5, 10, 5);
1289 UI_ThemeColor(TH_WIRE);
1291 glTranslatef(mval[0], mval[1], 0);
1295 drawArrow(UP, 5, 10, 5);
1296 drawArrow(DOWN, 5, 10, 5);
1301 float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
1302 float angle = atan2f(dy, dx);
1303 float dist = sqrtf(dx*dx + dy*dy);
1304 float delta_angle = MIN2(15.0f / dist, (float)M_PI/4.0f);
1305 float spacing_angle = MIN2(5.0f / dist, (float)M_PI/12.0f);
1306 UI_ThemeColor(TH_WIRE);
1309 glBegin(GL_LINE_STRIP);
1310 glVertex2iv(t->mval);
1314 glTranslatef(cent[0] - t->mval[0] + mval[0], cent[1] - t->mval[1] + mval[1], 0);
1318 drawArc(dist, angle - delta_angle, angle - spacing_angle, 10);
1319 drawArc(dist, angle + spacing_angle, angle + delta_angle, 10);
1323 glTranslatef(cosf(angle - delta_angle) * dist, sinf(angle - delta_angle) * dist, 0);
1324 glRotatef(RAD2DEGF(angle - delta_angle), 0, 0, 1);
1326 drawArrowHead(DOWN, 5);
1330 glTranslatef(cosf(angle + delta_angle) * dist, sinf(angle + delta_angle) * dist, 0);
1331 glRotatef(RAD2DEGF(angle + delta_angle), 0, 0, 1);
1333 drawArrowHead(UP, 5);
1340 unsigned char col[3], col2[3];
1341 UI_GetThemeColor3ubv(TH_GRID, col);
1343 glTranslatef(mval[0], mval[1], 0);
1347 UI_make_axis_color(col, col2, 'X');
1348 glColor3ubv((GLubyte *)col2);
1350 drawArrow(RIGHT, 5, 10, 5);
1351 drawArrow(LEFT, 5, 10, 5);
1353 UI_make_axis_color(col, col2, 'Y');
1354 glColor3ubv((GLubyte *)col2);
1356 drawArrow(UP, 5, 10, 5);
1357 drawArrow(DOWN, 5, 10, 5);
1367 static void drawTransformView(const struct bContext *C, struct ARegion *UNUSED(ar), void *arg)
1372 drawPropCircle(C, t);
1377 static void drawTransformPixel(const struct bContext *UNUSED(C), struct ARegion *UNUSED(ar), void *UNUSED(arg))
1379 // TransInfo *t = arg;
1381 // drawHelpline(C, t->mval[0], t->mval[1], t);
1385 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
1387 ToolSettings *ts = CTX_data_tool_settings(C);
1388 int constraint_axis[3] = {0, 0, 0};
1389 int proportional = 0;
1392 // Save back mode in case we're in the generic operator
1393 if ((prop= RNA_struct_find_property(op->ptr, "mode"))) {
1394 RNA_property_enum_set(op->ptr, prop, t->mode);
1397 if ((prop= RNA_struct_find_property(op->ptr, "value"))) {
1398 float *values= (t->flag & T_AUTOVALUES) ? t->auto_values : t->values;
1399 if (RNA_property_array_check(prop)) {
1400 RNA_property_float_set_array(op->ptr, prop, values);
1403 RNA_property_float_set(op->ptr, prop, values[0]);
1407 /* convert flag to enum */
1408 switch (t->flag & (T_PROP_EDIT|T_PROP_CONNECTED)) {
1409 case (T_PROP_EDIT|T_PROP_CONNECTED):
1410 proportional = PROP_EDIT_CONNECTED;
1413 proportional = PROP_EDIT_ON;
1416 proportional = PROP_EDIT_OFF;
1419 // If modal, save settings back in scene if not set as operator argument
1420 if (t->flag & T_MODAL) {
1422 /* save settings if not set in operator */
1423 if ((prop = RNA_struct_find_property(op->ptr, "proportional")) &&
1424 !RNA_property_is_set(op->ptr, prop))
1427 ts->proportional = proportional;
1429 ts->proportional_objects = (proportional != PROP_EDIT_OFF);
1432 if ((prop = RNA_struct_find_property(op->ptr, "proportional_size")) &&
1433 !RNA_property_is_set(op->ptr, prop))
1435 ts->proportional_size = t->prop_size;
1438 if ((prop = RNA_struct_find_property(op->ptr, "proportional_edit_falloff")) &&
1439 !RNA_property_is_set(op->ptr, prop))
1441 ts->prop_mode = t->prop_mode;
1444 /* do we check for parameter? */
1445 if (t->modifiers & MOD_SNAP) {
1446 ts->snap_flag |= SCE_SNAP;
1449 ts->snap_flag &= ~SCE_SNAP;
1452 if (t->spacetype == SPACE_VIEW3D) {
1453 if ((prop = RNA_struct_find_property(op->ptr, "constraint_orientation")) &&
1454 !RNA_property_is_set(op->ptr, prop))
1456 View3D *v3d = t->view;
1458 v3d->twmode = t->current_orientation;
1463 if (RNA_struct_find_property(op->ptr, "proportional")) {
1464 RNA_enum_set(op->ptr, "proportional", proportional);
1465 RNA_enum_set(op->ptr, "proportional_edit_falloff", t->prop_mode);
1466 RNA_float_set(op->ptr, "proportional_size", t->prop_size);
1469 if ((prop = RNA_struct_find_property(op->ptr, "axis"))) {
1470 RNA_property_float_set_array(op->ptr, prop, t->axis);
1473 if ((prop = RNA_struct_find_property(op->ptr, "mirror"))) {
1474 RNA_property_boolean_set(op->ptr, prop, t->flag & T_MIRROR);
1477 if ((prop = RNA_struct_find_property(op->ptr, "constraint_axis"))) {
1478 /* constraint orientation can be global, event if user selects something else
1479 * so use the orientation in the constraint if set
1481 if (t->con.mode & CON_APPLY) {
1482 RNA_enum_set(op->ptr, "constraint_orientation", t->con.orientation);
1485 RNA_enum_set(op->ptr, "constraint_orientation", t->current_orientation);
1488 if (t->con.mode & CON_APPLY) {
1489 if (t->con.mode & CON_AXIS0) {
1490 constraint_axis[0] = 1;
1492 if (t->con.mode & CON_AXIS1) {
1493 constraint_axis[1] = 1;
1495 if (t->con.mode & CON_AXIS2) {
1496 constraint_axis[2] = 1;
1500 RNA_property_boolean_set_array(op->ptr, prop, constraint_axis);
1504 /* note: caller needs to free 't' on a 0 return */
1505 int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int mode)
1512 /* added initialize, for external calls to set stuff in TransInfo, like undo string */
1514 t->state = TRANS_STARTING;
1516 if ( (prop = RNA_struct_find_property(op->ptr, "texture_space")) && RNA_property_is_set(op->ptr, prop)) {
1517 if (RNA_property_boolean_get(op->ptr, prop)) {
1518 options |= CTX_TEXTURE;
1522 t->options = options;
1526 t->launch_event = event ? event->type : -1;
1528 if (t->launch_event == EVT_TWEAK_R) {
1529 t->launch_event = RIGHTMOUSE;
1531 else if (t->launch_event == EVT_TWEAK_L) {
1532 t->launch_event = LEFTMOUSE;
1535 // XXX Remove this when wm_operator_call_internal doesn't use window->eventstate (which can have type = 0)
1536 // For manipulator only, so assume LEFTMOUSE
1537 if (t->launch_event == 0) {
1538 t->launch_event = LEFTMOUSE;
1541 if (!initTransInfo(C, t, op, event)) { /* internal data, mouse, vectors */
1545 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);
1558 t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
1560 else if (t->spacetype == SPACE_CLIP) {
1561 unit_m3(t->spacemtx);
1562 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
1563 t->options |= CTX_MOVIECLIP;
1566 unit_m3(t->spacemtx);
1568 createTransData(C, t); // make TransData structs from selection
1570 if (t->total == 0) {
1575 /* 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) {
1581 if (kmi->propvalue == TFM_MODAL_SNAP_INV_ON && kmi->val == KM_PRESS) {
1582 if ((ELEM(kmi->type, LEFTCTRLKEY, RIGHTCTRLKEY) && event->ctrl) ||
1583 (ELEM(kmi->type, LEFTSHIFTKEY, RIGHTSHIFTKEY) && event->shift) ||
1584 (ELEM(kmi->type, LEFTALTKEY, RIGHTALTKEY) && event->alt) ||
1585 ((kmi->type == OSKEY) && event->oskey) )
1587 t->modifiers |= MOD_SNAP_INVERT;
1595 initSnapping(t, op); // Initialize snapping data AFTER mode flags
1597 /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
1598 /* EVIL2: we gave as argument also texture space context bit... was cleared */
1599 /* EVIL3: extend mode for animation editors also switches modes... but is best way to avoid duplicate code */
1602 calculatePropRatio(t);
1605 initMouseInput(t, &t->mouse, t->center2d, t->imval);
1608 case TFM_TRANSLATION:
1626 case TFM_SHRINKFATTEN:
1627 initShrinkFatten(t);
1632 case TFM_CURVE_SHRINKFATTEN:
1633 initCurveShrinkFatten(t);
1645 { /* used for both B-Bone width (bonesize) as for deform-dist (envelope) */
1646 bArmature *arm= t->poseobj->data;
1647 if (arm->drawtype==ARM_ENVELOPE)
1648 initBoneEnvelope(t);
1653 case TFM_BONE_ENVELOPE:
1654 initBoneEnvelope(t);
1656 case TFM_EDGE_SLIDE:
1662 case TFM_TIME_TRANSLATE:
1663 initTimeTranslate(t);
1665 case TFM_TIME_SLIDE:
1668 case TFM_TIME_SCALE:
1671 case TFM_TIME_DUPLICATE:
1672 /* same as TFM_TIME_EXTEND, but we need the mode info for later
1673 * so that duplicate-culling will work properly
1675 if (ELEM(t->spacetype, SPACE_IPO, SPACE_NLA))
1678 initTimeTranslate(t);
1681 case TFM_TIME_EXTEND:
1682 /* now that transdata has been made, do like for TFM_TIME_TRANSLATE (for most Animation
1683 * Editors because they have only 1D transforms for time values) or TFM_TRANSLATION
1684 * (for Graph/NLA Editors only since they uses 'standard' transforms to get 2D movement)
1685 * depending on which editor this was called from
1687 if (ELEM(t->spacetype, SPACE_IPO, SPACE_NLA))
1690 initTimeTranslate(t);
1712 if (t->state == TRANS_CANCEL) {
1718 /* overwrite initial values if operator supplied a non-null vector */
1719 if ((prop = RNA_struct_find_property(op->ptr, "value")) && RNA_property_is_set(op->ptr, prop)) {
1720 float values[4]= {0}; /* in case value isn't length 4, avoid uninitialized memory */
1722 if (RNA_property_array_check(prop)) {
1723 RNA_float_get_array(op->ptr, "value", values);
1726 values[0]= RNA_float_get(op->ptr, "value");
1729 copy_v4_v4(t->values, values);
1730 copy_v4_v4(t->auto_values, values);
1731 t->flag |= T_AUTOVALUES;
1734 /* Transformation axis from operator */
1735 if ((prop = RNA_struct_find_property(op->ptr, "axis")) && RNA_property_is_set(op->ptr, prop)) {
1736 RNA_property_float_get_array(op->ptr, prop, t->axis);
1737 normalize_v3(t->axis);
1738 copy_v3_v3(t->axis_orig, t->axis);
1741 /* Constraint init from operator */
1742 if ((prop = RNA_struct_find_property(op->ptr, "constraint_axis")) && RNA_property_is_set(op->ptr, prop)) {
1743 int constraint_axis[3];
1745 RNA_property_boolean_get_array(op->ptr, prop, constraint_axis);
1747 if (constraint_axis[0] || constraint_axis[1] || constraint_axis[2]) {
1748 t->con.mode |= CON_APPLY;
1750 if (constraint_axis[0]) {
1751 t->con.mode |= CON_AXIS0;
1753 if (constraint_axis[1]) {
1754 t->con.mode |= CON_AXIS1;
1756 if (constraint_axis[2]) {
1757 t->con.mode |= CON_AXIS2;
1760 setUserConstraint(t, t->current_orientation, t->con.mode, "%s");
1769 void transformApply(bContext *C, TransInfo *t)
1773 if ((t->redraw & TREDRAW_HARD) || (t->draw_handle_apply == NULL && (t->redraw & TREDRAW_SOFT))) {
1774 if (t->modifiers & MOD_CONSTRAINT_SELECT)
1775 t->con.mode |= CON_SELECT;
1777 selectConstraint(t);
1779 t->transform(t, t->mval); // calls recalcData()
1780 viewRedrawForce(C, t);
1782 t->redraw = TREDRAW_NOTHING;
1784 else if (t->redraw & TREDRAW_SOFT) {
1785 viewRedrawForce(C, t);
1788 /* If auto confirm is on, break after one pass */
1789 if (t->options & CTX_AUTOCONFIRM) {
1790 t->state = TRANS_CONFIRM;
1793 if (BKE_ptcache_get_continue_physics()) {
1795 //do_screenhandlers(G.curscreen);
1796 t->redraw |= TREDRAW_HARD;
1802 static void drawTransformApply(const bContext *C, struct ARegion *UNUSED(ar), void *arg)
1806 if (t->redraw & TREDRAW_SOFT) {
1807 t->redraw |= TREDRAW_HARD;
1808 transformApply((bContext *)C, t);
1812 int transformEnd(bContext *C, TransInfo *t)
1814 int exit_code = OPERATOR_RUNNING_MODAL;
1818 if (t->state != TRANS_STARTING && t->state != TRANS_RUNNING) {
1819 /* handle restoring objects */
1820 if (t->state == TRANS_CANCEL) {
1821 /* exception, edge slide transformed UVs too */
1822 if (t->mode==TFM_EDGE_SLIDE)
1823 doEdgeSlide(t, 0.0f);
1825 exit_code = OPERATOR_CANCELLED;
1826 restoreTransObjects(t); // calls recalcData()
1829 exit_code = OPERATOR_FINISHED;
1832 /* aftertrans does insert keyframes, and clears base flags, doesnt read transdata */
1833 special_aftertrans_update(C, t);
1838 /* send events out for redraws */
1839 viewRedrawPost(C, t);
1841 /* Undo as last, certainly after special_trans_update! */
1843 if (t->state == TRANS_CANCEL) {
1844 // if (t->undostr) ED_undo_push(C, t->undostr);
1847 // if (t->undostr) ED_undo_push(C, t->undostr);
1848 // else ED_undo_push(C, transform_to_undostr(t));
1852 viewRedrawForce(C, t);
1860 /* ************************** TRANSFORM LOCKS **************************** */
1862 static void protectedTransBits(short protectflag, float *vec)
1864 if (protectflag & OB_LOCK_LOCX)
1866 if (protectflag & OB_LOCK_LOCY)
1868 if (protectflag & OB_LOCK_LOCZ)
1872 static void protectedSizeBits(short protectflag, float *size)
1874 if (protectflag & OB_LOCK_SCALEX)
1876 if (protectflag & OB_LOCK_SCALEY)
1878 if (protectflag & OB_LOCK_SCALEZ)
1882 static void protectedRotateBits(short protectflag, float *eul, float *oldeul)
1884 if (protectflag & OB_LOCK_ROTX)
1886 if (protectflag & OB_LOCK_ROTY)
1888 if (protectflag & OB_LOCK_ROTZ)
1893 /* this function only does the delta rotation */
1894 /* axis-angle is usually internally stored as quats... */
1895 static void protectedAxisAngleBits(short protectflag, float axis[3], float *angle, float oldAxis[3], float oldAngle)
1897 /* check that protection flags are set */
1898 if ((protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) == 0)
1901 if (protectflag & OB_LOCK_ROT4D) {
1902 /* axis-angle getting limited as 4D entities that they are... */
1903 if (protectflag & OB_LOCK_ROTW)
1905 if (protectflag & OB_LOCK_ROTX)
1906 axis[0]= oldAxis[0];
1907 if (protectflag & OB_LOCK_ROTY)
1908 axis[1]= oldAxis[1];
1909 if (protectflag & OB_LOCK_ROTZ)
1910 axis[2]= oldAxis[2];
1913 /* axis-angle get limited with euler... */
1914 float eul[3], oldeul[3];
1916 axis_angle_to_eulO( eul, EULER_ORDER_DEFAULT,axis, *angle);
1917 axis_angle_to_eulO( oldeul, EULER_ORDER_DEFAULT,oldAxis, oldAngle);
1919 if (protectflag & OB_LOCK_ROTX)
1921 if (protectflag & OB_LOCK_ROTY)
1923 if (protectflag & OB_LOCK_ROTZ)
1926 eulO_to_axis_angle( axis, angle,eul, EULER_ORDER_DEFAULT);
1928 /* when converting to axis-angle, we need a special exception for the case when there is no axis */
1929 if (IS_EQF(axis[0], axis[1]) && IS_EQF(axis[1], axis[2])) {
1930 /* for now, rotate around y-axis then (so that it simply becomes the roll) */
1936 /* this function only does the delta rotation */
1937 static void protectedQuaternionBits(short protectflag, float *quat, float *oldquat)
1939 /* check that protection flags are set */
1940 if ((protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) == 0)
1943 if (protectflag & OB_LOCK_ROT4D) {
1944 /* quaternions getting limited as 4D entities that they are... */
1945 if (protectflag & OB_LOCK_ROTW)
1946 quat[0]= oldquat[0];
1947 if (protectflag & OB_LOCK_ROTX)
1948 quat[1]= oldquat[1];
1949 if (protectflag & OB_LOCK_ROTY)
1950 quat[2]= oldquat[2];
1951 if (protectflag & OB_LOCK_ROTZ)
1952 quat[3]= oldquat[3];
1955 /* quaternions get limited with euler... (compatibility mode) */
1956 float eul[3], oldeul[3], nquat[4], noldquat[4];
1959 qlen= normalize_qt_qt(nquat, quat);
1960 normalize_qt_qt(noldquat, oldquat);
1962 quat_to_eul(eul, nquat);
1963 quat_to_eul(oldeul, noldquat);
1965 if (protectflag & OB_LOCK_ROTX)
1967 if (protectflag & OB_LOCK_ROTY)
1969 if (protectflag & OB_LOCK_ROTZ)
1972 eul_to_quat( quat,eul);
1974 /* restore original quat size */
1975 mul_qt_fl(quat, qlen);
1977 /* quaternions flip w sign to accumulate rotations correctly */
1978 if ( (nquat[0]<0.0f && quat[0]>0.0f) || (nquat[0]>0.0f && quat[0]<0.0f) ) {
1979 mul_qt_fl(quat, -1.0f);
1984 /* ******************* TRANSFORM LIMITS ********************** */
1986 static void constraintTransLim(TransInfo *t, TransData *td)
1989 bConstraintTypeInfo *ctiLoc= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
1990 bConstraintTypeInfo *ctiDist= get_constraint_typeinfo(CONSTRAINT_TYPE_DISTLIMIT);
1992 bConstraintOb cob= {NULL};
1994 float ctime = (float)(t->scene->r.cfra);
1996 /* Make a temporary bConstraintOb for using these limit constraints
1997 * - they only care that cob->matrix is correctly set ;-)
1998 * - current space should be local
2000 unit_m4(cob.matrix);
2001 copy_v3_v3(cob.matrix[3], td->loc);
2003 /* Evaluate valid constraints */
2004 for (con= td->con; con; con= con->next) {
2005 bConstraintTypeInfo *cti = NULL;
2006 ListBase targets = {NULL, NULL};
2009 /* only consider constraint if enabled */
2010 if (con->flag & CONSTRAINT_DISABLE) continue;
2011 if (con->enforce == 0.0f) continue;
2013 /* only use it if it's tagged for this purpose (and the right type) */
2014 if (con->type == CONSTRAINT_TYPE_LOCLIMIT) {
2015 bLocLimitConstraint *data= con->data;
2017 if ((data->flag2 & LIMIT_TRANSFORM)==0)
2021 else if (con->type == CONSTRAINT_TYPE_DISTLIMIT) {
2022 bDistLimitConstraint *data= con->data;
2024 if ((data->flag & LIMITDIST_TRANSFORM)==0)
2030 /* do space conversions */
2031 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2032 /* just multiply by td->mtx (this should be ok) */
2033 copy_m4_m4(tmat, cob.matrix);
2034 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
2036 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
2037 /* skip... incompatable spacetype */
2041 /* get constraint targets if needed */
2042 get_constraint_targets_for_solving(con, &cob, &targets, ctime);
2045 cti->evaluate_constraint(con, &cob, &targets);
2047 /* convert spaces again */
2048 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2049 /* just multiply by td->mtx (this should be ok) */
2050 copy_m4_m4(tmat, cob.matrix);
2051 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
2054 /* free targets list */
2055 BLI_freelistN(&targets);
2059 /* copy results from cob->matrix */
2060 copy_v3_v3(td->loc, cob.matrix[3]);
2064 static void constraintob_from_transdata(bConstraintOb *cob, TransData *td)
2066 /* Make a temporary bConstraintOb for use by limit constraints
2067 * - they only care that cob->matrix is correctly set ;-)
2068 * - current space should be local
2070 memset(cob, 0, sizeof(bConstraintOb));
2072 if (td->ext->rotOrder == ROT_MODE_QUAT) {
2074 /* objects and bones do normalization first too, otherwise
2075 * we don't necessarily end up with a rotation matrix, and
2076 * then conversion back to quat gives a different result */
2078 normalize_qt_qt(quat, td->ext->quat);
2079 quat_to_mat4(cob->matrix, quat);
2081 else if (td->ext->rotOrder == ROT_MODE_AXISANGLE) {
2083 axis_angle_to_mat4(cob->matrix, &td->ext->quat[1], td->ext->quat[0]);
2087 eulO_to_mat4(cob->matrix, td->ext->rot, td->ext->rotOrder);
2092 static void constraintRotLim(TransInfo *UNUSED(t), TransData *td)
2095 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
2100 /* Evaluate valid constraints */
2101 for (con= td->con; con; con= con->next) {
2102 /* only consider constraint if enabled */
2103 if (con->flag & CONSTRAINT_DISABLE) continue;
2104 if (con->enforce == 0.0f) continue;
2106 /* we're only interested in Limit-Rotation constraints */
2107 if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
2108 bRotLimitConstraint *data= con->data;
2111 /* only use it if it's tagged for this purpose */
2112 if ((data->flag2 & LIMIT_TRANSFORM)==0)
2115 /* skip incompatable spacetypes */
2116 if (!ELEM(con->ownspace, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL))
2119 /* only do conversion if necessary, to preserve quats and eulers */
2121 constraintob_from_transdata(&cob, td);
2125 /* do space conversions */
2126 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2127 /* just multiply by td->mtx (this should be ok) */
2128 copy_m4_m4(tmat, cob.matrix);
2129 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
2133 cti->evaluate_constraint(con, &cob, NULL);
2135 /* convert spaces again */
2136 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2137 /* just multiply by td->mtx (this should be ok) */
2138 copy_m4_m4(tmat, cob.matrix);
2139 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
2145 /* copy results from cob->matrix */
2146 if (td->ext->rotOrder == ROT_MODE_QUAT) {
2148 mat4_to_quat( td->ext->quat,cob.matrix);
2150 else if (td->ext->rotOrder == ROT_MODE_AXISANGLE) {
2152 mat4_to_axis_angle( &td->ext->quat[1], &td->ext->quat[0],cob.matrix);
2156 mat4_to_eulO( td->ext->rot, td->ext->rotOrder,cob.matrix);
2162 static void constraintSizeLim(TransInfo *t, TransData *td)
2164 if (td->con && td->ext) {
2165 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
2166 bConstraintOb cob= {NULL};
2169 /* Make a temporary bConstraintOb for using these limit constraints
2170 * - they only care that cob->matrix is correctly set ;-)
2171 * - current space should be local
2173 if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
2174 /* scale val and reset size */
2175 return; // TODO: fix this case
2178 /* Reset val if SINGLESIZE but using a constraint */
2179 if (td->flag & TD_SINGLESIZE)
2182 size_to_mat4( cob.matrix,td->ext->size);
2185 /* Evaluate valid constraints */
2186 for (con= td->con; con; con= con->next) {
2187 /* only consider constraint if enabled */
2188 if (con->flag & CONSTRAINT_DISABLE) continue;
2189 if (con->enforce == 0.0f) continue;
2191 /* we're only interested in Limit-Scale constraints */
2192 if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
2193 bSizeLimitConstraint *data= con->data;
2196 /* only use it if it's tagged for this purpose */
2197 if ((data->flag2 & LIMIT_TRANSFORM)==0)
2200 /* do space conversions */
2201 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2202 /* just multiply by td->mtx (this should be ok) */
2203 copy_m4_m4(tmat, cob.matrix);
2204 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
2206 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
2207 /* skip... incompatable spacetype */
2212 cti->evaluate_constraint(con, &cob, NULL);
2214 /* convert spaces again */
2215 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2216 /* just multiply by td->mtx (this should be ok) */
2217 copy_m4_m4(tmat, cob.matrix);
2218 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
2223 /* copy results from cob->matrix */
2224 if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
2225 /* scale val and reset size */
2226 return; // TODO: fix this case
2229 /* Reset val if SINGLESIZE but using a constraint */
2230 if (td->flag & TD_SINGLESIZE)
2233 mat4_to_size( td->ext->size,cob.matrix);
2238 /* ************************** WARP *************************** */
2240 static void postInputWarp(TransInfo *t, float values[3])
2242 mul_v3_fl(values, (float)(M_PI * 2));
2244 if (t->customData) { /* non-null value indicates reversed input */
2249 void initWarp(TransInfo *t)
2251 float max[3], min[3];
2255 t->transform = Warp;
2256 t->handleEvent = handleEventWarp;
2258 setInputPostFct(&t->mouse, postInputWarp);
2259 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2264 t->snap[1] = 5.0f / 180.0f * (float)M_PI;
2265 t->snap[2] = 1.0f / 180.0f * (float)M_PI;
2267 t->num.increment = 1.0f;
2269 t->flag |= T_NO_CONSTRAINT;
2271 /* we need min/max in view space */
2272 for (i = 0; i < t->total; i++) {
2274 copy_v3_v3(center, t->data[i].center);
2275 mul_m3_v3(t->data[i].mtx, center);
2276 mul_m4_v3(t->viewmat, center);
2277 sub_v3_v3(center, t->viewmat[3]);
2279 minmax_v3v3_v3(min, max, center);
2281 copy_v3_v3(max, center);
2282 copy_v3_v3(min, center);
2286 mid_v3_v3v3(t->center, min, max);
2288 if (max[0] == min[0]) max[0] += 0.1f; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */
2289 t->val= (max[0]-min[0])/2.0f; /* t->val is X dimension projected boundbox */
2292 int handleEventWarp(TransInfo *t, wmEvent *event)
2296 if (event->type == MIDDLEMOUSE && event->val == KM_PRESS) {
2297 // Use customData pointer to signal warp direction
2298 if (t->customData == NULL)
2299 t->customData = (void*)1;
2301 t->customData = NULL;
2309 int Warp(TransInfo *t, const int UNUSED(mval[2]))
2311 TransData *td = t->data;
2312 float vec[3], circumfac, dist, phi0, co, si, *curs, cursor[3], gcursor[3];
2316 curs= give_cursor(t->scene, t->view);
2318 * gcursor is the one used for helpline.
2319 * It has to be in the same space as the drawing loop
2320 * (that means it needs to be in the object's space when in edit mode and
2321 * in global space in object mode)
2323 * cursor is used for calculations.
2324 * It needs to be in view space, but we need to take object's offset
2325 * into account if in Edit mode.
2327 copy_v3_v3(cursor, curs);
2328 copy_v3_v3(gcursor, cursor);
2329 if (t->flag & T_EDIT) {
2330 sub_v3_v3(cursor, t->obedit->obmat[3]);
2331 sub_v3_v3(gcursor, t->obedit->obmat[3]);
2332 mul_m3_v3(t->data->smtx, gcursor);
2334 mul_m4_v3(t->viewmat, cursor);
2335 sub_v3_v3(cursor, t->viewmat[3]);
2337 /* amount of radians for warp */
2338 circumfac = t->values[0];
2340 snapGrid(t, &circumfac);
2341 applyNumInput(&t->num, &circumfac);
2343 /* header print for NumInput */
2344 if (hasNumInput(&t->num)) {
2347 outputNumInput(&(t->num), c);
2349 sprintf(str, "Warp: %s", c);
2351 circumfac = DEG2RADF(circumfac);
2354 /* default header print */
2355 sprintf(str, "Warp: %.3f", RAD2DEGF(circumfac));
2358 t->values[0] = circumfac;
2360 circumfac /= 2; /* only need 180 on each side to make 360 */
2362 for (i = 0; i < t->total; i++, td++) {
2364 if (td->flag & TD_NOACTION)
2367 if (td->flag & TD_SKIP)
2370 /* translate point to center, rotate in such a way that outline==distance */
2371 copy_v3_v3(vec, td->iloc);
2372 mul_m3_v3(td->mtx, vec);
2373 mul_m4_v3(t->viewmat, vec);
2374 sub_v3_v3(vec, t->viewmat[3]);
2376 dist= vec[0]-cursor[0];
2378 /* t->val is X dimension projected boundbox */
2379 phi0= (circumfac*dist/t->val);
2381 vec[1]= (vec[1]-cursor[1]);
2383 co= (float)cos(phi0);
2384 si= (float)sin(phi0);
2385 loc[0]= -si*vec[1]+cursor[0];
2386 loc[1]= co*vec[1]+cursor[1];
2389 mul_m4_v3(t->viewinv, loc);
2390 sub_v3_v3(loc, t->viewinv[3]);
2391 mul_m3_v3(td->smtx, loc);
2393 sub_v3_v3(loc, td->iloc);
2394 mul_v3_fl(loc, td->factor);
2395 add_v3_v3v3(td->loc, td->iloc, loc);
2400 ED_area_headerprint(t->sa, str);
2405 /* ************************** SHEAR *************************** */
2407 static void postInputShear(TransInfo *UNUSED(t), float values[3])
2409 mul_v3_fl(values, 0.05f);
2412 void initShear(TransInfo *t)
2414 t->mode = TFM_SHEAR;
2415 t->transform = Shear;
2416 t->handleEvent = handleEventShear;
2418 setInputPostFct(&t->mouse, postInputShear);
2419 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2425 t->snap[2] = t->snap[1] * 0.1f;
2427 t->num.increment = 0.1f;
2429 t->flag |= T_NO_CONSTRAINT;
2432 int handleEventShear(TransInfo *t, wmEvent *event)
2436 if (event->type == MIDDLEMOUSE && event->val == KM_PRESS) {
2437 // Use customData pointer to signal Shear direction
2438 if (t->customData == NULL) {
2439 initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
2440 t->customData = (void*)1;
2443 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2444 t->customData = NULL;
2454 int Shear(TransInfo *t, const int UNUSED(mval[2]))
2456 TransData *td = t->data;
2458 float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3];
2463 copy_m3_m4(persmat, t->viewmat);
2464 invert_m3_m3(persinv, persmat);
2466 value = t->values[0];
2468 snapGrid(t, &value);
2470 applyNumInput(&t->num, &value);
2472 /* header print for NumInput */
2473 if (hasNumInput(&t->num)) {
2476 outputNumInput(&(t->num), c);
2478 sprintf(str, "Shear: %s %s", c, t->proptext);
2481 /* default header print */
2482 sprintf(str, "Shear: %.3f %s", value, t->proptext);
2485 t->values[0] = value;
2489 // Custom data signals shear direction
2490 if (t->customData == NULL)
2495 mul_m3_m3m3(tmat, smat, persmat);
2496 mul_m3_m3m3(totmat, persinv, tmat);
2498 for (i = 0 ; i < t->total; i++, td++) {
2499 if (td->flag & TD_NOACTION)
2502 if (td->flag & TD_SKIP)
2507 mul_m3_m3m3(mat3, totmat, td->mtx);
2508 mul_m3_m3m3(tmat, td->smtx, mat3);
2511 copy_m3_m3(tmat, totmat);
2513 sub_v3_v3v3(vec, td->center, t->center);
2515 mul_m3_v3(tmat, vec);
2517 add_v3_v3(vec, t->center);
2518 sub_v3_v3(vec, td->center);
2520 mul_v3_fl(vec, td->factor);
2522 add_v3_v3v3(td->loc, td->iloc, vec);
2527 ED_area_headerprint(t->sa, str);
2532 /* ************************** RESIZE *************************** */
2534 void initResize(TransInfo *t)
2536 t->mode = TFM_RESIZE;
2537 t->transform = Resize;
2539 initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
2541 t->flag |= T_NULL_ONE;
2542 t->num.flag |= NUM_NULL_ONE;
2543 t->num.flag |= NUM_AFFECT_ALL;
2545 t->flag |= T_NO_ZERO;
2546 t->num.flag |= NUM_NO_ZERO;
2553 t->snap[2] = t->snap[1] * 0.1f;
2555 t->num.increment = t->snap[1];
2558 static void headerResize(TransInfo *t, float vec[3], char *str)
2562 if (hasNumInput(&t->num)) {
2563 outputNumInput(&(t->num), tvec);
2566 BLI_snprintf(&tvec[0], 20, "%.4f", vec[0]);
2567 BLI_snprintf(&tvec[20], 20, "%.4f", vec[1]);
2568 BLI_snprintf(&tvec[40], 20, "%.4f", vec[2]);
2571 if (t->con.mode & CON_APPLY) {
2572 switch (t->num.idx_max) {
2574 spos += sprintf(spos, "Scale: %s%s %s", &tvec[0], t->con.text, t->proptext);
2577 spos += sprintf(spos, "Scale: %s : %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2580 spos += sprintf(spos, "Scale: %s : %s : %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2584 if (t->flag & T_2D_EDIT)
2585 spos += sprintf(spos, "Scale X: %s Y: %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2587 spos += sprintf(spos, "Scale X: %s Y: %s Z: %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2590 if (t->flag & (T_PROP_EDIT|T_PROP_CONNECTED)) {
2591 spos += sprintf(spos, " Proportional size: %.2f", t->prop_size);
2597 #define SIGN(a) (a<-FLT_EPSILON?1:a>FLT_EPSILON?2:3)
2598 #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)
2600 /* smat is reference matrix, only scaled */
2601 static void TransMat3ToSize( float mat[][3], float smat[][3], float *size)
2605 copy_v3_v3(vec, mat[0]);
2606 size[0]= normalize_v3(vec);
2607 copy_v3_v3(vec, mat[1]);
2608 size[1]= normalize_v3(vec);
2609 copy_v3_v3(vec, mat[2]);
2610 size[2]= normalize_v3(vec);
2612 /* first tried with dotproduct... but the sign flip is crucial */
2613 if ( VECSIGNFLIP(mat[0], smat[0]) ) size[0]= -size[0];
2614 if ( VECSIGNFLIP(mat[1], smat[1]) ) size[1]= -size[1];
2615 if ( VECSIGNFLIP(mat[2], smat[2]) ) size[2]= -size[2];
2619 static void ElementResize(TransInfo *t, TransData *td, float mat[3][3])
2621 float tmat[3][3], smat[3][3], center[3];
2624 if (t->flag & T_EDIT) {
2625 mul_m3_m3m3(smat, mat, td->mtx);
2626 mul_m3_m3m3(tmat, td->smtx, smat);
2629 copy_m3_m3(tmat, mat);
2632 if (t->con.applySize) {
2633 t->con.applySize(t, td, tmat);
2636 /* local constraint shouldn't alter center */
2637 if ((t->around == V3D_LOCAL) &&
2638 ( (t->flag & (T_OBJECT|T_POSE)) ||
2639 ((t->flag & T_EDIT) && (t->settings->selectmode & (SCE_SELECT_EDGE|SCE_SELECT_FACE))) ||
2640 (t->obedit && t->obedit->type == OB_ARMATURE))
2643 copy_v3_v3(center, td->center);
2646 copy_v3_v3(center, t->center);
2652 if (t->flag & (T_OBJECT|T_TEXTURE|T_POSE)) {
2653 float obsizemat[3][3];
2654 // Reorient the size mat to fit the oriented object.
2655 mul_m3_m3m3(obsizemat, tmat, td->axismtx);
2656 //print_m3("obsizemat", obsizemat);
2657 TransMat3ToSize(obsizemat, td->axismtx, fsize);
2658 //print_v3("fsize", fsize);
2661 mat3_to_size( fsize,tmat);
2664 protectedSizeBits(td->protectflag, fsize);
2666 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't resize objects itself
2667 if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
2668 /* scale val and reset size */
2669 *td->val = td->ival * (1 + (fsize[0] - 1) * td->factor);
2671 td->ext->size[0] = td->ext->isize[0];
2672 td->ext->size[1] = td->ext->isize[1];
2673 td->ext->size[2] = td->ext->isize[2];
2676 /* Reset val if SINGLESIZE but using a constraint */
2677 if (td->flag & TD_SINGLESIZE)
2678 *td->val = td->ival;
2680 td->ext->size[0] = td->ext->isize[0] * (1 + (fsize[0] - 1) * td->factor);
2681 td->ext->size[1] = td->ext->isize[1] * (1 + (fsize[1] - 1) * td->factor);
2682 td->ext->size[2] = td->ext->isize[2] * (1 + (fsize[2] - 1) * td->factor);
2686 constraintSizeLim(t, td);
2689 /* For individual element center, Editmode need to use iloc */
2690 if (t->flag & T_POINTS)
2691 sub_v3_v3v3(vec, td->iloc, center);
2693 sub_v3_v3v3(vec, td->center, center);
2695 mul_m3_v3(tmat, vec);
2697 add_v3_v3(vec, center);
2698 if (t->flag & T_POINTS)
2699 sub_v3_v3(vec, td->iloc);
2701 sub_v3_v3(vec, td->center);
2703 mul_v3_fl(vec, td->factor);
2705 if (t->flag & (T_OBJECT|T_POSE)) {
2706 mul_m3_v3(td->smtx, vec);
2709 protectedTransBits(td->protectflag, vec);
2710 add_v3_v3v3(td->loc, td->iloc, vec);
2712 constraintTransLim(t, td);
2715 int Resize(TransInfo *t, const int mval[2])
2718 float size[3], mat[3][3];
2723 /* for manipulator, center handle, the scaling can't be done relative to center */
2724 if ( (t->flag & T_USES_MANIPULATOR) && t->con.mode==0) {
2725 ratio = 1.0f - ((t->imval[0] - mval[0]) + (t->imval[1] - mval[1]))/100.0f;
2728 ratio = t->values[0];
2731 size[0] = size[1] = size[2] = ratio;
2735 if (hasNumInput(&t->num)) {
2736 applyNumInput(&t->num, size);
2737 constraintNumInput(t, size);
2740 applySnapping(t, size);
2742 if (t->flag & T_AUTOVALUES) {
2743 copy_v3_v3(size, t->auto_values);
2746 copy_v3_v3(t->values, size);
2748 size_to_mat3( mat,size);
2750 if (t->con.applySize) {
2751 t->con.applySize(t, NULL, mat);
2754 copy_m3_m3(t->mat, mat); // used in manipulator
2756 headerResize(t, size, str);
2758 for (i = 0, td=t->data; i < t->total; i++, td++) {
2759 if (td->flag & TD_NOACTION)
2762 if (td->flag & TD_SKIP)
2765 ElementResize(t, td, mat);
2768 /* evil hack - redo resize if cliping needed */
2769 if (t->flag & T_CLIP_UV && clipUVTransform(t, size, 1)) {
2770 size_to_mat3( mat,size);
2772 if (t->con.applySize)
2773 t->con.applySize(t, NULL, mat);
2775 for (i = 0, td=t->data; i < t->total; i++, td++)
2776 ElementResize(t, td, mat);
2781 ED_area_headerprint(t->sa, str);
2786 /* ************************** TOSPHERE *************************** */
2788 void initToSphere(TransInfo *t)
2790 TransData *td = t->data;
2793 t->mode = TFM_TOSPHERE;
2794 t->transform = ToSphere;
2796 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2802 t->snap[2] = t->snap[1] * 0.1f;
2804 t->num.increment = t->snap[1];
2806 t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
2807 t->flag |= T_NO_CONSTRAINT;
2809 // Calculate average radius
2810 for (i = 0 ; i < t->total; i++, td++) {
2811 t->val += len_v3v3(t->center, td->iloc);
2814 t->val /= (float)t->total;
2817 int ToSphere(TransInfo *t, const int UNUSED(mval[2]))
2820 float ratio, radius;
2823 TransData *td = t->data;
2825 ratio = t->values[0];
2827 snapGrid(t, &ratio);
2829 applyNumInput(&t->num, &ratio);
2836 t->values[0] = ratio;
2838 /* header print for NumInput */
2839 if (hasNumInput(&t->num)) {
2842 outputNumInput(&(t->num), c);
2844 sprintf(str, "To Sphere: %s %s", c, t->proptext);
2847 /* default header print */
2848 sprintf(str, "To Sphere: %.4f %s", ratio, t->proptext);
2852 for (i = 0 ; i < t->total; i++, td++) {
2854 if (td->flag & TD_NOACTION)
2857 if (td->flag & TD_SKIP)
2860 sub_v3_v3v3(vec, td->iloc, t->center);
2862 radius = normalize_v3(vec);
2864 tratio = ratio * td->factor;
2866 mul_v3_fl(vec, radius * (1.0f - tratio) + t->val * tratio);
2868 add_v3_v3v3(td->loc, t->center, vec);
2874 ED_area_headerprint(t->sa, str);
2879 /* ************************** ROTATION *************************** */
2882 static void postInputRotation(TransInfo *t, float values[3])
2884 if ((t->con.mode & CON_APPLY) && t->con.applyRot) {
2885 t->con.applyRot(t, NULL, t->axis, values);
2889 void initRotation(TransInfo *t)