topical media & game development
mobile-query-three-vendor-three.js-loaders-PDBLoader.js / js
author: alteredq / alteredqualia.com/
THREE.PDBLoader = function ( showStatus ) {
THREE.Loader.call( this, showStatus );
};
THREE.PDBLoader.prototype = new THREE.Loader();
THREE.PDBLoader.prototype.constructor = THREE.PDBLoader;
THREE.PDBLoader.prototype.supr = THREE.Loader.prototype;
THREE.PDBLoader.prototype.load = function ( url, callback ) {
var worker, scope = this;
this.onLoadStart();
this.loadAjaxPDB( this, url, callback );
};
THREE.PDBLoader.prototype.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" );
}
// in context of more complex asset initialization
// do not block on single failed file
// maybe should go even one more level up
context.onLoadComplete();
} 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" );
}
};
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 );
};
// Based on CanvasMol PDB parser
THREE.PDBLoader.prototype.parsePDB = function ( text ) {
function trim( text ) {
return text.replace(/^\s\s*/, '').replace(/\s\s*
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.