MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / makeObjectMesh

Function makeObjectMesh

source/MRMesh/MRObjectLoad.cpp:223–273  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221}
222
223LoadedObject makeObjectMesh( std::string objName, LoadedMeshData data )
224{
225 MR_TIMER;
226 assert( data.mesh );
227
228 std::string warnings;
229 const auto numVerts = data.mesh->points.size();
230 bool hasVertColors = !data.vertColors.empty();
231 if ( hasVertColors && data.vertColors.size() < numVerts )
232 {
233 hasVertColors = false;
234 warnings += fmt::format( "Ignoring too few ({}) colors loaded for a mesh with {} vertices.\n", data.vertColors.size(), numVerts );
235 data.vertColors.clear();
236 }
237 bool hasUV = !data.uvCoordinates.empty();
238 if ( hasUV && data.uvCoordinates.size() < numVerts )
239 {
240 hasUV = false;
241 warnings += fmt::format( "Ignoring too few ({}) uv-coordinates loaded for a mesh with {} vertices.\n", data.uvCoordinates.size(), numVerts );
242 data.uvCoordinates.clear();
243 }
244
245 const auto numFaces = (int)data.mesh->topology.lastValidFace() + 1;
246 bool hasFaceColors = !data.faceColors.empty();
247 if ( hasFaceColors && data.faceColors.size() < numFaces )
248 {
249 hasFaceColors = false;
250 warnings += fmt::format( "Ignoring too few ({}) colors loaded for a mesh with {} triangles.\n", data.faceColors.size(), numVerts );
251 data.faceColors.clear();
252 }
253
254 auto objectMesh = std::make_unique<ObjectMesh>();
255 objectMesh->setName( objName );
256 objectMesh->setData( std::move( data ) );
257 objectMesh->setXf( data.xf );
258
259 const bool hasTexture = !data.texture.pixels.empty();
260 if ( hasTexture )
261 objectMesh->setTextures( { std::move( data.texture ) } );
262
263 if ( hasUV && hasTexture )
264 objectMesh->setVisualizeProperty( true, MeshVisualizePropertyType::Texture, ViewportMask::all() );
265 else if ( hasVertColors )
266 objectMesh->setColoringType( ColoringType::VertsColorMap );
267 else if ( hasFaceColors )
268 objectMesh->setColoringType( ColoringType::PrimitivesColorMap );
269
270 warnings = makeWarningString( data.skippedFaceCount, data.duplicatedVertexCount, int( objectMesh->numHoles() ) ) + warnings;
271
272 return LoadedObject{ .obj = std::move( objectMesh ), .warnings = std::move( warnings ) };
273}
274
275Expected<ObjectLines> makeObjectLinesFromFile( const std::filesystem::path& file, ProgressCallback callback )
276{

Callers 1

makeObjectFromMeshFileFunction · 0.85

Calls 9

makeWarningStringFunction · 0.85
lastValidFaceMethod · 0.80
setVisualizePropertyMethod · 0.80
setColoringTypeMethod · 0.80
numHolesMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45
clearMethod · 0.45
setXfMethod · 0.45

Tested by

no test coverage detected