Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/xs
diff options
context:
space:
mode:
authorJoseph Lenox <lenox.joseph@gmail.com>2016-11-28 04:15:27 +0300
committerbubnikv <bubnikv@gmail.com>2017-02-21 18:10:38 +0300
commitb91b98b21e342783b3c8989e0275294a808dd6ca (patch)
tree78ef983f0133abd4a13ea232c9d6a07ffc2be86b /xs
parent3bb237deee86b8a362cbfcef877e015aeee359be (diff)
Added prototype make_cylinder()
Diffstat (limited to 'xs')
-rw-r--r--xs/src/libslic3r/TriangleMesh.cpp40
-rw-r--r--xs/src/libslic3r/TriangleMesh.hpp3
-rw-r--r--xs/xsp/TriangleMesh.xsp2
3 files changed, 44 insertions, 1 deletions
diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp
index 968ce371e..0950ee26f 100644
--- a/xs/src/libslic3r/TriangleMesh.cpp
+++ b/xs/src/libslic3r/TriangleMesh.cpp
@@ -1140,7 +1140,7 @@ TriangleMeshSlicer::~TriangleMeshSlicer()
{
if (this->v_scaled_shared != NULL) free(this->v_scaled_shared);
}
-
+// Generate the vertex list for a cube solid of arbitrary size in X/Y/Z.
TriangleMesh make_cube(double x, double y, double z) {
Pointf3 pv[8] = {
Pointf3(x, y, 0), Pointf3(x, 0, 0), Pointf3(0, 0, 0),
@@ -1160,4 +1160,42 @@ TriangleMesh make_cube(double x, double y, double z) {
TriangleMesh mesh(vertices ,facets);
return mesh;
}
+
+// Generate the mesh for a cylinder and return it, using
+// the generated angle to calculate the top mesh triangles.
+TriangleMesh make_cylinder(double r, double h, double fa) {
+ Pointf3s vertices;
+ std::vector<Point3> facets;
+
+ // 2 special vertices, top and bottom center, rest are relative to this
+ vertices.push_back(Pointf3(0.0, 0.0, 0.0));
+ vertices.push_back(Pointf3(0.0, 0.0, h));
+
+ // adjust via rounding
+ double angle = (2*PI / floor(2*PI / fa));
+
+ // for each line along the polygon approximating the top/bottom of the
+ // circle, generate four points and four facets (2 for the wall, 2 for the
+ // top and bottom.
+ // Special case: Last line shares 2 vertices with the first line.
+ unsigned id = 3;
+ vertices.push_back(Pointf3(sin(0) * r , cos(0) * r, 0));
+ vertices.push_back(Pointf3(sin(0) * r , cos(0) * r, h));
+ for (double i = angle; i < 2*PI; i+=angle) {
+ vertices.push_back(Pointf3(sin(i) * r , cos(i) * r, 0));
+ vertices.push_back(Pointf3(sin(i) * r , cos(i) * r, h));
+ id += 2;
+ facets.push_back(Point3(0, id - 1, id - 3));
+ facets.push_back(Point3(1, id, id - 2));
+ facets.push_back(Point3(id, id - 1, id - 3));
+ facets.push_back(Point3(id - 3, id - 2, id));
+ }
+ facets.push_back(Point3(0, 2, id -1));
+ facets.push_back(Point3(1, 3, id));
+ facets.push_back(Point3(id - 1, 2, 3));
+ facets.push_back(Point3(id - 1, 3, id));
+
+ TriangleMesh mesh(vertices ,facets);
+ return mesh;
+}
}
diff --git a/xs/src/libslic3r/TriangleMesh.hpp b/xs/src/libslic3r/TriangleMesh.hpp
index 4c2ad2d5e..9320d2a16 100644
--- a/xs/src/libslic3r/TriangleMesh.hpp
+++ b/xs/src/libslic3r/TriangleMesh.hpp
@@ -111,6 +111,9 @@ class TriangleMeshSlicer
TriangleMesh make_cube(double x, double y, double z);
+// Generate a TriangleMesh of a cylinder
+TriangleMesh make_cylinder(double r, double h, double fa=(2*PI/360));
+
}
#endif
diff --git a/xs/xsp/TriangleMesh.xsp b/xs/xsp/TriangleMesh.xsp
index 24d1b5f88..32425d6d4 100644
--- a/xs/xsp/TriangleMesh.xsp
+++ b/xs/xsp/TriangleMesh.xsp
@@ -39,6 +39,8 @@
void reset_repair_stats();
Clone<TriangleMesh> cube(double x, double y, double z)
%code{% RETVAL = make_cube(x, y, z); %};
+ Clone<TriangleMesh> cylinder(double r, double h)
+ %code{% RETVAL = make_cylinder(r, h); %};
%{
void