Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/flo-bit/shapecraft. flo-bit.dev/shapecraft
Something went wrong. Try again.
2.7 kB · 134 lines
JavaScript
at commit da69385e
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135import { LinearFilter } from '../constants.js';import { FileLoader } from './FileLoader.js';import { CompressedTexture } from '../textures/CompressedTexture.js';import { Loader } from './Loader.js';
/** * Abstract Base class to block based textures loader (dds, pvr, ...) * * Sub classes have to implement the parse() method which will be used in load(). */
class CompressedTextureLoader extends Loader {
constructor( manager ) {
super( manager );
}
load( url, onLoad, onProgress, onError ) {
const scope = this;
const images = [];
const texture = new CompressedTexture();
const loader = new FileLoader( this.manager ); loader.setPath( this.path ); loader.setResponseType( 'arraybuffer' ); loader.setRequestHeader( this.requestHeader ); loader.setWithCredentials( scope.withCredentials );
let loaded = 0;
function loadTexture( i ) {
loader.load( url[ i ], function ( buffer ) {
const texDatas = scope.parse( buffer, true );
images[ i ] = { width: texDatas.width, height: texDatas.height, format: texDatas.format, mipmaps: texDatas.mipmaps };
loaded += 1;
if ( loaded === 6 ) {
if ( texDatas.mipmapCount === 1 ) texture.minFilter = LinearFilter;
texture.image = images; texture.format = texDatas.format; texture.needsUpdate = true;
if ( onLoad ) onLoad( texture );
}
}, onProgress, onError );
}
if ( Array.isArray( url ) ) {
for ( let i = 0, il = url.length; i < il; ++ i ) {
loadTexture( i );
}
} else {
// compressed cubemap texture stored in a single DDS file
loader.load( url, function ( buffer ) {
const texDatas = scope.parse( buffer, true );
if ( texDatas.isCubemap ) {
const faces = texDatas.mipmaps.length / texDatas.mipmapCount;
for ( let f = 0; f < faces; f ++ ) {
images[ f ] = { mipmaps: [] };
for ( let i = 0; i < texDatas.mipmapCount; i ++ ) {
images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] ); images[ f ].format = texDatas.format; images[ f ].width = texDatas.width; images[ f ].height = texDatas.height;
}
}
texture.image = images;
} else {
texture.image.width = texDatas.width; texture.image.height = texDatas.height; texture.mipmaps = texDatas.mipmaps;
}
if ( texDatas.mipmapCount === 1 ) {
texture.minFilter = LinearFilter;
}
texture.format = texDatas.format; texture.needsUpdate = true;
if ( onLoad ) onLoad( texture );
}, onProgress, onError );
}
return texture;
}
}
export { CompressedTextureLoader };