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

slabasebed.cpp « slabasebed « sandboxes - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1996a1eb870199a80e5d8841f14ebf1b9b5c2d36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <fstream>
#include <string>

#include <libslic3r/libslic3r.h>
#include <libslic3r/TriangleMesh.hpp>
#include <libslic3r/Tesselate.hpp>
#include <libslic3r/ClipperUtils.hpp>
#include <libslic3r/SLA/SLABasePool.hpp>
#include <libslic3r/SLA/SLABoilerPlate.hpp>
#include <libnest2d/tools/benchmark.h>

const std::string USAGE_STR = {
    "Usage: slabasebed stlfilename.stl"
};

namespace Slic3r { namespace sla {

Contour3D create_pad(const Polygons &ground_layer,
                           const ExPolygons &holes = {},
                           const PadConfig& cfg = PadConfig());

Contour3D walls(const Polygon& floor_plate, const Polygon& ceiling,
                double floor_z_mm, double ceiling_z_mm,
                double offset_difference_mm, ThrowOnCancel thr);

void offset(ExPolygon& sh, coord_t distance);

}
}

int main(const int argc, const char *argv[]) {
    using namespace Slic3r;
    using std::cout; using std::endl;

    if(argc < 2) {
        cout << USAGE_STR << endl;
        return EXIT_SUCCESS;
    }

    TriangleMesh model;
    Benchmark bench;

    model.ReadSTLFile(argv[1]);
    model.align_to_origin();

    ExPolygons ground_slice;
    sla::pad_plate(model, ground_slice, 0.1f);
    if(ground_slice.empty()) return EXIT_FAILURE;

    ground_slice = offset_ex(ground_slice, 0.5);
    ExPolygon gndfirst; gndfirst = ground_slice.front();
    sla::breakstick_holes(gndfirst, 0.5, 10, 0.3);

    sla::Contour3D mesh;

    bench.start();

    sla::PadConfig cfg;
    cfg.min_wall_height_mm = 0;
    cfg.edge_radius_mm = 0;
    mesh = sla::create_pad(to_polygons(ground_slice), {}, cfg);

    bench.stop();

    cout << "Base pool creation time: " << std::setprecision(10)
         << bench.getElapsedSec() << " seconds." << endl;

    for(auto& trind : mesh.indices) {
        Vec3d p0 = mesh.points[size_t(trind[0])];
        Vec3d p1 = mesh.points[size_t(trind[1])];
        Vec3d p2 = mesh.points[size_t(trind[2])];
        Vec3d p01 = p1 - p0;
        Vec3d p02 = p2 - p0;
        auto a = p01.cross(p02).norm() / 2.0;
        if(std::abs(a) < 1e-6) std::cout << "degenerate triangle" << std::endl;
    }

    //    basepool.write_ascii("out.stl");

    std::fstream outstream("out.obj", std::fstream::out);
    mesh.to_obj(outstream);

    return EXIT_SUCCESS;
}