STEP: Implementation ported from BambuStudio:
CMake handling is different STEP: Removed preprocessing stage STEP: Small refactoring STEP: Bigger refactoring STEP: Changed naming on loaded object and volumes: If the STEP contains exactly one named volume, the object and its first volume will both have that name. Otherwise, filename w/o suffix is used as object name and volumes are named using names from the STEP (if there is none, untranslated "PartN" string is used). STEP: Load the libraries dynamically on Win wip
This commit is contained in:
parent
dc9e35d8ea
commit
88ba89dbbc
13 changed files with 443 additions and 4 deletions
110
src/libslic3r/Format/STEP.cpp
Normal file
110
src/libslic3r/Format/STEP.cpp
Normal file
|
@ -0,0 +1,110 @@
|
|||
#include "STEP.hpp"
|
||||
#include "occt_wrapper/OCCTWrapper.hpp"
|
||||
|
||||
#include "libslic3r/Model.hpp"
|
||||
#include "libslic3r/TriangleMesh.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include<windows.h>
|
||||
#else
|
||||
#include<occt_wrapper/OCCTWrapper.hpp>
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
LoadStepFn get_load_step_fn()
|
||||
{
|
||||
static LoadStepFn load_step_fn = nullptr;
|
||||
|
||||
if (!load_step_fn) {
|
||||
#ifdef _WIN32
|
||||
HMODULE module = LoadLibraryW(L"OCCTWrapper.dll");
|
||||
if (module == NULL)
|
||||
throw Slic3r::RuntimeError("Cannot load OCCTWrapper.dll");
|
||||
|
||||
try {
|
||||
const char* fn_name = "load_step_internal";
|
||||
FARPROC farproc = GetProcAddress(module, fn_name);
|
||||
if (! farproc) {
|
||||
DWORD ec = GetLastError();
|
||||
throw Slic3r::RuntimeError(std::string("Cannot load function from OCCTWrapper.dll: ") + fn_name
|
||||
+ "\n\nError code: " + std::to_string(ec));
|
||||
}
|
||||
load_step_fn = reinterpret_cast<LoadStepFn>(farproc);
|
||||
} catch (const Slic3r::RuntimeError&) {
|
||||
FreeLibrary(module);
|
||||
throw;
|
||||
}
|
||||
#else
|
||||
void *plugin_ptr = dlopen("OCCTWrapper.so", RTLD_NOW | RTLD_GLOBAL);
|
||||
|
||||
if (plugin_ptr) {
|
||||
load_step_fn = reinterpret_cast<LoadStepFn>(dlsym(plugin_ptr, "load_step_internal"));
|
||||
if (!load_step_fn) {
|
||||
dlclose(plugin_ptr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return load_step_fn;
|
||||
}
|
||||
|
||||
bool load_step(const char *path, Model *model /*BBS:, ImportStepProgressFn proFn*/)
|
||||
{
|
||||
OCCTResult occt_object;
|
||||
|
||||
LoadStepFn load_step_fn = get_load_step_fn();
|
||||
|
||||
if (!load_step_fn)
|
||||
return false;
|
||||
|
||||
load_step_fn(path, &occt_object);
|
||||
|
||||
assert(! occt_object.volumes.empty());
|
||||
|
||||
assert(boost::algorithm::iends_with(occt_object.object_name, ".stp")
|
||||
|| boost::algorithm::iends_with(occt_object.object_name, ".step"));
|
||||
occt_object.object_name.erase(occt_object.object_name.find("."));
|
||||
assert(! occt_object.object_name.empty());
|
||||
|
||||
|
||||
ModelObject* new_object = model->add_object();
|
||||
new_object->input_file = path;
|
||||
if (new_object->volumes.size() == 1 && ! occt_object.volumes.front().volume_name.empty())
|
||||
new_object->name = new_object->volumes.front()->name;
|
||||
else
|
||||
new_object->name = occt_object.object_name;
|
||||
|
||||
|
||||
for (size_t i=0; i<occt_object.volumes.size(); ++i) {
|
||||
indexed_triangle_set its;
|
||||
for (size_t j=0; j<occt_object.volumes[i].vertices.size(); ++j)
|
||||
its.vertices.emplace_back(Vec3f(occt_object.volumes[i].vertices[j][0],
|
||||
occt_object.volumes[i].vertices[j][1],
|
||||
occt_object.volumes[i].vertices[j][2]));
|
||||
for (size_t j=0; j<occt_object.volumes[i].indices.size(); ++j)
|
||||
its.indices.emplace_back(Vec3i(occt_object.volumes[i].indices[j][0],
|
||||
occt_object.volumes[i].indices[j][1],
|
||||
occt_object.volumes[i].indices[j][2]));
|
||||
its_merge_vertices(its, true);
|
||||
TriangleMesh triangle_mesh(std::move(its));
|
||||
ModelVolume* new_volume = new_object->add_volume(std::move(triangle_mesh));
|
||||
|
||||
new_volume->name = occt_object.volumes[i].volume_name.empty()
|
||||
? std::string("Part") + std::to_string(i+1)
|
||||
: occt_object.volumes[i].volume_name;
|
||||
new_volume->source.input_file = path;
|
||||
new_volume->source.object_idx = (int)model->objects.size() - 1;
|
||||
new_volume->source.volume_idx = (int)new_object->volumes.size() - 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}; // namespace Slic3r
|
19
src/libslic3r/Format/STEP.hpp
Normal file
19
src/libslic3r/Format/STEP.hpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
// Original implementation of STEP format import created by Bambulab.
|
||||
// https://github.com/bambulab/BambuStudio
|
||||
// Forked off commit 1555904, modified by Prusa Research.
|
||||
|
||||
#ifndef slic3r_Format_STEP_hpp_
|
||||
#define slic3r_Format_STEP_hpp_
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class Model;
|
||||
|
||||
//typedef std::function<void(int load_stage, int current, int total, bool& cancel)> ImportStepProgressFn;
|
||||
|
||||
// Load a step file into a provided model.
|
||||
extern bool load_step(const char *path_str, Model *model /*LMBBS:, ImportStepProgressFn proFn = nullptr*/);
|
||||
|
||||
}; // namespace Slic3r
|
||||
|
||||
#endif /* slic3r_Format_STEP_hpp_ */
|
Loading…
Add table
Add a link
Reference in a new issue