Skip to content

Commit

Permalink
#3 Add basic simulated annealing. Also, 2D margin computation moved f…
Browse files Browse the repository at this point in the history
…rom scad to the python packing code.
  • Loading branch information
mbugert committed Sep 10, 2017
1 parent b364ed0 commit 0ab92bd
Show file tree
Hide file tree
Showing 10 changed files with 556 additions and 95 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,13 @@ These parameters can be defined in the global scope of a scad file.
#### lkerf
Compensate laser kerf (shrinkage caused by the laser) in millimeters. *Default = 0*

#### lmargin
Distance between lparts in 2D in millimeters. *Default = 2*

### Exporting to 2D
1. Drag your ``.scad`` source file(s) into the ``scad`` folder.
2. Open a shell in the folder containing ``Makefile`` and run ``make``. The resulting DXF files are located in the ``dxf`` folder.
3. *Recommended:* Open ``scad/<your-model>_2d.scad`` with OpenSCAD to verify that all ``lpart`` dimensions were defined correctly and nothing overlaps.

### Sheet Size
There is currently no nice way of specifying the sheet size. However, it can be changed with a text editor in the ``Makefile``. The default is 600x300 (millimeters).
There is currently no nice way of specifying the sheet size. However, it can be changed with a text editor in the ``Makefile``. The default is 600x300 (millimeters). In the same spot, the 2D object margins can be set (*Default = 2*).

## FAQ
### What does laserscad do?
Expand Down
7 changes: 5 additions & 2 deletions dist/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# one of [fastest, medium, high, insane]
quality = medium
sheet_xlen = 600
sheet_ylen = 300
object_margin = 2

SOURCE = scad
TEMP = temp
Expand Down Expand Up @@ -54,12 +57,12 @@ $(TEMP)/%_bb.csv: $(SOURCE)/%.scad | $(SOURCE) $(TEMP)
# optimize object placement
$(TEMP)/%_pos.csv: $(TEMP)/%_bb.csv | $(UTIL)
@echo Optimizing object placement...
@python3 $(UTIL)/column_packing.py $(sheet_xlen) $(sheet_ylen) $< $@
@python3 $(UTIL)/packing.py $< $@ $(quality) $(sheet_xlen) $(sheet_ylen) $(object_margin)

# copy the source scad file, then inject the optimal translations into it
$(SOURCE)/%_2d.scad: $(SOURCE)/%.scad $(TEMP)/%_pos.csv | $(UTIL)
@cp $< $@
@python3 $(UTIL)/writeback.py $@ $(word 2,$^)
@python3 $(UTIL)/write_back.py $@ $(word 2,$^)

$(OUTPUTS_DXF): $(TARGET_DXF)/%.dxf: $(SOURCE)/%_2d.scad | $(TARGET_DXF)
@echo Creating $@...
Expand Down
26 changes: 13 additions & 13 deletions dist/laserscad.scad
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,34 @@ module lpart(id, dims) {
}
}

// overwritten once optimal translations are known after packing
// overwritten once optimal translations/rotations are known after packing
function _lpart_translation(id) = [0,0,0];
function _lpart_rotation(id) = [0,0,0];

_lkerf_default = 0;
_lmargin_default = 2;

// actual lpart after sanity checks
module _lpart_sane(id, dims) {
if (_laserscad_mode <= 0) {
children();
} else {
lkerf = lkerf == undef? _lkerf_default : lkerf;
lmargin = lmargin == undef? _lmargin_default : lmargin;

if (_laserscad_mode == 1) {
ext_dims = dims + 2 * (lkerf + lmargin) * [1,1];
ext_dims = dims + 2*lkerf * [1,1];
echo(str("[laserscad] ##",id,",",ext_dims[0],",",ext_dims[1],"##"));
} else {
translate(_lpart_translation(id) + (lkerf + lmargin)*[1,1,0]) {
// show the bounding box if in validate mode
if (_laserscad_mode == 2) {
color("magenta", 0.6)
square(dims + lkerf*[1,1]);
translate(_lpart_translation(id) + lkerf*[1,1,0]) {
rotate(_lpart_rotation(id)) {
// show the bounding box if in validate mode
if (_laserscad_mode == 2) {
color("magenta", 0.6)
square(dims + lkerf*[1,1]);
}
offset(delta=lkerf)
projection(cut=false)
children();
}
offset(delta=lkerf)
projection(cut=false)
children();
}
}
}
Expand All @@ -93,7 +94,6 @@ module _lpart_sane(id, dims) {
// print hints in dev mode if variables are undefined
if (_laserscad_mode == 0) {
_laserscad_var_sanity_check(lkerf, "lkerf", _lkerf_default);
_laserscad_var_sanity_check(lmargin, "lmargin", _lmargin_default);
}

module _laserscad_var_sanity_check(var, name, default) {
Expand Down
46 changes: 0 additions & 46 deletions dist/util/column_packing.py

This file was deleted.

Loading

0 comments on commit 0ab92bd

Please sign in to comment.