Blender V5.3
node_geo_mesh_primitive_uv_sphere.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_material.hh"
6
8
10
12
14{
15 b.add_input<decl::Int>("Segments"_ustr)
16 .default_value(32)
17 .min(3)
18 .max(1024)
19 .description("Horizontal resolution of the sphere");
20 b.add_input<decl::Int>("Rings"_ustr)
21 .default_value(16)
22 .min(2)
23 .max(1024)
24 .description("The number of horizontal rings");
25 b.add_input<decl::Float>("Radius"_ustr)
26 .default_value(1.0f)
27 .min(0.0f)
29 .description("Distance from the generated points to the origin");
30 b.add_output<decl::Geometry>("Mesh"_ustr);
31 b.add_output<decl::Vector>("UV Map"_ustr).anonymous_attribute_output();
32}
33
35{
36 const int segments_num = params.extract_input<int>("Segments"_ustr);
37 const int rings_num = params.extract_input<int>("Rings"_ustr);
38 if (segments_num < 3 || rings_num < 2) {
39 if (segments_num < 3) {
40 params.error_message_add(NodeWarningType::Info, TIP_("Segments must be at least 3"));
41 }
42 if (rings_num < 3) {
43 params.error_message_add(NodeWarningType::Info, TIP_("Rings must be at least 3"));
44 }
46 return;
47 }
48
49 const float radius = params.extract_input<float>("Radius"_ustr);
50
51 std::optional<std::string> uv_map_id = params.get_output_anonymous_attribute_id_if_needed(
52 "UV Map"_ustr);
53
54 Mesh *mesh = geometry::create_uv_sphere_mesh(radius, segments_num, rings_num, uv_map_id);
56 params.set_output("Mesh"_ustr, GeometrySet::from_mesh(mesh));
57}
58
59static void node_register()
60{
61 static bke::bNodeType ntype;
62
63 geo_node_type_base(&ntype, "GeometryNodeMeshUVSphere"_ustr, GEO_NODE_MESH_PRIMITIVE_UV_SPHERE);
64 ntype.ui_name = "UV Sphere";
65 ntype.ui_description =
66 "Generate a spherical mesh with quads, except for triangles at the top and bottom";
67 ntype.enum_name_legacy = "MESH_PRIMITIVE_UV_SPHERE";
69 ntype.declare = node_declare;
72}
74
75} // namespace blender::nodes::node_geo_mesh_primitive_uv_sphere_cc
General operations, lookup, etc. for materials.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define GEO_NODE_MESH_PRIMITIVE_UV_SPHERE
#define TIP_(msgid)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
void error_message_add(const NodeWarningType type, StringRef message) const
std::optional< std::string > get_output_anonymous_attribute_id_if_needed(const UString output_identifier, const bool force_create=false)
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
Mesh * create_uv_sphere_mesh(float radius, int segments, int rings, std::optional< StringRef > uv_map_id)
void BKE_id_material_eval_ensure_default_slot(ID *id)
@ PROP_DISTANCE
Definition RNA_types.hh:313
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
static GeometrySet from_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)