~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Lukas Fittl
  • Date: 2006-09-20 01:57:27 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060920015727-gmoqlxwstx9wwqs3
Tags: 2.42a-1ubuntu1
* Merge from Debian unstable (Closes: Malone #55903). Remaining changes:
  - debian/genpot: Add python scripts from Lee June <blender@eyou.com> to
    generate a reasonable PO template from the sources. Since gettext is used
    in a highly nonstandard way, xgettext does not work for this job.
  - debian/rules: Call the scripts, generate po/blender.pot, and clean it up
    in the clean target.
  - Add a proper header to the generated PO template.
* debian/control: Build depend on libavformat-dev >= 3:0.cvs20060823-3.1,
  otherwise this package will FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: poseobject.c,v 1.35 2005/12/12 22:27:30 ton Exp $
 
2
 * $Id: poseobject.c,v 1.37 2006/06/15 04:13:26 hos Exp $
3
3
 *
4
4
 * ***** BEGIN GPL LICENSE BLOCK *****
5
5
 *
119
119
 
120
120
void set_pose_keys (Object *ob)
121
121
{
 
122
        bArmature *arm= ob->data;
122
123
        bPoseChannel *chan;
123
124
 
124
125
        if (ob->pose){
125
126
                for (chan=ob->pose->chanbase.first; chan; chan=chan->next){
126
127
                        Bone *bone= chan->bone;
127
 
                        if(bone && (bone->flag & BONE_SELECTED)) {
 
128
                        if(bone && (bone->flag & BONE_SELECTED) && (arm->layer & bone->layer)) {
128
129
                                chan->flag |= POSE_KEY;         
129
130
                        }
130
131
                        else {
157
158
/* called by buttons to find a bone to display/edit values for */
158
159
bPoseChannel *get_active_posechannel (Object *ob)
159
160
{
 
161
        bArmature *arm= ob->data;
160
162
        bPoseChannel *pchan;
161
163
        
162
164
        /* find active */
163
165
        for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
164
 
                if(pchan->bone && (pchan->bone->flag & BONE_ACTIVE))
 
166
                if(pchan->bone && (pchan->bone->flag & BONE_ACTIVE) && (pchan->bone->layer & arm->layer))
165
167
                        return pchan;
166
168
        }
167
169
        
194
196
/* for the object with pose/action: create path curves for selected bones */
195
197
void pose_calculate_path(Object *ob)
196
198
{
 
199
        bArmature *arm;
197
200
        bPoseChannel *pchan;
198
201
        Base *base;
199
202
        float *fp;
201
204
        
202
205
        if(ob==NULL || ob->pose==NULL)
203
206
                return;
 
207
        arm= ob->data;
204
208
        
205
209
        if(EFRA<=SFRA) return;
206
210
        
209
213
        /* malloc the path blocks */
210
214
        for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
211
215
                if(pchan->bone && (pchan->bone->flag & BONE_SELECTED)) {
212
 
                        pchan->pathlen= EFRA-SFRA;
213
 
                        if(pchan->path)
214
 
                                MEM_freeN(pchan->path);
215
 
                        pchan->path= MEM_callocN(3*pchan->pathlen*sizeof(float), "pchan path");
 
216
                        if(arm->layer & pchan->bone->layer) {
 
217
                                pchan->pathlen= EFRA-SFRA;
 
218
                                if(pchan->path)
 
219
                                        MEM_freeN(pchan->path);
 
220
                                pchan->path= MEM_callocN(3*pchan->pathlen*sizeof(float), "pchan path");
 
221
                        }
216
222
                }
217
223
        }
218
224
        
230
236
                
231
237
                for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
232
238
                        if(pchan->bone && (pchan->bone->flag & BONE_SELECTED)) {
233
 
                                if(pchan->path) {
234
 
                                        fp= pchan->path+3*(CFRA-SFRA);
235
 
                                        VECCOPY(fp, pchan->pose_tail);
236
 
                                        Mat4MulVecfl(ob->obmat, fp);
 
239
                                if(arm->layer & pchan->bone->layer) {
 
240
                                        if(pchan->path) {
 
241
                                                fp= pchan->path+3*(CFRA-SFRA);
 
242
                                                VECCOPY(fp, pchan->pose_tail);
 
243
                                                Mat4MulVecfl(ob->obmat, fp);
 
244
                                        }
237
245
                                }
238
246
                        }
239
247
                }
268
276
void pose_select_constraint_target(void)
269
277
{
270
278
        Object *ob= OBACT;
 
279
        bArmature *arm= ob->data;
271
280
        bPoseChannel *pchan;
272
281
        bConstraint *con;
273
282
        
276
285
        if(ob==G.obedit || (ob->flag & OB_POSEMODE)==0) return;
277
286
        
278
287
        for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
279
 
                if(pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) {
280
 
                        
281
 
                        for(con= pchan->constraints.first; con; con= con->next) {
282
 
                                char *subtarget;
283
 
                                Object *target= get_constraint_target(con, &subtarget);
 
288
                if(arm->layer & pchan->bone->layer) {
 
289
                        if(pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) {
284
290
                                
285
 
                                if(ob==target) {
286
 
                                        if(subtarget) {
287
 
                                                bPoseChannel *pchanc= get_pose_channel(ob->pose, subtarget);
288
 
                                                pchanc->bone->flag |= BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL;
 
291
                                for(con= pchan->constraints.first; con; con= con->next) {
 
292
                                        char *subtarget;
 
293
                                        Object *target= get_constraint_target(con, &subtarget);
 
294
                                        
 
295
                                        if(ob==target) {
 
296
                                                if(subtarget) {
 
297
                                                        bPoseChannel *pchanc= get_pose_channel(ob->pose, subtarget);
 
298
                                                        pchanc->bone->flag |= BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL;
 
299
                                                }
289
300
                                        }
290
301
                                }
291
302
                        }
340
351
void pose_clear_IK(void)
341
352
{
342
353
        Object *ob= OBACT;
 
354
        bArmature *arm= ob->data;
343
355
        bPoseChannel *pchan;
344
356
        bConstraint *con;
345
357
        bConstraint *next;
351
363
        if(okee("Remove IK constraint(s)")==0) return;
352
364
 
353
365
        for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
354
 
                if(pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) {
355
 
                        
356
 
                        for(con= pchan->constraints.first; con; con= next) {
357
 
                                next= con->next;
358
 
                                if(con->type==CONSTRAINT_TYPE_KINEMATIC) {
359
 
                                        BLI_remlink(&pchan->constraints, con);
360
 
                                        free_constraint_data(con);
361
 
                                        MEM_freeN(con);
 
366
                if(arm->layer & pchan->bone->layer) {
 
367
                        if(pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) {
 
368
                                
 
369
                                for(con= pchan->constraints.first; con; con= next) {
 
370
                                        next= con->next;
 
371
                                        if(con->type==CONSTRAINT_TYPE_KINEMATIC) {
 
372
                                                BLI_remlink(&pchan->constraints, con);
 
373
                                                free_constraint_data(con);
 
374
                                                MEM_freeN(con);
 
375
                                        }
362
376
                                }
 
377
                                pchan->constflag &= ~(PCHAN_HAS_IK|PCHAN_HAS_TARGET);
363
378
                        }
364
 
                        pchan->constflag &= ~(PCHAN_HAS_IK|PCHAN_HAS_TARGET);
365
379
                }
366
380
        }
367
381
        
377
391
void pose_clear_constraints(void)
378
392
{
379
393
        Object *ob= OBACT;
 
394
        bArmature *arm= ob->data;
380
395
        bPoseChannel *pchan;
381
396
        
382
397
        /* paranoia checks */
387
402
        
388
403
        /* find active */
389
404
        for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
390
 
                if(pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) {
391
 
                        free_constraints(&pchan->constraints);
392
 
                        pchan->constflag= 0;
 
405
                if(arm->layer & pchan->bone->layer) {
 
406
                        if(pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) {
 
407
                                free_constraints(&pchan->constraints);
 
408
                                pchan->constflag= 0;
 
409
                        }
393
410
                }
394
411
        }
395
412
        
407
424
void pose_copy_menu(void)
408
425
{
409
426
        Object *ob= OBACT;
 
427
        bArmature *arm= ob->data;
410
428
        bPoseChannel *pchan, *pchanact;
411
429
        short nr;
412
430
        
422
440
        if(pchan==NULL) return;
423
441
        pchanact= pchan;
424
442
        
425
 
        nr= pupmenu("Copy Pose Attributes %t|Location%x1|Rotation%x2|Size%x3|Constraints");
 
443
        nr= pupmenu("Copy Pose Attributes %t|Location%x1|Rotation%x2|Scale%x3|Constraints");
426
444
        
427
445
        for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
428
 
                if(pchan->bone->flag & BONE_SELECTED) {
429
 
                        if(pchan!=pchanact) {
430
 
                                if(nr==1) {
431
 
                                        VECCOPY(pchan->loc, pchanact->loc);
432
 
                                }
433
 
                                else if(nr==2) {
434
 
                                        QUATCOPY(pchan->quat, pchanact->quat);
435
 
                                }
436
 
                                else if(nr==3) {
437
 
                                        VECCOPY(pchan->size, pchanact->size);
438
 
                                }
439
 
                                else if(nr==4) {
440
 
                                        free_constraints(&pchan->constraints);
441
 
                                        copy_constraints(&pchan->constraints, &pchanact->constraints);
442
 
                                        pchan->constflag = pchanact->constflag;
 
446
                if(arm->layer & pchan->bone->layer) {
 
447
                        if(pchan->bone->flag & BONE_SELECTED) {
 
448
                                if(pchan!=pchanact) {
 
449
                                        if(nr==1) {
 
450
                                                VECCOPY(pchan->loc, pchanact->loc);
 
451
                                        }
 
452
                                        else if(nr==2) {
 
453
                                                QUATCOPY(pchan->quat, pchanact->quat);
 
454
                                        }
 
455
                                        else if(nr==3) {
 
456
                                                VECCOPY(pchan->size, pchanact->size);
 
457
                                        }
 
458
                                        else if(nr==4) {
 
459
                                                free_constraints(&pchan->constraints);
 
460
                                                copy_constraints(&pchan->constraints, &pchanact->constraints);
 
461
                                                pchan->constflag = pchanact->constflag;
 
462
                                        }
443
463
                                }
444
464
                        }
445
465
                }
616
636
        struct vgroup_map map;
617
637
        DerivedMesh *dm;
618
638
        Object *poseobj= modifiers_isDeformedByArmature(meshobj);
 
639
        bArmature *arm= poseobj->data;
619
640
        bPoseChannel *pchan;
620
641
        Bone *bone;
621
642
        bDeformGroup *dg, *curdef;
629
650
        
630
651
        for(pchan= poseobj->pose->chanbase.first; pchan; pchan= pchan->next) {
631
652
                bone= pchan->bone;
632
 
                if(bone->flag & (BONE_SELECTED)) {
633
 
                        
634
 
                        /* check if mesh has vgroups */
635
 
                        dg= get_named_vertexgroup(meshobj, bone->name);
636
 
                        if(dg==NULL)
637
 
                                dg= add_defgroup_name(meshobj, bone->name);
638
 
                        
639
 
                        /* flipped bone */
640
 
                        if(Gwp.flag & VP_MIRROR_X) {
641
 
                                char name[32];
642
 
                                
643
 
                                BLI_strncpy(name, dg->name, 32);
644
 
                                bone_flip_name(name, 0);                // 0 = don't strip off number extensions
645
 
                                
646
 
                                for (curdef = meshobj->defbase.first; curdef; curdef=curdef->next)
647
 
                                        if (!strcmp(curdef->name, name))
648
 
                                                break;
649
 
                                map.dgflip= curdef;
650
 
                        }
651
 
                        else map.dgflip= NULL;
652
 
                        
653
 
                        /* get the root of the bone in global coords */
654
 
                        VECCOPY(map.head, bone->arm_head);
655
 
                        Mat4MulVecfl(poseobj->obmat, map.head);
656
 
                        
657
 
            /* get the tip of the bone in global coords */
658
 
                        VECCOPY(map.tail, bone->arm_tail);
659
 
            Mat4MulVecfl(poseobj->obmat, map.tail);
660
 
                        
661
 
                        /* use the optimal vertices instead of mverts */
662
 
                        map.dg= dg;
663
 
                        map.bone= bone;
664
 
                        if(dm->foreachMappedVert) 
665
 
                                dm->foreachMappedVert(dm, pose_adds_vgroups__mapFunc, (void*) &map);
666
 
                        else {
667
 
                                Mesh *me= meshobj->data;
668
 
                                int i;
669
 
                                for(i=0; i<me->totvert; i++) 
670
 
                                        pose_adds_vgroups__mapFunc(&map, i, (me->mvert+i)->co, NULL, NULL);
671
 
                        }
672
 
                        
 
653
                if(arm->layer & pchan->bone->layer) {
 
654
                        if(bone->flag & (BONE_SELECTED)) {
 
655
                                
 
656
                                /* check if mesh has vgroups */
 
657
                                dg= get_named_vertexgroup(meshobj, bone->name);
 
658
                                if(dg==NULL)
 
659
                                        dg= add_defgroup_name(meshobj, bone->name);
 
660
                                
 
661
                                /* flipped bone */
 
662
                                if(Gwp.flag & VP_MIRROR_X) {
 
663
                                        char name[32];
 
664
                                        
 
665
                                        BLI_strncpy(name, dg->name, 32);
 
666
                                        bone_flip_name(name, 0);                // 0 = don't strip off number extensions
 
667
                                        
 
668
                                        for (curdef = meshobj->defbase.first; curdef; curdef=curdef->next)
 
669
                                                if (!strcmp(curdef->name, name))
 
670
                                                        break;
 
671
                                        map.dgflip= curdef;
 
672
                                }
 
673
                                else map.dgflip= NULL;
 
674
                                
 
675
                                /* get the root of the bone in global coords */
 
676
                                VECCOPY(map.head, bone->arm_head);
 
677
                                Mat4MulVecfl(poseobj->obmat, map.head);
 
678
                                
 
679
                                /* get the tip of the bone in global coords */
 
680
                                VECCOPY(map.tail, bone->arm_tail);
 
681
                                Mat4MulVecfl(poseobj->obmat, map.tail);
 
682
                                
 
683
                                /* use the optimal vertices instead of mverts */
 
684
                                map.dg= dg;
 
685
                                map.bone= bone;
 
686
                                if(dm->foreachMappedVert) 
 
687
                                        dm->foreachMappedVert(dm, pose_adds_vgroups__mapFunc, (void*) &map);
 
688
                                else {
 
689
                                        Mesh *me= meshobj->data;
 
690
                                        int i;
 
691
                                        for(i=0; i<me->totvert; i++) 
 
692
                                                pose_adds_vgroups__mapFunc(&map, i, (me->mvert+i)->co, NULL, NULL);
 
693
                                }
 
694
                                
 
695
                        }
673
696
                }
674
697
        }
675
698
        
688
711
void pose_flip_names(void)
689
712
{
690
713
        Object *ob= OBACT;
 
714
        bArmature *arm= ob->data;
691
715
        bPoseChannel *pchan;
692
716
        char newname[32];
693
717
        
696
720
        if(ob==G.obedit || (ob->flag & OB_POSEMODE)==0) return;
697
721
        
698
722
        for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
699
 
                if(pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) {
700
 
                        BLI_strncpy(newname, pchan->name, sizeof(newname));
701
 
                        bone_flip_name(newname, 1);     // 1 = do strip off number extensions
702
 
                        armature_bone_rename(ob->data, pchan->name, newname);
 
723
                if(arm->layer & pchan->bone->layer) {
 
724
                        if(pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) {
 
725
                                BLI_strncpy(newname, pchan->name, sizeof(newname));
 
726
                                bone_flip_name(newname, 1);     // 1 = do strip off number extensions
 
727
                                armature_bone_rename(ob->data, pchan->name, newname);
 
728
                        }
703
729
                }
704
730
        }
705
731
        
716
742
void pose_activate_flipped_bone(void)
717
743
{
718
744
        Object *ob= OBACT;
 
745
        bArmature *arm= ob->data;
719
746
        
720
747
        if(ob==NULL) return;
721
748
 
726
753
                bPoseChannel *pchan, *pchanf;
727
754
                
728
755
                for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
729
 
                        if(pchan->bone->flag & BONE_ACTIVE) {
730
 
                                break;
 
756
                        if(arm->layer & pchan->bone->layer) {
 
757
                                if(pchan->bone->flag & BONE_ACTIVE)
 
758
                                        break;
731
759
                        }
732
760
                }
733
761
                if(pchan) {
760
788
        }
761
789
}
762
790
 
 
791
 
 
792
void pose_movetolayer(void)
 
793
{
 
794
        Object *ob= OBACT;
 
795
        bArmature *arm;
 
796
        short lay= 0;
 
797
        
 
798
        if(ob==NULL) return;
 
799
        arm= ob->data;
 
800
        
 
801
        if(ob->flag & OB_POSEMODE) {
 
802
                bPoseChannel *pchan;
 
803
                
 
804
                for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
 
805
                        if(arm->layer & pchan->bone->layer) {
 
806
                                if(pchan->bone->flag & BONE_SELECTED)
 
807
                                        lay |= pchan->bone->layer;
 
808
                        }
 
809
                }
 
810
                if(lay==0) return;
 
811
                
 
812
                if( movetolayer_short_buts(&lay)==0 ) return;
 
813
                if(lay==0) return;
 
814
 
 
815
                for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
 
816
                        if(arm->layer & pchan->bone->layer) {
 
817
                                if(pchan->bone->flag & BONE_SELECTED)
 
818
                                        pchan->bone->layer= lay;
 
819
                        }
 
820
                }
 
821
                
 
822
                allqueue(REDRAWVIEW3D, 0);
 
823
                allqueue(REDRAWACTION, 0);
 
824
                allqueue(REDRAWBUTSEDIT, 0);
 
825
        }
 
826
}