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_Pair.h>
31 #include <UT/UT_StringArray.h>
32 #include <UT/UT_StringMap.h>
33 #include <UT/UT_StringSet.h>
34 #include <UT/UT_IntrusivePtr.h>
35 #include <UT/UT_Vector2.h>
36 #include <SYS/SYS_Types.h>
37 #include "HUSD_PrimHandle.h"
38 #include "HUSD_Overrides.h"
39 
41 class XUSD_ViewerDelegate;
42 class HdRenderIndex;
43 class HdRenderParam;
45 
46 class HUSD_HydraCamera;
47 class HUSD_HydraGeoPrim;
48 class HUSD_HydraLight;
49 class HUSD_HydraPrim;
50 class HUSD_HydraMaterial;
52 
57 
58 /// Scene information for the native viewport renderer
60 {
61 public:
62  HUSD_Scene();
63  virtual ~HUSD_Scene();
64 
65  UT_StringMap<HUSD_HydraGeoPrimPtr> &geometry() { return myDisplayGeometry; }
66  UT_StringMap<HUSD_HydraCameraPtr> &cameras() { return myCameras; }
67  UT_StringMap<HUSD_HydraLightPtr> &lights() { return myLights; }
69 
70  // all of these return true if the list was modified, false if the serial
71  // matched;
72  bool fillGeometry(UT_Array<HUSD_HydraGeoPrimPtr> &array,
73  int64 &list_serial);
74  bool fillLights(UT_Array<HUSD_HydraLightPtr> &array,
75  int64 &list_serial);
76  bool fillCameras(UT_Array<HUSD_HydraCameraPtr> &array,
77  int64 &list_serial);
78 
79  const UT_StringRef &lookupPath(int id) const;
80  int lookupGeomId(const UT_StringRef &path);
81 
82  // Hydra generated selection ids, set & query.
83  void setRenderID(const UT_StringRef &path, int id);
84  void clearRenderIDs();
85  int lookupRenderID(const UT_StringRef &path) const;
86  UT_StringHolder lookupRenderPath(int id) const;
87  int convertRenderID(int id) const;
88 
89  static PXR_NS::XUSD_ViewerDelegate *newDelegate();
90  static void freeDelegate(PXR_NS::XUSD_ViewerDelegate *del);
91 
92  static void pushScene(HUSD_Scene *scene);
93  static void popScene(HUSD_Scene *scene);
94  static bool hasScene();
95 
96  void addGeometry(HUSD_HydraGeoPrim *geo, bool new_geo);
97  void removeGeometry(HUSD_HydraGeoPrim *geo);
98 
99  void addDisplayGeometry(HUSD_HydraGeoPrim *geo);
100  void removeDisplayGeometry(HUSD_HydraGeoPrim *geo);
101 
102  virtual void addCamera(HUSD_HydraCamera *cam, bool new_cam);
103  virtual void removeCamera(HUSD_HydraCamera *cam);
104 
105  virtual void addLight(HUSD_HydraLight *light, bool new_light);
106  virtual void removeLight(HUSD_HydraLight *light);
107 
108  virtual void addMaterial(HUSD_HydraMaterial *mat);
109  virtual void removeMaterial(HUSD_HydraMaterial *mat);
110 
111  // Render Setting Prims don't exist in Hydra. The view places these
112  // here for easier interchange between high level objects.
113  const UT_StringArray &renderPrimNames() const { return myRenderPrimNames; }
114  bool setRenderPrimNames(const UT_StringArray &names);
115  const UT_StringRef &defaultRenderPrim() const { return myDefaultRenderPrim;}
117  { myDefaultRenderPrim = path;}
118  const UT_StringRef &currentRenderPrim() const { return myCurrentRenderPrim;}
120  { myCurrentRenderPrim = path;}
121  const UT_StringRef &renderPrimCamera() const { return myRenderPrimCamera; }
122  void setRenderPrimCamera(const UT_StringRef &camera);
123 
124  UT_Vector2I renderPrimResolution() const { return myRenderPrimRes; }
125  void setRenderPrimResolution(UT_Vector2I res) {myRenderPrimRes=res;}
126 
127  void deferUpdates(bool defer) { myDeferUpdate = defer; }
128  bool isDeferredUpdate() const { return myDeferUpdate; }
129 
130  // Volumes
131  const UT_StringSet &volumesUsingField(const UT_StringRef &field) const;
132  void addVolumeUsingField(const UT_StringHolder &volume,
133  const UT_StringHolder &field);
134  void removeVolumeUsingFields(const UT_StringRef &volume);
135 
136  // Selections. A highlight is a temporary selection which can be turned into
137  // a selection in various ways.
138  void addToHighlight(int id, bool render_id);
139  void addPathToHighlight(const UT_StringHolder &path);
140  void addInstanceToHighlight(int id);
141  void clearHighlight();
142 
143  void setHighlightAsSelection();
144  void addHighlightToSelection();
145  void removeHighlightFromSelection();
146  void toggleHighlightInSelection();
147  void intersectHighlightWithSelection();
148  bool clearSelection();
149 
150  bool selectParents();
151  bool selectChildren(bool all_children); // false = first child only
152  bool selectSiblings(bool next_sibling); // false = prev sibling
153  bool recallPrevSelection();
154  bool recallNextSelection();
155  void clearStashedSelections();
156 
157  void setSelection(const UT_StringArray &paths,
158  bool stash_selection = true);
159  const UT_StringArray &getSelectionList();
160  void redoSelectionList();
161 
162  // Convert a pattern to a selection.
163  void convertSelection(const char *selection_pattern,
165 
166  // Remove any non-prim (instance) selections.
167  bool removeInstanceSelections();
168  // Remove any non-instance (prim) selections.
169  bool removePrimSelections();
170 
171  bool hasSelection() const;
172  bool hasHighlight() const;
173  bool isSelected(int id) const;
174  bool isSelected(const HUSD_HydraPrim *prim) const;
175  bool isHighlighted(int id) const;
176  bool isHighlighted(const HUSD_HydraPrim *prim) const;
177 
178  int64 highlightID() const { return myHighlightID; }
179  int64 selectionID() const { return mySelectionID; }
180 
181  int64 getMaterialID(const UT_StringRef &path);
182 
183  static int getMaxGeoIndex();
184 
185  // bumped when a geo prim is added or removed.
186  int64 getGeoSerial() const { return myGeoSerial; }
187  int64 getCameraSerial() const { return myCamSerial; }
188  int64 getLightSerial() const { return myLightSerial; }
189 
190  // bumped when any prim has Sync() called.
191  int64 getModSerial() const { return myModSerial; }
192  void bumpModSerial() { myModSerial++; }
193 
194  enum PrimType
195  {
196  INVALID_TYPE = 0,
197 
203  INSTANCE
204  };
205  PrimType getPrimType(int id) const;
206 
207  int getOrCreateID(const UT_StringRef &path,
208  PrimType type = GEOMETRY);
209 
210  void setStage(const HUSD_DataHandle &data,
211  const HUSD_ConstOverridesPtr &overrides);
212 
213  PXR_NS::HdRenderIndex *renderIndex() { return myRenderIndex; }
214  void setRenderIndex(PXR_NS::HdRenderIndex *ri) { myRenderIndex = ri; }
215 
216  PXR_NS::HdRenderParam *renderParam() { return myRenderParam; }
217  void setRenderParam(PXR_NS::HdRenderParam *rp) { myRenderParam = rp; }
218 
219  // Debugging only... Do not use in production code.
220  HUSD_PrimHandle getPrim(const UT_StringHolder &path) const;
221 
223  {
225  CATEGORY_SHADOW
226  };
227  void addCategory(const UT_StringRef &name, LightCategory cat);
228  void removeCategory(const UT_StringRef &name,LightCategory cat);
229  bool isCategory(const UT_StringRef &name, LightCategory cat);
230 
231  void pendingRemovalGeom(const UT_StringRef &path,
232  HUSD_HydraGeoPrimPtr prim);
233  HUSD_HydraGeoPrimPtr fetchPendingRemovalGeom(const UT_StringRef &path);
234  void pendingRemovalCamera(const UT_StringRef &path,
235  HUSD_HydraCameraPtr prim);
236  HUSD_HydraCameraPtr fetchPendingRemovalCamera(const UT_StringRef &path);
237  void pendingRemovalLight(const UT_StringRef &path,
238  HUSD_HydraLightPtr prim);
239  HUSD_HydraLightPtr fetchPendingRemovalLight(const UT_StringRef &path);
240 
241  void clearPendingRemovalPrims();
242 protected:
243  virtual void geometryDisplayed(HUSD_HydraGeoPrim *, bool) {}
244  void selectionModified(int id);
245 
246  void stashSelection();
247  bool makeSelection(const UT_Map<int,int> &selection,
248  bool validate);
249 
250  int getIDForPrim(const UT_StringRef &path,
251  PrimType &return_prim_type,
252  bool create_path_id = false);
253 
272 
288 
293 
296 
301 
302  PXR_NS::HdRenderIndex *myRenderIndex; // TMP, hopefuly
303  PXR_NS::HdRenderParam *myRenderParam; // TMP, hopefuly
304 
307 };
308 
309 #endif
const UT_StringRef & defaultRenderPrim() const
Definition: HUSD_Scene.h:115
UT_StringHolder myDefaultRenderPrim
Definition: HUSD_Scene.h:271
GT_API const UT_StringHolder selection
int64 mySelectionID
Definition: HUSD_Scene.h:280
const UT_StringRef & currentRenderPrim() const
Definition: HUSD_Scene.h:118
int64 getCameraSerial() const
Definition: HUSD_Scene.h:187
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:289
UT_LinkList myStashedSelection
Definition: HUSD_Scene.h:297
UT_StringArray mySelectionArray
Definition: HUSD_Scene.h:276
virtual void geometryDisplayed(HUSD_HydraGeoPrim *, bool)
Definition: HUSD_Scene.h:243
UT_Vector2I renderPrimResolution() const
Definition: HUSD_Scene.h:124
Scene information for the native viewport renderer.
Definition: HUSD_Scene.h:59
UT_StringMap< HUSD_HydraMaterialPtr > & materials()
Definition: HUSD_Scene.h:68
HUSD_DataHandle myStage
Definition: HUSD_Scene.h:305
UT_StringMap< HUSD_HydraLightPtr > myLights
Definition: HUSD_Scene.h:263
int64 selectionID() const
Definition: HUSD_Scene.h:179
UT_Map< int, int > myRenderIDtoGeomID
Definition: HUSD_Scene.h:258
#define HUSD_API
Definition: HUSD_API.h:32
UT_StringMap< int > myLightLinkCategories
Definition: HUSD_Scene.h:294
UT_StringMap< HUSD_HydraGeoPrimPtr > myPendingRemovalGeom
Definition: HUSD_Scene.h:265
UT_StringMap< HUSD_HydraGeoPrimPtr > & geometry()
Definition: HUSD_Scene.h:65
UT_StringMap< HUSD_HydraCameraPtr > myPendingRemovalCamera
Definition: HUSD_Scene.h:266
void bumpModSerial()
Definition: HUSD_Scene.h:192
UT_Map< int, UT_Pair< UT_StringHolder, PrimType > > myNameIDLookup
Definition: HUSD_Scene.h:254
UT_StringMap< HUSD_HydraCameraPtr > myCameras
Definition: HUSD_Scene.h:262
int64 getModSerial() const
Definition: HUSD_Scene.h:191
UT_StringMap< HUSD_HydraLightPtr > & lights()
Definition: HUSD_Scene.h:67
ALEMBIC_EXPORT OMaterialSchema addMaterial(Abc::OObject iObject, const std::string &iPropName=MATERIAL_PROPNAME)
UT_StringMap< int > myShadowLinkCategories
Definition: HUSD_Scene.h:295
PXR_NS::HdRenderParam * renderParam()
Definition: HUSD_Scene.h:216
UT_StringMap< int > myRenderIDs
Definition: HUSD_Scene.h:257
long long int64
Definition: SYS_Types.h:111
UT_StringHolder myRenderPrimCamera
Definition: HUSD_Scene.h:269
void setCurrentRenderPrim(const UT_StringRef &path)
Definition: HUSD_Scene.h:119
const UT_StringRef & renderPrimCamera() const
Definition: HUSD_Scene.h:121
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
UT_LinkNode * myCurrentRecalledSelection
Definition: HUSD_Scene.h:299
PXR_NS::HdRenderParam * myRenderParam
Definition: HUSD_Scene.h:303
GLuint const GLuint * names
Definition: glew.h:2690
Wrapper around hboost::intrusive_ptr.
int64 getLightSerial() const
Definition: HUSD_Scene.h:188
UT_Lock myMaterialLock
Definition: HUSD_Scene.h:291
void setRenderPrimResolution(UT_Vector2I res)
Definition: HUSD_Scene.h:125
bool mySelectionArrayNeedsUpdate
Definition: HUSD_Scene.h:278
int64 myHighlightID
Definition: HUSD_Scene.h:279
UT_StringMap< int64 > myMatIDs
Definition: HUSD_Scene.h:275
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
HUSD_ConstOverridesPtr myStageOverrides
Definition: HUSD_Scene.h:306
UT_IntrusivePtr< HUSD_HydraCamera > HUSD_HydraCameraPtr
Definition: HUSD_Scene.h:54
UT_IntrusivePtr< HUSD_HydraLight > HUSD_HydraLightPtr
Definition: HUSD_Scene.h:55
const UT_StringArray & renderPrimNames() const
Definition: HUSD_Scene.h:113
int64 myLightSerial
Definition: HUSD_Scene.h:284
GLsizei const GLchar *const * path
Definition: glew.h:6461
UT_Map< int, int > myHighlight
Definition: HUSD_Scene.h:273
void deferUpdates(bool defer)
Definition: HUSD_Scene.h:127
int64 mySelectionResolveSerial
Definition: HUSD_Scene.h:285
void setRenderIndex(PXR_NS::HdRenderIndex *ri)
Definition: HUSD_Scene.h:214
UT_StringMap< HUSD_HydraLightPtr > myPendingRemovalLight
Definition: HUSD_Scene.h:267
UT_StringMap< HUSD_HydraGeoPrimPtr > myGeometry
Definition: HUSD_Scene.h:260
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1245
PXR_NS::HdRenderIndex * renderIndex()
Definition: HUSD_Scene.h:213
UT_Map< int, int > mySelection
Definition: HUSD_Scene.h:274
UT_Lock myCategoryLock
Definition: HUSD_Scene.h:292
bool isDeferredUpdate() const
Definition: HUSD_Scene.h:128
UT_Lock myLightCamLock
Definition: HUSD_Scene.h:290
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:83
int64 getGeoSerial() const
Definition: HUSD_Scene.h:186
UT_Map< int, UT_StringHolder > myRenderPaths
Definition: HUSD_Scene.h:256
void setRenderParam(PXR_NS::HdRenderParam *rp)
Definition: HUSD_Scene.h:217
GLenum array
Definition: glew.h:9066
UT_StringArray myRenderPrimNames
Definition: HUSD_Scene.h:268
UT_Vector2I myRenderPrimRes
Definition: HUSD_Scene.h:287
int64 myCurrentSelectionStashed
Definition: HUSD_Scene.h:300
int64 mySelectionArrayID
Definition: HUSD_Scene.h:277
UT_StringMap< HUSD_HydraCameraPtr > & cameras()
Definition: HUSD_Scene.h:66
PXR_NS::HdRenderIndex * myRenderIndex
Definition: HUSD_Scene.h:302
UT_StringMap< HUSD_HydraGeoPrimPtr > myDisplayGeometry
Definition: HUSD_Scene.h:261
UT_IntrusivePtr< HUSD_HydraGeoPrim > HUSD_HydraGeoPrimPtr
Definition: HUSD_Scene.h:51
int64 myCamSerial
Definition: HUSD_Scene.h:283
UT_StringHolder myCurrentRenderPrim
Definition: HUSD_Scene.h:270
void setDefaultRenderPrim(const UT_StringRef &path)
Definition: HUSD_Scene.h:116
int64 myModSerial
Definition: HUSD_Scene.h:282
int64 myGeoSerial
Definition: HUSD_Scene.h:281
GEO_API int getPrimType(const TypeMask &mask)
UT_IntrusivePtr< HUSD_HydraMaterial > HUSD_HydraMaterialPtr
Definition: HUSD_Scene.h:56
bool myDeferUpdate
Definition: HUSD_Scene.h:286
UT_StringMap< UT_StringSet > myFieldsInVolumes
Definition: HUSD_Scene.h:259
UT_StringMap< HUSD_HydraMaterialPtr > myMaterials
Definition: HUSD_Scene.h:264
int64 highlightID() const
Definition: HUSD_Scene.h:178
UT_StringMap< int > myPathIDs
Definition: HUSD_Scene.h:255
GLuint res
Definition: glew.h:11507
GLenum const void * paths
Definition: glew.h:13589
int64 myStashedSelectionSizeB
Definition: HUSD_Scene.h:298