1212#include " MRPch/MRJson.h"
1313#include " MRPch/MRTBB.h"
1414#include " MRPch/MRFmt.h"
15- #include " MRSceneSettings.h"
1615
1716namespace MR
1817{
@@ -189,12 +188,8 @@ std::shared_ptr<ObjectMesh> merge( const std::vector<std::shared_ptr<ObjectMesh>
189188
190189 bool hasVertColorMap = false ;
191190 bool hasFaceColorMap = false ;
192- bool needSaveTexture = true ;
193- Vector2i resolution ( -1 , -1 );
194- size_t numTexture = 0 ;
195191 size_t totalVerts = 0 ;
196192 size_t totalFaces = 0 ;
197- size_t numObject = 0 ;
198193 for ( const auto & obj : objsMesh )
199194 {
200195 if ( auto curMesh = obj->mesh () )
@@ -205,24 +200,6 @@ std::shared_ptr<ObjectMesh> merge( const std::vector<std::shared_ptr<ObjectMesh>
205200 hasVertColorMap = true ;
206201 if ( !obj->getFacesColorMap ().empty () )
207202 hasFaceColorMap = true ;
208-
209- const auto & textures = obj->getTextures ();
210- if ( needSaveTexture )
211- {
212- if ( textures.empty () )
213- {
214- needSaveTexture = false ;
215- continue ;
216- }
217-
218- numTexture += textures.size ();
219- numObject++;
220-
221- if ( resolution.x == -1 )
222- resolution = textures.back ().resolution ;
223- else if ( resolution != textures.back ().resolution )
224- needSaveTexture = false ;
225- }
226203 }
227204 }
228205 auto mesh = std::make_shared<Mesh>();
@@ -238,27 +215,14 @@ std::shared_ptr<ObjectMesh> merge( const std::vector<std::shared_ptr<ObjectMesh>
238215 if ( hasFaceColorMap )
239216 faceColors.resizeNoInit ( totalFaces );
240217
241- VertUVCoords uvCoords;
242- Vector<TextureId, FaceId> texturePerFace;
243- Vector<MeshTexture, TextureId> textures;
244- if ( needSaveTexture )
245- {
246- texturePerFace.resizeNoInit ( totalFaces );
247- uvCoords.resizeNoInit ( totalVerts );
248- textures.reserve ( numTexture );
249- }
250-
251- numObject = 0 ;
252- TextureId previousNumTexture (-1 );
253- TextureId curNumTexture (-1 );
254218 for ( const auto & obj : objsMesh )
255219 {
256220 if ( !obj->mesh () )
257221 continue ;
258222
259223 VertMap vertMap;
260224 FaceMap faceMap;
261- mesh->addPart ( *obj->mesh (), hasFaceColorMap || needSaveTexture ? &faceMap : nullptr , &vertMap );
225+ mesh->addPart ( *obj->mesh (), hasFaceColorMap ? &faceMap : nullptr , &vertMap );
262226
263227 auto worldXf = obj->worldXf ();
264228 for ( const auto & vInd : vertMap )
@@ -285,66 +249,19 @@ std::shared_ptr<ObjectMesh> merge( const std::vector<std::shared_ptr<ObjectMesh>
285249 faceColors[mergeId] = curColorMap.size () <= thisId ? obj->getFrontColor () : curColorMap[thisId];
286250 }
287251 }
288- if ( needSaveTexture )
289- {
290- const auto & curUvCoords = obj->getUVCoords ();
291- for ( VertId thisId = 0_v; thisId < vertMap.size (); ++thisId )
292- {
293- if ( auto mergeId = vertMap[thisId] )
294- uvCoords[mergeId] = curUvCoords[thisId];
295- }
296- const auto curTextures = obj->getTextures ();
297- textures.vec_ .insert ( textures.vec_ .end (), curTextures.vec_ .begin (), curTextures.vec_ .end () );
298-
299- if ( numObject == 0 )
300- curNumTexture = TextureId ( 0 );
301- else
302- curNumTexture += previousNumTexture;
303-
304- previousNumTexture = TextureId ( curTextures.size () );
305-
306- const auto & curTexturePerFace = obj->getTexturePerFace ();
307- for ( FaceId thisId = 0_f; thisId < faceMap.size (); ++thisId )
308- {
309- if ( auto mergeId = faceMap[thisId] )
310- texturePerFace[mergeId] = curNumTexture + curTexturePerFace[thisId];
311- }
312- }
313- numObject++;
314252 }
315253 assert ( totalVerts == mesh->topology .numValidVerts () );
316254 assert ( totalFaces == mesh->topology .numValidFaces () );
317255
318256 auto objectMesh = std::make_shared<ObjectMesh>();
319- // if this data does not need to be set, it will be empty at this point
320257 objectMesh->setVertsColorMap ( std::move ( vertColors ) );
321258 objectMesh->setFacesColorMap ( std::move ( faceColors ) );
322259 objectMesh->setMesh ( std::move ( mesh ) );
323- objectMesh->setTexturePerFace ( std::move ( texturePerFace ) );
324- objectMesh->setTextures ( std::move ( textures ) );
325- objectMesh->setUVCoords ( std::move ( uvCoords ) );
326260 if ( hasVertColorMap )
327261 objectMesh->setColoringType ( ColoringType::VertsColorMap );
328262 else if ( hasFaceColorMap )
329263 objectMesh->setColoringType ( ColoringType::FacesColorMap );
330264
331- ViewportMask flat = ViewportMask::all ();
332- ViewportMask smooth = ViewportMask::all ();
333- for ( const auto & obj : objsMesh )
334- {
335- ViewportMask shading = obj->getVisualizePropertyMask ( MeshVisualizePropertyType::FlatShading );
336- flat &= shading;
337- smooth &= ( ~shading );
338- }
339-
340- if ( SceneSettings::getDefaultShadingMode () == SceneSettings::ShadingMode::Flat )
341- objectMesh->setVisualizePropertyMask ( MeshVisualizePropertyType::FlatShading, ~smooth );
342- else
343- objectMesh->setVisualizePropertyMask ( MeshVisualizePropertyType::FlatShading, flat );
344-
345- if ( !objectMesh->getTextures ().empty () )
346- objectMesh->setVisualizePropertyMask ( MeshVisualizePropertyType::Texture, ViewportMask::all () );
347-
348265 return objectMesh;
349266}
350267
0 commit comments