landxml 0.1.0 → 0.2.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 +11 -0
- package/README.md +19 -0
- package/dist/index.js +22 -17
- package/dist/index.mjs +22 -17
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# landxml
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ae3bcf7: Swapped xml reader package from `xml2json` to `xml-js`
|
|
8
|
+
- ae3bcf7: Added `glb` download example into README.md
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- ae3bcf7: Fixed dependency list
|
|
13
|
+
|
|
3
14
|
## 0.1.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -27,3 +27,22 @@ const loadGeojson = async () => {
|
|
|
27
27
|
return reprojectGeoJson(geojson, wktString, targetCoordinateSystem, keepOriginalGeometryAsFeatureProperties);
|
|
28
28
|
}
|
|
29
29
|
```
|
|
30
|
+
|
|
31
|
+
### Example: Convert to GLB 3D model
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { toGlb } from "landxml";
|
|
35
|
+
|
|
36
|
+
const LandXml2GlbModel = async () => {
|
|
37
|
+
const landXmlString = "<?xml version="1.0"?>...</LandXML>";
|
|
38
|
+
|
|
39
|
+
// Define how the model's origin should be positioned (options: "origin" | "auto" | [x: number, y: number])
|
|
40
|
+
const center = "auto";
|
|
41
|
+
const glbSurfaces = await toGlb(landXmlString, center);
|
|
42
|
+
|
|
43
|
+
let { download, glb } = glbSurfaces[0];
|
|
44
|
+
download()
|
|
45
|
+
|
|
46
|
+
// Alternatively, process the raw binary data from the 'glb' variable (Uint8Array)
|
|
47
|
+
}
|
|
48
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -145,34 +145,39 @@ var downloadGlb = (glbData, fileName) => {
|
|
|
145
145
|
var download_glb_default = downloadGlb;
|
|
146
146
|
|
|
147
147
|
// src/private/parse-xml.ts
|
|
148
|
-
var
|
|
148
|
+
var import_xml_js = __toESM(require("xml-js"));
|
|
149
149
|
var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
150
|
-
const { LandXML } =
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
const { LandXML } = import_xml_js.default.xml2js(xmlString, {
|
|
151
|
+
compact: true,
|
|
152
|
+
attributesKey: "attr",
|
|
153
|
+
textKey: "content"
|
|
154
|
+
});
|
|
155
|
+
const landXML_surfaces = Array.isArray(LandXML.Surfaces.Surface) ? LandXML.Surfaces.Surface : [LandXML.Surfaces.Surface];
|
|
156
|
+
return landXML_surfaces.map((surface) => {
|
|
157
|
+
var _a, _b;
|
|
153
158
|
let points = [];
|
|
154
159
|
let faces = [];
|
|
155
160
|
let pointIdMap = {};
|
|
156
|
-
surface.Definition
|
|
157
|
-
const {
|
|
158
|
-
const [y, x, z] =
|
|
161
|
+
surface.Definition.Pnts.P.forEach((pt) => {
|
|
162
|
+
const { attr, content } = pt;
|
|
163
|
+
const [y, x, z] = content.split(" ").map((v) => parseFloat(v));
|
|
159
164
|
points.push([x, y, z]);
|
|
160
|
-
pointIdMap[id] = points.length - 1;
|
|
165
|
+
pointIdMap[attr.id] = points.length - 1;
|
|
161
166
|
}, []);
|
|
162
|
-
faces = surface.Definition
|
|
163
|
-
const {
|
|
164
|
-
const [a, b, c] =
|
|
167
|
+
faces = surface.Definition.Faces.F.map((face) => {
|
|
168
|
+
const { content } = face;
|
|
169
|
+
const [a, b, c] = content.split(" ").map((v) => pointIdMap[v]);
|
|
165
170
|
if ([a, b, c].filter((v) => typeof v === "undefined").length > 0) {
|
|
166
|
-
throw `Invalid LandXML. A face is referencing a point that doesn't exist. Face is referencing points: ${
|
|
171
|
+
throw `Invalid LandXML. A face is referencing a point that doesn't exist. Face is referencing points: ${content}`;
|
|
167
172
|
}
|
|
168
173
|
return [a, b, c];
|
|
169
174
|
});
|
|
170
175
|
return {
|
|
171
|
-
sourceFile: LandXML
|
|
172
|
-
timeStamp: LandXML
|
|
173
|
-
name: surface.name,
|
|
174
|
-
description: surface.desc,
|
|
175
|
-
wktString: (
|
|
176
|
+
sourceFile: LandXML.Project.attr.name,
|
|
177
|
+
timeStamp: LandXML.Application.attr.timeStamp,
|
|
178
|
+
name: surface.attr.name,
|
|
179
|
+
description: surface.attr.desc,
|
|
180
|
+
wktString: (_b = (_a = LandXML.CoordinateSystem) == null ? void 0 : _a.attr) == null ? void 0 : _b.ogcWktCode,
|
|
176
181
|
surfaceDefinition: {
|
|
177
182
|
points,
|
|
178
183
|
faces
|
package/dist/index.mjs
CHANGED
|
@@ -110,34 +110,39 @@ var downloadGlb = (glbData, fileName) => {
|
|
|
110
110
|
var download_glb_default = downloadGlb;
|
|
111
111
|
|
|
112
112
|
// src/private/parse-xml.ts
|
|
113
|
-
import
|
|
113
|
+
import convert from "xml-js";
|
|
114
114
|
var parseXML = (xmlString) => __async(void 0, null, function* () {
|
|
115
|
-
const { LandXML } =
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
const { LandXML } = convert.xml2js(xmlString, {
|
|
116
|
+
compact: true,
|
|
117
|
+
attributesKey: "attr",
|
|
118
|
+
textKey: "content"
|
|
119
|
+
});
|
|
120
|
+
const landXML_surfaces = Array.isArray(LandXML.Surfaces.Surface) ? LandXML.Surfaces.Surface : [LandXML.Surfaces.Surface];
|
|
121
|
+
return landXML_surfaces.map((surface) => {
|
|
122
|
+
var _a, _b;
|
|
118
123
|
let points = [];
|
|
119
124
|
let faces = [];
|
|
120
125
|
let pointIdMap = {};
|
|
121
|
-
surface.Definition
|
|
122
|
-
const {
|
|
123
|
-
const [y, x, z] =
|
|
126
|
+
surface.Definition.Pnts.P.forEach((pt) => {
|
|
127
|
+
const { attr, content } = pt;
|
|
128
|
+
const [y, x, z] = content.split(" ").map((v) => parseFloat(v));
|
|
124
129
|
points.push([x, y, z]);
|
|
125
|
-
pointIdMap[id] = points.length - 1;
|
|
130
|
+
pointIdMap[attr.id] = points.length - 1;
|
|
126
131
|
}, []);
|
|
127
|
-
faces = surface.Definition
|
|
128
|
-
const {
|
|
129
|
-
const [a, b, c] =
|
|
132
|
+
faces = surface.Definition.Faces.F.map((face) => {
|
|
133
|
+
const { content } = face;
|
|
134
|
+
const [a, b, c] = content.split(" ").map((v) => pointIdMap[v]);
|
|
130
135
|
if ([a, b, c].filter((v) => typeof v === "undefined").length > 0) {
|
|
131
|
-
throw `Invalid LandXML. A face is referencing a point that doesn't exist. Face is referencing points: ${
|
|
136
|
+
throw `Invalid LandXML. A face is referencing a point that doesn't exist. Face is referencing points: ${content}`;
|
|
132
137
|
}
|
|
133
138
|
return [a, b, c];
|
|
134
139
|
});
|
|
135
140
|
return {
|
|
136
|
-
sourceFile: LandXML
|
|
137
|
-
timeStamp: LandXML
|
|
138
|
-
name: surface.name,
|
|
139
|
-
description: surface.desc,
|
|
140
|
-
wktString: (
|
|
141
|
+
sourceFile: LandXML.Project.attr.name,
|
|
142
|
+
timeStamp: LandXML.Application.attr.timeStamp,
|
|
143
|
+
name: surface.attr.name,
|
|
144
|
+
description: surface.attr.desc,
|
|
145
|
+
wktString: (_b = (_a = LandXML.CoordinateSystem) == null ? void 0 : _a.attr) == null ? void 0 : _b.ogcWktCode,
|
|
141
146
|
surfaceDefinition: {
|
|
142
147
|
points,
|
|
143
148
|
faces
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "landxml",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Parse LandXML surfaces on the modern web.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@changesets/cli": "^2.26.2",
|
|
26
|
+
"@types/geojson": "^7946.0.13",
|
|
26
27
|
"@types/proj4": "^2.5.5",
|
|
27
28
|
"@types/xml2json": "^0.11.6",
|
|
28
29
|
"tsup": "^8.0.0",
|
|
@@ -31,8 +32,7 @@
|
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
34
|
"@gltf-transform/core": "^3.9.0",
|
|
34
|
-
"@types/geojson": "^7946.0.13",
|
|
35
35
|
"proj4": "^2.9.2",
|
|
36
|
-
"
|
|
36
|
+
"xml-js": "^1.6.11"
|
|
37
37
|
}
|
|
38
38
|
}
|