Nodes: Add Factor and Percentage subtypes for vector sockets

This patch adds support for the Factor and Percentage subtypes for
vector sockets. This is needed by the compositor, since it has some node
inputs that specify locations and sizes relative to image size, and
having factor and percentage subtypes for those improves the UX quite a
bit according to user feedback.

Pull Request: https://projects.blender.org/blender/blender/pulls/138805
This commit is contained in:
Omar Emara
2025-05-15 08:29:41 +02:00
committed by Omar Emara
parent 1a7b53ec0b
commit 79d37720de
6 changed files with 29 additions and 1 deletions

View File

@@ -147,6 +147,11 @@ static const bNodeSocketStaticTypeInfo node_socket_subtypes[] = {
{"NodeSocketRotation", "NodeTreeInterfaceSocketRotation", SOCK_ROTATION, PROP_NONE},
{"NodeSocketMatrix", "NodeTreeInterfaceSocketMatrix", SOCK_MATRIX, PROP_NONE},
{"NodeSocketVector", "NodeTreeInterfaceSocketVector", SOCK_VECTOR, PROP_NONE},
{"NodeSocketVectorFactor", "NodeTreeInterfaceSocketVectorFactor", SOCK_VECTOR, PROP_FACTOR},
{"NodeSocketVectorPercentage",
"NodeTreeInterfaceSocketVectorPercentage",
SOCK_VECTOR,
PROP_PERCENTAGE},
{"NodeSocketVectorTranslation",
"NodeTreeInterfaceSocketVectorTranslation",
SOCK_VECTOR,

View File

@@ -537,6 +537,10 @@ static StringRef get_legacy_socket_subtype_idname(StringRef idname, const void *
const bNodeSocketValueVector &vector_data = *static_cast<const bNodeSocketValueVector *>(
socket_data);
switch (vector_data.subtype) {
case PROP_FACTOR:
return "NodeSocketVectorFactor";
case PROP_PERCENTAGE:
return "NodeSocketVectorPercentage";
case PROP_TRANSLATION:
return "NodeSocketVectorTranslation";
case PROP_DIRECTION:
@@ -2547,6 +2551,10 @@ std::optional<StringRefNull> node_static_socket_type(const int type, const int s
return "NodeSocketMatrix";
case SOCK_VECTOR:
switch (PropertySubType(subtype)) {
case PROP_FACTOR:
return "NodeSocketVectorFactor";
case PROP_PERCENTAGE:
return "NodeSocketVectorPercentage";
case PROP_TRANSLATION:
return "NodeSocketVectorTranslation";
case PROP_DIRECTION:
@@ -2648,6 +2656,10 @@ std::optional<StringRefNull> node_static_socket_interface_type_new(const int typ
return "NodeTreeInterfaceSocketMatrix";
case SOCK_VECTOR:
switch (PropertySubType(subtype)) {
case PROP_FACTOR:
return "NodeTreeInterfaceSocketVectorFactor";
case PROP_PERCENTAGE:
return "NodeTreeInterfaceSocketVectorPercentage";
case PROP_TRANSLATION:
return "NodeTreeInterfaceSocketVectorTranslation";
case PROP_DIRECTION:

View File

@@ -1811,6 +1811,11 @@ static const bNodeSocketStaticTypeInfo node_socket_subtypes[] = {
{"NodeSocketRotation", "NodeTreeInterfaceSocketRotation", SOCK_ROTATION, PROP_NONE},
{"NodeSocketMatrix", "NodeTreeInterfaceSocketMatrix", SOCK_MATRIX, PROP_NONE},
{"NodeSocketVector", "NodeTreeInterfaceSocketVector", SOCK_VECTOR, PROP_NONE},
{"NodeSocketVectorFactor", "NodeTreeInterfaceSocketVectorFactor", SOCK_VECTOR, PROP_FACTOR},
{"NodeSocketVectorPercentage",
"NodeTreeInterfaceSocketVectorPercentage",
SOCK_VECTOR,
PROP_PERCENTAGE},
{"NodeSocketVectorTranslation",
"NodeTreeInterfaceSocketVectorTranslation",
SOCK_VECTOR,

View File

@@ -774,7 +774,9 @@ void rna_NodeTreeInterfaceSocketInt_default_value_range(
static const EnumPropertyItem *rna_NodeTreeInterfaceSocketVector_subtype_itemf(
bContext * /*C*/, PointerRNA * /*ptr*/, PropertyRNA * /*prop*/, bool *r_free)
{
return rna_subtype_filter_itemf({PROP_TRANSLATION,
return rna_subtype_filter_itemf({PROP_FACTOR,
PROP_PERCENTAGE,
PROP_TRANSLATION,
PROP_DIRECTION,
PROP_VELOCITY,
PROP_ACCELERATION,

View File

@@ -1217,6 +1217,8 @@ void register_standard_node_socket_types()
bke::node_register_socket_type(*make_socket_type_matrix());
bke::node_register_socket_type(*make_socket_type_vector(PROP_NONE));
bke::node_register_socket_type(*make_socket_type_vector(PROP_FACTOR));
bke::node_register_socket_type(*make_socket_type_vector(PROP_PERCENTAGE));
bke::node_register_socket_type(*make_socket_type_vector(PROP_TRANSLATION));
bke::node_register_socket_type(*make_socket_type_vector(PROP_DIRECTION));
bke::node_register_socket_type(*make_socket_type_vector(PROP_VELOCITY));

View File

@@ -48,6 +48,8 @@ subtype_idname = {
("BOOLEAN", "NONE"): "NodeSocketBool",
("ROTATION", "NONE"): "NodeSocketRotation",
("VECTOR", "NONE"): "NodeSocketVector",
("VECTOR", "FACTOR"): "NodeSocketVectorFactor",
("VECTOR", "PERCENTAGE"): "NodeSocketVectorPercentage",
("VECTOR", "TRANSLATION"): "NodeSocketVectorTranslation",
("VECTOR", "DIRECTION"): "NodeSocketVectorDirection",
("VECTOR", "VELOCITY"): "NodeSocketVectorVelocity",