Blender V4.3
node_geo_import_stl.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
6
7#include "BKE_mesh.hh"
8
9#include "BKE_report.hh"
10#include "BLI_string.h"
11
12#include "IO_stl.hh"
13
14#include "node_geometry_util.hh"
15
17
19{
20 b.add_input<decl::String>("Path")
21 .subtype(PROP_FILEPATH)
22 .hide_label()
23 .description("Path to a STL file");
24
25 b.add_output<decl::Geometry>("Mesh");
26}
27
29{
30#ifdef WITH_IO_STL
31 const std::string path = params.extract_input<std::string>("Path");
32 if (path.empty()) {
33 params.set_default_remaining_outputs();
34 return;
35 }
36
37 STLImportParams import_params;
38 STRNCPY(import_params.filepath, path.c_str());
39
40 import_params.forward_axis = IO_AXIS_NEGATIVE_Z;
41 import_params.up_axis = IO_AXIS_Y;
42 import_params.use_facet_normal = false;
43 import_params.use_scene_unit = false;
44 import_params.global_scale = 1.0f;
45 import_params.use_mesh_validate = true;
46
47 ReportList reports;
48 BKE_reports_init(&reports, RPT_STORE);
49 BLI_SCOPED_DEFER([&]() { BKE_reports_free(&reports); })
50 import_params.reports = &reports;
51
52 Mesh *mesh = STL_import_mesh(&import_params);
53
54 LISTBASE_FOREACH (Report *, report, &(import_params.reports)->list) {
55 NodeWarningType type;
56 switch (report->type) {
57 case RPT_ERROR:
58 type = NodeWarningType::Error;
59 break;
60 default:
61 type = NodeWarningType::Info;
62 break;
63 }
64 params.error_message_add(type, TIP_(report->message));
65 }
66
67 params.set_output("Mesh", GeometrySet::from_mesh(mesh));
68
69#else
70 params.error_message_add(NodeWarningType::Error,
71 TIP_("Disabled, Blender was compiled without STL I/O"));
72 params.set_default_remaining_outputs();
73#endif
74}
75
76static void node_register()
77{
78 static blender::bke::bNodeType ntype;
79
80 geo_node_type_base(&ntype, GEO_NODE_IMPORT_STL, "Import STL", NODE_CLASS_INPUT);
81
83 ntype.declare = node_declare;
85
87}
89
90} // namespace blender::nodes::node_geo_import_stl
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
void BKE_reports_free(ReportList *reports)
Definition report.cc:69
void BKE_reports_init(ReportList *reports, int flag)
Definition report.cc:54
#define LISTBASE_FOREACH(type, var, list)
#define BLI_SCOPED_DEFER(function_to_defer)
#define STRNCPY(dst, src)
Definition BLI_string.h:593
#define TIP_(msgid)
@ IO_AXIS_Y
@ IO_AXIS_NEGATIVE_Z
Mesh * STL_import_mesh(const STLImportParams *import_params)
Definition IO_stl.cc:27
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_FILEPATH
Definition RNA_types.hh:139
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
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
void search_link_ops_for_import_node(GatherLinkSearchOpParams &params)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
eIOAxis up_axis
Definition IO_stl.hh:25
bool use_mesh_validate
Definition IO_stl.hh:29
float global_scale
Definition IO_stl.hh:28
eIOAxis forward_axis
Definition IO_stl.hh:24
char filepath[FILE_MAX]
Definition IO_stl.hh:23
ReportList * reports
Definition IO_stl.hh:31
bool use_facet_normal
Definition IO_stl.hh:26
bool use_scene_unit
Definition IO_stl.hh:27
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
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:363
NodeDeclareFunction declare
Definition BKE_node.hh:347