KTX2Loader.js 18 KB

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