Page MenuHome

T90535: import UDIM textures from USD
ClosedPublic

Authored by Michael Kowalski (makowalski) on Jul 6 2022, 1:42 AM.

Details

Summary

This is a partial fix for T90535. This code was originally reviewed in D13297, but is now split into a separate patch, as suggested by Sybren in that review.

These changes add logic to the USD Preview Surface importer to convert UDIM textures.

I've attached two examples for testing:

usd_simple_udims: A mesh plane with 8 tiled textures. The texture images are of the tile indices, for easy visual verification.

alab_workbench_udim: The workbench model from the Alab scene.


Diff Detail

Repository
rB Blender

Event Timeline

Michael Kowalski (makowalski) requested review of this revision.Jul 6 2022, 1:42 AM
Michael Kowalski (makowalski) created this revision.
Michael Kowalski (makowalski) retitled this revision from USD import: support UDIM textures to T90535: import UDIM textures from USD.Jul 6 2022, 2:04 AM
Michael Kowalski (makowalski) edited the summary of this revision. (Show Details)
Jesse Yurkovich (deadpin) added inline comments.
source/blender/io/usd/intern/usd_reader_material.cc
672

I think this empty check should be moved above the is_udim_path check since that seems a bit more logical.

694

Is the use of an optional really gaining us anything here? I'd vote to just return a blender::Vector from get_udim_tiles and make the udim_tiles.is_empty() check here instead (remove use of optional header entirely)

Michael Kowalski (makowalski) edited the summary of this revision. (Show Details)
  • USD material import code cleanup.
Michael Kowalski (makowalski) marked an inline comment as done.Jul 7 2022, 5:59 AM
Michael Kowalski (makowalski) added inline comments.
source/blender/io/usd/intern/usd_reader_material.cc
672

Thanks, Jesse. Good catch!

694

I would agree that returning blender::vector is more direct and would make the code easier to follow.

@Sybren A. Stüvel (sybren) I believe you proposed returning an optional value in the original review, but that was for a more complex return value std::optional<std::pair<std::string, blender::Vector<int>>>, in a previous version of the function. Would you have any objection to having the function simply return blender::vector?

source/blender/io/usd/intern/usd_reader_material.cc
694

I'd certainly prefer a simpler return type. IMO the only reason to have an std::optional would be to distinguish between hypothetical cases "no data" and "there is data, and the data is empty".

I hesitate to say what I'm about to say... as it might delay this patch further... but, a bug came in literally yesterday for another importer that deals with a form of optional-ness that could impact the design of this code path here actually.

T99502 was filed because we have importers which tolerate missing image texture files differently than what's done here. What happens is that they create the Images anyhow, as-if they were available -- the Image datablock is created, the Image filepath is set, and the material graph is hooked up. This is "nice" because if the actual texture files are really missing blender will 1) tell you about it in some obvious ways, 2) provide mechanisms to find/repair them and, 3) once the textures are restored the scene will magically start working with no re-import required.

This would mean the current code here would have to change a bit to not quit early (not do the BKE_image_load_exists call) and to set various Image options as-if they'd work (like IMA_SRC_TILED with a default tile of 1001 for the UDIM case etc.)

Apparently glTF and OBJ will do this. I'm not sure what Alembic does currently?

I think, in my opinion, this can be iteratively improved after this current patch is accepted since right now loading these textures at all is more important.

Michael Kowalski (makowalski) marked an inline comment as done.Jul 7 2022, 11:35 PM

Thanks for the update, @Jesse Yurkovich (deadpin). It sounds like this new fallback behavior might not be too difficult to implement, so I'll investigate making this change now.

@Jesse Yurkovich (deadpin) I think that's an elegant way to go about things, thanks for letting us know!

No longer wrapping tile indices in std::optional.

Michael Kowalski (makowalski) marked 2 inline comments as done.Jul 14 2022, 2:26 AM

@Jesse Yurkovich (deadpin) I implemented your proposed solution for handling missing tiles with placeholder textures, and it's much nicer, indeed. The problem becomes immediately obvious to the user. Your suggestion is very much appreciated.

However, now I see that your idea of submitting this change in a new patch, after this patch is accepted, might be a better way to go. This is because, to be consistent, I'm now creating placeholder images for all missing textures, not just UDIMS, so it's of a bigger scope than the current task.

@Sybren A. Stüvel (sybren) Would you agree that we can perhaps submit the new missing texture functionality in a new patch, after the current patch is merged?

However, now I see that your idea of submitting this change in a new patch, after this patch is accepted, might be a better way to go. This is because, to be consistent, I'm now creating placeholder images for all missing textures, not just UDIMS, so it's of a bigger scope than the current task.

@Sybren A. Stüvel (sybren) Would you agree that we can perhaps submit the new missing texture functionality in a new patch, after the current patch is merged?

Yes, I think that would be a good approach indeed.

Sybren A. Stüvel (sybren) requested changes to this revision.Aug 1 2022, 12:40 PM

This crashes when importing workbench_udim.usd:

terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct null not valid
fish: Job 1, 'blender import.blend' terminated by signal SIGABRT (Abort)

Unfortunately, it doesn't crash in a debug build, only in a release build, so I can't give more info than this.

I tested on recent master, 3393b7137e247383477eb38d938239fbb9221680.

This revision now requires changes to proceed.Aug 1 2022, 12:40 PM

Never mind, the above crash was an issue with my local build. LGTM!

This revision is now accepted and ready to land.Aug 1 2022, 12:49 PM

Looks ok from my side too (tested with above 2 examples and the smaller version of the A-Lab scene). One nit is to remove the #include <optional> as it's no longer needed. There's no need to re-ask for approval here for that change, just include it with your submit.

  • Removed unneeded include.

Thanks so much for the helpful reviews, Jesse and Sybren!