浏览代码

Switch preload from returning a Promise to returning this

Tyler Lindberg 5 年之前
父节点
当前提交
828b01dcae

+ 1 - 1
docs/examples/en/loaders/DRACOLoader.html

@@ -131,7 +131,7 @@
 		in the application.
 		</p>
 
-		<h3>[method:Promise preload]()</h3>
+		<h3>[method:this preload]()</h3>
 		<p>
 		Requests the decoder libraries, if not already loaded.
 		</p>

+ 1 - 1
docs/examples/zh/loaders/DRACOLoader.html

@@ -131,7 +131,7 @@
 		in the application.
 		</p>
 
-		<h3>[method:Promise preload]()</h3>
+		<h3>[method:this preload]()</h3>
 		<p>
 		Requests the decoder libraries, if not already loaded.
 		</p>

+ 9 - 1
examples/js/loaders/DRACOLoader.js

@@ -222,6 +222,14 @@ THREE.DRACOLoader.prototype = Object.assign( Object.create( THREE.Loader.prototy
 
 	preload: function () {
 
+		this._initDecoder();
+
+		return this;
+
+	},
+
+	_initDecoder: function () {
+
 		if ( this.decoderPending ) return this.decoderPending;
 
 		var useJS = typeof WebAssembly !== 'object' || this.decoderConfig.type === 'js';
@@ -269,7 +277,7 @@ THREE.DRACOLoader.prototype = Object.assign( Object.create( THREE.Loader.prototy
 
 	_getWorker: function ( taskID, taskCost ) {
 
-		return this.preload().then( () => {
+		return this._initDecoder().then( () => {
 
 			if ( this.workerPool.length < this.workerLimit ) {
 

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

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

+ 9 - 1
examples/jsm/loaders/DRACOLoader.js

@@ -229,6 +229,14 @@ DRACOLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	preload: function () {
 
+		this._initDecoder();
+
+		return this;
+
+	},
+
+	_initDecoder: function () {
+
 		if ( this.decoderPending ) return this.decoderPending;
 
 		var useJS = typeof WebAssembly !== 'object' || this.decoderConfig.type === 'js';
@@ -276,7 +284,7 @@ DRACOLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	_getWorker: function ( taskID, taskCost ) {
 
-		return this.preload().then( () => {
+		return this._initDecoder().then( () => {
 
 			if ( this.workerPool.length < this.workerLimit ) {