Merge commit 'master@6ed15c5a41130b55cb57a43a8a9470a91d38c3d5' into blender2.8
[blender.git] / source / blender / alembic / intern / abc_mesh.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_MESH_H__
24 #define __ABC_MESH_H__
25
26 #include "abc_customdata.h"
27 #include "abc_object.h"
28
29 struct DerivedMesh;
30 struct Mesh;
31 struct ModifierData;
32
33 /* ************************************************************************** */
34
35 class AbcMeshWriter : public AbcObjectWriter {
36         Alembic::AbcGeom::OPolyMeshSchema m_mesh_schema;
37         Alembic::AbcGeom::OPolyMeshSchema::Sample m_mesh_sample;
38
39         Alembic::AbcGeom::OSubDSchema m_subdiv_schema;
40         Alembic::AbcGeom::OSubDSchema::Sample m_subdiv_sample;
41
42         Alembic::Abc::OArrayProperty m_mat_indices;
43
44         bool m_is_animated;
45         ModifierData *m_subsurf_mod;
46
47         CDStreamConfig m_custom_data_config;
48
49         bool m_is_liquid;
50         bool m_is_subd;
51
52 public:
53         AbcMeshWriter(Scene *scene,
54                       Object *ob,
55                       AbcTransformWriter *parent,
56                       uint32_t time_sampling,
57                       ExportSettings &settings);
58
59         ~AbcMeshWriter();
60
61 private:
62         virtual void do_write();
63
64         bool isAnimated() const;
65
66         void writeMesh(DerivedMesh *dm);
67         void writeSubD(DerivedMesh *dm);
68
69         void getMeshInfo(DerivedMesh *dm, std::vector<float> &points,
70                          std::vector<int32_t> &facePoints,
71                          std::vector<int32_t> &faceCounts,
72                          std::vector<int32_t> &creaseIndices,
73                          std::vector<int32_t> &creaseLengths,
74                          std::vector<float> &creaseSharpness);
75
76         DerivedMesh *getFinalMesh();
77         void freeMesh(DerivedMesh *dm);
78
79         void getMaterialIndices(DerivedMesh *dm, std::vector<int32_t> &indices);
80
81         void writeArbGeoParams(DerivedMesh *dm);
82         void getGeoGroups(DerivedMesh *dm, std::map<std::string, std::vector<int32_t> > &geoGroups);
83         
84         /* fluid surfaces support */
85         void getVelocities(DerivedMesh *dm, std::vector<Imath::V3f> &vels);
86
87         template <typename Schema>
88         void writeFaceSets(DerivedMesh *dm, Schema &schema);
89 };
90
91 /* ************************************************************************** */
92
93 class AbcMeshReader : public AbcObjectReader {
94         Alembic::AbcGeom::IPolyMeshSchema m_schema;
95
96         CDStreamConfig m_mesh_data;
97
98 public:
99         AbcMeshReader(const Alembic::Abc::IObject &object, ImportSettings &settings);
100
101         bool valid() const;
102
103         void readObjectData(Main *bmain, float time);
104
105         DerivedMesh *read_derivedmesh(DerivedMesh *dm, const float time, int read_flag, const char **err_str);
106
107 private:
108         void readFaceSetsSample(Main *bmain, Mesh *mesh, size_t poly_start,
109                                 const Alembic::AbcGeom::ISampleSelector &sample_sel);
110 };
111
112 /* ************************************************************************** */
113
114 class AbcSubDReader : public AbcObjectReader {
115         Alembic::AbcGeom::ISubDSchema m_schema;
116
117         CDStreamConfig m_mesh_data;
118
119 public:
120         AbcSubDReader(const Alembic::Abc::IObject &object, ImportSettings &settings);
121
122         bool valid() const;
123
124         void readObjectData(Main *bmain, float time);
125         DerivedMesh *read_derivedmesh(DerivedMesh *dm, const float time, int read_flag, const char **err_str);
126 };
127
128 /* ************************************************************************** */
129
130 void read_mverts(MVert *mverts,
131                  const Alembic::AbcGeom::P3fArraySamplePtr &positions,
132                  const Alembic::AbcGeom::N3fArraySamplePtr &normals);
133
134 CDStreamConfig get_config(DerivedMesh *dm);
135
136 #endif  /* __ABC_MESH_H__ */