HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_AgentDefinition.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: GU_AgentDefinition.h (GU Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GU_AgentDefinition__
12 #define __GU_AgentDefinition__
13 
14 #include "GU_API.h"
15 #include "GU_AgentClip.h"
16 #include "GU_AgentCustomDataItem.h"
17 #include "GU_AgentLayer.h"
18 #include "GU_AgentMetadata.h"
19 #include "GU_AgentRig.h"
20 #include "GU_AgentShapeLib.h"
21 #include "GU_AgentTransformGroup.h"
22 
23 #include <UT/UT_Array.h>
24 #include <UT/UT_IntrusivePtr.h>
25 #include <UT/UT_StringMap.h>
26 
27 #include <functional>
28 
32 
33 /// An agent definition contains a rig, a shape library, a set of available
34 /// clips, a set of available layers, and a set of transform groups.
36  : public UT_IntrusiveRefCounter<GU_AgentDefinition>
37 {
38 public:
40 
42  const GU_AgentShapeLibConstPtr &shapelib);
43 
44  /// Create a copy of the given agent definition, but referencing a new
45  /// version of the shape library and/or rig.
46  GU_AgentDefinition(const GU_AgentDefinition &src_defn,
47  const GU_AgentShapeLibConstPtr &new_shapelib,
48  const GU_AgentRigConstPtr &new_rig = nullptr);
49 
50  int64 getMemoryUsage(bool inclusive) const;
51 
52  /// Loads the agent definition from JSON. Used when loading agent
53  /// primitives from a geometry file.
54  bool load(UT_JSONParser &p);
55 
56  /// Saves the agent definition to JSON. Used when saving agent primitives
57  /// to a geometry file.
58  bool save(UT_JSONWriter &w) const;
59 
60  const GU_AgentRigConstPtr &rig() const { return myRig; }
61  const GU_AgentShapeLibConstPtr &shapeLibrary() const { return myShapeLib; }
62 
63  /// Add a layer to the agent definition. Replaces any pre-existing layer of
64  /// the same name.
65  void addLayer(const GU_AgentLayerConstPtr &layer);
66 
67  /// Remove a layer from the agent definition by name.
68  void removeLayer(const UT_StringRef &name);
69 
70  /// Return the list of layers.
72  { sortLayersIfNeeded(); return myLayers; }
73 
74  /// Get a pointer to a specfic layer. This may be a NULL pointer.
75  const GU_AgentLayer *layer(const UT_StringRef &name) const;
76 
77  /// Get the index of a layer, or -1 if it does not exist.
78  exint layerIndex(const UT_StringRef &name) const;
79 
80  /// Get a reference to the ith layer.
81  const GU_AgentLayer &layer(exint i) const
82  { sortLayersIfNeeded(); return *myLayers(i); }
83 
84  /// Return the layer count.
85  exint numLayers() const { return myLayers.size(); }
86 
87  /// Add a clip to the agent definition. Replaces any pre-existing clip of
88  /// the same name.
89  void addClip(const GU_AgentClipConstPtr &clip);
90 
91  /// Remove a clip from the agent definition by name.
92  void removeClip(const UT_StringRef &name);
93 
94  /// Return the list of clips.
96  { sortClipsIfNeeded(); return myClips; }
97 
98  /// Get a pointer to a specfic clip. This may be a NULL pointer.
99  const GU_AgentClip *clip(const UT_StringRef &name) const;
100 
101  /// Get the index of a clip, or -1 if it does not exist.
102  exint clipIndex(const UT_StringRef &name) const;
103 
104  /// Get a reference to the ith clip.
105  const GU_AgentClip &clip(exint i) const
106  { sortClipsIfNeeded(); return *myClips(i); }
107 
108  /// Return the clip count.
109  exint numClips() const { return myClips.size(); }
110 
111  /// Add a transform group to the agent definition. Replaces any
112  /// pre-existing group of the same name.
113  void addTransformGroup(const GU_AgentTransformGroupConstPtr &group);
114 
115  /// Remove a transform group from the agent definition by name.
116  void removeTransformGroup(const UT_StringRef &name);
117 
118  /// Return the list of groups.
120  { sortTransformGroupsIfNeeded(); return myTransformGroups; }
121 
122  /// Get a pointer to a specfic group. This may be a NULL pointer.
123  const GU_AgentTransformGroup *transformGroup(const UT_StringRef &name) const;
124 
125  /// Get the index of a transform group, or -1 if it does not exist.
126  exint transformGroupIndex(const UT_StringRef &name) const;
127 
128  /// Get the default transform group, which contains all transforms in the
129  /// rig.
131  { return *myDefaultTransformGroup; }
132 
133  /// Get a reference to the ith group.
135  { sortTransformGroupsIfNeeded(); return *myTransformGroups(i); }
136 
137  /// Return the transform group count.
138  exint numTransformGroups() const { return myTransformGroups.size(); }
139 
140  /// Return the metadata dictionary. This may be a nullptr.
141  const GU_AgentMetadataConstPtr &metadata() const { return myMetadata; }
142 
143  /// Replace the metadata dictionary.
145  { myMetadata = data; }
146 
147  /// Add a custom data item to the agent definition. Replaces any
148  /// pre-existing item of the same name.
149  void addCustomDataItem(const GU_AgentCustomDataItemConstPtr &data);
150 
151  /// Remove a custom data item from the agent definition by name.
152  void removeCustomDataItem(const UT_StringRef &name);
153 
154  /// Return the list of custom data items.
156  { sortCustomDataItemsIfNeeded(); return myCustomDataItems; }
157 
158  /// Get a pointer to a specfic data item by name. This may be a NULL
159  /// pointer.
160  const GU_AgentCustomDataItem *customDataItem(const UT_StringRef &name) const;
161 
162  /// Get a reference to the ith custom data item.
164  { sortCustomDataItemsIfNeeded(); return *myCustomDataItems[i]; }
165 
166  /// Return the number of custom data items.
167  exint numCustomDataItems() const { return myCustomDataItems.size(); }
168 
169  /// Constructs a new instance of a GU_AgentCustomDataItem. The provided
170  /// agent definition can be used if the data item requires references to
171  /// the rig, shape library, etc.
172  using CustomDataItemConstructor =
173  std::function<GU_AgentCustomDataItemPtr (const GU_AgentDefinition &)>;
174 
175  /// Register a new custom data item type.
176  static void registerCustomDataItemType(
177  const UT_StringHolder &dataitemtype,
178  CustomDataItemConstructor constructor);
179 
180  /// Called by GU_Agent during startup to register custom data item types.
181  static void installCustomDataItemTypes();
182 
183 private:
184  void sortLayersIfNeeded() const;
185  void sortClipsIfNeeded() const;
186  void sortTransformGroupsIfNeeded() const;
187  void sortCustomDataItemsIfNeeded() const;
188 
189  /// Constructs the default transform group that contains all of the joints.
190  void addDefaultTransformGroup();
191 
192 private:
193  GU_AgentRigConstPtr myRig;
194  GU_AgentShapeLibConstPtr myShapeLib;
195 
197  UT_StringMap<exint> myLayersIndex;
198 
200  UT_StringMap<exint> myClipsIndex;
201 
203  UT_StringMap<exint> myTransformGroupsIndex;
204  GU_AgentTransformGroupConstPtr myDefaultTransformGroup;
205 
206  GU_AgentMetadataConstPtr myMetadata;
207 
209  UT_StringMap<exint> myCustomDataItemsIndex;
210 
211  bool myAreLayersSorted;
212  bool myAreClipsSorted;
213  bool myAreTransformGroupsSorted;
214  bool myAreCustomDataItemsSorted;
215 };
216 
217 extern "C" {
218  /// Entry point for registering custom data item types.
220 };
221 
222 #endif
const GU_AgentMetadataConstPtr & metadata() const
Return the metadata dictionary. This may be a nullptr.
exint numTransformGroups() const
Return the transform group count.
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
const GU_AgentTransformGroup & defaultTransformGroup() const
#define SYS_VISIBILITY_EXPORT
const UT_Array< GU_AgentClipConstPtr > & clips() const
Return the list of clips.
std::function< GU_AgentCustomDataItemPtr(const GU_AgentDefinition &)> CustomDataItemConstructor
const UT_Array< GU_AgentLayerConstPtr > & layers() const
Return the list of layers.
int64 exint
Definition: SYS_Types.h:125
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:88
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:35
GLuint const GLchar * name
Definition: glcorearb.h:786
A reference counter base class for use with UT_IntrusivePtr.
const GU_AgentShapeLibConstPtr & shapeLibrary() const
UT_IntrusivePtr< GU_AgentDefinition > GU_AgentDefinitionPtr
exint numLayers() const
Return the layer count.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
const GU_AgentRigConstPtr & rig() const
const GU_AgentLayer & layer(exint i) const
Get a reference to the ith layer.
const GU_AgentTransformGroup & transformGroup(exint i) const
Get a reference to the ith group.
SYS_VISIBILITY_EXPORT void GUregisterAgentCustomDataItemType()
Entry point for registering custom data item types.
exint numClips() const
Return the clip count.
const GU_AgentCustomDataItem & customDataItem(exint i) const
Get a reference to the ith custom data item.
void setMetadata(const GU_AgentMetadataConstPtr &data)
Replace the metadata dictionary.
long long int64
Definition: SYS_Types.h:116
GLfloat GLfloat p
Definition: glew.h:16656
const GU_AgentClip & clip(exint i) const
Get a reference to the ith clip.
#define GU_API
Definition: GU_API.h:14
GLboolean * data
Definition: glcorearb.h:131
const UT_Array< GU_AgentTransformGroupConstPtr > & transformGroups() const
Return the list of groups.
GLboolean GLuint group
Definition: glew.h:2750
const UT_Array< GU_AgentCustomDataItemConstPtr > & customDataItems() const
Return the list of custom data items.
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T clip(const T &p, const Box< T > &box) IMATH_NOEXCEPT
Definition: ImathBoxAlgo.h:29
exint numCustomDataItems() const
Return the number of custom data items.
Definition: format.h:895
UT_IntrusivePtr< const GU_AgentDefinition > GU_AgentDefinitionConstPtr