| 146 | } |
| 147 | |
| 148 | Expected<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() ) ); |
no test coverage detected