-
Notifications
You must be signed in to change notification settings - Fork 1
/
stl2gcode.php
40 lines (29 loc) · 944 Bytes
/
stl2gcode.php
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
<?php
require "vendor/autoload.php";
use php3d\stlslice\Examples\STL2GCode;
use php3d\stlslice\Examples\STLMillingEdit;
use php3d\stlslice\STLSlice;
use php3d\stl\STL;
ini_set('memory_limit', -1);
if (count($argv) !== 3) {
die("Usage: php " . $argv[0] . " file-path output-path\n");
}
$fileName = $argv[1];
try {
bcscale(16);
echo "[+] Reading STL file...\n";
$stl = STL::fromString(file_get_contents($fileName));
echo "[+] Removing edges...\n";
$mill = STL::fromArray((new STLMillingEdit($stl->toArray()))
->extractMillingContent()
->getStlFileContentArray()
);
echo "[+] Slicing objects...\n";
$layers = (new STLSlice($mill, 10))
->slice();
echo "[+] Generating GCode...\n";
file_put_contents($argv[2], (new STL2GCode($layers, 10))->toGCodeString());
echo "[++] Done.\n";
} catch (Exception $ex) {
die("[-] Can not convert file: " . $ex->getMessage());
}