[Bf-blender-cvs] [0a6cf3ed0c6] master: Geometry Nodes: Fields version of the raycast node

Hans Goudey noreply at git.blender.org
Tue Oct 19 16:02:03 CEST 2021


Commit: 0a6cf3ed0c64a0e4e58ecd40a491d0e6c93532f2
Author: Hans Goudey
Date:   Tue Oct 19 09:01:39 2021 -0500
Branches: master
https://developer.blender.org/rB0a6cf3ed0c64a0e4e58ecd40a491d0e6c93532f2

Geometry Nodes: Fields version of the raycast node

This patch includes an updated version of the raycast node that uses
fields instead of attributes for inputs instead of outputs. This makes
the node's UI much clearer. It should be faster too, since the
evaluation system for fields provides multi-threading.

The source position replaces the input geometry (since this node is
evaluated in the context of a geometry like the other field nodes).

Thanks to @guitargeek for an initial version of this patch.

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

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

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_raycast.cc
A	source/blender/nodes/geometry/nodes/node_geo_raycast.cc
M	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 66c1ab0358a..05f2e900841 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -678,6 +678,7 @@ geometry_node_categories = [
         NodeItem("GeometryNodeLegacyDeleteGeometry", poll=geometry_nodes_legacy_poll),
         NodeItem("GeometryNodeLegacyRaycast", poll=geometry_nodes_legacy_poll),
 
+        NodeItem("GeometryNodeRaycast"),
         NodeItem("GeometryNodeProximity"),
         NodeItem("GeometryNodeBoundBox"),
         NodeItem("GeometryNodeConvexHull"),
diff --git a/source/blender/blenkernel/BKE_mesh_sample.hh b/source/blender/blenkernel/BKE_mesh_sample.hh
index 4845876751b..17f8e766724 100644
--- a/source/blender/blenkernel/BKE_mesh_sample.hh
+++ b/source/blender/blenkernel/BKE_mesh_sample.hh
@@ -75,6 +75,7 @@ enum class eAttributeMapMode {
 class MeshAttributeInterpolator {
  private:
   const Mesh *mesh_;
+  const IndexMask mask_;
   const Span<float3> positions_;
   const Span<int> looptri_indices_;
 
@@ -83,13 +84,13 @@ class MeshAttributeInterpolator {
 
  public:
   MeshAttributeInterpolator(const Mesh *mesh,
+                            const IndexMask mask,
                             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,
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 65e54be7db4..07ad317dd30 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1544,6 +1544,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_TRANSFER_ATTRIBUTE 1125
 #define GEO_NODE_SUBDIVISION_SURFACE 1126
 #define GEO_NODE_CURVE_ENDPOINT_SELECTION 1127
+#define GEO_NODE_RAYCAST 1128
 
 /** \} */
 
diff --git a/source/blender/blenkernel/intern/mesh_sample.cc b/source/blender/blenkernel/intern/mesh_sample.cc
index 9842b3aff31..2274d34f0f1 100644
--- a/source/blender/blenkernel/intern/mesh_sample.cc
+++ b/source/blender/blenkernel/intern/mesh_sample.cc
@@ -60,8 +60,6 @@ void sample_point_attribute(const Mesh &mesh,
                             const IndexMask mask,
                             const GMutableSpan data_out)
 {
-  BLI_assert(data_out.size() == looptri_indices.size());
-  BLI_assert(data_out.size() == bary_coords.size());
   BLI_assert(data_in.size() == mesh.totvert);
   BLI_assert(data_in.type() == data_out.type());
 
@@ -109,8 +107,6 @@ void sample_corner_attribute(const Mesh &mesh,
                              const IndexMask mask,
                              const GMutableSpan data_out)
 {
-  BLI_assert(data_out.size() == looptri_indices.size());
-  BLI_assert(data_out.size() == bary_coords.size());
   BLI_assert(data_in.size() == mesh.totloop);
   BLI_assert(data_in.type() == data_out.type());
 
@@ -146,7 +142,6 @@ void sample_face_attribute(const Mesh &mesh,
                            const IndexMask mask,
                            const GMutableSpan data_out)
 {
-  BLI_assert(data_out.size() == looptri_indices.size());
   BLI_assert(data_in.size() == mesh.totpoly);
   BLI_assert(data_in.type() == data_out.type());
 
@@ -158,9 +153,10 @@ void sample_face_attribute(const Mesh &mesh,
 }
 
 MeshAttributeInterpolator::MeshAttributeInterpolator(const Mesh *mesh,
+                                                     const IndexMask mask,
                                                      const Span<float3> positions,
                                                      const Span<int> looptri_indices)
-    : mesh_(mesh), positions_(positions), looptri_indices_(looptri_indices)
+    : mesh_(mesh), mask_(mask), positions_(positions), looptri_indices_(looptri_indices)
 {
   BLI_assert(positions.size() == looptri_indices.size());
 }
@@ -168,15 +164,15 @@ MeshAttributeInterpolator::MeshAttributeInterpolator(const Mesh *mesh,
 Span<float3> MeshAttributeInterpolator::ensure_barycentric_coords()
 {
   if (!bary_coords_.is_empty()) {
-    BLI_assert(bary_coords_.size() == positions_.size());
+    BLI_assert(bary_coords_.size() >= mask_.min_array_size());
     return bary_coords_;
   }
-  bary_coords_.reinitialize(positions_.size());
+  bary_coords_.reinitialize(mask_.min_array_size());
 
   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];
 
@@ -196,15 +192,15 @@ Span<float3> MeshAttributeInterpolator::ensure_barycentric_coords()
 Span<float3> MeshAttributeInterpolator::ensure_nearest_weights()
 {
   if (!nearest_weights_.is_empty()) {
-    BLI_assert(nearest_weights_.size() == positions_.size());
+    BLI_assert(nearest_weights_.size() >= mask_.min_array_size());
     return nearest_weights_;
   }
-  nearest_weights_.reinitialize(positions_.size());
+  nearest_weights_.reinitialize(mask_.min_array_size());
 
   const Span<MLoopTri> looptris{BKE_mesh_runtime_looptri_ensure(mesh_),
                                 BKE_mesh_runtime_looptri_len(mesh_)};
 
-  for (const int i : nearest_weights_.index_range()) {
+  for (const int i : mask_) {
     const int looptri_index = looptri_indices_[i];
     const MLoopTri &looptri = looptris[looptri_index];
 
@@ -224,7 +220,6 @@ Span<float3> MeshAttributeInterpolator::ensure_nearest_weights()
 void MeshAttributeInterpolator::sample_data(const GVArray &src,
                                             const AttributeDomain domain,
                                             const eAttributeMapMode mode,
-                                            const IndexMask mask,
                                             const GMutableSpan dst)
 {
   if (src.is_empty() || dst.is_empty()) {
@@ -247,15 +242,15 @@ void MeshAttributeInterpolator::sample_data(const GVArray &src,
   /* Interpolate the source attributes on the surface. */
   switch (domain) {
     case ATTR_DOMAIN_POINT: {
-      sample_point_attribute(*mesh_, looptri_indices_, weights, src, mask, dst);
+      sample_point_attribute(*mesh_, looptri_indices_, weights, src, mask_, dst);
       break;
     }
     case ATTR_DOMAIN_FACE: {
-      sample_face_attribute(*mesh_, looptri_indices_, src, mask, dst);
+      sample_face_attribute(*mesh_, looptri_indices_, src, mask_, dst);
       break;
     }
     case ATTR_DOMAIN_CORNER: {
-      sample_corner_attribute(*mesh_, looptri_indices_, weights, src, mask, dst);
+      sample_corner_attribute(*mesh_, looptri_indices_, weights, src, mask_, dst);
       break;
     }
     case ATTR_DOMAIN_EDGE: {
@@ -274,11 +269,7 @@ void MeshAttributeInterpolator::sample_attribute(const ReadAttributeLookup &src_
                                                  eAttributeMapMode mode)
 {
   if (src_attribute && dst_attribute) {
-    this->sample_data(*src_attribute.varray,
-                      src_attribute.domain,
-                      mode,
-                      IndexMask(dst_attribute->size()),
-                      dst_attribute.as_span());
+    this->sample_data(*src_attribute.varray, src_attribute.domain, mode, dst_attribute.as_span());
   }
 }
 
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index c5fb9030847..ce8f941b0b6 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -5751,6 +5751,7 @@ static void registerGeometryNodes()
   register_node_type_geo_legacy_curve_subdivide();
   register_node_type_geo_legacy_edge_split();
   register_node_type_geo_legacy_subdivision_surface();
+  register_node_type_geo_legacy_raycast();
 
   register_node_type_geo_align_rotation_to_vector();
   register_node_type_geo_attribute_capture();
@@ -5814,7 +5815,6 @@ static void registerGeometryNodes()
   register_node_type_geo_instance_on_points();
   register_node_type_geo_is_viewport();
   register_node_type_geo_join_geometry();
-  register_node_type_geo_material_replace();
   register_node_type_geo_material_selection();
   register_node_type_geo_mesh_primitive_circle();
   register_node_type_geo_mesh_primitive_cone();
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index dd749a9dc60..e6d02923dfe 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1526,9 +1526,13 @@ typedef struct NodeGeometryRaycast {
   /* GeometryNodeRaycastMapMode. */
   uint8_t mapping;
 
+  /* CustomDataType. */
+  int8_t data_type;
+
+  /* Deprecated input types in new Raycast node. Can be removed when legacy nodes are no longer
+   * supported. */
   uint8_t input_type_ray_direction;
   uint8_t input_type_ray_length;
-  char _pad[1];
 } NodeGeometryRaycast;
 
 typedef struct NodeGeometryCurveFill {
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 9571d889f6d..dfefc774b3d 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -10716,7 +10716,7 @@ static void def_geo_input_material(StructRNA *srna)
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
-static void def_geo_raycast(StructRNA *srna)
+static void def_geo_legacy_raycast(StructRNA *srna)
 {
   static EnumPropertyItem mapping_items[] = {
       {GEO_NODE_RAYCAST_INTERPOLATED,
@@ -10752,6 +10752,39 @@ static void def_geo_raycast(StructRNA *srna)
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
 }
 
+static void def_geo_raycast(StructRNA *srna)
+{
+  static EnumPropertyItem mapping_items[] = {
+      {GEO_NODE_RAYCAST_INTERPOLATED,
+       "INTERPOLATED",
+       0,
+       "Interpolated",
+       "Interpolate the attribute 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list