Merge commit 'master@6ed15c5a41130b55cb57a43a8a9470a91d38c3d5' into blender2.8
[blender.git] / source / blender / alembic / intern / abc_exporter.h
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Esteban Tovagliari, Cedric Paille, Kevin Dietrich
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 #ifndef __ABC_EXPORTER_H__
24 #define __ABC_EXPORTER_H__
25
26 #include <Alembic/Abc/All.h>
27 #include <map>
28 #include <set>
29 #include <vector>
30
31 #include "abc_util.h"
32
33 class AbcObjectWriter;
34 class AbcTransformWriter;
35 class ArchiveWriter;
36
37 struct EvaluationContext;
38 struct Main;
39 struct Object;
40 struct Scene;
41 struct SceneLayer;
42 struct Base;
43
44 struct ExportSettings {
45         ExportSettings();
46
47         Scene *scene;
48         SceneLayer *sl;  // Scene layer to export; all its objects will be exported, unless selected_only=true
49         SimpleLogger logger;
50
51         bool selected_only;
52         bool visible_layers_only;
53         bool renderable_only;
54
55         double frame_start, frame_end;
56         double frame_step_xform;
57         double frame_step_shape;
58         double shutter_open;
59         double shutter_close;
60         float global_scale;
61
62         bool flatten_hierarchy;
63
64         bool export_normals;
65         bool export_uvs;
66         bool export_vcols;
67         bool export_face_sets;
68         bool export_vweigths;
69         bool export_hair;
70         bool export_particles;
71
72         bool apply_subdiv;
73         bool use_subdiv_schema;
74         bool export_child_hairs;
75         bool export_ogawa;
76         bool pack_uv;
77         bool triangulate;
78
79         int quad_method;
80         int ngon_method;
81
82         bool do_convert_axis;
83         float convert_matrix[3][3];
84 };
85
86 class AbcExporter {
87         ExportSettings &m_settings;
88
89         const char *m_filename;
90
91         unsigned int m_trans_sampling_index, m_shape_sampling_index;
92
93         Scene *m_scene;
94
95         ArchiveWriter *m_writer;
96
97         /* mapping from name to transform writer */
98         typedef std::map<std::string, AbcTransformWriter *> m_xforms_type;
99         m_xforms_type m_xforms;
100
101         std::vector<AbcObjectWriter *> m_shapes;
102
103 public:
104         AbcExporter(Scene *scene, const char *filename, ExportSettings &settings);
105         ~AbcExporter();
106
107         void operator()(Main *bmain, float &progress, bool &was_canceled);
108
109 private:
110         void getShutterSamples(double step, bool time_relative, std::vector<double> &samples);
111
112         Alembic::Abc::TimeSamplingPtr createTimeSampling(double step);
113
114         void getFrameSet(double step, std::set<double> &frames);
115
116         void createTransformWritersHierarchy(EvaluationContext *eval_ctx);
117         AbcTransformWriter * createTransformWriter(Object *ob,  Object *parent, Object *dupliObParent);
118         void exploreTransform(EvaluationContext *eval_ctx, Base *ob_base, Object *parent, Object *dupliObParent);
119         void exploreObject(EvaluationContext *eval_ctx, Base *ob_base, Object *dupliObParent);
120         void createShapeWriters(EvaluationContext *eval_ctx);
121         void createShapeWriter(Base *ob_base, Object *dupliObParent);
122         void createParticleSystemsWriters(Object *ob, AbcTransformWriter *xform);
123
124         AbcTransformWriter *getXForm(const std::string &name);
125
126         void setCurrentFrame(Main *bmain, double t);
127 };
128
129 #endif  /* __ABC_EXPORTER_H__ */