HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUI_SceneCameras.h
Go to the documentation of this file.
1  /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GUI_SceneCameras.h
7  *
8  * COMMENTS:
9  * The list of generated cameras in the viewer from all sources.
10  */
11 #ifndef GUI_SceneCameras_h
12 #define GUI_SceneCameras_h
13 
14 #include "GUI_API.h"
15 
16 #include <GA/GA_Types.h>
17 #include <UT/UT_NonCopyable.h>
18 #include <UT/UT_Map.h>
19 #include <UT/UT_StringHolder.h>
20 #include <UT/UT_StringMap.h>
21 
22 class UT_CameraParms;
23 class OP_Node;
24 
25 /// Collection class for all cameras in a scene, from all sources
27 {
28 public:
29  /// Where the camera is generated from
30  enum SourceType { GEO_PRIM, OBJ_NODE, USD_PRIM, COP_NODE, DRAWABLE };
31 
32  enum LightType { LIGHT };
33  enum TypeGT { DRAWABLE_CAMERA };
34 
35  /// The context the camera is being shown for (not its source context).
36  /// This can affect how the camera name is displayed
37  enum ContextType { OBJ_SOP_CONTEXT, LOP_CONTEXT, COP_CONTEXT };
38 
39  /// The binding that drawable cameras are registered with.
40  enum DrawableBinding { DRAWABLE_INDEX = -1 };
41 
43  {
44  public:
45  CameraInfo() : myType(OBJ_NODE), myOpId(-999), myAltOpId(-999) {}
46 
47  // Object based cameras
48  CameraInfo(int op_id)
49  : myType(OBJ_NODE), myOpId(op_id), myIsLight(false) {}
50  // Object based lights
51  CameraInfo(int op_id, LightType)
52  : myType(OBJ_NODE), myOpId(op_id), myIsLight(true) {}
53  // Drawable cameras
54  CameraInfo(int look_id, const UT_StringHolder &name, TypeGT)
55  : myType(DRAWABLE), myLookId(look_id), myName(name) {}
56  // Sop based cameras
58  : myType(GEO_PRIM), myOpId(op_id), myIndex(index), myName(name),
59  myIsLight(false) {}
60  // COP or LOP light (name is layer or prim)
61  CameraInfo(int op_id, const UT_StringHolder &name,
62  SourceType type, bool is_light, int alt_op = -999)
63  : myType(type), myOpId(op_id), myName(name), myIsLight(is_light),
64  myAltOpId(alt_op) {}
65 
66  bool operator==(const CameraInfo &cam) const
67  {
68  if(cam.isValid() != isValid() ||
69  myType != cam.myType ||
70  myOpId != cam.myOpId ||
71  myLookId != cam.myLookId ||
72  myIsLight != cam.myIsLight)
73  {
74  return false;
75  }
76  if(myType == GEO_PRIM && myIndex != cam.myIndex)
77  return false;
78  if((myType == COP_NODE || myType == USD_PRIM) && myName!=cam.myName)
79  return false;
80 
81  return true;
82  }
83 
84  bool isValid() const;
85 
86  OP_Node *node() const;
87  OP_Node *nodeAlternate() const;
88  int opId() const { return myOpId; }
89  int lookId() const { return myLookId; }
90  GUI_SceneCameras::SourceType type() const { return myType; }
91  const UT_StringHolder &name() const { return myName; }
92  GA_Index primIndex() const { return myIndex; }
93  bool isLight() const { return myIsLight; }
94 
95  private:
96  SourceType myType;
97  int myOpId = -999;
98  int myAltOpId = -999;
99  int myLookId = 0;
100  GA_Index myIndex = GA_Index(0);
101  bool myIsLight = false;
102  UT_StringHolder myName;
103  };
104 
106 
107  /// Register a number of cameras created by the given look.
108  void registerCameras(int look_id, const UT_StringMap<CameraInfo> &cameras);
109 
110  /// Remove cameras associated with a look
111  void removeCameras(int look_id);
112 
113  bool hasCameras(int look_id) const { return myCameras.contains(look_id); }
114 
115  /// Return a list of camera names for a given context
116  void getCameras(UT_Array<std::pair<UT_StringHolder,CameraInfo>> &cams,
117  ContextType menu_type);
118 
119  /// Return a list of light names to view through, for a given context
120  void getLights(UT_Array<std::pair<UT_StringHolder,CameraInfo>> &lights,
121  ContextType menu_type);
122 
123  static UT_StringHolder getCameraName(ContextType for_context,
124  const CameraInfo &camera);
125 
126  static UT_StringHolder getCameraName(const OP_Node *node_network,
127  const CameraInfo &camera);
128 
129 protected:
130  /// Generate a name for a camera suitable for display
131  static UT_StringHolder makeCameraName(
132  SourceType cam_source,
133  ContextType context,
134  int op_id,
135  UT_StringHolder cam_name = UT_StringHolder());
136 
138 
140 };
141 
142 /* -------------------------------
143 
144  Resolve names:
145  OBJ /path/to/obj/camera
146  SOP /path/to/sop:cameraname
147  /path/to/sop:output:cameraname
148  LOP /path/to/lop:/path/to/prim
149  COP /path/to/cop:cameraname
150  /path/to/cop:output:cameraname
151 */
152 #endif
Collection class for all cameras in a scene, from all sources.
Unsorted map container.
Definition: UT_Map.h:114
CameraInfo(int op_id, GA_Index index, const UT_StringHolder &name)
CameraInfo(int op_id, const UT_StringHolder &name, SourceType type, bool is_light, int alt_op=-999)
DrawableBinding
The binding that drawable cameras are registered with.
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
#define GUI_API
Definition: GUI_API.h:10
CameraInfo(int op_id, LightType)
bool hasCameras(int look_id) const
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
UT_StringHolder getCameraName(const cgltf_data &data, const cgltf_camera &camera)
GLuint const GLchar * name
Definition: glcorearb.h:786
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:647
CameraInfo(int look_id, const UT_StringHolder &name, TypeGT)
UT_Map< int, UT_StringMap< CameraInfo > > myCameras
GUI_SceneCameras::SourceType type() const
GLuint index
Definition: glcorearb.h:786
bool operator==(const CameraInfo &cam) const
SourceType
Where the camera is generated from.
const UT_StringHolder & name() const