Geometry Nodes: Rename Curve Parameter, Add Index on Spline

- Rename the Curve Parameter node to Spline Parameter.
  - Add "Index on Spline" to the node. This output is the index of
the current point on it's parent spline rather than the entrire curve.

Differential Revision: https://developer.blender.org/D13275
This commit is contained in:
Johnny Matthews 2021-11-30 07:21:14 -06:00
parent 2f7bec04e8
commit 1cd9fcd98d
Notes: blender-bot 2023-08-29 14:50:05 +02:00
Referenced by pull request #111145, UI: fix and improve a few messages
Referenced by commit ea974b6681, UI: fix and improve a few messages
10 changed files with 109 additions and 11 deletions

View File

@ -111,7 +111,7 @@ def curve_node_items(context):
yield NodeItem("GeometryNodeTrimCurve")
yield NodeItemCustom(draw=lambda self, layout, context: layout.separator())
yield NodeItem("GeometryNodeInputCurveHandlePositions")
yield NodeItem("GeometryNodeCurveParameter")
yield NodeItem("GeometryNodeSplineParameter")
yield NodeItem("GeometryNodeInputTangent")
yield NodeItem("GeometryNodeInputCurveTilt")
yield NodeItem("GeometryNodeCurveEndpointSelection")

View File

@ -1507,7 +1507,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
#define GEO_NODE_SAMPLE_CURVE 1085
#define GEO_NODE_INPUT_TANGENT 1086
#define GEO_NODE_STRING_JOIN 1087
#define GEO_NODE_CURVE_PARAMETER 1088
#define GEO_NODE_CURVE_SPLINE_PARAMETER 1088
#define GEO_NODE_FILLET_CURVE 1089
#define GEO_NODE_DISTRIBUTE_POINTS_ON_FACES 1090
#define GEO_NODE_STRING_TO_CURVES 1091

View File

@ -5872,7 +5872,6 @@ static void registerGeometryNodes()
register_node_type_geo_curve_fillet();
register_node_type_geo_curve_handle_type_selection();
register_node_type_geo_curve_length();
register_node_type_geo_curve_parameter();
register_node_type_geo_curve_primitive_bezier_segment();
register_node_type_geo_curve_primitive_circle();
register_node_type_geo_curve_primitive_line();
@ -5884,6 +5883,7 @@ static void registerGeometryNodes()
register_node_type_geo_curve_reverse();
register_node_type_geo_curve_sample();
register_node_type_geo_curve_set_handles();
register_node_type_geo_curve_spline_parameter();
register_node_type_geo_curve_spline_type();
register_node_type_geo_curve_subdivide();
register_node_type_geo_curve_to_mesh();

View File

@ -2404,6 +2404,19 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
* \note Keep this message at the bottom of the function.
*/
{
LISTBASE_FOREACH (bNodeTree *, ntree, &bmain->nodetrees) {
if (ntree->type != NTREE_GEOMETRY) {
continue;
}
version_node_id(ntree, GEO_NODE_CURVE_SPLINE_PARAMETER, "GeometryNodeSplineParameter");
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (node->type == GEO_NODE_CURVE_SPLINE_PARAMETER) {
version_node_add_socket_if_not_exist(
ntree, node, SOCK_OUT, SOCK_INT, PROP_NONE, "Index", "Index");
}
}
}
/* Keep this block, even when empty. */
}
}

View File

@ -165,6 +165,21 @@ void version_node_output_socket_name(bNodeTree *ntree,
}
}
bNodeSocket *version_node_add_socket_if_not_exist(bNodeTree *ntree,
bNode *node,
eNodeSocketInOut in_out,
int type,
int subtype,
const char *identifier,
const char *name)
{
bNodeSocket *sock = nodeFindSocket(node, in_out, identifier);
if (sock != nullptr) {
return sock;
}
return nodeAddStaticSocket(ntree, node, in_out, type, subtype, identifier, name);
}
/**
* Replace the ID name of all nodes in the tree with the given type with the new name.
*/

View File

