Merge branch 'master' 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 Depsgraph;
39 struct Main;
40 struct Object;
41 struct Scene;
42 struct SceneLayer;
43 struct Base;
44
45 struct ExportSettings {
46         ExportSettings();
47
48         Scene *scene;
49         SceneLayer *scene_layer;  // Scene layer to export; all its objects will be exported, unless selected_only=true
50         Depsgraph *depsgraph;
51         SimpleLogger logger;
52
53         bool selected_only;
54         bool visible_layers_only;
55         bool renderable_only;
56
57         double frame_start, frame_end;
58         double frame_samples_xform;
59         double frame_samples_shape;
60         double shutter_open;
61         double shutter_close;
62         float global_scale;
63
64         bool flatten_hierarchy;
65
66         bool export_normals;
67         bool export_uvs;
68         bool export_vcols;
69         bool export_face_sets;
70         bool export_vweigths;
71         bool export_hair;
72         bool export_particles;
73
74         bool apply_subdiv;
75         bool use_subdiv_schema;
76         bool export_child_hairs;
77         bool export_ogawa;
78         bool pack_uv;
79         bool triangulate;
80
81         int quad_method;
82         int ngon_method;
83
84         bool do_convert_axis;
85         float convert_matrix[3][3];
86 };
87
88 class AbcExporter {
89         Main *m_bmain;
90         ExportSettings &m_settings;
91
92         const char *m_filename;
93
94         unsigned int m_trans_sampling_index, m_shape_sampling_index;
95
96         EvaluationContext *m_eval_ctx;
97         Scene *m_scene;
98         SceneLayer *m_scene_layer;
99         Depsgraph *m_depsgraph;
100
101         ArchiveWriter *m_writer;
102
103         /* mapping from name to transform writer */
104         typedef std::map<std::string, AbcTransformWriter *> m_xforms_type;
105         m_xforms_type m_xforms;
106
107         std::vector<AbcObjectWriter *> m_shapes;
108
109 public:
110         AbcExporter(Main *bmain, EvaluationContext *eval_ctx, Scene *scene, SceneLayer *scene_layer,
111                     Depsgraph *depsgraph,
112                     const char *filename, ExportSettings &settings);
113         ~AbcExporter();
114
115         void operator()(Main *bmain, float &progress, bool &was_canceled);
116
117 protected:
118         void getShutterSamples(unsigned int nr_of_samples,
119                                bool time_relative,
120                                std::vector<double> &samples);
121         void getFrameSet(unsigned int nr_of_samples, std::set<double> &frames);
122
123 private:
124         Alembic::Abc::TimeSamplingPtr createTimeSampling(double step);
125
126         void createTransformWritersHierarchy(EvaluationContext *eval_ctx);
127         AbcTransformWriter * createTransformWriter(EvaluationContext *eval_ctx, Object *ob,  Object *parent, Object *dupliObParent);
128         void exploreTransform(EvaluationContext *eval_ctx, Base *ob_base, Object *parent, Object *dupliObParent);
129         void exploreObject(EvaluationContext *eval_ctx, Base *ob_base, Object *dupliObParent);
130         void createShapeWriters(EvaluationContext *eval_ctx);
131         void createShapeWriter(Base *ob_base, Object *dupliObParent);
132         void createParticleSystemsWriters(Object *ob, AbcTransformWriter *xform);
133
134         AbcTransformWriter *getXForm(const std::string &name);
135
136         void setCurrentFrame(Main *bmain, double t);
137 };
138
139 #endif  /* __ABC_EXPORTER_H__ */