[Bf-blender-cvs] [3618948df85] master: Geometry Nodes: expose builtin crease attribute

Jacques Lucke noreply at git.blender.org
Mon Mar 15 15:39:10 CET 2021


Commit: 3618948df85f18f6ab5d33e10139520b4c3dd092
Author: Jacques Lucke
Date:   Mon Mar 15 15:32:30 2021 +0100
Branches: master
https://developer.blender.org/rB3618948df85f18f6ab5d33e10139520b4c3dd092

Geometry Nodes: expose builtin crease attribute

This exposes the `crease` attribute, that is used by the Subdivide Smooth node.
It is also the first attribute on the edge domain. Domain interpolations for the
edge domain have not been implemented yet.

Ref T86397.

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

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

M	source/blender/blenkernel/intern/geometry_component_mesh.cc
M	source/blender/blenkernel/intern/geometry_set_instances.cc
M	source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc

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

diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc
index d0c1929816f..b376a9dd083 100644
--- a/source/blender/blenkernel/intern/geometry_component_mesh.cc
+++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc
@@ -604,6 +604,28 @@ static WriteAttributePtr make_vertex_color_write_attribute(void *data, const int
       ATTR_DOMAIN_CORNER, MutableSpan((MLoopCol *)data, domain_size));
 }
 
+static float get_crease(const MEdge &edge)
+{
+  return edge.crease / 255.0f;
+}
+
+static void set_crease(MEdge &edge, const float &value)
+{
+  edge.crease = round_fl_to_uchar_clamp(value * 255.0f);
+}
+
+static ReadAttributePtr make_crease_read_attribute(const void *data, const int domain_size)
+{
+  return std::make_unique<DerivedArrayReadAttribute<MEdge, float, get_crease>>(
+      ATTR_DOMAIN_EDGE, Span((const MEdge *)data, domain_size));
+}
+
+static WriteAttributePtr make_crease_write_attribute(void *data, const int domain_size)
+{
+  return std::make_unique<DerivedArrayWriteAttribute<MEdge, float, get_crease, set_crease>>(
+      ATTR_DOMAIN_EDGE, MutableSpan((MEdge *)data, domain_size));
+}
+
 class VertexWeightWriteAttribute final : public WriteAttribute {
  private:
   MDeformVert *dverts_;
@@ -903,6 +925,18 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh()
                                                      make_shade_smooth_write_attribute,
                                                      nullptr);
 
+  static BuiltinCustomDataLayerProvider crease("crease",
+                                               ATTR_DOMAIN_EDGE,
+                                               CD_PROP_FLOAT,
+                                               CD_MEDGE,
+                                               BuiltinAttributeProvider::NonCreatable,
+                                               BuiltinAttributeProvider::Writable,
+                                               BuiltinAttributeProvider::NonDeletable,
+                                               edge_access,
+                                               make_crease_read_attribute,
+                                               make_crease_write_attribute,
+                                               nullptr);
+
   static NamedLegacyCustomDataProvider uvs(ATTR_DOMAIN_CORNER,
                                            CD_PROP_FLOAT2,
                                            CD_MLOOPUV,
@@ -923,7 +957,7 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh()
   static CustomDataAttributeProvider edge_custom_data(ATTR_DOMAIN_EDGE, edge_access);
   static CustomDataAttributeProvider polygon_custom_data(ATTR_DOMAIN_POLYGON, polygon_access);
 
-  return ComponentAttributeProviders({&position, &material_index, &shade_smooth, &normal},
+  return ComponentAttributeProviders({&position, &material_index, &shade_smooth, &normal, &crease},
                                      {&uvs,
                                       &vertex_colors,
                                       &corner_custom_data,
diff --git a/source/blender/blenkernel/intern/geometry_set_instances.cc b/source/blender/blenkernel/intern/geometry_set_instances.cc
index fc9d793c119..ce54ec7911f 100644
--- a/source/blender/blenkernel/intern/geometry_set_instances.cc
+++ b/source/blender/blenkernel/intern/geometry_set_instances.cc
@@ -381,7 +381,7 @@ static void join_instance_groups_mesh(Span<GeometryInstanceGroup> set_groups,
   gather_attribute_info(attributes,
                         component_types,
                         set_groups,
-                        {"position", "material_index", "normal", "shade_smooth"});
+                        {"position", "material_index", "normal", "shade_smooth", "crease"});
   join_attributes(
       set_groups, component_types, attributes, static_cast<GeometryComponent &>(dst_component));
 }
diff --git a/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc b/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
index 54b0c07a0a0..52512769a47 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
@@ -224,7 +224,7 @@ static void join_components(Span<const MeshComponent *> src_components, Geometry
   /* Don't copy attributes that are stored directly in the mesh data structs. */
   join_attributes(to_base_components(src_components),
                   dst_component,
-                  {"position", "material_index", "normal", "shade_smooth"});
+                  {"position", "material_index", "normal", "shade_smooth", "crease"});
 }
 
 static void join_components(Span<const PointCloudComponent *> src_components, GeometrySet &result)



More information about the Bf-blender-cvs mailing list