@jscad/web 2.5.10 → 2.6.0
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/CHANGELOG.md +35 -0
- package/README.md +1 -1
- package/dist/jscad-web.min.js +959 -2030
- package/examples/CHANGELOG.md +30 -0
- package/examples/README.md +1 -5
- package/examples/package.json +1 -1
- package/examples/parameters/gear.js +1 -1
- package/locales/README.md +23 -0
- package/locales/de.json +1 -0
- package/locales/en.json +2 -1
- package/locales/fr.json +1 -0
- package/locales/hr.json +1 -0
- package/locales/ja.json +1 -0
- package/locales/zh.json +62 -0
- package/package.json +7 -7
- package/postInstall.js +0 -1
- package/src/index.js +2 -1
- package/src/sideEffects/i18n/index.js +2 -1
- package/src/sideEffects/worker/index.js +7 -8
- package/src/ui/flow/design.js +10 -305
- package/src/ui/flow/reducers.js +304 -0
- package/examples/old/benchmark-cag.jscad +0 -27
- package/examples/old/benchmark-csg.jscad +0 -29
- package/examples/old/benchmark.jscad +0 -25
- package/examples/old/bunch-cubes.jscad +0 -17
- package/examples/old/complex/example001.jscad +0 -31
- package/examples/old/complex/example002.jscad +0 -25
- package/examples/old/complex/example003.jscad +0 -25
- package/examples/old/complex/example004.jscad +0 -16
- package/examples/old/complex/example005.jscad +0 -27
- package/examples/old/complex/globe.js +0 -235
- package/examples/old/complex/iphone4-case.js +0 -213
- package/examples/old/complex/umbilical_torus.js +0 -43
- package/examples/old/complex/umbilical_torus.scad +0 -37
- package/examples/old/core/cncCutout.js +0 -16
- package/examples/old/core/connectors/servo.js +0 -185
- package/examples/old/core/extrusions/extrudeLinear.js +0 -24
- package/examples/old/core/extrusions/extrudeRectangular.js +0 -21
- package/examples/old/core/extrusions/extrudeRotate.js +0 -43
- package/examples/old/core/extrusions/slices/four2three-round.js +0 -62
- package/examples/old/core/extrusions/slices/four2three.js +0 -53
- package/examples/old/core/extrusions/slices/jar-barrel.js +0 -60
- package/examples/old/core/extrusions/slices/jar.js +0 -69
- package/examples/old/core/extrusions/slices/non-aff.js +0 -72
- package/examples/old/core/extrusions/slices/rose.js +0 -52
- package/examples/old/core/extrusions/slices/screw.js +0 -34
- package/examples/old/core/extrusions/slices/screwDouble.js +0 -34
- package/examples/old/core/extrusions/slices/slices.js +0 -43
- package/examples/old/core/extrusions/slices/spring.js +0 -41
- package/examples/old/core/extrusions/slices/three2four.js +0 -42
- package/examples/old/core/extrusions/slices/tor.js +0 -30
- package/examples/old/core/hulls/hullChain.js +0 -58
- package/examples/old/core/lookup.js +0 -19
- package/examples/old/core/platonics/main.jscad +0 -42
- package/examples/old/core/platonics/maths_geodesic.jscad +0 -192
- package/examples/old/core/platonics/origv07/dualdodeca_difference.stl +0 -1962
- package/examples/old/core/platonics/origv07/dualdodeca_intersection.stl +0 -1374
- package/examples/old/core/platonics/origv07/dualdodeca_union.stl +0 -1822
- package/examples/old/core/platonics/origv07/maths_geodesic.scad +0 -162
- package/examples/old/core/platonics/origv07/platonic.scad +0 -483
- package/examples/old/core/platonics/origv07/test_platonic.scad +0 -616
- package/examples/old/core/platonics/platonic.jscad +0 -528
- package/examples/old/core/text/textSimplex.js +0 -625
- package/examples/old/core/transforms/transformations.js +0 -29
- package/examples/old/echo.jscad +0 -7
- package/examples/old/formats/scad/example001.scad +0 -26
- package/examples/old/formats/scad/example002.scad +0 -23
- package/examples/old/formats/scad/example003.scad +0 -20
- package/examples/old/formats/scad/example004.scad +0 -11
- package/examples/old/formats/scad/example005.scad +0 -20
- package/examples/old/json_logo.json +0 -1
- package/examples/old/parameters/axis-coupler.js +0 -149
- package/examples/old/parameters/celtic-knot-ring.js +0 -300
- package/examples/old/parameters/grille.js +0 -257
- package/examples/old/parameters/lamp-shade.js +0 -369
- package/examples/old/parameters/name-plate.js +0 -46
- package/examples/old/parameters/s-hook.js +0 -131
- package/examples/old/parameters/stepper-motor.js +0 -127
- package/examples/old/various/logo.js +0 -32
- package/examples/old/voxel.json +0 -1
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
// title : iPhone 4 Dock
|
|
2
|
-
// author : Joost Nieuwenhuijse
|
|
3
|
-
// license : MIT License
|
|
4
|
-
// description: iPhone 4 dock
|
|
5
|
-
// file : iphone4-case.jscad
|
|
6
|
-
|
|
7
|
-
/*
|
|
8
|
-
|
|
9
|
-
OpenJsCad script for iPhone 4 dock
|
|
10
|
-
Note: not tried printing yet, not sure if it really wil fit.
|
|
11
|
-
|
|
12
|
-
To create the STL file, launch Google Chrome and go to:
|
|
13
|
-
http://joostn.github.com/OpenJsCad/processfile.html or http://openjscad.org
|
|
14
|
-
|
|
15
|
-
Then drag&drop this file into the page
|
|
16
|
-
|
|
17
|
-
OpenJsCad is an open source 3d solid modeling tool using JavaScript.
|
|
18
|
-
For more information see http://joostn.github.com/OpenJsCad
|
|
19
|
-
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
function getParameterDefinitions () {
|
|
23
|
-
return [
|
|
24
|
-
{
|
|
25
|
-
name: 'quality',
|
|
26
|
-
type: 'choice',
|
|
27
|
-
caption: 'Quality:',
|
|
28
|
-
values: ['draft', 'smooth', 'supersmooth'],
|
|
29
|
-
captions: ['Draft (no rounded corners)', 'Smooth (rounded corners)', 'Super smooth (rounded corners)'],
|
|
30
|
-
initial: 'draft'
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
name: 'iphonemargin',
|
|
34
|
-
type: 'float',
|
|
35
|
-
initial: 0.5,
|
|
36
|
-
step: 0.1,
|
|
37
|
-
caption: 'Margin around iphone (in mm):'
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
name: 'plugmargin',
|
|
41
|
-
type: 'float',
|
|
42
|
-
initial: 0.25,
|
|
43
|
-
step: 0.05,
|
|
44
|
-
caption: 'Margin around dock connector (in mm):'
|
|
45
|
-
},
|
|
46
|
-
{name: 'mouseear', caption: 'Add mouse ear:', type: 'choice', values: [0, 1], initial: 1, captions: ['No', 'Yes']}
|
|
47
|
-
];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function main (params) {
|
|
51
|
-
var resolution = 16; // resolution for all the curved surfaces
|
|
52
|
-
var smoothing = (params.quality !== 'draft'); // set to false during development, for fast rendering
|
|
53
|
-
var draft = (params.quality !== 'supersmooth'); // set to false for high resolution smoothing, rendering will take several minutes!
|
|
54
|
-
|
|
55
|
-
var x1 = 40;
|
|
56
|
-
var x2 = 25;
|
|
57
|
-
var x3 = 8;
|
|
58
|
-
var y1 = 35;
|
|
59
|
-
var y2 = y1 + 8;
|
|
60
|
-
var y3 = y2 + 25;
|
|
61
|
-
var frontheight = 30;
|
|
62
|
-
|
|
63
|
-
// Build the base from two 2D polygons:
|
|
64
|
-
var base1 = new CSG.Polygon2D([[0, 0], [x1, 0], [x1, y1], [x2, y2], [0, y2]]);
|
|
65
|
-
var base2 = new CSG.Polygon2D([[0, y2], [x2, y2], [x3, y3], [0, y3]]);
|
|
66
|
-
var extruded1 = base1.extrude({offset: [0, 0, frontheight]});
|
|
67
|
-
var extruded2 = base2.extrude({offset: [0, 0, frontheight]});
|
|
68
|
-
// We now have the right half; mirror to create the left half:
|
|
69
|
-
extruded1 = extruded1.union(extruded1.mirroredX());
|
|
70
|
-
extruded2 = extruded2.union(extruded2.mirroredX());
|
|
71
|
-
var base = extruded1.union(extruded2);
|
|
72
|
-
|
|
73
|
-
// Make the top back surface slightly slanted:
|
|
74
|
-
var backtopplane = CSG.Plane.fromNormalAndPoint([0, 8, 10], [0, y2, frontheight]);
|
|
75
|
-
base = base.cutByPlane(backtopplane);
|
|
76
|
-
|
|
77
|
-
// Make the front surface slightly slanted:
|
|
78
|
-
var frontplane = CSG.Plane.fromNormalAndPoint([0, -10, 2], [0, 0, 0]);
|
|
79
|
-
base = base.cutByPlane(frontplane);
|
|
80
|
-
|
|
81
|
-
// Add a CSG.Connector to the base, at the point where the iphone should
|
|
82
|
-
// rest in the base. The connector's axis points upwards and its normal
|
|
83
|
-
// points towards the front:
|
|
84
|
-
var recessionDepth = 10;
|
|
85
|
-
var distanceFromFront = 20;
|
|
86
|
-
var angle = 15;
|
|
87
|
-
base.properties.iphoneConnector = new CSG.Connector(
|
|
88
|
-
[0, distanceFromFront, frontheight - recessionDepth], // the point
|
|
89
|
-
[0, 0, 1], // axis vector
|
|
90
|
-
[1, 0, 0] // normal vector
|
|
91
|
-
);
|
|
92
|
-
// rotate the base.properties.iphoneConnector, so that the iphone will be tilted:
|
|
93
|
-
var rotmaxtrix = CSG.Matrix4x4.rotation(base.properties.iphoneConnector.point, [1, 0, 0], angle);
|
|
94
|
-
base.properties.iphoneConnector = base.properties.iphoneConnector.transform(rotmaxtrix);
|
|
95
|
-
|
|
96
|
-
// Create iphone placeholder (it's just a cube with the iphone's dimensions):
|
|
97
|
-
var iphoneradius = new CSG.Vector3D(58.6 / 2 + params.iphonemargin, 9.4 / 2 + params.iphonemargin, 115 / 2);
|
|
98
|
-
var iphone = CSG.cube({radius: iphoneradius});
|
|
99
|
-
|
|
100
|
-
// Create the little tab behind the iphone:
|
|
101
|
-
var tabradius = new CSG.Vector3D(15, 5, 12);
|
|
102
|
-
var tab = CSG.cube({radius: tabradius});
|
|
103
|
-
tab = tab.translate([0, (iphoneradius.y + tabradius.y), (-iphoneradius.z + tabradius.z)]);
|
|
104
|
-
|
|
105
|
-
// Add a CSG.Connector to the iphone's properties. This is the place where the
|
|
106
|
-
// 30 pin dock plug will snap in. In this case it is the center of the bottom
|
|
107
|
-
// Z plane of the cube. Since the cube already has 6 predefined connectors
|
|
108
|
-
// at the center of each face, we can just use one of those instead of creating
|
|
109
|
-
// a new CSG.Connector:
|
|
110
|
-
iphone.properties.dockConnector = iphone.properties.cube.facecenters[5];
|
|
111
|
-
|
|
112
|
-
// transform the iphone so it sits in the base:
|
|
113
|
-
var iphoneTransformation = iphone.properties.dockConnector.getTransformationTo(base.properties.iphoneConnector, true, 0);
|
|
114
|
-
iphone = iphone.transform(iphoneTransformation);
|
|
115
|
-
|
|
116
|
-
// transform the tab so it stays behind the iphone:
|
|
117
|
-
tab = tab.transform(iphoneTransformation);
|
|
118
|
-
|
|
119
|
-
// and add the tab to the base:
|
|
120
|
-
base = base.union(tab);
|
|
121
|
-
|
|
122
|
-
// build the iphone plug:
|
|
123
|
-
var plug = getIphoneDockConnector(params.plugmargin, resolution);
|
|
124
|
-
|
|
125
|
-
// The plug has a predefined Connector plug.properties.iphoneConnector
|
|
126
|
-
// To attach the plug to the iphone we connect plug.properties.iphoneConnector
|
|
127
|
-
// to iphone.properties.dockConnector
|
|
128
|
-
plug = plug.connectTo(plug.properties.iphoneConnector,
|
|
129
|
-
iphone.properties.dockConnector, true, 0);
|
|
130
|
-
|
|
131
|
-
// We must make sure we can pull the USB cable through the dock. So there needs
|
|
132
|
-
// to be space for the plug. We just create a tall cube with the size of the USB
|
|
133
|
-
// plug (8 by 40 mm), which will be subtracted from the dock's shape:
|
|
134
|
-
var gapForUsbPlug = CSG.cube({radius: [8, 4, 40]});
|
|
135
|
-
|
|
136
|
-
// Align it to the plug. Again, since gapForUsbPlug is a CSG.cube it already
|
|
137
|
-
// has predefined CSG.Connectors at every face. Connect the Z face to the iphone:
|
|
138
|
-
gapForUsbPlug = gapForUsbPlug.connectTo(gapForUsbPlug.properties.cube.facecenters[5],
|
|
139
|
-
iphone.properties.dockConnector, true, 0);
|
|
140
|
-
|
|
141
|
-
base = base.subtract(iphone);
|
|
142
|
-
|
|
143
|
-
// make the cutout for the cable:
|
|
144
|
-
var cablewidth = 3;
|
|
145
|
-
var cableheight = 4;
|
|
146
|
-
var bottomplane = CSG.Plane.fromNormalAndPoint([0, 0, -1], [0, 0, 0]);
|
|
147
|
-
var cableline = plug.properties.cableConnector.axisLine();
|
|
148
|
-
var cableexitpoint = bottomplane.intersectWithLine(cableline);
|
|
149
|
-
var cableentrypoint = new CSG.Vector3D(0, y3, 0);
|
|
150
|
-
|
|
151
|
-
var cablepath = new CSG.Path2D([[cableentrypoint.x, cableentrypoint.y], [cableexitpoint.x, cableexitpoint.y]], false);
|
|
152
|
-
var cablecutout = cablepath.rectangularExtrude(cablewidth, cableheight, resolution, false);
|
|
153
|
-
|
|
154
|
-
// Smooth the base:
|
|
155
|
-
if (smoothing) {
|
|
156
|
-
base = base.contract(4, draft ? 4 : 16);
|
|
157
|
-
base = base.expand(4, draft ? 4 : 16);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Subtract the connector and cable:
|
|
161
|
-
base = base.subtract(iphone).subtract(plug).subtract(cablecutout).subtract(gapForUsbPlug);
|
|
162
|
-
|
|
163
|
-
// add mouse ear:
|
|
164
|
-
if (params.mouseear === 1) {
|
|
165
|
-
var mouseearpoint = new CSG.Vector3D(0, y3, 0);
|
|
166
|
-
var mouseearthickness = 0.5;
|
|
167
|
-
var mouseearradius = 15;
|
|
168
|
-
var mouseear = CSG.cylinder({
|
|
169
|
-
start: mouseearpoint,
|
|
170
|
-
end: mouseearpoint.plus(new CSG.Vector3D(0, 0, mouseearthickness)),
|
|
171
|
-
radius: mouseearradius,
|
|
172
|
-
resolution: 16
|
|
173
|
-
});
|
|
174
|
-
base = base.union(mouseear);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// center:
|
|
178
|
-
var basecenter = base.getBounds()[0].plus(base.getBounds()[1]).times(0.5);
|
|
179
|
-
base = base.translate(basecenter.negated());
|
|
180
|
-
|
|
181
|
-
return base;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function getIphoneDockConnector (margin, resolution) {
|
|
185
|
-
margin = new CSG.Vector3D(margin);
|
|
186
|
-
var dockConnectorSize = new CSG.Vector3D([26.2, 5.7, 9.5]).plus(margin.times(2));
|
|
187
|
-
var dockConnector = CSG.cube({radius: [(dockConnectorSize.x - dockConnectorSize.y) / 2, dockConnectorSize.y / 2, dockConnectorSize.z / 2]});
|
|
188
|
-
dockConnector = dockConnector.union(CSG.cylinder({
|
|
189
|
-
start: [(dockConnectorSize.x - dockConnectorSize.y) / 2, 0, -dockConnectorSize.z / 2],
|
|
190
|
-
end: [(dockConnectorSize.x - dockConnectorSize.y) / 2, 0, dockConnectorSize.z / 2],
|
|
191
|
-
radius: dockConnectorSize.y / 2,
|
|
192
|
-
resolution: resolution
|
|
193
|
-
}));
|
|
194
|
-
dockConnector = dockConnector.union(CSG.cylinder({
|
|
195
|
-
start: [-(dockConnectorSize.x - dockConnectorSize.y) / 2, 0, -dockConnectorSize.z / 2],
|
|
196
|
-
end: [-(dockConnectorSize.x - dockConnectorSize.y) / 2, 0, dockConnectorSize.z / 2],
|
|
197
|
-
radius: dockConnectorSize.y / 2,
|
|
198
|
-
resolution: resolution
|
|
199
|
-
}));
|
|
200
|
-
var cableTube = CSG.cylinder({
|
|
201
|
-
start: [0, 0, -dockConnectorSize.z / 2 - 5.70 - margin.z],
|
|
202
|
-
end: [0, 0, -dockConnectorSize.z / 2],
|
|
203
|
-
radius: 2.25 + margin.y,
|
|
204
|
-
resolution: resolution
|
|
205
|
-
});
|
|
206
|
-
dockConnector = dockConnector.union(cableTube);
|
|
207
|
-
|
|
208
|
-
// Add CSG.Connector properties:
|
|
209
|
-
dockConnector.properties.iphoneConnector = dockConnector.properties.cube.facecenters[4];
|
|
210
|
-
dockConnector.properties.cableConnector = cableTube.properties.cylinder.start;
|
|
211
|
-
|
|
212
|
-
return dockConnector;
|
|
213
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// title : Umbilical Torus generator
|
|
2
|
-
// author : Bruce Mueller
|
|
3
|
-
// license : Creative Commons CC BY-SA
|
|
4
|
-
// description: adapted for OpenJSCAD.org by Rene K. Mueller
|
|
5
|
-
// date: : 2013/03/30
|
|
6
|
-
// file : hull.jscad
|
|
7
|
-
|
|
8
|
-
// inc = incremental segments
|
|
9
|
-
// r = radius of circle
|
|
10
|
-
// t = 'radius' of triangle -distance from center to vertex
|
|
11
|
-
// a = angle of rotation of triangle
|
|
12
|
-
// b = angle rotation around center of circle
|
|
13
|
-
|
|
14
|
-
function tri (r, t, a, b) { return [(r + t * sin(a)) * cos(b), (r + t * sin(a)) * sin(b), t * cos(a)]; }
|
|
15
|
-
|
|
16
|
-
// module to generate a rotated triangle slice, inc degrees wide
|
|
17
|
-
// (could not implement this in the for loop below)
|
|
18
|
-
|
|
19
|
-
function wedge (r, t, i, inc) {
|
|
20
|
-
var a1 = tri(r, t, i / 3, i);
|
|
21
|
-
var b1 = tri(r, t, 120 + i / 3, i);
|
|
22
|
-
var c1 = tri(r, t, 240 + i / 3, i);
|
|
23
|
-
j = i + inc;
|
|
24
|
-
var a2 = tri(r, t, j / 3, j);
|
|
25
|
-
var b2 = tri(r, t, 120 + j / 3, j);
|
|
26
|
-
var c2 = tri(r, t, 240 + j / 3, j);
|
|
27
|
-
|
|
28
|
-
return polyhedron({
|
|
29
|
-
points: [a1, b1, c1, a2, b2, c2],
|
|
30
|
-
triangles: [ [0, 1, 2], [5, 4, 3], [3, 4, 0], [1, 0, 4], [3, 0, 2], [3, 2, 5], [5, 2, 4], [4, 2, 1] ] });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// created a conjoined set of triangular wedges around the circle
|
|
34
|
-
|
|
35
|
-
function main () {
|
|
36
|
-
var inc = 10;
|
|
37
|
-
var o = [];
|
|
38
|
-
|
|
39
|
-
for (var i = 0; i < 360; i += inc) {
|
|
40
|
-
o.push(wedge(2, 1, i, inc));
|
|
41
|
-
}
|
|
42
|
-
return union(o).scale(10); // would be more effectice & suitable to create just one polyhedron
|
|
43
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// Umbilical Torus generator, by Bruce Mueller 2013/03/30 CC-BY-SA
|
|
2
|
-
// inc = incremental segments
|
|
3
|
-
|
|
4
|
-
inc=5;
|
|
5
|
-
// r = radius of circle
|
|
6
|
-
// t = 'radius' of triangle -distance from center to vertex
|
|
7
|
-
// a = angle of rotation of triangle
|
|
8
|
-
// b = angle rotation around center of circle
|
|
9
|
-
|
|
10
|
-
function tri(r,t,a,b) = [(r + t*sin(a))*cos(b), (r+ t*sin(a))*sin(b), t*cos(a)];
|
|
11
|
-
|
|
12
|
-
// module to generate a rotated triangle slice, inc degrees wide
|
|
13
|
-
// (could not implement this in the for loop below)
|
|
14
|
-
|
|
15
|
-
module wedge(r,t,i,inc) {
|
|
16
|
-
a1 = tri(r,t,i/3,i);
|
|
17
|
-
b1 = tri(r,t,120+i/3,i);
|
|
18
|
-
c1 = tri(r,t,240+i/3,i);
|
|
19
|
-
j=i+inc;
|
|
20
|
-
a2 = tri(r,t,j/3,j);
|
|
21
|
-
b2 = tri(r,t,120+j/3,j);
|
|
22
|
-
c2 = tri(r,t,240+j/3,j);
|
|
23
|
-
|
|
24
|
-
polyhedron(
|
|
25
|
-
points=[a1,b1,c1,a2,b2,c2],
|
|
26
|
-
triangles=[ [0,1,2], [5,4,3],
|
|
27
|
-
[3,4,0], [1,0,4],
|
|
28
|
-
[3,0,2], [3,2,5],
|
|
29
|
-
[5,2,4], [4,2,1] ] );
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// created a conjoined set of triangular wedges around the circle
|
|
34
|
-
|
|
35
|
-
for (i=[0:inc:360-inc]) {
|
|
36
|
-
wedge(2,1,i,inc);
|
|
37
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// title : CNC Corner Cutout
|
|
2
|
-
// author : Jeff Gay
|
|
3
|
-
// license : MIT License
|
|
4
|
-
// revision : 0.0.1
|
|
5
|
-
// tags : 2d,cnc
|
|
6
|
-
// file : cnc-cutout.jscad
|
|
7
|
-
|
|
8
|
-
function main () {
|
|
9
|
-
var r1 = CAG.rectangle({center: [0, 0], radius: 4});
|
|
10
|
-
var r2 = CAG.rectangle({center: [2, 0], radius: 2});
|
|
11
|
-
var r3 = r1.subtract(r2);
|
|
12
|
-
var cutterradius = 0.5;
|
|
13
|
-
var r4 = r3.overCutInsideCorners(cutterradius);
|
|
14
|
-
|
|
15
|
-
return [r3.translate([0, 10]), r4];
|
|
16
|
-
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
// title : Servo Motor
|
|
2
|
-
// author : Joost Nieuwenhuijse
|
|
3
|
-
// license : MIT License
|
|
4
|
-
// description: a servo motor design
|
|
5
|
-
// file : servo.js
|
|
6
|
-
|
|
7
|
-
// This demo intends to show how to use properties and connectors.
|
|
8
|
-
// The servoMotor() function constructs the shape of a standard servo
|
|
9
|
-
// It also defines a property for the cutout shape, and a connector property
|
|
10
|
-
// which can be used to correctly attach the motor to a surface.
|
|
11
|
-
//
|
|
12
|
-
// By using connectors, we don't need to know the actual orientation of each
|
|
13
|
-
// object. Instead we just attach the two objects by attaching their connectors.
|
|
14
|
-
//
|
|
15
|
-
// The cutout shape is automatically transformed with every transformation of
|
|
16
|
-
// the servo. We can simply subtract it from an object to make space for the servo
|
|
17
|
-
// motor.
|
|
18
|
-
|
|
19
|
-
// TODO Determine if/how connectors work with no object properties.
|
|
20
|
-
|
|
21
|
-
const jscad = require('@jscad/modeling')
|
|
22
|
-
console.log(jscad)
|
|
23
|
-
const { curves, maths, extrusions, primitives, transforms, booleans } = jscad
|
|
24
|
-
const { bezier } = curves
|
|
25
|
-
const { slice } = extrusions
|
|
26
|
-
const { cuboid, cylinder } = primitives
|
|
27
|
-
const { translate } = transforms
|
|
28
|
-
const { union, subtract } = booleans
|
|
29
|
-
|
|
30
|
-
const main = (params) => {
|
|
31
|
-
// the servo motor solid:
|
|
32
|
-
var servo = servoMotor()
|
|
33
|
-
return servo
|
|
34
|
-
// the plate:
|
|
35
|
-
var plate = cuboid({ size: [40, 40, 4] })
|
|
36
|
-
|
|
37
|
-
// Define a Connector on the plate, at the place where we want to attach the servo:
|
|
38
|
-
plate.properties.servoConnector = new CSG.Connector(
|
|
39
|
-
[0, 0, 4], // point
|
|
40
|
-
[0, 0, 1], // axis: pointing upwards
|
|
41
|
-
[2.5, 1.1, 0] // normal: use some random vector in the z plane
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
// Do some random rotations:
|
|
45
|
-
plate = plate.rotateX(25)
|
|
46
|
-
plate = plate.rotateZ(10)
|
|
47
|
-
// now we really don't know the orientation of the plane anymore!
|
|
48
|
-
|
|
49
|
-
// Still we can perfectly align the servo motor to the plane at the servoConnector
|
|
50
|
-
// point that we decided on earlier:
|
|
51
|
-
servo = servo.connectTo(
|
|
52
|
-
servo.properties.servomotor.surfaceConnector, // the servo's pre defined Connector
|
|
53
|
-
plate.properties.servoConnector, // the connector on the surface
|
|
54
|
-
false, // we don't want to mirror; the Connector's axes should point in the same direction
|
|
55
|
-
0 // normalrotation; we could use it to rotate the servo in the plane
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
// Construct the result; use the parameters set by the end user:
|
|
59
|
-
var result = new CSG()
|
|
60
|
-
if (params.cutout === 1) plate = plate.subtract(servo.properties.servomotor.cutout)
|
|
61
|
-
if (params.showplate === 1) result = result.union(plate)
|
|
62
|
-
if (params.showservo === 1) result = result.union(servo)
|
|
63
|
-
if (params.showcutout === 1) result = result.union(servo.properties.servomotor.cutout.setColor(0, 0.8, 0))
|
|
64
|
-
|
|
65
|
-
return result
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Here we define the user editable parameters:
|
|
69
|
-
|
|
70
|
-
function getParameterDefinitions () {
|
|
71
|
-
return [
|
|
72
|
-
{ name: 'showservo', caption: 'Show servo:', type: 'choice', values: [0, 1], initial: 1, captions: ['No', 'Yes'] },
|
|
73
|
-
{ name: 'showplate', caption: 'Show plate:', type: 'choice', values: [0, 1], initial: 1, captions: ['No', 'Yes'] },
|
|
74
|
-
{ name: 'showcutout', caption: 'Show cutout:', type: 'choice', values: [0, 1], initial: 0, captions: ['No', 'Yes'] },
|
|
75
|
-
{ name: 'cutout', caption: 'Subtract the servo cutout shape from the plate:', type: 'choice', values: [0, 1], initial: 1, captions: ['No', 'Yes'] }
|
|
76
|
-
]
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// The servoMotor() function constructs the shape of a standard '3003' servo
|
|
80
|
-
// Returns a CSG solid. The solid has the following additional properties:
|
|
81
|
-
// .properties.servomotor.cutout: a CSG solid that can be used to create a cutout for the servo motor (including screw holes)
|
|
82
|
-
// .properties.servomotor.surfaceConnector: a CSG.Connector that can be used to attach the servo motor to a surface
|
|
83
|
-
|
|
84
|
-
function servoMotor () {
|
|
85
|
-
const bodyWidth = 20
|
|
86
|
-
const bodyLength = 40.5
|
|
87
|
-
const heightToTabs = 26.5
|
|
88
|
-
const tabsHeight = 2.5
|
|
89
|
-
const bodyHeight = 35.9
|
|
90
|
-
const tabsLength = 55.4
|
|
91
|
-
const tabsWidth = 17.8
|
|
92
|
-
const holeRadius = 2.1
|
|
93
|
-
const holeXOffset = 2 * 2.54
|
|
94
|
-
const holeYOffset = 9.5 * 2.54
|
|
95
|
-
const cutOutMargin = 1
|
|
96
|
-
const shaftRadius = 3
|
|
97
|
-
const shaftY = 9.25
|
|
98
|
-
const shaftHeight = 4
|
|
99
|
-
const cyl2radius = 7
|
|
100
|
-
const gearHousingHeight = 2
|
|
101
|
-
|
|
102
|
-
const resolution = 16 // for all circular objects
|
|
103
|
-
|
|
104
|
-
// servoMotor: this is the solid in which we will store the servomotor
|
|
105
|
-
let servoMotor = translate(
|
|
106
|
-
[0, 0, bodyHeight / 2],
|
|
107
|
-
cuboid({ size: [bodyWidth, bodyLength, bodyHeight] })
|
|
108
|
-
)
|
|
109
|
-
// console.log(servoMotor); return servoMotor
|
|
110
|
-
|
|
111
|
-
// cutout: this is the solid for the cutout. It is never rendered directly,
|
|
112
|
-
// but it will be returned as a property of the resulting solid.
|
|
113
|
-
// it can be used to cutout the shape of the servo motor and screw holes
|
|
114
|
-
// from another solid
|
|
115
|
-
var cutout = translate(
|
|
116
|
-
[0, 0, (bodyHeight / 2) + cutOutMargin],
|
|
117
|
-
cuboid({ size: [bodyWidth + (2 * cutOutMargin), bodyLength + (2 * cutOutMargin), bodyHeight + (2 * cutOutMargin)] })
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
// add a 'bottomface' property. Since the cube already has predefined connectors at each face,
|
|
121
|
-
// we can just copy the 5th:
|
|
122
|
-
// servoMotor.properties.servomotor = new CSG.Properties()
|
|
123
|
-
// servoMotor.properties.servomotor.bottomface = servoMotor.properties.cube.facecenters[5]
|
|
124
|
-
|
|
125
|
-
// the tabs at the end containing the screw holes:
|
|
126
|
-
let servoTabs = cuboid({ size: [tabsWidth, tabsLength, tabsHeight] })
|
|
127
|
-
servoTabs = translate([0, 0, (tabsHeight / 2) + heightToTabs], servoTabs)
|
|
128
|
-
servoMotor = union(servoMotor, servoTabs)
|
|
129
|
-
|
|
130
|
-
// servoMotor = cuboid({ size: [1,1,1] })
|
|
131
|
-
// create the cylinders for cutting out the screw holes:
|
|
132
|
-
for (let hole = 0; hole < 4; hole++) {
|
|
133
|
-
const xoffset = (hole & 1) ? holeXOffset : -holeXOffset
|
|
134
|
-
const yoffset = (hole & 2) ? holeYOffset : -holeYOffset
|
|
135
|
-
// let cylstart = [xoffset, yoffset, bottomZ + h2]
|
|
136
|
-
// let cylend = [xoffset, yoffset, bottomZ]
|
|
137
|
-
const cutoutcylinder = translate([xoffset, yoffset, tabsHeight / 2 + heightToTabs],
|
|
138
|
-
cylinder({ height: tabsHeight, radius: holeRadius, segments: resolution })
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
// create the screw hole in the tabs:
|
|
142
|
-
servoMotor = subtract(servoMotor, cutoutcylinder)
|
|
143
|
-
|
|
144
|
-
// And also add the cutout cylinder to the cutout shape:
|
|
145
|
-
cutout = union(cutoutcylinder, cutout)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// cylinder at top:
|
|
149
|
-
var gearHousing = translate(
|
|
150
|
-
[0,shaftY,gearHousingHeight / 2 + bodyHeight],
|
|
151
|
-
cylinder({ height: gearHousingHeight, radius: cyl2radius, resolution: resolution })
|
|
152
|
-
)
|
|
153
|
-
servoMotor = union(servoMotor,gearHousing)
|
|
154
|
-
|
|
155
|
-
// make the entire motor grey:
|
|
156
|
-
// servoMotor = servoMotor.setColor(0.2, 0.2, 0.2)
|
|
157
|
-
|
|
158
|
-
// create the shaft:
|
|
159
|
-
// p1 = new CSG.Vector3D([0, shaftY, bottomZ + bodyHeight])
|
|
160
|
-
// p2 = p1.plus(new CSG.Vector3D([0, 0, gearHousingHeight]))
|
|
161
|
-
var shaft = translate(
|
|
162
|
-
[0, shaftY, shaftHeight / 2 + bodyHeight + gearHousingHeight],
|
|
163
|
-
cylinder({height: shaftHeight, radius: shaftRadius, segments: resolution })
|
|
164
|
-
)
|
|
165
|
-
servoMotor = union(shaft, servoMotor)
|
|
166
|
-
|
|
167
|
-
// add the cutout solid to the properties:
|
|
168
|
-
// servoMotor.properties.cutout = 2
|
|
169
|
-
|
|
170
|
-
return servoMotor
|
|
171
|
-
|
|
172
|
-
// Add a Connector to facilitate proper alignment of the servo motor to a surface
|
|
173
|
-
// - The connector's point is at the x/y center of the box, in the bottom plane of the tabs
|
|
174
|
-
// - The connector's axis points towards the top of the box
|
|
175
|
-
// - The connector's normal points towards one of the tabs at the side
|
|
176
|
-
// servoMotor.properties.servomotor.surfaceConnector = new CSG.Connector(
|
|
177
|
-
// [0, 0, bottomZ + heightToTabs], // point
|
|
178
|
-
// [0, 0, 1], // axis
|
|
179
|
-
// [0, 1, 0] // normal
|
|
180
|
-
// )
|
|
181
|
-
|
|
182
|
-
// return servoMotor
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
module.exports = { main, getParameterDefinitions }
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/* title : Linear Extrude
|
|
2
|
-
// author : Rene K. Mueller
|
|
3
|
-
// license : MIT License
|
|
4
|
-
// description: testing extrudeLinear() function
|
|
5
|
-
// tags: extrusion, linear, extrudeLinear
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const { rectangle, circle, polygon } = require('@jscad/modeling').primitives
|
|
9
|
-
const { translate, scale } = require('@jscad/modeling').transforms
|
|
10
|
-
const { extrudeLinear } = require('@jscad/modeling').extrusions
|
|
11
|
-
|
|
12
|
-
const main = () => {
|
|
13
|
-
return [
|
|
14
|
-
scale(3, extrudeLinear({ height: 10 }, circle({ r: 1, fn: 5, center: true }))),
|
|
15
|
-
scale(3, extrudeLinear({ height: 10, twist: 90 }, rectangle({ size: [1, 2], center: true }))
|
|
16
|
-
.translate([0, 5, 0])),
|
|
17
|
-
scale(3, extrudeLinear({ height: 10, twist: -500, slices: 50 }, translate([2, 0, 0], circle({ r: 1, fn: 8, center: true })))
|
|
18
|
-
.translate([0, -6, 0])),
|
|
19
|
-
scale(3, extrudeLinear({ height: 20, twist: -90, center: true }, polygon([[0, 0], [4, 1], [1, 1], [1, 4]]))
|
|
20
|
-
.translate([0, -13, 0]))
|
|
21
|
-
]
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
module.exports = { main }
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/* title : Rectangular Extrude
|
|
2
|
-
// authors : Rene K. Mueller
|
|
3
|
-
// license : MIT License
|
|
4
|
-
// description: testing extrudeRectangular() function
|
|
5
|
-
// tags: extrusion, rectangular, extrudeRectangular
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const { rectangle, circle, polygon } = require('@jscad/modeling').primitives
|
|
9
|
-
const { translate } = require('@jscad/modeling').transforms
|
|
10
|
-
const { extrudeRectangular } = require('@jscad/modeling').extrusions
|
|
11
|
-
|
|
12
|
-
const main = () => {
|
|
13
|
-
return [
|
|
14
|
-
extrudeRectangular([[0, 0], [10, 0], [5, 10], [0, 10]], { corners: 'chamfer' }),
|
|
15
|
-
translate([0, 15, 0],
|
|
16
|
-
extrudeRectangular([[0, 0], [10, 0], [5, 10], [0, 10]], { segments: 8, corners: 'round' })
|
|
17
|
-
)
|
|
18
|
-
]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = { main }
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/* title : Rotate Extrude
|
|
2
|
-
// author : Rene K. Mueller
|
|
3
|
-
// license : MIT License
|
|
4
|
-
// description: testing extrudeRotate() function
|
|
5
|
-
// tags: extrusion, rotate, extrudeRotate
|
|
6
|
-
*/
|
|
7
|
-
const jscad = require('@jscad/modeling')
|
|
8
|
-
console.log(jscad)
|
|
9
|
-
const { rectangle, circle, polygon, star } = jscad.primitives
|
|
10
|
-
const { translate } = jscad.transforms
|
|
11
|
-
const { extrudeRotate } = jscad.extrusions
|
|
12
|
-
|
|
13
|
-
const main = () => {
|
|
14
|
-
return [
|
|
15
|
-
|
|
16
|
-
// smooth torus
|
|
17
|
-
translate([5, 5, 0], extrudeRotate(
|
|
18
|
-
{ segments: 32 },
|
|
19
|
-
polygon({points: [[1,0],[3,0],[3,1],[2.2,1],[1.6,2.2],[2,8], [1,8]], closed: true})
|
|
20
|
-
)),
|
|
21
|
-
|
|
22
|
-
// Pentagonal ring
|
|
23
|
-
translate([5, -5, 0], extrudeRotate(
|
|
24
|
-
{ segments: 5 },
|
|
25
|
-
translate([4, 0, 0], circle({ radius: 1, segments: 32 }))
|
|
26
|
-
)),
|
|
27
|
-
|
|
28
|
-
// Shooting star
|
|
29
|
-
translate([-5, -5, 0], extrudeRotate(
|
|
30
|
-
{ segments: 32, startAngle: 0, angle: (Math.PI * 0.75), overflow: 'cap' },
|
|
31
|
-
translate([4, 0, 0], star({ }))
|
|
32
|
-
)),
|
|
33
|
-
|
|
34
|
-
// Octagonol box
|
|
35
|
-
translate([-5, 5, 0], extrudeRotate(
|
|
36
|
-
{ segments: 8 },
|
|
37
|
-
translate([4, 0, 0], rectangle({ size: [1, 3] }))
|
|
38
|
-
))
|
|
39
|
-
|
|
40
|
-
]
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
module.exports = { main }
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
// title: Four to three (sides)
|
|
3
|
-
// author: Eduard Bespalov
|
|
4
|
-
// license: MIT License
|
|
5
|
-
// description: testing solidFromSlices()
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// TODO the code this demonstrates does not seem to exist any more.
|
|
9
|
-
|
|
10
|
-
const { geom2, geom3, line2, path2, poly3 } = require('@jscad/modeling').geometry
|
|
11
|
-
const { extrudeFromSlices } = require('@jscad/modeling').operations
|
|
12
|
-
|
|
13
|
-
const getParameterDefinitions = () => {
|
|
14
|
-
return [
|
|
15
|
-
{ name: 'radius', caption: 'Radius:', type: 'float', default: 10 },
|
|
16
|
-
{ name: 'height', caption: 'Height:', type: 'float', default: 35 },
|
|
17
|
-
{ name: 'twist', caption: 'Twist:', type: 'int', default: 90 }
|
|
18
|
-
]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const main = (params) => {
|
|
22
|
-
var thing = thingTwisted(params.radius, params.height, params.twist)
|
|
23
|
-
return thing
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function thingTwisted (radius, height, twistangle) {
|
|
27
|
-
const resolution = 16
|
|
28
|
-
twistangle = twistangle || 0
|
|
29
|
-
|
|
30
|
-
var cag = geom2.fromPoints([
|
|
31
|
-
[-radius, -radius, 0],
|
|
32
|
-
[radius, -radius, 0],
|
|
33
|
-
[radius, radius, 0]
|
|
34
|
-
]).expand(2, resolution)
|
|
35
|
-
|
|
36
|
-
var flatBottom = poly3.fromPoints(
|
|
37
|
-
cag.getOutlinePaths()[0].points
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
var thing = flatBottom.solidFromSlices({
|
|
41
|
-
numslices: height,
|
|
42
|
-
callback: function (t) {
|
|
43
|
-
var coef = 1 - t
|
|
44
|
-
if (coef < 0.01) coef = 0.01// must not collapse polygon
|
|
45
|
-
var h = height * t
|
|
46
|
-
var cag = geom2.fromPoints([
|
|
47
|
-
[-radius, -radius, h],
|
|
48
|
-
[radius, -radius, h],
|
|
49
|
-
[radius * coef, radius, h],
|
|
50
|
-
[-radius * coef, radius, h]
|
|
51
|
-
]).expand(2, resolution)
|
|
52
|
-
.rotate([0, 0, 0], [0, 0, 1], twistangle * t)
|
|
53
|
-
|
|
54
|
-
return poly3.fromPoints(
|
|
55
|
-
cag.getOutlinePaths()[0].points
|
|
56
|
-
).translate([0, 0, h])
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
return thing
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
module.exports = { main, getParameterDefinitions }
|