Blender V5.3
ply_export.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
8
9#include "BKE_context.hh"
10#include "BKE_lib_id.hh"
11#include "BKE_report.hh"
12#include "BKE_scene.hh"
13
15
16#include "ED_util.hh"
17
18#include "IO_ply.hh"
19
20#include "ply_data.hh"
21#include "ply_export.hh"
22#include "ply_export_data.hh"
23#include "ply_export_header.hh"
27
28#include "CLG_log.h"
29
30namespace blender {
31
32static CLG_LogRef LOG = {"io.ply"};
33
34namespace io::ply {
35
36void exporter_main(bContext *C, const PLYExportParams &export_params)
37{
38 std::unique_ptr<io::ply::PlyData> plyData = std::make_unique<PlyData>();
39
40 Main *bmain = CTX_data_main(C);
41 Scene *scene = CTX_data_scene(C);
42 ViewLayer *view_layer = CTX_data_view_layer(C);
43
45
46 Depsgraph *depsgraph = DEG_graph_new(bmain, scene, view_layer, export_params.evaluation_mode);
47
48 if (export_params.collection[0]) {
49 Collection *collection = reinterpret_cast<Collection *>(
50 BKE_libblock_find_name(bmain, ID_GR, export_params.collection));
51 if (!collection) {
52 BKE_reportf(export_params.reports,
54 "PLY Export: Unable to find collection '%s'",
55 export_params.collection);
56
57 DEG_graph_free(depsgraph);
58 return;
59 }
60
61 DEG_graph_build_from_collection(depsgraph, collection);
62 }
63 else {
65 }
66 BKE_scene_graph_update_tagged(depsgraph, bmain);
67
68 load_plydata(*plyData, depsgraph, export_params);
69
70 DEG_graph_free(depsgraph);
71
72 std::unique_ptr<FileBuffer> buffer;
73
74 try {
75 if (export_params.ascii_format) {
76 buffer = std::make_unique<FileBufferAscii>(export_params.filepath);
77 }
78 else {
79 buffer = std::make_unique<FileBufferBinary>(export_params.filepath);
80 }
81 }
82 catch (const std::system_error &ex) {
83 CLOG_ERROR(&LOG, "[%s] %s", ex.code().category().name(), ex.what());
84 BKE_reportf(export_params.reports,
86 "PLY Export: Cannot open file '%s'",
87 export_params.filepath);
88 return;
89 }
90
91 write_header(*buffer, *plyData, export_params);
92
93 write_vertices(*buffer, *plyData);
94
95 write_faces(*buffer, *plyData);
96
97 write_edges(*buffer, *plyData);
98
99 buffer->close_file();
100}
101} // namespace io::ply
102} // namespace blender
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
#define C
Definition RandGen.cpp:29
void write_vertices(FileBuffer &buffer, const PlyData &ply_data)
void load_plydata(PlyData &plyData, Depsgraph *depsgraph, const PLYExportParams &export_params)
void exporter_main(bContext *C, const PLYExportParams &export_params)
Definition ply_export.cc:36
void write_faces(FileBuffer &buffer, const PlyData &ply_data)
void write_edges(FileBuffer &buffer, const PlyData &ply_data)
void write_header(FileBuffer &buffer, const PlyData &ply_data, const PLYExportParams &export_params)
BMesh Iterators.
ID * BKE_libblock_find_name(Main *bmain, short type, const char *name, const std::optional< Library * > lib=std::nullopt) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition lib_id.cc:1808
bool ED_editors_flush_edits(Main *bmain)
Definition ed_util.cc:335
void DEG_graph_build_from_view_layer(Depsgraph *graph)
void DEG_graph_build_from_collection(Depsgraph *graph, Collection *collection)
void DEG_graph_free(Depsgraph *graph)
Definition depsgraph.cc:307
Depsgraph * DEG_graph_new(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluationMode mode)
Definition depsgraph.cc:279
ViewLayer * CTX_data_view_layer(const bContext *C)
void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2867
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
Main * CTX_data_main(const bContext *C)
static CLG_LogRef LOG
Definition logging.cpp:12
Scene * CTX_data_scene(const bContext *C)
char collection[MAX_ID_NAME - 2]
Definition IO_ply.hh:60
ReportList * reports
Definition IO_ply.hh:62
char filepath[FILE_MAX]
Definition IO_ply.hh:36
eEvaluationMode evaluation_mode
Definition IO_ply.hh:54