| 661 | }; |
| 662 | |
| 663 | struct ResamplePrimitiveVariableFunctor |
| 664 | { |
| 665 | |
| 666 | // Resample a primitive variable, given all the necessary indices from the mesh. |
| 667 | // |
| 668 | // The implementation is all pretty straightforward, since we already have the |
| 669 | // indices we need for each case prepared, and we can use Reindexer to deal with |
| 670 | // indexed primvars. |
| 671 | // |
| 672 | // All the bogus [[maybe_unused]] statements are required due to this bug: |
| 673 | // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81676 |
| 674 | // which I think was fixed in GCC 10, but I haven't tested |
| 675 | |
| 676 | template<typename T> |
| 677 | PrimitiveVariable operator()( [[maybe_unused]] const T *data, const PrimitiveVariable &primVar, [[maybe_unused]] int startIndex, [[maybe_unused]] int numFaces, [[maybe_unused]] int totalFaceVerts, [[maybe_unused]] const std::vector<int> &faceRemap, [[maybe_unused]] const std::vector<int> &verticesPerFace, [[maybe_unused]] const std::vector<int> &faceIndices, [[maybe_unused]] const std::vector<int> &vertRemapBackwards, [[maybe_unused]] const Canceller *canceller ) |
| 678 | { |
| 679 | if( |
| 680 | primVar.interpolation != PrimitiveVariable::Interpolation::Uniform && |
| 681 | primVar.interpolation != PrimitiveVariable::Interpolation::Vertex && |
| 682 | primVar.interpolation != PrimitiveVariable::Interpolation::Varying && |
| 683 | primVar.interpolation != PrimitiveVariable::Interpolation::FaceVarying |
| 684 | ) |
| 685 | { |
| 686 | // Just copying works for constants |
| 687 | return primVar; |
| 688 | } |
| 689 | |
| 690 | if constexpr ( ! IECore::TypeTraits::IsVectorTypedData< T >::value ) |
| 691 | { |
| 692 | throw IECore::Exception( "Invalid PrimitiveVariable, data is not a vector." ); |
| 693 | } |
| 694 | else |
| 695 | { |
| 696 | const typename T::ValueType &in = data->readable(); |
| 697 | typename T::Ptr outData = new T; |
| 698 | if constexpr ( IECore::TypeTraits::IsGeometricTypedData< T >::value ) |
| 699 | { |
| 700 | outData->setInterpretation( data->getInterpretation() ); |
| 701 | } |
| 702 | |
| 703 | typename T::ValueType &out = outData->writable(); |
| 704 | |
| 705 | if( !primVar.indices ) |
| 706 | { |
| 707 | switch( primVar.interpolation ) |
| 708 | { |
| 709 | case PrimitiveVariable::Interpolation::Uniform: |
| 710 | out.reserve( numFaces ); |
| 711 | for( int i = 0; i < numFaces; i++ ) |
| 712 | { |
| 713 | out.push_back( in[ faceRemap[ startIndex + i ] ] ); |
| 714 | } |
| 715 | break; |
| 716 | case PrimitiveVariable::Interpolation::Vertex: |
| 717 | case PrimitiveVariable::Interpolation::Varying: |
| 718 | out.reserve( vertRemapBackwards.size() ); |
| 719 | for( int remap : vertRemapBackwards ) |
| 720 | { |