a08b7352d16cc7fab58c46c41dc5aa17db276ef6
[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(EvaluationContext *eval_ctx,
54                       Scene *scene,
55                       Object *ob,
56                       AbcTransformWriter *parent,
57                       uint32_t time_sampling,
58                       ExportSettings &settings);
59
60         ~AbcMeshWriter();
61         void setIsAnimated(bool is_animated);
62
63 private:
64         virtual void do_write();
65
66         bool isAnimated() const;
67
68         void writeMesh(DerivedMesh *dm);
69         void writeSubD(DerivedMesh *dm);
70
71         void getMeshInfo(DerivedMesh *dm, std::vector<float> &points,
72                          std::vector<int32_t> &facePoints,
73                          std::vector<int32_t> &faceCounts,
74                          std::vector<int32_t> &creaseIndices,
75                          std::vector<int32_t> &creaseLengths,
76                          std::vector<float> &creaseSharpness);
77
78         DerivedMesh *getFinalMesh();
79         void freeMesh(DerivedMesh *dm);
80
81         void getMaterialIndices(DerivedMesh *dm, std::vector<int32_t> &indices);
82
83         void writeArbGeoParams(DerivedMesh *dm);
84         void getGeoGroups(DerivedMesh *dm, std::map<std::string, std::vector<int32_t> > &geoGroups);
85         
86         /* fluid surfaces support */
87         void getVelocities(DerivedMesh *dm, std::vector<Imath::V3f> &vels);
88
89         template <typename Schema>
90         void writeFaceSets(DerivedMesh *dm, Schema &schema);
91 };
92
93 /* ************************************************************************** */
94
95 class AbcMeshReader : public AbcObjectReader {
96         Alembic::AbcGeom::IPolyMeshSchema m_schema;
97
98         CDStreamConfig m_mesh_data;
99
100 public:
101         AbcMeshReader(const Alembic::Abc::IObject &object, ImportSettings &settings);
102
103         bool valid() const;
104         bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
105                                const Object *const ob,
106                                const char **err_str) const;
107         void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel);
108
109         DerivedMesh *read_derivedmesh(DerivedMesh *dm,
110                                       const Alembic::Abc::ISampleSelector &sample_sel,
111                                       int read_flag,
112                                       const char **err_str);
113
114 private:
115         void readFaceSetsSample(Main *bmain, Mesh *mesh, size_t poly_start,
116                                 const Alembic::AbcGeom::ISampleSelector &sample_sel);
117
118         void assign_facesets_to_mpoly(const Alembic::Abc::ISampleSelector &sample_sel,
119                                       size_t poly_start,
120                                       MPoly *mpoly, int totpoly,
121                                       std::map<std::string, int> & r_mat_map);
122 };
123
124 /* ************************************************************************** */
125
126 class AbcSubDReader : public AbcObjectReader {
127         Alembic::AbcGeom::ISubDSchema m_schema;
128
129         CDStreamConfig m_mesh_data;
130
131 public:
132         AbcSubDReader(const Alembic::Abc::IObject &object, ImportSettings &settings);
133
134         bool valid() const;
135         bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
136                                  const Object *const ob,
137                                  const char **err_str) const;
138         void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel);
139         DerivedMesh *read_derivedmesh(DerivedMesh *dm,
140                                       const Alembic::Abc::ISampleSelector &sample_sel,
141                                       int read_flag,
142                                       const char **err_str);
143 };
144
145 /* ************************************************************************** */
146
147 void read_mverts(MVert *mverts,
148                  const Alembic::AbcGeom::P3fArraySamplePtr &positions,
149                  const Alembic::AbcGeom::N3fArraySamplePtr &normals);
150
151 CDStreamConfig get_config(DerivedMesh *dm);
152
153 #endif  /* __ABC_MESH_H__ */