[Bf-blender-cvs] [ca8d1900ff8] geometry-nodes-mesh-primitives: Shell for UV sphere code
Hans Goudey
noreply at git.blender.org
Thu Mar 11 23:15:08 CET 2021
Commit: ca8d1900ff8ef0689095f6fb358878d3378d2c6f
Author: Hans Goudey
Date: Tue Feb 23 07:59:10 2021 -0600
Branches: geometry-nodes-mesh-primitives
https://developer.blender.org/rBca8d1900ff8ef0689095f6fb358878d3378d2c6f
Shell for UV sphere code
===================================================================
M source/blender/blenkernel/BKE_node.h
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_uv_sphere.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 81c45776bd0..c756ad6e667 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1375,6 +1375,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
#define GEO_NODE_SUBDIVISION_SURFACE_SIMPLE 1029
#define GEO_NODE_MESH_PRIMITIVE_CUBE 1030
#define GEO_NODE_MESH_PRIMITIVE_CIRCLE 1031
+#define GEO_NODE_MESH_PRIMITIVE_UV_SPHERE 1032
/** \} */
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 1e0322d1d89..4fe9c2cbc92 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -162,6 +162,7 @@ set(SRC
geometry/nodes/node_geo_join_geometry.cc
geometry/nodes/node_geo_mesh_primitive_circle.cc
geometry/nodes/node_geo_mesh_primitive_cube.cc
+ geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc
geometry/nodes/node_geo_object_info.cc
geometry/nodes/node_geo_point_distribute.cc
geometry/nodes/node_geo_point_instance.cc
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index 2f0d2fb8544..0a37218cf29 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -44,6 +44,7 @@ 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_cube(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 5bebec5c56d..addcbd24beb 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -301,6 +301,7 @@ DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_SEPARATE_XYZ, def_geo_attribute_separat
DefNode(GeometryNode, GEO_NODE_SUBDIVISION_SURFACE_SIMPLE, 0, "SUBDIVISION_SURFACE_SIMPLE", SubdivisionSurfaceSimple, "Simple Subdivision Surface", "")
DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_CUBE, 0, "MESH_PRIMITIVE_CUBE", MeshCube, "Cube", "")
DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_CIRCLE, def_geo_mesh_circle, "MESH_PRIMITIVE_CIRCLE", MeshCircle, "Circle", "")
+DefNode(GeometryNode, GEO_NODE_MESH_PRIMITIVE_UV_SPHERE, 0, "MESH_PRIMITIVE_UV_SPHERE", MeshUVSphere, "UV Sphere", "")
/* undefine macros */
#undef DefNode
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc
new file mode 100644
index 00000000000..8a7e57239d8
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc
@@ -0,0 +1,131 @@
+/*
+ * 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_uv_sphere_in[] = {
+ {SOCK_INT, N_("Segments"), 32, 0.0f, 0.0f, 0.0f, 3, 1024},
+ {SOCK_INT, N_("Rings"), 16, 0.0f, 0.0f, 0.0f, 3, 1024},
+ {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_uv_sphere_out[] = {
+ {SOCK_GEOMETRY, N_("Geometry")},
+ {-1, ""},
+};
+
+namespace blender::nodes {
+
+static int vert_total(const int segments, const int rings)
+{
+ return 0;
+}
+
+static int edge_total(const int segments, const int rings)
+{
+ return 0;
+}
+
+static int corner_total(const int segments, const int rings)
+{
+ return 0;
+}
+
+static int face_total(const int segments, const int rings)
+{
+ return 0;
+}
+
+static Mesh *create_uv_sphere_mesh(const float3 location,
+ const float3 rotation,
+ const float radius,
+ const int segments,
+ const int rings)
+{
+ float4x4 transform;
+ loc_eul_size_to_mat4(transform.values, location, rotation, float3(1.0f));
+
+ Mesh *mesh = BKE_mesh_new_nomain(vert_total(segments, rings),
+ edge_total(segments, rings),
+ 0,
+ corner_total(segments, rings),
+ face_total(segments, rings));
+ MutableSpan<MVert> verts = MutableSpan<MVert>(mesh->mvert, mesh->totvert);
+ MutableSpan<MEdge> edges = MutableSpan<MEdge>(mesh->medge, mesh->totedge);
+ MutableSpan<MLoop> loops = MutableSpan<MLoop>(mesh->mloop, mesh->totloop);
+ MutableSpan<MPoly> polys = MutableSpan<MPoly>(mesh->mpoly, mesh->totpoly);
+
+ BLI_assert(BKE_mesh_is_valid(mesh));
+
+ return mesh;
+}
+
+static void geo_node_mesh_primitive_uv_sphere_exec(GeoNodeExecParams params)
+{
+ GeometrySet geometry_set;
+
+ const bNode &node = params.node();
+
+ const int segments_num = params.extract_input<int>("Vertices");
+ const int rings_num = params.extract_input<int>("Vertices");
+ if (segments_num < 3 || rings_num < 3) {
+ params.set_output("Geometry", geometry_set);
+ 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");
+
+ if (rotation.length_squared() == 0.0f) {
+ params.error_message_add(NodeWarningType::Warning, "Rotation is zero");
+ }
+ const float3 rotation_normalized = rotation.length_squared() == 0.0f ? float3(0.0f, 0.0f, 1.0f) :
+ rotation.normalized();
+
+ geometry_set.replace_mesh(
+ create_uv_sphere_mesh(location, rotation_normalized, radius, segments_num, rings_num));
+
+ params.set_output("Geometry", geometry_set);
+}
+
+} // namespace blender::nodes
+
+void register_node_type_geo_mesh_primitive_uv_sphere()
+{
+ static bNodeType ntype;
+
+ geo_node_type_base(
+ &ntype, GEO_NODE_MESH_PRIMITIVE_UV_SPHERE, "UV Sphere", NODE_CLASS_GEOMETRY, 0);
+ node_type_socket_templates(
+ &ntype, geo_node_mesh_primitive_uv_sphere_in, geo_node_mesh_primitive_uv_sphere_out);
+ ntype.geometry_node_execute = blender::nodes::geo_node_mesh_primitive_uv_sphere_exec;
+ nodeRegisterType(&ntype);
+}
More information about the Bf-blender-cvs
mailing list