@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,149 +0,0 @@
|
|
|
1
|
-
// title : Axis Coupler
|
|
2
|
-
// author : Joost Nieuwenhuijse
|
|
3
|
-
// license : MIT License
|
|
4
|
-
// revision : 0.02
|
|
5
|
-
// description: a simple axis coupler
|
|
6
|
-
// file : axis-coupler.jscad
|
|
7
|
-
|
|
8
|
-
var cylresolution = 16
|
|
9
|
-
|
|
10
|
-
// Here we define the user editable parameters:
|
|
11
|
-
const getParameterDefinitions = () => {
|
|
12
|
-
return [
|
|
13
|
-
{ name: 'general', caption: 'General', type: 'group' },
|
|
14
|
-
{ name: 'quality', type: 'choice', caption: 'Quality', values: [0, 1], captions: ['Draft', 'High'], initial: 0 },
|
|
15
|
-
{ name: 'outerdiameter', caption: 'Outer diameter:', type: 'float', initial: 30 },
|
|
16
|
-
{ name: 'numteeth', caption: 'Num teeth per coupler:', type: 'int', initial: 2 },
|
|
17
|
-
{ name: 'coupler1', caption: 'First Coupler', type: 'group' },
|
|
18
|
-
{ name: 'diameter1', caption: 'Axis diameter:', type: 'float', initial: 12.2, step: 0.1 },
|
|
19
|
-
{ name: 'shaftlength1', caption: 'Axis depth:', type: 'float', initial: 15, step: 0.1 },
|
|
20
|
-
{ name: 'outerlength1', caption: 'Outer length:', type: 'float', initial: 20, step: 0.1 },
|
|
21
|
-
{ name: 'nutradius1', caption: 'Nut radius:', type: 'float', initial: 4.6, step: 0.1 },
|
|
22
|
-
{ name: 'nutthickness1', caption: 'Nut thickness:', type: 'float', initial: 4.2, step: 0.1 },
|
|
23
|
-
{ name: 'screwdiameter1', caption: 'Screw diameter:', type: 'float', initial: 5, step: 0.1 },
|
|
24
|
-
{ name: 'coupler2', caption: 'Second Coupler', type: 'group' },
|
|
25
|
-
{ name: 'diameter2', caption: 'Axis diameter:', type: 'float', initial: 9.5, step: 0.1 },
|
|
26
|
-
{ name: 'shaftlength2', caption: 'Axis depth:', type: 'float', initial: 10, step: 0.1 },
|
|
27
|
-
{ name: 'outerlength2', caption: 'Outer length:', type: 'float', initial: 15, step: 0.1 },
|
|
28
|
-
{ name: 'nutradius2', caption: 'Nut radius:', type: 'float', initial: 3.2, step: 0.1 },
|
|
29
|
-
{ name: 'nutthickness2', caption: 'Nut thickness:', type: 'float', initial: 2.6, step: 0.1 },
|
|
30
|
-
{ name: 'screwdiameter2', caption: 'Screw diameter:', type: 'float', initial: 3, step: 0.1 },
|
|
31
|
-
{ name: 'spider', caption: 'Spider Coupler', type: 'group' },
|
|
32
|
-
{ name: 'spiderlength', caption: 'Thickness:', type: 'float', initial: 12 },
|
|
33
|
-
{ name: 'spidermargin', caption: 'Tolerance:', type: 'float', initial: 0, min: 0.0, max: 1.0, step: 0.1 }
|
|
34
|
-
]
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const main = (params) => {
|
|
38
|
-
cylresolution = (params.quality === '1') ? 64 : 16
|
|
39
|
-
|
|
40
|
-
var outerdiameter = params.outerdiameter
|
|
41
|
-
outerdiameter = Math.max(outerdiameter, params.diameter1 + 0.5)
|
|
42
|
-
outerdiameter = Math.max(outerdiameter, params.diameter2 + 0.5)
|
|
43
|
-
|
|
44
|
-
var spidercenterdiameter = outerdiameter / 2
|
|
45
|
-
|
|
46
|
-
var part1 = makeShaft(params.diameter1, outerdiameter, spidercenterdiameter, params.shaftlength1, params.outerlength1, params.spiderlength, params.nutradius1, params.nutthickness1, params.screwdiameter1, params.numteeth)
|
|
47
|
-
var part2 = makeShaft(params.diameter2, outerdiameter, spidercenterdiameter, params.shaftlength2, params.outerlength2, params.spiderlength, params.nutradius2, params.nutthickness2, params.screwdiameter2, params.numteeth)
|
|
48
|
-
var spider = makeSpider(outerdiameter, spidercenterdiameter, params.spiderlength, params.numteeth)
|
|
49
|
-
|
|
50
|
-
if (params.spidermargin > 0) {
|
|
51
|
-
spider = spider.contract(params.spidermargin, 4)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// rotate shaft parts for better 3d printing:
|
|
55
|
-
part1 = part1.rotateX(180).translate([0, 0, params.outerlength1 + params.spiderlength])
|
|
56
|
-
part2 = part2.rotateX(180).translate([0, 0, params.outerlength2 + params.spiderlength])
|
|
57
|
-
|
|
58
|
-
var result = []
|
|
59
|
-
result.push(part1.translate([-outerdiameter - 5, 0, 0]))
|
|
60
|
-
result.push(part2.translate([0, 0, 0]))
|
|
61
|
-
result.push(spider.translate([outerdiameter + 5, 0, -params.spidermargin]))
|
|
62
|
-
return result
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function makeShaft (innerdiameter, outerdiameter, spidercenterdiameter, shaftlength, outerlength, spiderlength, nutradius, nutthickness, screwdiameter, numteeth) {
|
|
66
|
-
var result = CSG.cylinder({ start: [0, 0, 0], end: [0, 0, outerlength], radius: outerdiameter / 2, resolution: cylresolution })
|
|
67
|
-
|
|
68
|
-
for (var i = 0; i < numteeth; i++) {
|
|
69
|
-
var angle = i * 360 / numteeth
|
|
70
|
-
var pie = makePie(outerdiameter / 2, spiderlength, angle - 45 / numteeth, angle + 45 / numteeth)
|
|
71
|
-
pie = pie.translate([0, 0, outerlength])
|
|
72
|
-
result = result.union(pie)
|
|
73
|
-
}
|
|
74
|
-
var spidercylinder = CSG.cylinder({ start: [0, 0, outerlength], end: [0, 0, outerlength + spiderlength], radius: spidercenterdiameter / 2, resolution: cylresolution })
|
|
75
|
-
result = result.subtract(spidercylinder)
|
|
76
|
-
var shaftcylinder = CSG.cylinder({ start: [0, 0, 0], end: [0, 0, shaftlength], radius: innerdiameter / 2, resolution: cylresolution })
|
|
77
|
-
result = result.subtract(shaftcylinder)
|
|
78
|
-
|
|
79
|
-
var screwz = shaftlength / 2
|
|
80
|
-
if (screwz < nutradius) screwz = nutradius
|
|
81
|
-
var nutcutout = hexagon(nutradius, nutthickness).translate([0, 0, -nutthickness / 2])
|
|
82
|
-
var grubnutradiusAtFlatSide = nutradius * Math.cos(Math.PI / 180 * 30)
|
|
83
|
-
var nutcutoutrectangle = CSG.cube({
|
|
84
|
-
radius: [outerlength / 2, grubnutradiusAtFlatSide, nutthickness / 2],
|
|
85
|
-
center: [outerlength / 2, 0, 0]
|
|
86
|
-
})
|
|
87
|
-
nutcutout = nutcutout.union(nutcutoutrectangle)
|
|
88
|
-
nutcutout = nutcutout.rotateY(90)
|
|
89
|
-
nutcutout = nutcutout.translate([(outerdiameter + innerdiameter) / 4, 0, screwz])
|
|
90
|
-
result = result.subtract(nutcutout)
|
|
91
|
-
|
|
92
|
-
var screwcutout = CSG.cylinder({
|
|
93
|
-
start: [outerdiameter / 2, 0, screwz],
|
|
94
|
-
end: [0, 0, screwz],
|
|
95
|
-
radius: screwdiameter / 2,
|
|
96
|
-
resolution: cylresolution
|
|
97
|
-
})
|
|
98
|
-
result = result.subtract(screwcutout)
|
|
99
|
-
return result
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function makePie (radius, height, startangle, endangle) {
|
|
103
|
-
var absangle = Math.abs(startangle - endangle)
|
|
104
|
-
if (absangle >= 180) {
|
|
105
|
-
throw new Error('Pie angle must be less than 180 degrees')
|
|
106
|
-
}
|
|
107
|
-
var numsteps = cylresolution * absangle / 360
|
|
108
|
-
if (numsteps < 1) numsteps = 1
|
|
109
|
-
var points = []
|
|
110
|
-
for (var i = 0; i <= numsteps; i++) {
|
|
111
|
-
var angle = startangle + i / numsteps * (endangle - startangle)
|
|
112
|
-
var vec = CSG.Vector2D.fromAngleDegrees(angle).times(radius)
|
|
113
|
-
points.push(vec)
|
|
114
|
-
}
|
|
115
|
-
points.push(new CSG.Vector2D(0, 0))
|
|
116
|
-
var shape2d = new CSG.Polygon2D(points)
|
|
117
|
-
// direction for extrusion
|
|
118
|
-
var extruded = shape2d.extrude({ offset: [0, 0, height] })
|
|
119
|
-
return extruded
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function hexagon (radius, height) {
|
|
123
|
-
var vertices = []
|
|
124
|
-
for (var i = 0; i < 6; i++) {
|
|
125
|
-
var point = CSG.Vector2D.fromAngleDegrees(-i * 60).times(radius).toVector3D(0)
|
|
126
|
-
vertices.push(new CSG.Vertex(point))
|
|
127
|
-
}
|
|
128
|
-
var polygon = new CSG.Polygon(vertices)
|
|
129
|
-
var hex = polygon.extrude([0, 0, height])
|
|
130
|
-
return hex
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function makeSpider (outerdiameter, spidercenterdiameter, spiderlength, numteeth) {
|
|
134
|
-
var result = new CSG()
|
|
135
|
-
var numspiderteeth = numteeth * 2 // spider has twice the number of teeth
|
|
136
|
-
for (var i = 0; i < numspiderteeth; i++) {
|
|
137
|
-
var angle = i * 360 / numspiderteeth
|
|
138
|
-
var pie = makePie(outerdiameter / 2, spiderlength, angle - 90 / numspiderteeth, angle + 90 / numspiderteeth)
|
|
139
|
-
pie = pie.translate([0, 0, 0])
|
|
140
|
-
result = result.union(pie)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
var centercylinder = CSG.cylinder({ start: [0, 0, 0], end: [0, 0, spiderlength], radius: spidercenterdiameter / 2, resolution: cylresolution })
|
|
144
|
-
result = result.union(centercylinder)
|
|
145
|
-
|
|
146
|
-
return result
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
module.exports = { main, getParameterDefinitions }
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
// title : Celtic Knot Ring
|
|
2
|
-
// author : Joost Nieuwenhuijse
|
|
3
|
-
// license : MIT License
|
|
4
|
-
// description: a Celtic knot ring
|
|
5
|
-
// file : celtic-knot-ring.jscad
|
|
6
|
-
// tags : Catmull Spline
|
|
7
|
-
|
|
8
|
-
// -*- mode: javascript; -*-
|
|
9
|
-
|
|
10
|
-
function getParameterDefinitions () {
|
|
11
|
-
return [
|
|
12
|
-
{
|
|
13
|
-
name: 'hisorhers',
|
|
14
|
-
type: 'choice',
|
|
15
|
-
caption: 'For Daniel or Zette:',
|
|
16
|
-
values: [0, 1],
|
|
17
|
-
captions: ['Dan', 'Suzette'],
|
|
18
|
-
initial: 0
|
|
19
|
-
}
|
|
20
|
-
];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var his = true;
|
|
24
|
-
|
|
25
|
-
var debugcount = 10;
|
|
26
|
-
|
|
27
|
-
function debugprint () {
|
|
28
|
-
if (debugcount-- > 0) {
|
|
29
|
-
try {
|
|
30
|
-
console.log(arguments);
|
|
31
|
-
} catch (err) {
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// interpolate between v2 and v3, at time u
|
|
37
|
-
function catmullRom (v1, v2, v3, v4, u) {
|
|
38
|
-
var c1x, c2x, c3x, c4x, resX;
|
|
39
|
-
var c1y, c2y, c3y, c4y, resY;
|
|
40
|
-
var c1z, c2z, c3z, c4z, resZ;
|
|
41
|
-
|
|
42
|
-
// Coefficients for Matrix M
|
|
43
|
-
// these should all be const, but MSIE doens't handle that
|
|
44
|
-
// var M11 = 0.0;
|
|
45
|
-
var M12 = 1.0;
|
|
46
|
-
// var M13 = 0.0;
|
|
47
|
-
// var M14 = 0.0;
|
|
48
|
-
var M21 = -0.5;
|
|
49
|
-
// var M22 = 0.0;
|
|
50
|
-
var M23 = 0.5;
|
|
51
|
-
// var M24 = 0.0;
|
|
52
|
-
var M31 = 1.0;
|
|
53
|
-
var M32 = -2.5;
|
|
54
|
-
var M33 = 2.0;
|
|
55
|
-
var M34 = -0.5;
|
|
56
|
-
var M41 = -0.5;
|
|
57
|
-
var M42 = 1.5;
|
|
58
|
-
var M43 = -1.5;
|
|
59
|
-
var M44 = 0.5;
|
|
60
|
-
|
|
61
|
-
c1x = M12 * v2.x;
|
|
62
|
-
c2x = M21 * v1.x + M23 * v3.x;
|
|
63
|
-
c3x = M31 * v1.x + M32 * v2.x + M33 * v3.x + M34 * v4.x;
|
|
64
|
-
c4x = M41 * v1.x + M42 * v2.x + M43 * v3.x + M44 * v4.x;
|
|
65
|
-
|
|
66
|
-
c1y = M12 * v2.y;
|
|
67
|
-
c2y = M21 * v1.y + M23 * v3.y;
|
|
68
|
-
c3y = M31 * v1.y + M32 * v2.y + M33 * v3.y + M34 * v4.y;
|
|
69
|
-
c4y = M41 * v1.y + M42 * v2.y + M43 * v3.y + M44 * v4.y;
|
|
70
|
-
|
|
71
|
-
c1z = M12 * v2.z;
|
|
72
|
-
c2z = M21 * v1.z + M23 * v3.z;
|
|
73
|
-
c3z = M31 * v1.z + M32 * v2.z + M33 * v3.z + M34 * v4.z;
|
|
74
|
-
c4z = M41 * v1.z + M42 * v2.z + M43 * v3.z + M44 * v4.z;
|
|
75
|
-
|
|
76
|
-
resX = (((c4x * u + c3x) * u + c2x) * u + c1x);
|
|
77
|
-
resY = (((c4y * u + c3y) * u + c2y) * u + c1y);
|
|
78
|
-
resZ = (((c4z * u + c3z) * u + c2z) * u + c1z);
|
|
79
|
-
|
|
80
|
-
return new CSG.Vector3D(resX, resY, resZ);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
var tiny = 0.0000001;
|
|
84
|
-
|
|
85
|
-
function catmullRomWithTangent (v1, v2, v3, v4, u) {
|
|
86
|
-
var res1, res2, tangent;
|
|
87
|
-
if ((u + tiny) <= 1) {
|
|
88
|
-
res1 = catmullRom(v1, v2, v3, v4, u);
|
|
89
|
-
res2 = catmullRom(v1, v2, v3, v4, u + tiny);
|
|
90
|
-
tangent = res2.minus(res1).unit();
|
|
91
|
-
return [res1, tangent];
|
|
92
|
-
} else {
|
|
93
|
-
res1 = catmullRom(v1, v2, v3, v4, u - tiny);
|
|
94
|
-
res2 = catmullRom(v1, v2, v3, v4, u);
|
|
95
|
-
tangent = res2.minus(res1).unit();
|
|
96
|
-
return [res2, tangent];
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// create a CSG by dragging a CAG along a Catmull-Rom spline
|
|
101
|
-
// where the 'top' of the CAG is 'up' and 'sideways' of
|
|
102
|
-
// the CAG are perpendicular to 'up' and the spline tangent
|
|
103
|
-
|
|
104
|
-
function splineExtrude (vCP, numInterps, up, cag, transform) {
|
|
105
|
-
var polygons = [];
|
|
106
|
-
var splinePointsAndTangents = [];
|
|
107
|
-
// corners is an array of arrays
|
|
108
|
-
|
|
109
|
-
// corners [j] corresponds to the array of all points on the
|
|
110
|
-
// spline with the offset of cag.sides[j].vertex0
|
|
111
|
-
|
|
112
|
-
// corners[j][i] is the i'th interpolated point on the master
|
|
113
|
-
// spline, plus the offset of cag.sides[j].vertex0
|
|
114
|
-
|
|
115
|
-
var corners = [];
|
|
116
|
-
var nSides = cag.sides.length;
|
|
117
|
-
|
|
118
|
-
for (var i = 0; i < nSides; i++) {
|
|
119
|
-
corners.push([]);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (typeof (transform) !== 'function') {
|
|
123
|
-
transform = function (e) { return e; };
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// fencepost - do the zeroth point of the zeroth segment
|
|
127
|
-
splinePointsAndTangents.push(catmullRomWithTangent(vCP[0], vCP[0 + 1], vCP[0 + 2], vCP[0 + 3], 0));
|
|
128
|
-
for (var j = 0; j <= vCP.length - 4; j++) {
|
|
129
|
-
// don't do the zeroth point, because it's the same as the
|
|
130
|
-
// last point of the previous segment
|
|
131
|
-
for (i = 1; i <= numInterps; i++) {
|
|
132
|
-
var u = i / numInterps;
|
|
133
|
-
splinePointsAndTangents.push(catmullRomWithTangent(vCP[j], vCP[j + 1], vCP[j + 2], vCP[j + 3], u));
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
for (var m = 0; m < splinePointsAndTangents.length; m++) {
|
|
138
|
-
var sideways = up.cross(splinePointsAndTangents[m][1]);
|
|
139
|
-
for (var n = 0; n < nSides; n++) {
|
|
140
|
-
corners[n].push(
|
|
141
|
-
transform(splinePointsAndTangents[m][0]
|
|
142
|
-
.plus(sideways.times(cag.sides[n].vertex0.pos.x))
|
|
143
|
-
.plus(up.times(cag.sides[n].vertex0.pos.y)))
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
// vertex1 should be the same as vertex0 of the next side,
|
|
147
|
-
// so I don't need to handle it here
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
var shared = CSG.Polygon.defaultShared;
|
|
151
|
-
var start = 0;
|
|
152
|
-
var end = corners[0].length - 1;
|
|
153
|
-
|
|
154
|
-
// start cap
|
|
155
|
-
var startCap = [];
|
|
156
|
-
for (var p = nSides - 1; p >= 0; p--) {
|
|
157
|
-
startCap.push(corners[p][start]);
|
|
158
|
-
}
|
|
159
|
-
polygons.push(CSG.Polygon.createFromPoints(startCap, shared));
|
|
160
|
-
|
|
161
|
-
for (var q = start; q < end; q++) {
|
|
162
|
-
// This is done as triangles, (rather than rectangles) because
|
|
163
|
-
// at points on the spline with high curvature, the inside
|
|
164
|
-
// corners can become twisted, which messes up the
|
|
165
|
-
// renderer. What I don't know is what happens when such a
|
|
166
|
-
// file is converted to STL and sent to a 3D printer.
|
|
167
|
-
|
|
168
|
-
// In the words of Shapeways, it makes the printer cry.
|
|
169
|
-
|
|
170
|
-
for (var r = 0; r < nSides; r++) {
|
|
171
|
-
polygons.push(CSG.Polygon.createFromPoints(
|
|
172
|
-
[corners[r][q], corners[(r + 1) % nSides][q], corners[r][q + 1]], shared
|
|
173
|
-
));
|
|
174
|
-
polygons.push(CSG.Polygon.createFromPoints(
|
|
175
|
-
[corners[(r + 1) % nSides][q], corners[(r + 1) % nSides][q + 1], corners[r][q + 1]], shared
|
|
176
|
-
));
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
var endCap = [];
|
|
180
|
-
for (var s = 0; s < nSides; s++) {
|
|
181
|
-
endCap.push(corners[s][end]);
|
|
182
|
-
}
|
|
183
|
-
polygons.push(CSG.Polygon.createFromPoints(endCap, shared));
|
|
184
|
-
|
|
185
|
-
return CSG.fromPolygons(polygons);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
var controlPoints = [
|
|
189
|
-
[0, 0, 1, 1], // over across the middle
|
|
190
|
-
[10, 10, -1, 0], // under the first cross
|
|
191
|
-
[20, 20, 1, 1], // over the second cross
|
|
192
|
-
// [30, 24, 0, 0], //curving into the corner
|
|
193
|
-
[39, 27.25, 0, 1], // the sharp corner
|
|
194
|
-
// [32, 12, 0, 0],
|
|
195
|
-
[30, 10, -1, 0],
|
|
196
|
-
// [28, 8, 0, 0],
|
|
197
|
-
[20, 3.75, 0, 0], // bottom of loop under the corner
|
|
198
|
-
[10, 10, 1, 1],
|
|
199
|
-
[4, 20, 0, 0], // grand curve near the sharp corner (under the long arc)
|
|
200
|
-
// [6, 26, 0, 0],
|
|
201
|
-
// [8, 28, 0, 0],
|
|
202
|
-
[10, 30, -1, 0],
|
|
203
|
-
[24, 34, 0, 0],
|
|
204
|
-
// [30, 35, 0, 0], // top of the long arc
|
|
205
|
-
[40, 34, 0, 0],
|
|
206
|
-
[50, 30, 1, 1], // about where the long arc crosses over
|
|
207
|
-
// [58, 22, 0, 0],
|
|
208
|
-
[60, 20, -1, 0],
|
|
209
|
-
[70, 10, 1, 1],
|
|
210
|
-
[75, 5, 0, 0],
|
|
211
|
-
[80, 0, -1, 0]
|
|
212
|
-
// [79.9, .1, -1, 0] // under the middle (2 cycles right)
|
|
213
|
-
// [79.95, .05, -1, 0] // under the middle (2 cycles right)
|
|
214
|
-
];
|
|
215
|
-
|
|
216
|
-
var numberOfPatterns = 11;
|
|
217
|
-
var circumference = 40 * numberOfPatterns;
|
|
218
|
-
var radius = circumference / 2 / Math.PI;
|
|
219
|
-
var targetCircumference = his ? 54.3 : 56.3;
|
|
220
|
-
|
|
221
|
-
function main (params) {
|
|
222
|
-
his = (params.hisorhers !== 1);
|
|
223
|
-
targetCircumference = his ? 54.3 : 56.3;
|
|
224
|
-
|
|
225
|
-
var up = new CSG.Vector3D(0, 0, 1);
|
|
226
|
-
var flipCP = controlPoints.slice();
|
|
227
|
-
flipCP.reverse();
|
|
228
|
-
flipCP = flipCP.map(function (elt) {
|
|
229
|
-
return ([elt[0] * -1, elt[1] * -1, elt[2], elt[3]]);
|
|
230
|
-
});
|
|
231
|
-
// delete the repeated 0,0 point;
|
|
232
|
-
controlPoints.shift();
|
|
233
|
-
controlPoints = flipCP.concat(controlPoints);
|
|
234
|
-
if (!his) {
|
|
235
|
-
controlPoints = controlPoints.map(function (elt) {
|
|
236
|
-
return ([elt[0], elt[1] * -1, elt[2] * -1, elt[3]]);
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
var splines = [];
|
|
240
|
-
var lastPoint;
|
|
241
|
-
var tripleCP = [];
|
|
242
|
-
// one extra cycle before and after
|
|
243
|
-
for (var i = -1; i < numberOfPatterns + 1; i++) {
|
|
244
|
-
tripleCP = tripleCP.concat(controlPoints.map(function (elt) {
|
|
245
|
-
return ([elt[0] + (i * 160), elt[1], elt[2], elt[3]]);
|
|
246
|
-
}));
|
|
247
|
-
// delete final point so it's not duplicated
|
|
248
|
-
lastPoint = tripleCP.pop();
|
|
249
|
-
}
|
|
250
|
-
// put final point back after the last spline
|
|
251
|
-
tripleCP.push(lastPoint);
|
|
252
|
-
|
|
253
|
-
// delete all but last two points of the extra cycle
|
|
254
|
-
// ie. the start/end point and the extra control point
|
|
255
|
-
for (var t = 0; t < controlPoints.length - 2; t++) {
|
|
256
|
-
tripleCP.pop();
|
|
257
|
-
tripleCP.shift();
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
debugprint(tripleCP);
|
|
261
|
-
var vCP = tripleCP.map(function (e) {
|
|
262
|
-
return new CSG.Vector3D(e[0], e[1], e[2]);
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
var shape1 = CAG.fromPoints([[-4, 0], [-4, 5.0], [-1.5, 8.5], [1.55, 8.5], [4, 5.0], [4, 0]]);
|
|
266
|
-
|
|
267
|
-
// var shape1 = CAG.fromPoints([[-2.75,0], [0,2.75], [2.75,0]]);
|
|
268
|
-
splines.push(splineExtrude(vCP, 11, up, shape1, transformVec3DtoRingSpace));
|
|
269
|
-
// splines.push(splineExtrude(vCP, 11, up, shape1));
|
|
270
|
-
var csg = new CSG();
|
|
271
|
-
for (var u = 0; u < splines.length; u++) {
|
|
272
|
-
csg = csg.union(splines[u]);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
csg = csg.transform(CSG.Matrix4x4.rotationX(90));
|
|
276
|
-
csg = csg.scale(targetCircumference / circumference);
|
|
277
|
-
return csg;
|
|
278
|
-
|
|
279
|
-
// 7.5 ring size is 17.7 mm diameter 55.7mm circumference
|
|
280
|
-
// my guess as to my own ring size is 54mm
|
|
281
|
-
|
|
282
|
-
// augh! the pass-under bits are 1 pre-scaled unit narrower
|
|
283
|
-
// (after scaling, about 1/8 mm, so .4 mm in extra circumference.
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
function transformVec3DtoRingSpace (vec) {
|
|
287
|
-
var m = new CSG.Matrix4x4();
|
|
288
|
-
|
|
289
|
-
m = m.multiply(CSG.Matrix4x4.translation([-vec.x, 0, radius]));
|
|
290
|
-
m = m.multiply(CSG.Matrix4x4.rotationY(360 * (vec.x) / circumference));
|
|
291
|
-
var res = vec.transform(m);
|
|
292
|
-
return res;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// Question: polygons are supposed to be coplanar vertices, but after
|
|
296
|
-
// being transformed into ring space, are 4 coplanar vertices still
|
|
297
|
-
// always coplanar? I'm pretty sure the answer is 'No'. Does this matter?
|
|
298
|
-
// I think yes. So I can generate triangles instead, easily enough.
|
|
299
|
-
// Excpet the end caps... which for my model are not actually rotated
|
|
300
|
-
// because they are at the origin or exactly 11 loops away.
|