mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-08 23:46:24 -06:00
Add the full source of BambuStudio
using version 1.0.10
This commit is contained in:
parent
30bcadab3e
commit
1555904bef
3771 changed files with 1251328 additions and 0 deletions
152
src/libslic3r/ModelArrange.cpp
Normal file
152
src/libslic3r/ModelArrange.cpp
Normal file
|
@ -0,0 +1,152 @@
|
|||
#include "ModelArrange.hpp"
|
||||
|
||||
#include <libslic3r/Model.hpp>
|
||||
#include <libslic3r/Geometry/ConvexHull.hpp>
|
||||
#include "MTUtils.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
arrangement::ArrangePolygons get_arrange_polys(const Model &model, ModelInstancePtrs &instances)
|
||||
{
|
||||
size_t count = 0;
|
||||
for (auto obj : model.objects) count += obj->instances.size();
|
||||
|
||||
ArrangePolygons input;
|
||||
input.reserve(count);
|
||||
instances.clear(); instances.reserve(count);
|
||||
ArrangePolygon ap;
|
||||
for (ModelObject *mo : model.objects)
|
||||
for (ModelInstance *minst : mo->instances) {
|
||||
minst->get_arrange_polygon(&ap);
|
||||
input.emplace_back(ap);
|
||||
instances.emplace_back(minst);
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
bool apply_arrange_polys(ArrangePolygons &input, ModelInstancePtrs &instances, VirtualBedFn vfn)
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
for(size_t i = 0; i < input.size(); ++i) {
|
||||
if (input[i].bed_idx != 0) { ret = false; if (vfn) vfn(input[i]); }
|
||||
if (input[i].bed_idx >= 0)
|
||||
instances[i]->apply_arrange_result(input[i].translation.cast<double>(),
|
||||
input[i].rotation);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Slic3r::arrangement::ArrangePolygon get_arrange_poly(const Model &model)
|
||||
{
|
||||
ArrangePolygon ap;
|
||||
Points &apts = ap.poly.contour.points;
|
||||
for (const ModelObject *mo : model.objects)
|
||||
for (const ModelInstance *minst : mo->instances) {
|
||||
ArrangePolygon obj_ap;
|
||||
minst->get_arrange_polygon(&obj_ap);
|
||||
ap.poly.contour.rotate(obj_ap.rotation);
|
||||
ap.poly.contour.translate(obj_ap.translation.x(), obj_ap.translation.y());
|
||||
const Points &pts = obj_ap.poly.contour.points;
|
||||
std::copy(pts.begin(), pts.end(), std::back_inserter(apts));
|
||||
}
|
||||
|
||||
apts = std::move(Geometry::convex_hull(apts).points);
|
||||
return ap;
|
||||
}
|
||||
|
||||
void duplicate(Model &model, Slic3r::arrangement::ArrangePolygons &copies, VirtualBedFn vfn)
|
||||
{
|
||||
for (ModelObject *o : model.objects) {
|
||||
// make a copy of the pointers in order to avoid recursion when appending their copies
|
||||
ModelInstancePtrs instances = o->instances;
|
||||
o->instances.clear();
|
||||
for (const ModelInstance *i : instances) {
|
||||
for (arrangement::ArrangePolygon &ap : copies) {
|
||||
if (ap.bed_idx != 0) vfn(ap);
|
||||
ModelInstance *instance = o->add_instance(*i);
|
||||
Vec2d pos = unscale(ap.translation);
|
||||
instance->set_offset(instance->get_offset() + to_3d(pos, 0.));
|
||||
}
|
||||
}
|
||||
o->invalidate_bounding_box();
|
||||
}
|
||||
}
|
||||
|
||||
void duplicate_objects(Model &model, size_t copies_num)
|
||||
{
|
||||
for (ModelObject *o : model.objects) {
|
||||
// make a copy of the pointers in order to avoid recursion when appending their copies
|
||||
ModelInstancePtrs instances = o->instances;
|
||||
for (const ModelInstance *i : instances)
|
||||
for (size_t k = 2; k <= copies_num; ++ k)
|
||||
o->add_instance(*i);
|
||||
}
|
||||
}
|
||||
|
||||
// Set up arrange polygon for a ModelInstance and Wipe tower
|
||||
template<class T>
|
||||
arrangement::ArrangePolygon get_arrange_poly(T obj)
|
||||
{
|
||||
ArrangePolygon ap = obj.get_arrange_polygon();
|
||||
//BBS: always set bed_idx to 0 to use original transforms with no bed_idx
|
||||
//if this object is not arranged, it can keep the original transforms
|
||||
//ap.bed_idx = ap.translation.x() / bed_stride_x(plater);
|
||||
ap.bed_idx = 0;
|
||||
ap.setter = [obj](const ArrangePolygon& p) {
|
||||
if (p.is_arranged()) {
|
||||
Vec2d t = p.translation.cast<double>();
|
||||
//BBS: change to sudoku-style computation, do it in partplate list
|
||||
//t.x() += p.bed_idx * bed_stride(plater);
|
||||
//t.x() += col * bed_stride_x(plater);
|
||||
//t.y() -= row * bed_stride_y(plater);
|
||||
T{ obj }.apply_arrange_result(t, p.rotation, p.itemid);
|
||||
}
|
||||
};
|
||||
|
||||
return ap;
|
||||
}
|
||||
|
||||
template<>
|
||||
arrangement::ArrangePolygon get_arrange_poly(ModelInstance* inst)
|
||||
{
|
||||
return get_arrange_poly(PtrWrapper{ inst });
|
||||
}
|
||||
|
||||
ArrangePolygon get_instance_arrange_poly(ModelInstance* instance, const Slic3r::DynamicPrintConfig& config)
|
||||
{
|
||||
ArrangePolygon ap = get_arrange_poly(PtrWrapper{ instance });
|
||||
|
||||
//BBS: add temperature information
|
||||
if (config.has("curr_bed_type")) {
|
||||
ap.bed_temp = 0;
|
||||
ap.first_bed_temp = 0;
|
||||
BedType curr_bed_type = config.opt_enum<BedType>("curr_bed_type");
|
||||
|
||||
const ConfigOptionInts* bed_opt = config.option<ConfigOptionInts>(get_bed_temp_key(curr_bed_type));
|
||||
if (bed_opt != nullptr)
|
||||
ap.bed_temp = bed_opt->get_at(ap.extrude_ids.back());
|
||||
|
||||
const ConfigOptionInts* bed_opt_1st_layer = config.option<ConfigOptionInts>(get_bed_temp_1st_layer_key(curr_bed_type));
|
||||
if (bed_opt_1st_layer != nullptr)
|
||||
ap.first_bed_temp = bed_opt_1st_layer->get_at(ap.extrude_ids.back());
|
||||
}
|
||||
|
||||
if (config.has("nozzle_temperature")) //get the print temperature
|
||||
ap.print_temp = config.opt_int("nozzle_temperature", ap.extrude_ids.back() - 1);
|
||||
if (config.has("nozzle_temperature_initial_layer")) //get the nozzle_temperature_initial_layer
|
||||
ap.first_print_temp = config.opt_int("nozzle_temperature_initial_layer", ap.extrude_ids.back() - 1);
|
||||
// BBS: since first_bed_temp packs all 3 temperatures, vitrify_temp should follow same routine
|
||||
if (config.has("temperature_vitrification")) {
|
||||
int tmp = config.opt_int("temperature_vitrification", ap.extrude_ids.back() - 1);
|
||||
for (int i = 0; i < BedType::btCount; i++)
|
||||
ap.vitrify_temp += tmp * pow(100, BedType::btCount - i - 1);
|
||||
}
|
||||
ap.height = instance->get_object()->bounding_box().size().z();
|
||||
ap.name = instance->get_object()->name;
|
||||
return ap;
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
Loading…
Add table
Add a link
Reference in a new issue