@jscad/core 2.3.8 → 2.5.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jscad/core",
3
- "version": "2.3.8",
3
+ "version": "2.5.2",
4
4
  "description": "Core functionality for JSCAD Applications",
5
5
  "repository": "https://github.com/jscad/OpenJSCAD.org",
6
6
  "main": "src/index.js",
@@ -34,11 +34,10 @@
34
34
  ],
35
35
  "license": "MIT",
36
36
  "dependencies": {
37
- "@jscad/array-utils": "2.1.0",
38
- "@jscad/io": "2.0.9",
39
- "@jscad/io-utils": "2.0.8",
40
- "@jscad/modeling": "2.5.3",
41
- "@jscad/vtree": "2.0.9",
37
+ "@jscad/array-utils": "2.1.1",
38
+ "@jscad/io": "2.2.2",
39
+ "@jscad/io-utils": "2.0.12",
40
+ "@jscad/modeling": "2.7.1",
42
41
  "json5": "2.2.0",
43
42
  "strip-bom": "4.0.0"
44
43
  },
@@ -53,5 +52,5 @@
53
52
  "url": "https://opencollective.com/openjscad",
54
53
  "logo": "https://opencollective.com/openjscad/logo.txt"
55
54
  },
56
- "gitHead": "0bfbc72afe89ef8dc4f332acf55858831f173d6e"
55
+ "gitHead": "c8ac21281a7acf5a5575b940c18353c598ffa1a4"
57
56
  }
@@ -1,5 +1,3 @@
1
- const makeBuildCachedGeometryFromTree = require('@jscad/vtree').buildCachedGeometry
2
-
3
1
  const isGeom2 = require('@jscad/modeling').geometries.geom2.isA
4
2
  const isGeom3 = require('@jscad/modeling').geometries.geom3.isA
5
3
  const isPath2 = require('@jscad/modeling').geometries.path2.isA
@@ -18,98 +16,17 @@ const isResultGeometry = (results) => {
18
16
  return false
19
17
  }
20
18
 
