Compare commits

...

3 Commits

9 changed files with 254 additions and 2 deletions

View File

@@ -527,6 +527,7 @@ geometry_node_categories = [
NodeItem("GeometryNodeMeshIcoSphere"),
NodeItem("GeometryNodeMeshCylinder"),
NodeItem("GeometryNodeMeshCone"),
NodeItem("GeometryNodeMeshLine")
# NodeItem("GeometryNodeMeshPlane"),
# NodeItem("GeometryNodeMeshGrid"),
]),

View File

@@ -1380,6 +1380,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
#define GEO_NODE_MESH_PRIMITIVE_CYLINDER 1035
#define GEO_NODE_MESH_PRIMITIVE_ICO_SPHERE 1036
#define GEO_NODE_MESH_PRIMITIVE_CONE 1037
#define GEO_NODE_MESH_PRIMITIVE_LINE 1038
/** \} */

View File

@@ -4810,8 +4810,9 @@ static void registerGeometryNodes()
register_node_type_geo_mesh_primitive_cone();
register_node_type_geo_mesh_primitive_cube();
register_node_type_geo_mesh_primitive_cylinder();
register_node_type_geo_mesh_primitive_uv_sphere();
register_node_type_geo_mesh_primitive_ico_sphere();
register_node_type_geo_mesh_primitive_line();
register_node_type_geo_mesh_primitive_uv_sphere();
register_node_type_geo_object_info();
register_node_type_geo_point_distribute();
register_node_type_geo_point_instance();

View File

@@ -1249,6 +1249,13 @@ typedef struct NodeGeometryMeshCone {
uint8_t fill_type;
} NodeGeometryMeshCone;
typedef struct NodeGeometryMeshLine {
/* GeometryNodeMeshLineMode. */
uint8_t mode;
/* GeometryNodeMeshLineCountMode. */
uint8_t count_mode;
} NodeGeometryMeshLine;
/* script node mode */
#define NODE_SCRIPT_INTERNAL 0
#define NODE_SCRIPT_EXTERNAL 1
@@ -1731,6 +1738,16 @@ typedef enum GeometryNodeMeshCircleFillType {
GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN = 2,
} GeometryNodeMeshCircleFillType;
typedef enum GeometryNodeMeshLineMode {
GEO_NODE_MESH_LINE_MODE_END_POINTS = 0,
GEO_NODE_MESH_LINE_MODE_OFFSET = 1,
} GeometryNodeMeshLineMode;
typedef enum GeometryNodeMeshLineCountMode {
GEO_NODE_MESH_LINE_COUNT_TOTAL = 0,
GEO_NODE_MESH_LINE_COUNT_RESOLUTION = 1,
} GeometryNodeMeshLineCountMode;
#ifdef __cplusplus
}
#endif

View File

