[28897] | 1 | /**
|
---|
| 2 | * @author mrdoob / http://mrdoob.com/
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | THREE.MaterialLoader = function ( manager ) {
|
---|
| 6 |
|
---|
| 7 | this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
|
---|
| 8 |
|
---|
| 9 | };
|
---|
| 10 |
|
---|
| 11 | THREE.MaterialLoader.prototype = {
|
---|
| 12 |
|
---|
| 13 | constructor: THREE.MaterialLoader,
|
---|
| 14 |
|
---|
| 15 | load: function ( url, onLoad, onProgress, onError ) {
|
---|
| 16 |
|
---|
| 17 | var scope = this;
|
---|
| 18 |
|
---|
| 19 | var loader = new THREE.XHRLoader();
|
---|
| 20 | loader.setCrossOrigin( this.crossOrigin );
|
---|
| 21 | loader.load( url, function ( text ) {
|
---|
| 22 |
|
---|
| 23 | onLoad( scope.parse( JSON.parse( text ) ) );
|
---|
| 24 |
|
---|
| 25 | } );
|
---|
| 26 |
|
---|
| 27 | },
|
---|
| 28 |
|
---|
| 29 | setCrossOrigin: function ( value ) {
|
---|
| 30 |
|
---|
| 31 | this.crossOrigin = value;
|
---|
| 32 |
|
---|
| 33 | },
|
---|
| 34 |
|
---|
| 35 | parse: function ( json ) {
|
---|
| 36 |
|
---|
| 37 | var material = new THREE[ json.type ];
|
---|
| 38 |
|
---|
| 39 | if ( json.color !== undefined ) material.color.setHex( json.color );
|
---|
| 40 | if ( json.ambient !== undefined ) material.ambient.setHex( json.ambient );
|
---|
| 41 | if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
|
---|
| 42 | if ( json.specular !== undefined ) material.specular.setHex( json.specular );
|
---|
| 43 | if ( json.shininess !== undefined ) material.shininess = json.shininess;
|
---|
| 44 | if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
|
---|
| 45 | if ( json.blending !== undefined ) material.blending = json.blending;
|
---|
| 46 | if ( json.side !== undefined ) material.side = json.side;
|
---|
| 47 | if ( json.opacity !== undefined ) material.opacity = json.opacity;
|
---|
| 48 | if ( json.transparent !== undefined ) material.transparent = json.transparent;
|
---|
| 49 | if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
|
---|
| 50 |
|
---|
| 51 | if ( json.materials !== undefined ) {
|
---|
| 52 |
|
---|
| 53 | for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
|
---|
| 54 |
|
---|
| 55 | material.materials.push( this.parse( json.materials[ i ] ) );
|
---|
| 56 |
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | return material;
|
---|
| 62 |
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | };
|
---|