[Bf-blender-cvs] [4d39a0f8eb1] master: Geometry Nodes: Add Attribute Proximity Node

Victor-Louis De Gusseme noreply at git.blender.org
Fri Feb 5 15:28:55 CET 2021


Commit: 4d39a0f8eb1103aa58611fff7219f4bf3d70f70f
Author: Victor-Louis De Gusseme
Date:   Fri Feb 5 08:28:31 2021 -0600
Branches: master
https://developer.blender.org/rB4d39a0f8eb1103aa58611fff7219f4bf3d70f70f

Geometry Nodes: Add Attribute Proximity Node

This node calculates a distance from each point to the closest position
on a target geometry, similar to the vertex weight proximity modifier.
Mapping the output distance to a different range can be done with an
attribute math node after this node.

A drop-down changes whether to calculate distances from points,
edges, or faces. In points mode, the node also calculates distances
from point cloud points.

Design task and use cases: T84842

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

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

M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenkernel/BKE_bvhutils.h
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/bvhutils.c
M	source/blender/blenkernel/intern/node.cc
M	source/blender/editors/space_node/drawnode.c
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
A	source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc

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

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index f15eed64913..dac027d649e 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -487,6 +487,7 @@ geometry_node_categories = [
         NodeItem("GeometryNodeAttributeCompare"),
         NodeItem("GeometryNodeAttributeFill"),
         NodeItem("GeometryNodeAttributeMix"),
+        NodeItem("GeometryNodeAttributeProximity"),
         NodeItem("GeometryNodeAttributeColorRamp"),
         NodeItem("GeometryNodeAttributeVectorMath"),
         NodeItem("GeometryNodeAttributeSampleTexture"),
diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h
index 84a17136361..78908908343 100644
--- a/source/blender/blenkernel/BKE_bvhutils.h
+++ b/source/blender/blenkernel/BKE_bvhutils.h
@@ -38,6 +38,7 @@ struct BMEditMesh;
 struct MFace;
 struct MVert;
 struct Mesh;
+struct PointCloud;
 
 struct BVHCache;
 
@@ -249,6 +250,20 @@ float bvhtree_sphereray_tri_intersection(const BVHTreeRay *ray,
                                          const float v1[3],
                                          const float v2[3]);
 
+typedef struct BVHTreeFromPointCloud {
+  struct BVHTree *tree;
+
+  BVHTree_NearestPointCallback nearest_callback;
+
+  const float (*coords)[3];
+} BVHTreeFromPointCloud;
+
+BVHTree *BKE_bvhtree_from_pointcloud_get(struct BVHTreeFromPointCloud *data,
+                                         const struct PointCloud *pointcloud,
+                                         const int tree_type);
+
+void free_bvhtree_from_pointcloud(struct BVHTreeFromPointCloud *data);
+
 /**
  * BVHCache
  */
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 9ee21c6e825..0b8ef70de2a 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1368,6 +1368,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_POINTS_TO_VOLUME 1022
 #define GEO_NODE_COLLECTION_INFO 1023
 #define GEO_NODE_IS_VIEWPORT 1024
+#define GEO_NODE_ATTRIBUTE_PROXIMITY 1025
 
 /** \} */
 
diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c
index fd5cb33f02d..790fb128c7c 100644
--- a/source/blender/blenkernel/intern/bvhutils.c
+++ b/source/blender/blenkernel/intern/bvhutils.c
@@ -27,6 +27,7 @@
 
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
+#include "DNA_pointcloud_types.h"
 
 #include "BLI_linklist.h"
 #include "BLI_math.h"
@@ -1717,3 +1718,41 @@ void free_bvhtree_from_mesh(struct BVHTreeFromMesh *data)
 
   memset(data, 0, sizeof(*data));
 }
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Point Cloud BVH Building
+ * \{ */
+
+BVHTree *BKE_bvhtree_from_pointcloud_get(BVHTreeFromPointCloud *data,
+                                         const PointCloud *pointcloud,
+                                         const int tree_type)
+{
+  BVHTree *tree = BLI_bvhtree_new(pointcloud->totpoint, 0.0f, tree_type, 6);
+  if (!tree) {
+    return NULL;
+  }
+
+  for (int i = 0; i < pointcloud->totpoint; i++) {
+    BLI_bvhtree_insert(tree, i, pointcloud->co[i], 1);
+  }
+  BLI_assert(BLI_bvhtree_get_len(tree) == pointcloud->totpoint);
+  BLI_bvhtree_balance(tree);
+
+  data->coords = pointcloud->co;
+  data->tree = tree;
+  data->nearest_callback = NULL;
+
+  return tree;
+}
+
+void free_bvhtree_from_pointcloud(BVHTreeFromPointCloud *data)
+{
+  if (data->tree) {
+    BLI_bvhtree_free(data->tree);
+  }
+  memset(data, 0, sizeof(*data));
+}
+
+/** \} */
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index d78ba2a414e..44efbe64202 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -4753,6 +4753,7 @@ static void registerGeometryNodes()
 
   register_node_type_geo_attribute_compare();
   register_node_type_geo_attribute_fill();
+  register_node_type_geo_attribute_proximity();
   register_node_type_geo_attribute_vector_math();
   register_node_type_geo_triangulate();
   register_node_type_geo_edge_split();
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index d7edb1ecbed..b16ccb9bce4 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3381,6 +3381,13 @@ static void node_geometry_buts_collection_info(uiLayout *layout,
   uiItemR(layout, ptr, "transform_space", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
 }
 
+static void node_geometry_buts_attribute_proximity(uiLayout *layout,
+                                                   bContext *UNUSED(C),
+                                                   PointerRNA *ptr)
+{
+  uiItemR(layout, ptr, "target_geometry_element", DEFAULT_FLAGS, "", ICON_NONE);
+}
+
 static void node_geometry_set_butfunc(bNodeType *ntype)
 {
   switch (ntype->type) {
@@ -3444,6 +3451,9 @@ static void node_geometry_set_butfunc(bNodeType *ntype)
     case GEO_NODE_COLLECTION_INFO:
       ntype->draw_buttons = node_geometry_buts_collection_info;
       break;
+    case GEO_NODE_ATTRIBUTE_PROXIMITY:
+      ntype->draw_buttons = node_geometry_buts_attribute_proximity;
+      break;
   }
 }
 
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index a69af18ded2..edab43c752e 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1202,6 +1202,13 @@ typedef struct NodeGeometryCollectionInfo {
   char _pad[7];
 } NodeGeometryCollectionInfo;
 
+typedef struct NodeGeometryAttributeProximity {
+  /* GeometryNodeAttributeProximityTargetGeometryElement. */
+  uint8_t target_geometry_element;
+
+  char _pad[7];
+} NodeGeometryAttributeProximity;
+
 /* script node mode */
 #define NODE_SCRIPT_INTERNAL 0
 #define NODE_SCRIPT_EXTERNAL 1
@@ -1589,6 +1596,12 @@ typedef enum NodeShaderOutputTarget {
 
 /* Geometry Nodes */
 
+typedef enum GeometryNodeAttributeProximityTargetGeometryElement {
+  GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_POINTS = 0,
+  GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_EDGES = 1,
+  GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_FACES = 2,
+} GeometryNodeAttributeProximityTargetGeometryElement;
+
 /* Boolean Node */
 typedef enum GeometryNodeBooleanOperation {
   GEO_NODE_BOOLEAN_INTERSECT = 0,
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index ab6d4fa985c..7f66d5ff70f 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -8938,6 +8938,39 @@ static void def_geo_collection_info(StructRNA *srna)
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
+static void def_geo_attribute_proximity(StructRNA *srna)
+{
+  static const EnumPropertyItem target_geometry_element[] = {
+      {GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_POINTS,
+       "POINTS",
+       ICON_NONE,
+       "Points",
+       "Calculate proximity to the target's points (usually faster than the other two modes)"},
+      {GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_EDGES,
+       "EDGES",
+       ICON_NONE,
+       "Edges",
+       "Calculate proximity to the target's edges"},
+      {GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_FACES,
+       "FACES",
+       ICON_NONE,
+       "Faces",
+       "Calculate proximity to the target's faces"},
+      {0, NULL, 0, NULL, NULL},
+  };
+
+  PropertyRNA *prop;
+
+  RNA_def_struct_sdna_from(srna, "NodeGeometryAttributeProximity", "storage");
+
+  prop = RNA_def_property(srna, "target_geometry_element", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, target_geometry_element);
+  RNA_def_property_enum_default(prop, GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_FACES);
+  RNA_def_property_ui_text(
+      prop, "Target Geometry", "Element of the target geometry to calculate the distance from");
+  RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
+}
+
 /* -------------------------------------------------------------------------- */
 
 static void rna_def_shader_node(BlenderRNA *brna)
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index aedca4b34fb..76b19685456 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -147,6 +147,7 @@ set(SRC
   geometry/nodes/node_geo_attribute_math.cc
   geometry/nodes/node_geo_attribute_mix.cc
   geometry/nodes/node_geo_attribute_sample_texture.cc
+  geometry/nodes/node_geo_attribute_proximity.cc
   geometry/nodes/node_geo_attribute_randomize.cc
   geometry/nodes/node_geo_attribute_vector_math.cc
   geometry/nodes/node_geo_boolean.cc
@@ -351,6 +352,10 @@ if(WITH_INTERNATIONAL)
   add_definitions(-DWITH_INTERNATIONAL)
 endif()
 
+if(WITH_TBB)
+  add_definitions(-DWITH_TBB)
+endif()
+
 if(WITH_IMAGE_OPENEXR)
   add_definitions(-DWITH_OPENEXR)
 endif()
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index 9b391ab7981..54a728f5bfe 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -28,6 +28,7 @@ void register_node_type_geo_group(void);
 
 void register_node_type_geo_attribute_fill(void);
 void register_node_type_geo_attribute_vector_math(void);
+void register_node_type_geo_attribute_proximity(void);
 void register_node_type_geo_boolean(void);
 void register_node_type_geo_edge_split(void);
 void register_node_type_geo_transform(void);
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index f9730af0c08..1cf08a419c9 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -293,6 +293,8 @@ DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_SAMPLE_TEXTURE, def_geo_attribute_sampl
 DefNode(GeometryNode, GEO_NODE_POINTS_TO_VOLUME, def_geo_points_to_volume, "POINTS_TO_VOLUME", PointsToVolume, "Points to Volume", "")
 DefNode(GeometryNode, GEO_NODE_COLLECTION_INFO, def_geo_c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list