Blender V4.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
9#include <cstdio>
10
11#include "BKE_context.hh"
12#include "BKE_lib_id.hh"
13#include "BKE_report.hh"
14#include "BKE_scene.hh"
15
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
29
30void exporter_main(bContext *C, const PLYExportParams &export_params)
31{
32 std::unique_ptr<blender::io::ply::PlyData> plyData = std::make_unique<PlyData>();
33
34 Depsgraph *depsgraph = nullptr;
35 bool needs_free = false;
36
37 Main *bmain = CTX_data_main(C);
38 Scene *scene = CTX_data_scene(C);
39 if (export_params.collection[0]) {
40 Collection *collection = reinterpret_cast<Collection *>(
41 BKE_libblock_find_name(bmain, ID_GR, export_params.collection));
42 if (!collection) {
43 BKE_reportf(export_params.reports,
45 "PLY Export: Unable to find collection '%s'",
46 export_params.collection);
47 return;
48 }
49
50 ViewLayer *view_layer = CTX_data_view_layer(C);
51
52 depsgraph = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_RENDER);
53 needs_free = true;
56 }
57 else {
59 }
60
61 load_plydata(*plyData, depsgraph, export_params);
62
63 if (needs_free) {
65 }
66
67 std::unique_ptr<FileBuffer> buffer;
68
69 try {
70 if (export_params.ascii_format) {
71 buffer = std::make_unique<FileBufferAscii>(export_params.filepath);
72 }
73 else {
74 buffer = std::make_unique<FileBufferBinary>(export_params.filepath);
75 }
76 }
77 catch (const std::system_error &ex) {
78 fprintf(stderr, "%s\n", ex.what());
79 BKE_reportf(export_params.reports,
81 "PLY Export: Cannot open file '%s'",
82 export_params.filepath);
83 return;
84 }
85
86 write_header(*buffer.get(), *plyData.get(), export_params);
87
88 write_vertices(*buffer.get(), *plyData.get());
89
90 write_faces(*buffer.get(), *plyData.get());
91
92 write_edges(*buffer.get(), *plyData.get());
93
94 buffer->close_file();
95}
96} // namespace blender::io::ply
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
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:1657
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_scene_graph_evaluated_ensure(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2573
@ DAG_EVAL_RENDER
Depsgraph * DEG_graph_new(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluationMode mode)
Definition depsgraph.cc:273
void DEG_graph_free(Depsgraph *graph)
Definition depsgraph.cc:301
void DEG_graph_build_from_collection(Depsgraph *graph, Collection *collection)
@ ID_GR
const Depsgraph * depsgraph
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:30
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)
bool ascii_format
Definition IO_ply.hh:37
char collection[MAX_IDPROP_NAME]
Definition IO_ply.hh:52
ReportList * reports
Definition IO_ply.hh:54
char filepath[FILE_MAX]
Definition IO_ply.hh:29