ENH: Format: Add ModelIO support on macOS

Github pull request: #2439

Change-Id: I4464a735a0a20b3e8103a344a64500b3d14b70e6
This commit is contained in:
Merikesh Dev
2023-09-01 20:30:14 -07:00
committed by Lane.Wei
parent 607f4ca526
commit 570a98fd45
5 changed files with 80 additions and 1 deletions

View File

@@ -0,0 +1,27 @@
#include "ModelIO.hpp"
#import <ModelIO/ModelIO.h>
namespace Slic3r {
std::string make_temp_stl_with_modelio(const std::string &input_file)
{
NSURL *input_url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:input_file.c_str()]];
MDLAsset *asset = [[MDLAsset alloc] initWithURL:input_url];
NSString *tmp_file_name = [[[NSUUID UUID] UUIDString] stringByAppendingPathExtension:@"stl"];
NSURL *tmp_file_url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:tmp_file_name]];
if ([asset exportAssetToURL:tmp_file_url]) {
std::string output_file = std::string([[tmp_file_url path] UTF8String]);
return output_file;
}
return std::string();
}
void delete_temp_file(const std::string &temp_file)
{
NSString *file_path = [NSString stringWithUTF8String:temp_file.c_str()];
[[NSFileManager defaultManager] removeItemAtPath:file_path error:NULL];
}
} // namespace Slic3r