Blender  V3.3
node_geo_mesh_primitive_ico_sphere.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "DNA_mesh_types.h"
4 
5 #include "BKE_lib_id.h"
6 #include "BKE_material.h"
7 #include "BKE_mesh.h"
8 
9 #include "bmesh.h"
10 
11 #include "node_geometry_util.hh"
12 
14 
16 {
17  b.add_input<decl::Float>(N_("Radius"))
18  .default_value(1.0f)
19  .min(0.0f)
20  .subtype(PROP_DISTANCE)
21  .description(N_("Distance from the generated points to the origin"));
22  b.add_input<decl::Int>(N_("Subdivisions"))
23  .default_value(1)
24  .min(1)
25  .max(7)
26  .description(N_("Number of subdivisions on top of the basic icosahedron"));
27  b.add_output<decl::Geometry>(N_("Mesh"));
28 }
29 
30 static Mesh *create_ico_sphere_mesh(const int subdivisions, const float radius)
31 {
33 
34  BMeshCreateParams bmesh_create_params{};
35  bmesh_create_params.use_toolflags = true;
36  const BMAllocTemplate allocsize = {0, 0, 0, 0};
37  BMesh *bm = BM_mesh_create(&allocsize, &bmesh_create_params);
39 
42  "create_icosphere subdivisions=%i radius=%f matrix=%m4 calc_uvs=%b",
43  subdivisions,
44  std::abs(radius),
45  transform.values,
46  true);
47 
49  params.calc_object_remap = false;
50  Mesh *mesh = (Mesh *)BKE_id_new_nomain(ID_ME, nullptr);
52  BM_mesh_bm_to_me(nullptr, bm, mesh, &params);
54 
55  return mesh;
56 }
57 
59 {
60  const int subdivisions = std::min(params.extract_input<int>("Subdivisions"), 10);
61  const float radius = params.extract_input<float>("Radius");
62 
63  Mesh *mesh = create_ico_sphere_mesh(subdivisions, radius);
64  params.set_output("Mesh", GeometrySet::create_with_mesh(mesh));
65 }
66 
67 } // namespace blender::nodes::node_geo_mesh_primitive_ico_sphere_cc
68 
70 {
72 
73  static bNodeType ntype;
74 
79  nodeRegisterType(&ntype);
80 }
void * BKE_id_new_nomain(short type, const char *name)
Definition: lib_id.c:1173
General operations, lookup, etc. for materials.
void BKE_id_material_eval_ensure_default_slot(struct ID *id)
Definition: material.c:784
#define GEO_NODE_MESH_PRIMITIVE_ICO_SPHERE
Definition: BKE_node.h:1395
#define NODE_CLASS_GEOMETRY
Definition: BKE_node.h:359
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
@ ID_ME
Definition: DNA_ID_enums.h:48
@ CD_MLOOPUV
@ PROP_DISTANCE
Definition: RNA_types.h:149
void BM_data_layer_add_named(BMesh *bm, CustomData *data, int type, const char *name)
Definition: bmesh_interp.c:857
ATTR_WARN_UNUSED_RESULT BMesh * bm
void BM_mesh_free(BMesh *bm)
BMesh Free Mesh.
Definition: bmesh_mesh.cc:258
BMesh * BM_mesh_create(const BMAllocTemplate *allocsize, const struct BMeshCreateParams *params)
Definition: bmesh_mesh.cc:125
void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMeshParams *params)
bool BMO_op_callf(BMesh *bm, int flag, const char *fmt,...)
#define BMO_FLAG_DEFAULTS
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
T abs(const T &a)
static Mesh * create_ico_sphere_mesh(const int subdivisions, const float radius)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_geo_mesh_primitive_ico_sphere()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
#define min(a, b)
Definition: sort.c:35
CustomData ldata
Definition: bmesh_class.h:337
static GeometrySet create_with_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Defines a node type.
Definition: BKE_node.h:226
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:316
NodeDeclareFunction declare
Definition: BKE_node.h:324
static float4x4 identity()
Definition: BLI_float4x4.hh:80
#define N_(msgid)