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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 *****
35 #include "DNA_anim_types.h"
36 #include "DNA_armature_types.h"
37 #include "DNA_constraint_types.h"
38 #include "DNA_scene_types.h"
39 #include "DNA_screen_types.h"
40 #include "DNA_view3d_types.h"
41 #include "DNA_object_types.h"
43 #include "BLI_blenlib.h"
45 #include "BLI_dlrbTree.h"
46 #include "BLI_utildefines.h"
48 #include "BKE_animsys.h"
49 #include "BKE_action.h"
50 #include "BKE_armature.h"
51 #include "BKE_global.h"
52 #include "BKE_modifier.h"
57 #include "BIF_glutil.h"
59 #include "ED_armature.h"
60 #include "ED_keyframes_draw.h"
64 #include "UI_resources.h"
66 #include "view3d_intern.h"
69 /* *************** Armature Drawing - Coloring API ***************************** */
71 /* global here is reset before drawing each bone */
72 static ThemeWireColor *bcolor= NULL;
74 /* values of colCode for set_pchan_glcolor */
76 PCHAN_COLOR_NORMAL = 0, /* normal drawing */
77 PCHAN_COLOR_SOLID, /* specific case where "solid" color is needed */
78 PCHAN_COLOR_CONSTS, /* "constraint" colors (which may/may-not be suppressed) */
80 PCHAN_COLOR_SPHEREBONE_BASE, /* for the 'stick' of sphere (envelope) bones */
81 PCHAN_COLOR_SPHEREBONE_END, /* for the ends of sphere (envelope) bones */
82 PCHAN_COLOR_LINEBONE /* for the middle of line-bones */
85 /* This function sets the color-set for coloring a certain bone */
86 static void set_pchan_colorset (Object *ob, bPoseChannel *pchan)
88 bPose *pose= (ob) ? ob->pose : NULL;
89 bArmature *arm= (ob) ? ob->data : NULL;
90 bActionGroup *grp= NULL;
94 if (ELEM4(NULL, ob, arm, pose, pchan)) {
99 /* only try to set custom color if enabled for armature */
100 if (arm->flag & ARM_COL_CUSTOM) {
101 /* currently, a bone can only use a custom color set if it's group (if it has one),
102 * has been set to use one
104 if (pchan->agrp_index) {
105 grp= (bActionGroup *)BLI_findlink(&pose->agroups, (pchan->agrp_index - 1));
107 color_index= grp->customCol;
111 /* bcolor is a pointer to the color set to use. If NULL, then the default
112 * color set (based on the theme colors for 3d-view) is used.
114 if (color_index > 0) {
115 bTheme *btheme= U.themes.first;
116 bcolor= &btheme->tarm[(color_index - 1)];
118 else if (color_index == -1) {
119 /* use the group's own custom color set */
120 bcolor= (grp)? &grp->cs : NULL;
126 /* This function is for brightening/darkening a given color (like UI_ThemeColorShade()) */
127 static void cp_shade_color3ub (char cp[], int offset)
131 r= offset + (int) cp[0];
133 g= offset + (int) cp[1];
135 b= offset + (int) cp[2];
143 /* This function sets the gl-color for coloring a certain bone (based on bcolor) */
144 static short set_pchan_glColor (short colCode, int boneflag, int constflag)
147 case PCHAN_COLOR_NORMAL:
152 if (boneflag & BONE_DRAW_ACTIVE) {
153 VECCOPY(cp, bcolor->active);
154 if(!(boneflag & BONE_SELECTED)) {
155 cp_shade_color3ub(cp, -80);
158 else if (boneflag & BONE_SELECTED) {
159 VECCOPY(cp, bcolor->select);
162 /* a bit darker than solid */
163 VECCOPY(cp, bcolor->solid);
164 cp_shade_color3ub(cp, -50);
167 glColor3ub(cp[0], cp[1], cp[2]);
170 if (boneflag & BONE_DRAW_ACTIVE && boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_BONE_POSE, 40);
171 else if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColorBlend(TH_WIRE, TH_BONE_POSE, 0.15f); /* unselected active */
172 else if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_BONE_POSE);
173 else UI_ThemeColor(TH_WIRE);
180 case PCHAN_COLOR_SOLID:
183 char *cp= bcolor->solid;
184 glColor3ub(cp[0], cp[1], cp[2]);
187 UI_ThemeColor(TH_BONE_SOLID);
193 case PCHAN_COLOR_CONSTS:
195 if ( (bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS) ) {
196 if (constflag & PCHAN_HAS_STRIDE) glColor4ub(0, 0, 200, 80);
197 else if (constflag & PCHAN_HAS_TARGET) glColor4ub(255, 150, 0, 80);
198 else if (constflag & PCHAN_HAS_IK) glColor4ub(255, 255, 0, 80);
199 else if (constflag & PCHAN_HAS_SPLINEIK) glColor4ub(200, 255, 0, 80);
200 else if (constflag & PCHAN_HAS_CONST) glColor4ub(0, 255, 120, 80);
201 else if (constflag) UI_ThemeColor4(TH_BONE_POSE); // PCHAN_HAS_ACTION
210 case PCHAN_COLOR_SPHEREBONE_BASE:
215 if (boneflag & BONE_DRAW_ACTIVE) {
216 VECCOPY(cp, bcolor->active);
218 else if (boneflag & BONE_SELECTED) {
219 VECCOPY(cp, bcolor->select);
222 VECCOPY(cp, bcolor->solid);
225 glColor3ub(cp[0], cp[1], cp[2]);
228 if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 40);
229 else if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_BONE_POSE);
230 else UI_ThemeColor(TH_BONE_SOLID);
236 case PCHAN_COLOR_SPHEREBONE_END:
241 if (boneflag & BONE_DRAW_ACTIVE) {
242 VECCOPY(cp, bcolor->active);
243 cp_shade_color3ub(cp, 10);
245 else if (boneflag & BONE_SELECTED) {
246 VECCOPY(cp, bcolor->select);
247 cp_shade_color3ub(cp, -30);
250 VECCOPY(cp, bcolor->solid);
251 cp_shade_color3ub(cp, -30);
254 glColor3ub(cp[0], cp[1], cp[2]);
257 if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 10);
258 else if (boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_BONE_POSE, -30);
259 else UI_ThemeColorShade(TH_BONE_SOLID, -30);
264 case PCHAN_COLOR_LINEBONE:
266 /* inner part in background color or constraint */
267 if ( (constflag) && ((bcolor==NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS)) ) {
268 if (constflag & PCHAN_HAS_STRIDE) glColor3ub(0, 0, 200);
269 else if (constflag & PCHAN_HAS_TARGET) glColor3ub(255, 150, 0);
270 else if (constflag & PCHAN_HAS_IK) glColor3ub(255, 255, 0);
271 else if (constflag & PCHAN_HAS_SPLINEIK) glColor3ub(200, 255, 0);
272 else if (constflag & PCHAN_HAS_CONST) glColor3ub(0, 255, 120);
273 else if (constflag) UI_ThemeColor(TH_BONE_POSE); /* PCHAN_HAS_ACTION */
277 char *cp= bcolor->solid;
278 glColor4ub(cp[0], cp[1], cp[2], 204);
281 UI_ThemeColorShade(TH_BACK, -30);
292 static void set_ebone_glColor(const unsigned int boneflag)
294 if (boneflag & BONE_DRAW_ACTIVE && boneflag & BONE_SELECTED) UI_ThemeColor(TH_EDGE_SELECT);
295 else if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColorBlend(TH_WIRE, TH_EDGE_SELECT, 0.15f); /* unselected active */
296 else if (boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_EDGE_SELECT, -20);
297 else UI_ThemeColor(TH_WIRE);
300 /* *************** Armature drawing, helper calls for parts ******************* */
302 /* half the cube, in Y */
303 static float cube[8][3] = {
314 static void drawsolidcube_size(float xsize, float ysize, float zsize)
316 static GLuint displist=0;
319 glScalef(xsize, ysize, zsize);
321 n[0]=0; n[1]=0; n[2]=0;
324 displist= glGenLists(1);
325 glNewList(displist, GL_COMPILE);
330 glVertex3fv(cube[0]); glVertex3fv(cube[1]); glVertex3fv(cube[2]); glVertex3fv(cube[3]);
334 glVertex3fv(cube[0]); glVertex3fv(cube[4]); glVertex3fv(cube[5]); glVertex3fv(cube[1]);
338 glVertex3fv(cube[4]); glVertex3fv(cube[7]); glVertex3fv(cube[6]); glVertex3fv(cube[5]);
342 glVertex3fv(cube[7]); glVertex3fv(cube[3]); glVertex3fv(cube[2]); glVertex3fv(cube[6]);
346 glVertex3fv(cube[1]); glVertex3fv(cube[5]); glVertex3fv(cube[6]); glVertex3fv(cube[2]);
350 glVertex3fv(cube[7]); glVertex3fv(cube[4]); glVertex3fv(cube[0]); glVertex3fv(cube[3]);
356 glCallList(displist);
359 static void drawcube_size(float xsize, float ysize, float zsize)
361 static GLuint displist=0;
364 displist= glGenLists(1);
365 glNewList(displist, GL_COMPILE);
367 glBegin(GL_LINE_STRIP);
368 glVertex3fv(cube[0]); glVertex3fv(cube[1]);glVertex3fv(cube[2]); glVertex3fv(cube[3]);
369 glVertex3fv(cube[0]); glVertex3fv(cube[4]);glVertex3fv(cube[5]); glVertex3fv(cube[6]);
370 glVertex3fv(cube[7]); glVertex3fv(cube[4]);
374 glVertex3fv(cube[1]); glVertex3fv(cube[5]);
375 glVertex3fv(cube[2]); glVertex3fv(cube[6]);
376 glVertex3fv(cube[3]); glVertex3fv(cube[7]);
382 glScalef(xsize, ysize, zsize);
383 glCallList(displist);
388 static void draw_bonevert(void)
390 static GLuint displist=0;
395 displist= glGenLists(1);
396 glNewList(displist, GL_COMPILE);
400 qobj = gluNewQuadric();
401 gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
402 gluDisk(qobj, 0.0, 0.05, 16, 1);
404 glRotatef(90, 0, 1, 0);
405 gluDisk(qobj, 0.0, 0.05, 16, 1);
407 glRotatef(90, 1, 0, 0);
408 gluDisk(qobj, 0.0, 0.05, 16, 1);
410 gluDeleteQuadric(qobj);
416 glCallList(displist);
419 static void draw_bonevert_solid(void)
421 static GLuint displist=0;
426 displist= glGenLists(1);
427 glNewList(displist, GL_COMPILE);
429 qobj = gluNewQuadric();
430 gluQuadricDrawStyle(qobj, GLU_FILL);
431 glShadeModel(GL_SMOOTH);
432 gluSphere(qobj, 0.05, 8, 5);
433 glShadeModel(GL_FLAT);
434 gluDeleteQuadric(qobj);
439 glCallList(displist);
442 static void draw_bone_octahedral(void)
444 static GLuint displist=0;
449 displist= glGenLists(1);
450 glNewList(displist, GL_COMPILE);
452 vec[0][0]= vec[0][1]= vec[0][2]= 0.0f;
453 vec[5][0]= vec[5][2]= 0.0f; vec[5][1]= 1.0f;
455 vec[1][0]= 0.1f; vec[1][2]= 0.1f; vec[1][1]= 0.1f;
456 vec[2][0]= 0.1f; vec[2][2]= -0.1f; vec[2][1]= 0.1f;
457 vec[3][0]= -0.1f; vec[3][2]= -0.1f; vec[3][1]= 0.1f;
458 vec[4][0]= -0.1f; vec[4][2]= 0.1f; vec[4][1]= 0.1f;
460 /* Section 1, sides */
461 glBegin(GL_LINE_LOOP);
472 /* Section 1, square */
473 glBegin(GL_LINE_LOOP);
483 glCallList(displist);
486 static void draw_bone_solid_octahedral(void)
488 static GLuint displist=0;
491 float vec[6][3], nor[3];
493 displist= glGenLists(1);
494 glNewList(displist, GL_COMPILE);
496 vec[0][0]= vec[0][1]= vec[0][2]= 0.0f;
497 vec[5][0]= vec[5][2]= 0.0f; vec[5][1]= 1.0f;
499 vec[1][0]= 0.1f; vec[1][2]= 0.1f; vec[1][1]= 0.1f;
500 vec[2][0]= 0.1f; vec[2][2]= -0.1f; vec[2][1]= 0.1f;
501 vec[3][0]= -0.1f; vec[3][2]= -0.1f; vec[3][1]= 0.1f;
502 vec[4][0]= -0.1f; vec[4][2]= 0.1f; vec[4][1]= 0.1f;
505 glBegin(GL_TRIANGLES);
507 normal_tri_v3( nor,vec[2], vec[1], vec[0]);
509 glVertex3fv(vec[2]); glVertex3fv(vec[1]); glVertex3fv(vec[0]);
511 normal_tri_v3( nor,vec[3], vec[2], vec[0]);
513 glVertex3fv(vec[3]); glVertex3fv(vec[2]); glVertex3fv(vec[0]);
515 normal_tri_v3( nor,vec[4], vec[3], vec[0]);
517 glVertex3fv(vec[4]); glVertex3fv(vec[3]); glVertex3fv(vec[0]);
519 normal_tri_v3( nor,vec[1], vec[4], vec[0]);
521 glVertex3fv(vec[1]); glVertex3fv(vec[4]); glVertex3fv(vec[0]);
524 normal_tri_v3( nor,vec[5], vec[1], vec[2]);
526 glVertex3fv(vec[5]); glVertex3fv(vec[1]); glVertex3fv(vec[2]);
528 normal_tri_v3( nor,vec[5], vec[2], vec[3]);
530 glVertex3fv(vec[5]); glVertex3fv(vec[2]); glVertex3fv(vec[3]);
532 normal_tri_v3( nor,vec[5], vec[3], vec[4]);
534 glVertex3fv(vec[5]); glVertex3fv(vec[3]); glVertex3fv(vec[4]);
536 normal_tri_v3( nor,vec[5], vec[4], vec[1]);
538 glVertex3fv(vec[5]); glVertex3fv(vec[4]); glVertex3fv(vec[1]);
545 glCallList(displist);
548 /* *************** Armature drawing, bones ******************* */
551 static void draw_bone_points(int dt, int armflag, unsigned int boneflag, int id)
553 /* Draw root point if we are not connected */
554 if ((boneflag & BONE_CONNECTED)==0) {
556 glLoadName(id | BONESEL_ROOT);
559 if (armflag & ARM_EDITMODE) {
560 if (boneflag & BONE_ROOTSEL) UI_ThemeColor(TH_VERTEX_SELECT);
561 else UI_ThemeColor(TH_VERTEX);
565 if (armflag & ARM_POSEMODE)
566 set_pchan_glColor(PCHAN_COLOR_SOLID, boneflag, 0);
568 UI_ThemeColor(TH_BONE_SOLID);
572 draw_bonevert_solid();
579 glLoadName(id | BONESEL_TIP);
582 if (armflag & ARM_EDITMODE) {
583 if (boneflag & BONE_TIPSEL) UI_ThemeColor(TH_VERTEX_SELECT);
584 else UI_ThemeColor(TH_VERTEX);
588 if (armflag & ARM_POSEMODE)
589 set_pchan_glColor(PCHAN_COLOR_SOLID, boneflag, 0);
591 UI_ThemeColor(TH_BONE_SOLID);
594 glTranslatef(0.0f, 1.0f, 0.0f);
596 draw_bonevert_solid();
599 glTranslatef(0.0f, -1.0f, 0.0f);
603 /* 16 values of sin function (still same result!) */
604 static float si[16] = {
606 0.20129852f, 0.39435585f,
607 0.57126821f, 0.72479278f,
608 0.84864425f, 0.93775213f,
609 0.98846832f, 0.99871650f,
610 0.96807711f, 0.89780453f,
611 0.79077573f, 0.65137248f,
612 0.48530196f, 0.29936312f,
615 /* 16 values of cos function (still same result!) */
616 static float co[16] ={
618 0.97952994f, 0.91895781f,
619 0.82076344f, 0.68896691f,
620 0.52896401f, 0.34730525f,
621 0.15142777f, -0.05064916f,
622 -0.25065253f, -0.44039415f,
623 -0.61210598f, -0.75875812f,
624 -0.87434661f, -0.95413925f,
630 /* smat, imat = mat & imat to draw screenaligned */
631 static void draw_sphere_bone_dist(float smat[][4], float imat[][4], bPoseChannel *pchan, EditBone *ebone)
633 float head, tail, dist /*, length*/;
634 float *headvec, *tailvec, dirvec[3];
636 /* figure out the sizes of spheres */
638 /* this routine doesn't call get_matrix_editbone() that calculates it */
639 ebone->length = len_v3v3(ebone->head, ebone->tail);
641 /*length= ebone->length;*/ /*UNUSED*/
642 tail= ebone->rad_tail;
644 if (ebone->parent && (ebone->flag & BONE_CONNECTED))
645 head= ebone->parent->rad_tail;
647 head= ebone->rad_head;
648 headvec= ebone->head;
649 tailvec= ebone->tail;
652 /*length= pchan->bone->length;*/ /*UNUSED*/
653 tail= pchan->bone->rad_tail;
654 dist= pchan->bone->dist;
655 if (pchan->parent && (pchan->bone->flag & BONE_CONNECTED))
656 head= pchan->parent->bone->rad_tail;
658 head= pchan->bone->rad_head;
659 headvec= pchan->pose_head;
660 tailvec= pchan->pose_tail;
663 /* ***** draw it ***** */
665 /* move vector to viewspace */
666 sub_v3_v3v3(dirvec, tailvec, headvec);
667 mul_mat3_m4_v3(smat, dirvec);
672 /* correcyion when viewing along the bones axis
673 * it pops in and out but better then artifacts, [#23841] */
674 float view_dist= len_v2(dirvec);
676 if(head - view_dist > tail) {
680 dirvec[0]= 0.00001; // XXX. weak but ok
682 else if(tail - view_dist > head) {
686 dirvec[0]= 0.00001; // XXX. weak but ok
690 /* move vector back */
691 mul_mat3_m4_v3(imat, dirvec);
693 if (0.0f != normalize_v3(dirvec)) {
694 float norvec[3], vec1[3], vec2[3], vec[3];
697 //mul_v3_fl(dirvec, head);
698 cross_v3_v3v3(norvec, dirvec, imat[2]);
700 glBegin(GL_QUAD_STRIP);
702 for (a=0; a<16; a++) {
703 vec[0]= - *(si+a) * dirvec[0] + *(co+a) * norvec[0];
704 vec[1]= - *(si+a) * dirvec[1] + *(co+a) * norvec[1];
705 vec[2]= - *(si+a) * dirvec[2] + *(co+a) * norvec[2];
707 vec1[0]= headvec[0] + head*vec[0];
708 vec1[1]= headvec[1] + head*vec[1];
709 vec1[2]= headvec[2] + head*vec[2];
710 vec2[0]= headvec[0] + (head+dist)*vec[0];
711 vec2[1]= headvec[1] + (head+dist)*vec[1];
712 vec2[2]= headvec[2] + (head+dist)*vec[2];
714 glColor4ub(255, 255, 255, 50);
716 //glColor4ub(255, 255, 255, 0);
720 for (a=15; a>=0; a--) {
721 vec[0]= *(si+a) * dirvec[0] + *(co+a) * norvec[0];
722 vec[1]= *(si+a) * dirvec[1] + *(co+a) * norvec[1];
723 vec[2]= *(si+a) * dirvec[2] + *(co+a) * norvec[2];
725 vec1[0]= tailvec[0] + tail*vec[0];
726 vec1[1]= tailvec[1] + tail*vec[1];
727 vec1[2]= tailvec[2] + tail*vec[2];
728 vec2[0]= tailvec[0] + (tail+dist)*vec[0];
729 vec2[1]= tailvec[1] + (tail+dist)*vec[1];
730 vec2[2]= tailvec[2] + (tail+dist)*vec[2];
732 //glColor4ub(255, 255, 255, 50);
734 //glColor4ub(255, 255, 255, 0);
737 /* make it cyclic... */
739 vec[0]= - *(si) * dirvec[0] + *(co) * norvec[0];
740 vec[1]= - *(si) * dirvec[1] + *(co) * norvec[1];
741 vec[2]= - *(si) * dirvec[2] + *(co) * norvec[2];
743 vec1[0]= headvec[0] + head*vec[0];
744 vec1[1]= headvec[1] + head*vec[1];
745 vec1[2]= headvec[2] + head*vec[2];
746 vec2[0]= headvec[0] + (head+dist)*vec[0];
747 vec2[1]= headvec[1] + (head+dist)*vec[1];
748 vec2[2]= headvec[2] + (head+dist)*vec[2];
750 //glColor4ub(255, 255, 255, 50);
752 //glColor4ub(255, 255, 255, 0);
760 /* smat, imat = mat & imat to draw screenaligned */
761 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)
763 float head, tail /*, length*/;
764 float *headvec, *tailvec, dirvec[3];
766 /* figure out the sizes of spheres */
768 /* this routine doesn't call get_matrix_editbone() that calculates it */
769 ebone->length = len_v3v3(ebone->head, ebone->tail);
771 /*length= ebone->length;*/ /*UNUSED*/
772 tail= ebone->rad_tail;
773 if (ebone->parent && (boneflag & BONE_CONNECTED))
774 head= ebone->parent->rad_tail;
776 head= ebone->rad_head;
777 headvec= ebone->head;
778 tailvec= ebone->tail;
781 /*length= pchan->bone->length;*/ /*UNUSED*/
782 tail= pchan->bone->rad_tail;
783 if ((pchan->parent) && (boneflag & BONE_CONNECTED))
784 head= pchan->parent->bone->rad_tail;
786 head= pchan->bone->rad_head;
787 headvec= pchan->pose_head;
788 tailvec= pchan->pose_tail;
791 /* sphere root color */
792 if (armflag & ARM_EDITMODE) {
793 if (boneflag & BONE_ROOTSEL) UI_ThemeColor(TH_VERTEX_SELECT);
794 else UI_ThemeColor(TH_VERTEX);
796 else if (armflag & ARM_POSEMODE)
797 set_pchan_glColor(PCHAN_COLOR_NORMAL, boneflag, constflag);
799 /* Draw root point if we are not connected */
800 if ((boneflag & BONE_CONNECTED)==0) {
802 glLoadName(id | BONESEL_ROOT);
804 drawcircball(GL_LINE_LOOP, headvec, head, imat);
808 if (armflag & ARM_EDITMODE) {
809 if (boneflag & BONE_TIPSEL) UI_ThemeColor(TH_VERTEX_SELECT);
810 else UI_ThemeColor(TH_VERTEX);
814 glLoadName(id | BONESEL_TIP);
816 drawcircball(GL_LINE_LOOP, tailvec, tail, imat);
819 if (armflag & ARM_EDITMODE) {
820 if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_SELECT);
821 else UI_ThemeColor(TH_WIRE);
824 sub_v3_v3v3(dirvec, tailvec, headvec);
826 /* move vector to viewspace */
827 mul_mat3_m4_v3(smat, dirvec);
830 /* move vector back */
831 mul_mat3_m4_v3(imat, dirvec);
833 if (0.0f != normalize_v3(dirvec)) {
834 float norvech[3], norvect[3], vec[3];
836 VECCOPY(vec, dirvec);
838 mul_v3_fl(dirvec, head);
839 cross_v3_v3v3(norvech, dirvec, imat[2]);
841 mul_v3_fl(vec, tail);
842 cross_v3_v3v3(norvect, vec, imat[2]);
845 glLoadName(id | BONESEL_BONE);
848 vec[0]= headvec[0] + norvech[0];
849 vec[1]= headvec[1] + norvech[1];
850 vec[2]= headvec[2] + norvech[2];
852 vec[0]= tailvec[0] + norvect[0];
853 vec[1]= tailvec[1] + norvect[1];
854 vec[2]= tailvec[2] + norvect[2];
856 vec[0]= headvec[0] - norvech[0];
857 vec[1]= headvec[1] - norvech[1];
858 vec[2]= headvec[2] - norvech[2];
860 vec[0]= tailvec[0] - norvect[0];
861 vec[1]= tailvec[1] - norvect[1];
862 vec[2]= tailvec[2] - norvect[2];
869 /* does wire only for outline selecting */
870 static void draw_sphere_bone(int dt, int armflag, int boneflag, int constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
873 float head, tail, length;
877 qobj = gluNewQuadric();
879 /* figure out the sizes of spheres */
881 length= ebone->length;
882 tail= ebone->rad_tail;
883 if (ebone->parent && (boneflag & BONE_CONNECTED))
884 head= ebone->parent->rad_tail;
886 head= ebone->rad_head;
889 length= pchan->bone->length;
890 tail= pchan->bone->rad_tail;
891 if (pchan->parent && (boneflag & BONE_CONNECTED))
892 head= pchan->parent->bone->rad_tail;
894 head= pchan->bone->rad_head;
897 /* move to z-axis space */
898 glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
901 /* set up solid drawing */
902 glEnable(GL_COLOR_MATERIAL);
903 glEnable(GL_LIGHTING);
905 gluQuadricDrawStyle(qobj, GLU_FILL);
906 glShadeModel(GL_SMOOTH);
909 gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
912 /* sphere root color */
913 if (armflag & ARM_EDITMODE) {
914 if (boneflag & BONE_ROOTSEL) UI_ThemeColor(TH_VERTEX_SELECT);
915 else UI_ThemeColorShade(TH_BONE_SOLID, -30);
917 else if (armflag & ARM_POSEMODE)
918 set_pchan_glColor(PCHAN_COLOR_SPHEREBONE_END, boneflag, constflag);
919 else if (dt==OB_SOLID)
920 UI_ThemeColorShade(TH_BONE_SOLID, -30);
922 /* Draw root point if we are not connected */
923 if ((boneflag & BONE_CONNECTED)==0) {
925 glLoadName(id | BONESEL_ROOT);
926 gluSphere(qobj, head, 16, 10);
930 if (armflag & ARM_EDITMODE) {
931 if (boneflag & BONE_TIPSEL) UI_ThemeColor(TH_VERTEX_SELECT);
932 else UI_ThemeColorShade(TH_BONE_SOLID, -30);
936 glLoadName(id | BONESEL_TIP);
938 glTranslatef(0.0f, 0.0f, length);
939 gluSphere(qobj, tail, 16, 10);
940 glTranslatef(0.0f, 0.0f, -length);
943 if (armflag & ARM_EDITMODE) {
944 if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_SELECT);
945 else UI_ThemeColor(TH_BONE_SOLID);
947 else if (armflag & ARM_POSEMODE)
948 set_pchan_glColor(PCHAN_COLOR_SPHEREBONE_BASE, boneflag, constflag);
949 else if (dt == OB_SOLID)
950 UI_ThemeColor(TH_BONE_SOLID);
952 fac1= (length-head)/length;
953 fac2= (length-tail)/length;
955 if (length > (head+tail)) {
957 glLoadName (id | BONESEL_BONE);
959 glEnable(GL_POLYGON_OFFSET_FILL);
960 glPolygonOffset(-1.0f, -1.0f);
962 glTranslatef(0.0f, 0.0f, head);
963 gluCylinder(qobj, fac1*head + (1.0f-fac1)*tail, fac2*tail + (1.0f-fac2)*head, length-head-tail, 16, 1);
964 glTranslatef(0.0f, 0.0f, -head);
966 glDisable(GL_POLYGON_OFFSET_FILL);
968 /* draw sphere on extrema */
969 glTranslatef(0.0f, 0.0f, length-tail);
970 gluSphere(qobj, fac2*tail + (1.0f-fac2)*head, 16, 10);
971 glTranslatef(0.0f, 0.0f, -length+tail);
973 glTranslatef(0.0f, 0.0f, head);
974 gluSphere(qobj, fac1*head + (1.0f-fac1)*tail, 16, 10);
977 /* 1 sphere in center */
978 glTranslatef(0.0f, 0.0f, (head + length-tail)/2.0f);
979 gluSphere(qobj, fac1*head + (1.0f-fac1)*tail, 16, 10);
984 glShadeModel(GL_FLAT);
985 glDisable(GL_LIGHTING);
986 glDisable(GL_COLOR_MATERIAL);
990 gluDeleteQuadric(qobj);
993 static GLubyte bm_dot6[]= {0x0, 0x18, 0x3C, 0x7E, 0x7E, 0x3C, 0x18, 0x0};
994 static GLubyte bm_dot8[]= {0x3C, 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C};
996 static GLubyte bm_dot5[]= {0x0, 0x0, 0x10, 0x38, 0x7c, 0x38, 0x10, 0x0};
997 static GLubyte bm_dot7[]= {0x0, 0x38, 0x7C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38};
1000 static void draw_line_bone(int armflag, int boneflag, int constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
1004 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1007 length= pchan->bone->length;
1009 length= ebone->length;
1012 glScalef(length, length, length);
1014 /* this chunk not in object mode */
1015 if (armflag & (ARM_EDITMODE|ARM_POSEMODE)) {
1017 if (armflag & ARM_POSEMODE)
1018 set_pchan_glColor(PCHAN_COLOR_NORMAL, boneflag, constflag);
1019 else if (armflag & ARM_EDITMODE) {
1020 UI_ThemeColor(TH_WIRE);
1023 /* Draw root point if we are not connected */
1024 if ((boneflag & BONE_CONNECTED)==0) {
1025 if (G.f & G_PICKSEL) { // no bitmap in selection mode, crashes 3d cards...
1026 glLoadName (id | BONESEL_ROOT);
1028 glVertex3f(0.0f, 0.0f, 0.0f);
1032 glRasterPos3f(0.0f, 0.0f, 0.0f);
1033 glBitmap(8, 8, 4, 4, 0, 0, bm_dot8);
1038 glLoadName((GLuint) id|BONESEL_BONE);
1041 glVertex3f(0.0f, 0.0f, 0.0f);
1042 glVertex3f(0.0f, 1.0f, 0.0f);
1046 if (G.f & G_PICKSEL) {
1047 /* no bitmap in selection mode, crashes 3d cards... */
1048 glLoadName(id | BONESEL_TIP);
1050 glVertex3f(0.0f, 1.0f, 0.0f);
1054 glRasterPos3f(0.0f, 1.0f, 0.0f);
1055 glBitmap(8, 8, 4, 4, 0, 0, bm_dot7);
1058 /* further we send no names */
1060 glLoadName(id & 0xFFFF); /* object tag, for bordersel optim */
1062 if (armflag & ARM_POSEMODE)
1063 set_pchan_glColor(PCHAN_COLOR_LINEBONE, boneflag, constflag);
1068 /*Draw root point if we are not connected */
1069 if ((boneflag & BONE_CONNECTED)==0) {
1070 if ((G.f & G_PICKSEL)==0) {
1071 /* no bitmap in selection mode, crashes 3d cards... */
1072 if (armflag & ARM_EDITMODE) {
1073 if (boneflag & BONE_ROOTSEL) UI_ThemeColor(TH_VERTEX_SELECT);
1074 else UI_ThemeColor(TH_VERTEX);
1076 glRasterPos3f(0.0f, 0.0f, 0.0f);
1077 glBitmap(8, 8, 4, 4, 0, 0, bm_dot6);
1081 if (armflag & ARM_EDITMODE) {
1082 if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_EDGE_SELECT);
1083 else UI_ThemeColorShade(TH_BACK, -30);
1086 glVertex3f(0.0f, 0.0f, 0.0f);
1087 glVertex3f(0.0f, 1.0f, 0.0f);
1091 if ((G.f & G_PICKSEL)==0) {
1092 /* no bitmap in selection mode, crashes 3d cards... */
1093 if (armflag & ARM_EDITMODE) {
1094 if (boneflag & BONE_TIPSEL) UI_ThemeColor(TH_VERTEX_SELECT);
1095 else UI_ThemeColor(TH_VERTEX);
1097 glRasterPos3f(0.0f, 1.0f, 0.0f);
1098 glBitmap(8, 8, 4, 4, 0, 0, bm_dot5);
1106 static void draw_b_bone_boxes(int dt, bPoseChannel *pchan, float xwidth, float length, float zwidth)
1111 segments= pchan->bone->segments;
1113 if ((segments > 1) && (pchan)) {
1114 float dlen= length/(float)segments;
1115 Mat4 *bbone= b_bone_spline_setup(pchan, 0);
1118 for (a=0; a<segments; a++, bbone++) {
1120 glMultMatrixf(bbone->mat);
1121 if (dt==OB_SOLID) drawsolidcube_size(xwidth, dlen, zwidth);
1122 else drawcube_size(xwidth, dlen, zwidth);
1128 if (dt==OB_SOLID) drawsolidcube_size(xwidth, length, zwidth);
1129 else drawcube_size(xwidth, length, zwidth);
1134 static void draw_b_bone(int dt, int armflag, int boneflag, int constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
1136 float xwidth, length, zwidth;
1139 xwidth= pchan->bone->xwidth;
1140 length= pchan->bone->length;
1141 zwidth= pchan->bone->zwidth;
1144 xwidth= ebone->xwidth;
1145 length= ebone->length;
1146 zwidth= ebone->zwidth;
1149 /* draw points only if... */
1150 if (armflag & ARM_EDITMODE) {
1151 /* move to unitspace */
1153 glScalef(length, length, length);
1154 draw_bone_points(dt, armflag, boneflag, id);
1156 length*= 0.95f; // make vertices visible
1159 /* colors for modes */
1160 if (armflag & ARM_POSEMODE) {
1162 set_pchan_glColor(PCHAN_COLOR_NORMAL, boneflag, constflag);
1164 set_pchan_glColor(PCHAN_COLOR_SOLID, boneflag, constflag);
1166 else if (armflag & ARM_EDITMODE) {
1168 set_ebone_glColor(boneflag);
1171 UI_ThemeColor(TH_BONE_SOLID);
1175 glLoadName ((GLuint) id|BONESEL_BONE);
1178 /* set up solid drawing */
1180 glEnable(GL_COLOR_MATERIAL);
1181 glEnable(GL_LIGHTING);
1183 if (armflag & ARM_POSEMODE)
1184 set_pchan_glColor(PCHAN_COLOR_SOLID, boneflag, constflag);
1186 UI_ThemeColor(TH_BONE_SOLID);
1188 draw_b_bone_boxes(OB_SOLID, pchan, xwidth, length, zwidth);
1190 /* disable solid drawing */
1191 glDisable(GL_COLOR_MATERIAL);
1192 glDisable(GL_LIGHTING);
1196 if (armflag & ARM_POSEMODE) {
1198 /* set constraint colors */
1199 if (set_pchan_glColor(PCHAN_COLOR_CONSTS, boneflag, constflag)) {
1202 draw_b_bone_boxes(OB_SOLID, pchan, xwidth, length, zwidth);
1204 glDisable(GL_BLEND);
1207 /* restore colors */
1208 set_pchan_glColor(PCHAN_COLOR_NORMAL, boneflag, constflag);
1212 draw_b_bone_boxes(OB_WIRE, pchan, xwidth, length, zwidth);
1216 static void draw_bone(int dt, int armflag, int boneflag, int constflag, unsigned int id, float length)
1219 /* Draw a 3d octahedral bone, we use normalized space based on length,
1220 for glDisplayLists */
1222 glScalef(length, length, length);
1224 /* set up solid drawing */
1226 glEnable(GL_COLOR_MATERIAL);
1227 glEnable(GL_LIGHTING);
1228 UI_ThemeColor(TH_BONE_SOLID);
1231 /* colors for posemode */
1232 if (armflag & ARM_POSEMODE) {
1234 set_pchan_glColor(PCHAN_COLOR_NORMAL, boneflag, constflag);
1236 set_pchan_glColor(PCHAN_COLOR_SOLID, boneflag, constflag);
1240 draw_bone_points(dt, armflag, boneflag, id);
1242 /* now draw the bone itself */
1244 glLoadName((GLuint) id|BONESEL_BONE);
1248 if (dt <= OB_WIRE) {
1250 if (armflag & ARM_EDITMODE) {
1251 set_ebone_glColor(boneflag);
1253 else if (armflag & ARM_POSEMODE) {
1255 /* draw constraint colors */
1256 if (set_pchan_glColor(PCHAN_COLOR_CONSTS, boneflag, constflag)) {
1259 draw_bone_solid_octahedral();
1261 glDisable(GL_BLEND);
1264 /* restore colors */
1265 set_pchan_glColor(PCHAN_COLOR_NORMAL, boneflag, constflag);
1268 draw_bone_octahedral();
1272 if (armflag & ARM_POSEMODE)
1273 set_pchan_glColor(PCHAN_COLOR_SOLID, boneflag, constflag);
1275 UI_ThemeColor(TH_BONE_SOLID);
1276 draw_bone_solid_octahedral();
1279 /* disable solid drawing */
1281 glDisable(GL_COLOR_MATERIAL);
1282 glDisable(GL_LIGHTING);
1286 static void draw_custom_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, int dt, int armflag, int boneflag, unsigned int id, float length)
1288 if(ob==NULL) return;
1290 glScalef(length, length, length);
1292 /* colors for posemode */
1293 if (armflag & ARM_POSEMODE) {
1294 set_pchan_glColor(PCHAN_COLOR_NORMAL, boneflag, 0);
1298 glLoadName((GLuint) id|BONESEL_BONE);
1301 draw_object_instance(scene, v3d, rv3d, ob, dt, armflag & ARM_POSEMODE);
1305 static void pchan_draw_IK_root_lines(bPoseChannel *pchan, short only_temp)
1308 bPoseChannel *parchan;
1310 for (con= pchan->constraints.first; con; con= con->next) {
1311 if (con->enforce == 0.0f)
1314 switch (con->type) {
1315 case CONSTRAINT_TYPE_KINEMATIC:
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);
1348 case CONSTRAINT_TYPE_SPLINEIK:
1350 bSplineIKConstraint *data = (bSplineIKConstraint*)con->data;
1357 glVertex3fv(parchan->pose_tail);
1359 /* Find the chain's root */
1360 while (parchan->parent) {
1362 // FIXME: revise the breaking conditions
1363 if(segcount==data->chainlen || segcount>255) break; // 255 is weak
1364 parchan= parchan->parent;
1366 if (parchan) // XXX revise the breaking conditions to only stop at the tail?
1367 glVertex3fv(parchan->pose_head);
1377 static void bgl_sphere_project(float ax, float az)
1379 float dir[3], sine, q3;
1381 sine= 1.0f - ax*ax - az*az;
1382 q3= (sine < 0.0f)? 0.0f: (float)(2.0*sqrt(sine));
1385 dir[1]= 1.0f - 2.0f*sine;
1391 static void draw_dof_ellipse(float ax, float az)
1393 static float staticSine[16] = {
1394 0.0f, 0.104528463268f, 0.207911690818f, 0.309016994375f,
1395 0.406736643076f, 0.5f, 0.587785252292f, 0.669130606359f,
1396 0.743144825477f, 0.809016994375f, 0.866025403784f,
1397 0.913545457643f, 0.951056516295f, 0.978147600734f,
1398 0.994521895368f, 1.0f
1407 glColor4ub(70, 70, 70, 50);
1411 for(i=1; i<n; i++) {
1415 for(j=1; j<n-i+1; j++) {
1420 glBegin(GL_TRIANGLES);
1421 bgl_sphere_project(ax*px, az*z);
1422 bgl_sphere_project(ax*px, az*pz);
1423 bgl_sphere_project(ax*x, az*pz);
1428 bgl_sphere_project(ax*x, az*z);
1429 bgl_sphere_project(ax*x, az*pz);
1430 bgl_sphere_project(ax*px, az*pz);
1431 bgl_sphere_project(ax*px, az*z);
1440 glDisable(GL_BLEND);
1443 glColor3ub(0, 0, 0);
1445 glBegin(GL_LINE_STRIP);
1447 bgl_sphere_project(staticSine[n-i-1]*ax, staticSine[i]*az);
1451 static void draw_pose_dofs(Object *ob)
1453 bArmature *arm= ob->data;
1454 bPoseChannel *pchan;
1457 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1460 if ( (bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
1461 if (bone->flag & BONE_SELECTED) {
1462 if (bone->layer & arm->layer) {
1463 if (pchan->ikflag & (BONE_IK_XLIMIT|BONE_IK_ZLIMIT)) {
1464 if (ED_pose_channel_in_IK_chain(ob, pchan)) {
1465 float corner[4][3], posetrans[3], mat[4][4];
1466 float phi=0.0f, theta=0.0f, scale;
1469 /* in parent-bone pose, but own restspace */
1472 VECCOPY(posetrans, pchan->pose_mat[3]);
1473 glTranslatef(posetrans[0], posetrans[1], posetrans[2]);
1475 if (pchan->parent) {
1476 copy_m4_m4(mat, pchan->parent->pose_mat);
1477 mat[3][0]= mat[3][1]= mat[3][2]= 0.0f;
1481 copy_m4_m3(mat, pchan->bone->bone_mat);
1484 scale= bone->length*pchan->size[1];
1485 glScalef(scale, scale, scale);
1487 if (pchan->ikflag & BONE_IK_XLIMIT) {
1488 if (pchan->ikflag & BONE_IK_ZLIMIT) {
1489 float amin[3], amax[3];
1491 for (i=0; i<3; i++) {
1492 /* *0.5f here comes from M_PI/360.0f when rotations were still in degrees */
1493 amin[i]= (float)sin(pchan->limitmin[i]*0.5f);
1494 amax[i]= (float)sin(pchan->limitmax[i]*0.5f);
1497 glScalef(1.0f, -1.0f, 1.0f);
1498 if ((amin[0] != 0.0f) && (amin[2] != 0.0f))
1499 draw_dof_ellipse(amin[0], amin[2]);
1500 if ((amin[0] != 0.0f) && (amax[2] != 0.0f))
1501 draw_dof_ellipse(amin[0], amax[2]);
1502 if ((amax[0] != 0.0f) && (amin[2] != 0.0f))
1503 draw_dof_ellipse(amax[0], amin[2]);
1504 if ((amax[0] != 0.0f) && (amax[2] != 0.0f))
1505 draw_dof_ellipse(amax[0], amax[2]);
1506 glScalef(1.0f, -1.0f, 1.0f);
1511 if (pchan->ikflag & BONE_IK_ZLIMIT) {
1512 /* OpenGL requires rotations in degrees; so we're taking the average angle here */
1513 theta= 0.5f*(pchan->limitmin[2]+pchan->limitmax[2]) * (float)(180.0f/M_PI);
1514 glRotatef(theta, 0.0f, 0.0f, 1.0f);
1516 glColor3ub(50, 50, 255); // blue, Z axis limit
1517 glBegin(GL_LINE_STRIP);
1518 for (a=-16; a<=16; a++) {
1519 float fac= ((float)a)/16.0f * 0.5f; /* *0.5f here comes from M_PI/360.0f when rotations were still in degrees */
1521 phi= fac * (pchan->limitmax[2] - pchan->limitmin[2]);
1523 i= (a == -16) ? 0 : 1;
1524 corner[i][0]= (float)sin(phi);
1525 corner[i][1]= (float)cos(phi);
1527 glVertex3fv(corner[i]);
1531 glRotatef(-theta, 0.0f, 0.0f, 1.0f);
1534 if (pchan->ikflag & BONE_IK_XLIMIT) {
1535 /* OpenGL requires rotations in degrees; so we're taking the average angle here */
1536 theta= 0.5f*(pchan->limitmin[0] + pchan->limitmax[0]) * (float)(180.0f/M_PI);
1537 glRotatef(theta, 1.0f, 0.0f, 0.0f);
1539 glColor3ub(255, 50, 50); // Red, X axis limit
1540 glBegin(GL_LINE_STRIP);
1541 for (a=-16; a<=16; a++) {
1542 float fac= ((float)a)/16.0f * 0.5f; /* *0.5f here comes from M_PI/360.0f when rotations were still in degrees */
1543 phi= (float)(0.5*M_PI) + fac * (pchan->limitmax[0] - pchan->limitmin[0]);
1545 i= (a == -16) ? 2 : 3;
1547 corner[i][1]= (float)sin(phi);
1548 corner[i][2]= (float)cos(phi);
1549 glVertex3fv(corner[i]);
1553 glRotatef(-theta, 1.0f, 0.0f, 0.0f);
1556 /* out of cone, out of bone */
1566 static void bone_matrix_translate_y(float mat[][4], float y)
1570 VECCOPY(trans, mat[1]);
1571 mul_v3_fl(trans, y);
1572 add_v3_v3(mat[3], trans);
1575 /* assumes object is Armature with pose */
1576 static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, int dt, short ghost)
1578 RegionView3D *rv3d= ar->regiondata;
1579 Object *ob= base->object;
1580 bArmature *arm= ob->data;
1581 bPoseChannel *pchan;
1584 float smat[4][4], imat[4][4], bmat[4][4];
1586 short do_dashed= 3, draw_wire= 0;
1587 short flag, constflag;
1589 /* being set below */
1592 /* hacky... prevent outline select from drawing dashed helplines */
1593 glGetFloatv(GL_LINE_WIDTH, &tmp);
1594 if (tmp > 1.1) do_dashed &= ~1;
1595 if (v3d->flag & V3D_HIDE_HELPLINES) do_dashed &= ~2;
1597 /* precalc inverse matrix for drawing screen aligned */
1598 if (arm->drawtype==ARM_ENVELOPE) {
1599 /* precalc inverse matrix for drawing screen aligned */
1600 copy_m4_m4(smat, rv3d->viewmatob);
1601 mul_mat3_m4_fl(smat, 1.0f/len_v3(ob->obmat[0]));
1602 invert_m4_m4(imat, smat);
1604 /* and draw blended distances */
1605 if (arm->flag & ARM_POSEMODE) {
1607 //glShadeModel(GL_SMOOTH);
1609 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
1611 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1613 if (bone && !(bone->flag & (BONE_HIDDEN_P|BONE_NO_DEFORM|BONE_HIDDEN_PG))) {
1614 if (bone->flag & (BONE_SELECTED)) {
1615 if (bone->layer & arm->layer)
1616 draw_sphere_bone_dist(smat, imat, pchan, NULL);
1621 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
1622 glDisable(GL_BLEND);
1623 //glShadeModel(GL_FLAT);
1627 /* little speedup, also make sure transparent only draws once */
1628 glCullFace(GL_BACK);
1629 glEnable(GL_CULL_FACE);
1631 /* if solid we draw that first, with selection codes, but without names, axes etc */
1633 if (arm->flag & ARM_POSEMODE)
1634 index= base->selcol;
1636 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1638 arm->layer_used |= bone->layer;
1640 if ( (bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)) ) {
1641 if (bone->layer & arm->layer) {
1642 int use_custom = (pchan->custom) && !(arm->flag & ARM_NO_CUSTOM);
1645 if(use_custom && pchan->custom_tx) {
1646 glMultMatrixf(pchan->custom_tx->pose_mat);
1648 glMultMatrixf(pchan->pose_mat);
1651 /* catch exception for bone with hidden parent */
1653 if ( (bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)) )
1654 flag &= ~BONE_CONNECTED;
1656 /* set temporary flag for drawing bone as active, but only if selected */
1657 if (bone == arm->act_bone)
1658 flag |= BONE_DRAW_ACTIVE;
1660 /* set color-set to use */
1661 set_pchan_colorset(ob, pchan);
1664 /* if drawwire, don't try to draw in solid */
1665 if (pchan->bone->flag & BONE_DRAWWIRE)
1668 draw_custom_bone(scene, v3d, rv3d, pchan->custom, OB_SOLID, arm->flag, flag, index, bone->length);
1670 else if (arm->drawtype==ARM_LINE)
1671 ; /* nothing in solid */
1672 else if (arm->drawtype==ARM_ENVELOPE)
1673 draw_sphere_bone(OB_SOLID, arm->flag, flag, 0, index, pchan, NULL);
1674 else if (arm->drawtype==ARM_B_BONE)
1675 draw_b_bone(OB_SOLID, arm->flag, flag, 0, index, pchan, NULL);
1677 draw_bone(OB_SOLID, arm->flag, flag, 0, index, bone->length);
1684 index+= 0x10000; // pose bones count in higher 2 bytes only
1687 /* very very confusing... but in object mode, solid draw, we cannot do glLoadName yet,
1688 * stick bones and/or wire custom-shapes are drawn in next loop
1690 if ((arm->drawtype != ARM_LINE) && (draw_wire == 0)) {
1691 /* object tag, for bordersel optim */
1692 glLoadName(index & 0xFFFF);
1697 /* draw custom bone shapes as wireframes */
1698 if ( !(arm->flag & ARM_NO_CUSTOM) &&
1699 ((draw_wire) || (dt <= OB_WIRE)) )
1701 if (arm->flag & ARM_POSEMODE)
1702 index= base->selcol;
1704 /* only draw custom bone shapes that need to be drawn as wires */
1705 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1708 if ((bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
1709 if (bone->layer & arm->layer) {
1710 if (pchan->custom) {
1711 if ((dt < OB_SOLID) || (bone->flag & BONE_DRAWWIRE)) {
1714 if(pchan->custom_tx) {
1715 glMultMatrixf(pchan->custom_tx->pose_mat);
1717 glMultMatrixf(pchan->pose_mat);
1720 /* prepare colors */
1722 /* 13 October 2009, Disabled this to make ghosting show the right colors (Aligorith) */
1724 else if (arm->flag & ARM_POSEMODE)
1725 set_pchan_colorset(ob, pchan);
1727 if ((scene->basact)==base) {
1728 if (base->flag & (SELECT+BA_WAS_SEL)) UI_ThemeColor(TH_ACTIVE);
1729 else UI_ThemeColor(TH_WIRE);
1732 if (base->flag & (SELECT+BA_WAS_SEL)) UI_ThemeColor(TH_SELECT);
1733 else UI_ThemeColor(TH_WIRE);
1737 /* catch exception for bone with hidden parent */
1739 if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)))
1740 flag &= ~BONE_CONNECTED;
1742 /* set temporary flag for drawing bone as active, but only if selected */
1743 if (bone == arm->act_bone)
1744 flag |= BONE_DRAW_ACTIVE;
1746 draw_custom_bone(scene, v3d, rv3d, pchan->custom, OB_WIRE, arm->flag, flag, index, bone->length);
1755 index+= 0x10000; // pose bones count in higher 2 bytes only
1757 /* stick bones have not been drawn yet so dont clear object selection in this case */
1758 if ((arm->drawtype != ARM_LINE) && draw_wire) {
1759 /* object tag, for bordersel optim */
1760 glLoadName(index & 0xFFFF);
1765 /* wire draw over solid only in posemode */
1766 if ((dt <= OB_WIRE) || (arm->flag & ARM_POSEMODE) || (arm->drawtype==ARM_LINE)) {
1767 /* draw line check first. we do selection indices */
1768 if (arm->drawtype==ARM_LINE) {
1769 if (arm->flag & ARM_POSEMODE)
1770 index= base->selcol;
1772 /* if solid && posemode, we draw again with polygonoffset */
1773 else if ((dt > OB_WIRE) && (arm->flag & ARM_POSEMODE)) {
1774 bglPolygonOffset(rv3d->dist, 1.0);
1777 /* and we use selection indices if not done yet */
1778 if (arm->flag & ARM_POSEMODE)
1779 index= base->selcol;
1782 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1784 arm->layer_used |= bone->layer;
1786 if ((bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
1787 if (bone->layer & arm->layer) {
1788 if ((do_dashed & 1) && (pchan->parent)) {
1789 /* Draw a line from our root to the parent's tip
1790 * - only if V3D_HIDE_HELPLINES is enabled...
1792 if ( (do_dashed & 2) && ((bone->flag & BONE_CONNECTED)==0) ) {
1793 if (arm->flag & ARM_POSEMODE) {
1794 glLoadName(index & 0xFFFF); // object tag, for bordersel optim
1795 UI_ThemeColor(TH_WIRE);
1799 glVertex3fv(pchan->pose_head);
1800 glVertex3fv(pchan->parent->pose_tail);
1805 /* Draw a line to IK root bone
1806 * - only if temporary chain (i.e. "autoik")
1808 if (arm->flag & ARM_POSEMODE) {
1809 if (pchan->constflag & PCHAN_HAS_IK) {
1810 if (bone->flag & BONE_SELECTED) {
1811 if (pchan->constflag & PCHAN_HAS_TARGET) glColor3ub(200, 120, 0);
1812 else glColor3ub(200, 200, 50); // add theme!
1814 glLoadName(index & 0xFFFF);
1815 pchan_draw_IK_root_lines(pchan, !(do_dashed & 2));
1818 else if (pchan->constflag & PCHAN_HAS_SPLINEIK) {
1819 if (bone->flag & BONE_SELECTED) {
1820 glColor3ub(150, 200, 50); // add theme!
1822 glLoadName(index & 0xFFFF);
1823 pchan_draw_IK_root_lines(pchan, !(do_dashed & 2));
1830 if (arm->drawtype != ARM_ENVELOPE)
1831 glMultMatrixf(pchan->pose_mat);
1833 /* catch exception for bone with hidden parent */
1835 if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)))
1836 flag &= ~BONE_CONNECTED;
1838 /* set temporary flag for drawing bone as active, but only if selected */
1839 if (bone == arm->act_bone)
1840 flag |= BONE_DRAW_ACTIVE;
1842 /* extra draw service for pose mode */
1843 constflag= pchan->constflag;
1844 if (pchan->flag & (POSE_ROT|POSE_LOC|POSE_SIZE))
1845 constflag |= PCHAN_HAS_ACTION;
1846 if (pchan->flag & POSE_STRIDE)
1847 constflag |= PCHAN_HAS_STRIDE;
1849 /* set color-set to use */
1850 set_pchan_colorset(ob, pchan);
1852 if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM))
1853 ; // custom bone shapes should not be drawn here!
1854 else if (arm->drawtype==ARM_ENVELOPE) {
1856 draw_sphere_bone_wire(smat, imat, arm->flag, flag, constflag, index, pchan, NULL);
1858 else if (arm->drawtype==ARM_LINE)
1859 draw_line_bone(arm->flag, flag, constflag, index, pchan, NULL);
1860 else if (arm->drawtype==ARM_B_BONE)
1861 draw_b_bone(OB_WIRE, arm->flag, flag, constflag, index, pchan, NULL);
1863 draw_bone(OB_WIRE, arm->flag, flag, constflag, index, bone->length);
1869 /* pose bones count in higher 2 bytes only */
1873 /* restore things */
1874 if ((arm->drawtype!=ARM_LINE)&& (dt>OB_WIRE) && (arm->flag & ARM_POSEMODE))
1875 bglPolygonOffset(rv3d->dist, 0.0);
1879 glDisable(GL_CULL_FACE);
1882 if (arm->flag & ARM_POSEMODE)
1885 /* finally names and axes */
1886 if (arm->flag & (ARM_DRAWNAMES|ARM_DRAWAXES)) {
1887 /* patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing */
1888 if ((G.f & G_PICKSEL) == 0) {
1891 unsigned char col[4];
1893 glGetFloatv(GL_CURRENT_COLOR, col_f); /* incase this is not set below */
1894 rgb_float_to_byte(col_f, col);
1897 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
1899 for (pchan=ob->pose->chanbase.first; pchan; pchan=pchan->next) {
1900 if ((pchan->bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))==0) {
1901 if (pchan->bone->layer & arm->layer) {
1902 if (arm->flag & (ARM_EDITMODE|ARM_POSEMODE)) {
1904 UI_GetThemeColor3ubv((bone->flag & BONE_SELECTED) ? TH_TEXT_HI : TH_TEXT, col);
1906 else if (dt > OB_WIRE) {
1907 UI_GetThemeColor3ubv(TH_TEXT, col);
1910 /* Draw names of bone */
1911 if (arm->flag & ARM_DRAWNAMES) {
1912 mid_v3_v3v3(vec, pchan->pose_head, pchan->pose_tail);
1913 view3d_cached_text_draw_add(vec, pchan->name, 10, 0, col);
1916 /* Draw additional axes on the bone tail */
1917 if ( (arm->flag & ARM_DRAWAXES) && (arm->flag & ARM_POSEMODE) ) {
1919 copy_m4_m4(bmat, pchan->pose_mat);
1920 bone_matrix_translate_y(bmat, pchan->bone->length);
1921 glMultMatrixf(bmat);
1924 drawaxes(pchan->bone->length*0.25f, OB_ARROWS);
1932 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
1937 /* in editmode, we don't store the bone matrix... */
1938 static void get_matrix_editbone(EditBone *eBone, float bmat[][4])
1943 /* Compose the parent transforms (i.e. their translations) */
1944 sub_v3_v3v3(delta, eBone->tail, eBone->head);
1946 eBone->length = (float)sqrt(delta[0]*delta[0] + delta[1]*delta[1] +delta[2]*delta[2]);
1948 vec_roll_to_mat3(delta, eBone->roll, mat);
1949 copy_m4_m3(bmat, mat);
1951 add_v3_v3(bmat[3], eBone->head);
1954 static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, int dt)
1956 RegionView3D *rv3d= ar->regiondata;
1958 bArmature *arm= ob->data;
1959 float smat[4][4], imat[4][4], bmat[4][4];
1963 /* being set in code below */
1966 /* envelope (deform distance) */
1967 if(arm->drawtype==ARM_ENVELOPE) {
1968 /* precalc inverse matrix for drawing screen aligned */
1969 copy_m4_m4(smat, rv3d->viewmatob);
1970 mul_mat3_m4_fl(smat, 1.0f/len_v3(ob->obmat[0]));
1971 invert_m4_m4(imat, smat);
1973 /* and draw blended distances */
1975 //glShadeModel(GL_SMOOTH);
1977 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
1979 for (eBone=arm->edbo->first; eBone; eBone=eBone->next) {
1980 if (eBone->layer & arm->layer) {
1981 if ((eBone->flag & (BONE_HIDDEN_A|BONE_NO_DEFORM))==0) {
1982 if (eBone->flag & (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL))
1983 draw_sphere_bone_dist(smat, imat, NULL, eBone);
1988 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
1989 glDisable(GL_BLEND);
1990 //glShadeModel(GL_FLAT);
1993 /* if solid we draw it first */
1994 if ((dt > OB_WIRE) && (arm->drawtype!=ARM_LINE)) {
1995 for (eBone=arm->edbo->first, index=0; eBone; eBone=eBone->next, index++) {
1996 if (eBone->layer & arm->layer) {
1997 if ((eBone->flag & BONE_HIDDEN_A)==0) {
1999 get_matrix_editbone(eBone, bmat);
2000 glMultMatrixf(bmat);
2002 /* catch exception for bone with hidden parent */
2004 if ( (eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent))
2005 flag &= ~BONE_CONNECTED;
2007 /* set temporary flag for drawing bone as active, but only if selected */
2008 if (eBone == arm->act_edbone)
2009 flag |= BONE_DRAW_ACTIVE;
2011 if (arm->drawtype==ARM_ENVELOPE)
2012 draw_sphere_bone(OB_SOLID, arm->flag, flag, 0, index, NULL, eBone);
2013 else if(arm->drawtype==ARM_B_BONE)
2014 draw_b_bone(OB_SOLID, arm->flag, flag, 0, index, NULL, eBone);
2016 draw_bone(OB_SOLID, arm->flag, flag, 0, index, eBone->length);
2025 /* if wire over solid, set offset */
2028 if (arm->drawtype==ARM_LINE) {
2032 else if (dt > OB_WIRE)
2033 bglPolygonOffset(rv3d->dist, 1.0f);
2034 else if (arm->flag & ARM_EDITMODE)
2035 index= 0; /* do selection codes */
2037 for (eBone=arm->edbo->first; eBone; eBone=eBone->next) {
2038 arm->layer_used |= eBone->layer;
2039 if (eBone->layer & arm->layer) {
2040 if ((eBone->flag & BONE_HIDDEN_A)==0) {
2042 /* catch exception for bone with hidden parent */
2044 if ( (eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent))
2045 flag &= ~BONE_CONNECTED;
2047 /* set temporary flag for drawing bone as active, but only if selected */
2048 if (eBone == arm->act_edbone)
2049 flag |= BONE_DRAW_ACTIVE;
2051 if (arm->drawtype == ARM_ENVELOPE) {
2053 draw_sphere_bone_wire(smat, imat, arm->flag, flag, 0, index, NULL, eBone);
2057 get_matrix_editbone(eBone, bmat);
2058 glMultMatrixf(bmat);
2060 if (arm->drawtype == ARM_LINE)
2061 draw_line_bone(arm->flag, flag, 0, index, NULL, eBone);
2062 else if (arm->drawtype == ARM_B_BONE)
2063 draw_b_bone(OB_WIRE, arm->flag, flag, 0, index, NULL, eBone);
2065 draw_bone(OB_WIRE, arm->flag, flag, 0, index, eBone->length);
2070 /* offset to parent */
2071 if (eBone->parent) {
2072 UI_ThemeColor(TH_WIRE);
2073 glLoadName (-1); // -1 here is OK!
2077 glVertex3fv(eBone->parent->tail);
2078 glVertex3fv(eBone->head);
2085 if(index!=-1) index++;
2089 if(index!=-1) glLoadName(-1);
2090 if (arm->drawtype==ARM_LINE);
2091 else if (dt>OB_WIRE) bglPolygonOffset(rv3d->dist, 0.0f);
2093 /* finally names and axes */
2094 if (arm->flag & (ARM_DRAWNAMES|ARM_DRAWAXES)) {
2095 // patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing
2096 if ((G.f & G_PICKSEL) == 0) {
2098 unsigned char col[4];
2101 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
2103 for (eBone=arm->edbo->first; eBone; eBone=eBone->next) {
2104 if(eBone->layer & arm->layer) {
2105 if ((eBone->flag & BONE_HIDDEN_A)==0) {
2107 UI_GetThemeColor3ubv((eBone->flag & BONE_SELECTED) ? TH_TEXT_HI : TH_TEXT, col);
2110 if (arm->flag & ARM_DRAWNAMES) {
2111 mid_v3_v3v3(vec, eBone->head, eBone->tail);
2112 glRasterPos3fv(vec);
2113 view3d_cached_text_draw_add(vec, eBone->name, 10, 0, col);
2115 /* Draw additional axes */
2116 if (arm->flag & ARM_DRAWAXES) {
2118 get_matrix_editbone(eBone, bmat);
2119 bone_matrix_translate_y(bmat, eBone->length);
2120 glMultMatrixf(bmat);
2123 drawaxes(eBone->length*0.25f, OB_ARROWS);
2132 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
2137 /* ****************************** Armature Visualisation ******************************** */
2139 /* ---------- Paths --------- */
2144 static void draw_pose_paths(Scene *scene, View3D *v3d, ARegion *ar, Object *ob)
2146 bAnimVizSettings *avs= &ob->pose->avs;
2147 bArmature *arm= ob->data;
2148 bPoseChannel *pchan;
2150 /* setup drawing environment for paths */
2151 draw_motion_paths_init(v3d, ar);
2153 /* draw paths where they exist and they releated bone is visible */
2154 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
2155 if ((pchan->bone->layer & arm->layer) && (pchan->mpath))
2156 draw_motion_path_instance(scene, ob, pchan, avs, pchan->mpath);
2159 /* cleanup after drawing */
2160 draw_motion_paths_cleanup(v3d);
2164 /* ---------- Ghosts --------- */
2166 /* helper function for ghost drawing - sets/removes flags for temporarily
2167 * hiding unselected bones while drawing ghosts
2169 static void ghost_poses_tag_unselected(Object *ob, short unset)
2171 bArmature *arm= ob->data;
2172 bPose *pose= ob->pose;
2173 bPoseChannel *pchan;
2175 /* don't do anything if no hiding any bones */
2176 if ((arm->flag & ARM_GHOST_ONLYSEL)==0)
2179 /* loop over all pchans, adding/removing tags as appropriate */
2180 for (pchan= pose->chanbase.first; pchan; pchan= pchan->next) {
2181 if ((pchan->bone) && (arm->layer & pchan->bone->layer)) {
2183 /* remove tags from all pchans if cleaning up */
2184 pchan->bone->flag &= ~BONE_HIDDEN_PG;
2187 /* set tags on unselected pchans only */
2188 if ((pchan->bone->flag & BONE_SELECTED)==0)
2189 pchan->bone->flag |= BONE_HIDDEN_PG;
2195 /* draw ghosts that occur within a frame range
2196 * note: object should be in posemode
2198 static void draw_ghost_poses_range(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
2200 Object *ob= base->object;
2201 AnimData *adt= BKE_animdata_from_id(&ob->id);
2202 bArmature *arm= ob->data;
2203 bPose *posen, *poseo;
2204 float start, end, stepsize, range, colfac;
2205 int cfrao, flago, ipoflago;
2207 start = (float)arm->ghostsf;
2208 end = (float)arm->ghostef;
2212 stepsize= (float)(arm->ghostsize);
2213 range= (float)(end - start);
2216 ob->mode &= ~OB_MODE_POSE;
2219 arm->flag &= ~(ARM_DRAWNAMES|ARM_DRAWAXES);
2220 ipoflago= ob->ipoflag;
2221 ob->ipoflag |= OB_DISABLE_PATH;
2225 copy_pose(&posen, ob->pose, 1);
2227 armature_rebuild_pose(ob, ob->data); /* child pointers for IK */
2228 ghost_poses_tag_unselected(ob, 0); /* hide unselected bones if need be */
2231 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
2233 /* draw from first frame of range to last */
2234 for (CFRA= (int)start; CFRA < end; CFRA += (int)stepsize) {
2235 colfac = (end - (float)CFRA) / range;
2236 UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0*sqrt(colfac)));
2238 BKE_animsys_evaluate_animdata(&ob->id, adt, (float)CFRA, ADT_RECALC_ALL);
2239 where_is_pose(scene, ob);
2240 draw_pose_bones(scene, v3d, ar, base, OB_WIRE, TRUE);
2242 glDisable(GL_BLEND);
2243 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
2245 ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */
2252 armature_rebuild_pose(ob, ob->data);
2253 ob->mode |= OB_MODE_POSE;
2254 ob->ipoflag= ipoflago;
2257 /* draw ghosts on keyframes in action within range
2258 * - object should be in posemode
2260 static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
2262 Object *ob= base->object;
2263 AnimData *adt= BKE_animdata_from_id(&ob->id);
2264 bAction *act= (adt) ? adt->action : NULL;
2265 bArmature *arm= ob->data;
2266 bPose *posen, *poseo;
2268 ActKeyColumn *ak, *akn;
2269 float start, end, range, colfac, i;
2272 start = (float)arm->ghostsf;
2273 end = (float)arm->ghostef;
2277 /* get keyframes - then clip to only within range */
2278 BLI_dlrbTree_init(&keys);
2279 action_to_keylist(adt, act, &keys, NULL);
2280 BLI_dlrbTree_linkedlist_sync(&keys);
2283 for (ak= keys.first; ak; ak= akn) {
2286 if ((ak->cfra < start) || (ak->cfra > end))
2287 BLI_freelinkN((ListBase *)&keys, ak);
2291 if (range == 0) return;
2294 ob->mode &= ~OB_MODE_POSE;
2297 arm->flag &= ~(ARM_DRAWNAMES|ARM_DRAWAXES);
2298 ob->ipoflag |= OB_DISABLE_PATH;
2302 copy_pose(&posen, ob->pose, 1);
2304 armature_rebuild_pose(ob, ob->data); /* child pointers for IK */
2305 ghost_poses_tag_unselected(ob, 0); /* hide unselected bones if need be */
2308 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
2310 /* draw from first frame of range to last */
2311 for (ak=keys.first, i=0; ak; ak=ak->next, i++) {
2313 UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0*sqrt(colfac)));
2315 CFRA= (int)ak->cfra;
2317 BKE_animsys_evaluate_animdata(&ob->id, adt, (float)CFRA, ADT_RECALC_ALL);
2318 where_is_pose(scene, ob);
2319 draw_pose_bones(scene, v3d, ar, base, OB_WIRE, TRUE);
2321 glDisable(GL_BLEND);
2322 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
2324 ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */
2325 BLI_dlrbTree_free(&keys);
2332 armature_rebuild_pose(ob, ob->data);
2333 ob->mode |= OB_MODE_POSE;
2336 /* draw ghosts around current frame
2337 * - object is supposed to be armature in posemode
2339 static void draw_ghost_poses(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
2341 Object *ob= base->object;
2342 AnimData *adt= BKE_animdata_from_id(&ob->id);
2343 bArmature *arm= ob->data;
2344 bPose *posen, *poseo;
2345 float cur, start, end, stepsize, range, colfac, actframe, ctime;
2348 /* pre conditions, get an action with sufficient frames */
2349 if ELEM(NULL, adt, adt->action)
2352 calc_action_range(adt->action, &start, &end, 0);
2356 stepsize= (float)(arm->ghostsize);
2357 range= (float)(arm->ghostep)*stepsize + 0.5f; /* plus half to make the for loop end correct */
2360 ob->mode &= ~OB_MODE_POSE;
2362 actframe= BKE_nla_tweakedit_remap(adt, (float)CFRA, 0);
2364 arm->flag &= ~(ARM_DRAWNAMES|ARM_DRAWAXES);
2368 copy_pose(&posen, ob->pose, 1);
2370 armature_rebuild_pose(ob, ob->data); /* child pointers for IK */
2371 ghost_poses_tag_unselected(ob, 0); /* hide unselected bones if need be */
2374 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
2376 /* draw from darkest blend to lowest */
2377 for(cur= stepsize; cur<range; cur+=stepsize) {
2378 ctime= cur - (float)fmod(cfrao, stepsize); /* ensures consistent stepping */
2379 colfac= ctime/range;
2380 UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0*sqrt(colfac)));
2382 /* only within action range */
2383 if (actframe+ctime >= start && actframe+ctime <= end) {
2384 CFRA= (int)BKE_nla_tweakedit_remap(adt, actframe+ctime, NLATIME_CONVERT_MAP);
2386 if (CFRA != cfrao) {
2387 BKE_animsys_evaluate_animdata(&ob->id, adt, (float)CFRA, ADT_RECALC_ALL);
2388 where_is_pose(scene, ob);
2389 draw_pose_bones(scene, v3d, ar, base, OB_WIRE, TRUE);
2393 ctime= cur + (float)fmod((float)cfrao, stepsize) - stepsize+1.0f; /* ensures consistent stepping */
2394 colfac= ctime/range;
2395 UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0*sqrt(colfac)));
2397 /* only within action range */
2398 if ((actframe-ctime >= start) && (actframe-ctime <= end)) {
2399 CFRA= (int)BKE_nla_tweakedit_remap(adt, actframe-ctime, NLATIME_CONVERT_MAP);
2401 if (CFRA != cfrao) {
2402 BKE_animsys_evaluate_animdata(&ob->id, adt, (float)CFRA, ADT_RECALC_ALL);
2403 where_is_pose(scene, ob);
2404 draw_pose_bones(scene, v3d, ar, base, OB_WIRE, TRUE);
2408 glDisable(GL_BLEND);
2409 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
2411 ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */
2418 armature_rebuild_pose(ob, ob->data);
2419 ob->mode |= OB_MODE_POSE;
2422 /* ********************************** Armature Drawing - Main ************************* */
2424 /* called from drawobject.c, return 1 if nothing was drawn */
2425 int draw_armature(Scene *scene, View3D *v3d, ARegion *ar, Base *base, int dt, int flag)
2427 Object *ob= base->object;
2428 bArmature *arm= ob->data;
2431 if(v3d->flag2 & V3D_RENDER_OVERRIDE)
2434 if(dt>OB_WIRE && arm->drawtype!=ARM_LINE) {
2435 /* we use color for solid lighting */
2436 glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
2437 glEnable(GL_COLOR_MATERIAL);
2438 glColor3ub(255,0,255); // clear spec
2439 glDisable(GL_COLOR_MATERIAL);
2441 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
2442 glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW); // only for lighting...
2445 /* arm->flag is being used to detect mode... */
2448 arm->flag |= ARM_EDITMODE;
2449 draw_ebones(v3d, ar, ob, dt);
2450 arm->flag &= ~ARM_EDITMODE;
2454 if(ob->pose && ob->pose->chanbase.first) {
2455 /* drawing posemode selection indices or colors only in these cases */
2456 if(!(base->flag & OB_FROMDUPLI)) {
2457 if(G.f & G_PICKSEL) {
2458 if(OBACT && (OBACT->mode & OB_MODE_WEIGHT_PAINT)) {
2459 if(ob==modifiers_isDeformedByArmature(OBACT))
2460 arm->flag |= ARM_POSEMODE;
2462 else if(ob->mode & OB_MODE_POSE)
2463 arm->flag |= ARM_POSEMODE;
2465 else if(ob->mode & OB_MODE_POSE) {
2466 if (arm->ghosttype == ARM_GHOST_RANGE) {
2467 draw_ghost_poses_range(scene, v3d, ar, base);
2469 else if (arm->ghosttype == ARM_GHOST_KEYS) {
2470 draw_ghost_poses_keys(scene, v3d, ar, base);
2472 else if (arm->ghosttype == ARM_GHOST_CUR) {
2474 draw_ghost_poses(scene, v3d, ar, base);
2476 if ((flag & DRAW_SCENESET)==0) {
2478 arm->flag |= ARM_POSEMODE;
2479 else if(OBACT && (OBACT->mode & OB_MODE_WEIGHT_PAINT)) {
2480 if(ob==modifiers_isDeformedByArmature(OBACT))
2481 arm->flag |= ARM_POSEMODE;
2483 draw_pose_paths(scene, v3d, ar, ob);
2487 draw_pose_bones(scene, v3d, ar, base, dt, FALSE);
2488 arm->flag &= ~ARM_POSEMODE;
2490 if(ob->mode & OB_MODE_POSE)
2491 UI_ThemeColor(TH_WIRE); /* restore, for extra draw stuff */
2496 glFrontFace(GL_CCW);
2501 /* *************** END Armature drawing ******************* */