提交 e8eaefc3 编写于 作者: M Mr.doob

KMZLoader: Handle images with manager.setURLModifier.

上级 13e9ff25
......@@ -28,63 +28,75 @@ THREE.KMZLoader.prototype = {
parse: function ( data ) {
var zip = new JSZip( data ); // eslint-disable-line no-undef
var manager = new THREE.LoadingManager();
manager.setURLModifier( function ( url ) {
// console.log( zip );
var image;
// var xml = new DOMParser().parseFromString( zip.file( 'doc.kml' ).asText(), 'application/xml' );
zip.filter( function ( path, file ) {
function loadImage( image ) {
if ( path.substr( - url.length ) === url ) {
var path = decodeURI( image.init_from );
image = file;
// Hack to support relative paths
path = path.replace( '../', '' );
}
var regex = new RegExp( path + '$' );
var files = zip.file( regex );
} );
// console.log( image, files );
if ( image ) {
if ( files.length ) {
console.log( 'Loading', url );
var file = files[ 0 ];
var blob = new Blob( [ file.asArrayBuffer() ], { type: 'application/octet-binary' } );
image.build.src = URL.createObjectURL( blob );
var blob = new Blob( [ image.asArrayBuffer() ], { type: 'application/octet-stream' } );
return URL.createObjectURL( blob );
}
}
return url;
} );
// load collada
//
var collada;
var zip = new JSZip( data ); // eslint-disable-line no-undef
var files = zip.file( /dae$/i );
zip.filter( function ( path, file ) {
if ( files.length ) {
var extension = file.name.split( '.' ).pop().toLowerCase();
var file = files[ 0 ];
switch ( extension ) {
var collada = new THREE.ColladaLoader().parse( file.asText() );
/*
case 'kml':
// fix images
var xml = new DOMParser().parseFromString( file.asText(), 'application/xml' );
var images = collada.library.images;
break;
*/
for ( var name in images ) {
case 'dae':
loadImage( images[ name ] );
var loader = new THREE.ColladaLoader( manager );
collada = loader.parse( file.asText() );
break;
}
} );
if ( collada ) {
return collada;
}
} else {
console.error( 'KMZLoader: Couldn\'t find .dae file.' );
console.error( 'KMZLoader: Couldn\'t find .dae file.' );
return { scene: new THREE.Group() };
return {
scene: new THREE.Group()
};
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册