HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HUSD_Scene.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Side Effects Software Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * NAME: HUSD_Scene.h (HUSD Library, C++)
17  *
18  * COMMENTS: Scene info for the native Houdini viewport renderer
19  */
20 #ifndef HUSD_Scene_h
21 #define HUSD_Scene_h
22 
23 #include <pxr/pxr.h>
24 
25 #include "HUSD_API.h"
26 #include <UT/UT_Lock.h>
27 #include <UT/UT_LinkList.h>
28 #include <UT/UT_Map.h>
29 #include <UT/UT_NonCopyable.h>
30 #include <UT/UT_StringArray.h>
31 #include <UT/UT_StringMap.h>
32 #include <UT/UT_StringSet.h>
33 #include <UT/UT_IntrusivePtr.h>
34 #include <UT/UT_Vector2.h>
35 #include <SYS/SYS_Types.h>
36 #include <GT/GT_Primitive.h>
37 #include "HUSD_PrimHandle.h"
38 #include "HUSD_HydraPrim.h"
39 #include "HUSD_Overrides.h"
40 
42 class XUSD_ViewerDelegate;
44 class HdRenderIndex;
45 class HdRenderParam;
47 
48 class HUSD_HydraCamera;
49 class HUSD_HydraGeoPrim;
50 class HUSD_HydraLight;
51 class HUSD_HydraPrim;
52 class HUSD_HydraMaterial;
53 class HUSD_DataHandle;
54 class husd_SceneTree;
55 class husd_SceneNode;
56 class husd_ConsolidatedPrims;
57 
58 
63 
64 /// Scene information for the native viewport renderer
66 {
67 public:
68  HUSD_Scene();
69  virtual ~HUSD_Scene();
70 
71  UT_StringMap<HUSD_HydraGeoPrimPtr> &geometry() { return myDisplayGeometry; }
72  UT_StringMap<HUSD_HydraCameraPtr> &cameras() { return myCameras; }
73  UT_StringMap<HUSD_HydraLightPtr> &lights() { return myLights; }
75 
76  // all of these return true if the list was modified, false if the serial
77  // matched;
78  bool fillGeometry(UT_Array<HUSD_HydraGeoPrimPtr> &array,
79  int64 &list_serial);
80  bool fillLights(UT_Array<HUSD_HydraLightPtr> &array,
81  int64 &list_serial);
82  bool fillCameras(UT_Array<HUSD_HydraCameraPtr> &array,
83  int64 &list_serial);
84 
85  UT_StringHolder lookupPath(int id, bool allow_instances = true) const;
86  int lookupGeomId(const UT_StringRef &path);
87  UT_StringHolder resolveID(int id, bool allow_instances) const;
88 
89  // Hydra generated selection ids, set & query.
90  void setRenderID(const UT_StringRef &path, int id);
91  void clearRenderIDs();
92  int lookupRenderID(const UT_StringRef &path) const;
93  UT_StringHolder lookupRenderPath(int id) const;
94  int convertRenderID(int id) const;
95 
96  int getParentInstancer(int inst_id, bool topmost) const;
97 
98  static PXR_NS::XUSD_ViewerDelegate *newDelegate();
99  static void freeDelegate(PXR_NS::XUSD_ViewerDelegate *del);
100 
101  static void pushScene(HUSD_Scene *scene);
102  static void popScene(HUSD_Scene *scene);
103  static bool hasScene();
104 
105  void addGeometry(HUSD_HydraGeoPrim *geo, bool new_geo);
106  void removeGeometry(HUSD_HydraGeoPrim *geo);
107 
108  void addDisplayGeometry(HUSD_HydraGeoPrim *geo);
109  void removeDisplayGeometry(HUSD_HydraGeoPrim *geo);
110 
111  virtual void addCamera(HUSD_HydraCamera *cam, bool new_cam);
112  virtual void removeCamera(HUSD_HydraCamera *cam);
113 
114  virtual void addLight(HUSD_HydraLight *light, bool new_light);
115  virtual void removeLight(HUSD_HydraLight *light);
116 
117  virtual void addMaterial(HUSD_HydraMaterial *mat);
118  virtual void removeMaterial(HUSD_HydraMaterial *mat);
119  const UT_StringRef &lookupMaterial(int id) const;
120 
121  void addInstancer(const UT_StringRef &path,
122  PXR_NS::XUSD_HydraInstancer *instancer);
123  void removeInstancer(const UT_StringRef &path);
124  PXR_NS::XUSD_HydraInstancer *getInstancer(const UT_StringRef &path);
125 
126  static const UT_StringHolder &viewportRenderPrimToken();
127 
128  // Render Setting Prims don't exist in Hydra. The view places these
129  // here for easier interchange between high level objects.
130  const UT_StringArray &renderPrimNames() const { return myRenderPrimNames; }
131  bool setRenderPrimNames(const UT_StringArray &names);
132  const UT_StringRef &defaultRenderPrim() const { return myDefaultRenderPrim;}
134  { myDefaultRenderPrim = path;}
135  const UT_StringRef &currentRenderPrim() const { return myCurrentRenderPrim;}
137  { myCurrentRenderPrim = path;}
138  const UT_StringRef &renderPrimCamera() const { return myRenderPrimCamera; }
139  void setRenderPrimCamera(const UT_StringRef &camera);
140 
141  UT_Vector2I renderPrimResolution() const { return myRenderPrimRes; }
142  void setRenderPrimResolution(UT_Vector2I res) {myRenderPrimRes=res;}
143 
145  {
150  ADJUST_PIXEL_ASPECT
151  };
152  void setRenderPrimConform(ConformPolicy p) { myConformPolicy = p; }
153  ConformPolicy getRenderPrimConform() const { return myConformPolicy; }
154  void adjustAperture(fpreal &apv, fpreal caspect, fpreal iaspect);
155 
156  void deferUpdates(bool defer) { myDeferUpdate = defer; }
157  bool isDeferredUpdate() const { return myDeferUpdate; }
158 
159  void consolidateMesh(const GT_PrimitiveHandle &mesh,
160  const UT_BoundingBoxF &bbox,
161  int prim_id,
162  int mat_id,
163  int dirty_bits,
164  HUSD_HydraPrim::RenderTag tag,
165  bool left_handed,
166  bool auto_gen_nml,
167  UT_Array<UT_BoundingBox> &instance_bbox,
168  int instancer_id);
169  void removeConsolidatedPrim(int id);
170  void selectConsolidatedPrim(int id);
171 
172  void setPrimCount(int64 pcount) { myPrimCount = pcount; }
173  int64 getPrimCount() const { return myPrimCount; }
174 
175  HUSD_HydraGeoPrimPtr findConsolidatedPrim(int id) const;
176 
177  // Volumes
178  const UT_StringSet &volumesUsingField(const UT_StringRef &field) const;
179  void addVolumeUsingField(const UT_StringHolder &volume,
180  const UT_StringHolder &field);
181  void removeVolumeUsingFields(const UT_StringRef &volume);
182 
183  // Selections. A highlight is a temporary selection which can be turned into
184  // a selection in various ways.
185  void addToHighlight(int id);
186  void addPathToHighlight(const UT_StringRef &path);
187  void clearHighlight();
188 
189  void setHighlightAsSelection();
190  void addHighlightToSelection();
191  void removeHighlightFromSelection();
192  void toggleHighlightInSelection();
193  void intersectHighlightWithSelection();
194  bool clearSelection();
195 
196  bool selectParents();
197  bool selectChildren(bool all_children); // false = first child only
198  bool selectSiblings(bool next_sibling); // false = prev sibling
199  bool recallPrevSelection();
200  bool recallNextSelection();
201  void clearStashedSelections();
202 
203  void setSelection(const UT_StringArray &paths,
204  bool stash_selection = true);
205  const UT_StringArray &getSelectionList();
206  void redoSelectionList();
207 
208  // Convert a pattern to a selection.
209  void convertSelection(const char *selection_pattern,
211 
212  bool hasInstanceSelections();
213  // Remove any non-prim (instance) selections.
214  bool removeInstanceSelections();
215  // Remove any non-instance (prim) selections.
216  bool removePrimSelections();
217  // Trim instances to the nesting level.
218  void selectInstanceLevel(int nest_lvl);
219 
220  bool hasSelection() const;
221  bool hasHighlight() const;
222  bool isSelected(int id) const;
223  bool isSelected(const HUSD_HydraPrim *prim) const;
224  bool isHighlighted(int id) const;
225  bool isHighlighted(const HUSD_HydraPrim *prim) const;
226  void setHighlight(const UT_StringArray &paths);
227 
228  int64 highlightID() const { return myHighlightID; }
229  int64 selectionID() const { return mySelectionID; }
230 
231  static int getMaxGeoIndex();
232 
233  // bumped when a geo prim is added or removed.
234  int64 getGeoSerial() const { return myGeoSerial; }
235  int64 getCameraSerial() const { return myCamSerial; }
236  int64 getLightSerial() const { return myLightSerial; }
237 
238  // bumped when any prim has Sync() called.
239  int64 getModSerial() const { return myModSerial; }
240  void bumpModSerial() { myModSerial++; }
241 
242  enum PrimType
243  {
244  INVALID_TYPE = 0,
245 
254  ROOT
255  };
256  PrimType getPrimType(int id) const;
257 
258  int getOrCreateID(const UT_StringRef &path,
259  PrimType type = GEOMETRY);
260 
261  int getOrCreateInstanceID(const UT_StringRef &path,
262  const UT_StringRef &instancer,
263  const UT_StringRef &prototype);
264 
265  void setStage(const HUSD_DataHandle &data,
266  const HUSD_ConstOverridesPtr &overrides);
267 
268  PXR_NS::HdRenderIndex *renderIndex() { return myRenderIndex; }
269  void setRenderIndex(PXR_NS::HdRenderIndex *ri) { myRenderIndex = ri; }
270 
271  PXR_NS::HdRenderParam *renderParam() { return myRenderParam; }
272  void setRenderParam(PXR_NS::HdRenderParam *rp) { myRenderParam = rp; }
273 
274  // Debugging only... Do not use in production code.
275  HUSD_PrimHandle getPrim(const UT_StringHolder &path) const;
276 
278  {
280  CATEGORY_SHADOW
281  };
282  void addCategory(const UT_StringRef &name, LightCategory cat);
283  void removeCategory(const UT_StringRef &name,LightCategory cat);
284  bool isCategory(const UT_StringRef &name, LightCategory cat);
285 
286  void pendingRemovalGeom(const UT_StringRef &path,
287  HUSD_HydraGeoPrimPtr prim);
288  HUSD_HydraGeoPrimPtr fetchPendingRemovalGeom(const UT_StringRef &path);
289  void pendingRemovalCamera(const UT_StringRef &path,
290  HUSD_HydraCameraPtr prim);
291  HUSD_HydraCameraPtr fetchPendingRemovalCamera(const UT_StringRef &path);
292  void pendingRemovalLight(const UT_StringRef &path,
293  HUSD_HydraLightPtr prim);
294  HUSD_HydraLightPtr fetchPendingRemovalLight(const UT_StringRef &path);
295 
296  void postUpdate();
297  void processConsolidatedMeshes(bool finalize);
298  void clearInstances(int instr_id, const UT_StringRef &proto_id);
299 
300  void debugPrintTree();
301  void debugPrintSelection();
302 protected:
303  virtual void geometryDisplayed(HUSD_HydraGeoPrim *, bool) {}
304  bool selectionModified(int id);
305  bool selectionModified(husd_SceneNode *pnode);
306  UT_StringHolder instanceIDLookup(const UT_StringRef &pick_path,
307  int path_id) const;
308 
309  void stashSelection();
310  bool makeSelection(const UT_Map<int,int> &selection,
311  bool validate);
312  void enlargeInstanceSelection(const UT_Map<int,int> &selection,
313  UT_Map<int,int> &extra_selection);
314  int getIDForPrim(const UT_StringRef &path,
315  PrimType &return_prim_type,
316  bool create_path_id = false);
317 
318  // Update the tree for all instancers referring to prims, not point instances
319  void updateInstanceRefPrims();
320  void clearPendingRemovalPrims();
321 
343 
360 
365 
368 
373 
374  PXR_NS::HdRenderIndex *myRenderIndex; // TMP, hopefuly
375  PXR_NS::HdRenderParam *myRenderParam; // TMP, hopefuly
376 
379 
380  husd_SceneTree *myTree;
381  husd_ConsolidatedPrims *myPrimConsolidator;
382 
385 
388 };
389 
390 #endif
const UT_StringRef & defaultRenderPrim() const
Definition: HUSD_Scene.h:132
ConformPolicy getRenderPrimConform() const
Definition: HUSD_Scene.h:153
UT_StringHolder myDefaultRenderPrim
Definition: HUSD_Scene.h:342
GT_API const UT_StringHolder selection
husd_SceneTree * myTree
Definition: HUSD_Scene.h:380
UT_StringMap< PXR_NS::XUSD_HydraInstancer * > myInstancers
Definition: HUSD_Scene.h:383
int64 mySelectionID
Definition: HUSD_Scene.h:351
const UT_StringRef & currentRenderPrim() const
Definition: HUSD_Scene.h:135
int64 getCameraSerial() const
Definition: HUSD_Scene.h:235
GR_API GR_AttribMask hasSelection(const GR_UpdateParms &p)
Returns the selection type in p.geometry.
GLuint const GLchar * name
Definition: glew.h:1814
UT_Lock myDisplayLock
Definition: HUSD_Scene.h:361
UT_LinkList myStashedSelection
Definition: HUSD_Scene.h:369
UT_StringArray mySelectionArray
Definition: HUSD_Scene.h:347
husd_ConsolidatedPrims * myPrimConsolidator
Definition: HUSD_Scene.h:381
void setRenderPrimConform(ConformPolicy p)
Definition: HUSD_Scene.h:152
virtual void geometryDisplayed(HUSD_HydraGeoPrim *, bool)
Definition: HUSD_Scene.h:303
UT_Vector2I renderPrimResolution() const
Definition: HUSD_Scene.h:141
Scene information for the native viewport renderer.
Definition: HUSD_Scene.h:65
UT_StringMap< HUSD_HydraMaterialPtr > & materials()
Definition: HUSD_Scene.h:74
HUSD_DataHandle myStage
Definition: HUSD_Scene.h:377
UT_StringMap< HUSD_HydraLightPtr > myLights
Definition: HUSD_Scene.h:330
int64 selectionID() const
Definition: HUSD_Scene.h:229
UT_Map< int, int > myRenderIDtoGeomID
Definition: HUSD_Scene.h:325
#define HUSD_API
Definition: HUSD_API.h:32
UT_StringMap< int > myLightLinkCategories
Definition: HUSD_Scene.h:366
UT_StringMap< HUSD_HydraGeoPrimPtr > myPendingRemovalGeom
Definition: HUSD_Scene.h:333
int64 myPrimCount
Definition: HUSD_Scene.h:386
UT_StringMap< HUSD_HydraGeoPrimPtr > & geometry()
Definition: HUSD_Scene.h:71
UT_Map< int, PXR_NS::XUSD_HydraInstancer * > myInstancerIDs
Definition: HUSD_Scene.h:384
UT_StringMap< HUSD_HydraCameraPtr > myPendingRemovalCamera
Definition: HUSD_Scene.h:334
void bumpModSerial()
Definition: HUSD_Scene.h:240
UT_StringMap< HUSD_HydraCameraPtr > myCameras
Definition: HUSD_Scene.h:329
int64 getModSerial() const
Definition: HUSD_Scene.h:239
UT_StringMap< HUSD_HydraLightPtr > & lights()
Definition: HUSD_Scene.h:73
ALEMBIC_EXPORT OMaterialSchema addMaterial(Abc::OObject iObject, const std::string &iPropName=MATERIAL_PROPNAME)
UT_StringMap< int > myShadowLinkCategories
Definition: HUSD_Scene.h:367
PXR_NS::HdRenderParam * renderParam()
Definition: HUSD_Scene.h:271
UT_StringMap< int > myRenderIDs
Definition: HUSD_Scene.h:324
UT_Array< HUSD_HydraCameraPtr > myDuplicateCam
Definition: HUSD_Scene.h:337
UT_StringHolder myRenderPrimCamera
Definition: HUSD_Scene.h:340
void setCurrentRenderPrim(const UT_StringRef &path)
Definition: HUSD_Scene.h:136
void setPrimCount(int64 pcount)
Definition: HUSD_Scene.h:172
UT_Array< HUSD_HydraLightPtr > myDuplicateLight
Definition: HUSD_Scene.h:338
const UT_StringRef & renderPrimCamera() const
Definition: HUSD_Scene.h:138
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
UT_LinkNode * myCurrentRecalledSelection
Definition: HUSD_Scene.h:371
PXR_NS::HdRenderParam * myRenderParam
Definition: HUSD_Scene.h:375
GLuint const GLuint * names
Definition: glew.h:2690
Wrapper around hboost::intrusive_ptr.
long long int64
Definition: SYS_Types.h:116
int64 getLightSerial() const
Definition: HUSD_Scene.h:236
UT_Lock myMaterialLock
Definition: HUSD_Scene.h:363
void setRenderPrimResolution(UT_Vector2I res)
Definition: HUSD_Scene.h:142
int64 getPrimCount() const
Definition: HUSD_Scene.h:173
bool mySelectionArrayNeedsUpdate
Definition: HUSD_Scene.h:349
int64 myHighlightID
Definition: HUSD_Scene.h:350
UT_StringMap< int64 > myMatIDs
Definition: HUSD_Scene.h:346
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
HUSD_ConstOverridesPtr myStageOverrides
Definition: HUSD_Scene.h:378
UT_IntrusivePtr< HUSD_HydraCamera > HUSD_HydraCameraPtr
Definition: HUSD_Scene.h:60
UT_IntrusivePtr< HUSD_HydraLight > HUSD_HydraLightPtr
Definition: HUSD_Scene.h:61
const UT_StringArray & renderPrimNames() const
Definition: HUSD_Scene.h:130
int64 myLightSerial
Definition: HUSD_Scene.h:355
GLsizei const GLchar *const * path
Definition: glew.h:6461
UT_Map< int, int > myHighlight
Definition: HUSD_Scene.h:344
GLfloat GLfloat p
Definition: glew.h:16321
void deferUpdates(bool defer)
Definition: HUSD_Scene.h:156
int64 mySelectionResolveSerial
Definition: HUSD_Scene.h:356
void setRenderIndex(PXR_NS::HdRenderIndex *ri)
Definition: HUSD_Scene.h:269
UT_Map< int, UT_StringHolder > myMaterialIDs
Definition: HUSD_Scene.h:332
UT_StringMap< HUSD_HydraLightPtr > myPendingRemovalLight
Definition: HUSD_Scene.h:335
UT_StringMap< HUSD_HydraGeoPrimPtr > myGeometry
Definition: HUSD_Scene.h:327
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
int mySelectionSerial
Definition: HUSD_Scene.h:387
PXR_NS::HdRenderIndex * renderIndex()
Definition: HUSD_Scene.h:268
fpreal64 fpreal
Definition: SYS_Types.h:277
UT_Map< int, int > mySelection
Definition: HUSD_Scene.h:345
UT_Lock myCategoryLock
Definition: HUSD_Scene.h:364
bool isDeferredUpdate() const
Definition: HUSD_Scene.h:157
UT_Lock myLightCamLock
Definition: HUSD_Scene.h:362
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:83
int64 getGeoSerial() const
Definition: HUSD_Scene.h:234
UT_Map< int, UT_StringHolder > myRenderPaths
Definition: HUSD_Scene.h:323
void setRenderParam(PXR_NS::HdRenderParam *rp)
Definition: HUSD_Scene.h:272
GLenum array
Definition: glew.h:9066
UT_StringArray myRenderPrimNames
Definition: HUSD_Scene.h:339
UT_Vector2I myRenderPrimRes
Definition: HUSD_Scene.h:358
int64 myCurrentSelectionStashed
Definition: HUSD_Scene.h:372
int64 mySelectionArrayID
Definition: HUSD_Scene.h:348
UT_StringMap< HUSD_HydraCameraPtr > & cameras()
Definition: HUSD_Scene.h:72
PXR_NS::HdRenderIndex * myRenderIndex
Definition: HUSD_Scene.h:374
UT_StringMap< HUSD_HydraGeoPrimPtr > myDisplayGeometry
Definition: HUSD_Scene.h:328
UT_IntrusivePtr< HUSD_HydraGeoPrim > HUSD_HydraGeoPrimPtr
Definition: HUSD_Scene.h:56
int64 myCamSerial
Definition: HUSD_Scene.h:354
UT_StringHolder myCurrentRenderPrim
Definition: HUSD_Scene.h:341
void setDefaultRenderPrim(const UT_StringRef &path)
Definition: HUSD_Scene.h:133
int64 myModSerial
Definition: HUSD_Scene.h:353
int64 myGeoSerial
Definition: HUSD_Scene.h:352
GEO_API int getPrimType(const TypeMask &mask)
UT_IntrusivePtr< HUSD_HydraMaterial > HUSD_HydraMaterialPtr
Definition: HUSD_Scene.h:62
bool myDeferUpdate
Definition: HUSD_Scene.h:357
UT_StringMap< UT_StringSet > myFieldsInVolumes
Definition: HUSD_Scene.h:326
UT_StringMap< HUSD_HydraMaterialPtr > myMaterials
Definition: HUSD_Scene.h:331
int64 highlightID() const
Definition: HUSD_Scene.h:228
ConformPolicy myConformPolicy
Definition: HUSD_Scene.h:359
UT_StringMap< int > myPathIDs
Definition: HUSD_Scene.h:322
GLuint res
Definition: glew.h:11507
GLenum const void * paths
Definition: glew.h:13589
int64 myStashedSelectionSizeB
Definition: HUSD_Scene.h:370
UT_Array< HUSD_HydraGeoPrimPtr > myDuplicateGeo
Definition: HUSD_Scene.h:336