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 PXR_IMAGING_HDX_UNIT_TEST_DELEGATE_H
25 #define PXR_IMAGING_HDX_UNIT_TEST_DELEGATE_H
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 AddMaterialResource(SdfPath const &id,
102  VtValue materialResource);
103 
104  void BindMaterial(SdfPath const &rprimId, SdfPath const &materialId);
105 
106  // prims
107  void AddMesh(SdfPath const &id,
108  GfMatrix4d const &transform,
109  VtVec3fArray const &points,
110  VtIntArray const &numVerts,
111  VtIntArray const &verts,
112  bool guide=false,
113  SdfPath const &instancerId=SdfPath(),
114  TfToken const &scheme=PxOsdOpenSubdivTokens->catmark,
115  TfToken const &orientation=HdTokens->rightHanded,
116  bool doubleSided=false);
117 
118  void AddMesh(SdfPath const &id,
119  GfMatrix4d const &transform,
120  VtVec3fArray const &points,
121  VtIntArray const &numVerts,
122  VtIntArray const &verts,
123  PxOsdSubdivTags const &subdivTags,
124  VtValue const &color,
125  HdInterpolation colorInterpolation,
126  VtValue const &opacity,
127  HdInterpolation opacityInterpolation,
128  bool guide=false,
129  SdfPath const &instancerId=SdfPath(),
130  TfToken const &scheme=PxOsdOpenSubdivTokens->catmark,
131  TfToken const &orientation=HdTokens->rightHanded,
132  bool doubleSided=false);
133 
134  void AddCube(SdfPath const &id, GfMatrix4d const &transform,
135  bool guide=false,
136  SdfPath const &instancerId=SdfPath(),
137  TfToken const &scheme=PxOsdOpenSubdivTokens->catmark,
138  VtValue const &color = VtValue(GfVec3f(1,1,1)),
139  HdInterpolation colorInterpolation = HdInterpolationConstant,
140  VtValue const &opacity = VtValue(1.0f),
141  HdInterpolation opacityInterpolation = HdInterpolationConstant);
142 
143  void AddGrid(SdfPath const &id, GfMatrix4d const &transform,
144  bool guide=false, SdfPath const &instancerId=SdfPath());
145 
146  void AddTet(SdfPath const &id, GfMatrix4d const &transform,
147  bool guide=false, SdfPath const &instancerId=SdfPath(),
148  TfToken const &scheme=PxOsdOpenSubdivTokens->catmark);
149 
150  void SetRefineLevel(SdfPath const &id, int level);
151 
152  void SetReprName(SdfPath const &id, TfToken const &reprName);
153 
154  // delegate methods
155  GfRange3d GetExtent(SdfPath const & id) override;
156  GfMatrix4d GetTransform(SdfPath const & id) override;
157  bool GetVisible(SdfPath const& id) override;
158  HdMeshTopology GetMeshTopology(SdfPath const& id) override;
159  VtValue Get(SdfPath const& id, TfToken const& key) override;
160  HdPrimvarDescriptorVector GetPrimvarDescriptors(
161  SdfPath const& id,
162  HdInterpolation interpolation) override;
163  VtIntArray GetInstanceIndices(
164  SdfPath const& instancerId,
165  SdfPath const& prototypeId) override;
166 
167  GfMatrix4d GetInstancerTransform(SdfPath const& instancerId) override;
168  HdDisplayStyle GetDisplayStyle(SdfPath const& id) override;
169  HdReprSelector GetReprSelector(SdfPath const &id) override;
170 
171  SdfPath GetMaterialId(SdfPath const &rprimId) override;
172  VtValue GetMaterialResource(SdfPath const &materialId) override;
173 
175  SdfPath const &cameraId,
176  TfToken const &paramName) override;
177  HdTextureResource::ID GetTextureResourceID(SdfPath const& textureId)
178  override;
179  HdTextureResourceSharedPtr GetTextureResource(SdfPath const& textureId)
180  override;
181 
182  TfTokenVector GetTaskRenderTags(SdfPath const& taskId) override;
183 
184 private:
185  struct _Mesh {
186  _Mesh() { }
187  _Mesh(TfToken const &scheme,
188  TfToken const &orientation,
189  GfMatrix4d const &transform,
190  VtVec3fArray const &points,
191  VtIntArray const &numVerts,
192  VtIntArray const &verts,
193  PxOsdSubdivTags const &subdivTags,
194  VtValue const &color,
195  HdInterpolation colorInterpolation,
196  VtValue const &opacity,
197  HdInterpolation opacityInterpolation,
198  bool guide,
199  bool doubleSided) :
200  scheme(scheme), orientation(orientation),
201  transform(transform),
202  points(points), numVerts(numVerts), verts(verts),
203  subdivTags(subdivTags), color(color),
204  colorInterpolation(colorInterpolation), opacity(opacity),
205  opacityInterpolation(opacityInterpolation), guide(guide),
206  doubleSided(doubleSided) { }
207 
208  TfToken scheme;
209  TfToken orientation;
210  GfMatrix4d transform;
211  VtVec3fArray points;
212  VtIntArray numVerts;
213  VtIntArray verts;
214  PxOsdSubdivTags subdivTags;
215  VtValue color;
216  HdInterpolation colorInterpolation;
217  VtValue opacity;
218  HdInterpolation opacityInterpolation;
219  bool guide;
220  bool doubleSided;
221  TfToken reprName;
222  };
223 
224  struct _Instancer {
225  _Instancer() { }
226  _Instancer(VtVec3fArray const &scale,
227  VtVec4fArray const &rotate,
228  VtVec3fArray const &translate,
229  GfMatrix4f const &rootTransform) :
230  scale(scale), rotate(rotate), translate(translate),
231  rootTransform(rootTransform) {
232  }
233  VtVec3fArray scale;
234  VtVec4fArray rotate;
235  VtVec3fArray translate;
236  VtIntArray prototypeIndices;
237  GfMatrix4f rootTransform;
238 
239  std::vector<SdfPath> prototypes;
240  };
241  struct _DrawTarget {
242  };
243  std::map<SdfPath, _Mesh> _meshes;
244  std::map<SdfPath, _Instancer> _instancers;
245  std::map<SdfPath, VtValue> _materials;
246  std::map<SdfPath, int> _refineLevels;
247  std::map<SdfPath, _DrawTarget> _drawTargets;
248  int _refineLevel;
249 
250  typedef std::map<SdfPath, SdfPath> SdfPathMap;
251  SdfPathMap _materialBindings;
252 
253  typedef TfHashMap<TfToken, VtValue, TfToken::HashFunctor> _ValueCache;
254  typedef TfHashMap<SdfPath, _ValueCache, SdfPath::Hash> _ValueCacheMap;
255  _ValueCacheMap _valueCacheMap;
256 
257  SdfPath _cameraId;
258 };
259 
260 
261 PXR_NAMESPACE_CLOSE_SCOPE
262 
263 #endif // PXR_IMAGING_HDX_UNIT_TEST_DELEGATE_H
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:117
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
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.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:433
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 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