Blender V4.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.h"
6
8
10
12
14{
15 b.add_input<decl::Int>("Segments")
16 .default_value(32)
17 .min(3)
18 .max(1024)
19 .description("Horizontal resolution of the sphere");
20 b.add_input<decl::Int>("Rings").default_value(16).min(2).max(1024).description(
21 "The number of horizontal rings");
22 b.add_input<decl::Float>("Radius")
23 .default_value(1.0f)
24 .min(0.0f)
26 .description("Distance from the generated points to the origin");
27 b.add_output<decl::Geometry>("Mesh");
28 b.add_output<decl::Vector>("UV Map").field_on_all();
29}
30
32{
33 const int segments_num = params.extract_input<int>("Segments");
34 const int rings_num = params.extract_input<int>("Rings");
35 if (segments_num < 3 || rings_num < 2) {
36 if (segments_num < 3) {
37 params.error_message_add(NodeWarningType::Info, TIP_("Segments must be at least 3"));
38 }
39 if (rings_num < 3) {
40 params.error_message_add(NodeWarningType::Info, TIP_("Rings must be at least 3"));
41 }
42 params.set_default_remaining_outputs();
43 return;
44 }
45
46 const float radius = params.extract_input<float>("Radius");
47
48 std::optional<std::string> uv_map_id = params.get_output_anonymous_attribute_id_if_needed(
49 "UV Map");
50
51 Mesh *mesh = geometry::create_uv_sphere_mesh(radius, segments_num, rings_num, uv_map_id);
52 BKE_id_material_eval_ensure_default_slot(reinterpret_cast<ID *>(mesh));
53 params.set_output("Mesh", GeometrySet::from_mesh(mesh));
54}
55
56static void node_register()
57{
58 static blender::bke::bNodeType ntype;
59
60 geo_node_type_base(&ntype, GEO_NODE_MESH_PRIMITIVE_UV_SPHERE, "UV Sphere", NODE_CLASS_GEOMETRY);
61 ntype.declare = node_declare;
64}
66
67} // namespace blender::nodes::node_geo_mesh_primitive_uv_sphere_cc
General operations, lookup, etc. for materials.
void BKE_id_material_eval_ensure_default_slot(struct ID *id)
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
#define TIP_(msgid)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_DISTANCE
Definition RNA_types.hh:159
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
Mesh * create_uv_sphere_mesh(float radius, int segments, int rings, const std::optional< StringRef > &uv_map_id)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
Definition DNA_ID.h:413
static GeometrySet from_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Defines a node type.
Definition BKE_node.hh:218
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
NodeDeclareFunction declare
Definition BKE_node.hh:347