~ubuntu-branches/ubuntu/intrepid/blender/intrepid-updates

« back to all changes in this revision

Viewing changes to source/blender/src/transform_generics.c

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-08-08 02:45:40 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080808024540-kkjp7ekfivzhuw3l
Tags: 2.46+dfsg-4
* Fix python syntax warning in import_dxf.py, which led to nasty output
  in installation/upgrade logs during byte-compilation, using a patch
  provided by the script author (Closes: #492280):
   - debian/patches/45_fix_python_syntax_warning

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: transform_generics.c,v 1.86 2006/07/03 09:23:08 campbellbarton Exp $
 
2
 * $Id: transform_generics.c 14799 2008-05-11 19:58:46Z campbellbarton $
3
3
 *
4
 
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
 
4
 * ***** BEGIN GPL LICENSE BLOCK *****
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or
7
7
 * modify it under the terms of the GNU General Public License
8
8
 * as published by the Free Software Foundation; either version 2
9
 
 * of the License, or (at your option) any later version. The Blender
10
 
 * Foundation also sells licenses for use in proprietary software under
11
 
 * the Blender License.  See http://www.blender.org/BL/ for information
12
 
 * about this.
 
9
 * of the License, or (at your option) any later version.
13
10
 *
14
11
 * This program is distributed in the hope that it will be useful,
15
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
24
 *
28
25
 * Contributor(s): none yet.
29
26
 *
30
 
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
 
27
 * ***** END GPL LICENSE BLOCK *****
31
28
 */
32
29
 
33
30
#include <string.h>
42
39
#include "DNA_lattice_types.h"
43
40
#include "DNA_mesh_types.h"
44
41
#include "DNA_modifier_types.h"
 
42
#include "DNA_nla_types.h"
45
43
#include "DNA_object_types.h"
46
44
#include "DNA_object_force.h"
 
45
#include "DNA_particle_types.h"
47
46
#include "DNA_screen_types.h"
48
47
#include "DNA_space_types.h"
49
48
#include "DNA_scene_types.h"
54
53
#include "BIF_resources.h"
55
54
#include "BIF_mywindow.h"
56
55
#include "BIF_gl.h"
 
56
#include "BIF_editaction.h"
57
57
#include "BIF_editarmature.h"
58
58
#include "BIF_editmesh.h"
 
59
#include "BIF_editnla.h"
59
60
#include "BIF_editsima.h"
 
61
#include "BIF_editparticle.h"
60
62
#include "BIF_meshtools.h"
 
63
#include "BIF_retopo.h"
 
64
 
 
65
#include "BSE_editipo.h"
 
66
#include "BSE_editipo_types.h"
 
67
 
 
68
#ifdef WITH_VERSE
 
69
#include "BIF_verse.h"
 
70
#endif
61
71
 
62
72
#include "BKE_action.h"
63
73
#include "BKE_anim.h"
64
74
#include "BKE_armature.h"
 
75
#include "BKE_cloth.h"
65
76
#include "BKE_curve.h"
66
77
#include "BKE_depsgraph.h"
67
78
#include "BKE_displist.h"
68
79
#include "BKE_depsgraph.h"
69
80
#include "BKE_global.h"
 
81
#include "BKE_group.h"
70
82
#include "BKE_ipo.h"
71
83
#include "BKE_lattice.h"
 
84
#include "BKE_key.h"
72
85
#include "BKE_mesh.h"
73
86
#include "BKE_modifier.h"
74
87
#include "BKE_object.h"
75
88
#include "BKE_utildefines.h"
76
89
 
 
90
#ifdef WITH_VERSE
 
91
#include "BKE_verse.h"
 
92
#endif
 
93
 
77
94
#include "BSE_view.h"
 
95
#include "BSE_editaction_types.h"
78
96
#include "BDR_unwrapper.h"
79
97
 
80
98
#include "BLI_arithb.h"
81
99
#include "BLI_blenlib.h"
82
100
#include "BLI_editVert.h"
 
101
#include "BLI_rand.h"
83
102
 
84
103
#include "blendef.h"
85
104
 
99
118
{
100
119
        TransInfo *t = BIF_GetTransInfo();
101
120
 
102
 
        if (t->persp)
 
121
        if (t->persp != V3D_ORTHO)
103
122
        {
104
123
                float p1[4], p2[4];
105
124
 
120
139
        else {
121
140
                VECCOPY(vec, t->viewinv[2]);
122
141
        }
123
 
        Normalise(vec);
 
142
        Normalize(vec);
124
143
}
125
144
 
126
145
/* ************************** GENERICS **************************** */
128
147
static void clipMirrorModifier(TransInfo *t, Object *ob)
129
148
{
130
149
        ModifierData *md= ob->modifiers.first;
131
 
        float tolerance[3];
 
150
        float tolerance[3] = {0.0f, 0.0f, 0.0f};
132
151
        int axis = 0;
133
152
 
134
153
        for (; md; md=md->next) {
136
155
                        MirrorModifierData *mmd = (MirrorModifierData*) md;     
137
156
                
138
157
                        if(mmd->flag & MOD_MIR_CLIPPING) {
139
 
                                switch(mmd->axis){
140
 
                                        case 0:
141
 
                                                axis |= 1;
142
 
                                                tolerance[0] = mmd->tolerance;
143
 
                                                break;
144
 
                                        case 1:
145
 
                                                axis |= 2;
146
 
                                                tolerance[1] = mmd->tolerance;
147
 
                                                break;
148
 
                                        case 2:
149
 
                                                axis |= 4;
150
 
                                                tolerance[2] = mmd->tolerance;
151
 
                                }
152
 
                        }
153
 
                }
154
 
        }
155
 
        if (axis) {
156
 
                TransData *td = t->data;
157
 
                int i;
 
158
                                axis = 0;
 
159
                                if(mmd->flag & MOD_MIR_AXIS_X) {
 
160
                                        axis |= 1;
 
161
                                        tolerance[0] = mmd->tolerance;
 
162
                                }
 
163
                                if(mmd->flag & MOD_MIR_AXIS_Y) {
 
164
                                        axis |= 2;
 
165
                                        tolerance[1] = mmd->tolerance;
 
166
                                }
 
167
                                if(mmd->flag & MOD_MIR_AXIS_Z) {
 
168
                                        axis |= 4;
 
169
                                        tolerance[2] = mmd->tolerance;
 
170
                                }
 
171
                                if (axis) {
 
172
                                        float mtx[4][4], imtx[4][4];
 
173
                                        int i;
 
174
                                        TransData *td = t->data;
158
175
                
159
 
                for(i = 0 ; i < t->total; i++, td++) {
160
 
                        if (td->flag & TD_NOACTION)
161
 
                                break;
162
 
                        if (td->loc==NULL)
163
 
                                break;
164
 
                        
165
 
                        if(axis & 1) {
166
 
                                if(fabs(td->iloc[0])<=tolerance[0] || td->loc[0]*td->iloc[0]<0.0f) td->loc[0]= 0.0f;
167
 
                        }
168
 
                        
169
 
                        if(axis & 2) {
170
 
                                if(fabs(td->iloc[1])<=tolerance[1] || td->loc[1]*td->iloc[1]<0.0f) td->loc[1]= 0.0f;
171
 
                        }
172
 
                        if(axis & 4) {
173
 
                                if(fabs(td->iloc[2])<=tolerance[2] || td->loc[2]*td->iloc[2]<0.0f) td->loc[2]= 0.0f;
 
176
                                        if (mmd->mirror_ob) {
 
177
                                                float obinv[4][4];
 
178
 
 
179
                                                Mat4Invert(obinv, mmd->mirror_ob->obmat);
 
180
                                                Mat4MulMat4(mtx, ob->obmat, obinv);
 
181
                                                Mat4Invert(imtx, mtx);
 
182
                                        }
 
183
 
 
184
                                        for(i = 0 ; i < t->total; i++, td++) {
 
185
                                                int clip;
 
186
                                                float loc[3], iloc[3];
 
187
 
 
188
                                                if (td->flag & TD_NOACTION)
 
189
                                                        break;
 
190
                                                if (td->loc==NULL)
 
191
                                                        break;
 
192
                                                        
 
193
                                                if (td->flag & TD_SKIP)
 
194
                                                        continue;
 
195
                        
 
196
                                                VecCopyf(loc,  td->loc);
 
197
                                                VecCopyf(iloc, td->iloc);
 
198
 
 
199
                                                if (mmd->mirror_ob) {
 
200
                                                        VecMat4MulVecfl(loc, mtx, loc);
 
201
                                                        VecMat4MulVecfl(iloc, mtx, iloc);
 
202
                                                }
 
203
 
 
204
                                                clip = 0;
 
205
                                                if(axis & 1) {
 
206
                                                        if(fabs(iloc[0])<=tolerance[0] || 
 
207
                                                           loc[0]*iloc[0]<0.0f) {
 
208
                                                                loc[0]= 0.0f;
 
209
                                                                clip = 1;
 
210
                                                        }
 
211
                                                }
 
212
                        
 
213
                                                if(axis & 2) {
 
214
                                                        if(fabs(iloc[1])<=tolerance[1] || 
 
215
                                                           loc[1]*iloc[1]<0.0f) {
 
216
                                                                loc[1]= 0.0f;
 
217
                                                                clip = 1;
 
218
                                                        }
 
219
                                                }
 
220
                                                if(axis & 4) {
 
221
                                                        if(fabs(iloc[2])<=tolerance[2] || 
 
222
                                                           loc[2]*iloc[2]<0.0f) {
 
223
                                                                loc[2]= 0.0f;
 
224
                                                                clip = 1;
 
225
                                                        }
 
226
                                                }
 
227
                                                if (clip) {
 
228
                                                        if (mmd->mirror_ob) {
 
229
                                                                VecMat4MulVecfl(loc, imtx, loc);
 
230
                                                        }
 
231
                                                        VecCopyf(td->loc, loc);
 
232
                                                }
 
233
                                        }
 
234
                                }
 
235
 
174
236
                        }
175
237
                }
176
238
        }
188
250
                        break;
189
251
                if (td->loc==NULL)
190
252
                        break;
 
253
                if (td->flag & TD_SKIP)
 
254
                        continue;
191
255
                
192
 
                eve= td->tdmir;
 
256
                eve = td->tdmir;
193
257
                if(eve) {
194
258
                        eve->co[0]= -td->loc[0];
195
259
                        eve->co[1]= td->loc[1];
202
266
void recalcData(TransInfo *t)
203
267
{
204
268
        Base *base;
205
 
                
206
 
        if (G.obedit) {
 
269
#ifdef WITH_VERSE
 
270
        struct TransData *td;
 
271
#endif
 
272
        
 
273
        if (t->spacetype == SPACE_ACTION) {
 
274
                Object *ob= OBACT;
 
275
                void *data;
 
276
                short context;
 
277
                
 
278
                /* determine what type of data we are operating on */
 
279
                data = get_action_context(&context);
 
280
                if (data == NULL) return;
 
281
                
 
282
                if (G.saction->lock) {
 
283
                        if (context == ACTCONT_ACTION) {
 
284
                                if(ob) {
 
285
                                        ob->ctime= -1234567.0f;
 
286
                                        if(ob->pose || ob_get_key(ob))
 
287
                                                DAG_object_flush_update(G.scene, ob, OB_RECALC);
 
288
                                        else
 
289
                                                DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
 
290
                                }
 
291
                        }
 
292
                        else if (context == ACTCONT_SHAPEKEY) {
 
293
                                DAG_object_flush_update(G.scene, OBACT, OB_RECALC_OB|OB_RECALC_DATA);
 
294
                        }
 
295
                }
 
296
        }       
 
297
        else if (t->spacetype == SPACE_NLA) {
 
298
                if (G.snla->lock) {
 
299
                        for (base=G.scene->base.first; base; base=base->next) {
 
300
                                if (base->flag & BA_HAS_RECALC_OB)
 
301
                                        base->object->recalc |= OB_RECALC_OB;
 
302
                                if (base->flag & BA_HAS_RECALC_DATA)
 
303
                                        base->object->recalc |= OB_RECALC_DATA;
 
304
                                
 
305
                                if (base->object->recalc) 
 
306
                                        base->object->ctime= -1234567.0f;       // eveil! 
 
307
                                
 
308
                                /* recalculate scale of selected nla-strips */
 
309
                                if (base->object->nlastrips.first) {
 
310
                                        Object *bob= base->object;
 
311
                                        bActionStrip *strip;
 
312
                                        
 
313
                                        for (strip= bob->nlastrips.first; strip; strip= strip->next) {
 
314
                                                if (strip->flag & ACTSTRIP_SELECT) {
 
315
                                                        float actlen= strip->actend - strip->actstart;
 
316
                                                        float len= strip->end - strip->start;
 
317
                                                        
 
318
                                                        strip->scale= len / (actlen * strip->repeat);
 
319
                                                }
 
320
                                        }
 
321
                                }
 
322
                        }
 
323
                        
 
324
                        DAG_scene_flush_update(G.scene, screen_view3d_layers(), 0);
 
325
                }
 
326
                else {
 
327
                        for (base=G.scene->base.first; base; base=base->next) {
 
328
                                /* recalculate scale of selected nla-strips */
 
329
                                if (base->object->nlastrips.first) {
 
330
                                        Object *bob= base->object;
 
331
                                        bActionStrip *strip;
 
332
                                        
 
333
                                        for (strip= bob->nlastrips.first; strip; strip= strip->next) {
 
334
                                                if (strip->flag & ACTSTRIP_SELECT) {
 
335
                                                        float actlen= strip->actend - strip->actstart;
 
336
                                                        float len= strip->end - strip->start;
 
337
                                                        
 
338
                                                        /* prevent 'negative' scaling */
 
339
                                                        if (len < 0) {
 
340
                                                                SWAP(float, strip->start, strip->end);
 
341
                                                                len= fabs(len);
 
342
                                                        }
 
343
                                                        
 
344
                                                        /* calculate new scale */
 
345
                                                        strip->scale= len / (actlen * strip->repeat);
 
346
                                                }
 
347
                                        }
 
348
                                }
 
349
                        }
 
350
                }
 
351
        }
 
352
        else if (t->spacetype == SPACE_IPO) {
 
353
                EditIpo *ei;
 
354
                int dosort = 0;
 
355
                int a;
 
356
                
 
357
                /* do the flush first */
 
358
                flushTransIpoData(t);
 
359
                
 
360
                /* now test if there is a need to re-sort */
 
361
                ei= G.sipo->editipo;
 
362
                for (a=0; a<G.sipo->totipo; a++, ei++) {
 
363
                        if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
 
364
                                
 
365
                                /* watch it: if the time is wrong: do not correct handles */
 
366
                                if (test_time_ipocurve(ei->icu)) {
 
367
                                        dosort++;
 
368
                                } else {
 
369
                                        calchandles_ipocurve(ei->icu);
 
370
                                }
 
371
                        }
 
372
                }
 
373
                
 
374
                /* do resort and other updates? */
 
375
                if (dosort) remake_ipo_transdata(t);
 
376
                if (G.sipo->showkey) update_ipokey_val();
 
377
                
 
378
                calc_ipo(G.sipo->ipo, (float)CFRA);
 
379
                
 
380
                /* update realtime - not working? */
 
381
                if (G.sipo->lock) {
 
382
                        if (G.sipo->blocktype==ID_MA || G.sipo->blocktype==ID_TE) {
 
383
                                do_ipo(G.sipo->ipo);
 
384
                        }
 
385
                        else if(G.sipo->blocktype==ID_CA) {
 
386
                                do_ipo(G.sipo->ipo);
 
387
                        }
 
388
                        else if(G.sipo->blocktype==ID_KE) {
 
389
                                Object *ob= OBACT;
 
390
                                if(ob) {
 
391
                                        ob->shapeflag &= ~OB_SHAPE_TEMPLOCK;
 
392
                                        DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
 
393
                                }
 
394
                        }
 
395
                        else if(G.sipo->blocktype==ID_PO) {
 
396
                                Object *ob= OBACT;
 
397
                                if(ob && ob->pose) {
 
398
                                        DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
 
399
                                }
 
400
                        }
 
401
                        else if(G.sipo->blocktype==ID_OB) {
 
402
                                Base *base= FIRSTBASE;
 
403
                                
 
404
                                while(base) {
 
405
                                        if(base->object->ipo==G.sipo->ipo) {
 
406
                                                do_ob_ipo(base->object);
 
407
                                                base->object->recalc |= OB_RECALC_OB;
 
408
                                        }
 
409
                                        base= base->next;
 
410
                                }
 
411
                                DAG_scene_flush_update(G.scene, screen_view3d_layers(), 0);
 
412
                        }
 
413
                }
 
414
        }
 
415
        else if (G.obedit) {
207
416
                if (G.obedit->type == OB_MESH) {
208
 
 
209
 
                        /* mirror modifier clipping? */
210
 
                        if(t->state != TRANS_CANCEL)
211
 
                                clipMirrorModifier(t, G.obedit);
212
 
                        
213
 
                        if(G.scene->toolsettings->editbutflag & B_MESH_X_MIRROR)
214
 
                                editmesh_apply_to_mirror(t);
215
 
                        
216
 
                        DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);  /* sets recalc flags */
217
 
                        
218
 
                        recalc_editnormals();
 
417
                        if(t->spacetype==SPACE_IMAGE) {
 
418
                                flushTransUVs(t);
 
419
                                if (G.sima->flag & SI_LIVE_UNWRAP)
 
420
                                        unwrap_lscm_live_re_solve();
 
421
                        } else {
 
422
                                /* mirror modifier clipping? */
 
423
                                if(t->state != TRANS_CANCEL) {
 
424
                                        if ((G.qual & LR_CTRLKEY)==0) {
 
425
                                                /* Only retopo if not snapping, Note, this is the only case of G.qual being used, but we have no T_SHIFT_MOD - Campbell */
 
426
                                                retopo_do_all();
 
427
                                        }
 
428
                                        clipMirrorModifier(t, G.obedit);
 
429
                                }
 
430
                                if((t->context & CTX_NO_MIRROR) == 0 && (G.scene->toolsettings->editbutflag & B_MESH_X_MIRROR))
 
431
                                        editmesh_apply_to_mirror(t);
 
432
                                
 
433
                                DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);  /* sets recalc flags */
 
434
                                
 
435
                                recalc_editnormals();
 
436
                        }
219
437
                }
220
438
                else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
221
439
                        Nurb *nu= editNurb.first;
222
440
                        DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);  /* sets recalc flags */
223
441
                        
224
 
                        while(nu) {
225
 
                                test2DNurb(nu);
226
 
                                testhandlesNurb(nu); /* test for bezier too */
227
 
                                nu= nu->next;
 
442
                        if (t->state == TRANS_CANCEL) {
 
443
                                while(nu) {
 
444
                                        calchandlesNurb(nu); /* Cant do testhandlesNurb here, it messes up the h1 and h2 flags */
 
445
                                        nu= nu->next;
 
446
                                }
 
447
                        } else {
 
448
                                /* Normal updating */
 
449
                                while(nu) {
 
450
                                        test2DNurb(nu);
 
451
                                        calchandlesNurb(nu);
 
452
                                        nu= nu->next;
 
453
                                }
 
454
                                retopo_do_all();
228
455
                        }
229
456
                }
230
457
                else if(G.obedit->type==OB_ARMATURE){   /* no recalc flag, does pose */
286
513
                /* old optimize trick... this enforces to bypass the depgraph */
287
514
                if (!(arm->flag & ARM_DELAYDEFORM)) {
288
515
                        DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);  /* sets recalc flags */
289
 
                        
290
 
                        /* bah, softbody exception... recalcdata doesnt reset */
291
 
                        for(base= FIRSTBASE; base; base= base->next) {
292
 
                                if(base->object->recalc & OB_RECALC_DATA)
293
 
                                        if(modifiers_isSoftbodyEnabled(base->object)) {
294
 
                                                base->object->softflag |= OB_SB_REDO;
295
 
                                }
296
 
                        }
297
516
                }
298
517
                else
299
518
                        where_is_pose(ob);
300
519
        }
301
 
        else if(t->spacetype==SPACE_IMAGE) {
302
 
                flushTransUVs(t);
303
 
                if (G.sima->flag & SI_LIVE_UNWRAP)
304
 
                        unwrap_lscm_live_re_solve();
 
520
        else if(G.f & G_PARTICLEEDIT) {
 
521
                flushTransParticles(t);
305
522
        }
306
523
        else {
307
524
                for(base= FIRSTBASE; base; base= base->next) {
308
 
                        /* this flag is from depgraph, was stored in nitialize phase, handled in drawview.c */
 
525
                        Object *ob= base->object;
 
526
                        
 
527
                        /* this flag is from depgraph, was stored in initialize phase, handled in drawview.c */
309
528
                        if(base->flag & BA_HAS_RECALC_OB)
310
 
                                base->object->recalc |= OB_RECALC_OB;
 
529
                                ob->recalc |= OB_RECALC_OB;
311
530
                        if(base->flag & BA_HAS_RECALC_DATA)
312
 
                                base->object->recalc |= OB_RECALC_DATA;
313
 
                        
 
531
                                ob->recalc |= OB_RECALC_DATA;
 
532
 
314
533
                        /* thanks to ob->ctime usage, ipos are not called in where_is_object,
315
534
                           unless we edit ipokeys */
316
535
                        if(base->flag & BA_DO_IPO) {
317
 
                                if(base->object->ipo) {
 
536
                                if(ob->ipo) {
318
537
                                        IpoCurve *icu;
319
538
                                        
320
 
                                        base->object->ctime= -1234567.0;
 
539
                                        ob->ctime= -1234567.0;
321
540
                                        
322
 
                                        icu= base->object->ipo->curve.first;
 
541
                                        icu= ob->ipo->curve.first;
323
542
                                        while(icu) {
324
543
                                                calchandles_ipocurve(icu);
325
544
                                                icu= icu->next;
327
546
                                }                               
328
547
                        }
329
548
                        
330
 
                        /* softbody exception */
331
 
                        if(modifiers_isSoftbodyEnabled(base->object)) {
332
 
                                if(base->object->recalc & OB_RECALC_DATA)
333
 
                                        base->object->softflag |= OB_SB_REDO;
334
 
                        }
 
549
                        /* proxy exception */
 
550
                        if(ob->proxy)
 
551
                                ob->proxy->recalc |= ob->recalc;
 
552
                        if(ob->proxy_group)
 
553
                                group_tag_recalc(ob->proxy_group->dup_group);
335
554
                } 
336
555
        }
 
556
 
 
557
#ifdef WITH_VERSE
 
558
        for (td = t->data; td < t->data + t->total; td++) {
 
559
                if(td->flag & TD_VERSE_VERT) {
 
560
                        if(td->verse)
 
561
                                send_versevert_pos((VerseVert*)td->verse);
 
562
                }
 
563
                else if(td->flag & TD_VERSE_OBJECT)
 
564
                        if(td->verse) b_verse_send_transformation((Object*)td->verse);
 
565
        }
 
566
#endif
337
567
        
338
568
        /* update shaded drawmode while transform */
339
569
        if(t->spacetype==SPACE_VIEW3D && G.vd->drawtype == OB_SHADED)
340
570
                reshadeall_displist();
341
 
        
342
571
}
343
572
 
344
573
void initTransModeFlags(TransInfo *t, int mode) 
367
596
        case TFM_SHEAR:
368
597
        case TFM_CREASE:
369
598
        case TFM_BONE_ENVELOPE:
 
599
        case TFM_CURVE_SHRINKFATTEN:
 
600
        case TFM_BONE_ROLL:
370
601
                t->flag |= T_NO_CONSTRAINT;
371
602
                break;
372
603
        }
393
624
                BIF_GetThemeColor3ubv(TH_GRID, col);
394
625
        }
395
626
        make_axis_color(col, col2, axis);
396
 
        glColor3ubv(col2);
 
627
        glColor3ubv((GLubyte *)col2);
397
628
 
398
629
        setlinestyle(0);
399
630
        glBegin(GL_LINE_STRIP); 
409
640
        
410
641
        /* moving: is shown in drawobject() (transform color) */
411
642
        if(G.obedit || (t->flag & T_POSE) ) G.moving= G_TRANSFORM_EDIT;
 
643
        else if(G.f & G_PARTICLEEDIT) G.moving= G_TRANSFORM_PARTICLE;
412
644
        else G.moving= G_TRANSFORM_OBJ;
413
645
 
414
646
        t->data = NULL;
427
659
        t->con.imval[1] = t->imval[1];
428
660
 
429
661
        t->transform            = NULL;
 
662
        t->handleEvent          = NULL;
430
663
 
431
664
        t->total                        =
432
665
                t->num.idx              =
445
678
                t->vec[1]               =
446
679
                t->vec[2]               = 0.0f;
447
680
        
 
681
        t->center[0]            =
 
682
                t->center[1]    =
 
683
                t->center[2]    = 0.0f;
 
684
        
448
685
        Mat3One(t->mat);
449
686
        
450
687
        t->spacetype = curarea->spacetype;
451
688
        if(t->spacetype==SPACE_VIEW3D) {
452
689
                if(G.vd->flag & V3D_ALIGN) t->flag |= T_V3D_ALIGN;
453
690
                t->around = G.vd->around;
 
691
        } else if(t->spacetype==SPACE_IMAGE) {
 
692
                t->around = G.v2d->around;
454
693
        }
455
694
        else
456
 
                t->around = V3D_CENTRE;
 
695
                t->around = V3D_CENTER;
457
696
 
458
697
        setTransformViewMatrices(t);
 
698
        initNDofInput(&(t->ndof));
459
699
}
460
700
 
