@jscad/x3d-deserializer 2.2.10 → 3.0.1-alpha.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/src/objects.js CHANGED
@@ -1,6 +1,6 @@
1
- const { maths } = require('@jscad/modeling')
1
+ import { area } from '@jscad/modeling'
2
2
 
3
- const x3dTypes = {
3
+ export const x3dTypes = {
4
4
  X3D: 0,
5
5
  UNIT: 1,
6
6
  META: 2,
@@ -43,14 +43,14 @@ const x3dTypes = {
43
43
  }
44
44
 
45
45
  // document level node, basically a group
46
- const x3dX3D = (element) => {
46
+ export const x3dX3D = (element) => {
47
47
  const obj = { definition: x3dTypes.X3D }
48
48
 
49
49
  obj.objects = []
50
50
  return obj
51
51
  }
52
52
 
53
- const x3dUnit = (element) => {
53
+ export const x3dUnit = (element) => {
54
54
  const obj = { definition: x3dTypes.UNIT, category: '', name: '', conversionFactor: 1.0 }
55
55
 
56
56
  if (element.category) obj.category = element.category
@@ -60,7 +60,7 @@ const x3dUnit = (element) => {
60
60
  return obj
61
61
  }
62
62
 
63
- const x3dMeta = (element) => {
63
+ export const x3dMeta = (element) => {
64
64
  const obj = { definition: x3dTypes.META, content: '', name: '' }
65
65
 
66
66
  if (element.content) obj.content = element.content
@@ -70,7 +70,7 @@ const x3dMeta = (element) => {
70
70
  }
71
71
 
72
72
  // scenes contain various other nodes, basically a group
73
- const x3dScene = (element) => {
73
+ export const x3dScene = (element) => {
74
74
  const obj = { definition: x3dTypes.SCENE }
75
75
  obj.objects = []
76
76
  return obj
@@ -78,7 +78,7 @@ const x3dScene = (element) => {
78
78
 
79
79
  // transforms contain various other nodes, basically a group
80
80
  // horrific order of transforms... see http://edutechwiki.unige.ch/en/X3D_grouping_and_transforms
81
- const x3dTransform = (element) => {
81
+ export const x3dTransform = (element) => {
82
82
  const obj = {
83
83
  definition: x3dTypes.TRANSFORM,
84
84
  center: [0, 0, 0],
@@ -124,7 +124,7 @@ const x3dTransform = (element) => {
124
124
  }
125
125
 
126
126
  // shapes contain geometry and appearance, in any order
127
- const x3dShape = (element) => {
127
+ export const x3dShape = (element) => {
128
128
  const obj = { definition: x3dTypes.SHAPE }
129
129
  obj.objects = []
130
130
  return obj
@@ -134,7 +134,7 @@ const x3dShape = (element) => {
134
134
  // 3D shapes
135
135
  //
136
136
 
137
- const x3dBox = (element) => {
137
+ export const x3dBox = (element) => {
138
138
  const obj = { definition: x3dTypes.BOX, size: [2, 2, 2] }
139
139
 
140
140
  if (element.size) {
@@ -146,7 +146,7 @@ const x3dBox = (element) => {
146
146
  return obj
147
147
  }
148
148
 
149
- const x3dCone = (element) => {
149
+ export const x3dCone = (element) => {
150
150
  const NEAR0 = 0.00001
151
151
  const obj = { definition: x3dTypes.CONE, bottomRadius: 1, height: 2, subdivision: 32, topRadius: NEAR0 }
152
152
 
@@ -165,7 +165,7 @@ const x3dCone = (element) => {
165
165
  return obj
166
166
  }
167
167
 
168
- const x3dCylinder = (element) => {
168
+ export const x3dCylinder = (element) => {
169
169
  const obj = { definition: x3dTypes.CYLINDER, height: 2, radius: 1, subdivision: 32 }
170
170
 
171
171
  if (element.height) {
@@ -180,7 +180,7 @@ const x3dCylinder = (element) => {
180
180
  return obj
181
181
  }
182
182
 
183
- const x3dSphere = (element) => {
183
+ export const x3dSphere = (element) => {
184
184
  const obj = { definition: x3dTypes.SPHERE, radius: 1, subdivision: 24 }
185
185
 
186
186
  if (element.radius) {
@@ -195,7 +195,7 @@ const x3dSphere = (element) => {
195
195
  return obj
196
196
  }
197
197
 
198
- const x3dExtrusion = (element) => {
198
+ export const x3dExtrusion = (element) => {
199
199
  const obj = {
200
200
  definition: x3dTypes.EXTRUSION,
201
201
  ccw: true,
@@ -224,7 +224,7 @@ const x3dExtrusion = (element) => {
224
224
  const vi = i * 2
225
225
  points.push([values[vi], values[vi + 1]])
226
226
  }
227
- obj.ccw = (maths.utils.area(points) < 0) // WHAT!!!! X3D IS SICK!!!
227
+ obj.ccw = (area(points) < 0) // WHAT!!!! X3D IS SICK!!!
228
228
  obj.crossSection = points
229
229
  }
230
230
  if (element.orientation) {
@@ -267,7 +267,7 @@ const x3dExtrusion = (element) => {
267
267
  // 2D shapes
268
268
  //
269
269
 
270
- const x3dArc2D = (element) => {
270
+ export const x3dArc2D = (element) => {
271
271
  const obj = { definition: x3dTypes.ARC2D, endAngle: Math.PI / 2, radius: 1, startAngle: 0, subdivision: 32 }
272
272
 
273
273
  if (element.endAngle) {
@@ -285,7 +285,7 @@ const x3dArc2D = (element) => {
285
285
  return obj
286
286
  }
287
287
 
288
- const x3dArcClose2D = (element) => {
288
+ export const x3dArcClose2D = (element) => {
289
289
  const obj = { definition: x3dTypes.ARCCLOSE2D, closureType: 'PIE', endAngle: Math.PI / 2, radius: 1, startAngle: 0, subdivision: 32 }
290
290
 
291
291
  if (element.closureType) {
@@ -306,7 +306,7 @@ const x3dArcClose2D = (element) => {
306
306
  return obj
307
307
  }
308
308
 
309
- const x3dCircle2D = (element) => {
309
+ export const x3dCircle2D = (element) => {
310
310
  const obj = { definition: x3dTypes.CIRCLE2D, radius: 1, subdivision: 32 }
311
311
 
312
312
  if (element.radius) {
@@ -318,7 +318,7 @@ const x3dCircle2D = (element) => {
318
318
  return obj
319
319
  }
320
320
 
321
- const x3dDisk2D = (element) => {
321
+ export const x3dDisk2D = (element) => {
322
322
  const obj = { definition: x3dTypes.DISK2D, innerRadius: 0, outerRadius: 1, subdivision: 32 }
323
323
 
324
324
  if (element.innerRadius) {
@@ -333,7 +333,7 @@ const x3dDisk2D = (element) => {
333
333
  return obj
334
334
  }
335
335
 
336
- const x3dPolyline2D = (element) => {
336
+ export const x3dPolyline2D = (element) => {
337
337
  const obj = { definition: x3dTypes.POLYLINE2D, lineSegments: [] }
338
338
 
339
339
  if (element.lineSegments) {
@@ -346,7 +346,7 @@ const x3dPolyline2D = (element) => {
346
346
  return obj
347
347
  }
348
348
 
349
- const x3dRectangle2D = (element) => {
349
+ export const x3dRectangle2D = (element) => {
350
350
  const obj = { definition: x3dTypes.RECTANGLE2D, size: [2, 2] }
351
351
 
352
352
  if (element.size) {
@@ -358,7 +358,7 @@ const x3dRectangle2D = (element) => {
358
358
  return obj
359
359
  }
360
360
 
361
- const x3dTriangleSet2D = (element) => {
361
+ export const x3dTriangleSet2D = (element) => {
362
362
  const obj = { definition: x3dTypes.TRIANGLESET2D, vertices: [] }
363
363
 
364
364
  if (element.vertices) {
@@ -375,7 +375,7 @@ const x3dTriangleSet2D = (element) => {
375
375
  // Lines
376
376
  //
377
377
 
378
- const x3dLineSet = (element) => {
378
+ export const x3dLineSet = (element) => {
379
379
  const obj = { definition: x3dTypes.LINESET, vertexCount: [], colorPerVertex: true }
380
380
 
381
381
  if (element.vertexCount) {
@@ -389,7 +389,7 @@ const x3dLineSet = (element) => {
389
389
  return obj
390
390
  }
391
391
 
392
- const x3dIndexedLineSet = (element) => {
392
+ export const x3dIndexedLineSet = (element) => {
393
393
  const obj = { definition: x3dTypes.INDEXEDLINESET, indexes: [], colorPerVertex: true }
394
394
 
395
395
  if (element.coordIndex) {
@@ -408,7 +408,7 @@ const x3dIndexedLineSet = (element) => {
408
408
  // Meshs
409
409
  //
410
410
 
411
- const x3dColor = (element) => {
411
+ export const x3dColor = (element) => {
412
412
  const obj = { definition: x3dTypes.COLOR, colors: [] }
413
413
 
414
414
  if (element.color) {
@@ -423,7 +423,7 @@ const x3dColor = (element) => {
423
423
  return obj
424
424
  }
425
425
 
426
- const x3dCoordinate = (element) => {
426
+ export const x3dCoordinate = (element) => {
427
427
  const obj = { definition: x3dTypes.COORDINATE, points: [] }
428
428
 
429
429
  if (element.point) {
@@ -438,7 +438,7 @@ const x3dCoordinate = (element) => {
438
438
  return obj
439
439
  }
440
440
 
441
- const x3dTriangleSet = (element) => {
441
+ export const x3dTriangleSet = (element) => {
442
442
  const obj = { definition: x3dTypes.TRIANGLESET, ccw: true, colorPerVertex: true }
443
443
 
444
444
  if (element.ccw) {
@@ -448,7 +448,7 @@ const x3dTriangleSet = (element) => {
448
448
  return obj
449
449
  }
450
450
 
451
- const x3dTriangleFanSet = (element) => {
451
+ export const x3dTriangleFanSet = (element) => {
452
452
  const obj = { definition: x3dTypes.TRIANGLEFANSET, ccw: true, fanCount: [], colorPerVertex: true }
453
453
 
454
454
  if (element.ccw) {
@@ -461,7 +461,7 @@ const x3dTriangleFanSet = (element) => {
461
461
  return obj
462
462
  }
463
463
 
464
- const x3dTriangleStripSet = (element) => {
464
+ export const x3dTriangleStripSet = (element) => {
465
465
  const obj = { definition: x3dTypes.TRIANGLESTRIPSET, ccw: true, stripCount: [], colorPerVertex: true }
466
466
 
467
467
  if (element.ccw) {
@@ -474,7 +474,7 @@ const x3dTriangleStripSet = (element) => {
474
474
  return obj
475
475
  }
476
476
 
477
- const x3dQuadSet = (element) => {
477
+ export const x3dQuadSet = (element) => {
478
478
  const obj = { definition: x3dTypes.QUADSET, ccw: true, colorPerVertex: true }
479
479
 
480
480
  if (element.ccw) {
@@ -484,7 +484,7 @@ const x3dQuadSet = (element) => {
484
484
  return obj
485
485
  }
486
486
 
487
- const x3dIndexedTriangleSet = (element) => {
487
+ export const x3dIndexedTriangleSet = (element) => {
488
488
  const obj = { definition: x3dTypes.INDEXEDTRIANGLESET, ccw: true, index: [], colorPerVertex: true }
489
489
 
490
490
  if (element.ccw) {
@@ -497,7 +497,7 @@ const x3dIndexedTriangleSet = (element) => {
497
497
  return obj
498
498
  }
499
499
 
500
- const x3dIndexedTriangleFanSet = (element) => {
500
+ export const x3dIndexedTriangleFanSet = (element) => {
501
501
  const obj = { definition: x3dTypes.INDEXEDTRIANGLEFANSET, ccw: true, fans: [], colorPerVertex: true }
502
502
 
503
503
  if (element.ccw) {
@@ -511,7 +511,7 @@ const x3dIndexedTriangleFanSet = (element) => {
511
511
  return obj
512
512
  }
513
513
 
514
- const x3dIndexedTriangleStripSet = (element) => {
514
+ export const x3dIndexedTriangleStripSet = (element) => {
515
515
  const obj = { definition: x3dTypes.INDEXEDTRIANGLESTRIPSET, ccw: true, strips: [], colorPerVertex: true }
516
516
 
517
517
  obj.objects = []
@@ -525,7 +525,7 @@ const x3dIndexedTriangleStripSet = (element) => {
525
525
  return obj
526
526
  }
527
527
 
528
- const x3dIndexedQuadSet = (element) => {
528
+ export const x3dIndexedQuadSet = (element) => {
529
529
  const obj = { definition: x3dTypes.INDEXEDQUADSET, ccw: true, index: [], colorPerVertex: true }
530
530
 
531
531
  if (element.ccw) {
@@ -538,7 +538,7 @@ const x3dIndexedQuadSet = (element) => {
538
538
  return obj
539
539
  }
540
540
 
541
- const x3dIndexedFaceSet = (element) => {
541
+ export const x3dIndexedFaceSet = (element) => {
542
542
  const obj = { definition: x3dTypes.INDEXEDFACESET, ccw: true, convex: true, faces: [], colorPerVertex: true, colorIndex: null }
543
543
 
544
544
  if (element.ccw) {
@@ -572,7 +572,7 @@ const x3dIndexedFaceSet = (element) => {
572
572
  return obj
573
573
  }
574
574
 
575
- const x3dElevationGrid = (element) => {
575
+ export const x3dElevationGrid = (element) => {
576
576
  const obj = { definition: x3dTypes.ELEVATIONGRID, xDimension: 2, zDimension: 2, xSpacing: 1.0, zSpacing: 1.0, height: [0, 0, 0, 0], ccw: true, solid: false, colorPerVertex: true }
577
577
 
578
578
  if (element.xDimension) {
@@ -609,14 +609,14 @@ const x3dElevationGrid = (element) => {
609
609
  // Materials
610
610
  //
611
611
 
612
- const x3dAppearance = (element) => {
612
+ export const x3dAppearance = (element) => {
613
613
  const obj = { definition: x3dTypes.APPEARANCE }
614
614
 
615
615
  obj.objects = []
616
616
  return obj
617
617
  }
618
618
 
619
- const x3dMaterial = (element) => {
619
+ export const x3dMaterial = (element) => {
620
620
  const obj = { definition: x3dTypes.MATERIAL, color: [0.8, 0.8, 0.8, 1.0] }
621
621
 
622
622
  // convert material to colors if possible
@@ -649,62 +649,17 @@ const x3dMaterial = (element) => {
649
649
 
650
650
  // GROUPS
651
651
 
652
- const x3dGroup = (element) => {
652
+ export const x3dGroup = (element) => {
653
653
  const obj = { definition: x3dTypes.GROUP }
654
654
 
655
655
  obj.objects = []
656
656
  return obj
657
657
  }
658
658
 
659
- const parseNumbers = (attribute) =>
659
+ export const parseNumbers = (attribute) =>
660
660
  attribute.trim().replace(/,/g, ' ').split(/ +/).map((v) => parseFloat(v))
661
661
 
662
- const parseIndices = (attribute) => {
662
+ export const parseIndices = (attribute) => {
663
663
  const indexes = attribute.replace(/,/g, ' ').trim().split(/ -1/)
664
664
  return indexes.map((index) => parseNumbers(index))
665
665
  }
666
-
667
- module.exports = {
668
- x3dTypes,
669
-
670
- x3dX3D,
671
- x3dUnit,
672
- x3dMeta,
673
- x3dScene,
674
- x3dTransform,
675
- x3dShape,
676
- x3dGroup,
677
-
678
- x3dBox,
679
- x3dCone,
680
- x3dCylinder,
681
- x3dSphere,
682
- x3dExtrusion,
683
-
684
- x3dArc2D,
685
- x3dArcClose2D,
686
- x3dCircle2D,
687
- x3dDisk2D,
688
- x3dPolyline2D,
689
- x3dRectangle2D,
690
- x3dTriangleSet2D,
691
-
692
- x3dColor,
693
- x3dCoordinate,
694
- x3dTriangleSet,
695
- x3dTriangleFanSet,
696
- x3dTriangleStripSet,
697
- x3dQuadSet,
698
- x3dIndexedTriangleSet,
699
- x3dIndexedTriangleFanSet,
700
- x3dIndexedTriangleStripSet,
701
- x3dIndexedQuadSet,
702
- x3dIndexedFaceSet,
703
- x3dElevationGrid,
704
-
705
- x3dLineSet,
706
- x3dIndexedLineSet,
707
-
708
- x3dAppearance,
709
- x3dMaterial
710
- }
package/src/parse.js CHANGED
@@ -1,6 +1,6 @@
1
- const saxes = require('saxes')
1
+ import * as saxes from 'saxes'
2
2
 
3
- const {
3
+ import {
4
4
  x3dTypes,
5
5
 
6
6
  x3dX3D,
@@ -43,7 +43,7 @@ const {
43
43
 
44
44
  x3dAppearance,
45
45
  x3dMaterial
46
- } = require('./objects')
46
+ } from './objects.js'
47
47
 
48
48
  const nodeToObjectMap = {
49
49
  X3D: x3dX3D,
@@ -92,34 +92,33 @@ const nodeToObjectMap = {
92
92
  let objectId = 1
93
93
  const getObjectId = () => ('0000' + objectId++).slice(-4)
94
94
 
95
- const createX3DParser = (src, pxPmm) => {
95
+ export const parse = (src) => {
96
96
  // create a parser for the XML
97
97
  const parser = new saxes.SaxesParser()
98
- const x3dDefs = new Map() // list of named objects
99
- let x3dLast = null // last object found
100
- let x3dDefinition = x3dTypes.X3D // what kind of object beinging created
101
- let x3dObj = null // x3d in object form
102
98
 
103
99
  // high level elements / definitions
100
+ let x3dLast = null // last object found
101
+ let x3dDefinition = x3dTypes.X3D // what kind of object being created
102
+
104
103
  const x3dObjects = [] // list of objects
104
+ const x3dDefs = new Map() // list of named objects
105
+
105
106
  const x3dMaterials = [] // list of materials
106
107
  const x3dTextures = [] // list of textures
107
108
 
108
109
  const x3dLength = { factor: 1.0, name: 'meters' }
109
110
  const x3dAngle = { factor: 1.0, name: 'radians' }
110
111
 
112
+ let x3dObj = null // x3d in object form
113
+
111
114
  parser.on('error', (e) => {
112
- console.log(
113
- `error: line ${e.line}, column ${e.column}, bad character [${e.c}]`
114
- )
115
+ console.log(`error: line ${e.line}, column ${e.column}, bad character [${e.c}]`)
115
116
  })
116
117
 
117
118
  parser.on('opentag', (node) => {
118
119
  // convert known XML tags to objects
119
120
  const elementname = node.name.toUpperCase()
120
- let obj = nodeToObjectMap[elementname]
121
- ? nodeToObjectMap[elementname](node.attributes, { x3dObjects })
122
- : null
121
+ let obj = nodeToObjectMap[elementname] ? nodeToObjectMap[elementname](node.attributes, { x3dObjects }) : null
123
122
 
124
123
  if (obj) {
125
124
  obj.id = getObjectId()
@@ -130,23 +129,17 @@ const createX3DParser = (src, pxPmm) => {
130
129
  if (x3dDefs.has(objectname)) {
131
130
  const def = x3dDefs.get(objectname)
132
131
  if (def.definition !== obj.definition) {
133
- console.log(
134
- `WARNING: using a definition "${objectname}" of a different type; ${obj.definition} vs ${def.definition}`
135
- )
132
+ console.log(`WARNING: using a definition "${objectname}" of a different type; ${obj.definition} vs ${def.definition}`)
136
133
  }
137
134
  obj = def
138
135
  } else {
139
- console.log(
140
- `WARNING: definition "${objectname}" does not exist, using default for ${obj.definition}`
141
- )
136
+ console.log(`WARNING: definition "${objectname}" does not exist, using default for ${obj.definition}`)
142
137
  }
143
138
  } else {
144
139
  if (node.attributes.DEF) {
145
140
  const objectname = node.attributes.DEF
146
141
  if (x3dDefs.has(objectname)) {
147
- console.log(
148
- `WARNING: redefintion of ${objectname} has been ignored`
149
- )
142
+ console.log(`WARNING: redefintion of ${objectname} has been ignored`)
150
143
  } else {
151
144
  x3dDefs.set(objectname, obj)
152
145
  }
@@ -339,11 +332,7 @@ const createX3DParser = (src, pxPmm) => {
339
332
  // start the parser
340
333
  parser.write(src).close()
341
334
 
342
- return {
343
- x3dObj,
344
- x3dMaterials,
345
- x3dTextures
346
- }
335
+ // return the results
336
+ // console.log(JSON.stringify(x3dObj))
337
+ return { x3dObj, x3dMaterials, x3dTextures }
347
338
  }
348
-
349
- module.exports = createX3DParser
package/src/translate.js CHANGED
@@ -1,19 +1,17 @@
1
- const translateDefinitions = require('./translateDefinitions')
1
+ import { translateDefinitions } from './translateDefinitions.js'
2
+ import { x3dTypes } from './objects.js'
3
+ import { parse } from './parse.js'
2
4
 
3
- const { x3dTypes } = require('./objects')
4
- const parse = require('./parse')
5
-
6
- const translate = (options, src) => {
5
+ export const translate = (options, src) => {
7
6
  const defaults = {
8
- pxPmm: require('./constants').pxPmm
9
7
  }
10
8
  options = Object.assign({}, defaults, options)
11
- const { version, pxPmm, addMetaData, filename } = options
9
+ const { version, addMetaData, filename } = options
12
10
 
13
11
  options && options.statusCallback && options.statusCallback({ progress: 0 })
14
12
 
15
13
  // parse the X3D source
16
- const { x3dObj, x3dMaterials, x3dTextures } = parse(src, pxPmm)
14
+ const { x3dObj, x3dMaterials, x3dTextures } = parse(src)
17
15
 
18
16
  // convert the internal objects to JSCAD code
19
17
  let code = addMetaData
@@ -58,22 +56,9 @@ const codify = (x3d, data) => {
58
56
  // Units : ${length.name} (${length.factor})
59
57
  // Angles : ${angle.name} (${angle.factor})
60
58
 
61
- const {booleans, extrusions, geometries, maths, primitives, transforms, utils} = require('@jscad/modeling')
62
- const { colorize } = require('@jscad/modeling').colors
63
-
64
- const applyTransform = (matrix, ...objects) => {
65
- objects = utils.flatten(objects)
66
- if (objects.length === 0) return objects
67
-
68
- return objects.map((object) => {
69
- const color = object.color
70
- object = transforms.transform(matrix, object)
71
- if (color) object.color = color
72
- return object
73
- })
74
- }
59
+ import * from '@jscad/modeling'
75
60
 
76
- const main = () => {
61
+ export const main = () => {
77
62
  let options = {}
78
63
  let objects = []
79
64
  `
@@ -87,9 +72,5 @@ const main = () => {
87
72
 
88
73
  code += translateDefinitions({}, objects)
89
74
 
90
- code += 'module.exports = {main}\n'
91
-
92
75
  return code
93
76
  }
94
-
95
- module.exports = translate
@@ -1,8 +1,8 @@
1
- const createTransform = require('./createTransform')
1
+ import { createTransform } from './createTransform.js'
2
2
 
3
- const { x3dTypes } = require('./objects')
3
+ import { x3dTypes } from './objects.js'
4
4
 
5
- const translateShape = require('./translateShape')
5
+ import { translateShape } from './translateShape.js'
6
6
 
7
7
  // horrific order of transforms... see http://edutechwiki.unige.ch/en/X3D_grouping_and_transforms
8
8
  const translateTransform = (options, object) => {
@@ -23,7 +23,7 @@ const createObjects${object.id} = (options) => {
23
23
  // apply the transforms if any
24
24
  code += `
25
25
  const matrix = [${matrix}]
26
- return applyTransform(matrix, objects)
26
+ return transform(matrix, objects)
27
27
  }
28
28
  `
29
29
 
@@ -81,6 +81,4 @@ const translateDefinition = (options, object) => {
81
81
  }
82
82
 
83
83
  // convert the given X3D objects into a series of JSCAD function definitions
84
- const translateDefinitions = (options, objects) => objects.reduce((code, object, index) => code += translateDefinition(options, object), '')
85
-
86
- module.exports = translateDefinitions
84
+ export const translateDefinitions = (options, objects) => objects.reduce((code, object, index) => code += translateDefinition(options, object), '')
@@ -1,8 +1,8 @@
1
- const { x3dTypes } = require('./objects')
1
+ import { x3dTypes } from './objects.js'
2
2
 
3
- const findNode = (x3dtype, objects) => objects.find((object) => object.definition === x3dtype)
3
+ export const findNode = (x3dtype, objects) => objects.find((object) => object.definition === x3dtype)
4
4
 
5
- const findColor = (objects, options) => {
5
+ export const findColor = (objects, options) => {
6
6
  const appearance = findNode(x3dTypes.APPEARANCE, objects)
7
7
  let material
8
8
  if (appearance) {
@@ -19,9 +19,9 @@ const findColor = (objects, options) => {
19
19
  return null
20
20
  }
21
21
 
22
- const pointToString = (point) => `[${point}]`
22
+ export const pointToString = (point) => `[${point}]`
23
23
 
24
- const pointsToString = (triangle) => {
24
+ export const pointsToString = (triangle) => {
25
25
  const strings = triangle.map((point) => pointToString(point))
26
26
  return `[
27
27
  ${strings.join(',\n ')}
@@ -66,7 +66,7 @@ const createColorsFromFaceColors = (colorIndex, faceColors) => {
66
66
  }
67
67
 
68
68
  // create a list of colors from the given shape and color objects
69
- const createColors = (shape, color) => {
69
+ export const createColors = (shape, color) => {
70
70
  if (!color) return null
71
71
  if (!Array.isArray(shape.colorIndex)) return null
72
72
 
@@ -78,13 +78,3 @@ const createColors = (shape, color) => {
78
78
  }
79
79
  return colors
80
80
  }
81
-
82
- module.exports = {
83
- findNode,
84
- findColor,
85
-
86
- createColors,
87
-
88
- pointToString,
89
- pointsToString
90
- }
@@ -1,8 +1,8 @@
1
- const { pointsToString } = require('./translateHelpers')
1
+ import { pointsToString } from './translateHelpers.js'
2
2
 
3
- const { convertLine } = require('./instantiateLine')
3
+ import { convertLine } from './instantiateLine.js'
4
4
 
5
- const translateLine = (options, objects) => {
5
+ export const translateLine = (options, objects) => {
6
6
  const components = convertLine(options, objects)
7
7
  if (components) {
8
8
  const { pointsSet, colors } = components
@@ -24,5 +24,3 @@ const translateLine = (options, objects) => {
24
24
  }
25
25
  return null
26
26
  }
27
-
28
- module.exports = translateLine
@@ -1,10 +1,10 @@
1
- const { pointsToString } = require('./translateHelpers')
1
+ import { pointsToString } from './translateHelpers.js'
2
2
 
3
- const { convertMesh } = require('./instantiateMesh')
3
+ import { convertMesh } from './instantiateMesh.js'
4
4
 
5
5
  const translateToPolyhedron = (type, points, faces, colors, orientation) => {
6
6
  const colorsCode = Array.isArray(colors) ? pointsToString(colors) : 'null'
7
- const primitive = 'primitives.polyhedron({points, faces, colors, orientation})'
7
+ const primitive = 'polyhedron({points, faces, colors, orientation})'
8
8
  const code = `
9
9
  // 3D ${type} set: ${points.length} points, ${faces.length} faces
10
10
  const points = ${pointsToString(points)}
@@ -19,7 +19,7 @@ const translateToPolyhedron = (type, points, faces, colors, orientation) => {
19
19
  * Translate the given objects into mesh (polyhedron).
20
20
  * @return { primitive, code }
21
21
  */
22
- const translateMesh = (options, objects) => {
22
+ export const translateMesh = (options, objects) => {
23
23
  const components = convertMesh(options, objects)
24
24
  if (components) {
25
25
  const { type, points, faces, colors, orientation } = components
@@ -27,5 +27,3 @@ const translateMesh = (options, objects) => {
27
27
  }
28
28
  return null
29
29
  }
30
-
31
- module.exports = translateMesh