Просмотр исходного кода

Added parse method to KTX2Loader for direct buffer processing (#28936)

laddish 1 год назад
Родитель
Сommit
3602b98be2
1 измененных файлов с 19 добавлено и 7 удалено
  1. 19 7
      examples/jsm/loaders/KTX2Loader.js

+ 19 - 7
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 ) {

粤ICP备19079148号