Blender V5.0
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 "IO_ply.hh"
17
18#include "ply_data.hh"
19#include "ply_export.hh"
20#include "ply_export_data.hh"
21#include "ply_export_header.hh"
25
26#include "CLG_log.h"
27static CLG_LogRef LOG = {"io.ply"};
28
30
31void exporter_main(bContext *C, const PLYExportParams &export_params)
32{
33 std::unique_ptr<blender::io::ply::PlyData> plyData = std::make_unique<PlyData>();
34
35 Depsgraph *depsgraph = nullptr;
36 bool needs_free = false;
37
38 Main *bmain = CTX_data_main(C);
39 Scene *scene = CTX_data_scene(C);
40 if (export_params.collection[0]) {
41 Collection *collection = reinterpret_cast<Collection *>(
42 BKE_libblock_find_name(bmain, ID_GR, export_params.collection));
43 if (!collection) {
44 BKE_reportf(export_params.reports,
46 "PLY Export: Unable to find collection '%s'",
47 export_params.collection);
48 return;
49 }
50
51 ViewLayer *view_layer = CTX_data_view_layer(C);
52
53 depsgraph = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_RENDER);
54 needs_free = true;
57 }
58 else {
60 }
61
62 load_plydata(*plyData, depsgraph, export_params);
63
64 if (needs_free) {
66 }
67
68 std::unique_ptr<FileBuffer> buffer;
69
70 try {
71 if (export_params.ascii_format) {
72 buffer = std::make_unique<FileBufferAscii>(export_params.filepath);
73 }
74 else {
75 buffer = std::make_unique<FileBufferBinary>(export_params.filepath);
76 }
77 }
78 catch (const std::system_error &ex) {
79 CLOG_ERROR(&LOG, "[%s] %s", ex.code().category().name(), ex.what());
80 BKE_reportf(export_params.reports,
82 "PLY Export: Cannot open file '%s'",
83 export_params.filepath);
84 return;
85 }
86
87 write_header(*buffer, *plyData, export_params);
88
89 write_vertices(*buffer, *plyData);
90
91 write_faces(*buffer, *plyData);
92
93 write_edges(*buffer, *plyData);
94
95 buffer->close_file();
96}
97} // 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:1710
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
@ RPT_ERROR
Definition BKE_report.hh:39
void BKE_scene_graph_evaluated_ensure(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2626
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
@ DAG_EVAL_RENDER
Depsgraph * DEG_graph_new(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluationMode mode)
Definition depsgraph.cc:278
void DEG_graph_free(Depsgraph *graph)
Definition depsgraph.cc:306
void DEG_graph_build_from_collection(Depsgraph *graph, Collection *collection)
@ ID_GR
#define C
Definition RandGen.cpp:29
BPy_StructRNA * depsgraph
#define LOG(level)
Definition log.h:97
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:31
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
ReportList * reports
Definition IO_ply.hh:54
char filepath[FILE_MAX]
Definition IO_ply.hh:29
char collection[MAX_ID_NAME - 2]
Definition IO_ply.hh:52