| 171 | } |
| 172 | |
| 173 | std::shared_ptr<ObjectMesh> merge( const std::vector<std::shared_ptr<ObjectMesh>>& objsMesh, const ObjectMeshMergeOptions& options ) |
| 174 | { |
| 175 | MR_TIMER; |
| 176 | std::shared_ptr<ObjectMesh> res; |
| 177 | const auto firstNotEmptyIt = std::find_if( objsMesh.begin(), objsMesh.end(), []( const auto & p ) { return p && p->mesh(); } ); |
| 178 | if ( firstNotEmptyIt == objsMesh.end() ) |
| 179 | return res; // if no input object, then no output |
| 180 | res = std::make_shared<ObjectMesh>(); |
| 181 | res->copyAllSolidColors( **firstNotEmptyIt ); |
| 182 | |
| 183 | bool hasVertColorMap = false; // save if at least one has |
| 184 | bool hasFaceColorMap = false; // save if at least one has |
| 185 | bool needSaveUVCoords = true; // save if all have |
| 186 | |
| 187 | bool needSaveTextures = true; // save if all have textures of same size |
| 188 | bool exactSameTextures = true; // true if all object has identical textures |
| 189 | |
| 190 | const Vector<MeshTexture, TextureId>* prevObjTextures = nullptr; |
| 191 | |
| 192 | |
| 193 | size_t numTextures = 0; |
| 194 | size_t totalVerts = 0; |
| 195 | size_t totalFaces = 0; |
| 196 | size_t numObject = 0; |
| 197 | for ( const auto& obj : objsMesh ) |
| 198 | { |
| 199 | if ( auto curMesh = obj->mesh() ) |
| 200 | { |
| 201 | totalVerts += curMesh->topology.numValidVerts(); |
| 202 | totalFaces += curMesh->topology.numValidFaces(); |
| 203 | if ( !obj->getVertsColorMap().empty() ) |
| 204 | hasVertColorMap = true; |
| 205 | if ( !obj->getFacesColorMap().empty() ) |
| 206 | hasFaceColorMap = true; |
| 207 | if ( obj->getUVCoords().empty() ) |
| 208 | needSaveUVCoords = false; |
| 209 | |
| 210 | if ( !needSaveTextures ) |
| 211 | continue; |
| 212 | |
| 213 | const auto& textures = obj->getTextures(); |
| 214 | numTextures += textures.size(); |
| 215 | if ( textures.empty() ) |
| 216 | { |
| 217 | needSaveTextures = false; |
| 218 | continue; |
| 219 | } |
| 220 | if ( !prevObjTextures ) |
| 221 | { |
| 222 | prevObjTextures = &textures; |
| 223 | continue; |
| 224 | } |
| 225 | assert( prevObjTextures ); |
| 226 | if ( prevObjTextures->size() != textures.size() ) |
| 227 | exactSameTextures = false; |
| 228 | if ( prevObjTextures->front().resolution != textures.front().resolution ) |
| 229 | { |
| 230 | needSaveTextures = false; |
no test coverage detected