KTX2Loader.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /**
  2. * @author donmccurdy / https://www.donmccurdy.com
  3. * @author MarkCallow / https://github.com/MarkCallow
  4. *
  5. * References:
  6. * - KTX: http://github.khronos.org/KTX-Specification/
  7. * - DFD: https://www.khronos.org/registry/DataFormat/specs/1.3/dataformat.1.3.html#basicdescriptor
  8. *
  9. * To do:
  10. * - [ ] Cross-platform testing
  11. * - [ ] Specify JS/WASM transcoder path
  12. * - [ ] High-quality demo
  13. * - [ ] Documentation
  14. * - [ ] TypeScript definitions
  15. * - [ ] (Optional) Include BC5
  16. * - [ ] (Optional) Include EAC RG on mobile (WEBGL_compressed_texture_etc)
  17. * - [ ] (Optional) Include two-texture output mode (see: clearcoat + clearcoatRoughness)
  18. * - [ ] (Optional) Support Web Workers, after #18234
  19. */
  20. import {
  21. CompressedTexture,
  22. CompressedTextureLoader,
  23. FileLoader,
  24. LinearEncoding,
  25. LinearFilter,
  26. LinearMipmapLinearFilter,
  27. RGB_ETC1_Format,
  28. RGB_ETC2_Format,
  29. RGBA_ETC2_EAC_Format,
  30. RGB_PVRTC_4BPPV1_Format,
  31. RGB_S3TC_DXT1_Format,
  32. RGBA_ASTC_4x4_Format,
  33. RGBA_PVRTC_4BPPV1_Format,
  34. RGBA_S3TC_DXT5_Format,
  35. sRGBEncoding,
  36. UnsignedByteType,
  37. } from '../../../build/three.module.js';
  38. // Data Format Descriptor (DFD) constants.
  39. const DFDModel = {
  40. ETC1S: 163,
  41. UASTC: 166,
  42. }
  43. const DFDChannel = {
  44. ETC1S: {
  45. RGB: 0,
  46. RRR: 3,
  47. GGG: 4,
  48. AAA: 15,
  49. },
  50. UASTC: {
  51. RGB: 0,
  52. RGBA: 3,
  53. RRR: 4,
  54. RRRG: 5
  55. },
  56. };
  57. //
  58. class KTX2Loader extends CompressedTextureLoader {
  59. constructor ( manager ) {
  60. super( manager );
  61. this.basisModule = null;
  62. this.basisModulePending = null;
  63. this.transcoderConfig = {};
  64. }
  65. detectSupport ( renderer ) {
  66. this.transcoderConfig = {
  67. astcSupported: renderer.extensions.has( 'WEBGL_compressed_texture_astc' ),
  68. etc1Supported: renderer.extensions.has( 'WEBGL_compressed_texture_etc1' ),
  69. etc2Supported: renderer.extensions.has( 'WEBGL_compressed_texture_etc' ),
  70. dxtSupported: renderer.extensions.has( 'WEBGL_compressed_texture_s3tc' ),
  71. pvrtcSupported: renderer.extensions.has( 'WEBGL_compressed_texture_pvrtc' )
  72. || renderer.extensions.has( 'WEBKIT_WEBGL_compressed_texture_pvrtc' )
  73. };
  74. return this;
  75. }
  76. initModule () {
  77. if ( this.basisModulePending ) {
  78. return;
  79. }
  80. var scope = this;
  81. // The Emscripten wrapper returns a fake Promise, which can cause
  82. // infinite recursion when mixed with native Promises. Wrap the module
  83. // initialization to return a native Promise.
  84. scope.basisModulePending = new Promise( function ( resolve ) {
  85. MSC_TRANSCODER().then( function ( basisModule ) {
  86. scope.basisModule = basisModule;
  87. basisModule.initTranscoders();
  88. resolve();
  89. } );
  90. } );
  91. }
  92. load ( url, onLoad, onProgress, onError ) {
  93. var scope = this;
  94. var texture = new CompressedTexture();
  95. var bufferPending = new Promise( function (resolve, reject ) {
  96. new FileLoader( scope.manager )
  97. .setPath( scope.path )
  98. .setResponseType( 'arraybuffer' )
  99. .load( url, resolve, onProgress, reject );
  100. } );
  101. this.initModule();
  102. Promise.all( [ bufferPending, this.basisModulePending ] ).then( function ( [ buffer ] ) {
  103. scope.parse( buffer, function ( _texture ) {
  104. texture.copy( _texture );
  105. texture.needsUpdate = true;
  106. if ( onLoad ) onLoad( texture );
  107. }, onError );
  108. } );
  109. return texture;
  110. }
  111. parse ( buffer, onLoad, onError ) {
  112. var BasisLzEtc1sImageTranscoder = this.basisModule.BasisLzEtc1sImageTranscoder;
  113. var UastcImageTranscoder = this.basisModule.UastcImageTranscoder;
  114. var TextureFormat = this.basisModule.TextureFormat;
  115. var ktx = new KTX2Container( this.basisModule, buffer );
  116. // TODO(donmccurdy): Should test if texture is transcodable before attempting
  117. // any transcoding. If supercompressionScheme is KTX_SS_BASIS_LZ and dfd
  118. // colorModel is ETC1S (163) or if dfd colorModel is UASTCF (166)
  119. // then texture must be transcoded.
  120. var transcoder = ktx.getTexFormat() === TextureFormat.UASTC4x4
  121. ? new UastcImageTranscoder()
  122. : new BasisLzEtc1sImageTranscoder();
  123. ktx.initMipmaps( transcoder, this.transcoderConfig )
  124. .then( function () {
  125. var texture = new CompressedTexture(
  126. ktx.mipmaps,
  127. ktx.getWidth(),
  128. ktx.getHeight(),
  129. ktx.transcodedFormat,
  130. UnsignedByteType
  131. );
  132. texture.encoding = ktx.getEncoding();
  133. texture.premultiplyAlpha = ktx.getPremultiplyAlpha();
  134. texture.minFilter = ktx.mipmaps.length === 1 ? LinearFilter : LinearMipmapLinearFilter;
  135. texture.magFilter = LinearFilter;
  136. onLoad( texture );
  137. } )
  138. .catch( onError );
  139. return this;
  140. }
  141. }
  142. class KTX2Container {
  143. constructor ( basisModule, arrayBuffer ) {
  144. this.basisModule = basisModule;
  145. this.arrayBuffer = arrayBuffer;
  146. this.mipmaps = null;
  147. this.transcodedFormat = null;
  148. // Confirm this is a KTX 2.0 file, based on the identifier in the first 12 bytes.
  149. var idByteLength = 12;
  150. var id = new Uint8Array( this.arrayBuffer, 0, idByteLength );
  151. if ( id[ 0 ] !== 0xAB || // '´'
  152. id[ 1 ] !== 0x4B || // 'K'
  153. id[ 2 ] !== 0x54 || // 'T'
  154. id[ 3 ] !== 0x58 || // 'X'
  155. id[ 4 ] !== 0x20 || // ' '
  156. id[ 5 ] !== 0x32 || // '2'
  157. id[ 6 ] !== 0x30 || // '0'
  158. id[ 7 ] !== 0xBB || // 'ª'
  159. id[ 8 ] !== 0x0D || // '\r'
  160. id[ 9 ] !== 0x0A || // '\n'
  161. id[ 10 ] !== 0x1A || // '\x1A'
  162. id[ 11 ] !== 0x0A // '\n'
  163. ) {
  164. throw new Error( 'THREE.KTX2Loader: Missing KTX 2.0 identifier.' );
  165. }
  166. // TODO(donmccurdy): If we need to support BE, derive this from typeSize.
  167. var littleEndian = true;
  168. ///////////////////////////////////////////////////
  169. // Header.
  170. ///////////////////////////////////////////////////
  171. var headerByteLength = 17 * Uint32Array.BYTES_PER_ELEMENT;
  172. var headerReader = new KTX2BufferReader( this.arrayBuffer, idByteLength, headerByteLength, littleEndian );
  173. this.header = {
  174. vkFormat: headerReader.nextUint32(),
  175. typeSize: headerReader.nextUint32(),
  176. pixelWidth: headerReader.nextUint32(),
  177. pixelHeight: headerReader.nextUint32(),
  178. pixelDepth: headerReader.nextUint32(),
  179. arrayElementCount: headerReader.nextUint32(),
  180. faceCount: headerReader.nextUint32(),
  181. levelCount: headerReader.nextUint32(),
  182. supercompressionScheme: headerReader.nextUint32(),
  183. dfdByteOffset: headerReader.nextUint32(),
  184. dfdByteLength: headerReader.nextUint32(),
  185. kvdByteOffset: headerReader.nextUint32(),
  186. kvdByteLength: headerReader.nextUint32(),
  187. sgdByteOffset: headerReader.nextUint64(),
  188. sgdByteLength: headerReader.nextUint64(),
  189. };
  190. if ( this.header.pixelDepth > 0 ) {
  191. throw new Error( 'THREE.KTX2Loader: Only 2D textures are currently supported.' );
  192. }
  193. if ( this.header.arrayElementCount > 1 ) {
  194. throw new Error( 'THREE.KTX2Loader: Array textures are not currently supported.' );
  195. }
  196. if ( this.header.faceCount > 1 ) {
  197. throw new Error( 'THREE.KTX2Loader: Cube textures are not currently supported.' );
  198. }
  199. ///////////////////////////////////////////////////
  200. // Level index
  201. ///////////////////////////////////////////////////
  202. var levelByteLength = this.header.levelCount * 3 * 8;
  203. var levelReader = new KTX2BufferReader( this.arrayBuffer, idByteLength + headerByteLength, levelByteLength, littleEndian );
  204. this.levels = [];
  205. for ( var i = 0; i < this.header.levelCount; i ++ ) {
  206. this.levels.push( {
  207. byteOffset: levelReader.nextUint64(),
  208. byteLength: levelReader.nextUint64(),
  209. uncompressedByteLength: levelReader.nextUint64(),
  210. } );
  211. }
  212. ///////////////////////////////////////////////////
  213. // Data Format Descriptor (DFD)
  214. ///////////////////////////////////////////////////
  215. var dfdReader = new KTX2BufferReader(
  216. this.arrayBuffer,
  217. this.header.dfdByteOffset,
  218. this.header.dfdByteLength,
  219. littleEndian
  220. );
  221. const sampleStart = 6;
  222. const sampleWords = 4;
  223. this.dfd = {
  224. vendorId: dfdReader.skip( 4 /* totalSize */ ).nextUint16(),
  225. versionNumber: dfdReader.skip( 2 /* descriptorType */ ).nextUint16(),
  226. descriptorBlockSize: dfdReader.nextUint16(),
  227. colorModel: dfdReader.nextUint8(),
  228. colorPrimaries: dfdReader.nextUint8(),
  229. transferFunction: dfdReader.nextUint8(),
  230. flags: dfdReader.nextUint8(),
  231. texelBlockDimension: {
  232. x: dfdReader.nextUint8() + 1,
  233. y: dfdReader.nextUint8() + 1,
  234. z: dfdReader.nextUint8() + 1,
  235. w: dfdReader.nextUint8() + 1,
  236. },
  237. bytesPlane0: dfdReader.nextUint8(),
  238. numSamples: 0,
  239. samples: [],
  240. };
  241. this.dfd.numSamples = ( this.dfd.descriptorBlockSize / 4 - sampleStart ) / sampleWords;
  242. dfdReader.skip( 7 /* bytesPlane[1-7] */ );
  243. for ( var i = 0; i < this.dfd.numSamples; i++ ) {
  244. this.dfd.samples[i] = {
  245. channelID: dfdReader.skip( 3 /* bitOffset + bitLength */ ).nextUint8(),
  246. // ... remainder not implemented.
  247. };
  248. dfdReader.skip( 12 /* samplePosition[0-3], lower, upper */ );
  249. }
  250. if ( this.header.vkFormat !== 0x00 /* VK_FORMAT_UNDEFINED */ &&
  251. ! ( this.header.supercompressionScheme === 1 /* BasisLZ */ ||
  252. this.dfd.colorModel === DFDModel.UASTC ) ) {
  253. throw new Error( 'THREE.KTX2Loader: Only Basis Universal supercompression is currently supported.' );
  254. }
  255. ///////////////////////////////////////////////////
  256. // Key/Value Data (KVD)
  257. ///////////////////////////////////////////////////
  258. // Not implemented.
  259. this.kvd = {};
  260. ///////////////////////////////////////////////////
  261. // Supercompression Global Data (SGD)
  262. ///////////////////////////////////////////////////
  263. this.sgd = {};
  264. if ( this.header.sgdByteLength <= 0 ) return;
  265. var sgdReader = new KTX2BufferReader(
  266. this.arrayBuffer,
  267. this.header.sgdByteOffset,
  268. this.header.sgdByteLength,
  269. littleEndian
  270. );
  271. this.sgd.endpointCount = sgdReader.nextUint16();
  272. this.sgd.selectorCount = sgdReader.nextUint16();
  273. this.sgd.endpointsByteLength = sgdReader.nextUint32();
  274. this.sgd.selectorsByteLength = sgdReader.nextUint32();
  275. this.sgd.tablesByteLength = sgdReader.nextUint32();
  276. this.sgd.extendedByteLength = sgdReader.nextUint32();
  277. this.sgd.imageDescs = [];
  278. this.sgd.endpointsData = null;
  279. this.sgd.selectorsData = null;
  280. this.sgd.tablesData = null;
  281. this.sgd.extendedData = null;
  282. for ( var i = 0; i < this.header.levelCount; i ++ ) {
  283. this.sgd.imageDescs.push( {
  284. imageFlags: sgdReader.nextUint32(),
  285. rgbSliceByteOffset: sgdReader.nextUint32(),
  286. rgbSliceByteLength: sgdReader.nextUint32(),
  287. alphaSliceByteOffset: sgdReader.nextUint32(),
  288. alphaSliceByteLength: sgdReader.nextUint32(),
  289. } );
  290. }
  291. var endpointsByteOffset = this.header.sgdByteOffset + sgdReader.offset;
  292. var selectorsByteOffset = endpointsByteOffset + this.sgd.endpointsByteLength;
  293. var tablesByteOffset = selectorsByteOffset + this.sgd.selectorsByteLength;
  294. var extendedByteOffset = tablesByteOffset + this.sgd.tablesByteLength;
  295. this.sgd.endpointsData = new Uint8Array( this.arrayBuffer, endpointsByteOffset, this.sgd.endpointsByteLength );
  296. this.sgd.selectorsData = new Uint8Array( this.arrayBuffer, selectorsByteOffset, this.sgd.selectorsByteLength );
  297. this.sgd.tablesData = new Uint8Array( this.arrayBuffer, tablesByteOffset, this.sgd.tablesByteLength );
  298. this.sgd.extendedData = new Uint8Array( this.arrayBuffer, extendedByteOffset, this.sgd.extendedByteLength );
  299. }
  300. initMipmaps ( transcoder, config ) {
  301. var TranscodeTarget = this.basisModule.TranscodeTarget;
  302. var TextureFormat = this.basisModule.TextureFormat;
  303. var ImageInfo = this.basisModule.ImageInfo;
  304. var scope = this;
  305. var mipmaps = [];
  306. var width = this.getWidth();
  307. var height = this.getHeight();
  308. var texFormat = this.getTexFormat();
  309. var hasAlpha = this.getAlpha();
  310. var isVideo = false;
  311. if ( texFormat === TextureFormat.ETC1S ) {
  312. var numEndpoints = this.sgd.endpointCount;
  313. var numSelectors = this.sgd.selectorCount;
  314. var endpoints = this.sgd.endpointsData;
  315. var selectors = this.sgd.selectorsData;
  316. var tables = this.sgd.tablesData;
  317. transcoder.decodePalettes( numEndpoints, endpoints, numSelectors, selectors );
  318. transcoder.decodeTables( tables );
  319. }
  320. var targetFormat;
  321. if ( config.astcSupported ) {
  322. targetFormat = TranscodeTarget.ASTC_4x4_RGBA;
  323. this.transcodedFormat = RGBA_ASTC_4x4_Format;
  324. } else if ( config.dxtSupported ) {
  325. targetFormat = hasAlpha ? TranscodeTarget.BC3_RGBA : TranscodeTarget.BC1_RGB;
  326. this.transcodedFormat = hasAlpha ? RGBA_S3TC_DXT5_Format : RGB_S3TC_DXT1_Format;
  327. } else if ( config.pvrtcSupported ) {
  328. targetFormat = hasAlpha ? TranscodeTarget.PVRTC1_4_RGBA : TranscodeTarget.PVRTC1_4_RGB;
  329. this.transcodedFormat = hasAlpha ? RGBA_PVRTC_4BPPV1_Format : RGB_PVRTC_4BPPV1_Format;
  330. } else if ( config.etc2Supported ) {
  331. targetFormat = hasAlpha ? TranscodeTarget.ETC2_RGBA : TranscodeTarget.ETC1_RGB /* subset of ETC2 */;
  332. this.transcodedFormat = hasAlpha ? RGBA_ETC2_EAC_Format : RGB_ETC2_Format;
  333. } else if ( config.etc1Supported ) {
  334. targetFormat = TranscodeTarget.ETC1_RGB;
  335. this.transcodedFormat = RGB_ETC1_Format;
  336. } else {
  337. throw new Error( 'THREE.KTX2Loader: No suitable compressed texture format found.' );
  338. }
  339. if ( ! this.basisModule.isFormatSupported( targetFormat, texFormat ) ) {
  340. throw new Error( 'THREE.KTX2Loader: Selected texture format not supported by current transcoder build.' );
  341. }
  342. var imageDescIndex = 0;
  343. for ( var level = 0; level < this.header.levelCount; level ++ ) {
  344. var levelWidth = width / Math.pow( 2, level );
  345. var levelHeight = height / Math.pow( 2, level );
  346. var numImagesInLevel = 1; // TODO(donmccurdy): Support cubemaps, arrays and 3D.
  347. var imageOffsetInLevel = 0;
  348. var imageInfo = new ImageInfo( texFormat, levelWidth, levelHeight, level );
  349. var levelImageByteLength = imageInfo.numBlocksX * imageInfo.numBlocksY * this.dfd.bytesPlane0;
  350. for ( var imageIndex = 0; imageIndex < numImagesInLevel; imageIndex ++ ) {
  351. var result;
  352. var encodedData;
  353. if ( texFormat === TextureFormat.UASTC4x4 ) {
  354. // UASTC
  355. imageInfo.flags = 0;
  356. imageInfo.rgbByteOffset = 0;
  357. imageInfo.rgbByteLength = levelImageByteLength;
  358. imageInfo.alphaByteOffset = 0;
  359. imageInfo.alphaByteLength = 0;
  360. encodedData = new Uint8Array( this.arrayBuffer, this.levels[ level ].byteOffset + imageOffsetInLevel, levelImageByteLength );
  361. result = transcoder.transcodeImage( targetFormat, encodedData, imageInfo, 0, hasAlpha, isVideo );
  362. } else {
  363. // ETC1S
  364. var imageDesc = this.sgd.imageDescs[ imageDescIndex++ ];
  365. imageInfo.flags = imageDesc.imageFlags;
  366. imageInfo.rgbByteOffset = 0;
  367. imageInfo.rgbByteLength = imageDesc.rgbSliceByteLength;
  368. imageInfo.alphaByteOffset = imageDesc.alphaSliceByteOffset > 0 ? imageDesc.rgbSliceByteLength : 0;
  369. imageInfo.alphaByteLength = imageDesc.alphaSliceByteLength;
  370. encodedData = new Uint8Array( this.arrayBuffer, this.levels[ level ].byteOffset + imageDesc.rgbSliceByteOffset, imageDesc.rgbSliceByteLength + imageDesc.alphaSliceByteLength );
  371. result = transcoder.transcodeImage( targetFormat, encodedData, imageInfo, 0, isVideo );
  372. }
  373. if ( result.transcodedImage === undefined ) {
  374. throw new Error( 'THREE.KTX2Loader: Unable to transcode image.' );
  375. }
  376. // Transcoded image is written in memory allocated by WASM. We could avoid copying
  377. // the image by waiting until the image is uploaded to the GPU, then calling
  378. // delete(). However, (1) we don't know if the user will later need to re-upload it
  379. // e.g. after calling texture.clone(), and (2) this code will eventually be in a
  380. // Web Worker, and transferring WASM's memory seems like a very bad idea.
  381. var levelData = result.transcodedImage.get_typed_memory_view().slice();
  382. result.transcodedImage.delete();
  383. mipmaps.push( { data: levelData, width: levelWidth, height: levelHeight } );
  384. imageOffsetInLevel += levelImageByteLength;
  385. }
  386. }
  387. return new Promise( function ( resolve, reject ) {
  388. scope.mipmaps = mipmaps;
  389. resolve();
  390. } );
  391. }
  392. getWidth () { return this.header.pixelWidth; }
  393. getHeight () { return this.header.pixelHeight; }
  394. getEncoding () {
  395. return this.dfd.transferFunction === 2 /* KHR_DF_TRANSFER_SRGB */
  396. ? sRGBEncoding
  397. : LinearEncoding;
  398. }
  399. getTexFormat () {
  400. var TextureFormat = this.basisModule.TextureFormat;
  401. return this.dfd.colorModel === DFDModel.UASTC ? TextureFormat.UASTC4x4 : TextureFormat.ETC1S;
  402. }
  403. getAlpha () {
  404. var TextureFormat = this.basisModule.TextureFormat;
  405. // TODO(donmccurdy): Handle all channelIDs (i.e. the R & R+G cases),
  406. // choosing appropriate transcode target formats or providing queries
  407. // for applications so they know what to do with the content.
  408. if ( this.getTexFormat() === TextureFormat.UASTC4x4 ) {
  409. // UASTC
  410. if ( ( this.dfd.samples[ 0 ].channelID & 0xF ) === DFDChannel.UASTC.RGBA ) {
  411. return true;
  412. }
  413. return false;
  414. }
  415. // ETC1S
  416. if ( this.dfd.numSamples === 2 && ( this.dfd.samples[ 1 ].channelID & 0xF ) === DFDChannel.ETC1S.AAA ) {
  417. return true;
  418. }
  419. return false;
  420. }
  421. getPremultiplyAlpha () {
  422. return !! ( this.dfd.flags & 1 /* KHR_DF_FLAG_ALPHA_PREMULTIPLIED */ );
  423. }
  424. }
  425. class KTX2BufferReader {
  426. constructor ( arrayBuffer, byteOffset, byteLength, littleEndian ) {
  427. this.dataView = new DataView( arrayBuffer, byteOffset, byteLength );
  428. this.littleEndian = littleEndian;
  429. this.offset = 0;
  430. }
  431. nextUint8 () {
  432. var value = this.dataView.getUint8( this.offset, this.littleEndian );
  433. this.offset += 1;
  434. return value;
  435. }
  436. nextUint16 () {
  437. var value = this.dataView.getUint16( this.offset, this.littleEndian );
  438. this.offset += 2;
  439. return value;
  440. }
  441. nextUint32 () {
  442. var value = this.dataView.getUint32( this.offset, this.littleEndian );
  443. this.offset += 4;
  444. return value;
  445. }
  446. nextUint64 () {
  447. // https://stackoverflow.com/questions/53103695/
  448. var left = this.dataView.getUint32( this.offset, this.littleEndian );
  449. var right = this.dataView.getUint32( this.offset + 4, this.littleEndian );
  450. var value = this.littleEndian ? left + ( 2 ** 32 * right ) : ( 2 ** 32 * left ) + right;
  451. if ( ! Number.isSafeInteger( value ) ) {
  452. console.warn( 'THREE.KTX2Loader: ' + value + ' exceeds MAX_SAFE_INTEGER. Precision may be lost.' );
  453. }
  454. this.offset += 8;
  455. return value;
  456. }
  457. skip ( bytes ) {
  458. this.offset += bytes;
  459. return this;
  460. }
  461. }
  462. export { KTX2Loader };