From c441b6baeb220eedd8bead983809a3b437ed2c06 Mon Sep 17 00:00:00 2001 From: laddish <49431692+laddish@users.noreply.github.com> Date: Thu, 25 Jul 2024 16:49:55 +0800 Subject: [PATCH] Added parse method to KTX2Loader for direct buffer processing (#28936) --- examples/jsm/loaders/KTX2Loader.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/examples/jsm/loaders/KTX2Loader.js b/examples/jsm/loaders/KTX2Loader.js index 0e60b2c5acf608..95649b9bd691c0 100644 --- a/examples/jsm/loaders/KTX2Loader.js +++ b/examples/jsm/loaders/KTX2Loader.js @@ -251,22 +251,34 @@ class KTX2Loader extends Loader { loader.load( url, ( buffer ) => { - // Check for an existing task using this buffer. A transferred buffer cannot be transferred - // again from this thread. - if ( _taskCache.has( buffer ) ) { + this.parse( buffer, onLoad, onError); + + }, onProgress, onError ); + + } + + parse( buffer, onLoad, onError ) { + + if ( this.workerConfig === null ) { + + throw new Error( 'THREE.KTX2Loader: Missing initialization with `.detectSupport( renderer )`.' ); + + } + + // Check for an existing task using this buffer. A transferred buffer cannot be transferred + // again from this thread. + if ( _taskCache.has( buffer ) ) { const cachedTask = _taskCache.get( buffer ); return cachedTask.promise.then( onLoad ).catch( onError ); - } + } - this._createTexture( buffer ) + this._createTexture( buffer ) .then( ( texture ) => onLoad ? onLoad( texture ) : null ) .catch( onError ); - }, onProgress, onError ); - } _createTextureFrom( transcodeResult, container ) {