Skip to content

Commit 0f57b05

Browse files
committed
added Rimbox
1 parent eeaa003 commit 0f57b05

File tree

3 files changed

+83
-15
lines changed

3 files changed

+83
-15
lines changed

debug/viewer.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
<label for="selectModelCode">model: </label>
6363
<select id="selectModelCode" onchange="Viewer.loadModelCode(this.value)">
6464
<option>polygonstackbox</option>
65-
<option>stackbox</option>
65+
<option>Rimbox</option>
66+
<option>starbox</option>
6667
<option>combine</option>
6768
<option>logo</option>
6869
<option>smile</option>

examples/Rimbox.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/// <reference path="typings/tsd.d.ts" />
2+
var makerjs = require('makerjs');
3+
var RimboxCorner = (function () {
4+
function RimboxCorner(holeRadius, rimThickness) {
5+
var rim = Math.min(rimThickness, holeRadius);
6+
var hr = holeRadius + rim;
7+
this.paths = {
8+
centerRound: new makerjs.paths.Arc([0, 0], hr, 0, 90),
9+
hFillet: new makerjs.paths.Arc([0, hr + holeRadius], holeRadius, 180, 270),
10+
wFillet: new makerjs.paths.Arc([hr + holeRadius, 0], holeRadius, 180, 270)
11+
};
12+
}
13+
return RimboxCorner;
14+
})();
15+
var RimboxInner = (function () {
16+
function RimboxInner(width, height, holeRadius, rimThickness) {
17+
var mm = makerjs.model;
18+
var corner = new RimboxCorner(holeRadius, rimThickness);
19+
this.models = {
20+
bottomLeft: corner,
21+
bottomRight: mm.move(mm.mirror(corner, true, false), [width, 0]),
22+
topLeft: mm.move(mm.mirror(corner, false, true), [0, height]),
23+
topRight: mm.move(mm.mirror(corner, true, true), [width, height])
24+
};
25+
var line = makerjs.paths.Line;
26+
var rim = Math.min(rimThickness, holeRadius);
27+
var d = 2 * holeRadius + rim;
28+
this.paths = {
29+
bottom: new line([d, -holeRadius], [width - d, -holeRadius]),
30+
top: new line([d, height + holeRadius], [width - d, height + holeRadius]),
31+
left: new line([-holeRadius, d], [-holeRadius, height - d]),
32+
right: new line([width + holeRadius, d], [width + holeRadius, height - d])
33+
};
34+
}
35+
return RimboxInner;
36+
})();
37+
var Rimbox = (function () {
38+
function Rimbox(width, height, holeRadius, rimThickness, hollow) {
39+
if (arguments.length == 0) {
40+
var defaultValues = makerjs.kit.getParameterValues(Rimbox);
41+
width = defaultValues.shift();
42+
height = defaultValues.shift();
43+
holeRadius = defaultValues.shift();
44+
rimThickness = defaultValues.shift();
45+
}
46+
var mm = makerjs.models;
47+
var cornerRadius = holeRadius + rimThickness;
48+
var c2 = cornerRadius * 2;
49+
this.models = {
50+
bolts: new mm.BoltRectangle(width, height, holeRadius),
51+
outer: new mm.RoundRectangle(width + c2, height + c2, cornerRadius)
52+
};
53+
if (hollow) {
54+
this.models['inner'] = new RimboxInner(width, height, holeRadius, rimThickness);
55+
}
56+
this.models['outer'].origin = [-cornerRadius, -cornerRadius];
57+
}
58+
return Rimbox;
59+
})();
60+
Rimbox.metaParameters = [
61+
{ title: "width", type: "range", min: 10, max: 500, value: 120 },
62+
{ title: "height", type: "range", min: 10, max: 500, value: 100 },
63+
{ title: "holeRadius", type: "range", min: 1, max: 20, value: 3 },
64+
{ title: "rimThickness", type: "range", min: 1, max: 20, value: 2 },
65+
{ title: "hollow", type: "bool", value: true }
66+
];
67+
module.exports = Rimbox;
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// <reference path="typings/tsd.d.ts" />
22
var makerjs = require('makerjs');
3-
var stackboxCorner = (function () {
4-
function stackboxCorner(holeRadius, rimThickness) {
3+
var starboxCorner = (function () {
4+
function starboxCorner(holeRadius, rimThickness) {
55
var rim = Math.min(rimThickness, holeRadius);
66
var hr = holeRadius + rim;
77
this.paths = {
@@ -10,12 +10,12 @@ var stackboxCorner = (function () {
1010
wFillet: new makerjs.paths.Arc([hr + holeRadius, 0], holeRadius, 180, 270)
1111
};
1212
}
13-
return stackboxCorner;
13+
return starboxCorner;
1414
})();
15-
var stackboxInner = (function () {
16-
function stackboxInner(width, height, holeRadius, rimThickness) {
15+
var starboxInner = (function () {
16+
function starboxInner(width, height, holeRadius, rimThickness) {
1717
var mm = makerjs.model;
18-
var corner = new stackboxCorner(holeRadius, rimThickness);
18+
var corner = new starboxCorner(holeRadius, rimThickness);
1919
this.models = {
2020
bottomLeft: corner,
2121
bottomRight: mm.move(mm.mirror(corner, true, false), [width, 0]),
@@ -32,12 +32,12 @@ var stackboxInner = (function () {
3232
right: new line([width + holeRadius, d], [width + holeRadius, height - d])
3333
};
3434
}
35-
return stackboxInner;
35+
return starboxInner;
3636
})();
37-
var stackbox = (function () {
38-
function stackbox(width, height, holeRadius, rimThickness, angle) {
37+
var starbox = (function () {
38+
function starbox(width, height, holeRadius, rimThickness, angle) {
3939
if (arguments.length == 0) {
40-
var defaultValues = makerjs.kit.getParameterValues(stackbox);
40+
var defaultValues = makerjs.kit.getParameterValues(starbox);
4141
width = defaultValues.shift();
4242
height = defaultValues.shift();
4343
holeRadius = defaultValues.shift();
@@ -49,7 +49,7 @@ var stackbox = (function () {
4949
this.models = {
5050
bolts: new mm.BoltRectangle(width, height, holeRadius),
5151
outer: new mm.RoundRectangle(width + c2, height + c2, cornerRadius),
52-
inner: new stackboxInner(width, height, holeRadius, rimThickness)
52+
inner: new starboxInner(width, height, holeRadius, rimThickness)
5353
};
5454
this.models['outer'].origin = [-cornerRadius, -cornerRadius];
5555

@@ -64,13 +64,13 @@ var stackbox = (function () {
6464

6565
makerjs.model.combine(this.models.inner, star, false, true, true, false);
6666
}
67-
return stackbox;
67+
return starbox;
6868
})();
69-
stackbox.metaParameters = [
69+
starbox.metaParameters = [
7070
{ title: "width", type: "range", min: 10, max: 500, value: 120 },
7171
{ title: "height", type: "range", min: 10, max: 500, value: 100 },
7272
{ title: "holeRadius", type: "range", min: 1, max: 20, value: 3 },
7373
{ title: "rimThickness", type: "range", min: 1, max: 20, value: 2 },
7474
{ title: "angle", type: "range", min: -180, max: 180, value: 45 }
7575
];
76-
module.exports = stackbox;
76+
module.exports = starbox;

0 commit comments

Comments
 (0)