[Bf-blender-cvs] [370d6e50252] master: Geometry: add Attributes panel for PointCloud and Hair

Brecht Van Lommel noreply at git.blender.org
Wed Sep 9 17:01:32 CEST 2020


Commit: 370d6e50252b979433f27959070315911cc340e5
Author: Brecht Van Lommel
Date:   Wed Aug 19 18:12:52 2020 +0200
Branches: master
https://developer.blender.org/rB370d6e50252b979433f27959070315911cc340e5

Geometry: add Attributes panel for PointCloud and Hair

There is a list of attributes, along with operators to add and remove
attributes. For adding, there are a few standard attributes that can be
added quickly, as well as a popup to create a custom attribute.

Ref T76659

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

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

M	release/scripts/startup/bl_ui/properties_data_hair.py
M	release/scripts/startup/bl_ui/properties_data_pointcloud.py
M	source/blender/blenkernel/BKE_attribute.h
M	source/blender/blenkernel/intern/attribute.c
M	source/blender/editors/CMakeLists.txt
A	source/blender/editors/geometry/CMakeLists.txt
A	source/blender/editors/geometry/geometry_attributes.c
A	source/blender/editors/geometry/geometry_intern.h
A	source/blender/editors/geometry/geometry_ops.c
A	source/blender/editors/include/ED_geometry.h
M	source/blender/editors/space_api/CMakeLists.txt
M	source/blender/editors/space_api/spacetypes.c
M	source/blender/makesrna/RNA_enum_types.h
M	source/blender/makesrna/intern/rna_attribute.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_hair.py b/release/scripts/startup/bl_ui/properties_data_hair.py
index 6017765b83d..58491f16c6e 100644
--- a/release/scripts/startup/bl_ui/properties_data_hair.py
+++ b/release/scripts/startup/bl_ui/properties_data_hair.py
@@ -18,7 +18,7 @@
 
 # <pep8 compliant>
 import bpy
-from bpy.types import Panel, UIList
+from bpy.types import Menu, Panel, UIList
 from rna_prop_ui import PropertyPanel
 
 
@@ -51,14 +51,68 @@ class DATA_PT_context_hair(DataButtonsPanel, Panel):
             layout.template_ID(space, "pin_id")
 
 
-class DATA_PT_hair(DataButtonsPanel, Panel):
-    bl_label = "Hair"
-    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
+class HAIR_MT_add_attribute(Menu):
+    bl_label = "Add Attribute"
+
+    @staticmethod
+    def add_standard_attribute(layout, hair, name, data_type, domain):
+        exists = hair.attributes.get(name) != None
+
+        col = layout.column()
+        col.enabled = not exists
+        col.operator_context = 'EXEC_DEFAULT'
+
+        props = col.operator("geometry.attribute_add", text=name)
+        props.name = name
+        props.data_type = data_type
+        props.domain = domain
 
     def draw(self, context):
         layout = self.layout
         hair = context.hair
-        pass
+
+        self.add_standard_attribute(layout, hair, 'Radius', 'FLOAT', 'POINT')
+        self.add_standard_attribute(layout, hair, 'Color', 'FLOAT_COLOR', 'POINT')
+
+        layout.separator()
+
+        layout.operator_context = 'INVOKE_DEFAULT'
+        layout.operator("geometry.attribute_add", text="Custom...")
+
+
+class HAIR_UL_attributes(UIList):
+    def draw_item(self, context, layout, data, attribute, icon, active_data, active_propname, index):
+        data_type = attribute.bl_rna.properties['data_type'].enum_items[attribute.data_type]
+        domain = attribute.bl_rna.properties['domain'].enum_items[attribute.domain]
+
+        split = layout.split(factor=0.5)
+        row = split.row()
+        row.prop(attribute, "name", text="", emboss=False)
+        sub = split.split()
+        sub.alignment = 'RIGHT'
+        sub.active = False
+        sub.label(text=domain.name)
+        sub.label(text=data_type.name)
+
+
+class DATA_PT_hair_attributes(DataButtonsPanel, Panel):
+    bl_label = "Attributes"
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
+
+    def draw(self, context):
+        hair = context.hair
+
+        layout = self.layout
+        row = layout.row()
+
+        col = row.column()
+        col.template_list("HAIR_UL_attributes", "attributes", hair, "attributes", hair.attributes, "active_index", rows=3)
+
+        col = row.column(align=True)
+        col.menu("HAIR_MT_add_attribute", icon='ADD', text="")
+        col.operator("geometry.attribute_remove", icon='REMOVE', text="")
+
+
 
 class DATA_PT_custom_props_hair(DataButtonsPanel, PropertyPanel, Panel):
     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
