Blender  V2.93
node_geo_mesh_primitive_ico_sphere.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #include "DNA_mesh_types.h"
18 
19 #include "BKE_lib_id.h"
20 #include "BKE_mesh.h"
21 
22 #include "bmesh.h"
23 
24 #include "node_geometry_util.hh"
25 
27  {SOCK_FLOAT, N_("Radius"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX, PROP_DISTANCE},
28  {SOCK_INT, N_("Subdivisions"), 1, 0, 0, 0, 0, 7},
29  {-1, ""},
30 };
31 
33  {SOCK_GEOMETRY, N_("Geometry")},
34  {-1, ""},
35 };
36 
37 namespace blender::nodes {
38 
39 static Mesh *create_ico_sphere_mesh(const int subdivisions, const float radius)
40 {
42 
43  const BMeshCreateParams bmcp = {true};
44  const BMAllocTemplate allocsize = {0, 0, 0, 0};
45  BMesh *bm = BM_mesh_create(&allocsize, &bmcp);
46 
49  "create_icosphere subdivisions=%i diameter=%f matrix=%m4 calc_uvs=%b",
50  subdivisions,
51  std::abs(radius),
52  transform.values,
53  true);
54 
56  params.calc_object_remap = false;
57  Mesh *mesh = (Mesh *)BKE_id_new_nomain(ID_ME, nullptr);
58  BM_mesh_bm_to_me(nullptr, bm, mesh, &params);
60 
61  return mesh;
62 }
63 
65 {
66  const int subdivisions = std::min(params.extract_input<int>("Subdivisions"), 10);
67  const float radius = params.extract_input<float>("Radius");
68 
69  Mesh *mesh = create_ico_sphere_mesh(subdivisions, radius);
70  params.set_output("Geometry", GeometrySet::create_with_mesh(mesh));
71 }
72 
73 } // namespace blender::nodes
74 
76 {
77  static bNodeType ntype;
78 
84  nodeRegisterType(&ntype);
85 }
void * BKE_id_new_nomain(const short type, const char *name)
Definition: lib_id.c:1196
#define GEO_NODE_MESH_PRIMITIVE_ICO_SPHERE
Definition: BKE_node.h:1412
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
#define NODE_CLASS_GEOMETRY
Definition: BKE_node.h:359
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
#define N_(msgid)
@ ID_ME
Definition: DNA_ID_enums.h:60
@ SOCK_INT
@ SOCK_FLOAT
@ SOCK_GEOMETRY
@ PROP_DISTANCE
Definition: RNA_types.h:135
ATTR_WARN_UNUSED_RESULT BMesh * bm
void BM_mesh_free(BMesh *bm)
BMesh Free Mesh.
Definition: bmesh_mesh.c:307
BMesh * BM_mesh_create(const BMAllocTemplate *allocsize, const struct BMeshCreateParams *params)
BMesh Make Mesh.
Definition: bmesh_mesh.c:157
void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMeshParams *params)
#define BMO_FLAG_DEFAULTS
bool BMO_op_callf(BMesh *bm, const int flag, const char *fmt,...)
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static void geo_node_mesh_primitive_ico_sphere_exec(GeoNodeExecParams params)
static Mesh * create_ico_sphere_mesh(const int subdivisions, const float radius)
void register_node_type_geo_mesh_primitive_ico_sphere()
static bNodeSocketTemplate geo_node_mesh_primitive_ico_sphere_out[]
static bNodeSocketTemplate geo_node_mesh_primitive_ico_sphere_in[]
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
#define min(a, b)
Definition: sort.c:51
static GeometrySet create_with_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:327
static float4x4 identity()
Definition: BLI_float4x4.hh:48
__forceinline const avxi abs(const avxi &a)
Definition: util_avxi.h:186