openjscad-aurora-webapp

Форк
0
/
iphone4-case.jscad 
214 строк · 8.2 Кб
1
// title: iPhone 4 Dock
2
// author: Joost Nieuwenhuijse
3

4
/*
5

6
OpenJsCad script for iPhone 4 dock
7
Note: not tried printing yet, not sure if it really wil fit.
8

9
To create the STL file, launch Google Chrome and go to:
10
http://joostn.github.com/OpenJsCad/processfile.html or http://openjscad.org
11

12
Then drag&drop this file into the page
13

14
OpenJsCad is an open source 3d solid modeling tool using JavaScript.
15
For more information see http://joostn.github.com/OpenJsCad
16

17
*/
18

19
function getParameterDefinitions() {
20
  return [
21
    {
22
      name: 'quality', 
23
      type: 'choice',
24
      caption: 'Quality:',
25
      values: ["draft", "smooth", "supersmooth"],
26
      captions: ["Draft (no rounded corners)", "Smooth (rounded corners)", "Super smooth (rounded corners)"], 
27
      initial: "draft"
28
    },
29
    {
30
      name: 'iphonemargin', 
31
      type: 'float', 
32
      initial: 0.5,
33
      caption: "Margin around iphone (in mm):"
34
    },
35
    {
36
      name: 'plugmargin', 
37
      type: 'float', 
38
      initial: 0.25,
39
      caption: "Margin around dock connector (in mm):"
40
    },
41
    { name: 'mouseear', caption: 'Add mouse ear:', type: 'choice', values: [0, 1], initial: 1, captions: ["No", "Yes"]}
42
  ];
43
}
44

45
function main(params)
46
{  
47
  var resolution = 16;  // resolution for all the curved surfaces
48
  var smoothing = (params.quality != "draft"); // set to false during development, for fast rendering
49
  var draft = (params.quality != "supersmooth");     // set to false for high resolution smoothing, rendering will take several minutes!
50

51
  var x1=40, x2=25, x3=8;
52
  var y1=35, y2=y1+8, y3=y2+25;
53
  var frontheight = 30;
54
  
55
  // Build the base from two 2D polygons:
56
  var base1=new CSG.Polygon2D([[0,0],[x1,0],[x1,y1],[x2,y2],[0,y2]]);
57
  var base2=new CSG.Polygon2D([[0,y2],[x2,y2],[x3,y3],[0,y3]]);
58
  var extruded1=base1.extrude({offset: [0, 0,frontheight]});
59
  var extruded2=base2.extrude({offset: [0, 0,frontheight]});
60
  // We now have the right half; mirror to create the left half:
61
  extruded1 = extruded1.union(extruded1.mirroredX());
62
  extruded2 = extruded2.union(extruded2.mirroredX());
63
  var base = extruded1.union(extruded2);
64
  
65
  // Make the top back surface slightly slanted:
66
  var backtopplane = CSG.Plane.fromNormalAndPoint([0, 8, 10], [0, y2, frontheight]);
67
  base = base.cutByPlane(backtopplane);
68
  
69
  // Make the front surface slightly slanted:
70
  var frontplane = CSG.Plane.fromNormalAndPoint([0, -10, 2], [0, 0, 0]);
71
  base = base.cutByPlane(frontplane);
72
  
73
  // Add a CSG.Connector to the base, at the point where the iphone should
74
  // rest in the base. The connector's axis points upwards and its normal
75
  // points towards the front:
76
  var recessionDepth = 10;
77
  var distanceFromFront = 20;
78
  var angle = 15;
79
  base.properties.iphoneConnector = new CSG.Connector(
80
    [0, distanceFromFront, frontheight - recessionDepth],  // the point
81
    [0, 0, 1],  // axis vector
82
    [1, 0, 0]  // normal vector
83
  );
84
  // rotate the base.properties.iphoneConnector, so that the iphone will be tilted: 
85
  var rotmaxtrix = CSG.Matrix4x4.rotation(base.properties.iphoneConnector.point, [1, 0, 0], angle);
86
  base.properties.iphoneConnector = base.properties.iphoneConnector.transform(rotmaxtrix);
87
   
88
  // Create iphone placeholder (it's just a cube with the iphone's dimensions):
89
  var iphoneradius = new CSG.Vector3D(58.6/2 + params.iphonemargin, 9.4/2 + params.iphonemargin, 115/2); 
90
  var iphone = CSG.cube({radius: iphoneradius});
91
  
92
  // Create the little tab behind the iphone:
93
  var tabradius = new CSG.Vector3D(15, 5, 12); 
94
  var tab = CSG.cube({radius: tabradius});
95
  tab = tab.translate([0, (iphoneradius.y+tabradius.y), (-iphoneradius.z+tabradius.z)]);
96
  
97
  // Add a CSG.Connector to the iphone's properties. This is the place where the 
98
  // 30 pin dock plug will snap in. In this case it is the center of the bottom
99
  // Z plane of the cube. Since the cube already has 6 predefined connectors
100
  // at the center of each face, we can just use one of those instead of creating
101
  // a new CSG.Connector:
102
  iphone.properties.dockConnector = iphone.properties.cube.facecenters[5];
103

104
  // transform the iphone so it sits in the base:
105
  var iphoneTransformation = iphone.properties.dockConnector.getTransformationTo(base.properties.iphoneConnector, true, 0); 
106
  iphone = iphone.transform(iphoneTransformation);
107
  
108
  // transform the tab so it stays behind the iphone: 
109
  tab = tab.transform(iphoneTransformation);
110

111
  // and add the tab to the base:  
112
  base = base.union(tab);  
113

114
  // build the iphone plug:
115
  var plug = getIphoneDockConnector(params.plugmargin, resolution);
116
  
117
  // The plug has a predefined Connector plug.properties.iphoneConnector
118
  // To attach the plug to the iphone we connect plug.properties.iphoneConnector
119
  // to iphone.properties.dockConnector
120
  plug = plug.connectTo(plug.properties.iphoneConnector, 
121
    iphone.properties.dockConnector, true, 0);
122
  
123
  // We must make sure we can pull the USB cable through the dock. So there needs 
124
  // to be space for the plug. We just create a tall cube with the size of the USB
125
  // plug (8 by 40 mm), which will be subtracted from the dock's shape:
126
  var gapForUsbPlug = CSG.cube({radius: [8, 4, 40]});
127
  
128
  // Align it to the plug. Again, since gapForUsbPlug is a CSG.cube it already
129
  // has predefined CSG.Connectors at every face. Connect the Z face to the iphone: 
130
  gapForUsbPlug = gapForUsbPlug.connectTo(gapForUsbPlug.properties.cube.facecenters[5], 
131
    iphone.properties.dockConnector, true, 0);
132
  
133
//  return plug.union(iphone).union(gapForUsbPlug);
134
  
135
  //var cutout = plug.union(iphone).union(gapForUsbPlug);
136
  //return cutout;
137
  
138
  base = base.subtract(iphone);
139
  
140
  // make the cutout for the cable:
141
  var cablewidth = 3;
142
  var cableheight = 4; 
143
  var bottomplane = CSG.Plane.fromNormalAndPoint([0, 0, -1], [0, 0, 0]);
144
  var cableline = plug.properties.cableConnector.axisLine();
145
  var cableexitpoint = bottomplane.intersectWithLine(cableline);
146
  var cableentrypoint = new CSG.Vector3D(0, y3, 0);
147

148
  var cablepath = new CSG.Path2D([[cableentrypoint.x, cableentrypoint.y], [cableexitpoint.x, cableexitpoint.y]], false);
149
  var cablecutout = cablepath.rectangularExtrude(cablewidth, cableheight, resolution, false);
150
  
151
  // Smooth the base:
152
  if(smoothing)
153
  {
154
    base = base.contract(4, draft? 4:16);
155
    base = base.expand(4, draft? 4:16);
156
  }
157
  
158
  // Subtract the connector and cable:
159
  base = base.subtract(iphone).subtract(plug).subtract(cablecutout).subtract(gapForUsbPlug);
160
  
161
  // add mouse ear:
162
  if(params.mouseear == 1)
163
  {
164
    var mouseearpoint = new CSG.Vector3D(0, y3, 0);
165
    var mouseearthickness = 0.5;
166
    var mouseearradius = 15;
167
    var mouseear = CSG.cylinder({
168
      start: mouseearpoint, 
169
      end: mouseearpoint.plus(new CSG.Vector3D(0, 0, mouseearthickness)),
170
      radius: mouseearradius,
171
      resolution: 16
172
    });
173
    base = base.union(mouseear);     
174
  }
175
  
176
  // center:
177
  var basecenter = base.getBounds()[0].plus(base.getBounds()[1]).times(0.5);
178
  base = base.translate(basecenter.negated());
179
  
180
  return base;
181
}
182