@@ -68,8 +122,10 @@ class DATA_PT_custom_props_hair(DataButtonsPanel, PropertyPanel, Panel):
 
 classes = (
     DATA_PT_context_hair,
-    DATA_PT_hair,
+    DATA_PT_hair_attributes,
     DATA_PT_custom_props_hair,
+    HAIR_MT_add_attribute,
+    HAIR_UL_attributes,
 )
 
 if __name__ == "__main__":  # only for live edit.
diff --git a/release/scripts/startup/bl_ui/properties_data_pointcloud.py b/release/scripts/startup/bl_ui/properties_data_pointcloud.py
index 10ebdea3155..d7ff7389fc3 100644
--- a/release/scripts/startup/bl_ui/properties_data_pointcloud.py
+++ b/release/scripts/startup/bl_ui/properties_data_pointcloud.py
@@ -18,7 +18,7 @@
 
 # <pep8 compliant>
 import bpy
-from bpy.types import Panel, UIList
+from bpy.types import Menu, Panel, UIList
 from rna_prop_ui import PropertyPanel
 
 
@@ -51,14 +51,67 @@ class DATA_PT_context_pointcloud(DataButtonsPanel, Panel):
             layout.template_ID(space, "pin_id")
 
 
-class DATA_PT_pointcloud(DataButtonsPanel, Panel):
-    bl_label = "Point Cloud"
-    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
+class POINTCLOUD_MT_add_attribute(Menu):
+    bl_label = "Add Attribute"
+
+    @staticmethod
+    def add_standard_attribute(layout, pointcloud, name, data_type, domain):
+        exists = pointcloud.attributes.get(name) != None
+
+        col = layout.column()
+        col.enabled = not exists
+        col.operator_context = 'EXEC_DEFAULT'
+
+        props = col.operator("geometry.attribute_add", text=name)
+        props.name = name
+        props.data_type = data_type
+        props.domain = domain
 
     def draw(self, context):
         layout = self.layout
         pointcloud = context.pointcloud
-        pass
+
+        self.add_standard_attribute(layout, pointcloud, 'Radius', 'FLOAT', 'POINT')
+        self.add_standard_attribute(layout, pointcloud, 'Color', 'FLOAT_COLOR', 'POINT')
+        self.add_standard_attribute(layout, pointcloud, 'Particle ID', 'INT', 'POINT')
+        self.add_standard_attribute(layout, pointcloud, 'Velocity', 'FLOAT_VECTOR', 'POINT')
+
+        layout.separator()
+
+        layout.operator_context = 'INVOKE_DEFAULT'
+        layout.operator("geometry.attribute_add", text="Custom...")
+
+
+class POINTCLOUD_UL_attributes(UIList):
+    def draw_item(self, context, layout, data, attribute, icon, active_data, active_propname, index):
+        data_type = attribute.bl_rna.properties['data_type'].enum_items[attribute.data_type]
+
+        split = layout.split(factor=0.75)
+        split.prop(attribute, "name", text="", emboss=False)
+        sub = split.row()
+        sub.alignment = 'RIGHT'
+        sub.active = False
+        sub.label(text=data_type.name)
+
+
+class DATA_PT_pointcloud_attributes(DataButtonsPanel, Panel):
+    bl_label = "Attributes"
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
+
+    def draw(self, context):
+        pointcloud = context.pointcloud
+
+        layout = self.layout
+        row = layout.row()
+
+        col = row.column()
+        col.template_list("POINTCLOUD_UL_attributes", "attributes", pointcloud, "attributes", pointcloud.attributes, "active_index", rows=3)
+
+        col = row.column(align=True)
+        col.menu("POINTCLOUD_MT_add_attribute", icon='ADD', text="")
+        col.operator("geometry.attribute_remove", icon='REMOVE', text="")
+
+
 
 class DATA_PT_custom_props_pointcloud(DataButtonsPanel, PropertyPanel, Panel):
     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
