mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-20 11:53:48 +00:00
Add ModelIO support on macOS
This commit is contained in:
19
src/libslic3r/Format/ModelIO.hpp
Normal file
19
src/libslic3r/Format/ModelIO.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <string>
|
||||
|
||||
namespace Slic3r {
|
||||
/**
|
||||
* Uses ModelIO to convert supported model types to a temporary STL
|
||||
* that can then be consumed by the existing STL loader
|
||||
* @param input_file The File to load
|
||||
* @return Path to the temporary file, or an empty string if conversion failed
|
||||
*/
|
||||
std::string make_temp_stl_with_modelio(const std::string &input_file);
|
||||
|
||||
/**
|
||||
* Convenience function to delete the file.
|
||||
* No return value since success isn't required
|
||||
* @param temp_file File path to delete
|
||||
*/
|
||||
void delete_temp_file(const std::string &temp_file);
|
||||
}
|
||||
|
||||
27
src/libslic3r/Format/ModelIO.mm
Normal file
27
src/libslic3r/Format/ModelIO.mm
Normal 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
|
||||
Reference in New Issue
Block a user