| 209 | } |
| 210 | |
| 211 | Expected<void> to3mf( const Mesh & mesh, const std::filesystem::path& file, const SaveSettings & settings ) |
| 212 | { |
| 213 | MR_TIMER; |
| 214 | if ( file.empty() ) |
| 215 | return unexpected( "Cannot save to empty path" ); |
| 216 | |
| 217 | UniqueTemporaryFolder scenePath; |
| 218 | if ( !scenePath ) |
| 219 | return unexpected( "Cannot create temporary folder" ); |
| 220 | |
| 221 | { |
| 222 | std::ofstream f( scenePath / "[Content_Types].xml" ); |
| 223 | f << |
| 224 | R"(<?xml version="1.0" encoding="utf-8"?> |
| 225 | <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"> |
| 226 | <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" /> |
| 227 | <Default Extension="model" ContentType="application/vnd.ms-package.3dmanufacturing-3dmodel+xml" /> |
| 228 | <Default Extension="texture" ContentType="application/vnd.ms-package.3dmanufacturing-3dmodeltexture" /> |
| 229 | <Default Extension="xml" ContentType="application/vnd.ms-printing.printticket+xml" /> |
| 230 | <Default Extension="prop" ContentType="application/vnd.openxmlformats-package.core-properties+xml" /> |
| 231 | <Default Extension="gif" ContentType="image/gif" /> |
| 232 | <Default Extension="jpg" ContentType="image/jpeg" /> |
| 233 | <Default Extension="png" ContentType="image/png" /> |
| 234 | </Types> |
| 235 | )"; |
| 236 | if ( !f ) |
| 237 | return unexpected( "Cannot write file inside temporary folder" ); |
| 238 | } |
| 239 | |
| 240 | { |
| 241 | const auto dirRels = scenePath / "_rels"; |
| 242 | std::error_code ec; |
| 243 | if ( !create_directory( dirRels, ec ) ) |
| 244 | return unexpected( "Cannot create subdirectory inside temporary folder" ); |
| 245 | |
| 246 | std::ofstream f( dirRels / ".rels" ); |
| 247 | f << |
| 248 | R"(<?xml version="1.0" encoding="utf-8"?> |
| 249 | <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> |
| 250 | <Relationship Type="http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel" Target="/3D/3dmodel.model" Id="rel0" /> |
| 251 | </Relationships> |
| 252 | )"; |
| 253 | if ( !f ) |
| 254 | return unexpected( "Cannot write file inside temporary folder" ); |
| 255 | } |
| 256 | |
| 257 | { |
| 258 | const auto dir3D = scenePath / "3D"; |
| 259 | std::error_code ec; |
| 260 | if ( !create_directory( dir3D, ec ) ) |
| 261 | return unexpected( "Cannot create subdirectory inside temporary folder" ); |
| 262 | |
| 263 | auto settings1 = settings; |
| 264 | settings1.progress = subprogress( settings.progress, 0.0f, 0.9f ); |
| 265 | if ( auto maybeDone = toModel3mf( mesh, dir3D / "3dmodel.model", settings1 ); !maybeDone ) |
| 266 | return unexpected( std::move( maybeDone.error() ) ); |
| 267 | } |
| 268 |
nothing calls this directly
no test coverage detected