@jscad/dxf-deserializer 2.3.27 → 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/CHANGELOG.md +14 -201
- package/LICENSE +1 -1
- package/README.md +3 -1
- package/dist/jscad-dxf-deserializer.es.js +7 -0
- package/dist/jscad-dxf-deserializer.min.js +7 -0
- package/package.json +21 -11
- package/rollup.config.js +27 -0
- package/src/DxfReader.js +241 -0
- package/{autocad.js → src/autocad.js} +4 -17
- package/{colorindex2014.js → src/colorindex2014.js} +1 -3
- package/{colorindex2017.js → src/colorindex2017.js} +1 -3
- package/{helpers.js → src/helpers.js} +4 -19
- package/{index.js → src/index.js} +69 -77
- package/{instantiate.js → src/instantiate.js} +54 -67
- package/{translate.js → src/translate.js} +50 -70
- package/tests/test-2d-entities.js +39 -38
- package/tests/test-2d-translation.js +17 -17
- package/tests/test-3d-entities.js +18 -18
- package/tests/test-3d-translation.js +6 -6
- package/tests/test-DxfReader.js +8 -7
- package/tests/test-dxf-versions.js +12 -11
- package/tests/test-dxf.js +6 -5
- package/DxfReader.js +0 -250
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
2
|
AutoCAD Constants
|
|
3
|
-
|
|
4
|
-
## License
|
|
5
|
-
|
|
6
|
-
Copyright (c) 2017 Z3 Development https://github.com/z3dev
|
|
7
|
-
|
|
8
|
-
All code released under MIT license
|
|
9
3
|
*/
|
|
10
4
|
|
|
11
5
|
//
|
|
@@ -35,12 +29,12 @@ const dxfTLA = [
|
|
|
35
29
|
|
|
36
30
|
const dxfMap = new Map(dxfTLA)
|
|
37
31
|
|
|
38
|
-
const getTLA = (group) => dxfMap.get(group)
|
|
32
|
+
export const getTLA = (group) => dxfMap.get(group)
|
|
39
33
|
|
|
40
34
|
/*
|
|
41
35
|
* AutoCAD Drawing Units
|
|
42
36
|
*/
|
|
43
|
-
const drawingUnits = [
|
|
37
|
+
export const drawingUnits = [
|
|
44
38
|
[0, 'none'],
|
|
45
39
|
[1, 'inches'],
|
|
46
40
|
[2, 'feet'],
|
|
@@ -64,12 +58,5 @@ const drawingUnits = [
|
|
|
64
58
|
[20, 'parsecs']
|
|
65
59
|
]
|
|
66
60
|
|
|
67
|
-
const BYBLOCK = 0
|
|
68
|
-
const BYLAYER = 256
|
|
69
|
-
|
|
70
|
-
module.exports = {
|
|
71
|
-
drawingUnits,
|
|
72
|
-
BYBLOCK,
|
|
73
|
-
BYLAYER,
|
|
74
|
-
getTLA
|
|
75
|
-
}
|
|
61
|
+
export const BYBLOCK = 0
|
|
62
|
+
export const BYLAYER = 256
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* AutoCAD 2014 Color Index (1-255) as RGB + ALPHA colors
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
const colorIndex = [
|
|
5
|
+
export const colorIndex = [
|
|
6
6
|
[0, 0, 0, 255], // index 0, added for easy maintenance
|
|
7
7
|
// 1
|
|
8
8
|
[255, 0, 0, 255],
|
|
@@ -286,5 +286,3 @@ const colorIndex = [
|
|
|
286
286
|
[224, 224, 224, 255],
|
|
287
287
|
[0, 0, 0, 255]
|
|
288
288
|
]
|
|
289
|
-
|
|
290
|
-
module.exports = colorIndex
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* AutoCAD 2017 2018 Color Index (1-255) as RGB + ALPHA colors
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
const colorIndex = [
|
|
5
|
+
export const colorIndex = [
|
|
6
6
|
[0, 0, 0, 255], // index 0, added for easy maintenance
|
|
7
7
|
// 1
|
|
8
8
|
[255, 0, 0, 255],
|
|
@@ -286,5 +286,3 @@ const colorIndex = [
|
|
|
286
286
|
[204, 204, 204, 255],
|
|
287
287
|
[255, 255, 255, 255]
|
|
288
288
|
]
|
|
289
|
-
|
|
290
|
-
module.exports = colorIndex
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
## License
|
|
3
|
-
|
|
4
|
-
Copyright (c) 2017-2019 Z3 Development https://github.com/z3dev
|
|
5
|
-
|
|
6
|
-
All code released under MIT license
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const { BYBLOCK, BYLAYER } = require('./autocad')
|
|
1
|
+
import { BYBLOCK, BYLAYER } from './autocad.js'
|
|
11
2
|
|
|
12
3
|
//
|
|
13
4
|
// find the layer referenced by the given object
|
|
14
5
|
//
|
|
15
|
-
const findLayer = (obj, layers) => {
|
|
6
|
+
export const findLayer = (obj, layers) => {
|
|
16
7
|
const lname = obj.lnam || '0'
|
|
17
8
|
for (const layer of layers) {
|
|
18
9
|
if (layer.name === lname) {
|
|
@@ -26,7 +17,7 @@ const findLayer = (obj, layers) => {
|
|
|
26
17
|
// get the color number of the object, possibly looking at layer
|
|
27
18
|
// returns -1 if a color number was not found
|
|
28
19
|
//
|
|
29
|
-
const getColorNumber = (obj, layers) => {
|
|
20
|
+
export const getColorNumber = (obj, layers) => {
|
|
30
21
|
let cn = obj.cnmb || -1
|
|
31
22
|
if (cn === BYLAYER) {
|
|
32
23
|
// use the color number from the layer
|
|
@@ -50,7 +41,7 @@ const mod = (num, mod) => {
|
|
|
50
41
|
//
|
|
51
42
|
// instantiate color using the given index into the given color index
|
|
52
43
|
// Note: 0 > index <= length of colorindex
|
|
53
|
-
const getColor = (index, colorindex) => {
|
|
44
|
+
export const getColor = (index, colorindex) => {
|
|
54
45
|
if (index < 1) { return null }
|
|
55
46
|
|
|
56
47
|
index = mod(index, colorindex.length)
|
|
@@ -58,9 +49,3 @@ const getColor = (index, colorindex) => {
|
|
|
58
49
|
const rgba = [color[0] / 255, color[1] / 255, color[2] / 255, color[3] / 255]
|
|
59
50
|
return rgba
|
|
60
51
|
}
|
|
61
|
-
|
|
62
|
-
module.exports = {
|
|
63
|
-
findLayer,
|
|
64
|
-
getColor,
|
|
65
|
-
getColorNumber
|
|
66
|
-
}
|
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
## License
|
|
1
|
+
import { ensureString } from '@jscad/io-utils'
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
import { BYLAYER, getTLA } from './autocad.js'
|
|
4
|
+
import { colorIndex } from './colorindex2017.js'
|
|
5
|
+
import { DxfReader } from './DxfReader.js'
|
|
6
|
+
import { instantiateAsciiDxf } from './instantiate.js'
|
|
7
|
+
import { translateAsciiDxf } from './translate.js'
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const { ensureString } = require('@jscad/io-utils')
|
|
11
|
-
|
|
12
|
-
const version = require('./package.json').version
|
|
13
|
-
|
|
14
|
-
const { BYLAYER, getTLA } = require('./autocad')
|
|
15
|
-
const colorIndex = require('./colorindex2017')
|
|
16
|
-
const dxf = require('./DxfReader')
|
|
17
|
-
const { instantiateAsciiDxf } = require('./instantiate')
|
|
18
|
-
const translateAsciiDxf = require('./translate')
|
|
9
|
+
const version = '[VI]{version}[/VI]' // version is injected by rollup
|
|
19
10
|
|
|
20
11
|
// //////////////////////////////////////////
|
|
21
12
|
//
|
|
@@ -278,7 +269,7 @@ const handleXcoord = (reader, group, value) => {
|
|
|
278
269
|
const obj = reader.objstack.pop()
|
|
279
270
|
if ('type' in obj) {
|
|
280
271
|
if (obj.type === 'lwpolyline') {
|
|
281
|
-
|
|
272
|
+
// special handling to build a list of vertices
|
|
282
273
|
if (obj.pptxs === undefined) {
|
|
283
274
|
obj.pptxs = []
|
|
284
275
|
obj.bulgs = []
|
|
@@ -287,7 +278,7 @@ const handleXcoord = (reader, group, value) => {
|
|
|
287
278
|
obj.bulgs.push(0)
|
|
288
279
|
} else {
|
|
289
280
|
if (obj.type === 'mesh') {
|
|
290
|
-
|
|
281
|
+
// special handling to build a list of vertices
|
|
291
282
|
if (obj.pptxs === undefined) {
|
|
292
283
|
obj.pptxs = []
|
|
293
284
|
}
|
|
@@ -310,7 +301,7 @@ const handleYcoord = (reader, group, value) => {
|
|
|
310
301
|
const obj = reader.objstack.pop()
|
|
311
302
|
if ('type' in obj) {
|
|
312
303
|
if (obj.type === 'lwpolyline' || obj.type === 'mesh') {
|
|
313
|
-
|
|
304
|
+
// special handling to build a list of vertices
|
|
314
305
|
if (obj.pptys === undefined) {
|
|
315
306
|
obj.pptys = []
|
|
316
307
|
}
|
|
@@ -332,7 +323,7 @@ const handleZcoord = (reader, group, value) => {
|
|
|
332
323
|
const obj = reader.objstack.pop()
|
|
333
324
|
if ('type' in obj) {
|
|
334
325
|
if (obj.type === 'mesh') {
|
|
335
|
-
|
|
326
|
+
// special handling to build a list of vertices
|
|
336
327
|
if (obj.pptzs === undefined) {
|
|
337
328
|
obj.pptzs = []
|
|
338
329
|
}
|
|
@@ -354,7 +345,7 @@ const handleBulge = (reader, group, value) => {
|
|
|
354
345
|
const obj = reader.objstack.pop()
|
|
355
346
|
if ('type' in obj) {
|
|
356
347
|
if (obj.type === 'lwpolyline') {
|
|
357
|
-
|
|
348
|
+
// special handling to build a list of vertices
|
|
358
349
|
const bulgs = obj.bulgs
|
|
359
350
|
if (bulgs !== undefined) {
|
|
360
351
|
const pptxs = obj.pptxs
|
|
@@ -379,7 +370,7 @@ const handleLen = (reader, group, value) => {
|
|
|
379
370
|
const obj = reader.objstack.pop()
|
|
380
371
|
if ('type' in obj) {
|
|
381
372
|
if (obj.type === 'mesh') {
|
|
382
|
-
|
|
373
|
+
// mesh has an order of lengths
|
|
383
374
|
const state = obj.state
|
|
384
375
|
// console.log('mesh len: '+group+','+value+','+state)
|
|
385
376
|
switch (group) {
|
|
@@ -493,64 +484,65 @@ const handleName = (reader, group, value) => {
|
|
|
493
484
|
//
|
|
494
485
|
const createReader = (src, options) => {
|
|
495
486
|
// create a reader for the DXF
|
|
496
|
-
const
|
|
487
|
+
const dxfreader = new DxfReader(options)
|
|
497
488
|
|
|
498
489
|
// setup event handling from the reader
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
490
|
+
dxfreader.on('error', handleError)
|
|
491
|
+
dxfreader.on('start', handleStart)
|
|
492
|
+
dxfreader.on('end', handleEnd)
|
|
502
493
|
|
|
503
494
|
// setup group handling
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
495
|
+
dxfreader.absorb(0, handleEntity)
|
|
496
|
+
dxfreader.absorb(1, handleString)
|
|
497
|
+
dxfreader.absorb(2, handleName)
|
|
498
|
+
dxfreader.absorb(3, handleName)
|
|
499
|
+
dxfreader.absorb(6, handleString)
|
|
500
|
+
dxfreader.absorb(7, handleString)
|
|
501
|
+
dxfreader.absorb(8, handleString)
|
|
502
|
+
dxfreader.absorb(9, handleVariable)
|
|
503
|
+
dxfreader.absorb(10, handleXcoord)
|
|
504
|
+
dxfreader.absorb(11, handleDouble)
|
|
505
|
+
dxfreader.absorb(12, handleDouble)
|
|
506
|
+
dxfreader.absorb(13, handleDouble)
|
|
507
|
+
dxfreader.absorb(20, handleYcoord)
|
|
508
|
+
dxfreader.absorb(21, handleDouble)
|
|
509
|
+
dxfreader.absorb(22, handleDouble)
|
|
510
|
+
dxfreader.absorb(23, handleDouble)
|
|
511
|
+
dxfreader.absorb(30, handleZcoord)
|
|
512
|
+
dxfreader.absorb(31, handleDouble)
|
|
513
|
+
dxfreader.absorb(32, handleDouble)
|
|
514
|
+
dxfreader.absorb(33, handleDouble)
|
|
515
|
+
dxfreader.absorb(39, handleDouble)
|
|
516
|
+
dxfreader.absorb(40, handleDouble)
|
|
517
|
+
dxfreader.absorb(41, handleDouble)
|
|
518
|
+
dxfreader.absorb(42, handleBulge)
|
|
519
|
+
dxfreader.absorb(50, handleDouble)
|
|
520
|
+
dxfreader.absorb(51, handleDouble)
|
|
521
|
+
dxfreader.absorb(62, handleInt)
|
|
522
|
+
dxfreader.absorb(70, handleInt)
|
|
523
|
+
dxfreader.absorb(71, handleInt)
|
|
524
|
+
dxfreader.absorb(72, handleInt)
|
|
525
|
+
dxfreader.absorb(73, handleInt)
|
|
526
|
+
dxfreader.absorb(74, handleInt)
|
|
527
|
+
dxfreader.absorb(75, handleInt)
|
|
528
|
+
dxfreader.absorb(90, handleValue)
|
|
529
|
+
dxfreader.absorb(91, handleLen) // MESH
|
|
530
|
+
dxfreader.absorb(92, handleLen) // MESH
|
|
531
|
+
dxfreader.absorb(93, handleLen) // MESH
|
|
532
|
+
dxfreader.absorb(94, handleLen) // MESH
|
|
533
|
+
dxfreader.absorb(95, handleLen) // MESH
|
|
534
|
+
dxfreader.absorb(210, handleInt)
|
|
535
|
+
dxfreader.absorb(220, handleInt)
|
|
536
|
+
dxfreader.absorb(230, handleInt)
|
|
546
537
|
|
|
547
538
|
// initial state
|
|
548
|
-
|
|
549
|
-
|
|
539
|
+
dxfreader.objstack = []
|
|
540
|
+
dxfreader.objstack.push({ type: 'dxf' })
|
|
550
541
|
|
|
551
542
|
// start the reader
|
|
552
|
-
|
|
553
|
-
|
|
543
|
+
dxfreader.write(src)
|
|
544
|
+
dxfreader.close()
|
|
545
|
+
return dxfreader
|
|
554
546
|
}
|
|
555
547
|
|
|
556
548
|
//
|
|
@@ -604,13 +596,13 @@ const deserialize = (options, src) => {
|
|
|
604
596
|
}
|
|
605
597
|
options = Object.assign({}, defaults, options)
|
|
606
598
|
|
|
607
|
-
src = ensureString(src)
|
|
599
|
+
src = ensureString(src);
|
|
608
600
|
return options.output === 'script' ? translate(src, options) : instantiate(src, options)
|
|
609
601
|
}
|
|
610
602
|
|
|
611
|
-
const
|
|
603
|
+
const mimeType = 'image/vnd.dxf'
|
|
612
604
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
605
|
+
export {
|
|
606
|
+
mimeType,
|
|
607
|
+
deserialize
|
|
616
608
|
}
|
|
@@ -1,38 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
## License
|
|
1
|
+
import { arc, circle, ellipse, geom2, geom3, mat4, line, path2, poly3, vec2, vec3 } from '@jscad/modeling'
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
import { getColor, getColorNumber } from './helpers.js'
|
|
5
4
|
|
|
6
|
-
All code released under MIT license
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
const { geometries, maths, primitives } = require('@jscad/modeling')
|
|
10
5
|
const EPS = 1e-5 // FIXME
|
|
11
6
|
|
|
12
|
-
const { getColor, getColorNumber } = require('./helpers')
|
|
13
|
-
|
|
14
7
|
//
|
|
15
8
|
// instantiate the given object (3dface) as a polygon
|
|
16
9
|
//
|
|
17
|
-
const instantiatePolygon = (obj, layers, options) => {
|
|
10
|
+
export const instantiatePolygon = (obj, layers, options) => {
|
|
18
11
|
const vertices = []
|
|
19
12
|
// FIXME: should check global variable to instantiate in the proper orientation
|
|
20
|
-
vertices.push(
|
|
21
|
-
vertices.push(
|
|
22
|
-
vertices.push(
|
|
13
|
+
vertices.push(vec3.fromValues(obj.pptx, obj.ppty, obj.pptz))
|
|
14
|
+
vertices.push(vec3.fromValues(obj.sptx, obj.spty, obj.sptz))
|
|
15
|
+
vertices.push(vec3.fromValues(obj.tptx, obj.tpty, obj.tptz))
|
|
23
16
|
if (obj.fptx) {
|
|
24
17
|
let pushit = false
|
|
25
18
|
if (obj.tptx !== obj.fptx) { pushit = true }
|
|
26
19
|
if (obj.tpty !== obj.fpty) { pushit = true }
|
|
27
20
|
if (obj.tptz !== obj.fptz) { pushit = true }
|
|
28
21
|
if (pushit) {
|
|
29
|
-
vertices.push(
|
|
22
|
+
vertices.push(vec3.fromValues(obj.fptx, obj.fpty, obj.fptz))
|
|
30
23
|
}
|
|
31
24
|
}
|
|
32
25
|
const cn = getColorNumber(obj, layers)
|
|
33
26
|
const color = getColor(cn, options.colorindex)
|
|
34
27
|
|
|
35
|
-
const polygon =
|
|
28
|
+
const polygon = poly3.create(vertices)
|
|
36
29
|
if (color) polygon.color = color
|
|
37
30
|
return polygon
|
|
38
31
|
}
|
|
@@ -43,21 +36,21 @@ const instantiatePolygon = (obj, layers, options) => {
|
|
|
43
36
|
const instantiateLine = (obj, layers, options) => {
|
|
44
37
|
// console.log('***** instantiateLine',obj)
|
|
45
38
|
if (obj.pptz === obj.sptz && obj.pptz === 0) {
|
|
46
|
-
const p1 =
|
|
47
|
-
const p2 =
|
|
48
|
-
return
|
|
39
|
+
const p1 = vec2.fromValues(obj.pptx, obj.ppty)
|
|
40
|
+
const p2 = vec2.fromValues(obj.sptx, obj.spty)
|
|
41
|
+
return line([p1, p2])
|
|
49
42
|
}
|
|
50
43
|
|
|
51
|
-
const p1 =
|
|
52
|
-
const p2 =
|
|
44
|
+
const p1 = vec3.fromValues(obj.pptx, obj.ppty, obj.pptz)
|
|
45
|
+
const p2 = vec3.fromValues(obj.sptx, obj.spty, obj.sptz)
|
|
53
46
|
// FIXME what should this really create?
|
|
54
|
-
return
|
|
47
|
+
return line([p1, p2])
|
|
55
48
|
}
|
|
56
49
|
|
|
57
50
|
//
|
|
58
51
|
// instantiate the give object as 2D Vector or 3D Vector wrapped as an object
|
|
59
52
|
//
|
|
60
|
-
const instantiateVector = (obj) => {
|
|
53
|
+
export const instantiateVector = (obj) => {
|
|
61
54
|
const d3line = parseInt('00000000000100000', 2)
|
|
62
55
|
const d3mesh = parseInt('00000000001000000', 2)
|
|
63
56
|
const d3face = parseInt('00000000010000000', 2)
|
|
@@ -65,20 +58,20 @@ const instantiateVector = (obj) => {
|
|
|
65
58
|
const flags = obj.lflg
|
|
66
59
|
const vtype = {}
|
|
67
60
|
if ((flags & d3line) === d3line) {
|
|
68
|
-
vtype.vec =
|
|
61
|
+
vtype.vec = vec3.fromValues(obj.pptx, obj.ppty, obj.pptz)
|
|
69
62
|
} else
|
|
70
63
|
if ((flags & d3mesh) === d3mesh) {
|
|
71
|
-
vtype.vec =
|
|
64
|
+
vtype.vec = vec3.fromValues(obj.pptx, obj.ppty, obj.pptz)
|
|
72
65
|
} else
|
|
73
66
|
if ((flags & d3face) === d3face) {
|
|
74
|
-
vtype.vec =
|
|
67
|
+
vtype.vec = vec3.fromValues(obj.pptx, obj.ppty, obj.pptz)
|
|
75
68
|
// pass on face indexes
|
|
76
69
|
vtype.fvia = obj.fvia
|
|
77
70
|
vtype.fvib = obj.fvib
|
|
78
71
|
vtype.fvic = obj.fvic
|
|
79
72
|
vtype.fvid = obj.fvid
|
|
80
73
|
} else {
|
|
81
|
-
vtype.vec =
|
|
74
|
+
vtype.vec = vec2.fromValues(obj.pptx, obj.ppty)
|
|
82
75
|
vtype.bulg = obj.bulg // for rendering curved sections
|
|
83
76
|
}
|
|
84
77
|
return vtype
|
|
@@ -90,20 +83,20 @@ const instantiateVector = (obj) => {
|
|
|
90
83
|
const addSection = (path, x1, y1, bulg) => {
|
|
91
84
|
if (bulg === 0) {
|
|
92
85
|
// add straight line to the end of the path
|
|
93
|
-
path =
|
|
86
|
+
path = path2.appendPoints([[x1, y1]], path)
|
|
94
87
|
} else {
|
|
95
88
|
// add arc to the end of the path
|
|
96
|
-
const points =
|
|
89
|
+
const points = path2.toPoints(path)
|
|
97
90
|
const prev = points[points.length - 1]
|
|
98
|
-
const curr =
|
|
99
|
-
const u =
|
|
91
|
+
const curr = vec2.fromValues(x1, y1)
|
|
92
|
+
const u = vec2.distance(prev, curr)
|
|
100
93
|
const r = u * ((1 + Math.pow(bulg, 2)) / (4 * bulg))
|
|
101
94
|
const clockwise = (bulg < 0)
|
|
102
95
|
const large = false // FIXME how to determine?
|
|
103
96
|
const d = Math.atan(bulg) * 4
|
|
104
97
|
// FIXME; how to determine resolution
|
|
105
98
|
const res = 16
|
|
106
|
-
path =
|
|
99
|
+
path = path2.appendArc({ endpoint: [x1, y1], radius: [r, r], xaxisrotation: d, clockwise: clockwise, large: large, segments: res }, path)
|
|
107
100
|
}
|
|
108
101
|
return path
|
|
109
102
|
}
|
|
@@ -123,7 +116,7 @@ const instantiatePath2D = (obj, layers, options) => {
|
|
|
123
116
|
const flags = obj.lflg
|
|
124
117
|
|
|
125
118
|
// conversion
|
|
126
|
-
let path =
|
|
119
|
+
let path = path2.create()
|
|
127
120
|
const isclosed = ((flags & closed) === closed)
|
|
128
121
|
if (vlen === pptxs.length && vlen === pptys.length && vlen === bulgs.length) {
|
|
129
122
|
pptxs.forEach((item, index, array) => {
|
|
@@ -140,7 +133,7 @@ const instantiatePath2D = (obj, layers, options) => {
|
|
|
140
133
|
if (isclosed && (!path.isClosed)) {
|
|
141
134
|
// apply the last section between last and first points
|
|
142
135
|
path = addSection(path, pptxs[0], pptys[0], bulgs[vlen - 1])
|
|
143
|
-
path =
|
|
136
|
+
path = path2.close(path)
|
|
144
137
|
// FIXME add optional to create 2D geometry from the path
|
|
145
138
|
}
|
|
146
139
|
return path
|
|
@@ -166,10 +159,10 @@ const instantiateArc = (obj, layers, options) => {
|
|
|
166
159
|
// conversion
|
|
167
160
|
if (lthk === 0.0) {
|
|
168
161
|
// convert to 2D object
|
|
169
|
-
return
|
|
162
|
+
return arc({ center: [pptx, ppty], radius: swid, startAngle: ang0, endAngle: ang1, segments: res })
|
|
170
163
|
}
|
|
171
164
|
// FIXME how to represent 3D arc?
|
|
172
|
-
return
|
|
165
|
+
return arc({ center: [pptx, ppty], radius: swid, startAngle: ang0, endAngle: ang1, segments: res })
|
|
173
166
|
}
|
|
174
167
|
|
|
175
168
|
//
|
|
@@ -191,12 +184,12 @@ const instantiateCircle = (obj, layers, options) => {
|
|
|
191
184
|
|
|
192
185
|
// convert to 2D object
|
|
193
186
|
if (lthk === 0.0) {
|
|
194
|
-
const cag =
|
|
187
|
+
const cag = circle({ center: [pptx, ppty], radius: swid, segments: res })
|
|
195
188
|
if (color) cag.color = color
|
|
196
189
|
return cag
|
|
197
190
|
}
|
|
198
191
|
// convert to 3D object
|
|
199
|
-
const cag =
|
|
192
|
+
const cag = circle({ center: [pptx, ppty], radius: swid, segments: res })
|
|
200
193
|
const csg = cag.extrude({ offset: [0, 0, lthk] })
|
|
201
194
|
// FIXME need to use 210/220/230 for direction of extrusion
|
|
202
195
|
if (color) csg.color = color
|
|
@@ -220,19 +213,19 @@ const instantiateEllipse = (obj, layers, options) => {
|
|
|
220
213
|
|
|
221
214
|
// convert to 2D object
|
|
222
215
|
if (pptz === 0.0 && sptz === 0.0) {
|
|
223
|
-
const center =
|
|
224
|
-
const mjaxis =
|
|
225
|
-
const rx =
|
|
216
|
+
const center = vec2.fromValues(0, 0)
|
|
217
|
+
const mjaxis = vec2.fromValues(sptx, spty)
|
|
218
|
+
const rx = vec2.distance(center, mjaxis)
|
|
226
219
|
const ry = rx * swid
|
|
227
220
|
let angle = Math.atan2(spty, sptx) * 180 / Math.PI
|
|
228
221
|
if (angle < EPS) angle = 0
|
|
229
222
|
angle = angle * 0.017453292519943295 // radians
|
|
230
223
|
|
|
231
224
|
// FIXME add start and end angle when supported
|
|
232
|
-
const cag =
|
|
233
|
-
const matrix =
|
|
234
|
-
|
|
235
|
-
return
|
|
225
|
+
const cag = ellipse({ center: [0, 0], radius: [rx, ry], segments: res })
|
|
226
|
+
const matrix = mat4.fromZRotation(mat4.create(), angle)
|
|
227
|
+
mat4.multiply(matrix, matrix, mat4.fromTranslation(mat4.create(), [pptx, ppty, 0]))
|
|
228
|
+
return geom2.transform(matrix, cag)
|
|
236
229
|
}
|
|
237
230
|
// convert to 3D object
|
|
238
231
|
}
|
|
@@ -297,7 +290,7 @@ const instantiateMesh = (obj, layers, options) => {
|
|
|
297
290
|
let vi = 0
|
|
298
291
|
while (vi < face.length) {
|
|
299
292
|
const pi = face[vi]
|
|
300
|
-
const vertex =
|
|
293
|
+
const vertex = vec3.clone(points[pi])
|
|
301
294
|
vertices.push(vertex)
|
|
302
295
|
vi++
|
|
303
296
|
}
|
|
@@ -306,7 +299,7 @@ const instantiateMesh = (obj, layers, options) => {
|
|
|
306
299
|
}
|
|
307
300
|
// FIXME how to correct bad normals?
|
|
308
301
|
|
|
309
|
-
const poly =
|
|
302
|
+
const poly = poly3.create(vertices)
|
|
310
303
|
if (color) poly.color = color
|
|
311
304
|
polygons.push(poly)
|
|
312
305
|
|
|
@@ -318,7 +311,7 @@ const instantiateMesh = (obj, layers, options) => {
|
|
|
318
311
|
} else {
|
|
319
312
|
// invalid vlen
|
|
320
313
|
}
|
|
321
|
-
return
|
|
314
|
+
return geom3.create(polygons)
|
|
322
315
|
}
|
|
323
316
|
|
|
324
317
|
// works for both POLYLINE
|
|
@@ -336,16 +329,16 @@ const getPolyType = (obj) => {
|
|
|
336
329
|
ptype = null // FIXME what to do?
|
|
337
330
|
} else
|
|
338
331
|
if ((flags & d3mesh) === d3mesh) {
|
|
339
|
-
ptype =
|
|
332
|
+
ptype = geom3.create()
|
|
340
333
|
ptype.closedM = ((flags & closedM) === closedM)
|
|
341
334
|
ptype.closedN = ((flags & closedN) === closedN)
|
|
342
335
|
} else
|
|
343
336
|
if ((flags & d3face) === d3face) {
|
|
344
|
-
ptype =
|
|
337
|
+
ptype = geom3.create()
|
|
345
338
|
ptype.closedM = ((flags & closedM) === closedM)
|
|
346
339
|
ptype.closedN = ((flags & closedN) === closedN)
|
|
347
340
|
} else {
|
|
348
|
-
ptype =
|
|
341
|
+
ptype = path2.create()
|
|
349
342
|
ptype.closedM = ((flags & closedM) === closedM)
|
|
350
343
|
}
|
|
351
344
|
if ('cnmb' in obj) { ptype.cnmb = obj.cnmb }
|
|
@@ -358,23 +351,23 @@ const getPolyType = (obj) => {
|
|
|
358
351
|
// - a series of vertex => vectors => 2D geometry
|
|
359
352
|
//
|
|
360
353
|
const completeCurrent = (objects, baseobj, polygons, vectors, options) => {
|
|
361
|
-
if (
|
|
354
|
+
if (path2.isA(baseobj)) {
|
|
362
355
|
// console.log('##### completing 2D geometry')
|
|
363
356
|
const points = vectors.map((vector) => vector.vec)
|
|
364
357
|
// FIXME add color support
|
|
365
|
-
objects.push(
|
|
358
|
+
objects.push(path2.fromPoints({ closed: baseobj.closed }, points))
|
|
366
359
|
}
|
|
367
|
-
if (
|
|
360
|
+
if (geom3.isA(baseobj)) {
|
|
368
361
|
// console.log('##### completing 3D geometry')
|
|
369
362
|
// FIXME add color support
|
|
370
|
-
objects.push(
|
|
363
|
+
objects.push(geom3.create(polygons))
|
|
371
364
|
}
|
|
372
365
|
return null
|
|
373
366
|
}
|
|
374
367
|
|
|
375
|
-
const instantiateAsciiDxf = (reader, options) => {
|
|
368
|
+
export const instantiateAsciiDxf = (reader, options) => {
|
|
376
369
|
// console.log('**************************************************')
|
|
377
|
-
// console.log(JSON.stringify(reader.objstack))
|
|
370
|
+
// console.log(JSON.stringify(reader.objstack))
|
|
378
371
|
// console.log('**************************************************')
|
|
379
372
|
|
|
380
373
|
const layers = [] // list of layers with various information like color
|
|
@@ -391,7 +384,7 @@ const instantiateAsciiDxf = (reader, options) => {
|
|
|
391
384
|
// console.log('##### skip')
|
|
392
385
|
continue
|
|
393
386
|
}
|
|
394
|
-
// console.log(JSON.stringify(obj))
|
|
387
|
+
// console.log(JSON.stringify(obj))
|
|
395
388
|
|
|
396
389
|
switch (obj.type) {
|
|
397
390
|
// control objects
|
|
@@ -412,7 +405,7 @@ const instantiateAsciiDxf = (reader, options) => {
|
|
|
412
405
|
p = instantiatePolygon(obj, layers, options)
|
|
413
406
|
if (current === null) {
|
|
414
407
|
// console.log('##### start of 3dfaces')
|
|
415
|
-
current =
|
|
408
|
+
current = geom3.create()
|
|
416
409
|
}
|
|
417
410
|
break
|
|
418
411
|
case 'mesh':
|
|
@@ -470,7 +463,7 @@ const instantiateAsciiDxf = (reader, options) => {
|
|
|
470
463
|
break
|
|
471
464
|
}
|
|
472
465
|
// accumlate polygons if necessary
|
|
473
|
-
if (
|
|
466
|
+
if (poly3.isA(p)) {
|
|
474
467
|
polygons.push(p)
|
|
475
468
|
}
|
|
476
469
|
// accumlate vectors if necessary
|
|
@@ -488,15 +481,9 @@ const instantiateAsciiDxf = (reader, options) => {
|
|
|
488
481
|
// console.log('**************************************************')
|
|
489
482
|
// objects.forEach(
|
|
490
483
|
// (e) => {
|
|
491
|
-
// console.log(JSON.stringify(e))
|
|
484
|
+
// console.log(JSON.stringify(e))
|
|
492
485
|
// }
|
|
493
|
-
// )
|
|
486
|
+
// )
|
|
494
487
|
// console.log('**************************************************')
|
|
495
488
|
return objects
|
|
496
489
|
}
|
|
497
|
-
|
|
498
|
-
module.exports = {
|
|
499
|
-
instantiatePolygon,
|
|
500
|
-
instantiateVector,
|
|
501
|
-
instantiateAsciiDxf
|
|
502
|
-
}
|