All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
unitTestDelegate.h
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef HDX_UNIT_TEST_DELEGATE
25 #define HDX_UNIT_TEST_DELEGATE
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/sceneDelegate.h"
29 #include "pxr/imaging/hd/tokens.h"
30 #include "pxr/imaging/glf/simpleLight.h"
31 #include "pxr/imaging/pxOsd/tokens.h"
32 
33 #include "pxr/base/gf/vec3f.h"
34 #include "pxr/base/gf/vec3d.h"
35 #include "pxr/base/gf/vec4f.h"
36 #include "pxr/base/gf/vec4d.h"
37 #include "pxr/base/gf/matrix4f.h"
38 #include "pxr/base/gf/matrix4d.h"
39 #include "pxr/base/vt/array.h"
40 #include "pxr/base/tf/staticTokens.h"
41 
42 PXR_NAMESPACE_OPEN_SCOPE
43 
44 template <typename T>
45 static VtArray<T>
46 _BuildArray(T values[], int numValues)
47 {
48  VtArray<T> result(numValues);
49  std::copy(values, values+numValues, result.begin());
50  return result;
51 }
52 
53 class Hdx_UnitTestDelegate : public HdSceneDelegate
54 {
55 public:
56  Hdx_UnitTestDelegate(HdRenderIndex *renderIndex);
57 
58  void SetRefineLevel(int level);
59 
60  // camera
61  void SetCamera(GfMatrix4d const &viewMatrix, GfMatrix4d const &projMatrix);
62  void SetCamera(
63  SdfPath const &id,
64  GfMatrix4d const &viewMatrix,
65  GfMatrix4d const &projMatrix);
66  void AddCamera(SdfPath const &id);
67 
68  // light
69  void AddLight(SdfPath const &id, GlfSimpleLight const &light);
70  void SetLight(SdfPath const &id, TfToken const &key, VtValue value);
71 
72  // draw target
73  void AddDrawTarget(SdfPath const &id);
74  void SetDrawTarget(SdfPath const &id, TfToken const &key, VtValue value);
75 
76  // tasks
77  void AddRenderTask(SdfPath const &id);
78  void AddRenderSetupTask(SdfPath const &id);
79  void AddSimpleLightTask(SdfPath const &id);
80  void AddShadowTask(SdfPath const &id);
81  void AddSelectionTask(SdfPath const &id);
82  void AddDrawTargetTask(SdfPath const &id);
83  void AddDrawTargetResolveTask(SdfPath const &id);
84  void AddPickTask(SdfPath const &id);
85 
86  void SetTaskParam(SdfPath const &id, TfToken const &name, VtValue val);
87  VtValue GetTaskParam(SdfPath const &id, TfToken const &name);
88 
90  void AddInstancer(SdfPath const &id,
91  SdfPath const &parentId=SdfPath(),
92  GfMatrix4f const &rootTransform=GfMatrix4f(1));
93 
94  void SetInstancerProperties(SdfPath const &id,
95  VtIntArray const &prototypeIndex,
96  VtVec3fArray const &scale,
97  VtVec4fArray const &rotate,
98  VtVec3fArray const &translate);
99 
101  void AddMaterial(SdfPath const &id,
102  std::string const &sourceSurface,
103  std::string const &sourceDisplacement,
104  HdMaterialParamVector const &params);
105  void BindMaterial(SdfPath const &rprimId, SdfPath const &materialId);
106 
107  // prims
108  void AddMesh(SdfPath const &id,
109  GfMatrix4d const &transform,
110  VtVec3fArray const &points,
111  VtIntArray const &numVerts,
112  VtIntArray const &verts,
113  bool guide=false,
114  SdfPath const &instancerId=SdfPath(),
115  TfToken const &scheme=PxOsdOpenSubdivTokens->catmark,
116  TfToken const &orientation=HdTokens->rightHanded,
117  bool doubleSided=false);
118 
119  void AddMesh(SdfPath const &id,
120  GfMatrix4d const &transform,
121  VtVec3fArray const &points,
122  VtIntArray const &numVerts,
123  VtIntArray const &verts,
124  PxOsdSubdivTags const &subdivTags,
125  VtValue const &color,
126  HdInterpolation colorInterpolation,
127  VtValue const &opacity,
128  HdInterpolation opacityInterpolation,
129  bool guide=false,
130  SdfPath const &instancerId=SdfPath(),
131  TfToken const &scheme=PxOsdOpenSubdivTokens->catmark,
132  TfToken const &orientation=HdTokens->rightHanded,
133  bool doubleSided=false);
134 
135  void AddCube(SdfPath const &id, GfMatrix4d const &transform,
136  bool guide=false,
137  SdfPath const &instancerId=SdfPath(),
138  TfToken const &scheme=PxOsdOpenSubdivTokens->catmark,
139  VtValue const &color = VtValue(GfVec3f(1,1,1)),
140  HdInterpolation colorInterpolation = HdInterpolationConstant,
141  VtValue const &opacity = VtValue(1.0f),
142  HdInterpolation opacityInterpolation = HdInterpolationConstant);
143 
144  void AddGrid(SdfPath const &id, GfMatrix4d const &transform,
145  bool guide=false, SdfPath const &instancerId=SdfPath());
146 
147  void AddTet(SdfPath const &id, GfMatrix4d const &transform,
148  bool guide=false, SdfPath const &instancerId=SdfPath(),
149  TfToken const &scheme=PxOsdOpenSubdivTokens->catmark);
150 
151  void SetRefineLevel(SdfPath const &id, int level);
152 
153  void SetReprName(SdfPath const &id, TfToken const &reprName);
154 
155  // delegate methods
156  GfRange3d GetExtent(SdfPath const & id) override;
157  GfMatrix4d GetTransform(SdfPath const & id) override;
158  bool GetVisible(SdfPath const& id) override;
159  HdMeshTopology GetMeshTopology(SdfPath const& id) override;
160  VtValue Get(SdfPath const& id, TfToken const& key) override;
161  HdPrimvarDescriptorVector GetPrimvarDescriptors(
162  SdfPath const& id,
163  HdInterpolation interpolation) override;
164  VtIntArray GetInstanceIndices(
165  SdfPath const& instancerId,
166  SdfPath const& prototypeId) override;
167 
168  GfMatrix4d GetInstancerTransform(SdfPath const& instancerId) override;
169  HdDisplayStyle GetDisplayStyle(SdfPath const& id) override;
170  HdReprSelector GetReprSelector(SdfPath const &id) override;
171 
172  SdfPath GetMaterialId(SdfPath const &rprimId) override;
173  std::string GetSurfaceShaderSource(SdfPath const &shaderId) override;
174  std::string GetDisplacementShaderSource(SdfPath const &shaderId) override;
175  HdMaterialParamVector GetMaterialParams(SdfPath const &shaderId) override;
177  SdfPath const &shaderId,
178  TfToken const &paramName) override;
180  SdfPath const &cameraId,
181  TfToken const &paramName) override;
182  HdTextureResource::ID GetTextureResourceID(SdfPath const& textureId)
183  override;
184  HdTextureResourceSharedPtr GetTextureResource(SdfPath const& textureId)
185  override;
186 
187  TfTokenVector GetTaskRenderTags(SdfPath const& taskId) override;
188 
189 private:
190  struct _Mesh {
191  _Mesh() { }
192  _Mesh(TfToken const &scheme,
193  TfToken const &orientation,
194  GfMatrix4d const &transform,
195  VtVec3fArray const &points,
196  VtIntArray const &numVerts,
197  VtIntArray const &verts,
198  PxOsdSubdivTags const &subdivTags,
199  VtValue const &color,
200  HdInterpolation colorInterpolation,
201  VtValue const &opacity,
202  HdInterpolation opacityInterpolation,
203  bool guide,
204  bool doubleSided) :
205  scheme(scheme), orientation(orientation),
206  transform(transform),
207  points(points), numVerts(numVerts), verts(verts),
208  subdivTags(subdivTags), color(color),
209  colorInterpolation(colorInterpolation), opacity(opacity),
210  opacityInterpolation(opacityInterpolation), guide(guide),
211  doubleSided(doubleSided) { }
212 
213  TfToken scheme;
214  TfToken orientation;
215  GfMatrix4d transform;
216  VtVec3fArray points;
217  VtIntArray numVerts;
218  VtIntArray verts;
219  PxOsdSubdivTags subdivTags;
220  VtValue color;
221  HdInterpolation colorInterpolation;
222  VtValue opacity;
223  HdInterpolation opacityInterpolation;
224  bool guide;
225  bool doubleSided;
226  TfToken reprName;
227  };
228 
229  struct _Instancer {
230  _Instancer() { }
231  _Instancer(VtVec3fArray const &scale,
232  VtVec4fArray const &rotate,
233  VtVec3fArray const &translate,
234  GfMatrix4f const &rootTransform) :
235  scale(scale), rotate(rotate), translate(translate),
236  rootTransform(rootTransform) {
237  }
238  VtVec3fArray scale;
239  VtVec4fArray rotate;
240  VtVec3fArray translate;
241  VtIntArray prototypeIndices;
242  GfMatrix4f rootTransform;
243 
244  std::vector<SdfPath> prototypes;
245  };
246  struct _Material {
247  _Material() { }
248  _Material(std::string const &srcSurface,
249  std::string const &srcDisplacement,
250  HdMaterialParamVector const &pms)
251  : sourceSurface(srcSurface)
252  , sourceDisplacement(srcDisplacement)
253  , params(pms) {
254  }
255 
256  std::string sourceSurface;
257  std::string sourceDisplacement;
258  HdMaterialParamVector params;
259  };
260  struct _DrawTarget {
261  };
262  std::map<SdfPath, _Mesh> _meshes;
263  std::map<SdfPath, _Instancer> _instancers;
264  std::map<SdfPath, _Material> _materials;
265  std::map<SdfPath, int> _refineLevels;
266  std::map<SdfPath, _DrawTarget> _drawTargets;
267  int _refineLevel;
268 
269  typedef std::map<SdfPath, SdfPath> SdfPathMap;
270  SdfPathMap _materialBindings;
271 
272  typedef TfHashMap<TfToken, VtValue, TfToken::HashFunctor> _ValueCache;
273  typedef TfHashMap<SdfPath, _ValueCache, SdfPath::Hash> _ValueCacheMap;
274  _ValueCacheMap _valueCacheMap;
275 
276  SdfPath _cameraId;
277 };
278 
279 
280 PXR_NAMESPACE_CLOSE_SCOPE
281 
282 #endif // HDX_UNIT_TEST_DELEGATE
Tags for non-hierarchial subdiv surfaces.
Definition: subdivTags.h:41
Stores a 4x4 matrix of float elements.
Definition: matrix4f.h:88
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:119
virtual HD_API std::string GetSurfaceShaderSource(SdfPath const &materialId)
Returns the surface shader source code for the given material ID.
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
virtual HD_API HdMaterialParamVector GetMaterialParams(SdfPath const &materialId)
Returns the material params for the given material ID.
Describes how the geometry of a prim should be displayed.
Definition: sceneDelegate.h:79
virtual HD_API VtValue Get(SdfPath const &id, TfToken const &key)
Returns a named value.
virtual HD_API SdfPath GetMaterialId(SdfPath const &rprimId)
Returns the material ID bound to the rprim rprimId.
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
virtual HD_API GfMatrix4d GetInstancerTransform(SdfPath const &instancerId)
Returns the instancer transform.
virtual HD_API VtValue GetCameraParamValue(SdfPath const &cameraId, TfToken const &paramName)
Returns a single value for a given camera and parameter.
virtual HD_API GfMatrix4d GetTransform(SdfPath const &id)
Returns the object space transform, including all parent transforms.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Adapter class providing data exchange with the client scene graph.
virtual HD_API std::string GetDisplacementShaderSource(SdfPath const &materialId)
Returns the displacement shader source code for the given material ID.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:438
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
virtual HD_API bool GetVisible(SdfPath const &id)
Returns the authored visible state of the prim.
virtual HD_API HdPrimvarDescriptorVector GetPrimvarDescriptors(SdfPath const &id, HdInterpolation interpolation)
Returns descriptors for all primvars of the given interpolation type.
virtual HD_API HdMeshTopology GetMeshTopology(SdfPath const &id)
Gets the topological mesh data for a given prim.
virtual HD_API VtValue GetMaterialParamValue(SdfPath const &materialId, TfToken const &paramName)
Returns a single value for the given material and named parameter.
virtual HD_API GfRange3d GetExtent(SdfPath const &id)
Gets the axis aligned bounds of a prim.
virtual HD_API HdReprSelector GetReprSelector(SdfPath const &id)
Returns the authored repr (if any) for the given prim.
virtual HD_API HdTextureResource::ID GetTextureResourceID(SdfPath const &textureId)
Returns the texture resource ID for a given texture ID.
virtual HD_API HdTextureResourceSharedPtr GetTextureResource(SdfPath const &textureId)
Returns the texture resource for a given texture ID.
Describes one or more authored display representations for an rprim.
Definition: repr.h:48
virtual HD_API VtIntArray GetInstanceIndices(SdfPath const &instancerId, SdfPath const &prototypeId)
Gets the extracted indices array of the prototype id used in the instancer.
virtual HD_API HdDisplayStyle GetDisplayStyle(SdfPath const &id)
Returns the refinement level for the given prim in the range [0,8].
Topology data for meshes.
Definition: meshTopology.h:55
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182