@@ -9277,6 +9277,51 @@ static void def_geo_mesh_cone(StructRNA *srna)
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
static void def_geo_mesh_line(StructRNA *srna)
{
PropertyRNA *prop;
static EnumPropertyItem mode_items[] = {
{GEO_NODE_MESH_LINE_MODE_OFFSET,
"OFFSET",
0,
"Offset",
"Specify the offset from one vertex to the next"},
{GEO_NODE_MESH_LINE_MODE_END_POINTS,
"END_POINTS",
0,
"End Points",
"Specify the line's start and end points"},
{0, NULL, 0, NULL, NULL},
};
static EnumPropertyItem count_mode_items[] = {
{GEO_NODE_MESH_LINE_COUNT_TOTAL,
"TOTAL",
0,
"Count",
"Specify the total number of vertices"},
{GEO_NODE_MESH_LINE_COUNT_RESOLUTION,
"RESOLUTION",
0,
"Resolution",
"Specify the distance between vertices"},
{0, NULL, 0, NULL, NULL},
};
RNA_def_struct_sdna_from(srna, "NodeGeometryMeshLine", "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", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
prop = RNA_def_property(srna, "count_mode", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, count_mode_items);
RNA_def_property_ui_text(prop, "Count Mode", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
}
/* -------------------------------------------------------------------------- */
static void rna_def_shader_node(BlenderRNA *brna)

View File

@@ -167,6 +167,7 @@ set(SRC
geometry/nodes/node_geo_mesh_primitive_cube.cc
geometry/nodes/node_geo_mesh_primitive_cylinder.cc
geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
geometry/nodes/node_geo_mesh_primitive_line.cc
geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc
geometry/nodes/node_geo_object_info.cc
geometry/nodes/node_geo_point_distribute.cc

View File

@@ -48,8 +48,9 @@ void register_node_type_geo_mesh_primitive_circle(void);
void register_node_type_geo_mesh_primitive_cone(void);
void register_node_type_geo_mesh_primitive_cube(void);
void register_node_type_geo_mesh_primitive_cylinder(void);
void register_node_type_geo_mesh_primitive_uv_sphere(void);
void register_node_type_geo_mesh_primitive_ico_sphere(void);
void register_node_type_geo_mesh_primitive_line(void);
void register_node_type_geo_mesh_primitive_uv_sphere(void);
void register_node_type_geo_object_info(void);
void register_node_type_geo_point_distribute(void);
void register_node_type_geo_point_instance(void);

View File

@@ -307,6 +307,7 @@ DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_UV_SPHERE, 0, "MESH_PRIMITIVE_UV_S
DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_CYLINDER, def_geo_mesh_cylinder, "MESH_PRIMITIVE_CYLINDER", MeshCylinder, "Cylinder", "")
DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_ICO_SPHERE, 0, "MESH_PRIMITIVE_ICO_SPHERE", MeshIcoSphere, "Ico Sphere", "")
DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_CONE, def_geo_mesh_cone, "MESH_PRIMITIVE_CONE", MeshCone, "Cone", "")
DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_LINE, def_geo_mesh_line, "MESH_PRIMITIVE_LINE", MeshLine, "Line", "")
/* undefine macros */
#undef DefNode

View File

@@ -0,0 +1,184 @@
/*
* 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 "BLI_map.hh"
#include "BLI_math_matrix.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "BKE_mesh.h"
#include "UI_interface.h"
#include "UI_resources.h"
#include "node_geometry_util.hh"
static bNodeSocketTemplate geo_node_mesh_primitive_line_in[] = {
{SOCK_INT, N_("Count"), 10, 0.0f, 0.0f, 0.0f, 1, 10000},
{SOCK_FLOAT, N_("Resolution"), 1.0f, 0.0f, 0.0f, 0.0f, 0.01f, FLT_MAX, PROP_DISTANCE},
{SOCK_VECTOR,
N_("Start Location"),
0.0f,
0.0f,
0.0f,
1.0f,
-FLT_MAX,
FLT_MAX,
PROP_TRANSLATION},
{SOCK_VECTOR, N_("End Location"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_TRANSLATION},
{SOCK_VECTOR, N_("Offset"), 1.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_TRANSLATION},
{-1, ""},
};
static bNodeSocketTemplate geo_node_mesh_primitive_line_out[] = {
{SOCK_GEOMETRY, N_("Geometry")},
{-1, ""},
};
static void geo_node_mesh_primitive_line_layout(uiLayout *layout,
bContext *UNUSED(C),
PointerRNA *ptr)
{
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
if (RNA_enum_get(ptr, "mode") == GEO_NODE_MESH_LINE_MODE_END_POINTS) {
uiItemR(layout, ptr, "count_mode", 0, "", ICON_NONE);
}
}
static void geo_node_mesh_primitive_line_init(bNodeTree *UNUSED(ntree), bNode *node)
{
NodeGeometryMeshLine *node_storage = (NodeGeometryMeshLine *)MEM_callocN(
sizeof(NodeGeometryMeshLine), __func__);
node_storage->mode = GEO_NODE_MESH_LINE_MODE_OFFSET;
node_storage->count_mode = GEO_NODE_MESH_LINE_COUNT_TOTAL;
node->storage = node_storage;
}
static void geo_node_mesh_primitive_line_update(bNodeTree *UNUSED(tree), bNode *node)
{
bNodeSocket *count_socket = (bNodeSocket *)node->inputs.first;
bNodeSocket *resolution_socket = count_socket->next;
bNodeSocket *start_socket = resolution_socket->next;
bNodeSocket *end_socket = start_socket->next;
bNodeSocket *offset_socket = end_socket->next;
const NodeGeometryMeshLine &storage = *(const NodeGeometryMeshLine *)node->storage;
const GeometryNodeMeshLineMode mode = (const GeometryNodeMeshLineMode)storage.mode;
const GeometryNodeMeshLineCountMode count_mode = (const GeometryNodeMeshLineCountMode)
storage.count_mode;
nodeSetSocketAvailability(end_socket, mode == GEO_NODE_MESH_LINE_MODE_END_POINTS);
nodeSetSocketAvailability(resolution_socket,
mode == GEO_NODE_MESH_LINE_MODE_END_POINTS &&
count_mode == GEO_NODE_MESH_LINE_COUNT_RESOLUTION);
nodeSetSocketAvailability(count_socket,
mode == GEO_NODE_MESH_LINE_MODE_OFFSET ||
count_mode == GEO_NODE_MESH_LINE_COUNT_TOTAL);
nodeSetSocketAvailability(offset_socket, mode == GEO_NODE_MESH_LINE_MODE_OFFSET);
}
namespace blender::nodes {
static void fill_edge_data(MutableSpan<MEdge> edges)
{
for (const int i : edges.index_range()) {
edges[i].v1 = i;
edges[i].v2 = i + 1;
edges[i].flag |= ME_LOOSEEDGE;
}
}
static Mesh *create_line_mesh(const float3 start, const float3 delta, const int count)
{
Mesh *mesh = BKE_mesh_new_nomain(count, count - 1, 0, 0, 0);
MutableSpan<MVert> verts = MutableSpan<MVert>(mesh->mvert, mesh->totvert);
MutableSpan<MEdge> edges = MutableSpan<MEdge>(mesh->medge, mesh->totedge);
short normal[3];
normal_float_to_short_v3(normal, delta.normalized());
float3 co = start;
for (const int i : verts.index_range()) {
copy_v3_v3(verts[i].co, co);
copy_v3_v3_short(verts[i].no, normal);
co += delta;
}
fill_edge_data(edges);
return mesh;
}
static void geo_node_mesh_primitive_line_exec(GeoNodeExecParams params)
{
const NodeGeometryMeshLine &storage = *(const NodeGeometryMeshLine *)params.node().storage;
const GeometryNodeMeshLineMode mode = (const GeometryNodeMeshLineMode)storage.mode;
const GeometryNodeMeshLineCountMode count_mode = (const GeometryNodeMeshLineCountMode)
storage.count_mode;
Mesh *mesh = nullptr;
const float3 start = params.extract_input<float3>("Start Location");
if (mode == GEO_NODE_MESH_LINE_MODE_END_POINTS) {
const float3 end = params.extract_input<float3>("End Location");
const float3 total_delta = end - start;
int count;
float3 delta;
if (count_mode == GEO_NODE_MESH_LINE_COUNT_RESOLUTION) {
const float resolution = params.extract_input<float>("Resolution");
count = total_delta.length() / resolution;
delta = total_delta.normalized() * resolution;
}
else if (count_mode == GEO_NODE_MESH_LINE_COUNT_TOTAL) {
count = params.extract_input<int>("Count");
delta = total_delta / count;
}
if (count > 0) {
mesh = create_line_mesh(start, delta, count);
}
}
else if (mode == GEO_NODE_MESH_LINE_MODE_OFFSET) {
const float3 delta = params.extract_input<float3>("Offset");
const int count = params.extract_input<int>("Count");
mesh = create_line_mesh(start, delta, count);
}
params.set_output("Geometry", GeometrySet::create_with_mesh(mesh));
}
} // namespace blender::nodes
void register_node_type_geo_mesh_primitive_line()
{
static bNodeType ntype;
geo_node_type_base(&ntype, GEO_NODE_MESH_PRIMITIVE_LINE, "Line", NODE_CLASS_GEOMETRY, 0);
node_type_socket_templates(
&ntype, geo_node_mesh_primitive_line_in, geo_node_mesh_primitive_line_out);
node_type_init(&ntype, geo_node_mesh_primitive_line_init);
node_type_update(&ntype, geo_node_mesh_primitive_line_update);
node_type_storage(
&ntype, "NodeGeometryMeshLine", node_free_standard_storage, node_copy_standard_storage);
ntype.geometry_node_execute = blender::nodes::geo_node_mesh_primitive_line_exec;
ntype.draw_buttons = geo_node_mesh_primitive_line_layout;
nodeRegisterType(&ntype);
}