[Bf-blender-cvs] [36397a721a6] temp-geometry-nodes-mesh-primitive-line: Add boilerplate code for a line primitive

Hans Goudey noreply at git.blender.org
Sun Mar 14 00:04:13 CET 2021


Commit: 36397a721a6b467c6a06e1ccea2f538fb7731b64
Author: Hans Goudey
Date:   Sat Mar 13 18:04:07 2021 -0500
Branches: temp-geometry-nodes-mesh-primitive-line
https://developer.blender.org/rB36397a721a6b467c6a06e1ccea2f538fb7731b64

Add boilerplate code for a line primitive

===================================================================

M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenkernel/BKE_node.h
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/NOD_geometry.h
M	source/blender/nodes/NOD_static_types.h
A	source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc

===================================================================

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index b37f6b7b6bf..0925445942e 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -527,6 +527,7 @@ geometry_node_categories = [
         NodeItem("GeometryNodeMeshIcoSphere"),
         NodeItem("GeometryNodeMeshCylinder"),
         NodeItem("GeometryNodeMeshCone"),
+        NodeItem("GeometryNodeMeshLine")
         # NodeItem("GeometryNodeMeshPlane"),
         # NodeItem("GeometryNodeMeshGrid"),
     ]),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index d65c7e81009..15fc52e7cc3 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -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
 
 /** \} */
 
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 9a4b52b6782..74a9f094247 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1249,6 +1249,11 @@ typedef struct NodeGeometryMeshCone {
   uint8_t fill_type;
 } NodeGeometryMeshCone;
 
+typedef struct NodeGeometryMeshLine {
+  /* GeometryNodeMeshLineMode. */
+  uint8_t mode;
+} NodeGeometryMeshLine;
+
 /* script node mode */
 #define NODE_SCRIPT_INTERNAL 0
 #define NODE_SCRIPT_EXTERNAL 1
@@ -1731,6 +1736,11 @@ typedef enum GeometryNodeMeshCircleFillType {
   GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN = 2,
 } GeometryNodeMeshCircleFillType;
 
+typedef enum GeometryNodeMeshLineMode {
+  GEO_NODE_MESH_LINE_MODE_START_END = 0,
+  GEO_NODE_MESH_LINE_MODE_DIRECTION = 1,
+} GeometryNodeMeshLineMode;
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 7ed0a0e952d..fd726b82d35 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -9277,6 +9277,18 @@ 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;
+
+  RNA_def_struct_sdna_from(srna, "NodeGeometryMeshLine", "storage");
+
+  prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, rna_node_geometry_mesh_circle_fill_type_items);
+  RNA_def_property_ui_text(prop, "Mode", "");
+  RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
+}
+
 /* -------------------------------------------------------------------------- */
 
 static void rna_def_shader_node(BlenderRNA *brna)
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 2c673004070..697647e7b2d 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -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
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index ec2fa2de2ec..8ecda078b46 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -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);
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 147a4a496b0..50f45859d1a 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -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
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
new file mode 100644
index 00000000000..da02d796ffd
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
@@ -0,0 +1,130 @@
+/*
+ * 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_("Vertices"), 32, 0.0f, 0.0f, 0.0f, 3, 4096},
+    // {SOCK_FLOAT, N_("Radius"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX, PROP_DISTANCE},
+    // {SOCK_VECTOR, N_("Location"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_TRANSLATION},
+    // {SOCK_VECTOR, N_("Rotation"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_EULER},
+    {-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, nullptr, 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_DIRECTION;
+
+  node->storage = node_storage;
+}
+
+namespace blender::nodes {
+
+static int line_vert_total(const GeometryNodeMeshLineMode fill_type, const int verts_num)
+{
+  return 0;
+}
+
+static int line_edge_total(const GeometryNodeMeshLineMode fill_type, const int verts_num)
+{
+  return 0;
+}
+
+static Mesh *create_line_mesh(const float radius,
+                              const int verts_num,
+                              const GeometryNodeMeshLineMode fill_type)
+{
+  Mesh *mesh = BKE_mesh_new_nomain(
+      line_vert_total(fill_type, verts_num), line_edge_total(fill_type, verts_num), 0, 0, 0);
+  MutableSpan<MVert> verts = MutableSpan<MVert>(mesh->mvert, mesh->totvert);
+  MutableSpan<MEdge> edges = MutableSpan<MEdge>(mesh->medge, mesh->totedge);
+
+  /* Set loose edge flags. */
+  for (const int i : IndexRange(verts_num)) {
+    MEdge &edge = edges[i];
+    edge.flag |= ME_LOOSEEDGE;
+  }
+
+  BLI_assert(BKE_mesh_is_valid(mesh));
+
+  return mesh;
+}
+
+static void geo_node_mesh_primitive_line_exec(GeoNodeExecParams params)
+{
+  const NodeGeometryMeshLine &storage = *(const NodeGeometryMeshLine *)params.node().storage;
+  const GeometryNodeMeshLineMode fill_type = (const GeometryNodeMeshLineMode)storage.mode;
+
+  const int verts_num = params.extract_input<int>("Vertices");
+  if (verts_num < 3) {
+    params.set_output("Geometry", GeometrySet());
+    return;
+  }
+
+  const float radius = params.extract_input<float>("Radius");
+  const float3 location = params.extract_input<float3>("Location");
+  const float3 rotation = params.extract_input<float3>("Rotation");
+
+  Mesh *mesh = create_line_mesh(radius, verts_num, fill_type);
+  BLI_assert(BKE_mesh_is_valid(mesh));
+
+  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_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);
+}



More information about the Bf-blender-cvs mailing list