[Bf-blender-cvs] [54cab988a9f] geometry-nodes-distribute-points: WIP changes to point dist node

Sebastian Parborg noreply at git.blender.org
Thu Nov 26 14:55:51 CET 2020


Commit: 54cab988a9fdc1c4e236cd5485419f03643bc9d0
Author: Sebastian Parborg
Date:   Thu Nov 26 14:46:44 2020 +0100
Branches: geometry-nodes-distribute-points
https://developer.blender.org/rB54cab988a9fdc1c4e236cd5485419f03643bc9d0

WIP changes to point dist node

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

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/NOD_static_types.h
M	source/blender/nodes/geometry/nodes/cySampleElim.hh
M	source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc

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

diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index cb1dcf96bfb..aa05e8fc7a5 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3180,6 +3180,13 @@ static void node_geometry_buts_attribute_math(uiLayout *layout,
   uiItemR(layout, ptr, "input_type_b", DEFAULT_FLAGS, IFACE_("Type B"), ICON_NONE);
 }
 
+static void node_geometry_buts_attribute_point_distribute(uiLayout *layout,
+                                                          bContext *UNUSED(C),
+                                                          PointerRNA *ptr)
+{
+  uiItemR(layout, ptr, "distribute_method", DEFAULT_FLAGS, "", ICON_NONE);
+}
+
 static void node_geometry_set_butfunc(bNodeType *ntype)
 {
   switch (ntype->type) {
@@ -3198,6 +3205,9 @@ static void node_geometry_set_butfunc(bNodeType *ntype)
     case GEO_NODE_ATTRIBUTE_MATH:
       ntype->draw_buttons = node_geometry_buts_attribute_math;
       break;
+    case GEO_NODE_POINT_DISTRIBUTE:
+      ntype->draw_buttons = node_geometry_buts_attribute_point_distribute;
+      break;
   }
 }
 
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 29c83d2d4ed..825cdc55dbf 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -350,8 +350,8 @@ typedef struct bNode {
 /* XXX NODE_UPDATE is a generic update flag. More fine-grained updates
  * might be used in the future, but currently all work the same way.
  */
-#define NODE_UPDATE 0xFFFF     /* generic update flag (includes all others) */
-#define NODE_UPDATE_ID 1       /* associated id data block has changed */
+#define NODE_UPDATE 0xFFFF /* generic update flag (includes all others) */
+#define NODE_UPDATE_ID 1 /* associated id data block has changed */
 #define NODE_UPDATE_OPERATOR 2 /* node update triggered from update operator */
 
 /* Unique hash key for identifying node instances
@@ -510,11 +510,11 @@ typedef struct bNodeTree {
 #define NTREE_TYPE_INIT 1
 
 /* ntree->flag */
-#define NTREE_DS_EXPAND (1 << 0)            /* for animation editors */
-#define NTREE_COM_OPENCL (1 << 1)           /* use opencl */
-#define NTREE_TWO_PASS (1 << 2)             /* two pass */
+#define NTREE_DS_EXPAND (1 << 0) /* for animation editors */
+#define NTREE_COM_OPENCL (1 << 1) /* use opencl */
+#define NTREE_TWO_PASS (1 << 2) /* two pass */
 #define NTREE_COM_GROUPNODE_BUFFER (1 << 3) /* use groupnode buffers */
-#define NTREE_VIEWER_BORDER (1 << 4)        /* use a border for viewer nodes */
+#define NTREE_VIEWER_BORDER (1 << 4) /* use a border for viewer nodes */
 /* NOTE: DEPRECATED, use (id->tag & LIB_TAG_LOCALIZED) instead. */
 
 /* tree is localized copy, free when deleting node groups */
@@ -1071,7 +1071,7 @@ typedef struct NodeDenoise {
 #define NODE_IES_EXTERNAL 1
 
 /* frame node flags */
-#define NODE_FRAME_SHRINK 1     /* keep the bounding box minimal */
+#define NODE_FRAME_SHRINK 1 /* keep the bounding box minimal */
 #define NODE_FRAME_RESIZEABLE 2 /* test flag, if frame can be resized by user */
 
 /* proxy node flags */
@@ -1464,6 +1464,11 @@ typedef enum GeometryNodeUseAttributeFlag {
   GEO_NODE_USE_ATTRIBUTE_B = (1 << 1),
 } GeometryNodeUseAttributeFlag;
 
+typedef enum GeometryNodePointDistributeMethod {
+  GEO_NODE_POINT_DISTRIBUTE_RANDOM = 0,
+  GEO_NODE_POINT_DISTRIBUTE_POISSON = 1,
+} GeometryNodePointDistributeMethod;
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 6795426a6d2..5b2b9059269 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -435,6 +435,19 @@ static const EnumPropertyItem rna_node_geometry_attribute_input_b_items[] = {
     {0, NULL, 0, NULL, NULL},
 };
 
+static const EnumPropertyItem rna_node_geometry_point_distribute_method_items[] = {
+    {GEO_NODE_POINT_DISTRIBUTE_RANDOM,
+     "RANDOM",
+     0,
+     "Random",
+     "Distribute points randomly inside the domain"},
+    {GEO_NODE_POINT_DISTRIBUTE_POISSON,
+     "POISSON",
+     0,
+     "Poisson Disk",
+     "Distribute points inside the domain evenly with a Poisson disk distribution"},
+    {0, NULL, 0, NULL, NULL},
+};
 #endif
 
 #ifdef RNA_RUNTIME
@@ -8398,6 +8411,18 @@ static void def_geo_attribute_math(StructRNA *srna)
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
 }
 
+static void def_geo_point_distribute(StructRNA *srna)
+{
+  PropertyRNA *prop;
+
+  prop = RNA_def_property(srna, "distribute_method", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_sdna(prop, NULL, "custom1");
+  RNA_def_property_enum_items(prop, rna_node_geometry_point_distribute_method_items);
+  RNA_def_property_enum_default(prop, GEO_NODE_POINT_DISTRIBUTE_RANDOM);
+  RNA_def_property_ui_text(prop, "Distribution Method", "Method to use for scattering points");
+  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/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 09e0908140c..fff4bb2e43c 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -271,7 +271,7 @@ DefNode(GeometryNode, GEO_NODE_EDGE_SPLIT, 0, "EDGE_SPLIT", EdgeSplit, "Edge Spl
 DefNode(GeometryNode, GEO_NODE_TRANSFORM, 0, "TRANSFORM", Transform, "Transform", "")
 DefNode(GeometryNode, GEO_NODE_SUBDIVISION_SURFACE, 0, "SUBDIVISION_SURFACE", SubdivisionSurface, "Subdivision Surface", "")
 DefNode(GeometryNode, GEO_NODE_BOOLEAN, def_geo_boolean, "BOOLEAN", Boolean, "Boolean", "")
-DefNode(GeometryNode, GEO_NODE_POINT_DISTRIBUTE, 0, "POINT_DISTRIBUTE", PointDistribute, "Point Distribute", "")
+DefNode(GeometryNode, GEO_NODE_POINT_DISTRIBUTE, def_geo_point_distribute, "POINT_DISTRIBUTE", PointDistribute, "Point Distribute", "")
 DefNode(GeometryNode, GEO_NODE_POINT_INSTANCE, 0, "POINT_INSTANCE", PointInstance, "Point Instance", "")
 DefNode(GeometryNode, GEO_NODE_OBJECT_INFO, 0, "OBJECT_INFO", ObjectInfo, "Object Info", "")
 DefNode(GeometryNode, GEO_NODE_RANDOM_ATTRIBUTE, def_geo_random_attribute, "RANDOM_ATTRIBUTE", RandomAttribute, "Random Attribute", "")
diff --git a/source/blender/nodes/geometry/nodes/cySampleElim.hh b/source/blender/nodes/geometry/nodes/cySampleElim.hh
index 928e791b852..395d6ec4a4b 100644
--- a/source/blender/nodes/geometry/nodes/cySampleElim.hh
+++ b/source/blender/nodes/geometry/nodes/cySampleElim.hh
@@ -725,6 +725,7 @@ class WeightedSampleElimination {
     return dimensions == 2 ? Sqrt(FType(2)) : std::pow(FType(2), FType(1) / FType(dimensions));
   }
 
+ public:
   // Returns the minimum radius fraction used by the default weight function.
   FType GetWeightLimitFraction(SIZE_TYPE inputSize, SIZE_TYPE outputSize) const
   {
@@ -732,7 +733,6 @@ class WeightedSampleElimination {
     return (1 - std::pow(ratio, gamma)) * beta;
   }
 
- public:
   // This is the same functions as above except that we elimiate all points that have non zero
   // weight (IE they are within d_max if we are using the default weighting function). We don't
   // stop at any specific number of points.
@@ -897,7 +897,7 @@ class WeightedSampleElimination {
     SIZE_TYPE sampleSize = inputSize;
     // Stop when the top heap item has a weight of zero.
     // We have to return at least one point otherwise the heap triggers a ASAN error
-    while (heap.GetTopItem() > FLT_EPSILON && heap.NumItemsInHeap() > 1) {
+    while (heap.GetTopItem() > (0.5f * 1e-5f) && heap.NumItemsInHeap() > 1) {
       // Pull the top sample from heap
       SIZE_TYPE i = heap.GetTopItemID();
       heap.Pop();
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
index 457637d774b..c6e624ed6cb 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
@@ -34,9 +34,8 @@
 
 static bNodeSocketTemplate geo_node_point_distribute_in[] = {
     {SOCK_GEOMETRY, N_("Geometry")},
-    {SOCK_FLOAT, N_("Maximum Density"), 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 100000.0f, PROP_NONE},
     {SOCK_FLOAT, N_("Minimum Distance"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 100000.0f, PROP_NONE},
-    {SOCK_BOOLEAN, N_("Use Point Culling")},
+    {SOCK_FLOAT, N_("Maximum Density"), 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 100000.0f, PROP_NONE},
     {SOCK_STRING, N_("Density Attribute")},
     {-1, ""},
 };
@@ -46,12 +45,18 @@ static bNodeSocketTemplate geo_node_point_distribute_out[] = {
     {-1, ""},
 };
 
+static void node_point_distribute_update(bNodeTree *UNUSED(ntree), bNode *node)
+{
+  bNodeSocket *sock_min_dist = (bNodeSocket *)BLI_findlink(&node->inputs, 1);
+
+  nodeSetSocketAvailability(sock_min_dist, ELEM(node->custom1, GEO_NODE_POINT_DISTRIBUTE_POISSON));
+}
+
 namespace blender::nodes {
 
-static Vector<float3> scatter_points_from_mesh(const Mesh *mesh,
-                                               const float density,
-                                               const FloatReadAttribute &density_factors,
-                                               float &total_mesh_area)
+static Vector<float3> random_scatter_points_from_mesh(const Mesh *mesh,
+                                                      const float density,
+                                                      const FloatReadAttribute &density_factors)
 {
   /* This only updates a cache and can be considered to be logically const. */
   const MLoopTri *looptris = BKE_mesh_runtime_looptri_ensure(const_cast<Mesh *>(mesh));
@@ -74,7 +79,6 @@ static Vector<float3> scatter_points_from_mesh(const Mesh *mesh,
                                           v2_density_factor) /
                                          3.0f;
     const float area = area_tri_v3(v0_pos, v1_pos, v2_pos);
-    total_mesh_area += area;
 
     const int looptri_seed = BLI_hash_int(looptri_index);
     RandomNumberGenerator looptri_rng(l

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list