Fix #142464: Add customizable color for W quaternion channel

The W channel in quaternion and axis-angle F-Curves is now themeable
(defaulting to yellow), instead of incorrectly blending the X and Y axis
theme colors.

The original blending math did not take into account that the hue
channel actually wraps around, and so the blended color became blue
instead of the intended yellow.

Instead of fixing the math, the theme has been expanded for this W axis.
The default color is set to the mathematically correct yellow.

Co-authored-by: Sybren A. Stüvel <sybren@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/143211
This commit is contained in:
Sybren A. Stüvel
2025-08-05 17:55:12 +02:00
parent 0f65acef25
commit 0fa67c3ea2
11 changed files with 24 additions and 21 deletions

View File

@@ -253,6 +253,7 @@ const bTheme U_theme_default = {
.xaxis = RGBA(0xff3352ff),
.yaxis = RGBA(0x8bdc00ff),
.zaxis = RGBA(0x2890ffff),
.waxis = RGBA(0xedba18ff),
.gizmo_hi = RGBA(0xffffffff),
.gizmo_primary = RGBA(0xf5f14dff),
.gizmo_secondary = RGBA(0x63ffffff),

View File

@@ -24,6 +24,7 @@
axis_x="#ff3352"
axis_y="#8bdc00"
axis_z="#2890ff"
axis_w="#b47aff"
gizmo_hi="#ffffff"
gizmo_primary="#f5f14d"
gizmo_secondary="#63ffff"

View File

@@ -1233,6 +1233,7 @@ class USERPREF_PT_theme_interface_gizmos(ThemePanel, CenterAlignMixIn, Panel):
col.prop(ui, "axis_x", text="Axis X")
col.prop(ui, "axis_y", text="Y")
col.prop(ui, "axis_z", text="Z")
col.prop(ui, "axis_w", text="W")
col = flow.column()
col.prop(ui, "gizmo_primary")

View File

@@ -27,7 +27,7 @@
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 51
#define BLENDER_FILE_SUBVERSION 52
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and cancel loading the file, showing a warning to

View File

@@ -359,6 +359,10 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme)
FROM_DEFAULT_V4_UCHAR(common.anim.preview_range);
}
if (!USER_VERSION_ATLEAST(500, 52)) {
FROM_DEFAULT_V4_UCHAR(tui.waxis);
}
/**
* Always bump subversion in BKE_blender_version.h when adding versioning
* code here, and wrap it inside a USER_VERSION_ATLEAST check.

View File

@@ -342,6 +342,8 @@ enum ThemeColorID {
TH_AXIS_Y,
TH_AXIS_Z,
TH_AXIS_W, /* W (quaternion and axis-angle rotations) */
TH_GIZMO_HI,
TH_GIZMO_PRIMARY,
TH_GIZMO_SECONDARY,

View File

@@ -1001,6 +1001,9 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
case TH_AXIS_Z:
cp = btheme->tui.zaxis;
break;
case TH_AXIS_W:
cp = btheme->tui.waxis;
break;
case TH_GIZMO_HI:
cp = btheme->tui.gizmo_hi;

View File

@@ -751,23 +751,7 @@ static void graph_refresh_fcurve_colors(const bContext *C)
break;
case 0: {
/* Special Case: "W" channel should be yellowish, so blend X and Y channel colors... */
float c1[3], c2[3];
float h1[3], h2[3];
float hresult[3];
/* - get colors (rgb) */
UI_GetThemeColor3fv(TH_AXIS_X, c1);
UI_GetThemeColor3fv(TH_AXIS_Y, c2);
/* - perform blending in HSV space (to keep brightness similar) */
rgb_to_hsv_v(c1, h1);
rgb_to_hsv_v(c2, h2);
interp_v3_v3v3(hresult, h1, h2, 0.5f);
/* - convert back to RGB for display */
hsv_to_rgb_v(hresult, col);
UI_GetThemeColor3fv(TH_AXIS_W, col);
break;
}

View File

@@ -172,14 +172,14 @@ typedef struct ThemeUI {
/* Transparent Grid */
unsigned char transparent_checker_primary[4], transparent_checker_secondary[4];
unsigned char transparent_checker_size;
char _pad1[1];
char _pad1[5];
float icon_alpha;
float icon_saturation;
unsigned char widget_text_cursor[4];
/* Axis Colors */
unsigned char xaxis[4], yaxis[4], zaxis[4];
unsigned char xaxis[4], yaxis[4], zaxis[4], waxis[4];
/* Gizmo Colors. */
unsigned char gizmo_hi[4];

View File

@@ -2555,7 +2555,8 @@ static void rna_def_fcurve(BlenderRNA *brna)
"AUTO_YRGB",
0,
"Auto WXYZ to YRGB",
"Use axis colors for XYZ parts of transform, and yellow for the 'W' channel"},
"Use WXYZ axis colors for quaternion/axis-angle rotations, XYZ axis colors for other "
"transform and color properties, and auto-rainbow for the rest"},
{FCURVE_COLOR_CUSTOM,
"CUSTOM",
0,

View File

@@ -2045,6 +2045,12 @@ static void rna_def_userdef_theme_ui(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Z Axis", "");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
prop = RNA_def_property(srna, "axis_w", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_float_sdna(prop, nullptr, "waxis");
RNA_def_property_array(prop, 3);
RNA_def_property_ui_text(prop, "W Axis", "W-axis for quaternion and axis-angle rotations");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
/* Generic gizmo colors. */
prop = RNA_def_property(srna, "gizmo_hi", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_float_sdna(prop, nullptr, "gizmo_hi");