461
701
/* Here I would suggest only TransInfo related issues, like free data & reset vars. Not redraws */
462
702
void postTrans (TransInfo *t) 
463
703
{
 
704
        TransData *td;
 
705
 
464
706
        G.moving = 0; // Set moving flag off (display as usual)
 
707
#ifdef WITH_VERSE
 
708
 
 
709
        for (td = t->data; td < t->data + t->total; td++) {
 
710
                if(td->flag & TD_VERSE_VERT) {
 
711
                        if(td->verse) send_versevert_pos((VerseVert*)td->verse);
 
712
                }
 
713
                else if(td->flag & TD_VERSE_OBJECT) {
 
714
                        if(td->verse) {
 
715
                                struct VNode *vnode;
 
716
                                vnode = (VNode*)((Object*)td->verse)->vnode;
 
717
                                ((VObjectData*)vnode->data)->flag |= POS_SEND_READY;
 
718
                                ((VObjectData*)vnode->data)->flag |= ROT_SEND_READY;
 
719
                                ((VObjectData*)vnode->data)->flag |= SCALE_SEND_READY;
 
720
                                b_verse_send_transformation((Object*)td->verse);
 
721
                        }
 
722
                }
 
723
        }
 
724
#endif
465
725
 
466
726
        stopConstraint(t);
467
727
        
468
728
        /* postTrans can be called when nothing is selected, so data is NULL already */
469
729
        if (t->data) {
470
 
                TransData *td;
471
730
                int a;
472
731
 
473
732
                /* since ipokeys are optional on objects, we mallocced them per trans-data */
474
733
                for(a=0, td= t->data; a<t->total; a++, td++) {
475
734
                        if(td->tdi) MEM_freeN(td->tdi);
 
735
                        if (td->flag & TD_BEZTRIPLE) MEM_freeN(td->hdata); 
476
736
                }
477
737
                MEM_freeN(t->data);
478
738
        }
489
749
        }
