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

Function makeObjectFromMeshFile

source/MRMesh/MRObjectLoad.cpp:148–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146}
147
148Expected<LoadedObject> makeObjectFromMeshFile( const std::filesystem::path& file, const ProgressCallback& cb, bool returnOnlyMesh )
149{
150 MR_TIMER;
151
152 LoadedMeshData data;
153 VertNormals normals;
154 std::optional<Edges> edges;
155 MeshLoadSettings settings
156 {
157 .edges = &edges,
158 .colors = &data.vertColors,
159 .faceColors = &data.faceColors,
160 .uvCoords = &data.uvCoordinates,
161 .normals = returnOnlyMesh ? nullptr : &normals,
162 .texture = &data.texture,
163 .skippedFaceCount = &data.skippedFaceCount,
164 .duplicatedVertexCount = &data.duplicatedVertexCount,
165 .xf = &data.xf,
166 .callback = cb
167 };
168 auto mesh = MeshLoad::fromAnySupportedFormat( file, settings );
169 if ( !mesh.has_value() )
170 return unexpected( mesh.error() );
171
172 if ( !mesh->points.empty() && mesh->topology.numValidFaces() <= 0 )
173 {
174 if ( returnOnlyMesh )
175 return unexpected( "File contains a point cloud and not a mesh: " + utf8string( file ) );
176
177 if ( edges )
178 {
179 auto polyline = std::make_shared<Polyline3>();
180 polyline->points = std::move( mesh->points );
181 polyline->topology.vertResize( polyline->points.size() );
182 polyline->topology.makeEdges( *edges );
183
184 auto objectLines = std::make_unique<ObjectLines>();
185 objectLines->setName( utf8string( file.stem() ) );
186 objectLines->setPolyline( polyline );
187
188 if ( !data.vertColors.empty() )
189 {
190 objectLines->setVertsColorMap( std::move( data.vertColors ) );
191 objectLines->setColoringType( ColoringType::VertsColorMap );
192 }
193
194 objectLines->setXf( data.xf );
195
196 return LoadedObject{ .obj = std::move( objectLines ) };
197 }
198
199 auto pointCloud = std::make_shared<PointCloud>();
200 pointCloud->points = std::move( mesh->points );
201 pointCloud->normals = std::move( normals );
202 pointCloud->validPoints.resize( pointCloud->points.size(), true );
203
204 auto objectPoints = std::make_unique<ObjectPoints>();
205 objectPoints->setName( utf8string( file.stem() ) );

Callers 2

makeObjectMeshFromFileFunction · 0.85
loadObjectFromFileFunction · 0.85

Calls 15

utf8stringFunction · 0.85
makeObjectMeshFunction · 0.85
errorMethod · 0.80
numValidFacesMethod · 0.80
makeEdgesMethod · 0.80
setPolylineMethod · 0.80
setColoringTypeMethod · 0.80
fromAnySupportedFormatFunction · 0.70
unexpectedFunction · 0.70
emptyMethod · 0.45
vertResizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected