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:
authorHans Goudey <h.goudey@me.com>2022-09-28 22:38:27 +0300
committerHans Goudey <h.goudey@me.com>2022-09-28 22:38:27 +0300
commit482d431bb6735e8206961bd1115d2be7e63572b1 (patch)
treef47f10616f1f943def2bff975a6a869534feccc1 /source/blender/nodes/geometry/nodes/node_geo_curve_topology_curve_of_point.cc
parent25533dbe219f8bbcb3f04ffe2ff1e57599addf3f (diff)
Geometry Nodes: Curve and mesh topology access nodes
This patch contains an initial set of nodes to access basic mesh topology information, as explored in T100020. The nodes allow six direct topology mappings for meshes: - **Corner -> Face** The face a corner is in, the index in the face - **Vertex -> Edge** Choose an edge attached to the vertex - **Vertex -> Corner** Choose a corner attached to the vertex - **Corner -> Edge** The next and previous edge at each face corner - **Corner -> Vertex** The vertex associated with a corner - **Corner -> Corner** Offset a corner index within a face And two new topology mappings for curves: - **Curve -> Points** Choose a point within a curve - **Point -> Curve** The curve a point is in, the index in the curve The idea is that some of the 16 possible mesh mappings are more important, and that this is a useful set of nodes to start exploring this area. For mappings with an arbitrary number of connections, we must sort them and use an index to choose a single element, because geometry nodes does not support list fields. Note that the sort index has repeating behavior as it goes over the "Total" number of connections, and negative sort indices choose from the end. Currently which of the "start" elements is used is determined by the field context, so the "Field at Index" and "Interpolate Domain" nodes will be quite important. Also, currently the "Sort Index" inputs are clamped to the number of connections. One important feature that isn't implemented here is using the winding order for the output elements. This can be a separate mode for some of these nodes. It will be optional because of the performance impact. There are several todos for separate commits after this: - Rename "Control Point Neighbors" to be consistent with this naming - Version away the "Vertex Neighbors" node which is fully redundant now - Implement a special case for when no weights are used for performance - De-duplicating some of the sorting logic between the nodes - Improve performance and memory use of topology mappings - Look into caching some of the mappings on meshes Differential Revision: https://developer.blender.org/D16029
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_curve_topology_curve_of_point.cc')
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_topology_curve_of_point.cc121
1 files changed, 121 insertions, 0 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_topology_curve_of_point.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_topology_curve_of_point.cc
new file mode 100644
index 00000000000..4d60ab939ca
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_topology_curve_of_point.cc
@@ -0,0 +1,121 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BKE_curves.hh"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_curve_topology_curve_of_point_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Int>(N_("Point Index"))
+ .implicit_field(implicit_field_inputs::index)
+ .description(N_("The control point to retrieve data from"));
+ b.add_output<decl::Int>(N_("Curve Index"))
+ .dependent_field()
+ .description(N_("The curve the control point is part of"));
+ b.add_output<decl::Int>(N_("Index in Curve"))
+ .dependent_field()
+ .description(N_("How far along the control point is along its curve"));
+}
+
+class CurveOfPointInput final : public bke::CurvesFieldInput {
+ public:
+ CurveOfPointInput() : bke::CurvesFieldInput(CPPType::get<int>(), "Point Curve Index")
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const bke::CurvesGeometry &curves,
+ const eAttrDomain domain,
+ const IndexMask /*mask*/) const final
+ {
+ if (domain != ATTR_DOMAIN_POINT) {
+ return {};
+ }
+ return VArray<int>::ForContainer(curves.point_to_curve_map());
+ }
+
+ uint64_t hash() const override
+ {
+ return 413209687345908697;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const override
+ {
+ if (dynamic_cast<const CurveOfPointInput *>(&other)) {
+ return true;
+ }
+ return false;
+ }
+};
+
+class PointIndexInCurveInput final : public bke::CurvesFieldInput {
+ public:
+ PointIndexInCurveInput() : bke::CurvesFieldInput(CPPType::get<int>(), "Point Index in Curve")
+ {
+ category_ = Category::Generated;
+ }
+
+ GVArray get_varray_for_context(const bke::CurvesGeometry &curves,
+ const eAttrDomain domain,
+ const IndexMask /*mask*/) const final
+ {
+ if (domain != ATTR_DOMAIN_POINT) {
+ return {};
+ }
+ const Span<int> offsets = curves.offsets();
+ Array<int> point_to_curve_map = curves.point_to_curve_map();
+ return VArray<int>::ForFunc(
+ curves.points_num(),
+ [offsets, point_to_curve_map = std::move(point_to_curve_map)](const int point_i) {
+ const int curve_i = point_to_curve_map[point_i];
+ return point_i - offsets[curve_i];
+ });
+ }
+
+ uint64_t hash() const final
+ {
+ return 9834765987345677;
+ }
+
+ bool is_equal_to(const fn::FieldNode &other) const final
+ {
+ if (dynamic_cast<const PointIndexInCurveInput *>(&other)) {
+ return true;
+ }
+ return false;
+ }
+};
+
+static void node_geo_exec(GeoNodeExecParams params)
+{
+ const Field<int> point_index = params.extract_input<Field<int>>("Point Index");
+ if (params.output_is_required("Curve Index")) {
+ params.set_output(
+ "Curve Index",
+ Field<int>(std::make_shared<FieldAtIndexInput>(
+ point_index, Field<int>(std::make_shared<CurveOfPointInput>()), ATTR_DOMAIN_POINT)));
+ }
+ if (params.output_is_required("Index in Curve")) {
+ params.set_output("Index in Curve",
+ Field<int>(std::make_shared<FieldAtIndexInput>(
+ point_index,
+ Field<int>(std::make_shared<PointIndexInCurveInput>()),
+ ATTR_DOMAIN_POINT)));
+ }
+}
+
+} // namespace blender::nodes::node_geo_curve_topology_curve_of_point_cc
+
+void register_node_type_geo_curve_topology_curve_of_point()
+{
+ namespace file_ns = blender::nodes::node_geo_curve_topology_curve_of_point_cc;
+
+ static bNodeType ntype;
+ geo_node_type_base(
+ &ntype, GEO_NODE_CURVE_TOPOLOGY_CURVE_OF_POINT, "Curve of Point", NODE_CLASS_INPUT);
+ ntype.geometry_node_execute = file_ns::node_geo_exec;
+ ntype.declare = file_ns::node_declare;
+ nodeRegisterType(&ntype);
+}