-
Notifications
You must be signed in to change notification settings - Fork 1
/
picase.jscad
303 lines (274 loc) · 9.27 KB
/
picase.jscad
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
// title : picase
// author : John Cole
// license : ISC License
// file : picase.jscad
include ('jscad-utils.jscad')
include ('jscad-utils-color.jscad')
include ('jscad-raspberrypi.jscad')
include ('jscad-utils-parts.jscad')
include ('jscad-boxes.jscad')
include ('kodi_logo.jscad')
/* exported main, getParameterDefinitions */
function getParameterDefinitions() {
return [{
name: 'resolution',
type: 'choice',
values: [0, 1, 2, 3, 4],
captions: ['very low (6,16)', 'low (8,24)', 'normal (12,32)', 'high (24,64)', 'very high (48,128)'],
initial: 2,
caption: 'Resolution:'
}, {
name: 'part',
type: 'choice',
values: ['top', 'bottom', 'assembled', 'board', 'cutouts', 'board_cutouts'],
captions: ['top', 'bottom', 'assembled', 'board-only', 'cutouts', 'board and cutouts'],
initial: 'assembled',
caption: 'Part:'
}, {
name: 'type',
type: 'choice',
values: ['b_v1', 'b_v2', 'bplus', 'b3'],
captions: ['RaspberryPi B v1', 'RaspberryPi B v2', 'RaspberryPi 2', 'RaspberryPi 3'],
initial: 'b3',
caption: 'Board Type:'
}, {
name: 'thickness',
type: 'float',
initial: 2.0,
caption: 'Thickness:'
}, {
name: 'height',
type: 'float',
initial: 17.32, // thickness*2+3+1.32+9
caption: 'Height:'
}, {
name: 'gpio',
type: 'checkbox',
checked: true,
caption: 'GPIO:'
}, {
name: 'camera',
type: 'checkbox',
checked: true,
caption: 'Camera:'
}, {
name: 'logo',
type: 'checkbox',
checked: true,
caption: 'Render Logo:'
}, {
name: 'display',
type: 'checkbox',
checked: true,
caption: 'Display:'
}, {
name: 'text',
type: 'text',
initial: '',
caption: 'Text:'
}];
}
function main(params) {
// echo('params', JSON.stringify(params));
var resolutions = [
[6, 16],
[8, 24],
[12, 32],
[24, 64],
[48, 128]
];
CSG.defaultResolution3D = resolutions[params.resolution][0];
CSG.defaultResolution2D = resolutions[params.resolution][1];
util.init(CSG);
var thickness = params.thickness;
var BPlus;
var mounting;
var usb2 = false;
var usb2ports='';
var usb2clearance='';
var av_ports;
switch (params.type) {
case 'b_v1':
BPlus = RaspberryPi.B(false);
mounting = RaspberryPi.BMounting;
av_ports=',audiojackcylinder,rcajack';
break;
case 'b_v2':
BPlus = RaspberryPi.B(true);
mounting = RaspberryPi.BMounting;
av_ports=',audiojackcylinder,rcajack';
break;
case 'bplus':
BPlus = RaspberryPi.BPlus(false);
mounting = RaspberryPi.BPlusMounting;
usb2 = true;
av_ports=',avjackcylinder';
break;
case 'b3':
BPlus = RaspberryPi.BPlus(true);
mounting = RaspberryPi.BPlusMounting;
usb2 = true;
av_ports=',avjackcylinder';
break;
default:
}
if (usb2) {
usb2ports = ',usb2';
usb2clearance=',usb20Clearance,usb21Clearance';
BPlus.add(RaspberryPi.Parts.UsbWifiAdapter(BPlus.parts.usb2, 0).enlarge([1, 1, 1]), 'usb20Clearance', true);
BPlus.add(RaspberryPi.Parts.UsbWifiAdapter(BPlus.parts.usb2, 1).enlarge([1, 1, 1]), 'usb21Clearance', true);
}
BPlus.add(RaspberryPi.Parts.UsbWifiAdapter(BPlus.parts.usb1, 0).enlarge([1, 1, 1]), 'usb10Clearance', true);
BPlus.add(RaspberryPi.Parts.UsbWifiAdapter(BPlus.parts.usb1, 1).enlarge([1, 1, 1]), 'usb11Clearance', true);
BPlus.add(BPlus.parts.ethernet.color('blue').snap(BPlus.parts.ethernet, 'x', 'outside-'), 'ethernetClearance', true);
var center = BPlus.parts.mb.calcCenter('xy');
BPlus.map(function (part) {
return part.translate(center);
});
var mb = BPlus.parts.mb;
var topsupports = mounting.pads(mb, {
height: params.height - 2*thickness - 1.32 - 3
}).map(function (part) {
return part.fillet(-1, 'z+').color('blue');
});
var bottomsupports = mounting.pads(mb, {
height: 3,
snap: 'outside+'
}).map(function (part) {
return part.fillet(-1, 'z-').color('red');
});
var spacer = Parts.Cube([2, 2, 2]).snap(mb, 'x', 'outside-');
var interior = union([
topsupports.combine(),
bottomsupports.combine(),
BPlus.combine('mb'),
spacer
]);
var boxsize = interior.enlarge(1, 1, 0).size();
var chamfer = thickness / 2;
var box = Boxes.Rectangle(boxsize, thickness, function (box) {
return box
.rotateY(90)
.chamfer(chamfer, 'z+')
.chamfer(chamfer, 'z-')
.rotateY(-90)
.chamfer(chamfer, 'z+')
.chamfer(chamfer, 'z-')
.align(interior, 'xyz');
});
var screw = Parts.Hardware.FlatHeadScrew(5.38, 1.7, 2.84, 12.7 - 1.7).combine('head,thread');
var screws = bottomsupports.clone(function (part) {
return screw.align(part, 'xy').snap(box, 'z', 'inside-');
});
var label;
if (params.text.length > 0) {
var uselabel = true;
var labelarea = topsupports.combine().enlarge([-15, -5, 0]);
var labelsize = labelarea.size();
label = util.label(params.text, 0, 0, 3, thickness + 1)
.snap(box, 'z', 'inside+')
.align(labelarea, 'xy')
.fit([labelsize.x, labelsize.y, 0], true)
.translate([0, 0, 0.5]);
var connectorarea = label.size();
var connector = Parts.Cube([connectorarea.x, 1, 1])
.align(label, 'x')
.snap(label, 'y', 'outside+')
.snap(box, 'z', 'inside+')
.translate([0, 0, -thickness / 2]);
var connectors = union([0.2, 0.4, 0.6, 0.8].map(function (position) {
return connector.translate([0, connectorarea.y * position, 0]);
}));
}
if (params.logo) {
var uselogo = true;
var logoarea = topsupports.combine().enlarge([-15, -5, 0]);
var logosize = logoarea.size();
var logo_3d = logo().extrude({offset:[0,0,params.thickness+1]})
.snap(box, 'z', 'inside+')
.align(logoarea, 'xy')
.fit([logosize.x * 0.75, logosize.y * 0.75, 0], true)
.translate([-6, -2, 0.05]);
}
var ribbonhole = Parts.Board(2, 17, 1, thickness * 2);
var card = BPlus.parts.microsd || BPlus.parts.sdcard;
var microusbplug = RaspberryPi.Parts.MicroUsbPlug(BPlus.parts.microusb).combine().enlarge([1, 0, 1]);
if (usb2) {
microusbplug = microusbplug.translate([0, 1, 0]);
} else {
microusbplug = microusbplug
//.translate(microusbplug.calcCenter('xy'))
.rotateZ(-90)
.snap(mb, 'y', 'inside-')
.snap(mb, 'x', 'outside+')
.midlineTo('y', 3.8+7.59/2)
.translate([4, 0, 0]);
}
var cutouts =
union(
BPlus.combine('ethernet,usb1'+usb2ports, {}, function (part) {
return part.enlarge([thickness, 1, 1]);}),
BPlus.combine('ethernetClearance,usb10Clearance,usb11Clearance'+usb2clearance),
BPlus.combine('hdmi'+av_ports, {}, function (part) {
return part.enlarge([1, 1 + thickness, 1]).translate([0, 0, 0]);}),
BPlus.combine('microusb').enlarge(usb2 ? [1, thickness + 1, 1] : [thickness + 1, 1, 1]).
translate( usb2 ? [0, -thickness, 0] : [-thickness, 0, 0]),
microusbplug,
card.enlarge([thickness + 1, 1, 1]).translate([-thickness, 0, 0])
)
.unionIf(label, uselabel)
.unionIf(logo_3d, uselogo)
.unionIf(function () {
return BPlus.parts.gpio.snap(box, 'z', 'inside+').enlarge([2, 1, thickness * 3]);
}, params.gpio)
.unionIf(ribbonhole.snap(box, 'z', 'inside+').align(BPlus.parts.camera, 'xy'), params.camera)
.unionIf(function () {
return ribbonhole.snap(box, 'z', 'inside+').align(BPlus.parts.display, 'xy');
}, params.display);
box = Boxes.RabettTopBottom(box, thickness, 0.3, {
removableTop: true,
removableBottom: false
});
var parts = {
top: function () {
return box
.combine('top')
.union(topsupports.combine().snap(box.parts.top, 'z', 'outside+'))
.subtract(cutouts)
.unionIf(connectors, uselabel)
.color('blue')
.subtract(screws.combine(undefined, {}, function (screw) {
return screw.enlarge([-0.6, -0.6, 4]);
}));
},
bottom: function () {
return box
.combine('bottom')
.subtract(cutouts)
.union(bottomsupports.combine())
.color('red')
.subtract(screws.combine(undefined, {}, function (screw) {
return screw.enlarge([0.42, 0.42, 0]);
}));
},
assembled: function () {
return union([BPlus.combine(), parts.top(), parts.bottom()]);
},
board: function () {
return BPlus.combine();
},
cutouts: function () {
return cutouts;
},
board_cutouts: function () {
return union(BPlus.combine(),cutouts);
}
};
return parts[params.part]();
}
// ********************************************************
// Other jscad libraries are injected here. Do not remove.
// Install jscad libraries using NPM
// ********************************************************
// include:js
// endinject