[Bf-blender-cvs] [5f9bec93e66] geometry-nodes-mesh-primitives: Add working cone node based on cylinder code

Hans Goudey noreply at git.blender.org
Thu Mar 11 23:15:12 CET 2021


Commit: 5f9bec93e665ec998522c2e04a34de92c1742b3b
Author: Hans Goudey
Date:   Thu Mar 11 15:47:57 2021 -0500
Branches: geometry-nodes-mesh-primitives
https://developer.blender.org/rB5f9bec93e665ec998522c2e04a34de92c1742b3b

Add working cone node based on cylinder code

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

M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/node.cc
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
M	source/blender/nodes/geometry/node_geometry_util.hh
A	source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc
M	source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cylinder.cc

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

diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index e4eb95dbedd..ba55b2bc02a 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1377,6 +1377,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_MESH_PRIMITIVE_UV_SPHERE 1032
 #define GEO_NODE_MESH_PRIMITIVE_CYLINDER 1033
 #define GEO_NODE_MESH_PRIMITIVE_ICO_SPHERE 1034
+#define GEO_NODE_MESH_PRIMITIVE_CONE 1035
 
 /** \} */
 
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 6a3a2a2831e..2de5543b276 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -4805,6 +4805,7 @@ static void registerGeometryNodes()
   register_node_type_geo_is_viewport();
   register_node_type_geo_join_geometry();
   register_node_type_geo_mesh_primitive_circle();
+  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();
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 5dc5425cca4..e09a1ef38cf 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1236,6 +1236,11 @@ typedef struct NodeGeometryMeshCylinder {
   uint8_t fill_type;
 } NodeGeometryMeshCylinder;
 
+typedef struct NodeGeometryMeshCone {
+  /* GeometryNodeMeshCircleFillType. */
+  uint8_t fill_type;
+} NodeGeometryMeshCone;
+
 /* script node mode */
 #define NODE_SCRIPT_INTERNAL 0
 #define NODE_SCRIPT_EXTERNAL 1
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 6f222e8da1b..dd2924234ea 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -401,7 +401,7 @@ static const EnumPropertyItem prop_shader_output_target_items[] = {
 static EnumPropertyItem rna_node_geometry_mesh_circle_fill_type_items[] = {
     {GEO_NODE_MESH_CIRCLE_FILL_NONE, "NONE", 0, "None", ""},
     {GEO_NODE_MESH_CIRCLE_FILL_NGON, "NGON", 0, "N-Gon", ""},
-    {GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN, "TRIANGLE_FAN", 0, "Triangle Fan", ""},
+    {GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN, "TRIANGLE_FAN", 0, "Triangles", ""},
     {0, NULL, 0, NULL, NULL},
 };
 
@@ -9219,6 +9219,18 @@ static void def_geo_mesh_cylinder(StructRNA *srna)
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
+static void def_geo_mesh_cone(StructRNA *srna)
+{
+  PropertyRNA *prop;
+
+  RNA_def_struct_sdna_from(srna, "NodeGeometryMeshCone", "storage");
+
+  prop = RNA_def_property(srna, "fill_type", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, rna_node_geometry_mesh_circle_fill_type_items);
+  RNA_def_property_ui_text(prop, "Fill Type", "");
+  RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+}
+
 /* -------------------------------------------------------------------------- */
 
 static void rna_def_shader_node(BlenderRNA *brna)
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index d119a4c4450..743aaad84a2 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -161,6 +161,7 @@ set(SRC
   geometry/nodes/node_geo_is_viewport.cc
   geometry/nodes/node_geo_join_geometry.cc
   geometry/nodes/node_geo_mesh_primitive_circle.cc
+  geometry/nodes/node_geo_mesh_primitive_cone.cc
   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
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index 30dcf88b753..29d70dc06a9 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -43,6 +43,7 @@ void register_node_type_geo_edge_split(void);
 void register_node_type_geo_is_viewport(void);
 void register_node_type_geo_join_geometry(void);
 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);
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 9bfbc9afd80..c5a1ec1a786 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -304,6 +304,7 @@ DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_CIRCLE, def_geo_mesh_circle, "MESH
 DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_UV_SPHERE, 0, "MESH_PRIMITIVE_UV_SPHERE", MeshUVSphere, "UV Sphere", "")
 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", "")
 
 /* undefine macros */
 #undef DefNode
