Kaynağa Gözat

Merge pull request #12748 from duhaime/document-texture-loader-progress

document lack of xhr progress in TextureLoader
Mr.doob 7 yıl önce
ebeveyn
işleme
d75f390efd

+ 7 - 4
docs/api/loaders/AnimationLoader.html

@@ -25,16 +25,19 @@
 		loader.load(
 		loader.load(
 			// resource URL
 			// resource URL
 			'animations/animation.js',
 			'animations/animation.js',
-			// Function when resource is loaded
+
+			// onLoad callback
 			function ( animations ) {
 			function ( animations ) {
 				// animations is an array of AnimationClips
 				// animations is an array of AnimationClips
 			},
 			},
-			// Function called when download progresses
+
+			// onProgress callback
 			function ( xhr ) {
 			function ( xhr ) {
 				console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
 				console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
 			},
 			},
-			// Function called when download errors
-			function ( xhr ) {
+
+			// onError callback
+			function ( err ) {
 				console.log( 'An error happened' );
 				console.log( 'An error happened' );
 			}
 			}
 		);
 		);

+ 7 - 4
docs/api/loaders/AudioLoader.html

@@ -38,7 +38,8 @@
 		loader.load(
 		loader.load(
 			// resource URL
 			// resource URL
 			'audio/ambient_ocean.ogg',
 			'audio/ambient_ocean.ogg',
-			// Function when resource is loaded
+
+			// onLoad callback
 			function ( audioBuffer ) {
 			function ( audioBuffer ) {
 				// set the audio object buffer to the loaded object
 				// set the audio object buffer to the loaded object
 				oceanAmbientSound.setBuffer( audioBuffer );
 				oceanAmbientSound.setBuffer( audioBuffer );
@@ -46,12 +47,14 @@
 				// play the audio
 				// play the audio
 				oceanAmbientSound.play();
 				oceanAmbientSound.play();
 			},
 			},
-			// Function called when download progresses
+
+			// onProgress callback
 			function ( xhr ) {
 			function ( xhr ) {
 				console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
 				console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
 			},
 			},
-			// Function called when download errors
-			function ( xhr ) {
+
+			// onError callback
+			function ( err ) {
 				console.log( 'An error happened' );
 				console.log( 'An error happened' );
 			}
 			}
 		);
 		);

+ 8 - 5
docs/api/loaders/BufferGeometryLoader.html

@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <!DOCTYPE html>
 <html lang="en">
 <html lang="en">
 	<head>
 	<head>
-		<meta charset="utf-8" />
+		<meta charset="utf-8" />
 		<base href="../../" />
 		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="list.js"></script>
 		<script src="page.js"></script>
 		<script src="page.js"></script>
@@ -27,18 +27,21 @@
 		loader.load(
 		loader.load(
 			// resource URL
 			// resource URL
 			'models/json/pressure.json',
 			'models/json/pressure.json',
-			// Function when resource is loaded
+
+			// onLoad callback
 			function ( geometry ) {
 			function ( geometry ) {
 				var material = new THREE.MeshLambertMaterial( { color: 0xF5F5F5 } );
 				var material = new THREE.MeshLambertMaterial( { color: 0xF5F5F5 } );
 				var object = new THREE.Mesh( geometry, material );
 				var object = new THREE.Mesh( geometry, material );
 				scene.add( object );
 				scene.add( object );
 			},
 			},
-			// Function called when download progresses
+
+			// onProgress callback
 			function ( xhr ) {
 			function ( xhr ) {
 				console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
 				console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
 			},
 			},
-			// Function called when download errors
-			function ( xhr ) {
+
+			// onError callback
+			function ( err ) {
 				console.log( 'An error happened' );
 				console.log( 'An error happened' );
 			}
 			}
 		);
 		);

+ 24 - 24
docs/api/loaders/FileLoader.html

@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <!DOCTYPE html>
 <html lang="en">
 <html lang="en">
 	<head>
 	<head>
-		<meta charset="utf-8" />
+		<meta charset="utf-8" />
 		<base href="../../" />
 		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="list.js"></script>
 		<script src="page.js"></script>
 		<script src="page.js"></script>
@@ -22,29 +22,29 @@
 			[example:webgl_morphtargets_human WebGL / morphtargets / human]<br />
 			[example:webgl_morphtargets_human WebGL / morphtargets / human]<br />
 		</div>
 		</div>
 		<code>
 		<code>
