kcoley / gltf2usd

command-line utility for converting glTF 2.0 models to USD
MIT License
263 stars 39 forks source link

"apply texture transform if necessary" #133

Closed spiderworm closed 5 years ago

spiderworm commented 5 years ago

Hi kcoley,

Thanks for this great lib. I have noticed that, with certain of my glTF files, conversion takes considerably longer. I narrowed it down to GLTFImage.py, to the "if" block on line 91 that writes a new version of the file to the directory that is a rotation or crop of the original. It's preceded with the following comment:

"#apply texture transform if necessary"

My slower glTF files in question seem to have "KHR_texture_transform"s in place, and it appears this is what triggers the execution of that code block, which writes new images, which makes the overall conversion slower. So I wanted to check with you, do you know why this transform is necessary? Is there some limit to the USD spec that it doesn't support texture transformations? Do you know if this could theoretically be done in a different way that doesn't require creation of new images?

Appreciate your help.

kcoley commented 5 years ago

Hi @spiderworm Currently the USD spec does not have support for texture transformations, so the exporter works around this by generating a new texture that "bakes" the transform.

There is discussion in the USD interest group forum for adding support for this: https://groups.google.com/forum/#!msg/usd-interest/BoG8RYzyqOM/2YkgxHCFAAAJ

I could provide a flag to not generate a new texture, though the resulting USD may look incorrect. Would this be useful?

kcoley commented 5 years ago

@spiderworm another option would be to generate texture transformed texture coordinate channels and remap to them in the generated USD file. Though I am not sure if any application would be able to load this file reliably.

spiderworm commented 5 years ago

Hi @kcoley,

Thanks so much for the link to that discussion! I was trying to find any status from Pixar about implementing that feature and wasn't to find anything on my own, so this was very useful.

Adding a flag to not generate new textures sounds useful as it will help me eliminate it as a pain point when doing profiling (which is what I'm currently focused on) even tho the resulting models will have texture problems. But if you don't add it, I can always add it to my own branch I'm working off of.

I'm not sure if the other approach you're suggesting would work well or not either. I'm probably not yet quite qualified to make a call on that.

I wonder if parallelization of that image processing could speed things up. Is this something you've considered?

kcoley commented 5 years ago

@spiderworm no problem! I can add the flag support later today or tomorrow to toggle texture generation.

I wonder if parallelization of that image processing could speed things up. Is this something you've considered?

I thought about adding OpenGL shader support to generate a new texture on GPU, though the set up for this could get messy and I am not sure if all users of the library have access to GPUs. If texture transform support were to be released to USD, that could be an export option, which would speed things up, but other applications would have to add support to understand the feature.

kcoley commented 5 years ago

@spiderworm I just merged an update to toggle texture transform generation. To disable, you can use the flag --no-generate_texture_transform_texture

spiderworm commented 5 years ago

Thank you!