Fix: geometry nodes modifier property not working after changing it in Python
This affected only vector and color inputs. The issue was that those were expected to be stored as float-array properties. However, when setting them from python using `modifier["Input_X"] = [1, 2, 3]` the array type becomes either `int` or `double`, but not `float`. A workaround was to use `modifier["Input_X"][:] = [1, 2, 3]` as this changes the property inplace. Now `int` and `double` arrays are also understood by the modifier. Pull Request: https://projects.blender.org/blender/blender/pulls/109203
This commit is contained in:
@@ -530,9 +530,11 @@ static bool id_property_type_matches_socket(const bNodeSocket &socket, const IDP
|
||||
case SOCK_INT:
|
||||
return property.type == IDP_INT;
|
||||
case SOCK_VECTOR:
|
||||
return property.type == IDP_ARRAY && property.subtype == IDP_FLOAT && property.len == 3;
|
||||
return property.type == IDP_ARRAY &&
|
||||
ELEM(property.subtype, IDP_INT, IDP_FLOAT, IDP_DOUBLE) && property.len == 3;
|
||||
case SOCK_RGBA:
|
||||
return property.type == IDP_ARRAY && property.subtype == IDP_FLOAT && property.len == 4;
|
||||
return property.type == IDP_ARRAY &&
|
||||
ELEM(property.subtype, IDP_INT, IDP_FLOAT, IDP_DOUBLE) && property.len == 4;
|
||||
case SOCK_BOOLEAN:
|
||||
return property.type == IDP_BOOLEAN;
|
||||
case SOCK_STRING:
|
||||
@@ -570,14 +572,35 @@ static void init_socket_cpp_value_from_property(const IDProperty &property,
|
||||
break;
|
||||
}
|
||||
case SOCK_VECTOR: {
|
||||
const void *property_array = IDP_Array(&property);
|
||||
float3 value;
|
||||
copy_v3_v3(value, (const float *)IDP_Array(&property));
|
||||
if (property.subtype == IDP_FLOAT) {
|
||||
value = float3(static_cast<const float *>(property_array));
|
||||
}
|
||||
else if (property.subtype == IDP_INT) {
|
||||
value = float3(int3(static_cast<const int *>(property_array)));
|
||||
}
|
||||
else {
|
||||
BLI_assert(property.subtype == IDP_DOUBLE);
|
||||
value = float3(double3(static_cast<const double *>(property_array)));
|
||||
}
|
||||
new (r_value) fn::ValueOrField<float3>(value);
|
||||
break;
|
||||
}
|
||||
case SOCK_RGBA: {
|
||||
ColorGeometry4f value;
|
||||
copy_v4_v4((float *)value, (const float *)IDP_Array(&property));
|
||||
const void *property_array = IDP_Array(&property);
|
||||
float4 vec;
|
||||
if (property.subtype == IDP_FLOAT) {
|
||||
vec = float4(static_cast<const float *>(property_array));
|
||||
}
|
||||
else if (property.subtype == IDP_INT) {
|
||||
vec = float4(int4(static_cast<const int *>(property_array)));
|
||||
}
|
||||
else {
|
||||
BLI_assert(property.subtype == IDP_DOUBLE);
|
||||
vec = float4(double4(static_cast<const double *>(property_array)));
|
||||
}
|
||||
ColorGeometry4f value(vec);
|
||||
new (r_value) fn::ValueOrField<ColorGeometry4f>(value);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user