浏览代码

Simplified PDBLoader.

Mr.doob 11 年之前
父节点
当前提交
6b86f7b62c
共有 1 个文件被更改,包括 8 次插入59 次删除
  1. 8 59
      examples/js/loaders/PDBLoader.js

+ 8 - 59
examples/js/loaders/PDBLoader.js

@@ -8,69 +8,18 @@ THREE.PDBLoader.prototype = {
 
 	constructor: THREE.OBJLoader,
 
-	load: function ( url, callback ) {
+	load: function ( url, onLoad ) {
 
-		var worker, scope = this;
+		var scope = this;
 
-		this.loadAjaxPDB( this, url, callback );
+		var loader = new THREE.XHRLoader( scope.manager );
+		loader.setCrossOrigin( this.crossOrigin );
+		loader.load( url, function ( text ) {
 
-	},
-
-	loadAjaxPDB: function ( context, url, callback, callbackProgress ) {
-
-		var xhr = new XMLHttpRequest();
-
-		var length = 0;
-
-		xhr.onreadystatechange = function () {
-
-			if ( xhr.readyState === xhr.DONE ) {
-
-				if ( xhr.status === 200 || xhr.status === 0 ) {
-
-					if ( xhr.responseText ) {
-
-						var json = context.parsePDB( xhr.responseText );
-						context.createModel( json, callback );
-
-					} else {
-
-						console.warn( "THREE.PDBLoader: [" + url + "] seems to be unreachable or file there is empty" );
-
-					}
-
-				} else {
-
-					console.error( "THREE.PDBLoader: Couldn't load [" + url + "] [" + xhr.status + "]" );
-
-				}
-
-			} else if ( xhr.readyState === xhr.LOADING ) {
-
-				if ( callbackProgress ) {
-
-					if ( length === 0 ) {
-
-						length = xhr.getResponseHeader( "Content-Length" );
-
-					}
-
-					callbackProgress( { total: length, loaded: xhr.responseText.length } );
-
-				}
-
-			} else if ( xhr.readyState === xhr.HEADERS_RECEIVED ) {
-
-				length = xhr.getResponseHeader( "Content-Length" );
-
-			}
-
-		};
+			var json = scope.parsePDB( text );
+			scope.createModel( json, onLoad );
 
-		xhr.open( "GET", url, true );
-		if ( xhr.overrideMimeType ) xhr.overrideMimeType( "text/plain; charset=x-user-defined" );
-		xhr.setRequestHeader( "Content-Type", "text/plain" );
-		xhr.send( null );
+		} );
 
 	},