[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13364] trunk/blender/source/blender: == " Custom Bone Colors" ==

Joshua Leung aligorith at gmail.com
Wed Jan 23 11:14:45 CET 2008


Revision: 13364
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13364
Author:   aligorith
Date:     2008-01-23 11:14:45 +0100 (Wed, 23 Jan 2008)

Log Message:
-----------
== "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). 

Modified Paths:
--------------
    trunk/blender/source/blender/makesdna/DNA_userdef_types.h
    trunk/blender/source/blender/src/buttons_editing.c
    trunk/blender/source/blender/src/drawarmature.c
    trunk/blender/source/blender/src/resources.c
    trunk/blender/source/blender/src/space.c

Modified: trunk/blender/source/blender/makesdna/DNA_userdef_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_userdef_types.h	2008-01-23 00:04:59 UTC (rev 13363)
+++ trunk/blender/source/blender/makesdna/DNA_userdef_types.h	2008-01-23 10:14:45 UTC (rev 13364)
@@ -64,7 +64,6 @@
 	char but_drawtype;
 	char pad[3];
 	char iconfile[80];	// FILE_MAXFILE length
-
 } ThemeUI;
 
 /* try to put them all in one, if needed a special struct can be created as well
@@ -107,14 +106,20 @@
 	char editmesh_active[4]; 
 } ThemeSpace;
 
+
 /* set of colors for use as a custom color set for Objects/Bones wire drawing */
 typedef struct ThemeWireColor {
-	char 	unselected[3];
-	char	selected[3];
-	char 	active[3];
-	char	pad[7];
+	char 	solid[4];
+	char	select[4];
+	char 	active[4];
+	
+	short 	flag;
+	short 	pad;
 } ThemeWireColor; 
 
+/* flags for ThemeWireColor */
+#define TH_WIRECOLOR_CONSTCOLS	(1<<0)
+
 /* A theme */
 typedef struct bTheme {
 	struct bTheme *next, *prev;

Modified: trunk/blender/source/blender/src/buttons_editing.c
===================================================================
--- trunk/blender/source/blender/src/buttons_editing.c	2008-01-23 00:04:59 UTC (rev 13363)
+++ trunk/blender/source/blender/src/buttons_editing.c	2008-01-23 10:14:45 UTC (rev 13364)
@@ -4071,9 +4071,10 @@
 	uiDefButI(block, ROW, REDRAWVIEW3D, "B-Bone",	155, 87,70,20, &arm->drawtype, 0, ARM_B_BONE, 0, 0, "Draw bones as boxes, showing subdivision and b-splines");
 	uiDefButI(block, ROW, REDRAWVIEW3D, "Envelope",	225, 87,85,20, &arm->drawtype, 0, ARM_ENVELOPE, 0, 0, "Draw bones as extruded spheres, showing deformation influence volume");
 
-	uiDefButBitI(block, TOG, ARM_DRAWAXES, REDRAWVIEW3D, "Draw Axes", 10, 67,100,20, &arm->flag, 0, 0, 0, 0, "Draw bone axes");
-	uiDefButBitI(block, TOG, ARM_DRAWNAMES, REDRAWVIEW3D, "Draw Names", 110,67,100,20, &arm->flag, 0, 0, 0, 0, "Draw bone names");
-	uiDefButBitI(block, TOGN, ARM_NO_CUSTOM, REDRAWVIEW3D, "Draw Shapes", 210,67,100,20, &arm->flag, 0, 0, 0, 0, "Draw custom bone shapes");
+	uiDefButBitI(block, TOG, ARM_DRAWAXES, REDRAWVIEW3D, "Axes", 10, 67,75,20, &arm->flag, 0, 0, 0, 0, "Draw bone axes");
+	uiDefButBitI(block, TOG, ARM_DRAWNAMES, REDRAWVIEW3D, "Names", 85,67,75,20, &arm->flag, 0, 0, 0, 0, "Draw bone names");
+	uiDefButBitI(block, TOGN, ARM_NO_CUSTOM, REDRAWVIEW3D, "Shapes", 160,67,75,20, &arm->flag, 0, 0, 0, 0, "Draw custom bone shapes");
+	uiDefButBitI(block, TOG, ARM_COL_CUSTOM, REDRAWVIEW3D, "Colors", 235,67,75,20, &arm->flag, 0, 0, 0, 0, "Draw custom bone colors (colors are set per Bone Group)");
 	
 	uiBlockEndAlign(block);
 	
@@ -5167,7 +5168,19 @@
 						uiDefIconBut(block, BUT, B_POSEGRP_REMOVE, VICON_X, xco+140-20, 85, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Remove this Pose Group");
 						
 						/* set custom color set */
-						uiDefButI(block, MENU,B_POSEGRP_RECALC, "Custom Color Set%t|GrpCol: [None]%x0", xco,65,140,19, &grp->customCol, 0.0, 0.0, 0.0, 0.0, "Set of Custom Colors to shade Group's bones with. (NOT YET FUNCTIONAL)");
+						uiDefButI(block, NUM,B_POSEGRP_RECALC, "GroupColor: ", xco,65,110,19, &grp->customCol, 0, 20, 0.0, 0.0, "Index of set of Custom Colors to shade Group's bones with. 0 = Use Default Color Scheme");						
+						if (grp->customCol) {
+							bTheme *btheme= U.themes.first;
+							ThemeWireColor *col_set= &btheme->tarm[(grp->customCol - 1)];
+							
+							uiSetButLock(1, "To change these colors, see Themes -> Bone Color Sets");
+							
+							uiDefButC(block, COL, B_POSEGRP_RECALC, "",		xco+110, 65, 10, 19, col_set->solid, 0, 0, 0, 0, "Color to use for surface of bones. See current theme in Info Window.");
+							uiDefButC(block, COL, B_POSEGRP_RECALC, "",		xco+120, 65, 10, 19, col_set->select, 0, 0, 0, 0, "Color to use for 'selected' bones. See current theme in Info Window.");
+							uiDefButC(block, COL, B_POSEGRP_RECALC, "",		xco+130, 65, 10, 19, col_set->active, 0, 0, 0, 0, "Color to use for 'active' bones. See current theme in Info Window.");
+							
+							uiClearButLock();
+						}
 					}
 				uiBlockEndAlign(block);
 			}

Modified: trunk/blender/source/blender/src/drawarmature.c
===================================================================
--- trunk/blender/source/blender/src/drawarmature.c	2008-01-23 00:04:59 UTC (rev 13363)
+++ trunk/blender/source/blender/src/drawarmature.c	2008-01-23 10:14:45 UTC (rev 13364)
@@ -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 @@
 { 1.0,  1.0, -1.0},
 };
 
-
-/* *************** Armature drawing, helper calls for parts ******************* */
-

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list