Merge branch 'master' 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 Mesh;
30 struct ModifierData;
31
32 /* ************************************************************************** */
33
34 class AbcMeshWriter : public AbcObjectWriter {
35         Alembic::AbcGeom::OPolyMeshSchema m_mesh_schema;
36         Alembic::AbcGeom::OPolyMeshSchema::Sample m_mesh_sample;
37
38         Alembic::AbcGeom::OSubDSchema m_subdiv_schema;
39         Alembic::AbcGeom::OSubDSchema::Sample m_subdiv_sample;
40
41         Alembic::Abc::OArrayProperty m_mat_indices;
42
43         bool m_is_animated;
44         ModifierData *m_subsurf_mod;
45
46         CDStreamConfig m_custom_data_config;
47
48         bool m_is_liquid;
49         bool m_is_subd;
50
51 public:
52         AbcMeshWriter(Object *ob,
53                       AbcTransformWriter *parent,
54                       uint32_t time_sampling,
55                       ExportSettings &settings);
56
57         ~AbcMeshWriter();
58         void setIsAnimated(bool is_animated);
59
60 private:
61         virtual void do_write();
62
63         bool isAnimated() const;
64
65         void writeMesh(struct Mesh *mesh);
66         void writeSubD(struct Mesh *mesh);
67
68         void getMeshInfo(struct Mesh *mesh, std::vector<float> &points,
69                          std::vector<int32_t> &facePoints,
70                          std::vector<int32_t> &faceCounts,
71                          std::vector<int32_t> &creaseIndices,
72                          std::vector<int32_t> &creaseLengths,
73                          std::vector<float> &creaseSharpness);
74
75         struct Mesh *getFinalMesh(bool &r_needsfree);
76
77         void getMaterialIndices(struct Mesh *mesh, std::vector<int32_t> &indices);
78
79         void writeArbGeoParams(struct Mesh *mesh);
80         void getGeoGroups(struct Mesh *mesh, std::map<std::string, std::vector<int32_t> > &geoGroups);
81
82         /* fluid surfaces support */
83         void getVelocities(struct Mesh *mesh, std::vector<Imath::V3f> &vels);
84
85         template <typename Schema>
86         void writeFaceSets(struct Mesh *mesh, Schema &schema);
87 };
88
89 /* ************************************************************************** */
90
91 class AbcMeshReader : public AbcObjectReader {
92         Alembic::AbcGeom::IPolyMeshSchema m_schema;
93
94         CDStreamConfig m_mesh_data;
95
96 public:
97         AbcMeshReader(const Alembic::Abc::IObject &object, ImportSettings &settings);
98
99         bool valid() const;
100         bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
101                                const Object *const ob,
102                                const char **err_str) const;
103         void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel);
104
105         struct Mesh *read_mesh(struct Mesh *existing_mesh,
106                                const Alembic::Abc::ISampleSelector &sample_sel,
107                                int read_flag,
108                                const char **err_str);
109
110 private:
111         void readFaceSetsSample(Main *bmain, Mesh *mesh, size_t poly_start,
112                                 const Alembic::AbcGeom::ISampleSelector &sample_sel);
113
114         void assign_facesets_to_mpoly(const Alembic::Abc::ISampleSelector &sample_sel,
115                                       size_t poly_start,
116                                       MPoly *mpoly, int totpoly,
117                                       std::map<std::string, int> & r_mat_map);
118 };
119
120 /* ************************************************************************** */
121
122 class AbcSubDReader : public AbcObjectReader {
123         Alembic::AbcGeom::ISubDSchema m_schema;
124
125         CDStreamConfig m_mesh_data;
126
127 public:
128         AbcSubDReader(const Alembic::Abc::IObject &object, ImportSettings &settings);
129
130         bool valid() const;
131         bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
132                                  const Object *const ob,
133                                  const char **err_str) const;
134         void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel);
135         struct Mesh *read_mesh(struct Mesh *existing_mesh,
136                                const Alembic::Abc::ISampleSelector &sample_sel,
137                                int read_flag,
138                                const char **err_str);
139 };
140
141 /* ************************************************************************** */
142
143 void read_mverts(MVert *mverts,
144                  const Alembic::AbcGeom::P3fArraySamplePtr &positions,
145                  const Alembic::AbcGeom::N3fArraySamplePtr &normals);
146
147 CDStreamConfig get_config(struct Mesh *mesh);
148
149 #endif  /* __ABC_MESH_H__ */