mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
Check for existence of gcode toolpaths that can be exported to obj file
This commit is contained in:
parent
a99a89a831
commit
58473f84ee
7 changed files with 52 additions and 12 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue