itowns 2.44.3-next.9 → 2.45.1-next.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/README.md +3 -129
- package/examples/3dtiles_loader.html +20 -6
- package/examples/config.json +1 -0
- package/examples/copc_simple_loader.html +15 -5
- package/examples/effects_stereo.html +2 -2
- package/examples/entwine_3d_loader.html +3 -1
- package/examples/entwine_simple_loader.html +1 -1
- package/examples/images/itowns_logo.svg +123 -0
- package/examples/js/plugins/COGParser.js +1 -1
- package/examples/jsm/OGC3DTilesHelper.js +6 -1
- package/examples/layers/JSONLayers/GeoidMNT.json +3 -1
- package/examples/misc_collada.html +2 -2
- package/examples/source_file_geojson_3d.html +0 -1
- package/examples/source_file_kml_raster_usgs.html +0 -1
- package/examples/source_stream_wfs_raster.html +0 -7
- package/examples/vector_tile_mapbox_raster.html +91 -0
- package/examples/view_3d_map_webxr.html +3 -1
- package/examples/view_multi_25d.html +2 -2
- package/package.json +21 -75
- package/CODING.md +0 -120
- package/CONTRIBUTING.md +0 -150
- package/CONTRIBUTORS.md +0 -55
- package/LICENSE.md +0 -44
- package/changelog.md +0 -1361
- package/dist/455.js +0 -2
- package/dist/455.js.map +0 -1
- package/dist/debug.js +0 -3
- package/dist/debug.js.LICENSE.txt +0 -13
- package/dist/debug.js.map +0 -1
- package/dist/itowns.js +0 -3
- package/dist/itowns.js.LICENSE.txt +0 -7
- package/dist/itowns.js.map +0 -1
- package/dist/itowns_lasparser.js +0 -2
- package/dist/itowns_lasparser.js.map +0 -1
- package/dist/itowns_lasworker.js +0 -2
- package/dist/itowns_lasworker.js.map +0 -1
- package/dist/itowns_potree2worker.js +0 -2
- package/dist/itowns_potree2worker.js.map +0 -1
- package/dist/itowns_widgets.js +0 -2
- package/dist/itowns_widgets.js.map +0 -1
- package/examples/.eslintrc.cjs +0 -35
- package/examples/jsm/.eslintrc.cjs +0 -38
- package/lib/Controls/FirstPersonControls.js +0 -308
- package/lib/Controls/FlyControls.js +0 -175
- package/lib/Controls/GlobeControls.js +0 -1162
- package/lib/Controls/PlanarControls.js +0 -1025
- package/lib/Controls/StateControl.js +0 -429
- package/lib/Controls/StreetControls.js +0 -392
- package/lib/Converter/Feature2Mesh.js +0 -615
- package/lib/Converter/Feature2Texture.js +0 -170
- package/lib/Converter/convertToTile.js +0 -75
- package/lib/Converter/textureConverter.js +0 -44
- package/lib/Core/3DTiles/C3DTBatchTable.js +0 -131
- package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +0 -96
- package/lib/Core/3DTiles/C3DTBoundingVolume.js +0 -157
- package/lib/Core/3DTiles/C3DTExtensions.js +0 -97
- package/lib/Core/3DTiles/C3DTFeature.js +0 -110
- package/lib/Core/3DTiles/C3DTilesEnums.js +0 -20
- package/lib/Core/3DTiles/C3DTileset.js +0 -99
- package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +0 -100
- package/lib/Core/AnimationPlayer.js +0 -142
- package/lib/Core/CopcNode.js +0 -174
- package/lib/Core/Deprecated/Undeprecator.js +0 -75
- package/lib/Core/EntwinePointTileNode.js +0 -126
- package/lib/Core/Feature.js +0 -490
- package/lib/Core/Geographic/CoordStars.js +0 -80
- package/lib/Core/Geographic/Coordinates.js +0 -320
- package/lib/Core/Geographic/Crs.js +0 -175
- package/lib/Core/Geographic/Extent.js +0 -534
- package/lib/Core/Geographic/GeoidGrid.js +0 -109
- package/lib/Core/Label.js +0 -222
- package/lib/Core/MainLoop.js +0 -211
- package/lib/Core/Math/Ellipsoid.js +0 -144
- package/lib/Core/Picking.js +0 -255
- package/lib/Core/PointCloudNode.js +0 -42
- package/lib/Core/Potree2Node.js +0 -206
- package/lib/Core/Potree2PointAttributes.js +0 -139
- package/lib/Core/PotreeNode.js +0 -101
- package/lib/Core/Prefab/Globe/Atmosphere.js +0 -299
- package/lib/Core/Prefab/Globe/BuilderEllipsoidTile.js +0 -110
- package/lib/Core/Prefab/Globe/GlobeLayer.js +0 -145
- package/lib/Core/Prefab/Globe/SkyShader.js +0 -78
- package/lib/Core/Prefab/GlobeView.js +0 -161
- package/lib/Core/Prefab/Planar/PlanarLayer.js +0 -53
- package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +0 -72
- package/lib/Core/Prefab/PlanarView.js +0 -62
- package/lib/Core/Prefab/TileBuilder.js +0 -80
- package/lib/Core/Prefab/computeBufferTileGeometry.js +0 -183
- package/lib/Core/Scheduler/Cache.js +0 -256
- package/lib/Core/Scheduler/CancelledCommandException.js +0 -15
- package/lib/Core/Scheduler/Scheduler.js +0 -294
- package/lib/Core/Style.js +0 -1121
- package/lib/Core/System/Capabilities.js +0 -63
- package/lib/Core/Tile/Tile.js +0 -219
- package/lib/Core/Tile/TileGrid.js +0 -46
- package/lib/Core/TileGeometry.js +0 -40
- package/lib/Core/TileMesh.js +0 -109
- package/lib/Core/View.js +0 -1109
- package/lib/Layer/C3DTilesLayer.js +0 -456
- package/lib/Layer/ColorLayer.js +0 -128
- package/lib/Layer/CopcLayer.js +0 -58
- package/lib/Layer/ElevationLayer.js +0 -107
- package/lib/Layer/EntwinePointTileLayer.js +0 -64
- package/lib/Layer/FeatureGeometryLayer.js +0 -63
- package/lib/Layer/GeoidLayer.js +0 -80
- package/lib/Layer/GeometryLayer.js +0 -202
- package/lib/Layer/InfoLayer.js +0 -64
- package/lib/Layer/LabelLayer.js +0 -456
- package/lib/Layer/Layer.js +0 -304
- package/lib/Layer/LayerUpdateState.js +0 -89
- package/lib/Layer/LayerUpdateStrategy.js +0 -80
- package/lib/Layer/OGC3DTilesLayer.js +0 -412
- package/lib/Layer/OrientedImageLayer.js +0 -222
- package/lib/Layer/PointCloudLayer.js +0 -359
- package/lib/Layer/Potree2Layer.js +0 -164
- package/lib/Layer/PotreeLayer.js +0 -65
- package/lib/Layer/RasterLayer.js +0 -27
- package/lib/Layer/ReferencingLayerProperties.js +0 -62
- package/lib/Layer/TiledGeometryLayer.js +0 -403
- package/lib/Loader/LASLoader.js +0 -193
- package/lib/Loader/Potree2BrotliLoader.js +0 -261
- package/lib/Loader/Potree2Loader.js +0 -207
- package/lib/Main.js +0 -115
- package/lib/MainBundle.js +0 -4
- package/lib/Parser/B3dmParser.js +0 -174
- package/lib/Parser/CameraCalibrationParser.js +0 -94
- package/lib/Parser/GDFParser.js +0 -72
- package/lib/Parser/GTXParser.js +0 -75
- package/lib/Parser/GeoJsonParser.js +0 -212
- package/lib/Parser/GpxParser.js +0 -25
- package/lib/Parser/ISGParser.js +0 -71
- package/lib/Parser/KMLParser.js +0 -25
- package/lib/Parser/LASParser.js +0 -137
- package/lib/Parser/MapBoxUrlParser.js +0 -83
- package/lib/Parser/PntsParser.js +0 -131
- package/lib/Parser/Potree2BinParser.js +0 -92
- package/lib/Parser/PotreeBinParser.js +0 -106
- package/lib/Parser/PotreeCinParser.js +0 -29
- package/lib/Parser/ShapefileParser.js +0 -78
- package/lib/Parser/VectorTileParser.js +0 -202
- package/lib/Parser/XbilParser.js +0 -119
- package/lib/Parser/deprecated/LegacyGLTFLoader.js +0 -1386
- package/lib/Parser/iGLTFLoader.js +0 -168
- package/lib/Process/3dTilesProcessing.js +0 -304
- package/lib/Process/FeatureProcessing.js +0 -76
- package/lib/Process/LayeredMaterialNodeProcessing.js +0 -221
- package/lib/Process/ObjectRemovalHelper.js +0 -97
- package/lib/Process/handlerNodeError.js +0 -23
- package/lib/Provider/3dTilesProvider.js +0 -149
- package/lib/Provider/DataSourceProvider.js +0 -8
- package/lib/Provider/Fetcher.js +0 -229
- package/lib/Provider/PointCloudProvider.js +0 -45
- package/lib/Provider/TileProvider.js +0 -16
- package/lib/Provider/URLBuilder.js +0 -116
- package/lib/Renderer/Camera.js +0 -281
- package/lib/Renderer/Color.js +0 -56
- package/lib/Renderer/ColorLayersOrdering.js +0 -115
- package/lib/Renderer/CommonMaterial.js +0 -31
- package/lib/Renderer/Label2DRenderer.js +0 -190
- package/lib/Renderer/LayeredMaterial.js +0 -243
- package/lib/Renderer/OBB.js +0 -153
- package/lib/Renderer/OrientedImageCamera.js +0 -118
- package/lib/Renderer/OrientedImageMaterial.js +0 -167
- package/lib/Renderer/PointsMaterial.js +0 -485
- package/lib/Renderer/RasterTile.js +0 -209
- package/lib/Renderer/RenderMode.js +0 -31
- package/lib/Renderer/Shader/ShaderChunk.js +0 -160
- package/lib/Renderer/Shader/ShaderUtils.js +0 -47
- package/lib/Renderer/SphereHelper.js +0 -23
- package/lib/Renderer/WebXR.js +0 -51
- package/lib/Renderer/c3DEngine.js +0 -214
- package/lib/Source/C3DTilesGoogleSource.js +0 -74
- package/lib/Source/C3DTilesIonSource.js +0 -54
- package/lib/Source/C3DTilesSource.js +0 -30
- package/lib/Source/CopcSource.js +0 -115
- package/lib/Source/EntwinePointTileSource.js +0 -62
- package/lib/Source/FileSource.js +0 -189
- package/lib/Source/OGC3DTilesGoogleSource.js +0 -29
- package/lib/Source/OGC3DTilesIonSource.js +0 -34
- package/lib/Source/OGC3DTilesSource.js +0 -21
- package/lib/Source/OrientedImageSource.js +0 -59
- package/lib/Source/Potree2Source.js +0 -167
- package/lib/Source/PotreeSource.js +0 -82
- package/lib/Source/Source.js +0 -223
- package/lib/Source/TMSSource.js +0 -145
- package/lib/Source/VectorTilesSource.js +0 -178
- package/lib/Source/WFSSource.js +0 -168
- package/lib/Source/WMSSource.js +0 -133
- package/lib/Source/WMTSSource.js +0 -86
- package/lib/ThreeExtended/capabilities/WebGL.js +0 -69
- package/lib/ThreeExtended/libs/ktx-parse.module.js +0 -470
- package/lib/ThreeExtended/libs/zstddec.module.js +0 -29
- package/lib/ThreeExtended/loaders/DDSLoader.js +0 -200
- package/lib/ThreeExtended/loaders/DRACOLoader.js +0 -399
- package/lib/ThreeExtended/loaders/GLTFLoader.js +0 -2876
- package/lib/ThreeExtended/loaders/KTX2Loader.js +0 -625
- package/lib/ThreeExtended/utils/BufferGeometryUtils.js +0 -846
- package/lib/ThreeExtended/utils/WorkerPool.js +0 -70
- package/lib/Utils/CameraUtils.js +0 -555
- package/lib/Utils/DEMUtils.js +0 -350
- package/lib/Utils/FeaturesUtils.js +0 -156
- package/lib/Utils/Gradients.js +0 -16
- package/lib/Utils/OrientationUtils.js +0 -457
- package/lib/Utils/ThreeUtils.js +0 -115
- package/lib/Utils/gui/C3DTilesStyle.js +0 -215
- package/lib/Utils/gui/Main.js +0 -7
- package/lib/Utils/gui/Minimap.js +0 -154
- package/lib/Utils/gui/Navigation.js +0 -245
- package/lib/Utils/gui/Scale.js +0 -107
- package/lib/Utils/gui/Searchbar.js +0 -234
- package/lib/Utils/gui/Widget.js +0 -80
- package/lib/Utils/placeObjectOnGround.js +0 -137
- package/lib/Worker/LASLoaderWorker.js +0 -19
- package/lib/Worker/Potree2Worker.js +0 -21
|
@@ -1,625 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Loader for KTX 2.0 GPU Texture containers.
|
|
3
|
-
*
|
|
4
|
-
* KTX 2.0 is a container format for various GPU texture formats. The loader
|
|
5
|
-
* supports Basis Universal GPU textures, which can be quickly transcoded to
|
|
6
|
-
* a wide variety of GPU texture compression formats, as well as some
|
|
7
|
-
* uncompressed DataTexture and Data3DTexture formats.
|
|
8
|
-
*
|
|
9
|
-
* References:
|
|
10
|
-
* - KTX: http://github.khronos.org/KTX-Specification/
|
|
11
|
-
* - DFD: https://www.khronos.org/registry/DataFormat/specs/1.3/dataformat.1.3.html#basicdescriptor
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { CompressedTexture, CompressedArrayTexture, CompressedCubeTexture, Data3DTexture, DataTexture, DisplayP3ColorSpace, FileLoader, FloatType, HalfFloatType, NoColorSpace, LinearFilter, LinearMipmapLinearFilter, LinearDisplayP3ColorSpace, LinearSRGBColorSpace, Loader, RedFormat, RGB_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_4BPPV1_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_6x6_Format, RGBA_BPTC_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT5_Format, RGBA_S3TC_DXT1_Format, RGBAFormat, RGFormat, SRGBColorSpace, UnsignedByteType } from 'three';
|
|
15
|
-
import { WorkerPool } from "../utils/WorkerPool.js";
|
|
16
|
-
import { read, KHR_DF_FLAG_ALPHA_PREMULTIPLIED, KHR_DF_TRANSFER_SRGB, KHR_SUPERCOMPRESSION_NONE, KHR_SUPERCOMPRESSION_ZSTD, VK_FORMAT_UNDEFINED, VK_FORMAT_R16_SFLOAT, VK_FORMAT_R16G16_SFLOAT, VK_FORMAT_R16G16B16A16_SFLOAT, VK_FORMAT_R32_SFLOAT, VK_FORMAT_R32G32_SFLOAT, VK_FORMAT_R32G32B32A32_SFLOAT, VK_FORMAT_R8_SRGB, VK_FORMAT_R8_UNORM, VK_FORMAT_R8G8_SRGB, VK_FORMAT_R8G8_UNORM, VK_FORMAT_R8G8B8A8_SRGB, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_ASTC_6x6_SRGB_BLOCK, VK_FORMAT_ASTC_6x6_UNORM_BLOCK, KHR_DF_PRIMARIES_UNSPECIFIED, KHR_DF_PRIMARIES_BT709, KHR_DF_PRIMARIES_DISPLAYP3 } from "../libs/ktx-parse.module.js";
|
|
17
|
-
import { ZSTDDecoder } from "../libs/zstddec.module.js";
|
|
18
|
-
const _taskCache = new WeakMap();
|
|
19
|
-
let _activeLoaders = 0;
|
|
20
|
-
let _zstd;
|
|
21
|
-
class KTX2Loader extends Loader {
|
|
22
|
-
constructor(manager) {
|
|
23
|
-
super(manager);
|
|
24
|
-
this.transcoderPath = '';
|
|
25
|
-
this.transcoderBinary = null;
|
|
26
|
-
this.transcoderPending = null;
|
|
27
|
-
this.workerPool = new WorkerPool();
|
|
28
|
-
this.workerSourceURL = '';
|
|
29
|
-
this.workerConfig = null;
|
|
30
|
-
if (typeof MSC_TRANSCODER !== 'undefined') {
|
|
31
|
-
console.warn('THREE.KTX2Loader: Please update to latest "basis_transcoder".' + ' "msc_basis_transcoder" is no longer supported in three.js r125+.');
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
setTranscoderPath(path) {
|
|
35
|
-
this.transcoderPath = path;
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
setWorkerLimit(num) {
|
|
39
|
-
this.workerPool.setWorkerLimit(num);
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
async detectSupportAsync(renderer) {
|
|
43
|
-
this.workerConfig = {
|
|
44
|
-
astcSupported: await renderer.hasFeatureAsync('texture-compression-astc'),
|
|
45
|
-
etc1Supported: await renderer.hasFeatureAsync('texture-compression-etc1'),
|
|
46
|
-
etc2Supported: await renderer.hasFeatureAsync('texture-compression-etc2'),
|
|
47
|
-
dxtSupported: await renderer.hasFeatureAsync('texture-compression-bc'),
|
|
48
|
-
bptcSupported: await renderer.hasFeatureAsync('texture-compression-bptc'),
|
|
49
|
-
pvrtcSupported: await renderer.hasFeatureAsync('texture-compression-pvrtc')
|
|
50
|
-
};
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
detectSupport(renderer) {
|
|
54
|
-
if (renderer.isWebGPURenderer === true) {
|
|
55
|
-
this.workerConfig = {
|
|
56
|
-
astcSupported: renderer.hasFeature('texture-compression-astc'),
|
|
57
|
-
etc1Supported: renderer.hasFeature('texture-compression-etc1'),
|
|
58
|
-
etc2Supported: renderer.hasFeature('texture-compression-etc2'),
|
|
59
|
-
dxtSupported: renderer.hasFeature('texture-compression-bc'),
|
|
60
|
-
bptcSupported: renderer.hasFeature('texture-compression-bptc'),
|
|
61
|
-
pvrtcSupported: renderer.hasFeature('texture-compression-pvrtc')
|
|
62
|
-
};
|
|
63
|
-
} else {
|
|
64
|
-
this.workerConfig = {
|
|
65
|
-
astcSupported: renderer.extensions.has('WEBGL_compressed_texture_astc'),
|
|
66
|
-
etc1Supported: renderer.extensions.has('WEBGL_compressed_texture_etc1'),
|
|
67
|
-
etc2Supported: renderer.extensions.has('WEBGL_compressed_texture_etc'),
|
|
68
|
-
dxtSupported: renderer.extensions.has('WEBGL_compressed_texture_s3tc'),
|
|
69
|
-
bptcSupported: renderer.extensions.has('EXT_texture_compression_bptc'),
|
|
70
|
-
pvrtcSupported: renderer.extensions.has('WEBGL_compressed_texture_pvrtc') || renderer.extensions.has('WEBKIT_WEBGL_compressed_texture_pvrtc')
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
init() {
|
|
76
|
-
if (!this.transcoderPending) {
|
|
77
|
-
// Load transcoder wrapper.
|
|
78
|
-
const jsLoader = new FileLoader(this.manager);
|
|
79
|
-
jsLoader.setPath(this.transcoderPath);
|
|
80
|
-
jsLoader.setWithCredentials(this.withCredentials);
|
|
81
|
-
const jsContent = jsLoader.loadAsync('basis_transcoder.js');
|
|
82
|
-
|
|
83
|
-
// Load transcoder WASM binary.
|
|
84
|
-
const binaryLoader = new FileLoader(this.manager);
|
|
85
|
-
binaryLoader.setPath(this.transcoderPath);
|
|
86
|
-
binaryLoader.setResponseType('arraybuffer');
|
|
87
|
-
binaryLoader.setWithCredentials(this.withCredentials);
|
|
88
|
-
const binaryContent = binaryLoader.loadAsync('basis_transcoder.wasm');
|
|
89
|
-
this.transcoderPending = Promise.all([jsContent, binaryContent]).then(_ref => {
|
|
90
|
-
let [jsContent, binaryContent] = _ref;
|
|
91
|
-
const fn = KTX2Loader.BasisWorker.toString();
|
|
92
|
-
const body = ['/* constants */', 'let _EngineFormat = ' + JSON.stringify(KTX2Loader.EngineFormat), 'let _TranscoderFormat = ' + JSON.stringify(KTX2Loader.TranscoderFormat), 'let _BasisFormat = ' + JSON.stringify(KTX2Loader.BasisFormat), '/* basis_transcoder.js */', jsContent, '/* worker */', fn.substring(fn.indexOf('{') + 1, fn.lastIndexOf('}'))].join('\n');
|
|
93
|
-
this.workerSourceURL = URL.createObjectURL(new Blob([body]));
|
|
94
|
-
this.transcoderBinary = binaryContent;
|
|
95
|
-
this.workerPool.setWorkerCreator(() => {
|
|
96
|
-
const worker = new Worker(this.workerSourceURL);
|
|
97
|
-
const transcoderBinary = this.transcoderBinary.slice(0);
|
|
98
|
-
worker.postMessage({
|
|
99
|
-
type: 'init',
|
|
100
|
-
config: this.workerConfig,
|
|
101
|
-
transcoderBinary
|
|
102
|
-
}, [transcoderBinary]);
|
|
103
|
-
return worker;
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
if (_activeLoaders > 0) {
|
|
107
|
-
// Each instance loads a transcoder and allocates workers, increasing network and memory cost.
|
|
108
|
-
|
|
109
|
-
console.warn('THREE.KTX2Loader: Multiple active KTX2 loaders may cause performance issues.' + ' Use a single KTX2Loader instance, or call .dispose() on old instances.');
|
|
110
|
-
}
|
|
111
|
-
_activeLoaders++;
|
|
112
|
-
}
|
|
113
|
-
return this.transcoderPending;
|
|
114
|
-
}
|
|
115
|
-
load(url, onLoad, onProgress, onError) {
|
|
116
|
-
if (this.workerConfig === null) {
|
|
117
|
-
throw new Error('THREE.KTX2Loader: Missing initialization with `.detectSupport( renderer )`.');
|
|
118
|
-
}
|
|
119
|
-
const loader = new FileLoader(this.manager);
|
|
120
|
-
loader.setResponseType('arraybuffer');
|
|
121
|
-
loader.setWithCredentials(this.withCredentials);
|
|
122
|
-
loader.load(url, buffer => {
|
|
123
|
-
this.parse(buffer, onLoad, onError);
|
|
124
|
-
}, onProgress, onError);
|
|
125
|
-
}
|
|
126
|
-
parse(buffer, onLoad, onError) {
|
|
127
|
-
if (this.workerConfig === null) {
|
|
128
|
-
throw new Error('THREE.KTX2Loader: Missing initialization with `.detectSupport( renderer )`.');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Check for an existing task using this buffer. A transferred buffer cannot be transferred
|
|
132
|
-
// again from this thread.
|
|
133
|
-
if (_taskCache.has(buffer)) {
|
|
134
|
-
const cachedTask = _taskCache.get(buffer);
|
|
135
|
-
return cachedTask.promise.then(onLoad).catch(onError);
|
|
136
|
-
}
|
|
137
|
-
this._createTexture(buffer).then(texture => onLoad ? onLoad(texture) : null).catch(onError);
|
|
138
|
-
}
|
|
139
|
-
_createTextureFrom(transcodeResult, container) {
|
|
140
|
-
const {
|
|
141
|
-
faces,
|
|
142
|
-
width,
|
|
143
|
-
height,
|
|
144
|
-
format,
|
|
145
|
-
type,
|
|
146
|
-
error,
|
|
147
|
-
dfdFlags
|
|
148
|
-
} = transcodeResult;
|
|
149
|
-
if (type === 'error') return Promise.reject(error);
|
|
150
|
-
let texture;
|
|
151
|
-
if (container.faceCount === 6) {
|
|
152
|
-
texture = new CompressedCubeTexture(faces, format, UnsignedByteType);
|
|
153
|
-
} else {
|
|
154
|
-
const mipmaps = faces[0].mipmaps;
|
|
155
|
-
texture = container.layerCount > 1 ? new CompressedArrayTexture(mipmaps, width, height, container.layerCount, format, UnsignedByteType) : new CompressedTexture(mipmaps, width, height, format, UnsignedByteType);
|
|
156
|
-
}
|
|
157
|
-
texture.minFilter = faces[0].mipmaps.length === 1 ? LinearFilter : LinearMipmapLinearFilter;
|
|
158
|
-
texture.magFilter = LinearFilter;
|
|
159
|
-
texture.generateMipmaps = false;
|
|
160
|
-
texture.needsUpdate = true;
|
|
161
|
-
texture.colorSpace = parseColorSpace(container);
|
|
162
|
-
texture.premultiplyAlpha = !!(dfdFlags & KHR_DF_FLAG_ALPHA_PREMULTIPLIED);
|
|
163
|
-
return texture;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* @param {ArrayBuffer} buffer
|
|
168
|
-
* @param {object?} config
|
|
169
|
-
* @return {Promise<CompressedTexture|CompressedArrayTexture|DataTexture|Data3DTexture>}
|
|
170
|
-
*/
|
|
171
|
-
async _createTexture(buffer) {
|
|
172
|
-
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
173
|
-
const container = read(new Uint8Array(buffer));
|
|
174
|
-
if (container.vkFormat !== VK_FORMAT_UNDEFINED) {
|
|
175
|
-
return createRawTexture(container);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
//
|
|
179
|
-
|
|
180
|
-
const texturePending = this.init().then(() => {
|
|
181
|
-
return this.workerPool.postMessage({
|
|
182
|
-
type: 'transcode',
|
|
183
|
-
buffer,
|
|
184
|
-
taskConfig: config
|
|
185
|
-
}, [buffer]);
|
|
186
|
-
}).then(e => this._createTextureFrom(e.data, container));
|
|
187
|
-
|
|
188
|
-
// Cache the task result.
|
|
189
|
-
_taskCache.set(buffer, {
|
|
190
|
-
promise: texturePending
|
|
191
|
-
});
|
|
192
|
-
return texturePending;
|
|
193
|
-
}
|
|
194
|
-
dispose() {
|
|
195
|
-
this.workerPool.dispose();
|
|
196
|
-
if (this.workerSourceURL) URL.revokeObjectURL(this.workerSourceURL);
|
|
197
|
-
_activeLoaders--;
|
|
198
|
-
return this;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/* CONSTANTS */
|
|
203
|
-
|
|
204
|
-
KTX2Loader.BasisFormat = {
|
|
205
|
-
ETC1S: 0,
|
|
206
|
-
UASTC_4x4: 1
|
|
207
|
-
};
|
|
208
|
-
KTX2Loader.TranscoderFormat = {
|
|
209
|
-
ETC1: 0,
|
|
210
|
-
ETC2: 1,
|
|
211
|
-
BC1: 2,
|
|
212
|
-
BC3: 3,
|
|
213
|
-
BC4: 4,
|
|
214
|
-
BC5: 5,
|
|
215
|
-
BC7_M6_OPAQUE_ONLY: 6,
|
|
216
|
-
BC7_M5: 7,
|
|
217
|
-
PVRTC1_4_RGB: 8,
|
|
218
|
-
PVRTC1_4_RGBA: 9,
|
|
219
|
-
ASTC_4x4: 10,
|
|
220
|
-
ATC_RGB: 11,
|
|
221
|
-
ATC_RGBA_INTERPOLATED_ALPHA: 12,
|
|
222
|
-
RGBA32: 13,
|
|
223
|
-
RGB565: 14,
|
|
224
|
-
BGR565: 15,
|
|
225
|
-
RGBA4444: 16
|
|
226
|
-
};
|
|
227
|
-
KTX2Loader.EngineFormat = {
|
|
228
|
-
RGBAFormat: RGBAFormat,
|
|
229
|
-
RGBA_ASTC_4x4_Format: RGBA_ASTC_4x4_Format,
|
|
230
|
-
RGBA_BPTC_Format: RGBA_BPTC_Format,
|
|
231
|
-
RGBA_ETC2_EAC_Format: RGBA_ETC2_EAC_Format,
|
|
232
|
-
RGBA_PVRTC_4BPPV1_Format: RGBA_PVRTC_4BPPV1_Format,
|
|
233
|
-
RGBA_S3TC_DXT5_Format: RGBA_S3TC_DXT5_Format,
|
|
234
|
-
RGB_ETC1_Format: RGB_ETC1_Format,
|
|
235
|
-
RGB_ETC2_Format: RGB_ETC2_Format,
|
|
236
|
-
RGB_PVRTC_4BPPV1_Format: RGB_PVRTC_4BPPV1_Format,
|
|
237
|
-
RGBA_S3TC_DXT1_Format: RGBA_S3TC_DXT1_Format
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
/* WEB WORKER */
|
|
241
|
-
|
|
242
|
-
KTX2Loader.BasisWorker = function () {
|
|
243
|
-
let config;
|
|
244
|
-
let transcoderPending;
|
|
245
|
-
let BasisModule;
|
|
246
|
-
const EngineFormat = _EngineFormat; // eslint-disable-line no-undef
|
|
247
|
-
const TranscoderFormat = _TranscoderFormat; // eslint-disable-line no-undef
|
|
248
|
-
const BasisFormat = _BasisFormat; // eslint-disable-line no-undef
|
|
249
|
-
|
|
250
|
-
self.addEventListener('message', function (e) {
|
|
251
|
-
const message = e.data;
|
|
252
|
-
switch (message.type) {
|
|
253
|
-
case 'init':
|
|
254
|
-
config = message.config;
|
|
255
|
-
init(message.transcoderBinary);
|
|
256
|
-
break;
|
|
257
|
-
case 'transcode':
|
|
258
|
-
transcoderPending.then(() => {
|
|
259
|
-
try {
|
|
260
|
-
const {
|
|
261
|
-
faces,
|
|
262
|
-
buffers,
|
|
263
|
-
width,
|
|
264
|
-
height,
|
|
265
|
-
hasAlpha,
|
|
266
|
-
format,
|
|
267
|
-
dfdFlags
|
|
268
|
-
} = transcode(message.buffer);
|
|
269
|
-
self.postMessage({
|
|
270
|
-
type: 'transcode',
|
|
271
|
-
id: message.id,
|
|
272
|
-
faces,
|
|
273
|
-
width,
|
|
274
|
-
height,
|
|
275
|
-
hasAlpha,
|
|
276
|
-
format,
|
|
277
|
-
dfdFlags
|
|
278
|
-
}, buffers);
|
|
279
|
-
} catch (error) {
|
|
280
|
-
console.error(error);
|
|
281
|
-
self.postMessage({
|
|
282
|
-
type: 'error',
|
|
283
|
-
id: message.id,
|
|
284
|
-
error: error.message
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
break;
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
function init(wasmBinary) {
|
|
292
|
-
transcoderPending = new Promise(resolve => {
|
|
293
|
-
BasisModule = {
|
|
294
|
-
wasmBinary,
|
|
295
|
-
onRuntimeInitialized: resolve
|
|
296
|
-
};
|
|
297
|
-
BASIS(BasisModule); // eslint-disable-line no-undef
|
|
298
|
-
}).then(() => {
|
|
299
|
-
BasisModule.initializeBasis();
|
|
300
|
-
if (BasisModule.KTX2File === undefined) {
|
|
301
|
-
console.warn('THREE.KTX2Loader: Please update Basis Universal transcoder.');
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
function transcode(buffer) {
|
|
306
|
-
const ktx2File = new BasisModule.KTX2File(new Uint8Array(buffer));
|
|
307
|
-
function cleanup() {
|
|
308
|
-
ktx2File.close();
|
|
309
|
-
ktx2File.delete();
|
|
310
|
-
}
|
|
311
|
-
if (!ktx2File.isValid()) {
|
|
312
|
-
cleanup();
|
|
313
|
-
throw new Error('THREE.KTX2Loader: Invalid or unsupported .ktx2 file');
|
|
314
|
-
}
|
|
315
|
-
const basisFormat = ktx2File.isUASTC() ? BasisFormat.UASTC_4x4 : BasisFormat.ETC1S;
|
|
316
|
-
const width = ktx2File.getWidth();
|
|
317
|
-
const height = ktx2File.getHeight();
|
|
318
|
-
const layerCount = ktx2File.getLayers() || 1;
|
|
319
|
-
const levelCount = ktx2File.getLevels();
|
|
320
|
-
const faceCount = ktx2File.getFaces();
|
|
321
|
-
const hasAlpha = ktx2File.getHasAlpha();
|
|
322
|
-
const dfdFlags = ktx2File.getDFDFlags();
|
|
323
|
-
const {
|
|
324
|
-
transcoderFormat,
|
|
325
|
-
engineFormat
|
|
326
|
-
} = getTranscoderFormat(basisFormat, width, height, hasAlpha);
|
|
327
|
-
if (!width || !height || !levelCount) {
|
|
328
|
-
cleanup();
|
|
329
|
-
throw new Error('THREE.KTX2Loader: Invalid texture');
|
|
330
|
-
}
|
|
331
|
-
if (!ktx2File.startTranscoding()) {
|
|
332
|
-
cleanup();
|
|
333
|
-
throw new Error('THREE.KTX2Loader: .startTranscoding failed');
|
|
334
|
-
}
|
|
335
|
-
const faces = [];
|
|
336
|
-
const buffers = [];
|
|
337
|
-
for (let face = 0; face < faceCount; face++) {
|
|
338
|
-
const mipmaps = [];
|
|
339
|
-
for (let mip = 0; mip < levelCount; mip++) {
|
|
340
|
-
const layerMips = [];
|
|
341
|
-
let mipWidth, mipHeight;
|
|
342
|
-
for (let layer = 0; layer < layerCount; layer++) {
|
|
343
|
-
const levelInfo = ktx2File.getImageLevelInfo(mip, layer, face);
|
|
344
|
-
if (face === 0 && mip === 0 && layer === 0 && (levelInfo.origWidth % 4 !== 0 || levelInfo.origHeight % 4 !== 0)) {
|
|
345
|
-
console.warn('THREE.KTX2Loader: ETC1S and UASTC textures should use multiple-of-four dimensions.');
|
|
346
|
-
}
|
|
347
|
-
if (levelCount > 1) {
|
|
348
|
-
mipWidth = levelInfo.origWidth;
|
|
349
|
-
mipHeight = levelInfo.origHeight;
|
|
350
|
-
} else {
|
|
351
|
-
// Handles non-multiple-of-four dimensions in textures without mipmaps. Textures with
|
|
352
|
-
// mipmaps must use multiple-of-four dimensions, for some texture formats and APIs.
|
|
353
|
-
// See mrdoob/three.js#25908.
|
|
354
|
-
mipWidth = levelInfo.width;
|
|
355
|
-
mipHeight = levelInfo.height;
|
|
356
|
-
}
|
|
357
|
-
const dst = new Uint8Array(ktx2File.getImageTranscodedSizeInBytes(mip, layer, 0, transcoderFormat));
|
|
358
|
-
const status = ktx2File.transcodeImage(dst, mip, layer, face, transcoderFormat, 0, -1, -1);
|
|
359
|
-
if (!status) {
|
|
360
|
-
cleanup();
|
|
361
|
-
throw new Error('THREE.KTX2Loader: .transcodeImage failed.');
|
|
362
|
-
}
|
|
363
|
-
layerMips.push(dst);
|
|
364
|
-
}
|
|
365
|
-
const mipData = concat(layerMips);
|
|
366
|
-
mipmaps.push({
|
|
367
|
-
data: mipData,
|
|
368
|
-
width: mipWidth,
|
|
369
|
-
height: mipHeight
|
|
370
|
-
});
|
|
371
|
-
buffers.push(mipData.buffer);
|
|
372
|
-
}
|
|
373
|
-
faces.push({
|
|
374
|
-
mipmaps,
|
|
375
|
-
width,
|
|
376
|
-
height,
|
|
377
|
-
format: engineFormat
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
cleanup();
|
|
381
|
-
return {
|
|
382
|
-
faces,
|
|
383
|
-
buffers,
|
|
384
|
-
width,
|
|
385
|
-
height,
|
|
386
|
-
hasAlpha,
|
|
387
|
-
format: engineFormat,
|
|
388
|
-
dfdFlags
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
//
|
|
393
|
-
|
|
394
|
-
// Optimal choice of a transcoder target format depends on the Basis format (ETC1S or UASTC),
|
|
395
|
-
// device capabilities, and texture dimensions. The list below ranks the formats separately
|
|
396
|
-
// for ETC1S and UASTC.
|
|
397
|
-
//
|
|
398
|
-
// In some cases, transcoding UASTC to RGBA32 might be preferred for higher quality (at
|
|
399
|
-
// significant memory cost) compared to ETC1/2, BC1/3, and PVRTC. The transcoder currently
|
|
400
|
-
// chooses RGBA32 only as a last resort and does not expose that option to the caller.
|
|
401
|
-
const FORMAT_OPTIONS = [{
|
|
402
|
-
if: 'astcSupported',
|
|
403
|
-
basisFormat: [BasisFormat.UASTC_4x4],
|
|
404
|
-
transcoderFormat: [TranscoderFormat.ASTC_4x4, TranscoderFormat.ASTC_4x4],
|
|
405
|
-
engineFormat: [EngineFormat.RGBA_ASTC_4x4_Format, EngineFormat.RGBA_ASTC_4x4_Format],
|
|
406
|
-
priorityETC1S: Infinity,
|
|
407
|
-
priorityUASTC: 1,
|
|
408
|
-
needsPowerOfTwo: false
|
|
409
|
-
}, {
|
|
410
|
-
if: 'bptcSupported',
|
|
411
|
-
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
|
|
412
|
-
transcoderFormat: [TranscoderFormat.BC7_M5, TranscoderFormat.BC7_M5],
|
|
413
|
-
engineFormat: [EngineFormat.RGBA_BPTC_Format, EngineFormat.RGBA_BPTC_Format],
|
|
414
|
-
priorityETC1S: 3,
|
|
415
|
-
priorityUASTC: 2,
|
|
416
|
-
needsPowerOfTwo: false
|
|
417
|
-
}, {
|
|
418
|
-
if: 'dxtSupported',
|
|
419
|
-
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
|
|
420
|
-
transcoderFormat: [TranscoderFormat.BC1, TranscoderFormat.BC3],
|
|
421
|
-
engineFormat: [EngineFormat.RGBA_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format],
|
|
422
|
-
priorityETC1S: 4,
|
|
423
|
-
priorityUASTC: 5,
|
|
424
|
-
needsPowerOfTwo: false
|
|
425
|
-
}, {
|
|
426
|
-
if: 'etc2Supported',
|
|
427
|
-
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
|
|
428
|
-
transcoderFormat: [TranscoderFormat.ETC1, TranscoderFormat.ETC2],
|
|
429
|
-
engineFormat: [EngineFormat.RGB_ETC2_Format, EngineFormat.RGBA_ETC2_EAC_Format],
|
|
430
|
-
priorityETC1S: 1,
|
|
431
|
-
priorityUASTC: 3,
|
|
432
|
-
needsPowerOfTwo: false
|
|
433
|
-
}, {
|
|
434
|
-
if: 'etc1Supported',
|
|
435
|
-
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
|
|
436
|
-
transcoderFormat: [TranscoderFormat.ETC1],
|
|
437
|
-
engineFormat: [EngineFormat.RGB_ETC1_Format],
|
|
438
|
-
priorityETC1S: 2,
|
|
439
|
-
priorityUASTC: 4,
|
|
440
|
-
needsPowerOfTwo: false
|
|
441
|
-
}, {
|
|
442
|
-
if: 'pvrtcSupported',
|
|
443
|
-
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
|
|
444
|
-
transcoderFormat: [TranscoderFormat.PVRTC1_4_RGB, TranscoderFormat.PVRTC1_4_RGBA],
|
|
445
|
-
engineFormat: [EngineFormat.RGB_PVRTC_4BPPV1_Format, EngineFormat.RGBA_PVRTC_4BPPV1_Format],
|
|
446
|
-
priorityETC1S: 5,
|
|
447
|
-
priorityUASTC: 6,
|
|
448
|
-
needsPowerOfTwo: true
|
|
449
|
-
}];
|
|
450
|
-
const ETC1S_OPTIONS = FORMAT_OPTIONS.sort(function (a, b) {
|
|
451
|
-
return a.priorityETC1S - b.priorityETC1S;
|
|
452
|
-
});
|
|
453
|
-
const UASTC_OPTIONS = FORMAT_OPTIONS.sort(function (a, b) {
|
|
454
|
-
return a.priorityUASTC - b.priorityUASTC;
|
|
455
|
-
});
|
|
456
|
-
function getTranscoderFormat(basisFormat, width, height, hasAlpha) {
|
|
457
|
-
let transcoderFormat;
|
|
458
|
-
let engineFormat;
|
|
459
|
-
const options = basisFormat === BasisFormat.ETC1S ? ETC1S_OPTIONS : UASTC_OPTIONS;
|
|
460
|
-
for (let i = 0; i < options.length; i++) {
|
|
461
|
-
const opt = options[i];
|
|
462
|
-
if (!config[opt.if]) continue;
|
|
463
|
-
if (!opt.basisFormat.includes(basisFormat)) continue;
|
|
464
|
-
if (hasAlpha && opt.transcoderFormat.length < 2) continue;
|
|
465
|
-
if (opt.needsPowerOfTwo && !(isPowerOfTwo(width) && isPowerOfTwo(height))) continue;
|
|
466
|
-
transcoderFormat = opt.transcoderFormat[hasAlpha ? 1 : 0];
|
|
467
|
-
engineFormat = opt.engineFormat[hasAlpha ? 1 : 0];
|
|
468
|
-
return {
|
|
469
|
-
transcoderFormat,
|
|
470
|
-
engineFormat
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
console.warn('THREE.KTX2Loader: No suitable compressed texture format found. Decoding to RGBA32.');
|
|
474
|
-
transcoderFormat = TranscoderFormat.RGBA32;
|
|
475
|
-
engineFormat = EngineFormat.RGBAFormat;
|
|
476
|
-
return {
|
|
477
|
-
transcoderFormat,
|
|
478
|
-
engineFormat
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
function isPowerOfTwo(value) {
|
|
482
|
-
if (value <= 2) return true;
|
|
483
|
-
return (value & value - 1) === 0 && value !== 0;
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
/** Concatenates N byte arrays. */
|
|
487
|
-
function concat(arrays) {
|
|
488
|
-
if (arrays.length === 1) return arrays[0];
|
|
489
|
-
let totalByteLength = 0;
|
|
490
|
-
for (let i = 0; i < arrays.length; i++) {
|
|
491
|
-
const array = arrays[i];
|
|
492
|
-
totalByteLength += array.byteLength;
|
|
493
|
-
}
|
|
494
|
-
const result = new Uint8Array(totalByteLength);
|
|
495
|
-
let byteOffset = 0;
|
|
496
|
-
for (let i = 0; i < arrays.length; i++) {
|
|
497
|
-
const array = arrays[i];
|
|
498
|
-
result.set(array, byteOffset);
|
|
499
|
-
byteOffset += array.byteLength;
|
|
500
|
-
}
|
|
501
|
-
return result;
|
|
502
|
-
}
|
|
503
|
-
};
|
|
504
|
-
|
|
505
|
-
//
|
|
506
|
-
// Parsing for non-Basis textures. These textures are may have supercompression
|
|
507
|
-
// like Zstd, but they do not require transcoding.
|
|
508
|
-
|
|
509
|
-
const UNCOMPRESSED_FORMATS = new Set([RGBAFormat, RGFormat, RedFormat]);
|
|
510
|
-
const FORMAT_MAP = {
|
|
511
|
-
[VK_FORMAT_R32G32B32A32_SFLOAT]: RGBAFormat,
|
|
512
|
-
[VK_FORMAT_R16G16B16A16_SFLOAT]: RGBAFormat,
|
|
513
|
-
[VK_FORMAT_R8G8B8A8_UNORM]: RGBAFormat,
|
|
514
|
-
[VK_FORMAT_R8G8B8A8_SRGB]: RGBAFormat,
|
|
515
|
-
[VK_FORMAT_R32G32_SFLOAT]: RGFormat,
|
|
516
|
-
[VK_FORMAT_R16G16_SFLOAT]: RGFormat,
|
|
517
|
-
[VK_FORMAT_R8G8_UNORM]: RGFormat,
|
|
518
|
-
[VK_FORMAT_R8G8_SRGB]: RGFormat,
|
|
519
|
-
[VK_FORMAT_R32_SFLOAT]: RedFormat,
|
|
520
|
-
[VK_FORMAT_R16_SFLOAT]: RedFormat,
|
|
521
|
-
[VK_FORMAT_R8_SRGB]: RedFormat,
|
|
522
|
-
[VK_FORMAT_R8_UNORM]: RedFormat,
|
|
523
|
-
[VK_FORMAT_ASTC_6x6_SRGB_BLOCK]: RGBA_ASTC_6x6_Format,
|
|
524
|
-
[VK_FORMAT_ASTC_6x6_UNORM_BLOCK]: RGBA_ASTC_6x6_Format
|
|
525
|
-
};
|
|
526
|
-
const TYPE_MAP = {
|
|
527
|
-
[VK_FORMAT_R32G32B32A32_SFLOAT]: FloatType,
|
|
528
|
-
[VK_FORMAT_R16G16B16A16_SFLOAT]: HalfFloatType,
|
|
529
|
-
[VK_FORMAT_R8G8B8A8_UNORM]: UnsignedByteType,
|
|
530
|
-
[VK_FORMAT_R8G8B8A8_SRGB]: UnsignedByteType,
|
|
531
|
-
[VK_FORMAT_R32G32_SFLOAT]: FloatType,
|
|
532
|
-
[VK_FORMAT_R16G16_SFLOAT]: HalfFloatType,
|
|
533
|
-
[VK_FORMAT_R8G8_UNORM]: UnsignedByteType,
|
|
534
|
-
[VK_FORMAT_R8G8_SRGB]: UnsignedByteType,
|
|
535
|
-
[VK_FORMAT_R32_SFLOAT]: FloatType,
|
|
536
|
-
[VK_FORMAT_R16_SFLOAT]: HalfFloatType,
|
|
537
|
-
[VK_FORMAT_R8_SRGB]: UnsignedByteType,
|
|
538
|
-
[VK_FORMAT_R8_UNORM]: UnsignedByteType,
|
|
539
|
-
[VK_FORMAT_ASTC_6x6_SRGB_BLOCK]: UnsignedByteType,
|
|
540
|
-
[VK_FORMAT_ASTC_6x6_UNORM_BLOCK]: UnsignedByteType
|
|
541
|
-
};
|
|
542
|
-
async function createRawTexture(container) {
|
|
543
|
-
const {
|
|
544
|
-
vkFormat
|
|
545
|
-
} = container;
|
|
546
|
-
if (FORMAT_MAP[vkFormat] === undefined) {
|
|
547
|
-
throw new Error('THREE.KTX2Loader: Unsupported vkFormat.');
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
//
|
|
551
|
-
|
|
552
|
-
let zstd;
|
|
553
|
-
if (container.supercompressionScheme === KHR_SUPERCOMPRESSION_ZSTD) {
|
|
554
|
-
if (!_zstd) {
|
|
555
|
-
_zstd = new Promise(async resolve => {
|
|
556
|
-
const zstd = new ZSTDDecoder();
|
|
557
|
-
await zstd.init();
|
|
558
|
-
resolve(zstd);
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
zstd = await _zstd;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
//
|
|
565
|
-
|
|
566
|
-
const mipmaps = [];
|
|
567
|
-
for (let levelIndex = 0; levelIndex < container.levels.length; levelIndex++) {
|
|
568
|
-
const levelWidth = Math.max(1, container.pixelWidth >> levelIndex);
|
|
569
|
-
const levelHeight = Math.max(1, container.pixelHeight >> levelIndex);
|
|
570
|
-
const levelDepth = container.pixelDepth ? Math.max(1, container.pixelDepth >> levelIndex) : 0;
|
|
571
|
-
const level = container.levels[levelIndex];
|
|
572
|
-
let levelData;
|
|
573
|
-
if (container.supercompressionScheme === KHR_SUPERCOMPRESSION_NONE) {
|
|
574
|
-
levelData = level.levelData;
|
|
575
|
-
} else if (container.supercompressionScheme === KHR_SUPERCOMPRESSION_ZSTD) {
|
|
576
|
-
levelData = zstd.decode(level.levelData, level.uncompressedByteLength);
|
|
577
|
-
} else {
|
|
578
|
-
throw new Error('THREE.KTX2Loader: Unsupported supercompressionScheme.');
|
|
579
|
-
}
|
|
580
|
-
let data;
|
|
581
|
-
if (TYPE_MAP[vkFormat] === FloatType) {
|
|
582
|
-
data = new Float32Array(levelData.buffer, levelData.byteOffset, levelData.byteLength / Float32Array.BYTES_PER_ELEMENT);
|
|
583
|
-
} else if (TYPE_MAP[vkFormat] === HalfFloatType) {
|
|
584
|
-
data = new Uint16Array(levelData.buffer, levelData.byteOffset, levelData.byteLength / Uint16Array.BYTES_PER_ELEMENT);
|
|
585
|
-
} else {
|
|
586
|
-
data = levelData;
|
|
587
|
-
}
|
|
588
|
-
mipmaps.push({
|
|
589
|
-
data: data,
|
|
590
|
-
width: levelWidth,
|
|
591
|
-
height: levelHeight,
|
|
592
|
-
depth: levelDepth
|
|
593
|
-
});
|
|
594
|
-
}
|
|
595
|
-
let texture;
|
|
596
|
-
if (UNCOMPRESSED_FORMATS.has(FORMAT_MAP[vkFormat])) {
|
|
597
|
-
texture = container.pixelDepth === 0 ? new DataTexture(mipmaps[0].data, container.pixelWidth, container.pixelHeight) : new Data3DTexture(mipmaps[0].data, container.pixelWidth, container.pixelHeight, container.pixelDepth);
|
|
598
|
-
} else {
|
|
599
|
-
if (container.pixelDepth > 0) throw new Error('THREE.KTX2Loader: Unsupported pixelDepth.');
|
|
600
|
-
texture = new CompressedTexture(mipmaps, container.pixelWidth, container.pixelHeight);
|
|
601
|
-
}
|
|
602
|
-
texture.mipmaps = mipmaps;
|
|
603
|
-
texture.type = TYPE_MAP[vkFormat];
|
|
604
|
-
texture.format = FORMAT_MAP[vkFormat];
|
|
605
|
-
texture.colorSpace = parseColorSpace(container);
|
|
606
|
-
texture.needsUpdate = true;
|
|
607
|
-
|
|
608
|
-
//
|
|
609
|
-
|
|
610
|
-
return Promise.resolve(texture);
|
|
611
|
-
}
|
|
612
|
-
function parseColorSpace(container) {
|
|
613
|
-
const dfd = container.dataFormatDescriptor[0];
|
|
614
|
-
if (dfd.colorPrimaries === KHR_DF_PRIMARIES_BT709) {
|
|
615
|
-
return dfd.transferFunction === KHR_DF_TRANSFER_SRGB ? SRGBColorSpace : LinearSRGBColorSpace;
|
|
616
|
-
} else if (dfd.colorPrimaries === KHR_DF_PRIMARIES_DISPLAYP3) {
|
|
617
|
-
return dfd.transferFunction === KHR_DF_TRANSFER_SRGB ? DisplayP3ColorSpace : LinearDisplayP3ColorSpace;
|
|
618
|
-
} else if (dfd.colorPrimaries === KHR_DF_PRIMARIES_UNSPECIFIED) {
|
|
619
|
-
return NoColorSpace;
|
|
620
|
-
} else {
|
|
621
|
-
console.warn(`THREE.KTX2Loader: Unsupported color primaries, "${dfd.colorPrimaries}"`);
|
|
622
|
-
return NoColorSpace;
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
export { KTX2Loader };
|