Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2008-01-23 13:14:45 +0300
committerJoshua Leung <aligorith@gmail.com>2008-01-23 13:14:45 +0300
commit9cd27e908b4f4a607b2325be45491d465742e4bb (patch)
tree57fb5722a38e3a298e1c51c4c8ed954d4d7fad73 /source/blender/src/drawarmature.c
parent93f3585f8bd703e874752ef367717740248ff2c1 (diff)
== "Custom Bone Colors" ==
This commit introduces the ability to give groups of bones different colour-sets, which enables them to be more easily identified in the 3d-view. Currently, custom bone colours have been implemented as a way to visualise bone-group membership (after all, colours and groups are both just ways of managing bones). Usage Notes: * Each theme currently has 20 Color-Sets available for Bones. These can be accessed from the "Bone Color Sets" option under the Theme buttons. (Note: currently, I haven't defined any default colour-sets. Donations welcome on this ;-) ) As such, colour sets are not saved per file! You will need to save the theme to preserve the color set for the next session. * Each Bone-Group can use any one of these 20 sets, or just use the default colour-set. Use the "GroupCol" button to set this. When a set has been chosen, three little rectangles are drawn beside the button to preview the colours the set provides. * A bone must belong to a Bone-Group to get that group's colours. * "Colors" toggle on "Armature" panel must be enabled for these custom-colours to be shown for all bones that can have them. This toggle is off by default, but is there to allow rigs to be debugged (by colours) for example. * The "Use 'Constraint' Colouring" option (per Colour Set), determines whether the colours denoting presences of constraints, ik, or keyframes are drawn in conjunction with the custom colours. It is off by default, as in many combinations, they look quite ugly when used in conjunction with custom colours. * Custom colours are only shown in PoseMode Assorted Notes: * I've tested this thoroughly, and there shouldn't be any problems caused by this. * In the process, I found a bug with envelope bone drawmode. In wire-frame mode, all bones got scaled up by several types. * I've cleaned up the armature drawing code a bit (mostly fixing messy white-space usage), but also creating a centralised method of setting colours for bones (currently only used for bones in PoseMode).
Diffstat (limited to 'source/blender/src/drawarmature.c')
-rw-r--r--source/blender/src/drawarmature.c919
1 files changed, 570 insertions, 349 deletions
diff --git a/source/blender/src/drawarmature.c b/source/blender/src/drawarmature.c
index 3e08910abfe..abe22a1804d 100644
--- a/source/blender/src/drawarmature.c
+++ b/source/blender/src/drawarmature.c
@@ -49,6 +49,7 @@
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_view3d_types.h"
+#include "DNA_userdef_types.h"
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
@@ -86,6 +87,222 @@
#include "blendef.h"
#include "nla.h"
+
+/* *************** Armature Drawing - Coloring API ***************************** */
+
+/* global here is reset before drawing each bone */
+static ThemeWireColor *bcolor= NULL;
+
+/* values of colCode for set_pchan_glcolor */
+enum {
+ PCHAN_COLOR_NORMAL = 0, /* normal drawing */
+ PCHAN_COLOR_SOLID, /* specific case where "solid" colour is needed */
+ PCHAN_COLOR_CONSTS, /* "constraint" colors (which may/may-not be suppressed) */
+
+ PCHAN_COLOR_SPHEREBONE_BASE, /* for the 'stick' of sphere (envelope) bones */
+ PCHAN_COLOR_SPHEREBONE_END, /* for the ends of sphere (envelope) bones */
+ PCHAN_COLOR_LINEBONE /* for the middle of line-bones */
+};
+
+/* This function sets the color-set for coloring a certain bone */
+static void set_pchan_colorset (Object *ob, bPoseChannel *pchan)
+{
+ bPose *pose= (ob) ? ob->pose : NULL;
+ bArmature *arm= (ob) ? ob->data : NULL;
+ short color_index= 0;
+
+ /* sanity check */
+ if (ELEM4(NULL, ob, arm, pose, pchan)) {
+ bcolor= NULL;
+ return;
+ }
+
+ /* only try to set custom color if enabled for armature */
+ if (arm->flag & ARM_COL_CUSTOM) {
+ /* currently, a bone can only use a custom color set if it's group (if it has one),
+ * has been set to use one
+ */
+ if (pchan->agrp_index) {
+ bActionGroup *grp= (bActionGroup *)BLI_findlink(&pose->agroups, (pchan->agrp_index - 1));
+ if (grp)
+ color_index= grp->customCol;
+ }
+ }
+
+ /* bcolor is a pointer to the color set to use. If NULL, then the default
+ * color set (based on the theme colors for 3d-view) is used.
+ */
+ if (color_index) {
+ bTheme *btheme= U.themes.first;
+ bcolor= &btheme->tarm[(color_index - 1)];
+ }
+ else
+ bcolor= NULL;
+}
+
+/* This function is for brightening/darkening a given color (like BIF_ThemeColorShade()) */
+static void cp_shade_color3ub (char cp[], int offset)
+{
+ int r, g, b;
+
+ r= offset + (int) cp[0];
+ CLAMP(r, 0, 255);
+ g= offset + (int) cp[1];
+ CLAMP(g, 0, 255);
+ b= offset + (int) cp[2];
+ CLAMP(b, 0, 255);
+
+ cp[0]= r;
+ cp[1]= g;
+ cp[2]= b;
+}
+
+/* This function sets the gl-color for coloring a certain bone (based on bcolor) */
+static short set_pchan_glColor (short colCode, int armflag, int boneflag, int constflag)
+{
+ switch (colCode) {
+ case PCHAN_COLOR_NORMAL:
+ {
+ if (bcolor) {
+ char cp[3];
+
+ if (boneflag & BONE_ACTIVE) {
+ VECCOPY(cp, bcolor->active);
+ }
+ else if (boneflag & BONE_SELECTED) {
+ VECCOPY(cp, bcolor->select);
+ }
+ else {
+ /* a bit darker than solid */
+ VECCOPY(cp, bcolor->solid);
+ cp_shade_color3ub(cp, -50);
+ }
+
+ glColor3ub(cp[0], cp[1], cp[2]);
+ }
+ else {
+ if (boneflag & BONE_ACTIVE) BIF_ThemeColorShade(TH_BONE_POSE, 40);
+ else if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_BONE_POSE);
+ else BIF_ThemeColor(TH_WIRE);
+ }
+
+ return 1;
+ }
+ break;
+
+ case PCHAN_COLOR_SOLID:
+ {
+ if (bcolor) {
+ char *cp= bcolor->solid;
+ glColor3ub(cp[0], cp[1], cp[2]);
+ }
+ else
+ BIF_ThemeColor(TH_BONE_SOLID);
+
+ return 1;
+ }
+ break;
+
+ case PCHAN_COLOR_CONSTS:
+ {
+ if ( (bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS) ) {
+ if (constflag & PCHAN_HAS_STRIDE) glColor4ub(0, 0, 200, 80);
+ else if (constflag & PCHAN_HAS_TARGET) glColor4ub(255, 150, 0, 80);
+ else if (constflag & PCHAN_HAS_IK) glColor4ub(255, 255, 0, 80);
+ else if (constflag & PCHAN_HAS_CONST) glColor4ub(0, 255, 120, 80);
+ else if (constflag) BIF_ThemeColor4(TH_BONE_POSE); // PCHAN_HAS_ACTION
+
+ return 1;
+ }
+ else
+ return 0;
+ }
+ break;
+
+ case PCHAN_COLOR_SPHEREBONE_BASE:
+ {
+ if (bcolor) {
+ char cp[3];
+
+ if (boneflag & BONE_ACTIVE) {
+ VECCOPY(cp, bcolor->active);
+ }
+ else if (boneflag & BONE_SELECTED) {
+ VECCOPY(cp, bcolor->select);
+ }
+ else {
+ VECCOPY(cp, bcolor->solid);
+ }
+
+ glColor3ub(cp[0], cp[1], cp[2]);
+ }
+ else {
+ if (boneflag & BONE_ACTIVE) BIF_ThemeColorShade(TH_BONE_POSE, 40);
+ else if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_BONE_POSE);
+ else BIF_ThemeColor(TH_BONE_SOLID);
+ }
+
+ return 1;
+ }
+ break;
+ case PCHAN_COLOR_SPHEREBONE_END:
+ {
+ if (bcolor) {
+ char cp[3];
+
+ if (boneflag & BONE_ACTIVE) {
+ VECCOPY(cp, bcolor->active);
+ cp_shade_color3ub(cp, 10);
+ }
+ else if (boneflag & BONE_SELECTED) {
+ VECCOPY(cp, bcolor->select);
+ cp_shade_color3ub(cp, -30);
+ }
+ else {
+ VECCOPY(cp, bcolor->solid);
+ cp_shade_color3ub(cp, -30);
+ }
+
+ glColor3ub(cp[0], cp[1], cp[2]);
+ }
+ else {
+ if (boneflag & BONE_ACTIVE) BIF_ThemeColorShade(TH_BONE_POSE, 10);
+ else if (boneflag & BONE_SELECTED) BIF_ThemeColorShade(TH_BONE_POSE, -30);
+ else BIF_ThemeColorShade(TH_BONE_SOLID, -30);
+ }
+ }
+ break;
+
+ case PCHAN_COLOR_LINEBONE:
+ {
+ /* inner part in background color or constraint */
+ if ((bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS)) {
+ if (constflag & PCHAN_HAS_STRIDE) glColor3ub(0, 0, 200);
+ else if (constflag & PCHAN_HAS_TARGET) glColor3ub(255, 150, 0);
+ else if (constflag & PCHAN_HAS_IK) glColor3ub(255, 255, 0);
+ else if (constflag & PCHAN_HAS_CONST) glColor3ub(0, 255, 120);
+ else if (constflag) BIF_ThemeColor(TH_BONE_POSE); /* PCHAN_HAS_ACTION */
+ }
+ else {
+ if (bcolor) {
+ char *cp= bcolor->solid;
+ glColor4ub(cp[0], cp[1], cp[2], 0.8);
+ }
+ else
+ BIF_ThemeColorShade(TH_BACK, -30);
+ }
+
+ return 1;
+ }
+ break;
+ }
+
+ return 0;
+}
+
+
+/* *************** Armature drawing, helper calls for parts ******************* */
+
/* half the cube, in Y */
static float cube[8][3] = {
{-1.0, 0.0, -1.0},
@@ -98,9 +315,6 @@ static float cube[8][3] = {
{ 1.0, 1.0, -1.0},
};
-
-/* *************** Armature drawing, helper calls for parts ******************* */
-
static void drawsolidcube_size(float xsize, float ysize, float zsize)
{
static GLuint displist=0;
@@ -152,10 +366,10 @@ static void drawcube_size(float xsize, float ysize, float zsize)
glScalef(xsize, ysize, zsize);
- if(displist==0) {
+ if(displist == 0) {
displist= glGenLists(1);
glNewList(displist, GL_COMPILE_AND_EXECUTE);
-
+
glBegin(GL_LINE_STRIP);
glVertex3fv(cube[0]); glVertex3fv(cube[1]);glVertex3fv(cube[2]); glVertex3fv(cube[3]);
glVertex3fv(cube[0]); glVertex3fv(cube[4]);glVertex3fv(cube[5]); glVertex3fv(cube[6]);
@@ -167,7 +381,7 @@ static void drawcube_size(float xsize, float ysize, float zsize)
glVertex3fv(cube[2]); glVertex3fv(cube[6]);
glVertex3fv(cube[3]); glVertex3fv(cube[7]);
glEnd();
-
+
glEndList();
}
else glCallList(displist);
@@ -179,37 +393,38 @@ static void draw_bonevert(void)
{
static GLuint displist=0;
- if(displist==0) {
+ if (displist == 0) {
GLUquadricObj *qobj;
displist= glGenLists(1);
glNewList(displist, GL_COMPILE_AND_EXECUTE);
-
+
glPushMatrix();
qobj = gluNewQuadric();
gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
- gluDisk( qobj, 0.0, 0.05, 16, 1);
+ gluDisk(qobj, 0.0, 0.05, 16, 1);
- glRotatef (90, 0, 1, 0);
- gluDisk( qobj, 0.0, 0.05, 16, 1);
+ glRotatef(90, 0, 1, 0);
+ gluDisk(qobj, 0.0, 0.05, 16, 1);
- glRotatef (90, 1, 0, 0);
- gluDisk( qobj, 0.0, 0.05, 16, 1);
+ glRotatef(90, 1, 0, 0);
+ gluDisk(qobj, 0.0, 0.05, 16, 1);
gluDeleteQuadric(qobj);
glPopMatrix();
glEndList();
}
- else glCallList(displist);
+ else
+ glCallList(displist);
}
static void draw_bonevert_solid(void)
{
static GLuint displist=0;
- if(displist==0) {
+ if (displist == 0) {
GLUquadricObj *qobj;
displist= glGenLists(1);
@@ -224,19 +439,20 @@ static void draw_bonevert_solid(void)
glEndList();
}
- else glCallList(displist);
+ else
+ glCallList(displist);
}
static void draw_bone_octahedral()
{
static GLuint displist=0;
- if(displist==0) {
+ if (displist == 0) {
float vec[6][3];
displist= glGenLists(1);
glNewList(displist, GL_COMPILE_AND_EXECUTE);
-
+
vec[0][0]= vec[0][1]= vec[0][2]= 0.0;
vec[5][0]= vec[5][2]= 0.0; vec[5][1]= 1.0;
@@ -267,14 +483,15 @@ static void draw_bone_octahedral()
glEndList();
}
- else glCallList(displist);
+ else
+ glCallList(displist);
}
static void draw_bone_solid_octahedral(void)
{
static GLuint displist=0;
- if(displist==0) {
+ if (displist == 0) {
float vec[6][3], nor[3];
displist= glGenLists(1);
@@ -328,7 +545,8 @@ static void draw_bone_solid_octahedral(void)
glEndList();
}
- else glCallList(displist);
+ else
+ glCallList(displist);
}
/* *************** Armature drawing, bones ******************* */
@@ -337,40 +555,51 @@ static void draw_bone_solid_octahedral(void)
static void draw_bone_points(int dt, int armflag, unsigned int boneflag, int id)
{
/* Draw root point if we are not connected */
- if (!(boneflag & BONE_CONNECTED)){
+ if ((boneflag & BONE_CONNECTED)==0) {
if (id != -1)
- glLoadName (id | BONESEL_ROOT);
+ glLoadName(id | BONESEL_ROOT);
- if(dt<=OB_WIRE) {
- if(armflag & ARM_EDITMODE) {
+ if(dt <= OB_WIRE) {
+ if (armflag & ARM_EDITMODE) {
if (boneflag & BONE_ROOTSEL) BIF_ThemeColor(TH_VERTEX_SELECT);
else BIF_ThemeColor(TH_VERTEX);
}
}
- else
- BIF_ThemeColor(TH_BONE_SOLID);
+ else {
+ if (armflag & ARM_POSEMODE)
+ set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, 0);
+ else
+ BIF_ThemeColor(TH_BONE_SOLID);
+ }
- if(dt>OB_WIRE) draw_bonevert_solid();
- else draw_bonevert();
+ if (dt > OB_WIRE)
+ draw_bonevert_solid();
+ else
+ draw_bonevert();
}
/* Draw tip point */
if (id != -1)
- glLoadName (id | BONESEL_TIP);
+ glLoadName(id | BONESEL_TIP);
- if(dt<=OB_WIRE) {
- if(armflag & ARM_EDITMODE) {
+ if (dt <= OB_WIRE) {
+ if (armflag & ARM_EDITMODE) {
if (boneflag & BONE_TIPSEL) BIF_ThemeColor(TH_VERTEX_SELECT);
else BIF_ThemeColor(TH_VERTEX);
}
}
else {
- BIF_ThemeColor(TH_BONE_SOLID);
+ if (armflag & ARM_POSEMODE)
+ set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, 0);
+ else
+ BIF_ThemeColor(TH_BONE_SOLID);
}
glTranslatef(0.0, 1.0, 0.0);
- if(dt>OB_WIRE) draw_bonevert_solid();
- else draw_bonevert();
+ if (dt > OB_WIRE)
+ draw_bonevert_solid();
+ else
+ draw_bonevert();
glTranslatef(0.0, -1.0, 0.0);
}
@@ -409,7 +638,7 @@ static void draw_sphere_bone_dist(float smat[][4], float imat[][4], int boneflag
float *headvec, *tailvec, dirvec[3];
/* figure out the sizes of spheres */
- if(ebone) {
+ if (ebone) {
/* this routine doesn't call set_matrix_editbone() that calculates it */
ebone->length = VecLenf(ebone->head, ebone->tail);
@@ -445,7 +674,7 @@ static void draw_sphere_bone_dist(float smat[][4], float imat[][4], int boneflag
/* move vector back */
Mat4Mul3Vecfl(imat, dirvec);
- if(0.0f != Normalize(dirvec)) {
+ if (0.0f != Normalize(dirvec)) {
float norvec[3], vec1[3], vec2[3], vec[3];
int a;
@@ -453,8 +682,8 @@ static void draw_sphere_bone_dist(float smat[][4], float imat[][4], int boneflag
Crossf(norvec, dirvec, imat[2]);
glBegin(GL_QUAD_STRIP);
-
- for(a=0; a<16; a++) {
+
+ for (a=0; a<16; a++) {
vec[0]= - *(si+a) * dirvec[0] + *(co+a) * norvec[0];
vec[1]= - *(si+a) * dirvec[1] + *(co+a) * norvec[1];
vec[2]= - *(si+a) * dirvec[2] + *(co+a) * norvec[2];
@@ -472,7 +701,7 @@ static void draw_sphere_bone_dist(float smat[][4], float imat[][4], int boneflag
glVertex3fv(vec2);
}
- for(a=15; a>=0; a--) {
+ for (a=15; a>=0; a--) {
vec[0]= *(si+a) * dirvec[0] + *(co+a) * norvec[0];
vec[1]= *(si+a) * dirvec[1] + *(co+a) * norvec[1];
vec[2]= *(si+a) * dirvec[2] + *(co+a) * norvec[2];
@@ -519,10 +748,10 @@ static void draw_sphere_bone_wire(float smat[][4], float imat[][4], int armflag,
float *headvec, *tailvec, dirvec[3];
/* figure out the sizes of spheres */
- if(ebone) {
+ if (ebone) {
/* this routine doesn't call set_matrix_editbone() that calculates it */
ebone->length = VecLenf(ebone->head, ebone->tail);
-
+
length= ebone->length;
tail= ebone->rad_tail;
if (ebone->parent && (boneflag & BONE_CONNECTED))
@@ -535,7 +764,7 @@ static void draw_sphere_bone_wire(float smat[][4], float imat[][4], int armflag,
else {
length= pchan->bone->length;
tail= pchan->bone->rad_tail;
- if (pchan->parent && (boneflag & BONE_CONNECTED))
+ if ((pchan->parent) && (boneflag & BONE_CONNECTED))
head= pchan->parent->bone->rad_tail;
else
head= pchan->bone->rad_head;
@@ -544,38 +773,34 @@ static void draw_sphere_bone_wire(float smat[][4], float imat[][4], int armflag,
}
/* sphere root color */
- if(armflag & ARM_EDITMODE) {
+ if (armflag & ARM_EDITMODE) {
if (boneflag & BONE_ROOTSEL) BIF_ThemeColor(TH_VERTEX_SELECT);
else BIF_ThemeColor(TH_VERTEX);
}
- else if(armflag & ARM_POSEMODE) {
- /* in black or selection color */
- if (boneflag & BONE_ACTIVE) BIF_ThemeColorShade(TH_BONE_POSE, 40);
- else if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_BONE_POSE);
- else BIF_ThemeColor(TH_WIRE);
- }
+ else if (armflag & ARM_POSEMODE)
+ set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
/* Draw root point if we are not connected */
- if (!(boneflag & BONE_CONNECTED)){
+ if ((boneflag & BONE_CONNECTED)==0) {
if (id != -1)
- glLoadName (id | BONESEL_ROOT);
+ glLoadName(id | BONESEL_ROOT);
drawcircball(GL_LINE_LOOP, headvec, head, imat);
}
/* Draw tip point */
- if(armflag & ARM_EDITMODE) {
+ if (armflag & ARM_EDITMODE) {
if (boneflag & BONE_TIPSEL) BIF_ThemeColor(TH_VERTEX_SELECT);
else BIF_ThemeColor(TH_VERTEX);
}
if (id != -1)
- glLoadName (id | BONESEL_TIP);
+ glLoadName(id | BONESEL_TIP);
drawcircball(GL_LINE_LOOP, tailvec, tail, imat);
/* base */
- if(armflag & ARM_EDITMODE) {
+ if (armflag & ARM_EDITMODE) {
if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_SELECT);
else BIF_ThemeColor(TH_WIRE);
}
@@ -589,7 +814,7 @@ static void draw_sphere_bone_wire(float smat[][4], float imat[][4], int armflag,
/* move vector back */
Mat4Mul3Vecfl(imat, dirvec);
- if(0.0f != Normalize(dirvec)) {
+ if (0.0f != Normalize(dirvec)) {
float norvech[3], norvect[3], vec[3];
VECCOPY(vec, dirvec);
@@ -601,8 +826,8 @@ static void draw_sphere_bone_wire(float smat[][4], float imat[][4], int armflag,
Crossf(norvect, vec, imat[2]);
if (id != -1)
- glLoadName (id | BONESEL_BONE);
-
+ glLoadName(id | BONESEL_BONE);
+
glBegin(GL_LINES);
vec[0]= headvec[0] + norvech[0];
vec[1]= headvec[1] + norvech[1];
@@ -636,7 +861,7 @@ static void draw_sphere_bone(int dt, int armflag, int boneflag, int constflag, u
qobj = gluNewQuadric();
/* figure out the sizes of spheres */
- if(ebone) {
+ if (ebone) {
length= ebone->length;
tail= ebone->rad_tail;
if (ebone->parent && (boneflag & BONE_CONNECTED))
@@ -654,9 +879,9 @@ static void draw_sphere_bone(int dt, int armflag, int boneflag, int constflag, u
}
/* move to z-axis space */
- glRotatef (-90.0f, 1.0f, 0.0f, 0.0f);
+ glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
- if(dt==OB_SOLID) {
+ if (dt==OB_SOLID) {
/* set up solid drawing */
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
@@ -669,57 +894,49 @@ static void draw_sphere_bone(int dt, int armflag, int boneflag, int constflag, u
}
/* sphere root color */
- if(armflag & ARM_EDITMODE) {
+ if (armflag & ARM_EDITMODE) {
if (boneflag & BONE_ROOTSEL) BIF_ThemeColor(TH_VERTEX_SELECT);
else BIF_ThemeColorShade(TH_BONE_SOLID, -30);
}
- else if(armflag & ARM_POSEMODE) {
- if (boneflag & BONE_ACTIVE) BIF_ThemeColorShade(TH_BONE_POSE, 10);
- else if (boneflag & BONE_SELECTED) BIF_ThemeColorShade(TH_BONE_POSE, -30);
- else BIF_ThemeColorShade(TH_BONE_SOLID, -30);
-
- }
- else if(dt==OB_SOLID)
+ else if (armflag & ARM_POSEMODE)
+ set_pchan_glColor(PCHAN_COLOR_SPHEREBONE_END, armflag, boneflag, constflag);
+ else if (dt==OB_SOLID)
BIF_ThemeColorShade(TH_BONE_SOLID, -30);
/* Draw root point if we are not connected */
- if (!(boneflag & BONE_CONNECTED)){
+ if ((boneflag & BONE_CONNECTED)==0) {
if (id != -1)
- glLoadName (id | BONESEL_ROOT);
- gluSphere( qobj, head, 16, 10);
+ glLoadName(id | BONESEL_ROOT);
+ gluSphere(qobj, head, 16, 10);
}
/* Draw tip point */
- if(armflag & ARM_EDITMODE) {
+ if (armflag & ARM_EDITMODE) {
if (boneflag & BONE_TIPSEL) BIF_ThemeColor(TH_VERTEX_SELECT);
else BIF_ThemeColorShade(TH_BONE_SOLID, -30);
}
if (id != -1)
- glLoadName (id | BONESEL_TIP);
+ glLoadName(id | BONESEL_TIP);
glTranslatef(0.0, 0.0, length);
- gluSphere( qobj, tail, 16, 10);
+ gluSphere(qobj, tail, 16, 10);
glTranslatef(0.0, 0.0, -length);
/* base */
- if(armflag & ARM_EDITMODE) {
+ if (armflag & ARM_EDITMODE) {
if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_SELECT);
else BIF_ThemeColor(TH_BONE_SOLID);
}
- else if(armflag & ARM_POSEMODE) {
- if (boneflag & BONE_ACTIVE) BIF_ThemeColorShade(TH_BONE_POSE, 40);
- else if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_BONE_POSE);
- else BIF_ThemeColor(TH_BONE_SOLID);
-
- }
- else if(dt==OB_SOLID)
+ else if (armflag & ARM_POSEMODE)
+ set_pchan_glColor(PCHAN_COLOR_SPHEREBONE_BASE, armflag, boneflag, constflag);
+ else if (dt == OB_SOLID)
BIF_ThemeColor(TH_BONE_SOLID);
fac1= (length-head)/length;
fac2= (length-tail)/length;
- if(length > head+tail) {
+ if (length > (head+tail)) {
if (id != -1)
glLoadName (id | BONESEL_BONE);
@@ -729,25 +946,25 @@ static void draw_sphere_bone(int dt, int armflag, int boneflag, int constflag, u
glTranslatef(0.0f, 0.0f, head);
gluCylinder(qobj, fac1*head + (1.0f-fac1)*tail, fac2*tail + (1.0f-fac2)*head, length-head-tail, 16, 1);
glTranslatef(0.0f, 0.0f, -head);
-
+
glDisable(GL_POLYGON_OFFSET_FILL);
/* draw sphere on extrema */
glTranslatef(0.0f, 0.0f, length-tail);
- gluSphere( qobj, fac2*tail + (1.0f-fac2)*head, 16, 10);
+ gluSphere(qobj, fac2*tail + (1.0f-fac2)*head, 16, 10);
glTranslatef(0.0f, 0.0f, -length+tail);
-
+
glTranslatef(0.0f, 0.0f, head);
- gluSphere( qobj, fac1*head + (1.0f-fac1)*tail, 16, 10);
+ gluSphere(qobj, fac1*head + (1.0f-fac1)*tail, 16, 10);
}
else {
/* 1 sphere in center */
glTranslatef(0.0f, 0.0f, (head + length-tail)/2.0);
- gluSphere( qobj, fac1*head + (1.0f-fac1)*tail, 16, 10);
+ gluSphere(qobj, fac1*head + (1.0f-fac1)*tail, 16, 10);
}
/* restore */
- if(dt==OB_SOLID) {
+ if (dt==OB_SOLID) {
glShadeModel(GL_FLAT);
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
@@ -770,7 +987,7 @@ static void draw_line_bone(int armflag, int boneflag, int constflag, unsigned in
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- if(pchan)
+ if (pchan)
length= pchan->bone->length;
else
length= ebone->length;
@@ -779,20 +996,16 @@ static void draw_line_bone(int armflag, int boneflag, int constflag, unsigned in
glScalef(length, length, length);
/* this chunk not in object mode */
- if(armflag & (ARM_EDITMODE|ARM_POSEMODE)) {
+ if (armflag & (ARM_EDITMODE|ARM_POSEMODE)) {
glLineWidth(4.0);
- if(armflag & ARM_POSEMODE) {
- /* outline in black or selection color */
- if (boneflag & BONE_ACTIVE) BIF_ThemeColorShade(TH_BONE_POSE, 40);
- else if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_BONE_POSE);
- else BIF_ThemeColor(TH_WIRE);
- }
+ if (armflag & ARM_POSEMODE)
+ set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
else if (armflag & ARM_EDITMODE) {
BIF_ThemeColor(TH_WIRE);
}
/* Draw root point if we are not connected */
- if (!(boneflag & BONE_CONNECTED)){
+ if ((boneflag & BONE_CONNECTED)==0) {
if (G.f & G_PICKSEL) { // no bitmap in selection mode, crashes 3d cards...
glLoadName (id | BONESEL_ROOT);
glBegin(GL_POINTS);
@@ -806,7 +1019,7 @@ static void draw_line_bone(int armflag, int boneflag, int constflag, unsigned in
}
if (id != -1)
- glLoadName ((GLuint) id|BONESEL_BONE);
+ glLoadName((GLuint) id|BONESEL_BONE);
glBegin(GL_LINES);
glVertex3f(0.0f, 0.0f, 0.0f);
@@ -814,8 +1027,9 @@ static void draw_line_bone(int armflag, int boneflag, int constflag, unsigned in
glEnd();
/* tip */
- if (G.f & G_PICKSEL) { // no bitmap in selection mode, crashes 3d cards...
- glLoadName (id | BONESEL_TIP);
+ if (G.f & G_PICKSEL) {
+ /* no bitmap in selection mode, crashes 3d cards... */
+ glLoadName(id | BONESEL_TIP);
glBegin(GL_POINTS);
glVertex3f(0.0f, 1.0f, 0.0f);
glEnd();
@@ -827,27 +1041,19 @@ static void draw_line_bone(int armflag, int boneflag, int constflag, unsigned in
/* further we send no names */
if (id != -1)
- glLoadName (id & 0xFFFF); // object tag, for bordersel optim
-
- if(armflag & ARM_POSEMODE) {
- /* inner part in background color or constraint */
- if(constflag) {
- if(constflag & PCHAN_HAS_STRIDE) glColor3ub(0, 0, 200);
- else if(constflag & PCHAN_HAS_TARGET) glColor3ub(255, 150, 0);
- else if(constflag & PCHAN_HAS_IK) glColor3ub(255, 255, 0);
- else if(constflag & PCHAN_HAS_CONST) glColor3ub(0, 255, 120);
- else BIF_ThemeColor(TH_BONE_POSE); // PCHAN_HAS_ACTION
- }
- else BIF_ThemeColorShade(TH_BACK, -30);
- }
+ glLoadName(id & 0xFFFF); /* object tag, for bordersel optim */
+
+ if (armflag & ARM_POSEMODE)
+ set_pchan_glColor(PCHAN_COLOR_LINEBONE, armflag, boneflag, constflag);
}
glLineWidth(2.0);
- /* Draw root point if we are not connected */
- if (!(boneflag & BONE_CONNECTED)){
- if ((G.f & G_PICKSEL)==0) { // no bitmap in selection mode, crashes 3d cards...
- if(armflag & ARM_EDITMODE) {
+ /*Draw root point if we are not connected */
+ if ((boneflag & BONE_CONNECTED)==0) {
+ if ((G.f & G_PICKSEL)==0) {
+ /* no bitmap in selection mode, crashes 3d cards... */
+ if (armflag & ARM_EDITMODE) {
if (boneflag & BONE_ROOTSEL) BIF_ThemeColor(TH_VERTEX_SELECT);
else BIF_ThemeColor(TH_VERTEX);
}
@@ -856,18 +1062,19 @@ static void draw_line_bone(int armflag, int boneflag, int constflag, unsigned in
}
}
- if(armflag & ARM_EDITMODE) {
- if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_EDGE_SELECT);
- else BIF_ThemeColorShade(TH_BACK, -30);
- }
+ if (armflag & ARM_EDITMODE) {
+ if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_EDGE_SELECT);
+ else BIF_ThemeColorShade(TH_BACK, -30);
+ }
glBegin(GL_LINES);
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glEnd();
/* tip */
- if ((G.f & G_PICKSEL)==0) { // no bitmap in selection mode, crashes 3d cards...
- if(armflag & ARM_EDITMODE) {
+ if ((G.f & G_PICKSEL)==0) {
+ /* no bitmap in selection mode, crashes 3d cards... */
+ if (armflag & ARM_EDITMODE) {
if (boneflag & BONE_TIPSEL) BIF_ThemeColor(TH_VERTEX_SELECT);
else BIF_ThemeColor(TH_VERTEX);
}
@@ -884,24 +1091,25 @@ static void draw_b_bone_boxes(int dt, bPoseChannel *pchan, float xwidth, float l
{
int segments= 0;
- if(pchan) segments= pchan->bone->segments;
+ if (pchan)
+ segments= pchan->bone->segments;
- if(segments>1 && pchan) {
+ if ((segments > 1) && (pchan)) {
float dlen= length/(float)segments;
Mat4 *bbone= b_bone_spline_setup(pchan, 0);
int a;
- for(a=0; a<segments; a++, bbone++) {
+ for (a=0; a<segments; a++, bbone++) {
glPushMatrix();
glMultMatrixf(bbone->mat);
- if(dt==OB_SOLID) drawsolidcube_size(xwidth, dlen, zwidth);
+ if (dt==OB_SOLID) drawsolidcube_size(xwidth, dlen, zwidth);
else drawcube_size(xwidth, dlen, zwidth);
glPopMatrix();
}
}
else {
glPushMatrix();
- if(dt==OB_SOLID) drawsolidcube_size(xwidth, length, zwidth);
+ if (dt==OB_SOLID) drawsolidcube_size(xwidth, length, zwidth);
else drawcube_size(xwidth, length, zwidth);
glPopMatrix();
}
@@ -911,7 +1119,7 @@ static void draw_b_bone(int dt, int armflag, int boneflag, int constflag, unsign
{
float xwidth, length, zwidth;
- if(pchan) {
+ if (pchan) {
xwidth= pchan->bone->xwidth;
length= pchan->bone->length;
zwidth= pchan->bone->zwidth;
@@ -923,7 +1131,7 @@ static void draw_b_bone(int dt, int armflag, int boneflag, int constflag, unsign
}
/* draw points only if... */
- if(armflag & ARM_EDITMODE) {
+ if (armflag & ARM_EDITMODE) {
/* move to unitspace */
glPushMatrix();
glScalef(length, length, length);
@@ -934,16 +1142,13 @@ static void draw_b_bone(int dt, int armflag, int boneflag, int constflag, unsign
/* colors for modes */
if (armflag & ARM_POSEMODE) {
- if(dt==OB_WIRE) {
- if (boneflag & BONE_ACTIVE) BIF_ThemeColorShade(TH_BONE_POSE, 40);
- else if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_BONE_POSE);
- else BIF_ThemeColor(TH_WIRE);
- }
+ if (dt <= OB_WIRE)
+ set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
else
- BIF_ThemeColor(TH_BONE_SOLID);
+ set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, constflag);
}
else if (armflag & ARM_EDITMODE) {
- if(dt==OB_WIRE) {
+ if (dt==OB_WIRE) {
if (boneflag & BONE_ACTIVE) BIF_ThemeColor(TH_EDGE_SELECT);
else if (boneflag & BONE_SELECTED) BIF_ThemeColorShade(TH_EDGE_SELECT, -20);
else BIF_ThemeColor(TH_WIRE);
@@ -957,10 +1162,14 @@ static void draw_b_bone(int dt, int armflag, int boneflag, int constflag, unsign
}
/* set up solid drawing */
- if(dt > OB_WIRE) {
+ if (dt > OB_WIRE) {
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
- BIF_ThemeColor(TH_BONE_SOLID);
+
+ if (armflag & ARM_POSEMODE)
+ set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, constflag);
+ else
+ BIF_ThemeColor(TH_BONE_SOLID);
draw_b_bone_boxes(OB_SOLID, pchan, xwidth, length, zwidth);
@@ -968,25 +1177,21 @@ static void draw_b_bone(int dt, int armflag, int boneflag, int constflag, unsign
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_LIGHTING);
}
- else { // wire
- if (armflag & ARM_POSEMODE){
- if(constflag) {
- glEnable(GL_BLEND);
-
- if(constflag & PCHAN_HAS_STRIDE) glColor4ub(0, 0, 200, 80);
- else if(constflag & PCHAN_HAS_TARGET) glColor4ub(255, 150, 0, 80);
- else if(constflag & PCHAN_HAS_IK) glColor4ub(255, 255, 0, 80);
- else if(constflag & PCHAN_HAS_CONST) glColor4ub(0, 255, 120, 80);
- else BIF_ThemeColor4(TH_BONE_POSE); // PCHAN_HAS_ACTION
-
- draw_b_bone_boxes(OB_SOLID, pchan, xwidth, length, zwidth);
-
- glDisable(GL_BLEND);
+ else {
+ /* wire */
+ if (armflag & ARM_POSEMODE) {
+ if (constflag) {
+ /* set constraint colours */
+ if (set_pchan_glColor(PCHAN_COLOR_CONSTS, armflag, boneflag, constflag)) {
+ glEnable(GL_BLEND);
+
+ draw_b_bone_boxes(OB_SOLID, pchan, xwidth, length, zwidth);
+
+ glDisable(GL_BLEND);
+ }
/* restore colors */
- if (boneflag & BONE_ACTIVE) BIF_ThemeColorShade(TH_BONE_POSE, 40);
- else if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_BONE_POSE);
- else BIF_ThemeColor(TH_WIRE);
+ set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
}
}
@@ -1003,7 +1208,7 @@ static void draw_bone(int dt, int armflag, int boneflag, int constflag, unsigned
glScalef(length, length, length);
/* set up solid drawing */
- if(dt > OB_WIRE) {
+ if (dt > OB_WIRE) {
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
BIF_ThemeColor(TH_BONE_SOLID);
@@ -1011,61 +1216,56 @@ static void draw_bone(int dt, int armflag, int boneflag, int constflag, unsigned
/* colors for posemode */
if (armflag & ARM_POSEMODE) {
- if(dt==OB_WIRE) {
- if (boneflag & BONE_ACTIVE) BIF_ThemeColorShade(TH_BONE_POSE, 40);
- else if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_BONE_POSE);
- else BIF_ThemeColor(TH_WIRE);
- }
+ if (dt <= OB_WIRE)
+ set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
else
- BIF_ThemeColor(TH_BONE_SOLID);
+ set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, constflag);
}
draw_bone_points(dt, armflag, boneflag, id);
/* now draw the bone itself */
-
if (id != -1) {
- glLoadName ((GLuint) id|BONESEL_BONE);
+ glLoadName((GLuint) id|BONESEL_BONE);
}
/* wire? */
- if(dt <= OB_WIRE) {
+ if (dt <= OB_WIRE) {
/* colors */
if (armflag & ARM_EDITMODE) {
if (boneflag & BONE_ACTIVE) BIF_ThemeColor(TH_EDGE_SELECT);
else if (boneflag & BONE_SELECTED) BIF_ThemeColorShade(TH_EDGE_SELECT, -20);
else BIF_ThemeColor(TH_WIRE);
}
- else if (armflag & ARM_POSEMODE){
- if(constflag) {
- glEnable(GL_BLEND);
-
- if(constflag & PCHAN_HAS_STRIDE) glColor4ub(0, 0, 200, 80);
- else if(constflag & PCHAN_HAS_TARGET) glColor4ub(255, 150, 0, 80);
- else if(constflag & PCHAN_HAS_IK) glColor4ub(255, 255, 0, 80);
- else if(constflag & PCHAN_HAS_CONST) glColor4ub(0, 255, 120, 80);
- else BIF_ThemeColor4(TH_BONE_POSE); // PCHAN_HAS_ACTION
+ else if (armflag & ARM_POSEMODE) {
+ if (constflag) {
+ /* draw constraint colors */
+ if (set_pchan_glColor(PCHAN_COLOR_CONSTS, armflag, boneflag, constflag)) {
+ glEnable(GL_BLEND);
- draw_bone_solid_octahedral();
- glDisable(GL_BLEND);
-
+ draw_bone_solid_octahedral();
+
+ glDisable(GL_BLEND);
+ }
+
/* restore colors */
- if (boneflag & BONE_ACTIVE) BIF_ThemeColorShade(TH_BONE_POSE, 40);
- else if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_BONE_POSE);
- else BIF_ThemeColor(TH_WIRE);
+ set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, constflag);
}
}
draw_bone_octahedral();
}
- else { /* solid */
-
- BIF_ThemeColor(TH_BONE_SOLID);
+ else {
+ /* solid */
+ if (armflag & ARM_POSEMODE)
+ set_pchan_glColor(PCHAN_COLOR_SOLID, armflag, boneflag, constflag);
+ else
+ BIF_ThemeColor(TH_BONE_SOLID);
draw_bone_solid_octahedral();
}
/* disable solid drawing */
- if(dt>OB_WIRE) {
+ if (dt > OB_WIRE) {
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_LIGHTING);
}
@@ -1073,20 +1273,17 @@ static void draw_bone(int dt, int armflag, int boneflag, int constflag, unsigned
static void draw_custom_bone(Object *ob, int dt, int armflag, int boneflag, unsigned int id, float length)
{
-
if(ob==NULL) return;
glScalef(length, length, length);
/* colors for posemode */
if (armflag & ARM_POSEMODE) {
- if (boneflag & BONE_ACTIVE) BIF_ThemeColorShade(TH_BONE_POSE, 40);
- else if (boneflag & BONE_SELECTED) BIF_ThemeColor(TH_BONE_POSE);
- else BIF_ThemeColor(TH_WIRE);
+ set_pchan_glColor(PCHAN_COLOR_NORMAL, armflag, boneflag, 0);
}
if (id != -1) {
- glLoadName ((GLuint) id|BONESEL_BONE);
+ glLoadName((GLuint) id|BONESEL_BONE);
}
draw_object_instance(ob, dt, armflag & ARM_POSEMODE);
@@ -1098,8 +1295,8 @@ static void pchan_draw_IK_root_lines(bPoseChannel *pchan)
bConstraint *con;
bPoseChannel *parchan;
- for(con= pchan->constraints.first; con; con= con->next) {
- if(con->type == CONSTRAINT_TYPE_KINEMATIC) {
+ for (con= pchan->constraints.first; con; con= con->next) {
+ if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
bKinematicConstraint *data = (bKinematicConstraint*)con->data;
int segcount= 0;
@@ -1107,7 +1304,7 @@ static void pchan_draw_IK_root_lines(bPoseChannel *pchan)
glBegin(GL_LINES);
/* exclude tip from chain? */
- if(!(data->flag & CONSTRAINT_IK_TIP))
+ if ((data->flag & CONSTRAINT_IK_TIP)==0)
parchan= pchan->parent;
else
parchan= pchan;
@@ -1115,12 +1312,12 @@ static void pchan_draw_IK_root_lines(bPoseChannel *pchan)
glVertex3fv(parchan->pose_tail);
/* Find the chain's root */
- while (parchan->parent){
+ while (parchan->parent) {
segcount++;
if(segcount==data->rootbone || segcount>255) break; // 255 is weak
parchan= parchan->parent;
}
- if(parchan)
+ if (parchan)
glVertex3fv(parchan->pose_head);
glEnd();
@@ -1198,7 +1395,7 @@ static void draw_dof_ellipse(float ax, float az)
glColor3ub(0, 0, 0);
glBegin(GL_LINE_STRIP);
- for(i=0; i<n; i++)
+ for (i=0; i<n; i++)
bgl_sphere_project(staticSine[n-i-1]*ax, staticSine[i]*az);
glEnd();
}
@@ -1209,40 +1406,41 @@ static void draw_pose_dofs(Object *ob)
bPoseChannel *pchan;
Bone *bone;
- for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
+ for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
bone= pchan->bone;
- if(bone && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
- if(bone->flag & BONE_SELECTED) {
- if(bone->layer & arm->layer) {
- if(pchan->ikflag & (BONE_IK_XLIMIT|BONE_IK_ZLIMIT)) {
- if(pose_channel_in_IK_chain(ob, pchan)) {
+
+ if ( (bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
+ if (bone->flag & BONE_SELECTED) {
+ if (bone->layer & arm->layer) {
+ if (pchan->ikflag & (BONE_IK_XLIMIT|BONE_IK_ZLIMIT)) {
+ if (pose_channel_in_IK_chain(ob, pchan)) {
float corner[4][3], posetrans[3], mat[4][4];
float phi=0.0f, theta=0.0f, scale;
int a, i;
-
+
/* in parent-bone pose, but own restspace */
glPushMatrix();
-
+
VECCOPY(posetrans, pchan->pose_mat[3]);
glTranslatef(posetrans[0], posetrans[1], posetrans[2]);
-
- if(pchan->parent) {
+
+ if (pchan->parent) {
Mat4CpyMat4(mat, pchan->parent->pose_mat);
mat[3][0]= mat[3][1]= mat[3][2]= 0.0f;
glMultMatrixf(mat);
}
-
+
Mat4CpyMat3(mat, pchan->bone->bone_mat);
glMultMatrixf(mat);
-
+
scale= bone->length*pchan->size[1];
glScalef(scale, scale, scale);
-
- if(pchan->ikflag & BONE_IK_XLIMIT) {
- if(pchan->ikflag & BONE_IK_ZLIMIT) {
+
+ if (pchan->ikflag & BONE_IK_XLIMIT) {
+ if (pchan->ikflag & BONE_IK_ZLIMIT) {
float amin[3], amax[3];
-
- for(i=0; i<3; i++) {
+
+ for (i=0; i<3; i++) {
amin[i]= sin(pchan->limitmin[i]*M_PI/360.0);
amax[i]= sin(pchan->limitmax[i]*M_PI/360.0);
}
@@ -1261,49 +1459,50 @@ static void draw_pose_dofs(Object *ob)
}
/* arcs */
- if(pchan->ikflag & BONE_IK_ZLIMIT) {
+ if (pchan->ikflag & BONE_IK_ZLIMIT) {
theta= 0.5*(pchan->limitmin[2]+pchan->limitmax[2]);
glRotatef(theta, 0.0f, 0.0f, 1.0f);
-
+
glColor3ub(50, 50, 255); // blue, Z axis limit
glBegin(GL_LINE_STRIP);
- for(a=-16; a<=16; a++) {
+ for (a=-16; a<=16; a++) {
float fac= ((float)a)/16.0f;
phi= fac*(M_PI/360.0f)*(pchan->limitmax[2]-pchan->limitmin[2]);
- if(a==-16) i= 0; else i= 1;
+ i= (a == -16) ? 0 : 1;
corner[i][0]= sin(phi);
corner[i][1]= cos(phi);
corner[i][2]= 0.0f;
glVertex3fv(corner[i]);
}
glEnd();
-
+
glRotatef(-theta, 0.0f, 0.0f, 1.0f);
}
-
- if(pchan->ikflag & BONE_IK_XLIMIT) {
- theta= 0.5*( pchan->limitmin[0]+pchan->limitmax[0]);
+
+ if (pchan->ikflag & BONE_IK_XLIMIT) {
+ theta= 0.5*(pchan->limitmin[0]+pchan->limitmax[0]);
glRotatef(theta, 1.0f, 0.0f, 0.0f);
-
+
glColor3ub(255, 50, 50); // Red, X axis limit
glBegin(GL_LINE_STRIP);
- for(a=-16; a<=16; a++) {
+ for (a=-16; a<=16; a++) {
float fac= ((float)a)/16.0f;
phi= 0.5f*M_PI + fac*(M_PI/360.0f)*(pchan->limitmax[0]-pchan->limitmin[0]);
-
- if(a==-16) i= 2; else i= 3;
+
+ i= (a == -16) ? 2 : 3;
corner[i][0]= 0.0f;
corner[i][1]= sin(phi);
corner[i][2]= cos(phi);
glVertex3fv(corner[i]);
}
glEnd();
-
+
glRotatef(-theta, 1.0f, 0.0f, 0.0f);
}
-
- glPopMatrix(); // out of cone, out of bone
+
+ /* out of cone, out of bone */
+ glPopMatrix();
}
}
}
@@ -1327,33 +1526,34 @@ static void draw_pose_channels(Base *base, int dt)
/* hacky... prevent outline select from drawing dashed helplines */
glGetFloatv(GL_LINE_WIDTH, &tmp);
- if(tmp > 1.1) do_dashed= 0;
+ if (tmp > 1.1) do_dashed= 0;
if (G.vd->flag & V3D_HIDE_HELPLINES) do_dashed= 0;
/* precalc inverse matrix for drawing screen aligned */
- if(arm->drawtype==ARM_ENVELOPE) {
+ if (arm->drawtype==ARM_ENVELOPE) {
/* precalc inverse matrix for drawing screen aligned */
mygetmatrix(smat);
Mat4MulFloat3(smat[0], 1.0f/VecLength(ob->obmat[0]));
Mat4Invert(imat, smat);
/* and draw blended distances */
- if(arm->flag & ARM_POSEMODE) {
+ if (arm->flag & ARM_POSEMODE) {
glEnable(GL_BLEND);
//glShadeModel(GL_SMOOTH);
- if(G.vd->zbuf) glDisable(GL_DEPTH_TEST);
+ if (G.vd->zbuf) glDisable(GL_DEPTH_TEST);
- for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
+ for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
bone= pchan->bone;
- if(bone && !(bone->flag & (BONE_HIDDEN_P|BONE_NO_DEFORM|BONE_HIDDEN_PG))) {
- if(bone->flag & (BONE_SELECTED))
- if(bone->layer & arm->layer)
+ if (bone && !(bone->flag & (BONE_HIDDEN_P|BONE_NO_DEFORM|BONE_HIDDEN_PG))) {
+ if (bone->flag & (BONE_SELECTED)) {
+ if (bone->layer & arm->layer)
draw_sphere_bone_dist(smat, imat, bone->flag, pchan, NULL);
+ }
}
}
- if(G.vd->zbuf) glEnable(GL_DEPTH_TEST);
+ if (G.vd->zbuf) glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
//glShadeModel(GL_FLAT);
}
@@ -1364,67 +1564,80 @@ static void draw_pose_channels(Base *base, int dt)
glEnable(GL_CULL_FACE);
/* if solid we draw that first, with selection codes, but without names, axes etc */
- if(dt>OB_WIRE) {
- if(arm->flag & ARM_POSEMODE) index= base->selcol;
+ if (dt > OB_WIRE) {
+ if (arm->flag & ARM_POSEMODE)
+ index= base->selcol;
- for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
+ for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
bone= pchan->bone;
- if(bone && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
- if(bone->layer & arm->layer) {
+
+ if ( (bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)) ) {
+ if (bone->layer & arm->layer) {
glPushMatrix();
glMultMatrixf(pchan->pose_mat);
/* catch exception for bone with hidden parent */
flag= bone->flag;
- if(bone->parent && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)))
+ if ( (bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)) )
flag &= ~BONE_CONNECTED;
+
+ /* set color-set to use */
+ set_pchan_colorset(ob, pchan);
- if(pchan->custom && !(arm->flag & ARM_NO_CUSTOM))
+ if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM))
draw_custom_bone(pchan->custom, OB_SOLID, arm->flag, flag, index, bone->length);
- else if(arm->drawtype==ARM_LINE)
+ else if (arm->drawtype==ARM_LINE)
; /* nothing in solid */
- else if(arm->drawtype==ARM_ENVELOPE)
+ else if (arm->drawtype==ARM_ENVELOPE)
draw_sphere_bone(OB_SOLID, arm->flag, flag, 0, index, pchan, NULL);
- else if(arm->drawtype==ARM_B_BONE)
+ else if (arm->drawtype==ARM_B_BONE)
draw_b_bone(OB_SOLID, arm->flag, flag, 0, index, pchan, NULL);
- else {
+ else
draw_bone(OB_SOLID, arm->flag, flag, 0, index, bone->length);
- }
+
glPopMatrix();
}
}
- if (index!= -1) index+= 0x10000; // pose bones count in higher 2 bytes only
+
+ if (index!= -1)
+ index+= 0x10000; // pose bones count in higher 2 bytes only
}
+
/* very very confusing... but in object mode, solid draw, we cannot do glLoadName yet, stick bones are drawn in next loop */
- if(arm->drawtype!=ARM_LINE) {
- glLoadName (index & 0xFFFF); // object tag, for bordersel optim
+ if (arm->drawtype != ARM_LINE) {
+ /* object tag, for bordersel optim */
+ glLoadName(index & 0xFFFF);
index= -1;
}
}
/* wire draw over solid only in posemode */
- if( dt<=OB_WIRE || (arm->flag & ARM_POSEMODE) || arm->drawtype==ARM_LINE) {
-
+ if ((dt <= OB_WIRE) || (arm->flag & ARM_POSEMODE) || (arm->drawtype==ARM_LINE)) {
/* draw line check first. we do selection indices */
if (arm->drawtype==ARM_LINE) {
- if (arm->flag & ARM_POSEMODE) index= base->selcol;
+ if (arm->flag & ARM_POSEMODE)
+ index= base->selcol;
}
/* if solid && posemode, we draw again with polygonoffset */
- else if (dt>OB_WIRE && (arm->flag & ARM_POSEMODE))
+ else if ((dt > OB_WIRE) && (arm->flag & ARM_POSEMODE)) {
bglPolygonOffset(1.0);
- else
+ }
+ else {
/* and we use selection indices if not done yet */
- if (arm->flag & ARM_POSEMODE) index= base->selcol;
+ if (arm->flag & ARM_POSEMODE)
+ index= base->selcol;
+ }
- for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
+ for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
bone= pchan->bone;
- if(bone && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
- if(bone->layer & arm->layer) {
+
+ if ((bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
+ if (bone->layer & arm->layer) {
if (do_dashed && bone->parent) {
/* Draw a line from our root to the parent's tip */
- if(!(bone->flag & BONE_CONNECTED) ){
+ if ((bone->flag & BONE_CONNECTED)==0) {
if (arm->flag & ARM_POSEMODE) {
- glLoadName (index & 0xFFFF); // object tag, for bordersel optim
+ glLoadName(index & 0xFFFF); // object tag, for bordersel optim
BIF_ThemeColor(TH_WIRE);
}
setlinestyle(3);
@@ -1434,29 +1647,29 @@ static void draw_pose_channels(Base *base, int dt)
glEnd();
setlinestyle(0);
}
- // Draw a line to IK root bone
- if(arm->flag & ARM_POSEMODE) {
- if(pchan->constflag & PCHAN_HAS_IK) {
- if(bone->flag & BONE_SELECTED) {
-
- if(pchan->constflag & PCHAN_HAS_TARGET) glColor3ub(200, 120, 0);
+
+ /* Draw a line to IK root bone */
+ // TODO: make this draw with do_dashed off (V3D_HIDE_HELPLINES)
+ if (arm->flag & ARM_POSEMODE) {
+ if (pchan->constflag & PCHAN_HAS_IK) {
+ if (bone->flag & BONE_SELECTED) {
+ if (pchan->constflag & PCHAN_HAS_TARGET) glColor3ub(200, 120, 0);
else glColor3ub(200, 200, 50); // add theme!
-
- glLoadName (index & 0xFFFF);
+
+ glLoadName(index & 0xFFFF);
pchan_draw_IK_root_lines(pchan);
}
}
}
}
- if(arm->drawtype!=ARM_ENVELOPE) {
- glPushMatrix();
+ glPushMatrix();
+ if (arm->drawtype != ARM_ENVELOPE)
glMultMatrixf(pchan->pose_mat);
- }
/* catch exception for bone with hidden parent */
flag= bone->flag;
- if(bone->parent && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)))
+ if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)))
flag &= ~BONE_CONNECTED;
/* extra draw service for pose mode */
@@ -1465,33 +1678,36 @@ static void draw_pose_channels(Base *base, int dt)
constflag |= PCHAN_HAS_ACTION;
if(pchan->flag & POSE_STRIDE)
constflag |= PCHAN_HAS_STRIDE;
+
+ /* set color-set to use */
+ set_pchan_colorset(ob, pchan);
- if(pchan->custom && !(arm->flag & ARM_NO_CUSTOM)) {
- if(dt<OB_SOLID)
+ if (pchan->custom && !(arm->flag & ARM_NO_CUSTOM)) {
+ if (dt < OB_SOLID)
draw_custom_bone(pchan->custom, OB_WIRE, arm->flag, flag, index, bone->length);
}
- else if(arm->drawtype==ARM_ENVELOPE) {
- if(dt<OB_SOLID)
+ else if (arm->drawtype==ARM_ENVELOPE) {
+ if (dt < OB_SOLID)
draw_sphere_bone_wire(smat, imat, arm->flag, flag, constflag, index, pchan, NULL);
}
- else if(arm->drawtype==ARM_LINE)
+ else if (arm->drawtype==ARM_LINE)
draw_line_bone(arm->flag, flag, constflag, index, pchan, NULL);
- else if(arm->drawtype==ARM_B_BONE)
+ else if (arm->drawtype==ARM_B_BONE)
draw_b_bone(OB_WIRE, arm->flag, flag, constflag, index, pchan, NULL);
- else {
+ else
draw_bone(OB_WIRE, arm->flag, flag, constflag, index, bone->length);
- }
- if(arm->drawtype!=ARM_ENVELOPE)
- glPopMatrix();
+ glPopMatrix();
}
}
- if (index!= -1) index+= 0x10000; // pose bones count in higher 2 bytes only
+
+ /* pose bones count in higher 2 bytes only */
+ if (index != -1)
+ index+= 0x10000;
}
/* restore things */
- if (arm->drawtype!=ARM_LINE && dt>OB_WIRE && (arm->flag & ARM_POSEMODE))
+ if ((arm->drawtype!=ARM_LINE) && (dt>OB_WIRE) && (arm->flag & ARM_POSEMODE))
bglPolygonOffset(0.0);
-
}
/* restore */
@@ -1502,31 +1718,35 @@ static void draw_pose_channels(Base *base, int dt)
draw_pose_dofs(ob);
/* finally names and axes */
- if(arm->flag & (ARM_DRAWNAMES|ARM_DRAWAXES)) {
- // patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing
- if((G.f & G_PICKSEL) == 0) {
+ if (arm->flag & (ARM_DRAWNAMES|ARM_DRAWAXES)) {
+ /* patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing */
+ if ((G.f & G_PICKSEL) == 0) {
float vec[3];
- if(G.vd->zbuf) glDisable(GL_DEPTH_TEST);
+ if (G.vd->zbuf) glDisable(GL_DEPTH_TEST);
- for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
- if((pchan->bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))==0) {
- if(pchan->bone->layer & arm->layer) {
+ for (pchan=ob->pose->chanbase.first; pchan; pchan=pchan->next) {
+ if ((pchan->bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))==0) {
+ if (pchan->bone->layer & arm->layer) {
if (arm->flag & (ARM_EDITMODE|ARM_POSEMODE)) {
bone= pchan->bone;
- if(bone->flag & BONE_SELECTED) BIF_ThemeColor(TH_TEXT_HI);
+
+ if (bone->flag & BONE_SELECTED) BIF_ThemeColor(TH_TEXT_HI);
else BIF_ThemeColor(TH_TEXT);
}
- else if(dt > OB_WIRE) BIF_ThemeColor(TH_TEXT);
+ else if (dt > OB_WIRE)
+ BIF_ThemeColor(TH_TEXT);
- if (arm->flag & ARM_DRAWNAMES){
+ /* Draw names of bone */
+ if (arm->flag & ARM_DRAWNAMES) {
VecMidf(vec, pchan->pose_head, pchan->pose_tail);
glRasterPos3fv(vec);
BMF_DrawString(G.font, " ");
BMF_DrawString(G.font, pchan->name);
- }
- /* Draw additional axes */
- if( (arm->flag & ARM_DRAWAXES) && (arm->flag & ARM_POSEMODE) ){
+ }
+
+ /* Draw additional axes on the bone tail */
+ if ( (arm->flag & ARM_DRAWAXES) && (arm->flag & ARM_POSEMODE) ) {
glPushMatrix();
glMultMatrixf(pchan->pose_mat);
glTranslatef(0.0f, pchan->bone->length, 0.0f);
@@ -1537,10 +1757,9 @@ static void draw_pose_channels(Base *base, int dt)
}
}
- if(G.vd->zbuf) glEnable(GL_DEPTH_TEST);
+ if (G.vd->zbuf) glEnable(GL_DEPTH_TEST);
}
}
-
}
/* in editmode, we don't store the bone matrix... */
@@ -1549,10 +1768,10 @@ static void set_matrix_editbone(EditBone *eBone)
float delta[3],offset[3];
float mat[3][3], bmat[4][4];
- /* Compose the parent transforms (i.e. their translations) */
- VECCOPY (offset, eBone->head);
+ /* Compose the parent transforms (i.e. their translations) */
+ VECCOPY(offset, eBone->head);
- glTranslatef (offset[0],offset[1],offset[2]);
+ glTranslatef(offset[0],offset[1],offset[2]);
VecSubf(delta, eBone->tail, eBone->head);
@@ -1560,8 +1779,8 @@ static void set_matrix_editbone(EditBone *eBone)
vec_roll_to_mat3(delta, eBone->roll, mat);
Mat4CpyMat3(bmat, mat);
-
- glMultMatrixf (bmat);
+
+ glMultMatrixf(bmat);
}
@@ -1584,35 +1803,37 @@ static void draw_ebones(Object *ob, int dt)
glEnable(GL_BLEND);
//glShadeModel(GL_SMOOTH);
- if(G.vd->zbuf) glDisable(GL_DEPTH_TEST);
+ if (G.vd->zbuf) glDisable(GL_DEPTH_TEST);
- for (eBone=G.edbo.first, index=0; eBone; eBone=eBone->next, index++){
- if(eBone->layer & arm->layer)
- if(!(eBone->flag & (BONE_HIDDEN_A|BONE_NO_DEFORM)))
- if(eBone->flag & (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL))
+ for (eBone=G.edbo.first, index=0; eBone; eBone=eBone->next, index++) {
+ if (eBone->layer & arm->layer) {
+ if ((eBone->flag & (BONE_HIDDEN_A|BONE_NO_DEFORM))==0) {
+ if (eBone->flag & (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL))
draw_sphere_bone_dist(smat, imat, eBone->flag, NULL, eBone);
+ }
+ }
}
- if(G.vd->zbuf) glEnable(GL_DEPTH_TEST);
+ if (G.vd->zbuf) glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
//glShadeModel(GL_FLAT);
}
/* if solid we draw it first */
- if(dt>OB_WIRE && arm->drawtype!=ARM_LINE) {
+ if ((dt > OB_WIRE) && (arm->drawtype!=ARM_LINE)) {
index= 0;
- for (eBone=G.edbo.first, index=0; eBone; eBone=eBone->next, index++){
- if(eBone->layer & arm->layer) {
- if(!(eBone->flag & BONE_HIDDEN_A)) {
+ for (eBone=G.edbo.first, index=0; eBone; eBone=eBone->next, index++) {
+ if (eBone->layer & arm->layer) {
+ if ((eBone->flag & BONE_HIDDEN_A)==0) {
glPushMatrix();
set_matrix_editbone(eBone);
/* catch exception for bone with hidden parent */
flag= eBone->flag;
- if(eBone->parent && ((eBone->parent->flag & BONE_HIDDEN_A) || (eBone->parent->layer & arm->layer)==0) )
+ if ( (eBone->parent) && ((eBone->parent->flag & BONE_HIDDEN_A) || (eBone->parent->layer & arm->layer)==0) )
flag &= ~BONE_CONNECTED;
- if(arm->drawtype==ARM_ENVELOPE)
+ if (arm->drawtype==ARM_ENVELOPE)
draw_sphere_bone(OB_SOLID, arm->flag, flag, 0, index, NULL, eBone);
else if(arm->drawtype==ARM_B_BONE)
draw_b_bone(OB_SOLID, arm->flag, flag, 0, index, NULL, eBone);
@@ -1629,42 +1850,42 @@ static void draw_ebones(Object *ob, int dt)
/* if wire over solid, set offset */
index= -1;
glLoadName(-1);
- if(arm->drawtype==ARM_LINE) {
+ if (arm->drawtype==ARM_LINE) {
if(G.f & G_PICKSEL)
index= 0;
}
- else if (dt>OB_WIRE)
+ else if (dt > OB_WIRE)
bglPolygonOffset(1.0);
- else if(arm->flag & ARM_EDITMODE)
- index= 0; // do selection codes
+ else if (arm->flag & ARM_EDITMODE)
+ index= 0; /* do selection codes */
- for (eBone=G.edbo.first; eBone; eBone=eBone->next){
- if(eBone->layer & arm->layer) {
- if(!(eBone->flag & BONE_HIDDEN_A)) {
+ for (eBone=G.edbo.first; eBone; eBone=eBone->next) {
+ if (eBone->layer & arm->layer) {
+ if ((eBone->flag & BONE_HIDDEN_A)==0) {
/* catch exception for bone with hidden parent */
flag= eBone->flag;
- if(eBone->parent && ((eBone->parent->flag & BONE_HIDDEN_A) || (eBone->parent->layer & arm->layer)==0) )
+ if ( (eBone->parent) && ((eBone->parent->flag & BONE_HIDDEN_A) || (eBone->parent->layer & arm->layer)==0) )
flag &= ~BONE_CONNECTED;
- if(arm->drawtype==ARM_ENVELOPE) {
- if(dt<OB_SOLID)
+ if (arm->drawtype == ARM_ENVELOPE) {
+ if (dt < OB_SOLID)
draw_sphere_bone_wire(smat, imat, arm->flag, flag, 0, index, NULL, eBone);
}
else {
glPushMatrix();
set_matrix_editbone(eBone);
- if(arm->drawtype==ARM_LINE)
+ if (arm->drawtype == ARM_LINE)
draw_line_bone(arm->flag, flag, 0, index, NULL, eBone);
- else if(arm->drawtype==ARM_B_BONE)
+ else if (arm->drawtype == ARM_B_BONE)
draw_b_bone(OB_WIRE, arm->flag, flag, 0, index, NULL, eBone);
else
draw_bone(OB_WIRE, arm->flag, flag, 0, index, eBone->length);
-
+
glPopMatrix();
}
-
+
/* offset to parent */
if (eBone->parent) {
BIF_ThemeColor(TH_WIRE);
@@ -1684,33 +1905,33 @@ static void draw_ebones(Object *ob, int dt)
}
/* restore */
- if(arm->drawtype==ARM_LINE);
+ if (arm->drawtype==ARM_LINE);
else if (dt>OB_WIRE) bglPolygonOffset(0.0);
/* finally names and axes */
- if(arm->flag & (ARM_DRAWNAMES|ARM_DRAWAXES)) {
+ if (arm->flag & (ARM_DRAWNAMES|ARM_DRAWAXES)) {
// patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing
- if((G.f & G_PICKSEL) == 0) {
+ if ((G.f & G_PICKSEL) == 0) {
float vec[3];
- if(G.vd->zbuf) glDisable(GL_DEPTH_TEST);
+ if (G.vd->zbuf) glDisable(GL_DEPTH_TEST);
- for (eBone=G.edbo.first, index=0; eBone; eBone=eBone->next, index++){
+ for (eBone=G.edbo.first, index=0; eBone; eBone=eBone->next, index++) {
if(eBone->layer & arm->layer) {
- if(!(eBone->flag & BONE_HIDDEN_A)) {
+ if ((eBone->flag & BONE_HIDDEN_A)==0) {
- if(eBone->flag & BONE_SELECTED) BIF_ThemeColor(TH_TEXT_HI);
+ if (eBone->flag & BONE_SELECTED) BIF_ThemeColor(TH_TEXT_HI);
else BIF_ThemeColor(TH_TEXT);
/* Draw name */
- if(arm->flag & ARM_DRAWNAMES){
+ if (arm->flag & ARM_DRAWNAMES) {
VecMidf(vec, eBone->head, eBone->tail);
glRasterPos3fv(vec);
BMF_DrawString(G.font, " ");
BMF_DrawString(G.font, eBone->name);
}
/* Draw additional axes */
- if(arm->flag & ARM_DRAWAXES){
+ if (arm->flag & ARM_DRAWAXES) {
glPushMatrix();
set_matrix_editbone(eBone);
glTranslatef(0.0f, eBone->length, 0.0f);
@@ -1722,7 +1943,7 @@ static void draw_ebones(Object *ob, int dt)
}
}
- if(G.vd->zbuf) glEnable(GL_DEPTH_TEST);
+ if (G.vd->zbuf) glEnable(GL_DEPTH_TEST);
}
}
}
@@ -1829,12 +2050,12 @@ static void draw_pose_paths(Object *ob)
else {
/* green - on cfra */
if (pchan->bone->flag & BONE_SELECTED) {
- intensity= 0.3;
+ intensity= 0.5;
}
else {
- intensity= 0.8;
+ intensity= 0.99;
}
- BIF_ThemeColorBlend(TH_CFRAME, TH_BACK, intensity);
+ BIF_ThemeColorBlendShade(TH_CFRAME, TH_BACK, intensity, 10);
}
/* draw a vertex with this colour */