Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KTX2Loader: Add parse() method for direct buffer processing. #28936

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions examples/jsm/loaders/KTX2Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down