@ -64,6 +64,14 @@ void version_node_id(struct bNodeTree *ntree, const int node_type, const char *n
void version_node_socket_id_delim(bNodeSocket *socket);
struct bNodeSocket *version_node_add_socket_if_not_exist(struct bNodeTree *ntree,
struct bNode *node,
eNodeSocketInOut in_out,
int type,
int subtype,
const char *identifier,
const char *name);
#ifdef __cplusplus
}
#endif

View File

@ -76,7 +76,6 @@ void register_node_type_geo_curve_fill(void);
void register_node_type_geo_curve_fillet(void);
void register_node_type_geo_curve_handle_type_selection(void);
void register_node_type_geo_curve_length(void);
void register_node_type_geo_curve_parameter(void);
void register_node_type_geo_curve_primitive_bezier_segment(void);
void register_node_type_geo_curve_primitive_circle(void);
void register_node_type_geo_curve_primitive_line(void);
@ -89,6 +88,7 @@ void register_node_type_geo_curve_reverse(void);
void register_node_type_geo_curve_sample(void);
void register_node_type_geo_curve_set_handles(void);
void register_node_type_geo_curve_spline_type(void);
void register_node_type_geo_curve_spline_parameter(void);
void register_node_type_geo_curve_subdivide(void);
void register_node_type_geo_curve_to_mesh(void);
void register_node_type_geo_curve_to_points(void);

View File

@ -333,7 +333,7 @@ DefNode(GeometryNode, GEO_NODE_CONVEX_HULL, 0, "CONVEX_HULL", ConvexHull, "Conve
DefNode(GeometryNode, GEO_NODE_CURVE_ENDPOINT_SELECTION, 0, "CURVE_ENDPOINT_SELECTION", CurveEndpointSelection, "Endpoint Selection", "")
DefNode(GeometryNode, GEO_NODE_CURVE_HANDLE_TYPE_SELECTION, def_geo_curve_handle_type_selection, "CURVE_HANDLE_TYPE_SELECTION", CurveHandleTypeSelection, "Handle Type Selection", "")
DefNode(GeometryNode, GEO_NODE_CURVE_LENGTH, 0, "CURVE_LENGTH", CurveLength, "Curve Length", "")
DefNode(GeometryNode, GEO_NODE_CURVE_PARAMETER, 0, "CURVE_PARAMETER", CurveParameter, "Curve Parameter", "")
DefNode(GeometryNode, GEO_NODE_CURVE_SPLINE_PARAMETER, 0, "SPLINE_PARAMETER", SplineParameter, "Spline Parameter", "")
DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT, def_geo_curve_primitive_bezier_segment, "CURVE_PRIMITIVE_BEZIER_SEGMENT", CurvePrimitiveBezierSegment, "Bezier Segment", "")
DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_CIRCLE, def_geo_curve_primitive_circle, "CURVE_PRIMITIVE_CIRCLE", CurvePrimitiveCircle, "Curve Circle", "")
DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_LINE, def_geo_curve_primitive_line, "CURVE_PRIMITIVE_LINE", CurvePrimitiveLine, "Curve Line", "")

View File

