Geometry Nodes: Curve Primitive Line
This node creates a poly spline line in one of 2 modes: - Line between two points - Start Point, Direction, and Length Both modes create splines with only start and endpoints. A resample node can be used afterward to increase the point count. Differential Revision: https://developer.blender.org/D11769
This commit is contained in:
parent
de70bcbb36
commit
29d6750134
Notes:
blender-bot
2023-02-13 22:37:44 +01:00
Referenced by issue #89220, Curve Primitive Nodes
|
@ -510,6 +510,7 @@ geometry_node_categories = [
|
|||
NodeItem("GeometryNodeCurveReverse"),
|
||||
]),
|
||||
GeometryNodeCategory("GEO_PRIMITIVES_CURVE", "Curve Primitives", items=[
|
||||
NodeItem("GeometryNodeCurvePrimitiveLine"),
|
||||
NodeItem("GeometryNodeCurvePrimitiveCircle"),
|
||||
NodeItem("GeometryNodeCurveStar"),
|
||||
NodeItem("GeometryNodeCurveSpiral"),
|
||||
|
|
|
@ -1445,6 +1445,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
|
|||
#define GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT 1065
|
||||
#define GEO_NODE_CURVE_PRIMITIVE_CIRCLE 1066
|
||||
#define GEO_NODE_VIEWER 1067
|
||||
#define GEO_NODE_CURVE_PRIMITIVE_LINE 1068
|
||||
|
||||
/** \} */
|
||||
|
||||
|
|
|
@ -5056,6 +5056,7 @@ static void registerGeometryNodes()
|
|||
register_node_type_geo_curve_length();
|
||||
register_node_type_geo_curve_primitive_bezier_segment();
|
||||
register_node_type_geo_curve_primitive_circle();
|
||||
register_node_type_geo_curve_primitive_line();
|
||||
register_node_type_geo_curve_primitive_quadratic_bezier();
|
||||
register_node_type_geo_curve_primitive_spiral();
|
||||
register_node_type_geo_curve_primitive_star();
|
||||
|
|
|
@ -1358,6 +1358,11 @@ typedef struct NodeSwitch {
|
|||
uint8_t input_type;
|
||||
} NodeSwitch;
|
||||
|
||||
typedef struct NodeGeometryCurvePrimitiveLine {
|
||||
/* GeometryNodeCurvePrimitiveLineMode. */
|
||||
uint8_t mode;
|
||||
} NodeGeometryCurvePrimitiveLine;
|
||||
|
||||
typedef struct NodeGeometryCurvePrimitiveBezierSegment {
|
||||
/* GeometryNodeCurvePrimitiveBezierSegmentMode. */
|
||||
uint8_t mode;
|
||||
|
@ -1913,6 +1918,11 @@ typedef enum GeometryNodeMeshLineCountMode {
|
|||
GEO_NODE_MESH_LINE_COUNT_RESOLUTION = 1,
|
||||
} GeometryNodeMeshLineCountMode;
|
||||
|
||||
typedef enum GeometryNodeCurvePrimitiveLineMode {
|
||||
GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_POINTS = 0,
|
||||
GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_DIRECTION = 1
|
||||
} GeometryNodeCurvePrimitiveLineMode;
|
||||
|
||||
typedef enum GeometryNodeCurvePrimitiveBezierSegmentMode {
|
||||
GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT_POSITION = 0,
|
||||
GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT_OFFSET = 1,
|
||||
|
|
|
@ -9488,6 +9488,32 @@ static void def_geo_curve_primitive_circle(StructRNA *srna)
|
|||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
|
||||
}
|
||||
|
||||
static void def_geo_curve_primitive_line(StructRNA *srna)
|
||||
{
|
||||
static const EnumPropertyItem mode_items[] = {
|
||||
{GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_POINTS,
|
||||
"POINTS",
|
||||
ICON_NONE,
|
||||
"Points",
|
||||
"Define the start and end points of the line"},
|
||||
{GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_DIRECTION,
|
||||
"DIRECTION",
|
||||
ICON_NONE,
|
||||
"Direction",
|
||||
"Define a line with a start point, direction and length"},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
};
|
||||
|
||||
PropertyRNA *prop;
|
||||
|
||||
RNA_def_struct_sdna_from(srna, "NodeGeometryCurvePrimitiveLine", "storage");
|
||||
|
||||
prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_items(prop, mode_items);
|
||||
RNA_def_property_ui_text(prop, "Mode", "Method used to determine radius and placement");
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
|
||||
}
|
||||
|
||||
static void def_geo_point_rotate(StructRNA *srna)
|
||||
{
|
||||
static const EnumPropertyItem type_items[] = {
|
||||
|
|
|
@ -167,6 +167,7 @@ set(SRC
|
|||
geometry/nodes/node_geo_curve_length.cc
|
||||
geometry/nodes/node_geo_curve_primitive_bezier_segment.cc
|
||||
geometry/nodes/node_geo_curve_primitive_circle.cc
|
||||
geometry/nodes/node_geo_curve_primitive_line.cc
|
||||
geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc
|
||||
geometry/nodes/node_geo_curve_primitive_spiral.cc
|
||||
geometry/nodes/node_geo_curve_primitive_star.cc
|
||||
|
|
|
@ -54,6 +54,7 @@ void register_node_type_geo_convex_hull(void);
|
|||
void register_node_type_geo_curve_length(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);
|
||||
void register_node_type_geo_curve_primitive_quadratic_bezier(void);
|
||||
void register_node_type_geo_curve_primitive_spiral(void);
|
||||
void register_node_type_geo_curve_primitive_star(void);
|
||||
|
|
|
@ -294,6 +294,7 @@ DefNode(GeometryNode, GEO_NODE_CONVEX_HULL, 0, "CONVEX_HULL", ConvexHull, "Conve
|
|||
DefNode(GeometryNode, GEO_NODE_CURVE_LENGTH, 0, "CURVE_LENGTH", CurveLength, "Curve Length", "")
|
||||
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, "Circle", "")
|
||||
DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_LINE, def_geo_curve_primitive_line, "CURVE_PRIMITIVE_LINE", CurvePrimitiveLine, "Curve Line", "")
|
||||
DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_QUADRATIC_BEZIER, 0, "CURVE_PRIMITIVE_QUADRATIC_BEZIER", CurveQuadraticBezier, "Quadratic Bezier", "")
|
||||
DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_STAR, 0, "CURVE_PRIMITIVE_STAR", CurveStar, "Star", "")
|
||||
DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_SPIRAL, 0, "CURVE_PRIMITIVE_SPIRAL", CurveSpiral, "Curve Spiral", "")
|
||||
|
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "BKE_spline.hh"
|
||||
|
||||
#include "UI_interface.h"
|
||||
#include "UI_resources.h"
|
||||
|
||||
#include "node_geometry_util.hh"
|
||||
|
||||
static bNodeSocketTemplate geo_node_curve_primitive_line_in[] = {
|
||||
{SOCK_VECTOR, N_("Start"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_TRANSLATION},
|
||||
{SOCK_VECTOR, N_("End"), 0.0f, 2.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_TRANSLATION},
|
||||
{SOCK_VECTOR, N_("Direction"), 0.0f, 1.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX},
|
||||
{SOCK_FLOAT, N_("Length"), 2.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_DISTANCE},
|
||||
{-1, ""},
|
||||
};
|
||||
|
||||
static bNodeSocketTemplate geo_node_curve_primitive_line_out[] = {
|
||||
{SOCK_GEOMETRY, N_("Curve")},
|
||||
{-1, ""},
|
||||
};
|
||||
|
||||
static void geo_node_curve_primitive_line_layout(uiLayout *layout,
|
||||
bContext *UNUSED(C),
|
||||
PointerRNA *ptr)
|
||||
{
|
||||
uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
|
||||
}
|
||||
|
||||
namespace blender::nodes {
|
||||
|
||||
static void geo_node_curve_primitive_line_init(bNodeTree *UNUSED(tree), bNode *node)
|
||||
{
|
||||
NodeGeometryCurvePrimitiveLine *data = (NodeGeometryCurvePrimitiveLine *)MEM_callocN(
|
||||
sizeof(NodeGeometryCurvePrimitiveLine), __func__);
|
||||
|
||||
data->mode = GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_POINTS;
|
||||
node->storage = data;
|
||||
}
|
||||
|
||||
static void geo_node_curve_primitive_line_update(bNodeTree *UNUSED(ntree), bNode *node)
|
||||
{
|
||||
const NodeGeometryCurvePrimitiveLine *node_storage = (NodeGeometryCurvePrimitiveLine *)
|
||||
node->storage;
|
||||
const GeometryNodeCurvePrimitiveLineMode mode = (const GeometryNodeCurvePrimitiveLineMode)
|
||||
node_storage->mode;
|
||||
|
||||
bNodeSocket *p2_socket = ((bNodeSocket *)node->inputs.first)->next;
|
||||
bNodeSocket *direction_socket = p2_socket->next;
|
||||
bNodeSocket *length_socket = direction_socket->next;
|
||||
|
||||
nodeSetSocketAvailability(p2_socket, mode == GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_POINTS);
|
||||
nodeSetSocketAvailability(direction_socket,
|
||||
mode == GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_DIRECTION);
|
||||
nodeSetSocketAvailability(length_socket, mode == GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_DIRECTION);
|
||||
}
|
||||
|
||||
static std::unique_ptr<CurveEval> create_point_line_curve(const float3 start, const float3 end)
|
||||
{
|
||||
std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>();
|
||||
std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>();
|
||||
|
||||
spline->resize(2);
|
||||
MutableSpan<float3> positions = spline->positions();
|
||||
positions[0] = start;
|
||||
positions[1] = end;
|
||||
spline->radii().fill(1.0f);
|
||||
spline->tilts().fill(0.0f);
|
||||
curve->add_spline(std::move(spline));
|
||||
curve->attributes.reallocate(curve->splines().size());
|
||||
return curve;
|
||||
}
|
||||
|
||||
static std::unique_ptr<CurveEval> create_direction_line_curve(const float3 start,
|
||||
const float3 direction,
|
||||
const float length)
|
||||
{
|
||||
std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>();
|
||||
std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>();
|
||||
|
||||
spline->resize(2);
|
||||
MutableSpan<float3> positions = spline->positions();
|
||||
positions[0] = start;
|
||||
positions[1] = direction.normalized() * length;
|
||||
|
||||
spline->radii().fill(1.0f);
|
||||
spline->tilts().fill(0.0f);
|
||||
curve->add_spline(std::move(spline));
|
||||
curve->attributes.reallocate(curve->splines().size());
|
||||
return curve;
|
||||
}
|
||||
|
||||
static void geo_node_curve_primitive_line_exec(GeoNodeExecParams params)
|
||||
{
|
||||
|
||||
const NodeGeometryCurvePrimitiveLine *node_storage =
|
||||
(NodeGeometryCurvePrimitiveLine *)params.node().storage;
|
||||
|
||||
GeometryNodeCurvePrimitiveLineMode mode = (GeometryNodeCurvePrimitiveLineMode)node_storage->mode;
|
||||
|
||||
std::unique_ptr<CurveEval> curve;
|
||||
if (mode == GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_POINTS) {
|
||||
curve = create_point_line_curve(params.extract_input<float3>("Start"),
|
||||
params.extract_input<float3>("End"));
|
||||
}
|
||||
else if (mode == GEO_NODE_CURVE_PRIMITIVE_LINE_MODE_DIRECTION) {
|
||||
curve = create_direction_line_curve(params.extract_input<float3>("Start"),
|
||||
params.extract_input<float3>("Direction"),
|
||||
params.extract_input<float>("Length"));
|
||||
}
|
||||
|
||||
params.set_output("Curve", GeometrySet::create_with_curve(curve.release()));
|
||||
}
|
||||
|
||||
} // namespace blender::nodes
|
||||
|
||||
void register_node_type_geo_curve_primitive_line()
|
||||
{
|
||||
static bNodeType ntype;
|
||||
geo_node_type_base(&ntype, GEO_NODE_CURVE_PRIMITIVE_LINE, "Curve Line", NODE_CLASS_GEOMETRY, 0);
|
||||
node_type_socket_templates(
|
||||
&ntype, geo_node_curve_primitive_line_in, geo_node_curve_primitive_line_out);
|
||||
node_type_init(&ntype, blender::nodes::geo_node_curve_primitive_line_init);
|
||||
node_type_update(&ntype, blender::nodes::geo_node_curve_primitive_line_update);
|
||||
node_type_storage(&ntype,
|
||||
"NodeGeometryCurvePrimitiveLine",
|
||||
node_free_standard_storage,
|
||||
node_copy_standard_storage);
|
||||
ntype.geometry_node_execute = blender::nodes::geo_node_curve_primitive_line_exec;
|
||||
ntype.draw_buttons = geo_node_curve_primitive_line_layout;
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
Loading…
Reference in New Issue