openjscad-aurora-webapp

Форк
0
269 строк · 11.2 Кб
1
// title: Grille
2
// author: Joost Nieuwenhuijse
3
// license: MIT License
4

5
// Here we define the user editable parameters: 
6
function getParameterDefinitions() {
7
  return [
8
    { name: 'outerwidth', caption: 'Outer width of grille:', type: 'float', initial: 190 },
9
    { name: 'outerheight', caption: 'Outer height of grille:', type: 'float', initial: 120 },
10
    { name: 'outerdepth', caption: 'Outer depth of grille:', type: 'float', initial: 12 },
11
    { name: 'thickness', caption: 'Wall thickness:', type: 'float', initial: 2.5 },
12
    { name: 'innerdistance', caption: 'Inner standoff distance:', type: 'float', initial: 2 },
13
    { name: 'bladescale', caption: 'Relative size of blades (1.0 is default):', type: 'float', initial: 1 },
14
    { name: 'numdividers', caption: 'Number of vertical dividers:', type: 'int', initial: 2 },
15
    {
16
      name: 'addlooseners', 
17
      type: 'choice',
18
      caption: 'Add loops (for easy removal):',
19
      values: [0, 1],
20
      captions: ["No", "Yes"], 
21
      initial: 1
22
    },
23
    {
24
      name: 'show', 
25
      type: 'choice',
26
      caption: 'Show:',
27
      values: ["all", "grille", "holders"],
28
      captions: ["All", "Grille (for printing)", "Holders (for printing)"], 
29
      initial: "all"
30
    },
31
    {
32
      name: 'mouseears', 
33
      type: 'choice',
34
      caption: 'Add mouse ears:',
35
      values: [0, 1],
36
      captions: ["No", "Yes"], 
37
      initial: 1
38
    },
39
    {
40
      name: 'quality', 
41
      type: 'choice',
42
      caption: 'Quality:',
43
      values: [0, 1],
44
      captions: ["Draft", "Final"], 
45
      initial: 0
46
    }
47
  ];
48
}
49

