-
Notifications
You must be signed in to change notification settings - Fork 10
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
Enhancement: Render / Turntable #30
Closed
Closed
Changes from 13 commits
Commits
Show all changes
101 commits
Select commit
Hold shift + click to select a range
cd7fc55
first commit, adding playblast module
Sasbom 32b90dc
added utility and expanded on renderplayblast args and processing
Sasbom 663f958
parsing complexity argument better, fixed walrus bugs
Sasbom eb84c53
slight refactor
Sasbom d04aad3
ConverFramePlaceholderblabla does internal None checking, so removed …
Sasbom bbac50c
Merge branch 'BigRoy:main' into enhancement/usdview_render_turntable
Sasbom 8b9f7e6
Removed hardcoded complexity presets, added sanity checking for rende…
Sasbom b6c429c
Complete framerecorder initialization setup
Sasbom 623f105
Merge branch 'BigRoy:main' into enhancement/usdview_render_turntable
Sasbom 13f62c4
resources_rc added
Sasbom 6d1e89e
added menu, functionality for snapshot. Doesn't work as intended with…
Sasbom 94716ab
snapshot fix! Works now. Still needs major cleanup.
Sasbom 14e5e00
Merge branch 'BigRoy:main' into enhancement/usdview_render_turntable
Sasbom 028fdd4
changed logic in case no camera is selected to match usdrecord
Sasbom 583f35b
Merge branch 'enhancement/usdview_render_turntable' of https://github…
Sasbom d7f4b9d
house cleaning, suggested bugfixes
Sasbom 09a041b
slowly but surely adding methods to deal with cameras
Sasbom d69188d
added distance calculation function while downstairs neighbours are d…
Sasbom 962ab0c
finished clipping planes function.
Sasbom b86915c
finished calculate camera position function.
Sasbom 6b293db
cross platform catch for non-OGL native systems (macosx)
Sasbom 1b934c1
Completed routine to add a framing camera!
Sasbom 6cc9386
Merge branch 'BigRoy:main' into enhancement/usdview_render_turntable
Sasbom e0314a1
added fit parameter to add some padding
Sasbom f93c85b
micro commit to change a variable name in a function to something mor…
Sasbom 4bbdb2d
Created render_util.turntable,
Sasbom 271917b
bugfixes + exposed turntable render as temp functionality.
Sasbom 60801ee
bugfix: adjusted transforms when framing camera as turntable camera
Sasbom b00d12f
added some utility to deal with the frame argument
Sasbom cdf43c0
made tuples_to_frames_string.tuple_gen way more sane
Sasbom 9800a4b
made functions way less ridiculous
Sasbom 218e7c1
refactored some things, added dialog helpers
Sasbom fa016b3
notes
Sasbom 09a3104
top level function padding
Sasbom 02be61e
Merge branch 'BigRoy:main' into enhancement/usdview_render_turntable
Sasbom 38c53fa
Proposal: add traverse_prim_descendants to lib.usd
Sasbom 8a1991f
cleaned up test
Sasbom fc4be96
struggling to do reparenting properly
Sasbom 5f8ad2d
am no longer confused by reparenting, we're gonna do references.
Sasbom 766e5c4
building out new reference based logic for turntable from file functi…
Sasbom 3230460
fleshed out turntable_from_file to working order.
Sasbom bc8e23d
cleanup integration pass 1
Sasbom 13a8545
Cleanup finalized
Sasbom 8b46c65
cleared up some comments
Sasbom 880e376
removed deprecated functions
Sasbom 21b9868
updated comments
Sasbom e6289cb
updated comments
Sasbom 290b14e
Merge branch 'enhancement/usdview_render_turntable' of https://github…
Sasbom 8960936
A preset turntable USD file has been added.
Sasbom 7123fdb
Cosmetics / cleanup
BigRoy 3603058
Merge remote-tracking branch 'sasbom/enhancement/usdview_render_turnt…
BigRoy 5125573
Merge pull request #2 from BigRoy/enhancement/usdview_render_turntabl…
Sasbom fbb7ab7
Changed template file to .usda, fixed up minor things in turntable.
Sasbom 6730c38
division per element nessecary, fixed string error in dialog
Sasbom 7568426
fix unwanted inclusion
Sasbom b19cf1e
Remove prims made in Render menu
Sasbom 69ebc5d
clear bbox before stuffing it full of other things
Sasbom b6e5441
update gitignore to ignore temp folder
Sasbom 1ef9f02
fix ignore of temp folder
Sasbom 224de08
automated cleanup at the end of turntable render
Sasbom 52bfb19
small changes, tiny checks for turntable from file functionality.
Sasbom da9e1e7
Added a guide to setting up your own turntable.
Sasbom 910ff5c
Set up dialog and editor to dislay it
Sasbom 6b65c0c
Merge branch 'enhancement/usdview_render_turntable' of https://github…
Sasbom 8f81456
base layout style for PlayblastDialog
Sasbom cb2d3af
fleshing out dialog for playblasting
Sasbom 5699639
further refined playblast menu
Sasbom d36af8e
added destination selection
Sasbom 49866d2
added pre and post hooks to later hook into with the turntable
Sasbom 5143d37
updated playblast dialog with area to select purposes
Sasbom 38937ef
fixed some things, added progress bar and actual playblast functional…
Sasbom 2918587
modified PlayblastDialog to be more flexible when inheriting
Sasbom e2060d1
Complexity combobox fixed and moved to be above render engine, sepera…
Sasbom 25b84a2
added support for camera path argument in turntable_from_file
Sasbom 160a512
Added search for cameras in stage from file
Sasbom 09e1809
Pass along RenderReportable in turntable
Sasbom a8c4d35
started implementing turntable dialog
Sasbom ec89f96
added functionality for updating camera from file when finished typing.
Sasbom d6ede87
make sure playblast button on turntable doesn't do anything as it's n…
Sasbom 52400cc
logic pass TurntableDialog
Sasbom 0a6763e
adress minor fuckup
Sasbom 65ca6b3
exposed fit parameter to dialog for generated framing cameras
Sasbom 0e309e6
aux functionality for rendering turntables, laid out functionality
Sasbom 3a58851
implemented stage rotation turntable in dialog
Sasbom f47ab3b
implemented camera rotation in dialog
Sasbom 006a688
added better cleanup for camera around stage turntable in dialog, fix…
Sasbom 2bf24b8
implemented turntable from file
Sasbom ec8d45a
cleaned up render menu in editor
Sasbom b543b86
minor cleanup
Sasbom f68ae5f
small fixes
Sasbom 2feabcd
First pass of cleanup.
Sasbom 4d0e808
added context managers for managing open scenes and deleting files
Sasbom 5e85507
ExitStack shenanigans
Sasbom c104d5d
ExitStack shenanigans part 2: the big bugfix
Sasbom 5fbaccb
fixed potential -1 index on camera box in playblast dialog
Sasbom daf480f
removed unneeded import to weakref
Sasbom 30463db
exposed select functions in `__all__` and added missing stage context…
Sasbom 184cc32
fixed spacing from top
Sasbom 7f0720c
removed unnessecary import
Sasbom c51e2af
modified size, disallowed resizing of playblast/turntable dialogs
Sasbom 57828f6
bugfix, making sure that right parameters get passed around and that …
Sasbom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# module named render_util to not collide in names with houdini's render.py | ||
BigRoy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from .playblast import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
# Playblast framework | ||
# Inspired by: Prism, usdrecord | ||
|
||
# NOTES: | ||
# pxr.UsdViewq.ExportFreeCameraToStage will export the camera from the view (a FreeCamera/ pxr.Gf.Camera, purely OpenGL) | ||
|
||
from pxr import Usd, UsdGeom | ||
from pxr import UsdAppUtils | ||
from pxr import Tf, Sdf | ||
|
||
from pxr.Usdviewq.stageView import StageView | ||
BigRoy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from viewer import CustomStageView | ||
|
||
from qtpy import QtCore | ||
|
||
from typing import Union | ||
import logging | ||
BigRoy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def _setupOGLWidget(width : int, height : int, samples : int = 4): | ||
BigRoy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Utility function to produce a Qt openGL widget capable of catching | ||
the output of a render | ||
""" | ||
|
||
from qtpy import QtOpenGL | ||
|
||
# format object contains information about the Qt OpenGL buffer. | ||
QGLformat = QtOpenGL.QGLFormat() | ||
QGLformat.setSampleBuffers(True) # Enable multisample buffer | ||
QGLformat.setSamples(samples) # default samples is 4 / px | ||
|
||
GLWidget = QtOpenGL.QGLWidget(QGLformat) | ||
GLWidget.setFixedSize(QtCore.QSize(width,height)) | ||
|
||
GLWidget.makeCurrent() # bind widget buffer as target for OpenGL operations. | ||
|
||
return GLWidget | ||
|
||
def findCameras(stage : Usd.Stage, TraverseAll = True) -> list[UsdGeom.Camera]: | ||
""" | ||
Return all camera primitives. | ||
TraverseAll is on by default. This means that inactive cameras will also be shown. | ||
""" | ||
|
||
if TraverseAll: | ||
gen = stage.TraverseAll() | ||
else: | ||
gen = stage.Traverse() | ||
|
||
cams = [c for c in gen if UsdGeom.Camera(c)] | ||
return cams | ||
BigRoy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def cameraFromView(stage : Usd.Stage, stageview : Union[StageView, CustomStageView], name : str = "playblastCam") -> UsdGeom.Camera: | ||
""" Catches a stage view whether it'd be from the custom viewer or from the baseclass and calls the export to stage function.""" | ||
stageview.ExportFreeCameraToStage(stage,name) | ||
return UsdGeom.Camera.Get(stage,Sdf.Path(f"/{name}")) | ||
|
||
# Source: UsdAppUtils.colorArgs.py | ||
def getColorArgs(): | ||
return ("disabled","sRGB","openColorIO") | ||
BigRoy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def getComplexityLevels(): | ||
""" | ||
Returns a generator that iterates through all registered complexity presets in UsdAppUtils.complexityArgs | ||
""" | ||
from pxr.UsdAppUtils.complexityArgs import RefinementComplexities as Complex | ||
return (item.name for item in Complex._ordered) | ||
|
||
def getAllRenderEngineNames(): | ||
""" | ||
Returns a generator that will iterate through all names of Render Engine Plugin / Hydra Delegates | ||
""" | ||
from pxr.UsdImagingGL import Engine as En | ||
return (En.GetRendererDisplayName(pluginId) for pluginId in En.GetRendererPlugins()) | ||
|
||
def getRenderPlugin(enginestr : str): | ||
from pxr.UsdImagingGL import Engine as En | ||
for plug in En.GetRendererPlugins(): | ||
if enginestr == En.GetRendererDisplayName(plug): | ||
return plug | ||
return None | ||
|
||
def checkRenderEngineName(enginestr : str) -> Union[str, None]: | ||
plugnames = getAllRenderEngineNames() | ||
if enginestr in plugnames: | ||
return enginestr | ||
return None | ||
|
||
def renderPlayblast(stage : Usd.Stage, outputpath : str, frames : str, width : int, | ||
camera : UsdGeom.Camera = None, complexity : Union[str,int] = "High", | ||
renderer : str = "GL", colormode : str = "sRGB"): | ||
from pxr.UsdAppUtils.framesArgs import FrameSpecIterator, ConvertFramePlaceholderToFloatSpec | ||
from pxr.UsdAppUtils.complexityArgs import RefinementComplexities as Complex | ||
from pxr import UsdUtils | ||
|
||
# rectify pathname for use in .format with path.format(frame = timeCode.getValue())gi | ||
if not (outputpath := ConvertFramePlaceholderToFloatSpec(outputpath)): | ||
raise ValueError("Invalid/Empty filepath for rendering") | ||
|
||
# ensure right complexity object is picked. | ||
# the internal _RefinementComplexity.value is used to set rendering quality | ||
if isinstance(complexity,str): | ||
# ensure key correctness | ||
complexity = complexity.lower() # set all to lowercase | ||
complexity = complexity.title() # Uppercase Each Word (In Case Of "Very High") | ||
preset_names = getComplexityLevels() | ||
if complexity not in preset_names: | ||
raise ValueError(f"Value: {complexity} entered for complexity is not valid") | ||
|
||
complex_level = Complex.fromName(complexity) | ||
elif isinstance(complexity,int): | ||
complexity = min(max(complexity,0),3) # clamp to range of 0-3, 4 elements | ||
complex_level = Complex._ordered[complexity] | ||
|
||
complex_level = complex_level.value | ||
|
||
# validate render engine | ||
if not checkRenderEngineName(renderer): | ||
raise ValueError(f"Render engine arguement invalid") | ||
renderer = getRenderPlugin(renderer) | ||
|
||
# TEMP: pick first found camera | ||
if not camera: | ||
camera = next(findCameras(stage), None) | ||
if not camera: | ||
# Same procedure as default for pxr.UsdAppUtils.cameraArgs.py | ||
path = Sdf.Path(UsdUtils.GetPrimaryCameraName()) | ||
camera = UsdAppUtils.GetCameraAtPath(stage, path) | ||
|
||
if colormode not in getColorArgs(): | ||
raise ValueError("Color correction mode specifier is invalid.") | ||
|
||
# Set up OpenGL FBO to write to within Widget | ||
# Actual size doesn't matter | ||
# it does need to be stored in a variable though, otherwise it'll be collected | ||
ogl_widget = _setupOGLWidget(width,width) | ||
|
||
# Create FrameRecorder | ||
frameRecorder = UsdAppUtils.FrameRecorder() | ||
frameRecorder.SetRendererPlugin(renderer) | ||
frameRecorder.SetImageWidth(width) # Only width is needed, heigh will be computer from camera properties. | ||
frameRecorder.SetComplexity(complex_level) | ||
frameRecorder.SetColorCorrectionMode(colormode) | ||
#frameRecorder.SetIncludedPurposes(["default","render","proxy","guide"]) # set to all purposes for now. | ||
|
||
# Use Usds own frame specification parser | ||
# The following are examples of valid FrameSpecs: | ||
# 123 - 101:105 - 105:101 - 101:109x2 - 101:110x2 - 101:104x0.5 | ||
frame_iterator = FrameSpecIterator(frames) | ||
|
||
if not frame_iterator: | ||
frame_iterator = [Usd.TimeCode.EarliestTime()] | ||
|
||
for timeCode in frame_iterator: | ||
currentframe = outputpath.format(frame = timeCode.GetValue()) | ||
print(currentframe) | ||
try: | ||
print("attempting render") | ||
frameRecorder.Record(stage, camera, timeCode, currentframe) | ||
print("Done!") | ||
except Tf.ErrorException as e: | ||
logging.error("Recording aborted due to the following failure at time code {0}: {1}".format(timeCode, str(e))) | ||
BigRoy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
break | ||
|
||
# Set reference to None so that it can be collected before Qt context. | ||
frameRecorder = None | ||
BigRoy marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8 - check your linter. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really should ; _ ;
On the topic of PEP8 on a different note, I know that snake_case is preferable for functions,
I just look at Qt and Usd and can't help but copy their style to maintain consistency.
That's my reasoning for naming functions the way I do. I will rename them all to be snake case, I will never more be tempted by the demons hiding in libraries.