Blender  V2.93
node_geo_mesh_primitive_cube.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_("Size"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX, PROP_DISTANCE},
28  {-1, ""},
29 };
30 
32  {SOCK_GEOMETRY, N_("Geometry")},
33  {-1, ""},
34 };
35 
36 namespace blender::nodes {
37 
38 Mesh *create_cube_mesh(const float size)
39 {
41 
42  const BMeshCreateParams bmcp = {true};
43  const BMAllocTemplate allocsize = {8, 12, 24, 6};
44  BMesh *bm = BM_mesh_create(&allocsize, &bmcp);
45 
48  "create_cube matrix=%m4 size=%f calc_uvs=%b",
49  transform.values,
50  size,
51  true);
52 
54  params.calc_object_remap = false;
55  Mesh *mesh = (Mesh *)BKE_id_new_nomain(ID_ME, nullptr);
56  BM_mesh_bm_to_me(nullptr, bm, mesh, &params);
58 
59  return mesh;
60 }
61 
63 {
64  const float size = params.extract_input<float>("Size");
65 
67  params.set_output("Geometry", GeometrySet::create_with_mesh(mesh));
68 }
69 
70 } // namespace blender::nodes
71 
73 {
74  static bNodeType ntype;
75 
80  nodeRegisterType(&ntype);
81 }
void * BKE_id_new_nomain(const short type, const char *name)
Definition: lib_id.c:1196
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
#define GEO_NODE_MESH_PRIMITIVE_CUBE
Definition: BKE_node.h:1408
#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_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
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static void geo_node_mesh_primitive_cube_exec(GeoNodeExecParams params)
Mesh * create_cube_mesh(const float size)
static bNodeSocketTemplate geo_node_mesh_primitive_cube_in[]
void register_node_type_geo_mesh_primitive_cube()
static bNodeSocketTemplate geo_node_mesh_primitive_cube_out[]
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
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