/src/alembic/lib/Alembic/AbcGeom/OPolyMesh.h
Line | Count | Source (jump to first uncovered line) |
1 | | //-***************************************************************************** |
2 | | // |
3 | | // Copyright (c) 2009-2013, |
4 | | // Sony Pictures Imageworks, Inc. and |
5 | | // Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. |
6 | | // |
7 | | // All rights reserved. |
8 | | // |
9 | | // Redistribution and use in source and binary forms, with or without |
10 | | // modification, are permitted provided that the following conditions are |
11 | | // met: |
12 | | // * Redistributions of source code must retain the above copyright |
13 | | // notice, this list of conditions and the following disclaimer. |
14 | | // * Redistributions in binary form must reproduce the above |
15 | | // copyright notice, this list of conditions and the following disclaimer |
16 | | // in the documentation and/or other materials provided with the |
17 | | // distribution. |
18 | | // * Neither the name of Sony Pictures Imageworks, nor |
19 | | // Industrial Light & Magic nor the names of their contributors may be used |
20 | | // to endorse or promote products derived from this software without specific |
21 | | // prior written permission. |
22 | | // |
23 | | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
24 | | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
25 | | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
26 | | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
27 | | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
28 | | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
29 | | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
30 | | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
31 | | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
32 | | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
33 | | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
34 | | // |
35 | | //-***************************************************************************** |
36 | | |
37 | | #ifndef Alembic_AbcGeom_OPolyMesh_h |
38 | | #define Alembic_AbcGeom_OPolyMesh_h |
39 | | |
40 | | #include <Alembic/Util/Export.h> |
41 | | #include <Alembic/AbcGeom/Foundation.h> |
42 | | #include <Alembic/AbcGeom/SchemaInfoDeclarations.h> |
43 | | #include <Alembic/AbcGeom/OFaceSet.h> |
44 | | #include <Alembic/AbcGeom/OGeomParam.h> |
45 | | #include <Alembic/AbcGeom/OGeomBase.h> |
46 | | |
47 | | namespace Alembic { |
48 | | namespace AbcGeom { |
49 | | namespace ALEMBIC_VERSION_NS { |
50 | | |
51 | | //-***************************************************************************** |
52 | | class ALEMBIC_EXPORT OPolyMeshSchema |
53 | | : public OGeomBaseSchema<PolyMeshSchemaInfo> |
54 | | { |
55 | | public: |
56 | | //-************************************************************************* |
57 | | // POLY MESH SCHEMA SAMPLE TYPE |
58 | | //-************************************************************************* |
59 | | class Sample |
60 | | { |
61 | | public: |
62 | | //! Creates a default sample with no data in it. |
63 | | //! ... |
64 | 0 | Sample() { reset(); } |
65 | | |
66 | | //! Creates a sample with position data but no index |
67 | | //! or count data. For specifying samples after the first one |
68 | | Sample( const Abc::P3fArraySample &iPos ) |
69 | 0 | : m_positions( iPos ) {} |
70 | | |
71 | | |
72 | | //! Creates a sample with position data, index data, count data, |
73 | | //! and optional UV and Normals data. |
74 | | //! For specifying samples with an explicit topology. The first |
75 | | //! sample must be full like this. Subsequent samples may also |
76 | | //! be full like this, which would indicate a change of topology |
77 | | Sample( const Abc::P3fArraySample &iPos, |
78 | | const Abc::Int32ArraySample &iInd, |
79 | | const Abc::Int32ArraySample &iCnt, |
80 | | const OV2fGeomParam::Sample &iUVs = OV2fGeomParam::Sample(), |
81 | | const ON3fGeomParam::Sample &iNormals = ON3fGeomParam::Sample() ) |
82 | | : m_positions( iPos ) |
83 | | , m_indices( iInd ) |
84 | | , m_counts( iCnt ) |
85 | | , m_uvs( iUVs ) |
86 | | , m_normals( iNormals ) |
87 | 0 | {} |
88 | | |
89 | 0 | const Abc::P3fArraySample &getPositions() const { return m_positions; } |
90 | | void setPositions( const Abc::P3fArraySample &iSmp ) |
91 | 0 | { m_positions = iSmp; } |
92 | | |
93 | | // velocities accessor |
94 | 0 | const Abc::V3fArraySample &getVelocities() const { return m_velocities; } |
95 | | void setVelocities( const Abc::V3fArraySample &iVelocities ) |
96 | 0 | { m_velocities = iVelocities; } |
97 | | |
98 | 0 | const Abc::Int32ArraySample &getFaceIndices() const { return m_indices; } |
99 | | void setFaceIndices( const Abc::Int32ArraySample &iSmp ) |
100 | 0 | { m_indices = iSmp; } |
101 | | |
102 | 0 | const Abc::Int32ArraySample &getFaceCounts() const { return m_counts; } |
103 | | void setFaceCounts( const Abc::Int32ArraySample &iCnt ) |
104 | 0 | { m_counts = iCnt; } |
105 | | |
106 | 0 | const Abc::Box3d &getSelfBounds() const { return m_selfBounds; } |
107 | | void setSelfBounds( const Abc::Box3d &iBnds ) |
108 | 0 | { m_selfBounds = iBnds; } |
109 | | |
110 | 0 | const OV2fGeomParam::Sample &getUVs() const { return m_uvs; } |
111 | | void setUVs( const OV2fGeomParam::Sample &iUVs ) |
112 | 0 | { m_uvs = iUVs; } |
113 | | |
114 | 0 | const ON3fGeomParam::Sample &getNormals() const { return m_normals; } |
115 | | void setNormals( const ON3fGeomParam::Sample &iNormals ) |
116 | 0 | { m_normals = iNormals; } |
117 | | |
118 | | void reset() |
119 | 0 | { |
120 | 0 | m_positions.reset(); |
121 | 0 | m_indices.reset(); |
122 | 0 | m_counts.reset(); |
123 | 0 |
|
124 | 0 | m_selfBounds.makeEmpty(); |
125 | 0 |
|
126 | 0 | m_velocities.reset(); |
127 | 0 | m_uvs.reset(); |
128 | 0 | m_normals.reset(); |
129 | 0 | } |
130 | | |
131 | | bool isPartialSample() const |
132 | 0 | { |
133 | 0 | if( !m_positions.getData() && !m_indices.getData() && !m_counts.getData() ) |
134 | 0 | { |
135 | 0 | if( m_uvs.getVals() || m_normals.getVals() || m_velocities.getData() ) |
136 | 0 | { |
137 | 0 | return true; |
138 | 0 | } |
139 | 0 | } |
140 | 0 |
|
141 | 0 | return false; |
142 | 0 | } |
143 | | |
144 | | protected: |
145 | | Abc::P3fArraySample m_positions; |
146 | | Abc::Int32ArraySample m_indices; |
147 | | Abc::Int32ArraySample m_counts; |
148 | | |
149 | | Abc::Box3d m_selfBounds; |
150 | | |
151 | | Abc::V3fArraySample m_velocities; |
152 | | OV2fGeomParam::Sample m_uvs; |
153 | | ON3fGeomParam::Sample m_normals; |
154 | | |
155 | | }; |
156 | | //-************************************************************************* |
157 | | // POLY MESH SCHEMA |
158 | | //-************************************************************************* |
159 | | public: |
160 | | //! By convention we always define this_type in AbcGeom classes. |
161 | | //! Used by unspecified-bool-type conversion below |
162 | | typedef OPolyMeshSchema this_type; |
163 | | |
164 | | //-************************************************************************* |
165 | | // CONSTRUCTION, DESTRUCTION, ASSIGNMENT |
166 | | //-************************************************************************* |
167 | | |
168 | | //! The default constructor creates an empty OPolyMeshSchema |
169 | | //! ... |
170 | | OPolyMeshSchema() |
171 | 0 | { |
172 | 0 | m_selectiveExport = false; |
173 | 0 | m_numSamples = 0; |
174 | 0 | m_timeSamplingIndex = 0; |
175 | 0 | } |
176 | | |
177 | | //! This constructor creates a new poly mesh writer. |
178 | | //! The first argument is an CompoundPropertyWriterPtr to use as a parent. |
179 | | //! The next is the name to give the schema which is usually the default |
180 | | //! name given by OPolyMesh (.geom) The remaining optional arguments |
181 | | //! can be used to override the ErrorHandlerPolicy, to specify |
182 | | //! MetaData, specify sparse sampling and to set TimeSampling. |
183 | | OPolyMeshSchema( AbcA::CompoundPropertyWriterPtr iParent, |
184 | | const std::string &iName, |
185 | | const Abc::Argument &iArg0 = Abc::Argument(), |
186 | | const Abc::Argument &iArg1 = Abc::Argument(), |
187 | | const Abc::Argument &iArg2 = Abc::Argument(), |
188 | | const Abc::Argument &iArg3 = Abc::Argument() ); |
189 | | |
190 | | //! This constructor creates a new poly mesh writer. |
191 | | //! The first argument is an OCompundProperty to use as a parent, and from |
192 | | //! which the ErrorHandlerPolicy is derived. The next is the name to give |
193 | | //! the schema which is usually the default name given by OPolyMesh (.geom) |
194 | | //! The remaining optional arguments can be used to specify MetaData, |
195 | | //! specify sparse sampling and to set TimeSampling. |
196 | | OPolyMeshSchema( Abc::OCompoundProperty iParent, |
197 | | const std::string &iName, |
198 | | const Abc::Argument &iArg0 = Abc::Argument(), |
199 | | const Abc::Argument &iArg1 = Abc::Argument(), |
200 | | const Abc::Argument &iArg2 = Abc::Argument() ); |
201 | | |
202 | | //! Default assignment and copy operator used. |
203 | | |
204 | | //-************************************************************************* |
205 | | // SCHEMA STUFF |
206 | | //-************************************************************************* |
207 | | |
208 | | //! Return the time sampling type, which is stored on each of the |
209 | | //! sub properties. |
210 | | AbcA::TimeSamplingPtr getTimeSampling() const |
211 | 0 | { |
212 | 0 | if( m_positionsProperty.valid() ) |
213 | 0 | { |
214 | 0 | return m_positionsProperty.getTimeSampling(); |
215 | 0 | } |
216 | 0 | else |
217 | 0 | { |
218 | 0 | return getObject().getArchive().getTimeSampling( 0 ); |
219 | 0 | } |
220 | 0 | } |
221 | | |
222 | | //-************************************************************************* |
223 | | // SAMPLE STUFF |
224 | | //-************************************************************************* |
225 | | |
226 | | //! Get number of samples written so far. |
227 | | //! ... |
228 | | size_t getNumSamples() const |
229 | 0 | { return m_numSamples; } |
230 | | |
231 | | //! Set a sample! Sample zero has to have non-degenerate |
232 | | //! positions, indices and counts. |
233 | | void set( const Sample &iSamp ); |
234 | | |
235 | | //! Set from previous sample. Will apply to each of positions, |
236 | | //! indices, and counts. |
237 | | void setFromPrevious(); |
238 | | |
239 | | void setTimeSampling( uint32_t iIndex ); |
240 | | void setTimeSampling( AbcA::TimeSamplingPtr iTime ); |
241 | | |
242 | | //-************************************************************************* |
243 | | // ABC BASE MECHANISMS |
244 | | // These functions are used by Abc to deal with errors, validity, |
245 | | // and so on. |
246 | | //-************************************************************************* |
247 | | |
248 | | //! Reset returns this function set to an empty, default |
249 | | //! state. |
250 | | void reset() |
251 | 0 | { |
252 | 0 | m_positionsProperty.reset(); |
253 | 0 | m_velocitiesProperty.reset(); |
254 | 0 | m_indicesProperty.reset(); |
255 | 0 | m_countsProperty.reset(); |
256 | 0 | m_uvsParam.reset(); |
257 | 0 | m_normalsParam.reset(); |
258 | 0 |
|
259 | 0 | m_faceSets.clear(); |
260 | 0 |
|
261 | 0 | OGeomBaseSchema<PolyMeshSchemaInfo>::reset(); |
262 | 0 | } |
263 | | |
264 | | //! Valid returns whether this function set is |
265 | | //! valid. |
266 | | bool valid() const |
267 | 0 | { |
268 | 0 | return ( ( OGeomBaseSchema<PolyMeshSchemaInfo>::valid() && |
269 | 0 | m_positionsProperty.valid() && |
270 | 0 | m_indicesProperty.valid() && |
271 | 0 | m_countsProperty.valid() ) ) || |
272 | 0 | m_selectiveExport; |
273 | 0 | } |
274 | | |
275 | | // FaceSet stuff |
276 | | OFaceSet & createFaceSet( const std::string &iFaceSetName ); |
277 | | //! Appends the names of any FaceSets for this PolyMesh. |
278 | | void getFaceSetNames (std::vector <std::string> & oFaceSetNames); |
279 | | OFaceSet getFaceSet( const std::string &iFaceSetName ); |
280 | | bool hasFaceSet( const std::string &iFaceSetName ); |
281 | | |
282 | | //! Optional source name for the UV param. |
283 | | //! Must be set before the first UV sample is set. |
284 | | void setUVSourceName(const std::string & iName); |
285 | | |
286 | | //! unspecified-bool-type operator overload. |
287 | | //! ... |
288 | | ALEMBIC_OVERRIDE_OPERATOR_BOOL( OPolyMeshSchema::valid() ); |
289 | | |
290 | | private: |
291 | | void init( uint32_t iTsIdx, bool isSparse ); |
292 | | |
293 | | //! Set only some property data. Does not need to be a valid schema sample |
294 | | //! This is to be used when created a file which will be layered in to |
295 | | //! another file. |
296 | | void selectiveSet( const Sample &iSamp ); |
297 | | |
298 | | Abc::OP3fArrayProperty m_positionsProperty; |
299 | | Abc::OV3fArrayProperty m_velocitiesProperty; |
300 | | Abc::OInt32ArrayProperty m_indicesProperty; |
301 | | Abc::OInt32ArrayProperty m_countsProperty; |
302 | | |
303 | | // FaceSets created on this PolyMesh |
304 | | std::map <std::string, OFaceSet> m_faceSets; |
305 | | |
306 | | OV2fGeomParam m_uvsParam; |
307 | | ON3fGeomParam m_normalsParam; |
308 | | |
309 | | // optional source name for the UVs |
310 | | std::string m_uvSourceName; |
311 | | |
312 | | // Write out only some properties (UVs, normals). |
313 | | // This is to export data to layer into another file later. |
314 | | bool m_selectiveExport; |
315 | | |
316 | | // Number of times OPolyMeshSchema::set() has been called |
317 | | size_t m_numSamples; |
318 | | |
319 | | uint32_t m_timeSamplingIndex; |
320 | | |
321 | | void createPositionsProperty(); |
322 | | |
323 | | void createVelocitiesProperty(); |
324 | | |
325 | | void createUVsProperty( const Sample &iSamp ); |
326 | | |
327 | | void createNormalsProperty( const Sample &iSamp ); |
328 | | |
329 | | // self and child bounds and ArbGeomParams and UserProperties |
330 | | // all come from OGeomBaseSchema |
331 | | }; |
332 | | |
333 | | //-***************************************************************************** |
334 | | // SCHEMA OBJECT |
335 | | //-***************************************************************************** |
336 | | typedef Abc::OSchemaObject<OPolyMeshSchema> OPolyMesh; |
337 | | |
338 | | typedef Util::shared_ptr< OPolyMesh > OPolyMeshPtr; |
339 | | |
340 | | } // End namespace ALEMBIC_VERSION_NS |
341 | | |
342 | | using namespace ALEMBIC_VERSION_NS; |
343 | | |
344 | | } // End namespace AbcGeom |
345 | | } // End namespace Alembic |
346 | | |
347 | | #endif |