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  static PXR_NS::XUSD_ViewerDelegate *newDelegate();
83  static void freeDelegate(PXR_NS::XUSD_ViewerDelegate *del);
84 
85  static void pushScene(HUSD_Scene *scene);
86  static void popScene(HUSD_Scene *scene);
87  static bool hasScene();
88 
89  void addGeometry(HUSD_HydraGeoPrim *geo);
90  void removeGeometry(HUSD_HydraGeoPrim *geo);
91 
92  void addDisplayGeometry(HUSD_HydraGeoPrim *geo);
93  void removeDisplayGeometry(HUSD_HydraGeoPrim *geo);
94 
95  virtual void addCamera(HUSD_HydraCamera *cam);
96  virtual void removeCamera(HUSD_HydraCamera *cam);
97 
98  virtual void addLight(HUSD_HydraLight *light);
99  virtual void removeLight(HUSD_HydraLight *light);
100 
101  virtual void addMaterial(HUSD_HydraMaterial *mat);
102  virtual void removeMaterial(HUSD_HydraMaterial *mat);
103 
104  // Render Setting Prims don't exist in Hydra. The view places these
105  // here for easier interchange between high level objects.
106  const UT_StringArray &renderPrimNames() const { return myRenderPrimNames; }
107  bool setRenderPrimNames(const UT_StringArray &names);
108  const UT_StringRef &defaultRenderPrim() const { return myDefaultRenderPrim;}
110  { myDefaultRenderPrim = path;}
111  const UT_StringRef &currentRenderPrim() const { return myCurrentRenderPrim;}
113  { myCurrentRenderPrim = path;}
114  const UT_StringRef &renderPrimCamera() const { return myRenderPrimCamera; }
115  void setRenderPrimCamera(const UT_StringRef &camera);
116 
117  UT_Vector2I renderPrimResolution() const { return myRenderPrimRes; }
118  void setRenderPrimResolution(UT_Vector2I res) {myRenderPrimRes=res;}
119 
120  void deferUpdates(bool defer) { myDeferUpdate = defer; }
121  bool isDeferredUpdate() const { return myDeferUpdate; }
122 
123  // Volumes
124  const UT_StringSet &volumesUsingField(const UT_StringRef &field) const;
125  void addVolumeUsingField(const UT_StringHolder &volume,
126  const UT_StringHolder &field);
127  void removeVolumeUsingFields(const UT_StringRef &volume);
128 
129  // Selections. A highlight is a temporary selection which can be turned into
130  // a selection in various ways.
131  void addToHighlight(int id);
132  void addPathToHighlight(const UT_StringHolder &path);
133  void addInstanceToHighlight(int id);
134  void clearHighlight();
135 
136  void setHighlightAsSelection();
137  void addHighlightToSelection();
138  void removeHighlightFromSelection();
139  void toggleHighlightInSelection();
140  void intersectHighlightWithSelection();
141  bool clearSelection();
142 
143  bool selectParents();
144  bool selectChildren(bool all_children); // false = first child only
145  bool selectSiblings(bool next_sibling); // false = prev sibling
146  bool recallPrevSelection();
147  bool recallNextSelection();
148  void clearStashedSelections();
149 
150  void setSelection(const UT_StringArray &paths,
151  bool stash_selection = true);
152  const UT_StringArray &getSelectionList();
153  void redoSelectionList();
154 
155  // Convert a pattern to a selection.
156  void convertSelection(const char *selection_pattern,
158 
159  // Remove any non-prim (instance) selections.
160  bool removeInstanceSelections();
161  // Remove any non-instance (prim) selections.
162  bool removePrimSelections();
163 
164  bool hasSelection() const;
165  bool hasHighlight() const;
166  bool isSelected(int id) const;
167  bool isSelected(const HUSD_HydraPrim *prim) const;
168  bool isHighlighted(int id) const;
169  bool isHighlighted(const HUSD_HydraPrim *prim) const;
170 
171  int64 highlightID() const { return myHighlightID; }
172  int64 selectionID() const { return mySelectionID; }
173 
174  int64 getMaterialID(const UT_StringRef &path);
175 
176  static int getMaxGeoIndex();
177 
178  // bumped when a geo prim is added or removed.
179  int64 getGeoSerial() const { return myGeoSerial; }
180  int64 getCameraSerial() const { return myCamSerial; }
181  int64 getLightSerial() const { return myLightSerial; }
182 
183  // bumped when any prim has Sync() called.
184  int64 getModSerial() const { return myModSerial; }
185  void bumpModSerial() { myModSerial++; }
186 
187  enum PrimType
188  {
189  INVALID_TYPE = 0,
190 
196  INSTANCE
197  };
198  PrimType getPrimType(int id) const;
199 
200  int getOrCreateID(const UT_StringRef &path,
201  PrimType type = GEOMETRY);
202 
203  void setStage(const HUSD_DataHandle &data,
204  const HUSD_ConstOverridesPtr &overrides);
205 
206  PXR_NS::HdRenderIndex *renderIndex() { return myRenderIndex; }
207  void setRenderIndex(PXR_NS::HdRenderIndex *ri) { myRenderIndex = ri; }
208 
209  PXR_NS::HdRenderParam *renderParam() { return myRenderParam; }
210  void setRenderParam(PXR_NS::HdRenderParam *rp) { myRenderParam = rp; }
211 
212  // Debugging only... Do not use in production code.
213  HUSD_PrimHandle getPrim(const UT_StringHolder &path) const;
214 
216  {
218  CATEGORY_SHADOW
219  };
220  void addCategory(const UT_StringRef &name, LightCategory cat);
221  void removeCategory(const UT_StringRef &name,LightCategory cat);
222  bool isCategory(const UT_StringRef &name, LightCategory cat);
223 
224  void pendingRemovalPrim(const UT_StringRef &path,
225  HUSD_HydraGeoPrimPtr prim);
226  HUSD_HydraGeoPrimPtr fetchPendingRemovalPrim(const UT_StringRef &path);
227  void clearPendingRemovalPrims();
228 
229 protected:
230  virtual void geometryDisplayed(HUSD_HydraGeoPrim *, bool) {}
231  void selectionModified(int id);
232 
233  void stashSelection();
234  bool makeSelection(const UT_Map<int,int> &selection,
235  bool validate);
236 
237  int getIDForPrim(const UT_StringRef &path,
238  PrimType &return_prim_type,
239  bool create_path_id = false);
240 
254 
270 
275 
278 
283 
284  PXR_NS::HdRenderIndex *myRenderIndex; // TMP, hopefuly
285  PXR_NS::HdRenderParam *myRenderParam; // TMP, hopefuly
286 
289 };
290 
291 #endif
const UT_StringRef & defaultRenderPrim() const
Definition: HUSD_Scene.h:108
UT_StringHolder myDefaultRenderPrim
Definition: HUSD_Scene.h:253
GT_API const UT_StringHolder selection
int64 mySelectionID
Definition: HUSD_Scene.h:262
const UT_StringRef & currentRenderPrim() const
Definition: HUSD_Scene.h:111
int64 getCameraSerial() const
Definition: HUSD_Scene.h:180
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:271
UT_LinkList myStashedSelection
Definition: HUSD_Scene.h:279
UT_StringArray mySelectionArray
Definition: HUSD_Scene.h:258
virtual void geometryDisplayed(HUSD_HydraGeoPrim *, bool)
Definition: HUSD_Scene.h:230
UT_Vector2I renderPrimResolution() const
Definition: HUSD_Scene.h:117
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:287
UT_StringMap< HUSD_HydraLightPtr > myLights
Definition: HUSD_Scene.h:247
int64 selectionID() const
Definition: HUSD_Scene.h:172
#define HUSD_API
Definition: HUSD_API.h:32
UT_StringMap< int > myLightLinkCategories
Definition: HUSD_Scene.h:276
UT_StringMap< HUSD_HydraGeoPrimPtr > & geometry()
Definition: HUSD_Scene.h:65
void bumpModSerial()
Definition: HUSD_Scene.h:185
UT_Map< int, UT_Pair< UT_StringHolder, PrimType > > myNameIDLookup
Definition: HUSD_Scene.h:241
UT_StringMap< HUSD_HydraCameraPtr > myCameras
Definition: HUSD_Scene.h:246
UT_StringMap< HUSD_HydraGeoPrimPtr > myPendingRemovalPrims
Definition: HUSD_Scene.h:249
int64 getModSerial() const
Definition: HUSD_Scene.h:184
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:277
PXR_NS::HdRenderParam * renderParam()
Definition: HUSD_Scene.h:209
long long int64
Definition: SYS_Types.h:111
UT_StringHolder myRenderPrimCamera
Definition: HUSD_Scene.h:251
void setCurrentRenderPrim(const UT_StringRef &path)
Definition: HUSD_Scene.h:112
const UT_StringRef & renderPrimCamera() const
Definition: HUSD_Scene.h:114
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
UT_LinkNode * myCurrentRecalledSelection
Definition: HUSD_Scene.h:281
PXR_NS::HdRenderParam * myRenderParam
Definition: HUSD_Scene.h:285
GLuint const GLuint * names
Definition: glew.h:2690
Wrapper around hboost::intrusive_ptr.
int64 getLightSerial() const
Definition: HUSD_Scene.h:181
UT_Lock myMaterialLock
Definition: HUSD_Scene.h:273
void setRenderPrimResolution(UT_Vector2I res)
Definition: HUSD_Scene.h:118
bool mySelectionArrayNeedsUpdate
Definition: HUSD_Scene.h:260
int64 myHighlightID
Definition: HUSD_Scene.h:261
UT_StringMap< int64 > myMatIDs
Definition: HUSD_Scene.h:257
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
HUSD_ConstOverridesPtr myStageOverrides
Definition: HUSD_Scene.h:288
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:106
int64 myLightSerial
Definition: HUSD_Scene.h:266
GLsizei const GLchar *const * path
Definition: glew.h:6461
UT_Map< int, int > myHighlight
Definition: HUSD_Scene.h:255
void deferUpdates(bool defer)
Definition: HUSD_Scene.h:120
int64 mySelectionResolveSerial
Definition: HUSD_Scene.h:267
void setRenderIndex(PXR_NS::HdRenderIndex *ri)
Definition: HUSD_Scene.h:207
UT_StringMap< HUSD_HydraGeoPrimPtr > myGeometry
Definition: HUSD_Scene.h:244
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1245
PXR_NS::HdRenderIndex * renderIndex()
Definition: HUSD_Scene.h:206
UT_Map< int, int > mySelection
Definition: HUSD_Scene.h:256
UT_Lock myCategoryLock
Definition: HUSD_Scene.h:274
bool isDeferredUpdate() const
Definition: HUSD_Scene.h:121
UT_Lock myLightCamLock
Definition: HUSD_Scene.h:272
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:83
int64 getGeoSerial() const
Definition: HUSD_Scene.h:179
void setRenderParam(PXR_NS::HdRenderParam *rp)
Definition: HUSD_Scene.h:210
GLenum array
Definition: glew.h:9066
UT_StringArray myRenderPrimNames
Definition: HUSD_Scene.h:250
UT_Vector2I myRenderPrimRes
Definition: HUSD_Scene.h:269
int64 myCurrentSelectionStashed
Definition: HUSD_Scene.h:282
int64 mySelectionArrayID
Definition: HUSD_Scene.h:259
UT_StringMap< HUSD_HydraCameraPtr > & cameras()
Definition: HUSD_Scene.h:66
PXR_NS::HdRenderIndex * myRenderIndex
Definition: HUSD_Scene.h:284
UT_StringMap< HUSD_HydraGeoPrimPtr > myDisplayGeometry
Definition: HUSD_Scene.h:245
UT_IntrusivePtr< HUSD_HydraGeoPrim > HUSD_HydraGeoPrimPtr
Definition: HUSD_Scene.h:51
int64 myCamSerial
Definition: HUSD_Scene.h:265
UT_StringHolder myCurrentRenderPrim
Definition: HUSD_Scene.h:252
void setDefaultRenderPrim(const UT_StringRef &path)
Definition: HUSD_Scene.h:109
int64 myModSerial
Definition: HUSD_Scene.h:264
int64 myGeoSerial
Definition: HUSD_Scene.h:263
GEO_API int getPrimType(const TypeMask &mask)
UT_IntrusivePtr< HUSD_HydraMaterial > HUSD_HydraMaterialPtr
Definition: HUSD_Scene.h:56
bool myDeferUpdate
Definition: HUSD_Scene.h:268
UT_StringMap< UT_StringSet > myFieldsInVolumes
Definition: HUSD_Scene.h:243
UT_StringMap< HUSD_HydraMaterialPtr > myMaterials
Definition: HUSD_Scene.h:248
int64 highlightID() const
Definition: HUSD_Scene.h:171
UT_StringMap< int > myPathIDs
Definition: HUSD_Scene.h:242
GLuint res
Definition: glew.h:11507
GLenum const void * paths
Definition: glew.h:13589
int64 myStashedSelectionSizeB
Definition: HUSD_Scene.h:280