-var loader = new THREE.FileLoader();
-
-//load a text file a output the result to the console
-loader.load(
-    // resource URL
-    'example.txt',
-
-    // Function when resource is loaded
-    function ( data ) {
-        // output the text to the console
-        console.log( data )
-    },
-
-    // Function called when download progresses
-    function ( xhr ) {
-        console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
-    },
-
-    // Function called when download errors
-    function ( xhr ) {
-        console.error( 'An error happened' );
-    }
-);
+		var loader = new THREE.FileLoader();
+
+		//load a text file a output the result to the console
+		loader.load(
+			// resource URL
+			'example.txt',
+
+			// onLoad callback
+			function ( data ) {
+				// output the text to the console
+				console.log( data )
+			},
+
+			// onProgress callback
+			function ( xhr ) {
+				console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
+			},
+
+			// onError callback
+			function ( err ) {
+				console.error( 'An error happened' );
+			}
+		);
 		</code>
 		</code>
 
 
 		<h2>Constructor</h2>
 		<h2>Constructor</h2>

+ 7 - 4
docs/api/loaders/FontLoader.html

@@ -30,17 +30,20 @@
 		var font = loader.load(
 		var font = loader.load(
 			// resource URL
 			// resource URL
 			'fonts/helvetiker_bold.typeface.json'
 			'fonts/helvetiker_bold.typeface.json'
-			// Function when resource is loaded
+
+			// onLoad callback
 			function ( font ) {
 			function ( font ) {
 				// do something with the font
 				// do something with the font
 				scene.add( font );
 				scene.add( font );
 			},
 			},
-			// Function called when download progresses
+
+			// onProgress callback
 			function ( xhr ) {
 			function ( xhr ) {
 				console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
 				console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
 			},
 			},
-			// Function called when download errors
-			function ( xhr ) {
+
+			// onError callback
+			function ( err ) {
 				console.log( 'An error happened' );
 				console.log( 'An error happened' );
 			}
 			}
 		);
 		);

+ 8 - 7
docs/api/loaders/ImageBitmapLoader.html

@@ -29,17 +29,18 @@
 		loader.load(
 		loader.load(
 			// resource URL
 			// resource URL
 			'textures/skyboxsun25degtest.png',
 			'textures/skyboxsun25degtest.png',
-			// Function when resource is loaded
+
+			// onLoad callback
 			function ( imageBitmap ) {
 			function ( imageBitmap ) {
 				var texture = new THREE.CanvasTexture( imageBitmap );
 				var texture = new THREE.CanvasTexture( imageBitmap );
 				var material = new THREE.MeshBasicMaterial( { map: texture } );
 				var material = new THREE.MeshBasicMaterial( { map: texture } );
 			},
 			},
-			// Function called when download progresses
-			function ( xhr ) {
-				console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
-			},
-			// Function called when download errors
-			function ( xhr ) {
+
+			// onProgress callback currently not supported
+			undefined,
+
+			// onError callback
+			function ( err ) {
 				console.log( 'An error happened' );
 				console.log( 'An error happened' );
 			}
 			}
 		);
 		);

+ 11 - 11
docs/api/loaders/ImageLoader.html

@@ -32,26 +32,26 @@
 		loader.load(
 		loader.load(
 			// resource URL
 			// resource URL
 			'textures/skyboxsun25degtest.png',
 			'textures/skyboxsun25degtest.png',
-			// Function when resource is loaded
-			function ( image ) {
-				// do something with it
 
 
-				// like drawing a part of it on a canvas
+			// onLoad callback
+			function ( image ) {
+				// use the image, e.g. draw part of it on a canvas
 				var canvas = document.createElement( 'canvas' );
 				var canvas = document.createElement( 'canvas' );
 				var context = canvas.getContext( '2d' );
 				var context = canvas.getContext( '2d' );
 				context.drawImage( image, 100, 100 );
 				context.drawImage( image, 100, 100 );
 			},
 			},
-			// Function called when download progresses
-			function ( xhr ) {
-				console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
-			},
-			// Function called when download errors
-			function ( xhr ) {
-				console.log( 'An error happened' );
+
+			// onProgress callback currently not supported
+			undefined,
+
+			// onError callback
+			function () {
+				console.error( 'An error happened.' );
 			}
 			}
 		);
 		);
 		</code>
 		</code>
 
 
