mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-13 01:37:53 -06:00
ENABLE_GCODE_VIEWER set as default in:
3DScene hpp/cpp AboutDialog.cpp BackgroundSlicingProcess hpp/cpp BitmapCache.cpp ConfigWizard_private.hpp GUI_App hpp/cpp GUI_Init.cpp
This commit is contained in:
parent
2ea00cf916
commit
faff112ea8
10 changed files with 2 additions and 810 deletions
|
@ -993,290 +993,6 @@ bool GLVolumeCollection::has_toolpaths_to_export() const
|
|||
return false;
|
||||
}
|
||||
|
||||
#if !ENABLE_GCODE_VIEWER
|
||||
void GLVolumeCollection::export_toolpaths_to_obj(const char* filename) const
|
||||
{
|
||||
if (filename == nullptr)
|
||||
return;
|
||||
|
||||
if (!has_toolpaths_to_export())
|
||||
return;
|
||||
|
||||
// collect color information to generate materials
|
||||
typedef std::array<float, 4> Color;
|
||||
std::set<Color> colors;
|
||||
for (const GLVolume* volume : this->volumes)
|
||||
{
|
||||
if (!can_export_to_obj(*volume))
|
||||
continue;
|
||||
|
||||
Color color;
|
||||
::memcpy((void*)color.data(), (const void*)volume->color, 4 * sizeof(float));
|
||||
colors.insert(color);
|
||||
}
|
||||
|
||||
// save materials file
|
||||
boost::filesystem::path mat_filename(filename);
|
||||
mat_filename.replace_extension("mtl");
|
||||
FILE* fp = boost::nowide::fopen(mat_filename.string().c_str(), "w");
|
||||
if (fp == nullptr) {
|
||||
BOOST_LOG_TRIVIAL(error) << "GLVolumeCollection::export_toolpaths_to_obj: Couldn't open " << mat_filename.string().c_str() << " for writing";
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(fp, "# G-Code Toolpaths Materials\n");
|
||||
fprintf(fp, "# Generated by %s based on Slic3r\n", SLIC3R_BUILD_ID);
|
||||
|
||||
unsigned int colors_count = 1;
|
||||
for (const Color& color : colors)
|
||||
{
|
||||
fprintf(fp, "\nnewmtl material_%d\n", colors_count++);
|
||||
fprintf(fp, "Ka 1 1 1\n");
|
||||
fprintf(fp, "Kd %f %f %f\n", color[0], color[1], color[2]);
|
||||
fprintf(fp, "Ks 0 0 0\n");
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
// save geometry 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";
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(fp, "# G-Code Toolpaths\n");
|
||||
fprintf(fp, "# Generated by %s based on Slic3r\n", SLIC3R_BUILD_ID);
|
||||
fprintf(fp, "\nmtllib ./%s\n", mat_filename.filename().string().c_str());
|
||||
|
||||
unsigned int vertices_count = 0;
|
||||
unsigned int normals_count = 0;
|
||||
unsigned int volumes_count = 0;
|
||||
|
||||
for (const GLVolume* volume : this->volumes)
|
||||
{
|
||||
if (!can_export_to_obj(*volume))
|
||||
continue;
|
||||
|
||||
std::vector<float> src_vertices_and_normals_interleaved;
|
||||
std::vector<int> src_triangle_indices;
|
||||
std::vector<int> src_quad_indices;
|
||||
|
||||
if (!volume->indexed_vertex_array.vertices_and_normals_interleaved.empty())
|
||||
// data are in CPU memory
|
||||
src_vertices_and_normals_interleaved = volume->indexed_vertex_array.vertices_and_normals_interleaved;
|
||||
else if ((volume->indexed_vertex_array.vertices_and_normals_interleaved_VBO_id != 0) && (volume->indexed_vertex_array.vertices_and_normals_interleaved_size != 0))
|
||||
{
|
||||
// data are in GPU memory
|
||||
src_vertices_and_normals_interleaved = std::vector<float>(volume->indexed_vertex_array.vertices_and_normals_interleaved_size, 0.0f);
|
||||
|
||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, volume->indexed_vertex_array.vertices_and_normals_interleaved_VBO_id));
|
||||
glsafe(::glGetBufferSubData(GL_ARRAY_BUFFER, 0, src_vertices_and_normals_interleaved.size() * sizeof(float), src_vertices_and_normals_interleaved.data()));
|
||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
|
||||
}
|
||||
else
|
||||
continue;
|
||||
|
||||
if (!volume->indexed_vertex_array.triangle_indices.empty())
|
||||
{
|
||||
// data are in CPU memory
|
||||
size_t size = std::min(volume->indexed_vertex_array.triangle_indices.size(), volume->tverts_range.second - volume->tverts_range.first);
|
||||
if (size != 0)
|
||||
{
|
||||
std::vector<int>::const_iterator it_begin = volume->indexed_vertex_array.triangle_indices.begin() + volume->tverts_range.first;
|
||||
std::vector<int>::const_iterator it_end = volume->indexed_vertex_array.triangle_indices.begin() + volume->tverts_range.first + size;
|
||||
std::copy(it_begin, it_end, std::back_inserter(src_triangle_indices));
|
||||
}
|
||||
}
|
||||
else if ((volume->indexed_vertex_array.triangle_indices_VBO_id != 0) && (volume->indexed_vertex_array.triangle_indices_size != 0))
|
||||
{
|
||||
// data are in GPU memory
|
||||
size_t size = std::min(volume->indexed_vertex_array.triangle_indices_size, volume->tverts_range.second - volume->tverts_range.first);
|
||||
if (size != 0)
|
||||
{
|
||||
src_triangle_indices = std::vector<int>(size, 0);
|
||||
|
||||
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, volume->indexed_vertex_array.triangle_indices_VBO_id));
|
||||
glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, volume->tverts_range.first * sizeof(int), size * sizeof(int), src_triangle_indices.data()));
|
||||
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
||||
}
|
||||
}
|
||||
|
||||
if (!volume->indexed_vertex_array.quad_indices.empty())
|
||||
{
|
||||
// data are in CPU memory
|
||||
size_t size = std::min(volume->indexed_vertex_array.quad_indices.size(), volume->qverts_range.second - volume->qverts_range.first);
|
||||
if (size != 0)
|
||||
{
|
||||
std::vector<int>::const_iterator it_begin = volume->indexed_vertex_array.quad_indices.begin() + volume->qverts_range.first;
|
||||
std::vector<int>::const_iterator it_end = volume->indexed_vertex_array.quad_indices.begin() + volume->qverts_range.first + size;
|
||||
std::copy(it_begin, it_end, std::back_inserter(src_quad_indices));
|
||||
}
|
||||
}
|
||||
else if ((volume->indexed_vertex_array.quad_indices_VBO_id != 0) && (volume->indexed_vertex_array.quad_indices_size != 0))
|
||||
{
|
||||
// data are in GPU memory
|
||||
size_t size = std::min(volume->indexed_vertex_array.quad_indices_size, volume->qverts_range.second - volume->qverts_range.first);
|
||||
if (size != 0)
|
||||
{
|
||||
src_quad_indices = std::vector<int>(size, 0);
|
||||
|
||||
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, volume->indexed_vertex_array.quad_indices_VBO_id));
|
||||
glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, volume->qverts_range.first * sizeof(int), size * sizeof(int), src_quad_indices.data()));
|
||||
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
||||
}
|
||||
}
|
||||
|
||||
if (src_triangle_indices.empty() && src_quad_indices.empty())
|
||||
continue;
|
||||
|
||||
++volumes_count;
|
||||
|
||||
// reduce output size by keeping only used vertices and normals
|
||||
|
||||
struct Vector
|
||||
{
|
||||
std::array<coord_t, 3> vector;
|
||||
|
||||
explicit Vector(float* ptr)
|
||||
{
|
||||
vector[0] = scale_(*(ptr + 0));
|
||||
vector[1] = scale_(*(ptr + 1));
|
||||
vector[2] = scale_(*(ptr + 2));
|
||||
}
|
||||
};
|
||||
typedef std::vector<Vector> Vectors;
|
||||
|
||||
auto vector_less = [](const Vector& v1, const Vector& v2)->bool {
|
||||
return v1.vector < v2.vector;
|
||||
};
|
||||
|
||||
auto vector_equal = [](const Vector& v1, const Vector& v2)->bool {
|
||||
return (v1.vector[0] == v2.vector[0]) && (v1.vector[1] == v2.vector[1]) && (v1.vector[2] == v2.vector[2]);
|
||||
};
|
||||
|
||||
// copy used vertices and normals data
|
||||
Vectors dst_normals;
|
||||
Vectors dst_vertices;
|
||||
|
||||
unsigned int src_triangle_indices_size = (unsigned int)src_triangle_indices.size();
|
||||
for (unsigned int i = 0; i < src_triangle_indices_size; ++i)
|
||||
{
|
||||
float* src_ptr = src_vertices_and_normals_interleaved.data() + src_triangle_indices[i] * 6;
|
||||
dst_normals.emplace_back(src_ptr + 0);
|
||||
dst_vertices.emplace_back(src_ptr + 3);
|
||||
}
|
||||
|
||||
unsigned int src_quad_indices_size = (unsigned int)src_quad_indices.size();
|
||||
for (unsigned int i = 0; i < src_quad_indices_size; ++i)
|
||||
{
|
||||
float* src_ptr = src_vertices_and_normals_interleaved.data() + src_quad_indices[i] * 6;
|
||||
dst_normals.emplace_back(src_ptr + 0);
|
||||
dst_vertices.emplace_back(src_ptr + 3);
|
||||
}
|
||||
|
||||
// sort vertices and normals
|
||||
std::sort(dst_normals.begin(), dst_normals.end(), vector_less);
|
||||
std::sort(dst_vertices.begin(), dst_vertices.end(), vector_less);
|
||||
|
||||
// remove duplicated vertices and normals
|
||||
dst_normals.erase(std::unique(dst_normals.begin(), dst_normals.end(), vector_equal), dst_normals.end());
|
||||
dst_vertices.erase(std::unique(dst_vertices.begin(), dst_vertices.end(), vector_equal), dst_vertices.end());
|
||||
|
||||
// reindex triangles and quads
|
||||
struct IndicesPair
|
||||
{
|
||||
int vertex;
|
||||
int normal;
|
||||
IndicesPair(int vertex, int normal) : vertex(vertex), normal(normal) {}
|
||||
};
|
||||
typedef std::vector<IndicesPair> Indices;
|
||||
|
||||
unsigned int src_vertices_count = (unsigned int)src_vertices_and_normals_interleaved.size() / 6;
|
||||
std::vector<int> src_dst_vertex_indices_map(src_vertices_count, -1);
|
||||
std::vector<int> src_dst_normal_indices_map(src_vertices_count, -1);
|
||||
|
||||
for (unsigned int i = 0; i < src_vertices_count; ++i)
|
||||
{
|
||||
float* src_ptr = src_vertices_and_normals_interleaved.data() + i * 6;
|
||||
src_dst_normal_indices_map[i] = std::distance(dst_normals.begin(), std::lower_bound(dst_normals.begin(), dst_normals.end(), Vector(src_ptr + 0), vector_less));
|
||||
src_dst_vertex_indices_map[i] = std::distance(dst_vertices.begin(), std::lower_bound(dst_vertices.begin(), dst_vertices.end(), Vector(src_ptr + 3), vector_less));
|
||||
}
|
||||
|
||||
Indices dst_triangle_indices;
|
||||
if (src_triangle_indices_size > 0)
|
||||
dst_triangle_indices.reserve(src_triangle_indices_size);
|
||||
|
||||
for (unsigned int i = 0; i < src_triangle_indices_size; ++i)
|
||||
{
|
||||
int id = src_triangle_indices[i];
|
||||
dst_triangle_indices.emplace_back(src_dst_vertex_indices_map[id], src_dst_normal_indices_map[id]);
|
||||
}
|
||||
|
||||
Indices dst_quad_indices;
|
||||
if (src_quad_indices_size > 0)
|
||||
dst_quad_indices.reserve(src_quad_indices_size);
|
||||
|
||||
for (unsigned int i = 0; i < src_quad_indices_size; ++i)
|
||||
{
|
||||
int id = src_quad_indices[i];
|
||||
dst_quad_indices.emplace_back(src_dst_vertex_indices_map[id], src_dst_normal_indices_map[id]);
|
||||
}
|
||||
|
||||
// save to file
|
||||
fprintf(fp, "\n# vertices volume %d\n", volumes_count);
|
||||
for (const Vector& v : dst_vertices)
|
||||
{
|
||||
fprintf(fp, "v %g %g %g\n", unscale<float>(v.vector[0]), unscale<float>(v.vector[1]), unscale<float>(v.vector[2]));
|
||||
}
|
||||
|
||||
fprintf(fp, "\n# normals volume %d\n", volumes_count);
|
||||
for (const Vector& n : dst_normals)
|
||||
{
|
||||
fprintf(fp, "vn %g %g %g\n", unscale<float>(n.vector[0]), unscale<float>(n.vector[1]), unscale<float>(n.vector[2]));
|
||||
}
|
||||
|
||||
Color color;
|
||||
::memcpy((void*)color.data(), (const void*)volume->color, 4 * sizeof(float));
|
||||
fprintf(fp, "\n# material volume %d\n", volumes_count);
|
||||
fprintf(fp, "usemtl material_%lld\n", (long long)(1 + std::distance(colors.begin(), colors.find(color))));
|
||||
|
||||
int base_vertex_id = vertices_count + 1;
|
||||
int base_normal_id = normals_count + 1;
|
||||
|
||||
if (!dst_triangle_indices.empty())
|
||||
{
|
||||
fprintf(fp, "\n# triangular facets volume %d\n", volumes_count);
|
||||
for (unsigned int i = 0; i < (unsigned int)dst_triangle_indices.size(); i += 3)
|
||||
{
|
||||
fprintf(fp, "f %d//%d %d//%d %d//%d\n",
|
||||
base_vertex_id + dst_triangle_indices[i + 0].vertex, base_normal_id + dst_triangle_indices[i + 0].normal,
|
||||
base_vertex_id + dst_triangle_indices[i + 1].vertex, base_normal_id + dst_triangle_indices[i + 1].normal,
|
||||
base_vertex_id + dst_triangle_indices[i + 2].vertex, base_normal_id + dst_triangle_indices[i + 2].normal);
|
||||
}
|
||||
}
|
||||
|
||||
if (!dst_quad_indices.empty())
|
||||
{
|
||||
fprintf(fp, "\n# quadrangular facets volume %d\n", volumes_count);
|
||||
for (unsigned int i = 0; i < (unsigned int)src_quad_indices.size(); i += 4)
|
||||
{
|
||||
fprintf(fp, "f %d//%d %d//%d %d//%d %d//%d\n",
|
||||
base_vertex_id + dst_quad_indices[i + 0].vertex, base_normal_id + dst_quad_indices[i + 0].normal,
|
||||
base_vertex_id + dst_quad_indices[i + 1].vertex, base_normal_id + dst_quad_indices[i + 1].normal,
|
||||
base_vertex_id + dst_quad_indices[i + 2].vertex, base_normal_id + dst_quad_indices[i + 2].normal,
|
||||
base_vertex_id + dst_quad_indices[i + 3].vertex, base_normal_id + dst_quad_indices[i + 3].normal);
|
||||
}
|
||||
}
|
||||
|
||||
vertices_count += (unsigned int)dst_vertices.size();
|
||||
normals_count += (unsigned int)dst_normals.size();
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
#endif // !ENABLE_GCODE_VIEWER
|
||||
|
||||
// caller is responsible for supplying NO lines with zero length
|
||||
static void thick_lines_to_indexed_vertex_array(
|
||||
const Lines &lines,
|
||||
|
@ -1923,287 +1639,4 @@ void _3DScene::point3_to_verts(const Vec3crd& point, double width, double height
|
|||
thick_point_to_verts(point, width, height, volume);
|
||||
}
|
||||
|
||||
#if !ENABLE_GCODE_VIEWER
|
||||
GLModel::GLModel()
|
||||
: m_filename("")
|
||||
{
|
||||
m_volume.shader_outside_printer_detection_enabled = false;
|
||||
}
|
||||
|
||||
GLModel::~GLModel()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void GLModel::set_color(const float* color, unsigned int size)
|
||||
{
|
||||
::memcpy((void*)m_volume.color, (const void*)color, (size_t)(std::min((unsigned int)4, size) * sizeof(float)));
|
||||
m_volume.set_render_color(color, size);
|
||||
}
|
||||
|
||||
const Vec3d& GLModel::get_offset() const
|
||||
{
|
||||
return m_volume.get_volume_offset();
|
||||
}
|
||||
|
||||
void GLModel::set_offset(const Vec3d& offset)
|
||||
{
|
||||
m_volume.set_volume_offset(offset);
|
||||
}
|
||||
|
||||
const Vec3d& GLModel::get_rotation() const
|
||||
{
|
||||
return m_volume.get_volume_rotation();
|
||||
}
|
||||
|
||||
void GLModel::set_rotation(const Vec3d& rotation)
|
||||
{
|
||||
m_volume.set_volume_rotation(rotation);
|
||||
}
|
||||
|
||||
const Vec3d& GLModel::get_scale() const
|
||||
{
|
||||
return m_volume.get_volume_scaling_factor();
|
||||
}
|
||||
|
||||
void GLModel::set_scale(const Vec3d& scale)
|
||||
{
|
||||
m_volume.set_volume_scaling_factor(scale);
|
||||
}
|
||||
|
||||
void GLModel::reset()
|
||||
{
|
||||
m_volume.indexed_vertex_array.release_geometry();
|
||||
m_filename = "";
|
||||
}
|
||||
|
||||
void GLModel::render() const
|
||||
{
|
||||
GLShaderProgram* shader = GUI::wxGetApp().get_current_shader();
|
||||
if (shader == nullptr)
|
||||
return;
|
||||
|
||||
glsafe(::glEnable(GL_BLEND));
|
||||
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
||||
|
||||
glsafe(::glCullFace(GL_BACK));
|
||||
glsafe(::glEnableClientState(GL_VERTEX_ARRAY));
|
||||
glsafe(::glEnableClientState(GL_NORMAL_ARRAY));
|
||||
|
||||
shader->set_uniform("uniform_color", m_volume.render_color, 4);
|
||||
m_volume.render();
|
||||
|
||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
|
||||
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
||||
|
||||
glsafe(::glDisableClientState(GL_VERTEX_ARRAY));
|
||||
glsafe(::glDisableClientState(GL_NORMAL_ARRAY));
|
||||
|
||||
glsafe(::glDisable(GL_BLEND));
|
||||
}
|
||||
|
||||
bool GLArrow::on_init()
|
||||
{
|
||||
Pointf3s vertices;
|
||||
std::vector<Vec3i> triangles;
|
||||
|
||||
// bottom face
|
||||
vertices.emplace_back(0.5, 0.0, -0.1);
|
||||
vertices.emplace_back(0.5, 2.0, -0.1);
|
||||
vertices.emplace_back(1.0, 2.0, -0.1);
|
||||
vertices.emplace_back(0.0, 3.0, -0.1);
|
||||
vertices.emplace_back(-1.0, 2.0, -0.1);
|
||||
vertices.emplace_back(-0.5, 2.0, -0.1);
|
||||
vertices.emplace_back(-0.5, 0.0, -0.1);
|
||||
|
||||
// top face
|
||||
vertices.emplace_back(0.5, 0.0, 0.1);
|
||||
vertices.emplace_back(0.5, 2.0, 0.1);
|
||||
vertices.emplace_back(1.0, 2.0, 0.1);
|
||||
vertices.emplace_back(0.0, 3.0, 0.1);
|
||||
vertices.emplace_back(-1.0, 2.0, 0.1);
|
||||
vertices.emplace_back(-0.5, 2.0, 0.1);
|
||||
vertices.emplace_back(-0.5, 0.0, 0.1);
|
||||
|
||||
// bottom face
|
||||
triangles.emplace_back(0, 6, 1);
|
||||
triangles.emplace_back(6, 5, 1);
|
||||
triangles.emplace_back(5, 4, 3);
|
||||
triangles.emplace_back(5, 3, 1);
|
||||
triangles.emplace_back(1, 3, 2);
|
||||
|
||||
// top face
|
||||
triangles.emplace_back(7, 8, 13);
|
||||
triangles.emplace_back(13, 8, 12);
|
||||
triangles.emplace_back(12, 10, 11);
|
||||
triangles.emplace_back(8, 10, 12);
|
||||
triangles.emplace_back(8, 9, 10);
|
||||
|
||||
// side face
|
||||
triangles.emplace_back(0, 1, 8);
|
||||
triangles.emplace_back(8, 7, 0);
|
||||
triangles.emplace_back(1, 2, 9);
|
||||
triangles.emplace_back(9, 8, 1);
|
||||
triangles.emplace_back(2, 3, 10);
|
||||
triangles.emplace_back(10, 9, 2);
|
||||
triangles.emplace_back(3, 4, 11);
|
||||
triangles.emplace_back(11, 10, 3);
|
||||
triangles.emplace_back(4, 5, 12);
|
||||
triangles.emplace_back(12, 11, 4);
|
||||
triangles.emplace_back(5, 6, 13);
|
||||
triangles.emplace_back(13, 12, 5);
|
||||
triangles.emplace_back(6, 0, 7);
|
||||
triangles.emplace_back(7, 13, 6);
|
||||
|
||||
m_volume.indexed_vertex_array.load_mesh(TriangleMesh(vertices, triangles));
|
||||
m_volume.indexed_vertex_array.finalize_geometry(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
GLCurvedArrow::GLCurvedArrow(unsigned int resolution)
|
||||
: GLModel()
|
||||
, m_resolution(resolution)
|
||||
{
|
||||
if (m_resolution == 0)
|
||||
m_resolution = 1;
|
||||
}
|
||||
|
||||
bool GLCurvedArrow::on_init()
|
||||
{
|
||||
Pointf3s vertices;
|
||||
std::vector<Vec3i> triangles;
|
||||
|
||||
double ext_radius = 2.5;
|
||||
double int_radius = 1.5;
|
||||
double step = 0.5 * (double)PI / (double)m_resolution;
|
||||
|
||||
unsigned int vertices_per_level = 4 + 2 * m_resolution;
|
||||
|
||||
// bottom face
|
||||
vertices.emplace_back(0.0, 1.5, -0.1);
|
||||
vertices.emplace_back(0.0, 1.0, -0.1);
|
||||
vertices.emplace_back(-1.0, 2.0, -0.1);
|
||||
vertices.emplace_back(0.0, 3.0, -0.1);
|
||||
vertices.emplace_back(0.0, 2.5, -0.1);
|
||||
|
||||
for (unsigned int i = 1; i <= m_resolution; ++i)
|
||||
{
|
||||
double angle = (double)i * step;
|
||||
double x = ext_radius * ::sin(angle);
|
||||
double y = ext_radius * ::cos(angle);
|
||||
|
||||
vertices.emplace_back(x, y, -0.1);
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < m_resolution; ++i)
|
||||
{
|
||||
double angle = (double)i * step;
|
||||
double x = int_radius * ::cos(angle);
|
||||
double y = int_radius * ::sin(angle);
|
||||
|
||||
vertices.emplace_back(x, y, -0.1);
|
||||
}
|
||||
|
||||
// top face
|
||||
vertices.emplace_back(0.0, 1.5, 0.1);
|
||||
vertices.emplace_back(0.0, 1.0, 0.1);
|
||||
vertices.emplace_back(-1.0, 2.0, 0.1);
|
||||
vertices.emplace_back(0.0, 3.0, 0.1);
|
||||
vertices.emplace_back(0.0, 2.5, 0.1);
|
||||
|
||||
for (unsigned int i = 1; i <= m_resolution; ++i)
|
||||
{
|
||||
double angle = (double)i * step;
|
||||
double x = ext_radius * ::sin(angle);
|
||||
double y = ext_radius * ::cos(angle);
|
||||
|
||||
vertices.emplace_back(x, y, 0.1);
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < m_resolution; ++i)
|
||||
{
|
||||
double angle = (double)i * step;
|
||||
double x = int_radius * ::cos(angle);
|
||||
double y = int_radius * ::sin(angle);
|
||||
|
||||
vertices.emplace_back(x, y, 0.1);
|
||||
}
|
||||
|
||||
// bottom face
|
||||
triangles.emplace_back(0, 1, 2);
|
||||
triangles.emplace_back(0, 2, 4);
|
||||
triangles.emplace_back(4, 2, 3);
|
||||
|
||||
int first_id = 4;
|
||||
int last_id = (int)vertices_per_level;
|
||||
triangles.emplace_back(last_id, 0, first_id);
|
||||
triangles.emplace_back(last_id, first_id, first_id + 1);
|
||||
for (unsigned int i = 1; i < m_resolution; ++i)
|
||||
{
|
||||
triangles.emplace_back(last_id - i, last_id - i + 1, first_id + i);
|
||||
triangles.emplace_back(last_id - i, first_id + i, first_id + i + 1);
|
||||
}
|
||||
|
||||
// top face
|
||||
last_id += 1;
|
||||
triangles.emplace_back(last_id + 0, last_id + 2, last_id + 1);
|
||||
triangles.emplace_back(last_id + 0, last_id + 4, last_id + 2);
|
||||
triangles.emplace_back(last_id + 4, last_id + 3, last_id + 2);
|
||||
|
||||
first_id = last_id + 4;
|
||||
last_id = last_id + 4 + 2 * (int)m_resolution;
|
||||
triangles.emplace_back(last_id, first_id, (int)vertices_per_level + 1);
|
||||
triangles.emplace_back(last_id, first_id + 1, first_id);
|
||||
for (unsigned int i = 1; i < m_resolution; ++i)
|
||||
{
|
||||
triangles.emplace_back(last_id - i, first_id + i, last_id - i + 1);
|
||||
triangles.emplace_back(last_id - i, first_id + i + 1, first_id + i);
|
||||
}
|
||||
|
||||
// side face
|
||||
for (unsigned int i = 0; i < 4 + 2 * (unsigned int)m_resolution; ++i)
|
||||
{
|
||||
triangles.emplace_back(i, vertices_per_level + 2 + i, i + 1);
|
||||
triangles.emplace_back(i, vertices_per_level + 1 + i, vertices_per_level + 2 + i);
|
||||
}
|
||||
triangles.emplace_back(vertices_per_level, vertices_per_level + 1, 0);
|
||||
triangles.emplace_back(vertices_per_level, 2 * vertices_per_level + 1, vertices_per_level + 1);
|
||||
|
||||
m_volume.indexed_vertex_array.load_mesh(TriangleMesh(vertices, triangles));
|
||||
m_volume.indexed_vertex_array.finalize_geometry(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GLBed::on_init_from_file(const std::string& filename)
|
||||
{
|
||||
reset();
|
||||
|
||||
if (!boost::filesystem::exists(filename))
|
||||
return false;
|
||||
|
||||
if (!boost::algorithm::iends_with(filename, ".stl"))
|
||||
return false;
|
||||
|
||||
Model model;
|
||||
try
|
||||
{
|
||||
model = Model::read_from_file(filename);
|
||||
}
|
||||
catch (std::exception & /* ex */)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_filename = filename;
|
||||
|
||||
m_volume.indexed_vertex_array.load_mesh(model.mesh());
|
||||
m_volume.indexed_vertex_array.finalize_geometry(true);
|
||||
|
||||
float color[4] = { 0.235f, 0.235f, 0.235f, 1.0f };
|
||||
set_color(color, 4);
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif // !ENABLE_GCODE_VIEWER
|
||||
|
||||
} // namespace Slic3r
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue