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 *****
42 #include "MEM_guardedalloc.h"
44 #include "DNA_anim_types.h"
45 #include "DNA_armature_types.h"
46 #include "DNA_constraint_types.h"
47 #include "DNA_meshdata_types.h"
48 #include "DNA_scene_types.h" /* PET modes */
50 #include "RNA_access.h"
52 //#include "BIF_editview.h" /* arrows_move_cursor */
54 #include "BIF_glutil.h"
55 //#include "BIF_mywindow.h"
56 //#include "BIF_resources.h"
57 //#include "BIF_screen.h"
58 //#include "BIF_space.h" /* undo */
59 //#include "BIF_toets.h" /* persptoetsen */
60 //#include "BIF_mywindow.h" /* warp_pointer */
61 //#include "BIF_toolbox.h" /* notice */
62 //#include "BIF_editmesh.h"
63 //#include "BIF_editsima.h"
64 //#include "BIF_editparticle.h"
67 //#include "BKE_bad_level_calls.h"/* popmenu and error */
68 #include "BKE_bmesh.h"
69 #include "BKE_context.h"
70 #include "BKE_constraint.h"
71 #include "BKE_global.h"
72 #include "BKE_particle.h"
73 #include "BKE_pointcache.h"
76 //#include "BSE_view.h"
79 #include "ED_keyframing.h"
80 #include "ED_screen.h"
81 #include "ED_space_api.h"
82 #include "ED_markers.h"
83 #include "ED_view3d.h"
86 #include "UI_view2d.h"
91 #include "BLI_blenlib.h"
92 #include "BLI_editVert.h"
93 #include "BLI_ghash.h"
94 #include "BLI_linklist.h"
97 #include "UI_resources.h"
99 //#include "blendef.h"
101 //#include "mydevice.h"
103 #include "transform.h"
105 void drawTransformApply(const struct bContext *C, struct ARegion *ar, void *arg);
107 /* ************************** SPACE DEPENDANT CODE **************************** */
109 void setTransformViewMatrices(TransInfo *t)
111 if(t->spacetype==SPACE_VIEW3D && t->ar && t->ar->regiontype == RGN_TYPE_WINDOW) {
112 RegionView3D *rv3d = t->ar->regiondata;
114 copy_m4_m4(t->viewmat, rv3d->viewmat);
115 copy_m4_m4(t->viewinv, rv3d->viewinv);
116 copy_m4_m4(t->persmat, rv3d->persmat);
117 copy_m4_m4(t->persinv, rv3d->persinv);
118 t->persp = rv3d->persp;
125 t->persp = RV3D_ORTHO;
128 calculateCenter2D(t);
131 void convertViewVec(TransInfo *t, float *vec, short dx, short dy)
133 if (t->spacetype==SPACE_VIEW3D) {
134 if (t->ar->regiontype == RGN_TYPE_WINDOW)
136 window_to_3d_delta(t->ar, vec, dx, dy);
139 else if(t->spacetype==SPACE_IMAGE) {
140 View2D *v2d = t->view;
141 float divx, divy, aspx, aspy;
143 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
145 divx= v2d->mask.xmax-v2d->mask.xmin;
146 divy= v2d->mask.ymax-v2d->mask.ymin;
148 vec[0]= aspx*(v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
149 vec[1]= aspy*(v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
152 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
153 View2D *v2d = t->view;
156 divx= v2d->mask.xmax-v2d->mask.xmin;
157 divy= v2d->mask.ymax-v2d->mask.ymin;
159 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx) / (divx);
160 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy) / (divy);
163 else if(t->spacetype==SPACE_NODE) {
164 View2D *v2d = &t->ar->v2d;
167 divx= v2d->mask.xmax-v2d->mask.xmin;
168 divy= v2d->mask.ymax-v2d->mask.ymin;
170 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
171 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
174 else if(t->spacetype==SPACE_SEQ) {
175 View2D *v2d = &t->ar->v2d;
178 divx= v2d->mask.xmax-v2d->mask.xmin;
179 divy= v2d->mask.ymax-v2d->mask.ymin;
181 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
182 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
187 void projectIntView(TransInfo *t, float *vec, int *adr)
189 if (t->spacetype==SPACE_VIEW3D) {
190 if(t->ar->regiontype == RGN_TYPE_WINDOW)
191 project_int_noclip(t->ar, vec, adr);
193 else if(t->spacetype==SPACE_IMAGE) {
194 float aspx, aspy, v[2];
196 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
200 UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr+1);
202 else if(t->spacetype == SPACE_ACTION) {
203 SpaceAction *sact = t->sa->spacedata.first;
206 if (sact->flag & SACTION_DRAWTIME) {
207 //vec[0] = vec[0]/((t->scene->r.frs_sec / t->scene->r.frs_sec_base));
209 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
212 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
218 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
221 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
225 else if(t->spacetype==SPACE_SEQ) { /* XXX not tested yet, but should work */
228 UI_view2d_to_region_no_clip((View2D *)t->view, vec[0], vec[1], out, out+1);
234 void projectFloatView(TransInfo *t, float *vec, float *adr)
236 if (t->spacetype==SPACE_VIEW3D) {
237 if(t->ar->regiontype == RGN_TYPE_WINDOW)
238 project_float_noclip(t->ar, vec, adr);
240 else if(t->spacetype==SPACE_IMAGE) {
243 projectIntView(t, vec, a);
247 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
250 projectIntView(t, vec, a);
256 void applyAspectRatio(TransInfo *t, float *vec)
258 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
259 SpaceImage *sima= t->sa->spacedata.first;
262 if((sima->flag & SI_COORDFLOATS)==0) {
264 ED_space_image_size(sima, &width, &height);
270 ED_space_image_uv_aspect(sima, &aspx, &aspy);
276 void removeAspectRatio(TransInfo *t, float *vec)
278 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
279 SpaceImage *sima= t->sa->spacedata.first;
282 if((sima->flag & SI_COORDFLOATS)==0) {
284 ED_space_image_size(sima, &width, &height);
290 ED_space_image_uv_aspect(sima, &aspx, &aspy);
296 static void viewRedrawForce(const bContext *C, TransInfo *t)
298 if (t->spacetype == SPACE_VIEW3D)
300 /* Do we need more refined tags? */
302 WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
304 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
306 /* for realtime animation record - send notifiers recognised by animation editors */
307 // XXX: is this notifier a lame duck?
308 if ((t->animtimer) && IS_AUTOKEY_ON(t->scene))
309 WM_event_add_notifier(C, NC_OBJECT|ND_KEYS, NULL);
312 else if (t->spacetype == SPACE_ACTION) {
313 //SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
314 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
316 else if (t->spacetype == SPACE_IPO) {
317 //SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
318 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
320 else if (t->spacetype == SPACE_NLA) {
321 WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_EDITED, NULL);
323 else if(t->spacetype == SPACE_NODE)
325 //ED_area_tag_redraw(t->sa);
326 WM_event_add_notifier(C, NC_SPACE|ND_SPACE_NODE_VIEW, NULL);
328 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);
340 static void viewRedrawPost(TransInfo *t)
342 ED_area_headerprint(t->sa, NULL);
344 if(t->spacetype == SPACE_VIEW3D) {
345 /* if autokeying is enabled, send notifiers that keyframes were added */
346 if (IS_AUTOKEY_ON(t->scene))
347 WM_main_add_notifier(NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
350 #if 0 // TRANSFORM_FIX_ME
351 if(t->spacetype==SPACE_VIEW3D) {
352 allqueue(REDRAWBUTSOBJECT, 0);
353 allqueue(REDRAWVIEW3D, 0);
355 else if(t->spacetype==SPACE_IMAGE) {
356 allqueue(REDRAWIMAGE, 0);
357 allqueue(REDRAWVIEW3D, 0);
359 else if(ELEM3(t->spacetype, SPACE_ACTION, SPACE_NLA, SPACE_IPO)) {
360 allqueue(REDRAWVIEW3D, 0);
361 allqueue(REDRAWACTION, 0);
362 allqueue(REDRAWNLA, 0);
363 allqueue(REDRAWIPO, 0);
364 allqueue(REDRAWTIME, 0);
365 allqueue(REDRAWBUTSOBJECT, 0);
368 scrarea_queue_headredraw(curarea);
372 /* ************************** TRANSFORMATIONS **************************** */
374 void BIF_selectOrientation() {
375 #if 0 // TRANSFORM_FIX_ME
377 char *str_menu = BIF_menustringTransformOrientation("Orientation");
378 val= pupmenu(str_menu);
387 static void view_editmove(unsigned short UNUSED(event))
389 #if 0 // TRANSFORM_FIX_ME
391 /* Regular: Zoom in */
392 /* Shift: Scroll up */
393 /* Ctrl: Scroll right */
394 /* Alt-Shift: Rotate up */
395 /* Alt-Ctrl: Rotate right */
397 /* only work in 3D window for now
398 * In the end, will have to send to event to a 2D window handler instead
400 if (Trans.flag & T_2D_EDIT)
406 if( G.qual & LR_SHIFTKEY ) {
407 if( G.qual & LR_ALTKEY ) {
408 G.qual &= ~LR_SHIFTKEY;
410 G.qual |= LR_SHIFTKEY;
414 } else if( G.qual & LR_CTRLKEY ) {
415 if( G.qual & LR_ALTKEY ) {
416 G.qual &= ~LR_CTRLKEY;
418 G.qual |= LR_CTRLKEY;
422 } else if(U.uiflag & USER_WHEELZOOMDIR)
423 persptoetsen(PADMINUS);
425 persptoetsen(PADPLUSKEY);
430 if( G.qual & LR_SHIFTKEY ) {
431 if( G.qual & LR_ALTKEY ) {
432 G.qual &= ~LR_SHIFTKEY;
434 G.qual |= LR_SHIFTKEY;
438 } else if( G.qual & LR_CTRLKEY ) {
439 if( G.qual & LR_ALTKEY ) {
440 G.qual &= ~LR_CTRLKEY;
442 G.qual |= LR_CTRLKEY;
446 } else if(U.uiflag & USER_WHEELZOOMDIR)
447 persptoetsen(PADPLUSKEY);
449 persptoetsen(PADMINUS);
456 setTransformViewMatrices(&Trans);
460 /* ************************************************* */
462 /* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
463 #define TFM_MODAL_CANCEL 1
464 #define TFM_MODAL_CONFIRM 2
465 #define TFM_MODAL_TRANSLATE 3
466 #define TFM_MODAL_ROTATE 4
467 #define TFM_MODAL_RESIZE 5
468 #define TFM_MODAL_SNAP_INV_ON 6
469 #define TFM_MODAL_SNAP_INV_OFF 7
470 #define TFM_MODAL_SNAP_TOGGLE 8
471 #define TFM_MODAL_AXIS_X 9
472 #define TFM_MODAL_AXIS_Y 10
473 #define TFM_MODAL_AXIS_Z 11
474 #define TFM_MODAL_PLANE_X 12
475 #define TFM_MODAL_PLANE_Y 13
476 #define TFM_MODAL_PLANE_Z 14
477 #define TFM_MODAL_CONS_OFF 15
478 #define TFM_MODAL_ADD_SNAP 16
479 #define TFM_MODAL_REMOVE_SNAP 17
480 /* 18 and 19 used by numinput, defined in transform.h
482 #define TFM_MODAL_PROPSIZE_UP 20
483 #define TFM_MODAL_PROPSIZE_DOWN 21
485 /* called in transform_ops.c, on each regeneration of keymaps */
486 wmKeyMap* transform_modal_keymap(wmKeyConfig *keyconf)
488 static EnumPropertyItem modal_items[] = {
489 {TFM_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
490 {TFM_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
491 {TFM_MODAL_TRANSLATE, "TRANSLATE", 0, "Translate", ""},
492 {TFM_MODAL_ROTATE, "ROTATE", 0, "Rotate", ""},
493 {TFM_MODAL_RESIZE, "RESIZE", 0, "Resize", ""},
494 {TFM_MODAL_SNAP_INV_ON, "SNAP_INV_ON", 0, "Invert Snap On", ""},
495 {TFM_MODAL_SNAP_INV_OFF, "SNAP_INV_OFF", 0, "Invert Snap Off", ""},
496 {TFM_MODAL_SNAP_TOGGLE, "SNAP_TOGGLE", 0, "Snap Toggle", ""},
497 {TFM_MODAL_AXIS_X, "AXIS_X", 0, "Orientation X axis", ""},
498 {TFM_MODAL_AXIS_Y, "AXIS_Y", 0, "Orientation Y axis", ""},
499 {TFM_MODAL_AXIS_Z, "AXIS_Z", 0, "Orientation Z axis", ""},
500 {TFM_MODAL_PLANE_X, "PLANE_X", 0, "Orientation X plane", ""},
501 {TFM_MODAL_PLANE_Y, "PLANE_Y", 0, "Orientation Y plane", ""},
502 {TFM_MODAL_PLANE_Z, "PLANE_Z", 0, "Orientation Z plane", ""},
503 {TFM_MODAL_CONS_OFF, "CONS_OFF", 0, "Remove Constraints", ""},
504 {TFM_MODAL_ADD_SNAP, "ADD_SNAP", 0, "Add Snap Point", ""},
505 {TFM_MODAL_REMOVE_SNAP, "REMOVE_SNAP", 0, "Remove Last Snap Point", ""},
506 {NUM_MODAL_INCREMENT_UP, "INCREMENT_UP", 0, "Numinput Increment Up", ""},
507 {NUM_MODAL_INCREMENT_DOWN, "INCREMENT_DOWN", 0, "Numinput Increment Down", ""},
508 {TFM_MODAL_PROPSIZE_UP, "PROPORTIONAL_SIZE_UP", 0, "Increase Proportional Influence", ""},
509 {TFM_MODAL_PROPSIZE_DOWN, "PROPORTIONAL_SIZE_DOWN", 0, "Decrease Poportional Influence", ""},
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, AKEY, KM_PRESS, 0, 0, TFM_MODAL_ADD_SNAP);
535 WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, KM_ALT, 0, TFM_MODAL_REMOVE_SNAP);
537 WM_modalkeymap_add_item(keymap, UPARROWKEY, KM_PRESS, 0, 0, NUM_MODAL_INCREMENT_UP);
538 WM_modalkeymap_add_item(keymap, DOWNARROWKEY, KM_PRESS, 0, 0, NUM_MODAL_INCREMENT_DOWN);
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);
549 int transformEvent(TransInfo *t, wmEvent *event)
551 float mati[3][3] = {{1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}};
552 char cmode = constraintModeToChar(t);
555 t->redraw |= handleMouseInput(t, &t->mouse, event);
557 if (event->type == MOUSEMOVE)
559 if (t->modifiers & MOD_CONSTRAINT_SELECT)
560 t->con.mode |= CON_SELECT;
562 t->mval[0] = event->x - t->ar->winrct.xmin;
563 t->mval[1] = event->y - t->ar->winrct.ymin;
565 t->redraw |= TREDRAW_SOFT;
567 if (t->state == TRANS_STARTING) {
568 t->state = TRANS_RUNNING;
571 applyMouseInput(t, &t->mouse, t->mval, t->values);
574 /* handle modal keymap first */
575 if (event->type == EVT_MODAL_MAP) {
576 switch (event->val) {
577 case TFM_MODAL_CANCEL:
578 t->state = TRANS_CANCEL;
580 case TFM_MODAL_CONFIRM:
581 t->state = TRANS_CONFIRM;
583 case TFM_MODAL_TRANSLATE:
584 /* only switch when... */
585 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
586 resetTransRestrictions(t);
587 restoreTransObjects(t);
589 initSnapping(t, NULL); // need to reinit after mode change
590 t->redraw |= TREDRAW_HARD;
593 case TFM_MODAL_ROTATE:
594 /* only switch when... */
595 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
597 resetTransRestrictions(t);
599 if (t->mode == TFM_ROTATION) {
600 restoreTransObjects(t);
604 restoreTransObjects(t);
607 initSnapping(t, NULL); // need to reinit after mode change
608 t->redraw |= TREDRAW_HARD;
611 case TFM_MODAL_RESIZE:
612 /* only switch when... */
613 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
614 resetTransRestrictions(t);
615 restoreTransObjects(t);
617 initSnapping(t, NULL); // need to reinit after mode change
618 t->redraw |= TREDRAW_HARD;
622 case TFM_MODAL_SNAP_INV_ON:
623 t->modifiers |= MOD_SNAP_INVERT;
624 t->redraw |= TREDRAW_HARD;
626 case TFM_MODAL_SNAP_INV_OFF:
627 t->modifiers &= ~MOD_SNAP_INVERT;
628 t->redraw |= TREDRAW_HARD;
630 case TFM_MODAL_SNAP_TOGGLE:
631 t->modifiers ^= MOD_SNAP;
632 t->redraw |= TREDRAW_HARD;
634 case TFM_MODAL_AXIS_X:
635 if ((t->flag & T_NO_CONSTRAINT)==0) {
640 if (t->flag & T_2D_EDIT) {
641 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0), "along X");
644 setUserConstraint(t, t->current_orientation, (CON_AXIS0), "along %s X");
647 t->redraw |= TREDRAW_HARD;
650 case TFM_MODAL_AXIS_Y:
651 if ((t->flag & T_NO_CONSTRAINT)==0) {
656 if (t->flag & T_2D_EDIT) {
657 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1), "along Y");
660 setUserConstraint(t, t->current_orientation, (CON_AXIS1), "along %s Y");
663 t->redraw |= TREDRAW_HARD;
666 case TFM_MODAL_AXIS_Z:
667 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
672 setUserConstraint(t, t->current_orientation, (CON_AXIS2), "along %s Z");
674 t->redraw |= TREDRAW_HARD;
677 case TFM_MODAL_PLANE_X:
678 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
683 setUserConstraint(t, t->current_orientation, (CON_AXIS1|CON_AXIS2), "locking %s X");
685 t->redraw |= TREDRAW_HARD;
688 case TFM_MODAL_PLANE_Y:
689 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
694 setUserConstraint(t, t->current_orientation, (CON_AXIS0|CON_AXIS2), "locking %s Y");
696 t->redraw |= TREDRAW_HARD;
699 case TFM_MODAL_PLANE_Z:
700 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))== 0) {
705 setUserConstraint(t, t->current_orientation, (CON_AXIS0|CON_AXIS1), "locking %s Z");
707 t->redraw |= TREDRAW_HARD;
710 case TFM_MODAL_CONS_OFF:
711 if ((t->flag & T_NO_CONSTRAINT)==0) {
713 t->redraw |= TREDRAW_HARD;
716 case TFM_MODAL_ADD_SNAP:
718 t->redraw |= TREDRAW_HARD;
720 case TFM_MODAL_REMOVE_SNAP:
722 t->redraw |= TREDRAW_HARD;
724 case TFM_MODAL_PROPSIZE_UP:
725 if(t->flag & T_PROP_EDIT) {
727 calculatePropRatio(t);
729 t->redraw |= TREDRAW_HARD;
731 case TFM_MODAL_PROPSIZE_DOWN:
732 if (t->flag & T_PROP_EDIT) {
733 t->prop_size*= 0.90909090f;
734 calculatePropRatio(t);
736 t->redraw |= TREDRAW_HARD;
743 // Modal numinput events
744 t->redraw |= handleNumInput(&(t->num), event);
746 /* else do non-mapped events */
747 else if (event->val==KM_PRESS) {
748 switch (event->type){
750 t->state = TRANS_CANCEL;
752 /* enforce redraw of transform when modifiers are used */
755 t->modifiers |= MOD_CONSTRAINT_PLANE;
756 t->redraw |= TREDRAW_HARD;
760 if ((t->spacetype==SPACE_VIEW3D) && event->alt) {
761 #if 0 // TRANSFORM_FIX_ME
765 BIF_selectOrientation();
766 calc_manipulator_stats(curarea);
767 copy_m3_m4(t->spacemtx, G.vd->twmat);
768 warp_pointer(mval[0], mval[1]);
772 t->state = TRANS_CONFIRM;
777 if ((t->flag & T_NO_CONSTRAINT)==0) {
778 /* exception for switching to dolly, or trackball, in camera view */
779 if (t->flag & T_CAMERA) {
780 if (t->mode==TFM_TRANSLATION)
781 setLocalConstraint(t, (CON_AXIS2), "along local Z");
782 else if (t->mode==TFM_ROTATION) {
783 restoreTransObjects(t);
788 t->modifiers |= MOD_CONSTRAINT_SELECT;
789 if (t->con.mode & CON_APPLY) {
794 initSelectConstraint(t, t->spacemtx);
797 /* bit hackish... but it prevents mmb select to print the orientation from menu */
798 strcpy(t->spacename, "global");
799 initSelectConstraint(t, mati);
801 postSelectConstraint(t);
804 t->redraw |= TREDRAW_HARD;
808 t->state = TRANS_CANCEL;
812 t->state = TRANS_CONFIRM;
815 /* only switch when... */
816 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
817 resetTransRestrictions(t);
818 restoreTransObjects(t);
820 initSnapping(t, NULL); // need to reinit after mode change
821 t->redraw |= TREDRAW_HARD;
825 /* only switch when... */
826 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
827 resetTransRestrictions(t);
828 restoreTransObjects(t);
830 initSnapping(t, NULL); // need to reinit after mode change
831 t->redraw |= TREDRAW_HARD;
835 /* only switch when... */
836 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
838 resetTransRestrictions(t);
840 if (t->mode == TFM_ROTATION) {
841 restoreTransObjects(t);
845 restoreTransObjects(t);
848 initSnapping(t, NULL); // need to reinit after mode change
849 t->redraw |= TREDRAW_HARD;
854 t->flag ^= T_PROP_CONNECTED;
855 sort_trans_data_dist(t);
856 calculatePropRatio(t);
861 t->redraw |= TREDRAW_HARD;
865 if ((t->flag & T_NO_CONSTRAINT)==0) {
866 if (t->flag & T_2D_EDIT) {
870 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0), "along X");
874 if (t->con.orientation != V3D_MANIP_GLOBAL) {
877 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
878 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
879 setUserConstraint(t, orientation, (CON_AXIS0), "along %s X");
880 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
881 setUserConstraint(t, orientation, (CON_AXIS1|CON_AXIS2), "locking %s X");
884 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
885 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0), "along %s X");
886 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
887 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1|CON_AXIS2), "locking %s X");
890 t->redraw |= TREDRAW_HARD;
894 if ((t->flag & T_NO_CONSTRAINT)==0) {
895 if (t->flag & T_2D_EDIT) {
899 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1), "along Y");
903 if (t->con.orientation != V3D_MANIP_GLOBAL) {
906 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
907 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
908 setUserConstraint(t, orientation, (CON_AXIS1), "along %s Y");
909 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
910 setUserConstraint(t, orientation, (CON_AXIS0|CON_AXIS2), "locking %s Y");
913 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
914 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS1), "along %s Y");
915 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
916 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0|CON_AXIS2), "locking %s Y");
919 t->redraw |= TREDRAW_HARD;
923 if ((t->flag & (T_NO_CONSTRAINT|T_2D_EDIT))==0) {
925 if (t->con.orientation != V3D_MANIP_GLOBAL) {
928 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
929 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
930 setUserConstraint(t, orientation, (CON_AXIS2), "along %s Z");
931 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
932 setUserConstraint(t, orientation, (CON_AXIS0|CON_AXIS1), "locking %s Z");
935 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
936 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS2), "along %s Z");
937 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
938 setUserConstraint(t, V3D_MANIP_GLOBAL, (CON_AXIS0|CON_AXIS1), "locking %s Z");
940 t->redraw |= TREDRAW_HARD;
944 if (t->flag & T_PROP_EDIT && event->shift) {
945 t->prop_mode = (t->prop_mode + 1) % 6;
946 calculatePropRatio(t);
947 t->redraw |= TREDRAW_HARD;
951 if(event->alt && t->flag & T_PROP_EDIT) {
952 t->prop_size *= 1.1f;
953 calculatePropRatio(t);
959 if (t->flag & T_AUTOIK) {
960 transform_autoik_update(t, 1);
962 else view_editmove(event->type);
966 if(event->alt && t->flag & T_PROP_EDIT) {
967 t->prop_size*= 0.90909090f;
968 calculatePropRatio(t);
974 if (t->flag & T_AUTOIK) {
975 transform_autoik_update(t, -1);
977 else view_editmove(event->type);
988 // Numerical input events
989 t->redraw |= handleNumInput(&(t->num), event);
992 switch(handleNDofInput(&(t->ndof), event))
995 if ((t->options & CTX_NDOF) == 0)
997 /* Confirm on normal transform only */
998 t->state = TRANS_CONFIRM;
1002 if (t->options & CTX_NDOF)
1004 /* Cancel on pure NDOF transform */
1005 t->state = TRANS_CANCEL;
1009 /* Otherwise, just redraw, NDof input was cancelled */
1010 t->redraw |= TREDRAW_HARD;
1014 if (t->options & CTX_NDOF)
1016 /* Confirm on pure NDOF transform */
1017 t->state = TRANS_CONFIRM;
1021 t->redraw |= TREDRAW_HARD;
1029 t->redraw |= handleSnapping(t, event);
1031 //arrows_move_cursor(event->type);
1033 else if (event->val==KM_RELEASE) {
1034 switch (event->type){
1037 t->modifiers &= ~MOD_CONSTRAINT_PLANE;
1038 t->redraw |= TREDRAW_HARD;
1042 if ((t->flag & T_NO_CONSTRAINT)==0) {
1043 t->modifiers &= ~MOD_CONSTRAINT_SELECT;
1044 postSelectConstraint(t);
1045 t->redraw |= TREDRAW_HARD;
1050 // if(WM_modal_tweak_exit(event, t->event_type))
1051 //// if (t->options & CTX_TWEAK)
1052 // t->state = TRANS_CONFIRM;
1059 /* confirm transform if launch key is released after mouse move */
1060 if (t->flag & T_RELEASE_CONFIRM)
1062 /* XXX Keyrepeat bug in Xorg fucks this up, will test when fixed */
1063 if (event->type == t->launch_event && (t->launch_event == LEFTMOUSE || t->launch_event == RIGHTMOUSE))
1065 t->state = TRANS_CONFIRM;
1070 // Per transform event, if present
1072 t->redraw |= t->handleEvent(t, event);
1074 if (handled || t->redraw)
1077 return OPERATOR_PASS_THROUGH;
1080 int calculateTransformCenter(bContext *C, int centerMode, float *vec)
1082 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data");
1085 t->state = TRANS_RUNNING;
1087 t->options = CTX_NONE;
1089 t->mode = TFM_DUMMY;
1091 initTransInfo(C, t, NULL, NULL); // internal data, mouse, vectors
1093 createTransData(C, t); // make TransData structs from selection
1095 t->around = centerMode; // override userdefined mode
1097 if (t->total == 0) {
1105 // Copy center from constraint center. Transform center can be local
1106 VECCOPY(vec, t->con.center);
1110 /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
1111 special_aftertrans_update(C, t);
1126 static void drawArrow(ArrowDirection d, short offset, short length, short size)
1136 glVertex2s( offset, 0);
1137 glVertex2s( offset + length, 0);
1138 glVertex2s( offset + length, 0);
1139 glVertex2s( offset + length - size, -size);
1140 glVertex2s( offset + length, 0);
1141 glVertex2s( offset + length - size, size);
1150 glVertex2s( 0, offset);
1151 glVertex2s( 0, offset + length);
1152 glVertex2s( 0, offset + length);
1153 glVertex2s(-size, offset + length - size);
1154 glVertex2s( 0, offset + length);
1155 glVertex2s( size, offset + length - size);
1161 static void drawArrowHead(ArrowDirection d, short size)
1170 glVertex2s( -size, -size);
1172 glVertex2s( -size, size);
1180 glVertex2s(-size, -size);
1182 glVertex2s( size, -size);
1188 static void drawArc(float size, float angle_start, float angle_end, int segments)
1190 float delta = (angle_end - angle_start) / segments;
1193 glBegin(GL_LINE_STRIP);
1195 for( angle = angle_start; angle < angle_end; angle += delta)
1197 glVertex2f( cosf(angle) * size, sinf(angle) * size);
1199 glVertex2f( cosf(angle_end) * size, sinf(angle_end) * size);
1204 static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
1206 TransInfo *t = (TransInfo*)customdata;
1208 if (t->helpline != HLP_NONE && !(t->flag & T_USES_MANIPULATOR))
1210 float vecrot[3], cent[2];
1211 int mval[2] = {x, y};
1213 VECCOPY(vecrot, t->center);
1214 if(t->flag & T_EDIT) {
1215 Object *ob= t->obedit;
1216 if(ob) mul_m4_v3(ob->obmat, vecrot);
1218 else if(t->flag & T_POSE) {
1219 Object *ob=t->poseobj;
1220 if(ob) mul_m4_v3(ob->obmat, vecrot);
1223 projectFloatView(t, vecrot, cent); // no overflow in extreme cases
1230 UI_ThemeColor(TH_WIRE);
1233 glBegin(GL_LINE_STRIP);
1234 glVertex2sv(t->mval);
1238 glTranslatef(mval[0], mval[1], 0);
1239 glRotatef(-180 / M_PI * atan2f(cent[0] - t->mval[0], cent[1] - t->mval[1]), 0, 0, 1);
1243 drawArrow(UP, 5, 10, 5);
1244 drawArrow(DOWN, 5, 10, 5);
1248 UI_ThemeColor(TH_WIRE);
1250 glTranslatef(mval[0], mval[1], 0);
1253 drawArrow(RIGHT, 5, 10, 5);
1254 drawArrow(LEFT, 5, 10, 5);
1258 UI_ThemeColor(TH_WIRE);
1260 glTranslatef(mval[0], mval[1], 0);
1264 drawArrow(UP, 5, 10, 5);
1265 drawArrow(DOWN, 5, 10, 5);
1270 float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
1271 float angle = atan2f(dy, dx);
1272 float dist = sqrtf(dx*dx + dy*dy);
1273 float delta_angle = MIN2(15 / dist, M_PI/4);
1274 float spacing_angle = MIN2(5 / dist, M_PI/12);
1275 UI_ThemeColor(TH_WIRE);
1278 glBegin(GL_LINE_STRIP);
1279 glVertex2sv(t->mval);
1283 glTranslatef(cent[0] - t->mval[0] + mval[0], cent[1] - t->mval[1] + mval[1], 0);
1287 drawArc(dist, angle - delta_angle, angle - spacing_angle, 10);
1288 drawArc(dist, angle + spacing_angle, angle + delta_angle, 10);
1292 glTranslatef(cosf(angle - delta_angle) * dist, sinf(angle - delta_angle) * dist, 0);
1293 glRotatef(180 / M_PI * (angle - delta_angle), 0, 0, 1);
1295 drawArrowHead(DOWN, 5);
1299 glTranslatef(cosf(angle + delta_angle) * dist, sinf(angle + delta_angle) * dist, 0);
1300 glRotatef(180 / M_PI * (angle + delta_angle), 0, 0, 1);
1302 drawArrowHead(UP, 5);
1309 char col[3], col2[3];
1310 UI_GetThemeColor3ubv(TH_GRID, col);
1312 glTranslatef(mval[0], mval[1], 0);
1316 UI_make_axis_color(col, col2, 'x');
1317 glColor3ubv((GLubyte *)col2);
1319 drawArrow(RIGHT, 5, 10, 5);
1320 drawArrow(LEFT, 5, 10, 5);
1322 UI_make_axis_color(col, col2, 'y');
1323 glColor3ubv((GLubyte *)col2);
1325 drawArrow(UP, 5, 10, 5);
1326 drawArrow(DOWN, 5, 10, 5);
1336 void drawTransformView(const struct bContext *C, struct ARegion *UNUSED(ar), void *arg)
1341 drawPropCircle(C, t);
1345 void drawTransformPixel(const struct bContext *UNUSED(C), struct ARegion *UNUSED(ar), void *UNUSED(arg))
1347 // TransInfo *t = arg;
1349 // drawHelpline(C, t->mval[0], t->mval[1], t);
1352 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
1354 ToolSettings *ts = CTX_data_tool_settings(C);
1355 int constraint_axis[3] = {0, 0, 0};
1356 int proportional = 0;
1358 if (RNA_struct_find_property(op->ptr, "value"))
1360 if (t->flag & T_AUTOVALUES)
1362 RNA_float_set_array(op->ptr, "value", t->auto_values);
1366 RNA_float_set_array(op->ptr, "value", t->values);
1370 /* convert flag to enum */
1371 switch(t->flag & (T_PROP_EDIT|T_PROP_CONNECTED))
1373 case (T_PROP_EDIT|T_PROP_CONNECTED):
1374 proportional = PROP_EDIT_CONNECTED;
1377 proportional = PROP_EDIT_ON;
1380 proportional = PROP_EDIT_OFF;
1383 // If modal, save settings back in scene if not set as operator argument
1384 if (t->flag & T_MODAL) {
1386 /* save settings if not set in operator */
1387 if (RNA_struct_find_property(op->ptr, "proportional") && !RNA_property_is_set(op->ptr, "proportional")) {
1389 ts->proportional = proportional;
1391 ts->proportional_objects = (proportional != PROP_EDIT_OFF);
1394 if (RNA_struct_find_property(op->ptr, "proportional_size") && !RNA_property_is_set(op->ptr, "proportional_size")) {
1395 ts->proportional_size = t->prop_size;
1398 if (RNA_struct_find_property(op->ptr, "proportional_edit_falloff") && !RNA_property_is_set(op->ptr, "proportional_edit_falloff")) {
1399 ts->prop_mode = t->prop_mode;
1402 /* do we check for parameter? */
1403 if (t->modifiers & MOD_SNAP) {
1404 ts->snap_flag |= SCE_SNAP;
1406 ts->snap_flag &= ~SCE_SNAP;
1409 if(t->spacetype == SPACE_VIEW3D) {
1410 if (RNA_struct_find_property(op->ptr, "constraint_orientation") && !RNA_property_is_set(op->ptr, "constraint_orientation")) {
1411 View3D *v3d = t->view;
1413 v3d->twmode = t->current_orientation;
1418 if (RNA_struct_find_property(op->ptr, "proportional"))
1420 RNA_enum_set(op->ptr, "proportional", proportional);
1421 RNA_enum_set(op->ptr, "proportional_edit_falloff", t->prop_mode);
1422 RNA_float_set(op->ptr, "proportional_size", t->prop_size);
1425 if (RNA_struct_find_property(op->ptr, "axis"))
1427 RNA_float_set_array(op->ptr, "axis", t->axis);
1430 if (RNA_struct_find_property(op->ptr, "mirror"))
1432 RNA_boolean_set(op->ptr, "mirror", t->flag & T_MIRROR);
1435 if (RNA_struct_find_property(op->ptr, "constraint_axis"))
1437 /* constraint orientation can be global, event if user selects something else
1438 * so use the orientation in the constraint if set
1440 if (t->con.mode & CON_APPLY) {
1441 RNA_enum_set(op->ptr, "constraint_orientation", t->con.orientation);
1443 RNA_enum_set(op->ptr, "constraint_orientation", t->current_orientation);
1446 if (t->con.mode & CON_APPLY)
1448 if (t->con.mode & CON_AXIS0) {
1449 constraint_axis[0] = 1;
1451 if (t->con.mode & CON_AXIS1) {
1452 constraint_axis[1] = 1;
1454 if (t->con.mode & CON_AXIS2) {
1455 constraint_axis[2] = 1;
1459 RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis);
1463 /* note: caller needs to free 't' on a 0 return */
1464 int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int mode)
1468 /* added initialize, for external calls to set stuff in TransInfo, like undo string */
1470 t->state = TRANS_STARTING;
1472 t->options = options;
1476 t->launch_event = event ? event->type : -1;
1478 if (t->launch_event == EVT_TWEAK_R)
1480 t->launch_event = RIGHTMOUSE;
1482 else if (t->launch_event == EVT_TWEAK_L)
1484 t->launch_event = LEFTMOUSE;
1487 // XXX Remove this when wm_operator_call_internal doesn't use window->eventstate (which can have type = 0)
1488 // For manipulator only, so assume LEFTMOUSE
1489 if (t->launch_event == 0)
1491 t->launch_event = LEFTMOUSE;
1494 if (!initTransInfo(C, t, op, event)) // internal data, mouse, vectors
1499 if(t->spacetype == SPACE_VIEW3D)
1501 //calc_manipulator_stats(curarea);
1502 initTransformOrientation(C, t);
1504 t->draw_handle_apply = ED_region_draw_cb_activate(t->ar->type, drawTransformApply, t, REGION_DRAW_PRE_VIEW);
1505 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
1506 //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
1507 t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), NULL, drawHelpline, t);
1509 else if(t->spacetype == SPACE_IMAGE) {
1510 unit_m3(t->spacemtx);
1511 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
1512 //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
1515 unit_m3(t->spacemtx);
1517 createTransData(C, t); // make TransData structs from selection
1519 if (t->total == 0) {
1524 /* Stupid code to have Ctrl-Click on manipulator work ok */
1527 wmKeyMap *keymap = WM_keymap_active(CTX_wm_manager(C), op->type->modalkeymap);
1530 for (kmi = keymap->items.first; kmi; kmi = kmi->next)
1532 if (kmi->propvalue == TFM_MODAL_SNAP_INV_ON && kmi->val == KM_PRESS)
1534 if ((ELEM(kmi->type, LEFTCTRLKEY, RIGHTCTRLKEY) && event->ctrl) ||
1535 (ELEM(kmi->type, LEFTSHIFTKEY, RIGHTSHIFTKEY) && event->shift) ||
1536 (ELEM(kmi->type, LEFTALTKEY, RIGHTALTKEY) && event->alt) ||
1537 (kmi->type == OSKEY && event->oskey)) {
1538 t->modifiers |= MOD_SNAP_INVERT;
1546 initSnapping(t, op); // Initialize snapping data AFTER mode flags
1548 /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
1549 /* EVIL2: we gave as argument also texture space context bit... was cleared */
1550 /* EVIL3: extend mode for animation editors also switches modes... but is best way to avoid duplicate code */
1553 calculatePropRatio(t);
1556 initMouseInput(t, &t->mouse, t->center2d, t->imval);
1559 case TFM_TRANSLATION:
1577 case TFM_SHRINKFATTEN:
1578 initShrinkFatten(t);
1583 case TFM_CURVE_SHRINKFATTEN:
1584 initCurveShrinkFatten(t);
1596 { /* used for both B-Bone width (bonesize) as for deform-dist (envelope) */
1597 bArmature *arm= t->poseobj->data;
1598 if(arm->drawtype==ARM_ENVELOPE)
1599 initBoneEnvelope(t);
1604 case TFM_BONE_ENVELOPE:
1605 initBoneEnvelope(t);
1607 case TFM_EDGE_SLIDE:
1613 case TFM_TIME_TRANSLATE:
1614 initTimeTranslate(t);
1616 case TFM_TIME_SLIDE:
1619 case TFM_TIME_SCALE:
1622 case TFM_TIME_EXTEND:
1623 /* now that transdata has been made, do like for TFM_TIME_TRANSLATE (for most Animation
1624 * Editors because they have only 1D transforms for time values) or TFM_TRANSLATION
1625 * (for Graph/NLA Editors only since they uses 'standard' transforms to get 2D movement)
1626 * depending on which editor this was called from
1628 if ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)
1631 initTimeTranslate(t);
1653 /* overwrite initial values if operator supplied a non-null vector */
1654 if (RNA_property_is_set(op->ptr, "value"))
1657 RNA_float_get_array(op->ptr, "value", values);
1658 QUATCOPY(t->values, values);
1659 QUATCOPY(t->auto_values, values);
1660 t->flag |= T_AUTOVALUES;
1663 /* Transformation axis from operator */
1664 if (RNA_struct_find_property(op->ptr, "axis") && RNA_property_is_set(op->ptr, "axis"))
1666 RNA_float_get_array(op->ptr, "axis", t->axis);
1667 normalize_v3(t->axis);
1670 /* Constraint init from operator */
1671 if (RNA_struct_find_property(op->ptr, "constraint_axis") && RNA_property_is_set(op->ptr, "constraint_axis"))
1673 int constraint_axis[3];
1675 RNA_boolean_get_array(op->ptr, "constraint_axis", constraint_axis);
1677 if (constraint_axis[0] || constraint_axis[1] || constraint_axis[2])
1679 t->con.mode |= CON_APPLY;
1681 if (constraint_axis[0]) {
1682 t->con.mode |= CON_AXIS0;
1684 if (constraint_axis[1]) {
1685 t->con.mode |= CON_AXIS1;
1687 if (constraint_axis[2]) {
1688 t->con.mode |= CON_AXIS2;
1691 setUserConstraint(t, t->current_orientation, t->con.mode, "%s");
1698 void transformApply(const bContext *C, TransInfo *t)
1700 if ((t->redraw & TREDRAW_HARD) || (t->draw_handle_apply == NULL && (t->redraw & TREDRAW_SOFT)))
1702 selectConstraint(t);
1704 t->transform(t, t->mval); // calls recalcData()
1705 viewRedrawForce(C, t);
1707 t->redraw = TREDRAW_NOTHING;
1708 } else if (t->redraw & TREDRAW_SOFT) {
1709 viewRedrawForce(C, t);
1712 /* If auto confirm is on, break after one pass */
1713 if (t->options & CTX_AUTOCONFIRM)
1715 t->state = TRANS_CONFIRM;
1718 if (BKE_ptcache_get_continue_physics())
1721 //do_screenhandlers(G.curscreen);
1722 t->redraw |= TREDRAW_HARD;
1726 void drawTransformApply(const struct bContext *C, struct ARegion *UNUSED(ar), void *arg)
1730 if (t->redraw & TREDRAW_SOFT) {
1731 t->redraw |= TREDRAW_HARD;
1732 transformApply(C, t);
1736 int transformEnd(bContext *C, TransInfo *t)
1738 int exit_code = OPERATOR_RUNNING_MODAL;
1740 if (t->state != TRANS_STARTING && t->state != TRANS_RUNNING)
1742 /* handle restoring objects */
1743 if(t->state == TRANS_CANCEL)
1745 exit_code = OPERATOR_CANCELLED;
1746 restoreTransObjects(t); // calls recalcData()
1750 exit_code = OPERATOR_FINISHED;
1753 /* aftertrans does insert keyframes, and clears base flags, doesnt read transdata */
1754 special_aftertrans_update(C, t);
1759 /* send events out for redraws */
1762 /* Undo as last, certainly after special_trans_update! */
1764 if(t->state == TRANS_CANCEL) {
1765 // if(t->undostr) ED_undo_push(C, t->undostr);
1768 // if(t->undostr) ED_undo_push(C, t->undostr);
1769 // else ED_undo_push(C, transform_to_undostr(t));
1773 viewRedrawForce(C, t);
1779 /* ************************** TRANSFORM LOCKS **************************** */
1781 static void protectedTransBits(short protectflag, float *vec)
1783 if(protectflag & OB_LOCK_LOCX)
1785 if(protectflag & OB_LOCK_LOCY)
1787 if(protectflag & OB_LOCK_LOCZ)
1791 static void protectedSizeBits(short protectflag, float *size)
1793 if(protectflag & OB_LOCK_SCALEX)
1795 if(protectflag & OB_LOCK_SCALEY)
1797 if(protectflag & OB_LOCK_SCALEZ)
1801 static void protectedRotateBits(short protectflag, float *eul, float *oldeul)
1803 if(protectflag & OB_LOCK_ROTX)
1805 if(protectflag & OB_LOCK_ROTY)
1807 if(protectflag & OB_LOCK_ROTZ)
1812 /* this function only does the delta rotation */
1813 /* axis-angle is usually internally stored as quats... */
1814 static void protectedAxisAngleBits(short protectflag, float axis[3], float *angle, float oldAxis[3], float oldAngle)
1816 /* check that protection flags are set */
1817 if ((protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) == 0)
1820 if (protectflag & OB_LOCK_ROT4D) {
1821 /* axis-angle getting limited as 4D entities that they are... */
1822 if (protectflag & OB_LOCK_ROTW)
1824 if (protectflag & OB_LOCK_ROTX)
1825 axis[0]= oldAxis[0];
1826 if (protectflag & OB_LOCK_ROTY)
1827 axis[1]= oldAxis[1];
1828 if (protectflag & OB_LOCK_ROTZ)
1829 axis[2]= oldAxis[2];
1832 /* axis-angle get limited with euler... */
1833 float eul[3], oldeul[3];
1835 axis_angle_to_eulO( eul, EULER_ORDER_DEFAULT,axis, *angle);
1836 axis_angle_to_eulO( oldeul, EULER_ORDER_DEFAULT,oldAxis, oldAngle);
1838 if (protectflag & OB_LOCK_ROTX)
1840 if (protectflag & OB_LOCK_ROTY)
1842 if (protectflag & OB_LOCK_ROTZ)
1845 eulO_to_axis_angle( axis, angle,eul, EULER_ORDER_DEFAULT);
1847 /* when converting to axis-angle, we need a special exception for the case when there is no axis */
1848 if (IS_EQ(axis[0], axis[1]) && IS_EQ(axis[1], axis[2])) {
1849 /* for now, rotate around y-axis then (so that it simply becomes the roll) */
1855 /* this function only does the delta rotation */
1856 static void protectedQuaternionBits(short protectflag, float *quat, float *oldquat)
1858 /* check that protection flags are set */
1859 if ((protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) == 0)
1862 if (protectflag & OB_LOCK_ROT4D) {
1863 /* quaternions getting limited as 4D entities that they are... */
1864 if (protectflag & OB_LOCK_ROTW)
1865 quat[0]= oldquat[0];
1866 if (protectflag & OB_LOCK_ROTX)
1867 quat[1]= oldquat[1];
1868 if (protectflag & OB_LOCK_ROTY)
1869 quat[2]= oldquat[2];
1870 if (protectflag & OB_LOCK_ROTZ)
1871 quat[3]= oldquat[3];
1874 /* quaternions get limited with euler... (compatability mode) */
1875 float eul[3], oldeul[3], quat1[4];
1877 QUATCOPY(quat1, quat);
1878 quat_to_eul( eul,quat);
1879 quat_to_eul( oldeul,oldquat);
1881 if (protectflag & OB_LOCK_ROTX)
1883 if (protectflag & OB_LOCK_ROTY)
1885 if (protectflag & OB_LOCK_ROTZ)
1888 eul_to_quat( quat,eul);
1890 /* quaternions flip w sign to accumulate rotations correctly */
1891 if ( (quat1[0]<0.0f && quat[0]>0.0f) || (quat1[0]>0.0f && quat[0]<0.0f) ) {
1892 mul_qt_fl(quat, -1.0f);
1897 /* ******************* TRANSFORM LIMITS ********************** */
1899 static void constraintTransLim(TransInfo *UNUSED(t), TransData *td)
1902 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
1906 /* Make a temporary bConstraintOb for using these limit constraints
1907 * - they only care that cob->matrix is correctly set ;-)
1908 * - current space should be local
1910 memset(&cob, 0, sizeof(bConstraintOb));
1911 unit_m4(cob.matrix);
1912 VECCOPY(cob.matrix[3], td->loc);
1914 /* Evaluate valid constraints */
1915 for (con= td->con; con; con= con->next) {
1918 /* only consider constraint if enabled */
1919 if (con->flag & CONSTRAINT_DISABLE) continue;
1920 if (con->enforce == 0.0f) continue;
1922 /* only use it if it's tagged for this purpose (and the right type) */
1923 if (con->type == CONSTRAINT_TYPE_LOCLIMIT) {
1924 bLocLimitConstraint *data= con->data;
1926 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1929 /* do space conversions */
1930 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1931 /* just multiply by td->mtx (this should be ok) */
1932 copy_m4_m4(tmat, cob.matrix);
1933 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
1935 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1936 /* skip... incompatable spacetype */
1941 cti->evaluate_constraint(con, &cob, NULL);
1943 /* convert spaces again */
1944 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1945 /* just multiply by td->mtx (this should be ok) */
1946 copy_m4_m4(tmat, cob.matrix);
1947 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
1952 /* copy results from cob->matrix */
1953 VECCOPY(td->loc, cob.matrix[3]);
1957 static void constraintob_from_transdata(bConstraintOb *cob, TransData *td)
1959 /* Make a temporary bConstraintOb for use by limit constraints
1960 * - they only care that cob->matrix is correctly set ;-)
1961 * - current space should be local
1963 memset(cob, 0, sizeof(bConstraintOb));
1964 if (td->rotOrder == ROT_MODE_QUAT) {
1967 /* objects and bones do normalization first too, otherwise
1968 we don't necessarily end up with a rotation matrix, and
1969 then conversion back to quat gives a different result */
1971 copy_qt_qt(quat, td->ext->quat);
1973 quat_to_mat4(cob->matrix, quat);
1978 else if (td->rotOrder == ROT_MODE_AXISANGLE) {
1981 axis_angle_to_mat4(cob->matrix, &td->ext->quat[1], td->ext->quat[0]);
1988 eulO_to_mat4(cob->matrix, td->ext->rot, td->rotOrder);
1994 static void constraintRotLim(TransInfo *UNUSED(t), TransData *td)
1997 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
2002 /* Evaluate valid constraints */
2003 for (con= td->con; con; con= con->next) {
2004 /* only consider constraint if enabled */
2005 if (con->flag & CONSTRAINT_DISABLE) continue;
2006 if (con->enforce == 0.0f) continue;
2008 /* we're only interested in Limit-Rotation constraints */
2009 if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
2010 bRotLimitConstraint *data= con->data;
2013 /* only use it if it's tagged for this purpose */
2014 if ((data->flag2 & LIMIT_TRANSFORM)==0)
2017 /* skip incompatable spacetypes */
2018 if (!ELEM(con->ownspace, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL))
2021 /* only do conversion if necessary, to preserve quats and eulers */
2023 constraintob_from_transdata(&cob, td);
2027 /* do space conversions */
2028 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2029 /* just multiply by td->mtx (this should be ok) */
2030 copy_m4_m4(tmat, cob.matrix);
2031 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
2035 cti->evaluate_constraint(con, &cob, NULL);
2037 /* convert spaces again */
2038 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2039 /* just multiply by td->mtx (this should be ok) */
2040 copy_m4_m4(tmat, cob.matrix);
2041 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
2047 /* copy results from cob->matrix */
2048 if (td->rotOrder == ROT_MODE_QUAT) {
2050 mat4_to_quat( td->ext->quat,cob.matrix);
2052 else if (td->rotOrder == ROT_MODE_AXISANGLE) {
2054 mat4_to_axis_angle( &td->ext->quat[1], &td->ext->quat[0],cob.matrix);
2058 mat4_to_eulO( td->ext->rot, td->rotOrder,cob.matrix);
2064 static void constraintSizeLim(TransInfo *t, TransData *td)
2066 if (td->con && td->ext) {
2067 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
2071 /* Make a temporary bConstraintOb for using these limit constraints
2072 * - they only care that cob->matrix is correctly set ;-)
2073 * - current space should be local
2075 memset(&cob, 0, sizeof(bConstraintOb));
2076 if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
2077 /* scale val and reset size */
2078 return; // TODO: fix this case
2081 /* Reset val if SINGLESIZE but using a constraint */
2082 if (td->flag & TD_SINGLESIZE)
2085 size_to_mat4( cob.matrix,td->ext->size);
2088 /* Evaluate valid constraints */
2089 for (con= td->con; con; con= con->next) {
2090 /* only consider constraint if enabled */
2091 if (con->flag & CONSTRAINT_DISABLE) continue;
2092 if (con->enforce == 0.0f) continue;
2094 /* we're only interested in Limit-Scale constraints */
2095 if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
2096 bSizeLimitConstraint *data= con->data;
2099 /* only use it if it's tagged for this purpose */
2100 if ((data->flag2 & LIMIT_TRANSFORM)==0)
2103 /* do space conversions */
2104 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2105 /* just multiply by td->mtx (this should be ok) */
2106 copy_m4_m4(tmat, cob.matrix);
2107 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
2109 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
2110 /* skip... incompatable spacetype */
2115 cti->evaluate_constraint(con, &cob, NULL);
2117 /* convert spaces again */
2118 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2119 /* just multiply by td->mtx (this should be ok) */
2120 copy_m4_m4(tmat, cob.matrix);
2121 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
2126 /* copy results from cob->matrix */
2127 if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
2128 /* scale val and reset size */
2129 return; // TODO: fix this case
2132 /* Reset val if SINGLESIZE but using a constraint */
2133 if (td->flag & TD_SINGLESIZE)
2136 mat4_to_size( td->ext->size,cob.matrix);
2141 /* ************************** WARP *************************** */
2143 void postInputWarp(TransInfo *t, float values[3])
2145 mul_v3_fl(values, (float)(M_PI * 2));
2147 if (t->customData) /* non-null value indicates reversed input */
2153 void initWarp(TransInfo *t)
2155 float max[3], min[3];
2159 t->transform = Warp;
2160 t->handleEvent = handleEventWarp;
2162 setInputPostFct(&t->mouse, postInputWarp);
2163 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2168 t->snap[1] = 5.0f / 180 * M_PI;
2169 t->snap[2] = 1.0f / 180 * M_PI;
2171 t->num.increment = 1.0f;
2173 t->flag |= T_NO_CONSTRAINT;
2175 /* we need min/max in view space */
2176 for(i = 0; i < t->total; i++) {
2178 copy_v3_v3(center, t->data[i].center);
2179 mul_m3_v3(t->data[i].mtx, center);
2180 mul_m4_v3(t->viewmat, center);
2181 sub_v3_v3(center, t->viewmat[3]);
2183 minmax_v3v3_v3(min, max, center);
2185 copy_v3_v3(max, center);
2186 copy_v3_v3(min, center);
2190 mid_v3_v3v3(t->center, min, max);
2192 if (max[0] == min[0]) max[0] += 0.1; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */
2193 t->val= (max[0]-min[0])/2.0f; /* t->val is X dimension projected boundbox */
2196 int handleEventWarp(TransInfo *t, wmEvent *event)
2200 if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
2202 // Use customData pointer to signal warp direction
2203 if (t->customData == 0)
2204 t->customData = (void*)1;
2214 int Warp(TransInfo *t, short UNUSED(mval[2]))
2216 TransData *td = t->data;
2217 float vec[3], circumfac, dist, phi0, co, si, *curs, cursor[3], gcursor[3];
2221 curs= give_cursor(t->scene, t->view);
2223 * gcursor is the one used for helpline.
2224 * It has to be in the same space as the drawing loop
2225 * (that means it needs to be in the object's space when in edit mode and
2226 * in global space in object mode)
2228 * cursor is used for calculations.
2229 * It needs to be in view space, but we need to take object's offset
2230 * into account if in Edit mode.
2232 VECCOPY(cursor, curs);
2233 VECCOPY(gcursor, cursor);
2234 if (t->flag & T_EDIT) {
2235 sub_v3_v3(cursor, t->obedit->obmat[3]);
2236 sub_v3_v3(gcursor, t->obedit->obmat[3]);
2237 mul_m3_v3(t->data->smtx, gcursor);
2239 mul_m4_v3(t->viewmat, cursor);
2240 sub_v3_v3(cursor, t->viewmat[3]);
2242 /* amount of radians for warp */
2243 circumfac = t->values[0];
2245 snapGrid(t, &circumfac);
2246 applyNumInput(&t->num, &circumfac);
2248 /* header print for NumInput */
2249 if (hasNumInput(&t->num)) {
2252 outputNumInput(&(t->num), c);
2254 sprintf(str, "Warp: %s", c);
2256 circumfac = circumfac / 180 * M_PI;
2259 /* default header print */
2260 sprintf(str, "Warp: %.3f", circumfac * 180 / M_PI);
2263 t->values[0] = circumfac;
2265 circumfac /= 2; /* only need 180 on each side to make 360 */
2267 for(i = 0; i < t->total; i++, td++) {
2269 if (td->flag & TD_NOACTION)
2272 if (td->flag & TD_SKIP)
2275 /* translate point to center, rotate in such a way that outline==distance */
2276 VECCOPY(vec, td->iloc);
2277 mul_m3_v3(td->mtx, vec);
2278 mul_m4_v3(t->viewmat, vec);
2279 sub_v3_v3(vec, t->viewmat[3]);
2281 dist= vec[0]-cursor[0];
2283 /* t->val is X dimension projected boundbox */
2284 phi0= (circumfac*dist/t->val);
2286 vec[1]= (vec[1]-cursor[1]);
2288 co= (float)cos(phi0);
2289 si= (float)sin(phi0);
2290 loc[0]= -si*vec[1]+cursor[0];
2291 loc[1]= co*vec[1]+cursor[1];
2294 mul_m4_v3(t->viewinv, loc);
2295 sub_v3_v3(loc, t->viewinv[3]);
2296 mul_m3_v3(td->smtx, loc);
2298 sub_v3_v3(loc, td->iloc);
2299 mul_v3_fl(loc, td->factor);
2300 add_v3_v3v3(td->loc, td->iloc, loc);
2305 ED_area_headerprint(t->sa, str);
2310 /* ************************** SHEAR *************************** */
2312 void postInputShear(TransInfo *UNUSED(t), float values[3])
2314 mul_v3_fl(values, 0.05f);
2317 void initShear(TransInfo *t)
2319 t->mode = TFM_SHEAR;
2320 t->transform = Shear;
2321 t->handleEvent = handleEventShear;
2323 setInputPostFct(&t->mouse, postInputShear);
2324 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2330 t->snap[2] = t->snap[1] * 0.1f;
2332 t->num.increment = 0.1f;
2334 t->flag |= T_NO_CONSTRAINT;
2337 int handleEventShear(TransInfo *t, wmEvent *event)
2341 if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
2343 // Use customData pointer to signal Shear direction
2344 if (t->customData == 0)
2346 initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
2347 t->customData = (void*)1;
2351 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2362 int Shear(TransInfo *t, short UNUSED(mval[2]))
2364 TransData *td = t->data;
2366 float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3];
2371 copy_m3_m4(persmat, t->viewmat);
2372 invert_m3_m3(persinv, persmat);
2374 value = t->values[0];
2376 snapGrid(t, &value);
2378 applyNumInput(&t->num, &value);
2380 /* header print for NumInput */
2381 if (hasNumInput(&t->num)) {
2384 outputNumInput(&(t->num), c);
2386 sprintf(str, "Shear: %s %s", c, t->proptext);
2389 /* default header print */
2390 sprintf(str, "Shear: %.3f %s", value, t->proptext);
2395 // Custom data signals shear direction
2396 if (t->customData == 0)
2401 mul_m3_m3m3(tmat, smat, persmat);
2402 mul_m3_m3m3(totmat, persinv, tmat);
2404 for(i = 0 ; i < t->total; i++, td++) {
2405 if (td->flag & TD_NOACTION)
2408 if (td->flag & TD_SKIP)
2413 mul_m3_m3m3(mat3, totmat, td->mtx);
2414 mul_m3_m3m3(tmat, td->smtx, mat3);
2417 copy_m3_m3(tmat, totmat);
2419 sub_v3_v3v3(vec, td->center, t->center);
2421 mul_m3_v3(tmat, vec);
2423 add_v3_v3(vec, t->center);
2424 sub_v3_v3(vec, td->center);
2426 mul_v3_fl(vec, td->factor);
2428 add_v3_v3v3(td->loc, td->iloc, vec);
2433 ED_area_headerprint(t->sa, str);
2438 /* ************************** RESIZE *************************** */
2440 void initResize(TransInfo *t)
2442 t->mode = TFM_RESIZE;
2443 t->transform = Resize;
2445 initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
2447 t->flag |= T_NULL_ONE;
2448 t->num.flag |= NUM_NULL_ONE;
2449 t->num.flag |= NUM_AFFECT_ALL;
2451 t->flag |= T_NO_ZERO;
2452 t->num.flag |= NUM_NO_ZERO;
2459 t->snap[2] = t->snap[1] * 0.1f;
2461 t->num.increment = t->snap[1];
2464 static void headerResize(TransInfo *t, float vec[3], char *str) {
2466 if (hasNumInput(&t->num)) {
2467 outputNumInput(&(t->num), tvec);
2470 sprintf(&tvec[0], "%.4f", vec[0]);
2471 sprintf(&tvec[20], "%.4f", vec[1]);
2472 sprintf(&tvec[40], "%.4f", vec[2]);
2475 if (t->con.mode & CON_APPLY) {
2476 switch(t->num.idx_max) {
2478 sprintf(str, "Scale: %s%s %s", &tvec[0], t->con.text, t->proptext);
2481 sprintf(str, "Scale: %s : %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2484 sprintf(str, "Scale: %s : %s : %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2488 if (t->flag & T_2D_EDIT)
2489 sprintf(str, "Scale X: %s Y: %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2491 sprintf(str, "Scale X: %s Y: %s Z: %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2495 #define SIGN(a) (a<-FLT_EPSILON?1:a>FLT_EPSILON?2:3)
2496 #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)
2498 /* smat is reference matrix, only scaled */
2499 static void TransMat3ToSize( float mat[][3], float smat[][3], float *size)
2503 copy_v3_v3(vec, mat[0]);
2504 size[0]= normalize_v3(vec);
2505 copy_v3_v3(vec, mat[1]);
2506 size[1]= normalize_v3(vec);
2507 copy_v3_v3(vec, mat[2]);
2508 size[2]= normalize_v3(vec);
2510 /* first tried with dotproduct... but the sign flip is crucial */
2511 if( VECSIGNFLIP(mat[0], smat[0]) ) size[0]= -size[0];
2512 if( VECSIGNFLIP(mat[1], smat[1]) ) size[1]= -size[1];
2513 if( VECSIGNFLIP(mat[2], smat[2]) ) size[2]= -size[2];
2517 static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
2518 float tmat[3][3], smat[3][3], center[3];
2521 if (t->flag & T_EDIT) {
2522 mul_m3_m3m3(smat, mat, td->mtx);
2523 mul_m3_m3m3(tmat, td->smtx, smat);
2526 copy_m3_m3(tmat, mat);
2529 if (t->con.applySize) {
2530 t->con.applySize(t, td, tmat);
2533 /* local constraint shouldn't alter center */
2534 if (t->around == V3D_LOCAL) {
2535 if (t->flag & T_OBJECT) {
2536 VECCOPY(center, td->center);
2538 else if (t->flag & T_EDIT) {
2540 if(t->around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
2541 VECCOPY(center, td->center);
2544 VECCOPY(center, t->center);
2548 VECCOPY(center, t->center);
2552 VECCOPY(center, t->center);
2558 if (t->flag & (T_OBJECT|T_TEXTURE|T_POSE)) {
2559 float obsizemat[3][3];
2560 // Reorient the size mat to fit the oriented object.
2561 mul_m3_m3m3(obsizemat, tmat, td->axismtx);
2562 //print_m3("obsizemat", obsizemat);
2563 TransMat3ToSize(obsizemat, td->axismtx, fsize);
2564 //print_v3("fsize", fsize);
2567 mat3_to_size( fsize,tmat);
2570 protectedSizeBits(td->protectflag, fsize);
2572 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't resize objects itself
2573 if((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)){
2574 /* scale val and reset size */
2575 *td->val = td->ival * (1 + (fsize[0] - 1) * td->factor);
2577 td->ext->size[0] = td->ext->isize[0];
2578 td->ext->size[1] = td->ext->isize[1];
2579 td->ext->size[2] = td->ext->isize[2];
2582 /* Reset val if SINGLESIZE but using a constraint */
2583 if (td->flag & TD_SINGLESIZE)
2584 *td->val = td->ival;
2586 td->ext->size[0] = td->ext->isize[0] * (1 + (fsize[0] - 1) * td->factor);
2587 td->ext->size[1] = td->ext->isize[1] * (1 + (fsize[1] - 1) * td->factor);
2588 td->ext->size[2] = td->ext->isize[2] * (1 + (fsize[2] - 1) * td->factor);
2592 constraintSizeLim(t, td);
2595 /* For individual element center, Editmode need to use iloc */
2596 if (t->flag & T_POINTS)
2597 sub_v3_v3v3(vec, td->iloc, center);
2599 sub_v3_v3v3(vec, td->center, center);
2601 mul_m3_v3(tmat, vec);
2603 add_v3_v3(vec, center);
2604 if (t->flag & T_POINTS)
2605 sub_v3_v3(vec, td->iloc);
2607 sub_v3_v3(vec, td->center);
2609 mul_v3_fl(vec, td->factor);
2611 if (t->flag & (T_OBJECT|T_POSE)) {
2612 mul_m3_v3(td->smtx, vec);
2615 protectedTransBits(td->protectflag, vec);
2616 add_v3_v3v3(td->loc, td->iloc, vec);
2618 constraintTransLim(t, td);
2621 int Resize(TransInfo *t, short mval[2])
2624 float size[3], mat[3][3];
2629 /* for manipulator, center handle, the scaling can't be done relative to center */
2630 if( (t->flag & T_USES_MANIPULATOR) && t->con.mode==0)
2632 ratio = 1.0f - ((t->imval[0] - mval[0]) + (t->imval[1] - mval[1]))/100.0f;
2636 ratio = t->values[0];
2639 size[0] = size[1] = size[2] = ratio;
2643 if (hasNumInput(&t->num)) {
2644 applyNumInput(&t->num, size);
2645 constraintNumInput(t, size);
2648 applySnapping(t, size);
2650 if (t->flag & T_AUTOVALUES)
2652 VECCOPY(size, t->auto_values);
2655 VECCOPY(t->values, size);
2657 size_to_mat3( mat,size);
2659 if (t->con.applySize) {
2660 t->con.applySize(t, NULL, mat);
2663 copy_m3_m3(t->mat, mat); // used in manipulator
2665 headerResize(t, size, str);
2667 for(i = 0, td=t->data; i < t->total; i++, td++) {
2668 if (td->flag & TD_NOACTION)
2671 if (td->flag & TD_SKIP)
2674 ElementResize(t, td, mat);
2677 /* evil hack - redo resize if cliping needed */
2678 if (t->flag & T_CLIP_UV && clipUVTransform(t, size, 1)) {
2679 size_to_mat3( mat,size);
2681 if (t->con.applySize)
2682 t->con.applySize(t, NULL, mat);
2684 for(i = 0, td=t->data; i < t->total; i++, td++)
2685 ElementResize(t, td, mat);
2690 ED_area_headerprint(t->sa, str);
2695 /* ************************** TOSPHERE *************************** */
2697 void initToSphere(TransInfo *t)
2699 TransData *td = t->data;
2702 t->mode = TFM_TOSPHERE;
2703 t->transform = ToSphere;
2705 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2711 t->snap[2] = t->snap[1] * 0.1f;
2713 t->num.increment = t->snap[1];
2715 t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
2716 t->flag |= T_NO_CONSTRAINT;
2718 // Calculate average radius
2719 for(i = 0 ; i < t->total; i++, td++) {
2720 t->val += len_v3v3(t->center, td->iloc);
2723 t->val /= (float)t->total;
2726 int ToSphere(TransInfo *t, short UNUSED(mval[2]))
2729 float ratio, radius;
2732 TransData *td = t->data;
2734 ratio = t->values[0];
2736 snapGrid(t, &ratio);
2738 applyNumInput(&t->num, &ratio);
2745 t->values[0] = ratio;
2747 /* header print for NumInput */
2748 if (hasNumInput(&t->num)) {
2751 outputNumInput(&(t->num), c);
2753 sprintf(str, "To Sphere: %s %s", c, t->proptext);
2756 /* default header print */
2757 sprintf(str, "To Sphere: %.4f %s", ratio, t->proptext);
2761 for(i = 0 ; i < t->total; i++, td++) {
2763 if (td->flag & TD_NOACTION)
2766 if (td->flag & TD_SKIP)
2769 sub_v3_v3v3(vec, td->iloc, t->center);
2771 radius = normalize_v3(vec);
2773 tratio = ratio * td->factor;
2775 mul_v3_fl(vec, radius * (1.0f - tratio) + t->val * tratio);
2777 add_v3_v3v3(td->loc, t->center, vec);
2783 ED_area_headerprint(t->sa, str);
2788 /* ************************** ROTATION *************************** */
2791 void postInputRotation(TransInfo *t, float values[3])
2793 if ((t->con.mode & CON_APPLY) && t->con.applyRot) {
2794 t->con.applyRot(t, NULL, t->axis, values);
2798 void initRotation(TransInfo *t)
2800 t->mode = TFM_ROTATION;
2801 t->transform = Rotation;
2803 setInputPostFct(&t->mouse, postInputRotation);
2804 initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
2807 /* Scale down and flip input for rotation */
2808 t->ndof.factor[0] = -0.2f;
2813 t->snap[1] = (float)((5.0/180)*M_PI);
2814 t->snap[2] = t->snap[1] * 0.2f;
2816 t->num.increment = 1.0f;
2818 if (t->flag & T_2D_EDIT)
2819 t->flag |= T_NO_CONSTRAINT;
2821 negate_v3_v3(t->axis, t->viewinv[2]);
2822 normalize_v3(t->axis);
2825 static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short around) {
2826 float vec[3], totmat[3][3], smat[3][3];
2827 float eul[3], fmat[3][3], quat[4];
2828 float *center = t->center;
2830 /* local constraint shouldn't alter center */
2831 if (around == V3D_LOCAL) {
2832 if (t->flag & (T_OBJECT|T_POSE)) {
2833 center = td->center;
2836 if(around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
2837 center = td->center;
2842 if (t->flag & T_POINTS) {
2843 mul_m3_m3m3(totmat, mat, td->mtx);
2844 mul_m3_m3m3(smat, td->smtx, totmat);
2846 sub_v3_v3v3(vec, td->iloc, center);
2847 mul_m3_v3(smat, vec);
2849 add_v3_v3v3(td->loc, vec, center);
2851 sub_v3_v3v3(vec,td->loc,td->iloc);
2852 protectedTransBits(td->protectflag, vec);
2853 add_v3_v3v3(td->loc, td->iloc, vec);
2856 if(td->flag & TD_USEQUAT) {
2857 mul_serie_m3(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2858 mat3_to_quat( quat,fmat); // Actual transform
2861 mul_qt_qtqt(td->ext->quat, quat, td->ext->iquat);
2863 /* is there a reason not to have this here? -jahka */
2864 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2871 * This is some VERY ugly special case to deal with pose mode.
2873 * The problem is that mtx and smtx include each bone orientation.
2875 * That is needed to rotate each bone properly, HOWEVER, to calculate
2876 * the translation component, we only need the actual armature object's
2877 * matrix (and inverse). That is not all though. Once the proper translation
2878 * has been computed, it has to be converted back into the bone's space.
2880 else if (t->flag & T_POSE) {
2881 float pmtx[3][3], imtx[3][3];
2883 // Extract and invert armature object matrix
2884 copy_m3_m4(pmtx, t->poseobj->obmat);
2885 invert_m3_m3(imtx, pmtx);
2887 if ((td->flag & TD_NO_LOC) == 0)
2889 sub_v3_v3v3(vec, td->center, center);
2891 mul_m3_v3(pmtx, vec); // To Global space
2892 mul_m3_v3(mat, vec); // Applying rotation
2893 mul_m3_v3(imtx, vec); // To Local space
2895 add_v3_v3(vec, center);
2896 /* vec now is the location where the object has to be */