Geometry Nodes: expose float2 attribute in rna

This also fixes the issue reported in T85651.

Differential Revision: https://developer.blender.org/D10477
This commit is contained in:
2021-02-20 11:33:43 +01:00
parent 173b6b792c
commit 5dced2a063
3 changed files with 53 additions and 0 deletions

View File

@@ -430,6 +430,16 @@ static void attr_create_generic(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh, bool
});
break;
}
case BL::Attribute::data_type_FLOAT2: {
BL::Float2Attribute b_float2_attribute{b_attribute};
Attribute *attr = attributes.add(name, TypeFloat2, element);
float2 *data = attr->data_float2();
fill_generic_attribute(b_mesh, data, element, [&](int i) {
BL::Array<float, 2> v = b_float2_attribute.data[i].vector();
return make_float2(v[0], v[1]);
});
break;
}
default:
/* Not supported. */
break;

View File

@@ -265,6 +265,7 @@ extern StructRNA RNA_FloatAttributeValue;
extern StructRNA RNA_FloatColorAttribute;
extern StructRNA RNA_FloatColorAttributeValue;
extern StructRNA RNA_FloatProperty;
extern StructRNA RNA_Float2Attribute;
extern StructRNA RNA_FloorConstraint;
extern StructRNA RNA_FluidDomainSettings;
extern StructRNA RNA_FluidEffectorSettings;

View File

@@ -45,6 +45,7 @@ const EnumPropertyItem rna_enum_attribute_type_items[] = {
{CD_MLOOPCOL, "BYTE_COLOR", 0, "Byte Color", "RGBA color with 8-bit precision"},
{CD_PROP_STRING, "STRING", 0, "String", "Text string"},
{CD_PROP_BOOL, "BOOLEAN", 0, "Boolean", "True or false"},
{CD_PROP_FLOAT2, "FLOAT2", 0, "2D Vector", "2D vector with floating-point values"},
{0, NULL, 0, NULL, NULL},
};
@@ -96,6 +97,8 @@ static StructRNA *srna_by_custom_data_layer_type(const CustomDataType type)
return &RNA_StringAttribute;
case CD_PROP_BOOL:
return &RNA_BoolAttribute;
case CD_PROP_FLOAT2:
return &RNA_Float2Attribute;
default:
return NULL;
}
@@ -200,6 +203,9 @@ static void rna_Attribute_data_begin(CollectionPropertyIterator *iter, PointerRN
case CD_PROP_BOOL:
struct_size = sizeof(MBoolProperty);
break;
case CD_PROP_FLOAT2:
struct_size = sizeof(float[2]);
break;
default:
struct_size = 0;
length = 0;
@@ -593,6 +599,41 @@ static void rna_def_attribute_bool(BlenderRNA *brna)
RNA_def_property_boolean_sdna(prop, NULL, "b", 0x01);
}
static void rna_def_attribute_float2(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
/* Float2 Attribute */
srna = RNA_def_struct(brna, "Float2Attribute", "Attribute");
RNA_def_struct_sdna(srna, "CustomDataLayer");
RNA_def_struct_ui_text(
srna, "Float2 Attribute", "2D vector geometry attribute, with floating-point precision");
prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "Float2AttributeValue");
RNA_def_property_collection_funcs(prop,
"rna_Attribute_data_begin",
"rna_iterator_array_next",
"rna_iterator_array_end",
"rna_iterator_array_get",
"rna_Attribute_data_length",
NULL,
NULL,
NULL);
/* Float2 Attribute Value */
srna = RNA_def_struct(brna, "Float2AttributeValue", NULL);
RNA_def_struct_sdna(srna, "vec2f");
RNA_def_struct_ui_text(srna, "Float2 Attribute Value", "2D Vector value in geometry attribute");
prop = RNA_def_property(srna, "vector", PROP_FLOAT, PROP_DIRECTION);
RNA_def_property_ui_text(prop, "Vector", "2D vector");
RNA_def_property_float_sdna(prop, NULL, "x");
RNA_def_property_array(prop, 2);
RNA_def_property_update(prop, 0, "rna_Attribute_update_data");
}
static void rna_def_attribute(BlenderRNA *brna)
{
PropertyRNA *prop;
@@ -632,6 +673,7 @@ static void rna_def_attribute(BlenderRNA *brna)
rna_def_attribute_int(brna);
rna_def_attribute_string(brna);
rna_def_attribute_bool(brna);
rna_def_attribute_float2(brna);
}
/* Mesh/PointCloud/Hair.attributes */