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_context.h"
61 #include "BKE_depsgraph.h"
62 #include "BKE_DerivedMesh.h"
63 #include "BKE_global.h"
65 #include "BKE_object.h"
67 #include "BKE_utildefines.h"
69 #include "BIF_editarmature.h"
71 #include "BIF_glutil.h"
76 #include "UI_resources.h"
78 #include "view3d_intern.h"
80 /* XXX ***************** */
81 int pose_channel_in_IK_chain() {return 0;}
82 void ipo_to_keylist() {}
83 void *ob_get_action() {return NULL;}
84 void action_to_keylist() {}
86 typedef struct ActKeyColumn {
87 struct ActKeyColumn *next, *prev;
88 short sel, handle_type;
91 /* only while drawing - used to determine if long-keyframe needs to be drawn */
95 typedef struct ActKeysInc {
96 struct Object *ob; /* if present, used to find action-scaled time */
97 float start, end; /* frames (global-time) to only consider keys between */
100 /* ******************** */
103 /* *************** Armature Drawing - Coloring API ***************************** */
105 /* global here is reset before drawing each bone */
106 static ThemeWireColor *bcolor= NULL;
108 /* values of colCode for set_pchan_glcolor */
110 PCHAN_COLOR_NORMAL = 0, /* normal drawing */
111 PCHAN_COLOR_SOLID, /* specific case where "solid" color is needed */
112 PCHAN_COLOR_CONSTS, /* "constraint" colors (which may/may-not be suppressed) */
114 PCHAN_COLOR_SPHEREBONE_BASE, /* for the 'stick' of sphere (envelope) bones */
115 PCHAN_COLOR_SPHEREBONE_END, /* for the ends of sphere (envelope) bones */
116 PCHAN_COLOR_LINEBONE /* for the middle of line-bones */
119 /* This function sets the color-set for coloring a certain bone */
120 static void set_pchan_colorset (Object *ob, bPoseChannel *pchan)
122 bPose *pose= (ob) ? ob->pose : NULL;
123 bArmature *arm= (ob) ? ob->data : NULL;
124 bActionGroup *grp= NULL;
125 short color_index= 0;
128 if (ELEM4(NULL, ob, arm, pose, pchan)) {
133 /* only try to set custom color if enabled for armature */
134 if (arm->flag & ARM_COL_CUSTOM) {
135 /* currently, a bone can only use a custom color set if it's group (if it has one),
136 * has been set to use one
138 if (pchan->agrp_index) {
139 grp= (bActionGroup *)BLI_findlink(&pose->agroups, (pchan->agrp_index - 1));
141 color_index= grp->customCol;
145 /* bcolor is a pointer to the color set to use. If NULL, then the default
146 * color set (based on the theme colors for 3d-view) is used.
148 if (color_index > 0) {
149 bTheme *btheme= U.themes.first;
150 bcolor= &btheme->tarm[(color_index - 1)];
152 else if (color_index == -1) {
153 /* use the group's own custom color set */
154 bcolor= (grp)? &grp->cs : NULL;
160 /* This function is for brightening/darkening a given color (like UI_ThemeColorShade()) */
161 static void cp_shade_color3ub (char cp[], int offset)
165 r= offset + (int) cp[0];
167 g= offset + (int) cp[1];
169 b= offset + (int) cp[2];
177 /* This function sets the gl-color for coloring a certain bone (based on bcolor) */
178 static short set_pchan_glColor (short colCode, int armflag, int boneflag, int constflag)
181 case PCHAN_COLOR_NORMAL:
186 if (boneflag & BONE_ACTIVE) {
187 VECCOPY(cp, bcolor->active);
189 else if (boneflag & BONE_SELECTED) {
190 VECCOPY(cp, bcolor->select);
193 /* a bit darker than solid */
194 VECCOPY(cp, bcolor->solid);
195 cp_shade_color3ub(cp, -50);
198 glColor3ub(cp[0], cp[1], cp[2]);
201 if (boneflag & BONE_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 40);
202 else if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_BONE_POSE);
203 else UI_ThemeColor(TH_WIRE);
210 case PCHAN_COLOR_SOLID:
213 char *cp= bcolor->solid;
214 glColor3ub(cp[0], cp[1], cp[2]);
217 UI_ThemeColor(TH_BONE_SOLID);
223 case PCHAN_COLOR_CONSTS:
225 if ( (bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS) ) {
226 if (constflag & PCHAN_HAS_STRIDE) glColor4ub(0, 0, 200, 80);
227 else if (constflag & PCHAN_HAS_TARGET) glColor4ub(255, 150, 0, 80);
228 else if (constflag & PCHAN_HAS_IK) glColor4ub(255, 255, 0, 80);
229 else if (constflag & PCHAN_HAS_CONST) glColor4ub(0, 255, 120, 80);
230 else if (constflag) UI_ThemeColor4(TH_BONE_POSE); // PCHAN_HAS_ACTION
239 case PCHAN_COLOR_SPHEREBONE_BASE:
244 if (boneflag & BONE_ACTIVE) {
245 VECCOPY(cp, bcolor->active);
247 else if (boneflag & BONE_SELECTED) {
248 VECCOPY(cp, bcolor->select);
251 VECCOPY(cp, bcolor->solid);
254 glColor3ub(cp[0], cp[1], cp[2]);
257 if (boneflag & BONE_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 40);
258 else if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_BONE_POSE);
259 else UI_ThemeColor(TH_BONE_SOLID);
265 case PCHAN_COLOR_SPHEREBONE_END:
270 if (boneflag & BONE_ACTIVE) {
271 VECCOPY(cp, bcolor->active);
272 cp_shade_color3ub(cp, 10);
274 else if (boneflag & BONE_SELECTED) {
275 VECCOPY(cp, bcolor->select);
276 cp_shade_color3ub(cp, -30);
279 VECCOPY(cp, bcolor->solid);
280 cp_shade_color3ub(cp, -30);
283 glColor3ub(cp[0], cp[1], cp[2]);
286 if (boneflag & BONE_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 10);
287 else if (boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_BONE_POSE, -30);
288 else UI_ThemeColorShade(TH_BONE_SOLID, -30);
293 case PCHAN_COLOR_LINEBONE:
295 /* inner part in background color or constraint */
296 if ( (constflag) && ((bcolor==NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS)) ) {
297 if (constflag & PCHAN_HAS_STRIDE) glColor3ub(0, 0, 200);
298 else if (constflag & PCHAN_HAS_TARGET) glColor3ub(255, 150, 0);
299 else if (constflag & PCHAN_HAS_IK) glColor3ub(255, 255, 0);
300 else if (constflag & PCHAN_HAS_CONST) glColor3ub(0, 255, 120);
301 else if (constflag) UI_ThemeColor(TH_BONE_POSE); /* PCHAN_HAS_ACTION */
305 char *cp= bcolor->solid;
306 glColor4ub(cp[0], cp[1], cp[2], 0.8);
309 UI_ThemeColorShade(TH_BACK, -30);
321 /* *************** Armature drawing, helper calls for parts ******************* */
323 /* half the cube, in Y */
324 static float cube[8][3] = {
335 static void drawsolidcube_size(float xsize, float ysize, float zsize)
337 static GLuint displist=0;
340 glScalef(xsize, ysize, zsize);
342 n[0]=0; n[1]=0; n[2]=0;
345 displist= glGenLists(1);
346 glNewList(displist, GL_COMPILE_AND_EXECUTE);
351 glVertex3fv(cube[0]); glVertex3fv(cube[1]); glVertex3fv(cube[2]); glVertex3fv(cube[3]);
355 glVertex3fv(cube[0]); glVertex3fv(cube[4]); glVertex3fv(cube[5]); glVertex3fv(cube[1]);
359 glVertex3fv(cube[4]); glVertex3fv(cube[7]); glVertex3fv(cube[6]); glVertex3fv(cube[5]);
363 glVertex3fv(cube[7]); glVertex3fv(cube[3]); glVertex3fv(cube[2]); glVertex3fv(cube[6]);
367 glVertex3fv(cube[1]); glVertex3fv(cube[5]); glVertex3fv(cube[6]); glVertex3fv(cube[2]);
371 glVertex3fv(cube[7]); glVertex3fv(cube[4]); glVertex3fv(cube[0]); glVertex3fv(cube[3]);
376 else glCallList(displist);
380 static void drawcube_size(float xsize, float ysize, float zsize)
382 static GLuint displist=0;
384 glScalef(xsize, ysize, zsize);
387 displist= glGenLists(1);
388 glNewList(displist, GL_COMPILE_AND_EXECUTE);
390 glBegin(GL_LINE_STRIP);
391 glVertex3fv(cube[0]); glVertex3fv(cube[1]);glVertex3fv(cube[2]); glVertex3fv(cube[3]);
392 glVertex3fv(cube[0]); glVertex3fv(cube[4]);glVertex3fv(cube[5]); glVertex3fv(cube[6]);
393 glVertex3fv(cube[7]); glVertex3fv(cube[4]);
397 glVertex3fv(cube[1]); glVertex3fv(cube[5]);
398 glVertex3fv(cube[2]); glVertex3fv(cube[6]);
399 glVertex3fv(cube[3]); glVertex3fv(cube[7]);
404 else glCallList(displist);
409 static void draw_bonevert(void)
411 static GLuint displist=0;
416 displist= glGenLists(1);
417 glNewList(displist, GL_COMPILE_AND_EXECUTE);
421 qobj = gluNewQuadric();
422 gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
423 gluDisk(qobj, 0.0, 0.05, 16, 1);
425 glRotatef(90, 0, 1, 0);
426 gluDisk(qobj, 0.0, 0.05, 16, 1);
428 glRotatef(90, 1, 0, 0);
429 gluDisk(qobj, 0.0, 0.05, 16, 1);
431 gluDeleteQuadric(qobj);
437 glCallList(displist);
440 static void draw_bonevert_solid(void)
442 static GLuint displist=0;
447 displist= glGenLists(1);
448 glNewList(displist, GL_COMPILE_AND_EXECUTE);
450 qobj = gluNewQuadric();
451 gluQuadricDrawStyle(qobj, GLU_FILL);
452 glShadeModel(GL_SMOOTH);
453 gluSphere( qobj, 0.05, 8, 5);
454 glShadeModel(GL_FLAT);
455 gluDeleteQuadric(qobj);
460 glCallList(displist);
463 static void draw_bone_octahedral()
465 static GLuint displist=0;
470 displist= glGenLists(1);
471 glNewList(displist, GL_COMPILE_AND_EXECUTE);
473 vec[0][0]= vec[0][1]= vec[0][2]= 0.0;
474 vec[5][0]= vec[5][2]= 0.0; vec[5][1]= 1.0;
476 vec[1][0]= 0.1; vec[1][2]= 0.1; vec[1][1]= 0.1;
477 vec[2][0]= 0.1; vec[2][2]= -0.1; vec[2][1]= 0.1;
478 vec[3][0]= -0.1; vec[3][2]= -0.1; vec[3][1]= 0.1;
479 vec[4][0]= -0.1; vec[4][2]= 0.1; vec[4][1]= 0.1;
481 /* Section 1, sides */
482 glBegin(GL_LINE_LOOP);
493 /* Section 1, square */
494 glBegin(GL_LINE_LOOP);
504 glCallList(displist);
507 static void draw_bone_solid_octahedral(void)
509 static GLuint displist=0;
512 float vec[6][3], nor[3];
514 displist= glGenLists(1);
515 glNewList(displist, GL_COMPILE_AND_EXECUTE);
517 vec[0][0]= vec[0][1]= vec[0][2]= 0.0;
518 vec[5][0]= vec[5][2]= 0.0; vec[5][1]= 1.0;
520 vec[1][0]= 0.1; vec[1][2]= 0.1; vec[1][1]= 0.1;
521 vec[2][0]= 0.1; vec[2][2]= -0.1; vec[2][1]= 0.1;
522 vec[3][0]= -0.1; vec[3][2]= -0.1; vec[3][1]= 0.1;
523 vec[4][0]= -0.1; vec[4][2]= 0.1; vec[4][1]= 0.1;
526 glBegin(GL_TRIANGLES);
528 CalcNormFloat(vec[2], vec[1], vec[0], nor);
530 glVertex3fv(vec[2]);glVertex3fv(vec[1]);glVertex3fv(vec[0]);
532 CalcNormFloat(vec[3], vec[2], vec[0], nor);
534 glVertex3fv(vec[3]);glVertex3fv(vec[2]);glVertex3fv(vec[0]);
536 CalcNormFloat(vec[4], vec[3], vec[0], nor);
538 glVertex3fv(vec[4]);glVertex3fv(vec[3]);glVertex3fv(vec[0]);
540 CalcNormFloat(vec[1], vec[4], vec[0], nor);
542 glVertex3fv(vec[1]);glVertex3fv(vec[4]);glVertex3fv(vec[0]);
545 CalcNormFloat(vec[5], vec[1], vec[2], nor);
547 glVertex3fv(vec[5]);glVertex3fv(vec[1]);glVertex3fv(vec[2]);
549 CalcNormFloat(vec[5], vec[2], vec[3], nor);
551 glVertex3fv(vec[5]);glVertex3fv(vec[2]);glVertex3fv(vec[3]);
553 CalcNormFloat(vec[5], vec[3], vec[4], nor);
555 glVertex3fv(vec[5]);glVertex3fv(vec[3]);glVertex3fv(vec[4]);
557 CalcNormFloat(vec[5], vec[4], vec[1], nor);
559 glVertex3fv(vec[5]);glVertex3fv(vec[4]);glVertex3fv(vec[1]);
566 glCallList(displist);
569 /* *************** Armature drawing, bones ******************* */
572 static void draw_bone_points(int dt, int armflag, unsigned int boneflag, int id)
574 /* Draw root point if we are not connected */
575 if ((boneflag & BONE_CONNECTED)==0) {
577 glLoadName(id | BONESEL_ROOT);
580 if (armflag & ARM_EDITMODE) {
581 if (boneflag & BONE_ROOTSEL) UI_ThemeColor(TH_VERTEX_SELECT);
582 else UI_ThemeColor(TH_VERTEX);
586 if (armflag & ARM_POSEMODE)
587 set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, 0);
589 UI_ThemeColor(TH_BONE_SOLID);
593 draw_bonevert_solid();
600 glLoadName(id | BONESEL_TIP);
603 if (armflag & ARM_EDITMODE) {
604 if (boneflag & BONE_TIPSEL) UI_ThemeColor(TH_VERTEX_SELECT);
605 else UI_ThemeColor(TH_VERTEX);
609 if (armflag & ARM_POSEMODE)
610 set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, 0);
612 UI_ThemeColor(TH_BONE_SOLID);
615 glTranslatef(0.0, 1.0, 0.0);
617 draw_bonevert_solid();
620 glTranslatef(0.0, -1.0, 0.0);
624 /* 16 values of sin function (still same result!) */
625 static float si[16] = {
627 0.20129852, 0.39435585,
628 0.57126821, 0.72479278,
629 0.84864425, 0.93775213,
630 0.98846832, 0.99871650,
631 0.96807711, 0.89780453,
632 0.79077573, 0.65137248,
633 0.48530196, 0.29936312,
636 /* 16 values of cos function (still same result!) */
637 static float co[16] ={
639 0.97952994, 0.91895781,
640 0.82076344, 0.68896691,
641 0.52896401, 0.34730525,
642 0.15142777, -0.05064916,
643 -0.25065253, -0.44039415,
644 -0.61210598, -0.75875812,
645 -0.87434661, -0.95413925,
651 /* smat, imat = mat & imat to draw screenaligned */
652 static void draw_sphere_bone_dist(float smat[][4], float imat[][4], int boneflag, bPoseChannel *pchan, EditBone *ebone)
654 float head, tail, length, dist;
655 float *headvec, *tailvec, dirvec[3];
657 /* figure out the sizes of spheres */
659 /* this routine doesn't call set_matrix_editbone() that calculates it */
660 ebone->length = VecLenf(ebone->head, ebone->tail);
662 length= ebone->length;
663 tail= ebone->rad_tail;
665 if (ebone->parent && (ebone->flag & BONE_CONNECTED))
666 head= ebone->parent->rad_tail;
668 head= ebone->rad_head;
669 headvec= ebone->head;
670 tailvec= ebone->tail;
673 length= pchan->bone->length;
674 tail= pchan->bone->rad_tail;
675 dist= pchan->bone->dist;
676 if (pchan->parent && (pchan->bone->flag & BONE_CONNECTED))
677 head= pchan->parent->bone->rad_tail;
679 head= pchan->bone->rad_head;
680 headvec= pchan->pose_head;
681 tailvec= pchan->pose_tail;
684 /* ***** draw it ***** */
686 /* move vector to viewspace */
687 VecSubf(dirvec, tailvec, headvec);
688 Mat4Mul3Vecfl(smat, dirvec);
691 /* move vector back */
692 Mat4Mul3Vecfl(imat, dirvec);
694 if (0.0f != Normalize(dirvec)) {
695 float norvec[3], vec1[3], vec2[3], vec[3];
698 //VecMulf(dirvec, head);
699 Crossf(norvec, dirvec, imat[2]);
701 glBegin(GL_QUAD_STRIP);
703 for (a=0; a<16; a++) {
704 vec[0]= - *(si+a) * dirvec[0] + *(co+a) * norvec[0];
705 vec[1]= - *(si+a) * dirvec[1] + *(co+a) * norvec[1];
706 vec[2]= - *(si+a) * dirvec[2] + *(co+a) * norvec[2];
708 vec1[0]= headvec[0] + head*vec[0];
709 vec1[1]= headvec[1] + head*vec[1];
710 vec1[2]= headvec[2] + head*vec[2];
711 vec2[0]= headvec[0] + (head+dist)*vec[0];
712 vec2[1]= headvec[1] + (head+dist)*vec[1];
713 vec2[2]= headvec[2] + (head+dist)*vec[2];
715 glColor4ub(255, 255, 255, 50);
717 //glColor4ub(255, 255, 255, 0);
721 for (a=15; a>=0; a--) {
722 vec[0]= *(si+a) * dirvec[0] + *(co+a) * norvec[0];
723 vec[1]= *(si+a) * dirvec[1] + *(co+a) * norvec[1];
724 vec[2]= *(si+a) * dirvec[2] + *(co+a) * norvec[2];
726 vec1[0]= tailvec[0] + tail*vec[0];
727 vec1[1]= tailvec[1] + tail*vec[1];
728 vec1[2]= tailvec[2] + tail*vec[2];
729 vec2[0]= tailvec[0] + (tail+dist)*vec[0];
730 vec2[1]= tailvec[1] + (tail+dist)*vec[1];
731 vec2[2]= tailvec[2] + (tail+dist)*vec[2];
733 //glColor4ub(255, 255, 255, 50);
735 //glColor4ub(255, 255, 255, 0);
738 /* make it cyclic... */
740 vec[0]= - *(si) * dirvec[0] + *(co) * norvec[0];
741 vec[1]= - *(si) * dirvec[1] + *(co) * norvec[1];
742 vec[2]= - *(si) * dirvec[2] + *(co) * norvec[2];
744 vec1[0]= headvec[0] + head*vec[0];
745 vec1[1]= headvec[1] + head*vec[1];
746 vec1[2]= headvec[2] + head*vec[2];
747 vec2[0]= headvec[0] + (head+dist)*vec[0];
748 vec2[1]= headvec[1] + (head+dist)*vec[1];
749 vec2[2]= headvec[2] + (head+dist)*vec[2];
751 //glColor4ub(255, 255, 255, 50);
753 //glColor4ub(255, 255, 255, 0);
761 /* smat, imat = mat & imat to draw screenaligned */
762 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)
764 float head, tail, length;
765 float *headvec, *tailvec, dirvec[3];
767 /* figure out the sizes of spheres */
769 /* this routine doesn't call set_matrix_editbone() that calculates it */
770 ebone->length = VecLenf(ebone->head, ebone->tail);
772 length= ebone->length;
773 tail= ebone->rad_tail;
774 if (ebone->parent && (boneflag & BONE_CONNECTED))
775 head= ebone->parent->rad_tail;
777 head= ebone->rad_head;
778 headvec= ebone->head;
779 tailvec= ebone->tail;
782 length= pchan->bone->length;
783 tail= pchan->bone->rad_tail;
784 if ((pchan->parent) && (boneflag & BONE_CONNECTED))
785 head= pchan->parent->bone->rad_tail;
787 head= pchan->bone->rad_head;
788 headvec= pchan->pose_head;
789 tailvec= pchan->pose_tail;
792 /* sphere root color */
793 if (armflag & ARM_EDITMODE) {
794 if (boneflag & BONE_ROOTSEL) UI_ThemeColor(TH_VERTEX_SELECT);
795 else UI_ThemeColor(TH_VERTEX);
797 else if (armflag & ARM_POSEMODE)
798 set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
800 /* Draw root point if we are not connected */
801 if ((boneflag & BONE_CONNECTED)==0) {
803 glLoadName(id | BONESEL_ROOT);
805 drawcircball(GL_LINE_LOOP, headvec, head, imat);
809 if (armflag & ARM_EDITMODE) {
810 if (boneflag & BONE_TIPSEL) UI_ThemeColor(TH_VERTEX_SELECT);
811 else UI_ThemeColor(TH_VERTEX);
815 glLoadName(id | BONESEL_TIP);
817 drawcircball(GL_LINE_LOOP, tailvec, tail, imat);
820 if (armflag & ARM_EDITMODE) {
821 if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_SELECT);
822 else UI_ThemeColor(TH_WIRE);
825 VecSubf(dirvec, tailvec, headvec);
827 /* move vector to viewspace */
828 Mat4Mul3Vecfl(smat, dirvec);
831 /* move vector back */
832 Mat4Mul3Vecfl(imat, dirvec);
834 if (0.0f != Normalize(dirvec)) {
835 float norvech[3], norvect[3], vec[3];
837 VECCOPY(vec, dirvec);
839 VecMulf(dirvec, head);
840 Crossf(norvech, dirvec, imat[2]);
843 Crossf(norvect, vec, imat[2]);
846 glLoadName(id | BONESEL_BONE);
849 vec[0]= headvec[0] + norvech[0];
850 vec[1]= headvec[1] + norvech[1];
851 vec[2]= headvec[2] + norvech[2];
853 vec[0]= tailvec[0] + norvect[0];
854 vec[1]= tailvec[1] + norvect[1];
855 vec[2]= tailvec[2] + norvect[2];
857 vec[0]= headvec[0] - norvech[0];
858 vec[1]= headvec[1] - norvech[1];
859 vec[2]= headvec[2] - norvech[2];
861 vec[0]= tailvec[0] - norvect[0];
862 vec[1]= tailvec[1] - norvect[1];
863 vec[2]= tailvec[2] - norvect[2];
870 /* does wire only for outline selecting */
871 static void draw_sphere_bone(int dt, int armflag, int boneflag, int constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
874 float head, tail, length;
878 qobj = gluNewQuadric();
880 /* figure out the sizes of spheres */
882 length= ebone->length;
883 tail= ebone->rad_tail;
884 if (ebone->parent && (boneflag & BONE_CONNECTED))
885 head= ebone->parent->rad_tail;
887 head= ebone->rad_head;
890 length= pchan->bone->length;
891 tail= pchan->bone->rad_tail;
892 if (pchan->parent && (boneflag & BONE_CONNECTED))
893 head= pchan->parent->bone->rad_tail;
895 head= pchan->bone->rad_head;
898 /* move to z-axis space */
899 glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
902 /* set up solid drawing */
903 glEnable(GL_COLOR_MATERIAL);
904 glEnable(GL_LIGHTING);
906 gluQuadricDrawStyle(qobj, GLU_FILL);
907 glShadeModel(GL_SMOOTH);
910 gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
913 /* sphere root color */
914 if (armflag & ARM_EDITMODE) {
915 if (boneflag & BONE_ROOTSEL) UI_ThemeColor(TH_VERTEX_SELECT);
916 else UI_ThemeColorShade(TH_BONE_SOLID, -30);
918 else if (armflag & ARM_POSEMODE)
919 set_pchan_glColor(PCHAN_COLOR_SPHEREBONE_END, armflag, boneflag, constflag);
920 else if (dt==OB_SOLID)
921 UI_ThemeColorShade(TH_BONE_SOLID, -30);
923 /* Draw root point if we are not connected */
924 if ((boneflag & BONE_CONNECTED)==0) {
926 glLoadName(id | BONESEL_ROOT);
927 gluSphere(qobj, head, 16, 10);
931 if (armflag & ARM_EDITMODE) {
932 if (boneflag & BONE_TIPSEL) UI_ThemeColor(TH_VERTEX_SELECT);
933 else UI_ThemeColorShade(TH_BONE_SOLID, -30);
937 glLoadName(id | BONESEL_TIP);
939 glTranslatef(0.0, 0.0, length);
940 gluSphere(qobj, tail, 16, 10);
941 glTranslatef(0.0, 0.0, -length);
944 if (armflag & ARM_EDITMODE) {
945 if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_SELECT);
946 else UI_ThemeColor(TH_BONE_SOLID);
948 else if (armflag & ARM_POSEMODE)
949 set_pchan_glColor(PCHAN_COLOR_SPHEREBONE_BASE, armflag, boneflag, constflag);
950 else if (dt == OB_SOLID)
951 UI_ThemeColor(TH_BONE_SOLID);
953 fac1= (length-head)/length;
954 fac2= (length-tail)/length;
956 if (length > (head+tail)) {
958 glLoadName (id | BONESEL_BONE);
960 glEnable(GL_POLYGON_OFFSET_FILL);
961 glPolygonOffset(-1.0, -1.0);
963 glTranslatef(0.0f, 0.0f, head);
964 gluCylinder(qobj, fac1*head + (1.0f-fac1)*tail, fac2*tail + (1.0f-fac2)*head, length-head-tail, 16, 1);
965 glTranslatef(0.0f, 0.0f, -head);
967 glDisable(GL_POLYGON_OFFSET_FILL);
969 /* draw sphere on extrema */
970 glTranslatef(0.0f, 0.0f, length-tail);
971 gluSphere(qobj, fac2*tail + (1.0f-fac2)*head, 16, 10);
972 glTranslatef(0.0f, 0.0f, -length+tail);
974 glTranslatef(0.0f, 0.0f, head);
975 gluSphere(qobj, fac1*head + (1.0f-fac1)*tail, 16, 10);
978 /* 1 sphere in center */
979 glTranslatef(0.0f, 0.0f, (head + length-tail)/2.0);
980 gluSphere(qobj, fac1*head + (1.0f-fac1)*tail, 16, 10);
985 glShadeModel(GL_FLAT);
986 glDisable(GL_LIGHTING);
987 glDisable(GL_COLOR_MATERIAL);
991 gluDeleteQuadric(qobj);
994 static GLubyte bm_dot6[]= {0x0, 0x18, 0x3C, 0x7E, 0x7E, 0x3C, 0x18, 0x0};
995 static GLubyte bm_dot8[]= {0x3C, 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C};
997 static GLubyte bm_dot5[]= {0x0, 0x0, 0x10, 0x38, 0x7c, 0x38, 0x10, 0x0};
998 static GLubyte bm_dot7[]= {0x0, 0x38, 0x7C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38};
1001 static void draw_line_bone(int armflag, int boneflag, int constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
1005 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1008 length= pchan->bone->length;
1010 length= ebone->length;
1013 glScalef(length, length, length);
1015 /* this chunk not in object mode */
1016 if (armflag & (ARM_EDITMODE|ARM_POSEMODE)) {
1018 if (armflag & ARM_POSEMODE)
1019 set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
1020 else if (armflag & ARM_EDITMODE) {
1021 UI_ThemeColor(TH_WIRE);
1024 /* Draw root point if we are not connected */
1025 if ((boneflag & BONE_CONNECTED)==0) {
1026 if (G.f & G_PICKSEL) { // no bitmap in selection mode, crashes 3d cards...
1027 glLoadName (id | BONESEL_ROOT);
1029 glVertex3f(0.0f, 0.0f, 0.0f);
1033 glRasterPos3f(0.0f, 0.0f, 0.0f);
1034 glBitmap(8, 8, 4, 4, 0, 0, bm_dot8);
1039 glLoadName((GLuint) id|BONESEL_BONE);
1042 glVertex3f(0.0f, 0.0f, 0.0f);
1043 glVertex3f(0.0f, 1.0f, 0.0f);
1047 if (G.f & G_PICKSEL) {
1048 /* no bitmap in selection mode, crashes 3d cards... */
1049 glLoadName(id | BONESEL_TIP);
1051 glVertex3f(0.0f, 1.0f, 0.0f);
1055 glRasterPos3f(0.0f, 1.0f, 0.0f);
1056 glBitmap(8, 8, 4, 4, 0, 0, bm_dot7);
1059 /* further we send no names */
1061 glLoadName(id & 0xFFFF); /* object tag, for bordersel optim */
1063 if (armflag & ARM_POSEMODE)
1064 set_pchan_glColor(PCHAN_COLOR_LINEBONE, armflag, boneflag, constflag);
1069 /*Draw root point if we are not connected */
1070 if ((boneflag & BONE_CONNECTED)==0) {
1071 if ((G.f & G_PICKSEL)==0) {
1072 /* no bitmap in selection mode, crashes 3d cards... */
1073 if (armflag & ARM_EDITMODE) {
1074 if (boneflag & BONE_ROOTSEL) UI_ThemeColor(TH_VERTEX_SELECT);
1075 else UI_ThemeColor(TH_VERTEX);
1077 glRasterPos3f(0.0f, 0.0f, 0.0f);
1078 glBitmap(8, 8, 4, 4, 0, 0, bm_dot6);
1082 if (armflag & ARM_EDITMODE) {
1083 if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_EDGE_SELECT);
1084 else UI_ThemeColorShade(TH_BACK, -30);
1087 glVertex3f(0.0f, 0.0f, 0.0f);
1088 glVertex3f(0.0f, 1.0f, 0.0f);
1092 if ((G.f & G_PICKSEL)==0) {
1093 /* no bitmap in selection mode, crashes 3d cards... */
1094 if (armflag & ARM_EDITMODE) {
1095 if (boneflag & BONE_TIPSEL) UI_ThemeColor(TH_VERTEX_SELECT);
1096 else UI_ThemeColor(TH_VERTEX);
1098 glRasterPos3f(0.0f, 1.0f, 0.0f);
1099 glBitmap(8, 8, 4, 4, 0, 0, bm_dot5);
1107 static void draw_b_bone_boxes(int dt, bPoseChannel *pchan, float xwidth, float length, float zwidth)
1112 segments= pchan->bone->segments;
1114 if ((segments > 1) && (pchan)) {
1115 float dlen= length/(float)segments;
1116 Mat4 *bbone= b_bone_spline_setup(pchan, 0);
1119 for (a=0; a<segments; a++, bbone++) {
1121 glMultMatrixf(bbone->mat);
1122 if (dt==OB_SOLID) drawsolidcube_size(xwidth, dlen, zwidth);
1123 else drawcube_size(xwidth, dlen, zwidth);
1129 if (dt==OB_SOLID) drawsolidcube_size(xwidth, length, zwidth);
1130 else drawcube_size(xwidth, length, zwidth);
1135 static void draw_b_bone(int dt, int armflag, int boneflag, int constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
1137 float xwidth, length, zwidth;
1140 xwidth= pchan->bone->xwidth;
1141 length= pchan->bone->length;
1142 zwidth= pchan->bone->zwidth;
1145 xwidth= ebone->xwidth;
1146 length= ebone->length;
1147 zwidth= ebone->zwidth;
1150 /* draw points only if... */
1151 if (armflag & ARM_EDITMODE) {
1152 /* move to unitspace */
1154 glScalef(length, length, length);
1155 draw_bone_points(dt, armflag, boneflag, id);
1157 length*= 0.95f; // make vertices visible
1160 /* colors for modes */
1161 if (armflag & ARM_POSEMODE) {
1163 set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
1165 set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, constflag);
1167 else if (armflag & ARM_EDITMODE) {
1169 if (boneflag & BONE_ACTIVE) UI_ThemeColor(TH_EDGE_SELECT);
1170 else if (boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_EDGE_SELECT, -20);
1171 else UI_ThemeColor(TH_WIRE);
1174 UI_ThemeColor(TH_BONE_SOLID);
1178 glLoadName ((GLuint) id|BONESEL_BONE);
1181 /* set up solid drawing */
1183 glEnable(GL_COLOR_MATERIAL);
1184 glEnable(GL_LIGHTING);
1186 if (armflag & ARM_POSEMODE)
1187 set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, constflag);
1189 UI_ThemeColor(TH_BONE_SOLID);
1191 draw_b_bone_boxes(OB_SOLID, pchan, xwidth, length, zwidth);
1193 /* disable solid drawing */
1194 glDisable(GL_COLOR_MATERIAL);
1195 glDisable(GL_LIGHTING);
1199 if (armflag & ARM_POSEMODE) {
1201 /* set constraint colors */
1202 if (set_pchan_glColor(PCHAN_COLOR_CONSTS, armflag, boneflag, constflag)) {
1205 draw_b_bone_boxes(OB_SOLID, pchan, xwidth, length, zwidth);
1207 glDisable(GL_BLEND);
1210 /* restore colors */
1211 set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
1215 draw_b_bone_boxes(OB_WIRE, pchan, xwidth, length, zwidth);
1219 static void draw_bone(int dt, int armflag, int boneflag, int constflag, unsigned int id, float length)
1222 /* Draw a 3d octahedral bone, we use normalized space based on length,
1223 for glDisplayLists */
1225 glScalef(length, length, length);
1227 /* set up solid drawing */
1229 glEnable(GL_COLOR_MATERIAL);
1230 glEnable(GL_LIGHTING);
1231 UI_ThemeColor(TH_BONE_SOLID);
1234 /* colors for posemode */
1235 if (armflag & ARM_POSEMODE) {
1237 set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
1239 set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, constflag);
1243 draw_bone_points(dt, armflag, boneflag, id);
1245 /* now draw the bone itself */
1247 glLoadName((GLuint) id|BONESEL_BONE);
1251 if (dt <= OB_WIRE) {
1253 if (armflag & ARM_EDITMODE) {
1254 if (boneflag & BONE_ACTIVE) UI_ThemeColor(TH_EDGE_SELECT);
1255 else if (boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_EDGE_SELECT, -20);
1256 else UI_ThemeColor(TH_WIRE);
1258 else if (armflag & ARM_POSEMODE) {
1260 /* draw constraint colors */
1261 if (set_pchan_glColor(PCHAN_COLOR_CONSTS, armflag, boneflag, constflag)) {
1264 draw_bone_solid_octahedral();
1266 glDisable(GL_BLEND);
1269 /* restore colors */
1270 set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
1273 draw_bone_octahedral();
1277 if (armflag & ARM_POSEMODE)
1278 set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, constflag);
1280 UI_ThemeColor(TH_BONE_SOLID);
1281 draw_bone_solid_octahedral();
1284 /* disable solid drawing */
1286 glDisable(GL_COLOR_MATERIAL);
1287 glDisable(GL_LIGHTING);
1291 static void draw_custom_bone(Scene *scene, View3D *v3d, Object *ob, int dt, int armflag, int boneflag, unsigned int id, float length)
1293 if(ob==NULL) return;
1295 glScalef(length, length, length);
1297 /* colors for posemode */
1298 if (armflag & ARM_POSEMODE) {
1299 set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, 0);
1303 glLoadName((GLuint) id|BONESEL_BONE);
1306 draw_object_instance(scene, v3d, ob, dt, armflag & ARM_POSEMODE);
1310 static void pchan_draw_IK_root_lines(bPoseChannel *pchan, short only_temp)
1313 bPoseChannel *parchan;
1315 for (con= pchan->constraints.first; con; con= con->next) {
1316 if (con->type == CONSTRAINT_TYPE_KINEMATIC && (con->enforce!=0.0)) {
1317 bKinematicConstraint *data = (bKinematicConstraint*)con->data;
1320 /* if only_temp, only draw if it is a temporary ik-chain */
1321 if ((only_temp) && !(data->flag & CONSTRAINT_IK_TEMP))
1327 /* exclude tip from chain? */
1328 if ((data->flag & CONSTRAINT_IK_TIP)==0)
1329 parchan= pchan->parent;
1333 glVertex3fv(parchan->pose_tail);
1335 /* Find the chain's root */
1336 while (parchan->parent) {
1338 if(segcount==data->rootbone || segcount>255) break; // 255 is weak
1339 parchan= parchan->parent;
1342 glVertex3fv(parchan->pose_head);
1350 static void bgl_sphere_project(float ax, float az)
1352 float dir[3], sine, q3;
1354 sine= 1.0f-ax*ax-az*az;
1355 q3= (sine < 0.0f)? 0.0f: 2.0f*sqrt(sine);
1358 dir[1]= 1.0f-2.0f*sine;
1364 static void draw_dof_ellipse(float ax, float az)
1366 static float staticSine[16] = {
1367 0.0, 0.104528463268, 0.207911690818, 0.309016994375,
1368 0.406736643076, 0.5, 0.587785252292, 0.669130606359,
1369 0.743144825477, 0.809016994375, 0.866025403784,
1370 0.913545457643, 0.951056516295, 0.978147600734,
1380 glColor4ub(70, 70, 70, 50);
1384 for(i=1; i<n; i++) {
1388 for(j=1; j<n-i+1; j++) {
1393 glBegin(GL_TRIANGLES);
1394 bgl_sphere_project(ax*px, az*z);
1395 bgl_sphere_project(ax*px, az*pz);
1396 bgl_sphere_project(ax*x, az*pz);
1401 bgl_sphere_project(ax*x, az*z);
1402 bgl_sphere_project(ax*x, az*pz);
1403 bgl_sphere_project(ax*px, az*pz);
1404 bgl_sphere_project(ax*px, az*z);
1413 glDisable(GL_BLEND);
1416 glColor3ub(0, 0, 0);
1418 glBegin(GL_LINE_STRIP);
1420 bgl_sphere_project(staticSine[n-i-1]*ax, staticSine[i]*az);
1424 static void draw_pose_dofs(Object *ob)
1426 bArmature *arm= ob->data;
1427 bPoseChannel *pchan;
1430 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1433 if ( (bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
1434 if (bone->flag & BONE_SELECTED) {
1435 if (bone->layer & arm->layer) {
1436 if (pchan->ikflag & (BONE_IK_XLIMIT|BONE_IK_ZLIMIT)) {
1437 if (pose_channel_in_IK_chain(ob, pchan)) {
1438 float corner[4][3], posetrans[3], mat[4][4];
1439 float phi=0.0f, theta=0.0f, scale;
1442 /* in parent-bone pose, but own restspace */
1445 VECCOPY(posetrans, pchan->pose_mat[3]);
1446 glTranslatef(posetrans[0], posetrans[1], posetrans[2]);
1448 if (pchan->parent) {
1449 Mat4CpyMat4(mat, pchan->parent->pose_mat);
1450 mat[3][0]= mat[3][1]= mat[3][2]= 0.0f;
1454 Mat4CpyMat3(mat, pchan->bone->bone_mat);
1457 scale= bone->length*pchan->size[1];
1458 glScalef(scale, scale, scale);
1460 if (pchan->ikflag & BONE_IK_XLIMIT) {
1461 if (pchan->ikflag & BONE_IK_ZLIMIT) {
1462 float amin[3], amax[3];
1464 for (i=0; i<3; i++) {
1465 amin[i]= sin(pchan->limitmin[i]*M_PI/360.0);
1466 amax[i]= sin(pchan->limitmax[i]*M_PI/360.0);
1469 glScalef(1.0, -1.0, 1.0);
1470 if (amin[0] != 0.0 && amin[2] != 0.0)
1471 draw_dof_ellipse(amin[0], amin[2]);
1472 if (amin[0] != 0.0 && amax[2] != 0.0)
1473 draw_dof_ellipse(amin[0], amax[2]);
1474 if (amax[0] != 0.0 && amin[2] != 0.0)
1475 draw_dof_ellipse(amax[0], amin[2]);
1476 if (amax[0] != 0.0 && amax[2] != 0.0)
1477 draw_dof_ellipse(amax[0], amax[2]);
1478 glScalef(1.0, -1.0, 1.0);
1483 if (pchan->ikflag & BONE_IK_ZLIMIT) {
1484 theta= 0.5*(pchan->limitmin[2]+pchan->limitmax[2]);
1485 glRotatef(theta, 0.0f, 0.0f, 1.0f);
1487 glColor3ub(50, 50, 255); // blue, Z axis limit
1488 glBegin(GL_LINE_STRIP);
1489 for (a=-16; a<=16; a++) {
1490 float fac= ((float)a)/16.0f;
1491 phi= fac*(M_PI/360.0f)*(pchan->limitmax[2]-pchan->limitmin[2]);
1493 i= (a == -16) ? 0 : 1;
1494 corner[i][0]= sin(phi);
1495 corner[i][1]= cos(phi);
1497 glVertex3fv(corner[i]);
1501 glRotatef(-theta, 0.0f, 0.0f, 1.0f);
1504 if (pchan->ikflag & BONE_IK_XLIMIT) {
1505 theta= 0.5*(pchan->limitmin[0]+pchan->limitmax[0]);
1506 glRotatef(theta, 1.0f, 0.0f, 0.0f);
1508 glColor3ub(255, 50, 50); // Red, X axis limit
1509 glBegin(GL_LINE_STRIP);
1510 for (a=-16; a<=16; a++) {
1511 float fac= ((float)a)/16.0f;
1512 phi= 0.5f*M_PI + fac*(M_PI/360.0f)*(pchan->limitmax[0]-pchan->limitmin[0]);
1514 i= (a == -16) ? 2 : 3;
1516 corner[i][1]= sin(phi);
1517 corner[i][2]= cos(phi);
1518 glVertex3fv(corner[i]);
1522 glRotatef(-theta, 1.0f, 0.0f, 0.0f);
1525 /* out of cone, out of bone */
1535 /* assumes object is Armature with pose */
1536 static void draw_pose_channels(Scene *scene, View3D *v3d, Base *base, int dt)
1538 Object *ob= base->object;
1539 bArmature *arm= ob->data;
1540 bPoseChannel *pchan;
1543 float smat[4][4], imat[4][4];
1545 short do_dashed= 3, draw_wire= 0;
1546 short flag, constflag;
1548 /* hacky... prevent outline select from drawing dashed helplines */
1549 glGetFloatv(GL_LINE_WIDTH, &tmp);
1550 if (tmp > 1.1) do_dashed &= ~1;
1551 if (v3d->flag & V3D_HIDE_HELPLINES) do_dashed &= ~2;
1553 /* precalc inverse matrix for drawing screen aligned */
1554 if (arm->drawtype==ARM_ENVELOPE) {
1555 /* precalc inverse matrix for drawing screen aligned */
1557 Mat4MulFloat3(smat[0], 1.0f/VecLength(ob->obmat[0]));
1558 Mat4Invert(imat, smat);
1560 /* and draw blended distances */
1561 if (arm->flag & ARM_POSEMODE) {
1563 //glShadeModel(GL_SMOOTH);
1565 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
1567 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1569 if (bone && !(bone->flag & (BONE_HIDDEN_P|BONE_NO_DEFORM|BONE_HIDDEN_PG))) {
1570 if (bone->flag & (BONE_SELECTED)) {
1571 if (bone->layer & arm->layer)
1572 draw_sphere_bone_dist(smat, imat, bone->flag, pchan, NULL);
1577 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
1578 glDisable(GL_BLEND);
1579 //glShadeModel(GL_FLAT);
1583 /* little speedup, also make sure transparent only draws once */
1584 glCullFace(GL_BACK);
1585 glEnable(GL_CULL_FACE);
1587 /* if solid we draw that first, with selection codes, but without names, axes etc */
1589 if (arm->flag & ARM_POSEMODE)
1590 index= base->selcol;
1592 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1595 if ( (bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)) ) {
1596 if (bone->layer & arm->layer) {
1598 glMultMatrixf(pchan->pose_mat);
1600 /* catch exception for bone with hidden parent */
1602 if ( (bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)) )
1603 flag &= ~BONE_CONNECTED;
1605 /* set color-set to use */
1606 set_pchan_colorset(ob, pchan);
1608 if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM)) {
1609 /* if drawwire, don't try to draw in solid */
1610 if (pchan->bone->flag & BONE_DRAWWIRE)
1613 draw_custom_bone(scene, v3d, pchan->custom, OB_SOLID, arm->flag, flag, index, bone->length);
1615 else if (arm->drawtype==ARM_LINE)
1616 ; /* nothing in solid */
1617 else if (arm->drawtype==ARM_ENVELOPE)
1618 draw_sphere_bone(OB_SOLID, arm->flag, flag, 0, index, pchan, NULL);
1619 else if (arm->drawtype==ARM_B_BONE)
1620 draw_b_bone(OB_SOLID, arm->flag, flag, 0, index, pchan, NULL);
1622 draw_bone(OB_SOLID, arm->flag, flag, 0, index, bone->length);
1629 index+= 0x10000; // pose bones count in higher 2 bytes only
1632 /* very very confusing... but in object mode, solid draw, we cannot do glLoadName yet,
1633 * stick bones and/or wire custom-shapes are drawn in next loop
1635 if ((arm->drawtype != ARM_LINE) && (draw_wire == 0)) {
1636 /* object tag, for bordersel optim */
1637 glLoadName(index & 0xFFFF);
1642 /* draw custom bone shapes as wireframes */
1643 if ( !(arm->flag & ARM_NO_CUSTOM) &&
1644 ((draw_wire) || (dt <= OB_WIRE)) )
1646 if (arm->flag & ARM_POSEMODE)
1647 index= base->selcol;
1649 /* only draw custom bone shapes that need to be drawn as wires */
1650 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1653 if ((bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
1654 if (bone->layer & arm->layer) {
1655 if (pchan->custom) {
1656 if ((dt < OB_SOLID) || (bone->flag & BONE_DRAWWIRE)) {
1658 glMultMatrixf(pchan->pose_mat);
1660 /* prepare colors */
1661 if (arm->flag & ARM_POSEMODE)
1662 set_pchan_colorset(ob, pchan);
1664 if ((scene->basact)==base) {
1665 if (base->flag & (SELECT+BA_WAS_SEL)) UI_ThemeColor(TH_ACTIVE);
1666 else UI_ThemeColor(TH_WIRE);
1669 if (base->flag & (SELECT+BA_WAS_SEL)) UI_ThemeColor(TH_SELECT);
1670 else UI_ThemeColor(TH_WIRE);
1674 /* catch exception for bone with hidden parent */
1676 if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)))
1677 flag &= ~BONE_CONNECTED;
1679 draw_custom_bone(scene, v3d, pchan->custom, OB_WIRE, arm->flag, flag, index, bone->length);
1688 index+= 0x10000; // pose bones count in higher 2 bytes only
1692 /* object tag, for bordersel optim */
1693 glLoadName(index & 0xFFFF);
1698 /* wire draw over solid only in posemode */
1699 if ((dt <= OB_WIRE) || (arm->flag & ARM_POSEMODE) || (arm->drawtype==ARM_LINE)) {
1700 /* draw line check first. we do selection indices */
1701 if (arm->drawtype==ARM_LINE) {
1702 if (arm->flag & ARM_POSEMODE)
1703 index= base->selcol;
1705 /* if solid && posemode, we draw again with polygonoffset */
1706 else if ((dt > OB_WIRE) && (arm->flag & ARM_POSEMODE)) {
1707 bglPolygonOffset(v3d->dist, 1.0);
1710 /* and we use selection indices if not done yet */
1711 if (arm->flag & ARM_POSEMODE)
1712 index= base->selcol;
1715 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1718 if ((bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
1719 if (bone->layer & arm->layer) {
1720 if ((do_dashed & 1) && (bone->parent)) {
1721 /* Draw a line from our root to the parent's tip
1722 * - only if V3D_HIDE_HELPLINES is enabled...
1724 if ( (do_dashed & 2) && ((bone->flag & BONE_CONNECTED)==0) ) {
1725 if (arm->flag & ARM_POSEMODE) {
1726 glLoadName(index & 0xFFFF); // object tag, for bordersel optim
1727 UI_ThemeColor(TH_WIRE);
1731 glVertex3fv(pchan->pose_head);
1732 glVertex3fv(pchan->parent->pose_tail);
1737 /* Draw a line to IK root bone
1738 * - only if temporary chain (i.e. "autoik")
1740 if (arm->flag & ARM_POSEMODE) {
1741 if (pchan->constflag & PCHAN_HAS_IK) {
1742 if (bone->flag & BONE_SELECTED) {
1743 if (pchan->constflag & PCHAN_HAS_TARGET) glColor3ub(200, 120, 0);
1744 else glColor3ub(200, 200, 50); // add theme!
1746 glLoadName(index & 0xFFFF);
1747 pchan_draw_IK_root_lines(pchan, !(do_dashed & 2));
1754 if (arm->drawtype != ARM_ENVELOPE)
1755 glMultMatrixf(pchan->pose_mat);
1757 /* catch exception for bone with hidden parent */
1759 if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)))
1760 flag &= ~BONE_CONNECTED;
1762 /* extra draw service for pose mode */
1763 constflag= pchan->constflag;
1764 if (pchan->flag & (POSE_ROT|POSE_LOC|POSE_SIZE))
1765 constflag |= PCHAN_HAS_ACTION;
1766 if (pchan->flag & POSE_STRIDE)
1767 constflag |= PCHAN_HAS_STRIDE;
1769 /* set color-set to use */
1770 set_pchan_colorset(ob, pchan);
1772 if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM))
1773 ; // custom bone shapes should not be drawn here!
1774 else if (arm->drawtype==ARM_ENVELOPE) {
1776 draw_sphere_bone_wire(smat, imat, arm->flag, flag, constflag, index, pchan, NULL);
1778 else if (arm->drawtype==ARM_LINE)
1779 draw_line_bone(arm->flag, flag, constflag, index, pchan, NULL);
1780 else if (arm->drawtype==ARM_B_BONE)
1781 draw_b_bone(OB_WIRE, arm->flag, flag, constflag, index, pchan, NULL);
1783 draw_bone(OB_WIRE, arm->flag, flag, constflag, index, bone->length);
1789 /* pose bones count in higher 2 bytes only */
1793 /* restore things */
1794 if ((arm->drawtype!=ARM_LINE)&& (dt>OB_WIRE) && (arm->flag & ARM_POSEMODE))
1795 bglPolygonOffset(v3d->dist, 0.0);
1799 glDisable(GL_CULL_FACE);
1802 if (arm->flag & ARM_POSEMODE)
1805 /* finally names and axes */
1806 if (arm->flag & (ARM_DRAWNAMES|ARM_DRAWAXES)) {
1807 /* patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing */
1808 if ((G.f & G_PICKSEL) == 0) {
1811 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
1813 for (pchan=ob->pose->chanbase.first; pchan; pchan=pchan->next) {
1814 if ((pchan->bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))==0) {
1815 if (pchan->bone->layer & arm->layer) {
1816 if (arm->flag & (ARM_EDITMODE|ARM_POSEMODE)) {
1819 if (bone->flag & BONE_SELECTED) UI_ThemeColor(TH_TEXT_HI);
1820 else UI_ThemeColor(TH_TEXT);
1822 else if (dt > OB_WIRE)
1823 UI_ThemeColor(TH_TEXT);
1825 /* Draw names of bone */
1826 if (arm->flag & ARM_DRAWNAMES) {
1827 VecMidf(vec, pchan->pose_head, pchan->pose_tail);
1828 glRasterPos3fv(vec);
1829 BMF_DrawString(G.font, " ");
1830 BMF_DrawString(G.font, pchan->name);
1833 /* Draw additional axes on the bone tail */
1834 if ( (arm->flag & ARM_DRAWAXES) && (arm->flag & ARM_POSEMODE) ) {
1836 glMultMatrixf(pchan->pose_mat);
1837 glTranslatef(0.0f, pchan->bone->length, 0.0f);
1838 drawaxes(0.25f*pchan->bone->length, 0, OB_ARROWS);
1845 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
1850 /* in editmode, we don't store the bone matrix... */
1851 static void set_matrix_editbone(EditBone *eBone)
1853 float delta[3],offset[3];
1854 float mat[3][3], bmat[4][4];
1856 /* Compose the parent transforms (i.e. their translations) */
1857 VECCOPY(offset, eBone->head);
1859 glTranslatef(offset[0],offset[1],offset[2]);
1861 VecSubf(delta, eBone->tail, eBone->head);
1863 eBone->length = sqrt (delta[0]*delta[0] + delta[1]*delta[1] +delta[2]*delta[2]);
1865 vec_roll_to_mat3(delta, eBone->roll, mat);
1866 Mat4CpyMat3(bmat, mat);
1868 glMultMatrixf(bmat);
1872 static void draw_ebones(View3D *v3d, Object *ob, int dt)
1875 bArmature *arm= ob->data;
1876 float smat[4][4], imat[4][4];
1880 /* envelope (deform distance) */
1881 if(arm->drawtype==ARM_ENVELOPE) {
1882 /* precalc inverse matrix for drawing screen aligned */
1884 Mat4MulFloat3(smat[0], 1.0f/VecLength(ob->obmat[0]));
1885 Mat4Invert(imat, smat);
1887 /* and draw blended distances */
1889 //glShadeModel(GL_SMOOTH);
1891 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
1893 for (eBone=G.edbo.first, index=0; eBone; eBone=eBone->next, index++) {
1894 if (eBone->layer & arm->layer) {
1895 if ((eBone->flag & (BONE_HIDDEN_A|BONE_NO_DEFORM))==0) {
1896 if (eBone->flag & (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL))
1897 draw_sphere_bone_dist(smat, imat, eBone->flag, NULL, eBone);
1902 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
1903 glDisable(GL_BLEND);
1904 //glShadeModel(GL_FLAT);
1907 /* if solid we draw it first */
1908 if ((dt > OB_WIRE) && (arm->drawtype!=ARM_LINE)) {
1910 for (eBone=G.edbo.first, index=0; eBone; eBone=eBone->next, index++) {
1911 if (eBone->layer & arm->layer) {
1912 if ((eBone->flag & BONE_HIDDEN_A)==0) {
1914 set_matrix_editbone(eBone);
1916 /* catch exception for bone with hidden parent */
1918 if ( (eBone->parent) && ((eBone->parent->flag & BONE_HIDDEN_A) || (eBone->parent->layer & arm->layer)==0) )
1919 flag &= ~BONE_CONNECTED;
1921 if (arm->drawtype==ARM_ENVELOPE)
1922 draw_sphere_bone(OB_SOLID, arm->flag, flag, 0, index, NULL, eBone);
1923 else if(arm->drawtype==ARM_B_BONE)
1924 draw_b_bone(OB_SOLID, arm->flag, flag, 0, index, NULL, eBone);
1926 draw_bone(OB_SOLID, arm->flag, flag, 0, index, eBone->length);
1935 /* if wire over solid, set offset */
1938 if (arm->drawtype==ARM_LINE) {
1942 else if (dt > OB_WIRE)
1943 bglPolygonOffset(v3d->dist, 1.0);
1944 else if (arm->flag & ARM_EDITMODE)
1945 index= 0; /* do selection codes */
1947 for (eBone=G.edbo.first; eBone; eBone=eBone->next) {
1948 if (eBone->layer & arm->layer) {
1949 if ((eBone->flag & BONE_HIDDEN_A)==0) {
1951 /* catch exception for bone with hidden parent */
1953 if ( (eBone->parent) && ((eBone->parent->flag & BONE_HIDDEN_A) || (eBone->parent->layer & arm->layer)==0) )
1954 flag &= ~BONE_CONNECTED;
1956 if (arm->drawtype == ARM_ENVELOPE) {
1958 draw_sphere_bone_wire(smat, imat, arm->flag, flag, 0, index, NULL, eBone);
1962 set_matrix_editbone(eBone);
1964 if (arm->drawtype == ARM_LINE)
1965 draw_line_bone(arm->flag, flag, 0, index, NULL, eBone);
1966 else if (arm->drawtype == ARM_B_BONE)
1967 draw_b_bone(OB_WIRE, arm->flag, flag, 0, index, NULL, eBone);
1969 draw_bone(OB_WIRE, arm->flag, flag, 0, index, eBone->length);
1974 /* offset to parent */
1975 if (eBone->parent) {
1976 UI_ThemeColor(TH_WIRE);
1977 glLoadName (-1); // -1 here is OK!
1981 glVertex3fv(eBone->parent->tail);
1982 glVertex3fv(eBone->head);
1989 if(index!=-1) index++;
1993 if (arm->drawtype==ARM_LINE);
1994 else if (dt>OB_WIRE) bglPolygonOffset(v3d->dist, 0.0);
1996 /* finally names and axes */
1997 if (arm->flag & (ARM_DRAWNAMES|ARM_DRAWAXES)) {
1998 // patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing
1999 if ((G.f & G_PICKSEL) == 0) {
2002 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
2004 for (eBone=G.edbo.first, index=0; eBone; eBone=eBone->next, index++) {
2005 if(eBone->layer & arm->layer) {
2006 if ((eBone->flag & BONE_HIDDEN_A)==0) {
2008 if (eBone->flag & BONE_SELECTED) UI_ThemeColor(TH_TEXT_HI);
2009 else UI_ThemeColor(TH_TEXT);
2012 if (arm->flag & ARM_DRAWNAMES) {
2013 VecMidf(vec, eBone->head, eBone->tail);
2014 glRasterPos3fv(vec);
2015 BMF_DrawString(G.font, " ");
2016 BMF_DrawString(G.font, eBone->name);
2018 /* Draw additional axes */
2019 if (arm->flag & ARM_DRAWAXES) {
2021 set_matrix_editbone(eBone);
2022 glTranslatef(0.0f, eBone->length, 0.0f);
2023 drawaxes(eBone->length*0.25f, 0, OB_ARROWS);
2031 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
2036 /* ****************************** Armature Visualisation ******************************** */
2038 /* ---------- Paths --------- */
2043 static void draw_pose_paths(View3D *v3d, Object *ob)
2045 bArmature *arm= ob->data;
2046 bPoseChannel *pchan;
2048 bActionChannel *achan;
2051 float *fp, *fp_start;
2053 int sfra, efra, len;
2055 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
2058 glLoadMatrixf(v3d->viewmat);
2060 /* version patch here - cannot access frame info from file reading */
2061 if (arm->pathsize == 0) arm->pathsize= 1;
2062 stepsize = arm->pathsize;
2064 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
2065 if (pchan->bone->layer & arm->layer) {
2067 /* version patch here - cannot access frame info from file reading */
2068 if ((pchan->pathsf == 0) || (pchan->pathef == 0)) {
2069 pchan->pathsf= SFRA;
2070 pchan->pathef= EFRA;
2073 /* get frame ranges */
2074 if (arm->pathflag & ARM_PATH_ACFRA) {
2077 /* With "Around Current", we only choose frames from around
2078 * the current frame to draw. However, this range is still
2079 * restricted by the limits of the original path.
2081 sfra= CFRA - arm->pathbc;
2082 efra= CFRA + arm->pathac;
2083 if (sfra < pchan->pathsf) sfra= pchan->pathsf;
2084 if (efra > pchan->pathef) efra= pchan->pathef;
2088 sind= sfra - pchan->pathsf;
2089 fp_start= (pchan->path + (3*sind));
2092 sfra= pchan->pathsf;
2093 efra = sfra + pchan->pathlen;
2094 len = pchan->pathlen;
2095 fp_start = pchan->path;
2098 /* draw curve-line of path */
2099 glShadeModel(GL_SMOOTH);
2101 glBegin(GL_LINE_STRIP);
2102 for (a=0, fp=fp_start; a<len; a++, fp+=3) {
2103 float intensity; /* how faint */
2106 * - more intense for active/selected bones, less intense for unselected bones
2107 * - black for before current frame, green for current frame, blue for after current frame
2108 * - intensity decreases as distance from current frame increases
2110 #define SET_INTENSITY(A, B, C, min, max) (((1.0f - ((C - B) / (C - A))) * (max-min)) + min)
2111 if ((a+sfra) < CFRA) {
2112 /* black - before cfra */
2113 if (pchan->bone->flag & BONE_SELECTED) {
2115 intensity = SET_INTENSITY(sfra, a, CFRA, 0.25f, 0.75f);
2119 intensity = SET_INTENSITY(sfra, a, CFRA, 0.68f, 0.92f);
2121 UI_ThemeColorBlend(TH_WIRE, TH_BACK, intensity);
2123 else if ((a+sfra) > CFRA) {
2124 /* blue - after cfra */
2125 if (pchan->bone->flag & BONE_SELECTED) {
2127 intensity = SET_INTENSITY(CFRA, a, efra, 0.25f, 0.75f);
2131 intensity = SET_INTENSITY(CFRA, a, efra, 0.68f, 0.92f);
2133 UI_ThemeColorBlend(TH_BONE_POSE, TH_BACK, intensity);
2136 /* green - on cfra */
2137 if (pchan->bone->flag & BONE_SELECTED) {
2143 UI_ThemeColorBlendShade(TH_CFRAME, TH_BACK, intensity, 10);
2146 /* draw a vertex with this color */
2151 glShadeModel(GL_FLAT);
2155 /* draw little black point at each frame
2156 * NOTE: this is not really visible/noticable
2159 for (a=0, fp=fp_start; a<len; a++, fp+=3)
2163 /* Draw little white dots at each framestep value */
2164 UI_ThemeColor(TH_TEXT_HI);
2166 for (a=0, fp=fp_start; a<len; a+=stepsize, fp+=(stepsize*3))
2170 /* Draw frame numbers at each framestep value */
2171 if (arm->pathflag & ARM_PATH_FNUMS) {
2172 for (a=0, fp=fp_start; a<len; a+=stepsize, fp+=(stepsize*3)) {
2175 /* only draw framenum if several consecutive highlighted points don't occur on same point */
2178 sprintf(str, " %d\n", (a+sfra));
2179 BMF_DrawString(G.font, str);
2181 else if ((a > stepsize) && (a < len-stepsize)) {
2182 if ((VecEqual(fp, fp-(stepsize*3))==0) || (VecEqual(fp, fp+(stepsize*3))==0)) {
2184 sprintf(str, " %d\n", (a+sfra));
2185 BMF_DrawString(G.font, str);
2191 /* Keyframes - dots and numbers */
2192 if (arm->pathflag & ARM_PATH_KFRAS) {
2193 /* build list of all keyframes in active action for pchan */
2194 keys.first = keys.last = NULL;
2195 act= ob_get_action(ob);
2197 achan= get_action_channel(act, pchan->name);
2199 ipo_to_keylist(achan->ipo, &keys, NULL, NULL);
2202 /* Draw slightly-larger yellow dots at each keyframe */
2203 UI_ThemeColor(TH_VERTEX_SELECT);
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))
2217 /* Draw frame numbers of keyframes */
2218 if ((arm->pathflag & ARM_PATH_FNUMS) || (arm->pathflag & ARM_PATH_KFNOS)) {
2219 for(a=0, fp=fp_start; a<len; a++, fp+=3) {
2220 for (ak= keys.first; ak; ak= ak->next) {
2221 if (ak->cfra == (a+sfra)) {
2225 sprintf(str, " %d\n", (a+sfra));
2226 BMF_DrawString(G.font, str);
2232 BLI_freelistN(&keys);
2238 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
2243 /* ---------- Ghosts --------- */
2245 /* helper function for ghost drawing - sets/removes flags for temporarily
2246 * hiding unselected bones while drawing ghosts
2248 static void ghost_poses_tag_unselected(Object *ob, short unset)
2250 bArmature *arm= ob->data;
2251 bPose *pose= ob->pose;
2252 bPoseChannel *pchan;
2254 /* don't do anything if no hiding any bones */
2255 if ((arm->flag & ARM_GHOST_ONLYSEL)==0)
2258 /* loop over all pchans, adding/removing tags as appropriate */
2259 for (pchan= pose->chanbase.first; pchan; pchan= pchan->next) {
2260 if ((pchan->bone) && (arm->layer & pchan->bone->layer)) {
2262 /* remove tags from all pchans if cleaning up */
2263 pchan->bone->flag &= ~BONE_HIDDEN_PG;
2266 /* set tags on unselected pchans only */
2267 if ((pchan->bone->flag & BONE_SELECTED)==0)
2268 pchan->bone->flag |= BONE_HIDDEN_PG;
2274 /* draw ghosts that occur within a frame range
2275 * note: object should be in posemode
2277 static void draw_ghost_poses_range(Scene *scene, View3D *v3d, Base *base)
2279 Object *ob= base->object;
2280 bArmature *arm= ob->data;
2281 bPose *posen, *poseo;
2282 float start, end, stepsize, range, colfac;
2283 int cfrao, flago, ipoflago;
2285 start = arm->ghostsf;
2290 stepsize= (float)(arm->ghostsize);
2291 range= (float)(end - start);
2294 ob->flag &= ~OB_POSEMODE;
2297 arm->flag &= ~(ARM_DRAWNAMES|ARM_DRAWAXES);
2298 ipoflago= ob->ipoflag;
2299 ob->ipoflag |= OB_DISABLE_PATH;
2303 copy_pose(&posen, ob->pose, 1);
2305 armature_rebuild_pose(ob, ob->data); /* child pointers for IK */
2306 ghost_poses_tag_unselected(ob, 0); /* hide unselected bones if need be */
2309 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
2311 /* draw from first frame of range to last */
2312 for (CFRA= start; CFRA<end; CFRA+=stepsize) {
2313 colfac = (end-CFRA)/range;
2314 UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0f*sqrt(colfac)));
2316 do_all_pose_actions(ob);
2318 draw_pose_channels(scene, v3d, base, OB_WIRE);
2320 glDisable(GL_BLEND);
2321 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
2323 ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */
2330 armature_rebuild_pose(ob, ob->data);
2331 ob->flag |= OB_POSEMODE;
2332 ob->ipoflag= ipoflago;
2335 /* draw ghosts on keyframes in action within range
2336 * - object should be in posemode
2338 static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, Base *base)
2340 Object *ob= base->object;
2341 bAction *act= ob_get_action(ob);
2342 bArmature *arm= ob->data;
2343 bPose *posen, *poseo;
2344 ListBase keys= {NULL, NULL};
2345 ActKeysInc aki = {0, 0, 0};
2346 ActKeyColumn *ak, *akn;
2347 float start, end, range, colfac, i;
2348 int cfrao, flago, ipoflago;
2350 aki.start= start = arm->ghostsf;
2351 aki.end= end = arm->ghostef;
2355 /* get keyframes - then clip to only within range */
2356 action_to_keylist(act, &keys, NULL, &aki);
2358 for (ak= keys.first; ak; ak= akn) {
2361 if ((ak->cfra < start) || (ak->cfra > end))
2362 BLI_freelinkN(&keys, ak);
2366 if (range == 0) return;
2369 ob->flag &= ~OB_POSEMODE;
2372 arm->flag &= ~(ARM_DRAWNAMES|ARM_DRAWAXES);
2373 ipoflago= ob->ipoflag;
2374 ob->ipoflag |= OB_DISABLE_PATH;
2378 copy_pose(&posen, ob->pose, 1);
2380 armature_rebuild_pose(ob, ob->data); /* child pointers for IK */
2381 ghost_poses_tag_unselected(ob, 0); /* hide unselected bones if need be */
2384 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
2386 /* draw from first frame of range to last */
2387 for (ak=keys.first, i=0; ak; ak=ak->next, i++) {
2389 UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0f*sqrt(colfac)));
2391 CFRA= (int)ak->cfra;
2393 do_all_pose_actions(ob);
2395 draw_pose_channels(scene, v3d, base, OB_WIRE);
2397 glDisable(GL_BLEND);
2398 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
2400 ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */
2401 BLI_freelistN(&keys);
2408 armature_rebuild_pose(ob, ob->data);
2409 ob->flag |= OB_POSEMODE;
2410 ob->ipoflag= ipoflago;
2413 /* draw ghosts around current frame
2414 * - object is supposed to be armature in posemode
2416 static void draw_ghost_poses(Scene *scene, View3D *v3d, Base *base)
2418 Object *ob= base->object;
2419 bArmature *arm= ob->data;
2420 bPose *posen, *poseo;
2421 bActionStrip *strip;
2422 float cur, start, end, stepsize, range, colfac, actframe, ctime;
2423 int cfrao, maptime, flago, ipoflago;
2425 /* pre conditions, get an action with sufficient frames */
2426 if (ob->action==NULL)
2429 calc_action_range(ob->action, &start, &end, 0);
2433 stepsize= (float)(arm->ghostsize);
2434 range= (float)(arm->ghostep)*stepsize + 0.5f; /* plus half to make the for loop end correct */
2436 /* we only map time for armature when an active strip exists */
2437 for (strip=ob->nlastrips.first; strip; strip=strip->next)
2438 if (strip->flag & ACTSTRIP_ACTIVE)
2441 maptime= (strip!=NULL);
2444 ob->flag &= ~OB_POSEMODE;
2446 if (maptime) actframe= get_action_frame(ob, (float)CFRA);
2447 else actframe= CFRA;
2449 arm->flag &= ~(ARM_DRAWNAMES|ARM_DRAWAXES);
2450 ipoflago= ob->ipoflag;
2451 ob->ipoflag |= OB_DISABLE_PATH;
2455 copy_pose(&posen, ob->pose, 1);
2457 armature_rebuild_pose(ob, ob->data); /* child pointers for IK */
2458 ghost_poses_tag_unselected(ob, 0); /* hide unselected bones if need be */
2461 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
2463 /* draw from darkest blend to lowest */
2464 for(cur= stepsize; cur<range; cur+=stepsize) {
2465 ctime= cur - fmod((float)cfrao, stepsize); /* ensures consistant stepping */
2466 colfac= ctime/range;
2467 UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0f*sqrt(colfac)));
2469 /* only within action range */
2470 if (actframe+ctime >= start && actframe+ctime <= end) {
2471 if (maptime) CFRA= (int)get_action_frame_inv(ob, actframe+ctime);
2472 else CFRA= (int)floor(actframe+ctime);
2475 do_all_pose_actions(ob);
2477 draw_pose_channels(scene, v3d, base, OB_WIRE);
2481 ctime= cur + fmod((float)cfrao, stepsize) - stepsize+1.0f; /* ensures consistant stepping */
2482 colfac= ctime/range;
2483 UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0f*sqrt(colfac)));
2485 /* only within action range */
2486 if ((actframe-ctime >= start) && (actframe-ctime <= end)) {
2487 if (maptime) CFRA= (int)get_action_frame_inv(ob, actframe-ctime);
2488 else CFRA= (int)floor(actframe-ctime);
2490 if (CFRA != cfrao) {
2491 do_all_pose_actions(ob);
2493 draw_pose_channels(scene, v3d, base, OB_WIRE);
2497 glDisable(GL_BLEND);
2498 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
2500 ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */
2507 armature_rebuild_pose(ob, ob->data);
2508 ob->flag |= OB_POSEMODE;
2509 ob->ipoflag= ipoflago;
2512 /* ********************************** Armature Drawing - Main ************************* */
2514 /* called from drawobject.c, return 1 if nothing was drawn */
2515 int draw_armature(Scene *scene, View3D *v3d, Base *base, int dt, int flag)
2517 Object *ob= base->object;
2518 bArmature *arm= ob->data;
2521 if(G.f & G_RENDER_SHADOW)
2524 if(dt>OB_WIRE && arm->drawtype!=ARM_LINE) {
2525 /* we use color for solid lighting */
2526 glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
2527 glEnable(GL_COLOR_MATERIAL);
2528 glColor3ub(0,0,0); // clear spec
2529 glDisable(GL_COLOR_MATERIAL);
2531 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
2532 glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW); // only for lighting...
2535 /* arm->flag is being used to detect mode... */
2537 if(ob==G.obedit || (G.obedit && ob->data==G.obedit->data)) {
2538 if(ob==G.obedit) arm->flag |= ARM_EDITMODE;
2539 draw_ebones(v3d, ob, dt);
2540 arm->flag &= ~ARM_EDITMODE;
2544 if(ob->pose && ob->pose->chanbase.first) {
2545 /* drawing posemode selection indices or colors only in these cases */
2546 if(!(base->flag & OB_FROMDUPLI)) {
2547 if(G.f & G_PICKSEL) {
2548 if(ob->flag & OB_POSEMODE)
2549 arm->flag |= ARM_POSEMODE;
2551 else if(ob->flag & OB_POSEMODE) {
2552 if (arm->ghosttype == ARM_GHOST_RANGE) {
2553 draw_ghost_poses_range(scene, v3d, base);
2555 else if (arm->ghosttype == ARM_GHOST_KEYS) {
2556 draw_ghost_poses_keys(scene, v3d, base);
2558 else if (arm->ghosttype == ARM_GHOST_CUR) {
2560 draw_ghost_poses(scene, v3d, base);
2562 if ((flag & DRAW_SCENESET)==0) {
2564 arm->flag |= ARM_POSEMODE;
2565 else if(G.f & G_WEIGHTPAINT)
2566 arm->flag |= ARM_POSEMODE;
2568 draw_pose_paths(v3d, ob);
2572 draw_pose_channels(scene, v3d, base, dt);
2573 arm->flag &= ~ARM_POSEMODE;
2575 if(ob->flag & OB_POSEMODE)
2576 UI_ThemeColor(TH_WIRE); /* restore, for extra draw stuff */
2581 glFrontFace(GL_CCW);
2586 /* *************** END Armature drawing ******************* */