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
This commit is contained in:
parent
12bde317f4
commit
9a0a4b0c0d
Notes:
blender-bot
2023-02-14 06:21:59 +01:00
Referenced by issue #93044, Single Point Node
|
@ -225,6 +225,7 @@ def point_node_items(context):
|
|||
if not space:
|
||||
return
|
||||
yield NodeItem("GeometryNodeDistributePointsOnFaces")
|
||||
yield NodeItem("GeometryNodePoints")
|
||||
yield NodeItem("GeometryNodePointsToVertices")
|
||||
yield NodeItem("GeometryNodePointsToVolume")
|
||||
yield NodeItemCustom(draw=lambda self, layout, context: layout.separator())
|
||||
|
|
|
@ -1496,6 +1496,7 @@ struct TexResult;
|
|||
#define GEO_NODE_INPUT_INSTANCE_ROTATION 1159
|
||||
#define GEO_NODE_INPUT_INSTANCE_SCALE 1160
|
||||
#define GEO_NODE_VOLUME_CUBE 1161
|
||||
#define GEO_NODE_POINTS 1162
|
||||
|
||||
/** \} */
|
||||
|
||||
|
|
|
@ -4804,6 +4804,7 @@ static void registerGeometryNodes()
|
|||
register_node_type_geo_mesh_to_curve();
|
||||
register_node_type_geo_mesh_to_points();
|
||||
register_node_type_geo_object_info();
|
||||
register_node_type_geo_points();
|
||||
register_node_type_geo_points_to_vertices();
|
||||
register_node_type_geo_points_to_volume();
|
||||
register_node_type_geo_proximity();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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", "")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue