HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
frameRecorder.h
Go to the documentation of this file.
1 //
2 // Copyright 2019 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_IMAGING_USD_APP_UTILS_FRAME_RECORDER_H
8 #define PXR_USD_IMAGING_USD_APP_UTILS_FRAME_RECORDER_H
9 
10 /// \file usdAppUtils/frameRecorder.h
11 
12 #include "pxr/pxr.h"
14 
15 #include "pxr/base/tf/diagnostic.h"
16 #include "pxr/base/tf/token.h"
17 #include "pxr/usd/usd/stage.h"
18 #include "pxr/usd/usd/timeCode.h"
19 #include "pxr/usd/usdGeom/camera.h"
21 
22 #include <string>
23 
24 
26 
27 
28 /// \class UsdAppUtilsFrameRecorder
29 ///
30 /// A utility class for recording images of USD stages.
31 ///
32 /// UsdAppUtilsFrameRecorder uses Hydra to produce recorded images of a USD
33 /// stage looking through a particular UsdGeomCamera on that stage at a
34 /// particular UsdTimeCode. The images generated will be effectively the same
35 /// as what you would see in the viewer in usdview.
36 ///
37 /// Note that it is assumed that an OpenGL context has already been setup for
38 /// the UsdAppUtilsFrameRecorder if OpenGL is being used as the underlying HGI
39 /// device. This is not required for Metal or Vulkan.
41 {
42 public:
43  /// The \p rendererPluginId argument indicates the renderer plugin that
44  /// Hyrda should use. If the empty token is passed in, a default renderer
45  /// plugin will be chosen depending on the value of \p gpuEnabled.
46  /// The \p gpuEnabled argument determines if the UsdAppUtilsFrameRecorder
47  /// instance will allow Hydra to use the GPU to produce images.
50  const TfToken& rendererPluginId = TfToken(),
51  bool gpuEnabled = true);
52 
53  /// Gets the ID of the Hydra renderer plugin that will be used for
54  /// recording.
56  return _imagingEngine.GetCurrentRendererId();
57  }
58 
59  /// Sets the Hydra renderer plugin to be used for recording.
60  /// This also resets the presentation flag on the HdxPresentTask to false,
61  /// to avoid the need for an OpenGL context.
62  ///
63  /// Note that the renderer plugins that may be set will be restricted if
64  /// this UsdAppUtilsFrameRecorder instance has disabled the GPU.
65  bool SetRendererPlugin(const TfToken& id) {
66  const bool succeeded = _imagingEngine.SetRendererPlugin(id);
67  _imagingEngine.SetEnablePresentation(false);
68 
69  return succeeded;
70  }
71 
72  /// Sets the path to the render pass prim to use.
73  ///
74  /// \note If there is a render settings prim designated by the
75  /// render pass prim via renderSource, it must also be set
76  /// with SetActiveRenderSettingsPrimPath().
79 
80  /// Sets the path to the render settings prim to use.
81  ///
82  /// \see SetActiveRenderPassPrimPath()
85 
86  /// Sets the width of the recorded image.
87  ///
88  /// The height of the recorded image will be computed using this value and
89  /// the aspect ratio of the camera used for recording.
90  ///
91  /// The default image width is 960 pixels.
92  void SetImageWidth(const size_t imageWidth) {
93  if (imageWidth == 0u) {
94  TF_CODING_ERROR("Image width cannot be zero");
95  return;
96  }
97  _imageWidth = imageWidth;
98  }
99 
100  /// Sets the level of refinement complexity.
101  ///
102  /// The default complexity is "low" (1.0).
103  void SetComplexity(const float complexity) {
104  _complexity = complexity;
105  }
106 
107  /// Sets the color correction mode to be used for recording.
108  ///
109  /// By default, color correction is disabled.
111  void SetColorCorrectionMode(const TfToken& colorCorrectionMode);
112 
113  /// Turns the built-in camera light on or off.
114  ///
115  /// When on, this will add a light at the camera's origin.
116  /// This is sometimes called a "headlight".
118  void SetCameraLightEnabled(bool cameraLightEnabled);
119 
120  /// Sets the camera visibility of dome lights.
121  ///
122  /// When on, dome light textures will be drawn to the background as if
123  /// mapped onto a sphere infinitely far away.
125  void SetDomeLightVisibility(bool domeLightsVisible);
126 
127  /// Sets the UsdGeomImageable purposes to be used for rendering
128  ///
129  /// We will __always__ include "default" purpose, and by default,
130  /// we will also include UsdGeomTokens->proxy. Use this method
131  /// to explicitly enumerate an alternate set of purposes to be
132  /// included along with "default".
134  void SetIncludedPurposes(const TfTokenVector& purposes);
135 
136  /// Records an image and writes the result to \p outputImagePath.
137  ///
138  /// The recorded image will represent the view from \p usdCamera looking at
139  /// the imageable prims on USD stage \p stage at time \p timeCode.
140  ///
141  /// If \p usdCamera is not a valid camera, a camera will be computed
142  /// to automatically frame the stage geometry.
143  ///
144  /// When we are using a RenderSettings prim, the generated image will be
145  /// written to the file indicated on the connected RenderProducts,
146  /// instead of the given \p outputImagePath. Note that in this case the
147  /// given \p usdCamera will later be overridden by the one authored on the
148  /// RenderSettings Prim.
149  ///
150  /// Returns true if the image was generated and written successfully, or
151  /// false otherwise.
153  bool Record(
154  const UsdStagePtr& stage,
155  const UsdGeomCamera& usdCamera,
156  const UsdTimeCode timeCode,
157  const std::string& outputImagePath);
158 
159 private:
160  UsdImagingGLEngine _imagingEngine;
161  size_t _imageWidth;
162  float _complexity;
163  TfToken _colorCorrectionMode;
164  TfTokenVector _purposes;
165  SdfPath _renderPassPrimPath;
166  SdfPath _renderSettingsPrimPath;
167  bool _cameraLightEnabled;
168  bool _domeLightsVisible;
169 };
170 
171 
173 
174 
175 #endif
USDIMAGINGGL_API TfToken GetCurrentRendererId() const
Return the id of the currently used renderer plugin.
USDAPPUTILS_API UsdAppUtilsFrameRecorder(const TfToken &rendererPluginId=TfToken(), bool gpuEnabled=true)
bool SetRendererPlugin(const TfToken &id)
Definition: frameRecorder.h:65
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
#define TF_CODING_ERROR
#define USDAPPUTILS_API
Definition: api.h:23
USDAPPUTILS_API void SetColorCorrectionMode(const TfToken &colorCorrectionMode)
USDIMAGINGGL_API bool SetRendererPlugin(TfToken const &id)
Definition: token.h:70
USDAPPUTILS_API bool Record(const UsdStagePtr &stage, const UsdGeomCamera &usdCamera, const UsdTimeCode timeCode, const std::string &outputImagePath)
USDAPPUTILS_API void SetCameraLightEnabled(bool cameraLightEnabled)
USDAPPUTILS_API void SetActiveRenderPassPrimPath(SdfPath const &path)
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
Definition: path.h:273
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
USDAPPUTILS_API void SetDomeLightVisibility(bool domeLightsVisible)
TfToken GetCurrentRendererId() const
Definition: frameRecorder.h:55
USDAPPUTILS_API void SetIncludedPurposes(const TfTokenVector &purposes)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
void SetImageWidth(const size_t imageWidth)
Definition: frameRecorder.h:92
USDAPPUTILS_API void SetActiveRenderSettingsPrimPath(SdfPath const &path)
USDIMAGINGGL_API void SetEnablePresentation(bool enabled)
void SetComplexity(const float complexity)