Sfoglia il codice sorgente

Add preload method to DRACOLoader

Tyler Lindberg 5 anni fa
parent
commit
309154ffe6

+ 8 - 0
docs/examples/en/loaders/DRACOLoader.html

@@ -36,6 +36,9 @@
 		// Specify path to a folder containing WASM/JS decoding libraries.
 		loader.setDecoderPath( '/examples/js/libs/draco' );
 
+		// Optional: Pre-fetch Draco WASM/JS module.
+		loader.preload();
+
 		// Load a Draco geometry
 		loader.load(
 			// resource URL
@@ -128,6 +131,11 @@
 		in the application.
 		</p>
 
+		<h3>[method:Promise preload]()</h3>
+		<p>
+		Requests the decoder libraries, if not already loaded.
+		</p>
+
 		<h3>[method:this dispose]()</h3>
 		<p>
 		Disposes of the decoder resources and deallocates memory. The decoder

+ 8 - 0
docs/examples/zh/loaders/DRACOLoader.html

@@ -36,6 +36,9 @@
 		// Specify path to a folder containing WASM/JS decoding libraries.
 		loader.setDecoderPath( '/examples/js/libs/draco' );
 
+		// Optional: Pre-fetch Draco WASM/JS module.
+		loader.preload();
+
 		// Load a Draco geometry
 		loader.load(
 			// resource URL
@@ -128,6 +131,11 @@
 		in the application.
 		</p>
 
+		<h3>[method:Promise preload]()</h3>
+		<p>
+		Requests the decoder libraries, if not already loaded.
+		</p>
+
 		<h3>[method:this dispose]()</h3>
 		<p>
 		Disposes of the decoder resources and deallocates memory. The decoder

+ 2 - 2
examples/js/loaders/DRACOLoader.js

@@ -220,7 +220,7 @@ THREE.DRACOLoader.prototype = Object.assign( Object.create( THREE.Loader.prototy
 
 	},
 
-	_initDecoder: function () {
+	preload: function () {
 
 		if ( this.decoderPending ) return this.decoderPending;
 
@@ -269,7 +269,7 @@ THREE.DRACOLoader.prototype = Object.assign( Object.create( THREE.Loader.prototy
 
 	_getWorker: function ( taskID, taskCost ) {
 
-		return this._initDecoder().then( () => {
+		return this.preload().then( () => {
 
 			if ( this.workerPool.length < this.workerLimit ) {
 

+ 1 - 0
examples/jsm/loaders/DRACOLoader.d.ts

@@ -12,6 +12,7 @@ export class DRACOLoader extends Loader {
 	setDecoderPath( path: string ): DRACOLoader;
 	setDecoderConfig( config: object ): DRACOLoader;
 	setWorkerLimit( workerLimit: number ): DRACOLoader;
+	preload(): Promise<void>;
 	dispose(): DRACOLoader;
 
 }

+ 2 - 2
examples/jsm/loaders/DRACOLoader.js

@@ -227,7 +227,7 @@ DRACOLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	},
 
-	_initDecoder: function () {
+	preload: function () {
 
 		if ( this.decoderPending ) return this.decoderPending;
 
@@ -276,7 +276,7 @@ DRACOLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	_getWorker: function ( taskID, taskCost ) {
 
-		return this._initDecoder().then( () => {
+		return this.preload().then( () => {
 
 			if ( this.workerPool.length < this.workerLimit ) {