@jwc/jscad-raspberrypi 3.1.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +22 -0
- package/README.md +0 -12
- package/dist/examples/active-cooling-fan.jscad +2737 -0
- package/dist/examples/bplus.jscad +350 -334
- package/dist/examples/bplus3.jscad +350 -334
- package/dist/examples/camera-module-v1.jscad +350 -334
- package/dist/examples/camera-module-v2.jscad +350 -334
- package/dist/examples/example.jscad +366 -343
- package/dist/examples/hat-standoff.jscad +350 -334
- package/dist/examples/hat.jscad +350 -334
- package/dist/examples/hq_camera-module.jscad +2737 -0
- package/dist/examples/miniPiTFT.jscad +2737 -0
- package/dist/examples/pi-tft22.jscad +350 -334
- package/dist/examples/pi-tft24.jscad +350 -334
- package/dist/examples/pi4.jscad +2737 -0
- package/dist/examples/pi5.jscad +2747 -0
- package/dist/examples/spacer.jscad +350 -334
- package/dist/index.js +191 -102
- package/dist/v1compat.js +191 -102
- package/examples/active-cooling-fan.jscad +10 -0
- package/examples/example.jscad +16 -9
- package/examples/hq_camera-module.jscad +10 -0
- package/examples/miniPiTFT.jscad +10 -0
- package/examples/pi4.jscad +10 -0
- package/examples/pi5.jscad +20 -0
- package/gulpfile.js +4 -4
- package/package.json +31 -39
- package/src/active-cooling-fan.js +160 -0
- package/src/bplus.js +38 -2
- package/src/index.js +6 -9
|
@@ -0,0 +1,2737 @@
|
|
|
1
|
+
function main() {
|
|
2
|
+
util.init(CSG);
|
|
3
|
+
|
|
4
|
+
var camera = RaspberryPi.ActiveCoolingFan();
|
|
5
|
+
|
|
6
|
+
return camera.combine().Center();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// include:js
|
|
10
|
+
// /node_modules/@jwc/jscad-utils/dist/compat.js
|
|
11
|
+
var Parts, Boxes, Group, Debug, array, triUtils;
|
|
12
|
+
|
|
13
|
+
function initJscadutils(_CSG, options = {}) {
|
|
14
|
+
options = Object.assign({
|
|
15
|
+
debug: ""
|
|
16
|
+
}, options);
|
|
17
|
+
var jsCadCSG = {
|
|
18
|
+
CSG,
|
|
19
|
+
CAG
|
|
20
|
+
};
|
|
21
|
+
var scadApi = {
|
|
22
|
+
vector_text,
|
|
23
|
+
rectangular_extrude,
|
|
24
|
+
vector_char,
|
|
25
|
+
primitives3d: {
|
|
26
|
+
cube,
|
|
27
|
+
sphere,
|
|
28
|
+
cylinder
|
|
29
|
+
},
|
|
30
|
+
extrusions: {
|
|
31
|
+
rectangular_extrude
|
|
32
|
+
},
|
|
33
|
+
text: {
|
|
34
|
+
vector_text,
|
|
35
|
+
vector_char
|
|
36
|
+
},
|
|
37
|
+
booleanOps: {
|
|
38
|
+
union
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var jscadUtilsDebug = (options.debug.split(",") || []).reduce((checks, check) => {
|
|
42
|
+
if (check.startsWith("-")) {
|
|
43
|
+
checks.disabled.push(new RegExp(`^${check.slice(1).replace(/\*/g, ".*?")}$`));
|
|
44
|
+
} else {
|
|
45
|
+
checks.enabled.push(new RegExp(`^${check.replace(/\*/g, ".*?")}$`));
|
|
46
|
+
}
|
|
47
|
+
return checks;
|
|
48
|
+
}, {
|
|
49
|
+
enabled: [],
|
|
50
|
+
disabled: []
|
|
51
|
+
});
|
|
52
|
+
var jscadUtils = function(exports, jsCadCSG, scadApi) {
|
|
53
|
+
"use strict";
|
|
54
|
+
function _interopDefaultLegacy(e) {
|
|
55
|
+
return e && typeof e === "object" && "default" in e ? e : {
|
|
56
|
+
default: e
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
var jsCadCSG__default = _interopDefaultLegacy(jsCadCSG);
|
|
60
|
+
var scadApi__default = _interopDefaultLegacy(scadApi);
|
|
61
|
+
var util = Object.freeze({
|
|
62
|
+
__proto__: null,
|
|
63
|
+
get NOZZEL_SIZE() {
|
|
64
|
+
return NOZZEL_SIZE;
|
|
65
|
+
},
|
|
66
|
+
get nearest() {
|
|
67
|
+
return nearest;
|
|
68
|
+
},
|
|
69
|
+
get identity() {
|
|
70
|
+
return identity;
|
|
71
|
+
},
|
|
72
|
+
get result() {
|
|
73
|
+
return result;
|
|
74
|
+
},
|
|
75
|
+
get defaults() {
|
|
76
|
+
return defaults;
|
|
77
|
+
},
|
|
78
|
+
get isEmpty() {
|
|
79
|
+
return isEmpty;
|
|
80
|
+
},
|
|
81
|
+
get isNegative() {
|
|
82
|
+
return isNegative;
|
|
83
|
+
},
|
|
84
|
+
get print() {
|
|
85
|
+
return print;
|
|
86
|
+
},
|
|
87
|
+
get jscadToString() {
|
|
88
|
+
return jscadToString;
|
|
89
|
+
},
|
|
90
|
+
get error() {
|
|
91
|
+
return error;
|
|
92
|
+
},
|
|
93
|
+
get depreciated() {
|
|
94
|
+
return depreciated;
|
|
95
|
+
},
|
|
96
|
+
get inch() {
|
|
97
|
+
return inch;
|
|
98
|
+
},
|
|
99
|
+
get cm() {
|
|
100
|
+
return cm;
|
|
101
|
+
},
|
|
102
|
+
get label() {
|
|
103
|
+
return label;
|
|
104
|
+
},
|
|
105
|
+
get text() {
|
|
106
|
+
return text;
|
|
107
|
+
},
|
|
108
|
+
get unitCube() {
|
|
109
|
+
return unitCube;
|
|
110
|
+
},
|
|
111
|
+
get unitAxis() {
|
|
112
|
+
return unitAxis;
|
|
113
|
+
},
|
|
114
|
+
get toArray() {
|
|
115
|
+
return toArray;
|
|
116
|
+
},
|
|
117
|
+
get ifArray() {
|
|
118
|
+
return ifArray;
|
|
119
|
+
},
|
|
120
|
+
get segment() {
|
|
121
|
+
return segment;
|
|
122
|
+
},
|
|
123
|
+
get zipObject() {
|
|
124
|
+
return zipObject;
|
|
125
|
+
},
|
|
126
|
+
get map() {
|
|
127
|
+
return map;
|
|
128
|
+
},
|
|
129
|
+
get mapValues() {
|
|
130
|
+
return mapValues;
|
|
131
|
+
},
|
|
132
|
+
get pick() {
|
|
133
|
+
return pick;
|
|
134
|
+
},
|
|
135
|
+
get mapPick() {
|
|
136
|
+
return mapPick;
|
|
137
|
+
},
|
|
138
|
+
get divA() {
|
|
139
|
+
return divA;
|
|
140
|
+
},
|
|
141
|
+
get divxyz() {
|
|
142
|
+
return divxyz;
|
|
143
|
+
},
|
|
144
|
+
get div() {
|
|
145
|
+
return div;
|
|
146
|
+
},
|
|
147
|
+
get mulxyz() {
|
|
148
|
+
return mulxyz;
|
|
149
|
+
},
|
|
150
|
+
get mul() {
|
|
151
|
+
return mul;
|
|
152
|
+
},
|
|
153
|
+
get xyz2array() {
|
|
154
|
+
return xyz2array;
|
|
155
|
+
},
|
|
156
|
+
get rotationAxes() {
|
|
157
|
+
return rotationAxes;
|
|
158
|
+
},
|
|
159
|
+
get size() {
|
|
160
|
+
return size;
|
|
161
|
+
},
|
|
162
|
+
get scale() {
|
|
163
|
+
return scale;
|
|
164
|
+
},
|
|
165
|
+
get center() {
|
|
166
|
+
return center;
|
|
167
|
+
},
|
|
168
|
+
get centerY() {
|
|
169
|
+
return centerY;
|
|
170
|
+
},
|
|
171
|
+
get centerX() {
|
|
172
|
+
return centerX;
|
|
173
|
+
},
|
|
174
|
+
get enlarge() {
|
|
175
|
+
return enlarge;
|
|
176
|
+
},
|
|
177
|
+
get fit() {
|
|
178
|
+
return fit;
|
|
179
|
+
},
|
|
180
|
+
get shift() {
|
|
181
|
+
return shift;
|
|
182
|
+
},
|
|
183
|
+
get zero() {
|
|
184
|
+
return zero;
|
|
185
|
+
},
|
|
186
|
+
get mirrored4() {
|
|
187
|
+
return mirrored4;
|
|
188
|
+
},
|
|
189
|
+
get flushSide() {
|
|
190
|
+
return flushSide;
|
|
191
|
+
},
|
|
192
|
+
get calcFlush() {
|
|
193
|
+
return calcFlush;
|
|
194
|
+
},
|
|
195
|
+
get calcSnap() {
|
|
196
|
+
return calcSnap;
|
|
197
|
+
},
|
|
198
|
+
get snap() {
|
|
199
|
+
return snap;
|
|
200
|
+
},
|
|
201
|
+
get flush() {
|
|
202
|
+
return flush;
|
|
203
|
+
},
|
|
204
|
+
get axisApply() {
|
|
205
|
+
return axisApply;
|
|
206
|
+
},
|
|
207
|
+
get axis2array() {
|
|
208
|
+
return axis2array;
|
|
209
|
+
},
|
|
210
|
+
get centroid() {
|
|
211
|
+
return centroid;
|
|
212
|
+
},
|
|
213
|
+
get calcmidlineTo() {
|
|
214
|
+
return calcmidlineTo;
|
|
215
|
+
},
|
|
216
|
+
get midlineTo() {
|
|
217
|
+
return midlineTo;
|
|
218
|
+
},
|
|
219
|
+
get translator() {
|
|
220
|
+
return translator;
|
|
221
|
+
},
|
|
222
|
+
get calcCenterWith() {
|
|
223
|
+
return calcCenterWith;
|
|
224
|
+
},
|
|
225
|
+
get centerWith() {
|
|
226
|
+
return centerWith;
|
|
227
|
+
},
|
|
228
|
+
get getDelta() {
|
|
229
|
+
return getDelta;
|
|
230
|
+
},
|
|
231
|
+
get bisect() {
|
|
232
|
+
return bisect;
|
|
233
|
+
},
|
|
234
|
+
get slice() {
|
|
235
|
+
return slice;
|
|
236
|
+
},
|
|
237
|
+
get wedge() {
|
|
238
|
+
return wedge;
|
|
239
|
+
},
|
|
240
|
+
get stretch() {
|
|
241
|
+
return stretch;
|
|
242
|
+
},
|
|
243
|
+
get poly2solid() {
|
|
244
|
+
return poly2solid;
|
|
245
|
+
},
|
|
246
|
+
get slices2poly() {
|
|
247
|
+
return slices2poly;
|
|
248
|
+
},
|
|
249
|
+
get normalVector() {
|
|
250
|
+
return normalVector;
|
|
251
|
+
},
|
|
252
|
+
get sliceParams() {
|
|
253
|
+
return sliceParams;
|
|
254
|
+
},
|
|
255
|
+
get reShape() {
|
|
256
|
+
return reShape;
|
|
257
|
+
},
|
|
258
|
+
get chamfer() {
|
|
259
|
+
return chamfer;
|
|
260
|
+
},
|
|
261
|
+
get fillet() {
|
|
262
|
+
return fillet;
|
|
263
|
+
},
|
|
264
|
+
get calcRotate() {
|
|
265
|
+
return calcRotate;
|
|
266
|
+
},
|
|
267
|
+
get rotateAround() {
|
|
268
|
+
return rotateAround;
|
|
269
|
+
},
|
|
270
|
+
get clone() {
|
|
271
|
+
return clone;
|
|
272
|
+
},
|
|
273
|
+
get addConnector() {
|
|
274
|
+
return addConnector;
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
function _arrayLikeToArray(r, a) {
|
|
278
|
+
(null == a || a > r.length) && (a = r.length);
|
|
279
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
280
|
+
return n;
|
|
281
|
+
}
|
|
282
|
+
function _arrayWithHoles(r) {
|
|
283
|
+
if (Array.isArray(r)) return r;
|
|
284
|
+
}
|
|
285
|
+
function _defineProperty(e, r, t) {
|
|
286
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
287
|
+
value: t,
|
|
288
|
+
enumerable: !0,
|
|
289
|
+
configurable: !0,
|
|
290
|
+
writable: !0
|
|
291
|
+
}) : e[r] = t, e;
|
|
292
|
+
}
|
|
293
|
+
function _iterableToArrayLimit(r, l) {
|
|
294
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
295
|
+
if (null != t) {
|
|
296
|
+
var e, n, i, u, a = [], f = !0, o = !1;
|
|
297
|
+
try {
|
|
298
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
299
|
+
if (Object(t) !== t) return;
|
|
300
|
+
f = !1;
|
|
301
|
+
} else for (;!(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) ;
|
|
302
|
+
} catch (r) {
|
|
303
|
+
o = !0, n = r;
|
|
304
|
+
} finally {
|
|
305
|
+
try {
|
|
306
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
307
|
+
} finally {
|
|
308
|
+
if (o) throw n;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return a;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function _nonIterableRest() {
|
|
315
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
316
|
+
}
|
|
317
|
+
function ownKeys(e, r) {
|
|
318
|
+
var t = Object.keys(e);
|
|
319
|
+
if (Object.getOwnPropertySymbols) {
|
|
320
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
321
|
+
r && (o = o.filter(function(r) {
|
|
322
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
323
|
+
})), t.push.apply(t, o);
|
|
324
|
+
}
|
|
325
|
+
return t;
|
|
326
|
+
}
|
|
327
|
+
function _objectSpread2(e) {
|
|
328
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
329
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
330
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
331
|
+
_defineProperty(e, r, t[r]);
|
|
332
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
333
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
return e;
|
|
337
|
+
}
|
|
338
|
+
function _slicedToArray(r, e) {
|
|
339
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
340
|
+
}
|
|
341
|
+
function _toPrimitive(t, r) {
|
|
342
|
+
if ("object" != typeof t || !t) return t;
|
|
343
|
+
var e = t[Symbol.toPrimitive];
|
|
344
|
+
if (void 0 !== e) {
|
|
345
|
+
var i = e.call(t, r || "default");
|
|
346
|
+
if ("object" != typeof i) return i;
|
|
347
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
348
|
+
}
|
|
349
|
+
return ("string" === r ? String : Number)(t);
|
|
350
|
+
}
|
|
351
|
+
function _toPropertyKey(t) {
|
|
352
|
+
var i = _toPrimitive(t, "string");
|
|
353
|
+
return "symbol" == typeof i ? i : i + "";
|
|
354
|
+
}
|
|
355
|
+
function _typeof(o) {
|
|
356
|
+
"@babel/helpers - typeof";
|
|
357
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
358
|
+
return typeof o;
|
|
359
|
+
} : function(o) {
|
|
360
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
361
|
+
}, _typeof(o);
|
|
362
|
+
}
|
|
363
|
+
function _unsupportedIterableToArray(r, a) {
|
|
364
|
+
if (r) {
|
|
365
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
366
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
367
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
var toRadians = function toRadians(deg) {
|
|
371
|
+
return deg / 180 * Math.PI;
|
|
372
|
+
};
|
|
373
|
+
var toDegrees = function toDegrees(rad) {
|
|
374
|
+
return rad * (180 / Math.PI);
|
|
375
|
+
};
|
|
376
|
+
var solve = function solve(p1, p2) {
|
|
377
|
+
var r = {
|
|
378
|
+
c: 90,
|
|
379
|
+
A: Math.abs(p2.x - p1.x),
|
|
380
|
+
B: Math.abs(p2.y - p1.y)
|
|
381
|
+
};
|
|
382
|
+
var brad = Math.atan2(r.B, r.A);
|
|
383
|
+
r.b = this.toDegrees(brad);
|
|
384
|
+
r.C = r.B / Math.sin(brad);
|
|
385
|
+
r.a = 90 - r.b;
|
|
386
|
+
return r;
|
|
387
|
+
};
|
|
388
|
+
var solve90SA = function solve90SA(r) {
|
|
389
|
+
r = Object.assign(r, {
|
|
390
|
+
C: 90
|
|
391
|
+
});
|
|
392
|
+
r.A = r.A || 90 - r.B;
|
|
393
|
+
r.B = r.B || 90 - r.A;
|
|
394
|
+
var arad = toRadians(r.A);
|
|
395
|
+
r.a = r.a || (r.c ? r.c * Math.sin(arad) : r.b * Math.tan(arad));
|
|
396
|
+
r.c = r.c || r.a / Math.sin(arad);
|
|
397
|
+
r.b = r.b || r.a / Math.tan(arad);
|
|
398
|
+
return r;
|
|
399
|
+
};
|
|
400
|
+
var solve90ac = function solve90ac(r) {
|
|
401
|
+
r = Object.assign(r, {
|
|
402
|
+
C: 90
|
|
403
|
+
});
|
|
404
|
+
var arad = Math.asin(r.a / r.c);
|
|
405
|
+
r.A = toDegrees(arad);
|
|
406
|
+
r.B = 90 - r.A;
|
|
407
|
+
r.b = Math.sqrt(Math.pow(r.c, 2) - Math.pow(r.a, 2));
|
|
408
|
+
return r;
|
|
409
|
+
};
|
|
410
|
+
function solveab(r) {
|
|
411
|
+
r = Object.assign(r, {
|
|
412
|
+
C: 90
|
|
413
|
+
});
|
|
414
|
+
r.c = Math.sqrt(Math.pow(r.a, 2) + Math.pow(r.b, 2));
|
|
415
|
+
r.A = toDegrees(Math.asin(r.a / r.c));
|
|
416
|
+
r.B = toDegrees(Math.asin(r.b / r.c));
|
|
417
|
+
return r;
|
|
418
|
+
}
|
|
419
|
+
var triUtils = Object.freeze({
|
|
420
|
+
__proto__: null,
|
|
421
|
+
toRadians,
|
|
422
|
+
toDegrees,
|
|
423
|
+
solve,
|
|
424
|
+
solve90SA,
|
|
425
|
+
solve90ac,
|
|
426
|
+
solveab
|
|
427
|
+
});
|
|
428
|
+
var div$1 = function div(a, f) {
|
|
429
|
+
return a.map(function(e) {
|
|
430
|
+
return e / f;
|
|
431
|
+
});
|
|
432
|
+
};
|
|
433
|
+
var addValue = function addValue(a, f) {
|
|
434
|
+
return a.map(function(e) {
|
|
435
|
+
return e + f;
|
|
436
|
+
});
|
|
437
|
+
};
|
|
438
|
+
var addArray = function addArray(a, f) {
|
|
439
|
+
return a.map(function(e, i) {
|
|
440
|
+
return e + f[i];
|
|
441
|
+
});
|
|
442
|
+
};
|
|
443
|
+
var add = function add(a) {
|
|
444
|
+
return Array.prototype.slice.call(arguments, 1).reduce(function(result, arg) {
|
|
445
|
+
if (Array.isArray(arg)) {
|
|
446
|
+
result = addArray(result, arg);
|
|
447
|
+
} else {
|
|
448
|
+
result = addValue(result, arg);
|
|
449
|
+
}
|
|
450
|
+
return result;
|
|
451
|
+
}, a);
|
|
452
|
+
};
|
|
453
|
+
var fromxyz = function fromxyz(object) {
|
|
454
|
+
return Array.isArray(object) ? object : [ object.x, object.y, object.z ];
|
|
455
|
+
};
|
|
456
|
+
var toxyz = function toxyz(a) {
|
|
457
|
+
return {
|
|
458
|
+
x: a[0],
|
|
459
|
+
y: a[1],
|
|
460
|
+
z: a[2]
|
|
461
|
+
};
|
|
462
|
+
};
|
|
463
|
+
var first = function first(a) {
|
|
464
|
+
return a ? a[0] : undefined;
|
|
465
|
+
};
|
|
466
|
+
var last = function last(a) {
|
|
467
|
+
return a && a.length > 0 ? a[a.length - 1] : undefined;
|
|
468
|
+
};
|
|
469
|
+
var min = function min(a) {
|
|
470
|
+
return a.reduce(function(result, value) {
|
|
471
|
+
return value < result ? value : result;
|
|
472
|
+
}, Number.MAX_VALUE);
|
|
473
|
+
};
|
|
474
|
+
var range = function range(a, b) {
|
|
475
|
+
var result = [];
|
|
476
|
+
for (var i = a; i < b; i++) {
|
|
477
|
+
result.push(i);
|
|
478
|
+
}
|
|
479
|
+
return result;
|
|
480
|
+
};
|
|
481
|
+
var array = Object.freeze({
|
|
482
|
+
__proto__: null,
|
|
483
|
+
div: div$1,
|
|
484
|
+
addValue,
|
|
485
|
+
addArray,
|
|
486
|
+
add,
|
|
487
|
+
fromxyz,
|
|
488
|
+
toxyz,
|
|
489
|
+
first,
|
|
490
|
+
last,
|
|
491
|
+
min,
|
|
492
|
+
range
|
|
493
|
+
});
|
|
494
|
+
var debugColors = [ "#e41a1c", "#377eb8", "#4daf4a", "#984ea3", "#ff7f00", "#ffff33", "#a65628", "#f781bf", "#999999" ];
|
|
495
|
+
var termColors = [ "\\033[0;34m", "\\033[0;32m", "\\033[0;36m", "\\033[0;31m", "\\033[0;35m", "\\033[0;33m", "\\033[1;33m", "\\033[0;30m", "\\033[1;34m" ];
|
|
496
|
+
var debugCount = 0;
|
|
497
|
+
var Debug = function Debug(name) {
|
|
498
|
+
var checks = Object.assign({
|
|
499
|
+
enabled: [],
|
|
500
|
+
disabled: [],
|
|
501
|
+
options: {
|
|
502
|
+
browser: true
|
|
503
|
+
}
|
|
504
|
+
}, jscadUtilsDebug || {});
|
|
505
|
+
var style = checks.options.browser ? "color:".concat(debugColors[debugCount++ % debugColors.length]) : "".concat(termColors[debugCount++ % termColors.length]);
|
|
506
|
+
var enabled = checks.enabled.some(function checkEnabled(check) {
|
|
507
|
+
return check.test(name);
|
|
508
|
+
}) && !checks.disabled.some(function checkEnabled(check) {
|
|
509
|
+
return check.test(name);
|
|
510
|
+
});
|
|
511
|
+
var logger = enabled ? checks.options.browser ? function() {
|
|
512
|
+
var _console;
|
|
513
|
+
for (var _len = arguments.length, msg = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
514
|
+
msg[_key] = arguments[_key];
|
|
515
|
+
}
|
|
516
|
+
(_console = console).log.apply(_console, [ "%c%s", style, name ].concat(msg));
|
|
517
|
+
} : function() {
|
|
518
|
+
var _console2;
|
|
519
|
+
for (var _len2 = arguments.length, msg = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
520
|
+
msg[_key2] = arguments[_key2];
|
|
521
|
+
}
|
|
522
|
+
(_console2 = console).log.apply(_console2, [ "".concat(name) ].concat(msg));
|
|
523
|
+
} : function() {
|
|
524
|
+
return undefined;
|
|
525
|
+
};
|
|
526
|
+
logger.enabled = enabled;
|
|
527
|
+
return logger;
|
|
528
|
+
};
|
|
529
|
+
var nameArray = {
|
|
530
|
+
aliceblue: "#f0f8ff",
|
|
531
|
+
antiquewhite: "#faebd7",
|
|
532
|
+
aqua: "#00ffff",
|
|
533
|
+
aquamarine: "#7fffd4",
|
|
534
|
+
azure: "#f0ffff",
|
|
535
|
+
beige: "#f5f5dc",
|
|
536
|
+
bisque: "#ffe4c4",
|
|
537
|
+
black: "#000000",
|
|
538
|
+
blanchedalmond: "#ffebcd",
|
|
539
|
+
blue: "#0000ff",
|
|
540
|
+
blueviolet: "#8a2be2",
|
|
541
|
+
brown: "#a52a2a",
|
|
542
|
+
burlywood: "#deb887",
|
|
543
|
+
cadetblue: "#5f9ea0",
|
|
544
|
+
chartreuse: "#7fff00",
|
|
545
|
+
chocolate: "#d2691e",
|
|
546
|
+
coral: "#ff7f50",
|
|
547
|
+
cornflowerblue: "#6495ed",
|
|
548
|
+
cornsilk: "#fff8dc",
|
|
549
|
+
crimson: "#dc143c",
|
|
550
|
+
cyan: "#00ffff",
|
|
551
|
+
darkblue: "#00008b",
|
|
552
|
+
darkcyan: "#008b8b",
|
|
553
|
+
darkgoldenrod: "#b8860b",
|
|
554
|
+
darkgray: "#a9a9a9",
|
|
555
|
+
darkgrey: "#a9a9a9",
|
|
556
|
+
darkgreen: "#006400",
|
|
557
|
+
darkkhaki: "#bdb76b",
|
|
558
|
+
darkmagenta: "#8b008b",
|
|
559
|
+
darkolivegreen: "#556b2f",
|
|
560
|
+
darkorange: "#ff8c00",
|
|
561
|
+
darkorchid: "#9932cc",
|
|
562
|
+
darkred: "#8b0000",
|
|
563
|
+
darksalmon: "#e9967a",
|
|
564
|
+
darkseagreen: "#8fbc8f",
|
|
565
|
+
darkslateblue: "#483d8b",
|
|
566
|
+
darkslategray: "#2f4f4f",
|
|
567
|
+
darkslategrey: "#2f4f4f",
|
|
568
|
+
darkturquoise: "#00ced1",
|
|
569
|
+
darkviolet: "#9400d3",
|
|
570
|
+
deeppink: "#ff1493",
|
|
571
|
+
deepskyblue: "#00bfff",
|
|
572
|
+
dimgray: "#696969",
|
|
573
|
+
dimgrey: "#696969",
|
|
574
|
+
dodgerblue: "#1e90ff",
|
|
575
|
+
firebrick: "#b22222",
|
|
576
|
+
floralwhite: "#fffaf0",
|
|
577
|
+
forestgreen: "#228b22",
|
|
578
|
+
fuchsia: "#ff00ff",
|
|
579
|
+
gainsboro: "#dcdcdc",
|
|
580
|
+
ghostwhite: "#f8f8ff",
|
|
581
|
+
gold: "#ffd700",
|
|
582
|
+
goldenrod: "#daa520",
|
|
583
|
+
gray: "#808080",
|
|
584
|
+
grey: "#808080",
|
|
585
|
+
green: "#008000",
|
|
586
|
+
greenyellow: "#adff2f",
|
|
587
|
+
honeydew: "#f0fff0",
|
|
588
|
+
hotpink: "#ff69b4",
|
|
589
|
+
indianred: "#cd5c5c",
|
|
590
|
+
indigo: "#4b0082",
|
|
591
|
+
ivory: "#fffff0",
|
|
592
|
+
khaki: "#f0e68c",
|
|
593
|
+
lavender: "#e6e6fa",
|
|
594
|
+
lavenderblush: "#fff0f5",
|
|
595
|
+
lawngreen: "#7cfc00",
|
|
596
|
+
lemonchiffon: "#fffacd",
|
|
597
|
+
lightblue: "#add8e6",
|
|
598
|
+
lightcoral: "#f08080",
|
|
599
|
+
lightcyan: "#e0ffff",
|
|
600
|
+
lightgoldenrodyellow: "#fafad2",
|
|
601
|
+
lightgray: "#d3d3d3",
|
|
602
|
+
lightgrey: "#d3d3d3",
|
|
603
|
+
lightgreen: "#90ee90",
|
|
604
|
+
lightpink: "#ffb6c1",
|
|
605
|
+
lightsalmon: "#ffa07a",
|
|
606
|
+
lightseagreen: "#20b2aa",
|
|
607
|
+
lightskyblue: "#87cefa",
|
|
608
|
+
lightslategray: "#778899",
|
|
609
|
+
lightslategrey: "#778899",
|
|
610
|
+
lightsteelblue: "#b0c4de",
|
|
611
|
+
lightyellow: "#ffffe0",
|
|
612
|
+
lime: "#00ff00",
|
|
613
|
+
limegreen: "#32cd32",
|
|
614
|
+
linen: "#faf0e6",
|
|
615
|
+
magenta: "#ff00ff",
|
|
616
|
+
maroon: "#800000",
|
|
617
|
+
mediumaquamarine: "#66cdaa",
|
|
618
|
+
mediumblue: "#0000cd",
|
|
619
|
+
mediumorchid: "#ba55d3",
|
|
620
|
+
mediumpurple: "#9370d8",
|
|
621
|
+
mediumseagreen: "#3cb371",
|
|
622
|
+
mediumslateblue: "#7b68ee",
|
|
623
|
+
mediumspringgreen: "#00fa9a",
|
|
624
|
+
mediumturquoise: "#48d1cc",
|
|
625
|
+
mediumvioletred: "#c71585",
|
|
626
|
+
midnightblue: "#191970",
|
|
627
|
+
mintcream: "#f5fffa",
|
|
628
|
+
mistyrose: "#ffe4e1",
|
|
629
|
+
moccasin: "#ffe4b5",
|
|
630
|
+
navajowhite: "#ffdead",
|
|
631
|
+
navy: "#000080",
|
|
632
|
+
oldlace: "#fdf5e6",
|
|
633
|
+
olive: "#808000",
|
|
634
|
+
olivedrab: "#6b8e23",
|
|
635
|
+
orange: "#ffa500",
|
|
636
|
+
orangered: "#ff4500",
|
|
637
|
+
orchid: "#da70d6",
|
|
638
|
+
palegoldenrod: "#eee8aa",
|
|
639
|
+
palegreen: "#98fb98",
|
|
640
|
+
paleturquoise: "#afeeee",
|
|
641
|
+
palevioletred: "#d87093",
|
|
642
|
+
papayawhip: "#ffefd5",
|
|
643
|
+
peachpuff: "#ffdab9",
|
|
644
|
+
peru: "#cd853f",
|
|
645
|
+
pink: "#ffc0cb",
|
|
646
|
+
plum: "#dda0dd",
|
|
647
|
+
powderblue: "#b0e0e6",
|
|
648
|
+
purple: "#800080",
|
|
649
|
+
red: "#ff0000",
|
|
650
|
+
rosybrown: "#bc8f8f",
|
|
651
|
+
royalblue: "#4169e1",
|
|
652
|
+
saddlebrown: "#8b4513",
|
|
653
|
+
salmon: "#fa8072",
|
|
654
|
+
sandybrown: "#f4a460",
|
|
655
|
+
seagreen: "#2e8b57",
|
|
656
|
+
seashell: "#fff5ee",
|
|
657
|
+
sienna: "#a0522d",
|
|
658
|
+
silver: "#c0c0c0",
|
|
659
|
+
skyblue: "#87ceeb",
|
|
660
|
+
slateblue: "#6a5acd",
|
|
661
|
+
slategray: "#708090",
|
|
662
|
+
slategrey: "#708090",
|
|
663
|
+
snow: "#fffafa",
|
|
664
|
+
springgreen: "#00ff7f",
|
|
665
|
+
steelblue: "#4682b4",
|
|
666
|
+
tan: "#d2b48c",
|
|
667
|
+
teal: "#008080",
|
|
668
|
+
thistle: "#d8bfd8",
|
|
669
|
+
tomato: "#ff6347",
|
|
670
|
+
turquoise: "#40e0d0",
|
|
671
|
+
violet: "#ee82ee",
|
|
672
|
+
wheat: "#f5deb3",
|
|
673
|
+
white: "#ffffff",
|
|
674
|
+
whitesmoke: "#f5f5f5",
|
|
675
|
+
yellow: "#ffff00",
|
|
676
|
+
yellowgreen: "#9acd32"
|
|
677
|
+
};
|
|
678
|
+
function name2hex(n) {
|
|
679
|
+
n = n.toLowerCase();
|
|
680
|
+
if (!nameArray[n]) return "Invalid Color Name";
|
|
681
|
+
return nameArray[n];
|
|
682
|
+
}
|
|
683
|
+
function hex2rgb(h) {
|
|
684
|
+
h = h.replace(/^\#/, "");
|
|
685
|
+
if (h.length === 6) {
|
|
686
|
+
return [ parseInt(h.substr(0, 2), 16), parseInt(h.substr(2, 2), 16), parseInt(h.substr(4, 2), 16) ];
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
var _name2rgb = {};
|
|
690
|
+
function name2rgb(n) {
|
|
691
|
+
if (!_name2rgb[n]) _name2rgb[n] = hex2rgb(name2hex(n));
|
|
692
|
+
return _name2rgb[n];
|
|
693
|
+
}
|
|
694
|
+
function color(o, r, g, b, a) {
|
|
695
|
+
if (typeof r !== "string") return o.setColor(r, g, b, a);
|
|
696
|
+
if (r === "") return o;
|
|
697
|
+
var c = name2rgb(r).map(function(x) {
|
|
698
|
+
return x / 255;
|
|
699
|
+
});
|
|
700
|
+
c[3] = g || 1;
|
|
701
|
+
return o.setColor(c);
|
|
702
|
+
}
|
|
703
|
+
function init(proto) {
|
|
704
|
+
if (proto.prototype._jscadutilsinit) return;
|
|
705
|
+
proto.prototype.color = function(r, g, b, a) {
|
|
706
|
+
if (!r) return this;
|
|
707
|
+
return color(this, r, g, b, a);
|
|
708
|
+
};
|
|
709
|
+
proto.prototype.flush = function flush$1(to, axis, mside, wside) {
|
|
710
|
+
return flush(this, to, axis, mside, wside);
|
|
711
|
+
};
|
|
712
|
+
proto.prototype.snap = function snap$1(to, axis, orientation, delta) {
|
|
713
|
+
return snap(this, to, axis, orientation, delta);
|
|
714
|
+
};
|
|
715
|
+
proto.prototype.calcSnap = function calcSnap$1(to, axis, orientation, delta) {
|
|
716
|
+
return calcSnap(this, to, axis, orientation, delta);
|
|
717
|
+
};
|
|
718
|
+
proto.prototype.midlineTo = function midlineTo$1(axis, to) {
|
|
719
|
+
return midlineTo(this, axis, to);
|
|
720
|
+
};
|
|
721
|
+
proto.prototype.calcmidlineTo = function midlineTo(axis, to) {
|
|
722
|
+
return calcmidlineTo(this, axis, to);
|
|
723
|
+
};
|
|
724
|
+
proto.prototype.centerWith = function centerWith$1(axis, to) {
|
|
725
|
+
depreciated("centerWith", true, "Use align instead.");
|
|
726
|
+
return centerWith(this, axis, to);
|
|
727
|
+
};
|
|
728
|
+
if (proto.center) echo("proto already has .center");
|
|
729
|
+
proto.prototype.center = function center(axis) {
|
|
730
|
+
return centerWith(this, axis || "xyz", unitCube());
|
|
731
|
+
};
|
|
732
|
+
proto.prototype.calcCenter = function centerWith(axis) {
|
|
733
|
+
return calcCenterWith(this, axis || "xyz", unitCube(), 0);
|
|
734
|
+
};
|
|
735
|
+
proto.prototype.align = function align(to, axis) {
|
|
736
|
+
return centerWith(this, axis, to);
|
|
737
|
+
};
|
|
738
|
+
proto.prototype.calcAlign = function calcAlign(to, axis, delta) {
|
|
739
|
+
return calcCenterWith(this, axis, to, delta);
|
|
740
|
+
};
|
|
741
|
+
proto.prototype.enlarge = function enlarge$1(x, y, z) {
|
|
742
|
+
return enlarge(this, x, y, z);
|
|
743
|
+
};
|
|
744
|
+
proto.prototype.fit = function fit$1(x, y, z, a) {
|
|
745
|
+
return fit(this, x, y, z, a);
|
|
746
|
+
};
|
|
747
|
+
if (proto.size) echo("proto already has .size");
|
|
748
|
+
proto.prototype.size = function() {
|
|
749
|
+
return size(this.getBounds());
|
|
750
|
+
};
|
|
751
|
+
proto.prototype.centroid = function() {
|
|
752
|
+
return centroid(this);
|
|
753
|
+
};
|
|
754
|
+
proto.prototype.Zero = function zero$1() {
|
|
755
|
+
return zero(this);
|
|
756
|
+
};
|
|
757
|
+
proto.prototype.Center = function Center(axes) {
|
|
758
|
+
return this.align(unitCube(), axes || "xy");
|
|
759
|
+
};
|
|
760
|
+
proto.Vector2D.prototype.map = function Vector2D_map(cb) {
|
|
761
|
+
return new proto.Vector2D(cb(this.x), cb(this.y));
|
|
762
|
+
};
|
|
763
|
+
proto.prototype.fillet = function fillet$1(radius, orientation, options) {
|
|
764
|
+
return fillet(this, radius, orientation, options);
|
|
765
|
+
};
|
|
766
|
+
proto.prototype.chamfer = function chamfer$1(radius, orientation, options) {
|
|
767
|
+
return chamfer(this, radius, orientation, options);
|
|
768
|
+
};
|
|
769
|
+
proto.prototype.bisect = function bisect$1() {
|
|
770
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
771
|
+
args[_key] = arguments[_key];
|
|
772
|
+
}
|
|
773
|
+
return bisect.apply(util, [ this ].concat(args));
|
|
774
|
+
};
|
|
775
|
+
proto.prototype.slice = function slice$1() {
|
|
776
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
777
|
+
args[_key2] = arguments[_key2];
|
|
778
|
+
}
|
|
779
|
+
return slice.apply(util, [ this ].concat(args));
|
|
780
|
+
};
|
|
781
|
+
proto.prototype.wedge = function wedge$1() {
|
|
782
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
783
|
+
args[_key3] = arguments[_key3];
|
|
784
|
+
}
|
|
785
|
+
return wedge.apply(util, [ this ].concat(args));
|
|
786
|
+
};
|
|
787
|
+
proto.prototype.stretch = function stretch$1(axis, distance, offset) {
|
|
788
|
+
return stretch(this, axis, distance, offset);
|
|
789
|
+
};
|
|
790
|
+
proto.prototype.unionIf = function unionIf(object, condition) {
|
|
791
|
+
return condition ? this.union(result(this, object)) : this;
|
|
792
|
+
};
|
|
793
|
+
proto.prototype.subtractIf = function subtractIf(object, condition) {
|
|
794
|
+
return condition ? this.subtract(result(this, object)) : this;
|
|
795
|
+
};
|
|
796
|
+
proto.prototype._translate = proto.prototype.translate;
|
|
797
|
+
proto.prototype.translate = function translate() {
|
|
798
|
+
if (arguments.length === 1) {
|
|
799
|
+
return this._translate(arguments[0]);
|
|
800
|
+
} else {
|
|
801
|
+
var t = Array.prototype.slice.call(arguments, 0).reduce(function(result, arg) {
|
|
802
|
+
result = undefined(result, arg);
|
|
803
|
+
return result;
|
|
804
|
+
}, [ 0, 0, 0 ]);
|
|
805
|
+
return this._translate(t);
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
proto.prototype.addConnector = function addConnector$1(name, point, axis, normal) {
|
|
809
|
+
return addConnector(this, name, point, axis, normal);
|
|
810
|
+
};
|
|
811
|
+
proto.prototype.connect = function connectTo(myConnectorName, otherConnector) {
|
|
812
|
+
var mirror = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
813
|
+
var normalrotation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
814
|
+
var myConnector = myConnectorName.split(".").reduce(function(a, v) {
|
|
815
|
+
return a[v];
|
|
816
|
+
}, this.properties);
|
|
817
|
+
if (!myConnector) {
|
|
818
|
+
error("The connector '".concat(myConnectorName, "' does not exist on the object [").concat(Object.keys(this.properties).join(","), "]"), "Missing connector property");
|
|
819
|
+
}
|
|
820
|
+
return this.connectTo(myConnector, otherConnector, mirror, normalrotation);
|
|
821
|
+
};
|
|
822
|
+
proto.prototype._jscadutilsinit = true;
|
|
823
|
+
}
|
|
824
|
+
var init$1 = Object.freeze({
|
|
825
|
+
__proto__: null,
|
|
826
|
+
default: init
|
|
827
|
+
});
|
|
828
|
+
var CSG = jsCadCSG__default["default"].CSG, CAG = jsCadCSG__default["default"].CAG;
|
|
829
|
+
var rectangular_extrude = scadApi__default["default"].extrusions.rectangular_extrude;
|
|
830
|
+
var _scadApi$text = scadApi__default["default"].text, vector_text = _scadApi$text.vector_text, vector_char = _scadApi$text.vector_char;
|
|
831
|
+
var union = scadApi__default["default"].booleanOps.union;
|
|
832
|
+
init(CSG);
|
|
833
|
+
var debug$3 = Debug("jscadUtils:group");
|
|
834
|
+
function JsCadUtilsGroup() {
|
|
835
|
+
var names = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
836
|
+
var parts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
837
|
+
var holes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
838
|
+
this.name = "";
|
|
839
|
+
this.names = names;
|
|
840
|
+
this.parts = parts;
|
|
841
|
+
this.holes = holes;
|
|
842
|
+
}
|
|
843
|
+
JsCadUtilsGroup.prototype.add = function(object, name, hidden, subparts, parts) {
|
|
844
|
+
debug$3("add", object, name, hidden, subparts, parts);
|
|
845
|
+
var self = this;
|
|
846
|
+
if (object.parts) {
|
|
847
|
+
if (name) {
|
|
848
|
+
if (!hidden) self.names.push(name);
|
|
849
|
+
self.parts[name] = object.combine(parts);
|
|
850
|
+
if (subparts) {
|
|
851
|
+
Object.keys(object.parts).forEach(function(key) {
|
|
852
|
+
self.parts[subparts + key] = object.parts[key];
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
} else {
|
|
856
|
+
Object.assign(self.parts, object.parts);
|
|
857
|
+
if (!hidden) self.names = self.names.concat(object.names);
|
|
858
|
+
}
|
|
859
|
+
} else {
|
|
860
|
+
if (!hidden) self.names.push(name);
|
|
861
|
+
self.parts[name] = object;
|
|
862
|
+
}
|
|
863
|
+
return self;
|
|
864
|
+
};
|
|
865
|
+
JsCadUtilsGroup.prototype.combine = function(pieces) {
|
|
866
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
867
|
+
var map = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function(x) {
|
|
868
|
+
return x;
|
|
869
|
+
};
|
|
870
|
+
try {
|
|
871
|
+
var self = this;
|
|
872
|
+
options = Object.assign({
|
|
873
|
+
noholes: false
|
|
874
|
+
}, options);
|
|
875
|
+
pieces = pieces ? pieces.split(",") : self.names;
|
|
876
|
+
if (pieces.length === 0) {
|
|
877
|
+
throw new Error("no pieces found in ".concat(self.name, " pieces: ").concat(pieces, " parts: ").concat(Object.keys(self.parts), " names: ").concat(self.names));
|
|
878
|
+
}
|
|
879
|
+
debug$3("combine", self.names, self.parts);
|
|
880
|
+
var g = union(mapPick(self.parts, pieces, function(value, key, index, object) {
|
|
881
|
+
debug$3("combine mapPick", value, key, object);
|
|
882
|
+
return map ? map(value, key, index, object) : identity(value);
|
|
883
|
+
}, self.name));
|
|
884
|
+
return g.subtractIf(self.holes && Array.isArray(self.holes) ? union(self.holes) : self.holes, self.holes && !options.noholes);
|
|
885
|
+
} catch (err) {
|
|
886
|
+
debug$3("combine error", this, pieces, options, err);
|
|
887
|
+
throw error('group::combine error "'.concat(err.message || err.toString(), '"\nthis: ').concat(this, '\npieces: "').concat(pieces, '"\noptions: ').concat(JSON.stringify(options, null, 2), "\nstack: ").concat(err.stack, "\n"), "JSCAD_UTILS_GROUP_ERROR");
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
JsCadUtilsGroup.prototype.map = function(cb) {
|
|
891
|
+
var self = this;
|
|
892
|
+
self.parts = Object.keys(self.parts).filter(function(k) {
|
|
893
|
+
return k !== "holes";
|
|
894
|
+
}).reduce(function(result, key) {
|
|
895
|
+
result[key] = cb(self.parts[key], key);
|
|
896
|
+
return result;
|
|
897
|
+
}, {});
|
|
898
|
+
if (self.holes) {
|
|
899
|
+
if (Array.isArray(self.holes)) {
|
|
900
|
+
self.holes = self.holes.map(function(hole, idx) {
|
|
901
|
+
return cb(hole, idx);
|
|
902
|
+
});
|
|
903
|
+
} else {
|
|
904
|
+
self.holes = cb(self.holes, "holes");
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
return self;
|
|
908
|
+
};
|
|
909
|
+
JsCadUtilsGroup.prototype.clone = function(name, map) {
|
|
910
|
+
debug$3("clone", name, _typeof(name), map);
|
|
911
|
+
var self = this;
|
|
912
|
+
if (typeof name == "function") {
|
|
913
|
+
map = name;
|
|
914
|
+
name = undefined;
|
|
915
|
+
}
|
|
916
|
+
if (!map) map = identity;
|
|
917
|
+
var group = Group(name);
|
|
918
|
+
Object.keys(self.parts).forEach(function(key) {
|
|
919
|
+
var part = self.parts[key];
|
|
920
|
+
var hidden = self.names.indexOf(key) == -1;
|
|
921
|
+
group.add(map(clone(part)), key, hidden);
|
|
922
|
+
});
|
|
923
|
+
if (self.holes) {
|
|
924
|
+
group.holes = toArray(self.holes).map(function(part) {
|
|
925
|
+
return map(CSG.fromPolygons(part.toPolygons()), "holes");
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
return group;
|
|
929
|
+
};
|
|
930
|
+
JsCadUtilsGroup.prototype.rotate = function(solid, axis, angle) {
|
|
931
|
+
var self = this;
|
|
932
|
+
var axes = {
|
|
933
|
+
x: [ 1, 0, 0 ],
|
|
934
|
+
y: [ 0, 1, 0 ],
|
|
935
|
+
z: [ 0, 0, 1 ]
|
|
936
|
+
};
|
|
937
|
+
if (typeof solid === "string") {
|
|
938
|
+
var _names = solid;
|
|
939
|
+
solid = self.combine(_names);
|
|
940
|
+
}
|
|
941
|
+
var rotationCenter = solid.centroid();
|
|
942
|
+
var rotationAxis = axes[axis];
|
|
943
|
+
self.map(function(part) {
|
|
944
|
+
return part.rotate(rotationCenter, rotationAxis, angle);
|
|
945
|
+
});
|
|
946
|
+
return self;
|
|
947
|
+
};
|
|
948
|
+
JsCadUtilsGroup.prototype.combineAll = function(options, map) {
|
|
949
|
+
var self = this;
|
|
950
|
+
return self.combine(Object.keys(self.parts).join(","), options, map);
|
|
951
|
+
};
|
|
952
|
+
JsCadUtilsGroup.prototype.snap = function snap(part, to, axis, orientation, delta) {
|
|
953
|
+
try {
|
|
954
|
+
var self = this;
|
|
955
|
+
var t = calcSnap(self.combine(part), to, axis, orientation, delta);
|
|
956
|
+
self.map(function(part) {
|
|
957
|
+
return part.translate(t);
|
|
958
|
+
});
|
|
959
|
+
return self;
|
|
960
|
+
} catch (err) {
|
|
961
|
+
debug$3("snap error", this, part, to, axis, delta, err);
|
|
962
|
+
throw error('group::snap error "'.concat(err.message || err.toString(), '"\nthis: ').concat(this, '\npart: "').concat(part, '"\nto: ').concat(to, '\naxis: "').concat(axis, '"\norientation: "').concat(orientation, '"\ndelta: "').concat(delta, '"\nstack: ').concat(err.stack, "\n"), "JSCAD_UTILS_GROUP_ERROR");
|
|
963
|
+
}
|
|
964
|
+
};
|
|
965
|
+
JsCadUtilsGroup.prototype.align = function align(part, to, axis, delta) {
|
|
966
|
+
try {
|
|
967
|
+
var self = this;
|
|
968
|
+
var t = calcCenterWith(self.combine(part, {
|
|
969
|
+
noholes: true
|
|
970
|
+
}), axis, to, delta);
|
|
971
|
+
self.map(function(part) {
|
|
972
|
+
return part.translate(t);
|
|
973
|
+
});
|
|
974
|
+
return self;
|
|
975
|
+
} catch (err) {
|
|
976
|
+
debug$3("align error", this, part, to, axis, delta, err);
|
|
977
|
+
throw error('group::align error "'.concat(err.message || err.toString(), '"\nthis: ').concat(this, '\npart: "').concat(part, '"\nto: ').concat(to, '\naxis: "').concat(axis, '"\ndelta: "').concat(delta, '"\nstack: ').concat(err.stack, "\n"), "JSCAD_UTILS_GROUP_ERROR");
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
JsCadUtilsGroup.prototype.center = function center(part) {
|
|
981
|
+
var self = this;
|
|
982
|
+
return self.align(part, unitCube(), "xyz");
|
|
983
|
+
};
|
|
984
|
+
JsCadUtilsGroup.prototype.zero = function zero(part) {
|
|
985
|
+
var self = this;
|
|
986
|
+
var bounds = self.parts[part].getBounds();
|
|
987
|
+
return self.translate([ 0, 0, -bounds[0].z ]);
|
|
988
|
+
};
|
|
989
|
+
JsCadUtilsGroup.prototype.connectTo = function connectTo(partName, connectorName, to, toConnectorName) {
|
|
990
|
+
var mirror = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
991
|
+
var normalrotation = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
|
|
992
|
+
debug$3("connectTo", {
|
|
993
|
+
partName,
|
|
994
|
+
connectorName,
|
|
995
|
+
to,
|
|
996
|
+
toConnectorName,
|
|
997
|
+
mirror,
|
|
998
|
+
normalrotation
|
|
999
|
+
});
|
|
1000
|
+
var self = this;
|
|
1001
|
+
var myConnector = connectorName.split(".").reduce(function(a, v) {
|
|
1002
|
+
return a[v];
|
|
1003
|
+
}, self.parts[partName].properties);
|
|
1004
|
+
debug$3("toConnector", to instanceof CSG.Connector);
|
|
1005
|
+
var toConnector = toConnectorName.split(".").reduce(function(a, v) {
|
|
1006
|
+
return a[v];
|
|
1007
|
+
}, to.properties);
|
|
1008
|
+
var matrix = myConnector.getTransformationTo(toConnector, mirror, normalrotation);
|
|
1009
|
+
debug$3("connectTo", matrix);
|
|
1010
|
+
self.map(function(part) {
|
|
1011
|
+
return part.transform(matrix);
|
|
1012
|
+
});
|
|
1013
|
+
return self;
|
|
1014
|
+
};
|
|
1015
|
+
JsCadUtilsGroup.prototype.midlineTo = function midlineTo(part, axis, to) {
|
|
1016
|
+
var self = this;
|
|
1017
|
+
var size = self.combine(part).size();
|
|
1018
|
+
var t = axisApply(axis, function(i, a) {
|
|
1019
|
+
return to - size[a] / 2;
|
|
1020
|
+
});
|
|
1021
|
+
self.map(function(part) {
|
|
1022
|
+
return part.translate(t);
|
|
1023
|
+
});
|
|
1024
|
+
return self;
|
|
1025
|
+
};
|
|
1026
|
+
JsCadUtilsGroup.prototype.translate = function translate(x, y, z) {
|
|
1027
|
+
var self = this;
|
|
1028
|
+
var t = Array.isArray(x) ? x : [ x, y, z ];
|
|
1029
|
+
debug$3("translate", t);
|
|
1030
|
+
self.map(function(part) {
|
|
1031
|
+
return part.translate(t);
|
|
1032
|
+
});
|
|
1033
|
+
return self;
|
|
1034
|
+
};
|
|
1035
|
+
JsCadUtilsGroup.prototype.pick = function(parts, map) {
|
|
1036
|
+
var self = this;
|
|
1037
|
+
var p = parts && parts.length > 0 && parts.split(",") || self.names;
|
|
1038
|
+
if (!map) map = identity;
|
|
1039
|
+
var g = Group();
|
|
1040
|
+
p.forEach(function(name) {
|
|
1041
|
+
g.add(map(CSG.fromPolygons(self.parts[name].toPolygons()), name), name);
|
|
1042
|
+
});
|
|
1043
|
+
return g;
|
|
1044
|
+
};
|
|
1045
|
+
JsCadUtilsGroup.prototype.array = function(parts, map) {
|
|
1046
|
+
var _this = this;
|
|
1047
|
+
var self = this;
|
|
1048
|
+
var p = parts && parts.length > 0 && parts.split(",") || self.names;
|
|
1049
|
+
if (!map) map = identity;
|
|
1050
|
+
var a = [];
|
|
1051
|
+
p.forEach(function(name) {
|
|
1052
|
+
if (!self.parts[name]) {
|
|
1053
|
+
debug$3("array error", _this, parts);
|
|
1054
|
+
throw error('group::array error "'.concat(name, '" not found.\nthis: ').concat(_this, '\nparts: "').concat(parts, '"\n'), "JSCAD_UTILS_GROUP_ERROR");
|
|
1055
|
+
}
|
|
1056
|
+
a.push(map(CSG.fromPolygons(self.parts[name].toPolygons()), name));
|
|
1057
|
+
});
|
|
1058
|
+
return a;
|
|
1059
|
+
};
|
|
1060
|
+
JsCadUtilsGroup.prototype.toArray = function(pieces) {
|
|
1061
|
+
var self = this;
|
|
1062
|
+
var piecesArray = pieces ? pieces.split(",") : self.names;
|
|
1063
|
+
return piecesArray.map(function(piece) {
|
|
1064
|
+
if (!self.parts[piece]) console.error("Cannot find ".concat(piece, " in ").concat(self.names));
|
|
1065
|
+
return self.parts[piece];
|
|
1066
|
+
});
|
|
1067
|
+
};
|
|
1068
|
+
JsCadUtilsGroup.prototype.toString = function() {
|
|
1069
|
+
return '{\n name: "'.concat(this.name, '",\n names: "').concat(this.names.join(","), '", \n parts: "').concat(Object.keys(this.parts), '",\n holes: ').concat(Array.isArray(this.holes) ? this.holes.length : this.holes ? 1 : 0, "\n}");
|
|
1070
|
+
};
|
|
1071
|
+
JsCadUtilsGroup.prototype.setName = function(name) {
|
|
1072
|
+
this.name = name;
|
|
1073
|
+
return this;
|
|
1074
|
+
};
|
|
1075
|
+
function Group(objectNames, addObjects) {
|
|
1076
|
+
debug$3("Group", objectNames, addObjects);
|
|
1077
|
+
var self = {
|
|
1078
|
+
name: "",
|
|
1079
|
+
names: [],
|
|
1080
|
+
parts: {}
|
|
1081
|
+
};
|
|
1082
|
+
if (objectNames) {
|
|
1083
|
+
if (addObjects) {
|
|
1084
|
+
var names = objectNames;
|
|
1085
|
+
var objects = addObjects;
|
|
1086
|
+
self.names = names && names.length > 0 && names.split(",") || [];
|
|
1087
|
+
if (Array.isArray(objects)) {
|
|
1088
|
+
self.parts = zipObject(self.names, objects);
|
|
1089
|
+
} else if (objects instanceof CSG) {
|
|
1090
|
+
self.parts = zipObject(self.names, [ objects ]);
|
|
1091
|
+
} else {
|
|
1092
|
+
self.parts = objects || {};
|
|
1093
|
+
}
|
|
1094
|
+
} else {
|
|
1095
|
+
if (typeof objectNames == "string") {
|
|
1096
|
+
self.name = objectNames;
|
|
1097
|
+
} else {
|
|
1098
|
+
var objects = objectNames;
|
|
1099
|
+
self.names = Object.keys(objects).filter(function(k) {
|
|
1100
|
+
return k !== "holes";
|
|
1101
|
+
});
|
|
1102
|
+
self.parts = Object.assign({}, objects);
|
|
1103
|
+
self.holes = objects.holes;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
return new JsCadUtilsGroup(self.names, self.parts, self.holes);
|
|
1108
|
+
}
|
|
1109
|
+
var debug$2 = Debug("jscadUtils:util");
|
|
1110
|
+
var NOZZEL_SIZE = .4;
|
|
1111
|
+
var nearest = {
|
|
1112
|
+
under: function under(desired) {
|
|
1113
|
+
var nozzel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NOZZEL_SIZE;
|
|
1114
|
+
var nozzie = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
1115
|
+
return (Math.floor(desired / nozzel) + nozzie) * nozzel;
|
|
1116
|
+
},
|
|
1117
|
+
over: function over(desired) {
|
|
1118
|
+
var nozzel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NOZZEL_SIZE;
|
|
1119
|
+
var nozzie = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
1120
|
+
return (Math.ceil(desired / nozzel) + nozzie) * nozzel;
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
1123
|
+
function identity(solid) {
|
|
1124
|
+
return solid;
|
|
1125
|
+
}
|
|
1126
|
+
function result(object, f) {
|
|
1127
|
+
if (typeof f === "function") {
|
|
1128
|
+
return f.call(object);
|
|
1129
|
+
} else {
|
|
1130
|
+
return f;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
function defaults(target, defaults) {
|
|
1134
|
+
depreciated("defaults", true, "use Object.assign instead");
|
|
1135
|
+
return Object.assign(defaults, target);
|
|
1136
|
+
}
|
|
1137
|
+
function isEmpty(variable) {
|
|
1138
|
+
return typeof variable === "undefined" || variable === null;
|
|
1139
|
+
}
|
|
1140
|
+
function isNegative(n) {
|
|
1141
|
+
return ((n = +n) || 1 / n) < 0;
|
|
1142
|
+
}
|
|
1143
|
+
function print(msg, o) {
|
|
1144
|
+
debug$2(msg, JSON.stringify(o.getBounds()), JSON.stringify(this.size(o.getBounds())));
|
|
1145
|
+
}
|
|
1146
|
+
function jscadToString(o) {
|
|
1147
|
+
if (_typeof(o) == "object") {
|
|
1148
|
+
if (o.polygons) {
|
|
1149
|
+
return "{\npolygons: ".concat(o.polygons.length, ',\nproperties: "').concat(Object.keys(o.properties), '"\n}\n');
|
|
1150
|
+
}
|
|
1151
|
+
} else {
|
|
1152
|
+
return o.toString();
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
function error(msg, name, error) {
|
|
1156
|
+
if (console && console.error) console.error(msg, error);
|
|
1157
|
+
var err = new Error(msg);
|
|
1158
|
+
err.name = name || "JSCAD_UTILS_ERROR";
|
|
1159
|
+
err._error = error;
|
|
1160
|
+
throw err;
|
|
1161
|
+
}
|
|
1162
|
+
function depreciated(method, error, message) {
|
|
1163
|
+
var msg = method + " is depreciated." + (" " + message || "");
|
|
1164
|
+
if (!error && console && console.error) console[error ? "error" : "warn"](msg);
|
|
1165
|
+
if (error) {
|
|
1166
|
+
var err = new Error(msg);
|
|
1167
|
+
err.name = "JSCAD_UTILS_DEPRECATED";
|
|
1168
|
+
throw err;
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
function inch(x) {
|
|
1172
|
+
return x * 25.4;
|
|
1173
|
+
}
|
|
1174
|
+
function cm(x) {
|
|
1175
|
+
return x / 25.4;
|
|
1176
|
+
}
|
|
1177
|
+
function label(text, x, y, width, height) {
|
|
1178
|
+
var l = vector_text(x || 0, y || 0, text);
|
|
1179
|
+
var o = [];
|
|
1180
|
+
l.forEach(function(pl) {
|
|
1181
|
+
o.push(rectangular_extrude(pl, {
|
|
1182
|
+
w: width || 2,
|
|
1183
|
+
h: height || 2
|
|
1184
|
+
}));
|
|
1185
|
+
});
|
|
1186
|
+
return center(union(o));
|
|
1187
|
+
}
|
|
1188
|
+
function text(text) {
|
|
1189
|
+
var l = vector_char(0, 0, text);
|
|
1190
|
+
var _char = l.segments.reduce(function(result, segment) {
|
|
1191
|
+
var path = new CSG.Path2D(segment);
|
|
1192
|
+
var cag = path.expandToCAG(2);
|
|
1193
|
+
return result ? result.union(cag) : cag;
|
|
1194
|
+
}, undefined);
|
|
1195
|
+
return _char;
|
|
1196
|
+
}
|
|
1197
|
+
function unitCube(length, radius) {
|
|
1198
|
+
radius = radius || .5;
|
|
1199
|
+
return CSG.cube({
|
|
1200
|
+
center: [ 0, 0, 0 ],
|
|
1201
|
+
radius: [ radius, radius, length || .5 ]
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
function unitAxis(length, radius, centroid) {
|
|
1205
|
+
debug$2("unitAxis", length, radius, centroid);
|
|
1206
|
+
centroid = centroid || [ 0, 0, 0 ];
|
|
1207
|
+
var unitaxis = unitCube(length, radius).setColor(1, 0, 0).union([ unitCube(length, radius).rotateY(90).setColor(0, 1, 0), unitCube(length, radius).rotateX(90).setColor(0, 0, 1) ]);
|
|
1208
|
+
unitaxis.properties.origin = new CSG.Connector([ 0, 0, 0 ], [ 1, 0, 0 ], [ 0, 1, 0 ]);
|
|
1209
|
+
return unitaxis.translate(centroid);
|
|
1210
|
+
}
|
|
1211
|
+
function toArray(a) {
|
|
1212
|
+
return Array.isArray(a) ? a : [ a ];
|
|
1213
|
+
}
|
|
1214
|
+
function ifArray(a, cb) {
|
|
1215
|
+
return Array.isArray(a) ? a.map(cb) : cb(a);
|
|
1216
|
+
}
|
|
1217
|
+
function segment(object, segments, axis) {
|
|
1218
|
+
var size = object.size()[axis];
|
|
1219
|
+
var width = size / segments;
|
|
1220
|
+
var result = [];
|
|
1221
|
+
for (var i = width; i < size; i += width) {
|
|
1222
|
+
result.push(i);
|
|
1223
|
+
}
|
|
1224
|
+
return result;
|
|
1225
|
+
}
|
|
1226
|
+
function zipObject(names, values) {
|
|
1227
|
+
return names.reduce(function(result, value, idx) {
|
|
1228
|
+
result[value] = values[idx];
|
|
1229
|
+
return result;
|
|
1230
|
+
}, {});
|
|
1231
|
+
}
|
|
1232
|
+
function map(o, f) {
|
|
1233
|
+
return Object.keys(o).map(function(key) {
|
|
1234
|
+
return f(o[key], key, o);
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
function mapValues(o, f) {
|
|
1238
|
+
return Object.keys(o).map(function(key) {
|
|
1239
|
+
return f(o[key], key);
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
function pick(o, names) {
|
|
1243
|
+
return names.reduce(function(result, name) {
|
|
1244
|
+
result[name] = o[name];
|
|
1245
|
+
return result;
|
|
1246
|
+
}, {});
|
|
1247
|
+
}
|
|
1248
|
+
function mapPick(o, names, f, options) {
|
|
1249
|
+
return names.reduce(function(result, name, index) {
|
|
1250
|
+
if (!o[name]) {
|
|
1251
|
+
throw new Error("".concat(name, " not found in ").concat(options.name, ": ").concat(Object.keys(o).join(",")));
|
|
1252
|
+
}
|
|
1253
|
+
result.push(f ? f(o[name], name, index, o) : o[name]);
|
|
1254
|
+
return result;
|
|
1255
|
+
}, []);
|
|
1256
|
+
}
|
|
1257
|
+
function divA(a, f) {
|
|
1258
|
+
return div$1(a, f);
|
|
1259
|
+
}
|
|
1260
|
+
function divxyz(size, x, y, z) {
|
|
1261
|
+
return {
|
|
1262
|
+
x: size.x / x,
|
|
1263
|
+
y: size.y / y,
|
|
1264
|
+
z: size.z / z
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
function div(size, d) {
|
|
1268
|
+
return this.divxyz(size, d, d, d);
|
|
1269
|
+
}
|
|
1270
|
+
function mulxyz(size, x, y, z) {
|
|
1271
|
+
return {
|
|
1272
|
+
x: size.x * x,
|
|
1273
|
+
y: size.y * y,
|
|
1274
|
+
z: size.z * z
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
function mul(size, d) {
|
|
1278
|
+
return this.divxyz(size, d, d, d);
|
|
1279
|
+
}
|
|
1280
|
+
function xyz2array(size) {
|
|
1281
|
+
return [ size.x, size.y, size.z ];
|
|
1282
|
+
}
|
|
1283
|
+
var rotationAxes = {
|
|
1284
|
+
x: [ 1, 0, 0 ],
|
|
1285
|
+
y: [ 0, 1, 0 ],
|
|
1286
|
+
z: [ 0, 0, 1 ]
|
|
1287
|
+
};
|
|
1288
|
+
function size(o) {
|
|
1289
|
+
var bbox = o.getBounds ? o.getBounds() : o;
|
|
1290
|
+
var foo = bbox[1].minus(bbox[0]);
|
|
1291
|
+
return foo;
|
|
1292
|
+
}
|
|
1293
|
+
function scale(size, value) {
|
|
1294
|
+
if (value == 0) return 1;
|
|
1295
|
+
return 1 + 100 / (size / value) / 100;
|
|
1296
|
+
}
|
|
1297
|
+
function center(object, objectSize) {
|
|
1298
|
+
objectSize = objectSize || size(object.getBounds());
|
|
1299
|
+
return centerY(centerX(object, objectSize), objectSize);
|
|
1300
|
+
}
|
|
1301
|
+
function centerY(object, objectSize) {
|
|
1302
|
+
objectSize = objectSize || size(object.getBounds());
|
|
1303
|
+
return object.translate([ 0, -objectSize.y / 2, 0 ]);
|
|
1304
|
+
}
|
|
1305
|
+
function centerX(object, objectSize) {
|
|
1306
|
+
objectSize = objectSize || size(object.getBounds());
|
|
1307
|
+
return object.translate([ -objectSize.x / 2, 0, 0 ]);
|
|
1308
|
+
}
|
|
1309
|
+
function enlarge(object, x, y, z) {
|
|
1310
|
+
var a;
|
|
1311
|
+
if (Array.isArray(x)) {
|
|
1312
|
+
a = x;
|
|
1313
|
+
} else {
|
|
1314
|
+
a = [ x, y || x, z || x ];
|
|
1315
|
+
}
|
|
1316
|
+
var objectSize = size(object);
|
|
1317
|
+
var objectCentroid = centroid(object, objectSize);
|
|
1318
|
+
var idx = 0;
|
|
1319
|
+
var t = map(objectSize, function(i) {
|
|
1320
|
+
return scale(i, a[idx++]);
|
|
1321
|
+
});
|
|
1322
|
+
var new_object = object.scale(t);
|
|
1323
|
+
var new_centroid = centroid(new_object);
|
|
1324
|
+
var delta = new_centroid.minus(objectCentroid).times(-1);
|
|
1325
|
+
return new_object.translate(delta);
|
|
1326
|
+
}
|
|
1327
|
+
function fit(object, x, y, z, keep_aspect_ratio) {
|
|
1328
|
+
var a;
|
|
1329
|
+
if (Array.isArray(x)) {
|
|
1330
|
+
a = x;
|
|
1331
|
+
keep_aspect_ratio = y;
|
|
1332
|
+
x = a[0];
|
|
1333
|
+
y = a[1];
|
|
1334
|
+
z = a[2];
|
|
1335
|
+
} else {
|
|
1336
|
+
a = [ x, y, z ];
|
|
1337
|
+
}
|
|
1338
|
+
var objectSize = size(object.getBounds());
|
|
1339
|
+
function scale(size, value) {
|
|
1340
|
+
if (value == 0) return 1;
|
|
1341
|
+
return value / size;
|
|
1342
|
+
}
|
|
1343
|
+
var s = [ scale(objectSize.x, x), scale(objectSize.y, y), scale(objectSize.z, z) ];
|
|
1344
|
+
var min$1 = min(s);
|
|
1345
|
+
return centerWith(object.scale(s.map(function(d, i) {
|
|
1346
|
+
if (a[i] === 0) return 1;
|
|
1347
|
+
return keep_aspect_ratio ? min$1 : d;
|
|
1348
|
+
})), "xyz", object);
|
|
1349
|
+
}
|
|
1350
|
+
function shift(object, x, y, z) {
|
|
1351
|
+
var hsize = this.div(this.size(object.getBounds()), 2);
|
|
1352
|
+
return object.translate(this.xyz2array(this.mulxyz(hsize, x, y, z)));
|
|
1353
|
+
}
|
|
1354
|
+
function zero(object) {
|
|
1355
|
+
var bounds = object.getBounds();
|
|
1356
|
+
return object.translate([ 0, 0, -bounds[0].z ]);
|
|
1357
|
+
}
|
|
1358
|
+
function mirrored4(x) {
|
|
1359
|
+
return x.union([ x.mirroredY(90), x.mirroredX(90), x.mirroredY(90).mirroredX(90) ]);
|
|
1360
|
+
}
|
|
1361
|
+
var flushSide = {
|
|
1362
|
+
"above-outside": [ 1, 0 ],
|
|
1363
|
+
"above-inside": [ 1, 1 ],
|
|
1364
|
+
"below-outside": [ 0, 1 ],
|
|
1365
|
+
"below-inside": [ 0, 0 ],
|
|
1366
|
+
"outside+": [ 0, 1 ],
|
|
1367
|
+
"outside-": [ 1, 0 ],
|
|
1368
|
+
"inside+": [ 1, 1 ],
|
|
1369
|
+
"inside-": [ 0, 0 ],
|
|
1370
|
+
"center+": [ -1, 1 ],
|
|
1371
|
+
"center-": [ -1, 0 ]
|
|
1372
|
+
};
|
|
1373
|
+
function calcFlush(moveobj, withobj, axes, mside, wside) {
|
|
1374
|
+
depreciated("calcFlush", false, "Use calcSnap instead.");
|
|
1375
|
+
var side;
|
|
1376
|
+
if (mside === 0 || mside === 1) {
|
|
1377
|
+
side = [ wside !== undefined ? wside : mside, mside ];
|
|
1378
|
+
} else {
|
|
1379
|
+
side = flushSide[mside];
|
|
1380
|
+
if (!side) error("invalid side: " + mside);
|
|
1381
|
+
}
|
|
1382
|
+
var m = moveobj.getBounds();
|
|
1383
|
+
var w = withobj.getBounds();
|
|
1384
|
+
if (side[0] === -1) {
|
|
1385
|
+
w[-1] = toxyz(withobj.centroid());
|
|
1386
|
+
}
|
|
1387
|
+
return this.axisApply(axes, function(i, axis) {
|
|
1388
|
+
return w[side[0]][axis] - m[side[1]][axis];
|
|
1389
|
+
});
|
|
1390
|
+
}
|
|
1391
|
+
function calcSnap(moveobj, withobj, axes, orientation) {
|
|
1392
|
+
var delta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
1393
|
+
var side = flushSide[orientation];
|
|
1394
|
+
if (!side) {
|
|
1395
|
+
var fix = {
|
|
1396
|
+
"01": "outside+",
|
|
1397
|
+
10: "outside-",
|
|
1398
|
+
11: "inside+",
|
|
1399
|
+
"00": "inside-",
|
|
1400
|
+
"-11": "center+",
|
|
1401
|
+
"-10": "center-"
|
|
1402
|
+
};
|
|
1403
|
+
error("calcSnap: invalid side: " + orientation + " should be " + fix["" + orientation + delta]);
|
|
1404
|
+
}
|
|
1405
|
+
var m = moveobj.getBounds();
|
|
1406
|
+
var w = withobj.getBounds();
|
|
1407
|
+
if (side[0] === -1) {
|
|
1408
|
+
w[-1] = withobj.centroid();
|
|
1409
|
+
}
|
|
1410
|
+
var t = axisApply(axes, function(i, axis) {
|
|
1411
|
+
return w[side[0]][axis] - m[side[1]][axis];
|
|
1412
|
+
});
|
|
1413
|
+
return delta ? axisApply(axes, function(i) {
|
|
1414
|
+
return t[i] + delta;
|
|
1415
|
+
}) : t;
|
|
1416
|
+
}
|
|
1417
|
+
function snap(moveobj, withobj, axis, orientation, delta) {
|
|
1418
|
+
debug$2("snap", moveobj, withobj, axis, orientation, delta);
|
|
1419
|
+
var t = calcSnap(moveobj, withobj, axis, orientation, delta);
|
|
1420
|
+
return moveobj.translate(t);
|
|
1421
|
+
}
|
|
1422
|
+
function flush(moveobj, withobj, axis, mside, wside) {
|
|
1423
|
+
return moveobj.translate(calcFlush(moveobj, withobj, axis, mside, wside));
|
|
1424
|
+
}
|
|
1425
|
+
function axisApply(axes, valfun, a) {
|
|
1426
|
+
debug$2("axisApply", axes, valfun, a);
|
|
1427
|
+
var retval = a || [ 0, 0, 0 ];
|
|
1428
|
+
var lookup = {
|
|
1429
|
+
x: 0,
|
|
1430
|
+
y: 1,
|
|
1431
|
+
z: 2
|
|
1432
|
+
};
|
|
1433
|
+
axes.split("").forEach(function(axis) {
|
|
1434
|
+
retval[lookup[axis]] = valfun(lookup[axis], axis);
|
|
1435
|
+
});
|
|
1436
|
+
return retval;
|
|
1437
|
+
}
|
|
1438
|
+
function axis2array(axes, valfun) {
|
|
1439
|
+
depreciated("axis2array");
|
|
1440
|
+
var a = [ 0, 0, 0 ];
|
|
1441
|
+
var lookup = {
|
|
1442
|
+
x: 0,
|
|
1443
|
+
y: 1,
|
|
1444
|
+
z: 2
|
|
1445
|
+
};
|
|
1446
|
+
axes.split("").forEach(function(axis) {
|
|
1447
|
+
var i = lookup[axis];
|
|
1448
|
+
a[i] = valfun(i, axis);
|
|
1449
|
+
});
|
|
1450
|
+
return a;
|
|
1451
|
+
}
|
|
1452
|
+
function centroid(o, objectSize) {
|
|
1453
|
+
try {
|
|
1454
|
+
var bounds = o.getBounds();
|
|
1455
|
+
objectSize = objectSize || size(bounds);
|
|
1456
|
+
return bounds[0].plus(objectSize.dividedBy(2));
|
|
1457
|
+
} catch (err) {
|
|
1458
|
+
error("centroid error o:".concat(jscadToString(o), " objectSize: ").concat(objectSize), undefined, err);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
function calcmidlineTo(o, axis, to) {
|
|
1462
|
+
var bounds = o.getBounds();
|
|
1463
|
+
var objectSize = size(bounds);
|
|
1464
|
+
return axisApply(axis, function(i, a) {
|
|
1465
|
+
return to - objectSize[a] / 2;
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1468
|
+
function midlineTo(o, axis, to) {
|
|
1469
|
+
return o.translate(calcmidlineTo(o, axis, to));
|
|
1470
|
+
}
|
|
1471
|
+
function translator(o, axis, withObj) {
|
|
1472
|
+
var objectCentroid = centroid(o);
|
|
1473
|
+
var withCentroid = centroid(withObj);
|
|
1474
|
+
var t = axisApply(axis, function(i) {
|
|
1475
|
+
return withCentroid[i] - objectCentroid[i];
|
|
1476
|
+
});
|
|
1477
|
+
return t;
|
|
1478
|
+
}
|
|
1479
|
+
function calcCenterWith(o, axes, withObj) {
|
|
1480
|
+
var delta = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
1481
|
+
var objectCentroid = centroid(o);
|
|
1482
|
+
var withCentroid = centroid(withObj);
|
|
1483
|
+
var t = axisApply(axes, function(i, axis) {
|
|
1484
|
+
return withCentroid[axis] - objectCentroid[axis];
|
|
1485
|
+
});
|
|
1486
|
+
return delta ? add(t, delta) : t;
|
|
1487
|
+
}
|
|
1488
|
+
function centerWith(o, axis, withObj) {
|
|
1489
|
+
return o.translate(calcCenterWith(o, axis, withObj));
|
|
1490
|
+
}
|
|
1491
|
+
function getDelta(size, bounds, axis, offset, nonzero) {
|
|
1492
|
+
if (!isEmpty(offset) && nonzero) {
|
|
1493
|
+
if (Math.abs(offset) < 1e-4) {
|
|
1494
|
+
offset = 1e-4 * (isNegative(offset) ? -1 : 1);
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
var dist = isNegative(offset) ? offset = size[axis] + offset : offset;
|
|
1498
|
+
return axisApply(axis, function(i, a) {
|
|
1499
|
+
return bounds[0][a] + (isEmpty(dist) ? size[axis] / 2 : dist);
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
function bisect() {
|
|
1503
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1504
|
+
args[_key] = arguments[_key];
|
|
1505
|
+
}
|
|
1506
|
+
if (args.length < 2) {
|
|
1507
|
+
error("bisect requries an object and an axis", "JSCAD_UTILS_INVALID_ARGS");
|
|
1508
|
+
}
|
|
1509
|
+
var object = args[0];
|
|
1510
|
+
var axis = args[1];
|
|
1511
|
+
var offset, angle = 0, rotateaxis, rotateoffset, options = {};
|
|
1512
|
+
for (var i = 2; i < args.length; i++) {
|
|
1513
|
+
if (args[i] instanceof Object) {
|
|
1514
|
+
options = args[i];
|
|
1515
|
+
if (options.offset) offset = options.offset;
|
|
1516
|
+
if (options.angle) angle = options.angle;
|
|
1517
|
+
if (options.rotateaxis) rotateaxis = options.rotateaxis;
|
|
1518
|
+
if (options.rotateoffset) rotateoffset = options.rotateoffset;
|
|
1519
|
+
} else {
|
|
1520
|
+
switch (i) {
|
|
1521
|
+
case 2:
|
|
1522
|
+
offset = args[i];
|
|
1523
|
+
break;
|
|
1524
|
+
|
|
1525
|
+
case 3:
|
|
1526
|
+
angle = args[i];
|
|
1527
|
+
break;
|
|
1528
|
+
|
|
1529
|
+
case 4:
|
|
1530
|
+
rotateaxis = args[i];
|
|
1531
|
+
break;
|
|
1532
|
+
|
|
1533
|
+
case 5:
|
|
1534
|
+
rotateoffset = args[i];
|
|
1535
|
+
break;
|
|
1536
|
+
|
|
1537
|
+
case 6:
|
|
1538
|
+
options = args[i];
|
|
1539
|
+
break;
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
options = Object.assign({
|
|
1544
|
+
addRotationCenter: false
|
|
1545
|
+
}, options);
|
|
1546
|
+
angle = angle || 0;
|
|
1547
|
+
var info = normalVector(axis);
|
|
1548
|
+
var bounds = object.getBounds();
|
|
1549
|
+
var objectSize = size(object);
|
|
1550
|
+
rotateaxis = rotateaxis || {
|
|
1551
|
+
x: "y",
|
|
1552
|
+
y: "x",
|
|
1553
|
+
z: "x"
|
|
1554
|
+
}[axis];
|
|
1555
|
+
var cutDelta = options.cutDelta || getDelta(objectSize, bounds, axis, offset);
|
|
1556
|
+
var rotateOffsetAxis = {
|
|
1557
|
+
xy: "z",
|
|
1558
|
+
yz: "x",
|
|
1559
|
+
xz: "y"
|
|
1560
|
+
}[[ axis, rotateaxis ].sort().join("")];
|
|
1561
|
+
var centroid = object.centroid();
|
|
1562
|
+
var rotateDelta = getDelta(objectSize, bounds, rotateOffsetAxis, rotateoffset);
|
|
1563
|
+
var rotationCenter = options.rotationCenter || new CSG.Vector3D(axisApply("xyz", function(i, a) {
|
|
1564
|
+
if (a == axis) return cutDelta[i];
|
|
1565
|
+
if (a == rotateOffsetAxis) return rotateDelta[i];
|
|
1566
|
+
return centroid[a];
|
|
1567
|
+
}));
|
|
1568
|
+
var theRotationAxis = rotationAxes[rotateaxis];
|
|
1569
|
+
var cutplane = CSG.OrthoNormalBasis.GetCartesian(info.orthoNormalCartesian[0], info.orthoNormalCartesian[1]).translate(cutDelta).rotate(rotationCenter, theRotationAxis, angle);
|
|
1570
|
+
debug$2("bisect", debug$2.enabled && {
|
|
1571
|
+
axis,
|
|
1572
|
+
offset,
|
|
1573
|
+
angle,
|
|
1574
|
+
rotateaxis,
|
|
1575
|
+
cutDelta,
|
|
1576
|
+
rotateOffsetAxis,
|
|
1577
|
+
rotationCenter,
|
|
1578
|
+
theRotationAxis,
|
|
1579
|
+
cutplane,
|
|
1580
|
+
options
|
|
1581
|
+
});
|
|
1582
|
+
var g = Group("negative,positive", [ object.cutByPlane(cutplane.plane).color(options.color && "red"), object.cutByPlane(cutplane.plane.flipped()).color(options.color && "blue") ]);
|
|
1583
|
+
if (options.addRotationCenter) g.add(unitAxis(objectSize.length() + 10, .1, rotationCenter), "rotationCenter");
|
|
1584
|
+
return g;
|
|
1585
|
+
}
|
|
1586
|
+
function slice(object) {
|
|
1587
|
+
var angle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 15;
|
|
1588
|
+
var axis = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "x";
|
|
1589
|
+
var rotateaxis = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "z";
|
|
1590
|
+
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
1591
|
+
color: true,
|
|
1592
|
+
addRotationCenter: true
|
|
1593
|
+
};
|
|
1594
|
+
var info = normalVector(axis);
|
|
1595
|
+
var rotationCenter = options.rotationCenter || new CSG.Vector3D(0, 0, 0);
|
|
1596
|
+
var theRotationAxis = rotationAxes[rotateaxis];
|
|
1597
|
+
var cutplane = CSG.OrthoNormalBasis.GetCartesian(info.orthoNormalCartesian[0], info.orthoNormalCartesian[1]).rotate(rotationCenter, theRotationAxis, angle);
|
|
1598
|
+
var g = Group("negative,positive", [ object.cutByPlane(cutplane.plane).color(options.color && "red"), object.cutByPlane(cutplane.plane.flipped()).color(options.color && "blue") ]);
|
|
1599
|
+
if (options.addRotationCenter) {
|
|
1600
|
+
var objectSize = size(object);
|
|
1601
|
+
g.add(unitAxis(objectSize.length() + 10, .1, rotationCenter), "rotationCenter");
|
|
1602
|
+
}
|
|
1603
|
+
return g;
|
|
1604
|
+
}
|
|
1605
|
+
function wedge(object, start, end, axis) {
|
|
1606
|
+
var a = slice(object, start, axis);
|
|
1607
|
+
var b = slice(a.parts.positive, end, axis);
|
|
1608
|
+
return Group({
|
|
1609
|
+
body: b.parts.positive.union(a.parts.negative).color("blue"),
|
|
1610
|
+
wedge: b.parts.negative.color("red")
|
|
1611
|
+
});
|
|
1612
|
+
}
|
|
1613
|
+
function stretch(object, axis, distance, offset) {
|
|
1614
|
+
var normal = {
|
|
1615
|
+
x: [ 1, 0, 0 ],
|
|
1616
|
+
y: [ 0, 1, 0 ],
|
|
1617
|
+
z: [ 0, 0, 1 ]
|
|
1618
|
+
};
|
|
1619
|
+
var bounds = object.getBounds();
|
|
1620
|
+
var objectSize = size(object);
|
|
1621
|
+
var cutDelta = getDelta(objectSize, bounds, axis, offset, true);
|
|
1622
|
+
return object.stretchAtPlane(normal[axis], cutDelta, distance);
|
|
1623
|
+
}
|
|
1624
|
+
function poly2solid(top, bottom, height) {
|
|
1625
|
+
if (top.sides.length == 0) {
|
|
1626
|
+
return new CSG;
|
|
1627
|
+
}
|
|
1628
|
+
var offsetVector = CSG.Vector3D.Create(0, 0, height);
|
|
1629
|
+
var normalVector = CSG.Vector3D.Create(0, 1, 0);
|
|
1630
|
+
var polygons = [];
|
|
1631
|
+
polygons = polygons.concat(bottom._toPlanePolygons({
|
|
1632
|
+
translation: [ 0, 0, 0 ],
|
|
1633
|
+
normalVector,
|
|
1634
|
+
flipped: !(offsetVector.z < 0)
|
|
1635
|
+
}));
|
|
1636
|
+
polygons = polygons.concat(top._toPlanePolygons({
|
|
1637
|
+
translation: offsetVector,
|
|
1638
|
+
normalVector,
|
|
1639
|
+
flipped: offsetVector.z < 0
|
|
1640
|
+
}));
|
|
1641
|
+
var c1 = new CSG.Connector(offsetVector.times(0), [ 0, 0, offsetVector.z ], normalVector);
|
|
1642
|
+
var c2 = new CSG.Connector(offsetVector, [ 0, 0, offsetVector.z ], normalVector);
|
|
1643
|
+
polygons = polygons.concat(bottom._toWallPolygons({
|
|
1644
|
+
cag: top,
|
|
1645
|
+
toConnector1: c1,
|
|
1646
|
+
toConnector2: c2
|
|
1647
|
+
}));
|
|
1648
|
+
return CSG.fromPolygons(polygons);
|
|
1649
|
+
}
|
|
1650
|
+
function slices2poly(slices, options, axis) {
|
|
1651
|
+
debug$2("slices2poly", slices, options, axis);
|
|
1652
|
+
options = Object.assign({
|
|
1653
|
+
twistangle: 0,
|
|
1654
|
+
twiststeps: 0
|
|
1655
|
+
}, options);
|
|
1656
|
+
var twistangle = options && parseFloat(options.twistangle) || 0;
|
|
1657
|
+
options && parseInt(options.twiststeps) || CSG.defaultResolution3D;
|
|
1658
|
+
var normalVector = options.si.normalVector;
|
|
1659
|
+
var polygons = [];
|
|
1660
|
+
var first$1 = first(slices);
|
|
1661
|
+
var last$1 = last(slices);
|
|
1662
|
+
debug$2("slices2poly first", first$1, first$1.offset, "last", last$1);
|
|
1663
|
+
var up = first$1.offset[axis] > last$1.offset[axis];
|
|
1664
|
+
polygons = polygons.concat(first$1.poly._toPlanePolygons({
|
|
1665
|
+
translation: first$1.offset,
|
|
1666
|
+
normalVector,
|
|
1667
|
+
flipped: !up
|
|
1668
|
+
}));
|
|
1669
|
+
var rotateAxis = "rotate" + axis.toUpperCase();
|
|
1670
|
+
polygons = polygons.concat(last$1.poly._toPlanePolygons({
|
|
1671
|
+
translation: last$1.offset,
|
|
1672
|
+
normalVector: normalVector[rotateAxis](twistangle),
|
|
1673
|
+
flipped: up
|
|
1674
|
+
}));
|
|
1675
|
+
var rotate = twistangle === 0 ? function rotateZero(v) {
|
|
1676
|
+
return v;
|
|
1677
|
+
} : function rotate(v, angle, percent) {
|
|
1678
|
+
return v[rotateAxis](angle * percent);
|
|
1679
|
+
};
|
|
1680
|
+
var connectorAxis = last$1.offset.minus(first$1.offset).abs();
|
|
1681
|
+
slices.forEach(function(slice, idx) {
|
|
1682
|
+
if (idx < slices.length - 1) {
|
|
1683
|
+
var nextidx = idx + 1;
|
|
1684
|
+
var top = !up ? slices[nextidx] : slice;
|
|
1685
|
+
var bottom = up ? slices[nextidx] : slice;
|
|
1686
|
+
var c1 = new CSG.Connector(bottom.offset, connectorAxis, rotate(normalVector, twistangle, idx / slices.length));
|
|
1687
|
+
var c2 = new CSG.Connector(top.offset, connectorAxis, rotate(normalVector, twistangle, nextidx / slices.length));
|
|
1688
|
+
polygons = polygons.concat(bottom.poly._toWallPolygons({
|
|
1689
|
+
cag: top.poly,
|
|
1690
|
+
toConnector1: c1,
|
|
1691
|
+
toConnector2: c2
|
|
1692
|
+
}));
|
|
1693
|
+
}
|
|
1694
|
+
});
|
|
1695
|
+
return CSG.fromPolygons(polygons);
|
|
1696
|
+
}
|
|
1697
|
+
function normalVector(axis) {
|
|
1698
|
+
var axisInfo = {
|
|
1699
|
+
z: {
|
|
1700
|
+
orthoNormalCartesian: [ "X", "Y" ],
|
|
1701
|
+
normalVector: CSG.Vector3D.Create(0, 1, 0)
|
|
1702
|
+
},
|
|
1703
|
+
x: {
|
|
1704
|
+
orthoNormalCartesian: [ "Y", "Z" ],
|
|
1705
|
+
normalVector: CSG.Vector3D.Create(0, 0, 1)
|
|
1706
|
+
},
|
|
1707
|
+
y: {
|
|
1708
|
+
orthoNormalCartesian: [ "X", "Z" ],
|
|
1709
|
+
normalVector: CSG.Vector3D.Create(0, 0, 1)
|
|
1710
|
+
}
|
|
1711
|
+
};
|
|
1712
|
+
if (!axisInfo[axis]) error("normalVector: invalid axis " + axis);
|
|
1713
|
+
return axisInfo[axis];
|
|
1714
|
+
}
|
|
1715
|
+
function sliceParams(orientation, radius, bounds) {
|
|
1716
|
+
var axis = orientation[0];
|
|
1717
|
+
var direction = orientation[1];
|
|
1718
|
+
var dirInfo = {
|
|
1719
|
+
"dir+": {
|
|
1720
|
+
sizeIdx: 1,
|
|
1721
|
+
sizeDir: -1,
|
|
1722
|
+
moveDir: -1,
|
|
1723
|
+
positive: true
|
|
1724
|
+
},
|
|
1725
|
+
"dir-": {
|
|
1726
|
+
sizeIdx: 0,
|
|
1727
|
+
sizeDir: 1,
|
|
1728
|
+
moveDir: 0,
|
|
1729
|
+
positive: false
|
|
1730
|
+
}
|
|
1731
|
+
};
|
|
1732
|
+
var info = dirInfo["dir" + direction];
|
|
1733
|
+
return Object.assign({
|
|
1734
|
+
axis,
|
|
1735
|
+
cutDelta: axisApply(axis, function(i, a) {
|
|
1736
|
+
return bounds[info.sizeIdx][a] + Math.abs(radius) * info.sizeDir;
|
|
1737
|
+
}),
|
|
1738
|
+
moveDelta: axisApply(axis, function(i, a) {
|
|
1739
|
+
return bounds[info.sizeIdx][a] + Math.abs(radius) * info.moveDir;
|
|
1740
|
+
})
|
|
1741
|
+
}, info, normalVector(axis));
|
|
1742
|
+
}
|
|
1743
|
+
function reShape(object, radius, orientation, options, slicer) {
|
|
1744
|
+
options = options || {};
|
|
1745
|
+
var b = object.getBounds();
|
|
1746
|
+
var absoluteRadius = Math.abs(radius);
|
|
1747
|
+
var si = sliceParams(orientation, radius, b);
|
|
1748
|
+
debug$2("reShape", absoluteRadius, si);
|
|
1749
|
+
if (si.axis !== "z") throw new Error('reShape error: CAG._toPlanePolytons only uses the "z" axis. You must use the "z" axis for now.');
|
|
1750
|
+
var cutplane = CSG.OrthoNormalBasis.GetCartesian(si.orthoNormalCartesian[0], si.orthoNormalCartesian[1]).translate(si.cutDelta);
|
|
1751
|
+
var slice = object.sectionCut(cutplane);
|
|
1752
|
+
var first = axisApply(si.axis, function() {
|
|
1753
|
+
return si.positive ? 0 : absoluteRadius;
|
|
1754
|
+
});
|
|
1755
|
+
var last = axisApply(si.axis, function() {
|
|
1756
|
+
return si.positive ? absoluteRadius : 0;
|
|
1757
|
+
});
|
|
1758
|
+
var plane = si.positive ? cutplane.plane : cutplane.plane.flipped();
|
|
1759
|
+
debug$2("reShape first/last", first, last);
|
|
1760
|
+
var slices = slicer(first, last, slice, radius);
|
|
1761
|
+
var delta = slices2poly(slices, Object.assign(options, {
|
|
1762
|
+
si
|
|
1763
|
+
}), si.axis).color(options.color);
|
|
1764
|
+
var remainder = object.cutByPlane(plane);
|
|
1765
|
+
return union([ options.unionOriginal ? object : remainder, delta.translate(si.moveDelta) ]);
|
|
1766
|
+
}
|
|
1767
|
+
function chamfer(object, radius, orientation, options) {
|
|
1768
|
+
return reShape(object, radius, orientation, options, function(first, last, slice) {
|
|
1769
|
+
return [ {
|
|
1770
|
+
poly: slice,
|
|
1771
|
+
offset: new CSG.Vector3D(first)
|
|
1772
|
+
}, {
|
|
1773
|
+
poly: enlarge(slice, [ -radius * 2, -radius * 2 ]),
|
|
1774
|
+
offset: new CSG.Vector3D(last)
|
|
1775
|
+
} ];
|
|
1776
|
+
});
|
|
1777
|
+
}
|
|
1778
|
+
function fillet(object, radius, orientation, options) {
|
|
1779
|
+
options = options || {};
|
|
1780
|
+
return reShape(object, radius, orientation, options, function(first, last, slice) {
|
|
1781
|
+
var v1 = new CSG.Vector3D(first);
|
|
1782
|
+
var v2 = new CSG.Vector3D(last);
|
|
1783
|
+
var res = options.resolution || CSG.defaultResolution3D;
|
|
1784
|
+
var slices = range(0, res).map(function(i) {
|
|
1785
|
+
var p = i > 0 ? i / (res - 1) : 0;
|
|
1786
|
+
var v = v1.lerp(v2, p);
|
|
1787
|
+
var size = -radius * 2 - Math.cos(Math.asin(p)) * (-radius * 2);
|
|
1788
|
+
return {
|
|
1789
|
+
poly: enlarge(slice, [ size, size ]),
|
|
1790
|
+
offset: v
|
|
1791
|
+
};
|
|
1792
|
+
});
|
|
1793
|
+
return slices;
|
|
1794
|
+
});
|
|
1795
|
+
}
|
|
1796
|
+
function calcRotate(part, solid, axis) {
|
|
1797
|
+
var axes = {
|
|
1798
|
+
x: [ 1, 0, 0 ],
|
|
1799
|
+
y: [ 0, 1, 0 ],
|
|
1800
|
+
z: [ 0, 0, 1 ]
|
|
1801
|
+
};
|
|
1802
|
+
var rotationCenter = solid.centroid();
|
|
1803
|
+
var rotationAxis = axes[axis];
|
|
1804
|
+
return {
|
|
1805
|
+
rotationCenter,
|
|
1806
|
+
rotationAxis
|
|
1807
|
+
};
|
|
1808
|
+
}
|
|
1809
|
+
function rotateAround(part, solid, axis, angle) {
|
|
1810
|
+
var _calcRotate = calcRotate(part, solid, axis), rotationCenter = _calcRotate.rotationCenter, rotationAxis = _calcRotate.rotationAxis;
|
|
1811
|
+
return part.rotate(rotationCenter, rotationAxis, angle);
|
|
1812
|
+
}
|
|
1813
|
+
function cloneProperties(from, to) {
|
|
1814
|
+
return Object.entries(from).reduce(function(props, _ref) {
|
|
1815
|
+
var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1];
|
|
1816
|
+
props[key] = value;
|
|
1817
|
+
return props;
|
|
1818
|
+
}, to);
|
|
1819
|
+
}
|
|
1820
|
+
function clone(o) {
|
|
1821
|
+
var c = CSG.fromPolygons(o.toPolygons());
|
|
1822
|
+
cloneProperties(o, c);
|
|
1823
|
+
debug$2("clone", o, c, CSG);
|
|
1824
|
+
return c;
|
|
1825
|
+
}
|
|
1826
|
+
function addConnector(object, name) {
|
|
1827
|
+
var point = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [ 0, 0, 0 ];
|
|
1828
|
+
var axis = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [ 1, 0, 0 ];
|
|
1829
|
+
var normal = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [ 0, 0, 1 ];
|
|
1830
|
+
object.properties[name] = new CSG.Connector(point, axis, normal);
|
|
1831
|
+
return object;
|
|
1832
|
+
}
|
|
1833
|
+
var debug$1 = Debug("jscadUtils:parts");
|
|
1834
|
+
var parts = {
|
|
1835
|
+
BBox: BBox$1,
|
|
1836
|
+
Cube,
|
|
1837
|
+
RoundedCube,
|
|
1838
|
+
Cylinder,
|
|
1839
|
+
Cone
|
|
1840
|
+
};
|
|
1841
|
+
function BBox$1() {
|
|
1842
|
+
function box(object) {
|
|
1843
|
+
return CSG.cube({
|
|
1844
|
+
center: object.centroid(),
|
|
1845
|
+
radius: object.size().dividedBy(2)
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1848
|
+
for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1849
|
+
objects[_key] = arguments[_key];
|
|
1850
|
+
}
|
|
1851
|
+
return objects.reduce(function(bbox, part) {
|
|
1852
|
+
var object = bbox ? union([ bbox, box(part) ]) : part;
|
|
1853
|
+
return box(object);
|
|
1854
|
+
}, undefined);
|
|
1855
|
+
}
|
|
1856
|
+
function Cube(width) {
|
|
1857
|
+
var r = div$1(fromxyz(width), 2);
|
|
1858
|
+
return CSG.cube({
|
|
1859
|
+
center: r,
|
|
1860
|
+
radius: r
|
|
1861
|
+
});
|
|
1862
|
+
}
|
|
1863
|
+
function RoundedCube(x, y, thickness, corner_radius) {
|
|
1864
|
+
if (x.getBounds) {
|
|
1865
|
+
var size$1 = size(x.getBounds());
|
|
1866
|
+
var r = [ size$1.x / 2, size$1.y / 2 ];
|
|
1867
|
+
thickness = size$1.z;
|
|
1868
|
+
corner_radius = y;
|
|
1869
|
+
} else {
|
|
1870
|
+
var r = [ x / 2, y / 2 ];
|
|
1871
|
+
}
|
|
1872
|
+
debug$1("RoundedCube", size$1, r, thickness, corner_radius);
|
|
1873
|
+
var roundedcube = CAG.roundedRectangle({
|
|
1874
|
+
center: [ r[0], r[1], 0 ],
|
|
1875
|
+
radius: r,
|
|
1876
|
+
roundradius: corner_radius,
|
|
1877
|
+
resolution: CSG.defaultResolution2D
|
|
1878
|
+
}).extrude({
|
|
1879
|
+
offset: [ 0, 0, thickness || 1.62 ]
|
|
1880
|
+
});
|
|
1881
|
+
return roundedcube;
|
|
1882
|
+
}
|
|
1883
|
+
function Cylinder(diameter, height) {
|
|
1884
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1885
|
+
debug$1("parts.Cylinder", diameter, height, options);
|
|
1886
|
+
options = Object.assign({
|
|
1887
|
+
start: [ 0, 0, 0 ],
|
|
1888
|
+
end: [ 0, 0, height ],
|
|
1889
|
+
radius: diameter / 2,
|
|
1890
|
+
resolution: CSG.defaultResolution2D
|
|
1891
|
+
}, options);
|
|
1892
|
+
return CSG.cylinder(options);
|
|
1893
|
+
}
|
|
1894
|
+
function Cone(diameter1, diameter2, height) {
|
|
1895
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1896
|
+
debug$1("parts.Cone", diameter1, diameter2, height, options);
|
|
1897
|
+
return CSG.cylinder(Object.assign({
|
|
1898
|
+
start: [ 0, 0, 0 ],
|
|
1899
|
+
end: [ 0, 0, height ],
|
|
1900
|
+
radiusStart: diameter1 / 2,
|
|
1901
|
+
radiusEnd: diameter2 / 2,
|
|
1902
|
+
resolution: CSG.defaultResolution2D
|
|
1903
|
+
}, options));
|
|
1904
|
+
}
|
|
1905
|
+
function Hexagon(diameter, height) {
|
|
1906
|
+
debug$1("hexagon", diameter, height);
|
|
1907
|
+
var radius = diameter / 2;
|
|
1908
|
+
var sqrt3 = Math.sqrt(3) / 2;
|
|
1909
|
+
var hex = CAG.fromPoints([ [ radius, 0 ], [ radius / 2, radius * sqrt3 ], [ -radius / 2, radius * sqrt3 ], [ -radius, 0 ], [ -radius / 2, -radius * sqrt3 ], [ radius / 2, -radius * sqrt3 ] ]);
|
|
1910
|
+
return hex.extrude({
|
|
1911
|
+
offset: [ 0, 0, height ]
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
function Triangle(base, height) {
|
|
1915
|
+
var radius = base / 2;
|
|
1916
|
+
var tri = CAG.fromPoints([ [ -radius, 0 ], [ radius, 0 ], [ 0, Math.sin(30) * radius ] ]);
|
|
1917
|
+
return tri.extrude({
|
|
1918
|
+
offset: [ 0, 0, height ]
|
|
1919
|
+
});
|
|
1920
|
+
}
|
|
1921
|
+
function Tube(outsideDiameter, insideDiameter, height, outsideOptions, insideOptions) {
|
|
1922
|
+
return Cylinder(outsideDiameter, height, outsideOptions).subtract(Cylinder(insideDiameter, height, insideOptions || outsideOptions));
|
|
1923
|
+
}
|
|
1924
|
+
function Anchor() {
|
|
1925
|
+
var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
1926
|
+
var height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
1927
|
+
var hole = Cylinder(width, height).Center().color("red");
|
|
1928
|
+
var post = Cylinder(height / 2, width * .66).rotateX(90).align(hole, "xz").snap(hole, "y", "inside-").translate([ 0, 0, -height / 6 ]).color("purple");
|
|
1929
|
+
return Group({
|
|
1930
|
+
post,
|
|
1931
|
+
hole
|
|
1932
|
+
});
|
|
1933
|
+
}
|
|
1934
|
+
function Board(width, height, corner_radius, thickness) {
|
|
1935
|
+
var r = divA([ width, height ], 2);
|
|
1936
|
+
var board = CAG.roundedRectangle({
|
|
1937
|
+
center: [ r[0], r[1], 0 ],
|
|
1938
|
+
radius: r,
|
|
1939
|
+
roundradius: corner_radius,
|
|
1940
|
+
resolution: CSG.defaultResolution2D
|
|
1941
|
+
}).extrude({
|
|
1942
|
+
offset: [ 0, 0, thickness || 1.62 ]
|
|
1943
|
+
});
|
|
1944
|
+
return board;
|
|
1945
|
+
}
|
|
1946
|
+
var Hardware = {
|
|
1947
|
+
Orientation: {
|
|
1948
|
+
up: {
|
|
1949
|
+
head: "outside-",
|
|
1950
|
+
clear: "inside+"
|
|
1951
|
+
},
|
|
1952
|
+
down: {
|
|
1953
|
+
head: "outside+",
|
|
1954
|
+
clear: "inside-"
|
|
1955
|
+
}
|
|
1956
|
+
},
|
|
1957
|
+
Screw: function Screw(head, thread, headClearSpace, options) {
|
|
1958
|
+
depreciated("Screw", false, "Use the jscad-hardware screw methods instead");
|
|
1959
|
+
options = Object.assign(options, {
|
|
1960
|
+
orientation: "up",
|
|
1961
|
+
clearance: [ 0, 0, 0 ]
|
|
1962
|
+
});
|
|
1963
|
+
var orientation = Hardware.Orientation[options.orientation];
|
|
1964
|
+
var group = Group("head,thread", {
|
|
1965
|
+
head: head.color("gray"),
|
|
1966
|
+
thread: thread.snap(head, "z", orientation.head).color("silver")
|
|
1967
|
+
});
|
|
1968
|
+
if (headClearSpace) {
|
|
1969
|
+
group.add(headClearSpace.enlarge(options.clearance).snap(head, "z", orientation.clear).color("red"), "headClearSpace", true);
|
|
1970
|
+
}
|
|
1971
|
+
return group;
|
|
1972
|
+
},
|
|
1973
|
+
PanHeadScrew: function PanHeadScrew(headDiameter, headLength, diameter, length, clearLength, options) {
|
|
1974
|
+
depreciated("PanHeadScrew", false, "Use the jscad-hardware screw methods instead");
|
|
1975
|
+
var head = Cylinder(headDiameter, headLength);
|
|
1976
|
+
var thread = Cylinder(diameter, length);
|
|
1977
|
+
if (clearLength) {
|
|
1978
|
+
var headClearSpace = Cylinder(headDiameter, clearLength);
|
|
1979
|
+
}
|
|
1980
|
+
return Hardware.Screw(head, thread, headClearSpace, options);
|
|
1981
|
+
},
|
|
1982
|
+
HexHeadScrew: function HexHeadScrew(headDiameter, headLength, diameter, length, clearLength, options) {
|
|
1983
|
+
depreciated("HexHeadScrew", false, "Use the jscad-hardware screw methods instead");
|
|
1984
|
+
var head = Hexagon(headDiameter, headLength);
|
|
1985
|
+
var thread = Cylinder(diameter, length);
|
|
1986
|
+
if (clearLength) {
|
|
1987
|
+
var headClearSpace = Hexagon(headDiameter, clearLength);
|
|
1988
|
+
}
|
|
1989
|
+
return Hardware.Screw(head, thread, headClearSpace, options);
|
|
1990
|
+
},
|
|
1991
|
+
FlatHeadScrew: function FlatHeadScrew(headDiameter, headLength, diameter, length, clearLength, options) {
|
|
1992
|
+
depreciated("FlatHeadScrew", false, "Use the jscad-hardware screw methods instead");
|
|
1993
|
+
var head = Cone(headDiameter, diameter, headLength);
|
|
1994
|
+
var thread = Cylinder(diameter, length);
|
|
1995
|
+
if (clearLength) {
|
|
1996
|
+
var headClearSpace = Cylinder(headDiameter, clearLength);
|
|
1997
|
+
}
|
|
1998
|
+
return Hardware.Screw(head, thread, headClearSpace, options);
|
|
1999
|
+
}
|
|
2000
|
+
};
|
|
2001
|
+
var parts$1 = Object.freeze({
|
|
2002
|
+
__proto__: null,
|
|
2003
|
+
default: parts,
|
|
2004
|
+
BBox: BBox$1,
|
|
2005
|
+
Cube,
|
|
2006
|
+
RoundedCube,
|
|
2007
|
+
Cylinder,
|
|
2008
|
+
Cone,
|
|
2009
|
+
Hexagon,
|
|
2010
|
+
Triangle,
|
|
2011
|
+
Tube,
|
|
2012
|
+
Anchor,
|
|
2013
|
+
Board,
|
|
2014
|
+
Hardware
|
|
2015
|
+
});
|
|
2016
|
+
var debug = Debug("jscadUtils:boxes");
|
|
2017
|
+
function RabbetJoin(box, thickness, cutHeight) {
|
|
2018
|
+
depreciated("RabbetJoin", true, "Use 'Rabbet' instead");
|
|
2019
|
+
return rabbetJoin(box, thickness, cutHeight);
|
|
2020
|
+
}
|
|
2021
|
+
function topMiddleBottom(box, thickness) {
|
|
2022
|
+
debug("TopMiddleBottom", box, thickness);
|
|
2023
|
+
var bottom = box.bisect("z", thickness, {
|
|
2024
|
+
color: true
|
|
2025
|
+
});
|
|
2026
|
+
var top = bottom.parts.positive.bisect("z", -thickness);
|
|
2027
|
+
return Group("top,middle,bottom", [ top.parts.positive, top.parts.negative.color("green"), bottom.parts.negative ]);
|
|
2028
|
+
}
|
|
2029
|
+
function Rabett(box, thickness, gap, height, face) {
|
|
2030
|
+
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
2031
|
+
debug("Rabett", "thickness", thickness, "gap", gap, "height", height, "face", face);
|
|
2032
|
+
gap = gap || .25;
|
|
2033
|
+
var inside = thickness - gap;
|
|
2034
|
+
var outside = -thickness + gap;
|
|
2035
|
+
debug("inside", inside, "outside", outside);
|
|
2036
|
+
var group = Group();
|
|
2037
|
+
var _box$bisect$parts = box.bisect("z", height, options).parts, top = _box$bisect$parts.positive, lower2_3rd = _box$bisect$parts.negative;
|
|
2038
|
+
var lowerBisectHeight = Math.sign(height) < 0 ? face * Math.sign(height) : height - face;
|
|
2039
|
+
var _lower2_3rd$bisect$pa = lower2_3rd.bisect("z", lowerBisectHeight, options).parts, middle = _lower2_3rd$bisect$pa.positive, bottom = _lower2_3rd$bisect$pa.negative;
|
|
2040
|
+
var middleTop = middle.color("yellow").subtract(middle.color("darkred").enlarge([ outside, outside, 0 ]));
|
|
2041
|
+
group.add(top.union(middleTop), "top");
|
|
2042
|
+
var bottomOutline = middle.color("yellow").subtract(middle.color("orange").enlarge([ outside, outside, 0 ])).enlarge([ outside, outside, 0 ]);
|
|
2043
|
+
group.add(bottomOutline, "middle-top", true);
|
|
2044
|
+
group.add(middle.color("green").subtract(middle.color("pink").enlarge([ inside, inside, 0 ])), "middle-bottom", true);
|
|
2045
|
+
group.add(bottom.color("orange").union(middle.color("green").subtract(middle.color("red").enlarge([ inside, inside, 0 ])).subtract(middleTop)), "bottom");
|
|
2046
|
+
return group;
|
|
2047
|
+
}
|
|
2048
|
+
var RabettTopBottom = function rabbetTMB(box, thickness) {
|
|
2049
|
+
var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : .25;
|
|
2050
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
2051
|
+
options = Object.assign({
|
|
2052
|
+
removableTop: true,
|
|
2053
|
+
removableBottom: true,
|
|
2054
|
+
topWidth: -thickness,
|
|
2055
|
+
bottomWidth: thickness
|
|
2056
|
+
}, options);
|
|
2057
|
+
debug("RabettTopBottom", box, thickness, gap, options);
|
|
2058
|
+
var group = Group("", {
|
|
2059
|
+
box
|
|
2060
|
+
});
|
|
2061
|
+
var inside = -thickness - gap;
|
|
2062
|
+
var outside = -thickness + gap;
|
|
2063
|
+
if (options.removableTop) {
|
|
2064
|
+
var top = box.bisect("z", options.topWidth, {
|
|
2065
|
+
color: true
|
|
2066
|
+
});
|
|
2067
|
+
group.add(top.parts.positive.enlarge([ inside, inside, 0 ]), "top");
|
|
2068
|
+
if (!options.removableBottom) group.add(box.subtract(top.parts.positive.enlarge([ outside, outside, 0 ])), "bottom");
|
|
2069
|
+
}
|
|
2070
|
+
if (options.removableBottom) {
|
|
2071
|
+
var bottom = box.bisect("z", options.bottomWidth, {
|
|
2072
|
+
color: true
|
|
2073
|
+
});
|
|
2074
|
+
group.add(bottom.parts.negative.enlarge([ outside, outside, 0 ]), "bottomCutout", true);
|
|
2075
|
+
group.add(bottom.parts.negative.enlarge([ inside, inside, 0 ]), "bottom");
|
|
2076
|
+
if (!options.removableTop) group.add(box.subtract(group.parts.bottomCutout), "top");
|
|
2077
|
+
}
|
|
2078
|
+
if (options.removableBottom && options.removableTop) {
|
|
2079
|
+
group.add(box.subtract(union([ bottom.parts.negative.enlarge([ outside, outside, 0 ]), top.parts.positive.enlarge([ outside, outside, 0 ]) ])), "middle");
|
|
2080
|
+
}
|
|
2081
|
+
return group;
|
|
2082
|
+
};
|
|
2083
|
+
var CutOut = function cutOut(o, h, box, plug, gap) {
|
|
2084
|
+
gap = gap || .25;
|
|
2085
|
+
var s = o.size();
|
|
2086
|
+
var cutout = o.intersect(box);
|
|
2087
|
+
var cs = o.size();
|
|
2088
|
+
var clear = Parts.Cube([ s.x, s.y, h ]).align(o, "xy").color("yellow");
|
|
2089
|
+
var top = clear.snap(o, "z", "center+").union(o);
|
|
2090
|
+
var back = Parts.Cube([ cs.x + 6, 2, cs.z + 2.5 ]).align(cutout, "x").snap(cutout, "z", "center+").snap(cutout, "y", "outside-");
|
|
2091
|
+
var clip = Parts.Cube([ cs.x + 2 - gap, 1 - gap, cs.z + 2.5 ]).align(cutout, "x").snap(cutout, "z", "center+").snap(cutout, "y", "outside-");
|
|
2092
|
+
return Group("insert", {
|
|
2093
|
+
top,
|
|
2094
|
+
bottom: clear.snap(o, "z", "center-").union(o),
|
|
2095
|
+
cutout: union([ o, top ]),
|
|
2096
|
+
back: back.subtract(plug).subtract(clip.enlarge(gap, gap, gap)).subtract(clear.translate([ 0, 5, 0 ])),
|
|
2097
|
+
clip: clip.subtract(plug).color("red"),
|
|
2098
|
+
insert: union([ o, top ]).intersect(box).subtract(o).enlarge([ -gap, 0, 0 ]).union(clip.subtract(plug).enlarge(-gap, -gap, 0)).color("blue")
|
|
2099
|
+
});
|
|
2100
|
+
};
|
|
2101
|
+
var Rectangle = function Rectangle(size, thickness, cb) {
|
|
2102
|
+
thickness = thickness || 2;
|
|
2103
|
+
var s = div$1(xyz2array(size), 2);
|
|
2104
|
+
var r = add(s, thickness);
|
|
2105
|
+
var box = CSG.cube({
|
|
2106
|
+
center: r,
|
|
2107
|
+
radius: r
|
|
2108
|
+
}).subtract(CSG.cube({
|
|
2109
|
+
center: r,
|
|
2110
|
+
radius: s
|
|
2111
|
+
}));
|
|
2112
|
+
if (cb) box = cb(box);
|
|
2113
|
+
return box;
|
|
2114
|
+
};
|
|
2115
|
+
var Hollow = function Hollow(object, thickness, interiorcb, exteriorcb) {
|
|
2116
|
+
thickness = thickness || 2;
|
|
2117
|
+
var size = -thickness * 2;
|
|
2118
|
+
interiorcb = interiorcb || identity;
|
|
2119
|
+
var box = object.subtract(interiorcb(object.enlarge([ size, size, size ])));
|
|
2120
|
+
if (exteriorcb) box = exteriorcb(box);
|
|
2121
|
+
return box;
|
|
2122
|
+
};
|
|
2123
|
+
var BBox = function BBox(o) {
|
|
2124
|
+
depreciated("BBox", true, "Use 'parts.BBox' instead");
|
|
2125
|
+
var s = div$1(xyz2array(o.size()), 2);
|
|
2126
|
+
return CSG.cube({
|
|
2127
|
+
center: s,
|
|
2128
|
+
radius: s
|
|
2129
|
+
}).align(o, "xyz");
|
|
2130
|
+
};
|
|
2131
|
+
function getRadius(o) {
|
|
2132
|
+
return div$1(xyz2array(o.size()), 2);
|
|
2133
|
+
}
|
|
2134
|
+
function rabbetJoin(box, thickness) {
|
|
2135
|
+
var gap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : .25;
|
|
2136
|
+
var r = add(getRadius(box), -thickness / 2);
|
|
2137
|
+
r[2] = thickness / 2;
|
|
2138
|
+
var cutter = CSG.cube({
|
|
2139
|
+
center: r,
|
|
2140
|
+
radius: r
|
|
2141
|
+
}).align(box, "xy").color("green");
|
|
2142
|
+
var topCutter = cutter.snap(box, "z", "inside+");
|
|
2143
|
+
var group = Group("", {
|
|
2144
|
+
topCutter,
|
|
2145
|
+
bottomCutter: cutter
|
|
2146
|
+
});
|
|
2147
|
+
group.add(box.subtract(cutter.enlarge([ gap, gap, 0 ])).color("blue"), "top");
|
|
2148
|
+
group.add(box.subtract(topCutter.enlarge([ gap, gap, 0 ])).color("red"), "bottom");
|
|
2149
|
+
return group;
|
|
2150
|
+
}
|
|
2151
|
+
var Boxes = Object.freeze({
|
|
2152
|
+
__proto__: null,
|
|
2153
|
+
RabbetJoin,
|
|
2154
|
+
topMiddleBottom,
|
|
2155
|
+
Rabett,
|
|
2156
|
+
RabettTopBottom,
|
|
2157
|
+
CutOut,
|
|
2158
|
+
Rectangle,
|
|
2159
|
+
Hollow,
|
|
2160
|
+
BBox
|
|
2161
|
+
});
|
|
2162
|
+
var compatV1 = _objectSpread2(_objectSpread2({}, util), {}, {
|
|
2163
|
+
group: Group,
|
|
2164
|
+
init: init$1,
|
|
2165
|
+
triangle: triUtils,
|
|
2166
|
+
array,
|
|
2167
|
+
parts: parts$1,
|
|
2168
|
+
Boxes,
|
|
2169
|
+
Debug
|
|
2170
|
+
});
|
|
2171
|
+
exports.Boxes = Boxes;
|
|
2172
|
+
exports.Debug = Debug;
|
|
2173
|
+
exports.Group = Group;
|
|
2174
|
+
exports.array = array;
|
|
2175
|
+
exports.compatV1 = compatV1;
|
|
2176
|
+
exports.init = init$1;
|
|
2177
|
+
exports.parts = parts$1;
|
|
2178
|
+
exports.triUtils = triUtils;
|
|
2179
|
+
exports.util = util;
|
|
2180
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2181
|
+
value: true
|
|
2182
|
+
});
|
|
2183
|
+
return exports;
|
|
2184
|
+
}({}, jsCadCSG, scadApi);
|
|
2185
|
+
const debug = jscadUtils.Debug("jscadUtils:initJscadutils");
|
|
2186
|
+
util = jscadUtils.compatV1;
|
|
2187
|
+
util.init.default(CSG);
|
|
2188
|
+
debug("initJscadutils:jscadUtils", jscadUtils);
|
|
2189
|
+
Parts = jscadUtils.parts;
|
|
2190
|
+
Boxes = jscadUtils.Boxes;
|
|
2191
|
+
Group = jscadUtils.Group;
|
|
2192
|
+
Debug = jscadUtils.Debug;
|
|
2193
|
+
array = jscadUtils.array;
|
|
2194
|
+
triUtils = jscadUtils.triUtils;
|
|
2195
|
+
return jscadUtils;
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
var jscadUtilsPluginInit = [];
|
|
2199
|
+
|
|
2200
|
+
util = {
|
|
2201
|
+
init: (...a) => {
|
|
2202
|
+
initJscadutils(...a);
|
|
2203
|
+
jscadUtilsPluginInit.forEach(p => {
|
|
2204
|
+
p(...a);
|
|
2205
|
+
});
|
|
2206
|
+
}
|
|
2207
|
+
};
|
|
2208
|
+
// /dist/v1compat.js
|
|
2209
|
+
var RaspberryPi;
|
|
2210
|
+
|
|
2211
|
+
function initJscadRPi() {
|
|
2212
|
+
var Debug = util.Debug;
|
|
2213
|
+
var debug = Debug("jscadRPi:initJscadRPi");
|
|
2214
|
+
var jsCadCSG = {
|
|
2215
|
+
CSG,
|
|
2216
|
+
CAG
|
|
2217
|
+
};
|
|
2218
|
+
var scadApi = {
|
|
2219
|
+
vector_text,
|
|
2220
|
+
rectangular_extrude,
|
|
2221
|
+
vector_char,
|
|
2222
|
+
primitives3d: {
|
|
2223
|
+
cube,
|
|
2224
|
+
sphere,
|
|
2225
|
+
cylinder
|
|
2226
|
+
},
|
|
2227
|
+
extrusions: {
|
|
2228
|
+
rectangular_extrude
|
|
2229
|
+
},
|
|
2230
|
+
text: {
|
|
2231
|
+
vector_text,
|
|
2232
|
+
vector_char
|
|
2233
|
+
},
|
|
2234
|
+
booleanOps: {
|
|
2235
|
+
union
|
|
2236
|
+
}
|
|
2237
|
+
};
|
|
2238
|
+
var jscadUtils = {
|
|
2239
|
+
util,
|
|
2240
|
+
Debug,
|
|
2241
|
+
parts: Parts,
|
|
2242
|
+
Group,
|
|
2243
|
+
array,
|
|
2244
|
+
triUtils
|
|
2245
|
+
};
|
|
2246
|
+
var jscadRPi = function(exports, jscadUtils, jsCadCSG, scadApi) {
|
|
2247
|
+
"use strict";
|
|
2248
|
+
function activeCoolingFan() {
|
|
2249
|
+
var g = jscadUtils.Group("ActiveCoolingFan");
|
|
2250
|
+
var board = jscadUtils.parts.Cube([ 64, 42.5, 1 ]).subtract(jscadUtils.parts.Cube([ 64 - 58, 31.3, 1 ]).translate([ 0, 42.5 - 31.3, 0 ]).color("orange").union(jscadUtils.parts.Cube([ 28, 42.5 - 31.3, 1 ]).translate([ 64 - 28, 0, 0 ]).color("blue"))).union(jscadUtils.parts.Cube([ 19, 40, 9 ]).translate([ 64 - 58, 2.5, 0 ])).color("silver").union(jscadUtils.parts.Cube([ 30, 30, 9 ]).translate([ 64 - 58 + 19, 42.5 - 31.3, 0 ]).color("black"));
|
|
2251
|
+
g.add(board, "board");
|
|
2252
|
+
return g;
|
|
2253
|
+
}
|
|
2254
|
+
jsCadCSG.CSG;
|
|
2255
|
+
scadApi.booleanOps.union;
|
|
2256
|
+
function RightSide(o, mb) {
|
|
2257
|
+
return o.translate(jscadUtils.array.add(o.calcSnap(mb, "z", "outside-"), o.calcSnap(mb, "x", "inside+"), o.calcSnap(mb, "y", "inside-"), [ 2, 0, 0 ]));
|
|
2258
|
+
}
|
|
2259
|
+
function LeftSide(o, mb) {
|
|
2260
|
+
return o.translate(calcLeftSide(o, mb));
|
|
2261
|
+
}
|
|
2262
|
+
function calcLeftSide(o, mb) {
|
|
2263
|
+
return jscadUtils.array.add(o.calcSnap(mb, "z", "outside-"), o.calcSnap(mb, "xy", "inside+"));
|
|
2264
|
+
}
|
|
2265
|
+
function BPlusMotherboard() {
|
|
2266
|
+
var corner = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2;
|
|
2267
|
+
return jscadUtils.parts.Board(85, 56, corner, 1.32).color("green", .75);
|
|
2268
|
+
}
|
|
2269
|
+
function MountingHole(diameter, height) {
|
|
2270
|
+
var r = (diameter || 2.8) / 2;
|
|
2271
|
+
var h = (height || 4) / 2;
|
|
2272
|
+
return CSG.cylinder({
|
|
2273
|
+
start: [ 0, 0, -h ],
|
|
2274
|
+
end: [ 0, 0, h ],
|
|
2275
|
+
radius: r
|
|
2276
|
+
}).color("orange");
|
|
2277
|
+
}
|
|
2278
|
+
function Mountingpad(radius, height) {
|
|
2279
|
+
var r = (radius || 6.2) / 2;
|
|
2280
|
+
var h = (height || 1.5) / 2;
|
|
2281
|
+
return CSG.cylinder({
|
|
2282
|
+
start: [ 0, 0, -h ],
|
|
2283
|
+
end: [ 0, 0, h ],
|
|
2284
|
+
radius: r
|
|
2285
|
+
}).color("yellow");
|
|
2286
|
+
}
|
|
2287
|
+
function EthernetJack() {
|
|
2288
|
+
var r = jscadUtils.array.div([ 21.24, 15.88, 13.475 ], 2);
|
|
2289
|
+
return CSG.cube({
|
|
2290
|
+
center: [ 0, 0, 0 ],
|
|
2291
|
+
radius: r
|
|
2292
|
+
}).color("lightgray");
|
|
2293
|
+
}
|
|
2294
|
+
function UsbJack() {
|
|
2295
|
+
var jack = jscadUtils.Group("body", jscadUtils.parts.Cube([ 16.4, 13.36, 17 - 1.5 ]).color("lightgray"));
|
|
2296
|
+
jack.add(jscadUtils.parts.Cube([ .75, 15.3, 17.68 - 1.5 ]).align(jack.parts.body, "yz").snap(jack.parts.body, "x", "outside-").color("lightgray"), "flange");
|
|
2297
|
+
return jack;
|
|
2298
|
+
}
|
|
2299
|
+
function MicroUsb() {
|
|
2300
|
+
return jscadUtils.parts.Cube([ 7.59, 5.7, 2.64 ]).color("lightgray");
|
|
2301
|
+
}
|
|
2302
|
+
function Hdmi() {
|
|
2303
|
+
return jscadUtils.parts.Cube([ 15, 11.57, 7.4 ]).color("lightgray");
|
|
2304
|
+
}
|
|
2305
|
+
function AvJack() {
|
|
2306
|
+
var block = jscadUtils.parts.Cube([ 6.9, 12.47, 5.6 ]).color("lightgray");
|
|
2307
|
+
var cyl = jscadUtils.parts.Cylinder(6, 2).rotateX(90).align(block, "xz").snap(block, "y", "outside+").color("black");
|
|
2308
|
+
return jscadUtils.Group("block,cylinder", [ block, cyl ]);
|
|
2309
|
+
}
|
|
2310
|
+
function Ribbon() {
|
|
2311
|
+
return jscadUtils.parts.Cube([ 3, 22.4, 5.7 ]).color("gray");
|
|
2312
|
+
}
|
|
2313
|
+
function Gpio(mb) {
|
|
2314
|
+
var gpio = jscadUtils.parts.Cube([ 50.64, 5, 8.72 ]).color("gray");
|
|
2315
|
+
return mb ? gpio.snap(mb, "xy", "inside-").snap(mb, "z", "outside-").midlineTo("x", 32.5).midlineTo("y", 52.5) : gpio;
|
|
2316
|
+
}
|
|
2317
|
+
function BoardLed() {
|
|
2318
|
+
return jscadUtils.parts.Cube([ 1, 2, .7 ]);
|
|
2319
|
+
}
|
|
2320
|
+
var debug$2 = jscadUtils.Debug("jscadRPi:BPlusMounting");
|
|
2321
|
+
function holes(mb) {
|
|
2322
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2323
|
+
options = Object.assign(options, {
|
|
2324
|
+
height: 8
|
|
2325
|
+
});
|
|
2326
|
+
debug$2("holes", mb, options);
|
|
2327
|
+
var hole = MountingHole(options.diameter || 3.25, options.height).snap(mb, "xy", "inside-").align(mb, "z");
|
|
2328
|
+
var holes = [ hole.midlineTo("x", 3.5).midlineTo("y", 3.5), hole.midlineTo("x", 61.5).midlineTo("y", 3.5), hole.midlineTo("x", 3.5).midlineTo("y", 52.5), hole.midlineTo("x", 61.5).midlineTo("y", 52.5) ];
|
|
2329
|
+
return jscadUtils.Group("hole1,hole2,hole3,hole4", holes);
|
|
2330
|
+
}
|
|
2331
|
+
function pads(mb) {
|
|
2332
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2333
|
+
options = Object.assign({
|
|
2334
|
+
snap: "outside-",
|
|
2335
|
+
height: 4
|
|
2336
|
+
}, options);
|
|
2337
|
+
var pad = Mountingpad(undefined, options.height).snap(mb, "z", options.snap).snap(mb, "xy", "inside-");
|
|
2338
|
+
var pads = [ pad.midlineTo("x", 3.5).midlineTo("y", 3.5), pad.midlineTo("x", 61.5).midlineTo("y", 3.5), pad.midlineTo("x", 3.5).midlineTo("y", 52.5), pad.midlineTo("x", 61.5).midlineTo("y", 52.5) ];
|
|
2339
|
+
return jscadUtils.Group("pad1,pad2,pad3,pad4", pads);
|
|
2340
|
+
}
|
|
2341
|
+
var BPlusMounting = {
|
|
2342
|
+
holes,
|
|
2343
|
+
pads
|
|
2344
|
+
};
|
|
2345
|
+
var debug$1 = jscadUtils.Debug("jscadRPi:BPlus");
|
|
2346
|
+
function pi4(group, clearance, mb) {
|
|
2347
|
+
group.add(RightSide(jscadUtils.parts.Cube([ 21.5, 16.5, 13.5 ]).color("lightgray"), mb).translate([ 2, 0, 0 ]).midlineTo("y", 45.75), "ethernet");
|
|
2348
|
+
group.add(jscadUtils.parts.Cube([ clearance, 16.5, 13.5 ]).align(group.parts.ethernet, "yz").snap(group.parts.ethernet, "x", "outside-").color("red"), "clearance-ethernet", true, "clearance");
|
|
2349
|
+
var usb = jscadUtils.Group();
|
|
2350
|
+
usb.add(jscadUtils.parts.Cube([ 17, 13.1, 15 ]).snap(group.parts.ethernet, "x", "inside+", -1).snap(mb, "z", "outside-", 1.5).color("lightgray"), "body");
|
|
2351
|
+
usb.add(jscadUtils.parts.Cube([ 1, 15, 16 ]).snap(usb.parts.body, "x", "outside-").align(usb.parts.body, "yz").color("lightgray"), "flange");
|
|
2352
|
+
group.add(usb.clone().translate(jscadUtils.util.calcmidlineTo(usb.parts.body, "y", 27)), "usb1", false, "usb1");
|
|
2353
|
+
group.add(jscadUtils.parts.Cube([ clearance, 15, 16 ]).align(group.parts.usb1, "yz").snap(group.parts.usb1, "x", "outside-").color("red"), "clearance-usb1", true);
|
|
2354
|
+
group.add(usb.clone().translate(jscadUtils.util.calcmidlineTo(usb.parts.body, "y", 9)), "usb2", false, "usb2");
|
|
2355
|
+
group.add(jscadUtils.parts.Cube([ clearance, 15, 16 ]).align(group.parts.usb2, "yz").snap(group.parts.usb2, "x", "outside-").color("red"), "clearance-usb2", true);
|
|
2356
|
+
group.add(jscadUtils.parts.Cube([ 10, 7.5, 3.2 ]).snap(usb.parts.body, "y", "inside-", -1).snap(mb, "z", "outside-").midlineTo("x", 3.5 + 7.7).color("lightgray"), "usbc");
|
|
2357
|
+
group.add(jscadUtils.parts.Cube([ 10, clearance, 3.2 ]).align(group.parts.usbc, "xz").snap(group.parts.usbc, "y", "outside+").color("red"), "clearance-usbc", true);
|
|
2358
|
+
group.add(jscadUtils.parts.Cube([ 7, 7.5, 3 ]).snap(usb.parts.body, "y", "inside-", -1).snap(mb, "z", "outside-").midlineTo("x", 3.5 + 7.7 + 14.8).color("lightgray"), "hdmi1");
|
|
2359
|
+
group.add(jscadUtils.parts.Cube([ 7, clearance, 3 ]).align(group.parts.hdmi1, "xz").snap(group.parts.hdmi1, "y", "outside+").color("red"), "clearance-hdmi1", true);
|
|
2360
|
+
group.add(jscadUtils.parts.Cube([ 7, 7.5, 3 ]).snap(usb.parts.body, "y", "inside-", -1).snap(mb, "z", "outside-").midlineTo("x", 3.5 + 7.7 + 14.8 + 13.5).color("lightgray"), "hdmi2");
|
|
2361
|
+
group.add(jscadUtils.parts.Cube([ 7, clearance, 3 ]).align(group.parts.hdmi2, "xz").snap(group.parts.hdmi2, "y", "outside+").color("red"), "clearance-hdmi2", true);
|
|
2362
|
+
group.add(AvJack().snap("block", mb, "z", "outside-").midlineTo("block", "x", 3.5 + 7.7 + 14.8 + 13.5 + 7 + 7.5), "avjack", false, "avjack");
|
|
2363
|
+
group.add(jscadUtils.parts.Cylinder(6, clearance).rotateX(90).align(group.parts.avjack, "xz").snap(group.parts.avjack, "y", "outside+").color("red"), "clearance-avjack", true);
|
|
2364
|
+
group.add(Ribbon().snap(mb, "z", "outside-").midlineTo("x", 3.5 + 7.7 + 14.8 + 13.5 + 7), "camera");
|
|
2365
|
+
group.add(Ribbon().snap(mb, "z", "outside-").midlineTo("x", 4).midlineTo("y", 24.5 + 3.5), "display");
|
|
2366
|
+
group.add(Gpio().snap(mb, "z", "outside-").midlineTo("x", 29 + 3.5).midlineTo("y", 56 - 3.5), "gpio");
|
|
2367
|
+
group.add(BoardLed().snap(mb, "z", "outside-").midlineTo("x", 1.1).midlineTo("y", 8).color("lightgreen"), "activityled");
|
|
2368
|
+
group.add(BoardLed().snap(mb, "z", "outside-").midlineTo("x", 1.1).midlineTo("y", 12).color("red"), "powerled");
|
|
2369
|
+
}
|
|
2370
|
+
function pi5(group, clearance, mb) {
|
|
2371
|
+
group.add(jscadUtils.parts.Cube([ 12, 12, 3 ]).color("lightgray").translate([ 24, 15, 2 ]), "cpu");
|
|
2372
|
+
group.add(jscadUtils.parts.Cube([ 12, 12, clearance ]).color("red").translate([ 24, 15, 2 ]), "clearance-cpu", true, "clearance");
|
|
2373
|
+
group.add(RightSide(jscadUtils.parts.Cube([ 21.5, 16.5, 13.5 ]).color("lightgray"), mb).translate([ 2, 0, 0 ]).midlineTo("y", 10.2), "ethernet");
|
|
2374
|
+
group.add(jscadUtils.parts.Cube([ clearance, 16.5, 13.5 ]).align(group.parts.ethernet, "yz").snap(group.parts.ethernet, "x", "outside-").color("red"), "clearance-ethernet", true, "clearance");
|
|
2375
|
+
var usb = jscadUtils.Group();
|
|
2376
|
+
usb.add(jscadUtils.parts.Cube([ 17, 13.1, 15 ]).snap(group.parts.ethernet, "x", "inside+", -1).snap(mb, "z", "outside-", 1.5).color("lightgray"), "body");
|
|
2377
|
+
usb.add(jscadUtils.parts.Cube([ 1, 15, 16 ]).snap(usb.parts.body, "x", "outside-").align(usb.parts.body, "yz").color("lightgray"), "flange");
|
|
2378
|
+
group.add(usb.clone().translate(jscadUtils.util.calcmidlineTo(usb.parts.body, "y", 29.7)), "usb1", false, "usb1");
|
|
2379
|
+
group.add(jscadUtils.parts.Cube([ clearance, 15, 16 ]).align(group.parts.usb1, "yz").snap(group.parts.usb1, "x", "outside-").color("red"), "clearance-usb1", true);
|
|
2380
|
+
group.add(usb.clone().translate(jscadUtils.util.calcmidlineTo(usb.parts.body, "y", 47)), "usb2", false, "usb2");
|
|
2381
|
+
group.add(jscadUtils.parts.Cube([ clearance, 15, 16 ]).align(group.parts.usb2, "yz").snap(group.parts.usb2, "x", "outside-").color("red"), "clearance-usb2", true);
|
|
2382
|
+
group.add(jscadUtils.parts.Cube([ 10, 7.5, 3.2 ]).snap(usb.parts.body, "y", "inside-", -1).snap(mb, "z", "outside-").midlineTo("x", 3.5 + 7.7).color("lightgray"), "usbc");
|
|
2383
|
+
group.add(jscadUtils.parts.Cube([ 10, clearance, 3.2 ]).align(group.parts.usbc, "xz").snap(group.parts.usbc, "y", "outside+").color("red"), "clearance-usbc", true);
|
|
2384
|
+
group.add(jscadUtils.parts.Cube([ 7, 7.5, 3 ]).snap(usb.parts.body, "y", "inside-", -1).snap(mb, "z", "outside-").midlineTo("x", 3.5 + 7.7 + 14.8).color("lightgray"), "hdmi1");
|
|
2385
|
+
group.add(jscadUtils.parts.Cube([ 7, clearance, 3 ]).align(group.parts.hdmi1, "xz").snap(group.parts.hdmi1, "y", "outside+").color("red"), "clearance-hdmi1", true);
|
|
2386
|
+
group.add(jscadUtils.parts.Cube([ 7, 7.5, 3 ]).snap(usb.parts.body, "y", "inside-", -1).snap(mb, "z", "outside-").midlineTo("x", 3.5 + 7.7 + 14.8 + 13.5).color("lightgray"), "hdmi2");
|
|
2387
|
+
group.add(jscadUtils.parts.Cube([ 7, clearance, 3 ]).align(group.parts.hdmi2, "xz").snap(group.parts.hdmi2, "y", "outside+").color("red"), "clearance-hdmi2", true);
|
|
2388
|
+
group.add(AvJack().snap("block", mb, "z", "outside-").midlineTo("block", "x", 3.5 + 7.7 + 14.8 + 13.5 + 7 + 7.5), "avjack", false, "avjack");
|
|
2389
|
+
group.add(jscadUtils.parts.Cylinder(6, clearance).rotateX(90).align(group.parts.avjack, "xz").snap(group.parts.avjack, "y", "outside+").color("red"), "clearance-avjack", true);
|
|
2390
|
+
group.add(Ribbon().snap(mb, "z", "outside-").midlineTo("x", 3.5 + 7.7 + 14.8 + 13.5 + 7), "camera");
|
|
2391
|
+
group.add(Ribbon().snap(mb, "z", "outside-").midlineTo("x", 4).midlineTo("y", 24.5 + 3.5), "display");
|
|
2392
|
+
group.add(Gpio().snap(mb, "z", "outside-").midlineTo("x", 29 + 3.5).midlineTo("y", 56 - 3.5), "gpio");
|
|
2393
|
+
group.add(BoardLed().snap(mb, "z", "outside-").midlineTo("x", 1.1).midlineTo("y", 8).color("lightgreen"), "activityled");
|
|
2394
|
+
group.add(BoardLed().snap(mb, "z", "outside-").midlineTo("x", 1.1).midlineTo("y", 12).color("red"), "powerled");
|
|
2395
|
+
}
|
|
2396
|
+
function BPlus() {
|
|
2397
|
+
var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2;
|
|
2398
|
+
var options = arguments.length > 1 ? arguments[1] : undefined;
|
|
2399
|
+
var _Object$assign = Object.assign({
|
|
2400
|
+
clearance: 5
|
|
2401
|
+
}, options), clearance = _Object$assign.clearance;
|
|
2402
|
+
model = !model ? 2 : model === true ? 3 : model;
|
|
2403
|
+
debug$1("BPlus model:", model);
|
|
2404
|
+
var mb = BPlusMotherboard(model == 4 ? 3 : 2);
|
|
2405
|
+
var group = jscadUtils.Group("mb", mb);
|
|
2406
|
+
if (model < 4) {
|
|
2407
|
+
group.add(RightSide(EthernetJack(), mb).midlineTo("y", 10.25), "ethernet");
|
|
2408
|
+
debug$1("mb", mb);
|
|
2409
|
+
var usb = UsbJack();
|
|
2410
|
+
var usbTranslation = jscadUtils.array.add(usb.parts.flange.calcSnap(mb, "x", "inside+"), [ 2, 0, 0 ], usb.parts.body.calcSnap(mb, "y", "inside-"), usb.parts.body.calcSnap(mb, "z", "outside-"));
|
|
2411
|
+
debug$1("usbTranslation", usbTranslation, jscadUtils.util.calcmidlineTo(usb.parts.body, "y", 29));
|
|
2412
|
+
group.add(usb.clone().translate(usbTranslation).translate(jscadUtils.util.calcmidlineTo(usb.parts.body, "y", 29)), "usb1", false, "usb1");
|
|
2413
|
+
group.add(usb.clone().translate(usbTranslation).translate(jscadUtils.util.calcmidlineTo(usb.parts.body, "y", 47)), "usb2", false, "usb2");
|
|
2414
|
+
group.add(MicroUsb().snap(mb, "z", "outside-").midlineTo("x", 10.6).translate([ 0, -2, 0 ]), "microusb");
|
|
2415
|
+
group.add(Hdmi().snap(mb, "z", "outside-").midlineTo("x", 32).translate([ 0, -2, 0 ]), "hdmi");
|
|
2416
|
+
group.add(AvJack().snap("block", mb, "z", "outside-").midlineTo("block", "x", 53.5), "avjack", false, "avjack");
|
|
2417
|
+
group.add(Ribbon().snap(mb, "z", "outside-").midlineTo("x", 45), "camera");
|
|
2418
|
+
group.add(Ribbon().snap(mb, "z", "outside-").midlineTo("x", 3.5).midlineTo("y", 28), "display");
|
|
2419
|
+
group.add(Gpio().snap(mb, "z", "outside-").midlineTo("x", 32.5).midlineTo("y", 52.5), "gpio");
|
|
2420
|
+
if (model == 3) {
|
|
2421
|
+
group.add(BoardLed().snap(mb, "z", "outside-").midlineTo("x", 1.1).midlineTo("y", 7.9).color("lightgreen"), "activityled");
|
|
2422
|
+
group.add(BoardLed().snap(mb, "z", "outside-").midlineTo("x", 1.1).midlineTo("y", 11.5).color("red"), "powerled");
|
|
2423
|
+
} else {
|
|
2424
|
+
group.add(BoardLed().snap(mb, "z", "outside-").translate([ 1, 43.5, 0 ]).color("lightgreen"), "activityled");
|
|
2425
|
+
group.add(BoardLed().snap(mb, "z", "outside-").translate([ 1, 46, 0 ]).color("red"), "powerled");
|
|
2426
|
+
}
|
|
2427
|
+
} else if (model == 4) {
|
|
2428
|
+
pi4(group, clearance, mb);
|
|
2429
|
+
} else {
|
|
2430
|
+
pi5(group, clearance, mb);
|
|
2431
|
+
}
|
|
2432
|
+
group.add(jscadUtils.parts.Cube([ 15.2, 12, 1.5 ]).snap(mb, "z", "outside+").midlineTo("y", 28).translate([ -2.5, 0, 0 ]).color("silver"), "microsd");
|
|
2433
|
+
group.holes = holes(mb).array();
|
|
2434
|
+
group.add(group.holes[0], "hole1", true);
|
|
2435
|
+
group.add(group.holes[1], "hole2", true);
|
|
2436
|
+
group.add(group.holes[2], "hole3", true);
|
|
2437
|
+
group.add(group.holes[3], "hole4", true);
|
|
2438
|
+
if (model >= 5) {
|
|
2439
|
+
group.holes.push(MountingHole(3.25, 8).snap(mb, "xy", "inside-").align(mb, "z").midlineTo("x", 3.5).midlineTo("y", 6 + 3.5));
|
|
2440
|
+
group.add(group.holes[4], "fan1hole", true);
|
|
2441
|
+
group.holes.push(MountingHole(3.25, 8).snap(mb, "xy", "inside-").align(mb, "z").midlineTo("x", 3.5 + 58).midlineTo("y", 52.5 - 6));
|
|
2442
|
+
group.add(group.holes[5], "fan2hole", true);
|
|
2443
|
+
}
|
|
2444
|
+
return group;
|
|
2445
|
+
}
|
|
2446
|
+
function CameraModuleV1$1() {
|
|
2447
|
+
var t = 1.1;
|
|
2448
|
+
var height = {
|
|
2449
|
+
sensor: 5.9 - t,
|
|
2450
|
+
board: t
|
|
2451
|
+
};
|
|
2452
|
+
var g = jscadUtils.Group();
|
|
2453
|
+
g.add(jscadUtils.parts.Cube([ 24, 25, t ]).Center().color("green", .75), "board");
|
|
2454
|
+
function Hole(x, y) {
|
|
2455
|
+
return jscadUtils.parts.Cylinder(2.2, t).snap(g.parts.board, "xy", "inside-").midlineTo("x", x).midlineTo("y", y);
|
|
2456
|
+
}
|
|
2457
|
+
g.holes = [ Hole(2, 2).color("yellow"), Hole(2, 23), Hole(12.5 + 2, 2), Hole(12.5 + 2, 23) ];
|
|
2458
|
+
g.add(jscadUtils.Group("hole0,hole1,hole2,hole3", g.holes), "hole", false, "holes");
|
|
2459
|
+
var mounts = g.holes.reduce(function(m, h, i) {
|
|
2460
|
+
m["mount".concat(i)] = jscadUtils.parts.Cylinder(4, 2).align(h, "xy").snap(g.parts.board, "z", "outside-");
|
|
2461
|
+
return m;
|
|
2462
|
+
}, {});
|
|
2463
|
+
g.add(jscadUtils.Group(mounts), "mounts", true, "mounts");
|
|
2464
|
+
var pins = g.holes.reduce(function(m, h, i) {
|
|
2465
|
+
m["pin".concat(i)] = jscadUtils.parts.Cylinder(jscadUtils.util.nearest.under(1.5), height.board).align(h, "xy").align(g.parts.board, "z");
|
|
2466
|
+
return m;
|
|
2467
|
+
}, {});
|
|
2468
|
+
g.add(jscadUtils.Group(pins), "pins", true, "pins");
|
|
2469
|
+
g.add(jscadUtils.parts.Cube([ 8.5, 8.5, 2 ]).snap(g.parts.board, "xy", "inside-").snap(g.parts.board, "z", "outside-").midlineTo("x", 12.5 + 2).midlineTo("y", 8.5 + 4).color("black"), "sensor");
|
|
2470
|
+
g.add(jscadUtils.parts.Cube([ 8.5, 8.5, height.sensor - 2 ]).align(g.parts.sensor, "xy").snap(g.parts.sensor, "z", "outside-").color("gray"), "lense");
|
|
2471
|
+
g.add(jscadUtils.parts.Cube([ 7.56, 10, 2.65 - t ]).snap(g.parts.board, "z", "outside-").align(g.parts.lense, "y", "inside-").snap(g.parts.lense, "x", "outside+", -1).color("gray"), "lenseribbon");
|
|
2472
|
+
g.add(jscadUtils.parts.Cube([ 5.5, 17, 3 ]).snap(g.parts.board, "x", "inside+").snap(g.parts.board, "y", "inside-").snap(g.parts.board, "z", "outside+").midlineTo("y", 12.5), "ribbon");
|
|
2473
|
+
g.add(jscadUtils.parts.RoundedCube(24 - 5.5, 25, 2.5 - t, 2).snap(g.parts.board, "xy", "inside-").snap(g.parts.board, "z", "outside+").subtract(g.holes.map(function(hole) {
|
|
2474
|
+
return hole.enlarge(3, 3, 5);
|
|
2475
|
+
})).color("red"), "bottom-nogo");
|
|
2476
|
+
g.add(g.parts.ribbon.enlarge(2, -1, -1).snap(g.parts.ribbon, "x", "outside-").color("red"), "ribbon-nogo");
|
|
2477
|
+
return g;
|
|
2478
|
+
}
|
|
2479
|
+
function CameraModuleV1() {
|
|
2480
|
+
var t = 1.1;
|
|
2481
|
+
var height = {
|
|
2482
|
+
sensor: 4 - t,
|
|
2483
|
+
board: t
|
|
2484
|
+
};
|
|
2485
|
+
var g = jscadUtils.Group();
|
|
2486
|
+
g.add(jscadUtils.parts.RoundedCube(23.862, 25, t, 2).Center().color("green", .75), "board");
|
|
2487
|
+
function Hole(x, y) {
|
|
2488
|
+
return jscadUtils.parts.Cylinder(2.2, t).snap(g.parts.board, "xy", "inside-").midlineTo("x", x).midlineTo("y", y);
|
|
2489
|
+
}
|
|
2490
|
+
g.holes = [ Hole(2, 2).color("yellow"), Hole(2, 23), Hole(14.5, 2), Hole(14.5, 23) ];
|
|
2491
|
+
g.add(jscadUtils.Group("hole0,hole1,hole2,hole3", g.holes), "hole", false, "holes");
|
|
2492
|
+
var mounts = g.holes.reduce(function(m, h, i) {
|
|
2493
|
+
m["mount".concat(i)] = jscadUtils.parts.Cylinder(4, height.sensor).align(h, "xy").snap(g.parts.board, "z", "outside-");
|
|
2494
|
+
return m;
|
|
2495
|
+
}, {});
|
|
2496
|
+
g.add(jscadUtils.Group(mounts), "mounts", true, "mounts");
|
|
2497
|
+
var pins = g.holes.reduce(function(m, h, i) {
|
|
2498
|
+
m["pin".concat(i)] = jscadUtils.parts.Cylinder(jscadUtils.util.nearest.under(1.5), height.board).align(h, "xy").align(g.parts.board, "z");
|
|
2499
|
+
return m;
|
|
2500
|
+
}, {});
|
|
2501
|
+
g.add(jscadUtils.Group(pins), "pins", true, "pins");
|
|
2502
|
+
g.add(jscadUtils.parts.Cube([ 8.5, 8.5, height.sensor ]).snap(g.parts.board, "xy", "inside-").snap(g.parts.board, "z", "outside-").midlineTo("x", 14.5).midlineTo("y", 12.5).color("black"), "sensor");
|
|
2503
|
+
g.add(jscadUtils.parts.Cylinder(7.3, 1.6).align(g.parts.sensor, "xy").snap(g.parts.sensor, "z", "outside-").color("gray"), "lense");
|
|
2504
|
+
g.add(jscadUtils.parts.Cube([ 4, 9, 2.65 - t ]).snap(g.parts.board, "xy", "inside-").snap(g.parts.board, "z", "outside-").midlineTo("x", 4.7).midlineTo("y", 13.8).stretch("x", 4).color("gray"), "lenseribbon");
|
|
2505
|
+
g.add(jscadUtils.parts.Cube([ 5.5, 20.8, 3.55 - t ]).snap(g.parts.board, "x", "inside+").snap(g.parts.board, "y", "inside-").snap(g.parts.board, "z", "outside+").midlineTo("y", 12.5), "ribbon");
|
|
2506
|
+
g.add(jscadUtils.parts.RoundedCube(23.862 - 5.5, 25, 2.5 - t, 2).snap(g.parts.board, "xy", "inside-").snap(g.parts.board, "z", "outside+").subtract(g.holes.map(function(hole) {
|
|
2507
|
+
return hole.enlarge(3, 3, 5);
|
|
2508
|
+
})).color("red"), "bottom-nogo");
|
|
2509
|
+
g.add(g.parts.ribbon.enlarge(2, -1, -1).snap(g.parts.ribbon, "x", "outside-").color("red"), "ribbon-nogo");
|
|
2510
|
+
return g;
|
|
2511
|
+
}
|
|
2512
|
+
var union$1 = scadApi.booleanOps.union;
|
|
2513
|
+
function Hat(pi) {
|
|
2514
|
+
var hat = jscadUtils.Group();
|
|
2515
|
+
hat.add(jscadUtils.parts.Board(65.02, 56.39, 3.56, 1.62).color("darkgreen", .75), "mb");
|
|
2516
|
+
var hole = MountingHole().snap(hat.parts.mb, "xy", "inside-");
|
|
2517
|
+
var holes = union$1(hole.midlineTo("x", 3.56).midlineTo("y", 3.56), hole.midlineTo("x", 61.47).midlineTo("y", 3.56), hole.midlineTo("x", 3.56).midlineTo("y", 52.46), hole.midlineTo("x", 61.47).midlineTo("y", 52.46));
|
|
2518
|
+
hat.add(Gpio(hat.parts.mb).snap(hat.parts.mb, "z", "outside+"), "gpio");
|
|
2519
|
+
hat.holes = holes;
|
|
2520
|
+
if (pi) {
|
|
2521
|
+
hat.translate(hat.parts.mb.calcSnap(pi, "xy", "inside-")).translate(hat.parts.gpio.calcSnap(pi, "z", "outside-"));
|
|
2522
|
+
}
|
|
2523
|
+
return hat;
|
|
2524
|
+
}
|
|
2525
|
+
function HatStandoff() {
|
|
2526
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2527
|
+
options = Object.assign({
|
|
2528
|
+
height: 10
|
|
2529
|
+
}, options);
|
|
2530
|
+
var standoff = Mountingpad(null, options.height);
|
|
2531
|
+
var peg = MountingHole(null, options.height + 3);
|
|
2532
|
+
return standoff.union(peg);
|
|
2533
|
+
}
|
|
2534
|
+
function _arrayLikeToArray(r, a) {
|
|
2535
|
+
(null == a || a > r.length) && (a = r.length);
|
|
2536
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
2537
|
+
return n;
|
|
2538
|
+
}
|
|
2539
|
+
function _arrayWithoutHoles(r) {
|
|
2540
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
2541
|
+
}
|
|
2542
|
+
function _iterableToArray(r) {
|
|
2543
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
2544
|
+
}
|
|
2545
|
+
function _nonIterableSpread() {
|
|
2546
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
2547
|
+
}
|
|
2548
|
+
function _toConsumableArray(r) {
|
|
2549
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
2550
|
+
}
|
|
2551
|
+
function _unsupportedIterableToArray(r, a) {
|
|
2552
|
+
if (r) {
|
|
2553
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
2554
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
2555
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
function HQCameraModule() {
|
|
2559
|
+
var _camera$holes;
|
|
2560
|
+
var t = 1.1;
|
|
2561
|
+
var camera = jscadUtils.Group();
|
|
2562
|
+
camera.add(jscadUtils.parts.RoundedCube(38, 38, t, 1.4).Center().color("green", .75), "board");
|
|
2563
|
+
var hole = jscadUtils.parts.Cylinder(3.25, 10).snap(camera.parts.board, "xy", "inside+", 1.25).translate([ -4, -4, -5 ]).color("red");
|
|
2564
|
+
camera.add(hole, "hole1", true);
|
|
2565
|
+
camera.add(hole.rotateZ(90), "hole2", true);
|
|
2566
|
+
camera.add(hole.rotateZ(180), "hole3", true);
|
|
2567
|
+
camera.add(hole.rotateZ(-90), "hole4", true);
|
|
2568
|
+
(_camera$holes = camera.holes).push.apply(_camera$holes, _toConsumableArray(camera.array("hole1,hole2,hole3,hole4")));
|
|
2569
|
+
var sensor = jscadUtils.parts.Cube([ 8.5, 8.5, 1 ]).snap(camera.parts.board, "z", "outside-").align(camera.parts.board, "xy").color("white");
|
|
2570
|
+
camera.add(sensor, "sensor");
|
|
2571
|
+
var mount = jscadUtils.parts.Cylinder(36, 10.2).snap(camera.parts.board, "z", "outside-").align(camera.parts.board, "xy").color("black");
|
|
2572
|
+
var mountInside = jscadUtils.parts.Cylinder(30.75, 10.2).snap(camera.parts.board, "z", "outside-").align(camera.parts.board, "xy").color("black");
|
|
2573
|
+
camera.add(mount.subtract(mountInside), "mount");
|
|
2574
|
+
camera.add(mount, "mount-clearance", true);
|
|
2575
|
+
var tripodMount = jscadUtils.parts.Cube([ 13.97, 12, 11 ]).snap(mount, "z", "inside+").snap(camera.parts.board, "y", "outside+").align(mount, "x").color("gray");
|
|
2576
|
+
camera.add(tripodMount.union(jscadUtils.parts.Cube([ 24.5, 10, 7.62 ]).snap(mount, "z", "inside+").snap(tripodMount, "y", "outside-").align(mount, "x").color("darkgray").subtract(mountInside)), "tripodMount");
|
|
2577
|
+
camera.add(jscadUtils.parts.Cube([ 20.8, 5.5, 3.55 - t ]).snap(camera.parts.board, "y", "inside-").snap(camera.parts.board, "z", "outside+").align(camera.parts.board, "x"), "ribbon");
|
|
2578
|
+
camera.add(camera.parts.ribbon.enlarge(2, 4, -1).snap(camera.parts.ribbon, "y", "outside+").color("red"), "ribbon-nogo");
|
|
2579
|
+
return camera;
|
|
2580
|
+
}
|
|
2581
|
+
function boardButton(name, board, midline) {
|
|
2582
|
+
var g = jscadUtils.Group(name);
|
|
2583
|
+
g.add(jscadUtils.parts.Cube([ 6.5, 6.5, 2 ]).color("silver").snap(board, "xy", "inside-").snap(board, "z", "outside-").midlineTo("y", midline), "base");
|
|
2584
|
+
g.add(jscadUtils.parts.Cylinder(3, 1).color("black").align(g.parts.base, "xy").snap(g.parts.base, "z", "outside-"), "push");
|
|
2585
|
+
return g;
|
|
2586
|
+
}
|
|
2587
|
+
function buttonCap(name, button) {
|
|
2588
|
+
var g = jscadUtils.Group(name);
|
|
2589
|
+
g.add(jscadUtils.parts.Cylinder(4, 3).fillet(1, "z+").union(jscadUtils.parts.Cylinder(6, .5).bisect("x", -.5).parts.negative).color("blue").align(button, "xy").snap(button, "z", "outside-"), "cap");
|
|
2590
|
+
g.add(jscadUtils.parts.Cylinder(7, .75).bisect("x", -.5).parts.negative.color("green").union(jscadUtils.parts.Cylinder(4.5, 2).color("yellow").translate([ 0, 0, 0 ])).align(g.parts.cap, "xy").snap(g.parts.cap, "z", "inside-"), "clearance", true);
|
|
2591
|
+
return g;
|
|
2592
|
+
}
|
|
2593
|
+
function miniPiTFT() {
|
|
2594
|
+
var g = jscadUtils.Group("miniPiTFT");
|
|
2595
|
+
var board = jscadUtils.parts.RoundedCube(jscadUtils.util.inch(2), jscadUtils.util.inch(1), 2, 2).bisect("x", jscadUtils.util.inch(1.5)).parts.negative.bisect("y", -jscadUtils.util.inch(.96)).parts.negative.color("darkgreen");
|
|
2596
|
+
g.add(board, "board");
|
|
2597
|
+
g.add(jscadUtils.parts.Cube([ 31, 18, 2 ]).color("white").snap(board, "x", "inside+").snap(board, "y", "inside-").snap(board, "z", "outside-"), "screen");
|
|
2598
|
+
g.add(jscadUtils.parts.Cube([ jscadUtils.util.inch(.98), jscadUtils.util.inch(.58), 2.01 ]).color("black").snap(board, "x", "inside-", jscadUtils.util.inch(.34)).snap(board, "y", "inside+", -jscadUtils.util.inch(.32)).snap(board, "z", "outside-"), "display");
|
|
2599
|
+
g.add(g.parts.display.stretch("z", 5).chamfer(-5, "z+").align(g.parts.display, "xy").color("red"), "display-clearance", true);
|
|
2600
|
+
g.add(boardButton("button1", board, jscadUtils.util.inch(.53)), "button1", false, "button1-");
|
|
2601
|
+
g.add(boardButton("button2", board, jscadUtils.util.inch(.18)), "button2", false, "button2-");
|
|
2602
|
+
g.add(buttonCap("buttonCap1", g.parts.button1), "buttonCap1", true, "buttonCap1-");
|
|
2603
|
+
g.add(buttonCap("buttonCap2", g.parts.button2), "buttonCap2", true, "buttonCap2-");
|
|
2604
|
+
g.add(jscadUtils.parts.Cube([ 1, 5, .5 ]).color("blue").align(g.parts.buttonCap1, "x").snap(g.parts.buttonCap1, "y", "outside+", 1).snap(g.parts.buttonCap1, "z", "inside-"), "button-connector", true);
|
|
2605
|
+
g.add(g.parts["button-connector"].enlarge(.5, .5, .5).color("red"), "button-connector-clearance", true);
|
|
2606
|
+
g.add(jscadUtils.parts.Tube(7, 3, 7.5).snap(board, "x", "inside-").snap(board, "y", "inside+").snap(board, "z", "outside+").color("yellow"), "standoff", true);
|
|
2607
|
+
return g;
|
|
2608
|
+
}
|
|
2609
|
+
function PiTFT22() {
|
|
2610
|
+
var hat = Hat();
|
|
2611
|
+
var mb = hat.parts.mb;
|
|
2612
|
+
var gpio = hat.parts.gpio;
|
|
2613
|
+
var group = jscadUtils.Group();
|
|
2614
|
+
group.holes = hat.holes;
|
|
2615
|
+
group.add(mb, "mb");
|
|
2616
|
+
group.add(gpio, "gpio");
|
|
2617
|
+
group.add(jscadUtils.parts.Cube([ 45.97, 34.8, 4 ]).color("black").snap(mb, "z", "outside-").midlineTo("x", 33.4).midlineTo("y", 27.18), "lcd");
|
|
2618
|
+
group.add(jscadUtils.parts.Cube([ 55, 40, 3.5 ]).snap(mb, "z", "outside-").translate([ 8, 6, 0 ]).color("white"), "lcdbevel");
|
|
2619
|
+
var buttonBase = jscadUtils.parts.Cube([ 7, 6, 2.5 ]).color("gray");
|
|
2620
|
+
var button = buttonBase.union(jscadUtils.parts.Cylinder(3.1, 1.2).color("black").snap(buttonBase, "z", "outside-").align(buttonBase, "xy")).snap(mb, "z", "outside-");
|
|
2621
|
+
var buttons = [ button.midlineTo("x", 13.97), button.midlineTo("x", 13.97 + 12.7), button.midlineTo("x", 13.97 + 12.7 + 12.7), button.midlineTo("x", 13.97 + 12.7 + 12.7 + 12.7) ];
|
|
2622
|
+
group.add(buttons[0], "button1");
|
|
2623
|
+
group.add(buttons[1], "button2");
|
|
2624
|
+
group.add(buttons[2], "button3");
|
|
2625
|
+
group.add(buttons[3], "button4");
|
|
2626
|
+
return group;
|
|
2627
|
+
}
|
|
2628
|
+
var union = scadApi.booleanOps.union;
|
|
2629
|
+
var debug = jscadUtils.Debug("jscadRPi:PiTFT24");
|
|
2630
|
+
function PiTFT24() {
|
|
2631
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2632
|
+
var pi = arguments.length > 1 ? arguments[1] : undefined;
|
|
2633
|
+
var hiddenPart = true;
|
|
2634
|
+
options = Object.assign(options, {
|
|
2635
|
+
buttonCapHeight: 4,
|
|
2636
|
+
capBaseHeight: 1,
|
|
2637
|
+
buttonWireYOffset: 5,
|
|
2638
|
+
clearance: .9
|
|
2639
|
+
});
|
|
2640
|
+
debug("PiTFT24", options);
|
|
2641
|
+
var hat = Hat(pi);
|
|
2642
|
+
var mb = hat.parts.mb;
|
|
2643
|
+
var group = jscadUtils.Group();
|
|
2644
|
+
group.add(hat.parts.mb, "mb");
|
|
2645
|
+
group.add(hat.parts.gpio, "gpio");
|
|
2646
|
+
group.holes = hat.holes;
|
|
2647
|
+
var sink = 0;
|
|
2648
|
+
var lcd = jscadUtils.parts.Cube([ 50, 40, 3.72 ]).color("black");
|
|
2649
|
+
group.add(lcd.translate(lcd.calcSnap(mb, "xy", "inside-")).translate(lcd.calcSnap(mb, "z", "outside-")).translate([ 7, 0, 0 ]).translate(lcd.calcmidlineTo("y", 28.32)), "lcd");
|
|
2650
|
+
var lcdbevel = jscadUtils.parts.Cube([ 60, 42, 5.3 - 1.62 - sink ]).color("white");
|
|
2651
|
+
group.add(lcdbevel.translate(lcdbevel.calcSnap(mb, "xy", "inside-")).translate(lcdbevel.calcSnap(mb, "z", "outside-")).translate([ 4.5, 7, 0 ]), "lcdbevel");
|
|
2652
|
+
var buttonBase = jscadUtils.parts.Cube([ 6.1, 3.5, 3.55 ]).color("beige").snap(mb, "z", "outside-").snap(mb, "xy", "inside-").midlineTo("y", 2.5);
|
|
2653
|
+
var button = buttonBase.union(jscadUtils.parts.Cube([ 3, 1.5, .5 ]).color("white").snap(buttonBase, "z", "outside-").align(buttonBase, "xy"));
|
|
2654
|
+
var buttons = [ 12.39, 12.39 + 10, 12.39 + 20, 12.39 + 30, 12.39 + 40 ].map(function(midpoint) {
|
|
2655
|
+
return button.midlineTo("x", midpoint);
|
|
2656
|
+
});
|
|
2657
|
+
group.add(jscadUtils.Group("1,2,3,4,5", buttons), "buttons", false, "button");
|
|
2658
|
+
var capBaseHeight = options.capBaseHeight;
|
|
2659
|
+
var buttonCapBase = jscadUtils.parts.Cube([ 6.6, 4, capBaseHeight ]).color("blue");
|
|
2660
|
+
var buttonCapTop = jscadUtils.parts.Cube([ 6.1, 3.5, options.buttonCapHeight - capBaseHeight ]).snap(buttonCapBase, "z", "outside-").align(buttonCapBase, "xy").fillet(1, "z+").color("deepskyblue");
|
|
2661
|
+
var buttonCaps = buttons.map(function(button) {
|
|
2662
|
+
return union([ buttonCapBase, buttonCapTop ]).snap(button, "z", "outside-").align(button, "xy");
|
|
2663
|
+
});
|
|
2664
|
+
group.add(union(buttonCaps), "buttonCaps", hiddenPart);
|
|
2665
|
+
group.add(union(buttonCaps.map(function(button) {
|
|
2666
|
+
return union([ buttonCapBase.align(button, "xy").snap(button, "z", "inside-").enlarge([ options.clearance, options.clearance, 1 ]), jscadUtils.parts.Cube([ 6.1, 3.5, options.buttonCapHeight - capBaseHeight ]).align(button, "xy").snap(button, "z", "inside-").enlarge([ options.clearance, options.clearance, 1 ]) ]);
|
|
2667
|
+
})), "buttonCapClearance", hiddenPart);
|
|
2668
|
+
var bwthickness = options.capBaseHeight;
|
|
2669
|
+
var connector = LeftSide(jscadUtils.parts.Cube([ bwthickness, options.buttonWireYOffset, bwthickness ]), mb).snap(buttonCaps[0], "z", "inside-").snap(buttonCaps[0], "y", "outside+").color("blue");
|
|
2670
|
+
var buttonWire = jscadUtils.parts.Cube([ 40, bwthickness, bwthickness ]).snap(buttonCaps[0], "x", "center-").snap(buttonCaps[0], "z", "inside-").snap(connector, "y", "inside-").color("blue");
|
|
2671
|
+
group.add(union(buttonWire), "buttonWire", hiddenPart);
|
|
2672
|
+
var buttonWireConnector = buttonCaps.map(function(buttonCap) {
|
|
2673
|
+
return connector.align(buttonCap, "x");
|
|
2674
|
+
});
|
|
2675
|
+
group.add(union(buttonWireConnector), "buttonWireConnector", hiddenPart);
|
|
2676
|
+
var buttonWireClearance = union(buttonWireConnector.map(function(connector) {
|
|
2677
|
+
return connector.enlarge([ options.clearance, options.clearance, options.buttonCapHeight ]);
|
|
2678
|
+
})).union(buttonWire.enlarge([ options.clearance, options.clearance, options.buttonCapHeight ])).snap(buttonWire, "z", "inside+").color("red");
|
|
2679
|
+
group.add(buttonWireClearance, "buttonWireClearance", hiddenPart);
|
|
2680
|
+
group.add(jscadUtils.parts.Cube([ 15, 33, 7 ]).snap(mb, "x", "inside-").snap(mb, "z", "outside+").align(mb, "y").color("red"), "gpio2", hiddenPart);
|
|
2681
|
+
return group;
|
|
2682
|
+
}
|
|
2683
|
+
jscadUtils.Debug("jscadRPi:Spacer");
|
|
2684
|
+
function Spacer() {
|
|
2685
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2686
|
+
var mb = arguments.length > 1 ? arguments[1] : undefined;
|
|
2687
|
+
mb = mb || BPlus().parts.mb;
|
|
2688
|
+
options = Object.assign({
|
|
2689
|
+
height: 11,
|
|
2690
|
+
thickness: 1,
|
|
2691
|
+
snap: "outside-",
|
|
2692
|
+
gpio: true,
|
|
2693
|
+
offset: 2,
|
|
2694
|
+
gussetOutside: [ 45, 45 ],
|
|
2695
|
+
gussetInside: [ 40, 40 ],
|
|
2696
|
+
postOnly: false
|
|
2697
|
+
}, options);
|
|
2698
|
+
var spacer = BPlusMounting.pads(mb, {
|
|
2699
|
+
height: options.height,
|
|
2700
|
+
snap: options.snap
|
|
2701
|
+
});
|
|
2702
|
+
var spacers = spacer.combine();
|
|
2703
|
+
if (options.postOnly) return spacers.color("yellow");
|
|
2704
|
+
if (!options.hollow) {
|
|
2705
|
+
var p1 = spacer.parts.pad1.centroid();
|
|
2706
|
+
var p2 = spacer.parts.pad4.centroid();
|
|
2707
|
+
var tri = jscadUtils.triUtils.solve(p1, p2);
|
|
2708
|
+
var dy = Math.sin(jscadUtils.triUtils.toRadians(tri.a)) * 3.5 - 3.5;
|
|
2709
|
+
var dx = 3.5 - Math.cos(jscadUtils.triUtils.toRadians(tri.b + 45)) * 3.5;
|
|
2710
|
+
var x = jscadUtils.parts.Board(tri.C + 5.5, 6.2, 3.1, options.thickness).rotateZ(tri.b).translate([ dx, dy, 0 ]).snap(spacer.parts.pad1, "z", "inside+");
|
|
2711
|
+
var cross = x.union(x.mirroredY().translate([ 0, 56, 0 ])).snap(spacer.parts.pad1, "xy", "inside-").color("red");
|
|
2712
|
+
}
|
|
2713
|
+
var gussetInterior = jscadUtils.parts.Board(options.gussetInside[0], options.gussetInside[1], 3, options.thickness).align(spacers, "xy");
|
|
2714
|
+
var gusset = jscadUtils.parts.Board(options.gussetOutside[0], options.gussetOutside[1], 3, options.thickness).align(spacers, "xy").subtract(gussetInterior).snap(spacer.parts.pad1, "z", "inside+");
|
|
2715
|
+
var gpio = Gpio(mb);
|
|
2716
|
+
var assembly = spacers.union(gusset.unionIf(cross, !options.hollow).translate([ 0, 0, -options.offset ])).subtractIf(gpio.enlarge([ 1, 1, 0 ]), options.gpio);
|
|
2717
|
+
return assembly.color("yellow");
|
|
2718
|
+
}
|
|
2719
|
+
exports.ActiveCoolingFan = activeCoolingFan;
|
|
2720
|
+
exports.BPlus = BPlus;
|
|
2721
|
+
exports.CameraModuleV1 = CameraModuleV1$1;
|
|
2722
|
+
exports.CameraModuleV2 = CameraModuleV1;
|
|
2723
|
+
exports.HQCameraModule = HQCameraModule;
|
|
2724
|
+
exports.Hat = Hat;
|
|
2725
|
+
exports.HatStandoff = HatStandoff;
|
|
2726
|
+
exports.MiniPiTFT = miniPiTFT;
|
|
2727
|
+
exports.PiTFT22 = PiTFT22;
|
|
2728
|
+
exports.PiTFT24 = PiTFT24;
|
|
2729
|
+
exports.Spacer = Spacer;
|
|
2730
|
+
return exports;
|
|
2731
|
+
}({}, jscadUtils, jsCadCSG, scadApi);
|
|
2732
|
+
debug("jscadRPi", jscadRPi);
|
|
2733
|
+
RaspberryPi = jscadRPi;
|
|
2734
|
+
}
|
|
2735
|
+
|
|
2736
|
+
jscadUtilsPluginInit.push(initJscadRPi);
|
|
2737
|
+
// endinject
|