[Bf-blender-cvs] [5dced2a0636] master: Geometry Nodes: expose float2 attribute in rna

Jacques Lucke noreply at git.blender.org
Sat Feb 20 11:33:59 CET 2021


Commit: 5dced2a0636a7f3db73be09139cf8abd952612e7
Author: Jacques Lucke
Date:   Sat Feb 20 11:33:43 2021 +0100
Branches: master
https://developer.blender.org/rB5dced2a0636a7f3db73be09139cf8abd952612e7

Geometry Nodes: expose float2 attribute in rna

This also fixes the issue reported in T85651.

Differential Revision: https://developer.blender.org/D10477

===================================================================

M	intern/cycles/blender/blender_mesh.cpp
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_attribute.c

===================================================================

diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index 182aefa82ae..c7b49354d53 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -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;
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index eaa2675573c..eecac8ca19e 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -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;
diff --git a/source/blender/makesrna/intern/rna_attribute.c b/source/blender/makesrna/intern/rna_attribute.c
index 28c65992236..b99b6891d3d 100644
--- a/source/blender/makesrna/intern/rna_attribute.c
+++ b/source/blender/makesrna/intern/rna_attribute.c
@@ -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 */



More information about the Bf-blender-cvs mailing list