2
* $Id: drawarmature.c 16902 2008-10-03 19:34:49Z blendix $
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) 2005 by the Blender Foundation.
21
* All rights reserved.
23
* The Original Code is: all of this file.
25
* Contributor(s): none yet.
27
* ***** END GPL LICENSE BLOCK *****
38
#include "MEM_guardedalloc.h"
42
#include "DNA_action_types.h"
43
#include "DNA_armature_types.h"
44
#include "DNA_constraint_types.h"
46
#include "DNA_nla_types.h"
47
#include "DNA_object_types.h"
48
#include "DNA_scene_types.h"
49
#include "DNA_screen_types.h"
50
#include "DNA_space_types.h"
51
#include "DNA_view3d_types.h"
52
#include "DNA_userdef_types.h"
54
#include "BLI_blenlib.h"
55
#include "BLI_arithb.h"
57
#include "BKE_action.h"
58
#include "BKE_armature.h"
59
#include "BKE_constraint.h"
60
#include "BKE_depsgraph.h"
61
#include "BKE_DerivedMesh.h"
62
#include "BKE_global.h"
64
#include "BKE_object.h"
66
#include "BKE_utildefines.h"
68
#include "BIF_editaction.h"
69
#include "BIF_editarmature.h"
71
#include "BIF_glutil.h"
72
#include "BIF_graphics.h"
73
#include "BIF_interface.h"
74
#include "BIF_poseobject.h"
75
#include "BIF_mywindow.h"
76
#include "BIF_resources.h"
77
#include "BIF_screen.h"
79
#include "BDR_editobject.h"
80
#include "BDR_drawobject.h"
81
#include "BDR_drawaction.h"
91
/* *************** Armature Drawing - Coloring API ***************************** */
93
/* global here is reset before drawing each bone */
94
static ThemeWireColor *bcolor= NULL;
96
/* values of colCode for set_pchan_glcolor */
98
PCHAN_COLOR_NORMAL = 0, /* normal drawing */
99
PCHAN_COLOR_SOLID, /* specific case where "solid" color is needed */
100
PCHAN_COLOR_CONSTS, /* "constraint" colors (which may/may-not be suppressed) */
102
PCHAN_COLOR_SPHEREBONE_BASE, /* for the 'stick' of sphere (envelope) bones */
103
PCHAN_COLOR_SPHEREBONE_END, /* for the ends of sphere (envelope) bones */
104
PCHAN_COLOR_LINEBONE /* for the middle of line-bones */
107
/* This function sets the color-set for coloring a certain bone */
108
static void set_pchan_colorset (Object *ob, bPoseChannel *pchan)
110
bPose *pose= (ob) ? ob->pose : NULL;
111
bArmature *arm= (ob) ? ob->data : NULL;
112
bActionGroup *grp= NULL;
113
short color_index= 0;
116
if (ELEM4(NULL, ob, arm, pose, pchan)) {
121
/* only try to set custom color if enabled for armature */
122
if (arm->flag & ARM_COL_CUSTOM) {
123
/* currently, a bone can only use a custom color set if it's group (if it has one),
124
* has been set to use one
126
if (pchan->agrp_index) {
127
grp= (bActionGroup *)BLI_findlink(&pose->agroups, (pchan->agrp_index - 1));
129
color_index= grp->customCol;
133
/* bcolor is a pointer to the color set to use. If NULL, then the default
134
* color set (based on the theme colors for 3d-view) is used.
136
if (color_index > 0) {
137
bTheme *btheme= U.themes.first;
138
bcolor= &btheme->tarm[(color_index - 1)];
140
else if (color_index == -1) {
141
/* use the group's own custom color set */
142
bcolor= (grp)? &grp->cs : NULL;
148
/* This function is for brightening/darkening a given color (like BIF_ThemeColorShade()) */
149
static void cp_shade_color3ub (char cp[], int offset)
153
r= offset + (int) cp[0];
155
g= offset + (int) cp[1];
157
b= offset + (int) cp[2];
165
/* This function sets the gl-color for coloring a certain bone (based on bcolor) */
166
static short set_pchan_glColor (short colCode, int armflag, int boneflag, int constflag)
169
case PCHAN_COLOR_NORMAL:
174
if (boneflag & BONE_ACTIVE) {
175
VECCOPY(cp, bcolor->active);
177
else if (boneflag & BONE_SELECTED) {
178
VECCOPY(cp, bcolor->select);
181
/* a bit darker than solid */
182
VECCOPY(cp, bcolor->solid);
183
cp_shade_color3ub(cp, -50);
186
glColor3ub(cp[0], cp[1], cp[2]);
189
if (boneflag & BONE_ACTIVE) BIF_ThemeColorShade(TH_BONE_POSE, 40);
190
else if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_BONE_POSE);
191
else BIF_ThemeColor(TH_WIRE);
198
case PCHAN_COLOR_SOLID:
201
char *cp= bcolor->solid;
202
glColor3ub(cp[0], cp[1], cp[2]);
205
BIF_ThemeColor(TH_BONE_SOLID);
211
case PCHAN_COLOR_CONSTS:
213
if ( (bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS) ) {
214
if (constflag & PCHAN_HAS_STRIDE) glColor4ub(0, 0, 200, 80);
215
else if (constflag & PCHAN_HAS_TARGET) glColor4ub(255, 150, 0, 80);
216
else if (constflag & PCHAN_HAS_IK) glColor4ub(255, 255, 0, 80);
217
else if (constflag & PCHAN_HAS_CONST) glColor4ub(0, 255, 120, 80);
218
else if (constflag) BIF_ThemeColor4(TH_BONE_POSE); // PCHAN_HAS_ACTION
227
case PCHAN_COLOR_SPHEREBONE_BASE:
232
if (boneflag & BONE_ACTIVE) {
233
VECCOPY(cp, bcolor->active);
235
else if (boneflag & BONE_SELECTED) {
236
VECCOPY(cp, bcolor->select);
239
VECCOPY(cp, bcolor->solid);
242
glColor3ub(cp[0], cp[1], cp[2]);
245
if (boneflag & BONE_ACTIVE) BIF_ThemeColorShade(TH_BONE_POSE, 40);
246
else if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_BONE_POSE);
247
else BIF_ThemeColor(TH_BONE_SOLID);
253
case PCHAN_COLOR_SPHEREBONE_END:
258
if (boneflag & BONE_ACTIVE) {
259
VECCOPY(cp, bcolor->active);
260
cp_shade_color3ub(cp, 10);
262
else if (boneflag & BONE_SELECTED) {
263
VECCOPY(cp, bcolor->select);
264
cp_shade_color3ub(cp, -30);
267
VECCOPY(cp, bcolor->solid);
268
cp_shade_color3ub(cp, -30);
271
glColor3ub(cp[0], cp[1], cp[2]);
274
if (boneflag & BONE_ACTIVE) BIF_ThemeColorShade(TH_BONE_POSE, 10);
275
else if (boneflag & BONE_SELECTED) BIF_ThemeColorShade(TH_BONE_POSE, -30);
276
else BIF_ThemeColorShade(TH_BONE_SOLID, -30);
281
case PCHAN_COLOR_LINEBONE:
283
/* inner part in background color or constraint */
284
if ( (constflag) && ((bcolor==NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS)) ) {
285
if (constflag & PCHAN_HAS_STRIDE) glColor3ub(0, 0, 200);
286
else if (constflag & PCHAN_HAS_TARGET) glColor3ub(255, 150, 0);
287
else if (constflag & PCHAN_HAS_IK) glColor3ub(255, 255, 0);
288
else if (constflag & PCHAN_HAS_CONST) glColor3ub(0, 255, 120);
289
else if (constflag) BIF_ThemeColor(TH_BONE_POSE); /* PCHAN_HAS_ACTION */
293
char *cp= bcolor->solid;
294
glColor4ub(cp[0], cp[1], cp[2], 0.8);
297
BIF_ThemeColorShade(TH_BACK, -30);
309
/* *************** Armature drawing, helper calls for parts ******************* */
311
/* half the cube, in Y */
312
static float cube[8][3] = {
323
static void drawsolidcube_size(float xsize, float ysize, float zsize)
325
static GLuint displist=0;
328
glScalef(xsize, ysize, zsize);
330
n[0]=0; n[1]=0; n[2]=0;
333
displist= glGenLists(1);
334
glNewList(displist, GL_COMPILE_AND_EXECUTE);
339
glVertex3fv(cube[0]); glVertex3fv(cube[1]); glVertex3fv(cube[2]); glVertex3fv(cube[3]);
343
glVertex3fv(cube[0]); glVertex3fv(cube[4]); glVertex3fv(cube[5]); glVertex3fv(cube[1]);
347
glVertex3fv(cube[4]); glVertex3fv(cube[7]); glVertex3fv(cube[6]); glVertex3fv(cube[5]);
351
glVertex3fv(cube[7]); glVertex3fv(cube[3]); glVertex3fv(cube[2]); glVertex3fv(cube[6]);
355
glVertex3fv(cube[1]); glVertex3fv(cube[5]); glVertex3fv(cube[6]); glVertex3fv(cube[2]);
359
glVertex3fv(cube[7]); glVertex3fv(cube[4]); glVertex3fv(cube[0]); glVertex3fv(cube[3]);
364
else glCallList(displist);
368
static void drawcube_size(float xsize, float ysize, float zsize)
370
static GLuint displist=0;
372
glScalef(xsize, ysize, zsize);
375
displist= glGenLists(1);
376
glNewList(displist, GL_COMPILE_AND_EXECUTE);
378
glBegin(GL_LINE_STRIP);
379
glVertex3fv(cube[0]); glVertex3fv(cube[1]);glVertex3fv(cube[2]); glVertex3fv(cube[3]);
380
glVertex3fv(cube[0]); glVertex3fv(cube[4]);glVertex3fv(cube[5]); glVertex3fv(cube[6]);
381
glVertex3fv(cube[7]); glVertex3fv(cube[4]);
385
glVertex3fv(cube[1]); glVertex3fv(cube[5]);
386
glVertex3fv(cube[2]); glVertex3fv(cube[6]);
387
glVertex3fv(cube[3]); glVertex3fv(cube[7]);
392
else glCallList(displist);
397
static void draw_bonevert(void)
399
static GLuint displist=0;
404
displist= glGenLists(1);
405
glNewList(displist, GL_COMPILE_AND_EXECUTE);
409
qobj = gluNewQuadric();
410
gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
411
gluDisk(qobj, 0.0, 0.05, 16, 1);
413
glRotatef(90, 0, 1, 0);
414
gluDisk(qobj, 0.0, 0.05, 16, 1);
416
glRotatef(90, 1, 0, 0);
417
gluDisk(qobj, 0.0, 0.05, 16, 1);
419
gluDeleteQuadric(qobj);
425
glCallList(displist);
428
static void draw_bonevert_solid(void)
430
static GLuint displist=0;
435
displist= glGenLists(1);
436
glNewList(displist, GL_COMPILE_AND_EXECUTE);
438
qobj = gluNewQuadric();
439
gluQuadricDrawStyle(qobj, GLU_FILL);
440
glShadeModel(GL_SMOOTH);
441
gluSphere( qobj, 0.05, 8, 5);
442
glShadeModel(GL_FLAT);
443
gluDeleteQuadric(qobj);
448
glCallList(displist);
451
static void draw_bone_octahedral()
453
static GLuint displist=0;
458
displist= glGenLists(1);
459
glNewList(displist, GL_COMPILE_AND_EXECUTE);
461
vec[0][0]= vec[0][1]= vec[0][2]= 0.0;
462
vec[5][0]= vec[5][2]= 0.0; vec[5][1]= 1.0;
464
vec[1][0]= 0.1; vec[1][2]= 0.1; vec[1][1]= 0.1;
465
vec[2][0]= 0.1; vec[2][2]= -0.1; vec[2][1]= 0.1;
466
vec[3][0]= -0.1; vec[3][2]= -0.1; vec[3][1]= 0.1;
467
vec[4][0]= -0.1; vec[4][2]= 0.1; vec[4][1]= 0.1;
469
/* Section 1, sides */
470
glBegin(GL_LINE_LOOP);
481
/* Section 1, square */
482
glBegin(GL_LINE_LOOP);
492
glCallList(displist);
495
static void draw_bone_solid_octahedral(void)
497
static GLuint displist=0;
500
float vec[6][3], nor[3];
502
displist= glGenLists(1);
503
glNewList(displist, GL_COMPILE_AND_EXECUTE);
505
vec[0][0]= vec[0][1]= vec[0][2]= 0.0;
506
vec[5][0]= vec[5][2]= 0.0; vec[5][1]= 1.0;
508
vec[1][0]= 0.1; vec[1][2]= 0.1; vec[1][1]= 0.1;
509
vec[2][0]= 0.1; vec[2][2]= -0.1; vec[2][1]= 0.1;
510
vec[3][0]= -0.1; vec[3][2]= -0.1; vec[3][1]= 0.1;
511
vec[4][0]= -0.1; vec[4][2]= 0.1; vec[4][1]= 0.1;
514
glBegin(GL_TRIANGLES);
516
CalcNormFloat(vec[2], vec[1], vec[0], nor);
518
glVertex3fv(vec[2]);glVertex3fv(vec[1]);glVertex3fv(vec[0]);
520
CalcNormFloat(vec[3], vec[2], vec[0], nor);
522
glVertex3fv(vec[3]);glVertex3fv(vec[2]);glVertex3fv(vec[0]);
524
CalcNormFloat(vec[4], vec[3], vec[0], nor);
526
glVertex3fv(vec[4]);glVertex3fv(vec[3]);glVertex3fv(vec[0]);
528
CalcNormFloat(vec[1], vec[4], vec[0], nor);
530
glVertex3fv(vec[1]);glVertex3fv(vec[4]);glVertex3fv(vec[0]);
533
CalcNormFloat(vec[5], vec[1], vec[2], nor);
535
glVertex3fv(vec[5]);glVertex3fv(vec[1]);glVertex3fv(vec[2]);
537
CalcNormFloat(vec[5], vec[2], vec[3], nor);
539
glVertex3fv(vec[5]);glVertex3fv(vec[2]);glVertex3fv(vec[3]);
541
CalcNormFloat(vec[5], vec[3], vec[4], nor);
543
glVertex3fv(vec[5]);glVertex3fv(vec[3]);glVertex3fv(vec[4]);
545
CalcNormFloat(vec[5], vec[4], vec[1], nor);
547
glVertex3fv(vec[5]);glVertex3fv(vec[4]);glVertex3fv(vec[1]);
554
glCallList(displist);
557
/* *************** Armature drawing, bones ******************* */
560
static void draw_bone_points(int dt, int armflag, unsigned int boneflag, int id)
562
/* Draw root point if we are not connected */
563
if ((boneflag & BONE_CONNECTED)==0) {
565
glLoadName(id | BONESEL_ROOT);
568
if (armflag & ARM_EDITMODE) {
569
if (boneflag & BONE_ROOTSEL) BIF_ThemeColor(TH_VERTEX_SELECT);
570
else BIF_ThemeColor(TH_VERTEX);
574
if (armflag & ARM_POSEMODE)
575
set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, 0);
577
BIF_ThemeColor(TH_BONE_SOLID);
581
draw_bonevert_solid();
588
glLoadName(id | BONESEL_TIP);
591
if (armflag & ARM_EDITMODE) {
592
if (boneflag & BONE_TIPSEL) BIF_ThemeColor(TH_VERTEX_SELECT);
593
else BIF_ThemeColor(TH_VERTEX);
597
if (armflag & ARM_POSEMODE)
598
set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, 0);
600
BIF_ThemeColor(TH_BONE_SOLID);
603
glTranslatef(0.0, 1.0, 0.0);
605
draw_bonevert_solid();
608
glTranslatef(0.0, -1.0, 0.0);
612
/* 16 values of sin function (still same result!) */
613
static float si[16] = {
615
0.20129852, 0.39435585,
616
0.57126821, 0.72479278,
617
0.84864425, 0.93775213,
618
0.98846832, 0.99871650,
619
0.96807711, 0.89780453,
620
0.79077573, 0.65137248,
621
0.48530196, 0.29936312,
624
/* 16 values of cos function (still same result!) */
625
static float co[16] ={
627
0.97952994, 0.91895781,
628
0.82076344, 0.68896691,
629
0.52896401, 0.34730525,
630
0.15142777, -0.05064916,
631
-0.25065253, -0.44039415,
632
-0.61210598, -0.75875812,
633
-0.87434661, -0.95413925,
639
/* smat, imat = mat & imat to draw screenaligned */
640
static void draw_sphere_bone_dist(float smat[][4], float imat[][4], int boneflag, bPoseChannel *pchan, EditBone *ebone)
642
float head, tail, length, dist;
643
float *headvec, *tailvec, dirvec[3];
645
/* figure out the sizes of spheres */
647
/* this routine doesn't call set_matrix_editbone() that calculates it */
648
ebone->length = VecLenf(ebone->head, ebone->tail);
650
length= ebone->length;
651
tail= ebone->rad_tail;
653
if (ebone->parent && (ebone->flag & BONE_CONNECTED))
654
head= ebone->parent->rad_tail;
656
head= ebone->rad_head;
657
headvec= ebone->head;
658
tailvec= ebone->tail;
661
length= pchan->bone->length;
662
tail= pchan->bone->rad_tail;
663
dist= pchan->bone->dist;
664
if (pchan->parent && (pchan->bone->flag & BONE_CONNECTED))
665
head= pchan->parent->bone->rad_tail;
667
head= pchan->bone->rad_head;
668
headvec= pchan->pose_head;
669
tailvec= pchan->pose_tail;
672
/* ***** draw it ***** */
674
/* move vector to viewspace */
675
VecSubf(dirvec, tailvec, headvec);
676
Mat4Mul3Vecfl(smat, dirvec);
679
/* move vector back */
680
Mat4Mul3Vecfl(imat, dirvec);
682
if (0.0f != Normalize(dirvec)) {
683
float norvec[3], vec1[3], vec2[3], vec[3];
686
//VecMulf(dirvec, head);
687
Crossf(norvec, dirvec, imat[2]);
689
glBegin(GL_QUAD_STRIP);
691
for (a=0; a<16; a++) {
692
vec[0]= - *(si+a) * dirvec[0] + *(co+a) * norvec[0];
693
vec[1]= - *(si+a) * dirvec[1] + *(co+a) * norvec[1];
694
vec[2]= - *(si+a) * dirvec[2] + *(co+a) * norvec[2];
696
vec1[0]= headvec[0] + head*vec[0];
697
vec1[1]= headvec[1] + head*vec[1];
698
vec1[2]= headvec[2] + head*vec[2];
699
vec2[0]= headvec[0] + (head+dist)*vec[0];
700
vec2[1]= headvec[1] + (head+dist)*vec[1];
701
vec2[2]= headvec[2] + (head+dist)*vec[2];
703
glColor4ub(255, 255, 255, 50);
705
//glColor4ub(255, 255, 255, 0);
709
for (a=15; a>=0; a--) {
710
vec[0]= *(si+a) * dirvec[0] + *(co+a) * norvec[0];
711
vec[1]= *(si+a) * dirvec[1] + *(co+a) * norvec[1];
712
vec[2]= *(si+a) * dirvec[2] + *(co+a) * norvec[2];
714
vec1[0]= tailvec[0] + tail*vec[0];
715
vec1[1]= tailvec[1] + tail*vec[1];
716
vec1[2]= tailvec[2] + tail*vec[2];
717
vec2[0]= tailvec[0] + (tail+dist)*vec[0];
718
vec2[1]= tailvec[1] + (tail+dist)*vec[1];
719
vec2[2]= tailvec[2] + (tail+dist)*vec[2];
721
//glColor4ub(255, 255, 255, 50);
723
//glColor4ub(255, 255, 255, 0);
726
/* make it cyclic... */
728
vec[0]= - *(si) * dirvec[0] + *(co) * norvec[0];
729
vec[1]= - *(si) * dirvec[1] + *(co) * norvec[1];
730
vec[2]= - *(si) * dirvec[2] + *(co) * norvec[2];
732
vec1[0]= headvec[0] + head*vec[0];
733
vec1[1]= headvec[1] + head*vec[1];
734
vec1[2]= headvec[2] + head*vec[2];
735
vec2[0]= headvec[0] + (head+dist)*vec[0];
736
vec2[1]= headvec[1] + (head+dist)*vec[1];
737
vec2[2]= headvec[2] + (head+dist)*vec[2];
739
//glColor4ub(255, 255, 255, 50);
741
//glColor4ub(255, 255, 255, 0);
749
/* smat, imat = mat & imat to draw screenaligned */
750
static void draw_sphere_bone_wire(float smat[][4], float imat[][4], int armflag, int boneflag, int constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
752
float head, tail, length;
753
float *headvec, *tailvec, dirvec[3];
755
/* figure out the sizes of spheres */
757
/* this routine doesn't call set_matrix_editbone() that calculates it */
758
ebone->length = VecLenf(ebone->head, ebone->tail);
760
length= ebone->length;
761
tail= ebone->rad_tail;
762
if (ebone->parent && (boneflag & BONE_CONNECTED))
763
head= ebone->parent->rad_tail;
765
head= ebone->rad_head;
766
headvec= ebone->head;
767
tailvec= ebone->tail;
770
length= pchan->bone->length;
771
tail= pchan->bone->rad_tail;
772
if ((pchan->parent) && (boneflag & BONE_CONNECTED))
773
head= pchan->parent->bone->rad_tail;
775
head= pchan->bone->rad_head;
776
headvec= pchan->pose_head;
777
tailvec= pchan->pose_tail;
780
/* sphere root color */
781
if (armflag & ARM_EDITMODE) {
782
if (boneflag & BONE_ROOTSEL) BIF_ThemeColor(TH_VERTEX_SELECT);
783
else BIF_ThemeColor(TH_VERTEX);
785
else if (armflag & ARM_POSEMODE)
786
set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
788
/* Draw root point if we are not connected */
789
if ((boneflag & BONE_CONNECTED)==0) {
791
glLoadName(id | BONESEL_ROOT);
793
drawcircball(GL_LINE_LOOP, headvec, head, imat);
797
if (armflag & ARM_EDITMODE) {
798
if (boneflag & BONE_TIPSEL) BIF_ThemeColor(TH_VERTEX_SELECT);
799
else BIF_ThemeColor(TH_VERTEX);
803
glLoadName(id | BONESEL_TIP);
805
drawcircball(GL_LINE_LOOP, tailvec, tail, imat);
808
if (armflag & ARM_EDITMODE) {
809
if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_SELECT);
810
else BIF_ThemeColor(TH_WIRE);
813
VecSubf(dirvec, tailvec, headvec);
815
/* move vector to viewspace */
816
Mat4Mul3Vecfl(smat, dirvec);
819
/* move vector back */
820
Mat4Mul3Vecfl(imat, dirvec);
822
if (0.0f != Normalize(dirvec)) {
823
float norvech[3], norvect[3], vec[3];
825
VECCOPY(vec, dirvec);
827
VecMulf(dirvec, head);
828
Crossf(norvech, dirvec, imat[2]);
831
Crossf(norvect, vec, imat[2]);
834
glLoadName(id | BONESEL_BONE);
837
vec[0]= headvec[0] + norvech[0];
838
vec[1]= headvec[1] + norvech[1];
839
vec[2]= headvec[2] + norvech[2];
841
vec[0]= tailvec[0] + norvect[0];
842
vec[1]= tailvec[1] + norvect[1];
843
vec[2]= tailvec[2] + norvect[2];
845
vec[0]= headvec[0] - norvech[0];
846
vec[1]= headvec[1] - norvech[1];
847
vec[2]= headvec[2] - norvech[2];
849
vec[0]= tailvec[0] - norvect[0];
850
vec[1]= tailvec[1] - norvect[1];
851
vec[2]= tailvec[2] - norvect[2];
858
/* does wire only for outline selecting */
859
static void draw_sphere_bone(int dt, int armflag, int boneflag, int constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
862
float head, tail, length;
866
qobj = gluNewQuadric();
868
/* figure out the sizes of spheres */
870
length= ebone->length;
871
tail= ebone->rad_tail;
872
if (ebone->parent && (boneflag & BONE_CONNECTED))
873
head= ebone->parent->rad_tail;
875
head= ebone->rad_head;
878
length= pchan->bone->length;
879
tail= pchan->bone->rad_tail;
880
if (pchan->parent && (boneflag & BONE_CONNECTED))
881
head= pchan->parent->bone->rad_tail;
883
head= pchan->bone->rad_head;
886
/* move to z-axis space */
887
glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
890
/* set up solid drawing */
891
glEnable(GL_COLOR_MATERIAL);
892
glEnable(GL_LIGHTING);
894
gluQuadricDrawStyle(qobj, GLU_FILL);
895
glShadeModel(GL_SMOOTH);
898
gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
901
/* sphere root color */
902
if (armflag & ARM_EDITMODE) {
903
if (boneflag & BONE_ROOTSEL) BIF_ThemeColor(TH_VERTEX_SELECT);
904
else BIF_ThemeColorShade(TH_BONE_SOLID, -30);
906
else if (armflag & ARM_POSEMODE)
907
set_pchan_glColor(PCHAN_COLOR_SPHEREBONE_END, armflag, boneflag, constflag);
908
else if (dt==OB_SOLID)
909
BIF_ThemeColorShade(TH_BONE_SOLID, -30);
911
/* Draw root point if we are not connected */
912
if ((boneflag & BONE_CONNECTED)==0) {
914
glLoadName(id | BONESEL_ROOT);
915
gluSphere(qobj, head, 16, 10);
919
if (armflag & ARM_EDITMODE) {
920
if (boneflag & BONE_TIPSEL) BIF_ThemeColor(TH_VERTEX_SELECT);
921
else BIF_ThemeColorShade(TH_BONE_SOLID, -30);
925
glLoadName(id | BONESEL_TIP);
927
glTranslatef(0.0, 0.0, length);
928
gluSphere(qobj, tail, 16, 10);
929
glTranslatef(0.0, 0.0, -length);
932
if (armflag & ARM_EDITMODE) {
933
if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_SELECT);
934
else BIF_ThemeColor(TH_BONE_SOLID);
936
else if (armflag & ARM_POSEMODE)
937
set_pchan_glColor(PCHAN_COLOR_SPHEREBONE_BASE, armflag, boneflag, constflag);
938
else if (dt == OB_SOLID)
939
BIF_ThemeColor(TH_BONE_SOLID);
941
fac1= (length-head)/length;
942
fac2= (length-tail)/length;
944
if (length > (head+tail)) {
946
glLoadName (id | BONESEL_BONE);
948
glEnable(GL_POLYGON_OFFSET_FILL);
949
glPolygonOffset(-1.0, -1.0);
951
glTranslatef(0.0f, 0.0f, head);
952
gluCylinder(qobj, fac1*head + (1.0f-fac1)*tail, fac2*tail + (1.0f-fac2)*head, length-head-tail, 16, 1);
953
glTranslatef(0.0f, 0.0f, -head);
955
glDisable(GL_POLYGON_OFFSET_FILL);
957
/* draw sphere on extrema */
958
glTranslatef(0.0f, 0.0f, length-tail);
959
gluSphere(qobj, fac2*tail + (1.0f-fac2)*head, 16, 10);
960
glTranslatef(0.0f, 0.0f, -length+tail);
962
glTranslatef(0.0f, 0.0f, head);
963
gluSphere(qobj, fac1*head + (1.0f-fac1)*tail, 16, 10);
966
/* 1 sphere in center */
967
glTranslatef(0.0f, 0.0f, (head + length-tail)/2.0);
968
gluSphere(qobj, fac1*head + (1.0f-fac1)*tail, 16, 10);
973
glShadeModel(GL_FLAT);
974
glDisable(GL_LIGHTING);
975
glDisable(GL_COLOR_MATERIAL);
979
gluDeleteQuadric(qobj);
982
static GLubyte bm_dot6[]= {0x0, 0x18, 0x3C, 0x7E, 0x7E, 0x3C, 0x18, 0x0};
983
static GLubyte bm_dot8[]= {0x3C, 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C};
985
static GLubyte bm_dot5[]= {0x0, 0x0, 0x10, 0x38, 0x7c, 0x38, 0x10, 0x0};
986
static GLubyte bm_dot7[]= {0x0, 0x38, 0x7C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38};
989
static void draw_line_bone(int armflag, int boneflag, int constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
993
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
996
length= pchan->bone->length;
998
length= ebone->length;
1001
glScalef(length, length, length);
1003
/* this chunk not in object mode */
1004
if (armflag & (ARM_EDITMODE|ARM_POSEMODE)) {
1006
if (armflag & ARM_POSEMODE)
1007
set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
1008
else if (armflag & ARM_EDITMODE) {
1009
BIF_ThemeColor(TH_WIRE);
1012
/* Draw root point if we are not connected */
1013
if ((boneflag & BONE_CONNECTED)==0) {
1014
if (G.f & G_PICKSEL) { // no bitmap in selection mode, crashes 3d cards...
1015
glLoadName (id | BONESEL_ROOT);
1017
glVertex3f(0.0f, 0.0f, 0.0f);
1021
glRasterPos3f(0.0f, 0.0f, 0.0f);
1022
glBitmap(8, 8, 4, 4, 0, 0, bm_dot8);
1027
glLoadName((GLuint) id|BONESEL_BONE);
1030
glVertex3f(0.0f, 0.0f, 0.0f);
1031
glVertex3f(0.0f, 1.0f, 0.0f);
1035
if (G.f & G_PICKSEL) {
1036
/* no bitmap in selection mode, crashes 3d cards... */
1037
glLoadName(id | BONESEL_TIP);
1039
glVertex3f(0.0f, 1.0f, 0.0f);
1043
glRasterPos3f(0.0f, 1.0f, 0.0f);
1044
glBitmap(8, 8, 4, 4, 0, 0, bm_dot7);
1047
/* further we send no names */
1049
glLoadName(id & 0xFFFF); /* object tag, for bordersel optim */
1051
if (armflag & ARM_POSEMODE)
1052
set_pchan_glColor(PCHAN_COLOR_LINEBONE, armflag, boneflag, constflag);
1057
/*Draw root point if we are not connected */
1058
if ((boneflag & BONE_CONNECTED)==0) {
1059
if ((G.f & G_PICKSEL)==0) {
1060
/* no bitmap in selection mode, crashes 3d cards... */
1061
if (armflag & ARM_EDITMODE) {
1062
if (boneflag & BONE_ROOTSEL) BIF_ThemeColor(TH_VERTEX_SELECT);
1063
else BIF_ThemeColor(TH_VERTEX);
1065
glRasterPos3f(0.0f, 0.0f, 0.0f);
1066
glBitmap(8, 8, 4, 4, 0, 0, bm_dot6);
1070
if (armflag & ARM_EDITMODE) {
1071
if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_EDGE_SELECT);
1072
else BIF_ThemeColorShade(TH_BACK, -30);
1075
glVertex3f(0.0f, 0.0f, 0.0f);
1076
glVertex3f(0.0f, 1.0f, 0.0f);
1080
if ((G.f & G_PICKSEL)==0) {
1081
/* no bitmap in selection mode, crashes 3d cards... */
1082
if (armflag & ARM_EDITMODE) {
1083
if (boneflag & BONE_TIPSEL) BIF_ThemeColor(TH_VERTEX_SELECT);
1084
else BIF_ThemeColor(TH_VERTEX);
1086
glRasterPos3f(0.0f, 1.0f, 0.0f);
1087
glBitmap(8, 8, 4, 4, 0, 0, bm_dot5);
1095
static void draw_b_bone_boxes(int dt, bPoseChannel *pchan, float xwidth, float length, float zwidth)
1100
segments= pchan->bone->segments;
1102
if ((segments > 1) && (pchan)) {
1103
float dlen= length/(float)segments;
1104
Mat4 *bbone= b_bone_spline_setup(pchan, 0);
1107
for (a=0; a<segments; a++, bbone++) {
1109
glMultMatrixf(bbone->mat);
1110
if (dt==OB_SOLID) drawsolidcube_size(xwidth, dlen, zwidth);
1111
else drawcube_size(xwidth, dlen, zwidth);
1117
if (dt==OB_SOLID) drawsolidcube_size(xwidth, length, zwidth);
1118
else drawcube_size(xwidth, length, zwidth);
1123
static void draw_b_bone(int dt, int armflag, int boneflag, int constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
1125
float xwidth, length, zwidth;
1128
xwidth= pchan->bone->xwidth;
1129
length= pchan->bone->length;
1130
zwidth= pchan->bone->zwidth;
1133
xwidth= ebone->xwidth;
1134
length= ebone->length;
1135
zwidth= ebone->zwidth;
1138
/* draw points only if... */
1139
if (armflag & ARM_EDITMODE) {
1140
/* move to unitspace */
1142
glScalef(length, length, length);
1143
draw_bone_points(dt, armflag, boneflag, id);
1145
length*= 0.95f; // make vertices visible
1148
/* colors for modes */
1149
if (armflag & ARM_POSEMODE) {
1151
set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
1153
set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, constflag);
1155
else if (armflag & ARM_EDITMODE) {
1157
if (boneflag & BONE_ACTIVE) BIF_ThemeColor(TH_EDGE_SELECT);
1158
else if (boneflag & BONE_SELECTED) BIF_ThemeColorShade(TH_EDGE_SELECT, -20);
1159
else BIF_ThemeColor(TH_WIRE);
1162
BIF_ThemeColor(TH_BONE_SOLID);
1166
glLoadName ((GLuint) id|BONESEL_BONE);
1169
/* set up solid drawing */
1171
glEnable(GL_COLOR_MATERIAL);
1172
glEnable(GL_LIGHTING);
1174
if (armflag & ARM_POSEMODE)
1175
set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, constflag);
1177
BIF_ThemeColor(TH_BONE_SOLID);
1179
draw_b_bone_boxes(OB_SOLID, pchan, xwidth, length, zwidth);
1181
/* disable solid drawing */
1182
glDisable(GL_COLOR_MATERIAL);
1183
glDisable(GL_LIGHTING);
1187
if (armflag & ARM_POSEMODE) {
1189
/* set constraint colors */
1190
if (set_pchan_glColor(PCHAN_COLOR_CONSTS, armflag, boneflag, constflag)) {
1193
draw_b_bone_boxes(OB_SOLID, pchan, xwidth, length, zwidth);
1195
glDisable(GL_BLEND);
1198
/* restore colors */
1199
set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
1203
draw_b_bone_boxes(OB_WIRE, pchan, xwidth, length, zwidth);
1207
static void draw_bone(int dt, int armflag, int boneflag, int constflag, unsigned int id, float length)
1210
/* Draw a 3d octahedral bone, we use normalized space based on length,
1211
for glDisplayLists */
1213
glScalef(length, length, length);
1215
/* set up solid drawing */
1217
glEnable(GL_COLOR_MATERIAL);
1218
glEnable(GL_LIGHTING);
1219
BIF_ThemeColor(TH_BONE_SOLID);
1222
/* colors for posemode */
1223
if (armflag & ARM_POSEMODE) {
1225
set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
1227
set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, constflag);
1231
draw_bone_points(dt, armflag, boneflag, id);
1233
/* now draw the bone itself */
1235
glLoadName((GLuint) id|BONESEL_BONE);
1239
if (dt <= OB_WIRE) {
1241
if (armflag & ARM_EDITMODE) {
1242
if (boneflag & BONE_ACTIVE) BIF_ThemeColor(TH_EDGE_SELECT);
1243
else if (boneflag & BONE_SELECTED) BIF_ThemeColorShade(TH_EDGE_SELECT, -20);
1244
else BIF_ThemeColor(TH_WIRE);
1246
else if (armflag & ARM_POSEMODE) {
1248
/* draw constraint colors */
1249
if (set_pchan_glColor(PCHAN_COLOR_CONSTS, armflag, boneflag, constflag)) {
1252
draw_bone_solid_octahedral();
1254
glDisable(GL_BLEND);
1257
/* restore colors */
1258
set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
1261
draw_bone_octahedral();
1265
if (armflag & ARM_POSEMODE)
1266
set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, constflag);
1268
BIF_ThemeColor(TH_BONE_SOLID);
1269
draw_bone_solid_octahedral();
1272
/* disable solid drawing */
1274
glDisable(GL_COLOR_MATERIAL);
1275
glDisable(GL_LIGHTING);
1279
static void draw_custom_bone(Object *ob, int dt, int armflag, int boneflag, unsigned int id, float length)
1281
if(ob==NULL) return;
1283
glScalef(length, length, length);
1285
/* colors for posemode */
1286
if (armflag & ARM_POSEMODE) {
1287
set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, 0);
1291
glLoadName((GLuint) id|BONESEL_BONE);
1294
draw_object_instance(ob, dt, armflag & ARM_POSEMODE);
1298
static void pchan_draw_IK_root_lines(bPoseChannel *pchan, short only_temp)
1301
bPoseChannel *parchan;
1303
for (con= pchan->constraints.first; con; con= con->next) {
1304
if (con->type == CONSTRAINT_TYPE_KINEMATIC && (con->enforce!=0.0)) {
1305
bKinematicConstraint *data = (bKinematicConstraint*)con->data;
1308
/* if only_temp, only draw if it is a temporary ik-chain */
1309
if ((only_temp) && !(data->flag & CONSTRAINT_IK_TEMP))
1315
/* exclude tip from chain? */
1316
if ((data->flag & CONSTRAINT_IK_TIP)==0)
1317
parchan= pchan->parent;
1321
glVertex3fv(parchan->pose_tail);
1323
/* Find the chain's root */
1324
while (parchan->parent) {
1326
if(segcount==data->rootbone || segcount>255) break; // 255 is weak
1327
parchan= parchan->parent;
1330
glVertex3fv(parchan->pose_head);
1338
static void bgl_sphere_project(float ax, float az)
1340
float dir[3], sine, q3;
1342
sine= 1.0f-ax*ax-az*az;
1343
q3= (sine < 0.0f)? 0.0f: 2.0f*sqrt(sine);
1346
dir[1]= 1.0f-2.0f*sine;
1352
static void draw_dof_ellipse(float ax, float az)
1354
static float staticSine[16] = {
1355
0.0, 0.104528463268, 0.207911690818, 0.309016994375,
1356
0.406736643076, 0.5, 0.587785252292, 0.669130606359,
1357
0.743144825477, 0.809016994375, 0.866025403784,
1358
0.913545457643, 0.951056516295, 0.978147600734,
1368
glColor4ub(70, 70, 70, 50);
1372
for(i=1; i<n; i++) {
1376
for(j=1; j<n-i+1; j++) {
1381
glBegin(GL_TRIANGLES);
1382
bgl_sphere_project(ax*px, az*z);
1383
bgl_sphere_project(ax*px, az*pz);
1384
bgl_sphere_project(ax*x, az*pz);
1389
bgl_sphere_project(ax*x, az*z);
1390
bgl_sphere_project(ax*x, az*pz);
1391
bgl_sphere_project(ax*px, az*pz);
1392
bgl_sphere_project(ax*px, az*z);
1401
glDisable(GL_BLEND);
1404
glColor3ub(0, 0, 0);
1406
glBegin(GL_LINE_STRIP);
1408
bgl_sphere_project(staticSine[n-i-1]*ax, staticSine[i]*az);
1412
static void draw_pose_dofs(Object *ob)
1414
bArmature *arm= ob->data;
1415
bPoseChannel *pchan;
1418
for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1421
if ( (bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
1422
if (bone->flag & BONE_SELECTED) {
1423
if (bone->layer & arm->layer) {
1424
if (pchan->ikflag & (BONE_IK_XLIMIT|BONE_IK_ZLIMIT)) {
1425
if (pose_channel_in_IK_chain(ob, pchan)) {
1426
float corner[4][3], posetrans[3], mat[4][4];
1427
float phi=0.0f, theta=0.0f, scale;
1430
/* in parent-bone pose, but own restspace */
1433
VECCOPY(posetrans, pchan->pose_mat[3]);
1434
glTranslatef(posetrans[0], posetrans[1], posetrans[2]);
1436
if (pchan->parent) {
1437
Mat4CpyMat4(mat, pchan->parent->pose_mat);
1438
mat[3][0]= mat[3][1]= mat[3][2]= 0.0f;
1442
Mat4CpyMat3(mat, pchan->bone->bone_mat);
1445
scale= bone->length*pchan->size[1];
1446
glScalef(scale, scale, scale);
1448
if (pchan->ikflag & BONE_IK_XLIMIT) {
1449
if (pchan->ikflag & BONE_IK_ZLIMIT) {
1450
float amin[3], amax[3];
1452
for (i=0; i<3; i++) {
1453
amin[i]= sin(pchan->limitmin[i]*M_PI/360.0);
1454
amax[i]= sin(pchan->limitmax[i]*M_PI/360.0);
1457
glScalef(1.0, -1.0, 1.0);
1458
if (amin[0] != 0.0 && amin[2] != 0.0)
1459
draw_dof_ellipse(amin[0], amin[2]);
1460
if (amin[0] != 0.0 && amax[2] != 0.0)
1461
draw_dof_ellipse(amin[0], amax[2]);
1462
if (amax[0] != 0.0 && amin[2] != 0.0)
1463
draw_dof_ellipse(amax[0], amin[2]);
1464
if (amax[0] != 0.0 && amax[2] != 0.0)
1465
draw_dof_ellipse(amax[0], amax[2]);
1466
glScalef(1.0, -1.0, 1.0);
1471
if (pchan->ikflag & BONE_IK_ZLIMIT) {
1472
theta= 0.5*(pchan->limitmin[2]+pchan->limitmax[2]);
1473
glRotatef(theta, 0.0f, 0.0f, 1.0f);
1475
glColor3ub(50, 50, 255); // blue, Z axis limit
1476
glBegin(GL_LINE_STRIP);
1477
for (a=-16; a<=16; a++) {
1478
float fac= ((float)a)/16.0f;
1479
phi= fac*(M_PI/360.0f)*(pchan->limitmax[2]-pchan->limitmin[2]);
1481
i= (a == -16) ? 0 : 1;
1482
corner[i][0]= sin(phi);
1483
corner[i][1]= cos(phi);
1485
glVertex3fv(corner[i]);
1489
glRotatef(-theta, 0.0f, 0.0f, 1.0f);
1492
if (pchan->ikflag & BONE_IK_XLIMIT) {
1493
theta= 0.5*(pchan->limitmin[0]+pchan->limitmax[0]);
1494
glRotatef(theta, 1.0f, 0.0f, 0.0f);
1496
glColor3ub(255, 50, 50); // Red, X axis limit
1497
glBegin(GL_LINE_STRIP);
1498
for (a=-16; a<=16; a++) {
1499
float fac= ((float)a)/16.0f;
1500
phi= 0.5f*M_PI + fac*(M_PI/360.0f)*(pchan->limitmax[0]-pchan->limitmin[0]);
1502
i= (a == -16) ? 2 : 3;
1504
corner[i][1]= sin(phi);
1505
corner[i][2]= cos(phi);
1506
glVertex3fv(corner[i]);
1510
glRotatef(-theta, 1.0f, 0.0f, 0.0f);
1513
/* out of cone, out of bone */
1523
/* assumes object is Armature with pose */
1524
static void draw_pose_channels(Base *base, int dt)
1526
Object *ob= base->object;
1527
bArmature *arm= ob->data;
1528
bPoseChannel *pchan;
1531
float smat[4][4], imat[4][4];
1533
short do_dashed= 3, draw_wire= 0;
1534
short flag, constflag;
1536
/* hacky... prevent outline select from drawing dashed helplines */
1537
glGetFloatv(GL_LINE_WIDTH, &tmp);
1538
if (tmp > 1.1) do_dashed &= ~1;
1539
if (G.vd->flag & V3D_HIDE_HELPLINES) do_dashed &= ~2;
1541
/* precalc inverse matrix for drawing screen aligned */
1542
if (arm->drawtype==ARM_ENVELOPE) {
1543
/* precalc inverse matrix for drawing screen aligned */
1545
Mat4MulFloat3(smat[0], 1.0f/VecLength(ob->obmat[0]));
1546
Mat4Invert(imat, smat);
1548
/* and draw blended distances */
1549
if (arm->flag & ARM_POSEMODE) {
1551
//glShadeModel(GL_SMOOTH);
1553
if (G.vd->zbuf) glDisable(GL_DEPTH_TEST);
1555
for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1557
if (bone && !(bone->flag & (BONE_HIDDEN_P|BONE_NO_DEFORM|BONE_HIDDEN_PG))) {
1558
if (bone->flag & (BONE_SELECTED)) {
1559
if (bone->layer & arm->layer)
1560
draw_sphere_bone_dist(smat, imat, bone->flag, pchan, NULL);
1565
if (G.vd->zbuf) glEnable(GL_DEPTH_TEST);
1566
glDisable(GL_BLEND);
1567
//glShadeModel(GL_FLAT);
1571
/* little speedup, also make sure transparent only draws once */
1572
glCullFace(GL_BACK);
1573
glEnable(GL_CULL_FACE);
1575
/* if solid we draw that first, with selection codes, but without names, axes etc */
1577
if (arm->flag & ARM_POSEMODE)
1578
index= base->selcol;
1580
for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1583
if ( (bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)) ) {
1584
if (bone->layer & arm->layer) {
1586
glMultMatrixf(pchan->pose_mat);
1588
/* catch exception for bone with hidden parent */
1590
if ( (bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)) )
1591
flag &= ~BONE_CONNECTED;
1593
/* set color-set to use */
1594
set_pchan_colorset(ob, pchan);
1596
if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM)) {
1597
/* if drawwire, don't try to draw in solid */
1598
if (pchan->bone->flag & BONE_DRAWWIRE)
1601
draw_custom_bone(pchan->custom, OB_SOLID, arm->flag, flag, index, bone->length);
1603
else if (arm->drawtype==ARM_LINE)
1604
; /* nothing in solid */
1605
else if (arm->drawtype==ARM_ENVELOPE)
1606
draw_sphere_bone(OB_SOLID, arm->flag, flag, 0, index, pchan, NULL);
1607
else if (arm->drawtype==ARM_B_BONE)
1608
draw_b_bone(OB_SOLID, arm->flag, flag, 0, index, pchan, NULL);
1610
draw_bone(OB_SOLID, arm->flag, flag, 0, index, bone->length);
1617
index+= 0x10000; // pose bones count in higher 2 bytes only
1620
/* very very confusing... but in object mode, solid draw, we cannot do glLoadName yet,
1621
* stick bones and/or wire custom-shapes are drawn in next loop
1623
if ((arm->drawtype != ARM_LINE) && (draw_wire == 0)) {
1624
/* object tag, for bordersel optim */
1625
glLoadName(index & 0xFFFF);
1630
/* draw custom bone shapes as wireframes */
1631
if ( !(arm->flag & ARM_NO_CUSTOM) &&
1632
((draw_wire) || (dt <= OB_WIRE)) )
1634
if (arm->flag & ARM_POSEMODE)
1635
index= base->selcol;
1637
/* only draw custom bone shapes that need to be drawn as wires */
1638
for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1641
if ((bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
1642
if (bone->layer & arm->layer) {
1643
if (pchan->custom) {
1644
if ((dt < OB_SOLID) || (bone->flag & BONE_DRAWWIRE)) {
1646
glMultMatrixf(pchan->pose_mat);
1648
/* prepare colors */
1649
if (arm->flag & ARM_POSEMODE)
1650
set_pchan_colorset(ob, pchan);
1652
if ((G.scene->basact)==base) {
1653
if (base->flag & (SELECT+BA_WAS_SEL)) BIF_ThemeColor(TH_ACTIVE);
1654
else BIF_ThemeColor(TH_WIRE);
1657
if (base->flag & (SELECT+BA_WAS_SEL)) BIF_ThemeColor(TH_SELECT);
1658
else BIF_ThemeColor(TH_WIRE);
1662
/* catch exception for bone with hidden parent */
1664
if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)))
1665
flag &= ~BONE_CONNECTED;
1667
draw_custom_bone(pchan->custom, OB_WIRE, arm->flag, flag, index, bone->length);
1676
index+= 0x10000; // pose bones count in higher 2 bytes only
1680
/* object tag, for bordersel optim */
1681
glLoadName(index & 0xFFFF);
1686
/* wire draw over solid only in posemode */
1687
if ((dt <= OB_WIRE) || (arm->flag & ARM_POSEMODE) || (arm->drawtype==ARM_LINE)) {
1688
/* draw line check first. we do selection indices */
1689
if (arm->drawtype==ARM_LINE) {
1690
if (arm->flag & ARM_POSEMODE)
1691
index= base->selcol;
1693
/* if solid && posemode, we draw again with polygonoffset */
1694
else if ((dt > OB_WIRE) && (arm->flag & ARM_POSEMODE)) {
1695
bglPolygonOffset(1.0);
1698
/* and we use selection indices if not done yet */
1699
if (arm->flag & ARM_POSEMODE)
1700
index= base->selcol;
1703
for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1706
if ((bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
1707
if (bone->layer & arm->layer) {
1708
if ((do_dashed & 1) && (bone->parent)) {
1709
/* Draw a line from our root to the parent's tip
1710
* - only if V3D_HIDE_HELPLINES is enabled...
1712
if ( (do_dashed & 2) && ((bone->flag & BONE_CONNECTED)==0) ) {
1713
if (arm->flag & ARM_POSEMODE) {
1714
glLoadName(index & 0xFFFF); // object tag, for bordersel optim
1715
BIF_ThemeColor(TH_WIRE);
1719
glVertex3fv(pchan->pose_head);
1720
glVertex3fv(pchan->parent->pose_tail);
1725
/* Draw a line to IK root bone
1726
* - only if temporary chain (i.e. "autoik")
1728
if (arm->flag & ARM_POSEMODE) {
1729
if (pchan->constflag & PCHAN_HAS_IK) {
1730
if (bone->flag & BONE_SELECTED) {
1731
if (pchan->constflag & PCHAN_HAS_TARGET) glColor3ub(200, 120, 0);
1732
else glColor3ub(200, 200, 50); // add theme!
1734
glLoadName(index & 0xFFFF);
1735
pchan_draw_IK_root_lines(pchan, !(do_dashed & 2));
1742
if (arm->drawtype != ARM_ENVELOPE)
1743
glMultMatrixf(pchan->pose_mat);
1745
/* catch exception for bone with hidden parent */
1747
if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)))
1748
flag &= ~BONE_CONNECTED;
1750
/* extra draw service for pose mode */
1751
constflag= pchan->constflag;
1752
if (pchan->flag & (POSE_ROT|POSE_LOC|POSE_SIZE))
1753
constflag |= PCHAN_HAS_ACTION;
1754
if (pchan->flag & POSE_STRIDE)
1755
constflag |= PCHAN_HAS_STRIDE;
1757
/* set color-set to use */
1758
set_pchan_colorset(ob, pchan);
1760
if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM))
1761
; // custom bone shapes should not be drawn here!
1762
else if (arm->drawtype==ARM_ENVELOPE) {
1764
draw_sphere_bone_wire(smat, imat, arm->flag, flag, constflag, index, pchan, NULL);
1766
else if (arm->drawtype==ARM_LINE)
1767
draw_line_bone(arm->flag, flag, constflag, index, pchan, NULL);
1768
else if (arm->drawtype==ARM_B_BONE)
1769
draw_b_bone(OB_WIRE, arm->flag, flag, constflag, index, pchan, NULL);
1771
draw_bone(OB_WIRE, arm->flag, flag, constflag, index, bone->length);
1777
/* pose bones count in higher 2 bytes only */
1781
/* restore things */
1782
if ((arm->drawtype!=ARM_LINE)&& (dt>OB_WIRE) && (arm->flag & ARM_POSEMODE))
1783
bglPolygonOffset(0.0);
1787
glDisable(GL_CULL_FACE);
1790
if (arm->flag & ARM_POSEMODE)
1793
/* finally names and axes */
1794
if (arm->flag & (ARM_DRAWNAMES|ARM_DRAWAXES)) {
1795
/* patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing */
1796
if ((G.f & G_PICKSEL) == 0) {
1799
if (G.vd->zbuf) glDisable(GL_DEPTH_TEST);
1801
for (pchan=ob->pose->chanbase.first; pchan; pchan=pchan->next) {
1802
if ((pchan->bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))==0) {
1803
if (pchan->bone->layer & arm->layer) {
1804
if (arm->flag & (ARM_EDITMODE|ARM_POSEMODE)) {
1807
if (bone->flag & BONE_SELECTED) BIF_ThemeColor(TH_TEXT_HI);
1808
else BIF_ThemeColor(TH_TEXT);
1810
else if (dt > OB_WIRE)
1811
BIF_ThemeColor(TH_TEXT);
1813
/* Draw names of bone */
1814
if (arm->flag & ARM_DRAWNAMES) {
1815
VecMidf(vec, pchan->pose_head, pchan->pose_tail);
1816
glRasterPos3fv(vec);
1817
BMF_DrawString(G.font, " ");
1818
BMF_DrawString(G.font, pchan->name);
1821
/* Draw additional axes on the bone tail */
1822
if ( (arm->flag & ARM_DRAWAXES) && (arm->flag & ARM_POSEMODE) ) {
1824
glMultMatrixf(pchan->pose_mat);
1825
glTranslatef(0.0f, pchan->bone->length, 0.0f);
1826
drawaxes(0.25f*pchan->bone->length, 0, OB_ARROWS);
1833
if (G.vd->zbuf) glEnable(GL_DEPTH_TEST);
1838
/* in editmode, we don't store the bone matrix... */
1839
static void set_matrix_editbone(EditBone *eBone)
1841
float delta[3],offset[3];
1842
float mat[3][3], bmat[4][4];
1844
/* Compose the parent transforms (i.e. their translations) */
1845
VECCOPY(offset, eBone->head);
1847
glTranslatef(offset[0],offset[1],offset[2]);
1849
VecSubf(delta, eBone->tail, eBone->head);
1851
eBone->length = sqrt (delta[0]*delta[0] + delta[1]*delta[1] +delta[2]*delta[2]);
1853
vec_roll_to_mat3(delta, eBone->roll, mat);
1854
Mat4CpyMat3(bmat, mat);
1856
glMultMatrixf(bmat);
1860
static void draw_ebones(Object *ob, int dt)
1863
bArmature *arm= ob->data;
1864
float smat[4][4], imat[4][4];
1868
/* envelope (deform distance) */
1869
if(arm->drawtype==ARM_ENVELOPE) {
1870
/* precalc inverse matrix for drawing screen aligned */
1872
Mat4MulFloat3(smat[0], 1.0f/VecLength(ob->obmat[0]));
1873
Mat4Invert(imat, smat);
1875
/* and draw blended distances */
1877
//glShadeModel(GL_SMOOTH);
1879
if (G.vd->zbuf) glDisable(GL_DEPTH_TEST);
1881
for (eBone=G.edbo.first, index=0; eBone; eBone=eBone->next, index++) {
1882
if (eBone->layer & arm->layer) {
1883
if ((eBone->flag & (BONE_HIDDEN_A|BONE_NO_DEFORM))==0) {
1884
if (eBone->flag & (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL))
1885
draw_sphere_bone_dist(smat, imat, eBone->flag, NULL, eBone);
1890
if (G.vd->zbuf) glEnable(GL_DEPTH_TEST);
1891
glDisable(GL_BLEND);
1892
//glShadeModel(GL_FLAT);
1895
/* if solid we draw it first */
1896
if ((dt > OB_WIRE) && (arm->drawtype!=ARM_LINE)) {
1898
for (eBone=G.edbo.first, index=0; eBone; eBone=eBone->next, index++) {
1899
if (eBone->layer & arm->layer) {
1900
if ((eBone->flag & BONE_HIDDEN_A)==0) {
1902
set_matrix_editbone(eBone);
1904
/* catch exception for bone with hidden parent */
1906
if ( (eBone->parent) && ((eBone->parent->flag & BONE_HIDDEN_A) || (eBone->parent->layer & arm->layer)==0) )
1907
flag &= ~BONE_CONNECTED;
1909
if (arm->drawtype==ARM_ENVELOPE)
1910
draw_sphere_bone(OB_SOLID, arm->flag, flag, 0, index, NULL, eBone);
1911
else if(arm->drawtype==ARM_B_BONE)
1912
draw_b_bone(OB_SOLID, arm->flag, flag, 0, index, NULL, eBone);
1914
draw_bone(OB_SOLID, arm->flag, flag, 0, index, eBone->length);
1923
/* if wire over solid, set offset */
1926
if (arm->drawtype==ARM_LINE) {
1930
else if (dt > OB_WIRE)
1931
bglPolygonOffset(1.0);
1932
else if (arm->flag & ARM_EDITMODE)
1933
index= 0; /* do selection codes */
1935
for (eBone=G.edbo.first; eBone; eBone=eBone->next) {
1936
if (eBone->layer & arm->layer) {
1937
if ((eBone->flag & BONE_HIDDEN_A)==0) {
1939
/* catch exception for bone with hidden parent */
1941
if ( (eBone->parent) && ((eBone->parent->flag & BONE_HIDDEN_A) || (eBone->parent->layer & arm->layer)==0) )
1942
flag &= ~BONE_CONNECTED;
1944
if (arm->drawtype == ARM_ENVELOPE) {
1946
draw_sphere_bone_wire(smat, imat, arm->flag, flag, 0, index, NULL, eBone);
1950
set_matrix_editbone(eBone);
1952
if (arm->drawtype == ARM_LINE)
1953
draw_line_bone(arm->flag, flag, 0, index, NULL, eBone);
1954
else if (arm->drawtype == ARM_B_BONE)
1955
draw_b_bone(OB_WIRE, arm->flag, flag, 0, index, NULL, eBone);
1957
draw_bone(OB_WIRE, arm->flag, flag, 0, index, eBone->length);
1962
/* offset to parent */
1963
if (eBone->parent) {
1964
BIF_ThemeColor(TH_WIRE);
1965
glLoadName (-1); // -1 here is OK!
1969
glVertex3fv(eBone->parent->tail);
1970
glVertex3fv(eBone->head);
1977
if(index!=-1) index++;
1981
if (arm->drawtype==ARM_LINE);
1982
else if (dt>OB_WIRE) bglPolygonOffset(0.0);
1984
/* finally names and axes */
1985
if (arm->flag & (ARM_DRAWNAMES|ARM_DRAWAXES)) {
1986
// patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing
1987
if ((G.f & G_PICKSEL) == 0) {
1990
if (G.vd->zbuf) glDisable(GL_DEPTH_TEST);
1992
for (eBone=G.edbo.first, index=0; eBone; eBone=eBone->next, index++) {
1993
if(eBone->layer & arm->layer) {
1994
if ((eBone->flag & BONE_HIDDEN_A)==0) {
1996
if (eBone->flag & BONE_SELECTED) BIF_ThemeColor(TH_TEXT_HI);
1997
else BIF_ThemeColor(TH_TEXT);
2000
if (arm->flag & ARM_DRAWNAMES) {
2001
VecMidf(vec, eBone->head, eBone->tail);
2002
glRasterPos3fv(vec);
2003
BMF_DrawString(G.font, " ");
2004
BMF_DrawString(G.font, eBone->name);
2006
/* Draw additional axes */
2007
if (arm->flag & ARM_DRAWAXES) {
2009
set_matrix_editbone(eBone);
2010
glTranslatef(0.0f, eBone->length, 0.0f);
2011
drawaxes(eBone->length*0.25f, 0, OB_ARROWS);
2019
if (G.vd->zbuf) glEnable(GL_DEPTH_TEST);
2024
/* ****************************** Armature Visualisation ******************************** */
2026
/* ---------- Paths --------- */
2031
static void draw_pose_paths(Object *ob)
2033
bArmature *arm= ob->data;
2034
bPoseChannel *pchan;
2036
bActionChannel *achan;
2039
float *fp, *fp_start;
2041
int sfra, efra, len;
2043
if (G.vd->zbuf) glDisable(GL_DEPTH_TEST);
2046
glLoadMatrixf(G.vd->viewmat);
2048
/* version patch here - cannot access frame info from file reading */
2049
if (arm->pathsize == 0) arm->pathsize= 1;
2050
stepsize = arm->pathsize;
2052
for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
2053
if (pchan->bone->layer & arm->layer) {
2055
/* version patch here - cannot access frame info from file reading */
2056
if ((pchan->pathsf == 0) || (pchan->pathef == 0)) {
2057
pchan->pathsf= SFRA;
2058
pchan->pathef= EFRA;
2061
/* get frame ranges */
2062
if (arm->pathflag & ARM_PATH_ACFRA) {
2065
/* With "Around Current", we only choose frames from around
2066
* the current frame to draw. However, this range is still
2067
* restricted by the limits of the original path.
2069
sfra= CFRA - arm->pathbc;
2070
efra= CFRA + arm->pathac;
2071
if (sfra < pchan->pathsf) sfra= pchan->pathsf;
2072
if (efra > pchan->pathef) efra= pchan->pathef;
2076
sind= sfra - pchan->pathsf;
2077
fp_start= (pchan->path + (3*sind));
2080
sfra= pchan->pathsf;
2081
efra = sfra + pchan->pathlen;
2082
len = pchan->pathlen;
2083
fp_start = pchan->path;
2086
/* draw curve-line of path */
2087
glShadeModel(GL_SMOOTH);
2089
glBegin(GL_LINE_STRIP);
2090
for (a=0, fp=fp_start; a<len; a++, fp+=3) {
2091
float intensity; /* how faint */
2094
* - more intense for active/selected bones, less intense for unselected bones
2095
* - black for before current frame, green for current frame, blue for after current frame
2096
* - intensity decreases as distance from current frame increases
2098
#define SET_INTENSITY(A, B, C, min, max) (((1.0f - ((C - B) / (C - A))) * (max-min)) + min)
2099
if ((a+sfra) < CFRA) {
2100
/* black - before cfra */
2101
if (pchan->bone->flag & BONE_SELECTED) {
2103
intensity = SET_INTENSITY(sfra, a, CFRA, 0.25f, 0.75f);
2107
intensity = SET_INTENSITY(sfra, a, CFRA, 0.68f, 0.92f);
2109
BIF_ThemeColorBlend(TH_WIRE, TH_BACK, intensity);
2111
else if ((a+sfra) > CFRA) {
2112
/* blue - after cfra */
2113
if (pchan->bone->flag & BONE_SELECTED) {
2115
intensity = SET_INTENSITY(CFRA, a, efra, 0.25f, 0.75f);
2119
intensity = SET_INTENSITY(CFRA, a, efra, 0.68f, 0.92f);
2121
BIF_ThemeColorBlend(TH_BONE_POSE, TH_BACK, intensity);
2124
/* green - on cfra */
2125
if (pchan->bone->flag & BONE_SELECTED) {
2131
BIF_ThemeColorBlendShade(TH_CFRAME, TH_BACK, intensity, 10);
2134
/* draw a vertex with this color */
2139
glShadeModel(GL_FLAT);
2143
/* draw little black point at each frame
2144
* NOTE: this is not really visible/noticable
2147
for (a=0, fp=fp_start; a<len; a++, fp+=3)
2151
/* Draw little white dots at each framestep value */
2152
BIF_ThemeColor(TH_TEXT_HI);
2154
for (a=0, fp=fp_start; a<len; a+=stepsize, fp+=(stepsize*3))
2158
/* Draw frame numbers at each framestep value */
2159
if (arm->pathflag & ARM_PATH_FNUMS) {
2160
for (a=0, fp=fp_start; a<len; a+=stepsize, fp+=(stepsize*3)) {
2163
/* only draw framenum if several consecutive highlighted points don't occur on same point */
2166
sprintf(str, " %d\n", (a+sfra));
2167
BMF_DrawString(G.font, str);
2169
else if ((a > stepsize) && (a < len-stepsize)) {
2170
if ((VecEqual(fp, fp-(stepsize*3))==0) || (VecEqual(fp, fp+(stepsize*3))==0)) {
2172
sprintf(str, " %d\n", (a+sfra));
2173
BMF_DrawString(G.font, str);
2179
/* Keyframes - dots and numbers */
2180
if (arm->pathflag & ARM_PATH_KFRAS) {
2181
/* build list of all keyframes in active action for pchan */
2182
keys.first = keys.last = NULL;
2183
act= ob_get_action(ob);
2185
achan= get_action_channel(act, pchan->name);
2187
ipo_to_keylist(achan->ipo, &keys, NULL, NULL);
2190
/* Draw slightly-larger yellow dots at each keyframe */
2191
BIF_ThemeColor(TH_VERTEX_SELECT);
2195
for (a=0, fp=fp_start; a<len; a++, fp+=3) {
2196
for (ak= keys.first; ak; ak= ak->next) {
2197
if (ak->cfra == (a+sfra))
2205
/* Draw frame numbers of keyframes */
2206
if ((arm->pathflag & ARM_PATH_FNUMS) || (arm->pathflag & ARM_PATH_KFNOS)) {
2207
for(a=0, fp=fp_start; a<len; a++, fp+=3) {
2208
for (ak= keys.first; ak; ak= ak->next) {
2209
if (ak->cfra == (a+sfra)) {
2213
sprintf(str, " %d\n", (a+sfra));
2214
BMF_DrawString(G.font, str);
2220
BLI_freelistN(&keys);
2226
if (G.vd->zbuf) glEnable(GL_DEPTH_TEST);
2231
/* ---------- Ghosts --------- */
2233
/* helper function for ghost drawing - sets/removes flags for temporarily
2234
* hiding unselected bones while drawing ghosts
2236
static void ghost_poses_tag_unselected(Object *ob, short unset)
2238
bArmature *arm= ob->data;
2239
bPose *pose= ob->pose;
2240
bPoseChannel *pchan;
2242
/* don't do anything if no hiding any bones */
2243
if ((arm->flag & ARM_GHOST_ONLYSEL)==0)
2246
/* loop over all pchans, adding/removing tags as appropriate */
2247
for (pchan= pose->chanbase.first; pchan; pchan= pchan->next) {
2248
if ((pchan->bone) && (arm->layer & pchan->bone->layer)) {
2250
/* remove tags from all pchans if cleaning up */
2251
pchan->bone->flag &= ~BONE_HIDDEN_PG;
2254
/* set tags on unselected pchans only */
2255
if ((pchan->bone->flag & BONE_SELECTED)==0)
2256
pchan->bone->flag |= BONE_HIDDEN_PG;
2262
/* draw ghosts that occur within a frame range
2263
* note: object should be in posemode
2265
static void draw_ghost_poses_range(Base *base)
2267
Object *ob= base->object;
2268
bArmature *arm= ob->data;
2269
bPose *posen, *poseo;
2270
float start, end, stepsize, range, colfac;
2271
int cfrao, flago, ipoflago;
2273
start = arm->ghostsf;
2278
stepsize= (float)(arm->ghostsize);
2279
range= (float)(end - start);
2282
ob->flag &= ~OB_POSEMODE;
2285
arm->flag &= ~(ARM_DRAWNAMES|ARM_DRAWAXES);
2286
ipoflago= ob->ipoflag;
2287
ob->ipoflag |= OB_DISABLE_PATH;
2291
copy_pose(&posen, ob->pose, 1);
2293
armature_rebuild_pose(ob, ob->data); /* child pointers for IK */
2294
ghost_poses_tag_unselected(ob, 0); /* hide unselected bones if need be */
2297
if (G.vd->zbuf) glDisable(GL_DEPTH_TEST);
2299
/* draw from first frame of range to last */
2300
for (CFRA= start; CFRA<end; CFRA+=stepsize) {
2301
colfac = (end-CFRA)/range;
2302
BIF_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0f*sqrt(colfac)));
2304
do_all_pose_actions(ob);
2306
draw_pose_channels(base, OB_WIRE);
2308
glDisable(GL_BLEND);
2309
if (G.vd->zbuf) glEnable(GL_DEPTH_TEST);
2311
ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */
2318
armature_rebuild_pose(ob, ob->data);
2319
ob->flag |= OB_POSEMODE;
2320
ob->ipoflag= ipoflago;
2323
/* draw ghosts on keyframes in action within range
2324
* - object should be in posemode
2326
static void draw_ghost_poses_keys(Base *base)
2328
Object *ob= base->object;
2329
bAction *act= ob_get_action(ob);
2330
bArmature *arm= ob->data;
2331
bPose *posen, *poseo;
2332
ListBase keys= {NULL, NULL};
2333
ActKeysInc aki = {0, 0, 0};
2334
ActKeyColumn *ak, *akn;
2335
float start, end, range, colfac, i;
2336
int cfrao, flago, ipoflago;
2338
aki.start= start = arm->ghostsf;
2339
aki.end= end = arm->ghostef;
2343
/* get keyframes - then clip to only within range */
2344
action_to_keylist(act, &keys, NULL, &aki);
2346
for (ak= keys.first; ak; ak= akn) {
2349
if ((ak->cfra < start) || (ak->cfra > end))
2350
BLI_freelinkN(&keys, ak);
2354
if (range == 0) return;
2357
ob->flag &= ~OB_POSEMODE;
2360
arm->flag &= ~(ARM_DRAWNAMES|ARM_DRAWAXES);
2361
ipoflago= ob->ipoflag;
2362
ob->ipoflag |= OB_DISABLE_PATH;
2366
copy_pose(&posen, ob->pose, 1);
2368
armature_rebuild_pose(ob, ob->data); /* child pointers for IK */
2369
ghost_poses_tag_unselected(ob, 0); /* hide unselected bones if need be */
2372
if (G.vd->zbuf) glDisable(GL_DEPTH_TEST);
2374
/* draw from first frame of range to last */
2375
for (ak=keys.first, i=0; ak; ak=ak->next, i++) {
2377
BIF_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0f*sqrt(colfac)));
2379
CFRA= (int)ak->cfra;
2381
do_all_pose_actions(ob);
2383
draw_pose_channels(base, OB_WIRE);
2385
glDisable(GL_BLEND);
2386
if (G.vd->zbuf) glEnable(GL_DEPTH_TEST);
2388
ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */
2389
BLI_freelistN(&keys);
2396
armature_rebuild_pose(ob, ob->data);
2397
ob->flag |= OB_POSEMODE;
2398
ob->ipoflag= ipoflago;
2401
/* draw ghosts around current frame
2402
* - object is supposed to be armature in posemode
2404
static void draw_ghost_poses(Base *base)
2406
Object *ob= base->object;
2407
bArmature *arm= ob->data;
2408
bPose *posen, *poseo;
2409
bActionStrip *strip;
2410
float cur, start, end, stepsize, range, colfac, actframe, ctime;
2411
int cfrao, maptime, flago, ipoflago;
2413
/* pre conditions, get an action with sufficient frames */
2414
if (ob->action==NULL)
2417
calc_action_range(ob->action, &start, &end, 0);
2421
stepsize= (float)(arm->ghostsize);
2422
range= (float)(arm->ghostep)*stepsize + 0.5f; /* plus half to make the for loop end correct */
2424
/* we only map time for armature when an active strip exists */
2425
for (strip=ob->nlastrips.first; strip; strip=strip->next)
2426
if (strip->flag & ACTSTRIP_ACTIVE)
2429
maptime= (strip!=NULL);
2432
ob->flag &= ~OB_POSEMODE;
2434
if (maptime) actframe= get_action_frame(ob, (float)CFRA);
2435
else actframe= CFRA;
2437
arm->flag &= ~(ARM_DRAWNAMES|ARM_DRAWAXES);
2438
ipoflago= ob->ipoflag;
2439
ob->ipoflag |= OB_DISABLE_PATH;
2443
copy_pose(&posen, ob->pose, 1);
2445
armature_rebuild_pose(ob, ob->data); /* child pointers for IK */
2446
ghost_poses_tag_unselected(ob, 0); /* hide unselected bones if need be */
2449
if (G.vd->zbuf) glDisable(GL_DEPTH_TEST);
2451
/* draw from darkest blend to lowest */
2452
for(cur= stepsize; cur<range; cur+=stepsize) {
2453
ctime= cur - fmod((float)cfrao, stepsize); /* ensures consistant stepping */
2454
colfac= ctime/range;
2455
BIF_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0f*sqrt(colfac)));
2457
/* only within action range */
2458
if (actframe+ctime >= start && actframe+ctime <= end) {
2459
if (maptime) CFRA= (int)get_action_frame_inv(ob, actframe+ctime);
2460
else CFRA= (int)floor(actframe+ctime);
2463
do_all_pose_actions(ob);
2465
draw_pose_channels(base, OB_WIRE);
2469
ctime= cur + fmod((float)cfrao, stepsize) - stepsize+1.0f; /* ensures consistant stepping */
2470
colfac= ctime/range;
2471
BIF_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0f*sqrt(colfac)));
2473
/* only within action range */
2474
if ((actframe-ctime >= start) && (actframe-ctime <= end)) {
2475
if (maptime) CFRA= (int)get_action_frame_inv(ob, actframe-ctime);
2476
else CFRA= (int)floor(actframe-ctime);
2478
if (CFRA != cfrao) {
2479
do_all_pose_actions(ob);
2481
draw_pose_channels(base, OB_WIRE);
2485
glDisable(GL_BLEND);
2486
if (G.vd->zbuf) glEnable(GL_DEPTH_TEST);
2488
ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */
2495
armature_rebuild_pose(ob, ob->data);
2496
ob->flag |= OB_POSEMODE;
2497
ob->ipoflag= ipoflago;
2500
/* ********************************** Armature Drawing - Main ************************* */
2502
/* called from drawobject.c, return 1 if nothing was drawn */
2503
int draw_armature(Base *base, int dt, int flag)
2505
Object *ob= base->object;
2506
bArmature *arm= ob->data;
2509
if(G.f & G_RENDER_SHADOW)
2512
if(dt>OB_WIRE && arm->drawtype!=ARM_LINE) {
2513
/* we use color for solid lighting */
2514
glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
2515
glEnable(GL_COLOR_MATERIAL);
2516
glColor3ub(0,0,0); // clear spec
2517
glDisable(GL_COLOR_MATERIAL);
2519
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
2520
glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW); // only for lighting...
2523
/* arm->flag is being used to detect mode... */
2525
if(ob==G.obedit || (G.obedit && ob->data==G.obedit->data)) {
2526
if(ob==G.obedit) arm->flag |= ARM_EDITMODE;
2527
draw_ebones(ob, dt);
2528
arm->flag &= ~ARM_EDITMODE;
2532
if(ob->pose && ob->pose->chanbase.first) {
2533
/* drawing posemode selection indices or colors only in these cases */
2534
if(!(base->flag & OB_FROMDUPLI)) {
2535
if(G.f & G_PICKSEL) {
2536
if(ob->flag & OB_POSEMODE)
2537
arm->flag |= ARM_POSEMODE;
2539
else if(ob->flag & OB_POSEMODE) {
2540
if (arm->ghosttype == ARM_GHOST_RANGE) {
2541
draw_ghost_poses_range(base);
2543
else if (arm->ghosttype == ARM_GHOST_KEYS) {
2544
draw_ghost_poses_keys(base);
2546
else if (arm->ghosttype == ARM_GHOST_CUR) {
2548
draw_ghost_poses(base);
2550
if ((flag & DRAW_SCENESET)==0) {
2552
arm->flag |= ARM_POSEMODE;
2553
else if(G.f & G_WEIGHTPAINT)
2554
arm->flag |= ARM_POSEMODE;
2556
draw_pose_paths(ob);
2560
draw_pose_channels(base, dt);
2561
arm->flag &= ~ARM_POSEMODE;
2563
if(ob->flag & OB_POSEMODE)
2564
BIF_ThemeColor(TH_WIRE); /* restore, for extra draw stuff */
2569
glFrontFace(GL_CCW);
2574
/* *************** END Armature drawing ******************* */