@jscad/x3d-deserializer 2.2.6 → 2.2.8
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 +19 -0
- package/package.json +3 -3
- package/src/parse.js +33 -26
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.2.8](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/x3d-deserializer@2.2.7...@jscad/x3d-deserializer@2.2.8) (2024-10-06)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @jscad/x3d-deserializer
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [2.2.7](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/x3d-deserializer@2.2.6...@jscad/x3d-deserializer@2.2.7) (2024-06-02)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **x3d-deserializer:** correcting caching of x3d attributes in createX3DParser, allowing continuous parsing of X3D files ([7f44197](https://github.com/jscad/OpenJSCAD.org/commit/7f4419776e2b0d485a4b2621d9f12927d31a0bbc))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [2.2.6](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/x3d-deserializer@2.2.5...@jscad/x3d-deserializer@2.2.6) (2024-02-18)
|
|
7
26
|
|
|
8
27
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jscad/x3d-deserializer",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.8",
|
|
4
4
|
"description": "X3D Deserializer for JSCAD",
|
|
5
5
|
"repository": "https://github.com/jscad/OpenJSCAD.org/",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@jscad/array-utils": "2.1.4",
|
|
30
|
-
"@jscad/modeling": "2.12.
|
|
30
|
+
"@jscad/modeling": "2.12.3",
|
|
31
31
|
"saxes": "5.0.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"ava": "3.15.0",
|
|
35
35
|
"nyc": "15.1.0"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "4627312c2337120447a607ff3ac3da10056ce132"
|
|
38
38
|
}
|
package/src/parse.js
CHANGED
|
@@ -45,21 +45,6 @@ const {
|
|
|
45
45
|
x3dMaterial
|
|
46
46
|
} = require('./objects')
|
|
47
47
|
|
|
48
|
-
let x3dLast = null // last object found
|
|
49
|
-
let x3dDefinition = x3dTypes.X3D // what kind of object beinging created
|
|
50
|
-
|
|
51
|
-
// high level elements / definitions
|
|
52
|
-
const x3dObjects = [] // list of objects
|
|
53
|
-
const x3dDefs = new Map() // list of named objects
|
|
54
|
-
|
|
55
|
-
const x3dMaterials = [] // list of materials
|
|
56
|
-
const x3dTextures = [] // list of textures
|
|
57
|
-
|
|
58
|
-
const x3dLength = { factor: 1.0, name: 'meters' }
|
|
59
|
-
const x3dAngle = { factor: 1.0, name: 'radians' }
|
|
60
|
-
|
|
61
|
-
let x3dObj = null // x3d in object form
|
|
62
|
-
|
|
63
48
|
const nodeToObjectMap = {
|
|
64
49
|
X3D: x3dX3D,
|
|
65
50
|
UNIT: x3dUnit,
|
|
@@ -110,15 +95,31 @@ const getObjectId = () => ('0000' + objectId++).slice(-4)
|
|
|
110
95
|
const createX3DParser = (src, pxPmm) => {
|
|
111
96
|
// create a parser for the XML
|
|
112
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
|
+
|
|
103
|
+
// high level elements / definitions
|
|
104
|
+
const x3dObjects = [] // list of objects
|
|
105
|
+
const x3dMaterials = [] // list of materials
|
|
106
|
+
const x3dTextures = [] // list of textures
|
|
107
|
+
|
|
108
|
+
const x3dLength = { factor: 1.0, name: 'meters' }
|
|
109
|
+
const x3dAngle = { factor: 1.0, name: 'radians' }
|
|
113
110
|
|
|
114
111
|
parser.on('error', (e) => {
|
|
115
|
-
console.log(
|
|
112
|
+
console.log(
|
|
113
|
+
`error: line ${e.line}, column ${e.column}, bad character [${e.c}]`
|
|
114
|
+
)
|
|
116
115
|
})
|
|
117
116
|
|
|
118
117
|
parser.on('opentag', (node) => {
|
|
119
118
|
// convert known XML tags to objects
|
|
120
119
|
const elementname = node.name.toUpperCase()
|
|
121
|
-
let obj = nodeToObjectMap[elementname]
|
|
120
|
+
let obj = nodeToObjectMap[elementname]
|
|
121
|
+
? nodeToObjectMap[elementname](node.attributes, { x3dObjects })
|
|
122
|
+
: null
|
|
122
123
|
|
|
123
124
|
if (obj) {
|
|
124
125
|
obj.id = getObjectId()
|
|
@@ -129,17 +130,23 @@ const createX3DParser = (src, pxPmm) => {
|
|
|
129
130
|
if (x3dDefs.has(objectname)) {
|
|
130
131
|
const def = x3dDefs.get(objectname)
|
|
131
132
|
if (def.definition !== obj.definition) {
|
|
132
|
-
console.log(
|
|
133
|
+
console.log(
|
|
134
|
+
`WARNING: using a definition "${objectname}" of a different type; ${obj.definition} vs ${def.definition}`
|
|
135
|
+
)
|
|
133
136
|
}
|
|
134
137
|
obj = def
|
|
135
138
|
} else {
|
|
136
|
-
console.log(
|
|
139
|
+
console.log(
|
|
140
|
+
`WARNING: definition "${objectname}" does not exist, using default for ${obj.definition}`
|
|
141
|
+
)
|
|
137
142
|
}
|
|
138
143
|
} else {
|
|
139
144
|
if (node.attributes.DEF) {
|
|
140
145
|
const objectname = node.attributes.DEF
|
|
141
146
|
if (x3dDefs.has(objectname)) {
|
|
142
|
-
console.log(
|
|
147
|
+
console.log(
|
|
148
|
+
`WARNING: redefintion of ${objectname} has been ignored`
|
|
149
|
+
)
|
|
143
150
|
} else {
|
|
144
151
|
x3dDefs.set(objectname, obj)
|
|
145
152
|
}
|
|
@@ -331,12 +338,12 @@ const createX3DParser = (src, pxPmm) => {
|
|
|
331
338
|
|
|
332
339
|
// start the parser
|
|
333
340
|
parser.write(src).close()
|
|
334
|
-
}
|
|
335
341
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
342
|
+
return {
|
|
343
|
+
x3dObj,
|
|
344
|
+
x3dMaterials,
|
|
345
|
+
x3dTextures
|
|
346
|
+
}
|
|
340
347
|
}
|
|
341
348
|
|
|
342
|
-
module.exports =
|
|
349
|
+
module.exports = createX3DParser
|