| 84 | }; |
| 85 | |
| 86 | void deleteCreases( MeshPrimitive *out, const MeshPrimitive *in, const std::vector<int> &remapping, const Canceller *canceller ) |
| 87 | { |
| 88 | const auto &lengths = in->creaseLengths()->readable(); |
| 89 | if( lengths.empty() ) |
| 90 | { |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | const auto &ids = in->creaseIds()->readable(); |
| 95 | const auto &sharpnesses = in->creaseSharpnesses()->readable(); |
| 96 | |
| 97 | IntVectorDataPtr outLengthData = new IntVectorData; |
| 98 | auto &outLengths = outLengthData->writable(); |
| 99 | |
| 100 | IntVectorDataPtr outIdData = new IntVectorData; |
| 101 | auto &outIds = outIdData->writable(); |
| 102 | |
| 103 | FloatVectorDataPtr outSharpnessData = new FloatVectorData; |
| 104 | auto &outSharpnesses = outSharpnessData->writable(); |
| 105 | |
| 106 | int creaseIdOffset = 0; |
| 107 | for( size_t i = 0; i < lengths.size(); ++i ) |
| 108 | { |
| 109 | if( i % 1000 == 0 ) |
| 110 | { |
| 111 | Canceller::check( canceller ); |
| 112 | } |
| 113 | |
| 114 | int j = 0; |
| 115 | while( j < lengths[i] ) |
| 116 | { |
| 117 | // Skip non included verts |
| 118 | while( j < lengths[i] && remapping[ ids[ creaseIdOffset + j ] ] == -1 ) |
| 119 | { |
| 120 | j++; |
| 121 | } |
| 122 | int startCrease = j; |
| 123 | |
| 124 | // Scan until we reach the end, or a vert that isn't included. |
| 125 | // If there in a non-included vert in the middle of a crease of length 5 or more, |
| 126 | // we may need to output more than one crease per input crease. |
| 127 | while( j < lengths[i] && remapping[ ids[ creaseIdOffset + j ] ] != -1 ) |
| 128 | { |
| 129 | j++; |
| 130 | } |
| 131 | |
| 132 | // We've either reached the end, or a non-included vert - output a crease |
| 133 | if( j - startCrease >= 2 ) |
| 134 | { |
| 135 | for( int k = startCrease; k < j; k++ ) |
| 136 | { |
| 137 | // \todo - a little wasteful here, should be caching these lookups in the remapping map |
| 138 | outIds.push_back( remapping[ ids[ creaseIdOffset + k ] ] ); |
| 139 | } |
| 140 | outLengths.push_back( j - startCrease ); |
| 141 | outSharpnesses.push_back( sharpnesses[i] ); |
| 142 | } |
| 143 | } |
no test coverage detected