Blender  V3.3
node_geo_mesh_primitive_cube.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 #include "DNA_meshdata_types.h"
5 
6 #include "BKE_material.h"
7 #include "BKE_mesh.h"
8 
10 
11 #include "node_geometry_util.hh"
12 
14 
16 {
17  b.add_input<decl::Vector>(N_("Size"))
18  .default_value(float3(1))
19  .min(0.0f)
20  .subtype(PROP_TRANSLATION)
21  .description(N_("Side length along each axis"));
22  b.add_input<decl::Int>(N_("Vertices X"))
23  .default_value(2)
24  .min(2)
25  .max(1000)
26  .description(N_("Number of vertices for the X side of the shape"));
27  b.add_input<decl::Int>(N_("Vertices Y"))
28  .default_value(2)
29  .min(2)
30  .max(1000)
31  .description(N_("Number of vertices for the Y side of the shape"));
32  b.add_input<decl::Int>(N_("Vertices Z"))
33  .default_value(2)
34  .min(2)
35  .max(1000)
36  .description(N_("Number of vertices for the Z side of the shape"));
37  b.add_output<decl::Geometry>(N_("Mesh"));
38 }
39 
41  const int verts_x,
42  const int verts_y,
43  const int verts_z)
44 {
45  Mesh *mesh = geometry::create_cuboid_mesh(size, verts_x, verts_y, verts_z, "uv_map");
47  return mesh;
48 }
49 
51  const int verts_x,
52  const int verts_y,
53  const int verts_z)
54 {
55  const int dimensions = (verts_x - 1 > 0) + (verts_y - 1 > 0) + (verts_z - 1 > 0);
56  if (dimensions == 0) {
57  return create_line_mesh(float3(0), float3(0), 1);
58  }
59  if (dimensions == 1) {
60  float3 start;
61  float3 delta;
62  if (verts_x > 1) {
63  start = {-size.x / 2.0f, 0, 0};
64  delta = {size.x / (verts_x - 1), 0, 0};
65  }
66  else if (verts_y > 1) {
67  start = {0, -size.y / 2.0f, 0};
68  delta = {0, size.y / (verts_y - 1), 0};
69  }
70  else {
71  start = {0, 0, -size.z / 2.0f};
72  delta = {0, 0, size.z / (verts_z - 1)};
73  }
74 
75  return create_line_mesh(start, delta, verts_x * verts_y * verts_z);
76  }
77  if (dimensions == 2) {
78  if (verts_z == 1) { /* XY plane. */
79  return create_grid_mesh(verts_x, verts_y, size.x, size.y);
80  }
81  if (verts_y == 1) { /* XZ plane. */
82  Mesh *mesh = create_grid_mesh(verts_x, verts_z, size.x, size.z);
83  transform_mesh(*mesh, float3(0), float3(M_PI_2, 0.0f, 0.0f), float3(1));
84  return mesh;
85  }
86  /* YZ plane. */
87  Mesh *mesh = create_grid_mesh(verts_z, verts_y, size.z, size.y);
88  transform_mesh(*mesh, float3(0), float3(0.0f, M_PI_2, 0.0f), float3(1));
89  return mesh;
90  }
91 
92  return create_cuboid_mesh(size, verts_x, verts_y, verts_z);
93 }
94 
96 {
97  const float3 size = params.extract_input<float3>("Size");
98  const int verts_x = params.extract_input<int>("Vertices X");
99  const int verts_y = params.extract_input<int>("Vertices Y");
100  const int verts_z = params.extract_input<int>("Vertices Z");
101  if (verts_x < 1 || verts_y < 1 || verts_z < 1) {
102  params.error_message_add(NodeWarningType::Info, TIP_("Vertices must be at least 1"));
103  params.set_default_remaining_outputs();
104  return;
105  }
106 
107  Mesh *mesh = create_cube_mesh(size, verts_x, verts_y, verts_z);
108 
109  params.set_output("Mesh", GeometrySet::create_with_mesh(mesh));
110 }
111 
112 } // namespace blender::nodes::node_geo_mesh_primitive_cube_cc
113 
115 {
117 
118  static bNodeType ntype;
119 
123  nodeRegisterType(&ntype);
124 }
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_CUBE
Definition: BKE_node.h:1391
#define NODE_CLASS_GEOMETRY
Definition: BKE_node.h:359
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define M_PI_2
Definition: BLI_math_base.h:23
#define TIP_(msgid)
in reality light always falls off quadratically Particle Info
@ PROP_TRANSLATION
Definition: RNA_types.h:154
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
Mesh * create_cuboid_mesh(const float3 &size, int verts_x, int verts_y, int verts_z, const bke::AttributeIDRef &uv_id)
static Mesh * create_cube_mesh(const float3 size, const int verts_x, const int verts_y, const int verts_z)
static Mesh * create_cuboid_mesh(const float3 &size, const int verts_x, const int verts_y, const int verts_z)
Mesh * create_line_mesh(const float3 start, const float3 delta, int count)
void transform_mesh(Mesh &mesh, const float3 translation, const float3 rotation, const float3 scale)
Mesh * create_grid_mesh(int verts_x, int verts_y, float size_x, float size_y)
vec_base< float, 3 > float3
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_geo_mesh_primitive_cube()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
#define min(a, b)
Definition: sort.c:35
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
#define N_(msgid)