490
750
}
491
751
 
492
 
static void apply_grid3(TransInfo *t, float *val, int max_index, float fac1, float fac2, float fac3)
493
 
{
494
 
        /* fac1 is for 'nothing', fac2 for CTRL, fac3 for SHIFT */
495
 
        int invert;
496
 
        int ctrl;
497
 
        int i;
498
 
        float asp= 1.0f;
499
 
 
500
 
        if(t->mode==TFM_ROTATION || t->mode==TFM_WARP || t->mode==TFM_TILT || t->mode==TFM_TRACKBALL)
501
 
                invert = U.flag & USER_AUTOROTGRID;
502
 
        else if(t->mode==TFM_RESIZE || t->mode==TFM_SHEAR || t->mode==TFM_BONESIZE || t->mode==TFM_SHRINKFATTEN)
503
 
                invert = U.flag & USER_AUTOSIZEGRID;
504
 
        else
505
 
                invert = U.flag & USER_AUTOGRABGRID;
506
 
        
507
 
        for (i=0; i<=max_index; i++) {
508
 
 
509
 
                /* evil hack - snapping needs to be adapted for image aspect ratio */
510
 
                if((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
511
 
                        float aspx, aspy;
512
 
                        transform_aspect_ratio_tface_uv(&aspx, &aspy);
513
 
                        if(i==0) asp= aspx;
514
 
                        else asp= aspy;
515
 
                }
516
 
 
517
 
                if(invert) {
518
 
                        if(G.qual & LR_CTRLKEY) ctrl= 0;
519
 
                        else ctrl= 1;
520
 
                }
521
 
                else ctrl= (G.qual & LR_CTRLKEY);
522
 
 
523
 
                if(ctrl && (G.qual & LR_SHIFTKEY)) {
524
 
                        if(fac3!= 0.0) {
525
 
                                for (i=0; i<=max_index; i++) {
526
 
                                        val[i]= fac3*asp*(float)floor(val[i]/(fac3*asp) +.5);
527
 
                                }
528
 
                        }
529
 
                }
530
 
                else if(ctrl) {
531
 
                        if(fac2!= 0.0) {
532
 
                                for (i=0; i<=max_index; i++) {
533
 
                                        val[i]= fac2*asp*(float)floor(val[i]/(fac2*asp) +.5);
534
 
                                }
535
 
                        }
536
 
                }
537
 
                else {
538
 
                        if(fac1!= 0.0) {
539
 
                                for (i=0; i<=max_index; i++) {
540
 
                                        val[i]= fac1*asp*(float)floor(val[i]/(fac1*asp) +.5);
541
 
                                }
542
 
                        }
543
 
                }
544
 
        }
545
 
}
546
 
 
547
 
void snapGrid(TransInfo *t, float *val) {
548
 
        apply_grid3(t, val, t->idx_max, t->snap[0], t->snap[1], t->snap[2]);
549
 
}
550
 
 
551
752
void applyTransObjects(TransInfo *t)
552
753
{
553
754
        TransData *td;
582
783
        if (td->val) {
583
784
                *td->val = td->ival;
584
785
        }
585
 
        if (td->ext) {
 
786
        if (td->ext && (td->flag&TD_NO_EXT)==0) {
586
787
                if (td->ext->rot) {
587
788
                        VECCOPY(td->ext->rot, td->ext->irot);
588
789
                }
595
796
                        }
596
797
                }
597
798
        }
 
799
        
 
800
        if (td->flag & TD_BEZTRIPLE) {
 
801
                *(td->hdata->h1) = td->hdata->ih1;
 
802
                *(td->hdata->h2) = td->hdata->ih2;
 
803
        }
 
804
        
598
805
        if(td->tdi) {
599
806
                TransDataIpokey *tdi= td->tdi;
600
807
                
618
825
        
619
826
        for (td = t->data; td < t->data + t->total; td++) {
620
827
                restoreElement(td);
 
828
#ifdef WITH_VERSE
 
829
                /* position of vertexes and object transformation matrix is sent
 
830
                 * extra, becuase blender uses synchronous sending of vertexes
 
831
                 * position as well object trans. matrix and it isn't possible to
 
832
                 * send it in recalcData sometimes */
 
833
                if(td->flag & TD_VERSE_VERT) {
 
834
                        if(td->verse) {
 
835
                                ((VerseVert*)td->verse)->flag |= VERT_POS_OBSOLETE;
 
836
                        }
 
837
                }
 
838
                else if(td->flag & TD_VERSE_OBJECT)
 
839
                        if(td->verse) {
 
840
                                struct VNode *vnode;
 
841
                                vnode = (VNode*)((Object*)td->verse)->vnode;
 
842
                                ((VObjectData*)vnode->data)->flag |= POS_SEND_READY;
 
843
                                ((VObjectData*)vnode->data)->flag |= ROT_SEND_READY;
 
844
                                ((VObjectData*)vnode->data)->flag |= SCALE_SEND_READY;
 
845
                        }
 
846
#endif
621
847
        }       
622
848
        recalcData(t);
623
849
}
645
871
        VECCOPY(t->center, cursor);
646
872
 
647
873
        /* If edit or pose mode, move cursor in local space */
648
 
        if(t->flag & (T_EDIT|T_POSE)) {
649
 
                Object *ob= G.obedit?G.obedit:t->poseobj;
 
874
        if (t->flag & (T_EDIT|T_POSE)) {
 
875
                Object *ob = G.obedit?G.obedit:t->poseobj;
650
876
                float mat[3][3], imat[3][3];
651
877
                
652
878
                VecSubf(t->center, t->center, ob->obmat[3]);
658
884
        calculateCenter2D(t);
659
885
}
660
886
 
 
887
void calculateCenterCursor2D(TransInfo *t)
 
888
{
 
889
        float aspx=1.0, aspy=1.0;
 
890
        
 
891
        if(t->spacetype==SPACE_IMAGE) /* only space supported right now but may change */
 
892
                transform_aspect_ratio_tface_uv(&aspx, &aspy);
 
893
        if (G.v2d) {
 
894
                t->center[0] = G.v2d->cursor[0] * aspx; 
 
895
                t->center[1] = G.v2d->cursor[1] * aspy; 
 
896
        }
 
897
        calculateCenter2D(t);
 
898
}
 
899
 
661
900
void calculateCenterMedian(TransInfo *t)
662
901
{
663
902
        float partial[3] = {0.0f, 0.0f, 0.0f};
664
903
        int i;
 
904
        
665
905
        for(i = 0; i < t->total; i++) {
666
906
                if (t->data[i].flag & TD_SELECTED) {
667
 
                        VecAddf(partial, partial, t->data[i].center);
 
907
                        if (!(t->data[i].flag & TD_NOCENTER))
 
908
                                VecAddf(partial, partial, t->data[i].center);
668
909
                }
669
910
                else {
670
911
                        /* 
674
915
                        break;
675
916
                }
676
917
        }
677
 
        VecMulf(partial, 1.0f / i);
 
918
        if(i)
 
919
                VecMulf(partial, 1.0f / i);
678
920
        VECCOPY(t->center, partial);
679
921
 
680
922
        calculateCenter2D(t);
688
930
        for(i = 0; i < t->total; i++) {
689
931
                if (i) {
690
932
                        if (t->data[i].flag & TD_SELECTED) {
691
 
                                MinMax3(min, max, t->data[i].center);
 
933
                                if (!(t->data[i].flag & TD_NOCENTER))
 
934
                                        MinMax3(min, max, t->data[i].center);
692
935
                        }
693
936
                        else {
694
937
                                /* 
712
955
void calculateCenter(TransInfo *t) 
713
956
{
714
957
        switch(t->around) {
715
 
        case V3D_CENTRE:
 
958
        case V3D_CENTER:
716
959
                calculateCenterBound(t);
717
960
                break;
718
961
        case V3D_CENTROID:
719
962
                calculateCenterMedian(t);
720
963
                break;
721
964
        case V3D_CURSOR:
722
 
                calculateCenterCursor(t);
 
965
                if(t->spacetype==SPACE_IMAGE)
 
966
                        calculateCenterCursor2D(t);
 
967
                else
 
968
                        calculateCenterCursor(t);
723
969
                break;
724
970
        case V3D_LOCAL:
725
971
                /* Individual element center uses median center for helpline and such */
726
972
                calculateCenterMedian(t);
727
973
                break;
728
974
        case V3D_ACTIVE:
 
975
                {
729
976
                /* set median, and if if if... do object center */
730
 
                
 
977
                EditSelection ese;
731
978
                /* EDIT MODE ACTIVE EDITMODE ELEMENT */
732
 
                if (G.obedit && G.obedit->type == OB_MESH && G.editMesh->selected.last) {
733
 
                        EM_editselection_center(t->center, G.editMesh->selected.last);
 
979
                if (G.obedit && G.obedit->type == OB_MESH && EM_get_actSelection(&ese)) {
 
980
                        EM_editselection_center(t->center, &ese);
734
981
                        calculateCenter2D(t);
735
982
                        break;
736
983
                } /* END EDIT MODE ACTIVE ELEMENT */
743
990
                                projectIntView(t, t->center, t->center2d);
744
991
                        }
745
992
                }
 
993
                
 
994
                }
746
995
        }
747
996
 
748
997
        /* setting constraint center */
754
1003
 
755
1004
        /* voor panning from cameraview */
756
1005
        if(t->flag & T_OBJECT) {
757
 
                if( G.vd->camera==OBACT && G.vd->persp>1) {
 
1006
                if( G.vd->camera==OBACT && G.vd->persp==V3D_CAMOB) {
758
1007
                        float axis[3];
759
1008
                        /* persinv is nasty, use viewinv instead, always right */
760
1009
                        VECCOPY(axis, t->viewinv[2]);
761
 
                        Normalise(axis);
 
1010
                        Normalize(axis);
762
1011
 
763
1012
                        /* 6.0 = 6 grid units */
764
1013
                        axis[0]= t->center[0]- 6.0f*axis[0];
808
1057
                                /* Use rdist for falloff calculations, it is the real distance */
809
1058
                                td->flag &= ~TD_NOACTION;
810
1059
                                dist= (t->propsize-td->rdist)/t->propsize;
 
1060
                                
 
1061
                                /*
 
1062
                                 * Clamp to positive numbers.
 
1063
                                 * Certain corner cases with connectivity and individual centers
 
1064
                                 * can give values of rdist larger than propsize.
 
1065
                                 */
 
1066
                                if (dist < 0.0f)
 
1067
                                        dist = 0.0f;
 
1068
                                
811
1069
                                switch(G.scene->prop_mode) {
812
1070
                                case PROP_SHARP:
813
1071
                                        td->factor= dist*dist;
827
1085
                                case PROP_SPHERE:
828
1086
                                        td->factor = (float)sqrt(2*dist - dist * dist);
829
1087
                                        break;
 
1088
                                case PROP_RANDOM:
 
1089
                                        BLI_srand( BLI_rand() ); /* random seed */
 
1090
                                        td->factor = BLI_frand()*dist;
 
1091
                                        break;
830
1092
                                default:
831
1093
                                        td->factor = 1;
832
1094
                                }
851
1113
                case PROP_SPHERE:
852
1114
                        strcpy(t->proptext, "(Sphere)");
853
1115
                        break;
 
1116
                case PROP_RANDOM:
 
1117
                        strcpy(t->proptext, "(Random)");
 
1118
                        break;
854
1119
                default:
855
1120
                        strcpy(t->proptext, "");
856
1121
                }