How to use the XHRLoader function from three
Find comprehensive JavaScript three.XHRLoader code examples handpicked from public code repositorys.
three.XHRLoader is a helper class in the Three.js library that loads a file from a given URL using XMLHttpRequest (XHR).
GitHub: AVGP/spaceblaster
27 28 29 30 31 32 33 34 35 36
mtlLoader.load( mtlurl, function ( materials ) { var materialsCreator = materials; materialsCreator.preload(); var loader = new THREE.XHRLoader( scope.manager ); loader.setCrossOrigin( scope.crossOrigin ); loader.load( url, function ( text ) { var object = scope.parse( text );
5
4
2
+ 13 other calls in file
28 29 30 31 32 33 34 35 36 37
*/ load: function load(url, onLoad, onProgress, onError) { var scope = this; var loader = new THREE.XHRLoader(this.manager); loader.setPath(this.path); loader.load(url, function (text) { onLoad(scope.parse(text));
0
2
1
How does three.XHRLoader work?
three.XHRLoader is a class in the Three.js library that provides methods for loading various types of files (such as images, JSON, and text) using XMLHttpRequest. When called, it creates a new instance of XMLHttpRequest and sets its parameters and event listeners to perform the file load. Once the load is complete, the file's data is returned to the caller's callback function.
29 30 31 32 33 34 35 36 37 38
*/ load: function ( url, onLoad, onProgress, onError ) { let scope = this; let loader = new THREE.XHRLoader( this.manager ); loader.setPath( this.path ); loader.load( url, function ( text ) { onLoad( scope.parse( text ) );
0
0
2
+ 21 other calls in file
43 44 45 46 47 48 49 50 51 52
load: function (url, onLoad, onProgress, onError) { let scope = this; let loader = new THREE.XHRLoader(scope.manager); loader.setPath(this.path); loader.load(url, function (text) { onLoad(scope.parse(text));
0
0
2
+ 33 other calls in file
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
const loader = new THREE.XHRLoader(); loader.load( // URL of the file to load "texture.png", // Callback function to handle the loaded data function (data) { // Create a texture from the loaded image data const texture = new THREE.Texture(); texture.image = data; texture.needsUpdate = true; // Use the texture for a material, mesh, etc. // ... }, // Optional callback function to handle progress updates function (progressEvent) { console.log( "Loading progress:", progressEvent.loaded, "/", progressEvent.total ); } );
GitHub: stefadrian/planner
44 45 46 47 48 49 50 51 52 53
load: function load(url, onLoad, onProgress, onError) { var scope = this; var loader = new THREE.XHRLoader(scope.manager); loader.setPath(this.path); loader.load(url, function (text) { onLoad(scope.parse(text));
0
0
1
+ 24 other calls in file
three.Vector3 is the most popular function in three (22341 examples)