three.js - Import Zip Files -
i'm using obj format, obj heavy download it, reason, upload obj files in zip, then, viewer unzip , call function objloader. know what's best way it? thanks, rafa
problem solved :
1) add jszip script page 2) goto objmtlloader.js (about line 33) , place these 10 lines uncompress zip (assuming file.zip contains file.obj) inside loader.load function
loader.load( url, function ( text ) { if (url.split('/').pop().split('.')[1] == 'zip'){ //- uncompress url e.g. http:// .... / ptero.zip -> ptero.obj - // zip should contain 1 file ! // uncompression object var new_zip = new jszip(); // uncompress new_zip.load(text); // single file name convention filename = url.split('/').pop().split('.')[0] + ".obj"; // file content text text = new_zip.file(filename).astext(); } //-------------------------------------------- var object = scope.parse( text );
3) add these 2 lines in xhrloader in three.js loads binary when extension zip:
three.xhrloader.prototype = { constructor: three.xhrloader, load: function ( url, onload, onprogress, onerror ) { var scope = this; var cached = scope.cache.get( url ); if ( cached !== undefined ) { if ( onload ) onload( cached ); return; } var request = new xmlhttprequest(); request.open( 'get', url, true ); // ---------- zipped obj ------------ if ( url.split('.').pop() == 'zip') request.responsetype = "arraybuffer"; //-------------------------------------- request.addeventlistener( 'load', function ( event ) { scope.cache.add( url, this.response ); ...
Comments
Post a Comment