-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add thumbnail generation script #64
Add thumbnail generation script #64
Conversation
beersandrew
commented
Nov 2, 2023
- added python script for thumbnail generation
- added readme
- original repo: https://github.com/beersandrew/usd-thumbnail-generator
- added script - added readme - original repo: https://github.com/beersandrew/usd-thumbnail-generator
- added updates to height / width - fixed typo in windows example call
I think there is a bug with I'm trying to generate a thumbnail for an ALAB asset but the bbox is not being calculated properly. If I do something like Also, is there a way to force usdrender to render the render purpose or provide a rendersettigns prim? |
I think this BBoxCache behavior is not a bug. Specifying default does not imply render and/or proxy. This matches hydra's behavior where if you don't explicitly say you want proxy and/or render, you won't see proxy and/or render purpose geometry (but in hydra, usdrecord accepts a |
Oh, and also it's generally a bad idea to use |
- moved hardcoded names to global constants - added --apply-thumbnail argument to control if the thumbnail is written back to the asset, added to ReadMe - replaced axis modification to modify the camera & lights rather than the asset - set BBox calc to timeCode 0.0 by default instead of default
Thanks @beersandrew ! Nothing further from me. |
Hi, I have been doing some testing. This is looking awesome! Could we set the
Some things I found that could be improved:
Sorry for the long text 😅 |
- Set the drawMode to default, in case the given asset is in cardsMode, don't take a thumbnail of cards - in the case of zipping, zip all assets, rather than just the given usd file + thumbnail file - code cleanup with globals, suffixes - Don't create a thumbnail.usda file in the case of applying the thumbnail directly - delete thumbnail.usda in the case of zipping everything together given a usdz file
Makes sense, I've made a commit to add this.
I unfortunately have never dealt with purposes, I see the usdrecord function has the following complexity argument:
This doesn't seem to be the same thing as purposes to me, do you have a sample argument (and maybe a sample file?) I could test with purposes with usdrecord? I've held off on any purposes changes until I understand this more clearly.
Thanks, I've added this.
Thanks, I've added this.
Thanks, I've added all of these.
This is to create the folder to hold the thumbnails if the folder does not exist already, if it already exists then just ignore it. I could add some code here to delete the thumbnail and the folder in the case of creating a usdz result file, however this would require checking if there are other thumbnails in the same folder before deleting the folder, which I can do, but I think the folder itself makes sense, and it doesn't make sense to always delete it because that's where the result file is saved. To me there doesn't seem to be any necessary action here, however if that delete logic is valuable to you I can try to add it, I just worry about someone running it in some case, has a ton of thumbnails in the directory and blows away the directory, I guess checking that it's empty would protect against this though...
Thank you for all the suggestions! I really appreciate it 🙏 |
Thanks for the changes! About the purposes, we will need to add a new arg that gets a list of strings. usdrecord def take_snapshot(image_name):
renderer = get_renderer()
cmd = ['usdrecord', '--camera', 'MainCamera', '--imageWidth', str(args.width), '--renderer', renderer, DEFAULT_THUMBNAIL_FILENAME, image_name]
if args.purposes:
cmd.extend(['--purposes', args.purposes])
run_os_specific_command(cmd)
os.remove(DEFAULT_THUMBNAIL_FILENAME)
return image_name bbox DEFAULT_BBOX_PURPOSES = [UsdGeom.Tokens.default_]
def pseudo_converter(args.purposes):
if args.purpose:
tokenized_purposes = []
for purpose in args.purpose:
tokenized_purpose = convert(purpose)
tokenized_purposes.append(tokenized_purpose)
else:
tokenized_purposes = DEFAULT_BBOX_PURPOSES
return tokenized_purposes
bboxCache = UsdGeom.BBoxCache(Usd.TimeCode(0.0), pseudo_converter(args.purposes)) Well, that's a suggestion only, implement it in the way that you think is best. 👍
Gocha! it looks like the join path was not working properly with full paths. (at least for me) def generate_thumbnail(usd_file, verbose, extension):
if verbose:
print("Step 1: Setting up the camera...")
subject_stage = Usd.Stage.Open(usd_file)
setup_camera(subject_stage, usd_file)
if verbose:
print("Step 2: Taking the snapshot...")
image_path = create_image_filename(usd_file, extension)
return take_snapshot(image_path) def create_image_filename(input_path, extension):
if not isinstance(input_path, Path):
input_path = Path(input_path)
if THUMBNAIL_FOLDER_NAME:
thumbnail_folder_dir = Path().joinpath(input_path.parent, THUMBNAIL_FOLDER_NAME)
else:
thumbnail_folder_dir = input_path.parent
thumbnail_folder_dir.mkdir(parents=True, exist_ok=True)
return str(Path().joinpath(thumbnail_folder_dir, input_path.name).with_suffix("." + extension)).replace("\\", "/") |
- added support to specify which render purposes to be included in the bbox calculation as well as the render - added support for passing in a fully qualified usd path - small refactoring - updated docs
I've updated the branch with these changes
is this in the official docs somewhere? are there other arguments that you know about that aren't listed in the docs? Let me know if the code changes make sense the way I did them and let me know if there are any other improvements you can think of |
I only knew about the Also, I don't know if this is outdated or if any other conversations have happened about thumbnails, but I think that we could name the renders folder to thumbnails as it matches a bit better with the asset-structure-guidelines.md |
Agreed! Updated the default folder name, we did discuss this in the wg meeting and I forgot about it, thanks! |
BTW I found the argument in
This is an extract of the file
|
Excited to see this in action! @beersandrew Could you mark the conversations above as Resolved, wherever there is a "Resolve conversation" button, so the reviewers will know if any thing is still outstanding? |
@meshula Everything is currently resolved now, remaining comments are on the entire PR so I can't resolve them |
Ok cool, no worries :) |
Great work, Andy! |