Skip to content

Commit 885c2db

Browse files
authored
Editor: Fixed assets lost when importing zipped OBJ/MTL (#28292)
* imports OBJ with textures * set map.name to filename * no filename needed in UITexture
1 parent db4f94b commit 885c2db

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

editor/js/Loader.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -858,16 +858,36 @@ function Loader( editor ) {
858858

859859
const zip = unzipSync( new Uint8Array( contents ) );
860860

861+
const manager = new THREE.LoadingManager();
862+
manager.setURLModifier( function ( url ) {
863+
864+
const file = zip[ url ];
865+
866+
if ( file ) {
867+
868+
console.log( 'Loading', url );
869+
870+
const blob = new Blob( [ file.buffer ], { type: 'application/octet-stream' } );
871+
return URL.createObjectURL( blob );
872+
873+
}
874+
875+
return url;
876+
877+
} );
878+
861879
// Poly
862880

863881
if ( zip[ 'model.obj' ] && zip[ 'materials.mtl' ] ) {
864882

865883
const { MTLLoader } = await import( 'three/addons/loaders/MTLLoader.js' );
866884
const { OBJLoader } = await import( 'three/addons/loaders/OBJLoader.js' );
867885

868-
const materials = new MTLLoader().parse( strFromU8( zip[ 'materials.mtl' ] ) );
886+
const materials = new MTLLoader( manager ).parse( strFromU8( zip[ 'materials.mtl' ] ) );
869887
const object = new OBJLoader().setMaterials( materials ).parse( strFromU8( zip[ 'model.obj' ] ) );
888+
870889
editor.execute( new AddObjectCommand( editor, object ) );
890+
return;
871891

872892
}
873893

@@ -877,24 +897,6 @@ function Loader( editor ) {
877897

878898
const file = zip[ path ];
879899

880-
const manager = new THREE.LoadingManager();
881-
manager.setURLModifier( function ( url ) {
882-
883-
const file = zip[ url ];
884-
885-
if ( file ) {
886-
887-
console.log( 'Loading', url );
888-
889-
const blob = new Blob( [ file.buffer ], { type: 'application/octet-stream' } );
890-
return URL.createObjectURL( blob );
891-
892-
}
893-
894-
return url;
895-
896-
} );
897-
898900
const extension = path.split( '.' ).pop().toLowerCase();
899901

900902
switch ( extension ) {

0 commit comments

Comments
 (0)