Преглед изворни кода

USDLoader: Unify USD format handling and add .usd support.

Mr.doob пре 1 месец
родитељ
комит
5532147c69
2 измењених фајлова са 25 додато и 33 уклоњено
  1. 1 21
      editor/js/Loader.js
  2. 24 12
      examples/jsm/loaders/USDLoader.js

+ 1 - 21
editor/js/Loader.js

@@ -622,28 +622,8 @@ function Loader( editor ) {
 
 			}
 
+			case 'usd':
 			case 'usda':
-
-			{
-
-				reader.addEventListener( 'load', async function ( event ) {
-
-					const contents = event.target.result;
-
-					const { USDLoader } = await import( 'three/addons/loaders/USDLoader.js' );
-
-					const group = new USDLoader().parse( contents );
-					group.name = filename;
-
-					editor.execute( new AddObjectCommand( editor, group ) );
-
-				}, false );
-				reader.readAsText( file );
-
-				break;
-
-			}
-
 			case 'usdc':
 			case 'usdz':
 

+ 24 - 12
examples/jsm/loaders/USDLoader.js

@@ -221,30 +221,42 @@ class USDLoader extends Loader {
 
 		}
 
+		const bytes = new Uint8Array( buffer );
+
 		// USDZ
 
-		const zip = fflate.unzipSync( new Uint8Array( buffer ) );
+		if ( bytes[ 0 ] === 0x50 && bytes[ 1 ] === 0x4B ) {
 
-		const assets = parseAssets( zip );
+			const zip = fflate.unzipSync( bytes );
 
-		const { file, basePath } = findUSD( zip );
+			const assets = parseAssets( zip );
 
-		// Compose the main file using USDComposer (works for both USDC and USDA)
-		const composer = new USDComposer();
-		let data;
+			const { file, basePath } = findUSD( zip );
 
-		if ( isCrateFile( file ) ) {
+			const composer = new USDComposer();
+			let data;
 
-			data = usdc.parseData( file.buffer );
+			if ( isCrateFile( file ) ) {
 
-		} else {
+				data = usdc.parseData( file.buffer );
 
-			const text = fflate.strFromU8( file );
-			data = usda.parseData( text );
+			} else {
+
+				const text = fflate.strFromU8( file );
+				data = usda.parseData( text );
+
+			}
+
+			return composer.compose( data, assets, {}, basePath );
 
 		}
 
-		return composer.compose( data, assets, {}, basePath );
+		// USDA (standalone, as ArrayBuffer)
+
+		const composer = new USDComposer();
+		const text = fflate.strFromU8( bytes );
+		const data = usda.parseData( text );
+		return composer.compose( data, {} );
 
 	}
 

粤ICP备19079148号