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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 *****
33 #include "MEM_guardedalloc.h"
35 #include "BLO_sys_types.h" // for intptr_t support
37 #include "DNA_anim_types.h"
38 #include "DNA_action_types.h"
39 #include "DNA_armature_types.h"
40 #include "DNA_constraint_types.h"
41 #include "DNA_curve_types.h"
42 #include "DNA_lattice_types.h"
43 #include "DNA_mesh_types.h"
44 #include "DNA_modifier_types.h"
45 #include "DNA_nla_types.h"
46 #include "DNA_node_types.h"
47 #include "DNA_object_types.h"
48 #include "DNA_object_force.h"
49 #include "DNA_particle_types.h"
50 #include "DNA_screen_types.h"
51 #include "DNA_space_types.h"
52 #include "DNA_scene_types.h"
53 #include "DNA_userdef_types.h"
54 #include "DNA_view3d_types.h"
55 #include "DNA_windowmanager_types.h"
57 #include "RNA_access.h"
59 //#include "BIF_screen.h"
60 //#include "BIF_mywindow.h"
62 //#include "BIF_editaction.h"
63 //#include "BIF_editmesh.h"
64 //#include "BIF_editnla.h"
65 //#include "BIF_editsima.h"
66 //#include "BIF_editparticle.h"
67 //#include "BIF_meshtools.h"
68 #include "BIF_retopo.h"
70 #include "BKE_action.h"
72 #include "BKE_armature.h"
73 #include "BKE_cloth.h"
74 #include "BKE_curve.h"
75 #include "BKE_depsgraph.h"
76 #include "BKE_displist.h"
77 #include "BKE_depsgraph.h"
78 #include "BKE_fcurve.h"
79 #include "BKE_global.h"
80 #include "BKE_group.h"
81 #include "BKE_lattice.h"
84 #include "BKE_modifier.h"
85 #include "BKE_object.h"
86 #include "BKE_utildefines.h"
87 #include "BKE_context.h"
89 #include "ED_anim_api.h"
90 #include "ED_armature.h"
92 #include "ED_keyframing.h"
94 #include "ED_space_api.h"
95 #include "ED_uvedit.h"
96 #include "ED_view3d.h"
98 //#include "BDR_unwrapper.h"
100 #include "BLI_arithb.h"
101 #include "BLI_blenlib.h"
102 #include "BLI_editVert.h"
103 #include "BLI_rand.h"
105 #include "WM_types.h"
107 #include "UI_resources.h"
109 //#include "blendef.h"
111 //#include "mydevice.h"
113 #include "transform.h"
115 extern ListBase editelems;
117 extern TransInfo Trans; /* From transform.c */
119 /* ************************** Functions *************************** */
121 void getViewVector(TransInfo *t, float coord[3], float vec[3])
123 if (t->persp != V3D_ORTHO)
131 Mat4MulVec4fl(t->viewmat, p2);
133 p2[0] = 2.0f * p2[0];
134 p2[1] = 2.0f * p2[1];
135 p2[2] = 2.0f * p2[2];
137 Mat4MulVec4fl(t->viewinv, p2);
139 VecSubf(vec, p1, p2);
142 VECCOPY(vec, t->viewinv[2]);
147 /* ************************** GENERICS **************************** */
149 static void clipMirrorModifier(TransInfo *t, Object *ob)
151 ModifierData *md= ob->modifiers.first;
152 float tolerance[3] = {0.0f, 0.0f, 0.0f};
155 for (; md; md=md->next) {
156 if (md->type==eModifierType_Mirror) {
157 MirrorModifierData *mmd = (MirrorModifierData*) md;
159 if(mmd->flag & MOD_MIR_CLIPPING) {
161 if(mmd->flag & MOD_MIR_AXIS_X) {
163 tolerance[0] = mmd->tolerance;
165 if(mmd->flag & MOD_MIR_AXIS_Y) {
167 tolerance[1] = mmd->tolerance;
169 if(mmd->flag & MOD_MIR_AXIS_Z) {
171 tolerance[2] = mmd->tolerance;
174 float mtx[4][4], imtx[4][4];
176 TransData *td = t->data;
178 if (mmd->mirror_ob) {
181 Mat4Invert(obinv, mmd->mirror_ob->obmat);
182 Mat4MulMat4(mtx, ob->obmat, obinv);
183 Mat4Invert(imtx, mtx);
186 for(i = 0 ; i < t->total; i++, td++) {
188 float loc[3], iloc[3];
190 if (td->flag & TD_NOACTION)
195 if (td->flag & TD_SKIP)
198 VecCopyf(loc, td->loc);
199 VecCopyf(iloc, td->iloc);
201 if (mmd->mirror_ob) {
202 VecMat4MulVecfl(loc, mtx, loc);
203 VecMat4MulVecfl(iloc, mtx, iloc);
208 if(fabs(iloc[0])<=tolerance[0] ||
209 loc[0]*iloc[0]<0.0f) {
216 if(fabs(iloc[1])<=tolerance[1] ||
217 loc[1]*iloc[1]<0.0f) {
223 if(fabs(iloc[2])<=tolerance[2] ||
224 loc[2]*iloc[2]<0.0f) {
230 if (mmd->mirror_ob) {
231 VecMat4MulVecfl(loc, imtx, loc);
233 VecCopyf(td->loc, loc);
243 /* assumes obedit set to mesh object */
244 static void editmesh_apply_to_mirror(TransInfo *t)
246 TransData *td = t->data;
250 for(i = 0 ; i < t->total; i++, td++) {
251 if (td->flag & TD_NOACTION)
255 if (td->flag & TD_SKIP)
260 eve->co[0]= -td->loc[0];
261 eve->co[1]= td->loc[1];
262 eve->co[2]= td->loc[2];
267 /* called for updating while transform acts, once per redraw */
268 void recalcData(TransInfo *t)
270 Scene *scene = t->scene;
273 #if 0 // TRANSFORM_FIX_ME
274 if (t->spacetype == SPACE_ACTION) {
279 /* determine what type of data we are operating on */
280 data = get_action_context(&context);
281 if (data == NULL) return;
283 /* always flush data if gpencil context */
284 if (context == ACTCONT_GPENCIL) {
285 flushTransGPactionData(t);
288 if (G.saction->lock) {
289 if (context == ACTCONT_ACTION) {
291 ob->ctime= -1234567.0f;
292 if(ob->pose || ob_get_key(ob))
293 DAG_object_flush_update(G.scene, ob, OB_RECALC);
295 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
298 else if (context == ACTCONT_SHAPEKEY) {
299 DAG_object_flush_update(G.scene, OBACT, OB_RECALC_OB|OB_RECALC_DATA);
303 else if (t->spacetype == SPACE_NLA) {
305 for (base=G.scene->base.first; base; base=base->next) {
306 if (base->flag & BA_HAS_RECALC_OB)
307 base->object->recalc |= OB_RECALC_OB;
308 if (base->flag & BA_HAS_RECALC_DATA)
309 base->object->recalc |= OB_RECALC_DATA;
311 if (base->object->recalc)
312 base->object->ctime= -1234567.0f; // eveil!
314 /* recalculate scale of selected nla-strips */
315 if (base->object->nlastrips.first) {
316 Object *bob= base->object;
319 for (strip= bob->nlastrips.first; strip; strip= strip->next) {
320 if (strip->flag & ACTSTRIP_SELECT) {
321 float actlen= strip->actend - strip->actstart;
322 float len= strip->end - strip->start;
324 strip->scale= len / (actlen * strip->repeat);
330 DAG_scene_flush_update(G.scene, screen_view3d_layers(), 0);
333 for (base=G.scene->base.first; base; base=base->next) {
334 /* recalculate scale of selected nla-strips */
335 if (base->object && base->object->nlastrips.first) {
336 Object *bob= base->object;
339 for (strip= bob->nlastrips.first; strip; strip= strip->next) {
340 if (strip->flag & ACTSTRIP_SELECT) {
341 float actlen= strip->actend - strip->actstart;
342 float len= strip->end - strip->start;
344 /* prevent 'negative' scaling */
346 SWAP(float, strip->start, strip->end);
350 /* calculate new scale */
351 strip->scale= len / (actlen * strip->repeat);
361 else if(G.f & G_PARTICLEEDIT) {
362 flushTransParticles(t);
364 if (t->spacetype==SPACE_NODE) {
367 else if (t->spacetype==SPACE_SEQ) {
370 else if (t->spacetype == SPACE_IPO) {
371 SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
374 ListBase anim_data = {NULL, NULL};
382 /* initialise relevant anim-context 'context' data from TransInfo data */
383 /* NOTE: sync this with the code in ANIM_animdata_get_context() */
384 memset(&ac, 0, sizeof(bAnimContext));
386 scene= ac.scene= t->scene;
390 ac.spacetype= (t->sa)? t->sa->spacetype : 0;
391 ac.regiontype= (t->ar)? t->ar->regiontype : 0;
393 ANIM_animdata_context_getdata(&ac);
395 /* do the flush first */
396 flushTransGraphData(t);
398 /* get curves to check if a re-sort is needed */
399 filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY | ANIMFILTER_CURVEVISIBLE);
400 ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
402 /* now test if there is a need to re-sort */
403 for (ale= anim_data.first; ale; ale= ale->next) {
404 FCurve *fcu= (FCurve *)ale->key_data;
406 /* watch it: if the time is wrong: do not correct handles yet */
407 if (test_time_fcurve(fcu))
410 calchandles_fcurve(fcu);
413 /* do resort and other updates? */
414 if (dosort) remake_graph_transdata(t, &anim_data);
415 //if (sipo->showkey) update_ipokey_val();
417 /* now free temp channels */
418 BLI_freelistN(&anim_data);
420 /* update realtime - not working? */
425 else if (t->obedit) {
426 if ELEM(t->obedit->type, OB_CURVE, OB_SURF) {
427 Curve *cu= t->obedit->data;
428 Nurb *nu= cu->editnurb->first;
430 DAG_object_flush_update(scene, t->obedit, OB_RECALC_DATA); /* sets recalc flags */
432 if (t->state == TRANS_CANCEL) {
434 calchandlesNurb(nu); /* Cant do testhandlesNurb here, it messes up the h1 and h2 flags */
438 /* Normal updating */
444 /* TRANSFORM_FIX_ME */
448 else if(t->obedit->type==OB_LATTICE) {
449 Lattice *la= t->obedit->data;
450 DAG_object_flush_update(scene, t->obedit, OB_RECALC_DATA); /* sets recalc flags */
452 if(la->editlatt->flag & LT_OUTSIDE) outside_lattice(la->editlatt);
454 else if (t->obedit->type == OB_MESH) {
455 if(t->spacetype==SPACE_IMAGE) {
456 SpaceImage *sima= t->sa->spacedata.first;
459 if(sima->flag & SI_LIVE_UNWRAP)
460 ED_uvedit_live_unwrap_re_solve();
462 DAG_object_flush_update(scene, t->obedit, OB_RECALC_DATA);
464 EditMesh *em = ((Mesh*)t->obedit->data)->edit_mesh;
465 /* mirror modifier clipping? */
466 if(t->state != TRANS_CANCEL) {
467 /* TRANSFORM_FIX_ME */
468 // if ((G.qual & LR_CTRLKEY)==0) {
469 // /* Only retopo if not snapping, Note, this is the only case of G.qual being used, but we have no T_SHIFT_MOD - Campbell */
472 clipMirrorModifier(t, t->obedit);
474 if((t->options & CTX_NO_MIRROR) == 0 && (t->flag & T_MIRROR))
475 editmesh_apply_to_mirror(t);
477 DAG_object_flush_update(scene, t->obedit, OB_RECALC_DATA); /* sets recalc flags */
479 recalc_editnormals(em);
482 else if(t->obedit->type==OB_ARMATURE) { /* no recalc flag, does pose */
483 bArmature *arm= t->obedit->data;
484 ListBase *edbo = arm->edbo;
486 TransData *td = t->data;
489 /* Ensure all bones are correctly adjusted */
490 for (ebo = edbo->first; ebo; ebo = ebo->next){
492 if ((ebo->flag & BONE_CONNECTED) && ebo->parent){
493 /* If this bone has a parent tip that has been moved */
494 if (ebo->parent->flag & BONE_TIPSEL){
495 VECCOPY (ebo->head, ebo->parent->tail);
496 if(t->mode==TFM_BONE_ENVELOPE) ebo->rad_head= ebo->parent->rad_tail;
498 /* If this bone has a parent tip that has NOT been moved */
500 VECCOPY (ebo->parent->tail, ebo->head);
501 if(t->mode==TFM_BONE_ENVELOPE) ebo->parent->rad_tail= ebo->rad_head;
505 /* on extrude bones, oldlength==0.0f, so we scale radius of points */
506 ebo->length= VecLenf(ebo->head, ebo->tail);
507 if(ebo->oldlength==0.0f) {
508 ebo->rad_head= 0.25f*ebo->length;
509 ebo->rad_tail= 0.10f*ebo->length;
510 ebo->dist= 0.25f*ebo->length;
512 if(ebo->rad_head > ebo->parent->rad_tail)
513 ebo->rad_head= ebo->parent->rad_tail;
516 else if(t->mode!=TFM_BONE_ENVELOPE) {
517 /* if bones change length, lets do that for the deform distance as well */
518 ebo->dist*= ebo->length/ebo->oldlength;
519 ebo->rad_head*= ebo->length/ebo->oldlength;
520 ebo->rad_tail*= ebo->length/ebo->oldlength;
521 ebo->oldlength= ebo->length;
526 if (t->mode != TFM_BONE_ROLL)
529 for(i = 0; i < t->total; i++, td++)
533 float vec[3], up_axis[3];
537 VECCOPY(up_axis, td->axismtx[2]);
539 if (t->mode != TFM_ROTATION)
541 VecSubf(vec, ebo->tail, ebo->head);
543 RotationBetweenVectorsToQuat(qrot, td->axismtx[1], vec);
544 QuatMulVecf(qrot, up_axis);
548 Mat3MulVecfl(t->mat, up_axis);
551 ebo->roll = ED_rollBoneToVector(ebo, up_axis);
556 if(arm->flag & ARM_MIRROR_EDIT)
557 transform_armature_mirror_update(t->obedit);
561 DAG_object_flush_update(scene, t->obedit, OB_RECALC_DATA); /* sets recalc flags */
563 else if( (t->flag & T_POSE) && t->poseobj) {
564 Object *ob= t->poseobj;
565 bArmature *arm= ob->data;
567 /* if animtimer is running, and the object already has animation data,
568 * check if the auto-record feature means that we should record 'samples'
569 * (i.e. uneditable animation values)
571 // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes?
572 // TODO: maybe the ob->adt check isn't really needed? makes it too difficult to use...
573 if (/*(ob->adt) && */(t->animtimer) && IS_AUTOKEY_ON(t->scene)) {
574 short targetless_ik= (t->flag & T_AUTOIK); // XXX this currently doesn't work, since flags aren't set yet!
575 autokeyframe_pose_cb_func(t->scene, (View3D *)t->view, ob, t->mode, targetless_ik);
578 /* old optimize trick... this enforces to bypass the depgraph */
579 if (!(arm->flag & ARM_DELAYDEFORM)) {
580 DAG_object_flush_update(scene, ob, OB_RECALC_DATA); /* sets recalc flags */
583 where_is_pose(scene, ob);
586 for(base= FIRSTBASE; base; base= base->next) {
587 Object *ob= base->object;
589 /* this flag is from depgraph, was stored in initialize phase, handled in drawview.c */
590 if(base->flag & BA_HAS_RECALC_OB)
591 ob->recalc |= OB_RECALC_OB;
592 if(base->flag & BA_HAS_RECALC_DATA)
593 ob->recalc |= OB_RECALC_DATA;
595 /* if object/base is selected */
596 if ((base->flag & SELECT) || (ob->flag & SELECT)) {
597 /* if animtimer is running, and the object already has animation data,
598 * check if the auto-record feature means that we should record 'samples'
599 * (i.e. uneditable animation values)
601 // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes?
602 // TODO: maybe the ob->adt check isn't really needed? makes it too difficult to use...
603 if (/*(ob->adt) && */(t->animtimer) && IS_AUTOKEY_ON(t->scene)) {
604 autokeyframe_ob_cb_func(t->scene, (View3D *)t->view, ob, t->mode);
608 /* proxy exception */
610 ob->proxy->recalc |= ob->recalc;
612 group_tag_recalc(ob->proxy_group->dup_group);
616 /* update shaded drawmode while transform */
617 if(t->spacetype==SPACE_VIEW3D && ((View3D*)t->view)->drawtype == OB_SHADED)
618 reshadeall_displist(t->scene);
621 void drawLine(TransInfo *t, float *center, float *dir, char axis, short options)
623 extern void make_axis_color(char *col, char *col2, char axis); // view3d_draw.c
624 float v1[3], v2[3], v3[3];
625 char col[3], col2[3];
627 if (t->spacetype == SPACE_VIEW3D)
629 View3D *v3d = t->view;
633 //if(t->obedit) glLoadMatrixf(t->obedit->obmat); // sets opengl viewing
637 VecMulf(v3, v3d->far);
639 VecSubf(v2, center, v3);
640 VecAddf(v1, center, v3);
642 if (options & DRAWLIGHT) {
643 col[0] = col[1] = col[2] = 220;
646 UI_GetThemeColor3ubv(TH_GRID, col);
648 make_axis_color(col, col2, axis);
649 glColor3ubv((GLubyte *)col2);
652 glBegin(GL_LINE_STRIP);
661 void resetTransRestrictions(TransInfo *t)
663 t->flag &= ~T_ALL_RESTRICTIONS;
666 void initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
668 Scene *sce = CTX_data_scene(C);
669 ARegion *ar = CTX_wm_region(C);
670 ScrArea *sa = CTX_wm_area(C);
671 Object *obedit = CTX_data_edit_object(C);
673 /* moving: is shown in drawobject() (transform color) */
675 // if(obedit || (t->flag & T_POSE) ) G.moving= G_TRANSFORM_EDIT;
676 // else if(G.f & G_PARTICLEEDIT) G.moving= G_TRANSFORM_PARTICLE;
677 // else G.moving= G_TRANSFORM_OBJ;
689 t->redraw = 1; /* redraw first time */
693 t->imval[0] = event->x - t->ar->winrct.xmin;
694 t->imval[1] = event->y - t->ar->winrct.ymin;
696 t->event_type = event->type;
704 t->con.imval[0] = t->imval[0];
705 t->con.imval[1] = t->imval[1];
707 t->mval[0] = t->imval[0];
708 t->mval[1] = t->imval[1];
711 t->handleEvent = NULL;
727 t->spacetype = sa->spacetype;
728 if(t->spacetype == SPACE_VIEW3D)
730 View3D *v3d = sa->spacedata.first;
733 t->animtimer= CTX_wm_screen(C)->animtimer;
735 if(v3d->flag & V3D_ALIGN) t->flag |= T_V3D_ALIGN;
736 t->around = v3d->around;
738 if (op && RNA_property_is_set(op->ptr, "constraint_orientation"))
740 t->current_orientation = RNA_int_get(op->ptr, "constraint_orientation");
742 if (t->current_orientation >= V3D_MANIP_CUSTOM + BIF_countTransformOrientation(C) - 1)
744 t->current_orientation = V3D_MANIP_GLOBAL;
749 t->current_orientation = v3d->twmode;
752 else if(t->spacetype==SPACE_IMAGE || t->spacetype==SPACE_NODE)
754 // XXX for now, get View2D from the active region
756 t->around = ar->v2d.around;
760 // XXX for now, get View2D from the active region
763 t->around = V3D_CENTER;
766 if (op && RNA_struct_find_property(op->ptr, "mirror") && RNA_property_is_set(op->ptr, "mirror"))
768 if (RNA_boolean_get(op->ptr, "mirror"))
773 // Need stuff to take it from edit mesh or whatnot here
776 if (t->obedit && t->obedit->type == OB_MESH && sce->toolsettings->editbutflag & B_MESH_X_MIRROR)
782 /* setting PET flag */
783 if (op && RNA_struct_find_property(op->ptr, "proportional") && RNA_property_is_set(op->ptr, "proportional"))
785 switch(RNA_enum_get(op->ptr, "proportional"))
787 case 2: /* XXX connected constant */
788 t->flag |= T_PROP_CONNECTED;
789 case 1: /* XXX prop on constant */
790 t->flag |= T_PROP_EDIT;
796 if ((t->options & CTX_NO_PET) == 0 && (sce->proportional)) {
797 t->flag |= T_PROP_EDIT;
799 if(sce->proportional == 2)
800 t->flag |= T_PROP_CONNECTED; // yes i know, has to become define
804 if (op && RNA_struct_find_property(op->ptr, "proportional_size") && RNA_property_is_set(op->ptr, "proportional_size"))
806 t->prop_size = RNA_float_get(op->ptr, "proportional_size");
810 t->prop_size = sce->toolsettings->proportional_size;
813 if (op && RNA_struct_find_property(op->ptr, "proportional_falloff") && RNA_property_is_set(op->ptr, "proportional_falloff"))
815 t->prop_mode = RNA_enum_get(op->ptr, "proportional_falloff");
819 t->prop_mode = sce->prop_mode;
822 /* TRANSFORM_FIX_ME rna restrictions */
823 if (t->prop_size <= 0)
828 setTransformViewMatrices(t);
829 initNumInput(&t->num);
830 initNDofInput(&t->ndof);
833 /* Here I would suggest only TransInfo related issues, like free data & reset vars. Not redraws */
834 void postTrans (TransInfo *t)
840 ED_region_draw_cb_exit(t->ar->type, t->draw_handle);
843 /* postTrans can be called when nothing is selected, so data is NULL already */
847 /* since ipokeys are optional on objects, we mallocced them per trans-data */
848 for(a=0, td= t->data; a<t->total; a++, td++) {
849 if(td->tdi) MEM_freeN(td->tdi);
850 if (td->flag & TD_BEZTRIPLE) MEM_freeN(td->hdata);
855 if (t->ext) MEM_freeN(t->ext);
857 MEM_freeN(t->data2d);
861 if(t->spacetype==SPACE_IMAGE) {
862 SpaceImage *sima= t->sa->spacedata.first;
863 if(sima->flag & SI_LIVE_UNWRAP)
864 ED_uvedit_live_unwrap_end(t->state == TRANS_CANCEL);
866 else if(t->spacetype==SPACE_ACTION) {
868 MEM_freeN(t->customData);
872 void applyTransObjects(TransInfo *t)
876 for (td = t->data; td < t->data + t->total; td++) {
877 VECCOPY(td->iloc, td->loc);
879 VECCOPY(td->ext->irot, td->ext->rot);
882 VECCOPY(td->ext->isize, td->ext->size);
888 /* helper for below */
889 static void restore_ipokey(float *poin, float *old)
898 static void restoreElement(TransData *td) {
899 /* TransData for crease has no loc */
901 VECCOPY(td->loc, td->iloc);
906 if (td->ext && (td->flag&TD_NO_EXT)==0) {
908 VECCOPY(td->ext->rot, td->ext->irot);
911 VECCOPY(td->ext->size, td->ext->isize);
913 if(td->flag & TD_USEQUAT) {
915 QUATCOPY(td->ext->quat, td->ext->iquat);
920 if (td->flag & TD_BEZTRIPLE) {
921 *(td->hdata->h1) = td->hdata->ih1;
922 *(td->hdata->h2) = td->hdata->ih2;
926 TransDataIpokey *tdi= td->tdi;
928 restore_ipokey(tdi->locx, tdi->oldloc);
929 restore_ipokey(tdi->locy, tdi->oldloc+1);
930 restore_ipokey(tdi->locz, tdi->oldloc+2);
932 restore_ipokey(tdi->rotx, tdi->oldrot);
933 restore_ipokey(tdi->roty, tdi->oldrot+1);
934 restore_ipokey(tdi->rotz, tdi->oldrot+2);
936 restore_ipokey(tdi->sizex, tdi->oldsize);
937 restore_ipokey(tdi->sizey, tdi->oldsize+1);
938 restore_ipokey(tdi->sizez, tdi->oldsize+2);
942 void restoreTransObjects(TransInfo *t)
946 for (td = t->data; td < t->data + t->total; td++) {
955 void calculateCenter2D(TransInfo *t)
957 if (t->flag & (T_EDIT|T_POSE)) {
958 Object *ob= t->obedit?t->obedit:t->poseobj;
961 VECCOPY(vec, t->center);
962 Mat4MulVecfl(ob->obmat, vec);
963 projectIntView(t, vec, t->center2d);
966 projectIntView(t, t->center, t->center2d);
970 void calculateCenterCursor(TransInfo *t)
974 cursor = give_cursor(t->scene, t->view);
975 VECCOPY(t->center, cursor);
977 /* If edit or pose mode, move cursor in local space */
978 if (t->flag & (T_EDIT|T_POSE)) {
979 Object *ob = t->obedit?t->obedit:t->poseobj;
980 float mat[3][3], imat[3][3];
982 VecSubf(t->center, t->center, ob->obmat[3]);
983 Mat3CpyMat4(mat, ob->obmat);
985 Mat3MulVecfl(imat, t->center);
988 calculateCenter2D(t);
991 void calculateCenterCursor2D(TransInfo *t)
993 View2D *v2d= t->view;
994 float aspx=1.0, aspy=1.0;
996 if(t->spacetype==SPACE_IMAGE) /* only space supported right now but may change */
997 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
1000 t->center[0] = v2d->cursor[0] * aspx;
1001 t->center[1] = v2d->cursor[1] * aspy;
1004 calculateCenter2D(t);
1007 void calculateCenterMedian(TransInfo *t)
1009 float partial[3] = {0.0f, 0.0f, 0.0f};
1013 for(i = 0; i < t->total; i++) {
1014 if (t->data[i].flag & TD_SELECTED) {
1015 if (!(t->data[i].flag & TD_NOCENTER))
1017 VecAddf(partial, partial, t->data[i].center);
1023 All the selected elements are at the head of the array
1024 which means we can stop when it finds unselected data
1030 VecMulf(partial, 1.0f / total);
1031 VECCOPY(t->center, partial);
1033 calculateCenter2D(t);
1036 void calculateCenterBound(TransInfo *t)
1041 for(i = 0; i < t->total; i++) {
1043 if (t->data[i].flag & TD_SELECTED) {
1044 if (!(t->data[i].flag & TD_NOCENTER))
1045 MinMax3(min, max, t->data[i].center);
1049 All the selected elements are at the head of the array
1050 which means we can stop when it finds unselected data
1056 VECCOPY(max, t->data[i].center);
1057 VECCOPY(min, t->data[i].center);
1060 VecAddf(t->center, min, max);
1061 VecMulf(t->center, 0.5);
1063 calculateCenter2D(t);
1066 void calculateCenter(TransInfo *t)
1070 calculateCenterBound(t);
1073 calculateCenterMedian(t);
1076 if(t->spacetype==SPACE_IMAGE)
1077 calculateCenterCursor2D(t);
1079 calculateCenterCursor(t);
1082 /* Individual element center uses median center for helpline and such */
1083 calculateCenterMedian(t);
1087 /* set median, and if if if... do object center */
1088 #if 0 // TRANSFORM_FIX_ME
1090 /* EDIT MODE ACTIVE EDITMODE ELEMENT */
1092 if (t->obedit && t->obedit->type == OB_MESH && EM_get_actSelection(&ese)) {
1093 EM_editselection_center(t->center, &ese);
1094 calculateCenter2D(t);
1096 } /* END EDIT MODE ACTIVE ELEMENT */
1099 calculateCenterMedian(t);
1100 if((t->flag & (T_EDIT|T_POSE))==0)
1102 Scene *scene = t->scene;
1106 VECCOPY(t->center, ob->obmat[3]);
1107 projectIntView(t, t->center, t->center2d);
1114 /* setting constraint center */
1115 VECCOPY(t->con.center, t->center);
1116 if(t->flag & (T_EDIT|T_POSE))
1118 Object *ob= t->obedit?t->obedit:t->poseobj;
1119 Mat4MulVecfl(ob->obmat, t->con.center);
1122 /* voor panning from cameraview */
1123 if(t->flag & T_OBJECT)
1125 if(t->spacetype==SPACE_VIEW3D)
1127 View3D *v3d = t->view;
1128 Scene *scene = t->scene;
1129 RegionView3D *rv3d = t->ar->regiondata;
1131 if(v3d->camera == OBACT && rv3d->persp==V3D_CAMOB)
1134 /* persinv is nasty, use viewinv instead, always right */
1135 VECCOPY(axis, t->viewinv[2]);
1138 /* 6.0 = 6 grid units */
1139 axis[0]= t->center[0]- 6.0f*axis[0];
1140 axis[1]= t->center[1]- 6.0f*axis[1];
1141 axis[2]= t->center[2]- 6.0f*axis[2];
1143 projectIntView(t, axis, t->center2d);
1145 /* rotate only needs correct 2d center, grab needs initgrabz() value */
1146 if(t->mode==TFM_TRANSLATION)
1148 VECCOPY(t->center, axis);
1149 VECCOPY(t->con.center, t->center);
1155 if(t->spacetype==SPACE_VIEW3D)
1157 /* initgrabz() defines a factor for perspective depth correction, used in window_to_3d_delta() */
1158 if(t->flag & (T_EDIT|T_POSE)) {
1159 Object *ob= t->obedit?t->obedit:t->poseobj;
1162 VECCOPY(vec, t->center);
1163 Mat4MulVecfl(ob->obmat, vec);
1164 initgrabz(t->ar->regiondata, vec[0], vec[1], vec[2]);
1167 initgrabz(t->ar->regiondata, t->center[0], t->center[1], t->center[2]);
1172 void calculatePropRatio(TransInfo *t)
1174 TransData *td = t->data;
1177 short connected = t->flag & T_PROP_CONNECTED;
1179 if (t->flag & T_PROP_EDIT) {
1180 for(i = 0 ; i < t->total; i++, td++) {
1181 if (td->flag & TD_SELECTED) {
1184 else if ((connected &&
1185 (td->flag & TD_NOTCONNECTED || td->dist > t->prop_size))
1188 td->rdist > t->prop_size)) {
1190 The elements are sorted according to their dist member in the array,
1191 that means we can stop when it finds one element outside of the propsize.
1193 td->flag |= TD_NOACTION;
1198 /* Use rdist for falloff calculations, it is the real distance */
1199 td->flag &= ~TD_NOACTION;
1200 dist= (t->prop_size-td->rdist)/t->prop_size;
1203 * Clamp to positive numbers.
1204 * Certain corner cases with connectivity and individual centers
1205 * can give values of rdist larger than propsize.
1210 switch(t->prop_mode) {
1212 td->factor= dist*dist;
1215 td->factor= 3.0f*dist*dist - 2.0f*dist*dist*dist;
1218 td->factor = (float)sqrt(dist);
1227 td->factor = (float)sqrt(2*dist - dist * dist);
1230 BLI_srand( BLI_rand() ); /* random seed */
1231 td->factor = BLI_frand()*dist;
1238 switch(t->prop_mode) {
1240 strcpy(t->proptext, "(Sharp)");
1243 strcpy(t->proptext, "(Smooth)");
1246 strcpy(t->proptext, "(Root)");
1249 strcpy(t->proptext, "(Linear)");
1252 strcpy(t->proptext, "(Constant)");
1255 strcpy(t->proptext, "(Sphere)");
1258 strcpy(t->proptext, "(Random)");
1261 strcpy(t->proptext, "");
1265 for(i = 0 ; i < t->total; i++, td++) {
1268 strcpy(t->proptext, "");
1272 TransInfo *BIF_GetTransInfo()
1277 float get_drawsize(ARegion *ar, float *co)
1279 RegionView3D *rv3d= ar->regiondata;
1280 float size, vec[3], len1, len2;
1282 /* size calculus, depending ortho/persp settings, like initgrabz() */
1283 size= rv3d->persmat[0][3]*co[0]+ rv3d->persmat[1][3]*co[1]+ rv3d->persmat[2][3]*co[2]+ rv3d->persmat[3][3];
1285 VECCOPY(vec, rv3d->persinv[0]);
1286 len1= Normalize(vec);
1287 VECCOPY(vec, rv3d->persinv[1]);
1288 len2= Normalize(vec);
1290 size*= 0.01f*(len1>len2?len1:len2);
1292 /* correct for window size to make widgets appear fixed size */
1293 if(ar->winx > ar->winy) size*= 1000.0f/(float)ar->winx;
1294 else size*= 1000.0f/(float)ar->winy;