Skip to content

USDLoader: Added USDC file support.#32704

Merged
mrdoob merged 17 commits intodevfrom
usdc
Jan 13, 2026
Merged

USDLoader: Added USDC file support.#32704
mrdoob merged 17 commits intodevfrom
usdc

Conversation

@mrdoob
Copy link
Copy Markdown
Owner

@mrdoob mrdoob commented Jan 10, 2026

Related issue: #24574

Description

Implements a USDC (crate format) parser supporting:

  • Geometry: meshes, transforms, face triangulation
  • Materials: UsdPreviewSurface with PBR textures (PNG/JPEG)
  • GeomSubset multi-material meshes
  • Opacity/transparency
  • Skeletal animation (SkinnedMesh, Skeleton, AnimationClip)
  • LZ4 decompression and integer compression decoding

Not yet supported: cameras, lights, variants, references.

Screenshot 2026-01-10 at 12 08 28

(Made with Claude Opus 4.5)

@mrdoob mrdoob added this to the r183 milestone Jan 10, 2026
@mrdoob mrdoob requested a review from Copilot January 10, 2026 04:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for USDC (binary crate format) files to the USDLoader, significantly expanding the loader's capability to handle USD files beyond the existing ASCII (USDA) format support.

Changes:

  • Implements a comprehensive USDC parser with LZ4 decompression and integer compression decoding
  • Adds support for geometry, materials (UsdPreviewSurface), multi-material meshes via GeomSubsets, and PBR textures
  • Updates USDLoader to detect and route USDC files to the new parser

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
examples/jsm/loaders/usd/USDCParser.js New 2656-line parser implementing complete USDC binary format support including LZ4 decompression, integer compression, binary data reading, and Three.js scene building
examples/jsm/loaders/USDLoader.js Updated to detect USDC files via magic header check and route them to the new USDC parser

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examples/jsm/loaders/usd/USDCParser.js Outdated
Comment thread examples/jsm/loaders/usd/USDCParser.js Outdated
Comment thread examples/jsm/loaders/usd/USDCParser.js Outdated
Comment on lines 210 to 221
const file = findUSD( zip );

// Check if the main file is USDC (binary) or USDA (ASCII)
if ( isCrateFile( file ) ) {

return usdc.parse( file.buffer, assets );

}

const text = fflate.strFromU8( file );

return usda.parse( text, assets );
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The findUSD function can return undefined if no matching file is found (e.g., when zip has no .usda/.usdc/.usd file, or when the first file doesn't match any conditions). This would cause errors at line 213 when isCrateFile tries to access file.buffer or at line 219 when fflate.strFromU8 tries to process an undefined file. Consider adding validation to check if file is undefined and throw a descriptive error.

Copilot uses AI. Check for mistakes.

get payload() {

// 48-bit payload: lo (32 bits) + hi lower 16 bits
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The payload calculation uses JavaScript number arithmetic for a 48-bit value. While this should be safe for most USD files, values larger than Number.MAX_SAFE_INTEGER (2^53 - 1) could lose precision. However, for typical file offsets this should be acceptable. Consider adding a comment explaining the limitation if file offsets ever exceed this range.

Suggested change
// 48-bit payload: lo (32 bits) + hi lower 16 bits
// 48-bit payload: lo (32 bits) + hi lower 16 bits.
// This is safe with JavaScript Number arithmetic because 48 bits < 53 bits
// of mantissa precision (Number.MAX_SAFE_INTEGER). If the payload width or
// file offsets are ever extended beyond this range, this calculation will
// lose precision and should be reimplemented (e.g., using BigInt).

Copilot uses AI. Check for mistakes.
Comment thread examples/jsm/loaders/usd/USDCParser.js Outdated
Comment thread examples/jsm/loaders/usd/USDCParser.js Outdated
@mrdoob
Copy link
Copy Markdown
Owner Author

mrdoob commented Jan 11, 2026

We got animations working ✌️

Screen.Recording.2026-01-11.at.19.40.28.mov

@Mugen87
Copy link
Copy Markdown
Collaborator

Mugen87 commented Jan 11, 2026

The drummer asset is cute 😊 .

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 2 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examples/jsm/loaders/usd/USDCParser.js Outdated
Comment thread examples/jsm/loaders/usd/USDCParser.js Outdated
Comment thread examples/jsm/loaders/usd/USDCParser.js Outdated
Comment thread examples/jsm/loaders/usd/USDCParser.js Outdated
Comment thread examples/jsm/loaders/usd/USDCParser.js Outdated
@mrdoob mrdoob requested a review from Copilot January 13, 2026 00:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@mrdoob
Copy link
Copy Markdown
Owner Author

mrdoob commented Jan 13, 2026

Merging this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants