Skip to content

Conversation

@judubu
Copy link
Contributor

@judubu judubu commented Jul 31, 2021

Purpose of this PR

Ticket/Jira #:
https://jira.unity3d.com/browse/USDU-3
https://jira.unity3d.com/browse/USDU-10

USD geometric Primvars can be given different kind of interpolation across the uv space of a surface primitive:

  • constant: one value per-prim
  • uniform: one value per-face
  • vertex/varying: one value per-vertex
  • facevarying: one value per-vertex per-face

Each primvar can also be individually indexed for data-compression purpose.

This is an issue for Unity which requires all attributes of a mesh to be either interpolated per vertex or per-vertex per-face.
As a consequence it forces us to sanitize the data on the way in before being pushed to GameObjects.

The sanitization was previously done in the MeshImporter right before setting the Unity mesh buffers which was single threaded and made it impossible to properly cross check all attributes arrays for their interpolation value.

This PR introduces a way to perform sanitization of the Mesh and XForm data right after deserialization while using the job system to lessen the impact of interpolation conversion. For that a new ISanitizable interface and 2 new classes SanitizedMeshSample and XFormMeshSample have been added and the jobified ReadAllJob struct have been modified to provide sanitization service after deserialization.

The sanitization code takes care of:
- xform conversion
- triangulation
- de-indexation of attributes
- attribute scope conversion

As a consequence the MeshImporter has been greatly simplified.

The SkeletonImporter has been changed and the JointWeights and JointIndices are now deserialized/loaded by the MeshImporter to avoid aan extra mesh deserialization/sanitization.

Testing

Functional Testing status:

The sanitization service has almost 100% coverage but not the MeshImporter itself.

@cguer You should check the import with all the regular suspect (kitchen, human female, walking teapot ) and do a before after.

Performance Testing status:

I quickly profile the changes and they are a little bit slower both for static and animated data. Although GC has been greatly reduced. I'll update with the actual numbers after my PTO.

Overall Product Risks

Complexity:

High

Halo Effect:

High

Additional information

Note to reviewers:

Check the SanitizedMeshSample for the actual sanitization code and the MeshImporter to see how the sanitized data is pushed to Unity Meshes.
There are some minor changes to the deserialization process to flag colors as actual primvars which give us access to the indices and interpolation values.
Check the test usda file to get a feel for the kind of crappy edge case that can come up and if I forgot anything.

Reminder:

  • Add entry in CHANGELOG.md (if applicable)

Copy link
Contributor

@clusty clusty left a comment

Choose a reason for hiding this comment

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

Only comment was around need for both: MeshSample and SanitizedMeshSample & friends classes.

judubu added 4 commits August 24, 2021 15:16
Sanitizing the USD Meshes and XForms to Unity standards is now done by the sample itself right after deserialization. This has the
benefit to run in jobs and to simplify the MeshImporter code greatly.
Sanitization code takes care of:
    - xform conversion
    - triangulation
    - de-indexation of attributes
    - attribute scope conversion

The SkeletonImporter has been changed and the JointWeights and JointIndices are now deserialized/loaded by the MeshImporter to gain a whole extra mesh deserialization/sanitization.
MeshImporter was always changing handedness regardless of the importOptions.

Cameras were not sanitized so I added a new SanitizedCameraSample
@judubu judubu force-pushed the USDU-3/03_mesh_importer_refactor branch from eda421b to 08f7228 Compare August 26, 2021 18:29
Base automatically changed from USDU-3/02_add_type_alias_support to dev August 31, 2021 12:58
Copy link
Contributor

@jcowles jcowles left a comment

Choose a reason for hiding this comment

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

Wow, this change is incredible :)

It's clear that a massive amount of effort went into this, really nice work!

I have a few minor comments, but overall it totally makes sense and is a great simplification.

Copy link
Contributor

@cguer cguer left a comment

Choose a reason for hiding this comment

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

QA approved 👍!

Tested on:

  • 2021.2.0b10 (Windows + HDRP)

Sorry for the delay 🙈 ...

@judubu judubu merged commit 16a9a06 into dev Sep 27, 2021
@judubu judubu deleted the USDU-3/03_mesh_importer_refactor branch September 27, 2021 17:12
@vickycl vickycl mentioned this pull request Jan 13, 2023
1 task
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.

5 participants