@ -94,7 +94,6 @@ set(SRC
nodes/node_geo_curve_fillet.cc
nodes/node_geo_curve_handle_type_selection.cc
nodes/node_geo_curve_length.cc
nodes/node_geo_curve_parameter.cc
nodes/node_geo_curve_primitive_bezier_segment.cc
nodes/node_geo_curve_primitive_circle.cc
nodes/node_geo_curve_primitive_line.cc
@ -107,6 +106,7 @@ set(SRC
nodes/node_geo_curve_sample.cc
nodes/node_geo_curve_set_handles.cc
nodes/node_geo_curve_spline_type.cc
nodes/node_geo_curve_spline_parameter.cc
nodes/node_geo_curve_subdivide.cc
nodes/node_geo_curve_to_mesh.cc
nodes/node_geo_curve_to_points.cc

View File

@ -20,7 +20,7 @@
#include "node_geometry_util.hh"
namespace blender::nodes::node_geo_curve_parameter_cc {
namespace blender::nodes::node_geo_curve_spline_parameter_cc {
static void node_declare(NodeDeclarationBuilder &b)
{
@ -34,6 +34,9 @@ static void node_declare(NodeDeclarationBuilder &b)
.description(
N_("For points, the distance along the control point's spline, For splines, the "
"distance along the entire curve"));
b.add_output<decl::Int>(N_("Index"))
.field_source()
.description(N_("Each control point's index on its spline"));
}
/**
@ -182,6 +185,23 @@ static VArray<float> construct_curve_length_varray(const CurveEval &curve,
return {};
}
static VArray<int> construct_index_on_spline_varray(const CurveEval &curve,
const IndexMask UNUSED(mask),
const AttributeDomain domain)
{
if (domain == ATTR_DOMAIN_POINT) {
Array<int> output(curve.total_control_point_size());
int output_index = 0;
for (int spline_index : curve.splines().index_range()) {
for (int point_index : IndexRange(curve.splines()[spline_index]->size())) {
output[output_index++] = point_index;
}
}
return VArray<int>::ForContainer(std::move(output));
}
return {};
}
class CurveParameterFieldInput final : public fn::FieldInput {
public:
CurveParameterFieldInput() : fn::FieldInput(CPPType::get<float>(), "Curve Parameter node")
@ -261,22 +281,64 @@ class CurveLengthFieldInput final : public fn::FieldInput {
}
};
class IndexOnSplineFieldInput final : public fn::FieldInput {
public:
IndexOnSplineFieldInput() : fn::FieldInput(CPPType::get<int>(), "Spline Index")
{
category_ = Category::Generated;
}
GVArray get_varray_for_context(const fn::FieldContext &context,
IndexMask mask,
ResourceScope &UNUSED(scope)) const final
{
if (const GeometryComponentFieldContext *geometry_context =
dynamic_cast<const GeometryComponentFieldContext *>(&context)) {
const GeometryComponent &component = geometry_context->geometry_component();
const AttributeDomain domain = geometry_context->domain();
if (component.type() == GEO_COMPONENT_TYPE_CURVE) {
const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
const CurveEval *curve = curve_component.get_for_read();
if (curve) {
return construct_index_on_spline_varray(*curve, mask, domain);
}
}
}
return {};
}
uint64_t hash() const override
{
/* Some random constant hash. */
return 4536246522;
}
bool is_equal_to(const fn::FieldNode &other) const override
{
return dynamic_cast<const IndexOnSplineFieldInput *>(&other) != nullptr;
}
};
static void node_geo_exec(GeoNodeExecParams params)
{
Field<float> parameter_field{std::make_shared<CurveParameterFieldInput>()};
Field<float> length_field{std::make_shared<CurveLengthFieldInput>()};
Field<int> index_on_spline_field{std::make_shared<IndexOnSplineFieldInput>()};
params.set_output("Factor", std::move(parameter_field));
params.set_output("Length", std::move(length_field));
params.set_output("Index", std::move(index_on_spline_field));
}
} // namespace blender::nodes::node_geo_curve_parameter_cc
} // namespace blender::nodes::node_geo_curve_spline_parameter_cc
void register_node_type_geo_curve_parameter()
void register_node_type_geo_curve_spline_parameter()
{
namespace file_ns = blender::nodes::node_geo_curve_parameter_cc;
namespace file_ns = blender::nodes::node_geo_curve_spline_parameter_cc;
static bNodeType ntype;
geo_node_type_base(&ntype, GEO_NODE_CURVE_PARAMETER, "Curve Parameter", NODE_CLASS_INPUT, 0);
geo_node_type_base(
&ntype, GEO_NODE_CURVE_SPLINE_PARAMETER, "Spline Parameter", NODE_CLASS_INPUT, 0);
ntype.geometry_node_execute = file_ns::node_geo_exec;
ntype.declare = file_ns::node_declare;
nodeRegisterType(&ntype);