@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
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
|
|
3
|
+
const { applyParameterDefinitions } = require('@jscad/core').parameters
|
|
4
|
+
const { makeFakeFs } = require('@jscad/core').loading
|
|
5
|
+
const { getDesignEntryPoint, getDesignName } = require('@jscad/core').loading.requireDesignUtilsFs
|
|
6
|
+
|
|
7
|
+
const { keep } = require('../../utils/object')
|
|
8
|
+
const packageMetadata = require('../../../package.json')
|
|
9
|
+
const { availableExportFormatsFromSolids, exportFilePathFromFormatAndDesign } = require('../../core/io/exportUtils')
|
|
10
|
+
|
|
11
|
+
// what fields should we check to determine if two designs are the same
|
|
12
|
+
const designEqualityFields = [
|
|
13
|
+
'parameterDefinitions',
|
|
14
|
+
'parameterValues',
|
|
15
|
+
'mainPath',
|
|
16
|
+
'filesAndFolders',
|
|
17
|
+
'vtreeMode' // also trigger a recompute when vtree mode is enabled/disabled
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
// what fields we want to de/serialize
|
|
21
|
+
const serializableFields = [
|
|
22
|
+
'name',
|
|
23
|
+
'mainPath',
|
|
24
|
+
'origin',
|
|
25
|
+
'parameterValues',
|
|
26
|
+
'vtreeMode',
|
|
27
|
+
'autoReload',
|
|
28
|
+
'instantUpdate',
|
|
29
|
+
'solidsTimeOut'
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
const reducers = {
|
|
33
|
+
/**
|
|
34
|
+
* initialise the design's state
|
|
35
|
+
* @returns {Object} the default state for designs
|
|
36
|
+
*/
|
|
37
|
+
initialize: () => {
|
|
38
|
+
const design = {
|
|
39
|
+
// metadata
|
|
40
|
+
name: '',
|
|
41
|
+
path: '',
|
|
42
|
+
mainPath: '',
|
|
43
|
+
origin: undefined, // where the design came from : http, local etc
|
|
44
|
+
filesAndFolders: [], // file tree, of sorts
|
|
45
|
+
// code
|
|
46
|
+
instantUpdate: false,
|
|
47
|
+
autoReload: false,
|
|
48
|
+
// parameters
|
|
49
|
+
parameterDefinitions: [],
|
|
50
|
+
parameterValues: {},
|
|
51
|
+
parameterDefaults: {},
|
|
52
|
+
// solids
|
|
53
|
+
solidsTimeOut: 80000,
|
|
54
|
+
solids: [],
|
|
55
|
+
// geometry caching
|
|
56
|
+
vtreeMode: false,
|
|
57
|
+
lookup: {},
|
|
58
|
+
lookupCounts: {},
|
|
59
|
+
debug: {
|
|
60
|
+
startTime: 0,
|
|
61
|
+
endTime: 0,
|
|
62
|
+
totalTime: 0
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return { design }
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
/** reset the content of the design
|
|
69
|
+
* @param {Object} state
|
|
70
|
+
* @param {String} origin
|
|
71
|
+
* @returns {Object} the updated state
|
|
72
|
+
*/
|
|
73
|
+
resetDesign: (state, origin) => {
|
|
74
|
+
// we reset only the given fields: mostly all except design specific things
|
|
75
|
+
const fieldsToReset = [
|
|
76
|
+
'name', 'path', 'mainPath', 'origin', 'filesAndFolders',
|
|
77
|
+
'parameterDefinitions', 'parameterValues', 'parameterDefaults',
|
|
78
|
+
'lookup', 'lookupCounts', 'debug', 'solids'
|
|
79
|
+
]
|
|
80
|
+
const design = Object.assign({},
|
|
81
|
+
state.design, keep(fieldsToReset, reducers.initialize().design)
|
|
82
|
+
)
|
|
83
|
+
// ugh
|
|
84
|
+
design.origin = origin
|
|
85
|
+
return { design }
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
/** set the content of the design usually after a reset
|
|
89
|
+
* bulk of the data is set here
|
|
90
|
+
* @param {Object} state
|
|
91
|
+
* @param {String} payload
|
|
92
|
+
* @returns {Object} the updated state
|
|
93
|
+
*/
|
|
94
|
+
setDesignContent: (state, payload) => {
|
|
95
|
+
// all our available data (specific to web)
|
|
96
|
+
const { filesAndFolders } = payload
|
|
97
|
+
const fakeFs = makeFakeFs(filesAndFolders)
|
|
98
|
+
const rootPath = filesAndFolders[0].fullPath
|
|
99
|
+
const mainPath = getDesignEntryPoint(fakeFs, rootPath)
|
|
100
|
+
const designName = getDesignName(fakeFs, rootPath)
|
|
101
|
+
const designPath = path.dirname(rootPath)
|
|
102
|
+
|
|
103
|
+
let design = state.design
|
|
104
|
+
// to track computation time
|
|
105
|
+
const debug = Object.assign({ }, state.design.debug, { startTime: new Date() })
|
|
106
|
+
|
|
107
|
+
design = Object.assign({}, design, {
|
|
108
|
+
name: designName,
|
|
109
|
+
path: designPath,
|
|
110
|
+
mainPath,
|
|
111
|
+
filesAndFolders,
|
|
112
|
+
debug
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
const appTitle = `jscad v ${packageMetadata.version}: ${state.design.name}`
|
|
116
|
+
|
|
117
|
+
// FIXME: this is the same as clear errors?
|
|
118
|
+
const status = Object.assign({}, state.status, { busy: true, error: undefined })
|
|
119
|
+
return {
|
|
120
|
+
design,
|
|
121
|
+
appTitle,
|
|
122
|
+
status
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* set the solids (2d/ 3D /csg/cag data), and the geometry cache if applicable
|
|
128
|
+
* @param {Object} state
|
|
129
|
+
* @param {Object} options
|
|
130
|
+
* @param {Array} options.solids
|
|
131
|
+
* @param {Object} options.lookup
|
|
132
|
+
* @param {Object} options.lookupCounts
|
|
133
|
+
* @returns {Object} the updated state
|
|
134
|
+
*/
|
|
135
|
+
setDesignSolids: (state, { solids, lookup, lookupCounts }) => {
|
|
136
|
+
solids = solids || []
|
|
137
|
+
lookup = lookup || {}
|
|
138
|
+
lookupCounts = lookupCounts || {}
|
|
139
|
+
|
|
140
|
+
// should debug be part of status ?
|
|
141
|
+
const endTime = new Date()
|
|
142
|
+
const totalTime = endTime - state.design.debug.startTime
|
|
143
|
+
const debug = Object.assign({ }, state.design.debug, {
|
|
144
|
+
endTime,
|
|
145
|
+
totalTime
|
|
146
|
+
})
|
|
147
|
+
console.warn('total time for design regeneration', totalTime, new Date().getSeconds())
|
|
148
|
+
|
|
149
|
+
const design = Object.assign({}, state.design, {
|
|
150
|
+
solids,
|
|
151
|
+
lookup,
|
|
152
|
+
lookupCounts,
|
|
153
|
+
debug
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
// TODO: move this to IO?
|
|
157
|
+
const { exportFormat, availableExportFormats } = availableExportFormatsFromSolids(solids)
|
|
158
|
+
const exportInfos = exportFilePathFromFormatAndDesign(design, exportFormat)
|
|
159
|
+
const io = {
|
|
160
|
+
exportFormat,
|
|
161
|
+
exportFilePath: exportInfos.exportFilePath, // default export file path
|
|
162
|
+
availableExportFormats
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const status = Object.assign({}, state.status, { busy: false })
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
design,
|
|
169
|
+
status,
|
|
170
|
+
io
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
setDesignParameterDefinitions: (state, data) => {
|
|
175
|
+
const parameterDefaults = data.parameterDefaults || state.design.parameterDefaults
|
|
176
|
+
const parameterDefinitions = data.parameterDefinitions || state.design.parameterDefinitions
|
|
177
|
+
const design = Object.assign({}, state.design, {
|
|
178
|
+
parameterDefaults,
|
|
179
|
+
parameterDefinitions,
|
|
180
|
+
parametersOrigin: data.origin
|
|
181
|
+
})
|
|
182
|
+
return { design }
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* set the parameters of this design
|
|
187
|
+
* @param {Object} state
|
|
188
|
+
* @param {Object} data
|
|
189
|
+
* @returns {Object} the updated state
|
|
190
|
+
*/
|
|
191
|
+
setDesignParameterValues: (state, data) => {
|
|
192
|
+
let parameterValues = data.parameterValues
|
|
193
|
+
// one of many ways of filtering out data from instantUpdates
|
|
194
|
+
if (data.origin === 'instantUpdate' && !state.design.instantUpdate) {
|
|
195
|
+
parameterValues = state.design.parameterValues
|
|
196
|
+
}
|
|
197
|
+
parameterValues = parameterValues ? applyParameterDefinitions(parameterValues, state.design.parameterDefinitions) : parameterValues
|
|
198
|
+
parameterValues = Object.assign({}, state.design.parameterValues, parameterValues)
|
|
199
|
+
|
|
200
|
+
let design = Object.assign({}, state.design, {
|
|
201
|
+
parameterValues,
|
|
202
|
+
parametersOrigin: data.origin
|
|
203
|
+
})
|
|
204
|
+
// to track computation time
|
|
205
|
+
const debug = Object.assign({ }, state.design.debug, { startTime: new Date() })
|
|
206
|
+
design = Object.assign({}, design, { debug })
|
|
207
|
+
|
|
208
|
+
const status = Object.assign({}, state.status, { busy: true, error: undefined })
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
design,
|
|
212
|
+
status
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
|
|
216
|
+
setSettings: (state, { data }) => {
|
|
217
|
+
const {
|
|
218
|
+
vtreeMode,
|
|
219
|
+
autoReload,
|
|
220
|
+
instantUpdate,
|
|
221
|
+
solidsTimeOut
|
|
222
|
+
} = data
|
|
223
|
+
// FIXME : clunky but needed to make sure we have no invalid settings
|
|
224
|
+
if (vtreeMode === undefined) {
|
|
225
|
+
return { design: state.design }
|
|
226
|
+
}
|
|
227
|
+
const design = Object.assign({}, state.design, { vtreeMode, autoReload, instantUpdate, solidsTimeOut })
|
|
228
|
+
return {
|
|
229
|
+
design
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
requestGeometryRecompute: ({ design }, _) => keep(['mainPath', 'parameterValues', 'filesAndFolders', 'vtreeMode', 'lookup', 'lookupCounts'], design),
|
|
234
|
+
|
|
235
|
+
timeoutGeometryRecompute: ({ status }, _) => {
|
|
236
|
+
if (status.isBusy) { // still computing... we can kill it
|
|
237
|
+
return Object.assign({}, status, {
|
|
238
|
+
busy: false,
|
|
239
|
+
error: new Error('Failed to generate design within an acceptable time, bailing out')
|
|
240
|
+
})
|
|
241
|
+
}
|
|
242
|
+
// no problem, just act as a no-op
|
|
243
|
+
return { status }
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
requestWriteCachedGeometry: ({ design }, cache) => {
|
|
247
|
+
const data = {}
|
|
248
|
+
Object.keys(cache).forEach((key) => {
|
|
249
|
+
data[key] = cache[key]
|
|
250
|
+
})
|
|
251
|
+
// we want to save the geometry cache under '.solidsCache'
|
|
252
|
+
return { path: '.solidsCache', options: { isRawData: true }, origin: design.origin }
|
|
253
|
+
},
|
|
254
|
+
|
|
255
|
+
// what do we want to save, return an object containing only that data?
|
|
256
|
+
requestSaveSettings: ({ design }) => keep(serializableFields, design),
|
|
257
|
+
|
|
258
|
+
// helpers
|
|
259
|
+
isDesignValid: (state) => (state.design && state.design.name && state.design.path !== ''),
|
|
260
|
+
|
|
261
|
+
// determine if a design has remained the same : does NOT include solids, as they are a result of all the other parameters
|
|
262
|
+
isDesignTheSame: (previousState, state) => {
|
|
263
|
+
if (!previousState.design) {
|
|
264
|
+
return false
|
|
265
|
+
}
|
|
266
|
+
const current = JSON.stringify(keep(designEqualityFields, state.design))
|
|
267
|
+
const previous = JSON.stringify(keep(designEqualityFields, previousState.design))
|
|
268
|
+
return previous === current
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
// same as above but with added fields for settings
|
|
272
|
+
isDesignTheSameForSerialization: (previousState, state) => {
|
|
273
|
+
if (!previousState.design) {
|
|
274
|
+
return false
|
|
275
|
+
}
|
|
276
|
+
// do a JSON compare of the previous & current fields to save if needed
|
|
277
|
+
const current = JSON.stringify(keep(serializableFields, state.design))
|
|
278
|
+
const previous = JSON.stringify(keep(serializableFields, previousState.design))
|
|
279
|
+
return previous === current
|
|
280
|
+
},
|
|
281
|
+
|
|
282
|
+
// ui/toggles
|
|
283
|
+
toggleAutoReload: (state, autoReload) => {
|
|
284
|
+
const design = Object.assign({}, state.design, { autoReload })
|
|
285
|
+
return { design }
|
|
286
|
+
},
|
|
287
|
+
|
|
288
|
+
toggleInstantUpdate: (state, instantUpdate) => {
|
|
289
|
+
const design = Object.assign({}, state.design, { instantUpdate })
|
|
290
|
+
return { design }
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
toggleVtreeMode: (state, vtreeMode) => {
|
|
294
|
+
const design = Object.assign({}, state.design, { vtreeMode })
|
|
295
|
+
return { design }
|
|
296
|
+
},
|
|
297
|
+
|
|
298
|
+
setSolidsTimeout: (state, solidsTimeOut) => {
|
|
299
|
+
const design = Object.assign({}, state.design, { solidsTimeOut })
|
|
300
|
+
return { design }
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
module.exports = reducers
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// title : Benchmark CAG
|
|
2
|
-
// author : Z3 Development
|
|
3
|
-
// license : MIT License
|
|
4
|
-
// description: testing how fast the CAG objects are created
|
|
5
|
-
|
|
6
|
-
function main () {
|
|
7
|
-
echo('OpenJSCAD ' + OpenJsCad.version + ' CSG Benchmark');
|
|
8
|
-
|
|
9
|
-
var p = {
|
|
10
|
-
'rectangles': CAG.rectangle,
|
|
11
|
-
'roundedRectangles': CAG.roundedRectangle,
|
|
12
|
-
'circles': CAG.circle
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
var o = [];
|
|
16
|
-
for (var i in p) {
|
|
17
|
-
var n = 100;
|
|
18
|
-
var start = new Date();
|
|
19
|
-
for (var j = 0; j < n; j++) {
|
|
20
|
-
o.push(p[i]());
|
|
21
|
-
}
|
|
22
|
-
var t = (new Date() - start) / n; // milliseconds per iteration
|
|
23
|
-
t = 1000 / t; // iterations per second
|
|
24
|
-
echo(i + ' ' + t.toFixed(4) + ' iterations / sec');
|
|
25
|
-
}
|
|
26
|
-
return o[0];
|
|
27
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// title : Benchmark
|
|
2
|
-
// author : Z3 Development
|
|
3
|
-
// license : MIT License
|
|
4
|
-
// description: testing how fast the CSG objects are created
|
|
5
|
-
|
|
6
|
-
function main () {
|
|
7
|
-
echo('OpenJSCAD ' + OpenJsCad.version + ' CSG Benchmark');
|
|
8
|
-
|
|
9
|
-
var p = {
|
|
10
|
-
'cubes': CSG.cube,
|
|
11
|
-
'roundedCubes': CSG.roundedCube,
|
|
12
|
-
'spheres': CSG.sphere,
|
|
13
|
-
'cylinders': CSG.cylinder,
|
|
14
|
-
'roundedCylinders': CSG.roundedCylinder
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
var o = [];
|
|
18
|
-
for (var i in p) {
|
|
19
|
-
var n = 100;
|
|
20
|
-
var start = new Date();
|
|
21
|
-
for (var j = 0; j < n; j++) {
|
|
22
|
-
o.push(p[i]());
|
|
23
|
-
}
|
|
24
|
-
var t = (new Date() - start) / n; // milliseconds per iteration
|
|
25
|
-
t = 1000 / t; // iterations per second
|
|
26
|
-
echo(i + ' ' + t.toFixed(4) + ' interations / sec');
|
|
27
|
-
}
|
|
28
|
-
return o[0];
|
|
29
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// title : Benchmark SCAD Compatibility
|
|
2
|
-
// author : Rene K. Mueller
|
|
3
|
-
// license : MIT License
|
|
4
|
-
// description: testing how fast the computations are done
|
|
5
|
-
// file : benchmark.jscad
|
|
6
|
-
|
|
7
|
-
function main () {
|
|
8
|
-
var p = { 'spheres': sphere, 'cubes': cube, 'cylinders': cylinder, 'torus': torus };
|
|
9
|
-
var o = [];
|
|
10
|
-
var sum = 0;
|
|
11
|
-
echo('OpenJSCAD ' + OpenJsCad.version + ' Benchmark');
|
|
12
|
-
for (var i in p) {
|
|
13
|
-
var n = 100;
|
|
14
|
-
var start = new Date();
|
|
15
|
-
for (var j = 0; j < n; j++) {
|
|
16
|
-
o.push(p[i]());
|
|
17
|
-
}
|
|
18
|
-
var t = (new Date() - start) / n; // milliseconds per iteration
|
|
19
|
-
t = 1000 / t; // iterations per second
|
|
20
|
-
echo(i + ' ' + t.toFixed(4) + ' iterations / sec');
|
|
21
|
-
sum += t;
|
|
22
|
-
}
|
|
23
|
-
echo('total ' + sum.toFixed(4));
|
|
24
|
-
return o[0];
|
|
25
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// title : Bunch of Cubes
|
|
2
|
-
// author : Rene K. Mueller
|
|
3
|
-
// license : MIT License
|
|
4
|
-
// description: creating 100 cubes in space ...
|
|
5
|
-
// file : bunch-cubes.jscad
|
|
6
|
-
|
|
7
|
-
function main () {
|
|
8
|
-
var cubes = [];
|
|
9
|
-
|
|
10
|
-
for (var i = 0; i < 100; i++) {
|
|
11
|
-
cubes.push(
|
|
12
|
-
translate([150 * Math.random() - 75, 150 * Math.random() - 75, 150 * Math.random() - 75],
|
|
13
|
-
cube(5).setColor(hsl2rgb(Math.random() * 0.2 + 0.7, 1, 0.5)))
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
return cubes;
|
|
17
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// title : Example 001
|
|
2
|
-
// author : OpenSCAD.org, adapted by Rene K. Mueller
|
|
3
|
-
// license : MIT License
|
|
4
|
-
// description: example001.scad ported to OpenJSCAD.org
|
|
5
|
-
// file : example001.jscad
|
|
6
|
-
|
|
7
|
-
function radiusFromDiameter (d) {
|
|
8
|
-
return d / 2;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function rotcy (rot, r, h) {
|
|
12
|
-
return rotate(rot, cylinder({r: r, h: h, center: true}));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function example001 () {
|
|
16
|
-
var size = 50;
|
|
17
|
-
var hole = 25;
|
|
18
|
-
var radius = radiusFromDiameter(hole);
|
|
19
|
-
var height = radiusFromDiameter(size * 2.5);
|
|
20
|
-
|
|
21
|
-
return difference(
|
|
22
|
-
sphere({r: radiusFromDiameter(size)}),
|
|
23
|
-
rotcy([0, 0, 0], radius, height),
|
|
24
|
-
rotcy([90, 0, 0], radius, height),
|
|
25
|
-
rotcy([0, 90, 0], radius, height)
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function main () {
|
|
30
|
-
return example001();
|
|
31
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// title : Example 002
|
|
2
|
-
// author : OpenSCAD.org, adapted by Rene K. Mueller
|
|
3
|
-
// license : MIT License
|
|
4
|
-
// description: example002.scad ported to OpenJSCAD.org
|
|
5
|
-
// file : example002.jscad
|
|
6
|
-
|
|
7
|
-
function example002 () {
|
|
8
|
-
return intersection(
|
|
9
|
-
difference(
|
|
10
|
-
union(
|
|
11
|
-
cube({size: [30, 30, 30], center: true}),
|
|
12
|
-
translate([0, 0, -25], cube({size: [15, 15, 50], center: true}))
|
|
13
|
-
),
|
|
14
|
-
union(
|
|
15
|
-
cube({size: [50, 10, 10], center: true}),
|
|
16
|
-
cube({size: [10, 50, 10], center: true}),
|
|
17
|
-
cube({size: [10, 10, 50], center: true})
|
|
18
|
-
)
|
|
19
|
-
),
|
|
20
|
-
translate([0, 0, 5], cylinder({h: 50, r1: 20, r2: 5, center: true})));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function main () {
|
|
24
|
-
return example002();
|
|
25
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// title : Example 003
|
|
2
|
-
// author : OpenSCAD.org, adapted by Rene K. Mueller
|
|
3
|
-
// license : MIT License
|
|
4
|
-
// description: example003.scad ported to OpenJSCAD.org
|
|
5
|
-
// file : example003.jscad
|
|
6
|
-
|
|
7
|
-
function example003 () {
|
|
8
|
-
return difference(
|
|
9
|
-
union(
|
|
10
|
-
cube({size: [30, 30, 30], center: true}),
|
|
11
|
-
cube({size: [40, 15, 15], center: true}),
|
|
12
|
-
cube({size: [15, 40, 15], center: true}),
|
|
13
|
-
cube({size: [15, 15, 40], center: true})
|
|
14
|
-
),
|
|
15
|
-
union(
|
|
16
|
-
cube({size: [50, 10, 10], center: true}),
|
|
17
|
-
cube({size: [10, 50, 10], center: true}),
|
|
18
|
-
cube({size: [10, 10, 50], center: true})
|
|
19
|
-
)
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function main () {
|
|
24
|
-
return example003();
|
|
25
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// title : Example 004
|
|
2
|
-
// author : OpenSCAD.org, adapted by Rene K. Mueller
|
|
3
|
-
// license : MIT License
|
|
4
|
-
// description: example004.scad ported to OpenJSCAD.org
|
|
5
|
-
// file : example004.jscad
|
|
6
|
-
|
|
7
|
-
function example004 () {
|
|
8
|
-
return difference(
|
|
9
|
-
cube({size: 30, center: true}),
|
|
10
|
-
sphere(20)
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function main () {
|
|
15
|
-
return example004();
|
|
16
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// title : Example 005
|
|
2
|
-
// author : OpenSCAD.org, adapted by Rene K. Mueller
|
|
3
|
-
// license : MIT License
|
|
4
|
-
// description: example005.scad ported to OpenJSCAD
|
|
5
|
-
// file : example005.jscad
|
|
6
|
-
|
|
7
|
-
function example005 () {
|
|
8
|
-
var cy = [];
|
|
9
|
-
for (var i = 0; i <= 5; i++) {
|
|
10
|
-
cy[i] = translate([sin(360 * i / 6) * 80, cos(360 * i / 6) * 80, 0], cylinder({h: 200, r: 10}));
|
|
11
|
-
}
|
|
12
|
-
return translate([0, 0, -120],
|
|
13
|
-
union(
|
|
14
|
-
difference(
|
|
15
|
-
cylinder({h: 50, r: 100}),
|
|
16
|
-
translate([0, 0, 10], cylinder({h: 50, r: 80})),
|
|
17
|
-
translate([100, 0, 35], cube({size: 50, center: true}))
|
|
18
|
-
),
|
|
19
|
-
cy,
|
|
20
|
-
translate([0, 0, 200], cylinder({h: 80, r1: 120, r2: 0}))
|
|
21
|
-
)
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function main () {
|
|
26
|
-
return example005().scale(1 / 3);
|
|
27
|
-
}
|