+		Please note three.js r84 dropped support for ImageLoader progress events. For an ImageLoader that supports progress events, see [link:https://github.com/mrdoob/three.js/issues/10439#issuecomment-275785639 this thread].
 
 
 		<h2>Constructor</h2>
 		<h2>Constructor</h2>
 
 

+ 10 - 4
docs/api/loaders/JSONLoader.html

@@ -28,18 +28,24 @@
 
 
 		// load a resource
 		// load a resource
 		loader.load(
 		loader.load(
-
 			// resource URL
 			// resource URL
 			'models/animated/monster/monster.js',
 			'models/animated/monster/monster.js',
 
 
-			// Function when resource is loaded
+			// onLoad callback
 			function ( geometry, materials ) {
 			function ( geometry, materials ) {
-
 				var material = materials[ 0 ];
 				var material = materials[ 0 ];
 				var object = new THREE.Mesh( geometry, material );
 				var object = new THREE.Mesh( geometry, material );
-
 				scene.add( object );
 				scene.add( object );
+			},
+
+			// onProgress callback
+			function ( xhr ) {
+				console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
+			},
 
 
+			// onError callback
+			function( err ) {
+				console.log( 'An error happened' );
 			}
 			}
 		);
 		);
 		</code>
 		</code>

+ 8 - 5
docs/api/loaders/MaterialLoader.html

@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <!DOCTYPE html>
 <html lang="en">
 <html lang="en">
 	<head>
 	<head>
-		<meta charset="utf-8" />
+		<meta charset="utf-8" />
 		<base href="../../" />
 		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="list.js"></script>
 		<script src="page.js"></script>
 		<script src="page.js"></script>
@@ -26,16 +26,19 @@
 		loader.load(
 		loader.load(
 			// resource URL
 			// resource URL
 			'path/to/material.json',
 			'path/to/material.json',
-			// Function when resource is loaded
+
+			// onLoad callback
 			function ( material ) {
 			function ( material ) {
 				object.material = material;
 				object.material = material;
 			},
 			},
-			// Function called when download progresses
+
+			// onProgress callback
 			function ( xhr ) {
 			function ( xhr ) {
 				console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
 				console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
 			},
 			},
-			// Function called when download errors
-			function ( xhr ) {
+
+			// onError callback
+			function ( err ) {
 				console.log( 'An error happened' );
 				console.log( 'An error happened' );
 			}
 			}
 		);
 		);

+ 22 - 22
docs/api/loaders/ObjectLoader.html

@@ -29,35 +29,35 @@
 		</div>
 		</div>
 
 
 		<code>
 		<code>
-var loader = new THREE.ObjectLoader();
+		var loader = new THREE.ObjectLoader();
 
 
-loader.load(
-    // resource URL
-    "models/json/example.json",
+		loader.load(
+			// resource URL
+			"models/json/example.json",
 
 
-    // pass the loaded data to the onLoad function.
-		//Here it is assumed to be an object
-    function ( obj ) {
-				//add the loaded object to the scene
-        scene.add( obj );
-    },
+			// onLoad callback
+			// Here the loaded data is assumed to be an object
+			function ( obj ) {
+				// Add the loaded object to the scene
+				scene.add( obj );
+			},
 
 
-    // Function called when download progresses
-    function ( xhr ) {
-        console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
-    },
+			// onProgress callback
+			function ( err ) {
+				console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
+			},
 
 
-    // Function called when download errors
-    function ( xhr ) {
-        console.error( 'An error happened' );
-    }
-);
+			// onError callback
+			function ( xhr ) {
+				console.error( 'An error happened' );
+			}
+		);
 
 
 
 
-// Alternatively, to parse a previously loaded JSON structure
-var object = loader.parse( a_json_object );
+		// Alternatively, to parse a previously loaded JSON structure
+		var object = loader.parse( a_json_object );
 
 
-scene.add( object );
+		scene.add( object );
 		</code>
 		</code>
 
 
 
 

+ 11 - 8
docs/api/loaders/TextureLoader.html

@@ -36,24 +36,27 @@
 		loader.load(
 		loader.load(
 			// resource URL
 			// resource URL
 			'textures/land_ocean_ice_cloud_2048.jpg',
 			'textures/land_ocean_ice_cloud_2048.jpg',
-			// Function when resource is loaded
+
+			// onLoad callback
 			function ( texture ) {
 			function ( texture ) {
 				// in this example we create the material when the texture is loaded
 				// in this example we create the material when the texture is loaded
 				var material = new THREE.MeshBasicMaterial( {
 				var material = new THREE.MeshBasicMaterial( {
 					map: texture
 					map: texture
 				 } );
 				 } );
 			},
 			},
-			// Function called when download progresses
-			function ( xhr ) {
-				console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
-			},
-			// Function called when download errors
-			function ( xhr ) {
-				console.error( 'An error happened' );
+
+			// onProgress callback currently not supported
+			undefined,
+
+			// onError callback
+			function ( err ) {
+				console.error( 'An error happened.' );
 			}
 			}
 		);
 		);
 		</code>
 		</code>
 
 
+		Please note three.js r84 dropped support for TextureLoader progress events. For a TextureLoader that supports progress events, see [link:https://github.com/mrdoob/three.js/issues/10439#issuecomment-293260145 this thread].
+
 		<h2>Constructor</h2>
 		<h2>Constructor</h2>
 
 
 		<h3>[name]( [page:LoadingManager manager] )</h3>
 		<h3>[name]( [page:LoadingManager manager] )</h3>