| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- THREE.MaterialLoader = function () {};
- THREE.MaterialLoader.prototype = {
- constructor: THREE.MaterialLoader,
- addEventListener: THREE.EventDispatcher.prototype.addEventListener,
- hasEventListener: THREE.EventDispatcher.prototype.hasEventListener,
- removeEventListener: THREE.EventDispatcher.prototype.removeEventListener,
- dispatchEvent: THREE.EventDispatcher.prototype.dispatchEvent,
- load: function ( url ) {
- var scope = this;
- var request = new XMLHttpRequest();
- request.addEventListener( 'load', function ( event ) {
- var response = scope.parse( JSON.parse( event.target.responseText ) );
- scope.dispatchEvent( { type: 'load', content: response } );
- }, false );
- request.addEventListener( 'progress', function ( event ) {
- scope.dispatchEvent( { type: 'progress', loaded: event.loaded, total: event.total } );
- }, false );
- request.addEventListener( 'error', function () {
- scope.dispatchEvent( { type: 'error', message: 'Couldn\'t load URL [' + url + ']' } );
- }, false );
- request.open( 'GET', url, true );
- request.send( null );
- },
- parse: function ( json ) {
- var material;
- switch ( json.type ) {
- case 'MeshBasicMaterial':
- material = new THREE.MeshBasicMaterial( {
- color: json.color,
- opacity: json.opacity,
- transparent: json.transparent,
- wireframe: json.wireframe
- } );
- break;
- case 'MeshLambertMaterial':
- material = new THREE.MeshLambertMaterial( {
- color: json.color,
- ambient: json.ambient,
- emissive: json.emissive,
- opacity: json.opacity,
- transparent: json.transparent,
- wireframe: json.wireframe
- } );
- break;
- case 'MeshPhongMaterial':
- material = new THREE.MeshPhongMaterial( {
- color: json.color,
- ambient: json.ambient,
- emissive: json.emissive,
- specular: json.specular,
- shininess: json.shininess,
- opacity: json.opacity,
- transparent: json.transparent,
- wireframe: json.wireframe
- } );
- break;
- case 'MeshNormalMaterial':
- material = new THREE.MeshNormalMaterial( {
- opacity: json.opacity,
- transparent: json.transparent,
- wireframe: json.wireframe
- } );
- break;
- case 'MeshDepthMaterial':
- material = new THREE.MeshDepthMaterial( {
- opacity: json.opacity,
- transparent: json.transparent,
- wireframe: json.wireframe
- } );
- break;
- }
- return material;
- }
- };
|