Skip to content

USDZExporter: Refactor to use two stages #31400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2025
Merged

Conversation

mkeblx
Copy link
Contributor

@mkeblx mkeblx commented Jul 13, 2025

Description

This is a refactoring of the exporter to process in two stages: first building up trees of nodes, and then doing the final stringifying (and with the same final output as before, modulo whitespace which is improved). It stops short of fully breaking down properties and leaves most as strings.

This has the significant benefits of making upcoming changes much simpler (like object hierarchy (#31235), just change the tree layout), and in general easier to maintain and extend.

First create node trees, then stringify
@mkeblx mkeblx force-pushed the usdz-exp-refactor branch from 66eb6e5 to 3ef5c92 Compare July 13, 2025 01:34
@mrdoob mrdoob requested a review from Copilot July 13, 2025 02:18
Copy link

@Copilot 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 refactors the USDZExporter to use a two-stage process: first building a tree of USD nodes, then converting that tree to final USD string output. The refactoring maintains the same final output while improving code maintainability and making future changes easier.

  • Introduces a new USDNode class to represent USD nodes with properties, metadata, and children
  • Refactors material, mesh, and camera building functions to create node trees instead of direct string output
  • Consolidates string generation into the USDNode.toString() method for consistent formatting
Comments suppressed due to low confidence (2)

examples/jsm/exporters/USDZExporter.js:679

  • [nitpick] The function name 'buildTextureNodes' is inconsistent with the existing naming pattern. Other functions in the file use 'build' prefix for single objects (buildMaterial, buildCamera, buildMeshObject). Consider renaming to 'buildTextureNodeSet' or 'createTextureNodes' to better reflect that it returns multiple nodes.
	function buildTextureNodes( texture, mapType, color ) {

examples/jsm/exporters/USDZExporter.js:507

  • [nitpick] The function name 'buildMeshNode' is inconsistent with the original 'buildMesh' function it replaces. Since this is a refactoring, consider keeping the original name 'buildMesh' to maintain consistency with other build functions in the codebase.
function buildMeshNode( geometry ) {

@mrdoob
Copy link
Owner

mrdoob commented Jul 13, 2025

Anything from the copilot review that seems worth doing?

@mrdoob mrdoob added this to the r179 milestone Jul 13, 2025
@mkeblx
Copy link
Contributor Author

mkeblx commented Jul 13, 2025

Anything from the copilot review that seems worth doing?

Yes, the metadata handling suggestion makes sense. I simplified in a similar way.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 14, 2025

@mrdoob mrdoob merged commit a3f85f1 into mrdoob:dev Jul 15, 2025
8 checks passed
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