Skip to content

Commit fc737ba

Browse files
committed
Editor: Support zipped glb and gltfs.
1 parent abce986 commit fc737ba

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

editor/js/Loader.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ var Loader = function ( editor ) {
472472

473473
var zip = new JSZip( contents );
474474

475-
// BLOCKS
475+
// Poly
476476

477477
if ( zip.files[ 'model.obj' ] && zip.files[ 'materials.mtl' ] ) {
478478

@@ -482,6 +482,52 @@ var Loader = function ( editor ) {
482482

483483
}
484484

485+
//
486+
487+
zip.filter( function ( path, file ) {
488+
489+
// GLB
490+
491+
if ( file.name.search( /\.glb$/i ) > - 1 ) {
492+
493+
var loader = new THREE.GLTFLoader( manager );
494+
loader.parse( file.asArrayBuffer(), '', function ( result ) {
495+
496+
editor.execute( new AddObjectCommand( result.scene ) );
497+
498+
} );
499+
500+
}
501+
502+
// GLTF
503+
504+
if ( file.name.search( /\.gltf$/i ) > - 1 ) {
505+
506+
var manager = new THREE.LoadingManager();
507+
manager.setURLModifier( function ( url ) {
508+
509+
var file = zip.files[ url ];
510+
511+
if ( file ) {
512+
513+
var blob = new Blob( [ file.asArrayBuffer() ], { type: 'application/octet-stream' } );
514+
return URL.createObjectURL( blob );
515+
516+
}
517+
518+
} );
519+
520+
var loader = new THREE.GLTFLoader( manager );
521+
loader.parse( file.asText(), '', function ( result ) {
522+
523+
editor.execute( new AddObjectCommand( result.scene ) );
524+
525+
} );
526+
527+
}
528+
529+
} );
530+
485531
}, false );
486532
reader.readAsBinaryString( file );
487533

0 commit comments

Comments
 (0)