Alembic 1.8.11
Loading...
Searching...
No Matches
OPolyMesh.h
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
47namespace Alembic {
48namespace AbcGeom {
49namespace ALEMBIC_VERSION_NS {
50
51//-*****************************************************************************
52class ALEMBIC_EXPORT OPolyMeshSchema
53 : public OGeomBaseSchema<PolyMeshSchemaInfo>
54{
55public:
56 //-*************************************************************************
57 // POLY MESH SCHEMA SAMPLE TYPE
58 //-*************************************************************************
59 class Sample
60 {
61 public:
64 Sample() { reset(); }
65
68 Sample( const Abc::P3fArraySample &iPos )
69 : m_positions( iPos ) {}
70
71
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 {}
88
89 const Abc::P3fArraySample &getPositions() const { return m_positions; }
90 void setPositions( const Abc::P3fArraySample &iSmp )
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; }
99 void setFaceIndices( const Abc::Int32ArraySample &iSmp )
100 { m_indices = iSmp; }
101
102 const Abc::Int32ArraySample &getFaceCounts() const { return m_counts; }
103 void setFaceCounts( const Abc::Int32ArraySample &iCnt )
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:
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 //-*************************************************************************
159public:
163
164 //-*************************************************************************
165 // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
166 //-*************************************************************************
167
171 {
172 m_selectiveExport = false;
173 m_numSamples = 0;
174 m_timeSamplingIndex = 0;
175 }
176
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
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
203
204 //-*************************************************************************
205 // SCHEMA STUFF
206 //-*************************************************************************
207
210 AbcA::TimeSamplingPtr getTimeSampling() const
211 {
212 if( m_positionsProperty.valid() )
213 {
214 return m_positionsProperty.getTimeSampling();
215 }
216 else
217 {
218 return getObject().getArchive().getTimeSampling( 0 );
219 }
220 }
221
222 //-*************************************************************************
223 // SAMPLE STUFF
224 //-*************************************************************************
225
228 size_t getNumSamples() const
229 { return m_numSamples; }
230
233 void set( const Sample &iSamp );
234
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
250 void reset()
251 {
252 m_positionsProperty.reset();
253 m_velocitiesProperty.reset();
254 m_indicesProperty.reset();
255 m_countsProperty.reset();
256 m_uvsParam.reset();
257 m_normalsParam.reset();
258
259 m_faceSets.clear();
260
261 OGeomBaseSchema<PolyMeshSchemaInfo>::reset();
262 }
263
266 bool valid() const
267 {
268 return ( ( OGeomBaseSchema<PolyMeshSchemaInfo>::valid() &&
269 m_positionsProperty.valid() &&
270 m_indicesProperty.valid() &&
271 m_countsProperty.valid() ) ) ||
272 m_selectiveExport;
273 }
274
275 // FaceSet stuff
276 OFaceSet & createFaceSet( const std::string &iFaceSetName );
278 void getFaceSetNames (std::vector <std::string> & oFaceSetNames);
279 OFaceSet getFaceSet( const std::string &iFaceSetName );
280 bool hasFaceSet( const std::string &iFaceSetName );
281
284 void setUVSourceName(const std::string & iName);
285
289
290private:
291 void init( uint32_t iTsIdx, bool isSparse );
292
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//-*****************************************************************************
337
338typedef Util::shared_ptr< OPolyMesh > OPolyMeshPtr;
339
340} // End namespace ALEMBIC_VERSION_NS
341
342using namespace ALEMBIC_VERSION_NS;
343
344} // End namespace AbcGeom
345} // End namespace Alembic
346
347#endif
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
Sample(const Abc::P3fArraySample &iPos)
Definition OPolyMesh.h:68
AbcA::TimeSamplingPtr getTimeSampling() const
Default assignment and copy operator used.
Definition OPolyMesh.h:210
size_t getNumSamples() const
Definition OPolyMesh.h:228
bool valid() const
Definition OPolyMesh.h:266
OPolyMeshSchema this_type
Definition OPolyMesh.h:162
Alembic namespace ...
Definition ArchiveInfo.cpp:39