50
function main(params)
51
{
52
  var outerwidth = params.outerwidth;
53
  var outerheight = params.outerheight;
54
  var thickness = params.thickness;
55
  var outerdepth = params.outerdepth;
56
  var innerdistance = params.innerdistance;  
57
  var bladescale = params.bladescale;
58
  
59
  var draft = params.quality != 1;
60
  
61
  var marginleftright = 21;
62
  var margintopbottom = 15;
63
  var bladedistance = 12 * bladescale;
64
  var frontroundradius = 5;
65
  frontroundradius = Math.max(frontroundradius, thickness+0.2);
66
  var outerroundradius = 3;
67
  outerroundradius = Math.max(outerroundradius, thickness+0.2);
68
  outerdepth = Math.max(outerdepth, outerroundradius); 
69
  outerdepth = Math.max(outerdepth, innerdistance+thickness); 
70
  var frontextend = innerdistance + bladescale*12 + thickness - outerdepth;
71
  frontextend = Math.max(frontextend, 1.5);  
72
  var bladewidth = outerwidth - 2*marginleftright;
73
  var bladesheight = outerheight - 2*margintopbottom;
74
  var numblades = Math.ceil(bladesheight / bladedistance) + 1; 
75
  var topnotchsize = new CSG.Vector3D([20, 8, 3]);
76
  var topnotchpos = new CSG.Vector3D([outerwidth/2-thickness - topnotchsize.x/2, outerheight/2-thickness - topnotchsize.y/2, topnotchsize.z/2]);
77
  var bottomnotchsize = new CSG.Vector3D([12, 4, topnotchsize.z]);
78
  var bottomnotchpos = new CSG.Vector3D([outerwidth/2-thickness - 4 - bottomnotchsize.x/2, -outerheight/2+thickness + bottomnotchsize.y/2, bottomnotchsize.z/2]);
79

80
  var roundresolution = draft? 4 : 16;
81
  
82
  var result = new CSG();
83
  if(params.show != "holders")
84
  {
85
    // build the shell:
86
    var z0plane = CSG.Plane.fromNormalAndPoint([0, 0, -1], [0, 0, 0]);
87
    var outershell = CSG.roundedCube({center: [0,0,0], radius: [outerwidth/2, outerheight/2, outerdepth], roundradius: outerroundradius, resolution: roundresolution});
88
    outershell = outershell.cutByPlane(z0plane);
89
    var innershell = CSG.roundedCube({center: [0,0,0], radius: [outerwidth/2-thickness, outerheight/2-thickness, outerdepth-thickness], roundradius: outerroundradius-thickness, resolution: roundresolution});
90
    innershell = innershell.cutByPlane(z0plane);
91
    var shell = outershell.subtract(innershell);
92
    var frontextendoutershell = CSG.roundedCube({center: [0,0,0], radius: [bladewidth/2+thickness, bladesheight/2+thickness, outerdepth+frontextend+frontroundradius+thickness], roundradius: frontroundradius, resolution: roundresolution});
93
    var frontextendinnershell = CSG.roundedCube({center: [0,0,0], radius: [bladewidth/2, bladesheight/2, outerdepth+frontextend+frontroundradius+thickness+100], roundradius: frontroundradius-thickness, resolution: roundresolution});
94
    frontextendinnershell = frontextendinnershell.cutByPlane(z0plane);
95
    var plane3 = CSG.Plane.fromNormalAndPoint([0, 0, 1], [0, 0, outerdepth+frontextend+100]);
96
    frontextendinnershell = frontextendinnershell.cutByPlane(plane3);
97
    var plane1 = CSG.Plane.fromNormalAndPoint([0, 0, 1], [0, 0, outerdepth+frontextend]);
98
    frontextendoutershell = frontextendoutershell.cutByPlane(plane1);
99
    var plane2 = CSG.Plane.fromNormalAndPoint([0, 0, -1], [0, 0, innerdistance]);
100
    frontextendoutershell = frontextendoutershell.cutByPlane(plane2);
101
    shell = shell.subtract(frontextendinnershell);
102
    var frontextendshell = frontextendoutershell.subtract(frontextendinnershell);
103
    shell = shell.union(frontextendshell);
104
    
105
    // build a blade:
106
    var curvedpath = CSG.Path2D.arc({
107
      center: [0,0,0],
108
      radius: 15 * bladescale,
109
      startangle: 20,
110
      endangle: 80,
111
      resolution: draft? 8:32
112
    });
113
    var blade = curvedpath.rectangularExtrude(thickness, bladewidth, draft? 4:16, true);
114
    var bladecenter = blade.getBounds()[0].plus(blade.getBounds()[1]).times(0.5);
115
    blade = blade.translate(bladecenter.negated());
116
    blade = blade.rotateY(-90);
117
    blade = blade.translate([0, 0, -blade.getBounds()[0].z+innerdistance]);
118
    var bladesize = blade.getBounds()[1].minus(blade.getBounds()[0]);
119
    
120
    // add the blades to the shell:
121
    var blades = new CSG();
122
    for(var i = 0; i < numblades; i++)
123
    {
124
      var topy = bladesheight/2 + thickness - i*bladedistance;
125
      var translatedblade = blade.translate([0, topy-bladesize.y/2, 0]);
126
      blades = blades.union(translatedblade);
127
    }
128
    blades = blades.intersect(frontextendinnershell);
129
    var grille = shell;
130
    grille = shell.union(blades);
131
    
132
    // add the dividers:
133
    var dividers = new CSG();
134
    if(params.numdividers > 0)
135
    {
136
      var w1 = (bladewidth - params.numdividers * thickness)/(params.numdividers+1); 
137
      for(var j = 0; j < params.numdividers; j++)
138
      {
139
        var x = -(params.numdividers-1)*(w1+thickness)/2 + j*(w1+thickness);
140
        var z1 = outerdepth+frontextend;
141
        var divider = CSG.cube({center: [x, 0, (z1+innerdistance)/2], radius: [thickness/2, bladesheight/2, (z1-innerdistance)/2]});
142
        dividers = dividers.union(divider);
143
      }
144
    }
145
    grille = grille.union(dividers);
146
    
147
    // create the notches:
148
    var notches = new CSG();
149
    var topnotch1 = CSG.cube({center: topnotchpos, radius: topnotchsize.times(0.5) });
150
    notches = notches.union(topnotch1);  
151
    var topnotch2 = CSG.cube({center: [-topnotchpos.x, topnotchpos.y, topnotchpos.z], radius: topnotchsize.times(0.5) });
152
    notches = notches.union(topnotch2);
153
    var bottomnotch1 = CSG.cube({center: bottomnotchpos, radius: bottomnotchsize.times(0.5) });
154
    notches = notches.union(bottomnotch1);  
155
    var bottomnotch2 = CSG.cube({center: [-bottomnotchpos.x, bottomnotchpos.y, bottomnotchpos.z], radius: bottomnotchsize.times(0.5) });
156
    notches = notches.union(bottomnotch2);  
157
    notches = notches.intersect(outershell);    
158
    grille = grille.union(notches);
159
    result = result.union(grille);
160
    
161
    // create the looseners:
162
    if(params.addlooseners == 1)
163
    {
164
      var loosenerinnerwidth = 5;
165
      var loosenerinnerheight = 2;
166
      var loosenerdepth = 4;
167
      var loosener = CSG.cube({center: [0, -outerheight/2 - loosenerinnerheight/2, loosenerdepth/2],
168
        radius: [loosenerinnerwidth/2+thickness, loosenerinnerheight/2+thickness, loosenerdepth/2]});
169
      loosener = loosener.subtract(CSG.cube({center: [0, -outerheight/2 - loosenerinnerheight/2, loosenerdepth/2],
170
        radius: [loosenerinnerwidth/2, loosenerinnerheight/2, loosenerdepth/2]}));
171
      var loosenerx = -outerwidth/2 + loosenerinnerwidth/2 + 5 + thickness; 
172
  
173
      var looseners = loosener.translate([loosenerx, 0, 0]);
174
      looseners = looseners.union(loosener.translate([-loosenerx, 0, 0]));
175
      result = result.union(looseners);
176
    } 
177

178
    if(params.mouseears == 1)
179
    {
180
      for(var k = 0; k < 4; k++)
181
      {
182
        var xpos=outerwidth/2-10;
183
        var ypos=outerheight/2;
184
        if(k&1) xpos = -xpos;
185
        if(k&2) ypos = -ypos;
186
        var cylinder = CSG.cylinder({start: [xpos, ypos, 0], end: [xpos, ypos, 0.5], radius: 15});
187
        result = result.union(cylinder);
188
      }
189
      for(var m = 0; m < 4; m++)
190
      {
191
        var xpos2=bladewidth/2 + thickness/2;
192
        var ypos2=bladesheight/2 + thickness/2;
193
        if(m&1) xpos2 = -xpos2;
194
        if(m&2) ypos2 = -ypos2;
195
        var cyl1 = CSG.cylinder({start: [xpos2, ypos2, 0], end: [xpos2, ypos2, 0.5], radius: 15});
196
        var cyl2 = CSG.cylinder({start: [xpos2, ypos2, 0], end: [xpos2, ypos2, innerdistance], radius: 5});
197
        result = result.union(cyl1.union(cyl2));
198
      }
199
    }
200
  }
201
  
202
  if(params.show != "grille")
203
  {
204
    // create the holders:
205
    var holderyoffset = 0.5;
206
    var holderzoffset = 1;
207
    var holderwidth = 10;
208
    var holderthickness = 3;
209
    var holdertopclipheight = 4;
210
    var holderbottomclipheight = 2;
211
    var holderscrewholeradius = 2;
212
    var holderscrewholedistance = 6;
213
    
214
    var holderx;
215
    if(params.show == "holders")
216
    {
217
      // just the holders:
218
      holderx = holderwidth/2+2;
219
    }
220
    else
221
    {
222
      holderx = bottomnotchpos.x + bottomnotchsize.x/2 - holderwidth/2;
223
    }
224
    var holdery1 = topnotchpos.y - topnotchsize.y/2 - holderyoffset;
225
    var holdery2 = bottomnotchpos.y + bottomnotchsize.y/2 + holderyoffset;
226
    
227
    var holdery0 = holdery1+holdertopclipheight;
228
    var holdery3 = holdery2-holderbottomclipheight;
229
    var holder = CSG.cube({center: [0, (holdery1 + holdery2)/2 , holderthickness/2], 
230
      radius: [holderwidth/2, (holdery1-holdery2)/2, holderthickness/2]});
231
    var d1 = 7;  
232
    var holdery1a = holdery1 - d1;
233
    var holdery2a = holdery2 + d1;
234
    var holderz1 = topnotchsize.z + holderzoffset;
235
    var holderz2 = holderz1 + holderthickness;
236
    holder = holder.union(CSG.cube({
237
      center: [0, (holdery1a+holdery1)/2, holderz2/2],
238
      radius: [holderwidth/2, (holdery1-holdery1a)/2, holderz2/2]
239
    }));
240
    holder = holder.union(CSG.cube({
241
      center: [0, (holdery2a+holdery2)/2, holderz2/2],
242
      radius: [holderwidth/2, (holdery2a-holdery2)/2, holderz2/2]
243
    }));
244
    holder = holder.union(CSG.cube({
245
      center: [0, (holdery0+holdery1a)/2, (holderz2+holderz1)/2],
246
      radius: [holderwidth/2, (holdery0-holdery1a)/2, (holderz2-holderz1)/2]
247
    }));
248
    holder = holder.union(CSG.cube({
249
      center: [0, (holdery2a+holdery3)/2, (holderz2+holderz1)/2],
250
      radius: [holderwidth/2, (holdery2a-holdery3)/2, (holderz2-holderz1)/2]
251
    }));
252
    var screwhole = CSG.cylinder({start: [0,0,0], end: [0, 0, holderthickness], radius: holderscrewholeradius, resolution: 16});
253
    holder = holder.subtract(screwhole.translate([0, holdery1a-holderscrewholedistance, 0]));
254
    holder = holder.subtract(screwhole.translate([0, holdery2a+holderscrewholedistance, 0]));
255
    
256
    holder = holder.setColor(0, 1, 0);
257
    
258
    var holders = holder.translate([holderx,0,0]);
259
    holders = holders.union(holder.translate([-holderx,0,0]));
260
    if(params.show == "holders")
261
    {
262
      holders = holders.rotateZ(90);
263
    }
264
    
265
    result = result.union(holders);
266
  }
267
  result = result.rotateZ(90);
268
  return result;
269
}
270

271

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.