21
- const lookupFromCompactBinary = (compactLookup = {}) => {
22
- // console.log('lookupFromCompactBinary', compactLookup)
23
- // TODO: optimise this !!
24
- const lookup = {}
25
- Object.keys(compactLookup).forEach((key) => {
26
- const object = compactLookup[key]
27
- let result
28
- if (object[0] === 0) { // Geom2
29
- result = require('@jscad/modeling').geometries.geom2.fromCompactBinary(object)
30
- }
31
- if (object[0] === 1) { // Geom3
32
- result = require('@jscad/modeling').geometries.geom3.fromCompactBinary(object)
33
- }
34
- if (object[0] === 2) { // Path2
35
- result = require('@jscad/modeling').geometries.path2.fromCompactBinary(object)
36
- }
37
- lookup[key] = result
38
- })
39
- return lookup
40
- }
41
-
42
- const toJSON = (data) => JSON.stringify(data, (key, value) => {
43
- if (value instanceof Int8Array ||
44
- value instanceof Uint8Array ||
45
- value instanceof Uint8ClampedArray ||
46
- value instanceof Int16Array ||
47
- value instanceof Uint16Array ||
48
- value instanceof Int32Array ||
49
- value instanceof Uint32Array ||
50
- value instanceof Float32Array ||
51
- value instanceof Float64Array) {
52
- const replacement = {
53
- constructor: value.constructor.name,
54
- data: Array.apply([], value),
55
- flag: 'FLAG_TYPED_ARRAY'
56
- }
57
- return replacement
58
- }
59
- return value
60
- })
61
-
62
- const lookupToCompactBinary = (lookup) => {
63
- // FIXME: optimise this !!
64
- const compactLookup = {}
65
- Object.keys(lookup).forEach((key) => {
66
- const object = lookup[key]
67
- let result = object
68
- if (isGeom2(object)) {
69
- compactLookup[key] = require('@jscad/modeling').geometries.geom2.toCompactBinary(object)
70
- } else if (isGeom3(object)) {
71
- compactLookup[key] = require('@jscad/modeling').geometries.geom3.toCompactBinary(object)
72
- } else if (isPath2(object)) {
73
- compactLookup[key] = require('@jscad/modeling').geometries.path2.toCompactBinary(object)
74
- } else {
75
- result = toJSON(object)
76
- compactLookup[key] = result
77
- }
78
- })
79
- return compactLookup
80
- }
81
-
82
19
  const instanciateDesign = (rootModule, parameterValues, options) => {
83
- const { vtreeMode, serialize } = options
20
+ const { serialize } = options
84
21
  // deal with the actual solids generation
85
22
  let solids
86
23
  const rawResults = flatten(toArray(rootModule.main(parameterValues)))
87
24
 
88
- if (vtreeMode) {
89
- console.log('input lookup', options.lookup)
90
- let lookup = lookupFromCompactBinary(options.lookup)
91
- const lookupCounts = options.lookupCounts || {}
92
-
93
- console.log('lookup after', lookup)
94
- // const start = new Date()
95
- const buildCachedGeometryFromTree = makeBuildCachedGeometryFromTree({ passesBeforeElimination: 5, lookup, lookupCounts })
96
- solids = buildCachedGeometryFromTree({}, rawResults)
97
- console.log('created lookup', lookup, lookupCounts)
98
- // console.log('solids, vtree', solids, 'lookup', lookup)
99
- // console.warn(`buildCachedGeometryFromTree`, new Date() - start)//, rawResults, solids)
100
- // TODO: return both solids and cache instead of mutating ?
101
- lookup = lookupToCompactBinary(lookup)
102
- console.log('compact lookup', lookup)
103
-
104
- solids = serialize ? serializeSolids(solids) : solids
105
- return { solids, lookup, lookupCounts }
25
+ if (isResultGeometry(rawResults)) {
26
+ solids = serialize ? serializeSolids(rawResults) : rawResults
27
+ return { solids }
106
28
  } else {
107
- if (isResultGeometry(rawResults)) {
108
- solids = serialize ? serializeSolids(rawResults) : rawResults
109
- return { solids }
110
- } else {
111
- throw new Error('bad output from script: expected geom3/geom2/path2 objects')
112
- }
29
+ throw new Error('bad output from script: expected geom3/geom2/path2 objects')
113
30
  }
114
31
  }
115
32
 
@@ -12,7 +12,6 @@ const applyParameterDefinitions = require('../parameters/applyParameterDefinitio
12
12
  * @param {Array} data.filesAndFolders - array of files / directories
13
13
  * @param {String} [data.mainPath] - path of the file containing the main function (optional)
14
14
  * @param {Boolean} [data.serialize] - true to serialize the solids into JSON
15
- * @param {Boolean} [data.vtreeMode] - true to use the experimental Vtree caching (optional)
16
15
  * @param {Object} [data.lookup] - geometry cache lookup (optional)
17
16
  * @param {Object} [data.lookupCounts] - geometry cache lookup counts (optional)
18
17
  * @param {Object} [data.parameterValues] - over-rides of parameter values (optional)
@@ -28,15 +27,14 @@ const rebuildSolids = (data, callback) => {
28
27
  console.log('rebuildSolids',data)
29
28
  const defaults = {
30
29
  mainPath: '',
31
- vtreeMode: false,
32
- serialize: true,
30
+ apiMainPath: '@jscad/modeling',
31
+ serialize: false,
33
32
  lookup: null,
34
33
  lookupCounts: null,
35
34
  parameterValues: {}
36
35
  }
37
- let { mainPath, vtreeMode, serialize, lookup, lookupCounts, parameterValues } = Object.assign({}, defaults, data)
36
+ let { mainPath, apiMainPath, serialize, lookup, lookupCounts, parameterValues } = Object.assign({}, defaults, data)
38
37
 
39
- const apiMainPath = '@jscad/modeling'// vtreeMode ? '../code-loading/vtreeApi' : '@jscad/modeling'
40
38
  const filesAndFolders = data.filesAndFolders
41
39
 
42
40
  // let start = new Date()
@@ -56,7 +54,6 @@ const rebuildSolids = (data, callback) => {
56
54
  parameterValues = Object.assign({}, designData.parameterValues, parameterValues)
57
55
  // start = new Date()
58
56
  const options = {
59
- vtreeMode,
60
57
  lookup,
61
58
  lookupCounts,
62
59
  serialize
@@ -6,9 +6,11 @@ const getAllParameterDefintionsAndValues = require('../parameters/getParameterDe
6
6
  const makeWebRequire = require('../code-loading/webRequire')
7
7
 
8
8
  const rebuildSolids = (data) => {
9
- const defaults = { vtreeMode: false, serialize: false }
10
- let { mainPath, vtreeMode, parameterValues, useFakeFs } = Object.assign({}, defaults, data)
11
- const apiMainPath = vtreeMode ? '../code-loading/vtreeApi' : '@jscad/modeling'
9
+ const defaults = {
10
+ apiMainPath: '@jscad/modeling',
11
+ serialize: false
12
+ }
13
+ let { apiMainPath, serialize, mainPath, parameterValues, useFakeFs } = Object.assign({}, defaults, data)
12
14
  // we need to update the source for our module
13
15
  let requireFn = require
14
16
 
@@ -49,7 +49,7 @@ const makeWebRequire = (filesAndFolders, options) => {
49
49
  fakeFs: require('./makeFakeFs')(filesAndFolders)
50
50
  }
51
51
  const { apiMainPath, fakeFs } = Object.assign({}, defaults, options)
52
- const apiModule = apiMainPath === '@jscad/modeling' ? require('@jscad/modeling') : require('./vtreeApi')
52
+ const apiModule = apiMainPath === '@jscad/modeling' ? require('@jscad/modeling') : require(apiMainPath)
53
53
 
54
54
  // preset core modules
55
55
  // FIXME this list of modules should be an option, replacing apiMainPath