1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/** \file
* \ingroup obj
*/
#pragma once
#include "BLI_utility_mixins.hh"
#include "BLI_vector.hh"
#include "IO_wavefront_obj.h"
namespace blender::io::obj {
/**
* Behaves like `std::unique_ptr<Depsgraph, custom_deleter>`.
* Needed to free a new Depsgraph created for #DAG_EVAL_RENDER.
*/
class OBJDepsgraph : NonMovable, NonCopyable {
private:
Depsgraph *depsgraph_ = nullptr;
bool needs_free_ = false;
public:
OBJDepsgraph(const bContext *C, const eEvaluationMode eval_mode);
~OBJDepsgraph();
Depsgraph *get();
void update_for_newframe();
};
/**
* The main function for exporting a .obj file according to the given `export_parameters`.
* It uses the context `C` to get the dependency graph, and from that, the `Scene`.
* Depending on whether or not `export_params.export_animation` is set, it writes
* either one file per animation frame, or just one file.
*/
void exporter_main(bContext *C, const OBJExportParams &export_params);
class OBJMesh;
class OBJCurve;
/**
* Export a single frame of a .obj file, according to the given `export_parameters`.
* The frame state is given in `depsgraph`.
* The output file name is given by `filepath`.
* This function is normally called from `exporter_main`, but is exposed here for testing purposes.
*/
void export_frame(Depsgraph *depsgraph,
const OBJExportParams &export_params,
const char *filepath);
/**
* Find the objects to be exported in the `view_layer` of the dependency graph`depsgraph`,
* and return them in vectors `unique_ptr`s of `OBJMesh` and `OBJCurve`.
* If `export_params.export_selected_objects` is set, then only selected objects are to be
* exported, else all objects are to be exported. But only objects of type `OB_MESH`, `OB_CURVE`,
* and `OB_SURF` are supported; the rest will be ignored. If `export_params.export_curves_as_nurbs`
* is set, then curves of type `CU_NURBS` are exported in curve form in the .obj file, otherwise
* they are converted to mesh and returned in the `OBJMesh` vector. All other exportable types are
* always converted to mesh and returned in the `OBJMesh` vector.
*/
std::pair<Vector<std::unique_ptr<OBJMesh>>, Vector<std::unique_ptr<OBJCurve>>>
filter_supported_objects(Depsgraph *depsgraph, const OBJExportParams &export_params);
/**
* Makes `r_filepath_with_frames` (which should point at a character array of size `FILE_MAX`)
* be `filepath` with its "#" characters replaced by the number representing `frame`, and with
* a .obj extension.
*/
bool append_frame_to_filename(const char *filepath, const int frame, char *r_filepath_with_frames);
} // namespace blender::io::obj
|