@loaders.gl/textures 4.0.0-alpha.23 → 4.0.0-alpha.24
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/basis-worker-node.js +2 -2
- package/dist/basis-worker.js +2 -2
- package/dist/compressed-texture-worker.js +2 -2
- package/dist/crunch-loader.d.ts +9 -2
- package/dist/crunch-loader.d.ts.map +1 -1
- package/dist/crunch-worker.js +2 -2
- package/dist/es5/crunch-loader.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/esm/crunch-loader.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/ktx2-basis-writer-worker-node.js +2 -2
- package/dist/ktx2-basis-writer-worker.js +2 -2
- package/dist/npy-worker.js +1 -1
- package/dist/workers/crunch-worker.d.ts +3 -3
- package/package.json +7 -7
- package/src/crunch-loader.ts +10 -4
- package/dist/basis-loader.js +0 -37
- package/dist/bundle.js +0 -5
- package/dist/compressed-texture-loader.js +0 -63
- package/dist/compressed-texture-writer.js +0 -34
- package/dist/crunch-loader.js +0 -23
- package/dist/index.js +0 -57
- package/dist/ktx2-basis-writer.js +0 -28
- package/dist/lib/encoders/encode-ktx.js +0 -10
- package/dist/lib/encoders/encode-ktx2-basis-texture.js +0 -41
- package/dist/lib/encoders/encode-texture.js +0 -27
- package/dist/lib/gl-extensions.js +0 -72
- package/dist/lib/parsers/basis-module-loader.js +0 -118
- package/dist/lib/parsers/crunch-module-loader.js +0 -39
- package/dist/lib/parsers/parse-basis.js +0 -245
- package/dist/lib/parsers/parse-compressed-texture.js +0 -26
- package/dist/lib/parsers/parse-crunch.js +0 -106
- package/dist/lib/parsers/parse-dds.js +0 -108
- package/dist/lib/parsers/parse-ktx.js +0 -46
- package/dist/lib/parsers/parse-npy.js +0 -81
- package/dist/lib/parsers/parse-pvr.js +0 -250
- package/dist/lib/texture-api/async-deep-map.js +0 -41
- package/dist/lib/texture-api/deep-load.js +0 -15
- package/dist/lib/texture-api/generate-url.js +0 -17
- package/dist/lib/texture-api/load-image-array.js +0 -21
- package/dist/lib/texture-api/load-image-cube.js +0 -47
- package/dist/lib/texture-api/load-image.js +0 -43
- package/dist/lib/texture-api/texture-api-types.js +0 -3
- package/dist/lib/utils/extract-mipmap-images.js +0 -50
- package/dist/lib/utils/ktx-format-helper.js +0 -125
- package/dist/lib/utils/texture-formats.js +0 -51
- package/dist/lib/utils/version.js +0 -8
- package/dist/npy-loader.js +0 -31
- package/dist/types.js +0 -1
- package/dist/workers/basis-worker-node.js +0 -7
- package/dist/workers/basis-worker.js +0 -5
- package/dist/workers/compressed-texture-worker.js +0 -6
- package/dist/workers/crunch-worker.js +0 -14
- package/dist/workers/ktx2-basis-writer-worker-node.js +0 -28
- package/dist/workers/ktx2-basis-writer-worker.js +0 -26
- package/dist/workers/npy-worker.js +0 -5
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDxtXLevelSize = exports.getDxt1LevelSize = exports.parseDDS = exports.isDDS = void 0;
|
|
4
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
-
const gl_extensions_1 = require("../gl-extensions");
|
|
6
|
-
const extract_mipmap_images_1 = require("../utils/extract-mipmap-images");
|
|
7
|
-
const DDS_CONSTANTS = {
|
|
8
|
-
MAGIC_NUMBER: 0x20534444,
|
|
9
|
-
HEADER_LENGTH: 31,
|
|
10
|
-
MAGIC_NUMBER_INDEX: 0,
|
|
11
|
-
HEADER_SIZE_INDEX: 1,
|
|
12
|
-
HEADER_FLAGS_INDEX: 2,
|
|
13
|
-
HEADER_HEIGHT_INDEX: 3,
|
|
14
|
-
HEADER_WIDTH_INDEX: 4,
|
|
15
|
-
MIPMAPCOUNT_INDEX: 7,
|
|
16
|
-
HEADER_PF_FLAGS_INDEX: 20,
|
|
17
|
-
HEADER_PF_FOURCC_INDEX: 21,
|
|
18
|
-
DDSD_MIPMAPCOUNT: 0x20000,
|
|
19
|
-
DDPF_FOURCC: 0x4
|
|
20
|
-
};
|
|
21
|
-
const DDS_PIXEL_FORMATS = {
|
|
22
|
-
DXT1: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT,
|
|
23
|
-
DXT3: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
|
|
24
|
-
DXT5: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
|
|
25
|
-
'ATC ': gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ATC_WEBGL,
|
|
26
|
-
ATCA: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL,
|
|
27
|
-
ATCI: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL
|
|
28
|
-
};
|
|
29
|
-
const getATCLevelSize = getDxt1LevelSize;
|
|
30
|
-
const getATCALevelSize = getDxtXLevelSize;
|
|
31
|
-
const getATCILevelSize = getDxtXLevelSize;
|
|
32
|
-
const DDS_SIZE_FUNCTIONS = {
|
|
33
|
-
DXT1: getDxt1LevelSize,
|
|
34
|
-
DXT3: getDxtXLevelSize,
|
|
35
|
-
DXT5: getDxtXLevelSize,
|
|
36
|
-
'ATC ': getATCLevelSize,
|
|
37
|
-
ATCA: getATCALevelSize,
|
|
38
|
-
ATCI: getATCILevelSize
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Check if data is in "DDS" format by its magic number
|
|
42
|
-
* @param data - binary data of compressed texture
|
|
43
|
-
* @returns true - data in "DDS" format, else - false
|
|
44
|
-
*/
|
|
45
|
-
function isDDS(data) {
|
|
46
|
-
const header = new Uint32Array(data, 0, DDS_CONSTANTS.HEADER_LENGTH);
|
|
47
|
-
const magic = header[DDS_CONSTANTS.MAGIC_NUMBER_INDEX];
|
|
48
|
-
return magic === DDS_CONSTANTS.MAGIC_NUMBER;
|
|
49
|
-
}
|
|
50
|
-
exports.isDDS = isDDS;
|
|
51
|
-
/**
|
|
52
|
-
* Parse texture data as "DDS" format
|
|
53
|
-
* @param data - binary data of compressed texture
|
|
54
|
-
* @returns Array of the texture levels
|
|
55
|
-
*/
|
|
56
|
-
function parseDDS(data) {
|
|
57
|
-
const header = new Int32Array(data, 0, DDS_CONSTANTS.HEADER_LENGTH);
|
|
58
|
-
const pixelFormatNumber = header[DDS_CONSTANTS.HEADER_PF_FOURCC_INDEX];
|
|
59
|
-
(0, loader_utils_1.assert)(Boolean(header[DDS_CONSTANTS.HEADER_PF_FLAGS_INDEX] & DDS_CONSTANTS.DDPF_FOURCC), 'DDS: Unsupported format, must contain a FourCC code');
|
|
60
|
-
const fourCC = int32ToFourCC(pixelFormatNumber);
|
|
61
|
-
const internalFormat = DDS_PIXEL_FORMATS[fourCC];
|
|
62
|
-
const sizeFunction = DDS_SIZE_FUNCTIONS[fourCC];
|
|
63
|
-
(0, loader_utils_1.assert)(internalFormat && sizeFunction, `DDS: Unknown pixel format ${pixelFormatNumber}`);
|
|
64
|
-
let mipMapLevels = 1;
|
|
65
|
-
if (header[DDS_CONSTANTS.HEADER_FLAGS_INDEX] & DDS_CONSTANTS.DDSD_MIPMAPCOUNT) {
|
|
66
|
-
mipMapLevels = Math.max(1, header[DDS_CONSTANTS.MIPMAPCOUNT_INDEX]);
|
|
67
|
-
}
|
|
68
|
-
const width = header[DDS_CONSTANTS.HEADER_WIDTH_INDEX];
|
|
69
|
-
const height = header[DDS_CONSTANTS.HEADER_HEIGHT_INDEX];
|
|
70
|
-
const dataOffset = header[DDS_CONSTANTS.HEADER_SIZE_INDEX] + 4;
|
|
71
|
-
const image = new Uint8Array(data, dataOffset);
|
|
72
|
-
return (0, extract_mipmap_images_1.extractMipmapImages)(image, {
|
|
73
|
-
mipMapLevels,
|
|
74
|
-
width,
|
|
75
|
-
height,
|
|
76
|
-
sizeFunction,
|
|
77
|
-
internalFormat
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
exports.parseDDS = parseDDS;
|
|
81
|
-
/**
|
|
82
|
-
* DXT1 applicable function to calculate level size
|
|
83
|
-
* @param width - level width
|
|
84
|
-
* @param height - level height
|
|
85
|
-
* @returns level size in bytes
|
|
86
|
-
*/
|
|
87
|
-
function getDxt1LevelSize(width, height) {
|
|
88
|
-
return ((width + 3) >> 2) * ((height + 3) >> 2) * 8;
|
|
89
|
-
}
|
|
90
|
-
exports.getDxt1LevelSize = getDxt1LevelSize;
|
|
91
|
-
/**
|
|
92
|
-
* DXT3 & DXT5 applicable function to calculate level size
|
|
93
|
-
* @param width - level width
|
|
94
|
-
* @param height - level height
|
|
95
|
-
* @returns level size in bytes
|
|
96
|
-
*/
|
|
97
|
-
function getDxtXLevelSize(width, height) {
|
|
98
|
-
return ((width + 3) >> 2) * ((height + 3) >> 2) * 16;
|
|
99
|
-
}
|
|
100
|
-
exports.getDxtXLevelSize = getDxtXLevelSize;
|
|
101
|
-
/**
|
|
102
|
-
* Convert every byte of Int32 value to char
|
|
103
|
-
* @param value - Int32 number
|
|
104
|
-
* @returns string of 4 characters
|
|
105
|
-
*/
|
|
106
|
-
function int32ToFourCC(value) {
|
|
107
|
-
return String.fromCharCode(value & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff, (value >> 24) & 0xff);
|
|
108
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseKTX = exports.isKTX = void 0;
|
|
4
|
-
const ktx_parse_1 = require("ktx-parse");
|
|
5
|
-
const extract_mipmap_images_1 = require("../utils/extract-mipmap-images");
|
|
6
|
-
const ktx_format_helper_1 = require("../utils/ktx-format-helper");
|
|
7
|
-
const KTX2_ID = [
|
|
8
|
-
// '´', 'K', 'T', 'X', '2', '0', 'ª', '\r', '\n', '\x1A', '\n'
|
|
9
|
-
0xab, 0x4b, 0x54, 0x58, 0x20, 0x32, 0x30, 0xbb, 0x0d, 0x0a, 0x1a, 0x0a
|
|
10
|
-
];
|
|
11
|
-
// eslint-disable-next-line complexity
|
|
12
|
-
function isKTX(data) {
|
|
13
|
-
// const id = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
14
|
-
const id = new Uint8Array(data);
|
|
15
|
-
const notKTX = id.byteLength < KTX2_ID.length ||
|
|
16
|
-
id[0] !== KTX2_ID[0] || // '´'
|
|
17
|
-
id[1] !== KTX2_ID[1] || // 'K'
|
|
18
|
-
id[2] !== KTX2_ID[2] || // 'T'
|
|
19
|
-
id[3] !== KTX2_ID[3] || // 'X'
|
|
20
|
-
id[4] !== KTX2_ID[4] || // ' '
|
|
21
|
-
id[5] !== KTX2_ID[5] || // '2'
|
|
22
|
-
id[6] !== KTX2_ID[6] || // '0'
|
|
23
|
-
id[7] !== KTX2_ID[7] || // 'ª'
|
|
24
|
-
id[8] !== KTX2_ID[8] || // '\r'
|
|
25
|
-
id[9] !== KTX2_ID[9] || // '\n'
|
|
26
|
-
id[10] !== KTX2_ID[10] || // '\x1A'
|
|
27
|
-
id[11] !== KTX2_ID[11]; // '\n'
|
|
28
|
-
return !notKTX;
|
|
29
|
-
}
|
|
30
|
-
exports.isKTX = isKTX;
|
|
31
|
-
function parseKTX(arrayBuffer) {
|
|
32
|
-
const uint8Array = new Uint8Array(arrayBuffer);
|
|
33
|
-
const ktx = (0, ktx_parse_1.read)(uint8Array);
|
|
34
|
-
const mipMapLevels = Math.max(1, ktx.levels.length);
|
|
35
|
-
const width = ktx.pixelWidth;
|
|
36
|
-
const height = ktx.pixelHeight;
|
|
37
|
-
const internalFormat = (0, ktx_format_helper_1.mapVkFormatToWebGL)(ktx.vkFormat);
|
|
38
|
-
return (0, extract_mipmap_images_1.extractMipmapImages)(ktx.levels, {
|
|
39
|
-
mipMapLevels,
|
|
40
|
-
width,
|
|
41
|
-
height,
|
|
42
|
-
sizeFunction: (level) => level.uncompressedByteLength,
|
|
43
|
-
internalFormat
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
exports.parseKTX = parseKTX;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseNPY = void 0;
|
|
4
|
-
const a = new Uint32Array([0x12345678]);
|
|
5
|
-
const b = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
|
|
6
|
-
const isLittleEndian = !(b[0] === 0x12);
|
|
7
|
-
const LITTLE_ENDIAN_OS = isLittleEndian;
|
|
8
|
-
/**
|
|
9
|
-
* The basic string format consists of 3 characters:
|
|
10
|
-
* 1. a character describing the byteorder of the data (<: little-endian, >: big-endian, |: not-relevant)
|
|
11
|
-
* 2. a character code giving the basic type of the array
|
|
12
|
-
* 3. an integer providing the number of bytes the type uses.
|
|
13
|
-
* https://numpy.org/doc/stable/reference/arrays.interface.html
|
|
14
|
-
*
|
|
15
|
-
* Here I only include the second and third characters, and check endianness separately
|
|
16
|
-
*/
|
|
17
|
-
const DTYPES = {
|
|
18
|
-
u1: Uint8Array,
|
|
19
|
-
i1: Int8Array,
|
|
20
|
-
u2: Uint16Array,
|
|
21
|
-
i2: Int16Array,
|
|
22
|
-
u4: Uint32Array,
|
|
23
|
-
i4: Int32Array,
|
|
24
|
-
f4: Float32Array,
|
|
25
|
-
f8: Float64Array
|
|
26
|
-
};
|
|
27
|
-
function parseNPY(arrayBuffer, options) {
|
|
28
|
-
const view = new DataView(arrayBuffer);
|
|
29
|
-
const { header, headerEndOffset } = parseHeader(view);
|
|
30
|
-
const numpyType = header.descr;
|
|
31
|
-
const ArrayType = DTYPES[numpyType.slice(1, 3)];
|
|
32
|
-
if (!ArrayType) {
|
|
33
|
-
throw new Error(`Unimplemented type ${numpyType}`);
|
|
34
|
-
}
|
|
35
|
-
const nArrayElements = header.shape?.reduce((a, b) => a * b);
|
|
36
|
-
const arrayByteLength = nArrayElements * ArrayType.BYTES_PER_ELEMENT;
|
|
37
|
-
if (arrayBuffer.byteLength < headerEndOffset + arrayByteLength) {
|
|
38
|
-
throw new Error('Buffer overflow');
|
|
39
|
-
}
|
|
40
|
-
const data = new ArrayType(arrayBuffer.slice(headerEndOffset, headerEndOffset + arrayByteLength));
|
|
41
|
-
// Swap endianness if needed
|
|
42
|
-
if ((numpyType[0] === '>' && LITTLE_ENDIAN_OS) || (numpyType[0] === '<' && !LITTLE_ENDIAN_OS)) {
|
|
43
|
-
throw new Error('Incorrect endianness');
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
data,
|
|
47
|
-
header
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
exports.parseNPY = parseNPY;
|
|
51
|
-
/**
|
|
52
|
-
* Parse NPY header
|
|
53
|
-
*
|
|
54
|
-
* @param view
|
|
55
|
-
* @return
|
|
56
|
-
*/
|
|
57
|
-
function parseHeader(view) {
|
|
58
|
-
const majorVersion = view.getUint8(6);
|
|
59
|
-
// const minorVersion = view.getUint8(7);
|
|
60
|
-
let offset = 8;
|
|
61
|
-
let headerLength;
|
|
62
|
-
if (majorVersion >= 2) {
|
|
63
|
-
headerLength = view.getUint32(offset, true);
|
|
64
|
-
offset += 4;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
headerLength = view.getUint16(offset, true);
|
|
68
|
-
offset += 2;
|
|
69
|
-
}
|
|
70
|
-
const encoding = majorVersion <= 2 ? 'latin1' : 'utf-8';
|
|
71
|
-
const decoder = new TextDecoder(encoding);
|
|
72
|
-
const headerArray = new Uint8Array(view.buffer, offset, headerLength);
|
|
73
|
-
const headerText = decoder.decode(headerArray);
|
|
74
|
-
offset += headerLength;
|
|
75
|
-
const header = JSON.parse(headerText
|
|
76
|
-
.replace(/'/g, '"')
|
|
77
|
-
.replace('False', 'false')
|
|
78
|
-
.replace('(', '[')
|
|
79
|
-
.replace(/,*\),*/g, ']'));
|
|
80
|
-
return { header, headerEndOffset: offset };
|
|
81
|
-
}
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable camelcase */
|
|
3
|
-
// Forked from PicoGL: https://github.com/tsherif/picogl.js/blob/master/examples/utils/utils.js
|
|
4
|
-
// Copyright (c) 2017 Tarek Sherif, The MIT License (MIT)
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parsePVR = exports.isPVR = void 0;
|
|
7
|
-
const gl_extensions_1 = require("../gl-extensions");
|
|
8
|
-
const extract_mipmap_images_1 = require("../utils/extract-mipmap-images");
|
|
9
|
-
const PVR_CONSTANTS = {
|
|
10
|
-
MAGIC_NUMBER: 0x03525650,
|
|
11
|
-
MAGIC_NUMBER_EXTRA: 0x50565203,
|
|
12
|
-
HEADER_LENGTH: 13,
|
|
13
|
-
HEADER_SIZE: 52,
|
|
14
|
-
MAGIC_NUMBER_INDEX: 0,
|
|
15
|
-
PIXEL_FORMAT_INDEX: 2,
|
|
16
|
-
COLOUR_SPACE_INDEX: 4,
|
|
17
|
-
HEIGHT_INDEX: 6,
|
|
18
|
-
WIDTH_INDEX: 7,
|
|
19
|
-
MIPMAPCOUNT_INDEX: 11,
|
|
20
|
-
METADATA_SIZE_INDEX: 12
|
|
21
|
-
};
|
|
22
|
-
const PVR_PIXEL_FORMATS = {
|
|
23
|
-
0: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_2BPPV1_IMG],
|
|
24
|
-
1: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG],
|
|
25
|
-
2: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG],
|
|
26
|
-
3: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG],
|
|
27
|
-
6: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL],
|
|
28
|
-
7: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT],
|
|
29
|
-
9: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT],
|
|
30
|
-
11: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT],
|
|
31
|
-
22: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_ETC2],
|
|
32
|
-
23: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA8_ETC2_EAC],
|
|
33
|
-
24: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2],
|
|
34
|
-
25: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_R11_EAC],
|
|
35
|
-
26: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RG11_EAC],
|
|
36
|
-
27: [
|
|
37
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR,
|
|
38
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR
|
|
39
|
-
],
|
|
40
|
-
28: [
|
|
41
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X4_KHR,
|
|
42
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR
|
|
43
|
-
],
|
|
44
|
-
29: [
|
|
45
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X5_KHR,
|
|
46
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR
|
|
47
|
-
],
|
|
48
|
-
30: [
|
|
49
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X5_KHR,
|
|
50
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR
|
|
51
|
-
],
|
|
52
|
-
31: [
|
|
53
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X6_KHR,
|
|
54
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR
|
|
55
|
-
],
|
|
56
|
-
32: [
|
|
57
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X5_KHR,
|
|
58
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR
|
|
59
|
-
],
|
|
60
|
-
33: [
|
|
61
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X6_KHR,
|
|
62
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR
|
|
63
|
-
],
|
|
64
|
-
34: [
|
|
65
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X8_KHR,
|
|
66
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR
|
|
67
|
-
],
|
|
68
|
-
35: [
|
|
69
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X5_KHR,
|
|
70
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR
|
|
71
|
-
],
|
|
72
|
-
36: [
|
|
73
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X6_KHR,
|
|
74
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR
|
|
75
|
-
],
|
|
76
|
-
37: [
|
|
77
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X8_KHR,
|
|
78
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR
|
|
79
|
-
],
|
|
80
|
-
38: [
|
|
81
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X10_KHR,
|
|
82
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR
|
|
83
|
-
],
|
|
84
|
-
39: [
|
|
85
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X10_KHR,
|
|
86
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR
|
|
87
|
-
],
|
|
88
|
-
40: [
|
|
89
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X12_KHR,
|
|
90
|
-
gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR
|
|
91
|
-
]
|
|
92
|
-
};
|
|
93
|
-
const PVR_SIZE_FUNCTIONS = {
|
|
94
|
-
0: pvrtc2bppSize,
|
|
95
|
-
1: pvrtc2bppSize,
|
|
96
|
-
2: pvrtc4bppSize,
|
|
97
|
-
3: pvrtc4bppSize,
|
|
98
|
-
6: dxtEtcSmallSize,
|
|
99
|
-
7: dxtEtcSmallSize,
|
|
100
|
-
9: dxtEtcAstcBigSize,
|
|
101
|
-
11: dxtEtcAstcBigSize,
|
|
102
|
-
22: dxtEtcSmallSize,
|
|
103
|
-
23: dxtEtcAstcBigSize,
|
|
104
|
-
24: dxtEtcSmallSize,
|
|
105
|
-
25: dxtEtcSmallSize,
|
|
106
|
-
26: dxtEtcAstcBigSize,
|
|
107
|
-
27: dxtEtcAstcBigSize,
|
|
108
|
-
28: atc5x4Size,
|
|
109
|
-
29: atc5x5Size,
|
|
110
|
-
30: atc6x5Size,
|
|
111
|
-
31: atc6x6Size,
|
|
112
|
-
32: atc8x5Size,
|
|
113
|
-
33: atc8x6Size,
|
|
114
|
-
34: atc8x8Size,
|
|
115
|
-
35: atc10x5Size,
|
|
116
|
-
36: atc10x6Size,
|
|
117
|
-
37: atc10x8Size,
|
|
118
|
-
38: atc10x10Size,
|
|
119
|
-
39: atc12x10Size,
|
|
120
|
-
40: atc12x12Size
|
|
121
|
-
};
|
|
122
|
-
/**
|
|
123
|
-
* Check if data is in "PVR" format by its magic number
|
|
124
|
-
* @param data - binary data of compressed texture
|
|
125
|
-
* @returns true - data in "PVR" format, else - false
|
|
126
|
-
*/
|
|
127
|
-
function isPVR(data) {
|
|
128
|
-
const header = new Uint32Array(data, 0, PVR_CONSTANTS.HEADER_LENGTH);
|
|
129
|
-
const version = header[PVR_CONSTANTS.MAGIC_NUMBER_INDEX];
|
|
130
|
-
return version === PVR_CONSTANTS.MAGIC_NUMBER || version === PVR_CONSTANTS.MAGIC_NUMBER_EXTRA;
|
|
131
|
-
}
|
|
132
|
-
exports.isPVR = isPVR;
|
|
133
|
-
/**
|
|
134
|
-
* Parse texture data as "PVR" format
|
|
135
|
-
* @param data - binary data of compressed texture
|
|
136
|
-
* @returns Array of the texture levels
|
|
137
|
-
* @see http://cdn.imgtec.com/sdk-documentation/PVR+File+Format.Specification.pdf
|
|
138
|
-
*/
|
|
139
|
-
function parsePVR(data) {
|
|
140
|
-
const header = new Uint32Array(data, 0, PVR_CONSTANTS.HEADER_LENGTH);
|
|
141
|
-
const pvrFormat = header[PVR_CONSTANTS.PIXEL_FORMAT_INDEX];
|
|
142
|
-
const colourSpace = header[PVR_CONSTANTS.COLOUR_SPACE_INDEX];
|
|
143
|
-
const pixelFormats = PVR_PIXEL_FORMATS[pvrFormat] || [];
|
|
144
|
-
const internalFormat = pixelFormats.length > 1 && colourSpace ? pixelFormats[1] : pixelFormats[0];
|
|
145
|
-
const sizeFunction = PVR_SIZE_FUNCTIONS[pvrFormat];
|
|
146
|
-
const mipMapLevels = header[PVR_CONSTANTS.MIPMAPCOUNT_INDEX];
|
|
147
|
-
const width = header[PVR_CONSTANTS.WIDTH_INDEX];
|
|
148
|
-
const height = header[PVR_CONSTANTS.HEIGHT_INDEX];
|
|
149
|
-
const dataOffset = PVR_CONSTANTS.HEADER_SIZE + header[PVR_CONSTANTS.METADATA_SIZE_INDEX];
|
|
150
|
-
const image = new Uint8Array(data, dataOffset);
|
|
151
|
-
return (0, extract_mipmap_images_1.extractMipmapImages)(image, {
|
|
152
|
-
mipMapLevels,
|
|
153
|
-
width,
|
|
154
|
-
height,
|
|
155
|
-
sizeFunction,
|
|
156
|
-
internalFormat
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
exports.parsePVR = parsePVR;
|
|
160
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_pvrtc/
|
|
161
|
-
function pvrtc2bppSize(width, height) {
|
|
162
|
-
width = Math.max(width, 16);
|
|
163
|
-
height = Math.max(height, 8);
|
|
164
|
-
return (width * height) / 4;
|
|
165
|
-
}
|
|
166
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_pvrtc/
|
|
167
|
-
function pvrtc4bppSize(width, height) {
|
|
168
|
-
width = Math.max(width, 8);
|
|
169
|
-
height = Math.max(height, 8);
|
|
170
|
-
return (width * height) / 2;
|
|
171
|
-
}
|
|
172
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_s3tc/
|
|
173
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_etc/
|
|
174
|
-
// Size for:
|
|
175
|
-
// COMPRESSED_RGB_S3TC_DXT1_EXT
|
|
176
|
-
// COMPRESSED_R11_EAC
|
|
177
|
-
// COMPRESSED_SIGNED_R11_EAC
|
|
178
|
-
// COMPRESSED_RGB8_ETC2
|
|
179
|
-
// COMPRESSED_SRGB8_ETC2
|
|
180
|
-
// COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
|
|
181
|
-
// COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
|
|
182
|
-
function dxtEtcSmallSize(width, height) {
|
|
183
|
-
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 8;
|
|
184
|
-
}
|
|
185
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_s3tc/
|
|
186
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_etc/
|
|
187
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
188
|
-
// Size for:
|
|
189
|
-
// COMPRESSED_RGBA_S3TC_DXT3_EXT
|
|
190
|
-
// COMPRESSED_RGBA_S3TC_DXT5_EXT
|
|
191
|
-
// COMPRESSED_RG11_EAC
|
|
192
|
-
// COMPRESSED_SIGNED_RG11_EAC
|
|
193
|
-
// COMPRESSED_RGBA8_ETC2_EAC
|
|
194
|
-
// COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
|
|
195
|
-
// COMPRESSED_RGBA_ASTC_4x4_KHR
|
|
196
|
-
function dxtEtcAstcBigSize(width, height) {
|
|
197
|
-
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16;
|
|
198
|
-
}
|
|
199
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
200
|
-
function atc5x4Size(width, height) {
|
|
201
|
-
return Math.floor((width + 4) / 5) * Math.floor((height + 3) / 4) * 16;
|
|
202
|
-
}
|
|
203
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
204
|
-
function atc5x5Size(width, height) {
|
|
205
|
-
return Math.floor((width + 4) / 5) * Math.floor((height + 4) / 5) * 16;
|
|
206
|
-
}
|
|
207
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
208
|
-
function atc6x5Size(width, height) {
|
|
209
|
-
return Math.floor((width + 5) / 6) * Math.floor((height + 4) / 5) * 16;
|
|
210
|
-
}
|
|
211
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
212
|
-
function atc6x6Size(width, height) {
|
|
213
|
-
return Math.floor((width + 5) / 6) * Math.floor((height + 5) / 6) * 16;
|
|
214
|
-
}
|
|
215
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
216
|
-
function atc8x5Size(width, height) {
|
|
217
|
-
return Math.floor((width + 7) / 8) * Math.floor((height + 4) / 5) * 16;
|
|
218
|
-
}
|
|
219
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
220
|
-
function atc8x6Size(width, height) {
|
|
221
|
-
return Math.floor((width + 7) / 8) * Math.floor((height + 5) / 6) * 16;
|
|
222
|
-
}
|
|
223
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
224
|
-
function atc8x8Size(width, height) {
|
|
225
|
-
return Math.floor((width + 7) / 8) * Math.floor((height + 7) / 8) * 16;
|
|
226
|
-
}
|
|
227
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
228
|
-
function atc10x5Size(width, height) {
|
|
229
|
-
return Math.floor((width + 9) / 10) * Math.floor((height + 4) / 5) * 16;
|
|
230
|
-
}
|
|
231
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
232
|
-
function atc10x6Size(width, height) {
|
|
233
|
-
return Math.floor((width + 9) / 10) * Math.floor((height + 5) / 6) * 16;
|
|
234
|
-
}
|
|
235
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
236
|
-
function atc10x8Size(width, height) {
|
|
237
|
-
return Math.floor((width + 9) / 10) * Math.floor((height + 7) / 8) * 16;
|
|
238
|
-
}
|
|
239
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
240
|
-
function atc10x10Size(width, height) {
|
|
241
|
-
return Math.floor((width + 9) / 10) * Math.floor((height + 9) / 10) * 16;
|
|
242
|
-
}
|
|
243
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
244
|
-
function atc12x10Size(width, height) {
|
|
245
|
-
return Math.floor((width + 11) / 12) * Math.floor((height + 9) / 10) * 16;
|
|
246
|
-
}
|
|
247
|
-
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
248
|
-
function atc12x12Size(width, height) {
|
|
249
|
-
return Math.floor((width + 11) / 12) * Math.floor((height + 11) / 12) * 16;
|
|
250
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapSubtree = exports.asyncDeepMap = void 0;
|
|
4
|
-
const isObject = (value) => value && typeof value === 'object';
|
|
5
|
-
// Loads a deep structure of urls (objects and arrays of urls)
|
|
6
|
-
// Returns an object with six key-value pairs containing the images (or image mip arrays)
|
|
7
|
-
// for each cube face
|
|
8
|
-
async function asyncDeepMap(tree, func, options = {}) {
|
|
9
|
-
return await mapSubtree(tree, func, options);
|
|
10
|
-
}
|
|
11
|
-
exports.asyncDeepMap = asyncDeepMap;
|
|
12
|
-
async function mapSubtree(object, func, options) {
|
|
13
|
-
if (Array.isArray(object)) {
|
|
14
|
-
return await mapArray(object, func, options);
|
|
15
|
-
}
|
|
16
|
-
if (isObject(object)) {
|
|
17
|
-
return await mapObject(object, func, options);
|
|
18
|
-
}
|
|
19
|
-
// TODO - ignore non-urls, non-arraybuffers?
|
|
20
|
-
const url = object;
|
|
21
|
-
return await func(url, options);
|
|
22
|
-
}
|
|
23
|
-
exports.mapSubtree = mapSubtree;
|
|
24
|
-
// HELPERS
|
|
25
|
-
async function mapObject(object, func, options) {
|
|
26
|
-
const promises = [];
|
|
27
|
-
const values = {};
|
|
28
|
-
for (const key in object) {
|
|
29
|
-
const url = object[key];
|
|
30
|
-
const promise = mapSubtree(url, func, options).then((value) => {
|
|
31
|
-
values[key] = value;
|
|
32
|
-
});
|
|
33
|
-
promises.push(promise);
|
|
34
|
-
}
|
|
35
|
-
await Promise.all(promises);
|
|
36
|
-
return values;
|
|
37
|
-
}
|
|
38
|
-
async function mapArray(urlArray, func, options = {}) {
|
|
39
|
-
const promises = urlArray.map((url) => mapSubtree(url, func, options));
|
|
40
|
-
return await Promise.all(promises);
|
|
41
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.shallowLoad = exports.deepLoad = void 0;
|
|
4
|
-
// loaders.gl, MIT license
|
|
5
|
-
const async_deep_map_1 = require("./async-deep-map");
|
|
6
|
-
async function deepLoad(urlTree, load, options) {
|
|
7
|
-
return await (0, async_deep_map_1.asyncDeepMap)(urlTree, (url) => shallowLoad(url, load, options));
|
|
8
|
-
}
|
|
9
|
-
exports.deepLoad = deepLoad;
|
|
10
|
-
async function shallowLoad(url, load, options) {
|
|
11
|
-
const response = await fetch(url, options.fetch);
|
|
12
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
13
|
-
return await load(arrayBuffer, options);
|
|
14
|
-
}
|
|
15
|
-
exports.shallowLoad = shallowLoad;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateUrl = void 0;
|
|
4
|
-
// loaders.gl, MIT license
|
|
5
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
6
|
-
// Generate a url by calling getUrl with mix of options, applying options.baseUrl
|
|
7
|
-
function generateUrl(getUrl, options, urlOptions) {
|
|
8
|
-
// Get url
|
|
9
|
-
let url = typeof getUrl === 'function' ? getUrl({ ...options, ...urlOptions }) : getUrl;
|
|
10
|
-
// Apply options.baseUrl
|
|
11
|
-
const baseUrl = options.baseUrl;
|
|
12
|
-
if (baseUrl) {
|
|
13
|
-
url = baseUrl[baseUrl.length - 1] === '/' ? `${baseUrl}${url}` : `${baseUrl}/${url}`;
|
|
14
|
-
}
|
|
15
|
-
return (0, loader_utils_1.resolvePath)(url);
|
|
16
|
-
}
|
|
17
|
-
exports.generateUrl = generateUrl;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getImageArrayUrls = exports.loadImageTextureArray = void 0;
|
|
4
|
-
// loaders.gl, MIT license
|
|
5
|
-
const images_1 = require("@loaders.gl/images");
|
|
6
|
-
const load_image_1 = require("./load-image");
|
|
7
|
-
const deep_load_1 = require("./deep-load");
|
|
8
|
-
async function loadImageTextureArray(count, getUrl, options = {}) {
|
|
9
|
-
const imageUrls = await getImageArrayUrls(count, getUrl, options);
|
|
10
|
-
return await (0, deep_load_1.deepLoad)(imageUrls, images_1.ImageLoader.parse, options);
|
|
11
|
-
}
|
|
12
|
-
exports.loadImageTextureArray = loadImageTextureArray;
|
|
13
|
-
async function getImageArrayUrls(count, getUrl, options = {}) {
|
|
14
|
-
const promises = [];
|
|
15
|
-
for (let index = 0; index < count; index++) {
|
|
16
|
-
const promise = (0, load_image_1.getImageUrls)(getUrl, options, { index });
|
|
17
|
-
promises.push(promise);
|
|
18
|
-
}
|
|
19
|
-
return await Promise.all(promises);
|
|
20
|
-
}
|
|
21
|
-
exports.getImageArrayUrls = getImageArrayUrls;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadImageTextureCube = exports.getImageCubeUrls = void 0;
|
|
4
|
-
// loaders.gl, MIT license
|
|
5
|
-
const images_1 = require("@loaders.gl/images");
|
|
6
|
-
const load_image_1 = require("./load-image");
|
|
7
|
-
const deep_load_1 = require("./deep-load");
|
|
8
|
-
// Returned map will be have keys corresponding to GL cubemap constants
|
|
9
|
-
const GL_TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515;
|
|
10
|
-
const GL_TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516;
|
|
11
|
-
const GL_TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517;
|
|
12
|
-
const GL_TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518;
|
|
13
|
-
const GL_TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519;
|
|
14
|
-
const GL_TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851a;
|
|
15
|
-
const CUBE_FACES = [
|
|
16
|
-
{ face: GL_TEXTURE_CUBE_MAP_POSITIVE_X, direction: 'right', axis: 'x', sign: 'positive' },
|
|
17
|
-
{ face: GL_TEXTURE_CUBE_MAP_NEGATIVE_X, direction: 'left', axis: 'x', sign: 'negative' },
|
|
18
|
-
{ face: GL_TEXTURE_CUBE_MAP_POSITIVE_Y, direction: 'top', axis: 'y', sign: 'positive' },
|
|
19
|
-
{ face: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, direction: 'bottom', axis: 'y', sign: 'negative' },
|
|
20
|
-
{ face: GL_TEXTURE_CUBE_MAP_POSITIVE_Z, direction: 'front', axis: 'z', sign: 'positive' },
|
|
21
|
-
{ face: GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, direction: 'back', axis: 'z', sign: 'negative' }
|
|
22
|
-
];
|
|
23
|
-
// Returns an object with six key-value pairs containing the urls (or url mip arrays)
|
|
24
|
-
// for each cube face
|
|
25
|
-
async function getImageCubeUrls(getUrl, options) {
|
|
26
|
-
// Calculate URLs
|
|
27
|
-
const urls = {};
|
|
28
|
-
const promises = [];
|
|
29
|
-
let index = 0;
|
|
30
|
-
for (let i = 0; i < CUBE_FACES.length; ++i) {
|
|
31
|
-
const face = CUBE_FACES[index];
|
|
32
|
-
const promise = (0, load_image_1.getImageUrls)(getUrl, options, { ...face, index: index++ }).then((url) => {
|
|
33
|
-
urls[face.face] = url;
|
|
34
|
-
});
|
|
35
|
-
promises.push(promise);
|
|
36
|
-
}
|
|
37
|
-
await Promise.all(promises);
|
|
38
|
-
return urls;
|
|
39
|
-
}
|
|
40
|
-
exports.getImageCubeUrls = getImageCubeUrls;
|
|
41
|
-
// Returns an object with six key-value pairs containing the images (or image mip arrays)
|
|
42
|
-
// for each cube face
|
|
43
|
-
async function loadImageTextureCube(getUrl, options = {}) {
|
|
44
|
-
const urls = await getImageCubeUrls(getUrl, options);
|
|
45
|
-
return (await (0, deep_load_1.deepLoad)(urls, images_1.ImageLoader.parse, options));
|
|
46
|
-
}
|
|
47
|
-
exports.loadImageTextureCube = loadImageTextureCube;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMipLevels = exports.getImageUrls = exports.loadImageTexture = void 0;
|
|
4
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
-
const images_1 = require("@loaders.gl/images");
|
|
6
|
-
const generate_url_1 = require("./generate-url");
|
|
7
|
-
const deep_load_1 = require("./deep-load");
|
|
8
|
-
async function loadImageTexture(getUrl, options = {}) {
|
|
9
|
-
const imageUrls = await getImageUrls(getUrl, options);
|
|
10
|
-
return await (0, deep_load_1.deepLoad)(imageUrls, images_1.ImageLoader.parse, options);
|
|
11
|
-
}
|
|
12
|
-
exports.loadImageTexture = loadImageTexture;
|
|
13
|
-
async function getImageUrls(getUrl, options, urlOptions = {}) {
|
|
14
|
-
const mipLevels = (options && options.image && options.image.mipLevels) || 0;
|
|
15
|
-
return mipLevels !== 0
|
|
16
|
-
? await getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions)
|
|
17
|
-
: (0, generate_url_1.generateUrl)(getUrl, options, urlOptions);
|
|
18
|
-
}
|
|
19
|
-
exports.getImageUrls = getImageUrls;
|
|
20
|
-
async function getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions) {
|
|
21
|
-
const urls = [];
|
|
22
|
-
// If no mip levels supplied, we need to load the level 0 image and calculate based on size
|
|
23
|
-
if (mipLevels === 'auto') {
|
|
24
|
-
const url = (0, generate_url_1.generateUrl)(getUrl, options, { ...urlOptions, lod: 0 });
|
|
25
|
-
const image = await (0, deep_load_1.shallowLoad)(url, images_1.ImageLoader.parse, options);
|
|
26
|
-
const { width, height } = (0, images_1.getImageSize)(image);
|
|
27
|
-
mipLevels = getMipLevels({ width, height });
|
|
28
|
-
// TODO - push image and make `deepLoad` pass through non-url values, avoid loading twice?
|
|
29
|
-
urls.push(url);
|
|
30
|
-
}
|
|
31
|
-
// We now know how many mipLevels we need, remaining image urls can now be constructed
|
|
32
|
-
(0, loader_utils_1.assert)(mipLevels > 0);
|
|
33
|
-
for (let mipLevel = urls.length; mipLevel < mipLevels; ++mipLevel) {
|
|
34
|
-
const url = (0, generate_url_1.generateUrl)(getUrl, options, { ...urlOptions, lod: mipLevel });
|
|
35
|
-
urls.push(url);
|
|
36
|
-
}
|
|
37
|
-
return urls;
|
|
38
|
-
}
|
|
39
|
-
// Calculates number of mipmaps based on texture size (log2)
|
|
40
|
-
function getMipLevels(size) {
|
|
41
|
-
return 1 + Math.floor(Math.log2(Math.max(size.width, size.height)));
|
|
42
|
-
}
|
|
43
|
-
exports.getMipLevels = getMipLevels;
|