[Bf-blender-cvs] [76f386a37a9] master: Geometry Nodes: Fields transfer attribute node

Hans Goudey noreply at git.blender.org
Fri Oct 15 21:10:09 CEST 2021


Commit: 76f386a37a9cf14ac729be048230f81a0a397fc8
Author: Hans Goudey
Date:   Fri Oct 15 14:08:52 2021 -0500
Branches: master
https://developer.blender.org/rB76f386a37a9cf14ac729be048230f81a0a397fc8

Geometry Nodes: Fields transfer attribute node

This commit adds an updated version of the old attribute transfer node.
It works like a function node, so it works in the context of a
geometry, with a simple data output.

The "Nearest" mode finds the nearest element of the specified domain on
the target geometry and copies the value directly from the target input.

The "Nearest Face Interpolated" finds the nearest point on anywhere on
the surface of the target mesh and linearly interpolates the value on
the target from the face's corners.

The node also has a new "Index" mode, which can pick data from specific
indices on the target geometry. The implicit default is to do a simple
copy from the target geometry, but any indices could be used. It is also
possible to use a single value for the index to to retrieve a single
value from an attribute at a certain index.

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

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

M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenkernel/BKE_mesh_sample.hh
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/mesh_sample.cc
M	source/blender/blenkernel/intern/node.cc
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/NOD_geometry.h
M	source/blender/nodes/NOD_static_types.h
M	source/blender/nodes/geometry/nodes/legacy/node_geo_attribute_transfer.cc
M	source/blender/nodes/geometry/nodes/legacy/node_geo_point_distribute.cc
M	source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc
A	source/blender/nodes/geometry/nodes/node_geo_transfer_attribute.cc

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

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index 26d586ac859..2d03fbddd48 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -653,6 +653,7 @@ geometry_node_categories = [
 
         NodeItem("GeometryNodeCaptureAttribute"),
         NodeItem("GeometryNodeAttributeStatistic"),
+        NodeItem("GeometryNodeAttributeTransfer"),
     ]),
     GeometryNodeCategory("GEO_COLOR", "Color", items=[
         NodeItem("ShaderNodeMixRGB"),
diff --git a/source/blender/blenkernel/BKE_mesh_sample.hh b/source/blender/blenkernel/BKE_mesh_sample.hh
index 2fbf7372a09..4845876751b 100644
--- a/source/blender/blenkernel/BKE_mesh_sample.hh
+++ b/source/blender/blenkernel/BKE_mesh_sample.hh
@@ -44,17 +44,20 @@ void sample_point_attribute(const Mesh &mesh,
                             Span<int> looptri_indices,
                             Span<float3> bary_coords,
                             const GVArray &data_in,
+                            const IndexMask mask,
                             GMutableSpan data_out);
 
 void sample_corner_attribute(const Mesh &mesh,
                              Span<int> looptri_indices,
                              Span<float3> bary_coords,
                              const GVArray &data_in,
+                             const IndexMask mask,
                              GMutableSpan data_out);
 
 void sample_face_attribute(const Mesh &mesh,
                            Span<int> looptri_indices,
                            const GVArray &data_in,
+                           const IndexMask mask,
                            GMutableSpan data_out);
 
 enum class eAttributeMapMode {
@@ -83,6 +86,12 @@ class MeshAttributeInterpolator {
                             const Span<float3> positions,
                             const Span<int> looptri_indices);
 
+  void sample_data(const GVArray &src,
+                   const AttributeDomain domain,
+                   const eAttributeMapMode mode,
+                   const IndexMask mask,
+                   const GMutableSpan dst);
+
   void sample_attribute(const ReadAttributeLookup &src_attribute,
                         OutputAttribute &dst_attribute,
                         eAttributeMapMode mode);
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index f352fa37eab..a68edfca2d3 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -897,7 +897,7 @@ bool BKE_node_is_connected_to_output(struct bNodeTree *ntree, struct bNode *node
 /* ************** COMMON NODES *************** */
 
 #define NODE_UNDEFINED -2 /* node type is not registered */
-#define NODE_CUSTOM -1 /* for dynamically registered custom types */
+#define NODE_CUSTOM -1    /* for dynamically registered custom types */
 #define NODE_GROUP 2
 // #define NODE_FORLOOP 3       /* deprecated */
 // #define NODE_WHILELOOP   4   /* deprecated */
@@ -1537,6 +1537,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_ROTATE_INSTANCES 1122
 #define GEO_NODE_SPLIT_EDGES 1123
 #define GEO_NODE_MESH_TO_CURVE 1124
+#define GEO_NODE_TRANSFER_ATTRIBUTE 1125
 
 /** \} */
 
diff --git a/source/blender/blenkernel/intern/mesh_sample.cc b/source/blender/blenkernel/intern/mesh_sample.cc
index 5388f6e530e..9842b3aff31 100644
--- a/source/blender/blenkernel/intern/mesh_sample.cc
+++ b/source/blender/blenkernel/intern/mesh_sample.cc
@@ -29,12 +29,13 @@ BLI_NOINLINE static void sample_point_attribute(const Mesh &mesh,
                                                 const Span<int> looptri_indices,
                                                 const Span<float3> bary_coords,
                                                 const VArray<T> &data_in,
+                                                const IndexMask mask,
                                                 const MutableSpan<T> data_out)
 {
   const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
                                 BKE_mesh_runtime_looptri_len(&mesh)};
 
-  for (const int i : bary_coords.index_range()) {
+  for (const int i : mask) {
     const int looptri_index = looptri_indices[i];
     const MLoopTri &looptri = looptris[looptri_index];
     const float3 &bary_coord = bary_coords[i];
@@ -56,6 +57,7 @@ void sample_point_attribute(const Mesh &mesh,
                             const Span<int> looptri_indices,
                             const Span<float3> bary_coords,
                             const GVArray &data_in,
+                            const IndexMask mask,
                             const GMutableSpan data_out)
 {
   BLI_assert(data_out.size() == looptri_indices.size());
@@ -67,7 +69,7 @@ void sample_point_attribute(const Mesh &mesh,
   attribute_math::convert_to_static_type(type, [&](auto dummy) {
     using T = decltype(dummy);
     sample_point_attribute<T>(
-        mesh, looptri_indices, bary_coords, data_in.typed<T>(), data_out.typed<T>());
+        mesh, looptri_indices, bary_coords, data_in.typed<T>(), mask, data_out.typed<T>());
   });
 }
 
@@ -76,12 +78,13 @@ BLI_NOINLINE static void sample_corner_attribute(const Mesh &mesh,
                                                  const Span<int> looptri_indices,
                                                  const Span<float3> bary_coords,
                                                  const VArray<T> &data_in,
+                                                 const IndexMask mask,
                                                  const MutableSpan<T> data_out)
 {
   const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
                                 BKE_mesh_runtime_looptri_len(&mesh)};
 
-  for (const int i : bary_coords.index_range()) {
+  for (const int i : mask) {
     const int looptri_index = looptri_indices[i];
     const MLoopTri &looptri = looptris[looptri_index];
     const float3 &bary_coord = bary_coords[i];
@@ -103,6 +106,7 @@ void sample_corner_attribute(const Mesh &mesh,
                              const Span<int> looptri_indices,
                              const Span<float3> bary_coords,
                              const GVArray &data_in,
+                             const IndexMask mask,
                              const GMutableSpan data_out)
 {
   BLI_assert(data_out.size() == looptri_indices.size());
@@ -114,7 +118,7 @@ void sample_corner_attribute(const Mesh &mesh,
   attribute_math::convert_to_static_type(type, [&](auto dummy) {
     using T = decltype(dummy);
     sample_corner_attribute<T>(
-        mesh, looptri_indices, bary_coords, data_in.typed<T>(), data_out.typed<T>());
+        mesh, looptri_indices, bary_coords, data_in.typed<T>(), mask, data_out.typed<T>());
   });
 }
 
@@ -122,12 +126,13 @@ template<typename T>
 void sample_face_attribute(const Mesh &mesh,
                            const Span<int> looptri_indices,
                            const VArray<T> &data_in,
+                           const IndexMask mask,
                            const MutableSpan<T> data_out)
 {
   const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(&mesh),
                                 BKE_mesh_runtime_looptri_len(&mesh)};
 
-  for (const int i : data_out.index_range()) {
+  for (const int i : mask) {
     const int looptri_index = looptri_indices[i];
     const MLoopTri &looptri = looptris[looptri_index];
     const int poly_index = looptri.poly;
@@ -138,6 +143,7 @@ void sample_face_attribute(const Mesh &mesh,
 void sample_face_attribute(const Mesh &mesh,
                            const Span<int> looptri_indices,
                            const GVArray &data_in,
+                           const IndexMask mask,
                            const GMutableSpan data_out)
 {
   BLI_assert(data_out.size() == looptri_indices.size());
@@ -147,7 +153,7 @@ void sample_face_attribute(const Mesh &mesh,
   const CPPType &type = data_in.type();
   attribute_math::convert_to_static_type(type, [&](auto dummy) {
     using T = decltype(dummy);
-    sample_face_attribute<T>(mesh, looptri_indices, data_in.typed<T>(), data_out.typed<T>());
+    sample_face_attribute<T>(mesh, looptri_indices, data_in.typed<T>(), mask, data_out.typed<T>());
   });
 }
 
@@ -215,22 +221,19 @@ Span<float3> MeshAttributeInterpolator::ensure_nearest_weights()
   return nearest_weights_;
 }
 
-void MeshAttributeInterpolator::sample_attribute(const ReadAttributeLookup &src_attribute,
-                                                 OutputAttribute &dst_attribute,
-                                                 eAttributeMapMode mode)
+void MeshAttributeInterpolator::sample_data(const GVArray &src,
+                                            const AttributeDomain domain,
+                                            const eAttributeMapMode mode,
+                                            const IndexMask mask,
+                                            const GMutableSpan dst)
 {
-  if (!src_attribute || !dst_attribute) {
-    return;
-  }
-  const GVArray &src_varray = *src_attribute.varray;
-  GMutableSpan dst_span = dst_attribute.as_span();
-  if (src_varray.is_empty() || dst_span.is_empty()) {
+  if (src.is_empty() || dst.is_empty()) {
     return;
   }
 
   /* Compute barycentric coordinates only when they are needed. */
   Span<float3> weights;
-  if (ELEM(src_attribute.domain, ATTR_DOMAIN_POINT, ATTR_DOMAIN_CORNER)) {
+  if (ELEM(domain, ATTR_DOMAIN_POINT, ATTR_DOMAIN_CORNER)) {
     switch (mode) {
       case eAttributeMapMode::INTERPOLATED:
         weights = ensure_barycentric_coords();
@@ -242,17 +245,17 @@ void MeshAttributeInterpolator::sample_attribute(const ReadAttributeLookup &src_
   }
 
   /* Interpolate the source attributes on the surface. */
-  switch (src_attribute.domain) {
+  switch (domain) {
     case ATTR_DOMAIN_POINT: {
-      sample_point_attribute(*mesh_, looptri_indices_, weights, src_varray, dst_span);
+      sample_point_attribute(*mesh_, looptri_indices_, weights, src, mask, dst);
       break;
     }
     case ATTR_DOMAIN_FACE: {
-      sample_face_attribute(*mesh_, looptri_indices_, src_varray, d

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list