Blender V4.3
node_geo_mesh_primitive_grid.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::Float>("Size X")
16 .default_value(1.0f)
17 .min(0.0f)
19 .description("Side length of the plane in the X direction");
20 b.add_input<decl::Float>("Size Y")
21 .default_value(1.0f)
22 .min(0.0f)
24 .description("Side length of the plane in the Y direction");
25 b.add_input<decl::Int>("Vertices X")
26 .default_value(3)
27 .min(2)
28 .max(1000)
29 .description("Number of vertices in the X direction");
30 b.add_input<decl::Int>("Vertices Y")
31 .default_value(3)
32 .min(2)
33 .max(1000)
34 .description("Number of vertices in the Y direction");
35 b.add_output<decl::Geometry>("Mesh");
36 b.add_output<decl::Vector>("UV Map").field_on_all();
37}
38
40{
41 const float size_x = params.extract_input<float>("Size X");
42 const float size_y = params.extract_input<float>("Size Y");
43 const int verts_x = params.extract_input<int>("Vertices X");
44 const int verts_y = params.extract_input<int>("Vertices Y");
45 if (verts_x < 1 || verts_y < 1) {
46 params.set_default_remaining_outputs();
47 return;
48 }
49
50 std::optional<std::string> uv_map_id = params.get_output_anonymous_attribute_id_if_needed(
51 "UV Map");
52
53 Mesh *mesh = geometry::create_grid_mesh(verts_x, verts_y, size_x, size_y, uv_map_id);
54 BKE_id_material_eval_ensure_default_slot(reinterpret_cast<ID *>(mesh));
55
56 params.set_output("Mesh", GeometrySet::from_mesh(mesh));
57}
58
59static void node_register()
60{
61 static blender::bke::bNodeType ntype;
62
63 geo_node_type_base(&ntype, GEO_NODE_MESH_PRIMITIVE_GRID, "Grid", NODE_CLASS_GEOMETRY);
64 ntype.declare = node_declare;
67}
69
70} // namespace blender::nodes::node_geo_mesh_primitive_grid_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 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_grid_mesh(int verts_x, int verts_y, float size_x, float size_y, 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