183
///////////////////// 
184
function getIphoneDockConnector(margin, resolution)
185
{
186
  margin = new CSG.Vector3D(margin);
187
  var dockConnectorSize = new CSG.Vector3D([26.2, 5.7, 9.5]).plus(margin.times(2));  
188
  var dockConnector = CSG.cube({radius: [(dockConnectorSize.x-dockConnectorSize.y)/2, dockConnectorSize.y/2, dockConnectorSize.z/2]});
189
  dockConnector = dockConnector.union(CSG.cylinder({
190
    start: [(dockConnectorSize.x-dockConnectorSize.y)/2, 0, -dockConnectorSize.z/2],
191
    end: [(dockConnectorSize.x-dockConnectorSize.y)/2, 0, dockConnectorSize.z/2],
192
    radius: dockConnectorSize.y/2,
193
    resolution: resolution
194
  }));
195
  dockConnector = dockConnector.union(CSG.cylinder({
196
    start: [-(dockConnectorSize.x-dockConnectorSize.y)/2, 0, -dockConnectorSize.z/2],
197
    end: [-(dockConnectorSize.x-dockConnectorSize.y)/2, 0, dockConnectorSize.z/2],
198
    radius: dockConnectorSize.y/2,
199
    resolution: resolution
200
  }));
201
  var cableTube = CSG.cylinder({
202
    start: [0, 0, -dockConnectorSize.z/2-5.70-margin.z],
203
    end: [0, 0, -dockConnectorSize.z/2],
204
    radius: 2.25+margin.y,
205
    resolution: resolution
206
  }); 
207
  dockConnector = dockConnector.union(cableTube);
208
  
209
  // Add CSG.Connector properties:
210
  dockConnector.properties.iphoneConnector = dockConnector.properties.cube.facecenters[4];
211
  dockConnector.properties.cableConnector = cableTube.properties.cylinder.start;
212
    
213
  return dockConnector;
214
}
215

216

217

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

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

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

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