Skip to content

Commit 2ce3c15

Browse files
authored
USDLoader: Added USDC file support. (#32704)
1 parent e827e1d commit 2ce3c15

File tree

2 files changed

+3367
-10
lines changed

2 files changed

+3367
-10
lines changed

examples/jsm/loaders/USDLoader.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import { USDAParser } from './usd/USDAParser.js';
88
import { USDCParser } from './usd/USDCParser.js';
99

1010
/**
11-
* A loader for the USDZ format.
11+
* A loader for the USD format (USDA, USDC, USDZ).
1212
*
13-
* USDZ files that use USDC internally are not yet supported, only USDA.
13+
* Supports both ASCII (USDA) and binary (USDC) USD files, as well as
14+
* USDZ archives containing either format.
1415
*
1516
* ```js
16-
* const loader = new USDZLoader();
17-
* const model = await loader.loadAsync( 'saeukkang.usdz' );
17+
* const loader = new USDLoader();
18+
* const model = await loader.loadAsync( 'model.usdz' );
1819
* scene.add( model );
1920
* ```
2021
*
@@ -97,13 +98,18 @@ class USDLoader extends Loader {
9798

9899
for ( const filename in zip ) {
99100

100-
if ( filename.endsWith( 'png' ) ) {
101+
if ( filename.endsWith( 'png' ) || filename.endsWith( 'jpg' ) || filename.endsWith( 'jpeg' ) ) {
101102

102-
const blob = new Blob( [ zip[ filename ] ], { type: 'image/png' } );
103+
const type = filename.endsWith( 'png' ) ? 'image/png' : 'image/jpeg';
104+
const blob = new Blob( [ zip[ filename ] ], { type } );
103105
data[ filename ] = URL.createObjectURL( blob );
104106

105107
}
106108

109+
}
110+
111+
for ( const filename in zip ) {
112+
107113
if ( filename.endsWith( 'usd' ) || filename.endsWith( 'usda' ) || filename.endsWith( 'usdc' ) ) {
108114

109115
if ( isCrateFile( zip[ filename ] ) ) {
@@ -208,6 +214,13 @@ class USDLoader extends Loader {
208214

209215
const file = findUSD( zip );
210216

217+
// Check if the main file is USDC (binary) or USDA (ASCII)
218+
if ( isCrateFile( file ) ) {
219+
220+
return usdc.parse( file.buffer, assets );
221+
222+
}
223+
211224
const text = fflate.strFromU8( file );
212225

213226
return usda.parse( text, assets );

0 commit comments

Comments
 (0)