//-***************************************************************************** void OFaceSetSchema::set( const Sample &iSamp ) { ALEMBIC_ABC_SAFE_CALL_BEGIN( "OFaceSetSchema::set()" ); Abc::Box3d emptyBox; emptyBox.makeEmpty(); // do we need to create child bounds? if ( iSamp.getChildBounds().hasVolume() && !m_childBoundsProperty) { m_childBoundsProperty = Abc::OBox3dProperty( this->getPtr(), ".childBnds", m_facesProperty.getTimeSampling() ); // -1 because we just dis an m_positions set above size_t numSamples = m_facesProperty.getNumSamples() - 1; // set all the missing samples for ( size_t i = 0; i < numSamples; ++i ) { m_childBoundsProperty.set( emptyBox ); } } // We could add sample integrity checking here. if ( m_facesProperty.getNumSamples () == 0 ) { // First sample must provide faces ABCA_ASSERT( iSamp.getFaces() , "Sample 0 must provide the faces that make up the faceset." ); m_facesProperty.set( iSamp.getFaces() ); if (m_childBoundsProperty) { m_childBoundsProperty.set( iSamp.getChildBounds() ); } } else { SetPropUsePrevIfNull( m_facesProperty, iSamp.getFaces() ); if ( m_childBoundsProperty ) { SetPropUsePrevIfNull( m_childBoundsProperty, iSamp.getChildBounds() ); } } // We've now set the sample for the m_faces property. if ( iSamp.getSelfBounds().hasVolume() ) { // Caller explicity set bounds for this sample of the faceset. m_selfBoundsProperty.set( iSamp.getSelfBounds() ); } else { m_selfBoundsProperty.set( iSamp.getSelfBounds() ); // NYI compute self bounds via parent mesh's faces } if (m_facesExclusive != kFaceSetNonExclusive) { // The user has changed the exclusivity hint from the // default so we'll create a property now and store. _recordExclusivityHint(); } ALEMBIC_ABC_SAFE_CALL_END(); }
//-***************************************************************************** Abc::Box3d PolyMesh::writeSample( const Abc::OSampleSelector &iSS ) { // First, call base class sample write, which will return bounds // of any children. Abc::index_t sampleIndex = iSS.getIndex(); Abc::Box3d bounds = Exportable::writeSample( iSS ); // If we're not deforming, don't bother with new sample. // Do calculate bounds and set them, though. if ( sampleIndex != 0 && !m_deforming ) { bounds.extendBy( m_firstSampleSelfBounds ); m_boundsProperty.set( bounds, iSS ); return bounds; } // Make a mesh MStatus status; MFnMesh mesh( m_dagPath, &status ); CHECK_MAYA_STATUS; mesh.updateSurface(); mesh.syncObject(); // Make a sample. Abc::OPolyMeshSchema::Sample abcPolyMeshSample; //-************************************************************************* // WRITE VERTICES //-************************************************************************* MPointArray vertices; mesh.getPoints( vertices ); size_t npoints = vertices.length(); std::vector<Abc::V3f> v3fVerts( npoints ); Abc::Box3d shapeBounds; shapeBounds.makeEmpty(); for ( size_t i = 0; i < npoints; ++i ) { const MPoint &vi = vertices[i]; Abc::V3f pi( vi.x, vi.y, vi.z ); v3fVerts[i] = pi; shapeBounds.extendBy( Abc::V3d( vi.x, vi.y, vi.z ) ); } if ( sampleIndex == 0 ) { m_firstSampleSelfBounds = shapeBounds; } bounds.extendBy( shapeBounds ); // Set the bounds sample. m_boundsProperty.set( bounds, iSS ); // Stuff the positions into the mesh sample. abcPolyMeshSample.setPositions( Abc::V3fArraySample( v3fVerts ) ); //-************************************************************************* // OTHER STUFF, FOR FIRST OR LATER VERTICES //-************************************************************************* std::vector<Abc::int32_t> abcIndices; std::vector<Abc::int32_t> abcCounts; std::vector<Abc::N3f> abcNormals; std::vector<Abc::V2f> abcUvs; //-************************************************************************* // GET MESH NORMALS & UVS //-************************************************************************* size_t nnormals = mesh.numNormals(); MFloatVectorArray meshNorms; if ( nnormals > 0 ) { mesh.getNormals( meshNorms, MSpace::kObject ); } size_t nuvs = mesh.numUVs(); MFloatArray meshU; MFloatArray meshV; if ( nuvs > 0 ) { mesh.getUVs( meshU, meshV ); } //-************************************************************************* // LOOP OVER FIRST OR SUBSEQUENT SAMPLES //-************************************************************************* if ( sampleIndex == 0 ) { // FIRST SAMPLE // Loop over polys. size_t npolys = mesh.numPolygons(); abcCounts.resize( npolys ); Abc::int32_t faceIndex = 0; Abc::int32_t faceStartVertexIndex = 0; for ( MItMeshPolygon piter( m_dagPath ); !piter.isDone(); piter.next(), ++faceIndex ) { Abc::int32_t faceCount = piter.polygonVertexCount(); abcCounts[faceIndex] = faceCount; faceStartVertexIndex += faceCount; for ( Abc::int32_t faceVertex = 0; faceVertex < faceCount; ++faceVertex ) { abcIndices.push_back( piter.vertexIndex( faceVertex ) ); if ( nnormals > 0 ) { size_t normIndex = piter.normalIndex( faceVertex ); const MFloatVector &norm = meshNorms[normIndex]; Abc::N3f abcNorm( norm[0], norm[1], norm[2] ); abcNormals.push_back( abcNorm ); } if ( nuvs > 0 ) { int uvIndex = 0; piter.getUVIndex( faceVertex, uvIndex ); Abc::V2f abcUv( meshU[uvIndex], meshV[uvIndex] ); abcUvs.push_back( abcUv ); } } } // We have now collected abcIndices, abcStarts, abcNormals, and abcUvs. // Put them into the sample. abcPolyMeshSample.setIndices( Abc::Int32ArraySample( abcIndices ) ); abcPolyMeshSample.setCounts( Abc::Int32ArraySample( abcCounts ) ); if ( nnormals > 0 && m_normals ) { m_normals.set( Abc::N3fArraySample( abcNormals ), iSS ); } if ( nuvs > 0 && m_sts ) { m_sts.set( Abc::V2fArraySample( abcUvs ), iSS ); } } else if ( ( nnormals > 0 && m_normals ) || ( nuvs > 0 && m_sts ) ) { // SUBSEQUENT SAMPLES // Just gathering normals and uvs. // (vertices handled above) // Loop over polys. Abc::int32_t faceIndex = 0; Abc::int32_t faceStartVertexIndex = 0; for ( MItMeshPolygon piter( m_dagPath ); !piter.isDone(); piter.next(), ++faceIndex ) { Abc::int32_t faceCount = piter.polygonVertexCount(); for ( Abc::int32_t faceVertex = 0; faceVertex < faceCount; ++faceVertex ) { if ( nnormals > 0 ) { size_t normIndex = piter.normalIndex( faceVertex ); const MFloatVector &norm = meshNorms[normIndex]; Abc::N3f abcNorm( norm[0], norm[1], norm[2] ); abcNormals.push_back( abcNorm ); } if ( nuvs > 0 ) { int uvIndex = 0; piter.getUVIndex( faceVertex, uvIndex ); Abc::V2f abcUv( meshU[uvIndex], meshV[uvIndex] ); abcUvs.push_back( abcUv ); } } } // We have now collected abcNormals, and abcUvs. // Put them into the sample. if ( nnormals > 0 && m_normals ) { m_normals.set( Abc::N3fArraySample( abcNormals ), iSS ); } if ( nuvs > 0 ) { m_sts.set( Abc::V2fArraySample( abcUvs ), iSS ); } } // Set the mesh sample. m_polyMesh.getSchema().set( abcPolyMeshSample, iSS ); return bounds; }