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_modifier.h"
66 #include "BKE_object.h"
67 #include "BKE_utildefines.h"
70 #include "BIF_glutil.h"
72 #include "ED_armature.h"
73 #include "ED_keyframes_draw.h"
78 #include "UI_resources.h"
80 #include "view3d_intern.h"
83 /* *************** Armature Drawing - Coloring API ***************************** */
85 /* global here is reset before drawing each bone */
86 static ThemeWireColor *bcolor= NULL;
88 /* values of colCode for set_pchan_glcolor */
90 PCHAN_COLOR_NORMAL = 0, /* normal drawing */
91 PCHAN_COLOR_SOLID, /* specific case where "solid" color is needed */
92 PCHAN_COLOR_CONSTS, /* "constraint" colors (which may/may-not be suppressed) */
94 PCHAN_COLOR_SPHEREBONE_BASE, /* for the 'stick' of sphere (envelope) bones */
95 PCHAN_COLOR_SPHEREBONE_END, /* for the ends of sphere (envelope) bones */
96 PCHAN_COLOR_LINEBONE /* for the middle of line-bones */
99 /* This function sets the color-set for coloring a certain bone */
100 static void set_pchan_colorset (Object *ob, bPoseChannel *pchan)
102 bPose *pose= (ob) ? ob->pose : NULL;
103 bArmature *arm= (ob) ? ob->data : NULL;
104 bActionGroup *grp= NULL;
105 short color_index= 0;
108 if (ELEM4(NULL, ob, arm, pose, pchan)) {
113 /* only try to set custom color if enabled for armature */
114 if (arm->flag & ARM_COL_CUSTOM) {
115 /* currently, a bone can only use a custom color set if it's group (if it has one),
116 * has been set to use one
118 if (pchan->agrp_index) {
119 grp= (bActionGroup *)BLI_findlink(&pose->agroups, (pchan->agrp_index - 1));
121 color_index= grp->customCol;
125 /* bcolor is a pointer to the color set to use. If NULL, then the default
126 * color set (based on the theme colors for 3d-view) is used.
128 if (color_index > 0) {
129 bTheme *btheme= U.themes.first;
130 bcolor= &btheme->tarm[(color_index - 1)];
132 else if (color_index == -1) {
133 /* use the group's own custom color set */
134 bcolor= (grp)? &grp->cs : NULL;
140 /* This function is for brightening/darkening a given color (like UI_ThemeColorShade()) */
141 static void cp_shade_color3ub (char cp[], int offset)
145 r= offset + (int) cp[0];
147 g= offset + (int) cp[1];
149 b= offset + (int) cp[2];
157 /* This function sets the gl-color for coloring a certain bone (based on bcolor) */
158 static short set_pchan_glColor (short colCode, int armflag, int boneflag, int constflag)
161 case PCHAN_COLOR_NORMAL:
166 if (boneflag & BONE_ACTIVE) {
167 VECCOPY(cp, bcolor->active);
169 else if (boneflag & BONE_SELECTED) {
170 VECCOPY(cp, bcolor->select);
173 /* a bit darker than solid */
174 VECCOPY(cp, bcolor->solid);
175 cp_shade_color3ub(cp, -50);
178 glColor3ub(cp[0], cp[1], cp[2]);
181 if (boneflag & BONE_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 40);
182 else if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_BONE_POSE);
183 else UI_ThemeColor(TH_WIRE);
190 case PCHAN_COLOR_SOLID:
193 char *cp= bcolor->solid;
194 glColor3ub(cp[0], cp[1], cp[2]);
197 UI_ThemeColor(TH_BONE_SOLID);
203 case PCHAN_COLOR_CONSTS:
205 if ( (bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS) ) {
206 if (constflag & PCHAN_HAS_STRIDE) glColor4ub(0, 0, 200, 80);
207 else if (constflag & PCHAN_HAS_TARGET) glColor4ub(255, 150, 0, 80);
208 else if (constflag & PCHAN_HAS_IK) glColor4ub(255, 255, 0, 80);
209 else if (constflag & PCHAN_HAS_CONST) glColor4ub(0, 255, 120, 80);
210 else if (constflag) UI_ThemeColor4(TH_BONE_POSE); // PCHAN_HAS_ACTION
219 case PCHAN_COLOR_SPHEREBONE_BASE:
224 if (boneflag & BONE_ACTIVE) {
225 VECCOPY(cp, bcolor->active);
227 else if (boneflag & BONE_SELECTED) {
228 VECCOPY(cp, bcolor->select);
231 VECCOPY(cp, bcolor->solid);
234 glColor3ub(cp[0], cp[1], cp[2]);
237 if (boneflag & BONE_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 40);
238 else if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_BONE_POSE);
239 else UI_ThemeColor(TH_BONE_SOLID);
245 case PCHAN_COLOR_SPHEREBONE_END:
250 if (boneflag & BONE_ACTIVE) {
251 VECCOPY(cp, bcolor->active);
252 cp_shade_color3ub(cp, 10);
254 else if (boneflag & BONE_SELECTED) {
255 VECCOPY(cp, bcolor->select);
256 cp_shade_color3ub(cp, -30);
259 VECCOPY(cp, bcolor->solid);
260 cp_shade_color3ub(cp, -30);
263 glColor3ub(cp[0], cp[1], cp[2]);
266 if (boneflag & BONE_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 10);
267 else if (boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_BONE_POSE, -30);
268 else UI_ThemeColorShade(TH_BONE_SOLID, -30);
273 case PCHAN_COLOR_LINEBONE:
275 /* inner part in background color or constraint */
276 if ( (constflag) && ((bcolor==NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS)) ) {
277 if (constflag & PCHAN_HAS_STRIDE) glColor3ub(0, 0, 200);
278 else if (constflag & PCHAN_HAS_TARGET) glColor3ub(255, 150, 0);
279 else if (constflag & PCHAN_HAS_IK) glColor3ub(255, 255, 0);
280 else if (constflag & PCHAN_HAS_CONST) glColor3ub(0, 255, 120);
281 else if (constflag) UI_ThemeColor(TH_BONE_POSE); /* PCHAN_HAS_ACTION */
285 char *cp= bcolor->solid;
286 glColor4ub(cp[0], cp[1], cp[2], 204);
289 UI_ThemeColorShade(TH_BACK, -30);
301 /* *************** Armature drawing, helper calls for parts ******************* */
303 /* half the cube, in Y */
304 static float cube[8][3] = {
315 static void drawsolidcube_size(float xsize, float ysize, float zsize)
317 static GLuint displist=0;
320 glScalef(xsize, ysize, zsize);
322 n[0]=0; n[1]=0; n[2]=0;
325 displist= glGenLists(1);
326 glNewList(displist, GL_COMPILE_AND_EXECUTE);
331 glVertex3fv(cube[0]); glVertex3fv(cube[1]); glVertex3fv(cube[2]); glVertex3fv(cube[3]);
335 glVertex3fv(cube[0]); glVertex3fv(cube[4]); glVertex3fv(cube[5]); glVertex3fv(cube[1]);
339 glVertex3fv(cube[4]); glVertex3fv(cube[7]); glVertex3fv(cube[6]); glVertex3fv(cube[5]);
343 glVertex3fv(cube[7]); glVertex3fv(cube[3]); glVertex3fv(cube[2]); glVertex3fv(cube[6]);
347 glVertex3fv(cube[1]); glVertex3fv(cube[5]); glVertex3fv(cube[6]); glVertex3fv(cube[2]);
351 glVertex3fv(cube[7]); glVertex3fv(cube[4]); glVertex3fv(cube[0]); glVertex3fv(cube[3]);
356 else glCallList(displist);
360 static void drawcube_size(float xsize, float ysize, float zsize)
362 static GLuint displist=0;
364 glScalef(xsize, ysize, zsize);
367 displist= glGenLists(1);
368 glNewList(displist, GL_COMPILE_AND_EXECUTE);
370 glBegin(GL_LINE_STRIP);
371 glVertex3fv(cube[0]); glVertex3fv(cube[1]);glVertex3fv(cube[2]); glVertex3fv(cube[3]);
372 glVertex3fv(cube[0]); glVertex3fv(cube[4]);glVertex3fv(cube[5]); glVertex3fv(cube[6]);
373 glVertex3fv(cube[7]); glVertex3fv(cube[4]);
377 glVertex3fv(cube[1]); glVertex3fv(cube[5]);
378 glVertex3fv(cube[2]); glVertex3fv(cube[6]);
379 glVertex3fv(cube[3]); glVertex3fv(cube[7]);
384 else glCallList(displist);
389 static void draw_bonevert(void)
391 static GLuint displist=0;
396 displist= glGenLists(1);
397 glNewList(displist, GL_COMPILE_AND_EXECUTE);
401 qobj = gluNewQuadric();
402 gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
403 gluDisk(qobj, 0.0, 0.05, 16, 1);
405 glRotatef(90, 0, 1, 0);
406 gluDisk(qobj, 0.0, 0.05, 16, 1);
408 glRotatef(90, 1, 0, 0);
409 gluDisk(qobj, 0.0, 0.05, 16, 1);
411 gluDeleteQuadric(qobj);
417 glCallList(displist);
420 static void draw_bonevert_solid(void)
422 static GLuint displist=0;
427 displist= glGenLists(1);
428 glNewList(displist, GL_COMPILE_AND_EXECUTE);
430 qobj = gluNewQuadric();
431 gluQuadricDrawStyle(qobj, GLU_FILL);
432 glShadeModel(GL_SMOOTH);
433 gluSphere(qobj, 0.05, 8, 5);
434 glShadeModel(GL_FLAT);
435 gluDeleteQuadric(qobj);
440 glCallList(displist);
443 static void draw_bone_octahedral()
445 static GLuint displist=0;
450 displist= glGenLists(1);
451 glNewList(displist, GL_COMPILE_AND_EXECUTE);
453 vec[0][0]= vec[0][1]= vec[0][2]= 0.0f;
454 vec[5][0]= vec[5][2]= 0.0f; vec[5][1]= 1.0f;
456 vec[1][0]= 0.1f; vec[1][2]= 0.1f; vec[1][1]= 0.1f;
457 vec[2][0]= 0.1f; vec[2][2]= -0.1f; vec[2][1]= 0.1f;
458 vec[3][0]= -0.1f; vec[3][2]= -0.1f; vec[3][1]= 0.1f;
459 vec[4][0]= -0.1f; vec[4][2]= 0.1f; vec[4][1]= 0.1f;
461 /* Section 1, sides */
462 glBegin(GL_LINE_LOOP);
473 /* Section 1, square */
474 glBegin(GL_LINE_LOOP);
484 glCallList(displist);
487 static void draw_bone_solid_octahedral(void)
489 static GLuint displist=0;
492 float vec[6][3], nor[3];
494 displist= glGenLists(1);
495 glNewList(displist, GL_COMPILE_AND_EXECUTE);
497 vec[0][0]= vec[0][1]= vec[0][2]= 0.0f;
498 vec[5][0]= vec[5][2]= 0.0f; vec[5][1]= 1.0f;
500 vec[1][0]= 0.1f; vec[1][2]= 0.1f; vec[1][1]= 0.1f;
501 vec[2][0]= 0.1f; vec[2][2]= -0.1f; vec[2][1]= 0.1f;
502 vec[3][0]= -0.1f; vec[3][2]= -0.1f; vec[3][1]= 0.1f;
503 vec[4][0]= -0.1f; vec[4][2]= 0.1f; vec[4][1]= 0.1f;
506 glBegin(GL_TRIANGLES);
508 CalcNormFloat(vec[2], vec[1], vec[0], nor);
510 glVertex3fv(vec[2]); glVertex3fv(vec[1]); glVertex3fv(vec[0]);
512 CalcNormFloat(vec[3], vec[2], vec[0], nor);
514 glVertex3fv(vec[3]); glVertex3fv(vec[2]); glVertex3fv(vec[0]);
516 CalcNormFloat(vec[4], vec[3], vec[0], nor);
518 glVertex3fv(vec[4]); glVertex3fv(vec[3]); glVertex3fv(vec[0]);
520 CalcNormFloat(vec[1], vec[4], vec[0], nor);
522 glVertex3fv(vec[1]); glVertex3fv(vec[4]); glVertex3fv(vec[0]);
525 CalcNormFloat(vec[5], vec[1], vec[2], nor);
527 glVertex3fv(vec[5]); glVertex3fv(vec[1]); glVertex3fv(vec[2]);
529 CalcNormFloat(vec[5], vec[2], vec[3], nor);
531 glVertex3fv(vec[5]); glVertex3fv(vec[2]); glVertex3fv(vec[3]);
533 CalcNormFloat(vec[5], vec[3], vec[4], nor);
535 glVertex3fv(vec[5]); glVertex3fv(vec[3]); glVertex3fv(vec[4]);
537 CalcNormFloat(vec[5], vec[4], vec[1], nor);
539 glVertex3fv(vec[5]); glVertex3fv(vec[4]); glVertex3fv(vec[1]);
546 glCallList(displist);
549 /* *************** Armature drawing, bones ******************* */
552 static void draw_bone_points(int dt, int armflag, unsigned int boneflag, int id)
554 /* Draw root point if we are not connected */
555 if ((boneflag & BONE_CONNECTED)==0) {
557 glLoadName(id | BONESEL_ROOT);
560 if (armflag & ARM_EDITMODE) {
561 if (boneflag & BONE_ROOTSEL) UI_ThemeColor(TH_VERTEX_SELECT);
562 else UI_ThemeColor(TH_VERTEX);
566 if (armflag & ARM_POSEMODE)
567 set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, 0);
569 UI_ThemeColor(TH_BONE_SOLID);
573 draw_bonevert_solid();
580 glLoadName(id | BONESEL_TIP);
583 if (armflag & ARM_EDITMODE) {
584 if (boneflag & BONE_TIPSEL) UI_ThemeColor(TH_VERTEX_SELECT);
585 else UI_ThemeColor(TH_VERTEX);
589 if (armflag & ARM_POSEMODE)
590 set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, 0);
592 UI_ThemeColor(TH_BONE_SOLID);
595 glTranslatef(0.0f, 1.0f, 0.0f);
597 draw_bonevert_solid();
600 glTranslatef(0.0f, -1.0f, 0.0f);
604 /* 16 values of sin function (still same result!) */
605 static float si[16] = {
607 0.20129852f, 0.39435585f,
608 0.57126821f, 0.72479278f,
609 0.84864425f, 0.93775213f,
610 0.98846832f, 0.99871650f,
611 0.96807711f, 0.89780453f,
612 0.79077573f, 0.65137248f,
613 0.48530196f, 0.29936312f,
616 /* 16 values of cos function (still same result!) */
617 static float co[16] ={
619 0.97952994f, 0.91895781f,
620 0.82076344f, 0.68896691f,
621 0.52896401f, 0.34730525f,
622 0.15142777f, -0.05064916f,
623 -0.25065253f, -0.44039415f,
624 -0.61210598f, -0.75875812f,
625 -0.87434661f, -0.95413925f,
631 /* smat, imat = mat & imat to draw screenaligned */
632 static void draw_sphere_bone_dist(float smat[][4], float imat[][4], int boneflag, bPoseChannel *pchan, EditBone *ebone)
634 float head, tail, length, dist;
635 float *headvec, *tailvec, dirvec[3];
637 /* figure out the sizes of spheres */
639 /* this routine doesn't call set_matrix_editbone() that calculates it */
640 ebone->length = VecLenf(ebone->head, ebone->tail);
642 length= ebone->length;
643 tail= ebone->rad_tail;
645 if (ebone->parent && (ebone->flag & BONE_CONNECTED))
646 head= ebone->parent->rad_tail;
648 head= ebone->rad_head;
649 headvec= ebone->head;
650 tailvec= ebone->tail;
653 length= pchan->bone->length;
654 tail= pchan->bone->rad_tail;
655 dist= pchan->bone->dist;
656 if (pchan->parent && (pchan->bone->flag & BONE_CONNECTED))
657 head= pchan->parent->bone->rad_tail;
659 head= pchan->bone->rad_head;
660 headvec= pchan->pose_head;
661 tailvec= pchan->pose_tail;
664 /* ***** draw it ***** */
666 /* move vector to viewspace */
667 VecSubf(dirvec, tailvec, headvec);
668 Mat4Mul3Vecfl(smat, dirvec);
671 /* move vector back */
672 Mat4Mul3Vecfl(imat, dirvec);
674 if (0.0f != Normalize(dirvec)) {
675 float norvec[3], vec1[3], vec2[3], vec[3];
678 //VecMulf(dirvec, head);
679 Crossf(norvec, dirvec, imat[2]);
681 glBegin(GL_QUAD_STRIP);
683 for (a=0; a<16; a++) {
684 vec[0]= - *(si+a) * dirvec[0] + *(co+a) * norvec[0];
685 vec[1]= - *(si+a) * dirvec[1] + *(co+a) * norvec[1];
686 vec[2]= - *(si+a) * dirvec[2] + *(co+a) * norvec[2];
688 vec1[0]= headvec[0] + head*vec[0];
689 vec1[1]= headvec[1] + head*vec[1];
690 vec1[2]= headvec[2] + head*vec[2];
691 vec2[0]= headvec[0] + (head+dist)*vec[0];
692 vec2[1]= headvec[1] + (head+dist)*vec[1];
693 vec2[2]= headvec[2] + (head+dist)*vec[2];
695 glColor4ub(255, 255, 255, 50);
697 //glColor4ub(255, 255, 255, 0);
701 for (a=15; a>=0; a--) {
702 vec[0]= *(si+a) * dirvec[0] + *(co+a) * norvec[0];
703 vec[1]= *(si+a) * dirvec[1] + *(co+a) * norvec[1];
704 vec[2]= *(si+a) * dirvec[2] + *(co+a) * norvec[2];
706 vec1[0]= tailvec[0] + tail*vec[0];
707 vec1[1]= tailvec[1] + tail*vec[1];
708 vec1[2]= tailvec[2] + tail*vec[2];
709 vec2[0]= tailvec[0] + (tail+dist)*vec[0];
710 vec2[1]= tailvec[1] + (tail+dist)*vec[1];
711 vec2[2]= tailvec[2] + (tail+dist)*vec[2];
713 //glColor4ub(255, 255, 255, 50);
715 //glColor4ub(255, 255, 255, 0);
718 /* make it cyclic... */
720 vec[0]= - *(si) * dirvec[0] + *(co) * norvec[0];
721 vec[1]= - *(si) * dirvec[1] + *(co) * norvec[1];
722 vec[2]= - *(si) * dirvec[2] + *(co) * norvec[2];
724 vec1[0]= headvec[0] + head*vec[0];
725 vec1[1]= headvec[1] + head*vec[1];
726 vec1[2]= headvec[2] + head*vec[2];
727 vec2[0]= headvec[0] + (head+dist)*vec[0];
728 vec2[1]= headvec[1] + (head+dist)*vec[1];
729 vec2[2]= headvec[2] + (head+dist)*vec[2];
731 //glColor4ub(255, 255, 255, 50);
733 //glColor4ub(255, 255, 255, 0);
741 /* smat, imat = mat & imat to draw screenaligned */
742 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)
744 float head, tail, length;
745 float *headvec, *tailvec, dirvec[3];
747 /* figure out the sizes of spheres */
749 /* this routine doesn't call set_matrix_editbone() that calculates it */
750 ebone->length = VecLenf(ebone->head, ebone->tail);
752 length= ebone->length;
753 tail= ebone->rad_tail;
754 if (ebone->parent && (boneflag & BONE_CONNECTED))
755 head= ebone->parent->rad_tail;
757 head= ebone->rad_head;
758 headvec= ebone->head;
759 tailvec= ebone->tail;
762 length= pchan->bone->length;
763 tail= pchan->bone->rad_tail;
764 if ((pchan->parent) && (boneflag & BONE_CONNECTED))
765 head= pchan->parent->bone->rad_tail;
767 head= pchan->bone->rad_head;
768 headvec= pchan->pose_head;
769 tailvec= pchan->pose_tail;
772 /* sphere root color */
773 if (armflag & ARM_EDITMODE) {
774 if (boneflag & BONE_ROOTSEL) UI_ThemeColor(TH_VERTEX_SELECT);
775 else UI_ThemeColor(TH_VERTEX);
777 else if (armflag & ARM_POSEMODE)
778 set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
780 /* Draw root point if we are not connected */
781 if ((boneflag & BONE_CONNECTED)==0) {
783 glLoadName(id | BONESEL_ROOT);
785 drawcircball(GL_LINE_LOOP, headvec, head, imat);
789 if (armflag & ARM_EDITMODE) {
790 if (boneflag & BONE_TIPSEL) UI_ThemeColor(TH_VERTEX_SELECT);
791 else UI_ThemeColor(TH_VERTEX);
795 glLoadName(id | BONESEL_TIP);
797 drawcircball(GL_LINE_LOOP, tailvec, tail, imat);
800 if (armflag & ARM_EDITMODE) {
801 if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_SELECT);
802 else UI_ThemeColor(TH_WIRE);
805 VecSubf(dirvec, tailvec, headvec);
807 /* move vector to viewspace */
808 Mat4Mul3Vecfl(smat, dirvec);
811 /* move vector back */
812 Mat4Mul3Vecfl(imat, dirvec);
814 if (0.0f != Normalize(dirvec)) {
815 float norvech[3], norvect[3], vec[3];
817 VECCOPY(vec, dirvec);
819 VecMulf(dirvec, head);
820 Crossf(norvech, dirvec, imat[2]);
823 Crossf(norvect, vec, imat[2]);
826 glLoadName(id | BONESEL_BONE);
829 vec[0]= headvec[0] + norvech[0];
830 vec[1]= headvec[1] + norvech[1];
831 vec[2]= headvec[2] + norvech[2];
833 vec[0]= tailvec[0] + norvect[0];
834 vec[1]= tailvec[1] + norvect[1];
835 vec[2]= tailvec[2] + norvect[2];
837 vec[0]= headvec[0] - norvech[0];
838 vec[1]= headvec[1] - norvech[1];
839 vec[2]= headvec[2] - norvech[2];
841 vec[0]= tailvec[0] - norvect[0];
842 vec[1]= tailvec[1] - norvect[1];
843 vec[2]= tailvec[2] - norvect[2];
850 /* does wire only for outline selecting */
851 static void draw_sphere_bone(int dt, int armflag, int boneflag, int constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
854 float head, tail, length;
858 qobj = gluNewQuadric();
860 /* figure out the sizes of spheres */
862 length= ebone->length;
863 tail= ebone->rad_tail;
864 if (ebone->parent && (boneflag & BONE_CONNECTED))
865 head= ebone->parent->rad_tail;
867 head= ebone->rad_head;
870 length= pchan->bone->length;
871 tail= pchan->bone->rad_tail;
872 if (pchan->parent && (boneflag & BONE_CONNECTED))
873 head= pchan->parent->bone->rad_tail;
875 head= pchan->bone->rad_head;
878 /* move to z-axis space */
879 glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
882 /* set up solid drawing */
883 glEnable(GL_COLOR_MATERIAL);
884 glEnable(GL_LIGHTING);
886 gluQuadricDrawStyle(qobj, GLU_FILL);
887 glShadeModel(GL_SMOOTH);
890 gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
893 /* sphere root color */
894 if (armflag & ARM_EDITMODE) {
895 if (boneflag & BONE_ROOTSEL) UI_ThemeColor(TH_VERTEX_SELECT);
896 else UI_ThemeColorShade(TH_BONE_SOLID, -30);
898 else if (armflag & ARM_POSEMODE)
899 set_pchan_glColor(PCHAN_COLOR_SPHEREBONE_END, armflag, boneflag, constflag);
900 else if (dt==OB_SOLID)
901 UI_ThemeColorShade(TH_BONE_SOLID, -30);
903 /* Draw root point if we are not connected */
904 if ((boneflag & BONE_CONNECTED)==0) {
906 glLoadName(id | BONESEL_ROOT);
907 gluSphere(qobj, head, 16, 10);
911 if (armflag & ARM_EDITMODE) {
912 if (boneflag & BONE_TIPSEL) UI_ThemeColor(TH_VERTEX_SELECT);
913 else UI_ThemeColorShade(TH_BONE_SOLID, -30);
917 glLoadName(id | BONESEL_TIP);
919 glTranslatef(0.0f, 0.0f, length);
920 gluSphere(qobj, tail, 16, 10);
921 glTranslatef(0.0f, 0.0f, -length);
924 if (armflag & ARM_EDITMODE) {
925 if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_SELECT);
926 else UI_ThemeColor(TH_BONE_SOLID);
928 else if (armflag & ARM_POSEMODE)
929 set_pchan_glColor(PCHAN_COLOR_SPHEREBONE_BASE, armflag, boneflag, constflag);
930 else if (dt == OB_SOLID)
931 UI_ThemeColor(TH_BONE_SOLID);
933 fac1= (length-head)/length;
934 fac2= (length-tail)/length;
936 if (length > (head+tail)) {
938 glLoadName (id | BONESEL_BONE);
940 glEnable(GL_POLYGON_OFFSET_FILL);
941 glPolygonOffset(-1.0f, -1.0f);
943 glTranslatef(0.0f, 0.0f, head);
944 gluCylinder(qobj, fac1*head + (1.0f-fac1)*tail, fac2*tail + (1.0f-fac2)*head, length-head-tail, 16, 1);
945 glTranslatef(0.0f, 0.0f, -head);
947 glDisable(GL_POLYGON_OFFSET_FILL);
949 /* draw sphere on extrema */
950 glTranslatef(0.0f, 0.0f, length-tail);
951 gluSphere(qobj, fac2*tail + (1.0f-fac2)*head, 16, 10);
952 glTranslatef(0.0f, 0.0f, -length+tail);
954 glTranslatef(0.0f, 0.0f, head);
955 gluSphere(qobj, fac1*head + (1.0f-fac1)*tail, 16, 10);
958 /* 1 sphere in center */
959 glTranslatef(0.0f, 0.0f, (head + length-tail)/2.0f);
960 gluSphere(qobj, fac1*head + (1.0f-fac1)*tail, 16, 10);
965 glShadeModel(GL_FLAT);
966 glDisable(GL_LIGHTING);
967 glDisable(GL_COLOR_MATERIAL);
971 gluDeleteQuadric(qobj);
974 static GLubyte bm_dot6[]= {0x0, 0x18, 0x3C, 0x7E, 0x7E, 0x3C, 0x18, 0x0};
975 static GLubyte bm_dot8[]= {0x3C, 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C};
977 static GLubyte bm_dot5[]= {0x0, 0x0, 0x10, 0x38, 0x7c, 0x38, 0x10, 0x0};
978 static GLubyte bm_dot7[]= {0x0, 0x38, 0x7C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38};
981 static void draw_line_bone(int armflag, int boneflag, int constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
985 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
988 length= pchan->bone->length;
990 length= ebone->length;
993 glScalef(length, length, length);
995 /* this chunk not in object mode */
996 if (armflag & (ARM_EDITMODE|ARM_POSEMODE)) {
998 if (armflag & ARM_POSEMODE)
999 set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
1000 else if (armflag & ARM_EDITMODE) {
1001 UI_ThemeColor(TH_WIRE);
1004 /* Draw root point if we are not connected */
1005 if ((boneflag & BONE_CONNECTED)==0) {
1006 if (G.f & G_PICKSEL) { // no bitmap in selection mode, crashes 3d cards...
1007 glLoadName (id | BONESEL_ROOT);
1009 glVertex3f(0.0f, 0.0f, 0.0f);
1013 glRasterPos3f(0.0f, 0.0f, 0.0f);
1014 glBitmap(8, 8, 4, 4, 0, 0, bm_dot8);
1019 glLoadName((GLuint) id|BONESEL_BONE);
1022 glVertex3f(0.0f, 0.0f, 0.0f);
1023 glVertex3f(0.0f, 1.0f, 0.0f);
1027 if (G.f & G_PICKSEL) {
1028 /* no bitmap in selection mode, crashes 3d cards... */
1029 glLoadName(id | BONESEL_TIP);
1031 glVertex3f(0.0f, 1.0f, 0.0f);
1035 glRasterPos3f(0.0f, 1.0f, 0.0f);
1036 glBitmap(8, 8, 4, 4, 0, 0, bm_dot7);
1039 /* further we send no names */
1041 glLoadName(id & 0xFFFF); /* object tag, for bordersel optim */
1043 if (armflag & ARM_POSEMODE)
1044 set_pchan_glColor(PCHAN_COLOR_LINEBONE, armflag, boneflag, constflag);
1049 /*Draw root point if we are not connected */
1050 if ((boneflag & BONE_CONNECTED)==0) {
1051 if ((G.f & G_PICKSEL)==0) {
1052 /* no bitmap in selection mode, crashes 3d cards... */
1053 if (armflag & ARM_EDITMODE) {
1054 if (boneflag & BONE_ROOTSEL) UI_ThemeColor(TH_VERTEX_SELECT);
1055 else UI_ThemeColor(TH_VERTEX);
1057 glRasterPos3f(0.0f, 0.0f, 0.0f);
1058 glBitmap(8, 8, 4, 4, 0, 0, bm_dot6);
1062 if (armflag & ARM_EDITMODE) {
1063 if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_EDGE_SELECT);
1064 else UI_ThemeColorShade(TH_BACK, -30);
1067 glVertex3f(0.0f, 0.0f, 0.0f);
1068 glVertex3f(0.0f, 1.0f, 0.0f);
1072 if ((G.f & G_PICKSEL)==0) {
1073 /* no bitmap in selection mode, crashes 3d cards... */
1074 if (armflag & ARM_EDITMODE) {
1075 if (boneflag & BONE_TIPSEL) UI_ThemeColor(TH_VERTEX_SELECT);
1076 else UI_ThemeColor(TH_VERTEX);
1078 glRasterPos3f(0.0f, 1.0f, 0.0f);
1079 glBitmap(8, 8, 4, 4, 0, 0, bm_dot5);
1087 static void draw_b_bone_boxes(int dt, bPoseChannel *pchan, float xwidth, float length, float zwidth)
1092 segments= pchan->bone->segments;
1094 if ((segments > 1) && (pchan)) {
1095 float dlen= length/(float)segments;
1096 Mat4 *bbone= b_bone_spline_setup(pchan, 0);
1099 for (a=0; a<segments; a++, bbone++) {
1101 glMultMatrixf(bbone->mat);
1102 if (dt==OB_SOLID) drawsolidcube_size(xwidth, dlen, zwidth);
1103 else drawcube_size(xwidth, dlen, zwidth);
1109 if (dt==OB_SOLID) drawsolidcube_size(xwidth, length, zwidth);
1110 else drawcube_size(xwidth, length, zwidth);
1115 static void draw_b_bone(int dt, int armflag, int boneflag, int constflag, unsigned int id, bPoseChannel *pchan, EditBone *ebone)
1117 float xwidth, length, zwidth;
1120 xwidth= pchan->bone->xwidth;
1121 length= pchan->bone->length;
1122 zwidth= pchan->bone->zwidth;
1125 xwidth= ebone->xwidth;
1126 length= ebone->length;
1127 zwidth= ebone->zwidth;
1130 /* draw points only if... */
1131 if (armflag & ARM_EDITMODE) {
1132 /* move to unitspace */
1134 glScalef(length, length, length);
1135 draw_bone_points(dt, armflag, boneflag, id);
1137 length*= 0.95f; // make vertices visible
1140 /* colors for modes */
1141 if (armflag & ARM_POSEMODE) {
1143 set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
1145 set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, constflag);
1147 else if (armflag & ARM_EDITMODE) {
1149 if (boneflag & BONE_ACTIVE) UI_ThemeColor(TH_EDGE_SELECT);
1150 else if (boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_EDGE_SELECT, -20);
1151 else UI_ThemeColor(TH_WIRE);
1154 UI_ThemeColor(TH_BONE_SOLID);
1158 glLoadName ((GLuint) id|BONESEL_BONE);
1161 /* set up solid drawing */
1163 glEnable(GL_COLOR_MATERIAL);
1164 glEnable(GL_LIGHTING);
1166 if (armflag & ARM_POSEMODE)
1167 set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, constflag);
1169 UI_ThemeColor(TH_BONE_SOLID);
1171 draw_b_bone_boxes(OB_SOLID, pchan, xwidth, length, zwidth);
1173 /* disable solid drawing */
1174 glDisable(GL_COLOR_MATERIAL);
1175 glDisable(GL_LIGHTING);
1179 if (armflag & ARM_POSEMODE) {
1181 /* set constraint colors */
1182 if (set_pchan_glColor(PCHAN_COLOR_CONSTS, armflag, boneflag, constflag)) {
1185 draw_b_bone_boxes(OB_SOLID, pchan, xwidth, length, zwidth);
1187 glDisable(GL_BLEND);
1190 /* restore colors */
1191 set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
1195 draw_b_bone_boxes(OB_WIRE, pchan, xwidth, length, zwidth);
1199 static void draw_bone(int dt, int armflag, int boneflag, int constflag, unsigned int id, float length)
1202 /* Draw a 3d octahedral bone, we use normalized space based on length,
1203 for glDisplayLists */
1205 glScalef(length, length, length);
1207 /* set up solid drawing */
1209 glEnable(GL_COLOR_MATERIAL);
1210 glEnable(GL_LIGHTING);
1211 UI_ThemeColor(TH_BONE_SOLID);
1214 /* colors for posemode */
1215 if (armflag & ARM_POSEMODE) {
1217 set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
1219 set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, constflag);
1223 draw_bone_points(dt, armflag, boneflag, id);
1225 /* now draw the bone itself */
1227 glLoadName((GLuint) id|BONESEL_BONE);
1231 if (dt <= OB_WIRE) {
1233 if (armflag & ARM_EDITMODE) {
1234 if (boneflag & BONE_ACTIVE) UI_ThemeColor(TH_EDGE_SELECT);
1235 else if (boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_EDGE_SELECT, -20);
1236 else UI_ThemeColor(TH_WIRE);
1238 else if (armflag & ARM_POSEMODE) {
1240 /* draw constraint colors */
1241 if (set_pchan_glColor(PCHAN_COLOR_CONSTS, armflag, boneflag, constflag)) {
1244 draw_bone_solid_octahedral();
1246 glDisable(GL_BLEND);
1249 /* restore colors */
1250 set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
1253 draw_bone_octahedral();
1257 if (armflag & ARM_POSEMODE)
1258 set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, constflag);
1260 UI_ThemeColor(TH_BONE_SOLID);
1261 draw_bone_solid_octahedral();
1264 /* disable solid drawing */
1266 glDisable(GL_COLOR_MATERIAL);
1267 glDisable(GL_LIGHTING);
1271 static void draw_custom_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, int dt, int armflag, int boneflag, unsigned int id, float length)
1273 if(ob==NULL) return;
1275 glScalef(length, length, length);
1277 /* colors for posemode */
1278 if (armflag & ARM_POSEMODE) {
1279 set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, 0);
1283 glLoadName((GLuint) id|BONESEL_BONE);
1286 draw_object_instance(scene, v3d, rv3d, ob, dt, armflag & ARM_POSEMODE);
1290 static void pchan_draw_IK_root_lines(bPoseChannel *pchan, short only_temp)
1293 bPoseChannel *parchan;
1295 for (con= pchan->constraints.first; con; con= con->next) {
1296 if (con->type == CONSTRAINT_TYPE_KINEMATIC && (con->enforce!=0.0)) {
1297 bKinematicConstraint *data = (bKinematicConstraint*)con->data;
1300 /* if only_temp, only draw if it is a temporary ik-chain */
1301 if ((only_temp) && !(data->flag & CONSTRAINT_IK_TEMP))
1307 /* exclude tip from chain? */
1308 if ((data->flag & CONSTRAINT_IK_TIP)==0)
1309 parchan= pchan->parent;
1313 glVertex3fv(parchan->pose_tail);
1315 /* Find the chain's root */
1316 while (parchan->parent) {
1318 if(segcount==data->rootbone || segcount>255) break; // 255 is weak
1319 parchan= parchan->parent;
1322 glVertex3fv(parchan->pose_head);
1330 static void bgl_sphere_project(float ax, float az)
1332 float dir[3], sine, q3;
1334 sine= 1.0f - ax*ax - az*az;
1335 q3= (sine < 0.0f)? 0.0f: (float)(2.0*sqrt(sine));
1338 dir[1]= 1.0f - 2.0f*sine;
1344 static void draw_dof_ellipse(float ax, float az)
1346 static float staticSine[16] = {
1347 0.0f, 0.104528463268f, 0.207911690818f, 0.309016994375f,
1348 0.406736643076f, 0.5f, 0.587785252292f, 0.669130606359f,
1349 0.743144825477f, 0.809016994375f, 0.866025403784f,
1350 0.913545457643f, 0.951056516295f, 0.978147600734f,
1351 0.994521895368f, 1.0f
1360 glColor4ub(70, 70, 70, 50);
1364 for(i=1; i<n; i++) {
1368 for(j=1; j<n-i+1; j++) {
1373 glBegin(GL_TRIANGLES);
1374 bgl_sphere_project(ax*px, az*z);
1375 bgl_sphere_project(ax*px, az*pz);
1376 bgl_sphere_project(ax*x, az*pz);
1381 bgl_sphere_project(ax*x, az*z);
1382 bgl_sphere_project(ax*x, az*pz);
1383 bgl_sphere_project(ax*px, az*pz);
1384 bgl_sphere_project(ax*px, az*z);
1393 glDisable(GL_BLEND);
1396 glColor3ub(0, 0, 0);
1398 glBegin(GL_LINE_STRIP);
1400 bgl_sphere_project(staticSine[n-i-1]*ax, staticSine[i]*az);
1404 static void draw_pose_dofs(Object *ob)
1406 bArmature *arm= ob->data;
1407 bPoseChannel *pchan;
1410 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1413 if ( (bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
1414 if (bone->flag & BONE_SELECTED) {
1415 if (bone->layer & arm->layer) {
1416 if (pchan->ikflag & (BONE_IK_XLIMIT|BONE_IK_ZLIMIT)) {
1417 if (ED_pose_channel_in_IK_chain(ob, pchan)) {
1418 float corner[4][3], posetrans[3], mat[4][4];
1419 float phi=0.0f, theta=0.0f, scale;
1422 /* in parent-bone pose, but own restspace */
1425 VECCOPY(posetrans, pchan->pose_mat[3]);
1426 glTranslatef(posetrans[0], posetrans[1], posetrans[2]);
1428 if (pchan->parent) {
1429 Mat4CpyMat4(mat, pchan->parent->pose_mat);
1430 mat[3][0]= mat[3][1]= mat[3][2]= 0.0f;
1434 Mat4CpyMat3(mat, pchan->bone->bone_mat);
1437 scale= bone->length*pchan->size[1];
1438 glScalef(scale, scale, scale);
1440 if (pchan->ikflag & BONE_IK_XLIMIT) {
1441 if (pchan->ikflag & BONE_IK_ZLIMIT) {
1442 float amin[3], amax[3];
1444 for (i=0; i<3; i++) {
1445 amin[i]= (float)sin(pchan->limitmin[i]*M_PI/360.0);
1446 amax[i]= (float)sin(pchan->limitmax[i]*M_PI/360.0);
1449 glScalef(1.0f, -1.0f, 1.0f);
1450 if ((amin[0] != 0.0f) && (amin[2] != 0.0f))
1451 draw_dof_ellipse(amin[0], amin[2]);
1452 if ((amin[0] != 0.0f) && (amax[2] != 0.0f))
1453 draw_dof_ellipse(amin[0], amax[2]);
1454 if ((amax[0] != 0.0f) && (amin[2] != 0.0f))
1455 draw_dof_ellipse(amax[0], amin[2]);
1456 if ((amax[0] != 0.0f) && (amax[2] != 0.0f))
1457 draw_dof_ellipse(amax[0], amax[2]);
1458 glScalef(1.0f, -1.0f, 1.0f);
1463 if (pchan->ikflag & BONE_IK_ZLIMIT) {
1464 theta= 0.5f*(pchan->limitmin[2]+pchan->limitmax[2]);
1465 glRotatef(theta, 0.0f, 0.0f, 1.0f);
1467 glColor3ub(50, 50, 255); // blue, Z axis limit
1468 glBegin(GL_LINE_STRIP);
1469 for (a=-16; a<=16; a++) {
1470 float fac= ((float)a)/16.0f;
1472 phi= fac * (float)(M_PI/360.0f) * (pchan->limitmax[2] - pchan->limitmin[2]);
1474 i= (a == -16) ? 0 : 1;
1475 corner[i][0]= (float)sin(phi);
1476 corner[i][1]= (float)cos(phi);
1478 glVertex3fv(corner[i]);
1482 glRotatef(-theta, 0.0f, 0.0f, 1.0f);
1485 if (pchan->ikflag & BONE_IK_XLIMIT) {
1486 theta= 0.5f * (pchan->limitmin[0] + pchan->limitmax[0]);
1487 glRotatef(theta, 1.0f, 0.0f, 0.0f);
1489 glColor3ub(255, 50, 50); // Red, X axis limit
1490 glBegin(GL_LINE_STRIP);
1491 for (a=-16; a<=16; a++) {
1492 float fac= ((float)a)/16.0f;
1493 phi= (float)(0.5*M_PI) + fac * (float)(M_PI/360.0f) * (pchan->limitmax[0] - pchan->limitmin[0]);
1495 i= (a == -16) ? 2 : 3;
1497 corner[i][1]= (float)sin(phi);
1498 corner[i][2]= (float)cos(phi);
1499 glVertex3fv(corner[i]);
1503 glRotatef(-theta, 1.0f, 0.0f, 0.0f);
1506 /* out of cone, out of bone */
1516 /* assumes object is Armature with pose */
1517 static void draw_pose_channels(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt)
1519 Object *ob= base->object;
1520 bArmature *arm= ob->data;
1521 bPoseChannel *pchan;
1524 float smat[4][4], imat[4][4];
1526 short do_dashed= 3, draw_wire= 0;
1527 short flag, constflag;
1529 /* hacky... prevent outline select from drawing dashed helplines */
1530 glGetFloatv(GL_LINE_WIDTH, &tmp);
1531 if (tmp > 1.1) do_dashed &= ~1;
1532 if (v3d->flag & V3D_HIDE_HELPLINES) do_dashed &= ~2;
1534 /* precalc inverse matrix for drawing screen aligned */
1535 if (arm->drawtype==ARM_ENVELOPE) {
1536 /* precalc inverse matrix for drawing screen aligned */
1538 Mat4MulFloat3(smat[0], 1.0f/VecLength(ob->obmat[0]));
1539 Mat4Invert(imat, smat);
1541 /* and draw blended distances */
1542 if (arm->flag & ARM_POSEMODE) {
1544 //glShadeModel(GL_SMOOTH);
1546 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
1548 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1550 if (bone && !(bone->flag & (BONE_HIDDEN_P|BONE_NO_DEFORM|BONE_HIDDEN_PG))) {
1551 if (bone->flag & (BONE_SELECTED)) {
1552 if (bone->layer & arm->layer)
1553 draw_sphere_bone_dist(smat, imat, bone->flag, pchan, NULL);
1558 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
1559 glDisable(GL_BLEND);
1560 //glShadeModel(GL_FLAT);
1564 /* little speedup, also make sure transparent only draws once */
1565 glCullFace(GL_BACK);
1566 glEnable(GL_CULL_FACE);
1568 /* if solid we draw that first, with selection codes, but without names, axes etc */
1570 if (arm->flag & ARM_POSEMODE)
1571 index= base->selcol;
1573 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1576 if ( (bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)) ) {
1577 if (bone->layer & arm->layer) {
1579 glMultMatrixf(pchan->pose_mat);
1581 /* catch exception for bone with hidden parent */
1583 if ( (bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)) )
1584 flag &= ~BONE_CONNECTED;
1586 /* set color-set to use */
1587 set_pchan_colorset(ob, pchan);
1589 if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM)) {
1590 /* if drawwire, don't try to draw in solid */
1591 if (pchan->bone->flag & BONE_DRAWWIRE)
1594 draw_custom_bone(scene, v3d, rv3d, pchan->custom, OB_SOLID, arm->flag, flag, index, bone->length);
1596 else if (arm->drawtype==ARM_LINE)
1597 ; /* nothing in solid */
1598 else if (arm->drawtype==ARM_ENVELOPE)
1599 draw_sphere_bone(OB_SOLID, arm->flag, flag, 0, index, pchan, NULL);
1600 else if (arm->drawtype==ARM_B_BONE)
1601 draw_b_bone(OB_SOLID, arm->flag, flag, 0, index, pchan, NULL);
1603 draw_bone(OB_SOLID, arm->flag, flag, 0, index, bone->length);
1610 index+= 0x10000; // pose bones count in higher 2 bytes only
1613 /* very very confusing... but in object mode, solid draw, we cannot do glLoadName yet,
1614 * stick bones and/or wire custom-shapes are drawn in next loop
1616 if ((arm->drawtype != ARM_LINE) && (draw_wire == 0)) {
1617 /* object tag, for bordersel optim */
1618 glLoadName(index & 0xFFFF);
1623 /* draw custom bone shapes as wireframes */
1624 if ( !(arm->flag & ARM_NO_CUSTOM) &&
1625 ((draw_wire) || (dt <= OB_WIRE)) )
1627 if (arm->flag & ARM_POSEMODE)
1628 index= base->selcol;
1630 /* only draw custom bone shapes that need to be drawn as wires */
1631 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1634 if ((bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
1635 if (bone->layer & arm->layer) {
1636 if (pchan->custom) {
1637 if ((dt < OB_SOLID) || (bone->flag & BONE_DRAWWIRE)) {
1639 glMultMatrixf(pchan->pose_mat);
1641 /* prepare colors */
1642 if (arm->flag & ARM_POSEMODE)
1643 set_pchan_colorset(ob, pchan);
1645 if ((scene->basact)==base) {
1646 if (base->flag & (SELECT+BA_WAS_SEL)) UI_ThemeColor(TH_ACTIVE);
1647 else UI_ThemeColor(TH_WIRE);
1650 if (base->flag & (SELECT+BA_WAS_SEL)) UI_ThemeColor(TH_SELECT);
1651 else UI_ThemeColor(TH_WIRE);
1655 /* catch exception for bone with hidden parent */
1657 if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)))
1658 flag &= ~BONE_CONNECTED;
1660 draw_custom_bone(scene, v3d, rv3d, pchan->custom, OB_WIRE, arm->flag, flag, index, bone->length);
1669 index+= 0x10000; // pose bones count in higher 2 bytes only
1673 /* object tag, for bordersel optim */
1674 glLoadName(index & 0xFFFF);
1679 /* wire draw over solid only in posemode */
1680 if ((dt <= OB_WIRE) || (arm->flag & ARM_POSEMODE) || (arm->drawtype==ARM_LINE)) {
1681 /* draw line check first. we do selection indices */
1682 if (arm->drawtype==ARM_LINE) {
1683 if (arm->flag & ARM_POSEMODE)
1684 index= base->selcol;
1686 /* if solid && posemode, we draw again with polygonoffset */
1687 else if ((dt > OB_WIRE) && (arm->flag & ARM_POSEMODE)) {
1688 bglPolygonOffset(rv3d->dist, 1.0);
1691 /* and we use selection indices if not done yet */
1692 if (arm->flag & ARM_POSEMODE)
1693 index= base->selcol;
1696 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1699 if ((bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
1700 if (bone->layer & arm->layer) {
1701 if ((do_dashed & 1) && (bone->parent)) {
1702 /* Draw a line from our root to the parent's tip
1703 * - only if V3D_HIDE_HELPLINES is enabled...
1705 if ( (do_dashed & 2) && ((bone->flag & BONE_CONNECTED)==0) ) {
1706 if (arm->flag & ARM_POSEMODE) {
1707 glLoadName(index & 0xFFFF); // object tag, for bordersel optim
1708 UI_ThemeColor(TH_WIRE);
1712 glVertex3fv(pchan->pose_head);
1713 glVertex3fv(pchan->parent->pose_tail);
1718 /* Draw a line to IK root bone
1719 * - only if temporary chain (i.e. "autoik")
1721 if (arm->flag & ARM_POSEMODE) {
1722 if (pchan->constflag & PCHAN_HAS_IK) {
1723 if (bone->flag & BONE_SELECTED) {
1724 if (pchan->constflag & PCHAN_HAS_TARGET) glColor3ub(200, 120, 0);
1725 else glColor3ub(200, 200, 50); // add theme!
1727 glLoadName(index & 0xFFFF);
1728 pchan_draw_IK_root_lines(pchan, !(do_dashed & 2));
1735 if (arm->drawtype != ARM_ENVELOPE)
1736 glMultMatrixf(pchan->pose_mat);
1738 /* catch exception for bone with hidden parent */
1740 if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)))
1741 flag &= ~BONE_CONNECTED;
1743 /* extra draw service for pose mode */
1744 constflag= pchan->constflag;
1745 if (pchan->flag & (POSE_ROT|POSE_LOC|POSE_SIZE)) // XXX this is useless crap
1746 constflag |= PCHAN_HAS_ACTION;
1747 if (pchan->flag & POSE_STRIDE)
1748 constflag |= PCHAN_HAS_STRIDE;
1750 /* set color-set to use */
1751 set_pchan_colorset(ob, pchan);
1753 if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM))
1754 ; // custom bone shapes should not be drawn here!
1755 else if (arm->drawtype==ARM_ENVELOPE) {
1757 draw_sphere_bone_wire(smat, imat, arm->flag, flag, constflag, index, pchan, NULL);
1759 else if (arm->drawtype==ARM_LINE)
1760 draw_line_bone(arm->flag, flag, constflag, index, pchan, NULL);
1761 else if (arm->drawtype==ARM_B_BONE)
1762 draw_b_bone(OB_WIRE, arm->flag, flag, constflag, index, pchan, NULL);
1764 draw_bone(OB_WIRE, arm->flag, flag, constflag, index, bone->length);
1770 /* pose bones count in higher 2 bytes only */
1774 /* restore things */
1775 if ((arm->drawtype!=ARM_LINE)&& (dt>OB_WIRE) && (arm->flag & ARM_POSEMODE))
1776 bglPolygonOffset(rv3d->dist, 0.0);
1780 glDisable(GL_CULL_FACE);
1783 if (arm->flag & ARM_POSEMODE)
1786 /* finally names and axes */
1787 if (arm->flag & (ARM_DRAWNAMES|ARM_DRAWAXES)) {
1788 /* patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing */
1789 if ((G.f & G_PICKSEL) == 0) {
1792 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
1794 for (pchan=ob->pose->chanbase.first; pchan; pchan=pchan->next) {
1795 if ((pchan->bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))==0) {
1796 if (pchan->bone->layer & arm->layer) {
1797 if (arm->flag & (ARM_EDITMODE|ARM_POSEMODE)) {
1800 if (bone->flag & BONE_SELECTED) UI_ThemeColor(TH_TEXT_HI);
1801 else UI_ThemeColor(TH_TEXT);
1803 else if (dt > OB_WIRE)
1804 UI_ThemeColor(TH_TEXT);
1806 /* Draw names of bone */
1807 if (arm->flag & ARM_DRAWNAMES) {
1808 VecMidf(vec, pchan->pose_head, pchan->pose_tail);
1809 glRasterPos3fv(vec);
1810 BMF_DrawString(G.font, " ");
1811 BMF_DrawString(G.font, pchan->name);
1814 /* Draw additional axes on the bone tail */
1815 if ( (arm->flag & ARM_DRAWAXES) && (arm->flag & ARM_POSEMODE) ) {
1817 glMultMatrixf(pchan->pose_mat);
1818 glTranslatef(0.0f, pchan->bone->length, 0.0f);
1819 drawaxes(0.25f*pchan->bone->length, 0, OB_ARROWS);
1826 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
1831 /* in editmode, we don't store the bone matrix... */
1832 static void set_matrix_editbone(EditBone *eBone)
1834 float delta[3],offset[3];
1835 float mat[3][3], bmat[4][4];
1837 /* Compose the parent transforms (i.e. their translations) */
1838 VECCOPY(offset, eBone->head);
1840 glTranslatef(offset[0],offset[1],offset[2]);
1842 VecSubf(delta, eBone->tail, eBone->head);
1844 eBone->length = (float)sqrt(delta[0]*delta[0] + delta[1]*delta[1] +delta[2]*delta[2]);
1846 vec_roll_to_mat3(delta, eBone->roll, mat);
1847 Mat4CpyMat3(bmat, mat);
1849 glMultMatrixf(bmat);
1853 static void draw_ebones(View3D *v3d, RegionView3D *rv3d, Object *ob, int dt)
1856 bArmature *arm= ob->data;
1857 float smat[4][4], imat[4][4];
1861 /* envelope (deform distance) */
1862 if(arm->drawtype==ARM_ENVELOPE) {
1863 /* precalc inverse matrix for drawing screen aligned */
1865 Mat4MulFloat3(smat[0], 1.0f/VecLength(ob->obmat[0]));
1866 Mat4Invert(imat, smat);
1868 /* and draw blended distances */
1870 //glShadeModel(GL_SMOOTH);
1872 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
1874 for (eBone=arm->edbo->first, index=0; eBone; eBone=eBone->next, index++) {
1875 if (eBone->layer & arm->layer) {
1876 if ((eBone->flag & (BONE_HIDDEN_A|BONE_NO_DEFORM))==0) {
1877 if (eBone->flag & (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL))
1878 draw_sphere_bone_dist(smat, imat, eBone->flag, NULL, eBone);
1883 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
1884 glDisable(GL_BLEND);
1885 //glShadeModel(GL_FLAT);
1888 /* if solid we draw it first */
1889 if ((dt > OB_WIRE) && (arm->drawtype!=ARM_LINE)) {
1891 for (eBone=arm->edbo->first, index=0; eBone; eBone=eBone->next, index++) {
1892 if (eBone->layer & arm->layer) {
1893 if ((eBone->flag & BONE_HIDDEN_A)==0) {
1895 set_matrix_editbone(eBone);
1897 /* catch exception for bone with hidden parent */
1899 if ( (eBone->parent) && ((eBone->parent->flag & BONE_HIDDEN_A) || (eBone->parent->layer & arm->layer)==0) )
1900 flag &= ~BONE_CONNECTED;
1902 if (arm->drawtype==ARM_ENVELOPE)
1903 draw_sphere_bone(OB_SOLID, arm->flag, flag, 0, index, NULL, eBone);
1904 else if(arm->drawtype==ARM_B_BONE)
1905 draw_b_bone(OB_SOLID, arm->flag, flag, 0, index, NULL, eBone);
1907 draw_bone(OB_SOLID, arm->flag, flag, 0, index, eBone->length);
1916 /* if wire over solid, set offset */
1919 if (arm->drawtype==ARM_LINE) {
1923 else if (dt > OB_WIRE)
1924 bglPolygonOffset(rv3d->dist, 1.0f);
1925 else if (arm->flag & ARM_EDITMODE)
1926 index= 0; /* do selection codes */
1928 for (eBone=arm->edbo->first; eBone; eBone=eBone->next) {
1929 if (eBone->layer & arm->layer) {
1930 if ((eBone->flag & BONE_HIDDEN_A)==0) {
1932 /* catch exception for bone with hidden parent */
1934 if ( (eBone->parent) && ((eBone->parent->flag & BONE_HIDDEN_A) || (eBone->parent->layer & arm->layer)==0) )
1935 flag &= ~BONE_CONNECTED;
1937 if (arm->drawtype == ARM_ENVELOPE) {
1939 draw_sphere_bone_wire(smat, imat, arm->flag, flag, 0, index, NULL, eBone);
1943 set_matrix_editbone(eBone);
1945 if (arm->drawtype == ARM_LINE)
1946 draw_line_bone(arm->flag, flag, 0, index, NULL, eBone);
1947 else if (arm->drawtype == ARM_B_BONE)
1948 draw_b_bone(OB_WIRE, arm->flag, flag, 0, index, NULL, eBone);
1950 draw_bone(OB_WIRE, arm->flag, flag, 0, index, eBone->length);
1955 /* offset to parent */
1956 if (eBone->parent) {
1957 UI_ThemeColor(TH_WIRE);
1958 glLoadName (-1); // -1 here is OK!
1962 glVertex3fv(eBone->parent->tail);
1963 glVertex3fv(eBone->head);
1970 if(index!=-1) index++;
1974 if (arm->drawtype==ARM_LINE);
1975 else if (dt>OB_WIRE) bglPolygonOffset(rv3d->dist, 0.0f);
1977 /* finally names and axes */
1978 if (arm->flag & (ARM_DRAWNAMES|ARM_DRAWAXES)) {
1979 // patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing
1980 if ((G.f & G_PICKSEL) == 0) {
1983 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
1985 for (eBone=arm->edbo->first, index=0; eBone; eBone=eBone->next, index++) {
1986 if(eBone->layer & arm->layer) {
1987 if ((eBone->flag & BONE_HIDDEN_A)==0) {
1989 if (eBone->flag & BONE_SELECTED) UI_ThemeColor(TH_TEXT_HI);
1990 else UI_ThemeColor(TH_TEXT);
1993 if (arm->flag & ARM_DRAWNAMES) {
1994 VecMidf(vec, eBone->head, eBone->tail);
1995 glRasterPos3fv(vec);
1996 BMF_DrawString(G.font, " ");
1997 BMF_DrawString(G.font, eBone->name);
1999 /* Draw additional axes */
2000 if (arm->flag & ARM_DRAWAXES) {
2002 set_matrix_editbone(eBone);
2003 glTranslatef(0.0f, eBone->length, 0.0f);
2004 drawaxes(eBone->length*0.25f, 0, OB_ARROWS);
2012 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
2017 /* ****************************** Armature Visualisation ******************************** */
2019 /* ---------- Paths --------- */
2024 static void draw_pose_paths(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob)
2026 bArmature *arm= ob->data;
2027 bPoseChannel *pchan;
2028 // bAction *act; // XXX old animsys - watch it!
2029 // bActionChannel *achan;
2032 float *fp, *fp_start;
2034 int sfra, efra, len;
2036 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
2039 glLoadMatrixf(rv3d->viewmat);
2041 /* version patch here - cannot access frame info from file reading */
2042 if (arm->pathsize == 0) arm->pathsize= 1;
2043 stepsize = arm->pathsize;
2045 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
2046 if (pchan->bone->layer & arm->layer) {
2048 /* version patch here - cannot access frame info from file reading */
2049 if ((pchan->pathsf == 0) || (pchan->pathef == 0)) {
2050 pchan->pathsf= SFRA;
2051 pchan->pathef= EFRA;
2054 /* get frame ranges */
2055 if (arm->pathflag & ARM_PATH_ACFRA) {
2058 /* With "Around Current", we only choose frames from around
2059 * the current frame to draw. However, this range is still
2060 * restricted by the limits of the original path.
2062 sfra= CFRA - arm->pathbc;
2063 efra= CFRA + arm->pathac;
2064 if (sfra < pchan->pathsf) sfra= pchan->pathsf;
2065 if (efra > pchan->pathef) efra= pchan->pathef;
2069 sind= sfra - pchan->pathsf;
2070 fp_start= (pchan->path + (3*sind));
2073 sfra= pchan->pathsf;
2074 efra = sfra + pchan->pathlen;
2075 len = pchan->pathlen;
2076 fp_start = pchan->path;
2079 /* draw curve-line of path */
2080 glShadeModel(GL_SMOOTH);
2082 glBegin(GL_LINE_STRIP);
2083 for (a=0, fp=fp_start; a<len; a++, fp+=3) {
2084 float intensity; /* how faint */
2087 * - more intense for active/selected bones, less intense for unselected bones
2088 * - black for before current frame, green for current frame, blue for after current frame
2089 * - intensity decreases as distance from current frame increases
2091 #define SET_INTENSITY(A, B, C, min, max) (((1.0f - ((C - B) / (C - A))) * (max-min)) + min)
2092 if ((a+sfra) < CFRA) {
2093 /* black - before cfra */
2094 if (pchan->bone->flag & BONE_SELECTED) {
2096 intensity = SET_INTENSITY(sfra, a, CFRA, 0.25f, 0.75f);
2100 intensity = SET_INTENSITY(sfra, a, CFRA, 0.68f, 0.92f);
2102 UI_ThemeColorBlend(TH_WIRE, TH_BACK, intensity);
2104 else if ((a+sfra) > CFRA) {
2105 /* blue - after cfra */
2106 if (pchan->bone->flag & BONE_SELECTED) {
2108 intensity = SET_INTENSITY(CFRA, a, efra, 0.25f, 0.75f);
2112 intensity = SET_INTENSITY(CFRA, a, efra, 0.68f, 0.92f);
2114 UI_ThemeColorBlend(TH_BONE_POSE, TH_BACK, intensity);
2117 /* green - on cfra */
2118 if (pchan->bone->flag & BONE_SELECTED) {
2124 UI_ThemeColorBlendShade(TH_CFRAME, TH_BACK, intensity, 10);
2127 /* draw a vertex with this color */
2132 glShadeModel(GL_FLAT);
2136 /* draw little black point at each frame
2137 * NOTE: this is not really visible/noticable
2140 for (a=0, fp=fp_start; a<len; a++, fp+=3)
2144 /* Draw little white dots at each framestep value */
2145 UI_ThemeColor(TH_TEXT_HI);
2147 for (a=0, fp=fp_start; a<len; a+=stepsize, fp+=(stepsize*3))
2151 /* Draw frame numbers at each framestep value */
2152 if (arm->pathflag & ARM_PATH_FNUMS) {
2153 for (a=0, fp=fp_start; a<len; a+=stepsize, fp+=(stepsize*3)) {
2156 /* only draw framenum if several consecutive highlighted points don't occur on same point */
2159 sprintf(str, " %d\n", (a+sfra));
2160 BMF_DrawString(G.font, str);
2162 else if ((a > stepsize) && (a < len-stepsize)) {
2163 if ((VecEqual(fp, fp-(stepsize*3))==0) || (VecEqual(fp, fp+(stepsize*3))==0)) {
2165 sprintf(str, " %d\n", (a+sfra));
2166 BMF_DrawString(G.font, str);
2172 /* Keyframes - dots and numbers */
2173 if (arm->pathflag & ARM_PATH_KFRAS) {
2174 /* build list of all keyframes in active action for pchan */
2175 keys.first = keys.last = NULL;
2177 #if 0 // XXX old animation system
2180 achan= get_action_channel(act, pchan->name);
2182 ipo_to_keylist(achan->ipo, &keys, NULL, NULL);
2184 #endif // XXX old animation system
2186 /* Draw slightly-larger yellow dots at each keyframe */
2187 UI_ThemeColor(TH_VERTEX_SELECT);
2191 for (a=0, fp=fp_start; a<len; a++, fp+=3) {
2192 for (ak= keys.first; ak; ak= ak->next) {
2193 if (ak->cfra == (a+sfra))
2201 /* Draw frame numbers of keyframes */
2202 if ((arm->pathflag & ARM_PATH_FNUMS) || (arm->pathflag & ARM_PATH_KFNOS)) {
2203 for(a=0, fp=fp_start; a<len; a++, fp+=3) {
2204 for (ak= keys.first; ak; ak= ak->next) {
2205 if (ak->cfra == (a+sfra)) {
2209 sprintf(str, " %d\n", (a+sfra));
2210 BMF_DrawString(G.font, str);
2216 BLI_freelistN(&keys);
2222 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
2227 /* ---------- Ghosts --------- */
2229 /* helper function for ghost drawing - sets/removes flags for temporarily
2230 * hiding unselected bones while drawing ghosts
2232 static void ghost_poses_tag_unselected(Object *ob, short unset)
2234 bArmature *arm= ob->data;
2235 bPose *pose= ob->pose;
2236 bPoseChannel *pchan;
2238 /* don't do anything if no hiding any bones */
2239 if ((arm->flag & ARM_GHOST_ONLYSEL)==0)
2242 /* loop over all pchans, adding/removing tags as appropriate */
2243 for (pchan= pose->chanbase.first; pchan; pchan= pchan->next) {
2244 if ((pchan->bone) && (arm->layer & pchan->bone->layer)) {
2246 /* remove tags from all pchans if cleaning up */
2247 pchan->bone->flag &= ~BONE_HIDDEN_PG;
2250 /* set tags on unselected pchans only */
2251 if ((pchan->bone->flag & BONE_SELECTED)==0)
2252 pchan->bone->flag |= BONE_HIDDEN_PG;
2258 /* draw ghosts that occur within a frame range
2259 * note: object should be in posemode
2261 static void draw_ghost_poses_range(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base)
2263 Object *ob= base->object;
2264 bArmature *arm= ob->data;
2265 bPose *posen, *poseo;
2266 float start, end, stepsize, range, colfac;
2267 int cfrao, flago, ipoflago;
2269 start = (float)arm->ghostsf;
2270 end = (float)arm->ghostef;
2274 stepsize= (float)(arm->ghostsize);
2275 range= (float)(end - start);
2278 ob->flag &= ~OB_POSEMODE;
2281 arm->flag &= ~(ARM_DRAWNAMES|ARM_DRAWAXES);
2282 ipoflago= ob->ipoflag;
2283 ob->ipoflag |= OB_DISABLE_PATH;
2287 copy_pose(&posen, ob->pose, 1);
2289 armature_rebuild_pose(ob, ob->data); /* child pointers for IK */
2290 ghost_poses_tag_unselected(ob, 0); /* hide unselected bones if need be */
2293 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
2295 /* draw from first frame of range to last */
2296 for (CFRA= (int)start; CFRA < end; CFRA += (int)stepsize) {
2297 colfac = (end - (float)CFRA) / range;
2298 UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0*sqrt(colfac)));
2300 //do_all_pose_actions(scene, ob); // XXX old animation system
2301 where_is_pose(scene, ob);
2302 draw_pose_channels(scene, v3d, rv3d, base, OB_WIRE);
2304 glDisable(GL_BLEND);
2305 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
2307 ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */
2314 armature_rebuild_pose(ob, ob->data);
2315 ob->flag |= OB_POSEMODE;
2316 ob->ipoflag= ipoflago;
2319 /* draw ghosts on keyframes in action within range
2320 * - object should be in posemode
2322 static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base)
2324 Object *ob= base->object;
2325 bAction *act= ob->action; // XXX old animsys stuff... watch it!
2326 bArmature *arm= ob->data;
2327 bPose *posen, *poseo;
2328 ListBase keys= {NULL, NULL};
2329 ActKeysInc aki = {0, 0, 0};
2330 ActKeyColumn *ak, *akn;
2331 float start, end, range, colfac, i;
2334 aki.start= start = (float)arm->ghostsf;
2335 aki.end= end = (float)arm->ghostef;
2339 /* get keyframes - then clip to only within range */
2340 action_to_keylist(act, &keys, NULL, &aki);
2342 for (ak= keys.first; ak; ak= akn) {
2345 if ((ak->cfra < start) || (ak->cfra > end))
2346 BLI_freelinkN(&keys, ak);
2350 if (range == 0) return;
2353 ob->flag &= ~OB_POSEMODE;
2356 arm->flag &= ~(ARM_DRAWNAMES|ARM_DRAWAXES);
2357 ob->ipoflag |= OB_DISABLE_PATH;
2361 copy_pose(&posen, ob->pose, 1);
2363 armature_rebuild_pose(ob, ob->data); /* child pointers for IK */
2364 ghost_poses_tag_unselected(ob, 0); /* hide unselected bones if need be */
2367 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
2369 /* draw from first frame of range to last */
2370 for (ak=keys.first, i=0; ak; ak=ak->next, i++) {
2372 UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0*sqrt(colfac)));
2374 CFRA= (int)ak->cfra;
2376 //do_all_pose_actions(scene, ob); // XXX old animation system
2377 where_is_pose(scene, ob);
2378 draw_pose_channels(scene, v3d, rv3d, base, OB_WIRE);
2380 glDisable(GL_BLEND);
2381 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
2383 ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */
2384 BLI_freelistN(&keys);
2391 armature_rebuild_pose(ob, ob->data);
2392 ob->flag |= OB_POSEMODE;
2395 /* draw ghosts around current frame
2396 * - object is supposed to be armature in posemode
2398 static void draw_ghost_poses(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base)
2400 Object *ob= base->object;
2401 bArmature *arm= ob->data;
2402 bPose *posen, *poseo;
2403 //bActionStrip *strip;
2404 float cur, start, end, stepsize, range, colfac, actframe, ctime;
2405 int cfrao, maptime, flago;
2407 /* pre conditions, get an action with sufficient frames */
2408 //if (ob->action==NULL)
2411 calc_action_range(ob->action, &start, &end, 0);
2415 stepsize= (float)(arm->ghostsize);
2416 range= (float)(arm->ghostep)*stepsize + 0.5f; /* plus half to make the for loop end correct */
2418 #if 0 // XXX old animation system
2419 /* we only map time for armature when an active strip exists */
2420 for (strip=ob->nlastrips.first; strip; strip=strip->next)
2421 if (strip->flag & ACTSTRIP_ACTIVE)
2423 #endif // XXX old animsys
2425 //maptime= (strip!=NULL);
2429 ob->flag &= ~OB_POSEMODE;
2431 if (maptime) actframe= get_action_frame(ob, (float)CFRA);
2432 else actframe= (float)CFRA;
2434 arm->flag &= ~(ARM_DRAWNAMES|ARM_DRAWAXES);
2438 copy_pose(&posen, ob->pose, 1);
2440 armature_rebuild_pose(ob, ob->data); /* child pointers for IK */
2441 ghost_poses_tag_unselected(ob, 0); /* hide unselected bones if need be */
2444 if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
2446 /* draw from darkest blend to lowest */
2447 for(cur= stepsize; cur<range; cur+=stepsize) {
2448 ctime= cur - (float)fmod(cfrao, stepsize); /* ensures consistant stepping */
2449 colfac= ctime/range;
2450 UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0*sqrt(colfac)));
2452 /* only within action range */
2453 if (actframe+ctime >= start && actframe+ctime <= end) {
2454 if (maptime) CFRA= (int)get_action_frame_inv(ob, actframe+ctime);
2455 else CFRA= (int)floor(actframe+ctime);
2457 if (CFRA != cfrao) {
2458 //do_all_pose_actions(scene, ob); // xxx old animation system crap
2459 where_is_pose(scene, ob);
2460 draw_pose_channels(scene, v3d, rv3d, base, OB_WIRE);
2464 ctime= cur + (float)fmod((float)cfrao, stepsize) - stepsize+1.0f; /* ensures consistant stepping */
2465 colfac= ctime/range;
2466 UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0*sqrt(colfac)));
2468 /* only within action range */
2469 if ((actframe-ctime >= start) && (actframe-ctime <= end)) {
2470 if (maptime) CFRA= (int)get_action_frame_inv(ob, actframe-ctime);
2471 else CFRA= (int)floor(actframe-ctime);
2473 if (CFRA != cfrao) {
2474 //do_all_pose_actions(scene, ob); // XXX old animation system crap...
2475 where_is_pose(scene, ob);
2476 draw_pose_channels(scene, v3d, rv3d, base, OB_WIRE);
2480 glDisable(GL_BLEND);
2481 if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
2483 ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */
2490 armature_rebuild_pose(ob, ob->data);
2491 ob->flag |= OB_POSEMODE;
2494 /* ********************************** Armature Drawing - Main ************************* */
2496 /* called from drawobject.c, return 1 if nothing was drawn */
2497 int draw_armature(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt, int flag)
2499 Object *ob= base->object;
2500 bArmature *arm= ob->data;
2503 if(G.f & G_RENDER_SHADOW)
2506 if(dt>OB_WIRE && arm->drawtype!=ARM_LINE) {
2507 /* we use color for solid lighting */
2508 glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
2509 glEnable(GL_COLOR_MATERIAL);
2510 glColor3ub(0,0,0); // clear spec
2511 glDisable(GL_COLOR_MATERIAL);
2513 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
2514 glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW); // only for lighting...
2517 /* arm->flag is being used to detect mode... */
2520 arm->flag |= ARM_EDITMODE;
2521 draw_ebones(v3d, rv3d, ob, dt);
2522 arm->flag &= ~ARM_EDITMODE;
2526 if(ob->pose && ob->pose->chanbase.first) {
2527 /* drawing posemode selection indices or colors only in these cases */
2528 if(!(base->flag & OB_FROMDUPLI)) {
2529 if(G.f & G_PICKSEL) {
2530 if(ob->flag & OB_POSEMODE)
2531 arm->flag |= ARM_POSEMODE;
2533 else if(ob->flag & OB_POSEMODE) {
2534 if (arm->ghosttype == ARM_GHOST_RANGE) {
2535 draw_ghost_poses_range(scene, v3d, rv3d, base);
2537 else if (arm->ghosttype == ARM_GHOST_KEYS) {
2538 draw_ghost_poses_keys(scene, v3d, rv3d, base);
2540 else if (arm->ghosttype == ARM_GHOST_CUR) {
2542 draw_ghost_poses(scene, v3d, rv3d, base);
2544 if ((flag & DRAW_SCENESET)==0) {
2546 arm->flag |= ARM_POSEMODE;
2547 else if(G.f & G_WEIGHTPAINT) {
2548 if(OBACT && ob==modifiers_isDeformedByArmature(OBACT))
2549 arm->flag |= ARM_POSEMODE;
2551 draw_pose_paths(scene, v3d, rv3d, ob);
2555 draw_pose_channels(scene, v3d, rv3d, base, dt);
2556 arm->flag &= ~ARM_POSEMODE;
2558 if(ob->flag & OB_POSEMODE)
2559 UI_ThemeColor(TH_WIRE); /* restore, for extra draw stuff */
2564 glFrontFace(GL_CCW);
2569 /* *************** END Armature drawing ******************* */