diff --git a/source/blender/nodes/geometry/node_geometry_util.hh b/source/blender/nodes/geometry/node_geometry_util.hh
index ea78611d0dd..fb80bd08797 100644
--- a/source/blender/nodes/geometry/node_geometry_util.hh
+++ b/source/blender/nodes/geometry/node_geometry_util.hh
@@ -52,4 +52,10 @@ void transform_mesh(Mesh *mesh,
                     const float3 rotation,
                     const float3 scale);
 
+Mesh *create_cylinder_or_cone_mesh(const float radius_top,
+                                   const float radius_bottom,
+                                   const float depth,
+                                   const int verts_num,
+                                   const GeometryNodeMeshCircleFillType fill_type);
+
 }  // namespace blender::nodes
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc
new file mode 100644
index 00000000000..ad4408490da
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc
@@ -0,0 +1,112 @@
+/*
+ * 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_cone_in[] = {
+    {SOCK_INT, N_("Vertices"), 32, 0.0f, 0.0f, 0.0f, 3, 4096},
+    {SOCK_FLOAT, N_("Radius Top"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX, PROP_DISTANCE},
+    {SOCK_FLOAT, N_("Radius Bottom"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX, PROP_DISTANCE},
+    {SOCK_FLOAT, N_("Depth"), 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_cone_out[] = {
+    {SOCK_GEOMETRY, N_("Geometry")},
+    {-1, ""},
+};
+
+static void geo_node_mesh_primitive_cone_layout(uiLayout *layout,
+                                                bContext *UNUSED(C),
+                                                PointerRNA *ptr)
+{
+  uiLayoutSetPropSep(layout, true);
+  uiLayoutSetPropDecorate(layout, false);
+  uiItemR(layout, ptr, "fill_type", 0, IFACE_("Fill"), ICON_NONE);
+}
+
+static void geo_node_mesh_primitive_cone_init(bNodeTree *UNUSED(ntree), bNode *node)
+{
+  NodeGeometryMeshCone *node_storage = (NodeGeometryMeshCone *)MEM_callocN(
+      sizeof(NodeGeometryMeshCone), __func__);
+
+  node_storage->fill_type = GEO_NODE_MESH_CIRCLE_FILL_NGON;
+
+  node->storage = node_storage;
+}
+
+namespace blender::nodes {
+
+static void geo_node_mesh_primitive_cone_exec(GeoNodeExecParams params)
+{
+  const bNode &node = params.node();
+  const NodeGeometryMeshCone &storage = *(const NodeGeometryMeshCone *)node.storage;
+
+  const GeometryNodeMeshCircleFillType fill_type = (const GeometryNodeMeshCircleFillType)
+                                                       storage.fill_type;
+
+  const int verts_num = params.extract_input<int>("Vertices");
+  if (verts_num < 3) {
+    params.set_output("Geometry", GeometrySet());
+    return;
+  }
+
+  const float radius_top = params.extract_input<float>("Radius Top");
+  const float radius_bottom = params.extract_input<float>("Radius Bottom");
+  const float depth = params.extract_input<float>("Depth");
+  const float3 location = params.extract_input<float3>("Location");
+  const float3 rotation = params.extract_input<float3>("Rotation");
+
+  Mesh *mesh = create_cylinder_or_cone_mesh(
+      radius_top, radius_bottom, depth, verts_num, fill_type);
+
+  BLI_assert(BKE_mesh_is_valid(mesh));
+
+  /* Transform the mesh so that the base of the cone is at the origin. */
+  transform_mesh(mesh, location + float3(0.0f, 0.0f, depth), rotation, float3(1));
+
+  params.set_output("Geometry", GeometrySet::create_with_mesh(mesh));
+}
+
+}  // namespace blender::nodes
+
+void register_node_type_geo_mesh_primitive_cone()
+{
+  static bNodeType ntype;
+
+  geo_node_type_base(&ntype, GEO_NODE_MESH_PRIMITIVE_CONE, "Cone", NODE_CLASS_GEOMETRY, 0);
+  node_type_so

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list