@loaders.gl/tile-converter 3.3.0-alpha.7 → 3.3.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/dist/3d-tiles-attributes-worker.d.ts +2 -2
- package/dist/3d-tiles-attributes-worker.d.ts.map +1 -1
- package/dist/3d-tiles-attributes-worker.js +2 -2
- package/dist/3d-tiles-attributes-worker.js.map +3 -3
- package/dist/converter-cli.js +14 -2
- package/dist/converter.min.js +22 -22
- package/dist/deps-installer/deps-installer.d.ts.map +1 -1
- package/dist/deps-installer/deps-installer.js +8 -0
- package/dist/dist.min.js +1407 -1242
- package/dist/es5/3d-tiles-attributes-worker.js +1 -1
- package/dist/es5/3d-tiles-attributes-worker.js.map +1 -1
- package/dist/es5/converter-cli.js +14 -2
- package/dist/es5/converter-cli.js.map +1 -1
- package/dist/es5/deps-installer/deps-installer.js +13 -2
- package/dist/es5/deps-installer/deps-installer.js.map +1 -1
- package/dist/es5/i3s-attributes-worker.js +1 -1
- package/dist/es5/i3s-attributes-worker.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +16 -7
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +363 -113
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js +6 -11
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-index-document.js +517 -0
- package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/node-pages.js +455 -173
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +549 -618
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/geometry-definitions.js +107 -0
- package/dist/es5/i3s-converter/json-templates/geometry-definitions.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/layers.js +2 -93
- package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/shared-resources.js +3 -3
- package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/es5/i3s-converter/types.js.map +1 -1
- package/dist/es5/lib/utils/file-utils.js +93 -9
- package/dist/es5/lib/utils/file-utils.js.map +1 -1
- package/dist/es5/lib/utils/write-queue.js +38 -25
- package/dist/es5/lib/utils/write-queue.js.map +1 -1
- package/dist/es5/pgm-loader.js +1 -1
- package/dist/es5/pgm-loader.js.map +1 -1
- package/dist/es5/workers/i3s-attributes-worker.js +1 -1
- package/dist/es5/workers/i3s-attributes-worker.js.map +1 -1
- package/dist/esm/3d-tiles-attributes-worker.js +1 -1
- package/dist/esm/3d-tiles-attributes-worker.js.map +1 -1
- package/dist/esm/converter-cli.js +14 -2
- package/dist/esm/converter-cli.js.map +1 -1
- package/dist/esm/deps-installer/deps-installer.js +9 -1
- package/dist/esm/deps-installer/deps-installer.js.map +1 -1
- package/dist/esm/i3s-attributes-worker.js +1 -1
- package/dist/esm/i3s-attributes-worker.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js +16 -7
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.js +150 -40
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/gltf-attributes.js +6 -9
- package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-index-document.js +202 -0
- package/dist/esm/i3s-converter/helpers/node-index-document.js.map +1 -0
- package/dist/esm/i3s-converter/helpers/node-pages.js +162 -76
- package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +115 -220
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/geometry-definitions.js +89 -0
- package/dist/esm/i3s-converter/json-templates/geometry-definitions.js.map +1 -0
- package/dist/esm/i3s-converter/json-templates/layers.js +2 -85
- package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/shared-resources.js +3 -3
- package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/esm/i3s-converter/types.js.map +1 -1
- package/dist/esm/lib/utils/file-utils.js +44 -3
- package/dist/esm/lib/utils/file-utils.js.map +1 -1
- package/dist/esm/lib/utils/write-queue.js +19 -10
- package/dist/esm/lib/utils/write-queue.js.map +1 -1
- package/dist/esm/pgm-loader.js +1 -1
- package/dist/esm/pgm-loader.js.map +1 -1
- package/dist/esm/workers/i3s-attributes-worker.js +1 -1
- package/dist/esm/workers/i3s-attributes-worker.js.map +1 -1
- package/dist/i3s-attributes-worker.d.ts +2 -2
- package/dist/i3s-attributes-worker.d.ts.map +1 -1
- package/dist/i3s-attributes-worker.js +2 -2
- package/dist/i3s-attributes-worker.js.map +2 -2
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +3 -3
- package/dist/i3s-converter/helpers/batch-ids-extensions.js +3 -3
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-attributes.js +16 -10
- package/dist/i3s-converter/helpers/geometry-converter.d.ts +8 -4
- package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-converter.js +200 -44
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/gltf-attributes.js +2 -3
- package/dist/i3s-converter/helpers/node-index-document.d.ts +95 -0
- package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/node-index-document.js +250 -0
- package/dist/i3s-converter/helpers/node-pages.d.ts +78 -43
- package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-pages.js +195 -94
- package/dist/i3s-converter/i3s-converter.d.ts +33 -58
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.js +122 -233
- package/dist/i3s-converter/json-templates/geometry-definitions.d.ts +7 -0
- package/dist/i3s-converter/json-templates/geometry-definitions.d.ts.map +1 -0
- package/dist/i3s-converter/json-templates/geometry-definitions.js +87 -0
- package/dist/i3s-converter/json-templates/layers.d.ts +1 -30
- package/dist/i3s-converter/json-templates/layers.d.ts.map +1 -1
- package/dist/i3s-converter/json-templates/layers.js +2 -86
- package/dist/i3s-converter/json-templates/shared-resources.js +3 -3
- package/dist/i3s-converter/types.d.ts +34 -8
- package/dist/i3s-converter/types.d.ts.map +1 -1
- package/dist/lib/utils/file-utils.d.ts +17 -1
- package/dist/lib/utils/file-utils.d.ts.map +1 -1
- package/dist/lib/utils/file-utils.js +64 -7
- package/dist/lib/utils/write-queue.d.ts +19 -3
- package/dist/lib/utils/write-queue.d.ts.map +1 -1
- package/dist/lib/utils/write-queue.js +18 -12
- package/dist/workers/i3s-attributes-worker.js +1 -1
- package/package.json +25 -20
- package/src/converter-cli.ts +22 -2
- package/src/deps-installer/deps-installer.ts +9 -0
- package/src/i3s-converter/helpers/batch-ids-extensions.ts +3 -3
- package/src/i3s-converter/helpers/geometry-attributes.ts +16 -11
- package/src/i3s-converter/helpers/geometry-converter.ts +217 -48
- package/src/i3s-converter/helpers/gltf-attributes.ts +2 -3
- package/src/i3s-converter/helpers/node-index-document.ts +315 -0
- package/src/i3s-converter/helpers/node-pages.ts +215 -110
- package/src/i3s-converter/i3s-converter.ts +170 -312
- package/src/i3s-converter/json-templates/geometry-definitions.ts +83 -0
- package/src/i3s-converter/json-templates/layers.ts +2 -91
- package/src/i3s-converter/json-templates/shared-resources.ts +3 -3
- package/src/i3s-converter/types.ts +29 -2
- package/src/lib/utils/file-utils.ts +62 -7
- package/src/lib/utils/write-queue.ts +36 -15
- package/src/workers/i3s-attributes-worker.ts +2 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import transform from 'json-map-transform';
|
|
2
|
+
|
|
3
|
+
const PLAIN_GEOMETRY_DEFINITION = () => ({
|
|
4
|
+
offset: {
|
|
5
|
+
default: 8
|
|
6
|
+
},
|
|
7
|
+
position: {
|
|
8
|
+
default: {
|
|
9
|
+
type: 'Float32',
|
|
10
|
+
component: 3
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
normal: {
|
|
14
|
+
default: {
|
|
15
|
+
type: 'Float32',
|
|
16
|
+
component: 3
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
uv0: {
|
|
20
|
+
path: 'hasTexture',
|
|
21
|
+
transform: (val) => (val && {type: 'Float32', component: 2}) || false,
|
|
22
|
+
omitValues: [false]
|
|
23
|
+
},
|
|
24
|
+
color: {
|
|
25
|
+
default: {
|
|
26
|
+
type: 'UInt8',
|
|
27
|
+
component: 4
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
uvRegion: {
|
|
31
|
+
path: 'hasUvRegions',
|
|
32
|
+
transform: (val) => (val && {type: 'UInt16', component: 4}) || false,
|
|
33
|
+
omitValues: [false]
|
|
34
|
+
},
|
|
35
|
+
featureId: {
|
|
36
|
+
default: {
|
|
37
|
+
binding: 'per-feature',
|
|
38
|
+
type: 'UInt64',
|
|
39
|
+
component: 1
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
faceRange: {
|
|
43
|
+
default: {
|
|
44
|
+
binding: 'per-feature',
|
|
45
|
+
type: 'UInt32',
|
|
46
|
+
component: 2
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const COMPRESSED_GEOMETRY_DEFINITION = () => ({
|
|
52
|
+
'compressedAttributes.encoding': {
|
|
53
|
+
default: 'draco'
|
|
54
|
+
},
|
|
55
|
+
'compressedAttributes.attributes': {
|
|
56
|
+
path: 'geometryConfig',
|
|
57
|
+
transform: (val) => {
|
|
58
|
+
const result = ['position', 'normal'];
|
|
59
|
+
if (val.hasTexture) {
|
|
60
|
+
result.push('uv0');
|
|
61
|
+
}
|
|
62
|
+
result.push('color');
|
|
63
|
+
if (val.hasUvRegions) {
|
|
64
|
+
result.push('uv-region');
|
|
65
|
+
}
|
|
66
|
+
result.push('feature-index');
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export const GEOMETRY_DEFINITION = () => ({
|
|
73
|
+
geometryBuffers: {
|
|
74
|
+
path: 'geometryConfig',
|
|
75
|
+
transform: (val) => {
|
|
76
|
+
const result = [transform(val, PLAIN_GEOMETRY_DEFINITION())];
|
|
77
|
+
if (val.draco) {
|
|
78
|
+
result.push(transform({geometryConfig: val}, COMPRESSED_GEOMETRY_DEFINITION()));
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
@@ -1,76 +1,6 @@
|
|
|
1
1
|
import transform from 'json-map-transform';
|
|
2
2
|
import {STORE} from './store';
|
|
3
3
|
|
|
4
|
-
const PLAIN_GEOMETRY_DEFINITION = () => ({
|
|
5
|
-
offset: 8,
|
|
6
|
-
position: {
|
|
7
|
-
type: 'Float32',
|
|
8
|
-
component: 3
|
|
9
|
-
},
|
|
10
|
-
normal: {
|
|
11
|
-
type: 'Float32',
|
|
12
|
-
component: 3
|
|
13
|
-
},
|
|
14
|
-
uv0: {
|
|
15
|
-
type: 'Float32',
|
|
16
|
-
component: 2
|
|
17
|
-
},
|
|
18
|
-
color: {
|
|
19
|
-
type: 'UInt8',
|
|
20
|
-
component: 4
|
|
21
|
-
},
|
|
22
|
-
featureId: {
|
|
23
|
-
binding: 'per-feature',
|
|
24
|
-
type: 'UInt64',
|
|
25
|
-
component: 1
|
|
26
|
-
},
|
|
27
|
-
faceRange: {
|
|
28
|
-
binding: 'per-feature',
|
|
29
|
-
type: 'UInt32',
|
|
30
|
-
component: 2
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const PLAIN_GEOMETRY_DEFINITION_WITHOUT_UV0 = () => ({
|
|
35
|
-
offset: 8,
|
|
36
|
-
position: {
|
|
37
|
-
type: 'Float32',
|
|
38
|
-
component: 3
|
|
39
|
-
},
|
|
40
|
-
normal: {
|
|
41
|
-
type: 'Float32',
|
|
42
|
-
component: 3
|
|
43
|
-
},
|
|
44
|
-
color: {
|
|
45
|
-
type: 'UInt8',
|
|
46
|
-
component: 4
|
|
47
|
-
},
|
|
48
|
-
featureId: {
|
|
49
|
-
binding: 'per-feature',
|
|
50
|
-
type: 'UInt64',
|
|
51
|
-
component: 1
|
|
52
|
-
},
|
|
53
|
-
faceRange: {
|
|
54
|
-
binding: 'per-feature',
|
|
55
|
-
type: 'UInt32',
|
|
56
|
-
component: 2
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const COMPRESSED_GEOMETRY_DEFINITION = () => ({
|
|
61
|
-
compressedAttributes: {
|
|
62
|
-
encoding: 'draco',
|
|
63
|
-
attributes: ['position', 'normal', 'uv0', 'color', 'feature-index']
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const COMPRESSED_GEOMETRY_DEFINITION_WITHOUT_UV0 = () => ({
|
|
68
|
-
compressedAttributes: {
|
|
69
|
-
encoding: 'draco',
|
|
70
|
-
attributes: ['position', 'normal', 'color', 'feature-index']
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
4
|
const SPATIAL_REFERENCE = () => ({
|
|
75
5
|
wkid: {
|
|
76
6
|
path: 'wkid',
|
|
@@ -189,27 +119,8 @@ export const LAYERS = () => ({
|
|
|
189
119
|
default: []
|
|
190
120
|
},
|
|
191
121
|
geometryDefinitions: {
|
|
192
|
-
path: '
|
|
193
|
-
|
|
194
|
-
const result = [{geometryBuffers: []}, {geometryBuffers: []}];
|
|
195
|
-
|
|
196
|
-
// @ts-expect-error
|
|
197
|
-
result[0].geometryBuffers.push(PLAIN_GEOMETRY_DEFINITION());
|
|
198
|
-
// @ts-expect-error
|
|
199
|
-
result[1].geometryBuffers.push(PLAIN_GEOMETRY_DEFINITION_WITHOUT_UV0());
|
|
200
|
-
if (val) {
|
|
201
|
-
// @ts-expect-error
|
|
202
|
-
result[0].geometryBuffers.push(COMPRESSED_GEOMETRY_DEFINITION());
|
|
203
|
-
// @ts-expect-error
|
|
204
|
-
result[1].geometryBuffers.push(COMPRESSED_GEOMETRY_DEFINITION_WITHOUT_UV0());
|
|
205
|
-
}
|
|
206
|
-
return result;
|
|
207
|
-
},
|
|
208
|
-
default: [
|
|
209
|
-
{
|
|
210
|
-
geometryBuffers: [PLAIN_GEOMETRY_DEFINITION(), PLAIN_GEOMETRY_DEFINITION_WITHOUT_UV0()]
|
|
211
|
-
}
|
|
212
|
-
]
|
|
122
|
+
path: 'geometryDefinitions',
|
|
123
|
+
default: []
|
|
213
124
|
},
|
|
214
125
|
attributeStorageInfo: {
|
|
215
126
|
path: 'attributeStorageInfo',
|
|
@@ -15,15 +15,15 @@ const MATERIAL_DEFINITION_INFO_PARAMS = () => ({
|
|
|
15
15
|
},
|
|
16
16
|
ambient: {
|
|
17
17
|
path: 'ambient',
|
|
18
|
-
default: [1, 1, 1
|
|
18
|
+
default: [1, 1, 1]
|
|
19
19
|
},
|
|
20
20
|
diffuse: {
|
|
21
21
|
path: 'diffuse',
|
|
22
|
-
default: [1, 1, 1
|
|
22
|
+
default: [1, 1, 1]
|
|
23
23
|
},
|
|
24
24
|
specular: {
|
|
25
25
|
path: 'specular',
|
|
26
|
-
default: [0, 0, 0
|
|
26
|
+
default: [0, 0, 0]
|
|
27
27
|
},
|
|
28
28
|
useVertexColorAlpha: {
|
|
29
29
|
path: 'useVertexColorAlpha',
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import {GLTFImagePostprocessed} from '@loaders.gl/gltf';
|
|
1
2
|
import {
|
|
2
3
|
BoundingVolumes,
|
|
3
4
|
I3SMaterialDefinition,
|
|
4
5
|
MaterialDefinitionInfo,
|
|
5
6
|
TextureDefinitionInfo
|
|
6
7
|
} from '@loaders.gl/i3s';
|
|
7
|
-
import {ImageDataType} from '@loaders.gl/images';
|
|
8
8
|
|
|
9
9
|
/** Converted resources for specific node */
|
|
10
10
|
export type I3SConvertedResources = {
|
|
@@ -25,6 +25,10 @@ export type I3SConvertedResources = {
|
|
|
25
25
|
* Texture image content
|
|
26
26
|
*/
|
|
27
27
|
texture: any | null;
|
|
28
|
+
/**
|
|
29
|
+
* If the resource has uvRegions geometry attribute
|
|
30
|
+
*/
|
|
31
|
+
hasUvRegions: boolean;
|
|
28
32
|
/**
|
|
29
33
|
* Shared resources built from GLTF material
|
|
30
34
|
*/
|
|
@@ -63,6 +67,8 @@ export type ConvertedAttributes = {
|
|
|
63
67
|
texCoords: Float32Array;
|
|
64
68
|
/** COLOR_0 attribute value */
|
|
65
69
|
colors: Uint8Array;
|
|
70
|
+
/** uvRegion attribute for a texture atlas */
|
|
71
|
+
uvRegions: Uint16Array;
|
|
66
72
|
/** Feature indices grouped by ...
|
|
67
73
|
* converted from "batch ids" of GLTF
|
|
68
74
|
*/
|
|
@@ -73,6 +79,8 @@ export type ConvertedAttributes = {
|
|
|
73
79
|
* MBS and/or OBB bounding volumes of the node
|
|
74
80
|
*/
|
|
75
81
|
boundingVolumes: null | BoundingVolumes;
|
|
82
|
+
/** merged materials data */
|
|
83
|
+
mergedMaterials: MergedMaterial[];
|
|
76
84
|
};
|
|
77
85
|
|
|
78
86
|
/** Postprocessed geometry and feature attributes
|
|
@@ -87,6 +95,8 @@ export type GeometryAttributes = {
|
|
|
87
95
|
texCoords: Float32Array;
|
|
88
96
|
/** COLOR_0 attribute value */
|
|
89
97
|
colors: Uint8Array;
|
|
98
|
+
/** uvRegion attribute for a texture atlas */
|
|
99
|
+
uvRegions: Uint16Array;
|
|
90
100
|
/** faceRanges attribute value */
|
|
91
101
|
faceRange: Uint32Array;
|
|
92
102
|
/** feature Ids attribute value */
|
|
@@ -105,6 +115,8 @@ export type GroupedByFeatureIdAttributes = {
|
|
|
105
115
|
normals: Float32Array;
|
|
106
116
|
/** COLOR_0 attribute value */
|
|
107
117
|
colors: Uint8Array;
|
|
118
|
+
/** uvRegion attribute for a texture atlas */
|
|
119
|
+
uvRegions: Uint16Array;
|
|
108
120
|
/** TEXCOORD_0 attribute value */
|
|
109
121
|
texCoords: Float32Array;
|
|
110
122
|
};
|
|
@@ -124,5 +136,20 @@ export type I3SMaterialWithTexture = {
|
|
|
124
136
|
/** Material definition https://github.com/Esri/i3s-spec/blob/master/docs/1.8/materialDefinitions.cmn.md */
|
|
125
137
|
material: I3SMaterialDefinition;
|
|
126
138
|
/** Texture content (image) */
|
|
127
|
-
texture?:
|
|
139
|
+
texture?: GLTFImagePostprocessed;
|
|
140
|
+
/** Metadata of all merged materials */
|
|
141
|
+
mergedMaterials: MergedMaterial[];
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/** Metadata of some original texture */
|
|
145
|
+
export type MergedMaterial = {
|
|
146
|
+
/** Gltf material Id */
|
|
147
|
+
originalMaterialId: string;
|
|
148
|
+
/** Original texture size */
|
|
149
|
+
textureSize?: {
|
|
150
|
+
width: number;
|
|
151
|
+
height: number;
|
|
152
|
+
};
|
|
153
|
+
/** Uint16Array of 4 elements https://github.com/Esri/i3s-spec/blob/master/docs/1.7/geometryUVRegion.cmn.md */
|
|
154
|
+
uvRegion?: Uint16Array;
|
|
128
155
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {load} from '@loaders.gl/core';
|
|
2
|
+
import {JSONLoader} from '@loaders.gl/loader-utils';
|
|
1
3
|
import {promises as fs} from 'fs';
|
|
2
4
|
import {isAbsolute, join} from 'path';
|
|
3
5
|
import {compressFileWithGzip} from './compress-util';
|
|
@@ -40,23 +42,76 @@ export async function writeFile(
|
|
|
40
42
|
* @param data - file content
|
|
41
43
|
* @param fileName - name of output file (default: index.json)
|
|
42
44
|
* @param compress - if need to compress file with gzip (default: true)
|
|
45
|
+
* @param compressList - if set - the file should be added to this list and compressed in the end of conversion
|
|
43
46
|
*/
|
|
44
47
|
export async function writeFileForSlpk(
|
|
45
48
|
path: string,
|
|
46
49
|
data: string | Uint8Array | ArrayBuffer | Promise<ArrayBuffer>,
|
|
47
50
|
fileName: string = 'index.json',
|
|
48
|
-
compress: boolean = true
|
|
49
|
-
|
|
51
|
+
compress: boolean = true,
|
|
52
|
+
compressList?: string[] | null
|
|
53
|
+
): Promise<string | null> {
|
|
50
54
|
const pathFile = await writeFile(path, data, fileName);
|
|
51
55
|
if (compress) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
if (compressList) {
|
|
57
|
+
if (!compressList.includes(pathFile)) {
|
|
58
|
+
compressList.push(pathFile);
|
|
59
|
+
return `${pathFile}.gz`;
|
|
60
|
+
} else {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
const pathGzFile = await compressFileWithGzip(pathFile);
|
|
65
|
+
// After compression, we don't need an uncompressed file
|
|
66
|
+
await removeFile(pathFile);
|
|
67
|
+
return pathGzFile;
|
|
68
|
+
}
|
|
56
69
|
}
|
|
57
70
|
return pathFile;
|
|
58
71
|
}
|
|
59
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Open json file
|
|
75
|
+
* @param path - path to the file
|
|
76
|
+
* @param fileName - file name
|
|
77
|
+
* @returns object
|
|
78
|
+
*/
|
|
79
|
+
export async function openJson(path: string, fileName: string): Promise<{[key: string]: any}> {
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
let count = 0;
|
|
82
|
+
console.log(`load ${path}/${fileName}.`); // eslint-disable-line
|
|
83
|
+
const intervalId = setInterval(() => {
|
|
84
|
+
const pathFile = join(path, fileName);
|
|
85
|
+
load(pathFile, JSONLoader)
|
|
86
|
+
.then((result) => {
|
|
87
|
+
clearInterval(intervalId);
|
|
88
|
+
resolve(result);
|
|
89
|
+
})
|
|
90
|
+
.catch(() => {
|
|
91
|
+
count++;
|
|
92
|
+
if (count > 100) {
|
|
93
|
+
clearInterval(intervalId);
|
|
94
|
+
reject(new Error(`Cannon load ${path}/${fileName}.`));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}, 200);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Check if the file exists
|
|
103
|
+
* @param fileName - full name of file
|
|
104
|
+
* @returns true if file exists, otherwise - false
|
|
105
|
+
*/
|
|
106
|
+
export async function isFileExists(fileName: string): Promise<boolean> {
|
|
107
|
+
try {
|
|
108
|
+
await fs.stat(fileName);
|
|
109
|
+
return true;
|
|
110
|
+
} catch {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
60
115
|
/**
|
|
61
116
|
* Remove dir with path
|
|
62
117
|
*
|
|
@@ -80,5 +135,5 @@ export function removeFile(path: string) {
|
|
|
80
135
|
* @param filePath
|
|
81
136
|
*/
|
|
82
137
|
export function getAbsoluteFilePath(filePath: string) {
|
|
83
|
-
return isAbsolute(filePath) ? filePath : join(process.cwd(), filePath);
|
|
138
|
+
return isAbsolute(filePath) ? filePath : join(process.cwd(), filePath);
|
|
84
139
|
}
|
|
@@ -6,7 +6,23 @@ const MEMORY_LIMIT = 4 * 1024 * 1024 * 1024; // 4GB
|
|
|
6
6
|
|
|
7
7
|
export type WriteQueueItem = {
|
|
8
8
|
archiveKey?: string;
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* writePromise() returns a Promise that will be awaited in Promise.allSettled(promises);
|
|
11
|
+
* Arguments for this call are specified in writeQueue.enqueue call like this:
|
|
12
|
+
* await writeQueue.enqueue({
|
|
13
|
+
* archiveKey: `nodePages/xxx.json.gz`,
|
|
14
|
+
* writePromise: () => writeFileForSlpk(slpkPath, data, `xxx.json`)
|
|
15
|
+
* });
|
|
16
|
+
* Note, a function like writeFileForSlpk should NOT be called when initializing the object for enqueue().
|
|
17
|
+
* If he function is called, the promise will be created
|
|
18
|
+
* and the function will allocate resources (file descriptors) for file writing.
|
|
19
|
+
* It will be done for ALL items in the queue, which is not supposed to happen.
|
|
20
|
+
* That's why the function should be passed as
|
|
21
|
+
* writePromise: () => writeFileForSlpk(slpkPath, content, `xxx.json`)
|
|
22
|
+
* instead of
|
|
23
|
+
* writePromise: writeFileForSlpk(slpkPath, content, `xxx.json`) // INCORRECT !
|
|
24
|
+
*/
|
|
25
|
+
writePromise: () => Promise<string | null>;
|
|
10
26
|
};
|
|
11
27
|
|
|
12
28
|
export default class WriteQueue<T extends WriteQueueItem> extends Queue<T> {
|
|
@@ -22,11 +38,19 @@ export default class WriteQueue<T extends WriteQueueItem> extends Queue<T> {
|
|
|
22
38
|
this.writeConcurrency = writeConcurrency;
|
|
23
39
|
}
|
|
24
40
|
|
|
25
|
-
async enqueue(val: T) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
41
|
+
async enqueue(val: T, writeImmediately: boolean = false) {
|
|
42
|
+
if (writeImmediately) {
|
|
43
|
+
const {archiveKey, writePromise} = val as WriteQueueItem;
|
|
44
|
+
const result = await writePromise();
|
|
45
|
+
if (archiveKey && result) {
|
|
46
|
+
this.fileMap[archiveKey] = result;
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
super.enqueue(val);
|
|
50
|
+
/** https://nodejs.org/docs/latest-v14.x/api/process.html#process_process_memoryusage */
|
|
51
|
+
if (process.memoryUsage().rss > MEMORY_LIMIT) {
|
|
52
|
+
await this.startWrite();
|
|
53
|
+
}
|
|
30
54
|
}
|
|
31
55
|
}
|
|
32
56
|
|
|
@@ -41,12 +65,9 @@ export default class WriteQueue<T extends WriteQueueItem> extends Queue<T> {
|
|
|
41
65
|
}
|
|
42
66
|
|
|
43
67
|
async startWrite(): Promise<void> {
|
|
44
|
-
if (this.writePromise) {
|
|
45
|
-
|
|
46
|
-
this.writePromise = null;
|
|
47
|
-
return;
|
|
68
|
+
if (!this.writePromise) {
|
|
69
|
+
this.writePromise = this.doWrite();
|
|
48
70
|
}
|
|
49
|
-
this.writePromise = this.doWrite();
|
|
50
71
|
await this.writePromise;
|
|
51
72
|
this.writePromise = null;
|
|
52
73
|
}
|
|
@@ -58,7 +79,7 @@ export default class WriteQueue<T extends WriteQueueItem> extends Queue<T> {
|
|
|
58
79
|
|
|
59
80
|
private async doWrite(): Promise<void> {
|
|
60
81
|
while (this.length) {
|
|
61
|
-
const promises: Promise<string>[] = [];
|
|
82
|
+
const promises: Promise<string | null>[] = [];
|
|
62
83
|
const archiveKeys: (string | undefined)[] = [];
|
|
63
84
|
for (let i = 0; i < this.writeConcurrency; i++) {
|
|
64
85
|
const item = this.dequeue();
|
|
@@ -67,17 +88,17 @@ export default class WriteQueue<T extends WriteQueueItem> extends Queue<T> {
|
|
|
67
88
|
}
|
|
68
89
|
const {archiveKey, writePromise} = item as WriteQueueItem;
|
|
69
90
|
archiveKeys.push(archiveKey);
|
|
70
|
-
|
|
91
|
+
const promise = writePromise();
|
|
92
|
+
promises.push(promise);
|
|
71
93
|
}
|
|
72
94
|
const writeResults = await Promise.allSettled(promises);
|
|
73
95
|
this.updateFileMap(archiveKeys, writeResults);
|
|
74
96
|
}
|
|
75
|
-
this.writePromise = null;
|
|
76
97
|
}
|
|
77
98
|
|
|
78
99
|
private updateFileMap(
|
|
79
100
|
archiveKeys: (string | undefined)[],
|
|
80
|
-
writeResults: PromiseSettledResult<string>[]
|
|
101
|
+
writeResults: PromiseSettledResult<string | null>[]
|
|
81
102
|
) {
|
|
82
103
|
for (let i = 0; i < archiveKeys.length; i++) {
|
|
83
104
|
const archiveKey = archiveKeys[i];
|
|
@@ -2,5 +2,6 @@ import {createWorker} from '@loaders.gl/worker-utils';
|
|
|
2
2
|
import {convertAttributes} from '../i3s-converter/helpers/geometry-converter';
|
|
3
3
|
|
|
4
4
|
createWorker(
|
|
5
|
-
async (data, options = {}) =>
|
|
5
|
+
async (data, options = {}) =>
|
|
6
|
+
await convertAttributes(data, options.materialAndTextureList, options.useCartesianPositions)
|
|
6
7
|
);
|