Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnny Matthews <johnny.matthews@gmail.com>2022-06-25 16:47:31 +0300
committerJohnny Matthews <johnny.matthews@gmail.com>2022-06-25 16:47:31 +0300
commit9a0a4b0c0d452d8d4e7c1cfe211b140c58179c7f (patch)
treeb02adb5fc5d14920273685dab82baeeaa408673a /source/blender/nodes
parent12bde317f4c94d48a154c8815ad910ccdd73be74 (diff)
Geometry Nodes: Add Points Node
This node takes a point count,a vector field, and float field and creates a pointcloud with n points at the positions indicated in the vector field with the radii specified in the float field.The node is placed in the "Point" menu. Differential Revision: https://developer.blender.org/D13920 Maniphest Task: https://developer.blender.org/T93044
Diffstat (limited to 'source/blender/nodes')
-rw-r--r--source/blender/nodes/NOD_geometry.h1
-rw-r--r--source/blender/nodes/NOD_static_types.h1
-rw-r--r--source/blender/nodes/geometry/CMakeLists.txt1
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_points.cc102
4 files changed, 105 insertions, 0 deletions
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index e4e4295fd3a..391322a95c6 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -102,6 +102,7 @@ void register_node_type_geo_mesh_subdivide(void);
void register_node_type_geo_mesh_to_curve(void);
void register_node_type_geo_mesh_to_points(void);
void register_node_type_geo_object_info(void);
+void register_node_type_geo_points(void);
void register_node_type_geo_points_to_vertices(void);
void register_node_type_geo_points_to_volume(void);
void register_node_type_geo_proximity(void);
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 9793f133dd6..090594d2308 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -357,6 +357,7 @@ DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_UV_SPHERE, 0, "MESH_PRIMITIVE_UV_S
DefNode(GeometryNode, GEO_NODE_MESH_TO_CURVE, 0, "MESH_TO_CURVE", MeshToCurve, "Mesh to Curve", "")
DefNode(GeometryNode, GEO_NODE_MESH_TO_POINTS, def_geo_mesh_to_points, "MESH_TO_POINTS", MeshToPoints, "Mesh to Points", "")
DefNode(GeometryNode, GEO_NODE_OBJECT_INFO, def_geo_object_info, "OBJECT_INFO", ObjectInfo, "Object Info", "")
+DefNode(GeometryNode, GEO_NODE_POINTS, 0, "POINTS", Points, "Points", "")
DefNode(GeometryNode, GEO_NODE_POINTS_TO_VERTICES, 0, "POINTS_TO_VERTICES", PointsToVertices, "Points to Vertices", "")
DefNode(GeometryNode, GEO_NODE_POINTS_TO_VOLUME, def_geo_points_to_volume, "POINTS_TO_VOLUME", PointsToVolume, "Points to Volume", "")
DefNode(GeometryNode, GEO_NODE_PROXIMITY, def_geo_proximity, "PROXIMITY", Proximity, "Geometry Proximity", "")
diff --git a/source/blender/nodes/geometry/CMakeLists.txt b/source/blender/nodes/geometry/CMakeLists.txt
index 015edf2d26c..8334a673539 100644
--- a/source/blender/nodes/geometry/CMakeLists.txt
+++ b/source/blender/nodes/geometry/CMakeLists.txt
@@ -112,6 +112,7 @@ set(SRC
nodes/node_geo_mesh_to_curve.cc
nodes/node_geo_mesh_to_points.cc
nodes/node_geo_object_info.cc
+ nodes/node_geo_points.cc
nodes/node_geo_points_to_vertices.cc
nodes/node_geo_points_to_volume.cc
nodes/node_geo_proximity.cc
diff --git a/source/blender/nodes/geometry/nodes/node_geo_points.cc b/source/blender/nodes/geometry/nodes/node_geo_points.cc
new file mode 100644
index 00000000000..42a760906e1
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_points.cc
@@ -0,0 +1,102 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BKE_pointcloud.h"
+
+#include "BLI_task.hh"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_points_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Int>(N_("Count"))
+ .default_value(1)
+ .description(N_("The number of points to create"))
+ .min(0);
+ b.add_input<decl::Vector>(N_("Position"))
+ .supports_field()
+ .default_value(float3(0.0f))
+ .description(N_("The positions of the new points"));
+ b.add_input<decl::Float>(N_("Radius"))
+ .supports_field()
+ .supports_field()
+ .default_value(float(0.1f))
+ .description(N_("The radii of the new points"));
+ b.add_output<decl::Geometry>(N_("Geometry"));
+}
+
+class PointsFieldContext : public FieldContext {
+ private:
+ int points_num_;
+
+ public:
+ PointsFieldContext(const int points_num) : points_num_(points_num)
+ {
+ }
+
+ int64_t points_num() const
+ {
+ return points_num_;
+ }
+
+ GVArray get_varray_for_input(const FieldInput &field_input,
+ const IndexMask mask,
+ ResourceScope &UNUSED(scope)) const
+ {
+ const bke::IDAttributeFieldInput *id_field_input =
+ dynamic_cast<const bke::IDAttributeFieldInput *>(&field_input);
+
+ const fn::IndexFieldInput *index_field_input = dynamic_cast<const fn::IndexFieldInput *>(
+ &field_input);
+
+ if (id_field_input == nullptr && index_field_input == nullptr) {
+ return {};
+ }
+
+ return fn::IndexFieldInput::get_index_varray(mask);
+ }
+};
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ const int count = params.extract_input<int>("Count");
+ if (count <= 0) {
+ params.error_message_add(NodeWarningType::Warning, TIP_("Point count should be at least 1"));
+ params.set_default_remaining_outputs();
+ return;
+ }
+
+ Field<float3> position_field = params.extract_input<Field<float3>>("Position");
+ Field<float> radius_field = params.extract_input<Field<float>>("Radius");
+
+ PointCloud *new_point_cloud = BKE_pointcloud_new_nomain(count);
+ GeometrySet geometry_set = GeometrySet::create_with_pointcloud(new_point_cloud);
+ PointCloudComponent &points = geometry_set.get_component_for_write<PointCloudComponent>();
+ OutputAttribute_Typed<float3> output_position = points.attribute_try_get_for_output_only<float3>(
+ "position", ATTR_DOMAIN_POINT);
+ OutputAttribute_Typed<float> output_radii = points.attribute_try_get_for_output_only<float>(
+ "radius", ATTR_DOMAIN_POINT);
+
+ PointsFieldContext context{count};
+ fn::FieldEvaluator evaluator{context, count};
+ evaluator.add_with_destination(position_field, output_position.as_span());
+ evaluator.add_with_destination(radius_field, output_radii.as_span());
+ evaluator.evaluate();
+
+ output_position.save();
+ output_radii.save();
+ params.set_output("Geometry", std::move(geometry_set));
+}
+
+} // namespace blender::nodes::node_geo_points_cc
+
+void register_node_type_geo_points()
+{
+ namespace file_ns = blender::nodes::node_geo_points_cc;
+ static bNodeType ntype;
+ geo_node_type_base(&ntype, GEO_NODE_POINTS, "Points", NODE_CLASS_GEOMETRY);
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ ntype.declare = file_ns::node_declare;
+ nodeRegisterType(&ntype);
+}