Alembic Version 1.1
OPolyMesh.h
Go to the documentation of this file.
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>
46
47namespace Alembic {
48namespace AbcGeom {
49namespace ALEMBIC_VERSION_NS {
50
51//-*****************************************************************************
53 : public OGeomBaseSchema<PolyMeshSchemaInfo>
54{
55public:
56 //-*************************************************************************
57 // POLY MESH SCHEMA SAMPLE TYPE
58 //-*************************************************************************
59 class Sample
60 {
61 public:
64 Sample() { reset(); }
65
69 : m_positions( iPos ) {}
70
71
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 {}
88
89 const Abc::P3fArraySample &getPositions() const { return m_positions; }
91 { m_positions = iSmp; }
92
93 // velocities accessor
94 const Abc::V3fArraySample &getVelocities() const { return m_velocities; }
95 void setVelocities( const Abc::V3fArraySample &iVelocities )
96 { m_velocities = iVelocities; }
97
98 const Abc::Int32ArraySample &getFaceIndices() const { return m_indices; }
100 { m_indices = iSmp; }
101
102 const Abc::Int32ArraySample &getFaceCounts() const { return m_counts; }
104 { m_counts = iCnt; }
105
106 const Abc::Box3d &getSelfBounds() const { return m_selfBounds; }
107 void setSelfBounds( const Abc::Box3d &iBnds )
108 { m_selfBounds = iBnds; }
109
110 const OV2fGeomParam::Sample &getUVs() const { return m_uvs; }
111 void setUVs( const OV2fGeomParam::Sample &iUVs )
112 { m_uvs = iUVs; }
113
114 const ON3fGeomParam::Sample &getNormals() const { return m_normals; }
115 void setNormals( const ON3fGeomParam::Sample &iNormals )
116 { m_normals = iNormals; }
117
118 void reset()
119 {
120 m_positions.reset();
121 m_indices.reset();
122 m_counts.reset();
123
124 m_selfBounds.makeEmpty();
125
126 m_velocities.reset();
127 m_uvs.reset();
128 m_normals.reset();
129 }
130
131 bool isPartialSample() const
132 {
133 if( !m_positions.getData() && !m_indices.getData() && !m_counts.getData() )
134 {
135 if( m_uvs.getVals() || m_normals.getVals() || m_velocities.getData() )
136 {
137 return true;
138 }
139 }
140
141 return false;
142 }
143
144 protected:
148
149 Abc::Box3d m_selfBounds;
150
152 OV2fGeomParam::Sample m_uvs;
153 ON3fGeomParam::Sample m_normals;
154
155 };
156 //-*************************************************************************
157 // POLY MESH SCHEMA
158 //-*************************************************************************
159public:
163
164 //-*************************************************************************
165 // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
166 //-*************************************************************************
167
171 {
172 m_selectiveExport = false;
173 m_numSamples = 0;
174 m_timeSamplingIndex = 0;
175 }
176
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
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
204 : OGeomBaseSchema<PolyMeshSchemaInfo>()
205 {
206 *this = iCopy;
207 }
208
210
211 //-*************************************************************************
212 // SCHEMA STUFF
213 //-*************************************************************************
214
218 {
219 if( m_positionsProperty.valid() )
220 {
221 return m_positionsProperty.getTimeSampling();
222 }
223 else
224 {
225 return getObject().getArchive().getTimeSampling( 0 );
226 }
227 }
228
229 //-*************************************************************************
230 // SAMPLE STUFF
231 //-*************************************************************************
232
235 size_t getNumSamples() const
236 { return m_numSamples; }
237
240 void set( const Sample &iSamp );
241
245
246 void setTimeSampling( uint32_t iIndex );
248
249 //-*************************************************************************
250 // ABC BASE MECHANISMS
251 // These functions are used by Abc to deal with errors, validity,
252 // and so on.
253 //-*************************************************************************
254
257 void reset()
258 {
259 m_positionsProperty.reset();
260 m_velocitiesProperty.reset();
261 m_indicesProperty.reset();
262 m_countsProperty.reset();
263 m_uvsParam.reset();
264 m_normalsParam.reset();
265
266 m_faceSets.clear();
267
269 }
270
273 bool valid() const
274 {
276 m_positionsProperty.valid() &&
277 m_indicesProperty.valid() &&
278 m_countsProperty.valid() ) ) ||
279 m_selectiveExport;
280 }
281
282 // FaceSet stuff
283 OFaceSet & createFaceSet( const std::string &iFaceSetName );
285 void getFaceSetNames (std::vector <std::string> & oFaceSetNames);
286 OFaceSet getFaceSet( const std::string &iFaceSetName );
287 bool hasFaceSet( const std::string &iFaceSetName );
288
291 void setUVSourceName(const std::string & iName);
292
296
297private:
298 void init( uint32_t iTsIdx, bool isSparse );
299
303 void selectiveSet( const Sample &iSamp );
304
305 Abc::OP3fArrayProperty m_positionsProperty;
306 Abc::OV3fArrayProperty m_velocitiesProperty;
307 Abc::OInt32ArrayProperty m_indicesProperty;
308 Abc::OInt32ArrayProperty m_countsProperty;
309
310 // FaceSets created on this PolyMesh
311 std::map <std::string, OFaceSet> m_faceSets;
312
313 OV2fGeomParam m_uvsParam;
314 ON3fGeomParam m_normalsParam;
315
316 // optional source name for the UVs
317 std::string m_uvSourceName;
318
319 // Write out only some properties (UVs, normals).
320 // This is to export data to layer into another file later.
321 bool m_selectiveExport;
322
323 // Number of times OPolyMeshSchema::set() has been called
324 size_t m_numSamples;
325
326 uint32_t m_timeSamplingIndex;
327
328 void createPositionsProperty();
329
330 void createVelocitiesProperty();
331
332 void createUVsProperty( const Sample &iSamp );
333
334 void createNormalsProperty( const Sample &iSamp );
335
336 // self and child bounds and ArbGeomParams and UserProperties
337 // all come from OGeomBaseSchema
338};
339
340//-*****************************************************************************
341// SCHEMA OBJECT
342//-*****************************************************************************
344
345typedef Util::shared_ptr< OPolyMesh > OPolyMeshPtr;
346
347} // End namespace ALEMBIC_VERSION_NS
348
349using namespace ALEMBIC_VERSION_NS;
350
351} // End namespace AbcGeom
352} // End namespace Alembic
353
354#endif
#define ALEMBIC_EXPORT
Definition: Export.h:51
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:105
Sample(const Abc::P3fArraySample &iPos, const Abc::Int32ArraySample &iInd, const Abc::Int32ArraySample &iCnt, const OV2fGeomParam::Sample &iUVs=OV2fGeomParam::Sample(), const ON3fGeomParam::Sample &iNormals=ON3fGeomParam::Sample())
Definition: OPolyMesh.h:77
void setFaceCounts(const Abc::Int32ArraySample &iCnt)
Definition: OPolyMesh.h:103
const ON3fGeomParam::Sample & getNormals() const
Definition: OPolyMesh.h:114
const Abc::Int32ArraySample & getFaceIndices() const
Definition: OPolyMesh.h:98
const Abc::P3fArraySample & getPositions() const
Definition: OPolyMesh.h:89
const Abc::Int32ArraySample & getFaceCounts() const
Definition: OPolyMesh.h:102
void setNormals(const ON3fGeomParam::Sample &iNormals)
Definition: OPolyMesh.h:115
const Abc::V3fArraySample & getVelocities() const
Definition: OPolyMesh.h:94
void setFaceIndices(const Abc::Int32ArraySample &iSmp)
Definition: OPolyMesh.h:99
void setUVs(const OV2fGeomParam::Sample &iUVs)
Definition: OPolyMesh.h:111
void setPositions(const Abc::P3fArraySample &iSmp)
Definition: OPolyMesh.h:90
const OV2fGeomParam::Sample & getUVs() const
Definition: OPolyMesh.h:110
void setVelocities(const Abc::V3fArraySample &iVelocities)
Definition: OPolyMesh.h:95
AbcA::TimeSamplingPtr getTimeSampling() const
Default assignment operator used.
Definition: OPolyMesh.h:217
OPolyMeshSchema(const OPolyMeshSchema &iCopy)
Copy constructor.
Definition: OPolyMesh.h:203
OFaceSet & createFaceSet(const std::string &iFaceSetName)
void getFaceSetNames(std::vector< std::string > &oFaceSetNames)
Appends the names of any FaceSets for this PolyMesh.
OFaceSet getFaceSet(const std::string &iFaceSetName)
void setTimeSampling(AbcA::TimeSamplingPtr iTime)
OPolyMeshSchema(AbcA::CompoundPropertyWriterPtr iParent, const std::string &iName, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument(), const Abc::Argument &iArg2=Abc::Argument(), const Abc::Argument &iArg3=Abc::Argument())
bool hasFaceSet(const std::string &iFaceSetName)
OPolyMeshSchema(Abc::OCompoundProperty iParent, const std::string &iName, const Abc::Argument &iArg0=Abc::Argument(), const Abc::Argument &iArg1=Abc::Argument(), const Abc::Argument &iArg2=Abc::Argument())
Alembic::Util::shared_ptr< CompoundPropertyWriter > CompoundPropertyWriterPtr
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
Abc::OSchemaObject< OPolyMeshSchema > OPolyMesh
Definition: OPolyMesh.h:343
Util::shared_ptr< OPolyMesh > OPolyMeshPtr
Definition: OPolyMesh.h:345
Alembic namespace ...
Definition: ArchiveInfo.h:46