1 |
|
2 |
|
3 |
|
4 |
|
5 | import { RGBAFormat, RGBFormat } from '../constants.js';
|
6 | import { ImageLoader } from './ImageLoader.js';
|
7 | import { Texture } from '../textures/Texture.js';
|
8 | import { DefaultLoadingManager } from './LoadingManager.js';
|
9 |
|
10 |
|
11 | function TextureLoader( manager ) {
|
12 |
|
13 | this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
|
14 |
|
15 | }
|
16 |
|
17 | Object.assign( TextureLoader.prototype, {
|
18 |
|
19 | crossOrigin: 'Anonymous',
|
20 |
|
21 | load: function ( url, onLoad, onProgress, onError ) {
|
22 |
|
23 | var texture = new Texture();
|
24 |
|
25 | var loader = new ImageLoader( this.manager );
|
26 | loader.setCrossOrigin( this.crossOrigin );
|
27 | loader.setPath( this.path );
|
28 |
|
29 | loader.load( url, function ( image ) {
|
30 |
|
31 | texture.image = image;
|
32 |
|
33 |
|
34 | var isJPEG = url.search( /\.(jpg|jpeg)$/ ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
|
35 |
|
36 | texture.format = isJPEG ? RGBFormat : RGBAFormat;
|
37 | texture.needsUpdate = true;
|
38 |
|
39 | if ( onLoad !== undefined ) {
|
40 |
|
41 | onLoad( texture );
|
42 |
|
43 | }
|
44 |
|
45 | }, onProgress, onError );
|
46 |
|
47 | return texture;
|
48 |
|
49 | },
|
50 |
|
51 | setCrossOrigin: function ( value ) {
|
52 |
|
53 | this.crossOrigin = value;
|
54 | return this;
|
55 |
|
56 | },
|
57 |
|
58 | setPath: function ( value ) {
|
59 |
|
60 | this.path = value;
|
61 | return this;
|
62 |
|
63 | }
|
64 |
|
65 | } );
|
66 |
|
67 |
|
68 | export { TextureLoader };
|