mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-28 21:32:11 +00:00
Handy Models geometry improvement. (#10092)
* helper disk by code Co-Authored-By: Ian Bassi <12130714+ianalexis@users.noreply.github.com> * Torus Delete torus.stl Co-Authored-By: Ian Bassi <12130714+ianalexis@users.noreply.github.com> * traingle count tunning Co-Authored-By: Ian Bassi <12130714+ianalexis@users.noreply.github.com> * Update TriangleMesh.hpp Co-Authored-By: Ian Bassi <12130714+ianalexis@users.noreply.github.com> * adjusting disk diameter --------- Co-authored-by: Ian Bassi <12130714+ianalexis@users.noreply.github.com> Co-authored-by: Noisyfox <timemanager.rick@gmail.com>
This commit is contained in:
@@ -1004,6 +1004,62 @@ indexed_triangle_set its_make_frustum(double r, double h, double fa)
|
||||
return mesh;
|
||||
}
|
||||
|
||||
// Generate the mesh for a torus
|
||||
// r: major radius (distance from center of tube to center of torus)
|
||||
// h: minor radius (radius of the tube)
|
||||
// fa: angular step in radians (smaller = more segments)
|
||||
indexed_triangle_set its_make_torus(double r, double h, double fa)
|
||||
{
|
||||
indexed_triangle_set mesh;
|
||||
auto& vertices = mesh.vertices;
|
||||
auto& facets = mesh.indices;
|
||||
|
||||
// Number of segments around the main ring and the tube
|
||||
size_t n_major = (size_t)ceil(2. * PI / fa);
|
||||
size_t n_minor = (size_t)ceil(2. * PI / fa);
|
||||
|
||||
double major_step = 2. * PI / n_major;
|
||||
double minor_step = 2. * PI / n_minor;
|
||||
|
||||
// Reserve memory for performance
|
||||
vertices.reserve(n_major * n_minor);
|
||||
facets.reserve(n_major * n_minor * 2);
|
||||
|
||||
// Generate vertices
|
||||
for (size_t i = 0; i < n_major; ++i) {
|
||||
double major_angle = i * major_step;
|
||||
double cos_major = cos(major_angle);
|
||||
double sin_major = sin(major_angle);
|
||||
for (size_t j = 0; j < n_minor; ++j) {
|
||||
double minor_angle = j * minor_step;
|
||||
double cos_minor = cos(minor_angle);
|
||||
double sin_minor = sin(minor_angle);
|
||||
// Parametric equation for torus
|
||||
float x = float((r + h * cos_minor) * cos_major);
|
||||
float y = float((r + h * cos_minor) * sin_major);
|
||||
float z = float(h * sin_minor);
|
||||
vertices.emplace_back(Vec3f(x, y, z));
|
||||
}
|
||||
}
|
||||
|
||||
// Generate faces
|
||||
for (size_t i = 0; i < n_major; ++i) {
|
||||
size_t inext = (i + 1) % n_major;
|
||||
for (size_t j = 0; j < n_minor; ++j) {
|
||||
size_t jnext = (j + 1) % n_minor;
|
||||
int v0 = int(i * n_minor + j);
|
||||
int v1 = int(inext * n_minor + j);
|
||||
int v2 = int(inext * n_minor + jnext);
|
||||
int v3 = int(i * n_minor + jnext);
|
||||
// Two triangles per quad
|
||||
facets.emplace_back(v0, v1, v2);
|
||||
facets.emplace_back(v0, v2, v3);
|
||||
}
|
||||
}
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
indexed_triangle_set its_make_cone(double r, double h, double fa)
|
||||
{
|
||||
indexed_triangle_set mesh;
|
||||
|
||||
@@ -335,9 +335,10 @@ inline Vec3f its_face_normal(const indexed_triangle_set &its, const int face_idx
|
||||
|
||||
indexed_triangle_set its_make_cube(double x, double y, double z);
|
||||
indexed_triangle_set its_make_prism(float width, float length, float height);
|
||||
indexed_triangle_set its_make_cylinder(double r, double h, double fa=(2*PI/360));
|
||||
indexed_triangle_set its_make_cone(double r, double h, double fa=(2*PI/360));
|
||||
indexed_triangle_set its_make_frustum(double r, double h, double fa=(2*PI/360));
|
||||
indexed_triangle_set its_make_cylinder(double r, double h, double fa=(2*PI/180));
|
||||
indexed_triangle_set its_make_cone(double r, double h, double fa=(2*PI/180));
|
||||
indexed_triangle_set its_make_frustum(double r, double h, double fa=(2*PI/180));
|
||||
indexed_triangle_set its_make_torus(double r, double h, double fa);
|
||||
indexed_triangle_set its_make_frustum_dowel(double r, double h, int sectorCount);
|
||||
indexed_triangle_set its_make_pyramid(float base, float height);
|
||||
indexed_triangle_set its_make_sphere(double radius, double fa);
|
||||
@@ -349,10 +350,11 @@ inline indexed_triangle_set its_convex_hull(const indexed_triangle_set &its) { r
|
||||
|
||||
inline TriangleMesh make_cube(double x, double y, double z) { return TriangleMesh(its_make_cube(x, y, z)); }
|
||||
inline TriangleMesh make_prism(float width, float length, float height) { return TriangleMesh(its_make_prism(width, length, height)); }
|
||||
inline TriangleMesh make_cylinder(double r, double h, double fa=(2*PI/360)) { return TriangleMesh{its_make_cylinder(r, h, fa)}; }
|
||||
inline TriangleMesh make_cone(double r, double h, double fa=(2*PI/360)) { return TriangleMesh(its_make_cone(r, h, fa)); }
|
||||
inline TriangleMesh make_cylinder(double r, double h, double fa=(2*PI/180)) { return TriangleMesh{its_make_cylinder(r, h, fa)}; }
|
||||
inline TriangleMesh make_cone(double r, double h, double fa=(2*PI/180)) { return TriangleMesh(its_make_cone(r, h, fa)); }
|
||||
inline TriangleMesh make_pyramid(float base, float height) { return TriangleMesh(its_make_pyramid(base, height)); }
|
||||
inline TriangleMesh make_sphere(double rho, double fa=(2*PI/360)) { return TriangleMesh(its_make_sphere(rho, fa)); }
|
||||
inline TriangleMesh make_sphere(double rho, double fa=(2*PI/90)) { return TriangleMesh(its_make_sphere(rho, fa)); }
|
||||
inline TriangleMesh make_torus(double r, double h, double fa=(PI/60)) { return TriangleMesh(its_make_torus(r, h, fa)); }
|
||||
|
||||
bool its_write_stl_ascii(const char *file, const char *label, const std::vector<stl_triangle_vertex_indices> &indices, const std::vector<stl_vertex> &vertices);
|
||||
inline bool its_write_stl_ascii(const char *file, const char *label, const indexed_triangle_set &its) { return its_write_stl_ascii(file, label, its.indices, its.vertices); }
|
||||
|
||||
Reference in New Issue
Block a user