Added prototype make_cylinder()

This commit is contained in:
Joseph Lenox 2016-11-27 19:15:27 -06:00 committed by bubnikv
parent 3bb237deee
commit b91b98b21e
5 changed files with 54 additions and 6 deletions

View file

@ -60,7 +60,7 @@ sub new {
}, },
label_width => 100, label_width => 100,
); );
my @options = ("box"); my @options = ("box", "cylinder");
$self->{type} = Wx::ComboBox->new($self, 1, "box", wxDefaultPosition, wxDefaultSize, \@options, wxCB_READONLY); $self->{type} = Wx::ComboBox->new($self, 1, "box", wxDefaultPosition, wxDefaultSize, \@options, wxCB_READONLY);
$optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(

View file

@ -342,14 +342,19 @@ sub on_btn_lambda {
} }
my $params = $dlg->ObjectParameter; my $params = $dlg->ObjectParameter;
my $name = "lambda-".$params->{"type"}; my $name = "lambda-".$params->{"type"};
my $mesh = Slic3r::TriangleMesh->new();
my $new_volume = $self->{model_object}->add_volume(mesh => Slic3r::Test::mesh($params->{"type"}, dim=>$params->{"dim"}), material_id=>"generic"); #TODO support non-boxes
if ($name eq "box") {
$mesh = $mesh->cube($params->{"dim"}[0], $params->{"dim"}[1], $params->{"dim"}[2]);
} elsif ($name eq "cylinder") {
$mesh = $mesh->cylinder($params->{"dim"}[0], $params->{"dim"}[1]);
}
my $new_volume = $self->{model_object}->add_volume(mesh => $mesh);
$new_volume->set_modifier($is_modifier); $new_volume->set_modifier($is_modifier);
$new_volume->set_name($name); $new_volume->set_name($name);
# apply the same translation we applied to the object
$new_volume->mesh->translate(@{$self->{model_object}->origin_translation});
# set a default extruder value, since user can't add it manually # set a default extruder value, since user can't add it manually
$new_volume->config->set_ifndef('extruder', 0); $new_volume->config->set_ifndef('extruder', 0);

View file

@ -1140,7 +1140,7 @@ TriangleMeshSlicer::~TriangleMeshSlicer()
{ {
if (this->v_scaled_shared != NULL) free(this->v_scaled_shared); 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) { TriangleMesh make_cube(double x, double y, double z) {
Pointf3 pv[8] = { Pointf3 pv[8] = {
Pointf3(x, y, 0), Pointf3(x, 0, 0), Pointf3(0, 0, 0), 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); TriangleMesh mesh(vertices ,facets);
return mesh; 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;
}
} }

View file

@ -111,6 +111,9 @@ class TriangleMeshSlicer
TriangleMesh make_cube(double x, double y, double z); 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 #endif

View file

@ -39,6 +39,8 @@
void reset_repair_stats(); void reset_repair_stats();
Clone<TriangleMesh> cube(double x, double y, double z) Clone<TriangleMesh> cube(double x, double y, double z)
%code{% RETVAL = make_cube(x, y, z); %}; %code{% RETVAL = make_cube(x, y, z); %};
Clone<TriangleMesh> cylinder(double r, double h)
%code{% RETVAL = make_cylinder(r, h); %};
%{ %{
void void