@loaders.gl/terrain 4.0.0-alpha.5 → 4.0.0-alpha.6
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/bundle.js +2 -2
- package/dist/dist.min.js +100 -106
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +87 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/decode-quantized-mesh.js +250 -0
- package/dist/es5/lib/decode-quantized-mesh.js.map +1 -0
- package/dist/es5/lib/delatin/index.js +408 -0
- package/dist/es5/lib/delatin/index.js.map +1 -0
- package/dist/es5/lib/helpers/skirt.js +105 -0
- package/dist/es5/lib/helpers/skirt.js.map +1 -0
- package/dist/es5/lib/parse-quantized-mesh.js +95 -0
- package/dist/es5/lib/parse-quantized-mesh.js.map +1 -0
- package/dist/es5/lib/parse-terrain.js +152 -0
- package/dist/es5/lib/parse-terrain.js.map +1 -0
- package/dist/es5/lib/utils/version.js +9 -0
- package/dist/es5/lib/utils/version.js.map +1 -0
- package/dist/es5/quantized-mesh-loader.js +24 -0
- package/dist/es5/quantized-mesh-loader.js.map +1 -0
- package/dist/es5/terrain-loader.js +32 -0
- package/dist/es5/terrain-loader.js.map +1 -0
- package/dist/es5/workers/quantized-mesh-worker.js +6 -0
- package/dist/es5/workers/quantized-mesh-worker.js.map +1 -0
- package/dist/es5/workers/terrain-worker.js +6 -0
- package/dist/es5/workers/terrain-worker.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +32 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/decode-quantized-mesh.js +231 -0
- package/dist/esm/lib/decode-quantized-mesh.js.map +1 -0
- package/dist/esm/lib/delatin/index.js +355 -0
- package/dist/esm/lib/delatin/index.js.map +1 -0
- package/dist/esm/lib/helpers/skirt.js +89 -0
- package/dist/esm/lib/helpers/skirt.js.map +1 -0
- package/dist/esm/lib/parse-quantized-mesh.js +85 -0
- package/dist/esm/lib/parse-quantized-mesh.js.map +1 -0
- package/dist/esm/lib/parse-terrain.js +151 -0
- package/dist/esm/lib/parse-terrain.js.map +1 -0
- package/dist/esm/lib/utils/version.js +2 -0
- package/dist/esm/lib/utils/version.js.map +1 -0
- package/dist/esm/quantized-mesh-loader.js +17 -0
- package/dist/esm/quantized-mesh-loader.js.map +1 -0
- package/dist/esm/terrain-loader.js +25 -0
- package/dist/esm/terrain-loader.js.map +1 -0
- package/dist/esm/workers/quantized-mesh-worker.js +4 -0
- package/dist/esm/workers/quantized-mesh-worker.js.map +1 -0
- package/dist/esm/workers/terrain-worker.js +4 -0
- package/dist/esm/workers/terrain-worker.js.map +1 -0
- package/dist/index.d.ts +27 -69
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -14
- package/dist/lib/decode-quantized-mesh.d.ts +1 -1
- package/dist/lib/decode-quantized-mesh.d.ts.map +1 -1
- package/dist/lib/decode-quantized-mesh.js +200 -241
- package/dist/lib/delatin/index.js +397 -443
- package/dist/lib/helpers/skirt.d.ts +1 -1
- package/dist/lib/helpers/skirt.d.ts.map +1 -1
- package/dist/lib/helpers/skirt.js +119 -91
- package/dist/lib/parse-quantized-mesh.d.ts +6 -24
- package/dist/lib/parse-quantized-mesh.d.ts.map +1 -1
- package/dist/lib/parse-quantized-mesh.js +94 -93
- package/dist/lib/parse-terrain.d.ts +28 -2
- package/dist/lib/parse-terrain.d.ts.map +1 -1
- package/dist/lib/parse-terrain.js +146 -172
- package/dist/lib/utils/version.js +7 -2
- package/dist/quantized-mesh-loader.d.ts +8 -17
- package/dist/quantized-mesh-loader.d.ts.map +1 -1
- package/dist/quantized-mesh-loader.js +20 -16
- package/dist/quantized-mesh-worker.js +146 -117
- package/dist/terrain-loader.d.ts +7 -27
- package/dist/terrain-loader.d.ts.map +1 -1
- package/dist/terrain-loader.js +28 -24
- package/dist/terrain-worker.js +146 -117
- package/dist/workers/quantized-mesh-worker.js +5 -4
- package/dist/workers/terrain-worker.js +5 -4
- package/package.json +9 -8
- package/src/index.ts +29 -13
- package/src/lib/helpers/skirt.ts +7 -7
- package/src/lib/parse-quantized-mesh.ts +47 -43
- package/src/lib/parse-terrain.ts +83 -89
- package/src/quantized-mesh-loader.ts +9 -4
- package/src/terrain-loader.ts +14 -11
- package/dist/bundle.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/decode-quantized-mesh.js.map +0 -1
- package/dist/lib/delatin/index.js.map +0 -1
- package/dist/lib/helpers/skirt.js.map +0 -1
- package/dist/lib/parse-quantized-mesh.js.map +0 -1
- package/dist/lib/parse-terrain.js.map +0 -1
- package/dist/lib/utils/version.js.map +0 -1
- package/dist/quantized-mesh-loader.js.map +0 -1
- package/dist/terrain-loader.js.map +0 -1
- package/dist/workers/quantized-mesh-worker.js.map +0 -1
- package/dist/workers/terrain-worker.js.map +0 -1
- package/src/workers/quantized-mesh-worker.js +0 -3
- package/src/workers/terrain-worker.js +0 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,77 +1,35 @@
|
|
|
1
|
-
import type { LoaderWithParser } from '@loaders.gl/loader-utils';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { TerrainLoader as TerrainWorkerLoader } from './terrain-loader';
|
|
5
|
-
import { QuantizedMeshLoader as QuantizedMeshWorkerLoader } from './quantized-mesh-loader';
|
|
1
|
+
import type { LoaderContext, LoaderWithParser } from '@loaders.gl/loader-utils';
|
|
2
|
+
import { TerrainLoader as TerrainWorkerLoader, TerrainLoaderOptions } from './terrain-loader';
|
|
3
|
+
import { QuantizedMeshLoader as QuantizedMeshWorkerLoader, QuantizedMeshLoaderOptions } from './quantized-mesh-loader';
|
|
6
4
|
export { TerrainWorkerLoader };
|
|
7
|
-
export declare const TerrainLoader:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
5
|
+
export declare const TerrainLoader: LoaderWithParser<any, never, TerrainLoaderOptions>;
|
|
6
|
+
export declare function parseTerrain(arrayBuffer: ArrayBuffer, options?: TerrainLoaderOptions, context?: LoaderContext): Promise<{
|
|
7
|
+
loaderData: {
|
|
8
|
+
header: {};
|
|
9
|
+
};
|
|
10
|
+
header: {
|
|
11
|
+
vertexCount: any;
|
|
12
|
+
boundingBox: [[number, number, number], [number, number, number]];
|
|
13
|
+
};
|
|
14
|
+
mode: number;
|
|
15
|
+
indices: {
|
|
16
|
+
value: Uint32Array;
|
|
17
|
+
size: number;
|
|
18
|
+
};
|
|
19
|
+
attributes: {
|
|
20
|
+
POSITION: {
|
|
21
|
+
value: Float32Array;
|
|
22
|
+
size: number;
|
|
23
|
+
};
|
|
24
|
+
TEXCOORD_0: {
|
|
25
|
+
value: Float32Array;
|
|
26
|
+
size: number;
|
|
28
27
|
};
|
|
29
28
|
};
|
|
30
|
-
}
|
|
31
|
-
export declare const _typecheckTerrainLoader: LoaderWithParser;
|
|
29
|
+
}>;
|
|
32
30
|
export { QuantizedMeshWorkerLoader };
|
|
33
31
|
/**
|
|
34
32
|
* Loader for quantized meshes
|
|
35
33
|
*/
|
|
36
|
-
export declare const QuantizedMeshLoader:
|
|
37
|
-
parseSync: typeof parseQuantizedMesh;
|
|
38
|
-
parse: (arrayBuffer: any, options: any) => Promise<{
|
|
39
|
-
loaderData: {
|
|
40
|
-
header: {};
|
|
41
|
-
};
|
|
42
|
-
header: {
|
|
43
|
-
vertexCount: any;
|
|
44
|
-
boundingBox: [[number, number, number], [number, number, number]];
|
|
45
|
-
};
|
|
46
|
-
mode: number;
|
|
47
|
-
indices: {
|
|
48
|
-
value: any;
|
|
49
|
-
size: number;
|
|
50
|
-
};
|
|
51
|
-
attributes: {
|
|
52
|
-
POSITION: {
|
|
53
|
-
value: Float32Array;
|
|
54
|
-
size: number;
|
|
55
|
-
};
|
|
56
|
-
TEXCOORD_0: {
|
|
57
|
-
value: Float32Array;
|
|
58
|
-
size: number;
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
} | null>;
|
|
62
|
-
name: string;
|
|
63
|
-
id: string;
|
|
64
|
-
module: string;
|
|
65
|
-
version: any;
|
|
66
|
-
worker: boolean;
|
|
67
|
-
extensions: string[];
|
|
68
|
-
mimeTypes: string[];
|
|
69
|
-
options: {
|
|
70
|
-
'quantized-mesh': {
|
|
71
|
-
bounds: number[];
|
|
72
|
-
skirtHeight: null;
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
export declare const _typecheckQuantizedMeshLoader: LoaderWithParser;
|
|
34
|
+
export declare const QuantizedMeshLoader: LoaderWithParser<any, never, QuantizedMeshLoaderOptions>;
|
|
77
35
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAI9E,OAAO,EAAC,aAAa,IAAI,mBAAmB,EAAE,oBAAoB,EAAC,MAAM,kBAAkB,CAAC;AAC5F,OAAO,EACL,mBAAmB,IAAI,yBAAyB,EAChD,0BAA0B,EAC3B,MAAM,yBAAyB,CAAC;AAIjC,OAAO,EAAC,mBAAmB,EAAC,CAAC;AAE7B,eAAO,MAAM,aAAa,EAAE,gBAAgB,CAAC,GAAG,EAAE,KAAK,EAAE,oBAAoB,CAG5E,CAAC;AAEF,wBAAsB,YAAY,CAChC,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,oBAAoB,EAC9B,OAAO,CAAC,EAAE,aAAa;;;;;;;;;;;;;;;;;;;;;;;GAWxB;AAID,OAAO,EAAC,yBAAyB,EAAC,CAAC;AAEnC;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,gBAAgB,CAAC,GAAG,EAAE,KAAK,EAAE,0BAA0B,CAKxF,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QuantizedMeshLoader = exports.QuantizedMeshWorkerLoader = exports.parseTerrain = exports.TerrainLoader = exports.TerrainWorkerLoader = void 0;
|
|
4
|
+
const parse_quantized_mesh_1 = require("./lib/parse-quantized-mesh");
|
|
5
|
+
const parse_terrain_1 = require("./lib/parse-terrain");
|
|
6
|
+
const terrain_loader_1 = require("./terrain-loader");
|
|
7
|
+
Object.defineProperty(exports, "TerrainWorkerLoader", { enumerable: true, get: function () { return terrain_loader_1.TerrainLoader; } });
|
|
8
|
+
const quantized_mesh_loader_1 = require("./quantized-mesh-loader");
|
|
9
|
+
Object.defineProperty(exports, "QuantizedMeshWorkerLoader", { enumerable: true, get: function () { return quantized_mesh_loader_1.QuantizedMeshLoader; } });
|
|
10
|
+
exports.TerrainLoader = {
|
|
11
|
+
...terrain_loader_1.TerrainLoader,
|
|
12
|
+
parse: parseTerrain
|
|
8
13
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
async function parseTerrain(arrayBuffer, options, context) {
|
|
15
|
+
const loadImageOptions = {
|
|
16
|
+
...options,
|
|
17
|
+
mimeType: 'application/x.image',
|
|
18
|
+
image: { ...options?.image, type: 'data' }
|
|
19
|
+
};
|
|
20
|
+
const image = await context?.parse(arrayBuffer, loadImageOptions);
|
|
21
|
+
// Extend function to support additional mesh generation options (square grid or delatin)
|
|
22
|
+
const terrainOptions = { ...exports.TerrainLoader.options.terrain, ...options?.terrain };
|
|
23
|
+
return (0, parse_terrain_1.makeTerrainMeshFromImage)(image, terrainOptions);
|
|
24
|
+
}
|
|
25
|
+
exports.parseTerrain = parseTerrain;
|
|
26
|
+
/**
|
|
27
|
+
* Loader for quantized meshes
|
|
28
|
+
*/
|
|
29
|
+
exports.QuantizedMeshLoader = {
|
|
30
|
+
...quantized_mesh_loader_1.QuantizedMeshLoader,
|
|
31
|
+
parseSync: (arrayBuffer, options) => (0, parse_quantized_mesh_1.parseQuantizedMesh)(arrayBuffer, options?.['quantized-mesh']),
|
|
32
|
+
parse: async (arrayBuffer, options) => (0, parse_quantized_mesh_1.parseQuantizedMesh)(arrayBuffer, options?.['quantized-mesh'])
|
|
14
33
|
};
|
|
15
|
-
export const _typecheckQuantizedMeshLoader = QuantizedMeshLoader;
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode-quantized-mesh.d.ts","sourceRoot":"","sources":["../../src/lib/decode-quantized-mesh.ts"],"names":[],"mappings":"AAuNA,
|
|
1
|
+
{"version":3,"file":"decode-quantized-mesh.d.ts","sourceRoot":"","sources":["../../src/lib/decode-quantized-mesh.ts"],"names":[],"mappings":"AAuNA,KAAK,UAAU,GAAG;IAChB,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,SAAS,CAAC,EAAE,GAAG,CAAC;CACjB,CAAC;AA0CF,eAAO,MAAM,cAAc;;;;;;CAM1B,CAAC;AAMF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,IAAI,KAAA,EAAE,WAAW,KAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoD/C"}
|
|
@@ -1,268 +1,227 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (C) 2018-2019 HERE Europe B.V.
|
|
3
|
+
//
|
|
4
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
// in the Software without restriction, including without limitation the rights
|
|
7
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
// furnished to do so, subject to the following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included in
|
|
12
|
+
// all copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
// SOFTWARE.
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.DECODING_STEPS = void 0;
|
|
23
|
+
const QUANTIZED_MESH_HEADER = new Map([
|
|
24
|
+
['centerX', Float64Array.BYTES_PER_ELEMENT],
|
|
25
|
+
['centerY', Float64Array.BYTES_PER_ELEMENT],
|
|
26
|
+
['centerZ', Float64Array.BYTES_PER_ELEMENT],
|
|
27
|
+
['minHeight', Float32Array.BYTES_PER_ELEMENT],
|
|
28
|
+
['maxHeight', Float32Array.BYTES_PER_ELEMENT],
|
|
29
|
+
['boundingSphereCenterX', Float64Array.BYTES_PER_ELEMENT],
|
|
30
|
+
['boundingSphereCenterY', Float64Array.BYTES_PER_ELEMENT],
|
|
31
|
+
['boundingSphereCenterZ', Float64Array.BYTES_PER_ELEMENT],
|
|
32
|
+
['boundingSphereRadius', Float64Array.BYTES_PER_ELEMENT],
|
|
33
|
+
['horizonOcclusionPointX', Float64Array.BYTES_PER_ELEMENT],
|
|
34
|
+
['horizonOcclusionPointY', Float64Array.BYTES_PER_ELEMENT],
|
|
35
|
+
['horizonOcclusionPointZ', Float64Array.BYTES_PER_ELEMENT]
|
|
36
|
+
]);
|
|
3
37
|
function decodeZigZag(value) {
|
|
4
|
-
|
|
38
|
+
return (value >> 1) ^ -(value & 1);
|
|
5
39
|
}
|
|
6
|
-
|
|
7
40
|
function decodeHeader(dataView) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
header,
|
|
19
|
-
headerEndPosition: position
|
|
20
|
-
};
|
|
41
|
+
let position = 0;
|
|
42
|
+
const header = {};
|
|
43
|
+
for (const [key, bytesCount] of QUANTIZED_MESH_HEADER) {
|
|
44
|
+
const getter = bytesCount === 8 ? dataView.getFloat64 : dataView.getFloat32;
|
|
45
|
+
header[key] = getter.call(dataView, position, true);
|
|
46
|
+
position += bytesCount;
|
|
47
|
+
}
|
|
48
|
+
return { header, headerEndPosition: position };
|
|
21
49
|
}
|
|
22
|
-
|
|
23
50
|
function decodeVertexData(dataView, headerEndPosition) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
position += elementArrayLength * 3;
|
|
48
|
-
return {
|
|
49
|
-
vertexData,
|
|
50
|
-
vertexDataEndPosition: position
|
|
51
|
-
};
|
|
51
|
+
let position = headerEndPosition;
|
|
52
|
+
const elementsPerVertex = 3;
|
|
53
|
+
const vertexCount = dataView.getUint32(position, true);
|
|
54
|
+
const vertexData = new Uint16Array(vertexCount * elementsPerVertex);
|
|
55
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
56
|
+
const bytesPerArrayElement = Uint16Array.BYTES_PER_ELEMENT;
|
|
57
|
+
const elementArrayLength = vertexCount * bytesPerArrayElement;
|
|
58
|
+
const uArrayStartPosition = position;
|
|
59
|
+
const vArrayStartPosition = uArrayStartPosition + elementArrayLength;
|
|
60
|
+
const heightArrayStartPosition = vArrayStartPosition + elementArrayLength;
|
|
61
|
+
let u = 0;
|
|
62
|
+
let v = 0;
|
|
63
|
+
let height = 0;
|
|
64
|
+
for (let i = 0; i < vertexCount; i++) {
|
|
65
|
+
u += decodeZigZag(dataView.getUint16(uArrayStartPosition + bytesPerArrayElement * i, true));
|
|
66
|
+
v += decodeZigZag(dataView.getUint16(vArrayStartPosition + bytesPerArrayElement * i, true));
|
|
67
|
+
height += decodeZigZag(dataView.getUint16(heightArrayStartPosition + bytesPerArrayElement * i, true));
|
|
68
|
+
vertexData[i] = u;
|
|
69
|
+
vertexData[i + vertexCount] = v;
|
|
70
|
+
vertexData[i + vertexCount * 2] = height;
|
|
71
|
+
}
|
|
72
|
+
position += elementArrayLength * 3;
|
|
73
|
+
return { vertexData, vertexDataEndPosition: position };
|
|
52
74
|
}
|
|
53
|
-
|
|
54
75
|
function decodeIndex(buffer, position, indicesCount, bytesPerIndex, encoded = true) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (!encoded) {
|
|
64
|
-
return indices;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
let highest = 0;
|
|
68
|
-
|
|
69
|
-
for (let i = 0; i < indices.length; ++i) {
|
|
70
|
-
const code = indices[i];
|
|
71
|
-
indices[i] = highest - code;
|
|
72
|
-
|
|
73
|
-
if (code === 0) {
|
|
74
|
-
++highest;
|
|
76
|
+
let indices;
|
|
77
|
+
if (bytesPerIndex === 2) {
|
|
78
|
+
indices = new Uint16Array(buffer, position, indicesCount);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
indices = new Uint32Array(buffer, position, indicesCount);
|
|
75
82
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
83
|
+
if (!encoded) {
|
|
84
|
+
return indices;
|
|
85
|
+
}
|
|
86
|
+
let highest = 0;
|
|
87
|
+
for (let i = 0; i < indices.length; ++i) {
|
|
88
|
+
const code = indices[i];
|
|
89
|
+
indices[i] = highest - code;
|
|
90
|
+
if (code === 0) {
|
|
91
|
+
++highest;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return indices;
|
|
79
95
|
}
|
|
80
|
-
|
|
81
96
|
function decodeTriangleIndices(dataView, vertexData, vertexDataEndPosition) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
triangleIndices
|
|
99
|
-
};
|
|
97
|
+
let position = vertexDataEndPosition;
|
|
98
|
+
const elementsPerVertex = 3;
|
|
99
|
+
const vertexCount = vertexData.length / elementsPerVertex;
|
|
100
|
+
const bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
|
|
101
|
+
if (position % bytesPerIndex !== 0) {
|
|
102
|
+
position += bytesPerIndex - (position % bytesPerIndex);
|
|
103
|
+
}
|
|
104
|
+
const triangleCount = dataView.getUint32(position, true);
|
|
105
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
106
|
+
const triangleIndicesCount = triangleCount * 3;
|
|
107
|
+
const triangleIndices = decodeIndex(dataView.buffer, position, triangleIndicesCount, bytesPerIndex);
|
|
108
|
+
position += triangleIndicesCount * bytesPerIndex;
|
|
109
|
+
return {
|
|
110
|
+
triangleIndicesEndPosition: position,
|
|
111
|
+
triangleIndices
|
|
112
|
+
};
|
|
100
113
|
}
|
|
101
|
-
|
|
102
114
|
function decodeEdgeIndices(dataView, vertexData, triangleIndicesEndPosition) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
115
|
+
let position = triangleIndicesEndPosition;
|
|
116
|
+
const elementsPerVertex = 3;
|
|
117
|
+
const vertexCount = vertexData.length / elementsPerVertex;
|
|
118
|
+
const bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
|
|
119
|
+
const westVertexCount = dataView.getUint32(position, true);
|
|
120
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
121
|
+
const westIndices = decodeIndex(dataView.buffer, position, westVertexCount, bytesPerIndex, false);
|
|
122
|
+
position += westVertexCount * bytesPerIndex;
|
|
123
|
+
const southVertexCount = dataView.getUint32(position, true);
|
|
124
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
125
|
+
const southIndices = decodeIndex(dataView.buffer, position, southVertexCount, bytesPerIndex, false);
|
|
126
|
+
position += southVertexCount * bytesPerIndex;
|
|
127
|
+
const eastVertexCount = dataView.getUint32(position, true);
|
|
128
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
129
|
+
const eastIndices = decodeIndex(dataView.buffer, position, eastVertexCount, bytesPerIndex, false);
|
|
130
|
+
position += eastVertexCount * bytesPerIndex;
|
|
131
|
+
const northVertexCount = dataView.getUint32(position, true);
|
|
132
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
133
|
+
const northIndices = decodeIndex(dataView.buffer, position, northVertexCount, bytesPerIndex, false);
|
|
134
|
+
position += northVertexCount * bytesPerIndex;
|
|
135
|
+
return {
|
|
136
|
+
edgeIndicesEndPosition: position,
|
|
137
|
+
westIndices,
|
|
138
|
+
southIndices,
|
|
139
|
+
eastIndices,
|
|
140
|
+
northIndices
|
|
141
|
+
};
|
|
130
142
|
}
|
|
131
|
-
|
|
132
143
|
function decodeVertexNormalsExtension(extensionDataView) {
|
|
133
|
-
|
|
144
|
+
return new Uint8Array(extensionDataView.buffer, extensionDataView.byteOffset, extensionDataView.byteLength);
|
|
134
145
|
}
|
|
135
|
-
|
|
136
146
|
function decodeWaterMaskExtension(extensionDataView) {
|
|
137
|
-
|
|
147
|
+
return extensionDataView.buffer.slice(extensionDataView.byteOffset, extensionDataView.byteOffset + extensionDataView.byteLength);
|
|
138
148
|
}
|
|
139
|
-
|
|
140
149
|
function decodeExtensions(dataView, indicesEndPosition) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
case 2:
|
|
167
|
-
{
|
|
168
|
-
extensions.waterMask = decodeWaterMaskExtension(extensionView);
|
|
169
|
-
break;
|
|
150
|
+
const extensions = {};
|
|
151
|
+
if (dataView.byteLength <= indicesEndPosition) {
|
|
152
|
+
return { extensions, extensionsEndPosition: indicesEndPosition };
|
|
153
|
+
}
|
|
154
|
+
let position = indicesEndPosition;
|
|
155
|
+
while (position < dataView.byteLength) {
|
|
156
|
+
const extensionId = dataView.getUint8(position, true);
|
|
157
|
+
position += Uint8Array.BYTES_PER_ELEMENT;
|
|
158
|
+
const extensionLength = dataView.getUint32(position, true);
|
|
159
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
160
|
+
const extensionView = new DataView(dataView.buffer, position, extensionLength);
|
|
161
|
+
switch (extensionId) {
|
|
162
|
+
case 1: {
|
|
163
|
+
extensions.vertexNormals = decodeVertexNormalsExtension(extensionView);
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
case 2: {
|
|
167
|
+
extensions.waterMask = decodeWaterMaskExtension(extensionView);
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
default: {
|
|
171
|
+
// console.warn(`Unknown extension with id ${extensionId}`)
|
|
172
|
+
}
|
|
170
173
|
}
|
|
171
|
-
|
|
172
|
-
default:
|
|
173
|
-
{}
|
|
174
|
+
position += extensionLength;
|
|
174
175
|
}
|
|
175
|
-
|
|
176
|
-
position += extensionLength;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return {
|
|
180
|
-
extensions,
|
|
181
|
-
extensionsEndPosition: position
|
|
182
|
-
};
|
|
176
|
+
return { extensions, extensionsEndPosition: position };
|
|
183
177
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
extensions: 4
|
|
178
|
+
exports.DECODING_STEPS = {
|
|
179
|
+
header: 0,
|
|
180
|
+
vertices: 1,
|
|
181
|
+
triangleIndices: 2,
|
|
182
|
+
edgeIndices: 3,
|
|
183
|
+
extensions: 4
|
|
191
184
|
};
|
|
192
185
|
const DEFAULT_OPTIONS = {
|
|
193
|
-
|
|
186
|
+
maxDecodingStep: exports.DECODING_STEPS.extensions
|
|
194
187
|
};
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
vertexData,
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
triangleIndicesEndPosition
|
|
224
|
-
} = decodeTriangleIndices(view, vertexData, vertexDataEndPosition);
|
|
225
|
-
|
|
226
|
-
if (options.maxDecodingStep < DECODING_STEPS.edgeIndices) {
|
|
227
|
-
return {
|
|
228
|
-
header,
|
|
229
|
-
vertexData,
|
|
230
|
-
triangleIndices
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const {
|
|
235
|
-
westIndices,
|
|
236
|
-
southIndices,
|
|
237
|
-
eastIndices,
|
|
238
|
-
northIndices,
|
|
239
|
-
edgeIndicesEndPosition
|
|
240
|
-
} = decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition);
|
|
241
|
-
|
|
242
|
-
if (options.maxDecodingStep < DECODING_STEPS.extensions) {
|
|
188
|
+
function decode(data, userOptions) {
|
|
189
|
+
const options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
|
|
190
|
+
const view = new DataView(data);
|
|
191
|
+
const { header, headerEndPosition } = decodeHeader(view);
|
|
192
|
+
if (options.maxDecodingStep < exports.DECODING_STEPS.vertices) {
|
|
193
|
+
return { header };
|
|
194
|
+
}
|
|
195
|
+
const { vertexData, vertexDataEndPosition } = decodeVertexData(view, headerEndPosition);
|
|
196
|
+
if (options.maxDecodingStep < exports.DECODING_STEPS.triangleIndices) {
|
|
197
|
+
return { header, vertexData };
|
|
198
|
+
}
|
|
199
|
+
const { triangleIndices, triangleIndicesEndPosition } = decodeTriangleIndices(view, vertexData, vertexDataEndPosition);
|
|
200
|
+
if (options.maxDecodingStep < exports.DECODING_STEPS.edgeIndices) {
|
|
201
|
+
return { header, vertexData, triangleIndices };
|
|
202
|
+
}
|
|
203
|
+
const { westIndices, southIndices, eastIndices, northIndices, edgeIndicesEndPosition } = decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition);
|
|
204
|
+
if (options.maxDecodingStep < exports.DECODING_STEPS.extensions) {
|
|
205
|
+
return {
|
|
206
|
+
header,
|
|
207
|
+
vertexData,
|
|
208
|
+
triangleIndices,
|
|
209
|
+
westIndices,
|
|
210
|
+
northIndices,
|
|
211
|
+
eastIndices,
|
|
212
|
+
southIndices
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const { extensions } = decodeExtensions(view, edgeIndicesEndPosition);
|
|
243
216
|
return {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
217
|
+
header,
|
|
218
|
+
vertexData,
|
|
219
|
+
triangleIndices,
|
|
220
|
+
westIndices,
|
|
221
|
+
northIndices,
|
|
222
|
+
eastIndices,
|
|
223
|
+
southIndices,
|
|
224
|
+
extensions
|
|
251
225
|
};
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const {
|
|
255
|
-
extensions
|
|
256
|
-
} = decodeExtensions(view, edgeIndicesEndPosition);
|
|
257
|
-
return {
|
|
258
|
-
header,
|
|
259
|
-
vertexData,
|
|
260
|
-
triangleIndices,
|
|
261
|
-
westIndices,
|
|
262
|
-
northIndices,
|
|
263
|
-
eastIndices,
|
|
264
|
-
southIndices,
|
|
265
|
-
extensions
|
|
266
|
-
};
|
|
267
226
|
}
|
|
268
|
-
|
|
227
|
+
exports.default = decode;
|