@@ -68,8 +121,10 @@ class DATA_PT_custom_props_pointcloud(DataButtonsPanel, PropertyPanel, Panel):
 
 classes = (
     DATA_PT_context_pointcloud,
-    DATA_PT_pointcloud,
+    DATA_PT_pointcloud_attributes,
     DATA_PT_custom_props_pointcloud,
+    POINTCLOUD_MT_add_attribute,
+    POINTCLOUD_UL_attributes,
 )
 
 if __name__ == "__main__":  # only for live edit.
diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h
index 6144d36effd..aab962d42a6 100644
--- a/source/blender/blenkernel/BKE_attribute.h
+++ b/source/blender/blenkernel/BKE_attribute.h
@@ -53,12 +53,14 @@ typedef enum AttributeDomain {
 
 /* Attributes */
 
+bool BKE_id_attributes_supported(struct ID *id);
+
 struct CustomDataLayer *BKE_id_attribute_new(struct ID *id,
                                              const char *name,
                                              const int type,
                                              const AttributeDomain domain,
                                              struct ReportList *reports);
-void BKE_id_attribute_remove(struct ID *id,
+bool BKE_id_attribute_remove(struct ID *id,
                              struct CustomDataLayer *layer,
                              struct ReportList *reports);
 
diff --git a/source/blender/blenkernel/intern/attribute.c b/source/blender/blenkernel/intern/attribute.c
index 8a67e4581f0..9ad73133f9e 100644
--- a/source/blender/blenkernel/intern/attribute.c
+++ b/source/blender/blenkernel/intern/attribute.c
@@ -101,6 +101,18 @@ static CustomData *attribute_customdata_find(ID *id, CustomDataLayer *layer)
   return NULL;
 }
 
+bool BKE_id_attributes_supported(struct ID *id)
+{
+  DomainInfo info[ATTR_DOMAIN_NUM];
+  get_domains(id, info);
+  for (AttributeDomain domain = 0; domain < ATTR_DOMAIN_NUM; domain++) {
+    if (info[domain].customdata) {
+      return true;
+    }
+  }
+  return false;
+}
+
 bool BKE_id_attribute_rename(ID *id,
                              CustomDataLayer *layer,
                              const char *new_name,
@@ -139,7 +151,7 @@ CustomDataLayer *BKE_id_attribute_new(
   return (index == -1) ? NULL : &(customdata->layers[index]);
 }
 
-void BKE_id_attribute_remove(ID *id, CustomDataLayer *layer, ReportList *reports)
+bool BKE_id_attribute_remove(ID *id, CustomDataLayer *layer, ReportList *reports)
 {
   CustomData *customdata = attribute_customdata_find(id, layer);
   const int index = (customdata) ?
@@ -148,16 +160,17 @@ void BKE_id_attribute_remove(ID *id, CustomDataLayer *layer, ReportList *reports
 
   if (index == -1) {
     BKE_report(reports, RPT_ERROR, "Attribute is not part of this geometry");
-    return;
+    return false;
   }
 
   if (BKE_id_attribute_required(id, layer)) {
     BKE_report(reports, RPT_ERROR, "Attribute is required and can't be removed");
-    return;
+    return false;
   }
 
   const int length = BKE_id_attribute_data_length(id, layer);
   CustomData_free_layer(customdata, layer->type, length, index);
+  return true;
 }
 
 int BKE_id_attributes_length(ID *id, const CustomDataMask mask)
diff --git a/source/blender/editors/CMakeLists.txt b/source/blender/editors/CMakeLists.txt
index 7910cf47a33..1f5dc73f732 100644
--- a/source/blender/editors/CMakeLists.txt
+++ b/source/blender/editors/CMakeLists.txt
@@ -23,11 +23,12 @@ if(WITH_BLENDER)
   add_subdirectory(animation)
   add_subdirectory(armature)
   add_subdirectory(curve)
+  add_subdirectory(geometry)
+  add_subdirectory(gizmo_library)
   add_subdirectory(gpencil)
   add_subdirectory(interface)
   add_subdirectory(io)
   add_subdirectory(lattice)
-  add_subdirectory(gizmo_library)
   add_s

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list