mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 17:25:54 +08:00
Follow-up of a7d1c9b5e99132e51d84fcd5155ede7da1ecadd0 - Simplified code to generate a smooth cylinder
This commit is contained in:
parent
adb3d0101d
commit
74d3227703
@ -2254,7 +2254,7 @@ GLModel::Geometry smooth_sphere(unsigned int resolution, float radius)
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLModel::Geometry smooth_cylinder(Axis axis, unsigned int resolution, float radius, float height)
|
GLModel::Geometry smooth_cylinder(unsigned int resolution, float radius, float height)
|
||||||
{
|
{
|
||||||
resolution = std::max<unsigned int>(4, resolution);
|
resolution = std::max<unsigned int>(4, resolution);
|
||||||
|
|
||||||
@ -2266,39 +2266,19 @@ GLModel::Geometry smooth_cylinder(Axis axis, unsigned int resolution, float radi
|
|||||||
data.reserve_vertices(sectorCount * 4 + 2);
|
data.reserve_vertices(sectorCount * 4 + 2);
|
||||||
data.reserve_indices(sectorCount * 4 * 3);
|
data.reserve_indices(sectorCount * 4 * 3);
|
||||||
|
|
||||||
auto generate_vertices_on_circle = [sectorCount, sectorStep](Axis axis, float radius) {
|
auto generate_vertices_on_circle = [sectorCount, sectorStep](float radius) {
|
||||||
std::vector<Vec3f> ret;
|
std::vector<Vec3f> ret;
|
||||||
ret.reserve(sectorCount);
|
ret.reserve(sectorCount);
|
||||||
for (unsigned int i = 0; i < sectorCount; ++i) {
|
for (unsigned int i = 0; i < sectorCount; ++i) {
|
||||||
// from 0 to 2pi
|
// from 0 to 2pi
|
||||||
const float sectorAngle = (i != sectorCount) ? sectorStep * i : 0.0f;
|
const float sectorAngle = (i != sectorCount) ? sectorStep * i : 0.0f;
|
||||||
const float x1 = radius * std::cos(sectorAngle);
|
ret.emplace_back(radius * std::cos(sectorAngle), radius * std::sin(sectorAngle), 0.0f);
|
||||||
const float x2 = radius * std::sin(sectorAngle);
|
|
||||||
|
|
||||||
Vec3f v;
|
|
||||||
switch (axis)
|
|
||||||
{
|
|
||||||
case X: { v = Vec3f(0.0f, x1, x2); break; }
|
|
||||||
case Y: { v = Vec3f(-x1, 0.0f, x2); break; }
|
|
||||||
case Z: { v = Vec3f(x1, x2, 0.0f); break; }
|
|
||||||
default: { assert(false); break; }
|
|
||||||
}
|
|
||||||
|
|
||||||
ret.emplace_back(v);
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::vector<Vec3f> base_vertices = generate_vertices_on_circle(axis, radius);
|
const std::vector<Vec3f> base_vertices = generate_vertices_on_circle(radius);
|
||||||
|
const Vec3f h = height * Vec3f::UnitZ();
|
||||||
Vec3f h;
|
|
||||||
switch (axis)
|
|
||||||
{
|
|
||||||
case X: { h = height * Vec3f::UnitX(); break; }
|
|
||||||
case Y: { h = height * Vec3f::UnitY(); break; }
|
|
||||||
case Z: { h = height * Vec3f::UnitZ(); break; }
|
|
||||||
default: { assert(false); break; }
|
|
||||||
}
|
|
||||||
|
|
||||||
// stem vertices
|
// stem vertices
|
||||||
for (unsigned int i = 0; i < sectorCount; ++i) {
|
for (unsigned int i = 0; i < sectorCount; ++i) {
|
||||||
@ -2321,14 +2301,7 @@ GLModel::Geometry smooth_cylinder(Axis axis, unsigned int resolution, float radi
|
|||||||
// bottom cap vertices
|
// bottom cap vertices
|
||||||
Vec3f cap_center = Vec3f::Zero();
|
Vec3f cap_center = Vec3f::Zero();
|
||||||
unsigned int cap_center_id = data.vertices_count();
|
unsigned int cap_center_id = data.vertices_count();
|
||||||
Vec3f normal;
|
Vec3f normal = -Vec3f::UnitZ();
|
||||||
switch (axis)
|
|
||||||
{
|
|
||||||
case X: { normal = -Vec3f::UnitX(); break; }
|
|
||||||
case Y: { normal = -Vec3f::UnitY(); break; }
|
|
||||||
case Z: { normal = -Vec3f::UnitZ(); break; }
|
|
||||||
default: { assert(false); break; }
|
|
||||||
}
|
|
||||||
|
|
||||||
data.add_vertex(cap_center, normal);
|
data.add_vertex(cap_center, normal);
|
||||||
for (unsigned int i = 0; i < sectorCount; ++i) {
|
for (unsigned int i = 0; i < sectorCount; ++i) {
|
||||||
|
@ -374,16 +374,13 @@ namespace GUI {
|
|||||||
GLModel::Geometry diamond(unsigned int resolution);
|
GLModel::Geometry diamond(unsigned int resolution);
|
||||||
|
|
||||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||||
// create a sphere with the given resolution and smooth normals
|
// create a sphere with smooth normals
|
||||||
// the origin of the sphere is in its center
|
// the origin of the sphere is in its center
|
||||||
// the radius of the sphere is the given value
|
|
||||||
GLModel::Geometry smooth_sphere(unsigned int resolution, float radius);
|
GLModel::Geometry smooth_sphere(unsigned int resolution, float radius);
|
||||||
// create a cylinder with the given resolution and smooth normals
|
// create a cylinder with smooth normals
|
||||||
// the axis of the cylinder is the given value
|
// the axis of the cylinder is the Z axis
|
||||||
// the radius of the cylinder is the given value
|
// the origin of the cylinder is the center of its bottom cap face
|
||||||
// the height of the cylinder is the given value
|
GLModel::Geometry smooth_cylinder(unsigned int resolution, float radius, float height);
|
||||||
// the origin of the cylinder is in the center of the cap face having axis == 0
|
|
||||||
GLModel::Geometry smooth_cylinder(Axis axis, unsigned int resolution, float radius, float height);
|
|
||||||
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
|
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
|
||||||
|
|
||||||
} // namespace GUI
|
} // namespace GUI
|
||||||
|
@ -23,7 +23,7 @@ GLGizmoMeasure::GLGizmoMeasure(GLCanvas3D& parent, const std::string& icon_filen
|
|||||||
: GLGizmoBase(parent, icon_filename, sprite_id)
|
: GLGizmoBase(parent, icon_filename, sprite_id)
|
||||||
{
|
{
|
||||||
m_vbo_sphere.init_from(smooth_sphere(16, 7.5f));
|
m_vbo_sphere.init_from(smooth_sphere(16, 7.5f));
|
||||||
m_vbo_cylinder.init_from(smooth_cylinder(Z, 16, 5.0f, 1.0f));
|
m_vbo_cylinder.init_from(smooth_cylinder(16, 5.0f, 1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event)
|
bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user