Check for existence of gcode toolpaths that can be exported to obj file

This commit is contained in:
Enrico Turri 2019-08-20 11:33:58 +02:00
parent a99a89a831
commit 58473f84ee
7 changed files with 52 additions and 12 deletions

View File

@ -853,11 +853,39 @@ std::string GLVolumeCollection::log_memory_info() const
return " (GLVolumeCollection RAM: " + format_memsize_MB(this->cpu_memory_used()) + " GPU: " + format_memsize_MB(this->gpu_memory_used()) + " Both: " + format_memsize_MB(this->gpu_memory_used()) + ")";
}
bool can_export_to_obj(const GLVolume& volume)
{
if (!volume.is_active || !volume.is_extrusion_path)
return false;
if (volume.indexed_vertex_array.triangle_indices.empty() && (std::min(volume.indexed_vertex_array.triangle_indices_size, volume.tverts_range.second - volume.tverts_range.first) == 0))
return false;
if (volume.indexed_vertex_array.quad_indices.empty() && (std::min(volume.indexed_vertex_array.quad_indices_size, volume.qverts_range.second - volume.qverts_range.first) == 0))
return false;
return true;
}
bool GLVolumeCollection::has_toolpaths_to_export() const
{
for (const GLVolume* volume : this->volumes)
{
if (can_export_to_obj(*volume))
return true;
}
return false;
}
void GLVolumeCollection::export_toolpaths_to_obj(const char* filename) const
{
if (filename == nullptr)
return;
if (!has_toolpaths_to_export())
return;
FILE* fp = boost::nowide::fopen(filename, "w");
if (fp == nullptr) {
BOOST_LOG_TRIVIAL(error) << "GLVolumeCollection::export_toolpaths_to_obj: Couldn't open " << filename << " for writing";
@ -868,11 +896,11 @@ void GLVolumeCollection::export_toolpaths_to_obj(const char* filename) const
fprintf(fp, "# Generated by %s based on Slic3r\n\n", SLIC3R_BUILD_ID);
unsigned int vertices_count = 0;
unsigned int volume_count = 0;
unsigned int volumes_count = 0;
for (const GLVolume* volume : this->volumes)
{
if (!volume->is_active || !volume->is_extrusion_path)
if (!can_export_to_obj(*volume))
continue;
std::vector<float> vertices_and_normals_interleaved;
@ -925,19 +953,19 @@ void GLVolumeCollection::export_toolpaths_to_obj(const char* filename) const
if (triangle_indices.empty() && quad_indices.empty())
continue;
fprintf(fp, "\n# vertices volume %d\n", volume_count);
fprintf(fp, "\n# vertices volume %d\n", volumes_count);
for (unsigned int i = 0; i < vertices_and_normals_interleaved.size(); i += 6)
{
fprintf(fp, "v %f %f %f\n", vertices_and_normals_interleaved[i + 3], vertices_and_normals_interleaved[i + 4], vertices_and_normals_interleaved[i + 5]);
}
fprintf(fp, "\n# normals volume %d\n", volume_count);
fprintf(fp, "\n# normals volume %d\n", volumes_count);
for (unsigned int i = 0; i < vertices_and_normals_interleaved.size(); i += 6)
{
fprintf(fp, "vn %f %f %f\n", vertices_and_normals_interleaved[i + 0], vertices_and_normals_interleaved[i + 1], vertices_and_normals_interleaved[i + 2]);
}
fprintf(fp, "\n# triangular facets volume %d\n", volume_count);
fprintf(fp, "\n# triangular facets volume %d\n", volumes_count);
for (unsigned int i = 0; i < triangle_indices.size(); i += 3)
{
int id_v1 = vertices_count + 1 + triangle_indices[i + 0];
@ -946,7 +974,7 @@ void GLVolumeCollection::export_toolpaths_to_obj(const char* filename) const
fprintf(fp, "f %d//%d %d//%d %d//%d\n", id_v1, id_v1, id_v2, id_v2, id_v3, id_v3);
}
fprintf(fp, "\n# quadrangular facets volume %d\n", volume_count);
fprintf(fp, "\n# quadrangular facets volume %d\n", volumes_count);
for (unsigned int i = 0; i < quad_indices.size(); i += 4)
{
int id_v1 = vertices_count + 1 + quad_indices[i + 0];
@ -956,7 +984,7 @@ void GLVolumeCollection::export_toolpaths_to_obj(const char* filename) const
fprintf(fp, "f %d//%d %d//%d %d//%d %d//%d\n", id_v1, id_v1, id_v2, id_v2, id_v3, id_v3, id_v4, id_v4);
}
++volume_count;
++volumes_count;
vertices_count += vertices_and_normals_interleaved.size() / 6;
}

View File

@ -564,6 +564,7 @@ public:
// Return CPU, GPU and total memory log line.
std::string log_memory_info() const;
bool has_toolpaths_to_export() const;
// Export the geometry of the GLVolumes toolpaths of this collection into the file with the given path, in obj format
void export_toolpaths_to_obj(const char* filename) const;

View File

@ -3403,6 +3403,11 @@ void GLCanvas3D::msw_rescale()
m_warning_texture.msw_rescale(*this);
}
bool GLCanvas3D::has_toolpaths_to_export() const
{
return m_volumes.has_toolpaths_to_export();
}
void GLCanvas3D::export_toolpaths_to_obj(const char* filename) const
{
m_volumes.export_toolpaths_to_obj(filename);

View File

@ -644,6 +644,7 @@ public:
void get_undoredo_toolbar_additional_tooltip(unsigned int item_id, std::string& text) { return m_undoredo_toolbar.get_additional_tooltip(item_id, text); }
void set_undoredo_toolbar_additional_tooltip(unsigned int item_id, const std::string& text) { m_undoredo_toolbar.set_additional_tooltip(item_id, text); }
bool has_toolpaths_to_export() const;
void export_toolpaths_to_obj(const char* filename) const;
private:

View File

@ -247,7 +247,7 @@ bool MainFrame::can_export_model() const
bool MainFrame::can_export_toolpaths() const
{
return (m_plater != nullptr) && (m_plater->printer_technology() == ptFFF) && m_plater->is_preview_shown() && m_plater->is_preview_loaded();
return (m_plater != nullptr) && (m_plater->printer_technology() == ptFFF) && m_plater->is_preview_shown() && m_plater->is_preview_loaded() && m_plater->has_toolpaths_to_export();
}
bool MainFrame::can_export_supports() const

View File

@ -4434,7 +4434,12 @@ void Plater::export_3mf(const boost::filesystem::path& output_path)
}
}
void Plater::export_toolpaths_to_obj()
bool Plater::has_toolpaths_to_export() const
{
return p->preview->get_canvas3d()->has_toolpaths_to_export();
}
void Plater::export_toolpaths_to_obj() const
{
if ((printer_technology() != ptFFF) || !is_preview_loaded())
return;
@ -4444,7 +4449,6 @@ void Plater::export_toolpaths_to_obj()
return;
wxBusyCursor wait;
p->preview->get_canvas3d()->export_toolpaths_to_obj(into_u8(path).c_str());
}

View File

@ -183,7 +183,8 @@ public:
void export_stl(bool extended = false, bool selection_only = false);
void export_amf();
void export_3mf(const boost::filesystem::path& output_path = boost::filesystem::path());
void export_toolpaths_to_obj();
bool has_toolpaths_to_export() const;
void export_toolpaths_to_obj() const;
void reslice();
void reslice_SLA_supports(const ModelObject &object);
void changed_object(int obj_idx);